]> git.pld-linux.org Git - packages/kernel.git/blob - kernel-vserver-2.3.patch
- updated
[packages/kernel.git] / kernel-vserver-2.3.patch
1 diff -NurpP --minimal linux-2.6.29/arch/alpha/Kconfig linux-2.6.29-vs2.3.0.36.9-pre3/arch/alpha/Kconfig
2 --- linux-2.6.29/arch/alpha/Kconfig     2009-03-24 14:18:07.000000000 +0100
3 +++ linux-2.6.29-vs2.3.0.36.9-pre3/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/arch/alpha/kernel/entry.S linux-2.6.29-vs2.3.0.36.9-pre3/arch/alpha/kernel/entry.S
14 --- linux-2.6.29/arch/alpha/kernel/entry.S      2009-03-24 14:18:07.000000000 +0100
15 +++ linux-2.6.29-vs2.3.0.36.9-pre3/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/arch/alpha/kernel/osf_sys.c linux-2.6.29-vs2.3.0.36.9-pre3/arch/alpha/kernel/osf_sys.c
49 --- linux-2.6.29/arch/alpha/kernel/osf_sys.c    2009-03-24 14:18:07.000000000 +0100
50 +++ linux-2.6.29-vs2.3.0.36.9-pre3/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/arch/alpha/kernel/ptrace.c linux-2.6.29-vs2.3.0.36.9-pre3/arch/alpha/kernel/ptrace.c
61 --- linux-2.6.29/arch/alpha/kernel/ptrace.c     2008-12-25 00:26:37.000000000 +0100
62 +++ linux-2.6.29-vs2.3.0.36.9-pre3/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/arch/alpha/kernel/systbls.S linux-2.6.29-vs2.3.0.36.9-pre3/arch/alpha/kernel/systbls.S
72 --- linux-2.6.29/arch/alpha/kernel/systbls.S    2009-03-24 14:18:08.000000000 +0100
73 +++ linux-2.6.29-vs2.3.0.36.9-pre3/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/arch/alpha/kernel/traps.c linux-2.6.29-vs2.3.0.36.9-pre3/arch/alpha/kernel/traps.c
84 --- linux-2.6.29/arch/alpha/kernel/traps.c      2008-12-25 00:26:37.000000000 +0100
85 +++ linux-2.6.29-vs2.3.0.36.9-pre3/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/arch/alpha/mm/fault.c linux-2.6.29-vs2.3.0.36.9-pre3/arch/alpha/mm/fault.c
97 --- linux-2.6.29/arch/alpha/mm/fault.c  2008-12-25 00:26:37.000000000 +0100
98 +++ linux-2.6.29-vs2.3.0.36.9-pre3/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/arch/arm/Kconfig linux-2.6.29-vs2.3.0.36.9-pre3/arch/arm/Kconfig
111 --- linux-2.6.29/arch/arm/Kconfig       2009-03-24 14:18:08.000000000 +0100
112 +++ linux-2.6.29-vs2.3.0.36.9-pre3/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/arch/arm/kernel/calls.S linux-2.6.29-vs2.3.0.36.9-pre3/arch/arm/kernel/calls.S
123 --- linux-2.6.29/arch/arm/kernel/calls.S        2009-03-24 14:18:09.000000000 +0100
124 +++ linux-2.6.29-vs2.3.0.36.9-pre3/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/arch/arm/kernel/process.c linux-2.6.29-vs2.3.0.36.9-pre3/arch/arm/kernel/process.c
135 --- linux-2.6.29/arch/arm/kernel/process.c      2008-12-25 00:26:37.000000000 +0100
136 +++ linux-2.6.29-vs2.3.0.36.9-pre3/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/arch/arm/kernel/traps.c linux-2.6.29-vs2.3.0.36.9-pre3/arch/arm/kernel/traps.c
148 --- linux-2.6.29/arch/arm/kernel/traps.c        2008-12-25 00:26:37.000000000 +0100
149 +++ linux-2.6.29-vs2.3.0.36.9-pre3/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/arch/arm/mm/fault.c linux-2.6.29-vs2.3.0.36.9-pre3/arch/arm/mm/fault.c
162 --- linux-2.6.29/arch/arm/mm/fault.c    2009-03-24 14:18:17.000000000 +0100
163 +++ linux-2.6.29-vs2.3.0.36.9-pre3/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/arch/cris/Kconfig linux-2.6.29-vs2.3.0.36.9-pre3/arch/cris/Kconfig
175 --- linux-2.6.29/arch/cris/Kconfig      2009-03-24 14:18:23.000000000 +0100
176 +++ linux-2.6.29-vs2.3.0.36.9-pre3/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/arch/frv/kernel/kernel_thread.S linux-2.6.29-vs2.3.0.36.9-pre3/arch/frv/kernel/kernel_thread.S
187 --- linux-2.6.29/arch/frv/kernel/kernel_thread.S        2008-12-25 00:26:37.000000000 +0100
188 +++ linux-2.6.29-vs2.3.0.36.9-pre3/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/arch/h8300/Kconfig linux-2.6.29-vs2.3.0.36.9-pre3/arch/h8300/Kconfig
199 --- linux-2.6.29/arch/h8300/Kconfig     2009-03-24 14:18:24.000000000 +0100
200 +++ linux-2.6.29-vs2.3.0.36.9-pre3/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/arch/ia64/ia32/ia32_entry.S linux-2.6.29-vs2.3.0.36.9-pre3/arch/ia64/ia32/ia32_entry.S
211 --- linux-2.6.29/arch/ia64/ia32/ia32_entry.S    2009-03-24 14:18:24.000000000 +0100
212 +++ linux-2.6.29-vs2.3.0.36.9-pre3/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/arch/ia64/Kconfig linux-2.6.29-vs2.3.0.36.9-pre3/arch/ia64/Kconfig
223 --- linux-2.6.29/arch/ia64/Kconfig      2009-03-24 14:18:24.000000000 +0100
224 +++ linux-2.6.29-vs2.3.0.36.9-pre3/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/arch/ia64/kernel/entry.S linux-2.6.29-vs2.3.0.36.9-pre3/arch/ia64/kernel/entry.S
235 --- linux-2.6.29/arch/ia64/kernel/entry.S       2009-03-24 14:18:25.000000000 +0100
236 +++ linux-2.6.29-vs2.3.0.36.9-pre3/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/arch/ia64/kernel/perfmon.c linux-2.6.29-vs2.3.0.36.9-pre3/arch/ia64/kernel/perfmon.c
247 --- linux-2.6.29/arch/ia64/kernel/perfmon.c     2009-03-24 14:18:25.000000000 +0100
248 +++ linux-2.6.29-vs2.3.0.36.9-pre3/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/arch/ia64/kernel/process.c linux-2.6.29-vs2.3.0.36.9-pre3/arch/ia64/kernel/process.c
267 --- linux-2.6.29/arch/ia64/kernel/process.c     2008-12-25 00:26:37.000000000 +0100
268 +++ linux-2.6.29-vs2.3.0.36.9-pre3/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/arch/ia64/kernel/ptrace.c linux-2.6.29-vs2.3.0.36.9-pre3/arch/ia64/kernel/ptrace.c
281 --- linux-2.6.29/arch/ia64/kernel/ptrace.c      2008-12-25 00:26:37.000000000 +0100
282 +++ linux-2.6.29-vs2.3.0.36.9-pre3/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/arch/ia64/kernel/traps.c linux-2.6.29-vs2.3.0.36.9-pre3/arch/ia64/kernel/traps.c
292 --- linux-2.6.29/arch/ia64/kernel/traps.c       2008-12-25 00:26:37.000000000 +0100
293 +++ linux-2.6.29-vs2.3.0.36.9-pre3/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/arch/ia64/mm/fault.c linux-2.6.29-vs2.3.0.36.9-pre3/arch/ia64/mm/fault.c
319 --- linux-2.6.29/arch/ia64/mm/fault.c   2008-12-25 00:26:37.000000000 +0100
320 +++ linux-2.6.29-vs2.3.0.36.9-pre3/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/arch/m32r/kernel/traps.c linux-2.6.29-vs2.3.0.36.9-pre3/arch/m32r/kernel/traps.c
330 --- linux-2.6.29/arch/m32r/kernel/traps.c       2008-12-25 00:26:37.000000000 +0100
331 +++ linux-2.6.29-vs2.3.0.36.9-pre3/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/arch/m68k/Kconfig linux-2.6.29-vs2.3.0.36.9-pre3/arch/m68k/Kconfig
345 --- linux-2.6.29/arch/m68k/Kconfig      2009-03-24 14:18:26.000000000 +0100
346 +++ linux-2.6.29-vs2.3.0.36.9-pre3/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/arch/m68k/kernel/ptrace.c linux-2.6.29-vs2.3.0.36.9-pre3/arch/m68k/kernel/ptrace.c
357 --- linux-2.6.29/arch/m68k/kernel/ptrace.c      2008-12-25 00:26:37.000000000 +0100
358 +++ linux-2.6.29-vs2.3.0.36.9-pre3/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/arch/m68k/kernel/traps.c linux-2.6.29-vs2.3.0.36.9-pre3/arch/m68k/kernel/traps.c
377 --- linux-2.6.29/arch/m68k/kernel/traps.c       2009-03-24 14:18:26.000000000 +0100
378 +++ linux-2.6.29-vs2.3.0.36.9-pre3/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/arch/m68knommu/Kconfig linux-2.6.29-vs2.3.0.36.9-pre3/arch/m68knommu/Kconfig
391 --- linux-2.6.29/arch/m68knommu/Kconfig 2009-03-24 14:18:27.000000000 +0100
392 +++ linux-2.6.29-vs2.3.0.36.9-pre3/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/arch/m68knommu/kernel/traps.c linux-2.6.29-vs2.3.0.36.9-pre3/arch/m68knommu/kernel/traps.c
403 --- linux-2.6.29/arch/m68knommu/kernel/traps.c  2008-12-25 00:26:37.000000000 +0100
404 +++ linux-2.6.29-vs2.3.0.36.9-pre3/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/arch/mips/Kconfig linux-2.6.29-vs2.3.0.36.9-pre3/arch/mips/Kconfig
418 --- linux-2.6.29/arch/mips/Kconfig      2009-03-24 14:18:29.000000000 +0100
419 +++ linux-2.6.29-vs2.3.0.36.9-pre3/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/arch/mips/kernel/ptrace.c linux-2.6.29-vs2.3.0.36.9-pre3/arch/mips/kernel/ptrace.c
430 --- linux-2.6.29/arch/mips/kernel/ptrace.c      2008-12-25 00:26:37.000000000 +0100
431 +++ linux-2.6.29-vs2.3.0.36.9-pre3/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/arch/mips/kernel/scall32-o32.S linux-2.6.29-vs2.3.0.36.9-pre3/arch/mips/kernel/scall32-o32.S
451 --- linux-2.6.29/arch/mips/kernel/scall32-o32.S 2009-03-24 14:18:31.000000000 +0100
452 +++ linux-2.6.29-vs2.3.0.36.9-pre3/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/arch/mips/kernel/scall64-64.S linux-2.6.29-vs2.3.0.36.9-pre3/arch/mips/kernel/scall64-64.S
463 --- linux-2.6.29/arch/mips/kernel/scall64-64.S  2009-03-24 14:18:31.000000000 +0100
464 +++ linux-2.6.29-vs2.3.0.36.9-pre3/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/arch/mips/kernel/scall64-n32.S linux-2.6.29-vs2.3.0.36.9-pre3/arch/mips/kernel/scall64-n32.S
475 --- linux-2.6.29/arch/mips/kernel/scall64-n32.S 2009-03-24 14:18:31.000000000 +0100
476 +++ linux-2.6.29-vs2.3.0.36.9-pre3/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/arch/mips/kernel/scall64-o32.S linux-2.6.29-vs2.3.0.36.9-pre3/arch/mips/kernel/scall64-o32.S
487 --- linux-2.6.29/arch/mips/kernel/scall64-o32.S 2009-03-24 14:18:31.000000000 +0100
488 +++ linux-2.6.29-vs2.3.0.36.9-pre3/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/arch/mips/kernel/traps.c linux-2.6.29-vs2.3.0.36.9-pre3/arch/mips/kernel/traps.c
499 --- linux-2.6.29/arch/mips/kernel/traps.c       2009-03-24 14:18:31.000000000 +0100
500 +++ linux-2.6.29-vs2.3.0.36.9-pre3/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/arch/parisc/Kconfig linux-2.6.29-vs2.3.0.36.9-pre3/arch/parisc/Kconfig
516 --- linux-2.6.29/arch/parisc/Kconfig    2009-03-24 14:18:32.000000000 +0100
517 +++ linux-2.6.29-vs2.3.0.36.9-pre3/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/arch/parisc/kernel/syscall_table.S linux-2.6.29-vs2.3.0.36.9-pre3/arch/parisc/kernel/syscall_table.S
528 --- linux-2.6.29/arch/parisc/kernel/syscall_table.S     2008-12-25 00:26:37.000000000 +0100
529 +++ linux-2.6.29-vs2.3.0.36.9-pre3/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/arch/parisc/kernel/traps.c linux-2.6.29-vs2.3.0.36.9-pre3/arch/parisc/kernel/traps.c
540 --- linux-2.6.29/arch/parisc/kernel/traps.c     2009-03-24 14:18:32.000000000 +0100
541 +++ linux-2.6.29-vs2.3.0.36.9-pre3/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/arch/parisc/mm/fault.c linux-2.6.29-vs2.3.0.36.9-pre3/arch/parisc/mm/fault.c
566 --- linux-2.6.29/arch/parisc/mm/fault.c 2009-03-24 14:18:33.000000000 +0100
567 +++ linux-2.6.29-vs2.3.0.36.9-pre3/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/arch/powerpc/Kconfig linux-2.6.29-vs2.3.0.36.9-pre3/arch/powerpc/Kconfig
591 --- linux-2.6.29/arch/powerpc/Kconfig   2009-03-24 14:18:33.000000000 +0100
592 +++ linux-2.6.29-vs2.3.0.36.9-pre3/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/arch/powerpc/kernel/irq.c linux-2.6.29-vs2.3.0.36.9-pre3/arch/powerpc/kernel/irq.c
603 --- linux-2.6.29/arch/powerpc/kernel/irq.c      2009-03-24 14:18:35.000000000 +0100
604 +++ linux-2.6.29-vs2.3.0.36.9-pre3/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/arch/powerpc/kernel/process.c linux-2.6.29-vs2.3.0.36.9-pre3/arch/powerpc/kernel/process.c
614 --- linux-2.6.29/arch/powerpc/kernel/process.c  2009-03-24 14:18:35.000000000 +0100
615 +++ linux-2.6.29-vs2.3.0.36.9-pre3/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/arch/powerpc/kernel/traps.c linux-2.6.29-vs2.3.0.36.9-pre3/arch/powerpc/kernel/traps.c
629 --- linux-2.6.29/arch/powerpc/kernel/traps.c    2009-03-24 14:18:35.000000000 +0100
630 +++ linux-2.6.29-vs2.3.0.36.9-pre3/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/arch/powerpc/kernel/vdso.c linux-2.6.29-vs2.3.0.36.9-pre3/arch/powerpc/kernel/vdso.c
644 --- linux-2.6.29/arch/powerpc/kernel/vdso.c     2009-03-24 14:18:35.000000000 +0100
645 +++ linux-2.6.29-vs2.3.0.36.9-pre3/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/arch/powerpc/mm/fault.c linux-2.6.29-vs2.3.0.36.9-pre3/arch/powerpc/mm/fault.c
655 --- linux-2.6.29/arch/powerpc/mm/fault.c        2009-03-24 14:18:36.000000000 +0100
656 +++ linux-2.6.29-vs2.3.0.36.9-pre3/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/arch/s390/Kconfig linux-2.6.29-vs2.3.0.36.9-pre3/arch/s390/Kconfig
668 --- linux-2.6.29/arch/s390/Kconfig      2009-03-24 14:18:38.000000000 +0100
669 +++ linux-2.6.29-vs2.3.0.36.9-pre3/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/arch/s390/kernel/ptrace.c linux-2.6.29-vs2.3.0.36.9-pre3/arch/s390/kernel/ptrace.c
680 --- linux-2.6.29/arch/s390/kernel/ptrace.c      2009-03-24 14:18:40.000000000 +0100
681 +++ linux-2.6.29-vs2.3.0.36.9-pre3/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/arch/s390/kernel/syscalls.S linux-2.6.29-vs2.3.0.36.9-pre3/arch/s390/kernel/syscalls.S
691 --- linux-2.6.29/arch/s390/kernel/syscalls.S    2009-03-24 14:18:40.000000000 +0100
692 +++ linux-2.6.29-vs2.3.0.36.9-pre3/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/arch/s390/mm/fault.c linux-2.6.29-vs2.3.0.36.9-pre3/arch/s390/mm/fault.c
703 --- linux-2.6.29/arch/s390/mm/fault.c   2008-12-25 00:26:37.000000000 +0100
704 +++ linux-2.6.29-vs2.3.0.36.9-pre3/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/arch/sh/Kconfig linux-2.6.29-vs2.3.0.36.9-pre3/arch/sh/Kconfig
716 --- linux-2.6.29/arch/sh/Kconfig        2009-03-24 14:18:40.000000000 +0100
717 +++ linux-2.6.29-vs2.3.0.36.9-pre3/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/arch/sh/kernel/irq.c linux-2.6.29-vs2.3.0.36.9-pre3/arch/sh/kernel/irq.c
728 --- linux-2.6.29/arch/sh/kernel/irq.c   2008-12-25 00:26:37.000000000 +0100
729 +++ linux-2.6.29-vs2.3.0.36.9-pre3/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/arch/sh/kernel/vsyscall/vsyscall.c linux-2.6.29-vs2.3.0.36.9-pre3/arch/sh/kernel/vsyscall/vsyscall.c
739 --- linux-2.6.29/arch/sh/kernel/vsyscall/vsyscall.c     2009-03-24 14:18:42.000000000 +0100
740 +++ linux-2.6.29-vs2.3.0.36.9-pre3/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/arch/sparc/Kconfig linux-2.6.29-vs2.3.0.36.9-pre3/arch/sparc/Kconfig
750 --- linux-2.6.29/arch/sparc/Kconfig     2009-03-24 14:18:43.000000000 +0100
751 +++ linux-2.6.29-vs2.3.0.36.9-pre3/arch/sparc/Kconfig   2009-03-24 14:48:22.000000000 +0100
752 @@ -522,6 +522,8 @@ source "fs/Kconfig"
753  
754  source "arch/sparc/Kconfig.debug"
755  
756 +source "kernel/vserver/Kconfig"
757 +
758  source "security/Kconfig"
759  
760  source "crypto/Kconfig"
761 diff -NurpP --minimal linux-2.6.29/arch/x86/ia32/ia32entry.S linux-2.6.29-vs2.3.0.36.9-pre3/arch/x86/ia32/ia32entry.S
762 --- linux-2.6.29/arch/x86/ia32/ia32entry.S      2009-03-24 14:18:48.000000000 +0100
763 +++ linux-2.6.29-vs2.3.0.36.9-pre3/arch/x86/ia32/ia32entry.S    2009-03-22 23:29:11.000000000 +0100
764 @@ -768,7 +768,7 @@ ia32_sys_call_table:
765         .quad sys_tgkill                /* 270 */
766         .quad compat_sys_utimes
767         .quad sys32_fadvise64_64
768 -       .quad quiet_ni_syscall  /* sys_vserver */
769 +       .quad sys32_vserver
770         .quad sys_mbind
771         .quad compat_sys_get_mempolicy  /* 275 */
772         .quad sys_set_mempolicy
773 diff -NurpP --minimal linux-2.6.29/arch/x86/include/asm/unistd_64.h linux-2.6.29-vs2.3.0.36.9-pre3/arch/x86/include/asm/unistd_64.h
774 --- linux-2.6.29/arch/x86/include/asm/unistd_64.h       2008-12-25 00:26:37.000000000 +0100
775 +++ linux-2.6.29-vs2.3.0.36.9-pre3/arch/x86/include/asm/unistd_64.h     2009-02-22 22:54:24.000000000 +0100
776 @@ -535,7 +535,7 @@ __SYSCALL(__NR_tgkill, sys_tgkill)
777  #define __NR_utimes                            235
778  __SYSCALL(__NR_utimes, sys_utimes)
779  #define __NR_vserver                           236
780 -__SYSCALL(__NR_vserver, sys_ni_syscall)
781 +__SYSCALL(__NR_vserver, sys_vserver)
782  #define __NR_mbind                             237
783  __SYSCALL(__NR_mbind, sys_mbind)
784  #define __NR_set_mempolicy                     238
785 diff -NurpP --minimal linux-2.6.29/arch/x86/Kconfig linux-2.6.29-vs2.3.0.36.9-pre3/arch/x86/Kconfig
786 --- linux-2.6.29/arch/x86/Kconfig       2009-03-24 14:18:47.000000000 +0100
787 +++ linux-2.6.29-vs2.3.0.36.9-pre3/arch/x86/Kconfig     2009-03-24 14:48:23.000000000 +0100
788 @@ -1990,6 +1990,8 @@ source "fs/Kconfig"
789  
790  source "arch/x86/Kconfig.debug"
791  
792 +source "kernel/vserver/Kconfig"
793 +
794  source "security/Kconfig"
795  
796  source "crypto/Kconfig"
797 diff -NurpP --minimal linux-2.6.29/arch/x86/kernel/syscall_table_32.S linux-2.6.29-vs2.3.0.36.9-pre3/arch/x86/kernel/syscall_table_32.S
798 --- linux-2.6.29/arch/x86/kernel/syscall_table_32.S     2009-03-24 14:18:51.000000000 +0100
799 +++ linux-2.6.29-vs2.3.0.36.9-pre3/arch/x86/kernel/syscall_table_32.S   2009-02-22 22:54:24.000000000 +0100
800 @@ -272,7 +272,7 @@ ENTRY(sys_call_table)
801         .long sys_tgkill        /* 270 */
802         .long sys_utimes
803         .long sys_fadvise64_64
804 -       .long sys_ni_syscall    /* sys_vserver */
805 +       .long sys_vserver
806         .long sys_mbind
807         .long sys_get_mempolicy
808         .long sys_set_mempolicy
809 diff -NurpP --minimal linux-2.6.29/Documentation/vserver/debug.txt linux-2.6.29-vs2.3.0.36.9-pre3/Documentation/vserver/debug.txt
810 --- linux-2.6.29/Documentation/vserver/debug.txt        1970-01-01 01:00:00.000000000 +0100
811 +++ linux-2.6.29-vs2.3.0.36.9-pre3/Documentation/vserver/debug.txt      2009-02-22 22:54:24.000000000 +0100
812 @@ -0,0 +1,154 @@
813 +
814 +debug_cvirt:
815 +
816 + 2   4 "vx_map_tgid: %p/%llx: %d -> %d"
817 +       "vx_rmap_tgid: %p/%llx: %d -> %d"
818 +
819 +debug_dlim:
820 +
821 + 0   1 "ALLOC (%p,#%d)%c inode (%d)"
822 +       "FREE  (%p,#%d)%c inode"
823 + 1   2 "ALLOC (%p,#%d)%c %lld bytes (%d)"
824 +       "FREE  (%p,#%d)%c %lld bytes"
825 + 2   4 "ADJUST: %lld,%lld on %ld,%ld [mult=%d]"
826 + 3   8 "ext3_has_free_blocks(%p): %lu<%lu+1, %c, %u!=%u r=%d"
827 +       "ext3_has_free_blocks(%p): free=%lu, root=%lu"
828 +       "rcu_free_dl_info(%p)"
829 + 4  10 "alloc_dl_info(%p,%d) = %p"
830 +       "dealloc_dl_info(%p)"
831 +       "get_dl_info(%p[#%d.%d])"
832 +       "put_dl_info(%p[#%d.%d])"
833 + 5  20 "alloc_dl_info(%p,%d)*"
834 + 6  40 "__hash_dl_info: %p[#%d]"
835 +       "__unhash_dl_info: %p[#%d]"
836 + 7  80 "locate_dl_info(%p,#%d) = %p"
837 +
838 +debug_misc:
839 +
840 + 0   1 "destroy_dqhash: %p [#0x%08x] c=%d"
841 +       "new_dqhash: %p [#0x%08x]"
842 +       "vroot[%d]_clr_dev: dev=%p[%lu,%d:%d]"
843 +       "vroot[%d]_get_real_bdev: dev=%p[%lu,%d:%d]"
844 +       "vroot[%d]_set_dev: dev=%p[%lu,%d:%d]"
845 +       "vroot_get_real_bdev not set"
846 + 1   2 "cow_break_link(»%s«)"
847 +       "temp copy Â»%s«"
848 + 2   4 "dentry_open(new): %p"
849 +       "dentry_open(old): %p"
850 +       "lookup_create(new): %p"
851 +       "old path Â»%s«"
852 +       "path_lookup(old): %d"
853 +       "vfs_create(new): %d"
854 +       "vfs_rename: %d"
855 +       "vfs_sendfile: %d"
856 + 3   8 "fput(new_file=%p[#%d])"
857 +       "fput(old_file=%p[#%d])"
858 + 4  10 "vx_info_kill(%p[#%d],%d,%d) = %d"
859 +       "vx_info_kill(%p[#%d],%d,%d)*"
860 + 5  20 "vs_reboot(%p[#%d],%d)"
861 + 6  40 "dropping task %p[#%u,%u] for %p[#%u,%u]"
862 +
863 +debug_net:
864 +
865 + 2   4 "nx_addr_conflict(%p,%p) %d.%d,%d.%d"
866 + 3   8 "inet_bind(%p) %d.%d.%d.%d, %d.%d.%d.%d, %d.%d.%d.%d"
867 +       "inet_bind(%p)* %p,%p;%lx %d.%d.%d.%d"
868 + 4  10 "ip_route_connect(%p) %p,%p;%lx"
869 + 5  20 "__addr_in_socket(%p,%d.%d.%d.%d) %p:%d.%d.%d.%d %p;%lx"
870 + 6  40 "sk,egf: %p [#%d] (from %d)"
871 +       "sk,egn: %p [#%d] (from %d)"
872 +       "sk,req: %p [#%d] (from %d)"
873 +       "sk: %p [#%d] (from %d)"
874 +       "tw: %p [#%d] (from %d)"
875 + 7  80 "__sock_recvmsg: %p[%p,%p,%p;%d]:%d/%d"
876 +       "__sock_sendmsg: %p[%p,%p,%p;%d]:%d/%d"
877 +
878 +debug_nid:
879 +
880 + 0   1 "__lookup_nx_info(#%u): %p[#%u]"
881 +       "alloc_nx_info(%d) = %p"
882 +       "create_nx_info(%d) (dynamic rejected)"
883 +       "create_nx_info(%d) = %p (already there)"
884 +       "create_nx_info(%d) = %p (new)"
885 +       "dealloc_nx_info(%p)"
886 + 1   2 "alloc_nx_info(%d)*"
887 +       "create_nx_info(%d)*"
888 + 2   4 "get_nx_info(%p[#%d.%d])"
889 +       "put_nx_info(%p[#%d.%d])"
890 + 3   8 "claim_nx_info(%p[#%d.%d.%d]) %p"
891 +       "clr_nx_info(%p[#%d.%d])"
892 +       "init_nx_info(%p[#%d.%d])"
893 +       "release_nx_info(%p[#%d.%d.%d]) %p"
894 +       "set_nx_info(%p[#%d.%d])"
895 + 4  10 "__hash_nx_info: %p[#%d]"
896 +       "__nx_dynamic_id: [#%d]"
897 +       "__unhash_nx_info: %p[#%d.%d.%d]"
898 + 5  20 "moved task %p into nxi:%p[#%d]"
899 +       "nx_migrate_task(%p,%p[#%d.%d.%d])"
900 +       "task_get_nx_info(%p)"
901 + 6  40 "nx_clear_persistent(%p[#%d])"
902 +
903 +debug_quota:
904 +
905 + 0   1 "quota_sync_dqh(%p,%d) discard inode %p"
906 + 1   2 "quota_sync_dqh(%p,%d)"
907 +       "sync_dquots(%p,%d)"
908 +       "sync_dquots_dqh(%p,%d)"
909 + 3   8 "do_quotactl(%p,%d,cmd=%d,id=%d,%p)"
910 +
911 +debug_switch:
912 +
913 + 0   1 "vc: VCMD_%02d_%d[%d], %d,%p [%d,%d,%x,%x]"
914 + 1   2 "vc: VCMD_%02d_%d[%d] = %08lx(%ld) [%d,%d]"
915 + 4  10 "%s: (%s %s) returned %s with %d"
916 +
917 +debug_tag:
918 +
919 + 7  80 "dx_parse_tag(»%s«): %d:#%d"
920 +       "dx_propagate_tag(%p[#%lu.%d]): %d,%d"
921 +
922 +debug_xid:
923 +
924 + 0   1 "__lookup_vx_info(#%u): %p[#%u]"
925 +       "alloc_vx_info(%d) = %p"
926 +       "alloc_vx_info(%d)*"
927 +       "create_vx_info(%d) (dynamic rejected)"
928 +       "create_vx_info(%d) = %p (already there)"
929 +       "create_vx_info(%d) = %p (new)"
930 +       "dealloc_vx_info(%p)"
931 +       "loc_vx_info(%d) = %p (found)"
932 +       "loc_vx_info(%d) = %p (new)"
933 +       "loc_vx_info(%d) = %p (not available)"
934 + 1   2 "create_vx_info(%d)*"
935 +       "loc_vx_info(%d)*"
936 + 2   4 "get_vx_info(%p[#%d.%d])"
937 +       "put_vx_info(%p[#%d.%d])"
938 + 3   8 "claim_vx_info(%p[#%d.%d.%d]) %p"
939 +       "clr_vx_info(%p[#%d.%d])"
940 +       "init_vx_info(%p[#%d.%d])"
941 +       "release_vx_info(%p[#%d.%d.%d]) %p"
942 +       "set_vx_info(%p[#%d.%d])"
943 + 4  10 "__hash_vx_info: %p[#%d]"
944 +       "__unhash_vx_info: %p[#%d.%d.%d]"
945 +       "__vx_dynamic_id: [#%d]"
946 + 5  20 "enter_vx_info(%p[#%d],%p) %p[#%d,%p]"
947 +       "leave_vx_info(%p[#%d,%p]) %p[#%d,%p]"
948 +       "moved task %p into vxi:%p[#%d]"
949 +       "task_get_vx_info(%p)"
950 +       "vx_migrate_task(%p,%p[#%d.%d])"
951 + 6  40 "vx_clear_persistent(%p[#%d])"
952 +       "vx_exit_init(%p[#%d],%p[#%d,%d,%d])"
953 +       "vx_set_init(%p[#%d],%p[#%d,%d,%d])"
954 +       "vx_set_persistent(%p[#%d])"
955 +       "vx_set_reaper(%p[#%d],%p[#%d,%d])"
956 + 7  80 "vx_child_reaper(%p[#%u,%u]) = %p[#%u,%u]"
957 +
958 +
959 +debug_limit:
960 +
961 + n 2^n "vx_acc_cres[%5d,%s,%2d]: %5d%s"
962 +       "vx_cres_avail[%5d,%s,%2d]: %5ld > %5d + %5d"
963 +
964 + m 2^m "vx_acc_page[%5d,%s,%2d]: %5d%s"
965 +       "vx_acc_pages[%5d,%s,%2d]: %5d += %5d"
966 +       "vx_pages_avail[%5d,%s,%2d]: %5ld > %5d + %5d"
967 diff -NurpP --minimal linux-2.6.29/drivers/block/Kconfig linux-2.6.29-vs2.3.0.36.9-pre3/drivers/block/Kconfig
968 --- linux-2.6.29/drivers/block/Kconfig  2008-12-25 00:26:37.000000000 +0100
969 +++ linux-2.6.29-vs2.3.0.36.9-pre3/drivers/block/Kconfig        2009-02-22 22:54:24.000000000 +0100
970 @@ -264,6 +264,13 @@ config BLK_DEV_CRYPTOLOOP
971           instead, which can be configured to be on-disk compatible with the
972           cryptoloop device.
973  
974 +config BLK_DEV_VROOT
975 +       tristate "Virtual Root device support"
976 +       depends on QUOTACTL
977 +       ---help---
978 +         Saying Y here will allow you to use quota/fs ioctls on a shared
979 +         partition within a virtual server without compromising security.
980 +
981  config BLK_DEV_NBD
982         tristate "Network block device support"
983         depends on NET
984 diff -NurpP --minimal linux-2.6.29/drivers/block/loop.c linux-2.6.29-vs2.3.0.36.9-pre3/drivers/block/loop.c
985 --- linux-2.6.29/drivers/block/loop.c   2009-03-24 14:18:56.000000000 +0100
986 +++ linux-2.6.29-vs2.3.0.36.9-pre3/drivers/block/loop.c 2009-03-24 15:09:29.000000000 +0100
987 @@ -75,6 +75,7 @@
988  #include <linux/gfp.h>
989  #include <linux/kthread.h>
990  #include <linux/splice.h>
991 +#include <linux/vs_context.h>
992  
993  #include <asm/uaccess.h>
994  
995 @@ -809,6 +810,7 @@ static int loop_set_fd(struct loop_devic
996         lo->lo_blocksize = lo_blocksize;
997         lo->lo_device = bdev;
998         lo->lo_flags = lo_flags;
999 +       lo->lo_xid = vx_current_xid();
1000         lo->lo_backing_file = file;
1001         lo->transfer = transfer_none;
1002         lo->ioctl = NULL;
1003 @@ -931,6 +933,7 @@ static int loop_clr_fd(struct loop_devic
1004         lo->lo_encrypt_key_size = 0;
1005         lo->lo_flags = 0;
1006         lo->lo_thread = NULL;
1007 +       lo->lo_xid = 0;
1008         memset(lo->lo_encrypt_key, 0, LO_KEY_SIZE);
1009         memset(lo->lo_crypt_name, 0, LO_NAME_SIZE);
1010         memset(lo->lo_file_name, 0, LO_NAME_SIZE);
1011 @@ -958,7 +961,7 @@ loop_set_status(struct loop_device *lo, 
1012  
1013         if (lo->lo_encrypt_key_size &&
1014             lo->lo_key_owner != uid &&
1015 -           !capable(CAP_SYS_ADMIN))
1016 +           !vx_capable(CAP_SYS_ADMIN, VXC_ADMIN_CLOOP))
1017                 return -EPERM;
1018         if (lo->lo_state != Lo_bound)
1019                 return -ENXIO;
1020 @@ -1042,7 +1045,8 @@ loop_get_status(struct loop_device *lo, 
1021         memcpy(info->lo_crypt_name, lo->lo_crypt_name, LO_NAME_SIZE);
1022         info->lo_encrypt_type =
1023                 lo->lo_encryption ? lo->lo_encryption->number : 0;
1024 -       if (lo->lo_encrypt_key_size && capable(CAP_SYS_ADMIN)) {
1025 +       if (lo->lo_encrypt_key_size &&
1026 +               vx_capable(CAP_SYS_ADMIN, VXC_ADMIN_CLOOP)) {
1027                 info->lo_encrypt_key_size = lo->lo_encrypt_key_size;
1028                 memcpy(info->lo_encrypt_key, lo->lo_encrypt_key,
1029                        lo->lo_encrypt_key_size);
1030 @@ -1351,6 +1355,9 @@ static int lo_open(struct block_device *
1031  {
1032         struct loop_device *lo = bdev->bd_disk->private_data;
1033  
1034 +       if (!vx_check(lo->lo_xid, VS_IDENT|VS_HOSTID|VS_ADMIN_P))
1035 +               return -EACCES;
1036 +
1037         mutex_lock(&lo->lo_ctl_mutex);
1038         lo->lo_refcnt++;
1039         mutex_unlock(&lo->lo_ctl_mutex);
1040 diff -NurpP --minimal linux-2.6.29/drivers/block/Makefile linux-2.6.29-vs2.3.0.36.9-pre3/drivers/block/Makefile
1041 --- linux-2.6.29/drivers/block/Makefile 2009-03-24 14:18:55.000000000 +0100
1042 +++ linux-2.6.29-vs2.3.0.36.9-pre3/drivers/block/Makefile       2009-03-24 14:48:25.000000000 +0100
1043 @@ -31,5 +31,6 @@ obj-$(CONFIG_VIODASD)         += viodasd.o
1044  obj-$(CONFIG_BLK_DEV_SX8)      += sx8.o
1045  obj-$(CONFIG_BLK_DEV_UB)       += ub.o
1046  obj-$(CONFIG_BLK_DEV_HD)       += hd.o
1047 +obj-$(CONFIG_BLK_DEV_VROOT)    += vroot.o
1048  
1049  obj-$(CONFIG_XEN_BLKDEV_FRONTEND)      += xen-blkfront.o
1050 diff -NurpP --minimal linux-2.6.29/drivers/block/vroot.c linux-2.6.29-vs2.3.0.36.9-pre3/drivers/block/vroot.c
1051 --- linux-2.6.29/drivers/block/vroot.c  1970-01-01 01:00:00.000000000 +0100
1052 +++ linux-2.6.29-vs2.3.0.36.9-pre3/drivers/block/vroot.c        2009-02-22 22:54:24.000000000 +0100
1053 @@ -0,0 +1,281 @@
1054 +/*
1055 + *  linux/drivers/block/vroot.c
1056 + *
1057 + *  written by Herbert Pötzl, 9/11/2002
1058 + *  ported to 2.6.10 by Herbert Pötzl, 30/12/2004
1059 + *
1060 + *  based on the loop.c code by Theodore Ts'o.
1061 + *
1062 + * Copyright (C) 2002-2007 by Herbert Pötzl.
1063 + * Redistribution of this file is permitted under the
1064 + * GNU General Public License.
1065 + *
1066 + */
1067 +
1068 +#include <linux/module.h>
1069 +#include <linux/moduleparam.h>
1070 +#include <linux/file.h>
1071 +#include <linux/major.h>
1072 +#include <linux/blkdev.h>
1073 +
1074 +#include <linux/vroot.h>
1075 +#include <linux/vs_context.h>
1076 +
1077 +
1078 +static int max_vroot = 8;
1079 +
1080 +static struct vroot_device *vroot_dev;
1081 +static struct gendisk **disks;
1082 +
1083 +
1084 +static int vroot_set_dev(
1085 +       struct vroot_device *vr,
1086 +       struct block_device *bdev,
1087 +       unsigned int arg)
1088 +{
1089 +       struct block_device *real_bdev;
1090 +       struct file *file;
1091 +       struct inode *inode;
1092 +       int error;
1093 +
1094 +       error = -EBUSY;
1095 +       if (vr->vr_state != Vr_unbound)
1096 +               goto out;
1097 +
1098 +       error = -EBADF;
1099 +       file = fget(arg);
1100 +       if (!file)
1101 +               goto out;
1102 +
1103 +       error = -EINVAL;
1104 +       inode = file->f_dentry->d_inode;
1105 +
1106 +
1107 +       if (S_ISBLK(inode->i_mode)) {
1108 +               real_bdev = inode->i_bdev;
1109 +               vr->vr_device = real_bdev;
1110 +               __iget(real_bdev->bd_inode);
1111 +       } else
1112 +               goto out_fput;
1113 +
1114 +       vxdprintk(VXD_CBIT(misc, 0),
1115 +               "vroot[%d]_set_dev: dev=" VXF_DEV,
1116 +               vr->vr_number, VXD_DEV(real_bdev));
1117 +
1118 +       vr->vr_state = Vr_bound;
1119 +       error = 0;
1120 +
1121 + out_fput:
1122 +       fput(file);
1123 + out:
1124 +       return error;
1125 +}
1126 +
1127 +static int vroot_clr_dev(
1128 +       struct vroot_device *vr,
1129 +       struct block_device *bdev)
1130 +{
1131 +       struct block_device *real_bdev;
1132 +
1133 +       if (vr->vr_state != Vr_bound)
1134 +               return -ENXIO;
1135 +       if (vr->vr_refcnt > 1)  /* we needed one fd for the ioctl */
1136 +               return -EBUSY;
1137 +
1138 +       real_bdev = vr->vr_device;
1139 +
1140 +       vxdprintk(VXD_CBIT(misc, 0),
1141 +               "vroot[%d]_clr_dev: dev=" VXF_DEV,
1142 +               vr->vr_number, VXD_DEV(real_bdev));
1143 +
1144 +       bdput(real_bdev);
1145 +       vr->vr_state = Vr_unbound;
1146 +       vr->vr_device = NULL;
1147 +       return 0;
1148 +}
1149 +
1150 +
1151 +static int vr_ioctl(struct block_device *bdev, fmode_t mode,
1152 +       unsigned int cmd, unsigned long arg)
1153 +{
1154 +       struct vroot_device *vr = bdev->bd_disk->private_data;
1155 +       int err;
1156 +
1157 +       down(&vr->vr_ctl_mutex);
1158 +       switch (cmd) {
1159 +       case VROOT_SET_DEV:
1160 +               err = vroot_set_dev(vr, bdev, arg);
1161 +               break;
1162 +       case VROOT_CLR_DEV:
1163 +               err = vroot_clr_dev(vr, bdev);
1164 +               break;
1165 +       default:
1166 +               err = -EINVAL;
1167 +               break;
1168 +       }
1169 +       up(&vr->vr_ctl_mutex);
1170 +       return err;
1171 +}
1172 +
1173 +static int vr_open(struct block_device *bdev, fmode_t mode)
1174 +{
1175 +       struct vroot_device *vr = bdev->bd_disk->private_data;
1176 +
1177 +       down(&vr->vr_ctl_mutex);
1178 +       vr->vr_refcnt++;
1179 +       up(&vr->vr_ctl_mutex);
1180 +       return 0;
1181 +}
1182 +
1183 +static int vr_release(struct gendisk *disk, fmode_t mode)
1184 +{
1185 +       struct vroot_device *vr = disk->private_data;
1186 +
1187 +       down(&vr->vr_ctl_mutex);
1188 +       --vr->vr_refcnt;
1189 +       up(&vr->vr_ctl_mutex);
1190 +       return 0;
1191 +}
1192 +
1193 +static struct block_device_operations vr_fops = {
1194 +       .owner =        THIS_MODULE,
1195 +       .open =         vr_open,
1196 +       .release =      vr_release,
1197 +       .ioctl =        vr_ioctl,
1198 +};
1199 +
1200 +struct block_device *__vroot_get_real_bdev(struct block_device *bdev)
1201 +{
1202 +       struct inode *inode = bdev->bd_inode;
1203 +       struct vroot_device *vr;
1204 +       struct block_device *real_bdev;
1205 +       int minor = iminor(inode);
1206 +
1207 +       vr = &vroot_dev[minor];
1208 +       real_bdev = vr->vr_device;
1209 +
1210 +       vxdprintk(VXD_CBIT(misc, 0),
1211 +               "vroot[%d]_get_real_bdev: dev=" VXF_DEV,
1212 +               vr->vr_number, VXD_DEV(real_bdev));
1213 +
1214 +       if (vr->vr_state != Vr_bound)
1215 +               return ERR_PTR(-ENXIO);
1216 +
1217 +       __iget(real_bdev->bd_inode);
1218 +       return real_bdev;
1219 +}
1220 +
1221 +/*
1222 + * And now the modules code and kernel interface.
1223 + */
1224 +
1225 +module_param(max_vroot, int, 0);
1226 +
1227 +MODULE_PARM_DESC(max_vroot, "Maximum number of vroot devices (1-256)");
1228 +MODULE_LICENSE("GPL");
1229 +MODULE_ALIAS_BLOCKDEV_MAJOR(VROOT_MAJOR);
1230 +
1231 +MODULE_AUTHOR ("Herbert Pötzl");
1232 +MODULE_DESCRIPTION ("Virtual Root Device Mapper");
1233 +
1234 +
1235 +int __init vroot_init(void)
1236 +{
1237 +       int err, i;
1238 +
1239 +       if (max_vroot < 1 || max_vroot > 256) {
1240 +               max_vroot = MAX_VROOT_DEFAULT;
1241 +               printk(KERN_WARNING "vroot: invalid max_vroot "
1242 +                       "(must be between 1 and 256), "
1243 +                       "using default (%d)\n", max_vroot);
1244 +       }
1245 +
1246 +       if (register_blkdev(VROOT_MAJOR, "vroot"))
1247 +               return -EIO;
1248 +
1249 +       err = -ENOMEM;
1250 +       vroot_dev = kmalloc(max_vroot * sizeof(struct vroot_device), GFP_KERNEL);
1251 +       if (!vroot_dev)
1252 +               goto out_mem1;
1253 +       memset(vroot_dev, 0, max_vroot * sizeof(struct vroot_device));
1254 +
1255 +       disks = kmalloc(max_vroot * sizeof(struct gendisk *), GFP_KERNEL);
1256 +       if (!disks)
1257 +               goto out_mem2;
1258 +
1259 +       for (i = 0; i < max_vroot; i++) {
1260 +               disks[i] = alloc_disk(1);
1261 +               if (!disks[i])
1262 +                       goto out_mem3;
1263 +               disks[i]->queue = blk_alloc_queue(GFP_KERNEL);
1264 +               if (!disks[i]->queue)
1265 +                       goto out_mem3;
1266 +       }
1267 +
1268 +       for (i = 0; i < max_vroot; i++) {
1269 +               struct vroot_device *vr = &vroot_dev[i];
1270 +               struct gendisk *disk = disks[i];
1271 +
1272 +               memset(vr, 0, sizeof(*vr));
1273 +               init_MUTEX(&vr->vr_ctl_mutex);
1274 +               vr->vr_number = i;
1275 +               disk->major = VROOT_MAJOR;
1276 +               disk->first_minor = i;
1277 +               disk->fops = &vr_fops;
1278 +               sprintf(disk->disk_name, "vroot%d", i);
1279 +               disk->private_data = vr;
1280 +       }
1281 +
1282 +       err = register_vroot_grb(&__vroot_get_real_bdev);
1283 +       if (err)
1284 +               goto out_mem3;
1285 +
1286 +       for (i = 0; i < max_vroot; i++)
1287 +               add_disk(disks[i]);
1288 +       printk(KERN_INFO "vroot: loaded (max %d devices)\n", max_vroot);
1289 +       return 0;
1290 +
1291 +out_mem3:
1292 +       while (i--)
1293 +               put_disk(disks[i]);
1294 +       kfree(disks);
1295 +out_mem2:
1296 +       kfree(vroot_dev);
1297 +out_mem1:
1298 +       unregister_blkdev(VROOT_MAJOR, "vroot");
1299 +       printk(KERN_ERR "vroot: ran out of memory\n");
1300 +       return err;
1301 +}
1302 +
1303 +void vroot_exit(void)
1304 +{
1305 +       int i;
1306 +
1307 +       if (unregister_vroot_grb(&__vroot_get_real_bdev))
1308 +               printk(KERN_WARNING "vroot: cannot unregister grb\n");
1309 +
1310 +       for (i = 0; i < max_vroot; i++) {
1311 +               del_gendisk(disks[i]);
1312 +               put_disk(disks[i]);
1313 +       }
1314 +       unregister_blkdev(VROOT_MAJOR, "vroot");
1315 +
1316 +       kfree(disks);
1317 +       kfree(vroot_dev);
1318 +}
1319 +
1320 +module_init(vroot_init);
1321 +module_exit(vroot_exit);
1322 +
1323 +#ifndef MODULE
1324 +
1325 +static int __init max_vroot_setup(char *str)
1326 +{
1327 +       max_vroot = simple_strtol(str, NULL, 0);
1328 +       return 1;
1329 +}
1330 +
1331 +__setup("max_vroot=", max_vroot_setup);
1332 +
1333 +#endif
1334 +
1335 diff -NurpP --minimal linux-2.6.29/drivers/char/sysrq.c linux-2.6.29-vs2.3.0.36.9-pre3/drivers/char/sysrq.c
1336 --- linux-2.6.29/drivers/char/sysrq.c   2009-03-24 14:18:57.000000000 +0100
1337 +++ linux-2.6.29-vs2.3.0.36.9-pre3/drivers/char/sysrq.c 2009-03-24 15:15:27.000000000 +0100
1338 @@ -38,6 +38,7 @@
1339  #include <linux/irq.h>
1340  #include <linux/hrtimer.h>
1341  #include <linux/oom.h>
1342 +#include <linux/vserver/debug.h>
1343  
1344  #include <asm/ptrace.h>
1345  #include <asm/irq_regs.h>
1346 @@ -369,6 +370,21 @@ static struct sysrq_key_op sysrq_unrt_op
1347         .enable_mask    = SYSRQ_ENABLE_RTNICE,
1348  };
1349  
1350 +
1351 +#ifdef CONFIG_VSERVER_DEBUG
1352 +static void sysrq_handle_vxinfo(int key, struct tty_struct *tty)
1353 +{
1354 +       dump_vx_info_inactive((key == 'x')?0:1);
1355 +}
1356 +
1357 +static struct sysrq_key_op sysrq_showvxinfo_op = {
1358 +       .handler        = sysrq_handle_vxinfo,
1359 +       .help_msg       = "conteXt",
1360 +       .action_msg     = "Show Context Info",
1361 +       .enable_mask    = SYSRQ_ENABLE_DUMP,
1362 +};
1363 +#endif
1364 +
1365  /* Key Operations table and lock */
1366  static DEFINE_SPINLOCK(sysrq_key_table_lock);
1367  
1368 @@ -419,7 +435,11 @@ static struct sysrq_key_op *sysrq_key_ta
1369         NULL,                           /* v */
1370         &sysrq_showstate_blocked_op,    /* w */
1371         /* x: May be registered on ppc/powerpc for xmon */
1372 +#ifdef CONFIG_VSERVER_DEBUG
1373 +       &sysrq_showvxinfo_op,           /* x */
1374 +#else
1375         NULL,                           /* x */
1376 +#endif
1377         /* y: May be registered on sparc64 for global register dump */
1378         NULL,                           /* y */
1379         &sysrq_ftrace_dump_op,          /* z */
1380 @@ -434,6 +454,8 @@ static int sysrq_key_table_key2index(int
1381                 retval = key - '0';
1382         else if ((key >= 'a') && (key <= 'z'))
1383                 retval = key + 10 - 'a';
1384 +       else if ((key >= 'A') && (key <= 'Z'))
1385 +               retval = key + 10 - 'A';
1386         else
1387                 retval = -1;
1388         return retval;
1389 diff -NurpP --minimal linux-2.6.29/drivers/char/tty_io.c linux-2.6.29-vs2.3.0.36.9-pre3/drivers/char/tty_io.c
1390 --- linux-2.6.29/drivers/char/tty_io.c  2009-03-24 14:18:57.000000000 +0100
1391 +++ linux-2.6.29-vs2.3.0.36.9-pre3/drivers/char/tty_io.c        2009-03-24 14:48:25.000000000 +0100
1392 @@ -106,6 +106,7 @@
1393  
1394  #include <linux/kmod.h>
1395  #include <linux/nsproxy.h>
1396 +#include <linux/vs_pid.h>
1397  
1398  #undef TTY_DEBUG_HANGUP
1399  
1400 @@ -2303,6 +2304,7 @@ static int tiocspgrp(struct tty_struct *
1401                 return -ENOTTY;
1402         if (get_user(pgrp_nr, p))
1403                 return -EFAULT;
1404 +       pgrp_nr = vx_rmap_pid(pgrp_nr);
1405         if (pgrp_nr < 0)
1406                 return -EINVAL;
1407         rcu_read_lock();
1408 diff -NurpP --minimal linux-2.6.29/drivers/infiniband/hw/ipath/ipath_user_pages.c linux-2.6.29-vs2.3.0.36.9-pre3/drivers/infiniband/hw/ipath/ipath_user_pages.c
1409 --- linux-2.6.29/drivers/infiniband/hw/ipath/ipath_user_pages.c 2008-12-25 00:26:37.000000000 +0100
1410 +++ linux-2.6.29-vs2.3.0.36.9-pre3/drivers/infiniband/hw/ipath/ipath_user_pages.c       2009-02-22 22:54:24.000000000 +0100
1411 @@ -33,6 +33,7 @@
1412  
1413  #include <linux/mm.h>
1414  #include <linux/device.h>
1415 +#include <linux/vs_memory.h>
1416  
1417  #include "ipath_kernel.h"
1418  
1419 @@ -61,7 +62,8 @@ static int __get_user_pages(unsigned lon
1420         lock_limit = current->signal->rlim[RLIMIT_MEMLOCK].rlim_cur >>
1421                 PAGE_SHIFT;
1422  
1423 -       if (num_pages > lock_limit) {
1424 +       if (num_pages > lock_limit ||
1425 +               !vx_vmlocked_avail(current->mm, num_pages)) {
1426                 ret = -ENOMEM;
1427                 goto bail;
1428         }
1429 @@ -78,7 +80,7 @@ static int __get_user_pages(unsigned lon
1430                         goto bail_release;
1431         }
1432  
1433 -       current->mm->locked_vm += num_pages;
1434 +       vx_vmlocked_add(current->mm, num_pages);
1435  
1436         ret = 0;
1437         goto bail;
1438 @@ -177,7 +179,7 @@ void ipath_release_user_pages(struct pag
1439  
1440         __ipath_release_user_pages(p, num_pages, 1);
1441  
1442 -       current->mm->locked_vm -= num_pages;
1443 +       vx_vmlocked_sub(current->mm, num_pages);
1444  
1445         up_write(&current->mm->mmap_sem);
1446  }
1447 @@ -194,7 +196,7 @@ static void user_pages_account(struct wo
1448                 container_of(_work, struct ipath_user_pages_work, work);
1449  
1450         down_write(&work->mm->mmap_sem);
1451 -       work->mm->locked_vm -= work->num_pages;
1452 +       vx_vmlocked_sub(work->mm, work->num_pages);
1453         up_write(&work->mm->mmap_sem);
1454         mmput(work->mm);
1455         kfree(work);
1456 diff -NurpP --minimal linux-2.6.29/drivers/md/dm.c linux-2.6.29-vs2.3.0.36.9-pre3/drivers/md/dm.c
1457 --- linux-2.6.29/drivers/md/dm.c        2009-03-24 14:19:05.000000000 +0100
1458 +++ linux-2.6.29-vs2.3.0.36.9-pre3/drivers/md/dm.c      2009-03-24 15:15:57.000000000 +0100
1459 @@ -22,6 +22,7 @@
1460  #include <linux/hdreg.h>
1461  #include <linux/blktrace_api.h>
1462  #include <trace/block.h>
1463 +#include <linux/vs_base.h>
1464  
1465  #define DM_MSG_PREFIX "core"
1466  
1467 @@ -115,6 +116,7 @@ struct mapped_device {
1468         rwlock_t map_lock;
1469         atomic_t holders;
1470         atomic_t open_count;
1471 +       xid_t xid;
1472  
1473         unsigned long flags;
1474  
1475 @@ -295,6 +297,7 @@ static void __exit dm_exit(void)
1476  static int dm_blk_open(struct block_device *bdev, fmode_t mode)
1477  {
1478         struct mapped_device *md;
1479 +       int ret = -ENXIO;
1480  
1481         spin_lock(&_minor_lock);
1482  
1483 @@ -303,18 +306,19 @@ static int dm_blk_open(struct block_devi
1484                 goto out;
1485  
1486         if (test_bit(DMF_FREEING, &md->flags) ||
1487 -           test_bit(DMF_DELETING, &md->flags)) {
1488 -               md = NULL;
1489 +           test_bit(DMF_DELETING, &md->flags))
1490 +               goto out;
1491 +
1492 +       ret = -EACCES;
1493 +       if (!vx_check(md->xid, VS_IDENT|VS_HOSTID))
1494                 goto out;
1495 -       }
1496  
1497         dm_get(md);
1498         atomic_inc(&md->open_count);
1499 -
1500 +       ret = 0;
1501  out:
1502         spin_unlock(&_minor_lock);
1503 -
1504 -       return md ? 0 : -ENXIO;
1505 +       return ret;
1506  }
1507  
1508  static int dm_blk_close(struct gendisk *disk, fmode_t mode)
1509 @@ -504,6 +508,14 @@ int dm_set_geometry(struct mapped_device
1510         return 0;
1511  }
1512  
1513 +/*
1514 + * Get the xid associated with a dm device
1515 + */
1516 +xid_t dm_get_xid(struct mapped_device *md)
1517 +{
1518 +       return md->xid;
1519 +}
1520 +
1521  /*-----------------------------------------------------------------
1522   * CRUD START:
1523   *   A more elegant soln is in the works that uses the queue
1524 @@ -1110,6 +1122,7 @@ static struct mapped_device *alloc_dev(i
1525         INIT_LIST_HEAD(&md->uevent_list);
1526         spin_lock_init(&md->uevent_lock);
1527  
1528 +       md->xid = vx_current_xid();
1529         md->queue = blk_alloc_queue(GFP_KERNEL);
1530         if (!md->queue)
1531                 goto bad_queue;
1532 diff -NurpP --minimal linux-2.6.29/drivers/md/dm.h linux-2.6.29-vs2.3.0.36.9-pre3/drivers/md/dm.h
1533 --- linux-2.6.29/drivers/md/dm.h        2009-03-24 14:19:05.000000000 +0100
1534 +++ linux-2.6.29-vs2.3.0.36.9-pre3/drivers/md/dm.h      2009-03-24 14:48:26.000000000 +0100
1535 @@ -54,6 +54,8 @@ int dm_table_any_congested(struct dm_tab
1536  #define dm_target_is_valid(t) ((t)->table)
1537  int dm_table_barrier_ok(struct dm_table *t);
1538  
1539 +xid_t dm_get_xid(struct mapped_device *md);
1540 +
1541  /*-----------------------------------------------------------------
1542   * A registry of target types.
1543   *---------------------------------------------------------------*/
1544 diff -NurpP --minimal linux-2.6.29/drivers/md/dm-ioctl.c linux-2.6.29-vs2.3.0.36.9-pre3/drivers/md/dm-ioctl.c
1545 --- linux-2.6.29/drivers/md/dm-ioctl.c  2009-03-24 14:19:05.000000000 +0100
1546 +++ linux-2.6.29-vs2.3.0.36.9-pre3/drivers/md/dm-ioctl.c        2009-03-24 14:48:26.000000000 +0100
1547 @@ -16,6 +16,7 @@
1548  #include <linux/dm-ioctl.h>
1549  #include <linux/hdreg.h>
1550  #include <linux/compat.h>
1551 +#include <linux/vs_context.h>
1552  
1553  #include <asm/uaccess.h>
1554  
1555 @@ -101,7 +102,8 @@ static struct hash_cell *__get_name_cell
1556         unsigned int h = hash_str(str);
1557  
1558         list_for_each_entry (hc, _name_buckets + h, name_list)
1559 -               if (!strcmp(hc->name, str)) {
1560 +               if (vx_check(dm_get_xid(hc->md), VS_WATCH_P | VS_IDENT) &&
1561 +                       !strcmp(hc->name, str)) {
1562                         dm_get(hc->md);
1563                         return hc;
1564                 }
1565 @@ -115,7 +117,8 @@ static struct hash_cell *__get_uuid_cell
1566         unsigned int h = hash_str(str);
1567  
1568         list_for_each_entry (hc, _uuid_buckets + h, uuid_list)
1569 -               if (!strcmp(hc->uuid, str)) {
1570 +               if (vx_check(dm_get_xid(hc->md), VS_WATCH_P | VS_IDENT) &&
1571 +                       !strcmp(hc->uuid, str)) {
1572                         dm_get(hc->md);
1573                         return hc;
1574                 }
1575 @@ -352,6 +355,9 @@ typedef int (*ioctl_fn)(struct dm_ioctl 
1576  
1577  static int remove_all(struct dm_ioctl *param, size_t param_size)
1578  {
1579 +       if (!vx_check(0, VS_ADMIN))
1580 +               return -EPERM;
1581 +
1582         dm_hash_remove_all(1);
1583         param->data_size = 0;
1584         return 0;
1585 @@ -399,6 +405,8 @@ static int list_devices(struct dm_ioctl 
1586          */
1587         for (i = 0; i < NUM_BUCKETS; i++) {
1588                 list_for_each_entry (hc, _name_buckets + i, name_list) {
1589 +                       if (!vx_check(dm_get_xid(hc->md), VS_WATCH_P | VS_IDENT))
1590 +                               continue;
1591                         needed += sizeof(struct dm_name_list);
1592                         needed += strlen(hc->name) + 1;
1593                         needed += ALIGN_MASK;
1594 @@ -422,6 +430,8 @@ static int list_devices(struct dm_ioctl 
1595          */
1596         for (i = 0; i < NUM_BUCKETS; i++) {
1597                 list_for_each_entry (hc, _name_buckets + i, name_list) {
1598 +                       if (!vx_check(dm_get_xid(hc->md), VS_WATCH_P | VS_IDENT))
1599 +                               continue;
1600                         if (old_nl)
1601                                 old_nl->next = (uint32_t) ((void *) nl -
1602                                                            (void *) old_nl);
1603 @@ -612,10 +622,11 @@ static struct hash_cell *__find_device_h
1604         if (!md)
1605                 goto out;
1606  
1607 -       mdptr = dm_get_mdptr(md);
1608 +       if (vx_check(dm_get_xid(md), VS_WATCH_P | VS_IDENT))
1609 +               mdptr = dm_get_mdptr(md);
1610 +
1611         if (!mdptr)
1612                 dm_put(md);
1613 -
1614  out:
1615         return mdptr;
1616  }
1617 @@ -1405,8 +1416,8 @@ static int ctl_ioctl(uint command, struc
1618         ioctl_fn fn = NULL;
1619         size_t param_size;
1620  
1621 -       /* only root can play with this */
1622 -       if (!capable(CAP_SYS_ADMIN))
1623 +       /* only root and certain contexts can play with this */
1624 +       if (!vx_capable(CAP_SYS_ADMIN, VXC_ADMIN_MAPPER))
1625                 return -EACCES;
1626  
1627         if (_IOC_TYPE(command) != DM_IOCTL)
1628 diff -NurpP --minimal linux-2.6.29/drivers/net/tun.c linux-2.6.29-vs2.3.0.36.9-pre3/drivers/net/tun.c
1629 --- linux-2.6.29/drivers/net/tun.c      2009-03-24 14:19:23.000000000 +0100
1630 +++ linux-2.6.29-vs2.3.0.36.9-pre3/drivers/net/tun.c    2009-03-25 01:51:59.000000000 +0100
1631 @@ -61,6 +61,7 @@
1632  #include <linux/crc32.h>
1633  #include <linux/nsproxy.h>
1634  #include <linux/virtio_net.h>
1635 +#include <linux/vs_network.h>
1636  #include <net/net_namespace.h>
1637  #include <net/netns/generic.h>
1638  
1639 @@ -93,6 +94,7 @@ struct tun_struct {
1640         int                     attached;
1641         uid_t                   owner;
1642         gid_t                   group;
1643 +       nid_t                   nid;
1644  
1645         wait_queue_head_t       read_wait;
1646         struct sk_buff_head     readq;
1647 @@ -697,6 +699,7 @@ static void tun_setup(struct net_device 
1648  
1649         tun->owner = -1;
1650         tun->group = -1;
1651 +       tun->nid = current->nid;
1652  
1653         dev->ethtool_ops = &tun_ethtool_ops;
1654         dev->destructor = free_netdev;
1655 @@ -727,6 +730,9 @@ static int tun_set_iff(struct net *net, 
1656         tn = net_generic(net, tun_net_id);
1657         tun = tun_get_by_name(tn, ifr->ifr_name);
1658         if (tun) {
1659 +               if (!nx_check(tun->nid, VS_IDENT | VS_HOSTID | VS_ADMIN_P))
1660 +                       return -EPERM;
1661 +
1662                 if (tun->attached)
1663                         return -EBUSY;
1664  
1665 @@ -735,7 +741,7 @@ static int tun_set_iff(struct net *net, 
1666                       cred->euid != tun->owner) ||
1667                      (tun->group != -1 &&
1668                       cred->egid != tun->group)) &&
1669 -                   !capable(CAP_NET_ADMIN)) {
1670 +                    !cap_raised(current_cap(), CAP_NET_ADMIN)) {
1671                         return -EPERM;
1672                 }
1673         }
1674 @@ -747,7 +753,7 @@ static int tun_set_iff(struct net *net, 
1675  
1676                 err = -EINVAL;
1677  
1678 -               if (!capable(CAP_NET_ADMIN))
1679 +               if (!nx_capable(CAP_NET_ADMIN, NXC_TUN_CREATE))
1680                         return -EPERM;
1681  
1682                 /* Set dev type */
1683 @@ -987,6 +993,16 @@ static int tun_chr_ioctl(struct inode *i
1684                 DBG(KERN_INFO "%s: group set to %d\n", tun->dev->name, tun->group);
1685                 break;
1686  
1687 +       case TUNSETNID:
1688 +               if (!capable(CAP_CONTEXT))
1689 +                       return -EPERM;
1690 +
1691 +               /* Set nid owner of the device */
1692 +               tun->nid = (nid_t) arg;
1693 +
1694 +               DBG(KERN_INFO "%s: nid owner set to %u\n", tun->dev->name, tun->nid);
1695 +               break;
1696 +
1697         case TUNSETLINK:
1698                 /* Only allow setting the type when the interface is down */
1699                 rtnl_lock();
1700 diff -NurpP --minimal linux-2.6.29/fs/attr.c linux-2.6.29-vs2.3.0.36.9-pre3/fs/attr.c
1701 --- linux-2.6.29/fs/attr.c      2009-03-24 14:22:24.000000000 +0100
1702 +++ linux-2.6.29-vs2.3.0.36.9-pre3/fs/attr.c    2009-03-24 14:48:34.000000000 +0100
1703 @@ -14,6 +14,9 @@
1704  #include <linux/fcntl.h>
1705  #include <linux/quotaops.h>
1706  #include <linux/security.h>
1707 +#include <linux/proc_fs.h>
1708 +#include <linux/devpts_fs.h>
1709 +#include <linux/vs_tag.h>
1710  
1711  /* Taken over from the old code... */
1712  
1713 @@ -55,6 +58,10 @@ int inode_change_ok(struct inode *inode,
1714                 if (!is_owner_or_cap(inode))
1715                         goto error;
1716         }
1717 +
1718 +       if (dx_permission(inode, MAY_WRITE))
1719 +               goto error;
1720 +
1721  fine:
1722         retval = 0;
1723  error:
1724 @@ -78,6 +85,8 @@ int inode_setattr(struct inode * inode, 
1725                 inode->i_uid = attr->ia_uid;
1726         if (ia_valid & ATTR_GID)
1727                 inode->i_gid = attr->ia_gid;
1728 +       if ((ia_valid & ATTR_TAG) && IS_TAGGED(inode))
1729 +               inode->i_tag = attr->ia_tag;
1730         if (ia_valid & ATTR_ATIME)
1731                 inode->i_atime = timespec_trunc(attr->ia_atime,
1732                                                 inode->i_sb->s_time_gran);
1733 @@ -172,7 +181,8 @@ int notify_change(struct dentry * dentry
1734                 error = inode_change_ok(inode, attr);
1735                 if (!error) {
1736                         if ((ia_valid & ATTR_UID && attr->ia_uid != inode->i_uid) ||
1737 -                           (ia_valid & ATTR_GID && attr->ia_gid != inode->i_gid))
1738 +                           (ia_valid & ATTR_GID && attr->ia_gid != inode->i_gid) ||
1739 +                           (ia_valid & ATTR_TAG && attr->ia_tag != inode->i_tag))
1740                                 error = DQUOT_TRANSFER(inode, attr) ? -EDQUOT : 0;
1741                         if (!error)
1742                                 error = inode_setattr(inode, attr);
1743 diff -NurpP --minimal linux-2.6.29/fs/binfmt_aout.c linux-2.6.29-vs2.3.0.36.9-pre3/fs/binfmt_aout.c
1744 --- linux-2.6.29/fs/binfmt_aout.c       2009-03-24 14:22:24.000000000 +0100
1745 +++ linux-2.6.29-vs2.3.0.36.9-pre3/fs/binfmt_aout.c     2009-03-24 14:48:34.000000000 +0100
1746 @@ -24,6 +24,7 @@
1747  #include <linux/binfmts.h>
1748  #include <linux/personality.h>
1749  #include <linux/init.h>
1750 +#include <linux/vs_memory.h>
1751  
1752  #include <asm/system.h>
1753  #include <asm/uaccess.h>
1754 diff -NurpP --minimal linux-2.6.29/fs/binfmt_elf.c linux-2.6.29-vs2.3.0.36.9-pre3/fs/binfmt_elf.c
1755 --- linux-2.6.29/fs/binfmt_elf.c        2009-03-24 14:22:24.000000000 +0100
1756 +++ linux-2.6.29-vs2.3.0.36.9-pre3/fs/binfmt_elf.c      2009-03-24 14:48:34.000000000 +0100
1757 @@ -38,6 +38,7 @@
1758  #include <linux/random.h>
1759  #include <linux/elf.h>
1760  #include <linux/utsname.h>
1761 +#include <linux/vs_memory.h>
1762  #include <asm/uaccess.h>
1763  #include <asm/param.h>
1764  #include <asm/page.h>
1765 diff -NurpP --minimal linux-2.6.29/fs/binfmt_flat.c linux-2.6.29-vs2.3.0.36.9-pre3/fs/binfmt_flat.c
1766 --- linux-2.6.29/fs/binfmt_flat.c       2009-03-24 14:22:24.000000000 +0100
1767 +++ linux-2.6.29-vs2.3.0.36.9-pre3/fs/binfmt_flat.c     2009-03-24 14:48:34.000000000 +0100
1768 @@ -35,6 +35,7 @@
1769  #include <linux/init.h>
1770  #include <linux/flat.h>
1771  #include <linux/syscalls.h>
1772 +#include <linux/vs_memory.h>
1773  
1774  #include <asm/byteorder.h>
1775  #include <asm/system.h>
1776 diff -NurpP --minimal linux-2.6.29/fs/binfmt_som.c linux-2.6.29-vs2.3.0.36.9-pre3/fs/binfmt_som.c
1777 --- linux-2.6.29/fs/binfmt_som.c        2009-03-24 14:22:24.000000000 +0100
1778 +++ linux-2.6.29-vs2.3.0.36.9-pre3/fs/binfmt_som.c      2009-03-24 14:48:34.000000000 +0100
1779 @@ -28,6 +28,7 @@
1780  #include <linux/shm.h>
1781  #include <linux/personality.h>
1782  #include <linux/init.h>
1783 +#include <linux/vs_memory.h>
1784  
1785  #include <asm/uaccess.h>
1786  #include <asm/pgtable.h>
1787 diff -NurpP --minimal linux-2.6.29/fs/block_dev.c linux-2.6.29-vs2.3.0.36.9-pre3/fs/block_dev.c
1788 --- linux-2.6.29/fs/block_dev.c 2009-03-24 14:22:24.000000000 +0100
1789 +++ linux-2.6.29-vs2.3.0.36.9-pre3/fs/block_dev.c       2009-03-24 14:48:34.000000000 +0100
1790 @@ -24,6 +24,7 @@
1791  #include <linux/uio.h>
1792  #include <linux/namei.h>
1793  #include <linux/log2.h>
1794 +#include <linux/vs_device.h>
1795  #include <asm/uaccess.h>
1796  #include "internal.h"
1797  
1798 @@ -392,6 +393,7 @@ struct block_device *bdget(dev_t dev)
1799                 bdev->bd_invalidated = 0;
1800                 inode->i_mode = S_IFBLK;
1801                 inode->i_rdev = dev;
1802 +               inode->i_mdev = dev;
1803                 inode->i_bdev = bdev;
1804                 inode->i_data.a_ops = &def_blk_aops;
1805                 mapping_set_gfp_mask(&inode->i_data, GFP_USER);
1806 @@ -428,6 +430,11 @@ EXPORT_SYMBOL(bdput);
1807  static struct block_device *bd_acquire(struct inode *inode)
1808  {
1809         struct block_device *bdev;
1810 +       dev_t mdev;
1811 +
1812 +       if (!vs_map_blkdev(inode->i_rdev, &mdev, DATTR_OPEN))
1813 +               return NULL;
1814 +       inode->i_mdev = mdev;
1815  
1816         spin_lock(&bdev_lock);
1817         bdev = inode->i_bdev;
1818 @@ -438,7 +445,7 @@ static struct block_device *bd_acquire(s
1819         }
1820         spin_unlock(&bdev_lock);
1821  
1822 -       bdev = bdget(inode->i_rdev);
1823 +       bdev = bdget(mdev);
1824         if (bdev) {
1825                 spin_lock(&bdev_lock);
1826                 if (!inode->i_bdev) {
1827 diff -NurpP --minimal linux-2.6.29/fs/char_dev.c linux-2.6.29-vs2.3.0.36.9-pre3/fs/char_dev.c
1828 --- linux-2.6.29/fs/char_dev.c  2009-03-24 14:22:25.000000000 +0100
1829 +++ linux-2.6.29-vs2.3.0.36.9-pre3/fs/char_dev.c        2009-03-24 14:48:35.000000000 +0100
1830 @@ -21,6 +21,8 @@
1831  #include <linux/cdev.h>
1832  #include <linux/mutex.h>
1833  #include <linux/backing-dev.h>
1834 +#include <linux/vs_context.h>
1835 +#include <linux/vs_device.h>
1836  
1837  #include "internal.h"
1838  
1839 @@ -358,14 +360,21 @@ static int chrdev_open(struct inode *ino
1840         struct cdev *p;
1841         struct cdev *new = NULL;
1842         int ret = 0;
1843 +       dev_t mdev;
1844 +
1845 +       if (!vs_map_chrdev(inode->i_rdev, &mdev, DATTR_OPEN))
1846 +               return -EPERM;
1847 +       inode->i_mdev = mdev;
1848  
1849         spin_lock(&cdev_lock);
1850         p = inode->i_cdev;
1851         if (!p) {
1852                 struct kobject *kobj;
1853                 int idx;
1854 +
1855                 spin_unlock(&cdev_lock);
1856 -               kobj = kobj_lookup(cdev_map, inode->i_rdev, &idx);
1857 +
1858 +               kobj = kobj_lookup(cdev_map, mdev, &idx);
1859                 if (!kobj)
1860                         return -ENXIO;
1861                 new = container_of(kobj, struct cdev, kobj);
1862 diff -NurpP --minimal linux-2.6.29/fs/dcache.c linux-2.6.29-vs2.3.0.36.9-pre3/fs/dcache.c
1863 --- linux-2.6.29/fs/dcache.c    2009-03-24 14:22:25.000000000 +0100
1864 +++ linux-2.6.29-vs2.3.0.36.9-pre3/fs/dcache.c  2009-03-24 14:48:35.000000000 +0100
1865 @@ -32,6 +32,7 @@
1866  #include <linux/seqlock.h>
1867  #include <linux/swap.h>
1868  #include <linux/bootmem.h>
1869 +#include <linux/vs_limit.h>
1870  #include "internal.h"
1871  
1872  int sysctl_vfs_cache_pressure __read_mostly = 100;
1873 @@ -229,6 +230,8 @@ repeat:
1874                 return;
1875         }
1876  
1877 +       vx_dentry_dec(dentry);
1878 +
1879         /*
1880          * AV: ->d_delete() is _NOT_ allowed to block now.
1881          */
1882 @@ -320,6 +323,7 @@ static inline struct dentry * __dget_loc
1883  {
1884         atomic_inc(&dentry->d_count);
1885         dentry_lru_del_init(dentry);
1886 +       vx_dentry_inc(dentry);
1887         return dentry;
1888  }
1889  
1890 @@ -918,6 +922,9 @@ struct dentry *d_alloc(struct dentry * p
1891         struct dentry *dentry;
1892         char *dname;
1893  
1894 +       if (!vx_dentry_avail(1))
1895 +               return NULL;
1896 +
1897         dentry = kmem_cache_alloc(dentry_cache, GFP_KERNEL);
1898         if (!dentry)
1899                 return NULL;
1900 @@ -963,6 +970,7 @@ struct dentry *d_alloc(struct dentry * p
1901         if (parent)
1902                 list_add(&dentry->d_u.d_child, &parent->d_subdirs);
1903         dentry_stat.nr_dentry++;
1904 +       vx_dentry_inc(dentry);
1905         spin_unlock(&dcache_lock);
1906  
1907         return dentry;
1908 @@ -1418,6 +1426,7 @@ struct dentry * __d_lookup(struct dentry
1909                 }
1910  
1911                 atomic_inc(&dentry->d_count);
1912 +               vx_dentry_inc(dentry);
1913                 found = dentry;
1914                 spin_unlock(&dentry->d_lock);
1915                 break;
1916 diff -NurpP --minimal linux-2.6.29/fs/devpts/inode.c linux-2.6.29-vs2.3.0.36.9-pre3/fs/devpts/inode.c
1917 --- linux-2.6.29/fs/devpts/inode.c      2009-03-24 14:22:25.000000000 +0100
1918 +++ linux-2.6.29-vs2.3.0.36.9-pre3/fs/devpts/inode.c    2009-03-24 15:32:47.000000000 +0100
1919 @@ -19,12 +19,12 @@
1920  #include <linux/tty.h>
1921  #include <linux/mutex.h>
1922  #include <linux/idr.h>
1923 +#include <linux/magic.h>
1924  #include <linux/devpts_fs.h>
1925  #include <linux/parser.h>
1926  #include <linux/fsnotify.h>
1927  #include <linux/seq_file.h>
1928 -
1929 -#define DEVPTS_SUPER_MAGIC 0x1cd1
1930 +#include <linux/vs_base.h>
1931  
1932  #define DEVPTS_DEFAULT_MODE 0600
1933  /*
1934 @@ -36,6 +36,20 @@
1935  #define DEVPTS_DEFAULT_PTMX_MODE 0000
1936  #define PTMX_MINOR     2
1937  
1938 +static int devpts_permission(struct inode *inode, int mask)
1939 +{
1940 +       int ret = -EACCES;
1941 +
1942 +       /* devpts is xid tagged */
1943 +       if (vx_check((xid_t)inode->i_tag, VS_WATCH_P | VS_IDENT))
1944 +               ret = generic_permission(inode, mask, NULL);
1945 +       return ret;
1946 +}
1947 +
1948 +static struct inode_operations devpts_file_inode_operations = {
1949 +       .permission     = devpts_permission,
1950 +};
1951 +
1952  extern int pty_limit;                  /* Config limit on Unix98 ptys */
1953  static DEFINE_MUTEX(allocated_ptys_lock);
1954  
1955 @@ -254,6 +268,25 @@ static int devpts_show_options(struct se
1956         return 0;
1957  }
1958  
1959 +static int devpts_filter(struct dentry *de)
1960 +{
1961 +       /* devpts is xid tagged */
1962 +       return vx_check((xid_t)de->d_inode->i_tag, VS_WATCH_P | VS_IDENT);
1963 +}
1964 +
1965 +static int devpts_readdir(struct file * filp, void * dirent, filldir_t filldir)
1966 +{
1967 +       return dcache_readdir_filter(filp, dirent, filldir, devpts_filter);
1968 +}
1969 +
1970 +static struct file_operations devpts_dir_operations = {
1971 +       .open           = dcache_dir_open,
1972 +       .release        = dcache_dir_close,
1973 +       .llseek         = dcache_dir_lseek,
1974 +       .read           = generic_read_dir,
1975 +       .readdir        = devpts_readdir,
1976 +};
1977 +
1978  static const struct super_operations devpts_sops = {
1979         .statfs         = simple_statfs,
1980         .remount_fs     = devpts_remount,
1981 @@ -293,12 +326,15 @@ devpts_fill_super(struct super_block *s,
1982         inode = new_inode(s);
1983         if (!inode)
1984                 goto free_fsi;
1985 +
1986         inode->i_ino = 1;
1987         inode->i_mtime = inode->i_atime = inode->i_ctime = CURRENT_TIME;
1988         inode->i_mode = S_IFDIR | S_IRUGO | S_IXUGO | S_IWUSR;
1989         inode->i_op = &simple_dir_inode_operations;
1990 -       inode->i_fop = &simple_dir_operations;
1991 +       inode->i_fop = &devpts_dir_operations;
1992         inode->i_nlink = 2;
1993 +       /* devpts is xid tagged */
1994 +       inode->i_tag = (tag_t)vx_current_xid();
1995  
1996         s->s_root = d_alloc_root(inode);
1997         if (s->s_root)
1998 @@ -479,6 +515,7 @@ static int init_pts_mount(struct file_sy
1999         return err;
2000  }
2001  
2002 +
2003  static int devpts_get_sb(struct file_system_type *fs_type,
2004         int flags, const char *dev_name, void *data, struct vfsmount *mnt)
2005  {
2006 @@ -590,6 +627,9 @@ int devpts_pty_new(struct inode *ptmx_in
2007         inode->i_gid = opts->setgid ? opts->gid : current_fsgid();
2008         inode->i_mtime = inode->i_atime = inode->i_ctime = CURRENT_TIME;
2009         init_special_inode(inode, S_IFCHR|opts->mode, device);
2010 +       /* devpts is xid tagged */
2011 +       inode->i_tag = (tag_t)vx_current_xid();
2012 +       inode->i_op = &devpts_file_inode_operations;
2013         inode->i_private = tty;
2014         tty->driver_data = inode;
2015  
2016 diff -NurpP --minimal linux-2.6.29/fs/exec.c linux-2.6.29-vs2.3.0.36.9-pre3/fs/exec.c
2017 --- linux-2.6.29/fs/exec.c      2009-03-24 14:22:25.000000000 +0100
2018 +++ linux-2.6.29-vs2.3.0.36.9-pre3/fs/exec.c    2009-03-24 15:34:21.000000000 +0100
2019 @@ -257,7 +257,9 @@ static int __bprm_mm_init(struct linux_b
2020         if (err)
2021                 goto err;
2022  
2023 -       mm->stack_vm = mm->total_vm = 1;
2024 +       mm->total_vm = 0;
2025 +       vx_vmpages_inc(mm);
2026 +       mm->stack_vm = 1;
2027         up_write(&mm->mmap_sem);
2028         bprm->p = vma->vm_end - sizeof(void *);
2029         return 0;
2030 @@ -1450,7 +1452,7 @@ static int format_corename(char *corenam
2031                         /* UNIX time of coredump */
2032                         case 't': {
2033                                 struct timeval tv;
2034 -                               do_gettimeofday(&tv);
2035 +                               vx_gettimeofday(&tv);
2036                                 rc = snprintf(out_ptr, out_end - out_ptr,
2037                                               "%lu", tv.tv_sec);
2038                                 if (rc > out_end - out_ptr)
2039 diff -NurpP --minimal linux-2.6.29/fs/ext2/balloc.c linux-2.6.29-vs2.3.0.36.9-pre3/fs/ext2/balloc.c
2040 --- linux-2.6.29/fs/ext2/balloc.c       2009-03-24 14:22:25.000000000 +0100
2041 +++ linux-2.6.29-vs2.3.0.36.9-pre3/fs/ext2/balloc.c     2009-03-24 14:48:35.000000000 +0100
2042 @@ -16,6 +16,8 @@
2043  #include <linux/sched.h>
2044  #include <linux/buffer_head.h>
2045  #include <linux/capability.h>
2046 +#include <linux/vs_dlimit.h>
2047 +#include <linux/vs_tag.h>
2048  
2049  /*
2050   * balloc.c contains the blocks allocation and deallocation routines
2051 @@ -569,6 +571,7 @@ do_more:
2052         }
2053  error_return:
2054         brelse(bitmap_bh);
2055 +       DLIMIT_FREE_BLOCK(inode, freed);
2056         release_blocks(sb, freed);
2057         DQUOT_FREE_BLOCK(inode, freed);
2058  }
2059 @@ -701,7 +704,6 @@ ext2_try_to_allocate(struct super_block 
2060                         start = 0;
2061                 end = EXT2_BLOCKS_PER_GROUP(sb);
2062         }
2063 -
2064         BUG_ON(start > EXT2_BLOCKS_PER_GROUP(sb));
2065  
2066  repeat:
2067 @@ -1251,6 +1253,11 @@ ext2_fsblk_t ext2_new_blocks(struct inod
2068                 *errp = -EDQUOT;
2069                 return 0;
2070         }
2071 +       if (DLIMIT_ALLOC_BLOCK(inode, num)) {
2072 +               *errp = -ENOSPC;
2073 +               DQUOT_FREE_BLOCK(inode, num);
2074 +               return 0;
2075 +       }
2076  
2077         sbi = EXT2_SB(sb);
2078         es = EXT2_SB(sb)->s_es;
2079 @@ -1409,6 +1416,7 @@ allocated:
2080  
2081         *errp = 0;
2082         brelse(bitmap_bh);
2083 +       DLIMIT_FREE_BLOCK(inode, *count-num);
2084         DQUOT_FREE_BLOCK(inode, *count-num);
2085         *count = num;
2086         return ret_block;
2087 @@ -1419,8 +1427,10 @@ out:
2088         /*
2089          * Undo the block allocation
2090          */
2091 -       if (!performed_allocation)
2092 +       if (!performed_allocation) {
2093 +               DLIMIT_FREE_BLOCK(inode, *count);
2094                 DQUOT_FREE_BLOCK(inode, *count);
2095 +       }
2096         brelse(bitmap_bh);
2097         return 0;
2098  }
2099 diff -NurpP --minimal linux-2.6.29/fs/ext2/ext2.h linux-2.6.29-vs2.3.0.36.9-pre3/fs/ext2/ext2.h
2100 --- linux-2.6.29/fs/ext2/ext2.h 2008-12-25 00:26:37.000000000 +0100
2101 +++ linux-2.6.29-vs2.3.0.36.9-pre3/fs/ext2/ext2.h       2009-02-22 22:54:25.000000000 +0100
2102 @@ -170,6 +170,7 @@ extern const struct file_operations ext2
2103  extern const struct address_space_operations ext2_aops;
2104  extern const struct address_space_operations ext2_aops_xip;
2105  extern const struct address_space_operations ext2_nobh_aops;
2106 +extern int ext2_sync_flags(struct inode *inode);
2107  
2108  /* namei.c */
2109  extern const struct inode_operations ext2_dir_inode_operations;
2110 diff -NurpP --minimal linux-2.6.29/fs/ext2/file.c linux-2.6.29-vs2.3.0.36.9-pre3/fs/ext2/file.c
2111 --- linux-2.6.29/fs/ext2/file.c 2008-12-25 00:26:37.000000000 +0100
2112 +++ linux-2.6.29-vs2.3.0.36.9-pre3/fs/ext2/file.c       2009-02-22 22:54:25.000000000 +0100
2113 @@ -87,4 +87,5 @@ const struct inode_operations ext2_file_
2114         .setattr        = ext2_setattr,
2115         .permission     = ext2_permission,
2116         .fiemap         = ext2_fiemap,
2117 +       .sync_flags     = ext2_sync_flags,
2118  };
2119 diff -NurpP --minimal linux-2.6.29/fs/ext2/ialloc.c linux-2.6.29-vs2.3.0.36.9-pre3/fs/ext2/ialloc.c
2120 --- linux-2.6.29/fs/ext2/ialloc.c       2009-03-24 14:22:25.000000000 +0100
2121 +++ linux-2.6.29-vs2.3.0.36.9-pre3/fs/ext2/ialloc.c     2009-03-24 15:36:12.000000000 +0100
2122 @@ -17,6 +17,8 @@
2123  #include <linux/backing-dev.h>
2124  #include <linux/buffer_head.h>
2125  #include <linux/random.h>
2126 +#include <linux/vs_dlimit.h>
2127 +#include <linux/vs_tag.h>
2128  #include "ext2.h"
2129  #include "xattr.h"
2130  #include "acl.h"
2131 @@ -123,6 +125,7 @@ void ext2_free_inode (struct inode * ino
2132                 ext2_xattr_delete_inode(inode);
2133                 DQUOT_FREE_INODE(inode);
2134                 DQUOT_DROP(inode);
2135 +               DLIMIT_FREE_INODE(inode);
2136         }
2137  
2138         es = EXT2_SB(sb)->s_es;
2139 @@ -454,6 +457,11 @@ struct inode *ext2_new_inode(struct inod
2140         if (!inode)
2141                 return ERR_PTR(-ENOMEM);
2142  
2143 +       inode->i_tag = dx_current_fstag(sb);
2144 +       if (DLIMIT_ALLOC_INODE(inode)) {
2145 +               err = -ENOSPC;
2146 +               goto fail_dlim;
2147 +       }
2148         ei = EXT2_I(inode);
2149         sbi = EXT2_SB(sb);
2150         es = sbi->s_es;
2151 @@ -609,6 +617,7 @@ fail_free_drop:
2152  
2153  fail_drop:
2154         DQUOT_DROP(inode);
2155 +       DLIMIT_FREE_INODE(inode);
2156         inode->i_flags |= S_NOQUOTA;
2157         inode->i_nlink = 0;
2158         unlock_new_inode(inode);
2159 @@ -616,6 +625,8 @@ fail_drop:
2160         return ERR_PTR(err);
2161  
2162  fail:
2163 +       DLIMIT_FREE_INODE(inode);
2164 +fail_dlim:
2165         make_bad_inode(inode);
2166         iput(inode);
2167         return ERR_PTR(err);
2168 diff -NurpP --minimal linux-2.6.29/fs/ext2/inode.c linux-2.6.29-vs2.3.0.36.9-pre3/fs/ext2/inode.c
2169 --- linux-2.6.29/fs/ext2/inode.c        2009-03-24 14:22:25.000000000 +0100
2170 +++ linux-2.6.29-vs2.3.0.36.9-pre3/fs/ext2/inode.c      2009-03-24 15:41:38.000000000 +0100
2171 @@ -33,6 +33,7 @@
2172  #include <linux/mpage.h>
2173  #include <linux/fiemap.h>
2174  #include <linux/namei.h>
2175 +#include <linux/vs_tag.h>
2176  #include "ext2.h"
2177  #include "acl.h"
2178  #include "xip.h"
2179 @@ -1018,7 +1019,7 @@ void ext2_truncate(struct inode *inode)
2180                 return;
2181         if (ext2_inode_is_fast_symlink(inode))
2182                 return;
2183 -       if (IS_APPEND(inode) || IS_IMMUTABLE(inode))
2184 +       if (IS_APPEND(inode) || IS_IXORUNLINK(inode))
2185                 return;
2186  
2187         blocksize = inode->i_sb->s_blocksize;
2188 @@ -1156,38 +1157,72 @@ void ext2_set_inode_flags(struct inode *
2189  {
2190         unsigned int flags = EXT2_I(inode)->i_flags;
2191  
2192 -       inode->i_flags &= ~(S_SYNC|S_APPEND|S_IMMUTABLE|S_NOATIME|S_DIRSYNC);
2193 +       inode->i_flags &= ~(S_IMMUTABLE | S_IXUNLINK |
2194 +               S_SYNC | S_APPEND | S_NOATIME | S_DIRSYNC);
2195 +
2196 +
2197 +       if (flags & EXT2_IMMUTABLE_FL)
2198 +               inode->i_flags |= S_IMMUTABLE;
2199 +       if (flags & EXT2_IXUNLINK_FL)
2200 +               inode->i_flags |= S_IXUNLINK;
2201 +
2202         if (flags & EXT2_SYNC_FL)
2203                 inode->i_flags |= S_SYNC;
2204         if (flags & EXT2_APPEND_FL)
2205                 inode->i_flags |= S_APPEND;
2206 -       if (flags & EXT2_IMMUTABLE_FL)
2207 -               inode->i_flags |= S_IMMUTABLE;
2208         if (flags & EXT2_NOATIME_FL)
2209                 inode->i_flags |= S_NOATIME;
2210         if (flags & EXT2_DIRSYNC_FL)
2211                 inode->i_flags |= S_DIRSYNC;
2212 +
2213 +       inode->i_vflags &= ~(V_BARRIER | V_COW);
2214 +
2215 +       if (flags & EXT2_BARRIER_FL)
2216 +               inode->i_vflags |= V_BARRIER;
2217 +       if (flags & EXT2_COW_FL)
2218 +               inode->i_vflags |= V_COW;
2219  }
2220  
2221  /* Propagate flags from i_flags to EXT2_I(inode)->i_flags */
2222  void ext2_get_inode_flags(struct ext2_inode_info *ei)
2223  {
2224         unsigned int flags = ei->vfs_inode.i_flags;
2225 +       unsigned int vflags = ei->vfs_inode.i_vflags;
2226 +
2227 +       ei->i_flags &= ~(EXT2_SYNC_FL | EXT2_APPEND_FL |
2228 +                       EXT2_IMMUTABLE_FL | EXT2_IXUNLINK_FL |
2229 +                       EXT2_NOATIME_FL | EXT2_DIRSYNC_FL |
2230 +                       EXT2_BARRIER_FL | EXT2_COW_FL);
2231 +
2232 +       if (flags & S_IMMUTABLE)
2233 +               ei->i_flags |= EXT2_IMMUTABLE_FL;
2234 +       if (flags & S_IXUNLINK)
2235 +               ei->i_flags |= EXT2_IXUNLINK_FL;
2236  
2237 -       ei->i_flags &= ~(EXT2_SYNC_FL|EXT2_APPEND_FL|
2238 -                       EXT2_IMMUTABLE_FL|EXT2_NOATIME_FL|EXT2_DIRSYNC_FL);
2239         if (flags & S_SYNC)
2240                 ei->i_flags |= EXT2_SYNC_FL;
2241         if (flags & S_APPEND)
2242                 ei->i_flags |= EXT2_APPEND_FL;
2243 -       if (flags & S_IMMUTABLE)
2244 -               ei->i_flags |= EXT2_IMMUTABLE_FL;
2245         if (flags & S_NOATIME)
2246                 ei->i_flags |= EXT2_NOATIME_FL;
2247         if (flags & S_DIRSYNC)
2248                 ei->i_flags |= EXT2_DIRSYNC_FL;
2249 +
2250 +       if (vflags & V_BARRIER)
2251 +               ei->i_flags |= EXT2_BARRIER_FL;
2252 +       if (vflags & V_COW)
2253 +               ei->i_flags |= EXT2_COW_FL;
2254  }
2255  
2256 +int ext2_sync_flags(struct inode *inode)
2257 +{
2258 +       ext2_get_inode_flags(EXT2_I(inode));
2259 +       inode->i_ctime = CURRENT_TIME;
2260 +       mark_inode_dirty(inode);
2261 +       return 0;
2262 +}
2263 +
2264 +
2265  struct inode *ext2_iget (struct super_block *sb, unsigned long ino)
2266  {
2267         struct ext2_inode_info *ei;
2268 @@ -1195,6 +1230,8 @@ struct inode *ext2_iget (struct super_bl
2269         struct ext2_inode *raw_inode;
2270         struct inode *inode;
2271         long ret = -EIO;
2272 +       uid_t uid;
2273 +       gid_t gid;
2274         int n;
2275  
2276         inode = iget_locked(sb, ino);
2277 @@ -1217,12 +1254,17 @@ struct inode *ext2_iget (struct super_bl
2278         }
2279  
2280         inode->i_mode = le16_to_cpu(raw_inode->i_mode);
2281 -       inode->i_uid = (uid_t)le16_to_cpu(raw_inode->i_uid_low);
2282 -       inode->i_gid = (gid_t)le16_to_cpu(raw_inode->i_gid_low);
2283 +       uid = (uid_t)le16_to_cpu(raw_inode->i_uid_low);
2284 +       gid = (gid_t)le16_to_cpu(raw_inode->i_gid_low);
2285         if (!(test_opt (inode->i_sb, NO_UID32))) {
2286 -               inode->i_uid |= le16_to_cpu(raw_inode->i_uid_high) << 16;
2287 -               inode->i_gid |= le16_to_cpu(raw_inode->i_gid_high) << 16;
2288 +               uid |= le16_to_cpu(raw_inode->i_uid_high) << 16;
2289 +               gid |= le16_to_cpu(raw_inode->i_gid_high) << 16;
2290         }
2291 +       inode->i_uid = INOTAG_UID(DX_TAG(inode), uid, gid);
2292 +       inode->i_gid = INOTAG_GID(DX_TAG(inode), uid, gid);
2293 +       inode->i_tag = INOTAG_TAG(DX_TAG(inode), uid, gid,
2294 +               le16_to_cpu(raw_inode->i_raw_tag));
2295 +
2296         inode->i_nlink = le16_to_cpu(raw_inode->i_links_count);
2297         inode->i_size = le32_to_cpu(raw_inode->i_size);
2298         inode->i_atime.tv_sec = (signed)le32_to_cpu(raw_inode->i_atime);
2299 @@ -1320,8 +1362,8 @@ static int ext2_update_inode(struct inod
2300         struct ext2_inode_info *ei = EXT2_I(inode);
2301         struct super_block *sb = inode->i_sb;
2302         ino_t ino = inode->i_ino;
2303 -       uid_t uid = inode->i_uid;
2304 -       gid_t gid = inode->i_gid;
2305 +       uid_t uid = TAGINO_UID(DX_TAG(inode), inode->i_uid, inode->i_tag);
2306 +       gid_t gid = TAGINO_GID(DX_TAG(inode), inode->i_gid, inode->i_tag);
2307         struct buffer_head * bh;
2308         struct ext2_inode * raw_inode = ext2_get_inode(sb, ino, &bh);
2309         int n;
2310 @@ -1357,6 +1399,9 @@ static int ext2_update_inode(struct inod
2311                 raw_inode->i_uid_high = 0;
2312                 raw_inode->i_gid_high = 0;
2313         }
2314 +#ifdef CONFIG_TAGGING_INTERN
2315 +       raw_inode->i_raw_tag = cpu_to_le16(inode->i_tag);
2316 +#endif
2317         raw_inode->i_links_count = cpu_to_le16(inode->i_nlink);
2318         raw_inode->i_size = cpu_to_le32(inode->i_size);
2319         raw_inode->i_atime = cpu_to_le32(inode->i_atime.tv_sec);
2320 @@ -1443,7 +1488,8 @@ int ext2_setattr(struct dentry *dentry, 
2321         if (error)
2322                 return error;
2323         if ((iattr->ia_valid & ATTR_UID && iattr->ia_uid != inode->i_uid) ||
2324 -           (iattr->ia_valid & ATTR_GID && iattr->ia_gid != inode->i_gid)) {
2325 +           (iattr->ia_valid & ATTR_GID && iattr->ia_gid != inode->i_gid) ||
2326 +           (iattr->ia_valid & ATTR_TAG && iattr->ia_tag != inode->i_tag)) {
2327                 error = DQUOT_TRANSFER(inode, iattr) ? -EDQUOT : 0;
2328                 if (error)
2329                         return error;
2330 diff -NurpP --minimal linux-2.6.29/fs/ext2/ioctl.c linux-2.6.29-vs2.3.0.36.9-pre3/fs/ext2/ioctl.c
2331 --- linux-2.6.29/fs/ext2/ioctl.c        2009-03-24 14:22:25.000000000 +0100
2332 +++ linux-2.6.29-vs2.3.0.36.9-pre3/fs/ext2/ioctl.c      2009-03-24 14:48:35.000000000 +0100
2333 @@ -14,6 +14,7 @@
2334  #include <linux/compat.h>
2335  #include <linux/mount.h>
2336  #include <linux/smp_lock.h>
2337 +#include <linux/mount.h>
2338  #include <asm/current.h>
2339  #include <asm/uaccess.h>
2340  
2341 @@ -52,6 +53,11 @@ long ext2_ioctl(struct file *filp, unsig
2342  
2343                 flags = ext2_mask_flags(inode->i_mode, flags);
2344  
2345 +               if (IS_BARRIER(inode)) {
2346 +                       vxwprintk_task(1, "messing with the barrier.");
2347 +                       return -EACCES;
2348 +               }
2349 +
2350                 mutex_lock(&inode->i_mutex);
2351                 /* Is it quota file? Do not allow user to mess with it */
2352                 if (IS_NOQUOTA(inode)) {
2353 @@ -67,7 +73,9 @@ long ext2_ioctl(struct file *filp, unsig
2354                  *
2355                  * This test looks nicer. Thanks to Pauline Middelink
2356                  */
2357 -               if ((flags ^ oldflags) & (EXT2_APPEND_FL | EXT2_IMMUTABLE_FL)) {
2358 +               if ((oldflags & EXT2_IMMUTABLE_FL) ||
2359 +                       ((flags ^ oldflags) & (EXT2_APPEND_FL |
2360 +                       EXT2_IMMUTABLE_FL | EXT2_IXUNLINK_FL))) {
2361                         if (!capable(CAP_LINUX_IMMUTABLE)) {
2362                                 mutex_unlock(&inode->i_mutex);
2363                                 ret = -EPERM;
2364 diff -NurpP --minimal linux-2.6.29/fs/ext2/namei.c linux-2.6.29-vs2.3.0.36.9-pre3/fs/ext2/namei.c
2365 --- linux-2.6.29/fs/ext2/namei.c        2009-03-24 14:22:25.000000000 +0100
2366 +++ linux-2.6.29-vs2.3.0.36.9-pre3/fs/ext2/namei.c      2009-03-24 14:48:35.000000000 +0100
2367 @@ -31,6 +31,7 @@
2368   */
2369  
2370  #include <linux/pagemap.h>
2371 +#include <linux/vs_tag.h>
2372  #include "ext2.h"
2373  #include "xattr.h"
2374  #include "acl.h"
2375 @@ -68,6 +69,7 @@ static struct dentry *ext2_lookup(struct
2376                 inode = ext2_iget(dir->i_sb, ino);
2377                 if (IS_ERR(inode))
2378                         return ERR_CAST(inode);
2379 +               dx_propagate_tag(nd, inode);
2380         }
2381         return d_splice_alias(inode, dentry);
2382  }
2383 @@ -388,6 +390,7 @@ const struct inode_operations ext2_dir_i
2384  #endif
2385         .setattr        = ext2_setattr,
2386         .permission     = ext2_permission,
2387 +       .sync_flags     = ext2_sync_flags,
2388  };
2389  
2390  const struct inode_operations ext2_special_inode_operations = {
2391 @@ -399,4 +402,5 @@ const struct inode_operations ext2_speci
2392  #endif
2393         .setattr        = ext2_setattr,
2394         .permission     = ext2_permission,
2395 +       .sync_flags     = ext2_sync_flags,
2396  };
2397 diff -NurpP --minimal linux-2.6.29/fs/ext2/super.c linux-2.6.29-vs2.3.0.36.9-pre3/fs/ext2/super.c
2398 --- linux-2.6.29/fs/ext2/super.c        2009-03-24 14:22:25.000000000 +0100
2399 +++ linux-2.6.29-vs2.3.0.36.9-pre3/fs/ext2/super.c      2009-03-24 14:48:35.000000000 +0100
2400 @@ -391,7 +391,8 @@ enum {
2401         Opt_err_ro, Opt_nouid32, Opt_nocheck, Opt_debug,
2402         Opt_oldalloc, Opt_orlov, Opt_nobh, Opt_user_xattr, Opt_nouser_xattr,
2403         Opt_acl, Opt_noacl, Opt_xip, Opt_ignore, Opt_err, Opt_quota,
2404 -       Opt_usrquota, Opt_grpquota, Opt_reservation, Opt_noreservation
2405 +       Opt_usrquota, Opt_grpquota, Opt_reservation, Opt_noreservation,
2406 +       Opt_tag, Opt_notag, Opt_tagid
2407  };
2408  
2409  static const match_table_t tokens = {
2410 @@ -419,6 +420,9 @@ static const match_table_t tokens = {
2411         {Opt_acl, "acl"},
2412         {Opt_noacl, "noacl"},
2413         {Opt_xip, "xip"},
2414 +       {Opt_tag, "tag"},
2415 +       {Opt_notag, "notag"},
2416 +       {Opt_tagid, "tagid=%u"},
2417         {Opt_grpquota, "grpquota"},
2418         {Opt_ignore, "noquota"},
2419         {Opt_quota, "quota"},
2420 @@ -489,6 +493,20 @@ static int parse_options (char * options
2421                 case Opt_nouid32:
2422                         set_opt (sbi->s_mount_opt, NO_UID32);
2423                         break;
2424 +#ifndef CONFIG_TAGGING_NONE
2425 +               case Opt_tag:
2426 +                       set_opt (sbi->s_mount_opt, TAGGED);
2427 +                       break;
2428 +               case Opt_notag:
2429 +                       clear_opt (sbi->s_mount_opt, TAGGED);
2430 +                       break;
2431 +#endif
2432 +#ifdef CONFIG_PROPAGATE
2433 +               case Opt_tagid:
2434 +                       /* use args[0] */
2435 +                       set_opt (sbi->s_mount_opt, TAGGED);
2436 +                       break;
2437 +#endif
2438                 case Opt_nocheck:
2439                         clear_opt (sbi->s_mount_opt, CHECK);
2440                         break;
2441 @@ -838,6 +856,8 @@ static int ext2_fill_super(struct super_
2442         if (!parse_options ((char *) data, sbi))
2443                 goto failed_mount;
2444  
2445 +       if (EXT2_SB(sb)->s_mount_opt & EXT2_MOUNT_TAGGED)
2446 +               sb->s_flags |= MS_TAGGED;
2447         sb->s_flags = (sb->s_flags & ~MS_POSIXACL) |
2448                 ((EXT2_SB(sb)->s_mount_opt & EXT2_MOUNT_POSIX_ACL) ?
2449                  MS_POSIXACL : 0);
2450 @@ -1170,6 +1190,13 @@ static int ext2_remount (struct super_bl
2451                 goto restore_opts;
2452         }
2453  
2454 +       if ((sbi->s_mount_opt & EXT2_MOUNT_TAGGED) &&
2455 +               !(sb->s_flags & MS_TAGGED)) {
2456 +               printk("EXT2-fs: %s: tagging not permitted on remount.\n",
2457 +                      sb->s_id);
2458 +               return -EINVAL;
2459 +       }
2460 +
2461         sb->s_flags = (sb->s_flags & ~MS_POSIXACL) |
2462                 ((sbi->s_mount_opt & EXT2_MOUNT_POSIX_ACL) ? MS_POSIXACL : 0);
2463  
2464 diff -NurpP --minimal linux-2.6.29/fs/ext2/symlink.c linux-2.6.29-vs2.3.0.36.9-pre3/fs/ext2/symlink.c
2465 --- linux-2.6.29/fs/ext2/symlink.c      2008-12-25 00:26:37.000000000 +0100
2466 +++ linux-2.6.29-vs2.3.0.36.9-pre3/fs/ext2/symlink.c    2009-02-22 22:54:25.000000000 +0100
2467 @@ -38,6 +38,7 @@ const struct inode_operations ext2_symli
2468         .listxattr      = ext2_listxattr,
2469         .removexattr    = generic_removexattr,
2470  #endif
2471 +       .sync_flags     = ext2_sync_flags,
2472  };
2473   
2474  const struct inode_operations ext2_fast_symlink_inode_operations = {
2475 @@ -49,4 +50,5 @@ const struct inode_operations ext2_fast_
2476         .listxattr      = ext2_listxattr,
2477         .removexattr    = generic_removexattr,
2478  #endif
2479 +       .sync_flags     = ext2_sync_flags,
2480  };
2481 diff -NurpP --minimal linux-2.6.29/fs/ext2/xattr.c linux-2.6.29-vs2.3.0.36.9-pre3/fs/ext2/xattr.c
2482 --- linux-2.6.29/fs/ext2/xattr.c        2008-12-25 00:26:37.000000000 +0100
2483 +++ linux-2.6.29-vs2.3.0.36.9-pre3/fs/ext2/xattr.c      2009-02-22 22:54:25.000000000 +0100
2484 @@ -60,6 +60,7 @@
2485  #include <linux/mbcache.h>
2486  #include <linux/quotaops.h>
2487  #include <linux/rwsem.h>
2488 +#include <linux/vs_dlimit.h>
2489  #include "ext2.h"
2490  #include "xattr.h"
2491  #include "acl.h"
2492 @@ -641,8 +642,12 @@ ext2_xattr_set2(struct inode *inode, str
2493                                    the inode.  */
2494                                 ea_bdebug(new_bh, "reusing block");
2495  
2496 +                               error = -ENOSPC;
2497 +                               if (DLIMIT_ALLOC_BLOCK(inode, 1))
2498 +                                       goto cleanup;
2499                                 error = -EDQUOT;
2500                                 if (DQUOT_ALLOC_BLOCK(inode, 1)) {
2501 +                                       DLIMIT_FREE_BLOCK(inode, 1);
2502                                         unlock_buffer(new_bh);
2503                                         goto cleanup;
2504                                 }
2505 @@ -731,6 +736,7 @@ ext2_xattr_set2(struct inode *inode, str
2506                         le32_add_cpu(&HDR(old_bh)->h_refcount, -1);
2507                         if (ce)
2508                                 mb_cache_entry_release(ce);
2509 +                       DLIMIT_FREE_BLOCK(inode, 1);
2510                         DQUOT_FREE_BLOCK(inode, 1);
2511                         mark_buffer_dirty(old_bh);
2512                         ea_bdebug(old_bh, "refcount now=%d",
2513 @@ -794,6 +800,7 @@ ext2_xattr_delete_inode(struct inode *in
2514                 mark_buffer_dirty(bh);
2515                 if (IS_SYNC(inode))
2516                         sync_dirty_buffer(bh);
2517 +               DLIMIT_FREE_BLOCK(inode, 1);
2518                 DQUOT_FREE_BLOCK(inode, 1);
2519         }
2520         EXT2_I(inode)->i_file_acl = 0;
2521 diff -NurpP --minimal linux-2.6.29/fs/ext3/balloc.c linux-2.6.29-vs2.3.0.36.9-pre3/fs/ext3/balloc.c
2522 --- linux-2.6.29/fs/ext3/balloc.c       2009-03-24 14:22:25.000000000 +0100
2523 +++ linux-2.6.29-vs2.3.0.36.9-pre3/fs/ext3/balloc.c     2009-03-25 00:53:20.000000000 +0100
2524 @@ -19,6 +19,8 @@
2525  #include <linux/ext3_jbd.h>
2526  #include <linux/quotaops.h>
2527  #include <linux/buffer_head.h>
2528 +#include <linux/vs_dlimit.h>
2529 +#include <linux/vs_tag.h>
2530  
2531  /*
2532   * balloc.c contains the blocks allocation and deallocation routines
2533 @@ -675,8 +677,10 @@ void ext3_free_blocks(handle_t *handle, 
2534                 return;
2535         }
2536         ext3_free_blocks_sb(handle, sb, block, count, &dquot_freed_blocks);
2537 -       if (dquot_freed_blocks)
2538 +       if (dquot_freed_blocks) {
2539 +               DLIMIT_FREE_BLOCK(inode, dquot_freed_blocks);
2540                 DQUOT_FREE_BLOCK(inode, dquot_freed_blocks);
2541 +       }
2542         return;
2543  }
2544  
2545 @@ -1415,18 +1419,33 @@ out:
2546   *
2547   * Check if filesystem has at least 1 free block available for allocation.
2548   */
2549 -static int ext3_has_free_blocks(struct ext3_sb_info *sbi)
2550 +static int ext3_has_free_blocks(struct super_block *sb)
2551  {
2552 -       ext3_fsblk_t free_blocks, root_blocks;
2553 +       struct ext3_sb_info *sbi = EXT3_SB(sb);
2554 +       unsigned long long free_blocks, root_blocks;
2555 +       int cond;
2556  
2557         free_blocks = percpu_counter_read_positive(&sbi->s_freeblocks_counter);
2558         root_blocks = le32_to_cpu(sbi->s_es->s_r_blocks_count);
2559 -       if (free_blocks < root_blocks + 1 && !capable(CAP_SYS_RESOURCE) &&
2560 +
2561 +       vxdprintk(VXD_CBIT(dlim, 3),
2562 +               "ext3_has_free_blocks(%p): free=%llu, root=%llu",
2563 +               sb, free_blocks, root_blocks);
2564 +
2565 +       DLIMIT_ADJUST_BLOCK(sb, dx_current_tag(), &free_blocks, &root_blocks);
2566 +
2567 +       cond = (free_blocks < root_blocks + 1 &&
2568 +               !capable(CAP_SYS_RESOURCE) &&
2569                 sbi->s_resuid != current_fsuid() &&
2570 -               (sbi->s_resgid == 0 || !in_group_p (sbi->s_resgid))) {
2571 -               return 0;
2572 -       }
2573 -       return 1;
2574 +               (sbi->s_resgid == 0 || !in_group_p (sbi->s_resgid)));
2575 +
2576 +       vxdprintk(VXD_CBIT(dlim, 3),
2577 +               "ext3_has_free_blocks(%p): %llu<%llu+1, %c, %u!=%u r=%d",
2578 +               sb, free_blocks, root_blocks,
2579 +               !capable(CAP_SYS_RESOURCE)?'1':'0',
2580 +               sbi->s_resuid, current_fsuid(), cond?0:1);
2581 +
2582 +       return (cond ? 0 : 1);
2583  }
2584  
2585  /**
2586 @@ -1443,7 +1462,7 @@ static int ext3_has_free_blocks(struct e
2587   */
2588  int ext3_should_retry_alloc(struct super_block *sb, int *retries)
2589  {
2590 -       if (!ext3_has_free_blocks(EXT3_SB(sb)) || (*retries)++ > 3)
2591 +       if (!ext3_has_free_blocks(sb) || (*retries)++ > 3)
2592                 return 0;
2593  
2594         jbd_debug(1, "%s: retrying operation after ENOSPC\n", sb->s_id);
2595 @@ -1506,6 +1525,8 @@ ext3_fsblk_t ext3_new_blocks(handle_t *h
2596                 *errp = -EDQUOT;
2597                 return 0;
2598         }
2599 +       if (DLIMIT_ALLOC_BLOCK(inode, num))
2600 +           goto out_dlimit;
2601  
2602         sbi = EXT3_SB(sb);
2603         es = EXT3_SB(sb)->s_es;
2604 @@ -1522,7 +1543,7 @@ ext3_fsblk_t ext3_new_blocks(handle_t *h
2605         if (block_i && ((windowsz = block_i->rsv_window_node.rsv_goal_size) > 0))
2606                 my_rsv = &block_i->rsv_window_node;
2607  
2608 -       if (!ext3_has_free_blocks(sbi)) {
2609 +       if (!ext3_has_free_blocks(sb)) {
2610                 *errp = -ENOSPC;
2611                 goto out;
2612         }
2613 @@ -1715,12 +1736,16 @@ allocated:
2614         *errp = 0;
2615         brelse(bitmap_bh);
2616         DQUOT_FREE_BLOCK(inode, *count-num);
2617 +       DLIMIT_FREE_BLOCK(inode, *count-num);
2618         *count = num;
2619         return ret_block;
2620  
2621  io_error:
2622         *errp = -EIO;
2623  out:
2624 +       if (!performed_allocation)
2625 +               DLIMIT_FREE_BLOCK(inode, *count);
2626 +out_dlimit:
2627         if (fatal) {
2628                 *errp = fatal;
2629                 ext3_std_error(sb, fatal);
2630 diff -NurpP --minimal linux-2.6.29/fs/ext3/file.c linux-2.6.29-vs2.3.0.36.9-pre3/fs/ext3/file.c
2631 --- linux-2.6.29/fs/ext3/file.c 2008-12-25 00:26:37.000000000 +0100
2632 +++ linux-2.6.29-vs2.3.0.36.9-pre3/fs/ext3/file.c       2009-02-22 22:54:25.000000000 +0100
2633 @@ -135,5 +135,6 @@ const struct inode_operations ext3_file_
2634  #endif
2635         .permission     = ext3_permission,
2636         .fiemap         = ext3_fiemap,
2637 +       .sync_flags     = ext3_sync_flags,
2638  };
2639  
2640 diff -NurpP --minimal linux-2.6.29/fs/ext3/ialloc.c linux-2.6.29-vs2.3.0.36.9-pre3/fs/ext3/ialloc.c
2641 --- linux-2.6.29/fs/ext3/ialloc.c       2009-03-24 14:22:25.000000000 +0100
2642 +++ linux-2.6.29-vs2.3.0.36.9-pre3/fs/ext3/ialloc.c     2009-03-24 15:44:06.000000000 +0100
2643 @@ -23,6 +23,8 @@
2644  #include <linux/buffer_head.h>
2645  #include <linux/random.h>
2646  #include <linux/bitops.h>
2647 +#include <linux/vs_dlimit.h>
2648 +#include <linux/vs_tag.h>
2649  
2650  #include <asm/byteorder.h>
2651  
2652 @@ -127,6 +129,7 @@ void ext3_free_inode (handle_t *handle, 
2653         ext3_xattr_delete_inode(handle, inode);
2654         DQUOT_FREE_INODE(inode);
2655         DQUOT_DROP(inode);
2656 +       DLIMIT_FREE_INODE(inode);
2657  
2658         is_directory = S_ISDIR(inode->i_mode);
2659  
2660 @@ -440,6 +443,12 @@ struct inode *ext3_new_inode(handle_t *h
2661         inode = new_inode(sb);
2662         if (!inode)
2663                 return ERR_PTR(-ENOMEM);
2664 +
2665 +       inode->i_tag = dx_current_fstag(sb);
2666 +       if (DLIMIT_ALLOC_INODE(inode)) {
2667 +               err = -ENOSPC;
2668 +               goto out_dlimit;
2669 +       }
2670         ei = EXT3_I(inode);
2671  
2672         sbi = EXT3_SB(sb);
2673 @@ -613,6 +622,8 @@ got:
2674  fail:
2675         ext3_std_error(sb, err);
2676  out:
2677 +       DLIMIT_FREE_INODE(inode);
2678 +out_dlimit:
2679         iput(inode);
2680         ret = ERR_PTR(err);
2681  really_out:
2682 @@ -624,6 +635,7 @@ fail_free_drop:
2683  
2684  fail_drop:
2685         DQUOT_DROP(inode);
2686 +       DLIMIT_FREE_INODE(inode);
2687         inode->i_flags |= S_NOQUOTA;
2688         inode->i_nlink = 0;
2689         unlock_new_inode(inode);
2690 diff -NurpP --minimal linux-2.6.29/fs/ext3/inode.c linux-2.6.29-vs2.3.0.36.9-pre3/fs/ext3/inode.c
2691 --- linux-2.6.29/fs/ext3/inode.c        2009-03-24 14:22:25.000000000 +0100
2692 +++ linux-2.6.29-vs2.3.0.36.9-pre3/fs/ext3/inode.c      2009-03-24 15:44:29.000000000 +0100
2693 @@ -38,6 +38,7 @@
2694  #include <linux/bio.h>
2695  #include <linux/fiemap.h>
2696  #include <linux/namei.h>
2697 +#include <linux/vs_tag.h>
2698  #include "xattr.h"
2699  #include "acl.h"
2700  
2701 @@ -2288,7 +2289,7 @@ static void ext3_free_branches(handle_t 
2702  
2703  int ext3_can_truncate(struct inode *inode)
2704  {
2705 -       if (IS_APPEND(inode) || IS_IMMUTABLE(inode))
2706 +       if (IS_APPEND(inode) || IS_IXORUNLINK(inode))
2707                 return 0;
2708         if (S_ISREG(inode->i_mode))
2709                 return 1;
2710 @@ -2662,36 +2663,84 @@ void ext3_set_inode_flags(struct inode *
2711  {
2712         unsigned int flags = EXT3_I(inode)->i_flags;
2713  
2714 -       inode->i_flags &= ~(S_SYNC|S_APPEND|S_IMMUTABLE|S_NOATIME|S_DIRSYNC);
2715 +       inode->i_flags &= ~(S_IMMUTABLE | S_IXUNLINK |
2716 +               S_SYNC | S_APPEND | S_NOATIME | S_DIRSYNC);
2717 +
2718 +       if (flags & EXT3_IMMUTABLE_FL)
2719 +               inode->i_flags |= S_IMMUTABLE;
2720 +       if (flags & EXT3_IXUNLINK_FL)
2721 +               inode->i_flags |= S_IXUNLINK;
2722 +
2723         if (flags & EXT3_SYNC_FL)
2724                 inode->i_flags |= S_SYNC;
2725         if (flags & EXT3_APPEND_FL)
2726                 inode->i_flags |= S_APPEND;
2727 -       if (flags & EXT3_IMMUTABLE_FL)
2728 -               inode->i_flags |= S_IMMUTABLE;
2729         if (flags & EXT3_NOATIME_FL)
2730                 inode->i_flags |= S_NOATIME;
2731         if (flags & EXT3_DIRSYNC_FL)
2732                 inode->i_flags |= S_DIRSYNC;
2733 +
2734 +       inode->i_vflags &= ~(V_BARRIER | V_COW);
2735 +
2736 +       if (flags & EXT3_BARRIER_FL)
2737 +               inode->i_vflags |= V_BARRIER;
2738 +       if (flags & EXT3_COW_FL)
2739 +               inode->i_vflags |= V_COW;
2740  }
2741  
2742  /* Propagate flags from i_flags to EXT3_I(inode)->i_flags */
2743  void ext3_get_inode_flags(struct ext3_inode_info *ei)
2744  {
2745         unsigned int flags = ei->vfs_inode.i_flags;
2746 +       unsigned int vflags = ei->vfs_inode.i_vflags;
2747 +
2748 +       ei->i_flags &= ~(EXT3_SYNC_FL | EXT3_APPEND_FL |
2749 +                       EXT3_IMMUTABLE_FL | EXT3_IXUNLINK_FL |
2750 +                       EXT3_NOATIME_FL | EXT3_DIRSYNC_FL |
2751 +                       EXT3_BARRIER_FL | EXT3_COW_FL);
2752 +
2753 +       if (flags & S_IMMUTABLE)
2754 +               ei->i_flags |= EXT3_IMMUTABLE_FL;
2755 +       if (flags & S_IXUNLINK)
2756 +               ei->i_flags |= EXT3_IXUNLINK_FL;
2757  
2758 -       ei->i_flags &= ~(EXT3_SYNC_FL|EXT3_APPEND_FL|
2759 -                       EXT3_IMMUTABLE_FL|EXT3_NOATIME_FL|EXT3_DIRSYNC_FL);
2760         if (flags & S_SYNC)
2761                 ei->i_flags |= EXT3_SYNC_FL;
2762         if (flags & S_APPEND)
2763                 ei->i_flags |= EXT3_APPEND_FL;
2764 -       if (flags & S_IMMUTABLE)
2765 -               ei->i_flags |= EXT3_IMMUTABLE_FL;
2766         if (flags & S_NOATIME)
2767                 ei->i_flags |= EXT3_NOATIME_FL;
2768         if (flags & S_DIRSYNC)
2769                 ei->i_flags |= EXT3_DIRSYNC_FL;
2770 +
2771 +       if (vflags & V_BARRIER)
2772 +               ei->i_flags |= EXT3_BARRIER_FL;
2773 +       if (vflags & V_COW)
2774 +               ei->i_flags |= EXT3_COW_FL;
2775 +}
2776 +
2777 +int ext3_sync_flags(struct inode *inode)
2778 +{
2779 +       struct ext3_iloc iloc;
2780 +       handle_t *handle;
2781 +       int err;
2782 +
2783 +       handle = ext3_journal_start(inode, 1);
2784 +       if (IS_ERR(handle))
2785 +               return PTR_ERR(handle);
2786 +       if (IS_SYNC(inode))
2787 +               handle->h_sync = 1;
2788 +       err = ext3_reserve_inode_write(handle, inode, &iloc);
2789 +       if (err)
2790 +               goto flags_err;
2791 +
2792 +       ext3_get_inode_flags(EXT3_I(inode));
2793 +       inode->i_ctime = CURRENT_TIME;
2794 +
2795 +       err = ext3_mark_iloc_dirty(handle, inode, &iloc);
2796 +flags_err:
2797 +       ext3_journal_stop(handle);
2798 +       return err;
2799  }
2800  
2801  struct inode *ext3_iget(struct super_block *sb, unsigned long ino)
2802 @@ -2703,6 +2752,8 @@ struct inode *ext3_iget(struct super_blo
2803         struct inode *inode;
2804         long ret;
2805         int block;
2806 +       uid_t uid;
2807 +       gid_t gid;
2808  
2809         inode = iget_locked(sb, ino);
2810         if (!inode)
2811 @@ -2723,12 +2774,17 @@ struct inode *ext3_iget(struct super_blo
2812         bh = iloc.bh;
2813         raw_inode = ext3_raw_inode(&iloc);
2814         inode->i_mode = le16_to_cpu(raw_inode->i_mode);
2815 -       inode->i_uid = (uid_t)le16_to_cpu(raw_inode->i_uid_low);
2816 -       inode->i_gid = (gid_t)le16_to_cpu(raw_inode->i_gid_low);
2817 +       uid = (uid_t)le16_to_cpu(raw_inode->i_uid_low);
2818 +       gid = (gid_t)le16_to_cpu(raw_inode->i_gid_low);
2819         if(!(test_opt (inode->i_sb, NO_UID32))) {
2820 -               inode->i_uid |= le16_to_cpu(raw_inode->i_uid_high) << 16;
2821 -               inode->i_gid |= le16_to_cpu(raw_inode->i_gid_high) << 16;
2822 +               uid |= le16_to_cpu(raw_inode->i_uid_high) << 16;
2823 +               gid |= le16_to_cpu(raw_inode->i_gid_high) << 16;
2824         }
2825 +       inode->i_uid = INOTAG_UID(DX_TAG(inode), uid, gid);
2826 +       inode->i_gid = INOTAG_GID(DX_TAG(inode), uid, gid);
2827 +       inode->i_tag = INOTAG_TAG(DX_TAG(inode), uid, gid,
2828 +               le16_to_cpu(raw_inode->i_raw_tag));
2829 +
2830         inode->i_nlink = le16_to_cpu(raw_inode->i_links_count);
2831         inode->i_size = le32_to_cpu(raw_inode->i_size);
2832         inode->i_atime.tv_sec = (signed)le32_to_cpu(raw_inode->i_atime);
2833 @@ -2859,6 +2915,8 @@ static int ext3_do_update_inode(handle_t
2834         struct ext3_inode *raw_inode = ext3_raw_inode(iloc);
2835         struct ext3_inode_info *ei = EXT3_I(inode);
2836         struct buffer_head *bh = iloc->bh;
2837 +       uid_t uid = TAGINO_UID(DX_TAG(inode), inode->i_uid, inode->i_tag);
2838 +       gid_t gid = TAGINO_GID(DX_TAG(inode), inode->i_gid, inode->i_tag);
2839         int err = 0, rc, block;
2840  
2841         /* For fields not not tracking in the in-memory inode,
2842 @@ -2869,29 +2927,32 @@ static int ext3_do_update_inode(handle_t
2843         ext3_get_inode_flags(ei);
2844         raw_inode->i_mode = cpu_to_le16(inode->i_mode);
2845         if(!(test_opt(inode->i_sb, NO_UID32))) {
2846 -               raw_inode->i_uid_low = cpu_to_le16(low_16_bits(inode->i_uid));
2847 -               raw_inode->i_gid_low = cpu_to_le16(low_16_bits(inode->i_gid));
2848 +               raw_inode->i_uid_low = cpu_to_le16(low_16_bits(uid));
2849 +               raw_inode->i_gid_low = cpu_to_le16(low_16_bits(gid));
2850  /*
2851   * Fix up interoperability with old kernels. Otherwise, old inodes get
2852   * re-used with the upper 16 bits of the uid/gid intact
2853   */
2854                 if(!ei->i_dtime) {
2855                         raw_inode->i_uid_high =
2856 -                               cpu_to_le16(high_16_bits(inode->i_uid));
2857 +                               cpu_to_le16(high_16_bits(uid));
2858                         raw_inode->i_gid_high =
2859 -                               cpu_to_le16(high_16_bits(inode->i_gid));
2860 +                               cpu_to_le16(high_16_bits(gid));
2861                 } else {
2862                         raw_inode->i_uid_high = 0;
2863                         raw_inode->i_gid_high = 0;
2864                 }
2865         } else {
2866                 raw_inode->i_uid_low =
2867 -                       cpu_to_le16(fs_high2lowuid(inode->i_uid));
2868 +                       cpu_to_le16(fs_high2lowuid(uid));
2869                 raw_inode->i_gid_low =
2870 -                       cpu_to_le16(fs_high2lowgid(inode->i_gid));
2871 +                       cpu_to_le16(fs_high2lowgid(gid));
2872                 raw_inode->i_uid_high = 0;
2873                 raw_inode->i_gid_high = 0;
2874         }
2875 +#ifdef CONFIG_TAGGING_INTERN
2876 +       raw_inode->i_raw_tag = cpu_to_le16(inode->i_tag);
2877 +#endif
2878         raw_inode->i_links_count = cpu_to_le16(inode->i_nlink);
2879         raw_inode->i_size = cpu_to_le32(ei->i_disksize);
2880         raw_inode->i_atime = cpu_to_le32(inode->i_atime.tv_sec);
2881 @@ -3044,7 +3105,8 @@ int ext3_setattr(struct dentry *dentry, 
2882                 return error;
2883  
2884         if ((ia_valid & ATTR_UID && attr->ia_uid != inode->i_uid) ||
2885 -               (ia_valid & ATTR_GID && attr->ia_gid != inode->i_gid)) {
2886 +               (ia_valid & ATTR_GID && attr->ia_gid != inode->i_gid) ||
2887 +               (ia_valid & ATTR_TAG && attr->ia_tag != inode->i_tag)) {
2888                 handle_t *handle;
2889  
2890                 /* (user+group)*(old+new) structure, inode write (sb,
2891 @@ -3066,6 +3128,8 @@ int ext3_setattr(struct dentry *dentry, 
2892                         inode->i_uid = attr->ia_uid;
2893                 if (attr->ia_valid & ATTR_GID)
2894                         inode->i_gid = attr->ia_gid;
2895 +               if ((attr->ia_valid & ATTR_TAG) && IS_TAGGED(inode))
2896 +                       inode->i_tag = attr->ia_tag;
2897                 error = ext3_mark_inode_dirty(handle, inode);
2898                 ext3_journal_stop(handle);
2899         }
2900 diff -NurpP --minimal linux-2.6.29/fs/ext3/ioctl.c linux-2.6.29-vs2.3.0.36.9-pre3/fs/ext3/ioctl.c
2901 --- linux-2.6.29/fs/ext3/ioctl.c        2009-03-24 14:22:25.000000000 +0100
2902 +++ linux-2.6.29-vs2.3.0.36.9-pre3/fs/ext3/ioctl.c      2009-03-24 14:48:35.000000000 +0100
2903 @@ -8,6 +8,7 @@
2904   */
2905  
2906  #include <linux/fs.h>
2907 +#include <linux/mount.h>
2908  #include <linux/jbd.h>
2909  #include <linux/capability.h>
2910  #include <linux/ext3_fs.h>
2911 @@ -16,6 +17,7 @@
2912  #include <linux/time.h>
2913  #include <linux/compat.h>
2914  #include <linux/smp_lock.h>
2915 +#include <linux/vs_tag.h>
2916  #include <asm/uaccess.h>
2917  
2918  int ext3_ioctl (struct inode * inode, struct file * filp, unsigned int cmd,
2919 @@ -55,6 +57,11 @@ int ext3_ioctl (struct inode * inode, st
2920  
2921                 flags = ext3_mask_flags(inode->i_mode, flags);
2922  
2923 +               if (IS_BARRIER(inode)) {
2924 +                       vxwprintk_task(1, "messing with the barrier.");
2925 +                       return -EACCES;
2926 +               }
2927 +
2928                 mutex_lock(&inode->i_mutex);
2929                 /* Is it quota file? Do not allow user to mess with it */
2930                 if (IS_NOQUOTA(inode)) {
2931 @@ -73,7 +80,9 @@ int ext3_ioctl (struct inode * inode, st
2932                  *
2933                  * This test looks nicer. Thanks to Pauline Middelink
2934                  */
2935 -               if ((flags ^ oldflags) & (EXT3_APPEND_FL | EXT3_IMMUTABLE_FL)) {
2936 +               if ((oldflags & EXT3_IMMUTABLE_FL) ||
2937 +                       ((flags ^ oldflags) & (EXT3_APPEND_FL |
2938 +                       EXT3_IMMUTABLE_FL | EXT3_IXUNLINK_FL))) {
2939                         if (!capable(CAP_LINUX_IMMUTABLE)) {
2940                                 mutex_unlock(&inode->i_mutex);
2941                                 err = -EPERM;
2942 diff -NurpP --minimal linux-2.6.29/fs/ext3/namei.c linux-2.6.29-vs2.3.0.36.9-pre3/fs/ext3/namei.c
2943 --- linux-2.6.29/fs/ext3/namei.c        2009-03-24 14:22:25.000000000 +0100
2944 +++ linux-2.6.29-vs2.3.0.36.9-pre3/fs/ext3/namei.c      2009-03-24 14:48:35.000000000 +0100
2945 @@ -36,6 +36,7 @@
2946  #include <linux/quotaops.h>
2947  #include <linux/buffer_head.h>
2948  #include <linux/bio.h>
2949 +#include <linux/vs_tag.h>
2950  
2951  #include "namei.h"
2952  #include "xattr.h"
2953 @@ -912,6 +913,7 @@ restart:
2954                                 if (bh)
2955                                         ll_rw_block(READ_META, 1, &bh);
2956                         }
2957 +               dx_propagate_tag(nd, inode);
2958                 }
2959                 if ((bh = bh_use[ra_ptr++]) == NULL)
2960                         goto next;
2961 @@ -2433,6 +2435,7 @@ const struct inode_operations ext3_dir_i
2962         .removexattr    = generic_removexattr,
2963  #endif
2964         .permission     = ext3_permission,
2965 +       .sync_flags     = ext3_sync_flags,
2966  };
2967  
2968  const struct inode_operations ext3_special_inode_operations = {
2969 @@ -2444,4 +2447,5 @@ const struct inode_operations ext3_speci
2970         .removexattr    = generic_removexattr,
2971  #endif
2972         .permission     = ext3_permission,
2973 +       .sync_flags     = ext3_sync_flags,
2974  };
2975 diff -NurpP --minimal linux-2.6.29/fs/ext3/super.c linux-2.6.29-vs2.3.0.36.9-pre3/fs/ext3/super.c
2976 --- linux-2.6.29/fs/ext3/super.c        2009-03-24 14:22:25.000000000 +0100
2977 +++ linux-2.6.29-vs2.3.0.36.9-pre3/fs/ext3/super.c      2009-03-24 14:48:35.000000000 +0100
2978 @@ -790,7 +790,7 @@ enum {
2979         Opt_usrjquota, Opt_grpjquota, Opt_offusrjquota, Opt_offgrpjquota,
2980         Opt_jqfmt_vfsold, Opt_jqfmt_vfsv0, Opt_quota, Opt_noquota,
2981         Opt_ignore, Opt_barrier, Opt_err, Opt_resize, Opt_usrquota,
2982 -       Opt_grpquota
2983 +       Opt_grpquota, Opt_tag, Opt_notag, Opt_tagid
2984  };
2985  
2986  static const match_table_t tokens = {
2987 @@ -843,6 +843,9 @@ static const match_table_t tokens = {
2988         {Opt_usrquota, "usrquota"},
2989         {Opt_barrier, "barrier=%u"},
2990         {Opt_resize, "resize"},
2991 +       {Opt_tag, "tag"},
2992 +       {Opt_notag, "notag"},
2993 +       {Opt_tagid, "tagid=%u"},
2994         {Opt_err, NULL},
2995  };
2996  
2997 @@ -935,6 +938,20 @@ static int parse_options (char *options,
2998                 case Opt_nouid32:
2999                         set_opt (sbi->s_mount_opt, NO_UID32);
3000                         break;
3001 +#ifndef CONFIG_TAGGING_NONE
3002 +               case Opt_tag:
3003 +                       set_opt (sbi->s_mount_opt, TAGGED);
3004 +                       break;
3005 +               case Opt_notag:
3006 +                       clear_opt (sbi->s_mount_opt, TAGGED);
3007 +                       break;
3008 +#endif
3009 +#ifdef CONFIG_PROPAGATE
3010 +               case Opt_tagid:
3011 +                       /* use args[0] */
3012 +                       set_opt (sbi->s_mount_opt, TAGGED);
3013 +                       break;
3014 +#endif
3015                 case Opt_nocheck:
3016                         clear_opt (sbi->s_mount_opt, CHECK);
3017                         break;
3018 @@ -1653,6 +1670,9 @@ static int ext3_fill_super (struct super
3019                             NULL, 0))
3020                 goto failed_mount;
3021  
3022 +       if (EXT3_SB(sb)->s_mount_opt & EXT3_MOUNT_TAGGED)
3023 +               sb->s_flags |= MS_TAGGED;
3024 +
3025         sb->s_flags = (sb->s_flags & ~MS_POSIXACL) |
3026                 ((sbi->s_mount_opt & EXT3_MOUNT_POSIX_ACL) ? MS_POSIXACL : 0);
3027  
3028 @@ -2527,6 +2547,13 @@ static int ext3_remount (struct super_bl
3029         if (sbi->s_mount_opt & EXT3_MOUNT_ABORT)
3030                 ext3_abort(sb, __func__, "Abort forced by user");
3031  
3032 +       if ((sbi->s_mount_opt & EXT3_MOUNT_TAGGED) &&
3033 +               !(sb->s_flags & MS_TAGGED)) {
3034 +               printk("EXT3-fs: %s: tagging not permitted on remount.\n",
3035 +                       sb->s_id);
3036 +               return -EINVAL;
3037 +       }
3038 +
3039         sb->s_flags = (sb->s_flags & ~MS_POSIXACL) |
3040                 ((sbi->s_mount_opt & EXT3_MOUNT_POSIX_ACL) ? MS_POSIXACL : 0);
3041  
3042 diff -NurpP --minimal linux-2.6.29/fs/ext3/symlink.c linux-2.6.29-vs2.3.0.36.9-pre3/fs/ext3/symlink.c
3043 --- linux-2.6.29/fs/ext3/symlink.c      2008-12-25 00:26:37.000000000 +0100
3044 +++ linux-2.6.29-vs2.3.0.36.9-pre3/fs/ext3/symlink.c    2009-02-22 22:54:25.000000000 +0100
3045 @@ -40,6 +40,7 @@ const struct inode_operations ext3_symli
3046         .listxattr      = ext3_listxattr,
3047         .removexattr    = generic_removexattr,
3048  #endif
3049 +       .sync_flags     = ext3_sync_flags,
3050  };
3051  
3052  const struct inode_operations ext3_fast_symlink_inode_operations = {
3053 @@ -51,4 +52,5 @@ const struct inode_operations ext3_fast_
3054         .listxattr      = ext3_listxattr,
3055         .removexattr    = generic_removexattr,
3056  #endif
3057 +       .sync_flags     = ext3_sync_flags,
3058  };
3059 diff -NurpP --minimal linux-2.6.29/fs/ext3/xattr.c linux-2.6.29-vs2.3.0.36.9-pre3/fs/ext3/xattr.c
3060 --- linux-2.6.29/fs/ext3/xattr.c        2008-12-25 00:26:37.000000000 +0100
3061 +++ linux-2.6.29-vs2.3.0.36.9-pre3/fs/ext3/xattr.c      2009-02-22 22:54:25.000000000 +0100
3062 @@ -58,6 +58,7 @@
3063  #include <linux/mbcache.h>
3064  #include <linux/quotaops.h>
3065  #include <linux/rwsem.h>
3066 +#include <linux/vs_dlimit.h>
3067  #include "xattr.h"
3068  #include "acl.h"
3069  
3070 @@ -498,6 +499,7 @@ ext3_xattr_release_block(handle_t *handl
3071                 error = ext3_journal_dirty_metadata(handle, bh);
3072                 if (IS_SYNC(inode))
3073                         handle->h_sync = 1;
3074 +                       DLIMIT_FREE_BLOCK(inode, 1);
3075                 DQUOT_FREE_BLOCK(inode, 1);
3076                 ea_bdebug(bh, "refcount now=%d; releasing",
3077                           le32_to_cpu(BHDR(bh)->h_refcount));
3078 @@ -771,11 +773,14 @@ inserted:
3079                         if (new_bh == bs->bh)
3080                                 ea_bdebug(new_bh, "keeping");
3081                         else {
3082 +                               error = -ENOSPC;
3083 +                               if (DLIMIT_ALLOC_BLOCK(inode, 1))
3084 +                                       goto cleanup;
3085                                 /* The old block is released after updating
3086                                    the inode. */
3087                                 error = -EDQUOT;
3088                                 if (DQUOT_ALLOC_BLOCK(inode, 1))
3089 -                                       goto cleanup;
3090 +                                       goto cleanup_dlimit;
3091                                 error = ext3_journal_get_write_access(handle,
3092                                                                       new_bh);
3093                                 if (error)
3094 @@ -849,6 +854,8 @@ cleanup:
3095  
3096  cleanup_dquot:
3097         DQUOT_FREE_BLOCK(inode, 1);
3098 +cleanup_dlimit:
3099 +       DLIMIT_FREE_BLOCK(inode, 1);
3100         goto cleanup;
3101  
3102  bad_block:
3103 diff -NurpP --minimal linux-2.6.29/fs/ext4/balloc.c linux-2.6.29-vs2.3.0.36.9-pre3/fs/ext4/balloc.c
3104 --- linux-2.6.29/fs/ext4/balloc.c       2009-03-24 14:22:25.000000000 +0100
3105 +++ linux-2.6.29-vs2.3.0.36.9-pre3/fs/ext4/balloc.c     2009-03-24 14:48:35.000000000 +0100
3106 @@ -17,6 +17,8 @@
3107  #include <linux/jbd2.h>
3108  #include <linux/quotaops.h>
3109  #include <linux/buffer_head.h>
3110 +#include <linux/vs_dlimit.h>
3111 +#include <linux/vs_tag.h>
3112  #include "ext4.h"
3113  #include "ext4_jbd2.h"
3114  #include "group.h"
3115 @@ -535,8 +537,10 @@ void ext4_free_blocks(handle_t *handle, 
3116  
3117         ext4_mb_free_blocks(handle, inode, block, count,
3118                             metadata, &dquot_freed_blocks);
3119 -       if (dquot_freed_blocks)
3120 +       if (dquot_freed_blocks) {
3121 +               DLIMIT_FREE_BLOCK(inode, dquot_freed_blocks);
3122                 DQUOT_FREE_BLOCK(inode, dquot_freed_blocks);
3123 +       }
3124         return;
3125  }
3126  
3127 diff -NurpP --minimal linux-2.6.29/fs/ext4/ext4.h linux-2.6.29-vs2.3.0.36.9-pre3/fs/ext4/ext4.h
3128 --- linux-2.6.29/fs/ext4/ext4.h 2009-03-24 14:22:25.000000000 +0100
3129 +++ linux-2.6.29-vs2.3.0.36.9-pre3/fs/ext4/ext4.h       2009-03-24 15:44:56.000000000 +0100
3130 @@ -243,8 +243,12 @@ struct flex_groups {
3131  #define EXT4_HUGE_FILE_FL               0x00040000 /* Set to each huge file */
3132  #define EXT4_EXTENTS_FL                        0x00080000 /* Inode uses extents */
3133  #define EXT4_EXT_MIGRATE               0x00100000 /* Inode is migrating */
3134 +#define EXT4_IXUNLINK_FL               0x08000000 /* Immutable invert on unlink */
3135  #define EXT4_RESERVED_FL               0x80000000 /* reserved for ext4 lib */
3136  
3137 +#define EXT4_BARRIER_FL                        0x04000000 /* Barrier for chroot() */
3138 +#define EXT4_COW_FL                    0x20000000 /* Copy on Write marker */
3139 +
3140  #define EXT4_FL_USER_VISIBLE           0x000BDFFF /* User visible flags */
3141  #define EXT4_FL_USER_MODIFIABLE                0x000B80FF /* User modifiable flags */
3142  
3143 @@ -541,6 +545,7 @@ do {                                                                               \
3144  #define EXT4_MOUNT_I_VERSION            0x2000000 /* i_version support */
3145  #define EXT4_MOUNT_DELALLOC            0x8000000 /* Delalloc support */
3146  #define EXT4_MOUNT_DATA_ERR_ABORT      0x10000000 /* Abort on file data write */
3147 +#define EXT4_MOUNT_TAGGED              (1<<24) /* Enable Context Tags */
3148  
3149  /* Compatibility, for having both ext2_fs.h and ext4_fs.h included at once */
3150  #ifndef _LINUX_EXT2_FS_H
3151 @@ -1076,6 +1081,7 @@ struct buffer_head *ext4_bread(handle_t 
3152                                                 ext4_lblk_t, int, int *);
3153  int ext4_get_block(struct inode *inode, sector_t iblock,
3154                                 struct buffer_head *bh_result, int create);
3155 +extern int ext4_sync_flags(struct inode *inode);
3156  
3157  extern struct inode *ext4_iget(struct super_block *, unsigned long);
3158  extern int  ext4_write_inode(struct inode *, int);
3159 diff -NurpP --minimal linux-2.6.29/fs/ext4/file.c linux-2.6.29-vs2.3.0.36.9-pre3/fs/ext4/file.c
3160 --- linux-2.6.29/fs/ext4/file.c 2009-03-24 14:22:25.000000000 +0100
3161 +++ linux-2.6.29-vs2.3.0.36.9-pre3/fs/ext4/file.c       2009-03-24 14:48:35.000000000 +0100
3162 @@ -171,5 +171,6 @@ const struct inode_operations ext4_file_
3163         .permission     = ext4_permission,
3164         .fallocate      = ext4_fallocate,
3165         .fiemap         = ext4_fiemap,
3166 +       .sync_flags     = ext4_sync_flags,
3167  };
3168  
3169 diff -NurpP --minimal linux-2.6.29/fs/ext4/ialloc.c linux-2.6.29-vs2.3.0.36.9-pre3/fs/ext4/ialloc.c
3170 --- linux-2.6.29/fs/ext4/ialloc.c       2009-03-24 14:22:25.000000000 +0100
3171 +++ linux-2.6.29-vs2.3.0.36.9-pre3/fs/ext4/ialloc.c     2009-03-24 14:48:35.000000000 +0100
3172 @@ -22,6 +22,8 @@
3173  #include <linux/random.h>
3174  #include <linux/bitops.h>
3175  #include <linux/blkdev.h>
3176 +#include <linux/vs_dlimit.h>
3177 +#include <linux/vs_tag.h>
3178  #include <asm/byteorder.h>
3179  #include "ext4.h"
3180  #include "ext4_jbd2.h"
3181 @@ -224,6 +226,7 @@ void ext4_free_inode(handle_t *handle, s
3182         ext4_xattr_delete_inode(handle, inode);
3183         DQUOT_FREE_INODE(inode);
3184         DQUOT_DROP(inode);
3185 +       DLIMIT_FREE_INODE(inode);
3186  
3187         is_directory = S_ISDIR(inode->i_mode);
3188  
3189 @@ -711,6 +714,12 @@ struct inode *ext4_new_inode(handle_t *h
3190         inode = new_inode(sb);
3191         if (!inode)
3192                 return ERR_PTR(-ENOMEM);
3193 +
3194 +       inode->i_tag = dx_current_fstag(sb);
3195 +       if (DLIMIT_ALLOC_INODE(inode)) {
3196 +               err = -ENOSPC;
3197 +               goto out_dlimit;
3198 +       }
3199         ei = EXT4_I(inode);
3200  
3201         sbi = EXT4_SB(sb);
3202 @@ -889,7 +898,8 @@ got:
3203          * newly created directory and file only if -o extent mount option is
3204          * specified
3205          */
3206 -       ei->i_flags = EXT4_I(dir)->i_flags & ~(EXT4_INDEX_FL|EXT4_EXTENTS_FL);
3207 +       ei->i_flags = EXT4_I(dir)->i_flags &
3208 +               ~(EXT4_INDEX_FL|EXT4_EXTENTS_FL|EXT4_IXUNLINK_FL|EXT4_BARRIER_FL);
3209         if (S_ISLNK(mode))
3210                 ei->i_flags &= ~(EXT4_IMMUTABLE_FL|EXT4_APPEND_FL);
3211         /* dirsync only applies to directories */
3212 @@ -949,6 +959,8 @@ got:
3213  fail:
3214         ext4_std_error(sb, err);
3215  out:
3216 +       DLIMIT_FREE_INODE(inode);
3217 +out_dlimit:
3218         iput(inode);
3219         ret = ERR_PTR(err);
3220  really_out:
3221 @@ -960,6 +972,7 @@ fail_free_drop:
3222  
3223  fail_drop:
3224         DQUOT_DROP(inode);
3225 +       DLIMIT_FREE_INODE(inode);
3226         inode->i_flags |= S_NOQUOTA;
3227         inode->i_nlink = 0;
3228         unlock_new_inode(inode);
3229 diff -NurpP --minimal linux-2.6.29/fs/ext4/inode.c linux-2.6.29-vs2.3.0.36.9-pre3/fs/ext4/inode.c
3230 --- linux-2.6.29/fs/ext4/inode.c        2009-03-24 14:22:25.000000000 +0100
3231 +++ linux-2.6.29-vs2.3.0.36.9-pre3/fs/ext4/inode.c      2009-03-24 14:48:35.000000000 +0100
3232 @@ -37,6 +37,7 @@
3233  #include <linux/namei.h>
3234  #include <linux/uio.h>
3235  #include <linux/bio.h>
3236 +#include <linux/vs_tag.h>
3237  #include "ext4_jbd2.h"
3238  #include "xattr.h"
3239  #include "acl.h"
3240 @@ -3781,7 +3782,7 @@ static void ext4_free_branches(handle_t 
3241  
3242  int ext4_can_truncate(struct inode *inode)
3243  {
3244 -       if (IS_APPEND(inode) || IS_IMMUTABLE(inode))
3245 +       if (IS_APPEND(inode) || IS_IXORUNLINK(inode))
3246                 return 0;
3247         if (S_ISREG(inode->i_mode))
3248                 return 1;
3249 @@ -4134,37 +4135,86 @@ void ext4_set_inode_flags(struct inode *
3250  {
3251         unsigned int flags = EXT4_I(inode)->i_flags;
3252  
3253 -       inode->i_flags &= ~(S_SYNC|S_APPEND|S_IMMUTABLE|S_NOATIME|S_DIRSYNC);
3254 +       inode->i_flags &= ~(S_IMMUTABLE | S_IXUNLINK |
3255 +               S_SYNC | S_APPEND | S_NOATIME | S_DIRSYNC);
3256 +
3257 +       if (flags & EXT4_IMMUTABLE_FL)
3258 +               inode->i_flags |= S_IMMUTABLE;
3259 +       if (flags & EXT4_IXUNLINK_FL)
3260 +               inode->i_flags |= S_IXUNLINK;
3261 +
3262         if (flags & EXT4_SYNC_FL)
3263                 inode->i_flags |= S_SYNC;
3264         if (flags & EXT4_APPEND_FL)
3265                 inode->i_flags |= S_APPEND;
3266 -       if (flags & EXT4_IMMUTABLE_FL)
3267 -               inode->i_flags |= S_IMMUTABLE;
3268         if (flags & EXT4_NOATIME_FL)
3269                 inode->i_flags |= S_NOATIME;
3270         if (flags & EXT4_DIRSYNC_FL)
3271                 inode->i_flags |= S_DIRSYNC;
3272 +
3273 +       inode->i_vflags &= ~(V_BARRIER | V_COW);
3274 +
3275 +       if (flags & EXT4_BARRIER_FL)
3276 +               inode->i_vflags |= V_BARRIER;
3277 +       if (flags & EXT4_COW_FL)
3278 +               inode->i_vflags |= V_COW;
3279  }
3280  
3281  /* Propagate flags from i_flags to EXT4_I(inode)->i_flags */
3282  void ext4_get_inode_flags(struct ext4_inode_info *ei)
3283  {
3284         unsigned int flags = ei->vfs_inode.i_flags;
3285 +       unsigned int vflags = ei->vfs_inode.i_vflags;
3286 +
3287 +       ei->i_flags &= ~(EXT4_SYNC_FL | EXT4_APPEND_FL |
3288 +                       EXT4_IMMUTABLE_FL | EXT4_IXUNLINK_FL |
3289 +                       EXT4_NOATIME_FL | EXT4_DIRSYNC_FL |
3290 +                       EXT4_BARRIER_FL | EXT4_COW_FL);
3291 +
3292 +       if (flags & S_IMMUTABLE)
3293 +               ei->i_flags |= EXT4_IMMUTABLE_FL;
3294 +       if (flags & S_IXUNLINK)
3295 +               ei->i_flags |= EXT4_IXUNLINK_FL;
3296  
3297 -       ei->i_flags &= ~(EXT4_SYNC_FL|EXT4_APPEND_FL|
3298 -                       EXT4_IMMUTABLE_FL|EXT4_NOATIME_FL|EXT4_DIRSYNC_FL);
3299         if (flags & S_SYNC)
3300                 ei->i_flags |= EXT4_SYNC_FL;
3301         if (flags & S_APPEND)
3302                 ei->i_flags |= EXT4_APPEND_FL;
3303 -       if (flags & S_IMMUTABLE)
3304 -               ei->i_flags |= EXT4_IMMUTABLE_FL;
3305         if (flags & S_NOATIME)
3306                 ei->i_flags |= EXT4_NOATIME_FL;
3307         if (flags & S_DIRSYNC)
3308                 ei->i_flags |= EXT4_DIRSYNC_FL;
3309 +
3310 +       if (vflags & V_BARRIER)
3311 +               ei->i_flags |= EXT4_BARRIER_FL;
3312 +       if (vflags & V_COW)
3313 +               ei->i_flags |= EXT4_COW_FL;
3314 +}
3315 +
3316 +int ext4_sync_flags(struct inode *inode)
3317 +{
3318 +       struct ext4_iloc iloc;
3319 +       handle_t *handle;
3320 +       int err;
3321 +
3322 +       handle = ext4_journal_start(inode, 1);
3323 +       if (IS_ERR(handle))
3324 +               return PTR_ERR(handle);
3325 +       if (IS_SYNC(inode))
3326 +               handle->h_sync = 1;
3327 +       err = ext4_reserve_inode_write(handle, inode, &iloc);
3328 +       if (err)
3329 +               goto flags_err;
3330 +
3331 +       ext4_get_inode_flags(EXT4_I(inode));
3332 +       inode->i_ctime = CURRENT_TIME;
3333 +
3334 +       err = ext4_mark_iloc_dirty(handle, inode, &iloc);
3335 +flags_err:
3336 +       ext4_journal_stop(handle);
3337 +       return err;
3338  }
3339 +
3340  static blkcnt_t ext4_inode_blocks(struct ext4_inode *raw_inode,
3341                                         struct ext4_inode_info *ei)
3342  {
3343 @@ -4197,6 +4247,8 @@ struct inode *ext4_iget(struct super_blo
3344         struct inode *inode;
3345         long ret;
3346         int block;
3347 +       uid_t uid;
3348 +       gid_t gid;
3349  
3350         inode = iget_locked(sb, ino);
3351         if (!inode)
3352 @@ -4216,12 +4268,16 @@ struct inode *ext4_iget(struct super_blo
3353         bh = iloc.bh;
3354         raw_inode = ext4_raw_inode(&iloc);
3355         inode->i_mode = le16_to_cpu(raw_inode->i_mode);
3356 -       inode->i_uid = (uid_t)le16_to_cpu(raw_inode->i_uid_low);
3357 -       inode->i_gid = (gid_t)le16_to_cpu(raw_inode->i_gid_low);
3358 +       uid = (uid_t)le16_to_cpu(raw_inode->i_uid_low);
3359 +       gid = (gid_t)le16_to_cpu(raw_inode->i_gid_low);
3360         if (!(test_opt(inode->i_sb, NO_UID32))) {
3361 -               inode->i_uid |= le16_to_cpu(raw_inode->i_uid_high) << 16;
3362 -               inode->i_gid |= le16_to_cpu(raw_inode->i_gid_high) << 16;
3363 +               uid |= le16_to_cpu(raw_inode->i_uid_high) << 16;
3364 +               gid |= le16_to_cpu(raw_inode->i_gid_high) << 16;
3365         }
3366 +       inode->i_uid = INOTAG_UID(DX_TAG(inode), uid, gid);
3367 +       inode->i_gid = INOTAG_GID(DX_TAG(inode), uid, gid);
3368 +       inode->i_tag = INOTAG_TAG(DX_TAG(inode), uid, gid,
3369 +               le16_to_cpu(raw_inode->i_raw_tag));
3370         inode->i_nlink = le16_to_cpu(raw_inode->i_links_count);
3371  
3372         ei->i_state = 0;
3373 @@ -4387,6 +4443,8 @@ static int ext4_do_update_inode(handle_t
3374         struct ext4_inode *raw_inode = ext4_raw_inode(iloc);
3375         struct ext4_inode_info *ei = EXT4_I(inode);
3376         struct buffer_head *bh = iloc->bh;
3377 +       uid_t uid = TAGINO_UID(DX_TAG(inode), inode->i_uid, inode->i_tag);
3378 +       gid_t gid = TAGINO_GID(DX_TAG(inode), inode->i_gid, inode->i_tag);
3379         int err = 0, rc, block;
3380  
3381         /* For fields not not tracking in the in-memory inode,
3382 @@ -4397,29 +4455,32 @@ static int ext4_do_update_inode(handle_t
3383         ext4_get_inode_flags(ei);
3384         raw_inode->i_mode = cpu_to_le16(inode->i_mode);
3385         if (!(test_opt(inode->i_sb, NO_UID32))) {
3386 -               raw_inode->i_uid_low = cpu_to_le16(low_16_bits(inode->i_uid));
3387 -               raw_inode->i_gid_low = cpu_to_le16(low_16_bits(inode->i_gid));
3388 +               raw_inode->i_uid_low = cpu_to_le16(low_16_bits(uid));
3389 +               raw_inode->i_gid_low = cpu_to_le16(low_16_bits(gid));
3390  /*
3391   * Fix up interoperability with old kernels. Otherwise, old inodes get
3392   * re-used with the upper 16 bits of the uid/gid intact
3393   */
3394                 if (!ei->i_dtime) {
3395                         raw_inode->i_uid_high =
3396 -                               cpu_to_le16(high_16_bits(inode->i_uid));
3397 +                               cpu_to_le16(high_16_bits(uid));
3398                         raw_inode->i_gid_high =
3399 -                               cpu_to_le16(high_16_bits(inode->i_gid));
3400 +                               cpu_to_le16(high_16_bits(gid));
3401                 } else {
3402                         raw_inode->i_uid_high = 0;
3403                         raw_inode->i_gid_high = 0;
3404                 }
3405         } else {
3406                 raw_inode->i_uid_low =
3407 -                       cpu_to_le16(fs_high2lowuid(inode->i_uid));
3408 +                       cpu_to_le16(fs_high2lowuid(uid));
3409                 raw_inode->i_gid_low =
3410 -                       cpu_to_le16(fs_high2lowgid(inode->i_gid));
3411 +                       cpu_to_le16(fs_high2lowgid(gid));
3412                 raw_inode->i_uid_high = 0;
3413                 raw_inode->i_gid_high = 0;
3414         }
3415 +#ifdef CONFIG_TAGGING_INTERN
3416 +       raw_inode->i_raw_tag = cpu_to_le16(inode->i_tag);
3417 +#endif
3418         raw_inode->i_links_count = cpu_to_le16(inode->i_nlink);
3419  
3420         EXT4_INODE_SET_XTIME(i_ctime, inode, raw_inode);
3421 @@ -4601,7 +4662,8 @@ int ext4_setattr(struct dentry *dentry, 
3422                 return error;
3423  
3424         if ((ia_valid & ATTR_UID && attr->ia_uid != inode->i_uid) ||
3425 -               (ia_valid & ATTR_GID && attr->ia_gid != inode->i_gid)) {
3426 +               (ia_valid & ATTR_GID && attr->ia_gid != inode->i_gid) ||
3427 +               (ia_valid & ATTR_TAG && attr->ia_tag != inode->i_tag)) {
3428                 handle_t *handle;
3429  
3430                 /* (user+group)*(old+new) structure, inode write (sb,
3431 @@ -4623,6 +4685,8 @@ int ext4_setattr(struct dentry *dentry, 
3432                         inode->i_uid = attr->ia_uid;
3433                 if (attr->ia_valid & ATTR_GID)
3434                         inode->i_gid = attr->ia_gid;
3435 +               if ((attr->ia_valid & ATTR_TAG) && IS_TAGGED(inode))
3436 +                       inode->i_tag = attr->ia_tag;
3437                 error = ext4_mark_inode_dirty(handle, inode);
3438                 ext4_journal_stop(handle);
3439         }
3440 diff -NurpP --minimal linux-2.6.29/fs/ext4/ioctl.c linux-2.6.29-vs2.3.0.36.9-pre3/fs/ext4/ioctl.c
3441 --- linux-2.6.29/fs/ext4/ioctl.c        2009-03-24 14:22:25.000000000 +0100
3442 +++ linux-2.6.29-vs2.3.0.36.9-pre3/fs/ext4/ioctl.c      2009-03-24 14:48:35.000000000 +0100
3443 @@ -8,12 +8,14 @@
3444   */
3445  
3446  #include <linux/fs.h>
3447 +#include <linux/mount.h>
3448  #include <linux/jbd2.h>
3449  #include <linux/capability.h>
3450  #include <linux/time.h>
3451  #include <linux/compat.h>
3452  #include <linux/smp_lock.h>
3453  #include <linux/mount.h>
3454 +#include <linux/vs_tag.h>
3455  #include <asm/uaccess.h>
3456  #include "ext4_jbd2.h"
3457  #include "ext4.h"
3458 @@ -51,6 +53,11 @@ long ext4_ioctl(struct file *filp, unsig
3459                 if (!S_ISDIR(inode->i_mode))
3460                         flags &= ~EXT4_DIRSYNC_FL;
3461  
3462 +               if (IS_BARRIER(inode)) {
3463 +                       vxwprintk_task(1, "messing with the barrier.");
3464 +                       return -EACCES;
3465 +               }
3466 +
3467                 err = -EPERM;
3468                 mutex_lock(&inode->i_mutex);
3469                 /* Is it quota file? Do not allow user to mess with it */
3470 @@ -68,7 +75,9 @@ long ext4_ioctl(struct file *filp, unsig
3471                  *
3472                  * This test looks nicer. Thanks to Pauline Middelink
3473                  */
3474 -               if ((flags ^ oldflags) & (EXT4_APPEND_FL | EXT4_IMMUTABLE_FL)) {
3475 +               if ((oldflags & EXT4_IMMUTABLE_FL) ||
3476 +                       ((flags ^ oldflags) & (EXT4_APPEND_FL |
3477 +                       EXT4_IMMUTABLE_FL | EXT4_IXUNLINK_FL))) {
3478                         if (!capable(CAP_LINUX_IMMUTABLE))
3479                                 goto flags_out;
3480                 }
3481 diff -NurpP --minimal linux-2.6.29/fs/ext4/namei.c linux-2.6.29-vs2.3.0.36.9-pre3/fs/ext4/namei.c
3482 --- linux-2.6.29/fs/ext4/namei.c        2009-03-24 14:22:25.000000000 +0100
3483 +++ linux-2.6.29-vs2.3.0.36.9-pre3/fs/ext4/namei.c      2009-03-24 14:48:35.000000000 +0100
3484 @@ -34,6 +34,7 @@
3485  #include <linux/quotaops.h>
3486  #include <linux/buffer_head.h>
3487  #include <linux/bio.h>
3488 +#include <linux/vs_tag.h>
3489  #include "ext4.h"
3490  #include "ext4_jbd2.h"
3491  
3492 @@ -917,6 +918,7 @@ restart:
3493                                 if (bh)
3494                                         ll_rw_block(READ_META, 1, &bh);
3495                         }
3496 +               dx_propagate_tag(nd, inode);
3497                 }
3498                 if ((bh = bh_use[ra_ptr++]) == NULL)
3499                         goto next;
3500 @@ -2481,6 +2483,7 @@ const struct inode_operations ext4_dir_i
3501         .removexattr    = generic_removexattr,
3502  #endif
3503         .permission     = ext4_permission,
3504 +       .sync_flags     = ext4_sync_flags,
3505  };
3506  
3507  const struct inode_operations ext4_special_inode_operations = {
3508 @@ -2492,4 +2495,5 @@ const struct inode_operations ext4_speci
3509         .removexattr    = generic_removexattr,
3510  #endif
3511         .permission     = ext4_permission,
3512 +       .sync_flags     = ext4_sync_flags,
3513  };
3514 diff -NurpP --minimal linux-2.6.29/fs/ext4/super.c linux-2.6.29-vs2.3.0.36.9-pre3/fs/ext4/super.c
3515 --- linux-2.6.29/fs/ext4/super.c        2009-03-24 14:22:25.000000000 +0100
3516 +++ linux-2.6.29-vs2.3.0.36.9-pre3/fs/ext4/super.c      2009-03-24 15:46:48.000000000 +0100
3517 @@ -1013,7 +1013,8 @@ enum {
3518         Opt_ignore, Opt_barrier, Opt_err, Opt_resize, Opt_usrquota,
3519         Opt_grpquota, Opt_i_version,
3520         Opt_stripe, Opt_delalloc, Opt_nodelalloc,
3521 -       Opt_inode_readahead_blks, Opt_journal_ioprio
3522 +       Opt_inode_readahead_blks, Opt_journal_ioprio,
3523 +       Opt_tag, Opt_notag, Opt_tagid
3524  };
3525  
3526  static const match_table_t tokens = {
3527 @@ -1073,6 +1074,9 @@ static const match_table_t tokens = {
3528         {Opt_nodelalloc, "nodelalloc"},
3529         {Opt_inode_readahead_blks, "inode_readahead_blks=%u"},
3530         {Opt_journal_ioprio, "journal_ioprio=%u"},
3531 +       {Opt_tag, "tag"},
3532 +       {Opt_notag, "notag"},
3533 +       {Opt_tagid, "tagid=%u"},
3534         {Opt_err, NULL},
3535  };
3536  
3537 @@ -1168,6 +1172,20 @@ static int parse_options(char *options, 
3538                 case Opt_nouid32:
3539                         set_opt(sbi->s_mount_opt, NO_UID32);
3540                         break;
3541 +#ifndef CONFIG_TAGGING_NONE
3542 +               case Opt_tag:
3543 +                       set_opt (sbi->s_mount_opt, TAGGED);
3544 +                       break;
3545 +               case Opt_notag:
3546 +                       clear_opt (sbi->s_mount_opt, TAGGED);
3547 +                       break;
3548 +#endif
3549 +#ifdef CONFIG_PROPAGATE
3550 +               case Opt_tagid:
3551 +                       /* use args[0] */
3552 +                       set_opt (sbi->s_mount_opt, TAGGED);
3553 +                       break;
3554 +#endif
3555                 case Opt_debug:
3556                         set_opt(sbi->s_mount_opt, DEBUG);
3557                         break;
3558 @@ -2113,6 +2131,9 @@ static int ext4_fill_super(struct super_
3559                            &journal_ioprio, NULL, 0))
3560                 goto failed_mount;
3561  
3562 +       if (EXT4_SB(sb)->s_mount_opt & EXT4_MOUNT_TAGGED)
3563 +               sb->s_flags |= MS_TAGGED;
3564 +
3565         sb->s_flags = (sb->s_flags & ~MS_POSIXACL) |
3566                 ((sbi->s_mount_opt & EXT4_MOUNT_POSIX_ACL) ? MS_POSIXACL : 0);
3567  
3568 @@ -3160,6 +3181,13 @@ static int ext4_remount(struct super_blo
3569         if (sbi->s_mount_opt & EXT4_MOUNT_ABORT)
3570                 ext4_abort(sb, __func__, "Abort forced by user");
3571  
3572 +       if ((sbi->s_mount_opt & EXT4_MOUNT_TAGGED) &&
3573 +               !(sb->s_flags & MS_TAGGED)) {
3574 +               printk("EXT4-fs: %s: tagging not permitted on remount.\n",
3575 +                       sb->s_id);
3576 +               return -EINVAL;
3577 +       }
3578 +
3579         sb->s_flags = (sb->s_flags & ~MS_POSIXACL) |
3580                 ((sbi->s_mount_opt & EXT4_MOUNT_POSIX_ACL) ? MS_POSIXACL : 0);
3581  
3582 diff -NurpP --minimal linux-2.6.29/fs/ext4/symlink.c linux-2.6.29-vs2.3.0.36.9-pre3/fs/ext4/symlink.c
3583 --- linux-2.6.29/fs/ext4/symlink.c      2008-12-25 00:26:37.000000000 +0100
3584 +++ linux-2.6.29-vs2.3.0.36.9-pre3/fs/ext4/symlink.c    2009-02-22 22:54:25.000000000 +0100
3585 @@ -40,6 +40,7 @@ const struct inode_operations ext4_symli
3586         .listxattr      = ext4_listxattr,
3587         .removexattr    = generic_removexattr,
3588  #endif
3589 +       .sync_flags     = ext4_sync_flags,
3590  };
3591  
3592  const struct inode_operations ext4_fast_symlink_inode_operations = {
3593 @@ -51,4 +52,5 @@ const struct inode_operations ext4_fast_
3594         .listxattr      = ext4_listxattr,
3595         .removexattr    = generic_removexattr,
3596  #endif
3597 +       .sync_flags     = ext4_sync_flags,
3598  };
3599 diff -NurpP --minimal linux-2.6.29/fs/ext4/xattr.c linux-2.6.29-vs2.3.0.36.9-pre3/fs/ext4/xattr.c
3600 --- linux-2.6.29/fs/ext4/xattr.c        2009-03-24 14:22:25.000000000 +0100
3601 +++ linux-2.6.29-vs2.3.0.36.9-pre3/fs/ext4/xattr.c      2009-03-24 15:47:44.000000000 +0100
3602 @@ -56,6 +56,7 @@
3603  #include <linux/mbcache.h>
3604  #include <linux/quotaops.h>
3605  #include <linux/rwsem.h>
3606 +#include <linux/vs_dlimit.h>
3607  #include "ext4_jbd2.h"
3608  #include "ext4.h"
3609  #include "xattr.h"
3610 @@ -490,6 +491,7 @@ ext4_xattr_release_block(handle_t *handl
3611                 error = ext4_handle_dirty_metadata(handle, inode, bh);
3612                 if (IS_SYNC(inode))
3613                         ext4_handle_sync(handle);
3614 +               DLIMIT_FREE_BLOCK(inode, 1);
3615                 DQUOT_FREE_BLOCK(inode, 1);
3616                 ea_bdebug(bh, "refcount now=%d; releasing",
3617                           le32_to_cpu(BHDR(bh)->h_refcount));
3618 @@ -781,11 +783,14 @@ inserted:
3619                         if (new_bh == bs->bh)
3620                                 ea_bdebug(new_bh, "keeping");
3621                         else {
3622 +                               error = -ENOSPC;
3623 +                               if (DLIMIT_ALLOC_BLOCK(inode, 1))
3624 +                                       goto cleanup;
3625                                 /* The old block is released after updating
3626                                    the inode. */
3627                                 error = -EDQUOT;
3628                                 if (DQUOT_ALLOC_BLOCK(inode, 1))
3629 -                                       goto cleanup;
3630 +                                       goto cleanup_dlimit;
3631                                 error = ext4_journal_get_write_access(handle,
3632                                                                       new_bh);
3633                                 if (error)
3634 @@ -861,6 +866,8 @@ cleanup:
3635  
3636  cleanup_dquot:
3637         DQUOT_FREE_BLOCK(inode, 1);
3638 +cleanup_dlimit:
3639 +       DLIMIT_FREE_BLOCK(inode, 1);
3640         goto cleanup;
3641  
3642  bad_block:
3643 diff -NurpP --minimal linux-2.6.29/fs/fcntl.c linux-2.6.29-vs2.3.0.36.9-pre3/fs/fcntl.c
3644 --- linux-2.6.29/fs/fcntl.c     2009-03-24 14:22:25.000000000 +0100
3645 +++ linux-2.6.29-vs2.3.0.36.9-pre3/fs/fcntl.c   2009-03-24 14:48:35.000000000 +0100
3646 @@ -20,6 +20,7 @@
3647  #include <linux/rcupdate.h>
3648  #include <linux/pid_namespace.h>
3649  #include <linux/smp_lock.h>
3650 +#include <linux/vs_limit.h>
3651  
3652  #include <asm/poll.h>
3653  #include <asm/siginfo.h>
3654 @@ -103,6 +104,8 @@ SYSCALL_DEFINE3(dup3, unsigned int, oldf
3655  
3656         if (tofree)
3657                 filp_close(tofree, files);
3658 +       else
3659 +               vx_openfd_inc(newfd);   /* fd was unused */
3660  
3661         return newfd;
3662  
3663 @@ -343,6 +346,8 @@ SYSCALL_DEFINE3(fcntl, unsigned int, fd,
3664         filp = fget(fd);
3665         if (!filp)
3666                 goto out;
3667 +       if (!vx_files_avail(1))
3668 +               goto out;
3669  
3670         err = security_file_fcntl(filp, cmd, arg);
3671         if (err) {
3672 diff -NurpP --minimal linux-2.6.29/fs/file.c linux-2.6.29-vs2.3.0.36.9-pre3/fs/file.c
3673 --- linux-2.6.29/fs/file.c      2008-12-25 00:26:37.000000000 +0100
3674 +++ linux-2.6.29-vs2.3.0.36.9-pre3/fs/file.c    2009-02-22 22:54:25.000000000 +0100
3675 @@ -19,6 +19,7 @@
3676  #include <linux/spinlock.h>
3677  #include <linux/rcupdate.h>
3678  #include <linux/workqueue.h>
3679 +#include <linux/vs_limit.h>
3680  
3681  struct fdtable_defer {
3682         spinlock_t lock;
3683 @@ -367,6 +368,8 @@ struct files_struct *dup_fd(struct files
3684                 struct file *f = *old_fds++;
3685                 if (f) {
3686                         get_file(f);
3687 +                       /* TODO: sum it first for check and performance */
3688 +                       vx_openfd_inc(open_files - i);
3689                 } else {
3690                         /*
3691                          * The fd may be claimed in the fd bitmap but not yet
3692 @@ -475,6 +478,7 @@ repeat:
3693         else
3694                 FD_CLR(fd, fdt->close_on_exec);
3695         error = fd;
3696 +       vx_openfd_inc(fd);
3697  #if 1
3698         /* Sanity check */
3699         if (rcu_dereference(fdt->fd[fd]) != NULL) {
3700 diff -NurpP --minimal linux-2.6.29/fs/file_table.c linux-2.6.29-vs2.3.0.36.9-pre3/fs/file_table.c
3701 --- linux-2.6.29/fs/file_table.c        2009-03-24 14:22:25.000000000 +0100
3702 +++ linux-2.6.29-vs2.3.0.36.9-pre3/fs/file_table.c      2009-03-24 14:48:35.000000000 +0100
3703 @@ -21,6 +21,8 @@
3704  #include <linux/fsnotify.h>
3705  #include <linux/sysctl.h>
3706  #include <linux/percpu_counter.h>
3707 +#include <linux/vs_limit.h>
3708 +#include <linux/vs_context.h>
3709  
3710  #include <asm/atomic.h>
3711  
3712 @@ -129,6 +131,8 @@ struct file *get_empty_filp(void)
3713         f->f_cred = get_cred(cred);
3714         eventpoll_init_file(f);
3715         /* f->f_version: 0 */
3716 +       f->f_xid = vx_current_xid();
3717 +       vx_files_inc(f);
3718         return f;
3719  
3720  over:
3721 @@ -283,6 +287,8 @@ void __fput(struct file *file)
3722                 cdev_put(inode->i_cdev);
3723         fops_put(file->f_op);
3724         put_pid(file->f_owner.pid);
3725 +       vx_files_dec(file);
3726 +       file->f_xid = 0;
3727         file_kill(file);
3728         if (file->f_mode & FMODE_WRITE)
3729                 drop_file_write_access(file);
3730 @@ -350,6 +356,8 @@ void put_filp(struct file *file)
3731  {
3732         if (atomic_long_dec_and_test(&file->f_count)) {
3733                 security_file_free(file);
3734 +               vx_files_dec(file);
3735 +               file->f_xid = 0;
3736                 file_kill(file);
3737                 file_free(file);
3738         }
3739 diff -NurpP --minimal linux-2.6.29/fs/hfsplus/ioctl.c linux-2.6.29-vs2.3.0.36.9-pre3/fs/hfsplus/ioctl.c
3740 --- linux-2.6.29/fs/hfsplus/ioctl.c     2008-12-25 00:26:37.000000000 +0100
3741 +++ linux-2.6.29-vs2.3.0.36.9-pre3/fs/hfsplus/ioctl.c   2009-02-22 22:54:25.000000000 +0100
3742 @@ -17,6 +17,7 @@
3743  #include <linux/mount.h>
3744  #include <linux/sched.h>
3745  #include <linux/xattr.h>
3746 +#include <linux/mount.h>
3747  #include <asm/uaccess.h>
3748  #include "hfsplus_fs.h"
3749  
3750 diff -NurpP --minimal linux-2.6.29/fs/inode.c linux-2.6.29-vs2.3.0.36.9-pre3/fs/inode.c
3751 --- linux-2.6.29/fs/inode.c     2009-03-24 14:22:26.000000000 +0100
3752 +++ linux-2.6.29-vs2.3.0.36.9-pre3/fs/inode.c   2009-03-25 00:51:55.000000000 +0100
3753 @@ -126,6 +126,9 @@ struct inode *inode_init_always(struct s
3754         struct address_space * const mapping = &inode->i_data;
3755  
3756         inode->i_sb = sb;
3757 +
3758 +       /* essential because of inode slab reuse */
3759 +       inode->i_tag = 0;
3760         inode->i_blkbits = sb->s_blocksize_bits;
3761         inode->i_flags = 0;
3762         atomic_set(&inode->i_count, 1);
3763 @@ -146,6 +149,7 @@ struct inode *inode_init_always(struct s
3764         inode->i_bdev = NULL;
3765         inode->i_cdev = NULL;
3766         inode->i_rdev = 0;
3767 +       inode->i_mdev = 0;
3768         inode->dirtied_when = 0;
3769         if (security_inode_alloc(inode)) {
3770                 if (inode->i_sb->s_op->destroy_inode)
3771 @@ -267,6 +271,8 @@ void __iget(struct inode * inode)
3772         inodes_stat.nr_unused--;
3773  }
3774  
3775 +EXPORT_SYMBOL_GPL(__iget);
3776 +
3777  /**
3778   * clear_inode - clear an inode
3779   * @inode: inode to clear
3780 @@ -1539,9 +1545,11 @@ void init_special_inode(struct inode *in
3781         if (S_ISCHR(mode)) {
3782                 inode->i_fop = &def_chr_fops;
3783                 inode->i_rdev = rdev;
3784 +               inode->i_mdev = rdev;
3785         } else if (S_ISBLK(mode)) {
3786                 inode->i_fop = &def_blk_fops;
3787                 inode->i_rdev = rdev;
3788 +               inode->i_mdev = rdev;
3789         } else if (S_ISFIFO(mode))
3790                 inode->i_fop = &def_fifo_fops;
3791         else if (S_ISSOCK(mode))
3792 diff -NurpP --minimal linux-2.6.29/fs/ioctl.c linux-2.6.29-vs2.3.0.36.9-pre3/fs/ioctl.c
3793 --- linux-2.6.29/fs/ioctl.c     2009-03-24 14:22:26.000000000 +0100
3794 +++ linux-2.6.29-vs2.3.0.36.9-pre3/fs/ioctl.c   2009-03-24 14:48:35.000000000 +0100
3795 @@ -15,6 +15,9 @@
3796  #include <linux/uaccess.h>
3797  #include <linux/writeback.h>
3798  #include <linux/buffer_head.h>
3799 +#include <linux/proc_fs.h>
3800 +#include <linux/vserver/inode.h>
3801 +#include <linux/vs_tag.h>
3802  
3803  #include <asm/ioctls.h>
3804  
3805 diff -NurpP --minimal linux-2.6.29/fs/ioprio.c linux-2.6.29-vs2.3.0.36.9-pre3/fs/ioprio.c
3806 --- linux-2.6.29/fs/ioprio.c    2009-03-24 14:22:26.000000000 +0100
3807 +++ linux-2.6.29-vs2.3.0.36.9-pre3/fs/ioprio.c  2009-03-24 14:48:35.000000000 +0100
3808 @@ -26,6 +26,7 @@
3809  #include <linux/syscalls.h>
3810  #include <linux/security.h>
3811  #include <linux/pid_namespace.h>
3812 +#include <linux/vs_base.h>
3813  
3814  int set_task_ioprio(struct task_struct *task, int ioprio)
3815  {
3816 @@ -123,6 +124,8 @@ SYSCALL_DEFINE3(ioprio_set, int, which, 
3817                         else
3818                                 pgrp = find_vpid(who);
3819                         do_each_pid_thread(pgrp, PIDTYPE_PGID, p) {
3820 +                               if (!vx_check(p->xid, VS_ADMIN_P | VS_IDENT))
3821 +                                       continue;
3822                                 ret = set_task_ioprio(p, ioprio);
3823                                 if (ret)
3824                                         break;
3825 @@ -212,6 +215,8 @@ SYSCALL_DEFINE2(ioprio_get, int, which, 
3826                         else
3827                                 pgrp = find_vpid(who);
3828                         do_each_pid_thread(pgrp, PIDTYPE_PGID, p) {
3829 +                               if (!vx_check(p->xid, VS_ADMIN_P | VS_IDENT))
3830 +                                       continue;
3831                                 tmpio = get_task_ioprio(p);
3832                                 if (tmpio < 0)
3833                                         continue;
3834 diff -NurpP --minimal linux-2.6.29/fs/jfs/acl.c linux-2.6.29-vs2.3.0.36.9-pre3/fs/jfs/acl.c
3835 --- linux-2.6.29/fs/jfs/acl.c   2008-12-25 00:26:37.000000000 +0100
3836 +++ linux-2.6.29-vs2.3.0.36.9-pre3/fs/jfs/acl.c 2009-02-22 22:54:25.000000000 +0100
3837 @@ -232,7 +232,8 @@ int jfs_setattr(struct dentry *dentry, s
3838                 return rc;
3839  
3840         if ((iattr->ia_valid & ATTR_UID && iattr->ia_uid != inode->i_uid) ||
3841 -           (iattr->ia_valid & ATTR_GID && iattr->ia_gid != inode->i_gid)) {
3842 +           (iattr->ia_valid & ATTR_GID && iattr->ia_gid != inode->i_gid) ||
3843 +           (iattr->ia_valid & ATTR_TAG && iattr->ia_tag != inode->i_tag)) {
3844                 if (DQUOT_TRANSFER(inode, iattr))
3845                         return -EDQUOT;
3846         }
3847 diff -NurpP --minimal linux-2.6.29/fs/jfs/file.c linux-2.6.29-vs2.3.0.36.9-pre3/fs/jfs/file.c
3848 --- linux-2.6.29/fs/jfs/file.c  2008-12-25 00:26:37.000000000 +0100
3849 +++ linux-2.6.29-vs2.3.0.36.9-pre3/fs/jfs/file.c        2009-02-22 22:54:25.000000000 +0100
3850 @@ -98,6 +98,7 @@ const struct inode_operations jfs_file_i
3851         .setattr        = jfs_setattr,
3852         .permission     = jfs_permission,
3853  #endif
3854 +       .sync_flags     = jfs_sync_flags,
3855  };
3856  
3857  const struct file_operations jfs_file_operations = {
3858 diff -NurpP --minimal linux-2.6.29/fs/jfs/inode.c linux-2.6.29-vs2.3.0.36.9-pre3/fs/jfs/inode.c
3859 --- linux-2.6.29/fs/jfs/inode.c 2009-03-24 14:22:26.000000000 +0100
3860 +++ linux-2.6.29-vs2.3.0.36.9-pre3/fs/jfs/inode.c       2009-03-24 14:48:35.000000000 +0100
3861 @@ -22,6 +22,7 @@
3862  #include <linux/buffer_head.h>
3863  #include <linux/pagemap.h>
3864  #include <linux/quotaops.h>
3865 +#include <linux/vs_dlimit.h>
3866  #include "jfs_incore.h"
3867  #include "jfs_inode.h"
3868  #include "jfs_filsys.h"
3869 @@ -161,6 +162,7 @@ void jfs_delete_inode(struct inode *inod
3870                 DQUOT_INIT(inode);
3871                 DQUOT_FREE_INODE(inode);
3872                 DQUOT_DROP(inode);
3873 +               DLIMIT_FREE_INODE(inode);
3874         }
3875  
3876         clear_inode(inode);
3877 diff -NurpP --minimal linux-2.6.29/fs/jfs/ioctl.c linux-2.6.29-vs2.3.0.36.9-pre3/fs/jfs/ioctl.c
3878 --- linux-2.6.29/fs/jfs/ioctl.c 2008-12-25 00:26:37.000000000 +0100
3879 +++ linux-2.6.29-vs2.3.0.36.9-pre3/fs/jfs/ioctl.c       2009-02-22 22:54:25.000000000 +0100
3880 @@ -11,6 +11,7 @@
3881  #include <linux/mount.h>
3882  #include <linux/time.h>
3883  #include <linux/sched.h>
3884 +#include <linux/mount.h>
3885  #include <asm/current.h>
3886  #include <asm/uaccess.h>
3887  
3888 @@ -85,6 +86,11 @@ long jfs_ioctl(struct file *filp, unsign
3889                 if (!S_ISDIR(inode->i_mode))
3890                         flags &= ~JFS_DIRSYNC_FL;
3891  
3892 +               if (IS_BARRIER(inode)) {
3893 +                       vxwprintk_task(1, "messing with the barrier.");
3894 +                       return -EACCES;
3895 +               }
3896 +
3897                 /* Is it quota file? Do not allow user to mess with it */
3898                 if (IS_NOQUOTA(inode)) {
3899                         err = -EPERM;
3900 @@ -102,8 +108,8 @@ long jfs_ioctl(struct file *filp, unsign
3901                  * the relevant capability.
3902                  */
3903                 if ((oldflags & JFS_IMMUTABLE_FL) ||
3904 -                       ((flags ^ oldflags) &
3905 -                       (JFS_APPEND_FL | JFS_IMMUTABLE_FL))) {
3906 +                       ((flags ^ oldflags) & (JFS_APPEND_FL |
3907 +                       JFS_IMMUTABLE_FL | JFS_IXUNLINK_FL))) {
3908                         if (!capable(CAP_LINUX_IMMUTABLE)) {
3909                                 mutex_unlock(&inode->i_mutex);
3910                                 err = -EPERM;
3911 diff -NurpP --minimal linux-2.6.29/fs/jfs/jfs_dinode.h linux-2.6.29-vs2.3.0.36.9-pre3/fs/jfs/jfs_dinode.h
3912 --- linux-2.6.29/fs/jfs/jfs_dinode.h    2008-12-25 00:26:37.000000000 +0100
3913 +++ linux-2.6.29-vs2.3.0.36.9-pre3/fs/jfs/jfs_dinode.h  2009-02-22 22:54:25.000000000 +0100
3914 @@ -161,9 +161,13 @@ struct dinode {
3915  
3916  #define JFS_APPEND_FL          0x01000000 /* writes to file may only append */
3917  #define JFS_IMMUTABLE_FL       0x02000000 /* Immutable file */
3918 +#define JFS_IXUNLINK_FL                0x08000000 /* Immutable invert on unlink */
3919  
3920 -#define JFS_FL_USER_VISIBLE    0x03F80000
3921 -#define JFS_FL_USER_MODIFIABLE 0x03F80000
3922 +#define JFS_BARRIER_FL         0x04000000 /* Barrier for chroot() */
3923 +#define JFS_COW_FL             0x20000000 /* Copy on Write marker */
3924 +
3925 +#define JFS_FL_USER_VISIBLE    0x07F80000
3926 +#define JFS_FL_USER_MODIFIABLE 0x07F80000
3927  #define JFS_FL_INHERIT         0x03C80000
3928  
3929  /* These are identical to EXT[23]_IOC_GETFLAGS/SETFLAGS */
3930 diff -NurpP --minimal linux-2.6.29/fs/jfs/jfs_dtree.c linux-2.6.29-vs2.3.0.36.9-pre3/fs/jfs/jfs_dtree.c
3931 --- linux-2.6.29/fs/jfs/jfs_dtree.c     2008-12-25 00:26:37.000000000 +0100
3932 +++ linux-2.6.29-vs2.3.0.36.9-pre3/fs/jfs/jfs_dtree.c   2009-02-22 22:54:25.000000000 +0100
3933 @@ -102,6 +102,7 @@
3934  
3935  #include <linux/fs.h>
3936  #include <linux/quotaops.h>
3937 +#include <linux/vs_dlimit.h>
3938  #include "jfs_incore.h"
3939  #include "jfs_superblock.h"
3940  #include "jfs_filsys.h"
3941 @@ -383,10 +384,10 @@ static u32 add_index(tid_t tid, struct i
3942                  */
3943                 if (DQUOT_ALLOC_BLOCK(ip, sbi->nbperpage))
3944                         goto clean_up;
3945 -               if (dbAlloc(ip, 0, sbi->nbperpage, &xaddr)) {
3946 -                       DQUOT_FREE_BLOCK(ip, sbi->nbperpage);
3947 -                       goto clean_up;
3948 -               }
3949 +               if (DLIMIT_ALLOC_BLOCK(ip, sbi->nbperpage))
3950 +                       goto clean_up_dquot;
3951 +               if (dbAlloc(ip, 0, sbi->nbperpage, &xaddr))
3952 +                       goto clean_up_dlimit;
3953  
3954                 /*
3955                  * Save the table, we're going to overwrite it with the
3956 @@ -480,6 +481,12 @@ static u32 add_index(tid_t tid, struct i
3957  
3958         return index;
3959  
3960 +      clean_up_dlimit:
3961 +       DLIMIT_FREE_BLOCK(ip, sbi->nbperpage);
3962 +
3963 +      clean_up_dquot:
3964 +       DQUOT_FREE_BLOCK(ip, sbi->nbperpage);
3965 +
3966        clean_up:
3967  
3968         jfs_ip->next_index--;
3969 @@ -951,6 +958,7 @@ static int dtSplitUp(tid_t tid,
3970         struct tlock *tlck;
3971         struct lv *lv;
3972         int quota_allocation = 0;
3973 +       int dlimit_allocation = 0;
3974  
3975         /* get split page */
3976         smp = split->mp;
3977 @@ -1033,6 +1041,12 @@ static int dtSplitUp(tid_t tid,
3978                 }
3979                 quota_allocation += n;
3980  
3981 +               if (DLIMIT_ALLOC_BLOCK(ip, n)) {
3982 +                       rc = -ENOSPC;
3983 +                       goto extendOut;
3984 +               }
3985 +               dlimit_allocation += n;
3986 +
3987                 if ((rc = dbReAlloc(sbi->ipbmap, xaddr, (s64) xlen,
3988                                     (s64) n, &nxaddr)))
3989                         goto extendOut;
3990 @@ -1306,6 +1320,9 @@ static int dtSplitUp(tid_t tid,
3991        freeKeyName:
3992         kfree(key.name);
3993  
3994 +       /* Rollback dlimit allocation */
3995 +       if (rc && dlimit_allocation)
3996 +               DLIMIT_FREE_BLOCK(ip, dlimit_allocation);
3997         /* Rollback quota allocation */
3998         if (rc && quota_allocation)
3999                 DQUOT_FREE_BLOCK(ip, quota_allocation);
4000 @@ -1373,6 +1390,12 @@ static int dtSplitPage(tid_t tid, struct
4001                 release_metapage(rmp);
4002                 return -EDQUOT;
4003         }
4004 +       /* Allocate blocks to dlimit. */
4005 +       if (DLIMIT_ALLOC_BLOCK(ip, lengthPXD(pxd))) {
4006 +               DQUOT_FREE_BLOCK(ip, lengthPXD(pxd));
4007 +               release_metapage(rmp);
4008 +               return -ENOSPC;
4009 +       }
4010  
4011         jfs_info("dtSplitPage: ip:0x%p smp:0x%p rmp:0x%p", ip, smp, rmp);
4012  
4013 @@ -1920,6 +1943,12 @@ static int dtSplitRoot(tid_t tid,
4014                 release_metapage(rmp);
4015                 return -EDQUOT;
4016         }
4017 +       /* Allocate blocks to dlimit. */
4018 +       if (DLIMIT_ALLOC_BLOCK(ip, lengthPXD(pxd))) {
4019 +               DQUOT_FREE_BLOCK(ip, lengthPXD(pxd));
4020 +               release_metapage(rmp);
4021 +               return -ENOSPC;
4022 +       }
4023  
4024         BT_MARK_DIRTY(rmp, ip);
4025         /*
4026 @@ -2286,6 +2315,8 @@ static int dtDeleteUp(tid_t tid, struct 
4027  
4028         xlen = lengthPXD(&fp->header.self);
4029  
4030 +       /* Free dlimit allocation. */
4031 +       DLIMIT_FREE_BLOCK(ip, xlen);
4032         /* Free quota allocation. */
4033         DQUOT_FREE_BLOCK(ip, xlen);
4034  
4035 @@ -2362,6 +2393,8 @@ static int dtDeleteUp(tid_t tid, struct 
4036  
4037                                 xlen = lengthPXD(&p->header.self);
4038  
4039 +                               /* Free dlimit allocation */
4040 +                               DLIMIT_FREE_BLOCK(ip, xlen);
4041                                 /* Free quota allocation */
4042                                 DQUOT_FREE_BLOCK(ip, xlen);
4043  
4044 diff -NurpP --minimal linux-2.6.29/fs/jfs/jfs_extent.c linux-2.6.29-vs2.3.0.36.9-pre3/fs/jfs/jfs_extent.c
4045 --- linux-2.6.29/fs/jfs/jfs_extent.c    2008-12-25 00:26:37.000000000 +0100
4046 +++ linux-2.6.29-vs2.3.0.36.9-pre3/fs/jfs/jfs_extent.c  2009-02-22 22:54:25.000000000 +0100
4047 @@ -18,6 +18,7 @@
4048  
4049  #include <linux/fs.h>
4050  #include <linux/quotaops.h>
4051 +#include <linux/vs_dlimit.h>
4052  #include "jfs_incore.h"
4053  #include "jfs_inode.h"
4054  #include "jfs_superblock.h"
4055 @@ -147,6 +148,14 @@ extAlloc(struct inode *ip, s64 xlen, s64
4056                 return -EDQUOT;
4057         }
4058  
4059 +       /* Allocate blocks to dlimit. */
4060 +       if (DLIMIT_ALLOC_BLOCK(ip, nxlen)) {
4061 +               DQUOT_FREE_BLOCK(ip, nxlen);
4062 +               dbFree(ip, nxaddr, (s64) nxlen);
4063 +               mutex_unlock(&JFS_IP(ip)->commit_mutex);
4064 +               return -ENOSPC;
4065 +       }
4066 +
4067         /* determine the value of the extent flag */
4068         xflag = abnr ? XAD_NOTRECORDED : 0;
4069  
4070 @@ -164,6 +173,7 @@ extAlloc(struct inode *ip, s64 xlen, s64
4071          */
4072         if (rc) {
4073                 dbFree(ip, nxaddr, nxlen);
4074 +               DLIMIT_FREE_BLOCK(ip, nxlen);
4075                 DQUOT_FREE_BLOCK(ip, nxlen);
4076                 mutex_unlock(&JFS_IP(ip)->commit_mutex);
4077                 return (rc);
4078 @@ -261,6 +271,13 @@ int extRealloc(struct inode *ip, s64 nxl
4079                 mutex_unlock(&JFS_IP(ip)->commit_mutex);
4080                 return -EDQUOT;
4081         }
4082 +       /* Allocate blocks to dlimit. */
4083 +       if (DLIMIT_ALLOC_BLOCK(ip, nxlen)) {
4084 +               DQUOT_FREE_BLOCK(ip, nxlen);
4085 +               dbFree(ip, nxaddr, (s64) nxlen);
4086 +               up(&JFS_IP(ip)->commit_sem);
4087 +               return -ENOSPC;
4088 +       }
4089  
4090         delta = nxlen - xlen;
4091  
4092 @@ -297,6 +314,7 @@ int extRealloc(struct inode *ip, s64 nxl
4093                 /* extend the extent */
4094                 if ((rc = xtExtend(0, ip, xoff + xlen, (int) nextend, 0))) {
4095                         dbFree(ip, xaddr + xlen, delta);
4096 +                       DLIMIT_FREE_BLOCK(ip, nxlen);
4097                         DQUOT_FREE_BLOCK(ip, nxlen);
4098                         goto exit;
4099                 }
4100 @@ -308,6 +326,7 @@ int extRealloc(struct inode *ip, s64 nxl
4101                  */
4102                 if ((rc = xtTailgate(0, ip, xoff, (int) ntail, nxaddr, 0))) {
4103                         dbFree(ip, nxaddr, nxlen);
4104 +                       DLIMIT_FREE_BLOCK(ip, nxlen);
4105                         DQUOT_FREE_BLOCK(ip, nxlen);
4106                         goto exit;
4107                 }
4108 diff -NurpP --minimal linux-2.6.29/fs/jfs/jfs_filsys.h linux-2.6.29-vs2.3.0.36.9-pre3/fs/jfs/jfs_filsys.h
4109 --- linux-2.6.29/fs/jfs/jfs_filsys.h    2008-12-25 00:26:37.000000000 +0100
4110 +++ linux-2.6.29-vs2.3.0.36.9-pre3/fs/jfs/jfs_filsys.h  2009-02-22 22:54:25.000000000 +0100
4111 @@ -263,6 +263,7 @@
4112  #define JFS_NAME_MAX   255
4113  #define JFS_PATH_MAX   BPSIZE
4114  
4115 +#define JFS_TAGGED             0x00800000      /* Context Tagging */
4116  
4117  /*
4118   *     file system state (superblock state)
4119 diff -NurpP --minimal linux-2.6.29/fs/jfs/jfs_imap.c linux-2.6.29-vs2.3.0.36.9-pre3/fs/jfs/jfs_imap.c
4120 --- linux-2.6.29/fs/jfs/jfs_imap.c      2009-03-24 14:22:26.000000000 +0100
4121 +++ linux-2.6.29-vs2.3.0.36.9-pre3/fs/jfs/jfs_imap.c    2009-03-24 14:48:35.000000000 +0100
4122 @@ -45,6 +45,7 @@
4123  #include <linux/buffer_head.h>
4124  #include <linux/pagemap.h>
4125  #include <linux/quotaops.h>
4126 +#include <linux/vs_tag.h>
4127  
4128  #include "jfs_incore.h"
4129  #include "jfs_inode.h"
4130 @@ -3062,6 +3063,8 @@ static int copy_from_dinode(struct dinod
4131  {
4132         struct jfs_inode_info *jfs_ip = JFS_IP(ip);
4133         struct jfs_sb_info *sbi = JFS_SBI(ip->i_sb);
4134 +       uid_t uid;
4135 +       gid_t gid;
4136  
4137         jfs_ip->fileset = le32_to_cpu(dip->di_fileset);
4138         jfs_ip->mode2 = le32_to_cpu(dip->di_mode);
4139 @@ -3082,14 +3085,18 @@ static int copy_from_dinode(struct dinod
4140         }
4141         ip->i_nlink = le32_to_cpu(dip->di_nlink);
4142  
4143 -       jfs_ip->saved_uid = le32_to_cpu(dip->di_uid);
4144 +       uid = le32_to_cpu(dip->di_uid);
4145 +       gid = le32_to_cpu(dip->di_gid);
4146 +       ip->i_tag = INOTAG_TAG(DX_TAG(ip), uid, gid, 0);
4147 +
4148 +       jfs_ip->saved_uid = INOTAG_UID(DX_TAG(ip), uid, gid);
4149         if (sbi->uid == -1)
4150                 ip->i_uid = jfs_ip->saved_uid;
4151         else {
4152                 ip->i_uid = sbi->uid;
4153         }
4154  
4155 -       jfs_ip->saved_gid = le32_to_cpu(dip->di_gid);
4156 +       jfs_ip->saved_gid = INOTAG_GID(DX_TAG(ip), uid, gid);
4157         if (sbi->gid == -1)
4158                 ip->i_gid = jfs_ip->saved_gid;
4159         else {
4160 @@ -3154,14 +3161,12 @@ static void copy_to_dinode(struct dinode
4161         dip->di_size = cpu_to_le64(ip->i_size);
4162         dip->di_nblocks = cpu_to_le64(PBLK2LBLK(ip->i_sb, ip->i_blocks));
4163         dip->di_nlink = cpu_to_le32(ip->i_nlink);
4164 -       if (sbi->uid == -1)
4165 -               dip->di_uid = cpu_to_le32(ip->i_uid);
4166 -       else
4167 -               dip->di_uid = cpu_to_le32(jfs_ip->saved_uid);
4168 -       if (sbi->gid == -1)
4169 -               dip->di_gid = cpu_to_le32(ip->i_gid);
4170 -       else
4171 -               dip->di_gid = cpu_to_le32(jfs_ip->saved_gid);
4172 +
4173 +       dip->di_uid = cpu_to_le32(TAGINO_UID(DX_TAG(ip),
4174 +               (sbi->uid == -1) ? ip->i_uid : jfs_ip->saved_uid, ip->i_tag));
4175 +       dip->di_gid = cpu_to_le32(TAGINO_GID(DX_TAG(ip),
4176 +               (sbi->gid == -1) ? ip->i_gid : jfs_ip->saved_gid, ip->i_tag));
4177 +
4178         jfs_get_inode_flags(jfs_ip);
4179         /*
4180          * mode2 is only needed for storing the higher order bits.
4181 diff -NurpP --minimal linux-2.6.29/fs/jfs/jfs_inode.c linux-2.6.29-vs2.3.0.36.9-pre3/fs/jfs/jfs_inode.c
4182 --- linux-2.6.29/fs/jfs/jfs_inode.c     2009-03-24 14:22:26.000000000 +0100
4183 +++ linux-2.6.29-vs2.3.0.36.9-pre3/fs/jfs/jfs_inode.c   2009-03-24 15:58:01.000000000 +0100
4184 @@ -18,6 +18,8 @@
4185  
4186  #include <linux/fs.h>
4187  #include <linux/quotaops.h>
4188 +#include <linux/vs_dlimit.h>
4189 +#include <linux/vs_tag.h>
4190  #include "jfs_incore.h"
4191  #include "jfs_inode.h"
4192  #include "jfs_filsys.h"
4193 @@ -30,29 +32,46 @@ void jfs_set_inode_flags(struct inode *i
4194  {
4195         unsigned int flags = JFS_IP(inode)->mode2;
4196  
4197 -       inode->i_flags &= ~(S_IMMUTABLE | S_APPEND |
4198 -               S_NOATIME | S_DIRSYNC | S_SYNC);
4199 +       inode->i_flags &= ~(S_IMMUTABLE | S_IXUNLINK |
4200 +               S_SYNC | S_APPEND | S_NOATIME | S_DIRSYNC);
4201  
4202         if (flags & JFS_IMMUTABLE_FL)
4203                 inode->i_flags |= S_IMMUTABLE;
4204 +       if (flags & JFS_IXUNLINK_FL)
4205 +               inode->i_flags |= S_IXUNLINK;
4206 +
4207 +       if (flags & JFS_SYNC_FL)
4208 +               inode->i_flags |= S_SYNC;
4209         if (flags & JFS_APPEND_FL)
4210                 inode->i_flags |= S_APPEND;
4211         if (flags & JFS_NOATIME_FL)
4212                 inode->i_flags |= S_NOATIME;
4213         if (flags & JFS_DIRSYNC_FL)
4214                 inode->i_flags |= S_DIRSYNC;
4215 -       if (flags & JFS_SYNC_FL)
4216 -               inode->i_flags |= S_SYNC;
4217 +
4218 +       inode->i_vflags &= ~(V_BARRIER | V_COW);
4219 +
4220 +       if (flags & JFS_BARRIER_FL)
4221 +               inode->i_vflags |= V_BARRIER;
4222 +       if (flags & JFS_COW_FL)
4223 +               inode->i_vflags |= V_COW;
4224  }
4225  
4226  void jfs_get_inode_flags(struct jfs_inode_info *jfs_ip)
4227  {
4228         unsigned int flags = jfs_ip->vfs_inode.i_flags;
4229 +       unsigned int vflags = jfs_ip->vfs_inode.i_vflags;
4230 +
4231 +       jfs_ip->mode2 &= ~(JFS_IMMUTABLE_FL | JFS_IXUNLINK_FL |
4232 +                          JFS_APPEND_FL | JFS_NOATIME_FL |
4233 +                          JFS_DIRSYNC_FL | JFS_SYNC_FL |
4234 +                          JFS_BARRIER_FL | JFS_COW_FL);
4235  
4236 -       jfs_ip->mode2 &= ~(JFS_IMMUTABLE_FL | JFS_APPEND_FL | JFS_NOATIME_FL |
4237 -                          JFS_DIRSYNC_FL | JFS_SYNC_FL);
4238         if (flags & S_IMMUTABLE)
4239                 jfs_ip->mode2 |= JFS_IMMUTABLE_FL;
4240 +       if (flags & S_IXUNLINK)
4241 +               jfs_ip->mode2 |= JFS_IXUNLINK_FL;
4242 +
4243         if (flags & S_APPEND)
4244                 jfs_ip->mode2 |= JFS_APPEND_FL;
4245         if (flags & S_NOATIME)
4246 @@ -61,6 +80,19 @@ void jfs_get_inode_flags(struct jfs_inod
4247                 jfs_ip->mode2 |= JFS_DIRSYNC_FL;
4248         if (flags & S_SYNC)
4249                 jfs_ip->mode2 |= JFS_SYNC_FL;
4250 +
4251 +       if (vflags & V_BARRIER)
4252 +               jfs_ip->mode2 |= JFS_BARRIER_FL;
4253 +       if (vflags & V_COW)
4254 +               jfs_ip->mode2 |= JFS_COW_FL;
4255 +}
4256 +
4257 +int jfs_sync_flags(struct inode *inode)
4258 +{
4259 +       jfs_get_inode_flags(JFS_IP(inode));
4260 +       inode->i_ctime = CURRENT_TIME;
4261 +       mark_inode_dirty(inode);
4262 +       return 0;
4263  }
4264  
4265  /*
4266 @@ -113,6 +145,12 @@ struct inode *ialloc(struct inode *paren
4267         jfs_inode->saved_uid = inode->i_uid;
4268         jfs_inode->saved_gid = inode->i_gid;
4269  
4270 +       inode->i_tag = dx_current_fstag(sb);
4271 +       if (DLIMIT_ALLOC_INODE(inode)) {
4272 +               rc = -ENOSPC;
4273 +               goto fail_drop2;
4274 +       }
4275 +
4276         /*
4277          * Allocate inode to quota.
4278          */
4279 @@ -162,6 +200,8 @@ struct inode *ialloc(struct inode *paren
4280         return inode;
4281  
4282  fail_drop:
4283 +       DLIMIT_FREE_INODE(inode);
4284 +fail_drop2:
4285         DQUOT_DROP(inode);
4286         inode->i_flags |= S_NOQUOTA;
4287  fail_unlock:
4288 diff -NurpP --minimal linux-2.6.29/fs/jfs/jfs_inode.h linux-2.6.29-vs2.3.0.36.9-pre3/fs/jfs/jfs_inode.h
4289 --- linux-2.6.29/fs/jfs/jfs_inode.h     2008-12-25 00:26:37.000000000 +0100
4290 +++ linux-2.6.29-vs2.3.0.36.9-pre3/fs/jfs/jfs_inode.h   2009-02-22 22:54:25.000000000 +0100
4291 @@ -39,6 +39,7 @@ extern struct dentry *jfs_fh_to_dentry(s
4292  extern struct dentry *jfs_fh_to_parent(struct super_block *sb, struct fid *fid,
4293         int fh_len, int fh_type);
4294  extern void jfs_set_inode_flags(struct inode *);
4295 +extern int jfs_sync_flags(struct inode *);
4296  extern int jfs_get_block(struct inode *, sector_t, struct buffer_head *, int);
4297  
4298  extern const struct address_space_operations jfs_aops;
4299 diff -NurpP --minimal linux-2.6.29/fs/jfs/jfs_xtree.c linux-2.6.29-vs2.3.0.36.9-pre3/fs/jfs/jfs_xtree.c
4300 --- linux-2.6.29/fs/jfs/jfs_xtree.c     2008-12-25 00:26:37.000000000 +0100
4301 +++ linux-2.6.29-vs2.3.0.36.9-pre3/fs/jfs/jfs_xtree.c   2009-02-22 22:54:25.000000000 +0100
4302 @@ -23,6 +23,7 @@
4303  #include <linux/module.h>
4304  #include <linux/quotaops.h>
4305  #include <linux/seq_file.h>
4306 +#include <linux/vs_dlimit.h>
4307  #include "jfs_incore.h"
4308  #include "jfs_filsys.h"
4309  #include "jfs_metapage.h"
4310 @@ -848,7 +849,12 @@ int xtInsert(tid_t tid,            /* transaction 
4311                         hint = 0;
4312                 if ((rc = DQUOT_ALLOC_BLOCK(ip, xlen)))
4313                         goto out;
4314 +               if ((rc = DLIMIT_ALLOC_BLOCK(ip, xlen))) {
4315 +                       DQUOT_FREE_BLOCK(ip, xlen);
4316 +                       goto out;
4317 +               }
4318                 if ((rc = dbAlloc(ip, hint, (s64) xlen, &xaddr))) {
4319 +                       DLIMIT_FREE_BLOCK(ip, xlen);
4320                         DQUOT_FREE_BLOCK(ip, xlen);
4321                         goto out;
4322                 }
4323 @@ -878,6 +884,7 @@ int xtInsert(tid_t tid,             /* transaction 
4324                         /* undo data extent allocation */
4325                         if (*xaddrp == 0) {
4326                                 dbFree(ip, xaddr, (s64) xlen);
4327 +                               DLIMIT_FREE_BLOCK(ip, xlen);
4328                                 DQUOT_FREE_BLOCK(ip, xlen);
4329                         }
4330                         return rc;
4331 @@ -1234,6 +1241,7 @@ xtSplitPage(tid_t tid, struct inode *ip,
4332         struct tlock *tlck;
4333         struct xtlock *sxtlck = NULL, *rxtlck = NULL;
4334         int quota_allocation = 0;
4335 +       int dlimit_allocation = 0;
4336  
4337         smp = split->mp;
4338         sp = XT_PAGE(ip, smp);
4339 @@ -1253,6 +1261,13 @@ xtSplitPage(tid_t tid, struct inode *ip,
4340  
4341         quota_allocation += lengthPXD(pxd);
4342  
4343 +       /* Allocate blocks to dlimit. */
4344 +       if (DLIMIT_ALLOC_BLOCK(ip, lengthPXD(pxd))) {
4345 +              rc = -ENOSPC;
4346 +              goto clean_up;
4347 +       }
4348 +       dlimit_allocation += lengthPXD(pxd);
4349 +
4350         /*
4351          * allocate the new right page for the split
4352          */
4353 @@ -1454,6 +1469,9 @@ xtSplitPage(tid_t tid, struct inode *ip,
4354  
4355        clean_up:
4356  
4357 +       /* Rollback dlimit allocation. */
4358 +       if (dlimit_allocation)
4359 +               DLIMIT_FREE_BLOCK(ip, dlimit_allocation);
4360         /* Rollback quota allocation. */
4361         if (quota_allocation)
4362                 DQUOT_FREE_BLOCK(ip, quota_allocation);
4363 @@ -1517,6 +1535,12 @@ xtSplitRoot(tid_t tid,
4364                 release_metapage(rmp);
4365                 return -EDQUOT;
4366         }
4367 +       /* Allocate blocks to dlimit. */
4368 +       if (DLIMIT_ALLOC_BLOCK(ip, lengthPXD(pxd))) {
4369 +               DQUOT_FREE_BLOCK(ip, lengthPXD(pxd));
4370 +               release_metapage(rmp);
4371 +               return -ENOSPC;
4372 +       }
4373  
4374         jfs_info("xtSplitRoot: ip:0x%p rmp:0x%p", ip, rmp);
4375  
4376 @@ -3940,6 +3964,8 @@ s64 xtTruncate(tid_t tid, struct inode *
4377         else
4378                 ip->i_size = newsize;
4379  
4380 +       /* update dlimit allocation to reflect freed blocks */
4381 +       DLIMIT_FREE_BLOCK(ip, nfreed);
4382         /* update quota allocation to reflect freed blocks */
4383         DQUOT_FREE_BLOCK(ip, nfreed);
4384  
4385 diff -NurpP --minimal linux-2.6.29/fs/jfs/namei.c linux-2.6.29-vs2.3.0.36.9-pre3/fs/jfs/namei.c
4386 --- linux-2.6.29/fs/jfs/namei.c 2009-03-24 14:22:26.000000000 +0100
4387 +++ linux-2.6.29-vs2.3.0.36.9-pre3/fs/jfs/namei.c       2009-03-24 14:48:35.000000000 +0100
4388 @@ -21,6 +21,7 @@
4389  #include <linux/ctype.h>
4390  #include <linux/quotaops.h>
4391  #include <linux/exportfs.h>
4392 +#include <linux/vs_tag.h>
4393  #include "jfs_incore.h"
4394  #include "jfs_superblock.h"
4395  #include "jfs_inode.h"
4396 @@ -1476,6 +1477,7 @@ static struct dentry *jfs_lookup(struct 
4397                 return ERR_CAST(ip);
4398         }
4399  
4400 +       dx_propagate_tag(nd, ip);
4401         dentry = d_splice_alias(ip, dentry);
4402  
4403         if (dentry && (JFS_SBI(dip->i_sb)->mntflag & JFS_OS2))
4404 @@ -1545,6 +1547,7 @@ const struct inode_operations jfs_dir_in
4405         .setattr        = jfs_setattr,
4406         .permission     = jfs_permission,
4407  #endif
4408 +       .sync_flags     = jfs_sync_flags,
4409  };
4410  
4411  const struct file_operations jfs_dir_operations = {
4412 diff -NurpP --minimal linux-2.6.29/fs/jfs/super.c linux-2.6.29-vs2.3.0.36.9-pre3/fs/jfs/super.c
4413 --- linux-2.6.29/fs/jfs/super.c 2009-03-24 14:22:26.000000000 +0100
4414 +++ linux-2.6.29-vs2.3.0.36.9-pre3/fs/jfs/super.c       2009-03-24 14:48:35.000000000 +0100
4415 @@ -196,7 +196,8 @@ static void jfs_put_super(struct super_b
4416  enum {
4417         Opt_integrity, Opt_nointegrity, Opt_iocharset, Opt_resize,
4418         Opt_resize_nosize, Opt_errors, Opt_ignore, Opt_err, Opt_quota,
4419 -       Opt_usrquota, Opt_grpquota, Opt_uid, Opt_gid, Opt_umask
4420 +       Opt_usrquota, Opt_grpquota, Opt_uid, Opt_gid, Opt_umask,
4421 +       Opt_tag, Opt_notag, Opt_tagid
4422  };
4423  
4424  static const match_table_t tokens = {
4425 @@ -206,6 +207,10 @@ static const match_table_t tokens = {
4426         {Opt_resize, "resize=%u"},
4427         {Opt_resize_nosize, "resize"},
4428         {Opt_errors, "errors=%s"},
4429 +       {Opt_tag, "tag"},
4430 +       {Opt_notag, "notag"},
4431 +       {Opt_tagid, "tagid=%u"},
4432 +       {Opt_tag, "tagxid"},
4433         {Opt_ignore, "noquota"},
4434         {Opt_ignore, "quota"},
4435         {Opt_usrquota, "usrquota"},
4436 @@ -340,6 +345,20 @@ static int parse_options(char *options, 
4437                         }
4438                         break;
4439                 }
4440 +#ifndef CONFIG_TAGGING_NONE
4441 +               case Opt_tag:
4442 +                       *flag |= JFS_TAGGED;
4443 +                       break;
4444 +               case Opt_notag:
4445 +                       *flag &= JFS_TAGGED;
4446 +                       break;
4447 +#endif
4448 +#ifdef CONFIG_PROPAGATE
4449 +               case Opt_tagid:
4450 +                       /* use args[0] */
4451 +                       *flag |= JFS_TAGGED;
4452 +                       break;
4453 +#endif
4454                 default:
4455                         printk("jfs: Unrecognized mount option \"%s\" "
4456                                         " or missing value\n", p);
4457 @@ -370,6 +389,13 @@ static int jfs_remount(struct super_bloc
4458         if (!parse_options(data, sb, &newLVSize, &flag)) {
4459                 return -EINVAL;
4460         }
4461 +
4462 +       if ((flag & JFS_TAGGED) && !(sb->s_flags & MS_TAGGED)) {
4463 +               printk(KERN_ERR "JFS: %s: tagging not permitted on remount.\n",
4464 +                       sb->s_id);
4465 +               return -EINVAL;
4466 +       }
4467 +
4468         if (newLVSize) {
4469                 if (sb->s_flags & MS_RDONLY) {
4470                         printk(KERN_ERR
4471 @@ -441,6 +467,9 @@ static int jfs_fill_super(struct super_b
4472  #ifdef CONFIG_JFS_POSIX_ACL
4473         sb->s_flags |= MS_POSIXACL;
4474  #endif
4475 +       /* map mount option tagxid */
4476 +       if (sbi->flag & JFS_TAGGED)
4477 +               sb->s_flags |= MS_TAGGED;
4478  
4479         if (newLVSize) {
4480                 printk(KERN_ERR "resize option for remount only\n");
4481 diff -NurpP --minimal linux-2.6.29/fs/jfs/xattr.c linux-2.6.29-vs2.3.0.36.9-pre3/fs/jfs/xattr.c
4482 --- linux-2.6.29/fs/jfs/xattr.c 2008-12-25 00:26:37.000000000 +0100
4483 +++ linux-2.6.29-vs2.3.0.36.9-pre3/fs/jfs/xattr.c       2009-02-22 22:54:25.000000000 +0100
4484 @@ -23,6 +23,7 @@
4485  #include <linux/posix_acl_xattr.h>
4486  #include <linux/quotaops.h>
4487  #include <linux/security.h>
4488 +#include <linux/vs_dlimit.h>
4489  #include "jfs_incore.h"
4490  #include "jfs_superblock.h"
4491  #include "jfs_dmap.h"
4492 @@ -263,9 +264,16 @@ static int ea_write(struct inode *ip, st
4493         if (DQUOT_ALLOC_BLOCK(ip, nblocks)) {
4494                 return -EDQUOT;
4495         }
4496 +       /* Allocate new blocks to dlimit. */
4497 +       if (DLIMIT_ALLOC_BLOCK(ip, nblocks)) {
4498 +               DQUOT_FREE_BLOCK(ip, nblocks);
4499 +               return -ENOSPC;
4500 +       }
4501  
4502         rc = dbAlloc(ip, INOHINT(ip), nblocks, &blkno);
4503         if (rc) {
4504 +               /*Rollback dlimit allocation. */
4505 +               DLIMIT_FREE_BLOCK(ip, nblocks);
4506                 /*Rollback quota allocation. */
4507                 DQUOT_FREE_BLOCK(ip, nblocks);
4508                 return rc;
4509 @@ -332,6 +340,8 @@ static int ea_write(struct inode *ip, st
4510  
4511        failed:
4512         /* Rollback quota allocation. */
4513 +       DLIMIT_FREE_BLOCK(ip, nblocks);
4514 +       /* Rollback quota allocation. */
4515         DQUOT_FREE_BLOCK(ip, nblocks);
4516  
4517         dbFree(ip, blkno, nblocks);
4518 @@ -468,6 +478,7 @@ static int ea_get(struct inode *inode, s
4519         s64 blkno;
4520         int rc;
4521         int quota_allocation = 0;
4522 +       int dlimit_allocation = 0;
4523  
4524         /* When fsck.jfs clears a bad ea, it doesn't clear the size */
4525         if (ji->ea.flag == 0)
4526 @@ -543,6 +554,12 @@ static int ea_get(struct inode *inode, s
4527  
4528                 quota_allocation = blocks_needed;
4529  
4530 +               /* Allocate new blocks to dlimit. */
4531 +               rc = -ENOSPC;
4532 +               if (DLIMIT_ALLOC_BLOCK(inode, blocks_needed))
4533 +                       goto clean_up;
4534 +               dlimit_allocation = blocks_needed;
4535 +
4536                 rc = dbAlloc(inode, INOHINT(inode), (s64) blocks_needed,
4537                              &blkno);
4538                 if (rc)
4539 @@ -600,6 +617,9 @@ static int ea_get(struct inode *inode, s
4540         return ea_size;
4541  
4542        clean_up:
4543 +       /* Rollback dlimit allocation */
4544 +       if (dlimit_allocation)
4545 +               DLIMIT_FREE_BLOCK(inode, dlimit_allocation);
4546         /* Rollback quota allocation */
4547         if (quota_allocation)
4548                 DQUOT_FREE_BLOCK(inode, quota_allocation);
4549 @@ -676,8 +696,10 @@ static int ea_put(tid_t tid, struct inod
4550         }
4551  
4552         /* If old blocks exist, they must be removed from quota allocation. */
4553 -       if (old_blocks)
4554 +       if (old_blocks) {
4555 +               DLIMIT_FREE_BLOCK(inode, old_blocks);
4556                 DQUOT_FREE_BLOCK(inode, old_blocks);
4557 +       }
4558  
4559         inode->i_ctime = CURRENT_TIME;
4560  
4561 diff -NurpP --minimal linux-2.6.29/fs/libfs.c linux-2.6.29-vs2.3.0.36.9-pre3/fs/libfs.c
4562 --- linux-2.6.29/fs/libfs.c     2009-03-24 14:22:26.000000000 +0100
4563 +++ linux-2.6.29-vs2.3.0.36.9-pre3/fs/libfs.c   2009-03-24 14:48:35.000000000 +0100
4564 @@ -125,7 +125,8 @@ static inline unsigned char dt_type(stru
4565   * both impossible due to the lock on directory.
4566   */
4567  
4568 -int dcache_readdir(struct file * filp, void * dirent, filldir_t filldir)
4569 +static inline int do_dcache_readdir_filter(struct file *filp,
4570 +       void *dirent, filldir_t filldir, int (*filter)(struct dentry *dentry))
4571  {
4572         struct dentry *dentry = filp->f_path.dentry;
4573         struct dentry *cursor = filp->private_data;
4574 @@ -158,6 +159,8 @@ int dcache_readdir(struct file * filp, v
4575                                 next = list_entry(p, struct dentry, d_u.d_child);
4576                                 if (d_unhashed(next) || !next->d_inode)
4577                                         continue;
4578 +                               if (filter && !filter(next))
4579 +                                       continue;
4580  
4581                                 spin_unlock(&dcache_lock);
4582                                 if (filldir(dirent, next->d_name.name, 
4583 @@ -176,6 +179,18 @@ int dcache_readdir(struct file * filp, v
4584         return 0;
4585  }
4586  
4587 +int dcache_readdir(struct file *filp, void *dirent, filldir_t filldir)
4588 +{
4589 +       return do_dcache_readdir_filter(filp, dirent, filldir, NULL);
4590 +}
4591 +
4592 +int dcache_readdir_filter(struct file *filp, void *dirent, filldir_t filldir,
4593 +       int (*filter)(struct dentry *))
4594 +{
4595 +       return do_dcache_readdir_filter(filp, dirent, filldir, filter);
4596 +}
4597 +
4598 +
4599  ssize_t generic_read_dir(struct file *filp, char __user *buf, size_t siz, loff_t *ppos)
4600  {
4601         return -EISDIR;
4602 @@ -796,6 +811,7 @@ EXPORT_SYMBOL(dcache_dir_close);
4603  EXPORT_SYMBOL(dcache_dir_lseek);
4604  EXPORT_SYMBOL(dcache_dir_open);
4605  EXPORT_SYMBOL(dcache_readdir);
4606 +EXPORT_SYMBOL(dcache_readdir_filter);
4607  EXPORT_SYMBOL(generic_read_dir);
4608  EXPORT_SYMBOL(get_sb_pseudo);
4609  EXPORT_SYMBOL(simple_write_begin);
4610 diff -NurpP --minimal linux-2.6.29/fs/locks.c linux-2.6.29-vs2.3.0.36.9-pre3/fs/locks.c
4611 --- linux-2.6.29/fs/locks.c     2009-03-24 14:22:26.000000000 +0100
4612 +++ linux-2.6.29-vs2.3.0.36.9-pre3/fs/locks.c   2009-03-24 14:48:35.000000000 +0100
4613 @@ -127,6 +127,8 @@
4614  #include <linux/time.h>
4615  #include <linux/rcupdate.h>
4616  #include <linux/pid_namespace.h>
4617 +#include <linux/vs_base.h>
4618 +#include <linux/vs_limit.h>
4619  
4620  #include <asm/uaccess.h>
4621  
4622 @@ -148,6 +150,8 @@ static struct kmem_cache *filelock_cache
4623  /* Allocate an empty lock structure. */
4624  static struct file_lock *locks_alloc_lock(void)
4625  {
4626 +       if (!vx_locks_avail(1))
4627 +               return NULL;
4628         return kmem_cache_alloc(filelock_cache, GFP_KERNEL);
4629  }
4630  
4631 @@ -173,6 +177,7 @@ static void locks_free_lock(struct file_
4632         BUG_ON(!list_empty(&fl->fl_block));
4633         BUG_ON(!list_empty(&fl->fl_link));
4634  
4635 +       vx_locks_dec(fl);
4636         locks_release_private(fl);
4637         kmem_cache_free(filelock_cache, fl);
4638  }
4639 @@ -193,6 +198,7 @@ void locks_init_lock(struct file_lock *f
4640         fl->fl_start = fl->fl_end = 0;
4641         fl->fl_ops = NULL;
4642         fl->fl_lmops = NULL;
4643 +       fl->fl_xid = -1;
4644  }
4645  
4646  EXPORT_SYMBOL(locks_init_lock);
4647 @@ -247,6 +253,7 @@ void locks_copy_lock(struct file_lock *n
4648         new->fl_file = fl->fl_file;
4649         new->fl_ops = fl->fl_ops;
4650         new->fl_lmops = fl->fl_lmops;
4651 +       new->fl_xid = fl->fl_xid;
4652  
4653         locks_copy_private(new, fl);
4654  }
4655 @@ -285,6 +292,11 @@ static int flock_make_lock(struct file *
4656         fl->fl_flags = FL_FLOCK;
4657         fl->fl_type = type;
4658         fl->fl_end = OFFSET_MAX;
4659 +
4660 +       vxd_assert(filp->f_xid == vx_current_xid(),
4661 +               "f_xid(%d) == current(%d)", filp->f_xid, vx_current_xid());
4662 +       fl->fl_xid = filp->f_xid;
4663 +       vx_locks_inc(fl);
4664         
4665         *lock = fl;
4666         return 0;
4667 @@ -450,6 +462,7 @@ static int lease_init(struct file *filp,
4668  
4669         fl->fl_owner = current->files;
4670         fl->fl_pid = current->tgid;
4671 +       fl->fl_xid = vx_current_xid();
4672  
4673         fl->fl_file = filp;
4674         fl->fl_flags = FL_LEASE;
4675 @@ -469,6 +482,11 @@ static struct file_lock *lease_alloc(str
4676         if (fl == NULL)
4677                 return ERR_PTR(error);
4678  
4679 +       fl->fl_xid = vx_current_xid();
4680 +       if (filp)
4681 +               vxd_assert(filp->f_xid == fl->fl_xid,
4682 +                       "f_xid(%d) == fl_xid(%d)", filp->f_xid, fl->fl_xid);
4683 +       vx_locks_inc(fl);
4684         error = lease_init(filp, type, fl);
4685         if (error) {
4686                 locks_free_lock(fl);
4687 @@ -769,6 +787,7 @@ static int flock_lock_file(struct file *
4688         if (found)
4689                 cond_resched_bkl();
4690  
4691 +       new_fl->fl_xid = -1;
4692  find_conflict:
4693         for_each_lock(inode, before) {
4694                 struct file_lock *fl = *before;
4695 @@ -789,6 +808,7 @@ find_conflict:
4696                 goto out;
4697         locks_copy_lock(new_fl, request);
4698         locks_insert_lock(before, new_fl);
4699 +       vx_locks_inc(new_fl);
4700         new_fl = NULL;
4701         error = 0;
4702  
4703 @@ -799,7 +819,8 @@ out:
4704         return error;
4705  }
4706  
4707 -static int __posix_lock_file(struct inode *inode, struct file_lock *request, struct file_lock *conflock)
4708 +static int __posix_lock_file(struct inode *inode, struct file_lock *request,
4709 +       struct file_lock *conflock, xid_t xid)
4710  {
4711         struct file_lock *fl;
4712         struct file_lock *new_fl = NULL;
4713 @@ -809,6 +830,8 @@ static int __posix_lock_file(struct inod
4714         struct file_lock **before;
4715         int error, added = 0;
4716  
4717 +       vxd_assert(xid == vx_current_xid(),
4718 +               "xid(%d) == current(%d)", xid, vx_current_xid());
4719         /*
4720          * We may need two file_lock structures for this operation,
4721          * so we get them in advance to avoid races.
4722 @@ -819,7 +842,11 @@ static int __posix_lock_file(struct inod
4723             (request->fl_type != F_UNLCK ||
4724              request->fl_start != 0 || request->fl_end != OFFSET_MAX)) {
4725                 new_fl = locks_alloc_lock();
4726 +               new_fl->fl_xid = xid;
4727 +               vx_locks_inc(new_fl);
4728                 new_fl2 = locks_alloc_lock();
4729 +               new_fl2->fl_xid = xid;
4730 +               vx_locks_inc(new_fl2);
4731         }
4732  
4733         lock_kernel();
4734 @@ -1018,7 +1045,8 @@ static int __posix_lock_file(struct inod
4735  int posix_lock_file(struct file *filp, struct file_lock *fl,
4736                         struct file_lock *conflock)
4737  {
4738 -       return __posix_lock_file(filp->f_path.dentry->d_inode, fl, conflock);
4739 +       return __posix_lock_file(filp->f_path.dentry->d_inode,
4740 +               fl, conflock, filp->f_xid);
4741  }
4742  EXPORT_SYMBOL(posix_lock_file);
4743  
4744 @@ -1108,7 +1136,7 @@ int locks_mandatory_area(int read_write,
4745         fl.fl_end = offset + count - 1;
4746  
4747         for (;;) {
4748 -               error = __posix_lock_file(inode, &fl, NULL);
4749 +               error = __posix_lock_file(inode, &fl, NULL, filp->f_xid);
4750                 if (error != FILE_LOCK_DEFERRED)
4751                         break;
4752                 error = wait_event_interruptible(fl.fl_wait, !fl.fl_next);
4753 @@ -1423,6 +1451,7 @@ int generic_setlease(struct file *filp, 
4754  
4755         locks_copy_lock(new_fl, lease);
4756         locks_insert_lock(before, new_fl);
4757 +       vx_locks_inc(new_fl);
4758  
4759         *flp = new_fl;
4760         return 0;
4761 @@ -1778,6 +1807,11 @@ int fcntl_setlk(unsigned int fd, struct 
4762         if (file_lock == NULL)
4763                 return -ENOLCK;
4764  
4765 +       vxd_assert(filp->f_xid == vx_current_xid(),
4766 +               "f_xid(%d) == current(%d)", filp->f_xid, vx_current_xid());
4767 +       file_lock->fl_xid = filp->f_xid;
4768 +       vx_locks_inc(file_lock);
4769 +
4770         /*
4771          * This might block, so we do it before checking the inode.
4772          */
4773 @@ -1896,6 +1930,11 @@ int fcntl_setlk64(unsigned int fd, struc
4774         if (file_lock == NULL)
4775                 return -ENOLCK;
4776  
4777 +       vxd_assert(filp->f_xid == vx_current_xid(),
4778 +               "f_xid(%d) == current(%d)", filp->f_xid, vx_current_xid());
4779 +       file_lock->fl_xid = filp->f_xid;
4780 +       vx_locks_inc(file_lock);
4781 +
4782         /*
4783          * This might block, so we do it before checking the inode.
4784          */
4785 @@ -2161,8 +2200,11 @@ static int locks_show(struct seq_file *f
4786  
4787         lock_get_status(f, fl, (long)f->private, "");
4788  
4789 -       list_for_each_entry(bfl, &fl->fl_block, fl_block)
4790 +       list_for_each_entry(bfl, &fl->fl_block, fl_block) {
4791 +               if (!vx_check(fl->fl_xid, VS_WATCH_P | VS_IDENT))
4792 +                       continue;
4793                 lock_get_status(f, bfl, (long)f->private, " ->");
4794 +       }
4795  
4796         f->private++;
4797         return 0;
4798 diff -NurpP --minimal linux-2.6.29/fs/namei.c linux-2.6.29-vs2.3.0.36.9-pre3/fs/namei.c
4799 --- linux-2.6.29/fs/namei.c     2009-03-24 14:22:26.000000000 +0100
4800 +++ linux-2.6.29-vs2.3.0.36.9-pre3/fs/namei.c   2009-03-25 00:50:11.000000000 +0100
4801 @@ -31,6 +31,14 @@
4802  #include <linux/file.h>
4803  #include <linux/fcntl.h>
4804  #include <linux/device_cgroup.h>
4805 +#include <linux/proc_fs.h>
4806 +#include <linux/vserver/inode.h>
4807 +#include <linux/vs_base.h>
4808 +#include <linux/vs_tag.h>
4809 +#include <linux/vs_cowbl.h>
4810 +#include <linux/vs_device.h>
4811 +#include <linux/vs_context.h>
4812 +#include <linux/pid_namespace.h>
4813  #include <asm/uaccess.h>
4814  
4815  #define ACC_MODE(x) ("\000\004\002\006"[(x)&O_ACCMODE])
4816 @@ -167,6 +175,77 @@ void putname(const char *name)
4817  EXPORT_SYMBOL(putname);
4818  #endif
4819  
4820 +static inline int dx_barrier(struct inode *inode)
4821 +{
4822 +       if (IS_BARRIER(inode) && !vx_check(0, VS_ADMIN | VS_WATCH)) {
4823 +               vxwprintk_task(1, "did hit the barrier.");
4824 +               return 1;
4825 +       }
4826 +       return 0;
4827 +}
4828 +
4829 +static int __dx_permission(struct inode *inode, int mask)
4830 +{
4831 +       if (dx_barrier(inode))
4832 +               return -EACCES;
4833 +
4834 +       if (inode->i_sb->s_magic == DEVPTS_SUPER_MAGIC) {
4835 +               /* devpts is xid tagged */
4836 +               if (S_ISDIR(inode->i_mode) ||
4837 +                   vx_check((xid_t)inode->i_tag, VS_IDENT | VS_WATCH_P))
4838 +                       return 0;
4839 +       }
4840 +       else if (inode->i_sb->s_magic == PROC_SUPER_MAGIC) {
4841 +               struct proc_dir_entry *de = PDE(inode);
4842 +
4843 +               if (de && !vx_hide_check(0, de->vx_flags))
4844 +                       goto out;
4845 +
4846 +               if ((mask & (MAY_WRITE | MAY_APPEND))) {
4847 +                       struct pid *pid;
4848 +                       struct task_struct *tsk;
4849 +
4850 +                       if (vx_check(0, VS_ADMIN | VS_WATCH_P) ||
4851 +                           vx_flags(VXF_STATE_SETUP, 0))
4852 +                               return 0;
4853 +
4854 +                       pid = PROC_I(inode)->pid;
4855 +                       if (!pid)
4856 +                               goto out;
4857 +
4858 +                       tsk = pid_task(pid, PIDTYPE_PID);
4859 +                       vxdprintk(VXD_CBIT(tag, 0), "accessing %p[#%u]",
4860 +                                 tsk, (tsk ? vx_task_xid(tsk) : 0));
4861 +                       if (tsk && vx_check(vx_task_xid(tsk), VS_IDENT | VS_WATCH_P))
4862 +                               return 0;
4863 +               }
4864 +               else {
4865 +                       /* FIXME: Should we block some entries here? */
4866 +                       return 0;
4867 +               }
4868 +       }
4869 +       else {
4870 +               if (dx_notagcheck(inode->i_sb) ||
4871 +                   dx_check(inode->i_tag, DX_HOSTID | DX_ADMIN | DX_WATCH |
4872 +                            DX_IDENT))
4873 +                       return 0;
4874 +       }
4875 +
4876 +out:
4877 +       return -EACCES;
4878 +}
4879 +
4880 +int dx_permission(struct inode *inode, int mask)
4881 +{
4882 +       int ret = __dx_permission(inode, mask);
4883 +       if (unlikely(ret)) {
4884 +               vxwprintk_task(1, "denied %x access to %s:%p[#%d,%lu]",
4885 +                       mask, inode->i_sb->s_id, inode, inode->i_tag,
4886 +                       inode->i_ino);
4887 +       }
4888 +       return ret;
4889 +}
4890 +
4891  
4892  /**
4893   * generic_permission  -  check for access rights on a Posix-like filesystem
4894 @@ -253,10 +332,14 @@ int inode_permission(struct inode *inode
4895                 /*
4896                  * Nobody gets write access to an immutable file.
4897                  */
4898 -               if (IS_IMMUTABLE(inode))
4899 +               if (IS_IMMUTABLE(inode) && !IS_COW(inode))
4900                         return -EACCES;
4901         }
4902  
4903 +       retval = dx_permission(inode, mask);
4904 +       if (retval)
4905 +               return retval;
4906 +
4907         if (inode->i_op->permission)
4908                 retval = inode->i_op->permission(inode, mask);
4909         else
4910 @@ -432,6 +515,8 @@ static int exec_permission_lite(struct i
4911  {
4912         umode_t mode = inode->i_mode;
4913  
4914 +       if (dx_barrier(inode))
4915 +               return -EACCES;
4916         if (inode->i_op->permission)
4917                 return -EAGAIN;
4918  
4919 @@ -749,7 +834,8 @@ static __always_inline void follow_dotdo
4920                 if (nd->path.dentry == fs->root.dentry &&
4921                     nd->path.mnt == fs->root.mnt) {
4922                          read_unlock(&fs->lock);
4923 -                       break;
4924 +                       /* for sane '/' avoid follow_mount() */
4925 +                       return;
4926                 }
4927                  read_unlock(&fs->lock);
4928                 spin_lock(&dcache_lock);
4929 @@ -786,16 +872,30 @@ static int do_lookup(struct nameidata *n
4930  {
4931         struct vfsmount *mnt = nd->path.mnt;
4932         struct dentry *dentry = __d_lookup(nd->path.dentry, name);
4933 +       struct inode *inode;
4934  
4935         if (!dentry)
4936                 goto need_lookup;
4937         if (dentry->d_op && dentry->d_op->d_revalidate)
4938                 goto need_revalidate;
4939 +       inode = dentry->d_inode;
4940 +       if (!inode)
4941 +               goto done;
4942 +
4943 +       if (__dx_permission(inode, MAY_ACCESS))
4944 +               goto hidden;
4945 +
4946  done:
4947         path->mnt = mnt;
4948         path->dentry = dentry;
4949         __follow_mount(path);
4950         return 0;
4951 +hidden:
4952 +       vxwprintk_task(1, "did lookup hidden %s:%p[#%d,%lu] Â»%s«.",
4953 +               inode->i_sb->s_id, inode, inode->i_tag, inode->i_ino,
4954 +               vxd_path(&nd->path));
4955 +       dput(dentry);
4956 +       return -ENOENT;
4957  
4958  need_lookup:
4959         dentry = real_lookup(nd->path.dentry, name, nd);
4960 @@ -1364,7 +1464,7 @@ static int may_delete(struct inode *dir,
4961         if (IS_APPEND(dir))
4962                 return -EPERM;
4963         if (check_sticky(dir, victim->d_inode)||IS_APPEND(victim->d_inode)||
4964 -           IS_IMMUTABLE(victim->d_inode) || IS_SWAPFILE(victim->d_inode))
4965 +               IS_IXORUNLINK(victim->d_inode) || IS_SWAPFILE(victim->d_inode))
4966                 return -EPERM;
4967         if (isdir) {
4968                 if (!S_ISDIR(victim->d_inode->i_mode))
4969 @@ -1506,6 +1606,14 @@ int may_open(struct path *path, int acc_
4970                 flag &= ~O_TRUNC;
4971         }
4972  
4973 +#ifdef CONFIG_VSERVER_COWBL
4974 +       if (IS_COW(inode) && (flag & FMODE_WRITE)) {
4975 +               if (IS_COW_LINK(inode))
4976 +                       return -EMLINK;
4977 +               inode->i_flags &= ~(S_IXUNLINK|S_IMMUTABLE);
4978 +               mark_inode_dirty(inode);
4979 +       }
4980 +#endif
4981         error = inode_permission(inode, acc_mode);
4982         if (error)
4983                 return error;
4984 @@ -1639,6 +1747,11 @@ struct file *do_filp_open(int dfd, const
4985         int will_write;
4986         int flag = open_to_namei_flags(open_flag);
4987  
4988 +#ifdef CONFIG_VSERVER_COWBL
4989 +       int rflag = flag;
4990 +       int rmode = mode;
4991 +restart:
4992 +#endif
4993         acc_mode = MAY_OPEN | ACC_MODE(flag);
4994  
4995         /* O_TRUNC implies we need access checks for write permissions */
4996 @@ -1771,6 +1884,25 @@ ok:
4997                         goto exit;
4998         }
4999         error = may_open(&nd.path, acc_mode, flag);
5000 +#ifdef CONFIG_VSERVER_COWBL
5001 +       if (error == -EMLINK) {
5002 +               struct dentry *dentry;
5003 +               dentry = cow_break_link(pathname);
5004 +               if (IS_ERR(dentry)) {
5005 +                       error = PTR_ERR(dentry);
5006 +                       goto exit_cow;
5007 +               }
5008 +               dput(dentry);
5009 +               if (will_write)
5010 +                       mnt_drop_write(nd.path.mnt);
5011 +               release_open_intent(&nd);
5012 +               path_put(&nd.path);
5013 +               flag = rflag;
5014 +               mode = rmode;
5015 +               goto restart;
5016 +       }
5017 +exit_cow:
5018 +#endif
5019         if (error) {
5020                 if (will_write)
5021                         mnt_drop_write(nd.path.mnt);
5022 @@ -1924,9 +2056,17 @@ int vfs_mknod(struct inode *dir, struct 
5023         if (error)
5024                 return error;
5025  
5026 -       if ((S_ISCHR(mode) || S_ISBLK(mode)) && !capable(CAP_MKNOD))
5027 +       if (!(S_ISCHR(mode) || S_ISBLK(mode)))
5028 +               goto okay;
5029 +
5030 +       if (!capable(CAP_MKNOD))
5031                 return -EPERM;
5032  
5033 +       if (S_ISCHR(mode) && !vs_chrdev_perm(dev, DATTR_CREATE))
5034 +               return -EPERM;
5035 +       if (S_ISBLK(mode) && !vs_blkdev_perm(dev, DATTR_CREATE))
5036 +               return -EPERM;
5037 +okay:
5038         if (!dir->i_op->mknod)
5039                 return -EPERM;
5040  
5041 @@ -2393,7 +2533,7 @@ int vfs_link(struct dentry *old_dentry, 
5042         /*
5043          * A link to an append-only or immutable file cannot be created.
5044          */
5045 -       if (IS_APPEND(inode) || IS_IMMUTABLE(inode))
5046 +       if (IS_APPEND(inode) || IS_IXORUNLINK(inode))
5047                 return -EPERM;
5048         if (!dir->i_op->link)
5049                 return -EPERM;
5050 @@ -2766,6 +2906,219 @@ int vfs_follow_link(struct nameidata *nd
5051         return __vfs_follow_link(nd, link);
5052  }
5053  
5054 +
5055 +#ifdef CONFIG_VSERVER_COWBL
5056 +
5057 +#include <linux/file.h>
5058 +
5059 +static inline
5060 +long do_cow_splice(struct file *in, struct file *out, size_t len)
5061 +{
5062 +       loff_t ppos = 0;
5063 +
5064 +       return do_splice_direct(in, &ppos, out, len, 0);
5065 +}
5066 +
5067 +struct dentry *cow_break_link(const char *pathname)
5068 +{
5069 +       int ret, mode, pathlen, redo = 0;
5070 +       struct nameidata old_nd, dir_nd;
5071 +       struct path old_path, new_path;
5072 +       struct dentry *dir, *res = NULL;
5073 +       struct file *old_file;
5074 +       struct file *new_file;
5075 +       char *to, *path, pad='\251';
5076 +       loff_t size;
5077 +
5078 +       vxdprintk(VXD_CBIT(misc, 1), "cow_break_link(»%s«)", pathname);
5079 +       path = kmalloc(PATH_MAX, GFP_KERNEL);
5080 +       ret = -ENOMEM;
5081 +       if (!path)
5082 +               goto out;
5083 +
5084 +       /* old_nd will have refs to dentry and mnt */
5085 +       ret = path_lookup(pathname, LOOKUP_FOLLOW, &old_nd);
5086 +       vxdprintk(VXD_CBIT(misc, 2), "path_lookup(old): %d", ret);
5087 +       if (ret < 0)
5088 +               goto out_free_path;
5089 +
5090 +       old_path = old_nd.path;
5091 +       mode = old_path.dentry->d_inode->i_mode;
5092 +
5093 +       to = d_path(&old_path, path, PATH_MAX-2);
5094 +       pathlen = strlen(to);
5095 +       vxdprintk(VXD_CBIT(misc, 2), "old path Â»%s« [»%.*s«:%d]", to,
5096 +               old_path.dentry->d_name.len, old_path.dentry->d_name.name,
5097 +               old_path.dentry->d_name.len);
5098 +
5099 +       to[pathlen + 1] = 0;
5100 +retry:
5101 +       to[pathlen] = pad--;
5102 +       ret = -EMLINK;
5103 +       if (pad <= '\240')
5104 +               goto out_rel_old;
5105 +
5106 +       vxdprintk(VXD_CBIT(misc, 1), "temp copy Â»%s«", to);
5107 +       /* dir_nd will have refs to dentry and mnt */
5108 +       ret = path_lookup(to,
5109 +               LOOKUP_PARENT | LOOKUP_OPEN | LOOKUP_CREATE, &dir_nd);
5110 +       vxdprintk(VXD_CBIT(misc, 2),
5111 +               "path_lookup(new): %d", ret);
5112 +       if (ret < 0)
5113 +               goto retry;
5114 +
5115 +       /* this puppy downs the inode mutex */
5116 +       new_path.dentry = lookup_create(&dir_nd, 0);
5117 +       if (!new_path.dentry || IS_ERR(new_path.dentry)) {
5118 +               vxdprintk(VXD_CBIT(misc, 2),
5119 +                       "lookup_create(new): %p", new_path.dentry);
5120 +               mutex_unlock(&dir_nd.path.dentry->d_inode->i_mutex);
5121 +               path_put(&dir_nd.path);
5122 +               goto retry;
5123 +       }
5124 +       vxdprintk(VXD_CBIT(misc, 2),
5125 +               "lookup_create(new): %p [»%.*s«:%d]", new_path.dentry,
5126 +               new_path.dentry->d_name.len, new_path.dentry->d_name.name,
5127 +               new_path.dentry->d_name.len);
5128 +       dir = dir_nd.path.dentry;
5129 +
5130 +       ret = vfs_create(dir_nd.path.dentry->d_inode, new_path.dentry, mode, &dir_nd);
5131 +       vxdprintk(VXD_CBIT(misc, 2),
5132 +               "vfs_create(new): %d", ret);
5133 +       if (ret == -EEXIST) {
5134 +               mutex_unlock(&dir->d_inode->i_mutex);
5135 +               dput(new_path.dentry);
5136 +               path_put(&dir_nd.path);
5137 +               goto retry;
5138 +       }
5139 +       else if (ret < 0)
5140 +               goto out_unlock_new;
5141 +
5142 +       /* drop out early, ret passes ENOENT */
5143 +       ret = -ENOENT;
5144 +       if ((redo = d_unhashed(old_path.dentry)))
5145 +               goto out_unlock_new;
5146 +
5147 +       new_path.mnt = dir_nd.path.mnt;
5148 +       dget(old_path.dentry);
5149 +       mntget(old_path.mnt);
5150 +       /* this one cleans up the dentry/mnt in case of failure */
5151 +       old_file = dentry_open(old_path.dentry, old_path.mnt,
5152 +               O_RDONLY, current_cred());
5153 +       vxdprintk(VXD_CBIT(misc, 2),
5154 +               "dentry_open(old): %p", old_file);
5155 +       if (!old_file || IS_ERR(old_file)) {
5156 +               res = IS_ERR(old_file) ? (void *) old_file : res;
5157 +               goto out_unlock_new;
5158 +       }
5159 +
5160 +       dget(new_path.dentry);
5161 +       mntget(new_path.mnt);
5162 +       /* this one cleans up the dentry/mnt in case of failure */
5163 +       new_file = dentry_open(new_path.dentry, new_path.mnt,
5164 +               O_WRONLY, current_cred());
5165 +       vxdprintk(VXD_CBIT(misc, 2),
5166 +               "dentry_open(new): %p", new_file);
5167 +
5168 +       ret = IS_ERR(new_file) ? PTR_ERR(new_file) : -ENOENT;
5169 +       if (!new_file || IS_ERR(new_file))
5170 +               goto out_fput_old;
5171 +
5172 +       size = i_size_read(old_file->f_dentry->d_inode);
5173 +       ret = do_cow_splice(old_file, new_file, size);
5174 +       vxdprintk(VXD_CBIT(misc, 2), "do_splice_direct: %d", ret);
5175 +       if (ret < 0) {
5176 +               goto out_fput_both;
5177 +       } else if (ret < size) {
5178 +               ret = -ENOSPC;
5179 +               goto out_fput_both;
5180 +       } else {
5181 +               struct inode *old_inode = old_path.dentry->d_inode;
5182 +               struct inode *new_inode = new_path.dentry->d_inode;
5183 +               struct iattr attr = {
5184 +                       .ia_uid = old_inode->i_uid,
5185 +                       .ia_gid = old_inode->i_gid,
5186 +                       .ia_valid = ATTR_UID | ATTR_GID
5187 +                       };
5188 +
5189 +               ret = inode_setattr(new_inode, &attr);
5190 +               if (ret)
5191 +                       goto out_fput_both;
5192 +       }
5193 +
5194 +       mutex_lock(&old_path.dentry->d_inode->i_sb->s_vfs_rename_mutex);
5195 +
5196 +       /* drop out late */
5197 +       ret = -ENOENT;
5198 +       if ((redo = d_unhashed(old_path.dentry)))
5199 +               goto out_unlock;
5200 +
5201 +       vxdprintk(VXD_CBIT(misc, 2),
5202 +               "vfs_rename: [»%*s«:%d] -> [»%*s«:%d]",
5203 +               new_path.dentry->d_name.len, new_path.dentry->d_name.name,
5204 +               new_path.dentry->d_name.len,
5205 +               old_path.dentry->d_name.len, old_path.dentry->d_name.name,
5206 +               old_path.dentry->d_name.len);
5207 +       ret = vfs_rename(dir_nd.path.dentry->d_inode, new_path.dentry,
5208 +               old_nd.path.dentry->d_parent->d_inode, old_path.dentry);
5209 +       vxdprintk(VXD_CBIT(misc, 2), "vfs_rename: %d", ret);
5210 +       res = new_path.dentry;
5211 +
5212 +out_unlock:
5213 +       mutex_unlock(&old_path.dentry->d_inode->i_sb->s_vfs_rename_mutex);
5214 +
5215 +out_fput_both:
5216 +       vxdprintk(VXD_CBIT(misc, 3),
5217 +               "fput(new_file=%p[#%ld])", new_file,
5218 +               atomic_read(&new_file->f_count));
5219 +       fput(new_file);
5220 +
5221 +out_fput_old:
5222 +       vxdprintk(VXD_CBIT(misc, 3),
5223 +               "fput(old_file=%p[#%ld])", old_file,
5224 +               atomic_read(&old_file->f_count));
5225 +       fput(old_file);
5226 +
5227 +out_unlock_new:
5228 +       mutex_unlock(&dir->d_inode->i_mutex);
5229 +       if (!ret)
5230 +               goto out_redo;
5231 +
5232 +       /* error path cleanup */
5233 +       vfs_unlink(dir->d_inode, new_path.dentry);
5234 +       dput(new_path.dentry);
5235 +
5236 +out_redo:
5237 +       if (!redo)
5238 +               goto out_rel_both;
5239 +       /* lookup dentry once again */
5240 +       path_put(&old_nd.path);
5241 +       ret = path_lookup(pathname, LOOKUP_FOLLOW, &old_nd);
5242 +       if (ret)
5243 +               goto out_rel_both;
5244 +
5245 +       new_path.dentry = old_nd.path.dentry;
5246 +       vxdprintk(VXD_CBIT(misc, 2),
5247 +               "path_lookup(redo): %p [»%.*s«:%d]", new_path.dentry,
5248 +               new_path.dentry->d_name.len, new_path.dentry->d_name.name,
5249 +               new_path.dentry->d_name.len);
5250 +       dget(new_path.dentry);
5251 +       res = new_path.dentry;
5252 +
5253 +out_rel_both:
5254 +       path_put(&dir_nd.path);
5255 +out_rel_old:
5256 +       path_put(&old_nd.path);
5257 +out_free_path:
5258 +       kfree(path);
5259 +out:
5260 +       if (ret)
5261 +               res = ERR_PTR(ret);
5262 +       return res;
5263 +}
5264 +
5265 +#endif
5266 +
5267  /* get the link contents into pagecache */
5268  static char *page_getlink(struct dentry * dentry, struct page **ppage)
5269  {
5270 diff -NurpP --minimal linux-2.6.29/fs/namespace.c linux-2.6.29-vs2.3.0.36.9-pre3/fs/namespace.c
5271 --- linux-2.6.29/fs/namespace.c 2009-03-24 14:22:26.000000000 +0100
5272 +++ linux-2.6.29-vs2.3.0.36.9-pre3/fs/namespace.c       2009-03-24 14:48:35.000000000 +0100
5273 @@ -27,6 +27,11 @@
5274  #include <linux/ramfs.h>
5275  #include <linux/log2.h>
5276  #include <linux/idr.h>
5277 +#include <linux/vs_base.h>
5278 +#include <linux/vs_context.h>
5279 +#include <linux/vs_tag.h>
5280 +#include <linux/vserver/space.h>
5281 +#include <linux/vserver/global.h>
5282  #include <asm/uaccess.h>
5283  #include <asm/unistd.h>
5284  #include "pnode.h"
5285 @@ -573,6 +578,7 @@ static struct vfsmount *clone_mnt(struct
5286                 mnt->mnt_root = dget(root);
5287                 mnt->mnt_mountpoint = mnt->mnt_root;
5288                 mnt->mnt_parent = mnt;
5289 +               mnt->mnt_tag = old->mnt_tag;
5290  
5291                 if (flag & CL_SLAVE) {
5292                         list_add(&mnt->mnt_slave, &old->mnt_slave_list);
5293 @@ -687,6 +693,31 @@ static inline void mangle(struct seq_fil
5294         seq_escape(m, s, " \t\n\\");
5295  }
5296  
5297 +static int mnt_is_reachable(struct vfsmount *mnt)
5298 +{
5299 +       struct path root;
5300 +       struct dentry *point;
5301 +       int ret;
5302 +
5303 +       if (mnt == mnt->mnt_ns->root)
5304 +               return 1;
5305 +
5306 +       spin_lock(&vfsmount_lock);
5307 +       root = current->fs->root;
5308 +       point = root.dentry;
5309 +
5310 +       while ((mnt != mnt->mnt_parent) && (mnt != root.mnt)) {
5311 +               point = mnt->mnt_mountpoint;
5312 +               mnt = mnt->mnt_parent;
5313 +       }
5314 +
5315 +       ret = (mnt == root.mnt) && is_subdir(point, root.dentry);
5316 +
5317 +       spin_unlock(&vfsmount_lock);
5318 +
5319 +       return ret;
5320 +}
5321 +
5322  /*
5323   * Simple .show_options callback for filesystems which don't want to
5324   * implement more complex mount option showing.
5325 @@ -759,6 +790,8 @@ static int show_sb_opts(struct seq_file 
5326                 { MS_SYNCHRONOUS, ",sync" },
5327                 { MS_DIRSYNC, ",dirsync" },
5328                 { MS_MANDLOCK, ",mand" },
5329 +               { MS_TAGGED, ",tag" },
5330 +               { MS_NOTAGCHECK, ",notagcheck" },
5331                 { 0, NULL }
5332         };
5333         const struct proc_fs_info *fs_infop;
5334 @@ -805,10 +838,20 @@ static int show_vfsmnt(struct seq_file *
5335         int err = 0;
5336         struct path mnt_path = { .dentry = mnt->mnt_root, .mnt = mnt };
5337  
5338 -       mangle(m, mnt->mnt_devname ? mnt->mnt_devname : "none");
5339 -       seq_putc(m, ' ');
5340 -       seq_path(m, &mnt_path, " \t\n\\");
5341 -       seq_putc(m, ' ');
5342 +       if (vx_flags(VXF_HIDE_MOUNT, 0))
5343 +               return SEQ_SKIP;
5344 +       if (!mnt_is_reachable(mnt) && !vx_check(0, VS_WATCH_P))
5345 +               return SEQ_SKIP;
5346 +
5347 +       if (!vx_check(0, VS_ADMIN|VS_WATCH) &&
5348 +               mnt == current->fs->root.mnt) {
5349 +               seq_puts(m, "/dev/root / ");
5350 +       } else {
5351 +               mangle(m, mnt->mnt_devname ? mnt->mnt_devname : "none");
5352 +               seq_putc(m, ' ');
5353 +               seq_path(m, &mnt_path, " \t\n\\");
5354 +               seq_putc(m, ' ');
5355 +       }
5356         show_type(m, mnt->mnt_sb);
5357         seq_puts(m, __mnt_is_readonly(mnt) ? " ro" : " rw");
5358         err = show_sb_opts(m, mnt->mnt_sb);
5359 @@ -838,6 +881,11 @@ static int show_mountinfo(struct seq_fil
5360         struct path root = p->root;
5361         int err = 0;
5362  
5363 +       if (vx_flags(VXF_HIDE_MOUNT, 0))
5364 +               return SEQ_SKIP;
5365 +       if (!mnt_is_reachable(mnt) && !vx_check(0, VS_WATCH_P))
5366 +               return SEQ_SKIP;
5367 +
5368         seq_printf(m, "%i %i %u:%u ", mnt->mnt_id, mnt->mnt_parent->mnt_id,
5369                    MAJOR(sb->s_dev), MINOR(sb->s_dev));
5370         seq_dentry(m, mnt->mnt_root, " \t\n\\");
5371 @@ -896,17 +944,27 @@ static int show_vfsstat(struct seq_file 
5372         struct path mnt_path = { .dentry = mnt->mnt_root, .mnt = mnt };
5373         int err = 0;
5374  
5375 -       /* device */
5376 -       if (mnt->mnt_devname) {
5377 -               seq_puts(m, "device ");
5378 -               mangle(m, mnt->mnt_devname);
5379 -       } else
5380 -               seq_puts(m, "no device");
5381 +       if (vx_flags(VXF_HIDE_MOUNT, 0))
5382 +               return SEQ_SKIP;
5383 +       if (!mnt_is_reachable(mnt) && !vx_check(0, VS_WATCH_P))
5384 +               return SEQ_SKIP;
5385  
5386 -       /* mount point */
5387 -       seq_puts(m, " mounted on ");
5388 -       seq_path(m, &mnt_path, " \t\n\\");
5389 -       seq_putc(m, ' ');
5390 +       if (!vx_check(0, VS_ADMIN|VS_WATCH) &&
5391 +               mnt == current->fs->root.mnt) {
5392 +               seq_puts(m, "device /dev/root mounted on / ");
5393 +       } else {
5394 +               /* device */
5395 +               if (mnt->mnt_devname) {
5396 +                       seq_puts(m, "device ");
5397 +                       mangle(m, mnt->mnt_devname);
5398 +               } else
5399 +                       seq_puts(m, "no device");
5400 +
5401 +               /* mount point */
5402 +               seq_puts(m, " mounted on ");
5403 +               seq_path(m, &mnt_path, " \t\n\\");
5404 +               seq_putc(m, ' ');
5405 +       }
5406  
5407         /* file system type */
5408         seq_puts(m, "with fstype ");
5409 @@ -1145,7 +1203,7 @@ SYSCALL_DEFINE2(umount, char __user *, n
5410                 goto dput_and_out;
5411  
5412         retval = -EPERM;
5413 -       if (!capable(CAP_SYS_ADMIN))
5414 +       if (!vx_capable(CAP_SYS_ADMIN, VXC_SECURE_MOUNT))
5415                 goto dput_and_out;
5416  
5417         retval = do_umount(path.mnt, flags);
5418 @@ -1171,7 +1229,7 @@ SYSCALL_DEFINE1(oldumount, char __user *
5419  
5420  static int mount_is_safe(struct path *path)
5421  {
5422 -       if (capable(CAP_SYS_ADMIN))
5423 +       if (vx_capable(CAP_SYS_ADMIN, VXC_SECURE_MOUNT))
5424                 return 0;
5425         return -EPERM;
5426  #ifdef notyet
5427 @@ -1462,11 +1520,13 @@ static int do_change_type(struct path *p
5428   * do loopback mount.
5429   */
5430  static int do_loopback(struct path *path, char *old_name,
5431 -                               int recurse)
5432 +       tag_t tag, unsigned long flags, int mnt_flags)
5433  {
5434         struct path old_path;
5435         struct vfsmount *mnt = NULL;
5436         int err = mount_is_safe(path);
5437 +       int recurse = flags & MS_REC;
5438 +
5439         if (err)
5440                 return err;
5441         if (!old_name || !*old_name)
5442 @@ -1500,6 +1560,7 @@ static int do_loopback(struct path *path
5443                 spin_unlock(&vfsmount_lock);
5444                 release_mounts(&umount_list);
5445         }
5446 +       mnt->mnt_flags = mnt_flags;
5447  
5448  out:
5449         up_write(&namespace_sem);
5450 @@ -1530,12 +1591,12 @@ static int change_mount_flags(struct vfs
5451   * on it - tough luck.
5452   */
5453  static int do_remount(struct path *path, int flags, int mnt_flags,
5454 -                     void *data)
5455 +       void *data, xid_t xid)
5456  {
5457         int err;
5458         struct super_block *sb = path->mnt->mnt_sb;
5459  
5460 -       if (!capable(CAP_SYS_ADMIN))
5461 +       if (!vx_capable(CAP_SYS_ADMIN, VXC_SECURE_REMOUNT))
5462                 return -EPERM;
5463  
5464         if (!check_mnt(path->mnt))
5465 @@ -1577,7 +1638,7 @@ static int do_move_mount(struct path *pa
5466         struct path old_path, parent_path;
5467         struct vfsmount *p;
5468         int err = 0;
5469 -       if (!capable(CAP_SYS_ADMIN))
5470 +       if (!vx_capable(CAP_SYS_ADMIN, VXC_SECURE_MOUNT))
5471                 return -EPERM;
5472         if (!old_name || !*old_name)
5473                 return -EINVAL;
5474 @@ -1659,7 +1720,7 @@ static int do_new_mount(struct path *pat
5475                 return -EINVAL;
5476  
5477         /* we need capabilities... */
5478 -       if (!capable(CAP_SYS_ADMIN))
5479 +       if (!vx_capable(CAP_SYS_ADMIN, VXC_SECURE_MOUNT))
5480                 return -EPERM;
5481  
5482         mnt = do_kern_mount(type, flags, name, data);
5483 @@ -1904,6 +1965,7 @@ long do_mount(char *dev_name, char *dir_
5484         struct path path;
5485         int retval = 0;
5486         int mnt_flags = 0;
5487 +       tag_t tag = 0;
5488  
5489         /* Discard magic */
5490         if ((flags & MS_MGC_MSK) == MS_MGC_VAL)
5491 @@ -1919,6 +1981,12 @@ long do_mount(char *dev_name, char *dir_
5492         if (data_page)
5493                 ((char *)data_page)[PAGE_SIZE - 1] = 0;
5494  
5495 +       if (dx_parse_tag(data_page, &tag, 1, &mnt_flags, &flags)) {
5496 +               /* FIXME: bind and re-mounts get the tag flag? */
5497 +               if (flags & (MS_BIND|MS_REMOUNT))
5498 +                       flags |= MS_TAGID;
5499 +       }
5500 +
5501         /* Separate the per-mountpoint flags */
5502         if (flags & MS_NOSUID)
5503                 mnt_flags |= MNT_NOSUID;
5504 @@ -1935,6 +2003,8 @@ long do_mount(char *dev_name, char *dir_
5505         if (flags & MS_RDONLY)
5506                 mnt_flags |= MNT_READONLY;
5507  
5508 +       if (!capable(CAP_SYS_ADMIN))
5509 +               mnt_flags |= MNT_NODEV;
5510         flags &= ~(MS_NOSUID | MS_NOEXEC | MS_NODEV | MS_ACTIVE |
5511                    MS_NOATIME | MS_NODIRATIME | MS_RELATIME| MS_KERNMOUNT);
5512  
5513 @@ -1950,9 +2020,9 @@ long do_mount(char *dev_name, char *dir_
5514  
5515         if (flags & MS_REMOUNT)
5516                 retval = do_remount(&path, flags & ~MS_REMOUNT, mnt_flags,
5517 -                                   data_page);
5518 +                                   data_page, tag);
5519         else if (flags & MS_BIND)
5520 -               retval = do_loopback(&path, dev_name, flags & MS_REC);
5521 +               retval = do_loopback(&path, dev_name, tag, flags, mnt_flags);
5522         else if (flags & (MS_SHARED | MS_PRIVATE | MS_SLAVE | MS_UNBINDABLE))
5523                 retval = do_change_type(&path, flags);
5524         else if (flags & MS_MOVE)
5525 @@ -2021,6 +2091,7 @@ static struct mnt_namespace *dup_mnt_ns(
5526                 q = next_mnt(q, new_ns->root);
5527         }
5528         up_write(&namespace_sem);
5529 +       atomic_inc(&vs_global_mnt_ns);
5530  
5531         if (rootmnt)
5532                 mntput(rootmnt);
5533 @@ -2348,5 +2419,6 @@ void __put_mnt_ns(struct mnt_namespace *
5534         spin_unlock(&vfsmount_lock);
5535         up_write(&namespace_sem);
5536         release_mounts(&umount_list);
5537 +       atomic_dec(&vs_global_mnt_ns);
5538         kfree(ns);
5539  }
5540 diff -NurpP --minimal linux-2.6.29/fs/nfs/client.c linux-2.6.29-vs2.3.0.36.9-pre3/fs/nfs/client.c
5541 --- linux-2.6.29/fs/nfs/client.c        2009-03-24 14:22:26.000000000 +0100
5542 +++ linux-2.6.29-vs2.3.0.36.9-pre3/fs/nfs/client.c      2009-03-24 14:48:35.000000000 +0100
5543 @@ -696,6 +696,9 @@ static int nfs_init_server_rpcclient(str
5544         if (server->flags & NFS_MOUNT_SOFT)
5545                 server->client->cl_softrtry = 1;
5546  
5547 +       server->client->cl_tag = 0;
5548 +       if (server->flags & NFS_MOUNT_TAGGED)
5549 +               server->client->cl_tag = 1;
5550         return 0;
5551  }
5552  
5553 @@ -862,6 +865,10 @@ static void nfs_server_set_fsinfo(struct
5554                 server->acdirmin = server->acdirmax = 0;
5555         }
5556  
5557 +       /* FIXME: needs fsinfo
5558 +       if (server->flags & NFS_MOUNT_TAGGED)
5559 +               sb->s_flags |= MS_TAGGED;       */
5560 +
5561         server->maxfilesize = fsinfo->maxfilesize;
5562  
5563         /* We're airborne Set socket buffersize */
5564 diff -NurpP --minimal linux-2.6.29/fs/nfs/dir.c linux-2.6.29-vs2.3.0.36.9-pre3/fs/nfs/dir.c
5565 --- linux-2.6.29/fs/nfs/dir.c   2009-03-24 14:22:26.000000000 +0100
5566 +++ linux-2.6.29-vs2.3.0.36.9-pre3/fs/nfs/dir.c 2009-03-24 14:48:35.000000000 +0100
5567 @@ -34,6 +34,7 @@
5568  #include <linux/namei.h>
5569  #include <linux/mount.h>
5570  #include <linux/sched.h>
5571 +#include <linux/vs_tag.h>
5572  
5573  #include "nfs4_fs.h"
5574  #include "delegation.h"
5575 @@ -950,6 +951,7 @@ static struct dentry *nfs_lookup(struct 
5576         if (IS_ERR(res))
5577                 goto out_unblock_sillyrename;
5578  
5579 +       dx_propagate_tag(nd, inode);
5580  no_entry:
5581         res = d_materialise_unique(dentry, inode);
5582         if (res != NULL) {
5583 diff -NurpP --minimal linux-2.6.29/fs/nfs/inode.c linux-2.6.29-vs2.3.0.36.9-pre3/fs/nfs/inode.c
5584 --- linux-2.6.29/fs/nfs/inode.c 2009-03-24 14:22:26.000000000 +0100
5585 +++ linux-2.6.29-vs2.3.0.36.9-pre3/fs/nfs/inode.c       2009-03-24 14:48:35.000000000 +0100
5586 @@ -37,6 +37,7 @@
5587  #include <linux/vfs.h>
5588  #include <linux/inet.h>
5589  #include <linux/nfs_xdr.h>
5590 +#include <linux/vs_tag.h>
5591  
5592  #include <asm/system.h>
5593  #include <asm/uaccess.h>
5594 @@ -313,8 +314,10 @@ nfs_fhget(struct super_block *sb, struct
5595                         nfsi->change_attr = fattr->change_attr;
5596                 inode->i_size = nfs_size_to_loff_t(fattr->size);
5597                 inode->i_nlink = fattr->nlink;
5598 -               inode->i_uid = fattr->uid;
5599 -               inode->i_gid = fattr->gid;
5600 +               inode->i_uid = INOTAG_UID(DX_TAG(inode), fattr->uid, fattr->gid);
5601 +               inode->i_gid = INOTAG_GID(DX_TAG(inode), fattr->uid, fattr->gid);
5602 +               inode->i_tag = INOTAG_TAG(DX_TAG(inode), fattr->uid, fattr->gid, 0);
5603 +                                        /* maybe fattr->xid someday */
5604                 if (fattr->valid & (NFS_ATTR_FATTR_V3 | NFS_ATTR_FATTR_V4)) {
5605                         /*
5606                          * report the blocks in 512byte units
5607 @@ -462,6 +465,8 @@ void nfs_setattr_update_inode(struct ino
5608                         inode->i_uid = attr->ia_uid;
5609                 if ((attr->ia_valid & ATTR_GID) != 0)
5610                         inode->i_gid = attr->ia_gid;
5611 +               if ((attr->ia_valid & ATTR_TAG) && IS_TAGGED(inode))
5612 +                       inode->i_tag = attr->ia_tag;
5613                 NFS_I(inode)->cache_validity |= NFS_INO_INVALID_ACCESS|NFS_INO_INVALID_ACL;
5614                 spin_unlock(&inode->i_lock);
5615         }
5616 @@ -850,6 +855,9 @@ static int nfs_check_inode_attributes(st
5617         struct nfs_inode *nfsi = NFS_I(inode);
5618         loff_t cur_size, new_isize;
5619         unsigned long invalid = 0;
5620 +       uid_t uid;
5621 +       gid_t gid;
5622 +       tag_t tag;
5623  
5624  
5625         /* Has the inode gone and changed behind our back? */
5626 @@ -871,10 +879,15 @@ static int nfs_check_inode_attributes(st
5627         if (cur_size != new_isize && nfsi->npages == 0)
5628                 invalid |= NFS_INO_INVALID_ATTR|NFS_INO_REVAL_PAGECACHE;
5629  
5630 +       uid = INOTAG_UID(DX_TAG(inode), fattr->uid, fattr->gid);
5631 +       gid = INOTAG_GID(DX_TAG(inode), fattr->uid, fattr->gid);
5632 +       tag = INOTAG_TAG(DX_TAG(inode), fattr->uid, fattr->gid, 0);
5633 +
5634         /* Have any file permissions changed? */
5635         if ((inode->i_mode & S_IALLUGO) != (fattr->mode & S_IALLUGO)
5636 -                       || inode->i_uid != fattr->uid
5637 -                       || inode->i_gid != fattr->gid)
5638 +                       || inode->i_uid != uid
5639 +                       || inode->i_gid != gid
5640 +                       || inode->i_tag != tag)
5641                 invalid |= NFS_INO_INVALID_ATTR | NFS_INO_INVALID_ACCESS | NFS_INO_INVALID_ACL;
5642  
5643         /* Has the link count changed? */
5644 @@ -1073,6 +1086,9 @@ static int nfs_update_inode(struct inode
5645         loff_t cur_isize, new_isize;
5646         unsigned long invalid = 0;
5647         unsigned long now = jiffies;
5648 +       uid_t uid;
5649 +       gid_t gid;
5650 +       tag_t tag;
5651  
5652         dfprintk(VFS, "NFS: %s(%s/%ld ct=%d info=0x%x)\n",
5653                         __func__, inode->i_sb->s_id, inode->i_ino,
5654 @@ -1146,9 +1162,14 @@ static int nfs_update_inode(struct inode
5655         memcpy(&inode->i_atime, &fattr->atime, sizeof(inode->i_atime));
5656         nfsi->change_attr = fattr->change_attr;
5657  
5658 +       uid = INOTAG_UID(DX_TAG(inode), fattr->uid, fattr->gid);
5659 +       gid = INOTAG_GID(DX_TAG(inode), fattr->uid, fattr->gid);
5660 +       tag = INOTAG_TAG(DX_TAG(inode), fattr->uid, fattr->gid, 0);
5661 +
5662         if ((inode->i_mode & S_IALLUGO) != (fattr->mode & S_IALLUGO) ||
5663 -           inode->i_uid != fattr->uid ||
5664 -           inode->i_gid != fattr->gid)
5665 +           inode->i_uid != uid ||
5666 +           inode->i_gid != gid ||
5667 +           inode->i_tag != tag)
5668                 invalid |= NFS_INO_INVALID_ATTR|NFS_INO_INVALID_ACCESS|NFS_INO_INVALID_ACL;
5669  
5670         if (inode->i_nlink != fattr->nlink)
5671 @@ -1156,8 +1177,9 @@ static int nfs_update_inode(struct inode
5672  
5673         inode->i_mode = fattr->mode;
5674         inode->i_nlink = fattr->nlink;
5675 -       inode->i_uid = fattr->uid;
5676 -       inode->i_gid = fattr->gid;
5677 +       inode->i_uid = uid;
5678 +       inode->i_gid = gid;
5679 +       inode->i_tag = tag;
5680  
5681         if (fattr->valid & (NFS_ATTR_FATTR_V3 | NFS_ATTR_FATTR_V4)) {
5682                 /*
5683 diff -NurpP --minimal linux-2.6.29/fs/nfs/nfs3xdr.c linux-2.6.29-vs2.3.0.36.9-pre3/fs/nfs/nfs3xdr.c
5684 --- linux-2.6.29/fs/nfs/nfs3xdr.c       2009-03-24 14:22:26.000000000 +0100
5685 +++ linux-2.6.29-vs2.3.0.36.9-pre3/fs/nfs/nfs3xdr.c     2009-03-24 14:48:35.000000000 +0100
5686 @@ -22,6 +22,7 @@
5687  #include <linux/nfs3.h>
5688  #include <linux/nfs_fs.h>
5689  #include <linux/nfsacl.h>
5690 +#include <linux/vs_tag.h>
5691  #include "internal.h"
5692  
5693  #define NFSDBG_FACILITY                NFSDBG_XDR
5694 @@ -182,7 +183,7 @@ xdr_decode_fattr(__be32 *p, struct nfs_f
5695  }
5696  
5697  static inline __be32 *
5698 -xdr_encode_sattr(__be32 *p, struct iattr *attr)
5699 +xdr_encode_sattr(__be32 *p, struct iattr *attr, int tag)
5700  {
5701         if (attr->ia_valid & ATTR_MODE) {
5702                 *p++ = xdr_one;
5703 @@ -190,15 +191,17 @@ xdr_encode_sattr(__be32 *p, struct iattr
5704         } else {
5705                 *p++ = xdr_zero;
5706         }
5707 -       if (attr->ia_valid & ATTR_UID) {
5708 +       if (attr->ia_valid & ATTR_UID ||
5709 +               (tag && (attr->ia_valid & ATTR_TAG))) {
5710                 *p++ = xdr_one;
5711 -               *p++ = htonl(attr->ia_uid);
5712 +               *p++ = htonl(TAGINO_UID(tag, attr->ia_uid, attr->ia_tag));
5713         } else {
5714                 *p++ = xdr_zero;
5715         }
5716 -       if (attr->ia_valid & ATTR_GID) {
5717 +       if (attr->ia_valid & ATTR_GID ||
5718 +               (tag && (attr->ia_valid & ATTR_TAG))) {
5719                 *p++ = xdr_one;
5720 -               *p++ = htonl(attr->ia_gid);
5721 +               *p++ = htonl(TAGINO_GID(tag, attr->ia_gid, attr->ia_tag));
5722         } else {
5723                 *p++ = xdr_zero;
5724         }
5725 @@ -283,7 +286,8 @@ static int
5726  nfs3_xdr_sattrargs(struct rpc_rqst *req, __be32 *p, struct nfs3_sattrargs *args)
5727  {
5728         p = xdr_encode_fhandle(p, args->fh);
5729 -       p = xdr_encode_sattr(p, args->sattr);
5730 +       p = xdr_encode_sattr(p, args->sattr,
5731 +               req->rq_task->tk_client->cl_tag);
5732         *p++ = htonl(args->guard);
5733         if (args->guard)
5734                 p = xdr_encode_time3(p, &args->guardtime);
5735 @@ -388,7 +392,8 @@ nfs3_xdr_createargs(struct rpc_rqst *req
5736                 *p++ = args->verifier[0];
5737                 *p++ = args->verifier[1];
5738         } else
5739 -               p = xdr_encode_sattr(p, args->sattr);
5740 +               p = xdr_encode_sattr(p, args->sattr,
5741 +                       req->rq_task->tk_client->cl_tag);
5742  
5743         req->rq_slen = xdr_adjust_iovec(req->rq_svec, p);
5744         return 0;
5745 @@ -402,7 +407,8 @@ nfs3_xdr_mkdirargs(struct rpc_rqst *req,
5746  {
5747         p = xdr_encode_fhandle(p, args->fh);
5748         p = xdr_encode_array(p, args->name, args->len);
5749 -       p = xdr_encode_sattr(p, args->sattr);
5750 +       p = xdr_encode_sattr(p, args->sattr,
5751 +               req->rq_task->tk_client->cl_tag);
5752         req->rq_slen = xdr_adjust_iovec(req->rq_svec, p);
5753         return 0;
5754  }
5755 @@ -415,7 +421,8 @@ nfs3_xdr_symlinkargs(struct rpc_rqst *re
5756  {
5757         p = xdr_encode_fhandle(p, args->fromfh);
5758         p = xdr_encode_array(p, args->fromname, args->fromlen);
5759 -       p = xdr_encode_sattr(p, args->sattr);
5760 +       p = xdr_encode_sattr(p, args->sattr,
5761 +               req->rq_task->tk_client->cl_tag);
5762         *p++ = htonl(args->pathlen);
5763         req->rq_slen = xdr_adjust_iovec(req->rq_svec, p);
5764  
5765 @@ -433,7 +440,8 @@ nfs3_xdr_mknodargs(struct rpc_rqst *req,
5766         p = xdr_encode_fhandle(p, args->fh);
5767         p = xdr_encode_array(p, args->name, args->len);
5768         *p++ = htonl(args->type);
5769 -       p = xdr_encode_sattr(p, args->sattr);
5770 +       p = xdr_encode_sattr(p, args->sattr,
5771 +               req->rq_task->tk_client->cl_tag);
5772         if (args->type == NF3CHR || args->type == NF3BLK) {
5773                 *p++ = htonl(MAJOR(args->rdev));
5774                 *p++ = htonl(MINOR(args->rdev));
5775 diff -NurpP --minimal linux-2.6.29/fs/nfs/nfsroot.c linux-2.6.29-vs2.3.0.36.9-pre3/fs/nfs/nfsroot.c
5776 --- linux-2.6.29/fs/nfs/nfsroot.c       2009-03-24 14:22:26.000000000 +0100
5777 +++ linux-2.6.29-vs2.3.0.36.9-pre3/fs/nfs/nfsroot.c     2009-03-24 14:48:35.000000000 +0100
5778 @@ -119,12 +119,12 @@ static int mount_port __initdata = 0;             /
5779  enum {
5780         /* Options that take integer arguments */
5781         Opt_port, Opt_rsize, Opt_wsize, Opt_timeo, Opt_retrans, Opt_acregmin,
5782 -       Opt_acregmax, Opt_acdirmin, Opt_acdirmax,
5783 +       Opt_acregmax, Opt_acdirmin, Opt_acdirmax, Opt_tagid,
5784         /* Options that take no arguments */
5785         Opt_soft, Opt_hard, Opt_intr,
5786         Opt_nointr, Opt_posix, Opt_noposix, Opt_cto, Opt_nocto, Opt_ac, 
5787         Opt_noac, Opt_lock, Opt_nolock, Opt_v2, Opt_v3, Opt_udp, Opt_tcp,
5788 -       Opt_acl, Opt_noacl,
5789 +       Opt_acl, Opt_noacl, Opt_tag, Opt_notag,
5790         /* Error token */
5791         Opt_err
5792  };
5793 @@ -161,6 +161,9 @@ static match_table_t __initconst tokens 
5794         {Opt_tcp, "tcp"},
5795         {Opt_acl, "acl"},
5796         {Opt_noacl, "noacl"},
5797 +       {Opt_tag, "tag"},
5798 +       {Opt_notag, "notag"},
5799 +       {Opt_tagid, "tagid=%u"},
5800         {Opt_err, NULL}
5801         
5802  };
5803 @@ -272,6 +275,20 @@ static int __init root_nfs_parse(char *n
5804                         case Opt_noacl:
5805                                 nfs_data.flags |= NFS_MOUNT_NOACL;
5806                                 break;
5807 +#ifndef CONFIG_TAGGING_NONE
5808 +                       case Opt_tag:
5809 +                               nfs_data.flags |= NFS_MOUNT_TAGGED;
5810 +                               break;
5811 +                       case Opt_notag:
5812 +                               nfs_data.flags &= ~NFS_MOUNT_TAGGED;
5813 +                               break;
5814 +#endif
5815 +#ifdef CONFIG_PROPAGATE
5816 +                       case Opt_tagid:
5817 +                               /* use args[0] */
5818 +                               nfs_data.flags |= NFS_MOUNT_TAGGED;
5819 +                               break;
5820 +#endif
5821                         default:
5822                                 printk(KERN_WARNING "Root-NFS: unknown "
5823                                         "option: %s\n", p);
5824 diff -NurpP --minimal linux-2.6.29/fs/nfs/super.c linux-2.6.29-vs2.3.0.36.9-pre3/fs/nfs/super.c
5825 --- linux-2.6.29/fs/nfs/super.c 2009-03-24 14:22:26.000000000 +0100
5826 +++ linux-2.6.29-vs2.3.0.36.9-pre3/fs/nfs/super.c       2009-03-24 16:02:06.000000000 +0100
5827 @@ -51,6 +51,7 @@
5828  #include <linux/nfs_xdr.h>
5829  #include <linux/magic.h>
5830  #include <linux/parser.h>
5831 +#include <linux/vs_tag.h>
5832  
5833  #include <asm/system.h>
5834  #include <asm/uaccess.h>
5835 @@ -517,6 +518,7 @@ static void nfs_show_mount_options(struc
5836                 { NFS_MOUNT_NORDIRPLUS, ",nordirplus", "" },
5837                 { NFS_MOUNT_UNSHARED, ",nosharecache", "" },
5838                 { NFS_MOUNT_NORESVPORT, ",noresvport", "" },
5839 +               { NFS_MOUNT_TAGGED, ",tag", "" },
5840                 { 0, NULL, NULL }
5841         };
5842         const struct proc_nfs_info *nfs_infop;
5843 diff -NurpP --minimal linux-2.6.29/fs/nfsd/auth.c linux-2.6.29-vs2.3.0.36.9-pre3/fs/nfsd/auth.c
5844 --- linux-2.6.29/fs/nfsd/auth.c 2009-03-24 14:22:26.000000000 +0100
5845 +++ linux-2.6.29-vs2.3.0.36.9-pre3/fs/nfsd/auth.c       2009-03-24 16:09:39.000000000 +0100
5846 @@ -10,6 +10,7 @@
5847  #include <linux/sunrpc/svcauth.h>
5848  #include <linux/nfsd/nfsd.h>
5849  #include <linux/nfsd/export.h>
5850 +#include <linux/vs_tag.h>
5851  #include "auth.h"
5852  
5853  int nfsexp_flags(struct svc_rqst *rqstp, struct svc_export *exp)
5854 @@ -42,6 +43,9 @@ int nfsd_setuser(struct svc_rqst *rqstp,
5855  
5856         new->fsuid = rqstp->rq_cred.cr_uid;
5857         new->fsgid = rqstp->rq_cred.cr_gid;
5858 +       /* FIXME: this desperately needs a tag :)
5859 +       new->xid = (xid_t)INOTAG_TAG(DX_TAG_NFSD, cred.cr_uid, cred.cr_gid, 0);
5860 +                       */
5861  
5862         rqgi = rqstp->rq_cred.cr_group_info;
5863  
5864 @@ -69,7 +73,7 @@ int nfsd_setuser(struct svc_rqst *rqstp,
5865                 }
5866         } else {
5867                 gi = get_group_info(rqgi);
5868 -       }
5869 +       }
5870  
5871         if (new->fsuid == (uid_t) -1)
5872                 new->fsuid = exp->ex_anon_uid;
5873 @@ -94,6 +98,6 @@ oom:
5874         ret = -ENOMEM;
5875  error:
5876         abort_creds(new);
5877 -       return ret;
5878 +       return ret;
5879  }
5880  
5881 diff -NurpP --minimal linux-2.6.29/fs/nfsd/nfs3xdr.c linux-2.6.29-vs2.3.0.36.9-pre3/fs/nfsd/nfs3xdr.c
5882 --- linux-2.6.29/fs/nfsd/nfs3xdr.c      2008-12-25 00:26:37.000000000 +0100
5883 +++ linux-2.6.29-vs2.3.0.36.9-pre3/fs/nfsd/nfs3xdr.c    2009-02-22 22:54:25.000000000 +0100
5884 @@ -21,6 +21,7 @@
5885  #include <linux/sunrpc/svc.h>
5886  #include <linux/nfsd/nfsd.h>
5887  #include <linux/nfsd/xdr3.h>
5888 +#include <linux/vs_tag.h>
5889  #include "auth.h"
5890  
5891  #define NFSDDBG_FACILITY               NFSDDBG_XDR
5892 @@ -108,6 +109,8 @@ static __be32 *
5893  decode_sattr3(__be32 *p, struct iattr *iap)
5894  {
5895         u32     tmp;
5896 +       uid_t   uid = 0;
5897 +       gid_t   gid = 0;
5898  
5899         iap->ia_valid = 0;
5900  
5901 @@ -117,12 +120,15 @@ decode_sattr3(__be32 *p, struct iattr *i
5902         }
5903         if (*p++) {
5904                 iap->ia_valid |= ATTR_UID;
5905 -               iap->ia_uid = ntohl(*p++);
5906 +               uid = ntohl(*p++);
5907         }
5908         if (*p++) {
5909                 iap->ia_valid |= ATTR_GID;
5910 -               iap->ia_gid = ntohl(*p++);
5911 +               gid = ntohl(*p++);
5912         }
5913 +       iap->ia_uid = INOTAG_UID(DX_TAG_NFSD, uid, gid);
5914 +       iap->ia_gid = INOTAG_GID(DX_TAG_NFSD, uid, gid);
5915 +       iap->ia_tag = INOTAG_TAG(DX_TAG_NFSD, uid, gid, 0);
5916         if (*p++) {
5917                 u64     newsize;
5918  
5919 @@ -178,8 +184,12 @@ encode_fattr3(struct svc_rqst *rqstp, __
5920         *p++ = htonl(nfs3_ftypes[(stat->mode & S_IFMT) >> 12]);
5921         *p++ = htonl((u32) stat->mode);
5922         *p++ = htonl((u32) stat->nlink);
5923 -       *p++ = htonl((u32) nfsd_ruid(rqstp, stat->uid));
5924 -       *p++ = htonl((u32) nfsd_rgid(rqstp, stat->gid));
5925 +       *p++ = htonl((u32) nfsd_ruid(rqstp,
5926 +               TAGINO_UID(0 /* FIXME: DX_TAG(dentry->d_inode) */,
5927 +               stat->uid, stat->tag)));
5928 +       *p++ = htonl((u32) nfsd_rgid(rqstp,
5929 +               TAGINO_GID(0 /* FIXME: DX_TAG(dentry->d_inode) */,
5930 +               stat->gid, stat->tag)));
5931         if (S_ISLNK(stat->mode) && stat->size > NFS3_MAXPATHLEN) {
5932                 p = xdr_encode_hyper(p, (u64) NFS3_MAXPATHLEN);
5933         } else {
5934 diff -NurpP --minimal linux-2.6.29/fs/nfsd/nfs4xdr.c linux-2.6.29-vs2.3.0.36.9-pre3/fs/nfsd/nfs4xdr.c
5935 --- linux-2.6.29/fs/nfsd/nfs4xdr.c      2009-03-24 14:22:26.000000000 +0100
5936 +++ linux-2.6.29-vs2.3.0.36.9-pre3/fs/nfsd/nfs4xdr.c    2009-03-24 14:48:35.000000000 +0100
5937 @@ -56,6 +56,7 @@
5938  #include <linux/nfs4_acl.h>
5939  #include <linux/sunrpc/gss_api.h>
5940  #include <linux/sunrpc/svcauth_gss.h>
5941 +#include <linux/vs_tag.h>
5942  
5943  #define NFSDDBG_FACILITY               NFSDDBG_XDR
5944  
5945 @@ -1714,14 +1715,18 @@ out_acl:
5946                 WRITE32(stat.nlink);
5947         }
5948         if (bmval1 & FATTR4_WORD1_OWNER) {
5949 -               status = nfsd4_encode_user(rqstp, stat.uid, &p, &buflen);
5950 +               status = nfsd4_encode_user(rqstp,
5951 +                       TAGINO_UID(DX_TAG(dentry->d_inode),
5952 +                       stat.uid, stat.tag), &p, &buflen);
5953                 if (status == nfserr_resource)
5954                         goto out_resource;
5955                 if (status)
5956                         goto out;
5957         }
5958         if (bmval1 & FATTR4_WORD1_OWNER_GROUP) {
5959 -               status = nfsd4_encode_group(rqstp, stat.gid, &p, &buflen);
5960 +               status = nfsd4_encode_group(rqstp,
5961 +                       TAGINO_GID(DX_TAG(dentry->d_inode),
5962 +                       stat.gid, stat.tag), &p, &buflen);
5963                 if (status == nfserr_resource)
5964                         goto out_resource;
5965                 if (status)
5966 diff -NurpP --minimal linux-2.6.29/fs/nfsd/nfsxdr.c linux-2.6.29-vs2.3.0.36.9-pre3/fs/nfsd/nfsxdr.c
5967 --- linux-2.6.29/fs/nfsd/nfsxdr.c       2008-12-25 00:26:37.000000000 +0100
5968 +++ linux-2.6.29-vs2.3.0.36.9-pre3/fs/nfsd/nfsxdr.c     2009-02-22 22:54:25.000000000 +0100
5969 @@ -15,6 +15,7 @@
5970  #include <linux/nfsd/nfsd.h>
5971  #include <linux/nfsd/xdr.h>
5972  #include <linux/mm.h>
5973 +#include <linux/vs_tag.h>
5974  #include "auth.h"
5975  
5976  #define NFSDDBG_FACILITY               NFSDDBG_XDR
5977 @@ -98,6 +99,8 @@ static __be32 *
5978  decode_sattr(__be32 *p, struct iattr *iap)
5979  {
5980         u32     tmp, tmp1;
5981 +       uid_t   uid = 0;
5982 +       gid_t   gid = 0;
5983  
5984         iap->ia_valid = 0;
5985  
5986 @@ -111,12 +114,15 @@ decode_sattr(__be32 *p, struct iattr *ia
5987         }
5988         if ((tmp = ntohl(*p++)) != (u32)-1) {
5989                 iap->ia_valid |= ATTR_UID;
5990 -               iap->ia_uid = tmp;
5991 +               uid = tmp;
5992         }
5993         if ((tmp = ntohl(*p++)) != (u32)-1) {
5994                 iap->ia_valid |= ATTR_GID;
5995 -               iap->ia_gid = tmp;
5996 +               gid = tmp;
5997         }
5998 +       iap->ia_uid = INOTAG_UID(DX_TAG_NFSD, uid, gid);
5999 +       iap->ia_gid = INOTAG_GID(DX_TAG_NFSD, uid, gid);
6000 +       iap->ia_tag = INOTAG_TAG(DX_TAG_NFSD, uid, gid, 0);
6001         if ((tmp = ntohl(*p++)) != (u32)-1) {
6002                 iap->ia_valid |= ATTR_SIZE;
6003                 iap->ia_size = tmp;
6004 @@ -161,8 +167,10 @@ encode_fattr(struct svc_rqst *rqstp, __b
6005         *p++ = htonl(nfs_ftypes[type >> 12]);
6006         *p++ = htonl((u32) stat->mode);
6007         *p++ = htonl((u32) stat->nlink);
6008 -       *p++ = htonl((u32) nfsd_ruid(rqstp, stat->uid));
6009 -       *p++ = htonl((u32) nfsd_rgid(rqstp, stat->gid));
6010 +       *p++ = htonl((u32) nfsd_ruid(rqstp,
6011 +               TAGINO_UID(DX_TAG(dentry->d_inode), stat->uid, stat->tag)));
6012 +       *p++ = htonl((u32) nfsd_rgid(rqstp,
6013 +               TAGINO_GID(DX_TAG(dentry->d_inode), stat->gid, stat->tag)));
6014  
6015         if (S_ISLNK(type) && stat->size > NFS_MAXPATHLEN) {
6016                 *p++ = htonl(NFS_MAXPATHLEN);
6017 diff -NurpP --minimal linux-2.6.29/fs/ocfs2/dlm/dlmfs.c linux-2.6.29-vs2.3.0.36.9-pre3/fs/ocfs2/dlm/dlmfs.c
6018 --- linux-2.6.29/fs/ocfs2/dlm/dlmfs.c   2009-03-24 14:22:27.000000000 +0100
6019 +++ linux-2.6.29-vs2.3.0.36.9-pre3/fs/ocfs2/dlm/dlmfs.c 2009-03-24 16:10:48.000000000 +0100
6020 @@ -43,6 +43,7 @@
6021  #include <linux/init.h>
6022  #include <linux/string.h>
6023  #include <linux/backing-dev.h>
6024 +#include <linux/vs_tag.h>
6025  
6026  #include <asm/uaccess.h>
6027  
6028 @@ -341,6 +342,7 @@ static struct inode *dlmfs_get_root_inod
6029                 inode->i_mode = mode;
6030                 inode->i_uid = current_fsuid();
6031                 inode->i_gid = current_fsgid();
6032 +               inode->i_tag = dx_current_fstag(sb);
6033                 inode->i_mapping->backing_dev_info = &dlmfs_backing_dev_info;
6034                 inode->i_atime = inode->i_mtime = inode->i_ctime = CURRENT_TIME;
6035                 inc_nlink(inode);
6036 @@ -366,6 +368,7 @@ static struct inode *dlmfs_get_inode(str
6037         inode->i_mode = mode;
6038         inode->i_uid = current_fsuid();
6039         inode->i_gid = current_fsgid();
6040 +       inode->i_tag = dx_current_fstag(sb);
6041         inode->i_mapping->backing_dev_info = &dlmfs_backing_dev_info;
6042         inode->i_atime = inode->i_mtime = inode->i_ctime = CURRENT_TIME;
6043  
6044 diff -NurpP --minimal linux-2.6.29/fs/ocfs2/dlmglue.c linux-2.6.29-vs2.3.0.36.9-pre3/fs/ocfs2/dlmglue.c
6045 --- linux-2.6.29/fs/ocfs2/dlmglue.c     2009-03-24 14:22:27.000000000 +0100
6046 +++ linux-2.6.29-vs2.3.0.36.9-pre3/fs/ocfs2/dlmglue.c   2009-03-24 14:48:35.000000000 +0100
6047 @@ -1885,6 +1885,7 @@ static void __ocfs2_stuff_meta_lvb(struc
6048         lvb->lvb_iclusters = cpu_to_be32(oi->ip_clusters);
6049         lvb->lvb_iuid      = cpu_to_be32(inode->i_uid);
6050         lvb->lvb_igid      = cpu_to_be32(inode->i_gid);
6051 +       lvb->lvb_itag      = cpu_to_be16(inode->i_tag);
6052         lvb->lvb_imode     = cpu_to_be16(inode->i_mode);
6053         lvb->lvb_inlink    = cpu_to_be16(inode->i_nlink);
6054         lvb->lvb_iatime_packed  =
6055 @@ -1939,6 +1940,7 @@ static void ocfs2_refresh_inode_from_lvb
6056  
6057         inode->i_uid     = be32_to_cpu(lvb->lvb_iuid);
6058         inode->i_gid     = be32_to_cpu(lvb->lvb_igid);
6059 +       inode->i_tag     = be16_to_cpu(lvb->lvb_itag);
6060         inode->i_mode    = be16_to_cpu(lvb->lvb_imode);
6061         inode->i_nlink   = be16_to_cpu(lvb->lvb_inlink);
6062         ocfs2_unpack_timespec(&inode->i_atime,
6063 diff -NurpP --minimal linux-2.6.29/fs/ocfs2/dlmglue.h linux-2.6.29-vs2.3.0.36.9-pre3/fs/ocfs2/dlmglue.h
6064 --- linux-2.6.29/fs/ocfs2/dlmglue.h     2009-03-24 14:22:27.000000000 +0100
6065 +++ linux-2.6.29-vs2.3.0.36.9-pre3/fs/ocfs2/dlmglue.h   2009-03-24 14:48:35.000000000 +0100
6066 @@ -46,7 +46,8 @@ struct ocfs2_meta_lvb {
6067         __be16       lvb_inlink;
6068         __be32       lvb_iattr;
6069         __be32       lvb_igeneration;
6070 -       __be32       lvb_reserved2;
6071 +       __be16       lvb_itag;
6072 +       __be16       lvb_reserved2;
6073  };
6074  
6075  #define OCFS2_QINFO_LVB_VERSION 1
6076 diff -NurpP --minimal linux-2.6.29/fs/ocfs2/file.c linux-2.6.29-vs2.3.0.36.9-pre3/fs/ocfs2/file.c
6077 --- linux-2.6.29/fs/ocfs2/file.c        2009-03-24 14:22:27.000000000 +0100
6078 +++ linux-2.6.29-vs2.3.0.36.9-pre3/fs/ocfs2/file.c      2009-03-24 14:48:35.000000000 +0100
6079 @@ -911,13 +911,15 @@ int ocfs2_setattr(struct dentry *dentry,
6080                 mlog(0, "uid change: %d\n", attr->ia_uid);
6081         if (attr->ia_valid & ATTR_GID)
6082                 mlog(0, "gid change: %d\n", attr->ia_gid);
6083 +       if (attr->ia_valid & ATTR_TAG)
6084 +               mlog(0, "tag change: %d\n", attr->ia_tag);
6085         if (attr->ia_valid & ATTR_SIZE)
6086                 mlog(0, "size change...\n");
6087         if (attr->ia_valid & (ATTR_ATIME | ATTR_MTIME | ATTR_CTIME))
6088                 mlog(0, "time change...\n");
6089  
6090  #define OCFS2_VALID_ATTRS (ATTR_ATIME | ATTR_MTIME | ATTR_CTIME | ATTR_SIZE \
6091 -                          | ATTR_GID | ATTR_UID | ATTR_MODE)
6092 +                          | ATTR_GID | ATTR_UID | ATTR_TAG | ATTR_MODE)
6093         if (!(attr->ia_valid & OCFS2_VALID_ATTRS)) {
6094                 mlog(0, "can't handle attrs: 0x%x\n", attr->ia_valid);
6095                 return 0;
6096 @@ -2070,6 +2072,7 @@ const struct inode_operations ocfs2_file
6097         .removexattr    = generic_removexattr,
6098         .fallocate      = ocfs2_fallocate,
6099         .fiemap         = ocfs2_fiemap,
6100 +       .sync_flags     = ocfs2_sync_flags,
6101  };
6102  
6103  const struct inode_operations ocfs2_special_file_iops = {
6104 diff -NurpP --minimal linux-2.6.29/fs/ocfs2/inode.c linux-2.6.29-vs2.3.0.36.9-pre3/fs/ocfs2/inode.c
6105 --- linux-2.6.29/fs/ocfs2/inode.c       2009-03-24 14:22:27.000000000 +0100
6106 +++ linux-2.6.29-vs2.3.0.36.9-pre3/fs/ocfs2/inode.c     2009-03-24 16:11:11.000000000 +0100
6107 @@ -29,6 +29,7 @@
6108  #include <linux/highmem.h>
6109  #include <linux/pagemap.h>
6110  #include <linux/quotaops.h>
6111 +#include <linux/vs_tag.h>
6112  
6113  #include <asm/byteorder.h>
6114  
6115 @@ -44,6 +45,7 @@
6116  #include "file.h"
6117  #include "heartbeat.h"
6118  #include "inode.h"
6119 +#include "ioctl.h"
6120  #include "journal.h"
6121  #include "namei.h"
6122  #include "suballoc.h"
6123 @@ -77,11 +79,13 @@ void ocfs2_set_inode_flags(struct inode 
6124  {
6125         unsigned int flags = OCFS2_I(inode)->ip_attr;
6126  
6127 -       inode->i_flags &= ~(S_IMMUTABLE |
6128 +       inode->i_flags &= ~(S_IMMUTABLE | S_IXUNLINK |
6129                 S_SYNC | S_APPEND | S_NOATIME | S_DIRSYNC);
6130  
6131         if (flags & OCFS2_IMMUTABLE_FL)
6132                 inode->i_flags |= S_IMMUTABLE;
6133 +       if (flags & OCFS2_IXUNLINK_FL)
6134 +               inode->i_flags |= S_IXUNLINK;
6135  
6136         if (flags & OCFS2_SYNC_FL)
6137                 inode->i_flags |= S_SYNC;
6138 @@ -91,25 +95,85 @@ void ocfs2_set_inode_flags(struct inode 
6139                 inode->i_flags |= S_NOATIME;
6140         if (flags & OCFS2_DIRSYNC_FL)
6141                 inode->i_flags |= S_DIRSYNC;
6142 +
6143 +       inode->i_vflags &= ~(V_BARRIER | V_COW);
6144 +
6145 +       if (flags & OCFS2_BARRIER_FL)
6146 +               inode->i_vflags |= V_BARRIER;
6147 +       if (flags & OCFS2_COW_FL)
6148 +               inode->i_vflags |= V_COW;
6149  }
6150  
6151  /* Propagate flags from i_flags to OCFS2_I(inode)->ip_attr */
6152  void ocfs2_get_inode_flags(struct ocfs2_inode_info *oi)
6153  {
6154         unsigned int flags = oi->vfs_inode.i_flags;
6155 +       unsigned int vflags = oi->vfs_inode.i_vflags;
6156 +
6157 +       oi->ip_attr &= ~(OCFS2_SYNC_FL | OCFS2_APPEND_FL |
6158 +                       OCFS2_IMMUTABLE_FL | OCFS2_IXUNLINK_FL |
6159 +                       OCFS2_NOATIME_FL | OCFS2_DIRSYNC_FL |
6160 +                       OCFS2_BARRIER_FL | OCFS2_COW_FL);
6161 +
6162 +       if (flags & S_IMMUTABLE)
6163 +               oi->ip_attr |= OCFS2_IMMUTABLE_FL;
6164 +       if (flags & S_IXUNLINK)
6165 +               oi->ip_attr |= OCFS2_IXUNLINK_FL;
6166  
6167 -       oi->ip_attr &= ~(OCFS2_SYNC_FL|OCFS2_APPEND_FL|
6168 -                       OCFS2_IMMUTABLE_FL|OCFS2_NOATIME_FL|OCFS2_DIRSYNC_FL);
6169         if (flags & S_SYNC)
6170                 oi->ip_attr |= OCFS2_SYNC_FL;
6171         if (flags & S_APPEND)
6172                 oi->ip_attr |= OCFS2_APPEND_FL;
6173 -       if (flags & S_IMMUTABLE)
6174 -               oi->ip_attr |= OCFS2_IMMUTABLE_FL;
6175         if (flags & S_NOATIME)
6176                 oi->ip_attr |= OCFS2_NOATIME_FL;
6177         if (flags & S_DIRSYNC)
6178                 oi->ip_attr |= OCFS2_DIRSYNC_FL;
6179 +
6180 +       if (vflags & V_BARRIER)
6181 +               oi->ip_attr |= OCFS2_BARRIER_FL;
6182 +       if (vflags & V_COW)
6183 +               oi->ip_attr |= OCFS2_COW_FL;
6184 +}
6185 +
6186 +int ocfs2_sync_flags(struct inode *inode)
6187 +{
6188 +       struct ocfs2_inode_info *ocfs2_inode = OCFS2_I(inode);
6189 +       struct ocfs2_super *osb = OCFS2_SB(inode->i_sb);
6190 +       handle_t *handle = NULL;
6191 +       struct buffer_head *bh = NULL;
6192 +       int status;
6193 +
6194 +       status = ocfs2_inode_lock(inode, &bh, 1);
6195 +       if (status < 0) {
6196 +               mlog_errno(status);
6197 +               goto bail;
6198 +       }
6199 +
6200 +       status = -EROFS;
6201 +       if (IS_RDONLY(inode))
6202 +               goto bail_unlock;
6203 +
6204 +       handle = ocfs2_start_trans(osb, OCFS2_INODE_UPDATE_CREDITS);
6205 +       if (IS_ERR(handle)) {
6206 +               status = PTR_ERR(handle);
6207 +               mlog_errno(status);
6208 +               goto bail_unlock;
6209 +       }
6210 +
6211 +       ocfs2_get_inode_flags(ocfs2_inode);
6212 +       status = ocfs2_mark_inode_dirty(handle, inode, bh);
6213 +       if (status < 0)
6214 +               mlog_errno(status);
6215 +
6216 +       ocfs2_commit_trans(osb, handle);
6217 +bail_unlock:
6218 +       ocfs2_inode_unlock(inode, 1);
6219 +bail:
6220 +       if (bh)
6221 +               brelse(bh);
6222 +
6223 +       mlog_exit(status);
6224 +       return status;
6225  }
6226  
6227  struct inode *ocfs2_iget(struct ocfs2_super *osb, u64 blkno, unsigned flags,
6228 @@ -222,6 +286,8 @@ void ocfs2_populate_inode(struct inode *
6229         struct super_block *sb;
6230         struct ocfs2_super *osb;
6231         int use_plocks = 1;
6232 +       uid_t uid;
6233 +       gid_t gid;
6234  
6235         mlog_entry("(0x%p, size:%llu)\n", inode,
6236                    (unsigned long long)le64_to_cpu(fe->i_size));
6237 @@ -253,8 +319,12 @@ void ocfs2_populate_inode(struct inode *
6238         inode->i_generation = le32_to_cpu(fe->i_generation);
6239         inode->i_rdev = huge_decode_dev(le64_to_cpu(fe->id1.dev1.i_rdev));
6240         inode->i_mode = le16_to_cpu(fe->i_mode);
6241 -       inode->i_uid = le32_to_cpu(fe->i_uid);
6242 -       inode->i_gid = le32_to_cpu(fe->i_gid);
6243 +       uid = le32_to_cpu(fe->i_uid);
6244 +       gid = le32_to_cpu(fe->i_gid);
6245 +       inode->i_uid = INOTAG_UID(DX_TAG(inode), uid, gid);
6246 +       inode->i_gid = INOTAG_GID(DX_TAG(inode), uid, gid);
6247 +       inode->i_tag = INOTAG_TAG(DX_TAG(inode), uid, gid,
6248 +               /* le16_to_cpu(raw_inode->i_raw_tag)i */ 0);
6249  
6250         /* Fast symlinks will have i_size but no allocated clusters. */
6251         if (S_ISLNK(inode->i_mode) && !fe->i_clusters)
6252 @@ -1206,8 +1276,11 @@ int ocfs2_mark_inode_dirty(handle_t *han
6253  
6254         fe->i_size = cpu_to_le64(i_size_read(inode));
6255         fe->i_links_count = cpu_to_le16(inode->i_nlink);
6256 -       fe->i_uid = cpu_to_le32(inode->i_uid);
6257 -       fe->i_gid = cpu_to_le32(inode->i_gid);
6258 +       fe->i_uid = cpu_to_le32(TAGINO_UID(DX_TAG(inode),
6259 +               inode->i_uid, inode->i_tag));
6260 +       fe->i_gid = cpu_to_le32(TAGINO_GID(DX_TAG(inode),
6261 +               inode->i_gid, inode->i_tag));
6262 +       /* i_tag = = cpu_to_le16(inode->i_tag); */
6263         fe->i_mode = cpu_to_le16(inode->i_mode);
6264         fe->i_atime = cpu_to_le64(inode->i_atime.tv_sec);
6265         fe->i_atime_nsec = cpu_to_le32(inode->i_atime.tv_nsec);
6266 @@ -1235,16 +1308,25 @@ leave:
6267  void ocfs2_refresh_inode(struct inode *inode,
6268                          struct ocfs2_dinode *fe)
6269  {
6270 +       uid_t uid;
6271 +       gid_t gid;
6272 +
6273         spin_lock(&OCFS2_I(inode)->ip_lock);
6274  
6275         OCFS2_I(inode)->ip_clusters = le32_to_cpu(fe->i_clusters);
6276         OCFS2_I(inode)->ip_attr = le32_to_cpu(fe->i_attr);
6277 +       /* OCFS2_I(inode)->ip_flags &= ~OCFS2_FL_MASK;
6278 +          OCFS2_I(inode)->ip_flags |= le32_to_cpu(fe->i_flags) & OCFS2_FL_MASK; */
6279         OCFS2_I(inode)->ip_dyn_features = le16_to_cpu(fe->i_dyn_features);
6280         ocfs2_set_inode_flags(inode);
6281         i_size_write(inode, le64_to_cpu(fe->i_size));
6282         inode->i_nlink = le16_to_cpu(fe->i_links_count);
6283 -       inode->i_uid = le32_to_cpu(fe->i_uid);
6284 -       inode->i_gid = le32_to_cpu(fe->i_gid);
6285 +       uid = le32_to_cpu(fe->i_uid);
6286 +       gid = le32_to_cpu(fe->i_gid);
6287 +       inode->i_uid = INOTAG_UID(DX_TAG(inode), uid, gid);
6288 +       inode->i_gid = INOTAG_GID(DX_TAG(inode), uid, gid);
6289 +       inode->i_tag = INOTAG_TAG(DX_TAG(inode), uid, gid,
6290 +               /* le16_to_cpu(raw_inode->i_raw_tag)i */ 0);
6291         inode->i_mode = le16_to_cpu(fe->i_mode);
6292         if (S_ISLNK(inode->i_mode) && le32_to_cpu(fe->i_clusters) == 0)
6293                 inode->i_blocks = 0;
6294 diff -NurpP --minimal linux-2.6.29/fs/ocfs2/inode.h linux-2.6.29-vs2.3.0.36.9-pre3/fs/ocfs2/inode.h
6295 --- linux-2.6.29/fs/ocfs2/inode.h       2009-03-24 14:22:27.000000000 +0100
6296 +++ linux-2.6.29-vs2.3.0.36.9-pre3/fs/ocfs2/inode.h     2009-03-24 14:48:35.000000000 +0100
6297 @@ -147,6 +147,7 @@ struct buffer_head *ocfs2_bread(struct i
6298  
6299  void ocfs2_set_inode_flags(struct inode *inode);
6300  void ocfs2_get_inode_flags(struct ocfs2_inode_info *oi);
6301 +int ocfs2_sync_flags(struct inode *inode);
6302  
6303  static inline blkcnt_t ocfs2_inode_sector_count(struct inode *inode)
6304  {
6305 diff -NurpP --minimal linux-2.6.29/fs/ocfs2/ioctl.c linux-2.6.29-vs2.3.0.36.9-pre3/fs/ocfs2/ioctl.c
6306 --- linux-2.6.29/fs/ocfs2/ioctl.c       2008-12-25 00:26:37.000000000 +0100
6307 +++ linux-2.6.29-vs2.3.0.36.9-pre3/fs/ocfs2/ioctl.c     2009-02-22 22:54:25.000000000 +0100
6308 @@ -42,7 +42,7 @@ static int ocfs2_get_inode_attr(struct i
6309         return status;
6310  }
6311  
6312 -static int ocfs2_set_inode_attr(struct inode *inode, unsigned flags,
6313 +int ocfs2_set_inode_attr(struct inode *inode, unsigned flags,
6314                                 unsigned mask)
6315  {
6316         struct ocfs2_inode_info *ocfs2_inode = OCFS2_I(inode);
6317 @@ -67,6 +67,11 @@ static int ocfs2_set_inode_attr(struct i
6318         if (!S_ISDIR(inode->i_mode))
6319                 flags &= ~OCFS2_DIRSYNC_FL;
6320  
6321 +       if (IS_BARRIER(inode)) {
6322 +               vxwprintk_task(1, "messing with the barrier.");
6323 +               goto bail_unlock;
6324 +       }
6325 +
6326         handle = ocfs2_start_trans(osb, OCFS2_INODE_UPDATE_CREDITS);
6327         if (IS_ERR(handle)) {
6328                 status = PTR_ERR(handle);
6329 diff -NurpP --minimal linux-2.6.29/fs/ocfs2/ioctl.h linux-2.6.29-vs2.3.0.36.9-pre3/fs/ocfs2/ioctl.h
6330 --- linux-2.6.29/fs/ocfs2/ioctl.h       2008-12-25 00:26:37.000000000 +0100
6331 +++ linux-2.6.29-vs2.3.0.36.9-pre3/fs/ocfs2/ioctl.h     2009-02-22 22:54:25.000000000 +0100
6332 @@ -10,6 +10,9 @@
6333  #ifndef OCFS2_IOCTL_H
6334  #define OCFS2_IOCTL_H
6335  
6336 +int ocfs2_set_inode_attr(struct inode *inode, unsigned flags,
6337 +                               unsigned mask);
6338 +
6339  long ocfs2_ioctl(struct file *filp, unsigned int cmd, unsigned long arg);
6340  long ocfs2_compat_ioctl(struct file *file, unsigned cmd, unsigned long arg);
6341  
6342 diff -NurpP --minimal linux-2.6.29/fs/ocfs2/namei.c linux-2.6.29-vs2.3.0.36.9-pre3/fs/ocfs2/namei.c
6343 --- linux-2.6.29/fs/ocfs2/namei.c       2009-03-24 14:22:27.000000000 +0100
6344 +++ linux-2.6.29-vs2.3.0.36.9-pre3/fs/ocfs2/namei.c     2009-03-25 01:04:31.000000000 +0100
6345 @@ -41,6 +41,7 @@
6346  #include <linux/slab.h>
6347  #include <linux/highmem.h>
6348  #include <linux/quotaops.h>
6349 +#include <linux/vs_tag.h>
6350  
6351  #define MLOG_MASK_PREFIX ML_NAMEI
6352  #include <cluster/masklog.h>
6353 @@ -462,6 +463,7 @@ static int ocfs2_mknod_locked(struct ocf
6354         struct ocfs2_extent_list *fel;
6355         u64 fe_blkno = 0;
6356         u16 suballoc_bit;
6357 +       tag_t tag;
6358  
6359         mlog_entry("(0x%p, 0x%p, %d, %lu, '%.*s')\n", dir, dentry,
6360                    inode->i_mode, (unsigned long)dev, dentry->d_name.len,
6361 @@ -508,8 +510,11 @@ static int ocfs2_mknod_locked(struct ocf
6362         fe->i_blkno = cpu_to_le64(fe_blkno);
6363         fe->i_suballoc_bit = cpu_to_le16(suballoc_bit);
6364         fe->i_suballoc_slot = cpu_to_le16(inode_ac->ac_alloc_slot);
6365 -       fe->i_uid = cpu_to_le32(inode->i_uid);
6366 -       fe->i_gid = cpu_to_le32(inode->i_gid);
6367 +
6368 +       tag = dx_current_fstag(osb->sb);
6369 +       fe->i_uid = cpu_to_le32(TAGINO_UID(DX_TAG(inode), inode->i_uid, tag));
6370 +       fe->i_gid = cpu_to_le32(TAGINO_GID(DX_TAG(inode), inode->i_gid, tag));
6371 +       inode->i_tag = tag;
6372         fe->i_mode = cpu_to_le16(inode->i_mode);
6373         if (S_ISCHR(inode->i_mode) || S_ISBLK(inode->i_mode))
6374                 fe->id1.dev1.i_rdev = cpu_to_le64(huge_encode_dev(dev));
6375 @@ -2025,6 +2030,7 @@ const struct inode_operations ocfs2_dir_
6376         .rename         = ocfs2_rename,
6377         .setattr        = ocfs2_setattr,
6378         .getattr        = ocfs2_getattr,
6379 +       .sync_flags     = ocfs2_sync_flags,
6380         .permission     = ocfs2_permission,
6381         .setxattr       = generic_setxattr,
6382         .getxattr       = generic_getxattr,
6383 diff -NurpP --minimal linux-2.6.29/fs/ocfs2/ocfs2_fs.h linux-2.6.29-vs2.3.0.36.9-pre3/fs/ocfs2/ocfs2_fs.h
6384 --- linux-2.6.29/fs/ocfs2/ocfs2_fs.h    2009-03-24 14:22:27.000000000 +0100
6385 +++ linux-2.6.29-vs2.3.0.36.9-pre3/fs/ocfs2/ocfs2_fs.h  2009-03-24 14:48:35.000000000 +0100
6386 @@ -219,18 +219,23 @@
6387  #define OCFS2_INDEXED_DIR_FL   (0x0008)
6388  
6389  /* Inode attributes, keep in sync with EXT2 */
6390 -#define OCFS2_SECRM_FL         (0x00000001)    /* Secure deletion */
6391 -#define OCFS2_UNRM_FL          (0x00000002)    /* Undelete */
6392 -#define OCFS2_COMPR_FL         (0x00000004)    /* Compress file */
6393 -#define OCFS2_SYNC_FL          (0x00000008)    /* Synchronous updates */
6394 -#define OCFS2_IMMUTABLE_FL     (0x00000010)    /* Immutable file */
6395 -#define OCFS2_APPEND_FL                (0x00000020)    /* writes to file may only append */
6396 -#define OCFS2_NODUMP_FL                (0x00000040)    /* do not dump file */
6397 -#define OCFS2_NOATIME_FL       (0x00000080)    /* do not update atime */
6398 -#define OCFS2_DIRSYNC_FL       (0x00010000)    /* dirsync behaviour (directories only) */
6399 +#define OCFS2_SECRM_FL         FS_SECRM_FL     /* Secure deletion */
6400 +#define OCFS2_UNRM_FL          FS_UNRM_FL      /* Undelete */
6401 +#define OCFS2_COMPR_FL         FS_COMPR_FL     /* Compress file */
6402 +#define OCFS2_SYNC_FL          FS_SYNC_FL      /* Synchronous updates */
6403 +#define OCFS2_IMMUTABLE_FL     FS_IMMUTABLE_FL /* Immutable file */
6404 +#define OCFS2_APPEND_FL                FS_APPEND_FL    /* writes to file may only append */
6405 +#define OCFS2_NODUMP_FL                FS_NODUMP_FL    /* do not dump file */
6406 +#define OCFS2_NOATIME_FL       FS_NOATIME_FL   /* do not update atime */
6407  
6408 -#define OCFS2_FL_VISIBLE       (0x000100FF)    /* User visible flags */
6409 -#define OCFS2_FL_MODIFIABLE    (0x000100FF)    /* User modifiable flags */
6410 +#define OCFS2_DIRSYNC_FL       FS_DIRSYNC_FL   /* dirsync behaviour (directories only) */
6411 +#define OCFS2_IXUNLINK_FL      FS_IXUNLINK_FL  /* Immutable invert on unlink */
6412 +
6413 +#define OCFS2_BARRIER_FL       FS_BARRIER_FL   /* Barrier for chroot() */
6414 +#define OCFS2_COW_FL           FS_COW_FL       /* Copy on Write marker */
6415 +
6416 +#define OCFS2_FL_VISIBLE       (0x010300FF)    /* User visible flags */
6417 +#define OCFS2_FL_MODIFIABLE    (0x010300FF)    /* User modifiable flags */
6418  
6419  /*
6420   * Extent record flags (e_node.leaf.flags)
6421 diff -NurpP --minimal linux-2.6.29/fs/ocfs2/ocfs2.h linux-2.6.29-vs2.3.0.36.9-pre3/fs/ocfs2/ocfs2.h
6422 --- linux-2.6.29/fs/ocfs2/ocfs2.h       2009-03-24 14:22:27.000000000 +0100
6423 +++ linux-2.6.29-vs2.3.0.36.9-pre3/fs/ocfs2/ocfs2.h     2009-03-24 16:18:22.000000000 +0100
6424 @@ -199,6 +199,7 @@ enum ocfs2_mount_options
6425         OCFS2_MOUNT_POSIX_ACL = 1 << 8, /* POSIX access control lists */
6426         OCFS2_MOUNT_USRQUOTA = 1 << 9, /* We support user quotas */
6427         OCFS2_MOUNT_GRPQUOTA = 1 << 10, /* We support group quotas */
6428 +       OCFS2_MOUNT_TAGGED = 1 << 11, /* use tagging */
6429  };
6430  
6431  #define OCFS2_OSB_SOFT_RO      0x0001
6432 diff -NurpP --minimal linux-2.6.29/fs/ocfs2/super.c linux-2.6.29-vs2.3.0.36.9-pre3/fs/ocfs2/super.c
6433 --- linux-2.6.29/fs/ocfs2/super.c       2009-03-24 14:22:27.000000000 +0100
6434 +++ linux-2.6.29-vs2.3.0.36.9-pre3/fs/ocfs2/super.c     2009-03-24 16:19:44.000000000 +0100
6435 @@ -172,6 +172,7 @@ enum {
6436         Opt_noacl,
6437         Opt_usrquota,
6438         Opt_grpquota,
6439 +       Opt_tag, Opt_notag, Opt_tagid,
6440         Opt_err,
6441  };
6442  
6443 @@ -198,6 +199,9 @@ static const match_table_t tokens = {
6444         {Opt_noacl, "noacl"},
6445         {Opt_usrquota, "usrquota"},
6446         {Opt_grpquota, "grpquota"},
6447 +       {Opt_tag, "tag"},
6448 +       {Opt_notag, "notag"},
6449 +       {Opt_tagid, "tagid=%u"},
6450         {Opt_err, NULL}
6451  };
6452  
6453 @@ -436,6 +440,13 @@ static int ocfs2_remount(struct super_bl
6454                 goto out;
6455         }
6456  
6457 +       if ((parsed_options.mount_opt & OCFS2_MOUNT_TAGGED) &&
6458 +               !(sb->s_flags & MS_TAGGED)) {
6459 +               ret = -EINVAL;
6460 +               mlog(ML_ERROR, "Cannot change tagging on remount\n");
6461 +               goto out;
6462 +       }
6463 +
6464         if ((osb->s_mount_opt & OCFS2_MOUNT_HB_LOCAL) !=
6465             (parsed_options.mount_opt & OCFS2_MOUNT_HB_LOCAL)) {
6466                 ret = -EINVAL;
6467 @@ -950,6 +961,9 @@ static int ocfs2_fill_super(struct super
6468  
6469         ocfs2_complete_mount_recovery(osb);
6470  
6471 +       if (osb->s_mount_opt & OCFS2_MOUNT_TAGGED)
6472 +               sb->s_flags |= MS_TAGGED;
6473 +
6474         if (ocfs2_mount_local(osb))
6475                 snprintf(nodestr, sizeof(nodestr), "local");
6476         else
6477 @@ -1208,6 +1222,20 @@ static int ocfs2_parse_options(struct su
6478                         printk(KERN_INFO "ocfs2 (no)acl options not supported\n");
6479                         break;
6480  #endif
6481 +#ifndef CONFIG_TAGGING_NONE
6482 +               case Opt_tag:
6483 +                       mopt->mount_opt |= OCFS2_MOUNT_TAGGED;
6484 +                       break;
6485 +               case Opt_notag:
6486 +                       mopt->mount_opt &= ~OCFS2_MOUNT_TAGGED;
6487 +                       break;
6488 +#endif
6489 +#ifdef CONFIG_PROPAGATE
6490 +               case Opt_tagid:
6491 +                       /* use args[0] */
6492 +                       mopt->mount_opt |= OCFS2_MOUNT_TAGGED;
6493 +                       break;
6494 +#endif
6495                 default:
6496                         mlog(ML_ERROR,
6497                              "Unrecognized mount option \"%s\" "
6498 diff -NurpP --minimal linux-2.6.29/fs/open.c linux-2.6.29-vs2.3.0.36.9-pre3/fs/open.c
6499 --- linux-2.6.29/fs/open.c      2009-03-24 14:22:27.000000000 +0100
6500 +++ linux-2.6.29-vs2.3.0.36.9-pre3/fs/open.c    2009-03-24 14:48:35.000000000 +0100
6501 @@ -29,22 +29,31 @@
6502  #include <linux/rcupdate.h>
6503  #include <linux/audit.h>
6504  #include <linux/falloc.h>
6505 +#include <linux/vs_base.h>
6506 +#include <linux/vs_limit.h>
6507 +#include <linux/vs_dlimit.h>
6508 +#include <linux/vs_tag.h>
6509 +#include <linux/vs_cowbl.h>
6510  
6511  int vfs_statfs(struct dentry *dentry, struct kstatfs *buf)
6512  {
6513         int retval = -ENODEV;
6514  
6515         if (dentry) {
6516 +               struct super_block *sb = dentry->d_sb;
6517 +
6518                 retval = -ENOSYS;
6519 -               if (dentry->d_sb->s_op->statfs) {
6520 +               if (sb->s_op->statfs) {
6521                         memset(buf, 0, sizeof(*buf));
6522                         retval = security_sb_statfs(dentry);
6523                         if (retval)
6524                                 return retval;
6525 -                       retval = dentry->d_sb->s_op->statfs(dentry, buf);
6526 +                       retval = sb->s_op->statfs(dentry, buf);
6527                         if (retval == 0 && buf->f_frsize == 0)
6528                                 buf->f_frsize = buf->f_bsize;
6529                 }
6530 +               if (!vx_check(0, VS_ADMIN|VS_WATCH))
6531 +                       vx_vsi_statfs(sb, buf);
6532         }
6533         return retval;
6534  }
6535 @@ -638,6 +647,10 @@ SYSCALL_DEFINE3(fchmodat, int, dfd, cons
6536         error = user_path_at(dfd, filename, LOOKUP_FOLLOW, &path);
6537         if (error)
6538                 goto out;
6539 +
6540 +       error = cow_check_and_break(&path);
6541 +       if (error)
6542 +               goto dput_and_out;
6543         inode = path.dentry->d_inode;
6544  
6545         error = mnt_want_write(path.mnt);
6546 @@ -671,11 +684,11 @@ static int chown_common(struct dentry * 
6547         newattrs.ia_valid =  ATTR_CTIME;
6548         if (user != (uid_t) -1) {
6549                 newattrs.ia_valid |= ATTR_UID;
6550 -               newattrs.ia_uid = user;
6551 +               newattrs.ia_uid = dx_map_uid(user);
6552         }
6553         if (group != (gid_t) -1) {
6554                 newattrs.ia_valid |= ATTR_GID;
6555 -               newattrs.ia_gid = group;
6556 +               newattrs.ia_gid = dx_map_gid(group);
6557         }
6558         if (!S_ISDIR(inode->i_mode))
6559                 newattrs.ia_valid |=
6560 @@ -698,7 +711,11 @@ SYSCALL_DEFINE3(chown, const char __user
6561         error = mnt_want_write(path.mnt);
6562         if (error)
6563                 goto out_release;
6564 -       error = chown_common(path.dentry, user, group);
6565 +#ifdef CONFIG_VSERVER_COWBL
6566 +       error = cow_check_and_break(&path);
6567 +       if (!error)
6568 +#endif
6569 +               error = chown_common(path.dentry, user, group);
6570         mnt_drop_write(path.mnt);
6571  out_release:
6572         path_put(&path);
6573 @@ -723,7 +740,11 @@ SYSCALL_DEFINE5(fchownat, int, dfd, cons
6574         error = mnt_want_write(path.mnt);
6575         if (error)
6576                 goto out_release;
6577 -       error = chown_common(path.dentry, user, group);
6578 +#ifdef CONFIG_VSERVER_COWBL
6579 +       error = cow_check_and_break(&path);
6580 +       if (!error)
6581 +#endif
6582 +               error = chown_common(path.dentry, user, group);
6583         mnt_drop_write(path.mnt);
6584  out_release:
6585         path_put(&path);
6586 @@ -742,7 +763,11 @@ SYSCALL_DEFINE3(lchown, const char __use
6587         error = mnt_want_write(path.mnt);
6588         if (error)
6589                 goto out_release;
6590 -       error = chown_common(path.dentry, user, group);
6591 +#ifdef CONFIG_VSERVER_COWBL
6592 +       error = cow_check_and_break(&path);
6593 +       if (!error)
6594 +#endif
6595 +               error = chown_common(path.dentry, user, group);
6596         mnt_drop_write(path.mnt);
6597  out_release:
6598         path_put(&path);
6599 @@ -986,6 +1011,7 @@ static void __put_unused_fd(struct files
6600         __FD_CLR(fd, fdt->open_fds);
6601         if (fd < files->next_fd)
6602                 files->next_fd = fd;
6603 +       vx_openfd_dec(fd);
6604  }
6605  
6606  void put_unused_fd(unsigned int fd)
6607 diff -NurpP --minimal linux-2.6.29/fs/proc/array.c linux-2.6.29-vs2.3.0.36.9-pre3/fs/proc/array.c
6608 --- linux-2.6.29/fs/proc/array.c        2009-03-24 14:22:27.000000000 +0100
6609 +++ linux-2.6.29-vs2.3.0.36.9-pre3/fs/proc/array.c      2009-03-25 01:07:51.000000000 +0100
6610 @@ -81,6 +81,8 @@
6611  #include <linux/seq_file.h>
6612  #include <linux/pid_namespace.h>
6613  #include <linux/tracehook.h>
6614 +#include <linux/vs_context.h>
6615 +#include <linux/vs_network.h>
6616  
6617  #include <asm/pgtable.h>
6618  #include <asm/processor.h>
6619 @@ -137,8 +139,9 @@ static const char *task_state_array[] = 
6620         "D (disk sleep)",       /*  2 */
6621         "T (stopped)",          /*  4 */
6622         "T (tracing stop)",     /*  8 */
6623 -       "Z (zombie)",           /* 16 */
6624 -       "X (dead)"              /* 32 */
6625 +       "H (on hold)",          /* 16 */
6626 +       "Z (zombie)",           /* 32 */
6627 +       "X (dead)",             /* 64 */
6628  };
6629  
6630  static inline const char *get_task_state(struct task_struct *tsk)
6631 @@ -165,6 +168,9 @@ static inline void task_state(struct seq
6632         rcu_read_lock();
6633         ppid = pid_alive(p) ?
6634                 task_tgid_nr_ns(rcu_dereference(p->real_parent), ns) : 0;
6635 +       if (unlikely(vx_current_initpid(p->pid)))
6636 +               ppid = 0;
6637 +
6638         tpid = 0;
6639         if (pid_alive(p)) {
6640                 struct task_struct *tracer = tracehook_tracer_task(p);
6641 @@ -280,7 +286,7 @@ static inline void task_sig(struct seq_f
6642  }
6643  
6644  static void render_cap_t(struct seq_file *m, const char *header,
6645 -                       kernel_cap_t *a)
6646 +                       struct vx_info *vxi, kernel_cap_t *a)
6647  {
6648         unsigned __capi;
6649  
6650 @@ -305,10 +311,11 @@ static inline void task_cap(struct seq_f
6651         cap_bset        = cred->cap_bset;
6652         rcu_read_unlock();
6653  
6654 -       render_cap_t(m, "CapInh:\t", &cap_inheritable);
6655 -       render_cap_t(m, "CapPrm:\t", &cap_permitted);
6656 -       render_cap_t(m, "CapEff:\t", &cap_effective);
6657 -       render_cap_t(m, "CapBnd:\t", &cap_bset);
6658 +       /* FIXME: maybe move the p->vx_info masking to __task_cred() ? */
6659 +       render_cap_t(m, "CapInh:\t", p->vx_info, &cap_inheritable);
6660 +       render_cap_t(m, "CapPrm:\t", p->vx_info, &cap_permitted);
6661 +       render_cap_t(m, "CapEff:\t", p->vx_info, &cap_effective);
6662 +       render_cap_t(m, "CapBnd:\t", p->vx_info, &cap_bset);
6663  }
6664  
6665  static inline void task_context_switch_counts(struct seq_file *m,
6666 @@ -320,6 +327,42 @@ static inline void task_context_switch_c
6667                         p->nivcsw);
6668  }
6669  
6670 +int proc_pid_nsproxy(struct seq_file *m, struct pid_namespace *ns,
6671 +                       struct pid *pid, struct task_struct *task)
6672 +{
6673 +       seq_printf(m,   "Proxy:\t%p(%c)\n"
6674 +                       "Count:\t%u\n"
6675 +                       "uts:\t%p(%c)\n"
6676 +                       "ipc:\t%p(%c)\n"
6677 +                       "mnt:\t%p(%c)\n"
6678 +                       "pid:\t%p(%c)\n"
6679 +                       "net:\t%p(%c)\n",
6680 +                       task->nsproxy,
6681 +                       (task->nsproxy == init_task.nsproxy ? 'I' : '-'),
6682 +                       atomic_read(&task->nsproxy->count),
6683 +                       task->nsproxy->uts_ns,
6684 +                       (task->nsproxy->uts_ns == init_task.nsproxy->uts_ns ? 'I' : '-'),
6685 +                       task->nsproxy->ipc_ns,
6686 +                       (task->nsproxy->ipc_ns == init_task.nsproxy->ipc_ns ? 'I' : '-'),
6687 +                       task->nsproxy->mnt_ns,
6688 +                       (task->nsproxy->mnt_ns == init_task.nsproxy->mnt_ns ? 'I' : '-'),
6689 +                       task->nsproxy->pid_ns,
6690 +                       (task->nsproxy->pid_ns == init_task.nsproxy->pid_ns ? 'I' : '-'),
6691 +                       task->nsproxy->net_ns,
6692 +                       (task->nsproxy->net_ns == init_task.nsproxy->net_ns ? 'I' : '-'));
6693 +       return 0;
6694 +}
6695 +
6696 +void task_vs_id(struct seq_file *m, struct task_struct *task)
6697 +{
6698 +       if (task_vx_flags(task, VXF_HIDE_VINFO, 0))
6699 +               return;
6700 +
6701 +       seq_printf(m, "VxID: %d\n", vx_task_xid(task));
6702 +       seq_printf(m, "NxID: %d\n", nx_task_nid(task));
6703 +}
6704 +
6705 +
6706  int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
6707                         struct pid *pid, struct task_struct *task)
6708  {
6709 @@ -335,6 +378,7 @@ int proc_pid_status(struct seq_file *m, 
6710         task_sig(m, task);
6711         task_cap(m, task);
6712         cpuset_task_status_allowed(m, task);
6713 +       task_vs_id(m, task);
6714  #if defined(CONFIG_S390)
6715         task_show_regs(m, task);
6716  #endif
6717 @@ -447,6 +491,17 @@ static int do_task_stat(struct seq_file 
6718         /* convert nsec -> ticks */
6719         start_time = nsec_to_clock_t(start_time);
6720  
6721 +       /* fixup start time for virt uptime */
6722 +       if (vx_flags(VXF_VIRT_UPTIME, 0)) {
6723 +               unsigned long long bias =
6724 +                       current->vx_info->cvirt.bias_clock;
6725 +
6726 +               if (start_time > bias)
6727 +                       start_time -= bias;
6728 +               else
6729 +                       start_time = 0;
6730 +       }
6731 +
6732         seq_printf(m, "%d (%s) %c %d %d %d %d %d %u %lu \
6733  %lu %lu %lu %lu %lu %ld %ld %ld %ld %d 0 %llu %lu %ld %lu %lu %lu %lu %lu \
6734  %lu %lu %lu %lu %lu %lu %lu %lu %d %d %u %u %llu %lu %ld\n",
6735 diff -NurpP --minimal linux-2.6.29/fs/proc/base.c linux-2.6.29-vs2.3.0.36.9-pre3/fs/proc/base.c
6736 --- linux-2.6.29/fs/proc/base.c 2009-03-24 14:22:27.000000000 +0100
6737 +++ linux-2.6.29-vs2.3.0.36.9-pre3/fs/proc/base.c       2009-03-24 16:29:35.000000000 +0100
6738 @@ -80,6 +80,8 @@
6739  #include <linux/oom.h>
6740  #include <linux/elf.h>
6741  #include <linux/pid_namespace.h>
6742 +#include <linux/vs_context.h>
6743 +#include <linux/vs_network.h>
6744  #include "internal.h"
6745  
6746  /* NOTE:
6747 @@ -1458,6 +1460,8 @@ static struct inode *proc_pid_make_inode
6748                 inode->i_gid = cred->egid;
6749                 rcu_read_unlock();
6750         }
6751 +       /* procfs is xid tagged */
6752 +       inode->i_tag = (tag_t)vx_task_xid(task);
6753         security_task_to_inode(task, inode);
6754  
6755  out:
6756 @@ -2008,6 +2012,13 @@ static struct dentry *proc_pident_lookup
6757         if (!task)
6758                 goto out_no_task;
6759  
6760 +       /* TODO: maybe we can come up with a generic approach? */
6761 +       if (task_vx_flags(task, VXF_HIDE_VINFO, 0) &&
6762 +               (dentry->d_name.len == 5) &&
6763 +               (!memcmp(dentry->d_name.name, "vinfo", 5) ||
6764 +               !memcmp(dentry->d_name.name, "ninfo", 5)))
6765 +               goto out;
6766 +
6767         /*
6768          * Yes, it does not scale. And it should not. Don't add
6769          * new entries into /proc/<tgid>/ without very good reasons.
6770 @@ -2393,7 +2404,7 @@ out_iput:
6771  static struct dentry *proc_base_lookup(struct inode *dir, struct dentry *dentry)
6772  {
6773         struct dentry *error;
6774 -       struct task_struct *task = get_proc_task(dir);
6775 +       struct task_struct *task = get_proc_task_real(dir);
6776         const struct pid_entry *p, *last;
6777  
6778         error = ERR_PTR(-ENOENT);
6779 @@ -2483,6 +2494,9 @@ static int proc_pid_personality(struct s
6780  static const struct file_operations proc_task_operations;
6781  static const struct inode_operations proc_task_inode_operations;
6782  
6783 +extern int proc_pid_vx_info(struct task_struct *, char *);
6784 +extern int proc_pid_nx_info(struct task_struct *, char *);
6785 +
6786  static const struct pid_entry tgid_base_stuff[] = {
6787         DIR("task",       S_IRUGO|S_IXUGO, proc_task_inode_operations, proc_task_operations),
6788         DIR("fd",         S_IRUSR|S_IXUSR, proc_fd_inode_operations, proc_fd_operations),
6789 @@ -2541,6 +2555,8 @@ static const struct pid_entry tgid_base_
6790  #ifdef CONFIG_CGROUPS
6791         REG("cgroup",  S_IRUGO, proc_cgroup_operations),
6792  #endif
6793 +       INF("vinfo",      S_IRUGO, proc_pid_vx_info),
6794 +       INF("ninfo",      S_IRUGO, proc_pid_nx_info),
6795         INF("oom_score",  S_IRUGO, proc_oom_score),
6796         REG("oom_adj",    S_IRUGO|S_IWUSR, proc_oom_adjust_operations),
6797  #ifdef CONFIG_AUDITSYSCALL
6798 @@ -2556,6 +2572,7 @@ static const struct pid_entry tgid_base_
6799  #ifdef CONFIG_TASK_IO_ACCOUNTING
6800         INF("io",       S_IRUGO, proc_tgid_io_accounting),
6801  #endif
6802 +       ONE("nsproxy",  S_IRUGO, proc_pid_nsproxy),
6803  };
6804  
6805  static int proc_tgid_base_readdir(struct file * filp,
6806 @@ -2752,7 +2769,7 @@ retry:
6807         iter.task = NULL;
6808         pid = find_ge_pid(iter.tgid, ns);
6809         if (pid) {
6810 -               iter.tgid = pid_nr_ns(pid, ns);
6811 +               iter.tgid = pid_unmapped_nr_ns(pid, ns);
6812                 iter.task = pid_task(pid, PIDTYPE_PID);
6813                 /* What we to know is if the pid we have find is the
6814                  * pid of a thread_group_leader.  Testing for task
6815 @@ -2782,7 +2799,7 @@ static int proc_pid_fill_cache(struct fi
6816         struct tgid_iter iter)
6817  {
6818         char name[PROC_NUMBUF];
6819 -       int len = snprintf(name, sizeof(name), "%d", iter.tgid);
6820 +       int len = snprintf(name, sizeof(name), "%d", vx_map_tgid(iter.tgid));
6821         return proc_fill_cache(filp, dirent, filldir, name, len,
6822                                 proc_pid_instantiate, iter.task, NULL);
6823  }
6824 @@ -2791,7 +2808,7 @@ static int proc_pid_fill_cache(struct fi
6825  int proc_pid_readdir(struct file * filp, void * dirent, filldir_t filldir)
6826  {
6827         unsigned int nr = filp->f_pos - FIRST_PROCESS_ENTRY;
6828 -       struct task_struct *reaper = get_proc_task(filp->f_path.dentry->d_inode);
6829 +       struct task_struct *reaper = get_proc_task_real(filp->f_path.dentry->d_inode);
6830         struct tgid_iter iter;
6831         struct pid_namespace *ns;
6832  
6833 @@ -2811,6 +2828,8 @@ int proc_pid_readdir(struct file * filp,
6834              iter.task;
6835              iter.tgid += 1, iter = next_tgid(ns, iter)) {
6836                 filp->f_pos = iter.tgid + TGID_OFFSET;
6837 +               if (!vx_proc_task_visible(iter.task))
6838 +                       continue;
6839                 if (proc_pid_fill_cache(filp, dirent, filldir, iter) < 0) {
6840                         put_task_struct(iter.task);
6841                         goto out;
6842 @@ -2957,6 +2976,8 @@ static struct dentry *proc_task_lookup(s
6843         tid = name_to_int(dentry);
6844         if (tid == ~0U)
6845                 goto out;
6846 +       if (vx_current_initpid(tid))
6847 +               goto out;
6848  
6849         ns = dentry->d_sb->s_fs_info;
6850         rcu_read_lock();
6851 diff -NurpP --minimal linux-2.6.29/fs/proc/generic.c linux-2.6.29-vs2.3.0.36.9-pre3/fs/proc/generic.c
6852 --- linux-2.6.29/fs/proc/generic.c      2009-03-24 14:22:27.000000000 +0100
6853 +++ linux-2.6.29-vs2.3.0.36.9-pre3/fs/proc/generic.c    2009-03-24 14:48:35.000000000 +0100
6854 @@ -20,6 +20,7 @@
6855  #include <linux/bitops.h>
6856  #include <linux/spinlock.h>
6857  #include <linux/completion.h>
6858 +#include <linux/vserver/inode.h>
6859  #include <asm/uaccess.h>
6860  
6861  #include "internal.h"
6862 @@ -382,6 +383,8 @@ struct dentry *proc_lookup_de(struct pro
6863         for (de = de->subdir; de ; de = de->next) {
6864                 if (de->namelen != dentry->d_name.len)
6865                         continue;
6866 +                       if (!vx_hide_check(0, de->vx_flags))
6867 +                               continue;
6868                 if (!memcmp(dentry->d_name.name, de->name, de->namelen)) {
6869                         unsigned int ino;
6870  
6871 @@ -390,6 +393,8 @@ struct dentry *proc_lookup_de(struct pro
6872                         spin_unlock(&proc_subdir_lock);
6873                         error = -EINVAL;
6874                         inode = proc_get_inode(dir->i_sb, ino, de);
6875 +                               /* generic proc entries belong to the host */
6876 +                               inode->i_tag = 0;
6877                         goto out_unlock;
6878                 }
6879         }
6880 @@ -467,6 +472,8 @@ int proc_readdir_de(struct proc_dir_entr
6881  
6882                                 /* filldir passes info to user space */
6883                                 de_get(de);
6884 +                               if (!vx_hide_check(0, de->vx_flags))
6885 +                                       goto skip;
6886                                 spin_unlock(&proc_subdir_lock);
6887                                 if (filldir(dirent, de->name, de->namelen, filp->f_pos,
6888                                             de->low_ino, de->mode >> 12) < 0) {
6889 @@ -474,6 +481,7 @@ int proc_readdir_de(struct proc_dir_entr
6890                                         goto out;
6891                                 }
6892                                 spin_lock(&proc_subdir_lock);
6893 +                       skip:
6894                                 filp->f_pos++;
6895                                 next = de->next;
6896                                 de_put(de);
6897 @@ -588,6 +596,7 @@ static struct proc_dir_entry *__proc_cre
6898         ent->nlink = nlink;
6899         atomic_set(&ent->count, 1);
6900         ent->pde_users = 0;
6901 +       ent->vx_flags = IATTR_PROC_DEFAULT;
6902         spin_lock_init(&ent->pde_unload_lock);
6903         ent->pde_unload_completion = NULL;
6904         INIT_LIST_HEAD(&ent->pde_openers);
6905 @@ -611,7 +620,8 @@ struct proc_dir_entry *proc_symlink(cons
6906                                 kfree(ent->data);
6907                                 kfree(ent);
6908                                 ent = NULL;
6909 -                       }
6910 +                       } else
6911 +                               ent->vx_flags = IATTR_PROC_SYMLINK;
6912                 } else {
6913                         kfree(ent);
6914                         ent = NULL;
6915 diff -NurpP --minimal linux-2.6.29/fs/proc/inode.c linux-2.6.29-vs2.3.0.36.9-pre3/fs/proc/inode.c
6916 --- linux-2.6.29/fs/proc/inode.c        2009-03-24 14:22:27.000000000 +0100
6917 +++ linux-2.6.29-vs2.3.0.36.9-pre3/fs/proc/inode.c      2009-03-24 14:48:35.000000000 +0100
6918 @@ -465,6 +465,8 @@ struct inode *proc_get_inode(struct supe
6919                         inode->i_uid = de->uid;
6920                         inode->i_gid = de->gid;
6921                 }
6922 +               if (de->vx_flags)
6923 +                       PROC_I(inode)->vx_flags = de->vx_flags;
6924                 if (de->size)
6925                         inode->i_size = de->size;
6926                 if (de->nlink)
6927 diff -NurpP --minimal linux-2.6.29/fs/proc/internal.h linux-2.6.29-vs2.3.0.36.9-pre3/fs/proc/internal.h
6928 --- linux-2.6.29/fs/proc/internal.h     2009-03-24 14:22:27.000000000 +0100
6929 +++ linux-2.6.29-vs2.3.0.36.9-pre3/fs/proc/internal.h   2009-03-24 14:48:35.000000000 +0100
6930 @@ -10,6 +10,7 @@
6931   */
6932  
6933  #include <linux/proc_fs.h>
6934 +#include <linux/vs_pid.h>
6935  
6936  extern struct proc_dir_entry proc_root;
6937  #ifdef CONFIG_PROC_SYSCTL
6938 @@ -51,6 +52,9 @@ extern int proc_pid_status(struct seq_fi
6939                                 struct pid *pid, struct task_struct *task);
6940  extern int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns,
6941                                 struct pid *pid, struct task_struct *task);
6942 +extern int proc_pid_nsproxy(struct seq_file *m, struct pid_namespace *ns,
6943 +                               struct pid *pid, struct task_struct *task);
6944 +
6945  extern loff_t mem_lseek(struct file *file, loff_t offset, int orig);
6946  
6947  extern const struct file_operations proc_maps_operations;
6948 @@ -70,11 +74,16 @@ static inline struct pid *proc_pid(struc
6949         return PROC_I(inode)->pid;
6950  }
6951  
6952 -static inline struct task_struct *get_proc_task(struct inode *inode)
6953 +static inline struct task_struct *get_proc_task_real(struct inode *inode)
6954  {
6955         return get_pid_task(proc_pid(inode), PIDTYPE_PID);
6956  }
6957  
6958 +static inline struct task_struct *get_proc_task(struct inode *inode)
6959 +{
6960 +       return vx_get_proc_task(inode, proc_pid(inode));
6961 +}
6962 +
6963  static inline int proc_fd(struct inode *inode)
6964  {
6965         return PROC_I(inode)->fd;
6966 diff -NurpP --minimal linux-2.6.29/fs/proc/meminfo.c linux-2.6.29-vs2.3.0.36.9-pre3/fs/proc/meminfo.c
6967 --- linux-2.6.29/fs/proc/meminfo.c      2009-03-24 14:22:27.000000000 +0100
6968 +++ linux-2.6.29-vs2.3.0.36.9-pre3/fs/proc/meminfo.c    2009-03-24 14:48:35.000000000 +0100
6969 @@ -41,7 +41,7 @@ static int meminfo_proc_show(struct seq_
6970  
6971         cached = global_page_state(NR_FILE_PAGES) -
6972                         total_swapcache_pages - i.bufferram;
6973 -       if (cached < 0)
6974 +       if (cached < 0 || vx_flags(VXF_VIRT_MEM, 0))
6975                 cached = 0;
6976  
6977         get_vmalloc_info(&vmi);
6978 diff -NurpP --minimal linux-2.6.29/fs/proc/root.c linux-2.6.29-vs2.3.0.36.9-pre3/fs/proc/root.c
6979 --- linux-2.6.29/fs/proc/root.c 2009-03-24 14:22:27.000000000 +0100
6980 +++ linux-2.6.29-vs2.3.0.36.9-pre3/fs/proc/root.c       2009-03-24 14:48:35.000000000 +0100
6981 @@ -18,9 +18,14 @@
6982  #include <linux/bitops.h>
6983  #include <linux/mount.h>
6984  #include <linux/pid_namespace.h>
6985 +#include <linux/vserver/inode.h>
6986  
6987  #include "internal.h"
6988  
6989 +struct proc_dir_entry *proc_virtual;
6990 +
6991 +extern void proc_vx_init(void);
6992 +
6993  static int proc_test_super(struct super_block *sb, void *data)
6994  {
6995         return sb->s_fs_info == data;
6996 @@ -136,6 +141,7 @@ void __init proc_root_init(void)
6997  #endif
6998         proc_mkdir("bus", NULL);
6999         proc_sys_init();
7000 +       proc_vx_init();
7001  }
7002  
7003  static int proc_root_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat
7004 @@ -203,6 +209,7 @@ struct proc_dir_entry proc_root = {
7005         .proc_iops      = &proc_root_inode_operations, 
7006         .proc_fops      = &proc_root_operations,
7007         .parent         = &proc_root,
7008 +       .vx_flags       = IATTR_ADMIN | IATTR_WATCH,
7009  };
7010  
7011  int pid_ns_prepare_proc(struct pid_namespace *ns)
7012 diff -NurpP --minimal linux-2.6.29/fs/proc/uptime.c linux-2.6.29-vs2.3.0.36.9-pre3/fs/proc/uptime.c
7013 --- linux-2.6.29/fs/proc/uptime.c       2008-12-25 00:26:37.000000000 +0100
7014 +++ linux-2.6.29-vs2.3.0.36.9-pre3/fs/proc/uptime.c     2009-02-22 22:54:25.000000000 +0100
7015 @@ -2,6 +2,7 @@
7016  #include <linux/proc_fs.h>
7017  #include <linux/sched.h>
7018  #include <linux/time.h>
7019 +#include <linux/vserver/cvirt.h>
7020  #include <asm/cputime.h>
7021  
7022  static int proc_calc_metrics(char *page, char **start, off_t off,
7023 @@ -29,6 +30,10 @@ static int uptime_read_proc(char *page, 
7024         do_posix_clock_monotonic_gettime(&uptime);
7025         monotonic_to_bootbased(&uptime);
7026         cputime_to_timespec(idletime, &idle);
7027 +
7028 +       if (vx_flags(VXF_VIRT_UPTIME, 0))
7029 +               vx_vsi_uptime(&uptime, &idle);
7030 +
7031         len = sprintf(page, "%lu.%02lu %lu.%02lu\n",
7032                         (unsigned long) uptime.tv_sec,
7033                         (uptime.tv_nsec / (NSEC_PER_SEC / 100)),
7034 diff -NurpP --minimal linux-2.6.29/fs/quota.c linux-2.6.29-vs2.3.0.36.9-pre3/fs/quota.c
7035 --- linux-2.6.29/fs/quota.c     2009-03-24 14:22:27.000000000 +0100
7036 +++ linux-2.6.29-vs2.3.0.36.9-pre3/fs/quota.c   2009-03-24 14:48:35.000000000 +0100
7037 @@ -18,6 +18,7 @@
7038  #include <linux/capability.h>
7039  #include <linux/quotaops.h>
7040  #include <linux/types.h>
7041 +#include <linux/vs_context.h>
7042  
7043  /* Check validity of generic quotactl commands */
7044  static int generic_quotactl_valid(struct super_block *sb, int type, int cmd, qid_t id)
7045 @@ -81,11 +82,11 @@ static int generic_quotactl_valid(struct
7046         if (cmd == Q_GETQUOTA) {
7047                 if (((type == USRQUOTA && current_euid() != id) ||
7048                      (type == GRPQUOTA && !in_egroup_p(id))) &&
7049 -                   !capable(CAP_SYS_ADMIN))
7050 +                   !vx_capable(CAP_SYS_ADMIN, VXC_QUOTA_CTL))
7051                         return -EPERM;
7052         }
7053         else if (cmd != Q_GETFMT && cmd != Q_SYNC && cmd != Q_GETINFO)
7054 -               if (!capable(CAP_SYS_ADMIN))
7055 +               if (!vx_capable(CAP_SYS_ADMIN, VXC_QUOTA_CTL))
7056                         return -EPERM;
7057  
7058         return 0;
7059 @@ -132,10 +133,10 @@ static int xqm_quotactl_valid(struct sup
7060         if (cmd == Q_XGETQUOTA) {
7061                 if (((type == XQM_USRQUOTA && current_euid() != id) ||
7062                      (type == XQM_GRPQUOTA && !in_egroup_p(id))) &&
7063 -                    !capable(CAP_SYS_ADMIN))
7064 +                    !vx_capable(CAP_SYS_ADMIN, VXC_QUOTA_CTL))
7065                         return -EPERM;
7066         } else if (cmd != Q_XGETQSTAT && cmd != Q_XQUOTASYNC) {
7067 -               if (!capable(CAP_SYS_ADMIN))
7068 +               if (!vx_capable(CAP_SYS_ADMIN, VXC_QUOTA_CTL))
7069                         return -EPERM;
7070         }
7071  
7072 @@ -337,6 +338,46 @@ static int do_quotactl(struct super_bloc
7073         return 0;
7074  }
7075  
7076 +#if defined(CONFIG_BLK_DEV_VROOT) || defined(CONFIG_BLK_DEV_VROOT_MODULE)
7077 +
7078 +#include <linux/vroot.h>
7079 +#include <linux/major.h>
7080 +#include <linux/module.h>
7081 +#include <linux/kallsyms.h>
7082 +#include <linux/vserver/debug.h>
7083 +
7084 +static vroot_grb_func *vroot_get_real_bdev = NULL;
7085 +
7086 +static spinlock_t vroot_grb_lock = SPIN_LOCK_UNLOCKED;
7087 +
7088 +int register_vroot_grb(vroot_grb_func *func) {
7089 +       int ret = -EBUSY;
7090 +
7091 +       spin_lock(&vroot_grb_lock);
7092 +       if (!vroot_get_real_bdev) {
7093 +               vroot_get_real_bdev = func;
7094 +               ret = 0;
7095 +       }
7096 +       spin_unlock(&vroot_grb_lock);
7097 +       return ret;
7098 +}
7099 +EXPORT_SYMBOL(register_vroot_grb);
7100 +
7101 +int unregister_vroot_grb(vroot_grb_func *func) {
7102 +       int ret = -EINVAL;
7103 +
7104 +       spin_lock(&vroot_grb_lock);
7105 +       if (vroot_get_real_bdev) {
7106 +               vroot_get_real_bdev = NULL;
7107 +               ret = 0;
7108 +       }
7109 +       spin_unlock(&vroot_grb_lock);
7110 +       return ret;
7111 +}
7112 +EXPORT_SYMBOL(unregister_vroot_grb);
7113 +
7114 +#endif
7115 +
7116  /*
7117   * look up a superblock on which quota ops will be performed
7118   * - use the name of a block device to find the superblock thereon
7119 @@ -354,6 +395,22 @@ static inline struct super_block *quotac
7120         putname(tmp);
7121         if (IS_ERR(bdev))
7122                 return ERR_CAST(bdev);
7123 +#if defined(CONFIG_BLK_DEV_VROOT) || defined(CONFIG_BLK_DEV_VROOT_MODULE)
7124 +       if (bdev && bdev->bd_inode &&
7125 +                       imajor(bdev->bd_inode) == VROOT_MAJOR) {
7126 +               struct block_device *bdnew = (void *)-EINVAL;
7127 +
7128 +               if (vroot_get_real_bdev)
7129 +                       bdnew = vroot_get_real_bdev(bdev);
7130 +               else
7131 +                       vxdprintk(VXD_CBIT(misc, 0),
7132 +                                       "vroot_get_real_bdev not set");
7133 +               bdput(bdev);
7134 +               if (IS_ERR(bdnew))
7135 +                       return ERR_PTR(PTR_ERR(bdnew));
7136 +               bdev = bdnew;
7137 +       }
7138 +#endif
7139         sb = get_super(bdev);
7140         bdput(bdev);
7141         if (!sb)
7142 diff -NurpP --minimal linux-2.6.29/fs/reiserfs/bitmap.c linux-2.6.29-vs2.3.0.36.9-pre3/fs/reiserfs/bitmap.c
7143 --- linux-2.6.29/fs/reiserfs/bitmap.c   2008-12-25 00:26:37.000000000 +0100
7144 +++ linux-2.6.29-vs2.3.0.36.9-pre3/fs/reiserfs/bitmap.c 2009-02-22 22:54:25.000000000 +0100
7145 @@ -13,6 +13,7 @@
7146  #include <linux/reiserfs_fs_sb.h>
7147  #include <linux/reiserfs_fs_i.h>
7148  #include <linux/quotaops.h>
7149 +#include <linux/vs_dlimit.h>
7150  
7151  #define PREALLOCATION_SIZE 9
7152  
7153 @@ -429,8 +430,10 @@ static void _reiserfs_free_block(struct 
7154         set_sb_free_blocks(rs, sb_free_blocks(rs) + 1);
7155  
7156         journal_mark_dirty(th, s, sbh);
7157 -       if (for_unformatted)
7158 +       if (for_unformatted) {
7159 +               DLIMIT_FREE_BLOCK(inode, 1);
7160                 DQUOT_FREE_BLOCK_NODIRTY(inode, 1);
7161 +       }
7162  }
7163  
7164  void reiserfs_free_block(struct reiserfs_transaction_handle *th,
7165 @@ -1045,6 +1048,7 @@ static inline int blocknrs_and_prealloc_
7166         b_blocknr_t finish = SB_BLOCK_COUNT(s) - 1;
7167         int passno = 0;
7168         int nr_allocated = 0;
7169 +       int blocks;
7170  
7171         determine_prealloc_size(hint);
7172         if (!hint->formatted_node) {
7173 @@ -1054,19 +1058,30 @@ static inline int blocknrs_and_prealloc_
7174                                "reiserquota: allocating %d blocks id=%u",
7175                                amount_needed, hint->inode->i_uid);
7176  #endif
7177 -               quota_ret =
7178 -                   DQUOT_ALLOC_BLOCK_NODIRTY(hint->inode, amount_needed);
7179 -               if (quota_ret)  /* Quota exceeded? */
7180 +               quota_ret = DQUOT_ALLOC_BLOCK_NODIRTY(hint->inode,
7181 +                       amount_needed);
7182 +               if (quota_ret)
7183                         return QUOTA_EXCEEDED;
7184 +               if (DLIMIT_ALLOC_BLOCK(hint->inode, amount_needed)) {
7185 +                       DQUOT_FREE_BLOCK_NODIRTY(hint->inode,
7186 +                               amount_needed);
7187 +                       return NO_DISK_SPACE;
7188 +               }
7189 +
7190                 if (hint->preallocate && hint->prealloc_size) {
7191  #ifdef REISERQUOTA_DEBUG
7192                         reiserfs_debug(s, REISERFS_DEBUG_CODE,
7193                                        "reiserquota: allocating (prealloc) %d blocks id=%u",
7194                                        hint->prealloc_size, hint->inode->i_uid);
7195  #endif
7196 -                       quota_ret =
7197 -                           DQUOT_PREALLOC_BLOCK_NODIRTY(hint->inode,
7198 -                                                        hint->prealloc_size);
7199 +                       quota_ret = DQUOT_PREALLOC_BLOCK_NODIRTY(hint->inode,
7200 +                               hint->prealloc_size);
7201 +                       if (!quota_ret &&
7202 +                               DLIMIT_ALLOC_BLOCK(hint->inode, hint->prealloc_size)) {
7203 +                               DQUOT_FREE_BLOCK_NODIRTY(hint->inode,
7204 +                                       hint->prealloc_size);
7205 +                               quota_ret = 1;
7206 +                       }
7207                         if (quota_ret)
7208                                 hint->preallocate = hint->prealloc_size = 0;
7209                 }
7210 @@ -1098,7 +1113,10 @@ static inline int blocknrs_and_prealloc_
7211                                                nr_allocated,
7212                                                hint->inode->i_uid);
7213  #endif
7214 -                               DQUOT_FREE_BLOCK_NODIRTY(hint->inode, amount_needed + hint->prealloc_size - nr_allocated);      /* Free not allocated blocks */
7215 +                               /* Free not allocated blocks */
7216 +                               blocks = amount_needed + hint->prealloc_size - nr_allocated;
7217 +                               DLIMIT_FREE_BLOCK(hint->inode, blocks);
7218 +                               DQUOT_FREE_BLOCK_NODIRTY(hint->inode, blocks);
7219                         }
7220                         while (nr_allocated--)
7221                                 reiserfs_free_block(hint->th, hint->inode,
7222 @@ -1129,10 +1147,10 @@ static inline int blocknrs_and_prealloc_
7223                                REISERFS_I(hint->inode)->i_prealloc_count,
7224                                hint->inode->i_uid);
7225  #endif
7226 -               DQUOT_FREE_BLOCK_NODIRTY(hint->inode, amount_needed +
7227 -                                        hint->prealloc_size - nr_allocated -
7228 -                                        REISERFS_I(hint->inode)->
7229 -                                        i_prealloc_count);
7230 +               blocks = amount_needed + hint->prealloc_size - nr_allocated -
7231 +                       REISERFS_I(hint->inode)->i_prealloc_count;
7232 +               DLIMIT_FREE_BLOCK(hint->inode, blocks);
7233 +               DQUOT_FREE_BLOCK_NODIRTY(hint->inode, blocks);
7234         }
7235  
7236         return CARRY_ON;
7237 diff -NurpP --minimal linux-2.6.29/fs/reiserfs/file.c linux-2.6.29-vs2.3.0.36.9-pre3/fs/reiserfs/file.c
7238 --- linux-2.6.29/fs/reiserfs/file.c     2008-12-25 00:26:37.000000000 +0100
7239 +++ linux-2.6.29-vs2.3.0.36.9-pre3/fs/reiserfs/file.c   2009-02-22 22:54:25.000000000 +0100
7240 @@ -307,4 +307,5 @@ const struct inode_operations reiserfs_f
7241         .listxattr = reiserfs_listxattr,
7242         .removexattr = reiserfs_removexattr,
7243         .permission = reiserfs_permission,
7244 +       .sync_flags = reiserfs_sync_flags,
7245  };
7246 diff -NurpP --minimal linux-2.6.29/fs/reiserfs/inode.c linux-2.6.29-vs2.3.0.36.9-pre3/fs/reiserfs/inode.c
7247 --- linux-2.6.29/fs/reiserfs/inode.c    2009-03-24 14:22:27.000000000 +0100
7248 +++ linux-2.6.29-vs2.3.0.36.9-pre3/fs/reiserfs/inode.c  2009-03-24 14:48:35.000000000 +0100
7249 @@ -18,6 +18,8 @@
7250  #include <linux/writeback.h>
7251  #include <linux/quotaops.h>
7252  #include <linux/swap.h>
7253 +#include <linux/vs_dlimit.h>
7254 +#include <linux/vs_tag.h>
7255  
7256  int reiserfs_commit_write(struct file *f, struct page *page,
7257                           unsigned from, unsigned to);
7258 @@ -54,6 +56,7 @@ void reiserfs_delete_inode(struct inode 
7259                  * stat data deletion */
7260                 if (!err) 
7261                         DQUOT_FREE_INODE(inode);
7262 +               DLIMIT_FREE_INODE(inode);
7263  
7264                 if (journal_end(&th, inode->i_sb, jbegin_count))
7265                         goto out;
7266 @@ -1116,6 +1119,8 @@ static void init_inode(struct inode *ino
7267         struct buffer_head *bh;
7268         struct item_head *ih;
7269         __u32 rdev;
7270 +       uid_t uid;
7271 +       gid_t gid;
7272         //int version = ITEM_VERSION_1;
7273  
7274         bh = PATH_PLAST_BUFFER(path);
7275 @@ -1139,12 +1144,13 @@ static void init_inode(struct inode *ino
7276                     (struct stat_data_v1 *)B_I_PITEM(bh, ih);
7277                 unsigned long blocks;
7278  
7279 +               uid = sd_v1_uid(sd);
7280 +               gid = sd_v1_gid(sd);
7281 +
7282                 set_inode_item_key_version(inode, KEY_FORMAT_3_5);
7283                 set_inode_sd_version(inode, STAT_DATA_V1);
7284                 inode->i_mode = sd_v1_mode(sd);
7285                 inode->i_nlink = sd_v1_nlink(sd);
7286 -               inode->i_uid = sd_v1_uid(sd);
7287 -               inode->i_gid = sd_v1_gid(sd);
7288                 inode->i_size = sd_v1_size(sd);
7289                 inode->i_atime.tv_sec = sd_v1_atime(sd);
7290                 inode->i_mtime.tv_sec = sd_v1_mtime(sd);
7291 @@ -1186,11 +1192,12 @@ static void init_inode(struct inode *ino
7292                 // (directories and symlinks)
7293                 struct stat_data *sd = (struct stat_data *)B_I_PITEM(bh, ih);
7294  
7295 +               uid    = sd_v2_uid(sd);
7296 +               gid    = sd_v2_gid(sd);
7297 +
7298                 inode->i_mode = sd_v2_mode(sd);
7299                 inode->i_nlink = sd_v2_nlink(sd);
7300 -               inode->i_uid = sd_v2_uid(sd);
7301                 inode->i_size = sd_v2_size(sd);
7302 -               inode->i_gid = sd_v2_gid(sd);
7303                 inode->i_mtime.tv_sec = sd_v2_mtime(sd);
7304                 inode->i_atime.tv_sec = sd_v2_atime(sd);
7305                 inode->i_ctime.tv_sec = sd_v2_ctime(sd);
7306 @@ -1220,6 +1227,10 @@ static void init_inode(struct inode *ino
7307                 sd_attrs_to_i_attrs(sd_v2_attrs(sd), inode);
7308         }
7309  
7310 +       inode->i_uid = INOTAG_UID(DX_TAG(inode), uid, gid);
7311 +       inode->i_gid = INOTAG_GID(DX_TAG(inode), uid, gid);
7312 +       inode->i_tag = INOTAG_TAG(DX_TAG(inode), uid, gid, 0);
7313 +
7314         pathrelse(path);
7315         if (S_ISREG(inode->i_mode)) {
7316                 inode->i_op = &reiserfs_file_inode_operations;
7317 @@ -1242,13 +1253,15 @@ static void init_inode(struct inode *ino
7318  static void inode2sd(void *sd, struct inode *inode, loff_t size)
7319  {
7320         struct stat_data *sd_v2 = (struct stat_data *)sd;
7321 +       uid_t uid = TAGINO_UID(DX_TAG(inode), inode->i_uid, inode->i_tag);
7322 +       gid_t gid = TAGINO_GID(DX_TAG(inode), inode->i_gid, inode->i_tag);
7323         __u16 flags;
7324  
7325 +       set_sd_v2_uid(sd_v2, uid);
7326 +       set_sd_v2_gid(sd_v2, gid);
7327         set_sd_v2_mode(sd_v2, inode->i_mode);
7328         set_sd_v2_nlink(sd_v2, inode->i_nlink);
7329 -       set_sd_v2_uid(sd_v2, inode->i_uid);
7330         set_sd_v2_size(sd_v2, size);
7331 -       set_sd_v2_gid(sd_v2, inode->i_gid);
7332         set_sd_v2_mtime(sd_v2, inode->i_mtime.tv_sec);
7333         set_sd_v2_atime(sd_v2, inode->i_atime.tv_sec);
7334         set_sd_v2_ctime(sd_v2, inode->i_ctime.tv_sec);
7335 @@ -1763,6 +1776,10 @@ int reiserfs_new_inode(struct reiserfs_t
7336  
7337         BUG_ON(!th->t_trans_id);
7338  
7339 +       if (DLIMIT_ALLOC_INODE(inode)) {
7340 +               err = -ENOSPC;
7341 +               goto out_bad_dlimit;
7342 +       }
7343         if (DQUOT_ALLOC_INODE(inode)) {
7344                 err = -EDQUOT;
7345                 goto out_end_trans;
7346 @@ -1950,6 +1967,9 @@ int reiserfs_new_inode(struct reiserfs_t
7347         DQUOT_FREE_INODE(inode);
7348  
7349        out_end_trans:
7350 +       DLIMIT_FREE_INODE(inode);
7351 +
7352 +      out_bad_dlimit:
7353         journal_end(th, th->t_super, th->t_blocks_allocated);
7354         /* Drop can be outside and it needs more credits so it's better to have it outside */
7355         DQUOT_DROP(inode);
7356 @@ -2837,14 +2857,19 @@ int reiserfs_commit_write(struct file *f
7357  void sd_attrs_to_i_attrs(__u16 sd_attrs, struct inode *inode)
7358  {
7359         if (reiserfs_attrs(inode->i_sb)) {
7360 -               if (sd_attrs & REISERFS_SYNC_FL)
7361 -                       inode->i_flags |= S_SYNC;
7362 -               else
7363 -                       inode->i_flags &= ~S_SYNC;
7364                 if (sd_attrs & REISERFS_IMMUTABLE_FL)
7365                         inode->i_flags |= S_IMMUTABLE;
7366                 else
7367                         inode->i_flags &= ~S_IMMUTABLE;
7368 +               if (sd_attrs & REISERFS_IXUNLINK_FL)
7369 +                       inode->i_flags |= S_IXUNLINK;
7370 +               else
7371 +                       inode->i_flags &= ~S_IXUNLINK;
7372 +
7373 +               if (sd_attrs & REISERFS_SYNC_FL)
7374 +                       inode->i_flags |= S_SYNC;
7375 +               else
7376 +                       inode->i_flags &= ~S_SYNC;
7377                 if (sd_attrs & REISERFS_APPEND_FL)
7378                         inode->i_flags |= S_APPEND;
7379                 else
7380 @@ -2857,6 +2882,15 @@ void sd_attrs_to_i_attrs(__u16 sd_attrs,
7381                         REISERFS_I(inode)->i_flags |= i_nopack_mask;
7382                 else
7383                         REISERFS_I(inode)->i_flags &= ~i_nopack_mask;
7384 +
7385 +               if (sd_attrs & REISERFS_BARRIER_FL)
7386 +                       inode->i_vflags |= V_BARRIER;
7387 +               else
7388 +                       inode->i_vflags &= ~V_BARRIER;
7389 +               if (sd_attrs & REISERFS_COW_FL)
7390 +                       inode->i_vflags |= V_COW;
7391 +               else
7392 +                       inode->i_vflags &= ~V_COW;
7393         }
7394  }
7395  
7396 @@ -2867,6 +2901,11 @@ void i_attrs_to_sd_attrs(struct inode *i
7397                         *sd_attrs |= REISERFS_IMMUTABLE_FL;
7398                 else
7399                         *sd_attrs &= ~REISERFS_IMMUTABLE_FL;
7400 +               if (inode->i_flags & S_IXUNLINK)
7401 +                       *sd_attrs |= REISERFS_IXUNLINK_FL;
7402 +               else
7403 +                       *sd_attrs &= ~REISERFS_IXUNLINK_FL;
7404 +
7405                 if (inode->i_flags & S_SYNC)
7406                         *sd_attrs |= REISERFS_SYNC_FL;
7407                 else
7408 @@ -2879,6 +2918,15 @@ void i_attrs_to_sd_attrs(struct inode *i
7409                         *sd_attrs |= REISERFS_NOTAIL_FL;
7410                 else
7411                         *sd_attrs &= ~REISERFS_NOTAIL_FL;
7412 +
7413 +               if (inode->i_vflags & V_BARRIER)
7414 +                       *sd_attrs |= REISERFS_BARRIER_FL;
7415 +               else
7416 +                       *sd_attrs &= ~REISERFS_BARRIER_FL;
7417 +               if (inode->i_vflags & V_COW)
7418 +                       *sd_attrs |= REISERFS_COW_FL;
7419 +               else
7420 +                       *sd_attrs &= ~REISERFS_COW_FL;
7421         }
7422  }
7423  
7424 @@ -3046,6 +3094,22 @@ static ssize_t reiserfs_direct_IO(int rw
7425                                   reiserfs_get_blocks_direct_io, NULL);
7426  }
7427  
7428 +int reiserfs_sync_flags(struct inode *inode)
7429 +{
7430 +       u16 oldflags, newflags;
7431 +
7432 +       oldflags = REISERFS_I(inode)->i_attrs;
7433 +       newflags = oldflags;
7434 +       i_attrs_to_sd_attrs(inode, &newflags);
7435 +
7436 +       if (oldflags ^ newflags) {
7437 +               REISERFS_I(inode)->i_attrs = newflags;
7438 +               inode->i_ctime = CURRENT_TIME_SEC;
7439 +               mark_inode_dirty(inode);
7440 +       }
7441 +       return 0;
7442 +}
7443 +
7444  int reiserfs_setattr(struct dentry *dentry, struct iattr *attr)
7445  {
7446         struct inode *inode = dentry->d_inode;
7447 @@ -3099,9 +3163,11 @@ int reiserfs_setattr(struct dentry *dent
7448         }
7449  
7450         error = inode_change_ok(inode, attr);
7451 +
7452         if (!error) {
7453                 if ((ia_valid & ATTR_UID && attr->ia_uid != inode->i_uid) ||
7454 -                   (ia_valid & ATTR_GID && attr->ia_gid != inode->i_gid)) {
7455 +                   (ia_valid & ATTR_GID && attr->ia_gid != inode->i_gid) ||
7456 +                   (ia_valid & ATTR_TAG && attr->ia_tag != inode->i_tag)) {
7457                         error = reiserfs_chown_xattrs(inode, attr);
7458  
7459                         if (!error) {
7460 @@ -3131,6 +3197,9 @@ int reiserfs_setattr(struct dentry *dent
7461                                         inode->i_uid = attr->ia_uid;
7462                                 if (attr->ia_valid & ATTR_GID)
7463                                         inode->i_gid = attr->ia_gid;
7464 +                               if ((attr->ia_valid & ATTR_TAG) &&
7465 +                                       IS_TAGGED(inode))
7466 +                                       inode->i_tag = attr->ia_tag;
7467                                 mark_inode_dirty(inode);
7468                                 error =
7469                                     journal_end(&th, inode->i_sb, jbegin_count);
7470 diff -NurpP --minimal linux-2.6.29/fs/reiserfs/ioctl.c linux-2.6.29-vs2.3.0.36.9-pre3/fs/reiserfs/ioctl.c
7471 --- linux-2.6.29/fs/reiserfs/ioctl.c    2008-12-25 00:26:37.000000000 +0100
7472 +++ linux-2.6.29-vs2.3.0.36.9-pre3/fs/reiserfs/ioctl.c  2009-02-22 22:54:25.000000000 +0100
7473 @@ -7,6 +7,7 @@
7474  #include <linux/mount.h>
7475  #include <linux/reiserfs_fs.h>
7476  #include <linux/time.h>
7477 +#include <linux/mount.h>
7478  #include <asm/uaccess.h>
7479  #include <linux/pagemap.h>
7480  #include <linux/smp_lock.h>
7481 @@ -23,7 +24,7 @@
7482  int reiserfs_ioctl(struct inode *inode, struct file *filp, unsigned int cmd,
7483                    unsigned long arg)
7484  {
7485 -       unsigned int flags;
7486 +       unsigned int flags, oldflags;
7487         int err = 0;
7488  
7489         switch (cmd) {
7490 @@ -43,6 +44,7 @@ int reiserfs_ioctl(struct inode *inode, 
7491  
7492                 flags = REISERFS_I(inode)->i_attrs;
7493                 i_attrs_to_sd_attrs(inode, (__u16 *) & flags);
7494 +               flags &= REISERFS_FL_USER_VISIBLE;
7495                 return put_user(flags, (int __user *)arg);
7496         case REISERFS_IOC_SETFLAGS:{
7497                         if (!reiserfs_attrs(inode->i_sb))
7498 @@ -60,6 +62,10 @@ int reiserfs_ioctl(struct inode *inode, 
7499                                 err = -EFAULT;
7500                                 goto setflags_out;
7501                         }
7502 +                       if (IS_BARRIER(inode)) {
7503 +                               vxwprintk_task(1, "messing with the barrier.");
7504 +                               return -EACCES;
7505 +                       }
7506                         /*
7507                          * Is it quota file? Do not allow user to mess with it
7508                          */
7509 @@ -84,6 +90,10 @@ int reiserfs_ioctl(struct inode *inode, 
7510                                         goto setflags_out;
7511                                 }
7512                         }
7513 +
7514 +                       oldflags = REISERFS_I(inode)->i_attrs;
7515 +                       flags = flags & REISERFS_FL_USER_MODIFIABLE;
7516 +                       flags |= oldflags & ~REISERFS_FL_USER_MODIFIABLE;
7517                         sd_attrs_to_i_attrs(flags, inode);
7518                         REISERFS_I(inode)->i_attrs = flags;
7519                         inode->i_ctime = CURRENT_TIME_SEC;
7520 diff -NurpP --minimal linux-2.6.29/fs/reiserfs/namei.c linux-2.6.29-vs2.3.0.36.9-pre3/fs/reiserfs/namei.c
7521 --- linux-2.6.29/fs/reiserfs/namei.c    2009-03-24 14:22:27.000000000 +0100
7522 +++ linux-2.6.29-vs2.3.0.36.9-pre3/fs/reiserfs/namei.c  2009-03-24 14:48:35.000000000 +0100
7523 @@ -17,6 +17,7 @@
7524  #include <linux/reiserfs_acl.h>
7525  #include <linux/reiserfs_xattr.h>
7526  #include <linux/quotaops.h>
7527 +#include <linux/vs_tag.h>
7528  
7529  #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; }
7530  #define DEC_DIR_INODE_NLINK(i) if (i->i_nlink != 1) drop_nlink(i);
7531 @@ -360,6 +361,7 @@ static struct dentry *reiserfs_lookup(st
7532                         reiserfs_write_unlock(dir->i_sb);
7533                         return ERR_PTR(-EACCES);
7534                 }
7535 +               dx_propagate_tag(nd, inode);
7536  
7537                 /* Propogate the priv_object flag so we know we're in the priv tree */
7538                 if (is_reiserfs_priv_object(dir))
7539 @@ -586,6 +588,7 @@ static int new_inode_init(struct inode *
7540         } else {
7541                 inode->i_gid = current_fsgid();
7542         }
7543 +       inode->i_tag = dx_current_fstag(inode->i_sb);
7544         DQUOT_INIT(inode);
7545         return 0;
7546  }
7547 @@ -1540,6 +1543,7 @@ const struct inode_operations reiserfs_d
7548         .listxattr = reiserfs_listxattr,
7549         .removexattr = reiserfs_removexattr,
7550         .permission = reiserfs_permission,
7551 +       .sync_flags = reiserfs_sync_flags,
7552  };
7553  
7554  /*
7555 @@ -1556,6 +1560,7 @@ const struct inode_operations reiserfs_s
7556         .listxattr = reiserfs_listxattr,
7557         .removexattr = reiserfs_removexattr,
7558         .permission = reiserfs_permission,
7559 +       .sync_flags = reiserfs_sync_flags,
7560  
7561  };
7562  
7563 @@ -1569,5 +1574,6 @@ const struct inode_operations reiserfs_s
7564         .listxattr = reiserfs_listxattr,
7565         .removexattr = reiserfs_removexattr,
7566         .permission = reiserfs_permission,
7567 +       .sync_flags = reiserfs_sync_flags,
7568  
7569  };
7570 diff -NurpP --minimal linux-2.6.29/fs/reiserfs/stree.c linux-2.6.29-vs2.3.0.36.9-pre3/fs/reiserfs/stree.c
7571 --- linux-2.6.29/fs/reiserfs/stree.c    2008-12-25 00:26:37.000000000 +0100
7572 +++ linux-2.6.29-vs2.3.0.36.9-pre3/fs/reiserfs/stree.c  2009-02-22 22:54:25.000000000 +0100
7573 @@ -55,6 +55,7 @@
7574  #include <linux/reiserfs_fs.h>
7575  #include <linux/buffer_head.h>
7576  #include <linux/quotaops.h>
7577 +#include <linux/vs_dlimit.h>
7578  
7579  /* Does the buffer contain a disk block which is in the tree. */
7580  inline int B_IS_IN_TREE(const struct buffer_head *p_s_bh)
7581 @@ -1297,6 +1298,7 @@ int reiserfs_delete_item(struct reiserfs
7582                        "reiserquota delete_item(): freeing %u, id=%u type=%c",
7583                        quota_cut_bytes, p_s_inode->i_uid, head2type(&s_ih));
7584  #endif
7585 +       DLIMIT_FREE_SPACE(p_s_inode, quota_cut_bytes);
7586         DQUOT_FREE_SPACE_NODIRTY(p_s_inode, quota_cut_bytes);
7587  
7588         /* Return deleted body length */
7589 @@ -1385,6 +1387,7 @@ void reiserfs_delete_solid_item(struct r
7590  #endif
7591                                 DQUOT_FREE_SPACE_NODIRTY(inode,
7592                                                          quota_cut_bytes);
7593 +                               DLIMIT_FREE_SPACE(inode, quota_cut_bytes);
7594                         }
7595                         break;
7596                 }
7597 @@ -1734,6 +1737,7 @@ int reiserfs_cut_from_item(struct reiser
7598                        "reiserquota cut_from_item(): freeing %u id=%u type=%c",
7599                        quota_cut_bytes, p_s_inode->i_uid, '?');
7600  #endif
7601 +       DLIMIT_FREE_SPACE(p_s_inode, quota_cut_bytes);
7602         DQUOT_FREE_SPACE_NODIRTY(p_s_inode, quota_cut_bytes);
7603         return n_ret_value;
7604  }
7605 @@ -1975,6 +1979,11 @@ int reiserfs_paste_into_item(struct reis
7606                 pathrelse(p_s_search_path);
7607                 return -EDQUOT;
7608         }
7609 +       if (DLIMIT_ALLOC_SPACE(inode, n_pasted_size)) {
7610 +               DQUOT_FREE_SPACE_NODIRTY(inode, n_pasted_size);
7611 +               pathrelse(p_s_search_path);
7612 +               return -ENOSPC;
7613 +       }
7614         init_tb_struct(th, &s_paste_balance, th->t_super, p_s_search_path,
7615                        n_pasted_size);
7616  #ifdef DISPLACE_NEW_PACKING_LOCALITIES
7617 @@ -2027,6 +2036,7 @@ int reiserfs_paste_into_item(struct reis
7618                        n_pasted_size, inode->i_uid,
7619                        key2type(&(p_s_key->on_disk_key)));
7620  #endif
7621 +       DLIMIT_FREE_SPACE(inode, n_pasted_size);
7622         DQUOT_FREE_SPACE_NODIRTY(inode, n_pasted_size);
7623         return retval;
7624  }
7625 @@ -2064,6 +2074,11 @@ int reiserfs_insert_item(struct reiserfs
7626                         pathrelse(p_s_path);
7627                         return -EDQUOT;
7628                 }
7629 +               if (DLIMIT_ALLOC_SPACE(inode, quota_bytes)) {
7630 +                       DQUOT_FREE_SPACE_NODIRTY(inode, quota_bytes);
7631 +                       pathrelse(p_s_path);
7632 +                       return -ENOSPC;
7633 +               }
7634         }
7635         init_tb_struct(th, &s_ins_balance, th->t_super, p_s_path,
7636                        IH_SIZE + ih_item_len(p_s_ih));
7637 @@ -2111,7 +2126,9 @@ int reiserfs_insert_item(struct reiserfs
7638                        "reiserquota insert_item(): freeing %u id=%u type=%c",
7639                        quota_bytes, inode->i_uid, head2type(p_s_ih));
7640  #endif
7641 -       if (inode)
7642 +       if (inode) {
7643 +               DLIMIT_FREE_SPACE(inode, quota_bytes);
7644                 DQUOT_FREE_SPACE_NODIRTY(inode, quota_bytes);
7645 +       }
7646         return retval;
7647  }
7648 diff -NurpP --minimal linux-2.6.29/fs/reiserfs/super.c linux-2.6.29-vs2.3.0.36.9-pre3/fs/reiserfs/super.c
7649 --- linux-2.6.29/fs/reiserfs/super.c    2009-03-24 14:22:27.000000000 +0100
7650 +++ linux-2.6.29-vs2.3.0.36.9-pre3/fs/reiserfs/super.c  2009-03-24 14:48:35.000000000 +0100
7651 @@ -902,6 +902,14 @@ static int reiserfs_parse_options(struct
7652                 {"user_xattr",.setmask = 1 << REISERFS_UNSUPPORTED_OPT},
7653                 {"nouser_xattr",.clrmask = 1 << REISERFS_UNSUPPORTED_OPT},
7654  #endif
7655 +#ifndef CONFIG_TAGGING_NONE
7656 +               {"tagxid",.setmask = 1 << REISERFS_TAGGED},
7657 +               {"tag",.setmask = 1 << REISERFS_TAGGED},
7658 +               {"notag",.clrmask = 1 << REISERFS_TAGGED},
7659 +#endif
7660 +#ifdef CONFIG_PROPAGATE
7661 +               {"tag",.arg_required = 'T',.values = NULL},
7662 +#endif
7663  #ifdef CONFIG_REISERFS_FS_POSIX_ACL
7664                 {"acl",.setmask = 1 << REISERFS_POSIXACL},
7665                 {"noacl",.clrmask = 1 << REISERFS_POSIXACL},
7666 @@ -1195,6 +1203,12 @@ static int reiserfs_remount(struct super
7667         handle_quota_files(s, qf_names, &qfmt);
7668  #endif
7669  
7670 +       if ((mount_options & (1 << REISERFS_TAGGED)) &&
7671 +               !(s->s_flags & MS_TAGGED)) {
7672 +               reiserfs_warning(s, "reiserfs: tagging not permitted on remount.");
7673 +               return -EINVAL;
7674 +       }
7675 +
7676         handle_attrs(s);
7677  
7678         /* Add options that are safe here */
7679 @@ -1659,6 +1673,10 @@ static int reiserfs_fill_super(struct su
7680                 goto error;
7681         }
7682  
7683 +       /* map mount option tagxid */
7684 +       if (REISERFS_SB(s)->s_mount_opt & (1 << REISERFS_TAGGED))
7685 +               s->s_flags |= MS_TAGGED;
7686 +
7687         rs = SB_DISK_SUPER_BLOCK(s);
7688         /* Let's do basic sanity check to verify that underlying device is not
7689            smaller than the filesystem. If the check fails then abort and scream,
7690 diff -NurpP --minimal linux-2.6.29/fs/reiserfs/xattr.c linux-2.6.29-vs2.3.0.36.9-pre3/fs/reiserfs/xattr.c
7691 --- linux-2.6.29/fs/reiserfs/xattr.c    2008-12-25 00:26:37.000000000 +0100
7692 +++ linux-2.6.29-vs2.3.0.36.9-pre3/fs/reiserfs/xattr.c  2009-02-22 22:54:25.000000000 +0100
7693 @@ -35,6 +35,7 @@
7694  #include <linux/namei.h>
7695  #include <linux/errno.h>
7696  #include <linux/fs.h>
7697 +#include <linux/mount.h>
7698  #include <linux/file.h>
7699  #include <linux/pagemap.h>
7700  #include <linux/xattr.h>
7701 diff -NurpP --minimal linux-2.6.29/fs/stat.c linux-2.6.29-vs2.3.0.36.9-pre3/fs/stat.c
7702 --- linux-2.6.29/fs/stat.c      2009-03-24 14:22:36.000000000 +0100
7703 +++ linux-2.6.29-vs2.3.0.36.9-pre3/fs/stat.c    2009-03-24 14:48:35.000000000 +0100
7704 @@ -26,6 +26,7 @@ void generic_fillattr(struct inode *inod
7705         stat->nlink = inode->i_nlink;
7706         stat->uid = inode->i_uid;
7707         stat->gid = inode->i_gid;
7708 +       stat->tag = inode->i_tag;
7709         stat->rdev = inode->i_rdev;
7710         stat->atime = inode->i_atime;
7711         stat->mtime = inode->i_mtime;
7712 diff -NurpP --minimal linux-2.6.29/fs/super.c linux-2.6.29-vs2.3.0.36.9-pre3/fs/super.c
7713 --- linux-2.6.29/fs/super.c     2009-03-24 14:22:36.000000000 +0100
7714 +++ linux-2.6.29-vs2.3.0.36.9-pre3/fs/super.c   2009-03-24 16:32:06.000000000 +0100
7715 @@ -39,6 +39,9 @@
7716  #include <linux/mutex.h>
7717  #include <linux/file.h>
7718  #include <linux/async.h>
7719 +#include <linux/devpts_fs.h>
7720 +#include <linux/proc_fs.h>
7721 +#include <linux/vs_context.h>
7722  #include <asm/uaccess.h>
7723  #include "internal.h"
7724  
7725 @@ -918,12 +921,18 @@ struct vfsmount *
7726  vfs_kern_mount(struct file_system_type *type, int flags, const char *name, void *data)
7727  {
7728         struct vfsmount *mnt;
7729 +       struct super_block *sb;
7730         char *secdata = NULL;
7731         int error;
7732  
7733         if (!type)
7734                 return ERR_PTR(-ENODEV);
7735  
7736 +       error = -EPERM;
7737 +       if ((type->fs_flags & FS_BINARY_MOUNTDATA) &&
7738 +               !vx_capable(CAP_SYS_ADMIN, VXC_BINARY_MOUNT))
7739 +               goto out;
7740 +
7741         error = -ENOMEM;
7742         mnt = alloc_vfsmnt(name);
7743         if (!mnt)
7744 @@ -942,9 +951,17 @@ vfs_kern_mount(struct file_system_type *
7745         error = type->get_sb(type, flags, name, data, mnt);
7746         if (error < 0)
7747                 goto out_free_secdata;
7748 -       BUG_ON(!mnt->mnt_sb);
7749  
7750 -       error = security_sb_kern_mount(mnt->mnt_sb, flags, secdata);
7751 +       sb = mnt->mnt_sb;
7752 +       BUG_ON(!sb);
7753 +
7754 +       error = -EPERM;
7755 +       if (!vx_capable(CAP_SYS_ADMIN, VXC_BINARY_MOUNT) && !sb->s_bdev &&
7756 +               (sb->s_magic != PROC_SUPER_MAGIC) &&
7757 +               (sb->s_magic != DEVPTS_SUPER_MAGIC))
7758 +               goto out_sb;
7759 +
7760 +       error = security_sb_kern_mount(sb, flags, secdata);
7761         if (error)
7762                 goto out_sb;
7763  
7764 diff -NurpP --minimal linux-2.6.29/fs/sysfs/mount.c linux-2.6.29-vs2.3.0.36.9-pre3/fs/sysfs/mount.c
7765 --- linux-2.6.29/fs/sysfs/mount.c       2008-12-25 00:26:37.000000000 +0100
7766 +++ linux-2.6.29-vs2.3.0.36.9-pre3/fs/sysfs/mount.c     2009-02-22 22:54:25.000000000 +0100
7767 @@ -20,8 +20,6 @@
7768  
7769  #include "sysfs.h"
7770  
7771 -/* Random magic number */
7772 -#define SYSFS_MAGIC 0x62656572
7773  
7774  static struct vfsmount *sysfs_mount;
7775  struct super_block * sysfs_sb = NULL;
7776 @@ -47,7 +45,7 @@ static int sysfs_fill_super(struct super
7777  
7778         sb->s_blocksize = PAGE_CACHE_SIZE;
7779         sb->s_blocksize_bits = PAGE_CACHE_SHIFT;
7780 -       sb->s_magic = SYSFS_MAGIC;
7781 +       sb->s_magic = SYSFS_SUPER_MAGIC;
7782         sb->s_op = &sysfs_ops;
7783         sb->s_time_gran = 1;
7784         sysfs_sb = sb;
7785 diff -NurpP --minimal linux-2.6.29/fs/utimes.c linux-2.6.29-vs2.3.0.36.9-pre3/fs/utimes.c
7786 --- linux-2.6.29/fs/utimes.c    2009-03-24 14:22:37.000000000 +0100
7787 +++ linux-2.6.29-vs2.3.0.36.9-pre3/fs/utimes.c  2009-02-22 22:54:25.000000000 +0100
7788 @@ -8,6 +8,8 @@
7789  #include <linux/stat.h>
7790  #include <linux/utime.h>
7791  #include <linux/syscalls.h>
7792 +#include <linux/mount.h>
7793 +#include <linux/vs_cowbl.h>
7794  #include <asm/uaccess.h>
7795  #include <asm/unistd.h>
7796  
7797 diff -NurpP --minimal linux-2.6.29/fs/xattr.c linux-2.6.29-vs2.3.0.36.9-pre3/fs/xattr.c
7798 --- linux-2.6.29/fs/xattr.c     2009-03-24 14:22:37.000000000 +0100
7799 +++ linux-2.6.29-vs2.3.0.36.9-pre3/fs/xattr.c   2009-03-24 14:48:35.000000000 +0100
7800 @@ -18,6 +18,7 @@
7801  #include <linux/module.h>
7802  #include <linux/fsnotify.h>
7803  #include <linux/audit.h>
7804 +#include <linux/mount.h>
7805  #include <asm/uaccess.h>
7806  
7807  
7808 diff -NurpP --minimal linux-2.6.29/fs/xfs/linux-2.6/xfs_ioctl.c linux-2.6.29-vs2.3.0.36.9-pre3/fs/xfs/linux-2.6/xfs_ioctl.c
7809 --- linux-2.6.29/fs/xfs/linux-2.6/xfs_ioctl.c   2009-03-24 14:22:37.000000000 +0100
7810 +++ linux-2.6.29-vs2.3.0.36.9-pre3/fs/xfs/linux-2.6/xfs_ioctl.c 2009-03-24 14:48:35.000000000 +0100
7811 @@ -769,6 +769,10 @@ xfs_merge_ioc_xflags(
7812                 xflags |= XFS_XFLAG_IMMUTABLE;
7813         else
7814                 xflags &= ~XFS_XFLAG_IMMUTABLE;
7815 +       if (flags & FS_IXUNLINK_FL)
7816 +               xflags |= XFS_XFLAG_IXUNLINK;
7817 +       else
7818 +               xflags &= ~XFS_XFLAG_IXUNLINK;
7819         if (flags & FS_APPEND_FL)
7820                 xflags |= XFS_XFLAG_APPEND;
7821         else
7822 @@ -797,6 +801,8 @@ xfs_di2lxflags(
7823  
7824         if (di_flags & XFS_DIFLAG_IMMUTABLE)
7825                 flags |= FS_IMMUTABLE_FL;
7826 +       if (di_flags & XFS_DIFLAG_IXUNLINK)
7827 +               flags |= FS_IXUNLINK_FL;
7828         if (di_flags & XFS_DIFLAG_APPEND)
7829                 flags |= FS_APPEND_FL;
7830         if (di_flags & XFS_DIFLAG_SYNC)
7831 @@ -855,6 +861,8 @@ xfs_set_diflags(
7832         di_flags = (ip->i_d.di_flags & XFS_DIFLAG_PREALLOC);
7833         if (xflags & XFS_XFLAG_IMMUTABLE)
7834                 di_flags |= XFS_DIFLAG_IMMUTABLE;
7835 +       if (xflags & XFS_XFLAG_IXUNLINK)
7836 +               di_flags |= XFS_DIFLAG_IXUNLINK;
7837         if (xflags & XFS_XFLAG_APPEND)
7838                 di_flags |= XFS_DIFLAG_APPEND;
7839         if (xflags & XFS_XFLAG_SYNC)
7840 @@ -897,6 +905,10 @@ xfs_diflags_to_linux(
7841                 inode->i_flags |= S_IMMUTABLE;
7842         else
7843                 inode->i_flags &= ~S_IMMUTABLE;
7844 +       if (xflags & XFS_XFLAG_IXUNLINK)
7845 +               inode->i_flags |= S_IXUNLINK;
7846 +       else
7847 +               inode->i_flags &= ~S_IXUNLINK;
7848         if (xflags & XFS_XFLAG_APPEND)
7849                 inode->i_flags |= S_APPEND;
7850         else
7851 @@ -1371,10 +1383,18 @@ xfs_file_ioctl(
7852         case XFS_IOC_FSGETXATTRA:
7853                 return xfs_ioc_fsgetxattr(ip, 1, arg);
7854         case XFS_IOC_FSSETXATTR:
7855 +               if (IS_BARRIER(inode)) {
7856 +                       vxwprintk_task(1, "messing with the barrier.");
7857 +                       return -XFS_ERROR(EACCES);
7858 +               }
7859                 return xfs_ioc_fssetxattr(ip, filp, arg);
7860         case XFS_IOC_GETXFLAGS:
7861                 return xfs_ioc_getxflags(ip, arg);
7862         case XFS_IOC_SETXFLAGS:
7863 +               if (IS_BARRIER(inode)) {
7864 +                       vxwprintk_task(1, "messing with the barrier.");
7865 +                       return -XFS_ERROR(EACCES);
7866 +               }
7867                 return xfs_ioc_setxflags(ip, filp, arg);
7868  
7869         case XFS_IOC_FSSETDM: {
7870 diff -NurpP --minimal linux-2.6.29/fs/xfs/linux-2.6/xfs_iops.c linux-2.6.29-vs2.3.0.36.9-pre3/fs/xfs/linux-2.6/xfs_iops.c
7871 --- linux-2.6.29/fs/xfs/linux-2.6/xfs_iops.c    2009-03-24 14:22:37.000000000 +0100
7872 +++ linux-2.6.29-vs2.3.0.36.9-pre3/fs/xfs/linux-2.6/xfs_iops.c  2009-03-24 16:33:10.000000000 +0100
7873 @@ -54,6 +54,7 @@
7874  #include <linux/security.h>
7875  #include <linux/falloc.h>
7876  #include <linux/fiemap.h>
7877 +#include <linux/vs_tag.h>
7878  
7879  /*
7880   * Bring the atime in the XFS inode uptodate.
7881 @@ -552,6 +553,7 @@ xfs_vn_getattr(
7882         stat->nlink = ip->i_d.di_nlink;
7883         stat->uid = ip->i_d.di_uid;
7884         stat->gid = ip->i_d.di_gid;
7885 +       stat->tag = ip->i_d.di_tag;
7886         stat->ino = ip->i_ino;
7887  #if XFS_BIG_INUMS
7888         stat->ino += mp->m_inoadd;
7889 @@ -591,6 +593,12 @@ xfs_vn_getattr(
7890  }
7891  
7892  STATIC int
7893 +xfs_vn_sync_xflags(struct inode *inode)
7894 +{
7895 +       return -xfs_sync_xflags(XFS_I(inode));
7896 +}
7897 +
7898 +STATIC int
7899  xfs_vn_setattr(
7900         struct dentry   *dentry,
7901         struct iattr    *iattr)
7902 @@ -748,6 +756,7 @@ static const struct inode_operations xfs
7903         .listxattr              = xfs_vn_listxattr,
7904         .fallocate              = xfs_vn_fallocate,
7905         .fiemap                 = xfs_vn_fiemap,
7906 +       .sync_flags             = xfs_vn_sync_xflags,
7907  };
7908  
7909  static const struct inode_operations xfs_dir_inode_operations = {
7910 @@ -773,6 +782,7 @@ static const struct inode_operations xfs
7911         .getxattr               = generic_getxattr,
7912         .removexattr            = generic_removexattr,
7913         .listxattr              = xfs_vn_listxattr,
7914 +       .sync_flags             = xfs_vn_sync_xflags,
7915  };
7916  
7917  static const struct inode_operations xfs_dir_ci_inode_operations = {
7918 @@ -822,6 +832,10 @@ xfs_diflags_to_iflags(
7919                 inode->i_flags |= S_IMMUTABLE;
7920         else
7921                 inode->i_flags &= ~S_IMMUTABLE;
7922 +       if (ip->i_d.di_flags & XFS_DIFLAG_IXUNLINK)
7923 +               inode->i_flags |= S_IXUNLINK;
7924 +       else
7925 +               inode->i_flags &= ~S_IXUNLINK;
7926         if (ip->i_d.di_flags & XFS_DIFLAG_APPEND)
7927                 inode->i_flags |= S_APPEND;
7928         else
7929 @@ -834,6 +848,15 @@ xfs_diflags_to_iflags(
7930                 inode->i_flags |= S_NOATIME;
7931         else
7932                 inode->i_flags &= ~S_NOATIME;
7933 +
7934 +       if (ip->i_d.di_vflags & XFS_DIVFLAG_BARRIER)
7935 +               inode->i_vflags |= V_BARRIER;
7936 +       else
7937 +               inode->i_vflags &= ~V_BARRIER;
7938 +       if (ip->i_d.di_vflags & XFS_DIVFLAG_COW)
7939 +               inode->i_vflags |= V_COW;
7940 +       else
7941 +               inode->i_vflags &= ~V_COW;
7942  }
7943  
7944  /*
7945 @@ -862,6 +885,7 @@ xfs_setup_inode(
7946         inode->i_nlink  = ip->i_d.di_nlink;
7947         inode->i_uid    = ip->i_d.di_uid;
7948         inode->i_gid    = ip->i_d.di_gid;
7949 +       inode->i_tag    = ip->i_d.di_tag;
7950  
7951         switch (inode->i_mode & S_IFMT) {
7952         case S_IFBLK:
7953 diff -NurpP --minimal linux-2.6.29/fs/xfs/linux-2.6/xfs_linux.h linux-2.6.29-vs2.3.0.36.9-pre3/fs/xfs/linux-2.6/xfs_linux.h
7954 --- linux-2.6.29/fs/xfs/linux-2.6/xfs_linux.h   2009-03-24 14:22:37.000000000 +0100
7955 +++ linux-2.6.29-vs2.3.0.36.9-pre3/fs/xfs/linux-2.6/xfs_linux.h 2009-03-25 01:26:04.000000000 +0100
7956 @@ -119,6 +119,7 @@
7957  
7958  #define current_cpu()          (raw_smp_processor_id())
7959  #define current_pid()          (current->pid)
7960 +#define current_fstag(cred,vp) (dx_current_fstag((vp)->i_sb))
7961  #define current_test_flags(f)  (current->flags & (f))
7962  #define current_set_flags_nested(sp, f)                \
7963                 (*(sp) = current->flags, current->flags |= (f))
7964 diff -NurpP --minimal linux-2.6.29/fs/xfs/linux-2.6/xfs_super.c linux-2.6.29-vs2.3.0.36.9-pre3/fs/xfs/linux-2.6/xfs_super.c
7965 --- linux-2.6.29/fs/xfs/linux-2.6/xfs_super.c   2009-03-24 14:22:37.000000000 +0100
7966 +++ linux-2.6.29-vs2.3.0.36.9-pre3/fs/xfs/linux-2.6/xfs_super.c 2009-03-25 01:48:51.000000000 +0100
7967 @@ -120,6 +120,9 @@ mempool_t *xfs_ioend_pool;
7968  #define MNTOPT_DMAPI   "dmapi"         /* DMI enabled (DMAPI / XDSM) */
7969  #define MNTOPT_XDSM    "xdsm"          /* DMI enabled (DMAPI / XDSM) */
7970  #define MNTOPT_DMI     "dmi"           /* DMI enabled (DMAPI / XDSM) */
7971 +#define MNTOPT_TAGXID  "tagxid"        /* context tagging for inodes */
7972 +#define MNTOPT_TAGGED  "tag"           /* context tagging for inodes */
7973 +#define MNTOPT_NOTAGTAG        "notag"         /* do not use context tagging */
7974  
7975  /*
7976   * Table driven mount option parser.
7977 @@ -128,10 +131,14 @@ mempool_t *xfs_ioend_pool;
7978   * in the future, too.
7979   */
7980  enum {
7981 +       Opt_tag, Opt_notag,
7982         Opt_barrier, Opt_nobarrier, Opt_err
7983  };
7984  
7985  static const match_table_t tokens = {
7986 +       {Opt_tag, "tagxid"},
7987 +       {Opt_tag, "tag"},
7988 +       {Opt_notag, "notag"},
7989         {Opt_barrier, "barrier"},
7990         {Opt_nobarrier, "nobarrier"},
7991         {Opt_err, NULL}
7992 @@ -395,6 +402,19 @@ xfs_parseargs(
7993                 } else if (!strcmp(this_char, "irixsgid")) {
7994                         cmn_err(CE_WARN,
7995         "XFS: irixsgid is now a sysctl(2) variable, option is deprecated.");
7996 +#ifndef CONFIG_TAGGING_NONE
7997 +               } else if (!strcmp(this_char, MNTOPT_TAGGED)) {
7998 +                       mp->m_flags |= XFS_MOUNT_TAGGED;
7999 +               } else if (!strcmp(this_char, MNTOPT_NOTAGTAG)) {
8000 +                       mp->m_flags &= ~XFS_MOUNT_TAGGED;
8001 +               } else if (!strcmp(this_char, MNTOPT_TAGXID)) {
8002 +                       mp->m_flags |= XFS_MOUNT_TAGGED;
8003 +#endif
8004 +#ifdef CONFIG_PROPAGATE
8005 +               } else if (!strcmp(this_char, MNTOPT_TAGGED)) {
8006 +                       /* use value */
8007 +                       mp->m_flags |= XFS_MOUNT_TAGGED;
8008 +#endif
8009                 } else {
8010                         cmn_err(CE_WARN,
8011                                 "XFS: unknown mount option [%s].", this_char);
8012 @@ -1221,6 +1241,16 @@ xfs_fs_remount(
8013                 case Opt_nobarrier:
8014                         mp->m_flags &= ~XFS_MOUNT_BARRIER;
8015                         break;
8016 +               case Opt_tag:
8017 +                       if (!(sb->s_flags & MS_TAGGED)) {
8018 +                               printk(KERN_INFO
8019 +                                       "XFS: %s: tagging not permitted on remount.\n",
8020 +                                       sb->s_id);
8021 +                               return -EINVAL;
8022 +                       }
8023 +                       break;
8024 +               case Opt_notag:
8025 +                       break;
8026                 default:
8027                         /*
8028                          * Logically we would return an error here to prevent
8029 @@ -1480,6 +1510,9 @@ xfs_fs_fill_super(
8030  
8031         XFS_SEND_MOUNT(mp, DM_RIGHT_NULL, mtpt, mp->m_fsname);
8032  
8033 +       if (mp->m_flags & XFS_MOUNT_TAGGED)
8034 +               sb->s_flags |= MS_TAGGED;
8035 +
8036         sb->s_dirt = 1;
8037         sb->s_magic = XFS_SB_MAGIC;
8038         sb->s_blocksize = mp->m_sb.sb_blocksize;
8039 diff -NurpP --minimal linux-2.6.29/fs/xfs/quota/xfs_qm_syscalls.c linux-2.6.29-vs2.3.0.36.9-pre3/fs/xfs/quota/xfs_qm_syscalls.c
8040 --- linux-2.6.29/fs/xfs/quota/xfs_qm_syscalls.c 2009-03-24 14:22:37.000000000 +0100
8041 +++ linux-2.6.29-vs2.3.0.36.9-pre3/fs/xfs/quota/xfs_qm_syscalls.c       2009-03-24 14:48:35.000000000 +0100
8042 @@ -426,7 +426,7 @@ xfs_qm_scall_quotaon(
8043         uint            accflags;
8044         __int64_t       sbflags;
8045  
8046 -       if (!capable(CAP_SYS_ADMIN))
8047 +       if (!vx_capable(CAP_SYS_ADMIN, VXC_QUOTA_CTL))
8048                 return XFS_ERROR(EPERM);
8049  
8050         flags &= (XFS_ALL_QUOTA_ACCT | XFS_ALL_QUOTA_ENFD);
8051 diff -NurpP --minimal linux-2.6.29/fs/xfs/xfs_dinode.h linux-2.6.29-vs2.3.0.36.9-pre3/fs/xfs/xfs_dinode.h
8052 --- linux-2.6.29/fs/xfs/xfs_dinode.h    2009-03-24 14:22:37.000000000 +0100
8053 +++ linux-2.6.29-vs2.3.0.36.9-pre3/fs/xfs/xfs_dinode.h  2009-03-24 16:38:27.000000000 +0100
8054 @@ -50,7 +50,9 @@ typedef struct xfs_dinode {
8055         __be32          di_gid;         /* owner's group id */
8056         __be32          di_nlink;       /* number of links to file */
8057         __be16          di_projid;      /* owner's project id */
8058 -       __u8            di_pad[8];      /* unused, zeroed space */
8059 +       __be16          di_tag;         /* context tagging */
8060 +       __be16          di_vflags;      /* vserver specific flags */
8061 +       __u8            di_pad[4];      /* unused, zeroed space */
8062         __be16          di_flushiter;   /* incremented on flush */
8063         xfs_timestamp_t di_atime;       /* time last accessed */
8064         xfs_timestamp_t di_mtime;       /* time last modified */
8065 @@ -181,6 +183,8 @@ static inline void xfs_dinode_put_rdev(s
8066  #define XFS_DIFLAG_EXTSZINHERIT_BIT 12 /* inherit inode extent size */
8067  #define XFS_DIFLAG_NODEFRAG_BIT     13 /* do not reorganize/defragment */
8068  #define XFS_DIFLAG_FILESTREAM_BIT   14  /* use filestream allocator */
8069 +#define XFS_DIFLAG_IXUNLINK_BIT     15 /* Immutable inver on unlink */
8070 +
8071  #define XFS_DIFLAG_REALTIME      (1 << XFS_DIFLAG_REALTIME_BIT)
8072  #define XFS_DIFLAG_PREALLOC      (1 << XFS_DIFLAG_PREALLOC_BIT)
8073  #define XFS_DIFLAG_NEWRTBM       (1 << XFS_DIFLAG_NEWRTBM_BIT)
8074 @@ -196,6 +200,7 @@ static inline void xfs_dinode_put_rdev(s
8075  #define XFS_DIFLAG_EXTSZINHERIT  (1 << XFS_DIFLAG_EXTSZINHERIT_BIT)
8076  #define XFS_DIFLAG_NODEFRAG      (1 << XFS_DIFLAG_NODEFRAG_BIT)
8077  #define XFS_DIFLAG_FILESTREAM    (1 << XFS_DIFLAG_FILESTREAM_BIT)
8078 +#define XFS_DIFLAG_IXUNLINK      (1 << XFS_DIFLAG_IXUNLINK_BIT)
8079  
8080  #ifdef CONFIG_XFS_RT
8081  #define XFS_IS_REALTIME_INODE(ip) ((ip)->i_d.di_flags & XFS_DIFLAG_REALTIME)
8082 @@ -208,6 +213,10 @@ static inline void xfs_dinode_put_rdev(s
8083          XFS_DIFLAG_IMMUTABLE | XFS_DIFLAG_APPEND | XFS_DIFLAG_SYNC | \
8084          XFS_DIFLAG_NOATIME | XFS_DIFLAG_NODUMP | XFS_DIFLAG_RTINHERIT | \
8085          XFS_DIFLAG_PROJINHERIT | XFS_DIFLAG_NOSYMLINKS | XFS_DIFLAG_EXTSIZE | \
8086 -        XFS_DIFLAG_EXTSZINHERIT | XFS_DIFLAG_NODEFRAG | XFS_DIFLAG_FILESTREAM)
8087 +        XFS_DIFLAG_EXTSZINHERIT | XFS_DIFLAG_NODEFRAG | XFS_DIFLAG_FILESTREAM | \
8088 +        XFS_DIFLAG_IXUNLINK)
8089 +
8090 +#define XFS_DIVFLAG_BARRIER    0x01
8091 +#define XFS_DIVFLAG_COW                0x02
8092  
8093  #endif /* __XFS_DINODE_H__ */
8094 diff -NurpP --minimal linux-2.6.29/fs/xfs/xfs_fs.h linux-2.6.29-vs2.3.0.36.9-pre3/fs/xfs/xfs_fs.h
8095 --- linux-2.6.29/fs/xfs/xfs_fs.h        2009-03-24 14:22:37.000000000 +0100
8096 +++ linux-2.6.29-vs2.3.0.36.9-pre3/fs/xfs/xfs_fs.h      2009-03-24 14:48:35.000000000 +0100
8097 @@ -67,6 +67,9 @@ struct fsxattr {
8098  #define XFS_XFLAG_EXTSZINHERIT 0x00001000      /* inherit inode extent size */
8099  #define XFS_XFLAG_NODEFRAG     0x00002000      /* do not defragment */
8100  #define XFS_XFLAG_FILESTREAM   0x00004000      /* use filestream allocator */
8101 +#define XFS_XFLAG_IXUNLINK     0x00008000      /* immutable invert on unlink */
8102 +#define XFS_XFLAG_BARRIER      0x10000000      /* chroot() barrier */
8103 +#define XFS_XFLAG_COW          0x20000000      /* copy on write mark */
8104  #define XFS_XFLAG_HASATTR      0x80000000      /* no DIFLAG for this   */
8105  
8106  /*
8107 @@ -289,7 +292,8 @@ typedef struct xfs_bstat {
8108         __s32           bs_extents;     /* number of extents            */
8109         __u32           bs_gen;         /* generation count             */
8110         __u16           bs_projid;      /* project id                   */
8111 -       unsigned char   bs_pad[14];     /* pad space, unused            */
8112 +       __u16           bs_tag;         /* context tagging              */
8113 +       unsigned char   bs_pad[12];     /* pad space, unused            */
8114         __u32           bs_dmevmask;    /* DMIG event mask              */
8115         __u16           bs_dmstate;     /* DMIG state info              */
8116         __u16           bs_aextents;    /* attribute number of extents  */
8117 diff -NurpP --minimal linux-2.6.29/fs/xfs/xfs_ialloc.c linux-2.6.29-vs2.3.0.36.9-pre3/fs/xfs/xfs_ialloc.c
8118 --- linux-2.6.29/fs/xfs/xfs_ialloc.c    2009-03-24 14:22:37.000000000 +0100
8119 +++ linux-2.6.29-vs2.3.0.36.9-pre3/fs/xfs/xfs_ialloc.c  2009-03-24 17:03:17.000000000 +0100
8120 @@ -41,7 +41,6 @@
8121  #include "xfs_error.h"
8122  #include "xfs_bmap.h"
8123  
8124 -
8125  /*
8126   * Allocation group level functions.
8127   */
8128 diff -NurpP --minimal linux-2.6.29/fs/xfs/xfs_inode.c linux-2.6.29-vs2.3.0.36.9-pre3/fs/xfs/xfs_inode.c
8129 --- linux-2.6.29/fs/xfs/xfs_inode.c     2009-03-24 14:22:37.000000000 +0100
8130 +++ linux-2.6.29-vs2.3.0.36.9-pre3/fs/xfs/xfs_inode.c   2009-03-25 01:42:50.000000000 +0100
8131 @@ -250,6 +250,7 @@ xfs_inotobp(
8132         return 0;
8133  }
8134  
8135 +#include <linux/vs_tag.h>
8136  
8137  /*
8138   * This routine is called to map an inode to the buffer containing
8139 @@ -645,15 +646,25 @@ xfs_iformat_btree(
8140  void
8141  xfs_dinode_from_disk(
8142         xfs_icdinode_t          *to,
8143 -       xfs_dinode_t            *from)
8144 +       xfs_dinode_t            *from,
8145 +       int tagged)
8146  {
8147 +       uint32_t uid, gid, tag;
8148 +
8149         to->di_magic = be16_to_cpu(from->di_magic);
8150         to->di_mode = be16_to_cpu(from->di_mode);
8151         to->di_version = from ->di_version;
8152         to->di_format = from->di_format;
8153         to->di_onlink = be16_to_cpu(from->di_onlink);
8154 -       to->di_uid = be32_to_cpu(from->di_uid);
8155 -       to->di_gid = be32_to_cpu(from->di_gid);
8156 +
8157 +       uid = be32_to_cpu(from->di_uid);
8158 +       gid = be32_to_cpu(from->di_gid);
8159 +       tag = be16_to_cpu(from->di_tag);
8160 +
8161 +       to->di_uid = INOTAG_UID(tagged, uid, gid);
8162 +       to->di_gid = INOTAG_GID(tagged, uid, gid);
8163 +       to->di_tag = INOTAG_TAG(tagged, uid, gid, tag);
8164 +
8165         to->di_nlink = be32_to_cpu(from->di_nlink);
8166         to->di_projid = be16_to_cpu(from->di_projid);
8167         memcpy(to->di_pad, from->di_pad, sizeof(to->di_pad));
8168 @@ -674,21 +685,26 @@ xfs_dinode_from_disk(
8169         to->di_dmevmask = be32_to_cpu(from->di_dmevmask);
8170         to->di_dmstate  = be16_to_cpu(from->di_dmstate);
8171         to->di_flags    = be16_to_cpu(from->di_flags);
8172 +       to->di_vflags   = be16_to_cpu(from->di_vflags);
8173         to->di_gen      = be32_to_cpu(from->di_gen);
8174  }
8175  
8176  void
8177  xfs_dinode_to_disk(
8178         xfs_dinode_t            *to,
8179 -       xfs_icdinode_t          *from)
8180 +       xfs_icdinode_t          *from,
8181 +       int tagged)
8182  {
8183         to->di_magic = cpu_to_be16(from->di_magic);
8184         to->di_mode = cpu_to_be16(from->di_mode);
8185         to->di_version = from ->di_version;
8186         to->di_format = from->di_format;
8187         to->di_onlink = cpu_to_be16(from->di_onlink);
8188 -       to->di_uid = cpu_to_be32(from->di_uid);
8189 -       to->di_gid = cpu_to_be32(from->di_gid);
8190 +
8191 +       to->di_uid = cpu_to_be32(TAGINO_UID(tagged, from->di_uid, from->di_tag));
8192 +       to->di_gid = cpu_to_be32(TAGINO_GID(tagged, from->di_gid, from->di_tag));
8193 +       to->di_tag = cpu_to_be16(TAGINO_TAG(tagged, from->di_tag));
8194 +
8195         to->di_nlink = cpu_to_be32(from->di_nlink);
8196         to->di_projid = cpu_to_be16(from->di_projid);
8197         memcpy(to->di_pad, from->di_pad, sizeof(to->di_pad));
8198 @@ -709,12 +725,14 @@ xfs_dinode_to_disk(
8199         to->di_dmevmask = cpu_to_be32(from->di_dmevmask);
8200         to->di_dmstate = cpu_to_be16(from->di_dmstate);
8201         to->di_flags = cpu_to_be16(from->di_flags);
8202 +       to->di_vflags = cpu_to_be16(from->di_vflags);
8203         to->di_gen = cpu_to_be32(from->di_gen);
8204  }
8205  
8206  STATIC uint
8207  _xfs_dic2xflags(
8208 -       __uint16_t              di_flags)
8209 +       __uint16_t              di_flags,
8210 +       __uint16_t              di_vflags)
8211  {
8212         uint                    flags = 0;
8213  
8214 @@ -725,6 +743,8 @@ _xfs_dic2xflags(
8215                         flags |= XFS_XFLAG_PREALLOC;
8216                 if (di_flags & XFS_DIFLAG_IMMUTABLE)
8217                         flags |= XFS_XFLAG_IMMUTABLE;
8218 +               if (di_flags & XFS_DIFLAG_IXUNLINK)
8219 +                       flags |= XFS_XFLAG_IXUNLINK;
8220                 if (di_flags & XFS_DIFLAG_APPEND)
8221                         flags |= XFS_XFLAG_APPEND;
8222                 if (di_flags & XFS_DIFLAG_SYNC)
8223 @@ -749,6 +769,10 @@ _xfs_dic2xflags(
8224                         flags |= XFS_XFLAG_FILESTREAM;
8225         }
8226  
8227 +       if (di_vflags & XFS_DIVFLAG_BARRIER)
8228 +               flags |= FS_BARRIER_FL;
8229 +       if (di_vflags & XFS_DIVFLAG_COW)
8230 +               flags |= FS_COW_FL;
8231         return flags;
8232  }
8233  
8234 @@ -758,7 +782,7 @@ xfs_ip2xflags(
8235  {
8236         xfs_icdinode_t          *dic = &ip->i_d;
8237  
8238 -       return _xfs_dic2xflags(dic->di_flags) |
8239 +       return _xfs_dic2xflags(dic->di_flags, dic->di_vflags) |
8240                                 (XFS_IFORK_Q(ip) ? XFS_XFLAG_HASATTR : 0);
8241  }
8242  
8243 @@ -766,7 +790,8 @@ uint
8244  xfs_dic2xflags(
8245         xfs_dinode_t            *dip)
8246  {
8247 -       return _xfs_dic2xflags(be16_to_cpu(dip->di_flags)) |
8248 +       return _xfs_dic2xflags(be16_to_cpu(dip->di_flags),
8249 +                               be16_to_cpu(dip->di_vflags)) |
8250                                 (XFS_DFORK_Q(dip) ? XFS_XFLAG_HASATTR : 0);
8251  }
8252  
8253 @@ -802,7 +827,6 @@ xfs_iread(
8254         if (error)
8255                 return error;
8256         dip = (xfs_dinode_t *)xfs_buf_offset(bp, ip->i_imap.im_boffset);
8257 -
8258         /*
8259          * If we got something that isn't an inode it means someone
8260          * (nfs or dmi) has a stale handle.
8261 @@ -827,7 +851,8 @@ xfs_iread(
8262          * Otherwise, just get the truly permanent information.
8263          */
8264         if (dip->di_mode) {
8265 -               xfs_dinode_from_disk(&ip->i_d, dip);
8266 +               xfs_dinode_from_disk(&ip->i_d, dip,
8267 +                       mp->m_flags & XFS_MOUNT_TAGGED);
8268                 error = xfs_iformat(ip, dip);
8269                 if (error)  {
8270  #ifdef DEBUG
8271 @@ -1027,6 +1052,7 @@ xfs_ialloc(
8272         ASSERT(ip->i_d.di_nlink == nlink);
8273         ip->i_d.di_uid = current_fsuid();
8274         ip->i_d.di_gid = current_fsgid();
8275 +       ip->i_d.di_tag = current_fstag(cr, &ip->i_vnode);
8276         ip->i_d.di_projid = prid;
8277         memset(&(ip->i_d.di_pad[0]), 0, sizeof(ip->i_d.di_pad));
8278  
8279 @@ -1087,6 +1113,7 @@ xfs_ialloc(
8280         ip->i_d.di_dmevmask = 0;
8281         ip->i_d.di_dmstate = 0;
8282         ip->i_d.di_flags = 0;
8283 +       ip->i_d.di_vflags = 0;
8284         flags = XFS_ILOG_CORE;
8285         switch (mode & S_IFMT) {
8286         case S_IFIFO:
8287 @@ -2161,6 +2188,7 @@ xfs_ifree(
8288         }
8289         ip->i_d.di_mode = 0;            /* mark incore inode as free */
8290         ip->i_d.di_flags = 0;
8291 +       ip->i_d.di_vflags = 0;
8292         ip->i_d.di_dmevmask = 0;
8293         ip->i_d.di_forkoff = 0;         /* mark the attr fork not in use */
8294         ip->i_df.if_ext_max =
8295 @@ -3128,7 +3156,8 @@ xfs_iflush_int(
8296          * because if the inode is dirty at all the core must
8297          * be.
8298          */
8299 -       xfs_dinode_to_disk(dip, &ip->i_d);
8300 +       xfs_dinode_to_disk(dip, &ip->i_d,
8301 +               mp->m_flags & XFS_MOUNT_TAGGED);
8302  
8303         /* Wrap, we never let the log put out DI_MAX_FLUSH */
8304         if (ip->i_d.di_flushiter == DI_MAX_FLUSH)
8305 diff -NurpP --minimal linux-2.6.29/fs/xfs/xfs_inode.h linux-2.6.29-vs2.3.0.36.9-pre3/fs/xfs/xfs_inode.h
8306 --- linux-2.6.29/fs/xfs/xfs_inode.h     2009-03-24 14:22:37.000000000 +0100
8307 +++ linux-2.6.29-vs2.3.0.36.9-pre3/fs/xfs/xfs_inode.h   2009-03-25 01:10:35.000000000 +0100
8308 @@ -134,7 +134,9 @@ typedef struct xfs_icdinode {
8309         __uint32_t      di_gid;         /* owner's group id */
8310         __uint32_t      di_nlink;       /* number of links to file */
8311         __uint16_t      di_projid;      /* owner's project id */
8312 -       __uint8_t       di_pad[8];      /* unused, zeroed space */
8313 +       __uint16_t      di_tag;         /* context tagging */
8314 +       __uint16_t      di_vflags;      /* vserver specific flags */
8315 +       __uint8_t       di_pad[4];      /* unused, zeroed space */
8316         __uint16_t      di_flushiter;   /* incremented on flush */
8317         xfs_ictimestamp_t di_atime;     /* time last accessed */
8318         xfs_ictimestamp_t di_mtime;     /* time last modified */
8319 @@ -589,9 +591,9 @@ int         xfs_itobp(struct xfs_mount *, struc
8320  int            xfs_iread(struct xfs_mount *, struct xfs_trans *,
8321                           struct xfs_inode *, xfs_daddr_t, uint);
8322  void           xfs_dinode_from_disk(struct xfs_icdinode *,
8323 -                                    struct xfs_dinode *);
8324 +                                    struct xfs_dinode *, int);
8325  void           xfs_dinode_to_disk(struct xfs_dinode *,
8326 -                                  struct xfs_icdinode *);
8327 +                                  struct xfs_icdinode *, int);
8328  void           xfs_idestroy_fork(struct xfs_inode *, int);
8329  void           xfs_idata_realloc(struct xfs_inode *, int, int);
8330  void           xfs_iroot_realloc(struct xfs_inode *, int, int);
8331 diff -NurpP --minimal linux-2.6.29/fs/xfs/xfs_itable.c linux-2.6.29-vs2.3.0.36.9-pre3/fs/xfs/xfs_itable.c
8332 --- linux-2.6.29/fs/xfs/xfs_itable.c    2009-03-24 14:22:37.000000000 +0100
8333 +++ linux-2.6.29-vs2.3.0.36.9-pre3/fs/xfs/xfs_itable.c  2009-03-24 14:48:35.000000000 +0100
8334 @@ -82,6 +82,7 @@ xfs_bulkstat_one_iget(
8335         buf->bs_mode = dic->di_mode;
8336         buf->bs_uid = dic->di_uid;
8337         buf->bs_gid = dic->di_gid;
8338 +       buf->bs_tag = dic->di_tag;
8339         buf->bs_size = dic->di_size;
8340         vn_atime_to_bstime(VFS_I(ip), &buf->bs_atime);
8341         buf->bs_mtime.tv_sec = dic->di_mtime.t_sec;
8342 diff -NurpP --minimal linux-2.6.29/fs/xfs/xfs_log_recover.c linux-2.6.29-vs2.3.0.36.9-pre3/fs/xfs/xfs_log_recover.c
8343 --- linux-2.6.29/fs/xfs/xfs_log_recover.c       2009-03-24 14:22:37.000000000 +0100
8344 +++ linux-2.6.29-vs2.3.0.36.9-pre3/fs/xfs/xfs_log_recover.c     2009-03-24 17:17:15.000000000 +0100
8345 @@ -2421,7 +2421,8 @@ xlog_recover_do_inode_trans(
8346         }
8347  
8348         /* The core is in in-core format */
8349 -       xfs_dinode_to_disk(dip, (xfs_icdinode_t *)item->ri_buf[1].i_addr);
8350 +       xfs_dinode_to_disk(dip, (xfs_icdinode_t *)item->ri_buf[1].i_addr,
8351 +               mp->m_flags & XFS_MOUNT_TAGGED);
8352  
8353         /* the rest is in on-disk format */
8354         if (item->ri_buf[1].i_len > sizeof(struct xfs_icdinode)) {
8355 diff -NurpP --minimal linux-2.6.29/fs/xfs/xfs_mount.h linux-2.6.29-vs2.3.0.36.9-pre3/fs/xfs/xfs_mount.h
8356 --- linux-2.6.29/fs/xfs/xfs_mount.h     2009-03-24 14:22:37.000000000 +0100
8357 +++ linux-2.6.29-vs2.3.0.36.9-pre3/fs/xfs/xfs_mount.h   2009-03-24 14:48:35.000000000 +0100
8358 @@ -371,6 +371,7 @@ typedef struct xfs_mount {
8359                                                    allocator */
8360  #define XFS_MOUNT_NOATTR2      (1ULL << 25)    /* disable use of attr2 format */
8361  
8362 +#define XFS_MOUNT_TAGGED       (1ULL << 31)    /* context tagging */
8363  
8364  /*
8365   * Default minimum read and write sizes.
8366 diff -NurpP --minimal linux-2.6.29/fs/xfs/xfs_vnodeops.c linux-2.6.29-vs2.3.0.36.9-pre3/fs/xfs/xfs_vnodeops.c
8367 --- linux-2.6.29/fs/xfs/xfs_vnodeops.c  2009-03-24 14:22:37.000000000 +0100
8368 +++ linux-2.6.29-vs2.3.0.36.9-pre3/fs/xfs/xfs_vnodeops.c        2009-03-24 17:18:40.000000000 +0100
8369 @@ -53,6 +53,90 @@
8370  #include "xfs_filestream.h"
8371  #include "xfs_vnodeops.h"
8372  
8373 +
8374 +STATIC void
8375 +xfs_get_inode_flags(
8376 +       xfs_inode_t     *ip)
8377 +{
8378 +       struct inode    *inode = VFS_I(ip);
8379 +       unsigned int    flags = inode->i_flags;
8380 +       unsigned int    vflags = inode->i_vflags;
8381 +
8382 +       if (flags & S_IMMUTABLE)
8383 +               ip->i_d.di_flags |= XFS_DIFLAG_IMMUTABLE;
8384 +       else
8385 +               ip->i_d.di_flags &= ~XFS_DIFLAG_IMMUTABLE;
8386 +       if (flags & S_IXUNLINK)
8387 +               ip->i_d.di_flags |= XFS_DIFLAG_IXUNLINK;
8388 +       else
8389 +               ip->i_d.di_flags &= ~XFS_DIFLAG_IXUNLINK;
8390 +
8391 +       if (vflags & V_BARRIER)
8392 +               ip->i_d.di_vflags |= XFS_DIVFLAG_BARRIER;
8393 +       else
8394 +               ip->i_d.di_vflags &= ~XFS_DIVFLAG_BARRIER;
8395 +       if (vflags & V_COW)
8396 +               ip->i_d.di_vflags |= XFS_DIVFLAG_COW;
8397 +       else
8398 +               ip->i_d.di_vflags &= ~XFS_DIVFLAG_COW;
8399 +}
8400 +
8401 +int
8402 +xfs_sync_xflags(
8403 +       xfs_inode_t             *ip)
8404 +{
8405 +       struct xfs_mount        *mp = ip->i_mount;
8406 +       struct xfs_trans        *tp;
8407 +       unsigned int            lock_flags = 0;
8408 +       int                     code;
8409 +
8410 +       xfs_itrace_entry(ip);
8411 +
8412 +       if (mp->m_flags & XFS_MOUNT_RDONLY)
8413 +               return XFS_ERROR(EROFS);
8414 +
8415 +       /*
8416 +        * we acquire the inode lock and do an error checking pass.
8417 +        */
8418 +       tp = xfs_trans_alloc(mp, XFS_TRANS_SETATTR_NOT_SIZE);
8419 +       code = xfs_trans_reserve(tp, 0, XFS_ICHANGE_LOG_RES(mp), 0, 0, 0);
8420 +       if (code)
8421 +               goto error_return;
8422 +
8423 +       lock_flags = XFS_ILOCK_EXCL;
8424 +       xfs_ilock(ip, lock_flags);
8425 +
8426 +       xfs_trans_ijoin(tp, ip, lock_flags);
8427 +       xfs_trans_ihold(tp, ip);
8428 +
8429 +       xfs_get_inode_flags(ip);
8430 +       // xfs_diflags_to_linux(ip);
8431 +
8432 +       xfs_trans_log_inode(tp, ip, XFS_ILOG_CORE);
8433 +       xfs_ichgtime(ip, XFS_ICHGTIME_CHG);
8434 +
8435 +       XFS_STATS_INC(xs_ig_attrchg);
8436 +
8437 +       /*
8438 +        * If this is a synchronous mount, make sure that the
8439 +        * transaction goes to disk before returning to the user.
8440 +        */
8441 +       if (mp->m_flags & XFS_MOUNT_WSYNC)
8442 +               xfs_trans_set_sync(tp);
8443 +       code = xfs_trans_commit(tp, 0);
8444 +       xfs_iunlock(ip, lock_flags);
8445 +
8446 +       if (code)
8447 +               return code;
8448 +       return 0;
8449 +
8450 + error_return:
8451 +       xfs_trans_cancel(tp, 0);
8452 +       if (lock_flags)
8453 +               xfs_iunlock(ip, lock_flags);
8454 +       return code;
8455 +}
8456 +
8457  int
8458  xfs_setattr(
8459         struct xfs_inode        *ip,
8460 @@ -68,6 +152,7 @@ xfs_setattr(
8461         uint                    commit_flags=0;
8462         uid_t                   uid=0, iuid=0;
8463         gid_t                   gid=0, igid=0;
8464 +       tag_t                   tag=0, itag=0;
8465         int                     timeflags = 0;
8466         struct xfs_dquot        *udqp, *gdqp, *olddquot1, *olddquot2;
8467         int                     need_iolock = 1;
8468 @@ -164,7 +249,7 @@ xfs_setattr(
8469         /*
8470          * Change file ownership.  Must be the owner or privileged.
8471          */
8472 -       if (mask & (ATTR_UID|ATTR_GID)) {
8473 +       if (mask & (ATTR_UID|ATTR_GID|ATTR_TAG)) {
8474                 /*
8475                  * These IDs could have changed since we last looked at them.
8476                  * But, we're assured that if the ownership did change
8477 @@ -173,15 +258,19 @@ xfs_setattr(
8478                  */
8479                 iuid = ip->i_d.di_uid;
8480                 igid = ip->i_d.di_gid;
8481 +               itag = ip->i_d.di_tag;
8482                 gid = (mask & ATTR_GID) ? iattr->ia_gid : igid;
8483                 uid = (mask & ATTR_UID) ? iattr->ia_uid : iuid;
8484 +               tag = (mask & ATTR_TAG) ? iattr->ia_tag : itag;
8485  
8486                 /*
8487                  * Do a quota reservation only if uid/gid is actually
8488                  * going to change.
8489                  */
8490                 if ((XFS_IS_UQUOTA_ON(mp) && iuid != uid) ||
8491 -                   (XFS_IS_GQUOTA_ON(mp) && igid != gid)) {
8492 +                   (XFS_IS_GQUOTA_ON(mp) && igid != gid) ||
8493 +                   (XFS_IS_GQUOTA_ON(mp) && itag != tag)) {
8494 +                       /* TODO: handle tagging? */
8495                         ASSERT(tp);
8496                         code = XFS_QM_DQVOPCHOWNRESV(mp, tp, ip, udqp, gdqp,
8497                                                 capable(CAP_FOWNER) ?
8498 @@ -334,7 +423,7 @@ xfs_setattr(
8499         /*
8500          * Change file ownership.  Must be the owner or privileged.
8501          */
8502 -       if (mask & (ATTR_UID|ATTR_GID)) {
8503 +       if (mask & (ATTR_UID|ATTR_GID|ATTR_TAG)) {
8504                 /*
8505                  * CAP_FSETID overrides the following restrictions:
8506                  *
8507 @@ -350,6 +439,10 @@ xfs_setattr(
8508                  * Change the ownerships and register quota modifications
8509                  * in the transaction.
8510                  */
8511 +               if (itag != tag) {
8512 +                       ip->i_d.di_tag = tag;
8513 +                       inode->i_tag = tag;
8514 +               }
8515                 if (iuid != uid) {
8516                         if (XFS_IS_UQUOTA_ON(mp)) {
8517                                 ASSERT(mask & ATTR_UID);
8518 diff -NurpP --minimal linux-2.6.29/fs/xfs/xfs_vnodeops.h linux-2.6.29-vs2.3.0.36.9-pre3/fs/xfs/xfs_vnodeops.h
8519 --- linux-2.6.29/fs/xfs/xfs_vnodeops.h  2009-03-24 14:22:37.000000000 +0100
8520 +++ linux-2.6.29-vs2.3.0.36.9-pre3/fs/xfs/xfs_vnodeops.h        2009-03-24 17:19:30.000000000 +0100
8521 @@ -14,6 +14,7 @@ struct xfs_inode;
8522  struct xfs_iomap;
8523  
8524  
8525 +int xfs_sync_xflags(struct xfs_inode *ip);
8526  int xfs_setattr(struct xfs_inode *ip, struct iattr *vap, int flags);
8527  #define        XFS_ATTR_DMI            0x01    /* invocation from a DMI function */
8528  #define        XFS_ATTR_NONBLOCK       0x02    /* return EAGAIN if operation would block */
8529 diff -NurpP --minimal linux-2.6.29/include/asm-generic/tlb.h linux-2.6.29-vs2.3.0.36.9-pre3/include/asm-generic/tlb.h
8530 --- linux-2.6.29/include/asm-generic/tlb.h      2008-12-25 00:26:37.000000000 +0100
8531 +++ linux-2.6.29-vs2.3.0.36.9-pre3/include/asm-generic/tlb.h    2009-02-22 22:54:26.000000000 +0100
8532 @@ -14,6 +14,7 @@
8533  #define _ASM_GENERIC__TLB_H
8534  
8535  #include <linux/swap.h>
8536 +#include <linux/vs_memory.h>
8537  #include <asm/pgalloc.h>
8538  #include <asm/tlbflush.h>
8539  
8540 diff -NurpP --minimal linux-2.6.29/include/linux/capability.h linux-2.6.29-vs2.3.0.36.9-pre3/include/linux/capability.h
8541 --- linux-2.6.29/include/linux/capability.h     2009-03-24 14:22:41.000000000 +0100
8542 +++ linux-2.6.29-vs2.3.0.36.9-pre3/include/linux/capability.h   2009-03-24 14:48:35.000000000 +0100
8543 @@ -285,6 +285,7 @@ struct cpu_vfs_cap_data {
8544     arbitrary SCSI commands */
8545  /* Allow setting encryption key on loopback filesystem */
8546  /* Allow setting zone reclaim policy */
8547 +/* Allow the selection of a security context */
8548  
8549  #define CAP_SYS_ADMIN        21
8550  
8551 @@ -357,7 +358,13 @@ struct cpu_vfs_cap_data {
8552  
8553  #define CAP_MAC_ADMIN        33
8554  
8555 -#define CAP_LAST_CAP         CAP_MAC_ADMIN
8556 +/* Allow context manipulations */
8557 +/* Allow changing context info on files */
8558 +
8559 +#define CAP_CONTEXT         34
8560 +
8561 +
8562 +#define CAP_LAST_CAP         CAP_CONTEXT
8563  
8564  #define cap_valid(x) ((x) >= 0 && (x) <= CAP_LAST_CAP)
8565  
8566 diff -NurpP --minimal linux-2.6.29/include/linux/devpts_fs.h linux-2.6.29-vs2.3.0.36.9-pre3/include/linux/devpts_fs.h
8567 --- linux-2.6.29/include/linux/devpts_fs.h      2008-12-25 00:26:37.000000000 +0100
8568 +++ linux-2.6.29-vs2.3.0.36.9-pre3/include/linux/devpts_fs.h    2009-02-22 22:54:26.000000000 +0100
8569 @@ -45,5 +45,4 @@ static inline void devpts_pty_kill(struc
8570  
8571  #endif
8572  
8573 -
8574  #endif /* _LINUX_DEVPTS_FS_H */
8575 diff -NurpP --minimal linux-2.6.29/include/linux/ext2_fs.h linux-2.6.29-vs2.3.0.36.9-pre3/include/linux/ext2_fs.h
8576 --- linux-2.6.29/include/linux/ext2_fs.h        2009-03-24 14:22:41.000000000 +0100
8577 +++ linux-2.6.29-vs2.3.0.36.9-pre3/include/linux/ext2_fs.h      2009-03-24 15:39:54.000000000 +0100
8578 @@ -189,8 +189,12 @@ struct ext2_group_desc
8579  #define EXT2_NOTAIL_FL                 FS_NOTAIL_FL    /* file tail should not be merged */
8580  #define EXT2_DIRSYNC_FL                        FS_DIRSYNC_FL   /* dirsync behaviour (directories only) */
8581  #define EXT2_TOPDIR_FL                 FS_TOPDIR_FL    /* Top of directory hierarchies*/
8582 +#define EXT2_IXUNLINK_FL               FS_IXUNLINK_FL  /* Immutable invert on unlink */
8583  #define EXT2_RESERVED_FL               FS_RESERVED_FL  /* reserved for ext2 lib */
8584  
8585 +#define EXT2_BARRIER_FL                        FS_BARRIER_FL   /* Barrier for chroot() */
8586 +#define EXT2_COW_FL                    FS_COW_FL       /* Copy on Write marker */
8587 +
8588  #define EXT2_FL_USER_VISIBLE           FS_FL_USER_VISIBLE      /* User visible flags */
8589  #define EXT2_FL_USER_MODIFIABLE                FS_FL_USER_MODIFIABLE   /* User modifiable flags */
8590  
8591 @@ -271,7 +275,7 @@ struct ext2_inode {
8592                 struct {
8593                         __u8    l_i_frag;       /* Fragment number */
8594                         __u8    l_i_fsize;      /* Fragment size */
8595 -                       __u16   i_pad1;
8596 +                       __u16   l_i_tag;        /* Context Tag */
8597                         __le16  l_i_uid_high;   /* these 2 fields    */
8598                         __le16  l_i_gid_high;   /* were reserved2[0] */
8599                         __u32   l_i_reserved2;
8600 @@ -303,6 +307,7 @@ struct ext2_inode {
8601  #define i_gid_low      i_gid
8602  #define i_uid_high     osd2.linux2.l_i_uid_high
8603  #define i_gid_high     osd2.linux2.l_i_gid_high
8604 +#define i_raw_tag      osd2.linux2.l_i_tag
8605  #define i_reserved2    osd2.linux2.l_i_reserved2
8606  #endif
8607  
8608 @@ -347,6 +352,7 @@ struct ext2_inode {
8609  #define EXT2_MOUNT_USRQUOTA            0x020000  /* user quota */
8610  #define EXT2_MOUNT_GRPQUOTA            0x040000  /* group quota */
8611  #define EXT2_MOUNT_RESERVATION         0x080000  /* Preallocation */
8612 +#define EXT2_MOUNT_TAGGED              (1<<24)   /* Enable Context Tags */
8613  
8614  
8615  #define clear_opt(o, opt)              o &= ~EXT2_MOUNT_##opt
8616 diff -NurpP --minimal linux-2.6.29/include/linux/ext3_fs.h linux-2.6.29-vs2.3.0.36.9-pre3/include/linux/ext3_fs.h
8617 --- linux-2.6.29/include/linux/ext3_fs.h        2009-03-24 14:22:41.000000000 +0100
8618 +++ linux-2.6.29-vs2.3.0.36.9-pre3/include/linux/ext3_fs.h      2009-03-24 14:48:36.000000000 +0100
8619 @@ -173,10 +173,14 @@ struct ext3_group_desc
8620  #define EXT3_NOTAIL_FL                 0x00008000 /* file tail should not be merged */
8621  #define EXT3_DIRSYNC_FL                        0x00010000 /* dirsync behaviour (directories only) */
8622  #define EXT3_TOPDIR_FL                 0x00020000 /* Top of directory hierarchies*/
8623 +#define EXT3_IXUNLINK_FL               0x08000000 /* Immutable invert on unlink */
8624  #define EXT3_RESERVED_FL               0x80000000 /* reserved for ext3 lib */
8625  
8626 -#define EXT3_FL_USER_VISIBLE           0x0003DFFF /* User visible flags */
8627 -#define EXT3_FL_USER_MODIFIABLE                0x000380FF /* User modifiable flags */
8628 +#define EXT3_BARRIER_FL                        0x04000000 /* Barrier for chroot() */
8629 +#define EXT3_COW_FL                    0x20000000 /* Copy on Write marker */
8630 +
8631 +#define EXT3_FL_USER_VISIBLE           0x0103DFFF /* User visible flags */
8632 +#define EXT3_FL_USER_MODIFIABLE                0x010380FF /* User modifiable flags */
8633  
8634  /* Flags that should be inherited by new inodes from their parent. */
8635  #define EXT3_FL_INHERITED (EXT3_SECRM_FL | EXT3_UNRM_FL | EXT3_COMPR_FL |\
8636 @@ -316,7 +320,7 @@ struct ext3_inode {
8637                 struct {
8638                         __u8    l_i_frag;       /* Fragment number */
8639                         __u8    l_i_fsize;      /* Fragment size */
8640 -                       __u16   i_pad1;
8641 +                       __u16   l_i_tag;        /* Context Tag */
8642                         __le16  l_i_uid_high;   /* these 2 fields    */
8643                         __le16  l_i_gid_high;   /* were reserved2[0] */
8644                         __u32   l_i_reserved2;
8645 @@ -350,6 +354,7 @@ struct ext3_inode {
8646  #define i_gid_low      i_gid
8647  #define i_uid_high     osd2.linux2.l_i_uid_high
8648  #define i_gid_high     osd2.linux2.l_i_gid_high
8649 +#define i_raw_tag      osd2.linux2.l_i_tag
8650  #define i_reserved2    osd2.linux2.l_i_reserved2
8651  
8652  #elif defined(__GNU__)
8653 @@ -413,6 +418,7 @@ struct ext3_inode {
8654  #define EXT3_MOUNT_GRPQUOTA            0x200000 /* "old" group quota */
8655  #define EXT3_MOUNT_DATA_ERR_ABORT      0x400000 /* Abort on file data write
8656                                                   * error in ordered mode */
8657 +#define EXT3_MOUNT_TAGGED              (1<<24) /* Enable Context Tags */
8658  
8659  /* Compatibility, for having both ext2_fs.h and ext3_fs.h included at once */
8660  #ifndef _LINUX_EXT2_FS_H
8661 @@ -874,6 +880,7 @@ struct buffer_head * ext3_bread (handle_
8662  int ext3_get_blocks_handle(handle_t *handle, struct inode *inode,
8663         sector_t iblock, unsigned long maxblocks, struct buffer_head *bh_result,
8664         int create, int extend_disksize);
8665 +extern int ext3_sync_flags(struct inode *inode);
8666  
8667  extern struct inode *ext3_iget(struct super_block *, unsigned long);
8668  extern int  ext3_write_inode (struct inode *, int);
8669 diff -NurpP --minimal linux-2.6.29/include/linux/fs.h linux-2.6.29-vs2.3.0.36.9-pre3/include/linux/fs.h
8670 --- linux-2.6.29/include/linux/fs.h     2009-03-24 14:22:41.000000000 +0100
8671 +++ linux-2.6.29-vs2.3.0.36.9-pre3/include/linux/fs.h   2009-03-24 17:21:20.000000000 +0100
8672 @@ -141,6 +141,9 @@ struct inodes_stat_t {
8673  #define MS_RELATIME    (1<<21) /* Update atime relative to mtime/ctime. */
8674  #define MS_KERNMOUNT   (1<<22) /* this is a kern_mount call */
8675  #define MS_I_VERSION   (1<<23) /* Update inode I_version field */
8676 +#define MS_TAGGED      (1<<24) /* use generic inode tagging */
8677 +#define MS_TAGID       (1<<25) /* use specific tag for this mount */
8678 +#define MS_NOTAGCHECK  (1<<26) /* don't check tags */
8679  #define MS_ACTIVE      (1<<30)
8680  #define MS_NOUSER      (1<<31)
8681  
8682 @@ -167,6 +170,14 @@ struct inodes_stat_t {
8683  #define S_PRIVATE      512     /* Inode is fs-internal */
8684  #define S_ATOMIC_COPY  1024    /* Pages mapped with this inode need to be
8685                                    atomically copied (gem) */
8686 +#define S_IXUNLINK     2048    /* Immutable Invert on unlink */
8687 +
8688 +/* Linux-VServer related Inode flags */
8689 +
8690 +#define V_VALID                1
8691 +#define V_XATTR                2
8692 +#define V_BARRIER      4       /* Barrier for chroot() */
8693 +#define V_COW          8       /* Copy on Write */
8694  
8695  /*
8696   * Note that nosuid etc flags are inode-specific: setting some file-system
8697 @@ -189,12 +200,15 @@ struct inodes_stat_t {
8698  #define IS_DIRSYNC(inode)      (__IS_FLG(inode, MS_SYNCHRONOUS|MS_DIRSYNC) || \
8699                                         ((inode)->i_flags & (S_SYNC|S_DIRSYNC)))
8700  #define IS_MANDLOCK(inode)     __IS_FLG(inode, MS_MANDLOCK)
8701 -#define IS_NOATIME(inode)   __IS_FLG(inode, MS_RDONLY|MS_NOATIME)
8702 -#define IS_I_VERSION(inode)   __IS_FLG(inode, MS_I_VERSION)
8703 +#define IS_NOATIME(inode)      __IS_FLG(inode, MS_RDONLY|MS_NOATIME)
8704 +#define IS_I_VERSION(inode)    __IS_FLG(inode, MS_I_VERSION)
8705 +#define IS_TAGGED(inode)       __IS_FLG(inode, MS_TAGGED)
8706  
8707  #define IS_NOQUOTA(inode)      ((inode)->i_flags & S_NOQUOTA)
8708  #define IS_APPEND(inode)       ((inode)->i_flags & S_APPEND)
8709  #define IS_IMMUTABLE(inode)    ((inode)->i_flags & S_IMMUTABLE)
8710 +#define IS_IXUNLINK(inode)     ((inode)->i_flags & S_IXUNLINK)
8711 +#define IS_IXORUNLINK(inode)   ((IS_IXUNLINK(inode) ? S_IMMUTABLE : 0) ^ IS_IMMUTABLE(inode))
8712  #define IS_POSIXACL(inode)     __IS_FLG(inode, MS_POSIXACL)
8713  
8714  #define IS_DEADDIR(inode)      ((inode)->i_flags & S_DEAD)
8715 @@ -202,6 +216,16 @@ struct inodes_stat_t {
8716  #define IS_SWAPFILE(inode)     ((inode)->i_flags & S_SWAPFILE)
8717  #define IS_PRIVATE(inode)      ((inode)->i_flags & S_PRIVATE)
8718  
8719 +#define IS_BARRIER(inode)      (S_ISDIR((inode)->i_mode) && ((inode)->i_vflags & V_BARRIER))
8720 +
8721 +#ifdef CONFIG_VSERVER_COWBL
8722 +#  define IS_COW(inode)                (IS_IXUNLINK(inode) && IS_IMMUTABLE(inode))
8723 +#  define IS_COW_LINK(inode)   (S_ISREG((inode)->i_mode) && ((inode)->i_nlink > 1))
8724 +#else
8725 +#  define IS_COW(inode)                (0)
8726 +#  define IS_COW_LINK(inode)   (0)
8727 +#endif
8728 +
8729  /* the read-only stuff doesn't really belong here, but any other place is
8730     probably as bad and I don't want to create yet another include file. */
8731  
8732 @@ -279,11 +303,14 @@ struct inodes_stat_t {
8733  #define FS_TOPDIR_FL                   0x00020000 /* Top of directory hierarchies*/
8734  #define FS_EXTENT_FL                   0x00080000 /* Extents */
8735  #define FS_DIRECTIO_FL                 0x00100000 /* Use direct i/o */
8736 +#define FS_IXUNLINK_FL                 0x08000000 /* Immutable invert on unlink */
8737  #define FS_RESERVED_FL                 0x80000000 /* reserved for ext2 lib */
8738  
8739 -#define FS_FL_USER_VISIBLE             0x0003DFFF /* User visible flags */
8740 -#define FS_FL_USER_MODIFIABLE          0x000380FF /* User modifiable flags */
8741 +#define FS_BARRIER_FL                  0x04000000 /* Barrier for chroot() */
8742 +#define FS_COW_FL                      0x20000000 /* Copy on Write marker */
8743  
8744 +#define FS_FL_USER_VISIBLE             0x0103DFFF /* User visible flags */
8745 +#define FS_FL_USER_MODIFIABLE          0x010380FF /* User modifiable flags */
8746  
8747  #define SYNC_FILE_RANGE_WAIT_BEFORE    1
8748  #define SYNC_FILE_RANGE_WRITE          2
8749 @@ -365,6 +392,7 @@ typedef void (dio_iodone_t)(struct kiocb
8750  #define ATTR_KILL_PRIV (1 << 14)
8751  #define ATTR_OPEN      (1 << 15) /* Truncating from open(O_TRUNC) */
8752  #define ATTR_TIMES_SET (1 << 16)
8753 +#define ATTR_TAG       (1 << 17)
8754  
8755  /*
8756   * This is the Inode Attributes structure, used for notify_change().  It
8757 @@ -380,6 +408,7 @@ struct iattr {
8758         umode_t         ia_mode;
8759         uid_t           ia_uid;
8760         gid_t           ia_gid;
8761 +       tag_t           ia_tag;
8762         loff_t          ia_size;
8763         struct timespec ia_atime;
8764         struct timespec ia_mtime;
8765 @@ -393,6 +422,9 @@ struct iattr {
8766         struct file     *ia_file;
8767  };
8768  
8769 +#define ATTR_FLAG_BARRIER      512     /* Barrier for chroot() */
8770 +#define ATTR_FLAG_IXUNLINK     1024    /* Immutable invert on unlink */
8771 +
8772  /*
8773   * Includes for diskquotas.
8774   */
8775 @@ -656,7 +688,9 @@ struct inode {
8776         unsigned int            i_nlink;
8777         uid_t                   i_uid;
8778         gid_t                   i_gid;
8779 +       tag_t                   i_tag;
8780         dev_t                   i_rdev;
8781 +       dev_t                   i_mdev;
8782         u64                     i_version;
8783         loff_t                  i_size;
8784  #ifdef __NEED_I_SIZE_ORDERED
8785 @@ -704,7 +738,8 @@ struct inode {
8786         unsigned long           i_state;
8787         unsigned long           dirtied_when;   /* jiffies of first dirtying */
8788  
8789 -       unsigned int            i_flags;
8790 +       unsigned short          i_flags;
8791 +       unsigned short          i_vflags;
8792  
8793         atomic_t                i_writecount;
8794  #ifdef CONFIG_SECURITY
8795 @@ -791,12 +826,12 @@ static inline void i_size_write(struct i
8796  
8797  static inline unsigned iminor(const struct inode *inode)
8798  {
8799 -       return MINOR(inode->i_rdev);
8800 +       return MINOR(inode->i_mdev);
8801  }
8802  
8803  static inline unsigned imajor(const struct inode *inode)
8804  {
8805 -       return MAJOR(inode->i_rdev);
8806 +       return MAJOR(inode->i_mdev);
8807  }
8808  
8809  extern struct block_device *I_BDEV(struct inode *inode);
8810 @@ -854,6 +889,7 @@ struct file {
8811         loff_t                  f_pos;
8812         struct fown_struct      f_owner;
8813         const struct cred       *f_cred;
8814 +       xid_t                   f_xid;
8815         struct file_ra_state    f_ra;
8816  
8817         u64                     f_version;
8818 @@ -996,6 +1032,7 @@ struct file_lock {
8819         struct file *fl_file;
8820         loff_t fl_start;
8821         loff_t fl_end;
8822 +       xid_t fl_xid;
8823  
8824         struct fasync_struct *  fl_fasync; /* for lease break notifications */
8825         unsigned long fl_break_time;    /* for nonblocking lease breaks */
8826 @@ -1363,6 +1400,7 @@ struct inode_operations {
8827                           loff_t len);
8828         int (*fiemap)(struct inode *, struct fiemap_extent_info *, u64 start,
8829                       u64 len);
8830 +       int (*sync_flags) (struct inode *);
8831  };
8832  
8833  struct seq_file;
8834 @@ -1378,6 +1416,7 @@ extern ssize_t vfs_readv(struct file *, 
8835                 unsigned long, loff_t *);
8836  extern ssize_t vfs_writev(struct file *, const struct iovec __user *,
8837                 unsigned long, loff_t *);
8838 +ssize_t vfs_sendfile(struct file *, struct file *, loff_t *, size_t, loff_t);
8839  
8840  struct super_operations {
8841         struct inode *(*alloc_inode)(struct super_block *sb);
8842 @@ -2096,6 +2135,7 @@ extern int dcache_dir_open(struct inode 
8843  extern int dcache_dir_close(struct inode *, struct file *);
8844  extern loff_t dcache_dir_lseek(struct file *, loff_t, int);
8845  extern int dcache_readdir(struct file *, void *, filldir_t);
8846 +extern int dcache_readdir_filter(struct file *, void *, filldir_t, int (*)(struct dentry *));
8847  extern int simple_getattr(struct vfsmount *, struct dentry *, struct kstat *);
8848  extern int simple_statfs(struct dentry *, struct kstatfs *);
8849  extern int simple_link(struct dentry *, struct inode *, struct dentry *);
8850 diff -NurpP --minimal linux-2.6.29/include/linux/if_tun.h linux-2.6.29-vs2.3.0.36.9-pre3/include/linux/if_tun.h
8851 --- linux-2.6.29/include/linux/if_tun.h 2008-12-25 00:26:37.000000000 +0100
8852 +++ linux-2.6.29-vs2.3.0.36.9-pre3/include/linux/if_tun.h       2009-02-22 22:54:26.000000000 +0100
8853 @@ -46,6 +46,7 @@
8854  #define TUNSETOFFLOAD  _IOW('T', 208, unsigned int)
8855  #define TUNSETTXFILTER _IOW('T', 209, unsigned int)
8856  #define TUNGETIFF      _IOR('T', 210, unsigned int)
8857 +#define TUNSETNID     _IOW('T', 215, int)
8858  
8859  /* TUNSETIFF ifr flags */
8860  #define IFF_TUN                0x0001
8861 diff -NurpP --minimal linux-2.6.29/include/linux/init_task.h linux-2.6.29-vs2.3.0.36.9-pre3/include/linux/init_task.h
8862 --- linux-2.6.29/include/linux/init_task.h      2009-03-24 14:22:41.000000000 +0100
8863 +++ linux-2.6.29-vs2.3.0.36.9-pre3/include/linux/init_task.h    2009-03-24 14:48:36.000000000 +0100
8864 @@ -184,6 +184,10 @@ extern struct cred init_cred;
8865         INIT_IDS                                                        \
8866         INIT_TRACE_IRQFLAGS                                             \
8867         INIT_LOCKDEP                                                    \
8868 +       .xid            = 0,                                            \
8869 +       .vx_info        = NULL,                                         \
8870 +       .nid            = 0,                                            \
8871 +       .nx_info        = NULL,                                         \
8872  }
8873  
8874  
8875 diff -NurpP --minimal linux-2.6.29/include/linux/interrupt.h linux-2.6.29-vs2.3.0.36.9-pre3/include/linux/interrupt.h
8876 --- linux-2.6.29/include/linux/interrupt.h      2009-03-24 14:22:41.000000000 +0100
8877 +++ linux-2.6.29-vs2.3.0.36.9-pre3/include/linux/interrupt.h    2009-03-24 14:48:36.000000000 +0100
8878 @@ -9,8 +9,8 @@
8879  #include <linux/cpumask.h>
8880  #include <linux/irqreturn.h>
8881  #include <linux/irqnr.h>
8882 -#include <linux/hardirq.h>
8883  #include <linux/sched.h>
8884 +#include <linux/hardirq.h>
8885  #include <linux/irqflags.h>
8886  #include <linux/smp.h>
8887  #include <linux/percpu.h>
8888 diff -NurpP --minimal linux-2.6.29/include/linux/ipc.h linux-2.6.29-vs2.3.0.36.9-pre3/include/linux/ipc.h
8889 --- linux-2.6.29/include/linux/ipc.h    2008-12-25 00:26:37.000000000 +0100
8890 +++ linux-2.6.29-vs2.3.0.36.9-pre3/include/linux/ipc.h  2009-02-22 22:54:26.000000000 +0100
8891 @@ -93,6 +93,7 @@ struct kern_ipc_perm
8892         key_t           key;
8893         uid_t           uid;
8894         gid_t           gid;
8895 +       xid_t           xid;
8896         uid_t           cuid;
8897         gid_t           cgid;
8898         mode_t          mode; 
8899 diff -NurpP --minimal linux-2.6.29/include/linux/Kbuild linux-2.6.29-vs2.3.0.36.9-pre3/include/linux/Kbuild
8900 --- linux-2.6.29/include/linux/Kbuild   2009-03-24 14:22:40.000000000 +0100
8901 +++ linux-2.6.29-vs2.3.0.36.9-pre3/include/linux/Kbuild 2009-03-24 17:22:07.000000000 +0100
8902 @@ -373,5 +373,8 @@ unifdef-y += xattr.h
8903  unifdef-y += xfrm.h
8904  
8905  objhdr-y += version.h
8906 +
8907 +header-y += vserver/
8908  header-y += wimax.h
8909  header-y += wimax/
8910 +
8911 diff -NurpP --minimal linux-2.6.29/include/linux/loop.h linux-2.6.29-vs2.3.0.36.9-pre3/include/linux/loop.h
8912 --- linux-2.6.29/include/linux/loop.h   2009-03-24 14:22:42.000000000 +0100
8913 +++ linux-2.6.29-vs2.3.0.36.9-pre3/include/linux/loop.h 2009-03-24 14:48:36.000000000 +0100
8914 @@ -45,6 +45,7 @@ struct loop_device {
8915         struct loop_func_table *lo_encryption;
8916         __u32           lo_init[2];
8917         uid_t           lo_key_owner;   /* Who set the key */
8918 +       xid_t           lo_xid;
8919         int             (*ioctl)(struct loop_device *, int cmd, 
8920                                  unsigned long arg); 
8921  
8922 diff -NurpP --minimal linux-2.6.29/include/linux/magic.h linux-2.6.29-vs2.3.0.36.9-pre3/include/linux/magic.h
8923 --- linux-2.6.29/include/linux/magic.h  2009-03-24 14:22:42.000000000 +0100
8924 +++ linux-2.6.29-vs2.3.0.36.9-pre3/include/linux/magic.h        2009-03-24 14:48:36.000000000 +0100
8925 @@ -3,7 +3,7 @@
8926  
8927  #define ADFS_SUPER_MAGIC       0xadf5
8928  #define AFFS_SUPER_MAGIC       0xadff
8929 -#define AFS_SUPER_MAGIC                0x5346414F
8930 +#define AFS_SUPER_MAGIC                0x5346414F
8931  #define AUTOFS_SUPER_MAGIC     0x0187
8932  #define CODA_SUPER_MAGIC       0x73757245
8933  #define DEBUGFS_MAGIC          0x64626720
8934 @@ -33,6 +33,7 @@
8935  #define NFS_SUPER_MAGIC                0x6969
8936  #define OPENPROM_SUPER_MAGIC   0x9fa1
8937  #define PROC_SUPER_MAGIC       0x9fa0
8938 +#define DEVPTS_SUPER_MAGIC     0x1cd1
8939  #define QNX4_SUPER_MAGIC       0x002f          /* qnx4 fs detection */
8940  
8941  #define REISERFS_SUPER_MAGIC   0x52654973      /* used by gcc */
8942 diff -NurpP --minimal linux-2.6.29/include/linux/major.h linux-2.6.29-vs2.3.0.36.9-pre3/include/linux/major.h
8943 --- linux-2.6.29/include/linux/major.h  2008-12-25 00:26:37.000000000 +0100
8944 +++ linux-2.6.29-vs2.3.0.36.9-pre3/include/linux/major.h        2009-02-22 22:54:26.000000000 +0100
8945 @@ -15,6 +15,7 @@
8946  #define HD_MAJOR               IDE0_MAJOR
8947  #define PTY_SLAVE_MAJOR                3
8948  #define TTY_MAJOR              4
8949 +#define VROOT_MAJOR            4
8950  #define TTYAUX_MAJOR           5
8951  #define LP_MAJOR               6
8952  #define VCS_MAJOR              7
8953 diff -NurpP --minimal linux-2.6.29/include/linux/mm_types.h linux-2.6.29-vs2.3.0.36.9-pre3/include/linux/mm_types.h
8954 --- linux-2.6.29/include/linux/mm_types.h       2009-03-24 14:22:42.000000000 +0100
8955 +++ linux-2.6.29-vs2.3.0.36.9-pre3/include/linux/mm_types.h     2009-03-24 14:48:36.000000000 +0100
8956 @@ -232,6 +232,7 @@ struct mm_struct {
8957  
8958         /* Architecture-specific MM context */
8959         mm_context_t context;
8960 +       struct vx_info *mm_vx_info;
8961  
8962         /* Swap token stuff */
8963         /*
8964 diff -NurpP --minimal linux-2.6.29/include/linux/mount.h linux-2.6.29-vs2.3.0.36.9-pre3/include/linux/mount.h
8965 --- linux-2.6.29/include/linux/mount.h  2008-12-25 00:26:37.000000000 +0100
8966 +++ linux-2.6.29-vs2.3.0.36.9-pre3/include/linux/mount.h        2009-02-22 22:54:26.000000000 +0100
8967 @@ -35,6 +35,9 @@ struct mnt_namespace;
8968  #define MNT_UNBINDABLE 0x2000  /* if the vfsmount is a unbindable mount */
8969  #define MNT_PNODE_MASK 0x3000  /* propagation flag mask */
8970  
8971 +#define MNT_TAGID      0x10000
8972 +#define MNT_NOTAG      0x20000
8973 +
8974  struct vfsmount {
8975         struct list_head mnt_hash;
8976         struct vfsmount *mnt_parent;    /* fs we are mounted on */
8977 @@ -69,6 +72,7 @@ struct vfsmount {
8978          * are held, and all mnt_writer[]s on this mount have 0 as their ->count
8979          */
8980         atomic_t __mnt_writers;
8981 +       tag_t mnt_tag;                  /* tagging used for vfsmount */
8982  };
8983  
8984  static inline struct vfsmount *mntget(struct vfsmount *mnt)
8985 diff -NurpP --minimal linux-2.6.29/include/linux/net.h linux-2.6.29-vs2.3.0.36.9-pre3/include/linux/net.h
8986 --- linux-2.6.29/include/linux/net.h    2008-12-25 00:26:37.000000000 +0100
8987 +++ linux-2.6.29-vs2.3.0.36.9-pre3/include/linux/net.h  2009-02-22 22:54:26.000000000 +0100
8988 @@ -68,6 +68,7 @@ struct net;
8989  #define SOCK_NOSPACE           2
8990  #define SOCK_PASSCRED          3
8991  #define SOCK_PASSSEC           4
8992 +#define SOCK_USER_SOCKET       5
8993  
8994  #ifndef ARCH_HAS_SOCKET_TYPES
8995  /**
8996 diff -NurpP --minimal linux-2.6.29/include/linux/nfs_mount.h linux-2.6.29-vs2.3.0.36.9-pre3/include/linux/nfs_mount.h
8997 --- linux-2.6.29/include/linux/nfs_mount.h      2009-03-24 14:22:43.000000000 +0100
8998 +++ linux-2.6.29-vs2.3.0.36.9-pre3/include/linux/nfs_mount.h    2009-03-24 14:48:36.000000000 +0100
8999 @@ -63,7 +63,8 @@ struct nfs_mount_data {
9000  #define NFS_MOUNT_SECFLAVOUR   0x2000  /* 5 */
9001  #define NFS_MOUNT_NORDIRPLUS   0x4000  /* 5 */
9002  #define NFS_MOUNT_UNSHARED     0x8000  /* 5 */
9003 -#define NFS_MOUNT_FLAGMASK     0xFFFF
9004 +#define NFS_MOUNT_TAGGED       0x10000 /* context tagging */
9005 +#define NFS_MOUNT_FLAGMASK     0x1FFFF
9006  
9007  /* The following are for internal use only */
9008  #define NFS_MOUNT_LOOKUP_CACHE_NONEG   0x10000
9009 diff -NurpP --minimal linux-2.6.29/include/linux/nsproxy.h linux-2.6.29-vs2.3.0.36.9-pre3/include/linux/nsproxy.h
9010 --- linux-2.6.29/include/linux/nsproxy.h        2009-03-24 14:22:43.000000000 +0100
9011 +++ linux-2.6.29-vs2.3.0.36.9-pre3/include/linux/nsproxy.h      2009-03-24 14:48:36.000000000 +0100
9012 @@ -3,6 +3,7 @@
9013  
9014  #include <linux/spinlock.h>
9015  #include <linux/sched.h>
9016 +#include <linux/vserver/debug.h>
9017  
9018  struct mnt_namespace;
9019  struct uts_namespace;
9020 @@ -62,22 +63,33 @@ static inline struct nsproxy *task_nspro
9021  }
9022  
9023  int copy_namespaces(unsigned long flags, struct task_struct *tsk);
9024 +struct nsproxy *copy_nsproxy(struct nsproxy *orig);
9025  void exit_task_namespaces(struct task_struct *tsk);
9026  void switch_task_namespaces(struct task_struct *tsk, struct nsproxy *new);
9027  void free_nsproxy(struct nsproxy *ns);
9028  int unshare_nsproxy_namespaces(unsigned long, struct nsproxy **,
9029         struct fs_struct *);
9030  
9031 -static inline void put_nsproxy(struct nsproxy *ns)
9032 +#define        get_nsproxy(n)  __get_nsproxy(n, __FILE__, __LINE__)
9033 +
9034 +static inline void __get_nsproxy(struct nsproxy *ns,
9035 +       const char *_file, int _line)
9036  {
9037 -       if (atomic_dec_and_test(&ns->count)) {
9038 -               free_nsproxy(ns);
9039 -       }
9040 +       vxlprintk(VXD_CBIT(space, 0), "get_nsproxy(%p[%u])",
9041 +               ns, atomic_read(&ns->count), _file, _line);
9042 +       atomic_inc(&ns->count);
9043  }
9044  
9045 -static inline void get_nsproxy(struct nsproxy *ns)
9046 +#define        put_nsproxy(n)  __put_nsproxy(n, __FILE__, __LINE__)
9047 +
9048 +static inline void __put_nsproxy(struct nsproxy *ns,
9049 +       const char *_file, int _line)
9050  {
9051 -       atomic_inc(&ns->count);
9052 +       vxlprintk(VXD_CBIT(space, 0), "put_nsproxy(%p[%u])",
9053 +               ns, atomic_read(&ns->count), _file, _line);
9054 +       if (atomic_dec_and_test(&ns->count)) {
9055 +               free_nsproxy(ns);
9056 +       }
9057  }
9058  
9059  #ifdef CONFIG_CGROUP_NS
9060 diff -NurpP --minimal linux-2.6.29/include/linux/pid.h linux-2.6.29-vs2.3.0.36.9-pre3/include/linux/pid.h
9061 --- linux-2.6.29/include/linux/pid.h    2009-03-24 14:22:43.000000000 +0100
9062 +++ linux-2.6.29-vs2.3.0.36.9-pre3/include/linux/pid.h  2009-03-24 14:48:36.000000000 +0100
9063 @@ -8,7 +8,8 @@ enum pid_type
9064         PIDTYPE_PID,
9065         PIDTYPE_PGID,
9066         PIDTYPE_SID,
9067 -       PIDTYPE_MAX
9068 +       PIDTYPE_MAX,
9069 +       PIDTYPE_REALPID
9070  };
9071  
9072  /*
9073 @@ -160,6 +161,7 @@ static inline pid_t pid_nr(struct pid *p
9074  }
9075  
9076  pid_t pid_nr_ns(struct pid *pid, struct pid_namespace *ns);
9077 +pid_t pid_unmapped_nr_ns(struct pid *pid, struct pid_namespace *ns);
9078  pid_t pid_vnr(struct pid *pid);
9079  
9080  #define do_each_pid_task(pid, type, task)                              \
9081 diff -NurpP --minimal linux-2.6.29/include/linux/proc_fs.h linux-2.6.29-vs2.3.0.36.9-pre3/include/linux/proc_fs.h
9082 --- linux-2.6.29/include/linux/proc_fs.h        2008-12-25 00:26:37.000000000 +0100
9083 +++ linux-2.6.29-vs2.3.0.36.9-pre3/include/linux/proc_fs.h      2009-02-22 22:54:26.000000000 +0100
9084 @@ -59,6 +59,7 @@ struct proc_dir_entry {
9085         nlink_t nlink;
9086         uid_t uid;
9087         gid_t gid;
9088 +       int vx_flags;
9089         loff_t size;
9090         const struct inode_operations *proc_iops;
9091         /*
9092 @@ -268,12 +269,18 @@ static inline void kclist_add(struct kco
9093  extern void kclist_add(struct kcore_list *, void *, size_t);
9094  #endif
9095  
9096 +struct vx_info;
9097 +struct nx_info;
9098 +
9099  union proc_op {
9100         int (*proc_get_link)(struct inode *, struct path *);
9101         int (*proc_read)(struct task_struct *task, char *page);
9102         int (*proc_show)(struct seq_file *m,
9103                 struct pid_namespace *ns, struct pid *pid,
9104                 struct task_struct *task);
9105 +       int (*proc_vs_read)(char *page);
9106 +       int (*proc_vxi_read)(struct vx_info *vxi, char *page);
9107 +       int (*proc_nxi_read)(struct nx_info *nxi, char *page);
9108  };
9109  
9110  struct ctl_table_header;
9111 @@ -281,6 +288,7 @@ struct ctl_table;
9112  
9113  struct proc_inode {
9114         struct pid *pid;
9115 +       int vx_flags;
9116         int fd;
9117         union proc_op op;
9118         struct proc_dir_entry *pde;
9119 diff -NurpP --minimal linux-2.6.29/include/linux/reiserfs_fs.h linux-2.6.29-vs2.3.0.36.9-pre3/include/linux/reiserfs_fs.h
9120 --- linux-2.6.29/include/linux/reiserfs_fs.h    2008-12-25 00:26:37.000000000 +0100
9121 +++ linux-2.6.29-vs2.3.0.36.9-pre3/include/linux/reiserfs_fs.h  2009-02-22 22:54:26.000000000 +0100
9122 @@ -837,6 +837,11 @@ struct stat_data_v1 {
9123  #define REISERFS_COMPR_FL     FS_COMPR_FL
9124  #define REISERFS_NOTAIL_FL    FS_NOTAIL_FL
9125  
9126 +/* unfortunately reiserfs sdattr is only 16 bit */
9127 +#define REISERFS_IXUNLINK_FL  (FS_IXUNLINK_FL >> 16)
9128 +#define REISERFS_BARRIER_FL   (FS_BARRIER_FL >> 16)
9129 +#define REISERFS_COW_FL       (FS_COW_FL >> 16)
9130 +
9131  /* persistent flags that file inherits from the parent directory */
9132  #define REISERFS_INHERIT_MASK ( REISERFS_IMMUTABLE_FL |        \
9133                                 REISERFS_SYNC_FL |      \
9134 @@ -846,6 +851,9 @@ struct stat_data_v1 {
9135                                 REISERFS_COMPR_FL |     \
9136                                 REISERFS_NOTAIL_FL )
9137  
9138 +#define REISERFS_FL_USER_VISIBLE       0x80FF
9139 +#define REISERFS_FL_USER_MODIFIABLE    0x80FF
9140 +
9141  /* Stat Data on disk (reiserfs version of UFS disk inode minus the
9142     address blocks) */
9143  struct stat_data {
9144 @@ -1911,6 +1919,7 @@ static inline void reiserfs_update_sd(st
9145  void sd_attrs_to_i_attrs(__u16 sd_attrs, struct inode *inode);
9146  void i_attrs_to_sd_attrs(struct inode *inode, __u16 * sd_attrs);
9147  int reiserfs_setattr(struct dentry *dentry, struct iattr *attr);
9148 +int reiserfs_sync_flags(struct inode *inode);
9149  
9150  /* namei.c */
9151  void set_de_name_and_namelen(struct reiserfs_dir_entry *de);
9152 diff -NurpP --minimal linux-2.6.29/include/linux/reiserfs_fs_sb.h linux-2.6.29-vs2.3.0.36.9-pre3/include/linux/reiserfs_fs_sb.h
9153 --- linux-2.6.29/include/linux/reiserfs_fs_sb.h 2008-12-25 00:26:37.000000000 +0100
9154 +++ linux-2.6.29-vs2.3.0.36.9-pre3/include/linux/reiserfs_fs_sb.h       2009-02-22 22:54:26.000000000 +0100
9155 @@ -456,6 +456,7 @@ enum reiserfs_mount_options {
9156         REISERFS_POSIXACL,
9157         REISERFS_BARRIER_NONE,
9158         REISERFS_BARRIER_FLUSH,
9159 +       REISERFS_TAGGED,
9160  
9161         /* Actions on error */
9162         REISERFS_ERROR_PANIC,
9163 diff -NurpP --minimal linux-2.6.29/include/linux/sched.h linux-2.6.29-vs2.3.0.36.9-pre3/include/linux/sched.h
9164 --- linux-2.6.29/include/linux/sched.h  2009-03-24 14:22:43.000000000 +0100
9165 +++ linux-2.6.29-vs2.3.0.36.9-pre3/include/linux/sched.h        2009-03-24 14:48:36.000000000 +0100
9166 @@ -71,7 +71,6 @@ struct sched_param {
9167  #include <linux/fs_struct.h>
9168  #include <linux/compiler.h>
9169  #include <linux/completion.h>
9170 -#include <linux/pid.h>
9171  #include <linux/percpu.h>
9172  #include <linux/topology.h>
9173  #include <linux/proportions.h>
9174 @@ -88,6 +87,7 @@ struct sched_param {
9175  #include <linux/kobject.h>
9176  #include <linux/latencytop.h>
9177  #include <linux/cred.h>
9178 +#include <linux/pid.h>
9179  
9180  #include <asm/processor.h>
9181  
9182 @@ -176,12 +176,13 @@ extern unsigned long long time_sync_thre
9183  #define TASK_UNINTERRUPTIBLE   2
9184  #define __TASK_STOPPED         4
9185  #define __TASK_TRACED          8
9186 +#define TASK_ONHOLD            16
9187  /* in tsk->exit_state */
9188 -#define EXIT_ZOMBIE            16
9189 -#define EXIT_DEAD              32
9190 +#define EXIT_ZOMBIE            32
9191 +#define EXIT_DEAD              64
9192  /* in tsk->state again */
9193 -#define TASK_DEAD              64
9194 -#define TASK_WAKEKILL          128
9195 +#define TASK_DEAD              128
9196 +#define TASK_WAKEKILL          256
9197  
9198  /* Convenience macros for the sake of set_task_state */
9199  #define TASK_KILLABLE          (TASK_WAKEKILL | TASK_UNINTERRUPTIBLE)
9200 @@ -358,25 +359,28 @@ extern void arch_unmap_area_topdown(stru
9201   * The mm counters are not protected by its page_table_lock,
9202   * so must be incremented atomically.
9203   */
9204 -#define set_mm_counter(mm, member, value) atomic_long_set(&(mm)->_##member, value)
9205 -#define get_mm_counter(mm, member) ((unsigned long)atomic_long_read(&(mm)->_##member))
9206 -#define add_mm_counter(mm, member, value) atomic_long_add(value, &(mm)->_##member)
9207 -#define inc_mm_counter(mm, member) atomic_long_inc(&(mm)->_##member)
9208 -#define dec_mm_counter(mm, member) atomic_long_dec(&(mm)->_##member)
9209 +#define __set_mm_counter(mm, member, value) \
9210 +       atomic_long_set(&(mm)->_##member, value)
9211 +#define get_mm_counter(mm, member) \
9212 +       ((unsigned long)atomic_long_read(&(mm)->_##member))
9213  
9214  #else  /* !USE_SPLIT_PTLOCKS */
9215  /*
9216   * The mm counters are protected by its page_table_lock,
9217   * so can be incremented directly.
9218   */
9219 -#define set_mm_counter(mm, member, value) (mm)->_##member = (value)
9220 +#define __set_mm_counter(mm, member, value) (mm)->_##member = (value)
9221  #define get_mm_counter(mm, member) ((mm)->_##member)
9222 -#define add_mm_counter(mm, member, value) (mm)->_##member += (value)
9223 -#define inc_mm_counter(mm, member) (mm)->_##member++
9224 -#define dec_mm_counter(mm, member) (mm)->_##member--
9225  
9226  #endif /* !USE_SPLIT_PTLOCKS */
9227  
9228 +#define set_mm_counter(mm, member, value) \
9229 +       vx_ ## member ## pages_sub((mm), (get_mm_counter(mm, member) - value))
9230 +#define add_mm_counter(mm, member, value) \
9231 +       vx_ ## member ## pages_add((mm), (value))
9232 +#define inc_mm_counter(mm, member) vx_ ## member ## pages_inc((mm))
9233 +#define dec_mm_counter(mm, member) vx_ ## member ## pages_dec((mm))
9234 +
9235  #define get_mm_rss(mm)                                 \
9236         (get_mm_counter(mm, file_rss) + get_mm_counter(mm, anon_rss))
9237  #define update_hiwater_rss(mm) do {                    \
9238 @@ -1131,7 +1135,9 @@ struct task_struct {
9239         const struct sched_class *sched_class;
9240         struct sched_entity se;
9241         struct sched_rt_entity rt;
9242 -
9243 +#ifdef CONFIG_VSERVER_HARDCPU
9244 +       struct list_head hq;
9245 +#endif
9246  #ifdef CONFIG_PREEMPT_NOTIFIERS
9247         /* list of struct preempt_notifier: */
9248         struct hlist_head preempt_notifiers;
9249 @@ -1287,6 +1293,14 @@ struct task_struct {
9250  #endif
9251         seccomp_t seccomp;
9252  
9253 +/* vserver context data */
9254 +       struct vx_info *vx_info;
9255 +       struct nx_info *nx_info;
9256 +
9257 +       xid_t xid;
9258 +       nid_t nid;
9259 +       tag_t tag;
9260 +
9261  /* Thread group tracking */
9262         u32 parent_exec_id;
9263         u32 self_exec_id;
9264 @@ -1499,6 +1513,11 @@ struct pid_namespace;
9265   * see also pid_nr() etc in include/linux/pid.h
9266   */
9267  
9268 +#include <linux/vserver/base.h>
9269 +#include <linux/vserver/context.h>
9270 +#include <linux/vserver/debug.h>
9271 +#include <linux/vserver/pid.h>
9272 +
9273  static inline pid_t task_pid_nr(struct task_struct *tsk)
9274  {
9275         return tsk->pid;
9276 @@ -1508,7 +1527,7 @@ pid_t task_pid_nr_ns(struct task_struct 
9277  
9278  static inline pid_t task_pid_vnr(struct task_struct *tsk)
9279  {
9280 -       return pid_vnr(task_pid(tsk));
9281 +       return vx_map_pid(pid_vnr(task_pid(tsk)));
9282  }
9283  
9284  
9285 @@ -1521,7 +1540,7 @@ pid_t task_tgid_nr_ns(struct task_struct
9286  
9287  static inline pid_t task_tgid_vnr(struct task_struct *tsk)
9288  {
9289 -       return pid_vnr(task_tgid(tsk));
9290 +       return vx_map_tgid(pid_vnr(task_tgid(tsk)));
9291  }
9292  
9293  
9294 diff -NurpP --minimal linux-2.6.29/include/linux/shmem_fs.h linux-2.6.29-vs2.3.0.36.9-pre3/include/linux/shmem_fs.h
9295 --- linux-2.6.29/include/linux/shmem_fs.h       2008-12-25 00:26:37.000000000 +0100
9296 +++ linux-2.6.29-vs2.3.0.36.9-pre3/include/linux/shmem_fs.h     2009-02-22 22:54:26.000000000 +0100
9297 @@ -8,6 +8,9 @@
9298  
9299  #define SHMEM_NR_DIRECT 16
9300  
9301 +#define TMPFS_SUPER_MAGIC      0x01021994
9302 +
9303 +
9304  struct shmem_inode_info {
9305         spinlock_t              lock;
9306         unsigned long           flags;
9307 diff -NurpP --minimal linux-2.6.29/include/linux/stat.h linux-2.6.29-vs2.3.0.36.9-pre3/include/linux/stat.h
9308 --- linux-2.6.29/include/linux/stat.h   2008-12-25 00:26:37.000000000 +0100
9309 +++ linux-2.6.29-vs2.3.0.36.9-pre3/include/linux/stat.h 2009-02-22 22:54:26.000000000 +0100
9310 @@ -66,6 +66,7 @@ struct kstat {
9311         unsigned int    nlink;
9312         uid_t           uid;
9313         gid_t           gid;
9314 +       tag_t           tag;
9315         dev_t           rdev;
9316         loff_t          size;
9317         struct timespec  atime;
9318 diff -NurpP --minimal linux-2.6.29/include/linux/sunrpc/auth.h linux-2.6.29-vs2.3.0.36.9-pre3/include/linux/sunrpc/auth.h
9319 --- linux-2.6.29/include/linux/sunrpc/auth.h    2008-12-25 00:26:37.000000000 +0100
9320 +++ linux-2.6.29-vs2.3.0.36.9-pre3/include/linux/sunrpc/auth.h  2009-02-22 22:54:26.000000000 +0100
9321 @@ -25,6 +25,7 @@
9322  struct auth_cred {
9323         uid_t   uid;
9324         gid_t   gid;
9325 +       tag_t   tag;
9326         struct group_info *group_info;
9327         unsigned char machine_cred : 1;
9328  };
9329 diff -NurpP --minimal linux-2.6.29/include/linux/sunrpc/clnt.h linux-2.6.29-vs2.3.0.36.9-pre3/include/linux/sunrpc/clnt.h
9330 --- linux-2.6.29/include/linux/sunrpc/clnt.h    2009-03-24 14:22:43.000000000 +0100
9331 +++ linux-2.6.29-vs2.3.0.36.9-pre3/include/linux/sunrpc/clnt.h  2009-03-24 14:48:36.000000000 +0100
9332 @@ -43,7 +43,8 @@ struct rpc_clnt {
9333         unsigned int            cl_softrtry : 1,/* soft timeouts */
9334                                 cl_discrtry : 1,/* disconnect before retry */
9335                                 cl_autobind : 1,/* use getport() */
9336 -                               cl_chatty   : 1;/* be verbose */
9337 +                               cl_chatty   : 1,/* be verbose */
9338 +                               cl_tag      : 1;/* context tagging */
9339  
9340         struct rpc_rtt *        cl_rtt;         /* RTO estimator data */
9341         const struct rpc_timeout *cl_timeout;   /* Timeout strategy */
9342 diff -NurpP --minimal linux-2.6.29/include/linux/syscalls.h linux-2.6.29-vs2.3.0.36.9-pre3/include/linux/syscalls.h
9343 --- linux-2.6.29/include/linux/syscalls.h       2009-03-24 14:22:43.000000000 +0100
9344 +++ linux-2.6.29-vs2.3.0.36.9-pre3/include/linux/syscalls.h     2009-03-24 14:48:36.000000000 +0100
9345 @@ -369,6 +369,8 @@ asmlinkage long sys_symlink(const char _
9346  asmlinkage long sys_unlink(const char __user *pathname);
9347  asmlinkage long sys_rename(const char __user *oldname,
9348                                 const char __user *newname);
9349 +asmlinkage long sys_copyfile(const char __user *from, const char __user *to,
9350 +                               umode_t mode);
9351  asmlinkage long sys_chmod(const char __user *filename, mode_t mode);
9352  asmlinkage long sys_fchmod(unsigned int fd, mode_t mode);
9353  
9354 diff -NurpP --minimal linux-2.6.29/include/linux/sysctl.h linux-2.6.29-vs2.3.0.36.9-pre3/include/linux/sysctl.h
9355 --- linux-2.6.29/include/linux/sysctl.h 2008-12-25 00:26:37.000000000 +0100
9356 +++ linux-2.6.29-vs2.3.0.36.9-pre3/include/linux/sysctl.h       2009-02-22 22:54:26.000000000 +0100
9357 @@ -70,6 +70,7 @@ enum
9358         CTL_ABI=9,              /* Binary emulation */
9359         CTL_CPU=10,             /* CPU stuff (speed scaling, etc) */
9360         CTL_ARLAN=254,          /* arlan wireless driver */
9361 +       CTL_VSERVER=4242,       /* Linux-VServer debug */
9362         CTL_S390DBF=5677,       /* s390 debug */
9363         CTL_SUNRPC=7249,        /* sunrpc debug */
9364         CTL_PM=9899,            /* frv power management */
9365 @@ -104,6 +105,7 @@ enum
9366  
9367         KERN_PANIC=15,          /* int: panic timeout */
9368         KERN_REALROOTDEV=16,    /* real root device to mount after initrd */
9369 +       KERN_VSHELPER=17,       /* string: path to vshelper policy agent */
9370  
9371         KERN_SPARC_REBOOT=21,   /* reboot command on Sparc */
9372         KERN_CTLALTDEL=22,      /* int: allow ctl-alt-del to reboot */
9373 diff -NurpP --minimal linux-2.6.29/include/linux/sysfs.h linux-2.6.29-vs2.3.0.36.9-pre3/include/linux/sysfs.h
9374 --- linux-2.6.29/include/linux/sysfs.h  2008-12-25 00:26:37.000000000 +0100
9375 +++ linux-2.6.29-vs2.3.0.36.9-pre3/include/linux/sysfs.h        2009-02-22 22:54:26.000000000 +0100
9376 @@ -17,6 +17,8 @@
9377  #include <linux/list.h>
9378  #include <asm/atomic.h>
9379  
9380 +#define SYSFS_SUPER_MAGIC      0x62656572
9381 +
9382  struct kobject;
9383  struct module;
9384  
9385 diff -NurpP --minimal linux-2.6.29/include/linux/time.h linux-2.6.29-vs2.3.0.36.9-pre3/include/linux/time.h
9386 --- linux-2.6.29/include/linux/time.h   2009-03-24 14:22:43.000000000 +0100
9387 +++ linux-2.6.29-vs2.3.0.36.9-pre3/include/linux/time.h 2009-02-22 22:54:26.000000000 +0100
9388 @@ -190,6 +190,9 @@ static __always_inline void timespec_add
9389         a->tv_sec += __iter_div_u64_rem(a->tv_nsec + ns, NSEC_PER_SEC, &ns);
9390         a->tv_nsec = ns;
9391  }
9392 +
9393 +#include <linux/vs_time.h>
9394 +
9395  #endif /* __KERNEL__ */
9396  
9397  #define NFDBITS                        __NFDBITS
9398 diff -NurpP --minimal linux-2.6.29/include/linux/types.h linux-2.6.29-vs2.3.0.36.9-pre3/include/linux/types.h
9399 --- linux-2.6.29/include/linux/types.h  2009-03-24 14:22:43.000000000 +0100
9400 +++ linux-2.6.29-vs2.3.0.36.9-pre3/include/linux/types.h        2009-03-24 14:48:36.000000000 +0100
9401 @@ -36,6 +36,9 @@ typedef __kernel_uid32_t      uid_t;
9402  typedef __kernel_gid32_t       gid_t;
9403  typedef __kernel_uid16_t        uid16_t;
9404  typedef __kernel_gid16_t        gid16_t;
9405 +typedef unsigned int           xid_t;
9406 +typedef unsigned int           nid_t;
9407 +typedef unsigned int           tag_t;
9408  
9409  typedef unsigned long          uintptr_t;
9410  
9411 diff -NurpP --minimal linux-2.6.29/include/linux/vroot.h linux-2.6.29-vs2.3.0.36.9-pre3/include/linux/vroot.h
9412 --- linux-2.6.29/include/linux/vroot.h  1970-01-01 01:00:00.000000000 +0100
9413 +++ linux-2.6.29-vs2.3.0.36.9-pre3/include/linux/vroot.h        2009-02-22 22:54:26.000000000 +0100
9414 @@ -0,0 +1,51 @@
9415 +
9416 +/*
9417 + * include/linux/vroot.h
9418 + *
9419 + * written by Herbert Pötzl, 9/11/2002
9420 + * ported to 2.6 by Herbert Pötzl, 30/12/2004
9421 + *
9422 + * Copyright (C) 2002-2007 by Herbert Pötzl.
9423 + * Redistribution of this file is permitted under the
9424 + * GNU General Public License.
9425 + */
9426 +
9427 +#ifndef _LINUX_VROOT_H
9428 +#define _LINUX_VROOT_H
9429 +
9430 +
9431 +#ifdef __KERNEL__
9432 +
9433 +/* Possible states of device */
9434 +enum {
9435 +       Vr_unbound,
9436 +       Vr_bound,
9437 +};
9438 +
9439 +struct vroot_device {
9440 +       int             vr_number;
9441 +       int             vr_refcnt;
9442 +
9443 +       struct semaphore        vr_ctl_mutex;
9444 +       struct block_device    *vr_device;
9445 +       int                     vr_state;
9446 +};
9447 +
9448 +
9449 +typedef struct block_device *(vroot_grb_func)(struct block_device *);
9450 +
9451 +extern int register_vroot_grb(vroot_grb_func *);
9452 +extern int unregister_vroot_grb(vroot_grb_func *);
9453 +
9454 +#endif /* __KERNEL__ */
9455 +
9456 +#define MAX_VROOT_DEFAULT      8
9457 +
9458 +/*
9459 + * IOCTL commands --- we will commandeer 0x56 ('V')
9460 + */
9461 +
9462 +#define VROOT_SET_DEV          0x5600
9463 +#define VROOT_CLR_DEV          0x5601
9464 +
9465 +#endif /* _LINUX_VROOT_H */
9466 diff -NurpP --minimal linux-2.6.29/include/linux/vs_base.h linux-2.6.29-vs2.3.0.36.9-pre3/include/linux/vs_base.h
9467 --- linux-2.6.29/include/linux/vs_base.h        1970-01-01 01:00:00.000000000 +0100
9468 +++ linux-2.6.29-vs2.3.0.36.9-pre3/include/linux/vs_base.h      2009-02-22 22:54:26.000000000 +0100
9469 @@ -0,0 +1,10 @@
9470 +#ifndef _VS_BASE_H
9471 +#define _VS_BASE_H
9472 +
9473 +#include "vserver/base.h"
9474 +#include "vserver/check.h"
9475 +#include "vserver/debug.h"
9476 +
9477 +#else
9478 +#warning duplicate inclusion
9479 +#endif
9480 diff -NurpP --minimal linux-2.6.29/include/linux/vs_context.h linux-2.6.29-vs2.3.0.36.9-pre3/include/linux/vs_context.h
9481 --- linux-2.6.29/include/linux/vs_context.h     1970-01-01 01:00:00.000000000 +0100
9482 +++ linux-2.6.29-vs2.3.0.36.9-pre3/include/linux/vs_context.h   2009-02-22 22:54:26.000000000 +0100
9483 @@ -0,0 +1,227 @@
9484 +#ifndef _VS_CONTEXT_H
9485 +#define _VS_CONTEXT_H
9486 +
9487 +#include "vserver/base.h"
9488 +#include "vserver/check.h"
9489 +#include "vserver/context.h"
9490 +#include "vserver/history.h"
9491 +#include "vserver/debug.h"
9492 +
9493 +#include <linux/sched.h>
9494 +
9495 +
9496 +#define get_vx_info(i) __get_vx_info(i, __FILE__, __LINE__, __HERE__)
9497 +
9498 +static inline struct vx_info *__get_vx_info(struct vx_info *vxi,
9499 +       const char *_file, int _line, void *_here)
9500 +{
9501 +       if (!vxi)
9502 +               return NULL;
9503 +
9504 +       vxlprintk(VXD_CBIT(xid, 2), "get_vx_info(%p[#%d.%d])",
9505 +               vxi, vxi ? vxi->vx_id : 0,
9506 +               vxi ? atomic_read(&vxi->vx_usecnt) : 0,
9507 +               _file, _line);
9508 +       __vxh_get_vx_info(vxi, _here);
9509 +
9510 +       atomic_inc(&vxi->vx_usecnt);
9511 +       return vxi;
9512 +}
9513 +
9514 +
9515 +extern void free_vx_info(struct vx_info *);
9516 +
9517 +#define put_vx_info(i) __put_vx_info(i, __FILE__, __LINE__, __HERE__)
9518 +
9519 +static inline void __put_vx_info(struct vx_info *vxi,
9520 +       const char *_file, int _line, void *_here)
9521 +{
9522 +       if (!vxi)
9523 +               return;
9524 +
9525 +       vxlprintk(VXD_CBIT(xid, 2), "put_vx_info(%p[#%d.%d])",
9526 +               vxi, vxi ? vxi->vx_id : 0,
9527 +               vxi ? atomic_read(&vxi->vx_usecnt) : 0,
9528 +               _file, _line);
9529 +       __vxh_put_vx_info(vxi, _here);
9530 +
9531 +       if (atomic_dec_and_test(&vxi->vx_usecnt))
9532 +               free_vx_info(vxi);
9533 +}
9534 +
9535 +
9536 +#define init_vx_info(p, i) \
9537 +       __init_vx_info(p, i, __FILE__, __LINE__, __HERE__)
9538 +
9539 +static inline void __init_vx_info(struct vx_info **vxp, struct vx_info *vxi,
9540 +       const char *_file, int _line, void *_here)
9541 +{
9542 +       if (vxi) {
9543 +               vxlprintk(VXD_CBIT(xid, 3),
9544 +                       "init_vx_info(%p[#%d.%d])",
9545 +                       vxi, vxi ? vxi->vx_id : 0,
9546 +                       vxi ? atomic_read(&vxi->vx_usecnt) : 0,
9547 +                       _file, _line);
9548 +               __vxh_init_vx_info(vxi, vxp, _here);
9549 +
9550 +               atomic_inc(&vxi->vx_usecnt);
9551 +       }
9552 +       *vxp = vxi;
9553 +}
9554 +
9555 +
9556 +#define set_vx_info(p, i) \
9557 +       __set_vx_info(p, i, __FILE__, __LINE__, __HERE__)
9558 +
9559 +static inline void __set_vx_info(struct vx_info **vxp, struct vx_info *vxi,
9560 +       const char *_file, int _line, void *_here)
9561 +{
9562 +       struct vx_info *vxo;
9563 +
9564 +       if (!vxi)
9565 +               return;
9566 +
9567 +       vxlprintk(VXD_CBIT(xid, 3), "set_vx_info(%p[#%d.%d])",
9568 +               vxi, vxi ? vxi->vx_id : 0,
9569 +               vxi ? atomic_read(&vxi->vx_usecnt) : 0,
9570 +               _file, _line);
9571 +       __vxh_set_vx_info(vxi, vxp, _here);
9572 +
9573 +       atomic_inc(&vxi->vx_usecnt);
9574 +       vxo = xchg(vxp, vxi);
9575 +       BUG_ON(vxo);
9576 +}
9577 +
9578 +
9579 +#define clr_vx_info(p) __clr_vx_info(p, __FILE__, __LINE__, __HERE__)
9580 +
9581 +static inline void __clr_vx_info(struct vx_info **vxp,
9582 +       const char *_file, int _line, void *_here)
9583 +{
9584 +       struct vx_info *vxo;
9585 +
9586 +       vxo = xchg(vxp, NULL);
9587 +       if (!vxo)
9588 +               return;
9589 +
9590 +       vxlprintk(VXD_CBIT(xid, 3), "clr_vx_info(%p[#%d.%d])",
9591 +               vxo, vxo ? vxo->vx_id : 0,
9592 +               vxo ? atomic_read(&vxo->vx_usecnt) : 0,
9593 +               _file, _line);
9594 +       __vxh_clr_vx_info(vxo, vxp, _here);
9595 +
9596 +       if (atomic_dec_and_test(&vxo->vx_usecnt))
9597 +               free_vx_info(vxo);
9598 +}
9599 +
9600 +
9601 +#define claim_vx_info(v, p) \
9602 +       __claim_vx_info(v, p, __FILE__, __LINE__, __HERE__)
9603 +
9604 +static inline void __claim_vx_info(struct vx_info *vxi,
9605 +       struct task_struct *task,
9606 +       const char *_file, int _line, void *_here)
9607 +{
9608 +       vxlprintk(VXD_CBIT(xid, 3), "claim_vx_info(%p[#%d.%d.%d]) %p",
9609 +               vxi, vxi ? vxi->vx_id : 0,
9610 +               vxi ? atomic_read(&vxi->vx_usecnt) : 0,
9611 +               vxi ? atomic_read(&vxi->vx_tasks) : 0,
9612 +               task, _file, _line);
9613 +       __vxh_claim_vx_info(vxi, task, _here);
9614 +
9615 +       atomic_inc(&vxi->vx_tasks);
9616 +}
9617 +
9618 +
9619 +extern void unhash_vx_info(struct vx_info *);
9620 +
9621 +#define release_vx_info(v, p) \
9622 +       __release_vx_info(v, p, __FILE__, __LINE__, __HERE__)
9623 +
9624 +static inline void __release_vx_info(struct vx_info *vxi,
9625 +       struct task_struct *task,
9626 +       const char *_file, int _line, void *_here)
9627 +{
9628 +       vxlprintk(VXD_CBIT(xid, 3), "release_vx_info(%p[#%d.%d.%d]) %p",
9629 +               vxi, vxi ? vxi->vx_id : 0,
9630 +               vxi ? atomic_read(&vxi->vx_usecnt) : 0,
9631 +               vxi ? atomic_read(&vxi->vx_tasks) : 0,
9632 +               task, _file, _line);
9633 +       __vxh_release_vx_info(vxi, task, _here);
9634 +
9635 +       might_sleep();
9636 +
9637 +       if (atomic_dec_and_test(&vxi->vx_tasks))
9638 +               unhash_vx_info(vxi);
9639 +}
9640 +
9641 +
9642 +#define task_get_vx_info(p) \
9643 +       __task_get_vx_info(p, __FILE__, __LINE__, __HERE__)
9644 +
9645 +static inline struct vx_info *__task_get_vx_info(struct task_struct *p,
9646 +       const char *_file, int _line, void *_here)
9647 +{
9648 +       struct vx_info *vxi;
9649 +
9650 +       task_lock(p);
9651 +       vxlprintk(VXD_CBIT(xid, 5), "task_get_vx_info(%p)",
9652 +               p, _file, _line);
9653 +       vxi = __get_vx_info(p->vx_info, _file, _line, _here);
9654 +       task_unlock(p);
9655 +       return vxi;
9656 +}
9657 +
9658 +
9659 +static inline void __wakeup_vx_info(struct vx_info *vxi)
9660 +{
9661 +       if (waitqueue_active(&vxi->vx_wait))
9662 +               wake_up_interruptible(&vxi->vx_wait);
9663 +}
9664 +
9665 +
9666 +#define enter_vx_info(v, s) __enter_vx_info(v, s, __FILE__, __LINE__)
9667 +
9668 +static inline void __enter_vx_info(struct vx_info *vxi,
9669 +       struct vx_info_save *vxis, const char *_file, int _line)
9670 +{
9671 +       vxlprintk(VXD_CBIT(xid, 5), "enter_vx_info(%p[#%d],%p) %p[#%d,%p]",
9672 +               vxi, vxi ? vxi->vx_id : 0, vxis, current,
9673 +               current->xid, current->vx_info, _file, _line);
9674 +       vxis->vxi = xchg(&current->vx_info, vxi);
9675 +       vxis->xid = current->xid;
9676 +       current->xid = vxi ? vxi->vx_id : 0;
9677 +}
9678 +
9679 +#define leave_vx_info(s) __leave_vx_info(s, __FILE__, __LINE__)
9680 +
9681 +static inline void __leave_vx_info(struct vx_info_save *vxis,
9682 +       const char *_file, int _line)
9683 +{
9684 +       vxlprintk(VXD_CBIT(xid, 5), "leave_vx_info(%p[#%d,%p]) %p[#%d,%p]",
9685 +               vxis, vxis->xid, vxis->vxi, current,
9686 +               current->xid, current->vx_info, _file, _line);
9687 +       (void)xchg(&current->vx_info, vxis->vxi);
9688 +       current->xid = vxis->xid;
9689 +}
9690 +
9691 +
9692 +static inline void __enter_vx_admin(struct vx_info_save *vxis)
9693 +{
9694 +       vxis->vxi = xchg(&current->vx_info, NULL);
9695 +       vxis->xid = xchg(&current->xid, (xid_t)0);
9696 +}
9697 +
9698 +static inline void __leave_vx_admin(struct vx_info_save *vxis)
9699 +{
9700 +       (void)xchg(&current->xid, vxis->xid);
9701 +       (void)xchg(&current->vx_info, vxis->vxi);
9702 +}
9703 +
9704 +extern void exit_vx_info(struct task_struct *, int);
9705 +extern void exit_vx_info_early(struct task_struct *, int);
9706 +
9707 +
9708 +#else
9709 +#warning duplicate inclusion
9710 +#endif
9711 diff -NurpP --minimal linux-2.6.29/include/linux/vs_cowbl.h linux-2.6.29-vs2.3.0.36.9-pre3/include/linux/vs_cowbl.h
9712 --- linux-2.6.29/include/linux/vs_cowbl.h       1970-01-01 01:00:00.000000000 +0100
9713 +++ linux-2.6.29-vs2.3.0.36.9-pre3/include/linux/vs_cowbl.h     2009-02-22 22:54:26.000000000 +0100
9714 @@ -0,0 +1,47 @@
9715 +#ifndef _VS_COWBL_H
9716 +#define _VS_COWBL_H
9717 +
9718 +#include <linux/fs.h>
9719 +#include <linux/dcache.h>
9720 +#include <linux/namei.h>
9721 +
9722 +extern struct dentry *cow_break_link(const char *pathname);
9723 +
9724 +static inline int cow_check_and_break(struct path *path)
9725 +{
9726 +       struct inode *inode = path->dentry->d_inode;
9727 +       int error = 0;
9728 +
9729 +       /* do we need this check? */
9730 +       if (IS_RDONLY(inode))
9731 +               return -EROFS;
9732 +
9733 +       if (IS_COW(inode)) {
9734 +               if (IS_COW_LINK(inode)) {
9735 +                       struct dentry *new_dentry, *old_dentry = path->dentry;
9736 +                       char *pp, *buf;
9737 +
9738 +                       buf = kmalloc(PATH_MAX, GFP_KERNEL);
9739 +                       if (!buf) {
9740 +                               return -ENOMEM;
9741 +                       }
9742 +                       pp = d_path(path, buf, PATH_MAX);
9743 +                       new_dentry = cow_break_link(pp);
9744 +                       kfree(buf);
9745 +                       if (!IS_ERR(new_dentry)) {
9746 +                               path->dentry = new_dentry;
9747 +                               dput(old_dentry);
9748 +                       } else
9749 +                               error = PTR_ERR(new_dentry);
9750 +               } else {
9751 +                       inode->i_flags &= ~(S_IXUNLINK | S_IMMUTABLE);
9752 +                       inode->i_ctime = CURRENT_TIME;
9753 +                       mark_inode_dirty(inode);
9754 +               }
9755 +       }
9756 +       return error;
9757 +}
9758 +
9759 +#else
9760 +#warning duplicate inclusion
9761 +#endif
9762 diff -NurpP --minimal linux-2.6.29/include/linux/vs_cvirt.h linux-2.6.29-vs2.3.0.36.9-pre3/include/linux/vs_cvirt.h
9763 --- linux-2.6.29/include/linux/vs_cvirt.h       1970-01-01 01:00:00.000000000 +0100
9764 +++ linux-2.6.29-vs2.3.0.36.9-pre3/include/linux/vs_cvirt.h     2009-02-22 22:54:26.000000000 +0100
9765 @@ -0,0 +1,50 @@
9766 +#ifndef _VS_CVIRT_H
9767 +#define _VS_CVIRT_H
9768 +
9769 +#include "vserver/cvirt.h"
9770 +#include "vserver/context.h"
9771 +#include "vserver/base.h"
9772 +#include "vserver/check.h"
9773 +#include "vserver/debug.h"
9774 +
9775 +
9776 +static inline void vx_activate_task(struct task_struct *p)
9777 +{
9778 +       struct vx_info *vxi;
9779 +
9780 +       if ((vxi = p->vx_info)) {
9781 +               vx_update_load(vxi);
9782 +               atomic_inc(&vxi->cvirt.nr_running);
9783 +       }
9784 +}
9785 +
9786 +static inline void vx_deactivate_task(struct task_struct *p)
9787 +{
9788 +       struct vx_info *vxi;
9789 +
9790 +       if ((vxi = p->vx_info)) {
9791 +               vx_update_load(vxi);
9792 +               atomic_dec(&vxi->cvirt.nr_running);
9793 +       }
9794 +}
9795 +
9796 +static inline void vx_uninterruptible_inc(struct task_struct *p)
9797 +{
9798 +       struct vx_info *vxi;
9799 +
9800 +       if ((vxi = p->vx_info))
9801 +               atomic_inc(&vxi->cvirt.nr_uninterruptible);
9802 +}
9803 +
9804 +static inline void vx_uninterruptible_dec(struct task_struct *p)
9805 +{
9806 +       struct vx_info *vxi;
9807 +
9808 +       if ((vxi = p->vx_info))
9809 +               atomic_dec(&vxi->cvirt.nr_uninterruptible);
9810 +}
9811 +
9812 +
9813 +#else
9814 +#warning duplicate inclusion
9815 +#endif
9816 diff -NurpP --minimal linux-2.6.29/include/linux/vs_device.h linux-2.6.29-vs2.3.0.36.9-pre3/include/linux/vs_device.h
9817 --- linux-2.6.29/include/linux/vs_device.h      1970-01-01 01:00:00.000000000 +0100
9818 +++ linux-2.6.29-vs2.3.0.36.9-pre3/include/linux/vs_device.h    2009-02-22 22:54:26.000000000 +0100
9819 @@ -0,0 +1,45 @@
9820 +#ifndef _VS_DEVICE_H
9821 +#define _VS_DEVICE_H
9822 +
9823 +#include "vserver/base.h"
9824 +#include "vserver/device.h"
9825 +#include "vserver/debug.h"
9826 +
9827 +
9828 +#ifdef CONFIG_VSERVER_DEVICE
9829 +
9830 +int vs_map_device(struct vx_info *, dev_t, dev_t *, umode_t);
9831 +
9832 +#define vs_device_perm(v, d, m, p) \
9833 +       ((vs_map_device(current_vx_info(), d, NULL, m) & (p)) == (p))
9834 +
9835 +#else
9836 +
9837 +static inline
9838 +int vs_map_device(struct vx_info *vxi,
9839 +       dev_t device, dev_t *target, umode_t mode)
9840 +{
9841 +       if (target)
9842 +               *target = device;
9843 +       return ~0;
9844 +}
9845 +
9846 +#define vs_device_perm(v, d, m, p) ((p) == (p))
9847 +
9848 +#endif
9849 +
9850 +
9851 +#define vs_map_chrdev(d, t, p) \
9852 +       ((vs_map_device(current_vx_info(), d, t, S_IFCHR) & (p)) == (p))
9853 +#define vs_map_blkdev(d, t, p) \
9854 +       ((vs_map_device(current_vx_info(), d, t, S_IFBLK) & (p)) == (p))
9855 +
9856 +#define vs_chrdev_perm(d, p) \
9857 +       vs_device_perm(current_vx_info(), d, S_IFCHR, p)
9858 +#define vs_blkdev_perm(d, p) \
9859 +       vs_device_perm(current_vx_info(), d, S_IFBLK, p)
9860 +
9861 +
9862 +#else
9863 +#warning duplicate inclusion
9864 +#endif
9865 diff -NurpP --minimal linux-2.6.29/include/linux/vs_dlimit.h linux-2.6.29-vs2.3.0.36.9-pre3/include/linux/vs_dlimit.h
9866 --- linux-2.6.29/include/linux/vs_dlimit.h      1970-01-01 01:00:00.000000000 +0100
9867 +++ linux-2.6.29-vs2.3.0.36.9-pre3/include/linux/vs_dlimit.h    2009-02-22 22:54:26.000000000 +0100
9868 @@ -0,0 +1,211 @@
9869 +#ifndef _VS_DLIMIT_H
9870 +#define _VS_DLIMIT_H
9871 +
9872 +#include <linux/fs.h>
9873 +
9874 +#include "vserver/dlimit.h"
9875 +#include "vserver/base.h"
9876 +#include "vserver/debug.h"
9877 +
9878 +
9879 +#define get_dl_info(i) __get_dl_info(i, __FILE__, __LINE__)
9880 +
9881 +static inline struct dl_info *__get_dl_info(struct dl_info *dli,
9882 +       const char *_file, int _line)
9883 +{
9884 +       if (!dli)
9885 +               return NULL;
9886 +       vxlprintk(VXD_CBIT(dlim, 4), "get_dl_info(%p[#%d.%d])",
9887 +               dli, dli ? dli->dl_tag : 0,
9888 +               dli ? atomic_read(&dli->dl_usecnt) : 0,
9889 +               _file, _line);
9890 +       atomic_inc(&dli->dl_usecnt);
9891 +       return dli;
9892 +}
9893 +
9894 +
9895 +#define free_dl_info(i) \
9896 +       call_rcu(&(i)->dl_rcu, rcu_free_dl_info)
9897 +
9898 +#define put_dl_info(i) __put_dl_info(i, __FILE__, __LINE__)
9899 +
9900 +static inline void __put_dl_info(struct dl_info *dli,
9901 +       const char *_file, int _line)
9902 +{
9903 +       if (!dli)
9904 +               return;
9905 +       vxlprintk(VXD_CBIT(dlim, 4), "put_dl_info(%p[#%d.%d])",
9906 +               dli, dli ? dli->dl_tag : 0,
9907 +               dli ? atomic_read(&dli->dl_usecnt) : 0,
9908 +               _file, _line);
9909 +       if (atomic_dec_and_test(&dli->dl_usecnt))
9910 +               free_dl_info(dli);
9911 +}
9912 +
9913 +
9914 +#define __dlimit_char(d)       ((d) ? '*' : ' ')
9915 +
9916 +static inline int __dl_alloc_space(struct super_block *sb,
9917 +       tag_t tag, dlsize_t nr, const char *file, int line)
9918 +{
9919 +       struct dl_info *dli = NULL;
9920 +       int ret = 0;
9921 +
9922 +       if (nr == 0)
9923 +               goto out;
9924 +       dli = locate_dl_info(sb, tag);
9925 +       if (!dli)
9926 +               goto out;
9927 +
9928 +       spin_lock(&dli->dl_lock);
9929 +       ret = (dli->dl_space_used + nr > dli->dl_space_total);
9930 +       if (!ret)
9931 +               dli->dl_space_used += nr;
9932 +       spin_unlock(&dli->dl_lock);
9933 +       put_dl_info(dli);
9934 +out:
9935 +       vxlprintk(VXD_CBIT(dlim, 1),
9936 +               "ALLOC (%p,#%d)%c %lld bytes (%d)",
9937 +               sb, tag, __dlimit_char(dli), (long long)nr,
9938 +               ret, file, line);
9939 +       return ret;
9940 +}
9941 +
9942 +static inline void __dl_free_space(struct super_block *sb,
9943 +       tag_t tag, dlsize_t nr, const char *_file, int _line)
9944 +{
9945 +       struct dl_info *dli = NULL;
9946 +
9947 +       if (nr == 0)
9948 +               goto out;
9949 +       dli = locate_dl_info(sb, tag);
9950 +       if (!dli)
9951 +               goto out;
9952 +
9953 +       spin_lock(&dli->dl_lock);
9954 +       if (dli->dl_space_used > nr)
9955 +               dli->dl_space_used -= nr;
9956 +       else
9957 +               dli->dl_space_used = 0;
9958 +       spin_unlock(&dli->dl_lock);
9959 +       put_dl_info(dli);
9960 +out:
9961 +       vxlprintk(VXD_CBIT(dlim, 1),
9962 +               "FREE  (%p,#%d)%c %lld bytes",
9963 +               sb, tag, __dlimit_char(dli), (long long)nr,
9964 +               _file, _line);
9965 +}
9966 +
9967 +static inline int __dl_alloc_inode(struct super_block *sb,
9968 +       tag_t tag, const char *_file, int _line)
9969 +{
9970 +       struct dl_info *dli;
9971 +       int ret = 0;
9972 +
9973 +       dli = locate_dl_info(sb, tag);
9974 +       if (!dli)
9975 +               goto out;
9976 +
9977 +       spin_lock(&dli->dl_lock);
9978 +       ret = (dli->dl_inodes_used >= dli->dl_inodes_total);
9979 +       if (!ret)
9980 +               dli->dl_inodes_used++;
9981 +       spin_unlock(&dli->dl_lock);
9982 +       put_dl_info(dli);
9983 +out:
9984 +       vxlprintk(VXD_CBIT(dlim, 0),
9985 +               "ALLOC (%p,#%d)%c inode (%d)",
9986 +               sb, tag, __dlimit_char(dli), ret, _file, _line);
9987 +       return ret;
9988 +}
9989 +
9990 +static inline void __dl_free_inode(struct super_block *sb,
9991 +       tag_t tag, const char *_file, int _line)
9992 +{
9993 +       struct dl_info *dli;
9994 +
9995 +       dli = locate_dl_info(sb, tag);
9996 +       if (!dli)
9997 +               goto out;
9998 +
9999 +       spin_lock(&dli->dl_lock);
10000 +       if (dli->dl_inodes_used > 1)
10001 +               dli->dl_inodes_used--;
10002 +       else
10003 +               dli->dl_inodes_used = 0;
10004 +       spin_unlock(&dli->dl_lock);
10005 +       put_dl_info(dli);
10006 +out:
10007 +       vxlprintk(VXD_CBIT(dlim, 0),
10008 +               "FREE  (%p,#%d)%c inode",
10009 +               sb, tag, __dlimit_char(dli), _file, _line);
10010 +}
10011 +
10012 +static inline void __dl_adjust_block(struct super_block *sb, tag_t tag,
10013 +       unsigned long long *free_blocks, unsigned long long *root_blocks,
10014 +       const char *_file, int _line)
10015 +{
10016 +       struct dl_info *dli;
10017 +       uint64_t broot, bfree;
10018 +
10019 +       dli = locate_dl_info(sb, tag);
10020 +       if (!dli)
10021 +               return;
10022 +
10023 +       spin_lock(&dli->dl_lock);
10024 +       broot = (dli->dl_space_total -
10025 +               (dli->dl_space_total >> 10) * dli->dl_nrlmult)
10026 +               >> sb->s_blocksize_bits;
10027 +       bfree = (dli->dl_space_total - dli->dl_space_used)
10028 +                       >> sb->s_blocksize_bits;
10029 +       spin_unlock(&dli->dl_lock);
10030 +
10031 +       vxlprintk(VXD_CBIT(dlim, 2),
10032 +               "ADJUST: %lld,%lld on %lld,%lld [mult=%d]",
10033 +               (long long)bfree, (long long)broot,
10034 +               *free_blocks, *root_blocks, dli->dl_nrlmult,
10035 +               _file, _line);
10036 +       if (free_blocks) {
10037 +               if (*free_blocks > bfree)
10038 +                       *free_blocks = bfree;
10039 +       }
10040 +       if (root_blocks) {
10041 +               if (*root_blocks > broot)
10042 +                       *root_blocks = broot;
10043 +       }
10044 +       put_dl_info(dli);
10045 +}
10046 +
10047 +#define DLIMIT_ALLOC_SPACE(in, bytes) \
10048 +       __dl_alloc_space((in)->i_sb, (in)->i_tag, (dlsize_t)(bytes), \
10049 +               __FILE__, __LINE__ )
10050 +
10051 +#define DLIMIT_FREE_SPACE(in, bytes) \
10052 +       __dl_free_space((in)->i_sb, (in)->i_tag, (dlsize_t)(bytes), \
10053 +               __FILE__, __LINE__ )
10054 +
10055 +#define DLIMIT_ALLOC_BLOCK(in, nr) \
10056 +       __dl_alloc_space((in)->i_sb, (in)->i_tag, \
10057 +               ((dlsize_t)(nr)) << (in)->i_sb->s_blocksize_bits, \
10058 +               __FILE__, __LINE__ )
10059 +
10060 +#define DLIMIT_FREE_BLOCK(in, nr) \
10061 +       __dl_free_space((in)->i_sb, (in)->i_tag, \
10062 +               ((dlsize_t)(nr)) << (in)->i_sb->s_blocksize_bits, \
10063 +               __FILE__, __LINE__ )
10064 +
10065 +
10066 +#define DLIMIT_ALLOC_INODE(in) \
10067 +       __dl_alloc_inode((in)->i_sb, (in)->i_tag, __FILE__, __LINE__ )
10068 +
10069 +#define DLIMIT_FREE_INODE(in) \
10070 +       __dl_free_inode((in)->i_sb, (in)->i_tag, __FILE__, __LINE__ )
10071 +
10072 +
10073 +#define DLIMIT_ADJUST_BLOCK(sb, tag, fb, rb) \
10074 +       __dl_adjust_block(sb, tag, fb, rb, __FILE__, __LINE__ )
10075 +
10076 +
10077 +#else
10078 +#warning duplicate inclusion
10079 +#endif
10080 diff -NurpP --minimal linux-2.6.29/include/linux/vserver/base.h linux-2.6.29-vs2.3.0.36.9-pre3/include/linux/vserver/base.h
10081 --- linux-2.6.29/include/linux/vserver/base.h   1970-01-01 01:00:00.000000000 +0100
10082 +++ linux-2.6.29-vs2.3.0.36.9-pre3/include/linux/vserver/base.h 2009-03-25 00:36:15.000000000 +0100
10083 @@ -0,0 +1,157 @@
10084 +#ifndef _VX_BASE_H
10085 +#define _VX_BASE_H
10086 +
10087 +
10088 +/* context state changes */
10089 +
10090 +enum {
10091 +       VSC_STARTUP = 1,
10092 +       VSC_SHUTDOWN,
10093 +
10094 +       VSC_NETUP,
10095 +       VSC_NETDOWN,
10096 +};
10097 +
10098 +
10099 +
10100 +#define vx_task_xid(t) ((t)->xid)
10101 +
10102 +#define vx_current_xid() vx_task_xid(current)
10103 +
10104 +#define current_vx_info() (current->vx_info)
10105 +
10106 +
10107 +#define nx_task_nid(t) ((t)->nid)
10108 +
10109 +#define nx_current_nid() nx_task_nid(current)
10110 +
10111 +#define current_nx_info() (current->nx_info)
10112 +
10113 +
10114 +/* generic flag merging */
10115 +
10116 +#define vs_check_flags(v, m, f)        (((v) & (m)) ^ (f))
10117 +
10118 +#define vs_mask_flags(v, f, m) (((v) & ~(m)) | ((f) & (m)))
10119 +
10120 +#define vs_mask_mask(v, f, m)  (((v) & ~(m)) | ((v) & (f) & (m)))
10121 +
10122 +#define vs_check_bit(v, n)     ((v) & (1LL << (n)))
10123 +
10124 +
10125 +/* context flags */
10126 +
10127 +#define __vx_flags(v)  ((v) ? (v)->vx_flags : 0)
10128 +
10129 +#define vx_current_flags()     __vx_flags(current->vx_info)
10130 +
10131 +#define vx_info_flags(v, m, f) \
10132 +       vs_check_flags(__vx_flags(v), m, f)
10133 +
10134 +#define task_vx_flags(t, m, f) \
10135 +       ((t) && vx_info_flags((t)->vx_info, m, f))
10136 +
10137 +#define vx_flags(m, f) vx_info_flags(current->vx_info, m, f)
10138 +
10139 +
10140 +/* context caps */
10141 +
10142 +#define __vx_ccaps(v)  ((v) ? (v)->vx_ccaps : 0)
10143 +
10144 +#define vx_current_ccaps()     __vx_ccaps(current->vx_info)
10145 +
10146 +#define vx_info_ccaps(v, c)    (__vx_ccaps(v) & (c))
10147 +
10148 +#define vx_ccaps(c)    vx_info_ccaps(current->vx_info, (c))
10149 +
10150 +
10151 +
10152 +/* network flags */
10153 +
10154 +#define __nx_flags(n)  ((n) ? (n)->nx_flags : 0)
10155 +
10156 +#define nx_current_flags()     __nx_flags(current->nx_info)
10157 +
10158 +#define nx_info_flags(n, m, f) \
10159 +       vs_check_flags(__nx_flags(n), m, f)
10160 +
10161 +#define task_nx_flags(t, m, f) \
10162 +       ((t) && nx_info_flags((t)->nx_info, m, f))
10163 +
10164 +#define nx_flags(m, f) nx_info_flags(current->nx_info, m, f)
10165 +
10166 +
10167 +/* network caps */
10168 +
10169 +#define __nx_ncaps(n)  ((n) ? (n)->nx_ncaps : 0)
10170 +
10171 +#define nx_current_ncaps()     __nx_ncaps(current->nx_info)
10172 +
10173 +#define nx_info_ncaps(n, c)    (__nx_ncaps(n) & (c))
10174 +
10175 +#define nx_ncaps(c)    nx_info_ncaps(current->nx_info, c)
10176 +
10177 +
10178 +/* context mask capabilities */
10179 +
10180 +#define __vx_mcaps(v)  ((v) ? (v)->vx_ccaps >> 32UL : ~0 )
10181 +
10182 +#define vx_info_mcaps(v, c)    (__vx_mcaps(v) & (c))
10183 +
10184 +#define vx_mcaps(c)    vx_info_mcaps(current->vx_info, c)
10185 +
10186 +
10187 +/* context bcap mask */
10188 +
10189 +#define __vx_bcaps(v)          ((v)->vx_bcaps)
10190 +
10191 +#define vx_current_bcaps()     __vx_bcaps(current->vx_info)
10192 +
10193 +
10194 +/* mask given bcaps */
10195 +
10196 +#define vx_info_mbcaps(v, c)   ((v) ? cap_intersect(__vx_bcaps(v), c) : c)
10197 +
10198 +#define vx_mbcaps(c)           vx_info_mbcaps(current->vx_info, c)
10199 +
10200 +
10201 +/* masked cap_bset */
10202 +
10203 +#define vx_info_cap_bset(v)    vx_info_mbcaps(v, current->cap_bset)
10204 +
10205 +#define vx_current_cap_bset()  vx_info_cap_bset(current->vx_info)
10206 +
10207 +#if 0
10208 +#define vx_info_mbcap(v, b) \
10209 +       (!vx_info_flags(v, VXF_STATE_SETUP, 0) ? \
10210 +       vx_info_bcaps(v, b) : (b))
10211 +
10212 +#define task_vx_mbcap(t, b) \
10213 +       vx_info_mbcap((t)->vx_info, (t)->b)
10214 +
10215 +#define vx_mbcap(b)    task_vx_mbcap(current, b)
10216 +#endif
10217 +
10218 +#define vx_cap_raised(v, c, f) cap_raised(vx_info_mbcaps(v, c), f)
10219 +
10220 +#define vx_capable(b, c) (capable(b) || \
10221 +       (cap_raised(current_cap(), b) && vx_ccaps(c)))
10222 +
10223 +#define nx_capable(b, c) (capable(b) || \
10224 +       (cap_raised(current_cap(), b) && nx_ncaps(c)))
10225 +
10226 +#define vx_current_initpid(n) \
10227 +       (current->vx_info && \
10228 +       (current->vx_info->vx_initpid == (n)))
10229 +
10230 +
10231 +#define __vx_state(v)  ((v) ? ((v)->vx_state) : 0)
10232 +
10233 +#define vx_info_state(v, m)    (__vx_state(v) & (m))
10234 +
10235 +
10236 +#define __nx_state(n)  ((n) ? ((n)->nx_state) : 0)
10237 +
10238 +#define nx_info_state(n, m)    (__nx_state(n) & (m))
10239 +
10240 +#endif
10241 diff -NurpP --minimal linux-2.6.29/include/linux/vserver/cacct_cmd.h linux-2.6.29-vs2.3.0.36.9-pre3/include/linux/vserver/cacct_cmd.h
10242 --- linux-2.6.29/include/linux/vserver/cacct_cmd.h      1970-01-01 01:00:00.000000000 +0100
10243 +++ linux-2.6.29-vs2.3.0.36.9-pre3/include/linux/vserver/cacct_cmd.h    2009-02-22 22:54:26.000000000 +0100
10244 @@ -0,0 +1,23 @@
10245 +#ifndef _VX_CACCT_CMD_H
10246 +#define _VX_CACCT_CMD_H
10247 +
10248 +
10249 +/* virtual host info name commands */
10250 +
10251 +#define VCMD_sock_stat         VC_CMD(VSTAT, 5, 0)
10252 +
10253 +struct vcmd_sock_stat_v0 {
10254 +       uint32_t field;
10255 +       uint32_t count[3];
10256 +       uint64_t total[3];
10257 +};
10258 +
10259 +
10260 +#ifdef __KERNEL__
10261 +
10262 +#include <linux/compiler.h>
10263 +
10264 +extern int vc_sock_stat(struct vx_info *, void __user *);
10265 +
10266 +#endif /* __KERNEL__ */
10267 +#endif /* _VX_CACCT_CMD_H */
10268 diff -NurpP --minimal linux-2.6.29/include/linux/vserver/cacct_def.h linux-2.6.29-vs2.3.0.36.9-pre3/include/linux/vserver/cacct_def.h
10269 --- linux-2.6.29/include/linux/vserver/cacct_def.h      1970-01-01 01:00:00.000000000 +0100
10270 +++ linux-2.6.29-vs2.3.0.36.9-pre3/include/linux/vserver/cacct_def.h    2009-02-22 22:54:26.000000000 +0100
10271 @@ -0,0 +1,43 @@
10272 +#ifndef _VX_CACCT_DEF_H
10273 +#define _VX_CACCT_DEF_H
10274 +
10275 +#include <asm/atomic.h>
10276 +#include <linux/vserver/cacct.h>
10277 +
10278 +
10279 +struct _vx_sock_acc {
10280 +       atomic_long_t count;
10281 +       atomic_long_t total;
10282 +};
10283 +
10284 +/* context sub struct */
10285 +
10286 +struct _vx_cacct {
10287 +       struct _vx_sock_acc sock[VXA_SOCK_SIZE][3];
10288 +       atomic_t slab[8];
10289 +       atomic_t page[6][8];
10290 +};
10291 +
10292 +#ifdef CONFIG_VSERVER_DEBUG
10293 +
10294 +static inline void __dump_vx_cacct(struct _vx_cacct *cacct)
10295 +{
10296 +       int i, j;
10297 +
10298 +       printk("\t_vx_cacct:");
10299 +       for (i = 0; i < 6; i++) {
10300 +               struct _vx_sock_acc *ptr = cacct->sock[i];
10301 +
10302 +               printk("\t [%d] =", i);
10303 +               for (j = 0; j < 3; j++) {
10304 +                       printk(" [%d] = %8lu, %8lu", j,
10305 +                               atomic_long_read(&ptr[j].count),
10306 +                               atomic_long_read(&ptr[j].total));
10307 +               }
10308 +               printk("\n");
10309 +       }
10310 +}
10311 +
10312 +#endif
10313 +
10314 +#endif /* _VX_CACCT_DEF_H */
10315 diff -NurpP --minimal linux-2.6.29/include/linux/vserver/cacct.h linux-2.6.29-vs2.3.0.36.9-pre3/include/linux/vserver/cacct.h
10316 --- linux-2.6.29/include/linux/vserver/cacct.h  1970-01-01 01:00:00.000000000 +0100
10317 +++ linux-2.6.29-vs2.3.0.36.9-pre3/include/linux/vserver/cacct.h        2009-02-22 22:54:26.000000000 +0100
10318 @@ -0,0 +1,15 @@
10319 +#ifndef _VX_CACCT_H
10320 +#define _VX_CACCT_H
10321 +
10322 +
10323 +enum sock_acc_field {
10324 +       VXA_SOCK_UNSPEC = 0,
10325 +       VXA_SOCK_UNIX,
10326 +       VXA_SOCK_INET,
10327 +       VXA_SOCK_INET6,
10328 +       VXA_SOCK_PACKET,
10329 +       VXA_SOCK_OTHER,
10330 +       VXA_SOCK_SIZE   /* array size */
10331 +};
10332 +
10333 +#endif /* _VX_CACCT_H */
10334 diff -NurpP --minimal linux-2.6.29/include/linux/vserver/cacct_int.h linux-2.6.29-vs2.3.0.36.9-pre3/include/linux/vserver/cacct_int.h
10335 --- linux-2.6.29/include/linux/vserver/cacct_int.h      1970-01-01 01:00:00.000000000 +0100
10336 +++ linux-2.6.29-vs2.3.0.36.9-pre3/include/linux/vserver/cacct_int.h    2009-02-22 22:54:26.000000000 +0100
10337 @@ -0,0 +1,21 @@
10338 +#ifndef _VX_CACCT_INT_H
10339 +#define _VX_CACCT_INT_H
10340 +
10341 +
10342 +#ifdef __KERNEL__
10343 +
10344 +static inline
10345 +unsigned long vx_sock_count(struct _vx_cacct *cacct, int type, int pos)
10346 +{
10347 +       return atomic_long_read(&cacct->sock[type][pos].count);
10348 +}
10349 +
10350 +
10351 +static inline
10352 +unsigned long vx_sock_total(struct _vx_cacct *cacct, int type, int pos)
10353 +{
10354 +       return atomic_long_read(&cacct->sock[type][pos].total);
10355 +}
10356 +
10357 +#endif /* __KERNEL__ */
10358 +#endif /* _VX_CACCT_INT_H */
10359 diff -NurpP --minimal linux-2.6.29/include/linux/vserver/check.h linux-2.6.29-vs2.3.0.36.9-pre3/include/linux/vserver/check.h
10360 --- linux-2.6.29/include/linux/vserver/check.h  1970-01-01 01:00:00.000000000 +0100
10361 +++ linux-2.6.29-vs2.3.0.36.9-pre3/include/linux/vserver/check.h        2009-02-22 22:54:26.000000000 +0100
10362 @@ -0,0 +1,89 @@
10363 +#ifndef _VS_CHECK_H
10364 +#define _VS_CHECK_H
10365 +
10366 +
10367 +#define MAX_S_CONTEXT  65535   /* Arbitrary limit */
10368 +
10369 +#ifdef CONFIG_VSERVER_DYNAMIC_IDS
10370 +#define MIN_D_CONTEXT  49152   /* dynamic contexts start here */
10371 +#else
10372 +#define MIN_D_CONTEXT  65536
10373 +#endif
10374 +
10375 +/* check conditions */
10376 +
10377 +#define VS_ADMIN       0x0001
10378 +#define VS_WATCH       0x0002
10379 +#define VS_HIDE                0x0004
10380 +#define VS_HOSTID      0x0008
10381 +
10382 +#define VS_IDENT       0x0010
10383 +#define VS_EQUIV       0x0020
10384 +#define VS_PARENT      0x0040
10385 +#define VS_CHILD       0x0080
10386 +
10387 +#define VS_ARG_MASK    0x00F0
10388 +
10389 +#define VS_DYNAMIC     0x0100
10390 +#define VS_STATIC      0x0200
10391 +
10392 +#define VS_ATR_MASK    0x0F00
10393 +
10394 +#ifdef CONFIG_VSERVER_PRIVACY
10395 +#define VS_ADMIN_P     (0)
10396 +#define VS_WATCH_P     (0)
10397 +#else
10398 +#define VS_ADMIN_P     VS_ADMIN
10399 +#define VS_WATCH_P     VS_WATCH
10400 +#endif
10401 +
10402 +#define VS_HARDIRQ     0x1000
10403 +#define VS_SOFTIRQ     0x2000
10404 +#define VS_IRQ         0x4000
10405 +
10406 +#define VS_IRQ_MASK    0xF000
10407 +
10408 +#include <linux/hardirq.h>
10409 +
10410 +/*
10411 + * check current context for ADMIN/WATCH and
10412 + * optionally against supplied argument
10413 + */
10414 +static inline int __vs_check(int cid, int id, unsigned int mode)
10415 +{
10416 +       if (mode & VS_ARG_MASK) {
10417 +               if ((mode & VS_IDENT) && (id == cid))
10418 +                       return 1;
10419 +       }
10420 +       if (mode & VS_ATR_MASK) {
10421 +               if ((mode & VS_DYNAMIC) &&
10422 +                       (id >= MIN_D_CONTEXT) &&
10423 +                       (id <= MAX_S_CONTEXT))
10424 +                       return 1;
10425 +               if ((mode & VS_STATIC) &&
10426 +                       (id > 1) && (id < MIN_D_CONTEXT))
10427 +                       return 1;
10428 +       }
10429 +       if (mode & VS_IRQ_MASK) {
10430 +               if ((mode & VS_IRQ) && unlikely(in_interrupt()))
10431 +                       return 1;
10432 +               if ((mode & VS_HARDIRQ) && unlikely(in_irq()))
10433 +                       return 1;
10434 +               if ((mode & VS_SOFTIRQ) && unlikely(in_softirq()))
10435 +                       return 1;
10436 +       }
10437 +       return (((mode & VS_ADMIN) && (cid == 0)) ||
10438 +               ((mode & VS_WATCH) && (cid == 1)) ||
10439 +               ((mode & VS_HOSTID) && (id == 0)));
10440 +}
10441 +
10442 +#define vx_check(c, m) __vs_check(vx_current_xid(), c, (m) | VS_IRQ)
10443 +
10444 +#define vx_weak_check(c, m)    ((m) ? vx_check(c, m) : 1)
10445 +
10446 +
10447 +#define nx_check(c, m) __vs_check(nx_current_nid(), c, m)
10448 +
10449 +#define nx_weak_check(c, m)    ((m) ? nx_check(c, m) : 1)
10450 +
10451 +#endif
10452 diff -NurpP --minimal linux-2.6.29/include/linux/vserver/context_cmd.h linux-2.6.29-vs2.3.0.36.9-pre3/include/linux/vserver/context_cmd.h
10453 --- linux-2.6.29/include/linux/vserver/context_cmd.h    1970-01-01 01:00:00.000000000 +0100
10454 +++ linux-2.6.29-vs2.3.0.36.9-pre3/include/linux/vserver/context_cmd.h  2009-02-22 22:54:26.000000000 +0100
10455 @@ -0,0 +1,128 @@
10456 +#ifndef _VX_CONTEXT_CMD_H
10457 +#define _VX_CONTEXT_CMD_H
10458 +
10459 +
10460 +/* vinfo commands */
10461 +
10462 +#define VCMD_task_xid          VC_CMD(VINFO, 1, 0)
10463 +
10464 +#ifdef __KERNEL__
10465 +extern int vc_task_xid(uint32_t);
10466 +
10467 +#endif /* __KERNEL__ */
10468 +
10469 +#define VCMD_vx_info           VC_CMD(VINFO, 5, 0)
10470 +
10471 +struct vcmd_vx_info_v0 {
10472 +       uint32_t xid;
10473 +       uint32_t initpid;
10474 +       /* more to come */
10475 +};
10476 +
10477 +#ifdef __KERNEL__
10478 +extern int vc_vx_info(struct vx_info *, void __user *);
10479 +
10480 +#endif /* __KERNEL__ */
10481 +
10482 +#define VCMD_ctx_stat          VC_CMD(VSTAT, 0, 0)
10483 +
10484 +struct vcmd_ctx_stat_v0 {
10485 +       uint32_t usecnt;
10486 +       uint32_t tasks;
10487 +       /* more to come */
10488 +};
10489 +
10490 +#ifdef __KERNEL__
10491 +extern int vc_ctx_stat(struct vx_info *, void __user *);
10492 +
10493 +#endif /* __KERNEL__ */
10494 +
10495 +/* context commands */
10496 +
10497 +#define VCMD_ctx_create_v0     VC_CMD(VPROC, 1, 0)
10498 +#define VCMD_ctx_create                VC_CMD(VPROC, 1, 1)
10499 +
10500 +struct vcmd_ctx_create {
10501 +       uint64_t flagword;
10502 +};
10503 +
10504 +#define VCMD_ctx_migrate_v0    VC_CMD(PROCMIG, 1, 0)
10505 +#define VCMD_ctx_migrate       VC_CMD(PROCMIG, 1, 1)
10506 +
10507 +struct vcmd_ctx_migrate {
10508 +       uint64_t flagword;
10509 +};
10510 +
10511 +#ifdef __KERNEL__
10512 +extern int vc_ctx_create(uint32_t, void __user *);
10513 +extern int vc_ctx_migrate(struct vx_info *, void __user *);
10514 +
10515 +#endif /* __KERNEL__ */
10516 +
10517 +
10518 +/* flag commands */
10519 +
10520 +#define VCMD_get_cflags                VC_CMD(FLAGS, 1, 0)
10521 +#define VCMD_set_cflags                VC_CMD(FLAGS, 2, 0)
10522 +
10523 +struct vcmd_ctx_flags_v0 {
10524 +       uint64_t flagword;
10525 +       uint64_t mask;
10526 +};
10527 +
10528 +#ifdef __KERNEL__
10529 +extern int vc_get_cflags(struct vx_info *, void __user *);
10530 +extern int vc_set_cflags(struct vx_info *, void __user *);
10531 +
10532 +#endif /* __KERNEL__ */
10533 +
10534 +
10535 +/* context caps commands */
10536 +
10537 +#define VCMD_get_ccaps         VC_CMD(FLAGS, 3, 1)
10538 +#define VCMD_set_ccaps         VC_CMD(FLAGS, 4, 1)
10539 +
10540 +struct vcmd_ctx_caps_v1 {
10541 +       uint64_t ccaps;
10542 +       uint64_t cmask;
10543 +};
10544 +
10545 +#ifdef __KERNEL__
10546 +extern int vc_get_ccaps(struct vx_info *, void __user *);
10547 +extern int vc_set_ccaps(struct vx_info *, void __user *);
10548 +
10549 +#endif /* __KERNEL__ */
10550 +
10551 +
10552 +/* bcaps commands */
10553 +
10554 +#define VCMD_get_bcaps         VC_CMD(FLAGS, 9, 0)
10555 +#define VCMD_set_bcaps         VC_CMD(FLAGS, 10, 0)
10556 +
10557 +struct vcmd_bcaps {
10558 +       uint64_t bcaps;
10559 +       uint64_t bmask;
10560 +};
10561 +
10562 +#ifdef __KERNEL__
10563 +extern int vc_get_bcaps(struct vx_info *, void __user *);
10564 +extern int vc_set_bcaps(struct vx_info *, void __user *);
10565 +
10566 +#endif /* __KERNEL__ */
10567 +
10568 +
10569 +/* OOM badness */
10570 +
10571 +#define VCMD_get_badness       VC_CMD(MEMCTRL, 5, 0)
10572 +#define VCMD_set_badness       VC_CMD(MEMCTRL, 6, 0)
10573 +
10574 +struct vcmd_badness_v0 {
10575 +       int64_t bias;
10576 +};
10577 +
10578 +#ifdef __KERNEL__
10579 +extern int vc_get_badness(struct vx_info *, void __user *);
10580 +extern int vc_set_badness(struct vx_info *, void __user *);
10581 +
10582 +#endif /* __KERNEL__ */
10583 +#endif /* _VX_CONTEXT_CMD_H */
10584 diff -NurpP --minimal linux-2.6.29/include/linux/vserver/context.h linux-2.6.29-vs2.3.0.36.9-pre3/include/linux/vserver/context.h
10585 --- linux-2.6.29/include/linux/vserver/context.h        1970-01-01 01:00:00.000000000 +0100
10586 +++ linux-2.6.29-vs2.3.0.36.9-pre3/include/linux/vserver/context.h      2009-02-22 22:54:26.000000000 +0100
10587 @@ -0,0 +1,179 @@
10588 +#ifndef _VX_CONTEXT_H
10589 +#define _VX_CONTEXT_H
10590 +
10591 +#include <linux/types.h>
10592 +#include <linux/capability.h>
10593 +
10594 +
10595 +/* context flags */
10596 +
10597 +#define VXF_INFO_SCHED         0x00000002
10598 +#define VXF_INFO_NPROC         0x00000004
10599 +#define VXF_INFO_PRIVATE       0x00000008
10600 +
10601 +#define VXF_INFO_INIT          0x00000010
10602 +#define VXF_INFO_HIDE          0x00000020
10603 +#define VXF_INFO_ULIMIT                0x00000040
10604 +#define VXF_INFO_NSPACE                0x00000080
10605 +
10606 +#define VXF_SCHED_HARD         0x00000100
10607 +#define VXF_SCHED_PRIO         0x00000200
10608 +#define VXF_SCHED_PAUSE                0x00000400
10609 +
10610 +#define VXF_VIRT_MEM           0x00010000
10611 +#define VXF_VIRT_UPTIME                0x00020000
10612 +#define VXF_VIRT_CPU           0x00040000
10613 +#define VXF_VIRT_LOAD          0x00080000
10614 +#define VXF_VIRT_TIME          0x00100000
10615 +
10616 +#define VXF_HIDE_MOUNT         0x01000000
10617 +/* was VXF_HIDE_NETIF          0x02000000 */
10618 +#define VXF_HIDE_VINFO         0x04000000
10619 +
10620 +#define VXF_STATE_SETUP                (1ULL << 32)
10621 +#define VXF_STATE_INIT         (1ULL << 33)
10622 +#define VXF_STATE_ADMIN                (1ULL << 34)
10623 +
10624 +#define VXF_SC_HELPER          (1ULL << 36)
10625 +#define VXF_REBOOT_KILL                (1ULL << 37)
10626 +#define VXF_PERSISTENT         (1ULL << 38)
10627 +
10628 +#define VXF_FORK_RSS           (1ULL << 48)
10629 +#define VXF_PROLIFIC           (1ULL << 49)
10630 +
10631 +#define VXF_IGNEG_NICE         (1ULL << 52)
10632 +
10633 +#define VXF_ONE_TIME           (0x0007ULL << 32)
10634 +
10635 +#define VXF_INIT_SET           (VXF_STATE_SETUP | VXF_STATE_INIT | VXF_STATE_ADMIN)
10636 +
10637 +
10638 +/* context migration */
10639 +
10640 +#define VXM_SET_INIT           0x00000001
10641 +#define VXM_SET_REAPER         0x00000002
10642 +
10643 +/* context caps */
10644 +
10645 +#define VXC_CAP_MASK           0x00000000
10646 +
10647 +#define VXC_SET_UTSNAME                0x00000001
10648 +#define VXC_SET_RLIMIT         0x00000002
10649 +#define VXC_FS_SECURITY                0x00000004
10650 +
10651 +/* was VXC_RAW_ICMP            0x00000100 */
10652 +#define VXC_SYSLOG             0x00001000
10653 +
10654 +#define VXC_SECURE_MOUNT       0x00010000
10655 +#define VXC_SECURE_REMOUNT     0x00020000
10656 +#define VXC_BINARY_MOUNT       0x00040000
10657 +
10658 +#define VXC_QUOTA_CTL          0x00100000
10659 +#define VXC_ADMIN_MAPPER       0x00200000
10660 +#define VXC_ADMIN_CLOOP                0x00400000
10661 +
10662 +#define VXC_KTHREAD            0x01000000
10663 +
10664 +
10665 +#ifdef __KERNEL__
10666 +
10667 +#include <linux/list.h>
10668 +#include <linux/spinlock.h>
10669 +#include <linux/rcupdate.h>
10670 +
10671 +#include "limit_def.h"
10672 +#include "sched_def.h"
10673 +#include "cvirt_def.h"
10674 +#include "cacct_def.h"
10675 +#include "device_def.h"
10676 +
10677 +#define VX_SPACES      2
10678 +
10679 +struct _vx_info_pc {
10680 +       struct _vx_sched_pc sched_pc;
10681 +       struct _vx_cvirt_pc cvirt_pc;
10682 +};
10683 +
10684 +struct vx_info {
10685 +       struct hlist_node vx_hlist;             /* linked list of contexts */
10686 +       xid_t vx_id;                            /* context id */
10687 +       atomic_t vx_usecnt;                     /* usage count */
10688 +       atomic_t vx_tasks;                      /* tasks count */
10689 +       struct vx_info *vx_parent;              /* parent context */
10690 +       int vx_state;                           /* context state */
10691 +
10692 +       unsigned long vx_nsmask[VX_SPACES];     /* assignment mask */
10693 +       struct nsproxy *vx_nsproxy[VX_SPACES];  /* private namespaces */
10694 +       struct fs_struct *vx_fs[VX_SPACES];     /* private namespace fs */
10695 +
10696 +       uint64_t vx_flags;                      /* context flags */
10697 +       uint64_t vx_ccaps;                      /* context caps (vserver) */
10698 +       kernel_cap_t vx_bcaps;                  /* bounding caps (system) */
10699 +       // kernel_cap_t vx_cap_bset;            /* the guest's bset */
10700 +
10701 +       struct task_struct *vx_reaper;          /* guest reaper process */
10702 +       pid_t vx_initpid;                       /* PID of guest init */
10703 +       int64_t vx_badness_bias;                /* OOM points bias */
10704 +
10705 +       struct _vx_limit limit;                 /* vserver limits */
10706 +       struct _vx_sched sched;                 /* vserver scheduler */
10707 +       struct _vx_cvirt cvirt;                 /* virtual/bias stuff */
10708 +       struct _vx_cacct cacct;                 /* context accounting */
10709 +
10710 +       struct _vx_device dmap;                 /* default device map targets */
10711 +
10712 +#ifndef CONFIG_SMP
10713 +       struct _vx_info_pc info_pc;             /* per cpu data */
10714 +#else
10715 +       struct _vx_info_pc *ptr_pc;             /* per cpu array */
10716 +#endif
10717 +
10718 +       wait_queue_head_t vx_wait;              /* context exit waitqueue */
10719 +       int reboot_cmd;                         /* last sys_reboot() cmd */
10720 +       int exit_code;                          /* last process exit code */
10721 +
10722 +       char vx_name[65];                       /* vserver name */
10723 +};
10724 +
10725 +#ifndef CONFIG_SMP
10726 +#define        vx_ptr_pc(vxi)          (&(vxi)->info_pc)
10727 +#define        vx_per_cpu(vxi, v, id)  vx_ptr_pc(vxi)->v
10728 +#else
10729 +#define        vx_ptr_pc(vxi)          ((vxi)->ptr_pc)
10730 +#define        vx_per_cpu(vxi, v, id)  per_cpu_ptr(vx_ptr_pc(vxi), id)->v
10731 +#endif
10732 +
10733 +#define        vx_cpu(vxi, v)          vx_per_cpu(vxi, v, smp_processor_id())
10734 +
10735 +
10736 +struct vx_info_save {
10737 +       struct vx_info *vxi;
10738 +       xid_t xid;
10739 +};
10740 +
10741 +
10742 +/* status flags */
10743 +
10744 +#define VXS_HASHED     0x0001
10745 +#define VXS_PAUSED     0x0010
10746 +#define VXS_SHUTDOWN   0x0100
10747 +#define VXS_HELPER     0x1000
10748 +#define VXS_RELEASED   0x8000
10749 +
10750 +
10751 +extern void claim_vx_info(struct vx_info *, struct task_struct *);
10752 +extern void release_vx_info(struct vx_info *, struct task_struct *);
10753 +
10754 +extern struct vx_info *lookup_vx_info(int);
10755 +extern struct vx_info *lookup_or_create_vx_info(int);
10756 +
10757 +extern int get_xid_list(int, unsigned int *, int);
10758 +extern int xid_is_hashed(xid_t);
10759 +
10760 +extern int vx_migrate_task(struct task_struct *, struct vx_info *, int);
10761 +
10762 +extern long vs_state_change(struct vx_info *, unsigned int);
10763 +
10764 +
10765 +#endif /* __KERNEL__ */
10766 +#endif /* _VX_CONTEXT_H */
10767 diff -NurpP --minimal linux-2.6.29/include/linux/vserver/cvirt_cmd.h linux-2.6.29-vs2.3.0.36.9-pre3/include/linux/vserver/cvirt_cmd.h
10768 --- linux-2.6.29/include/linux/vserver/cvirt_cmd.h      1970-01-01 01:00:00.000000000 +0100
10769 +++ linux-2.6.29-vs2.3.0.36.9-pre3/include/linux/vserver/cvirt_cmd.h    2009-02-22 22:54:26.000000000 +0100
10770 @@ -0,0 +1,53 @@
10771 +#ifndef _VX_CVIRT_CMD_H
10772 +#define _VX_CVIRT_CMD_H
10773 +
10774 +
10775 +/* virtual host info name commands */
10776 +
10777 +#define VCMD_set_vhi_name      VC_CMD(VHOST, 1, 0)
10778 +#define VCMD_get_vhi_name      VC_CMD(VHOST, 2, 0)
10779 +
10780 +struct vcmd_vhi_name_v0 {
10781 +       uint32_t field;
10782 +       char name[65];
10783 +};
10784 +
10785 +
10786 +enum vhi_name_field {
10787 +       VHIN_CONTEXT = 0,
10788 +       VHIN_SYSNAME,
10789 +       VHIN_NODENAME,
10790 +       VHIN_RELEASE,
10791 +       VHIN_VERSION,
10792 +       VHIN_MACHINE,
10793 +       VHIN_DOMAINNAME,
10794 +};
10795 +
10796 +
10797 +#ifdef __KERNEL__
10798 +
10799 +#include <linux/compiler.h>
10800 +
10801 +extern int vc_set_vhi_name(struct vx_info *, void __user *);
10802 +extern int vc_get_vhi_name(struct vx_info *, void __user *);
10803 +
10804 +#endif /* __KERNEL__ */
10805 +
10806 +#define VCMD_virt_stat         VC_CMD(VSTAT, 3, 0)
10807 +
10808 +struct vcmd_virt_stat_v0 {
10809 +       uint64_t offset;
10810 +       uint64_t uptime;
10811 +       uint32_t nr_threads;
10812 +       uint32_t nr_running;
10813 +       uint32_t nr_uninterruptible;
10814 +       uint32_t nr_onhold;
10815 +       uint32_t nr_forks;
10816 +       uint32_t load[3];
10817 +};
10818 +
10819 +#ifdef __KERNEL__
10820 +extern int vc_virt_stat(struct vx_info *, void __user *);
10821 +
10822 +#endif /* __KERNEL__ */
10823 +#endif /* _VX_CVIRT_CMD_H */
10824 diff -NurpP --minimal linux-2.6.29/include/linux/vserver/cvirt_def.h linux-2.6.29-vs2.3.0.36.9-pre3/include/linux/vserver/cvirt_def.h
10825 --- linux-2.6.29/include/linux/vserver/cvirt_def.h      1970-01-01 01:00:00.000000000 +0100
10826 +++ linux-2.6.29-vs2.3.0.36.9-pre3/include/linux/vserver/cvirt_def.h    2009-02-22 22:54:26.000000000 +0100
10827 @@ -0,0 +1,80 @@
10828 +#ifndef _VX_CVIRT_DEF_H
10829 +#define _VX_CVIRT_DEF_H
10830 +
10831 +#include <linux/jiffies.h>
10832 +#include <linux/spinlock.h>
10833 +#include <linux/wait.h>
10834 +#include <linux/time.h>
10835 +#include <asm/atomic.h>
10836 +
10837 +
10838 +struct _vx_usage_stat {
10839 +       uint64_t user;
10840 +       uint64_t nice;
10841 +       uint64_t system;
10842 +       uint64_t softirq;
10843 +       uint64_t irq;
10844 +       uint64_t idle;
10845 +       uint64_t iowait;
10846 +};
10847 +
10848 +struct _vx_syslog {
10849 +       wait_queue_head_t log_wait;
10850 +       spinlock_t logbuf_lock;         /* lock for the log buffer */
10851 +
10852 +       unsigned long log_start;        /* next char to be read by syslog() */
10853 +       unsigned long con_start;        /* next char to be sent to consoles */
10854 +       unsigned long log_end;  /* most-recently-written-char + 1 */
10855 +       unsigned long logged_chars;     /* #chars since last read+clear operation */
10856 +
10857 +       char log_buf[1024];
10858 +};
10859 +
10860 +
10861 +/* context sub struct */
10862 +
10863 +struct _vx_cvirt {
10864 +       atomic_t nr_threads;            /* number of current threads */
10865 +       atomic_t nr_running;            /* number of running threads */
10866 +       atomic_t nr_uninterruptible;    /* number of uninterruptible threads */
10867 +
10868 +       atomic_t nr_onhold;             /* processes on hold */
10869 +       uint32_t onhold_last;           /* jiffies when put on hold */
10870 +
10871 +       struct timeval bias_tv;         /* time offset to the host */
10872 +       struct timespec bias_idle;
10873 +       struct timespec bias_uptime;    /* context creation point */
10874 +       uint64_t bias_clock;            /* offset in clock_t */
10875 +
10876 +       spinlock_t load_lock;           /* lock for the load averages */
10877 +       atomic_t load_updates;          /* nr of load updates done so far */
10878 +       uint32_t load_last;             /* last time load was calculated */
10879 +       uint32_t load[3];               /* load averages 1,5,15 */
10880 +
10881 +       atomic_t total_forks;           /* number of forks so far */
10882 +
10883 +       struct _vx_syslog syslog;
10884 +};
10885 +
10886 +struct _vx_cvirt_pc {
10887 +       struct _vx_usage_stat cpustat;
10888 +};
10889 +
10890 +
10891 +#ifdef CONFIG_VSERVER_DEBUG
10892 +
10893 +static inline void __dump_vx_cvirt(struct _vx_cvirt *cvirt)
10894 +{
10895 +       printk("\t_vx_cvirt:\n");
10896 +       printk("\t threads: %4d, %4d, %4d, %4d\n",
10897 +               atomic_read(&cvirt->nr_threads),
10898 +               atomic_read(&cvirt->nr_running),
10899 +               atomic_read(&cvirt->nr_uninterruptible),
10900 +               atomic_read(&cvirt->nr_onhold));
10901 +       /* add rest here */
10902 +       printk("\t total_forks = %d\n", atomic_read(&cvirt->total_forks));
10903 +}
10904 +
10905 +#endif
10906 +
10907 +#endif /* _VX_CVIRT_DEF_H */
10908 diff -NurpP --minimal linux-2.6.29/include/linux/vserver/cvirt.h linux-2.6.29-vs2.3.0.36.9-pre3/include/linux/vserver/cvirt.h
10909 --- linux-2.6.29/include/linux/vserver/cvirt.h  1970-01-01 01:00:00.000000000 +0100
10910 +++ linux-2.6.29-vs2.3.0.36.9-pre3/include/linux/vserver/cvirt.h        2009-02-22 22:54:26.000000000 +0100
10911 @@ -0,0 +1,20 @@
10912 +#ifndef _VX_CVIRT_H
10913 +#define _VX_CVIRT_H
10914 +
10915 +
10916 +#ifdef __KERNEL__
10917 +
10918 +struct timespec;
10919 +
10920 +void vx_vsi_uptime(struct timespec *, struct timespec *);
10921 +
10922 +
10923 +struct vx_info;
10924 +
10925 +void vx_update_load(struct vx_info *);
10926 +
10927 +
10928 +int vx_do_syslog(int, char __user *, int);
10929 +
10930 +#endif /* __KERNEL__ */
10931 +#endif /* _VX_CVIRT_H */
10932 diff -NurpP --minimal linux-2.6.29/include/linux/vserver/debug_cmd.h linux-2.6.29-vs2.3.0.36.9-pre3/include/linux/vserver/debug_cmd.h
10933 --- linux-2.6.29/include/linux/vserver/debug_cmd.h      1970-01-01 01:00:00.000000000 +0100
10934 +++ linux-2.6.29-vs2.3.0.36.9-pre3/include/linux/vserver/debug_cmd.h    2009-02-22 22:54:26.000000000 +0100
10935 @@ -0,0 +1,58 @@
10936 +#ifndef _VX_DEBUG_CMD_H
10937 +#define _VX_DEBUG_CMD_H
10938 +
10939 +
10940 +/* debug commands */
10941 +
10942 +#define VCMD_dump_history      VC_CMD(DEBUG, 1, 0)
10943 +
10944 +#define VCMD_read_history      VC_CMD(DEBUG, 5, 0)
10945 +#define VCMD_read_monitor      VC_CMD(DEBUG, 6, 0)
10946 +
10947 +struct  vcmd_read_history_v0 {
10948 +       uint32_t index;
10949 +       uint32_t count;
10950 +       char __user *data;
10951 +};
10952 +
10953 +struct  vcmd_read_monitor_v0 {
10954 +       uint32_t index;
10955 +       uint32_t count;
10956 +       char __user *data;
10957 +};
10958 +
10959 +
10960 +#ifdef __KERNEL__
10961 +
10962 +#ifdef CONFIG_COMPAT
10963 +
10964 +#include <asm/compat.h>
10965 +
10966 +struct vcmd_read_history_v0_x32 {
10967 +       uint32_t index;
10968 +       uint32_t count;
10969 +       compat_uptr_t data_ptr;
10970 +};
10971 +
10972 +struct vcmd_read_monitor_v0_x32 {
10973 +       uint32_t index;
10974 +       uint32_t count;
10975 +       compat_uptr_t data_ptr;
10976 +};
10977 +
10978 +#endif  /* CONFIG_COMPAT */
10979 +
10980 +extern int vc_dump_history(uint32_t);
10981 +
10982 +extern int vc_read_history(uint32_t, void __user *);
10983 +extern int vc_read_monitor(uint32_t, void __user *);
10984 +
10985 +#ifdef CONFIG_COMPAT
10986 +
10987 +extern int vc_read_history_x32(uint32_t, void __user *);
10988 +extern int vc_read_monitor_x32(uint32_t, void __user *);
10989 +
10990 +#endif  /* CONFIG_COMPAT */
10991 +
10992 +#endif /* __KERNEL__ */
10993 +#endif /* _VX_DEBUG_CMD_H */
10994 diff -NurpP --minimal linux-2.6.29/include/linux/vserver/debug.h linux-2.6.29-vs2.3.0.36.9-pre3/include/linux/vserver/debug.h
10995 --- linux-2.6.29/include/linux/vserver/debug.h  1970-01-01 01:00:00.000000000 +0100
10996 +++ linux-2.6.29-vs2.3.0.36.9-pre3/include/linux/vserver/debug.h        2009-02-22 22:54:26.000000000 +0100
10997 @@ -0,0 +1,127 @@
10998 +#ifndef _VX_DEBUG_H
10999 +#define _VX_DEBUG_H
11000 +
11001 +
11002 +#define VXD_CBIT(n, m) (vx_debug_ ## n & (1 << (m)))
11003 +#define VXD_CMIN(n, m) (vx_debug_ ## n > (m))
11004 +#define VXD_MASK(n, m) (vx_debug_ ## n & (m))
11005 +
11006 +#define VXD_DEV(d)     (d), (d)->bd_inode->i_ino,              \
11007 +                       imajor((d)->bd_inode), iminor((d)->bd_inode)
11008 +#define VXF_DEV                "%p[%lu,%d:%d]"
11009 +
11010 +
11011 +#define vxd_path(p)                                            \
11012 +       ({ static char _buffer[PATH_MAX];                       \
11013 +          d_path(p, _buffer, sizeof(_buffer)); })
11014 +
11015 +#define vxd_cond_path(n)                                       \
11016 +       ((n) ? vxd_path(&(n)->path) : "<null>" )
11017 +
11018 +
11019 +#ifdef CONFIG_VSERVER_DEBUG
11020 +
11021 +extern unsigned int vx_debug_switch;
11022 +extern unsigned int vx_debug_xid;
11023 +extern unsigned int vx_debug_nid;
11024 +extern unsigned int vx_debug_tag;
11025 +extern unsigned int vx_debug_net;
11026 +extern unsigned int vx_debug_limit;
11027 +extern unsigned int vx_debug_cres;
11028 +extern unsigned int vx_debug_dlim;
11029 +extern unsigned int vx_debug_quota;
11030 +extern unsigned int vx_debug_cvirt;
11031 +extern unsigned int vx_debug_space;
11032 +extern unsigned int vx_debug_misc;
11033 +
11034 +
11035 +#define VX_LOGLEVEL    "vxD: "
11036 +#define VX_PROC_FMT    "%p: "
11037 +#define VX_PROCESS     current
11038 +
11039 +#define vxdprintk(c, f, x...)                                  \
11040 +       do {                                                    \
11041 +               if (c)                                          \
11042 +                       printk(VX_LOGLEVEL VX_PROC_FMT f "\n",  \
11043 +                               VX_PROCESS , ##x);              \
11044 +       } while (0)
11045 +
11046 +#define vxlprintk(c, f, x...)                                  \
11047 +       do {                                                    \
11048 +               if (c)                                          \
11049 +                       printk(VX_LOGLEVEL f " @%s:%d\n", x);   \
11050 +       } while (0)
11051 +
11052 +#define vxfprintk(c, f, x...)                                  \
11053 +       do {                                                    \
11054 +               if (c)                                          \
11055 +                       printk(VX_LOGLEVEL f " %s@%s:%d\n", x); \
11056 +       } while (0)
11057 +
11058 +
11059 +struct vx_info;
11060 +
11061 +void dump_vx_info(struct vx_info *, int);
11062 +void dump_vx_info_inactive(int);
11063 +
11064 +#else  /* CONFIG_VSERVER_DEBUG */
11065 +
11066 +#define vx_debug_switch 0
11067 +#define vx_debug_xid   0
11068 +#define vx_debug_nid   0
11069 +#define vx_debug_tag   0
11070 +#define vx_debug_net   0
11071 +#define vx_debug_limit 0
11072 +#define vx_debug_cres  0
11073 +#define vx_debug_dlim  0
11074 +#define vx_debug_cvirt 0
11075 +
11076 +#define vxdprintk(x...) do { } while (0)
11077 +#define vxlprintk(x...) do { } while (0)
11078 +#define vxfprintk(x...) do { } while (0)
11079 +
11080 +#endif /* CONFIG_VSERVER_DEBUG */
11081 +
11082 +
11083 +#ifdef CONFIG_VSERVER_WARN
11084 +
11085 +#define VX_WARNLEVEL   KERN_WARNING "vxW: "
11086 +#define VX_WARN_TASK   "[»%s«,%u:#%u|%u|%u] "
11087 +#define VX_WARN_XID    "[xid #%u] "
11088 +#define VX_WARN_NID    "[nid #%u] "
11089 +#define VX_WARN_TAG    "[tag #%u] "
11090 +
11091 +#define vxwprintk(c, f, x...)                                  \
11092 +       do {                                                    \
11093 +               if (c)                                          \
11094 +                       printk(VX_WARNLEVEL f "\n", ##x);       \
11095 +       } while (0)
11096 +
11097 +#else  /* CONFIG_VSERVER_WARN */
11098 +
11099 +#define vxwprintk(x...) do { } while (0)
11100 +
11101 +#endif /* CONFIG_VSERVER_WARN */
11102 +
11103 +#define vxwprintk_task(c, f, x...)                             \
11104 +       vxwprintk(c, VX_WARN_TASK f,                            \
11105 +               current->comm, current->pid,                    \
11106 +               current->xid, current->nid, current->tag, ##x)
11107 +#define vxwprintk_xid(c, f, x...)                              \
11108 +       vxwprintk(c, VX_WARN_XID f, current->xid, x)
11109 +#define vxwprintk_nid(c, f, x...)                              \
11110 +       vxwprintk(c, VX_WARN_NID f, current->nid, x)
11111 +#define vxwprintk_tag(c, f, x...)                              \
11112 +       vxwprintk(c, VX_WARN_TAG f, current->tag, x)
11113 +
11114 +#ifdef CONFIG_VSERVER_DEBUG
11115 +#define vxd_assert_lock(l)     assert_spin_locked(l)
11116 +#define vxd_assert(c, f, x...) vxlprintk(!(c), \
11117 +       "assertion [" f "] failed.", ##x, __FILE__, __LINE__)
11118 +#else
11119 +#define vxd_assert_lock(l)     do { } while (0)
11120 +#define vxd_assert(c, f, x...) do { } while (0)
11121 +#endif
11122 +
11123 +
11124 +#endif /* _VX_DEBUG_H */
11125 diff -NurpP --minimal linux-2.6.29/include/linux/vserver/device_cmd.h linux-2.6.29-vs2.3.0.36.9-pre3/include/linux/vserver/device_cmd.h
11126 --- linux-2.6.29/include/linux/vserver/device_cmd.h     1970-01-01 01:00:00.000000000 +0100
11127 +++ linux-2.6.29-vs2.3.0.36.9-pre3/include/linux/vserver/device_cmd.h   2009-02-22 22:54:26.000000000 +0100
11128 @@ -0,0 +1,44 @@
11129 +#ifndef _VX_DEVICE_CMD_H
11130 +#define _VX_DEVICE_CMD_H
11131 +
11132 +
11133 +/*  device vserver commands */
11134 +
11135 +#define VCMD_set_mapping       VC_CMD(DEVICE, 1, 0)
11136 +#define VCMD_unset_mapping     VC_CMD(DEVICE, 2, 0)
11137 +
11138 +struct vcmd_set_mapping_v0 {
11139 +       const char __user *device;
11140 +       const char __user *target;
11141 +       uint32_t flags;
11142 +};
11143 +
11144 +
11145 +#ifdef __KERNEL__
11146 +
11147 +#ifdef CONFIG_COMPAT
11148 +
11149 +#include <asm/compat.h>
11150 +
11151 +struct vcmd_set_mapping_v0_x32 {
11152 +       compat_uptr_t device_ptr;
11153 +       compat_uptr_t target_ptr;
11154 +       uint32_t flags;
11155 +};
11156 +
11157 +#endif /* CONFIG_COMPAT */
11158 +
11159 +#include <linux/compiler.h>
11160 +
11161 +extern int vc_set_mapping(struct vx_info *, void __user *);
11162 +extern int vc_unset_mapping(struct vx_info *, void __user *);
11163 +
11164 +#ifdef CONFIG_COMPAT
11165 +
11166 +extern int vc_set_mapping_x32(struct vx_info *, void __user *);
11167 +extern int vc_unset_mapping_x32(struct vx_info *, void __user *);
11168 +
11169 +#endif /* CONFIG_COMPAT */
11170 +
11171 +#endif /* __KERNEL__ */
11172 +#endif /* _VX_DEVICE_CMD_H */
11173 diff -NurpP --minimal linux-2.6.29/include/linux/vserver/device_def.h linux-2.6.29-vs2.3.0.36.9-pre3/include/linux/vserver/device_def.h
11174 --- linux-2.6.29/include/linux/vserver/device_def.h     1970-01-01 01:00:00.000000000 +0100
11175 +++ linux-2.6.29-vs2.3.0.36.9-pre3/include/linux/vserver/device_def.h   2009-02-22 22:54:26.000000000 +0100
11176 @@ -0,0 +1,17 @@
11177 +#ifndef _VX_DEVICE_DEF_H
11178 +#define _VX_DEVICE_DEF_H
11179 +
11180 +#include <linux/types.h>
11181 +
11182 +struct vx_dmap_target {
11183 +       dev_t target;
11184 +       uint32_t flags;
11185 +};
11186 +
11187 +struct _vx_device {
11188 +#ifdef CONFIG_VSERVER_DEVICE
11189 +       struct vx_dmap_target targets[2];
11190 +#endif
11191 +};
11192 +
11193 +#endif /* _VX_DEVICE_DEF_H */
11194 diff -NurpP --minimal linux-2.6.29/include/linux/vserver/device.h linux-2.6.29-vs2.3.0.36.9-pre3/include/linux/vserver/device.h
11195 --- linux-2.6.29/include/linux/vserver/device.h 1970-01-01 01:00:00.000000000 +0100
11196 +++ linux-2.6.29-vs2.3.0.36.9-pre3/include/linux/vserver/device.h       2009-02-22 22:54:26.000000000 +0100
11197 @@ -0,0 +1,15 @@
11198 +#ifndef _VX_DEVICE_H
11199 +#define _VX_DEVICE_H
11200 +
11201 +
11202 +#define DATTR_CREATE   0x00000001
11203 +#define DATTR_OPEN     0x00000002
11204 +
11205 +#define DATTR_REMAP    0x00000010
11206 +
11207 +#define DATTR_MASK     0x00000013
11208 +
11209 +
11210 +#else  /* _VX_DEVICE_H */
11211 +#warning duplicate inclusion
11212 +#endif /* _VX_DEVICE_H */
11213 diff -NurpP --minimal linux-2.6.29/include/linux/vserver/dlimit_cmd.h linux-2.6.29-vs2.3.0.36.9-pre3/include/linux/vserver/dlimit_cmd.h
11214 --- linux-2.6.29/include/linux/vserver/dlimit_cmd.h     1970-01-01 01:00:00.000000000 +0100
11215 +++ linux-2.6.29-vs2.3.0.36.9-pre3/include/linux/vserver/dlimit_cmd.h   2009-02-22 22:54:26.000000000 +0100
11216 @@ -0,0 +1,74 @@
11217 +#ifndef _VX_DLIMIT_CMD_H
11218 +#define _VX_DLIMIT_CMD_H
11219 +
11220 +
11221 +/*  dlimit vserver commands */
11222 +
11223 +#define VCMD_add_dlimit                VC_CMD(DLIMIT, 1, 0)
11224 +#define VCMD_rem_dlimit                VC_CMD(DLIMIT, 2, 0)
11225 +
11226 +#define VCMD_set_dlimit                VC_CMD(DLIMIT, 5, 0)
11227 +#define VCMD_get_dlimit                VC_CMD(DLIMIT, 6, 0)
11228 +
11229 +struct vcmd_ctx_dlimit_base_v0 {
11230 +       const char __user *name;
11231 +       uint32_t flags;
11232 +};
11233 +
11234 +struct vcmd_ctx_dlimit_v0 {
11235 +       const char __user *name;
11236 +       uint32_t space_used;                    /* used space in kbytes */
11237 +       uint32_t space_total;                   /* maximum space in kbytes */
11238 +       uint32_t inodes_used;                   /* used inodes */
11239 +       uint32_t inodes_total;                  /* maximum inodes */
11240 +       uint32_t reserved;                      /* reserved for root in % */
11241 +       uint32_t flags;
11242 +};
11243 +
11244 +#define CDLIM_UNSET            ((uint32_t)0UL)
11245 +#define CDLIM_INFINITY         ((uint32_t)~0UL)
11246 +#define CDLIM_KEEP             ((uint32_t)~1UL)
11247 +
11248 +#ifdef __KERNEL__
11249 +
11250 +#ifdef CONFIG_COMPAT
11251 +
11252 +#include <asm/compat.h>
11253 +
11254 +struct vcmd_ctx_dlimit_base_v0_x32 {
11255 +       compat_uptr_t name_ptr;
11256 +       uint32_t flags;
11257 +};
11258 +
11259 +struct vcmd_ctx_dlimit_v0_x32 {
11260 +       compat_uptr_t name_ptr;
11261 +       uint32_t space_used;                    /* used space in kbytes */
11262 +       uint32_t space_total;                   /* maximum space in kbytes */
11263 +       uint32_t inodes_used;                   /* used inodes */
11264 +       uint32_t inodes_total;                  /* maximum inodes */
11265 +       uint32_t reserved;                      /* reserved for root in % */
11266 +       uint32_t flags;
11267 +};
11268 +
11269 +#endif /* CONFIG_COMPAT */
11270 +
11271 +#include <linux/compiler.h>
11272 +
11273 +extern int vc_add_dlimit(uint32_t, void __user *);
11274 +extern int vc_rem_dlimit(uint32_t, void __user *);
11275 +
11276 +extern int vc_set_dlimit(uint32_t, void __user *);
11277 +extern int vc_get_dlimit(uint32_t, void __user *);
11278 +
11279 +#ifdef CONFIG_COMPAT
11280 +
11281 +extern int vc_add_dlimit_x32(uint32_t, void __user *);
11282 +extern int vc_rem_dlimit_x32(uint32_t, void __user *);
11283 +
11284 +extern int vc_set_dlimit_x32(uint32_t, void __user *);
11285 +extern int vc_get_dlimit_x32(uint32_t, void __user *);
11286 +
11287 +#endif /* CONFIG_COMPAT */
11288 +
11289 +#endif /* __KERNEL__ */
11290 +#endif /* _VX_DLIMIT_CMD_H */
11291 diff -NurpP --minimal linux-2.6.29/include/linux/vserver/dlimit.h linux-2.6.29-vs2.3.0.36.9-pre3/include/linux/vserver/dlimit.h
11292 --- linux-2.6.29/include/linux/vserver/dlimit.h 1970-01-01 01:00:00.000000000 +0100
11293 +++ linux-2.6.29-vs2.3.0.36.9-pre3/include/linux/vserver/dlimit.h       2009-02-22 22:54:26.000000000 +0100
11294 @@ -0,0 +1,54 @@
11295 +#ifndef _VX_DLIMIT_H
11296 +#define _VX_DLIMIT_H
11297 +
11298 +#include "switch.h"
11299 +
11300 +
11301 +#ifdef __KERNEL__
11302 +
11303 +/*      keep in sync with CDLIM_INFINITY       */
11304 +
11305 +#define DLIM_INFINITY          (~0ULL)
11306 +
11307 +#include <linux/spinlock.h>
11308 +#include <linux/rcupdate.h>
11309 +
11310 +struct super_block;
11311 +
11312 +struct dl_info {
11313 +       struct hlist_node dl_hlist;             /* linked list of contexts */
11314 +       struct rcu_head dl_rcu;                 /* the rcu head */
11315 +       tag_t dl_tag;                           /* context tag */
11316 +       atomic_t dl_usecnt;                     /* usage count */
11317 +       atomic_t dl_refcnt;                     /* reference count */
11318 +
11319 +       struct super_block *dl_sb;              /* associated superblock */
11320 +
11321 +       spinlock_t dl_lock;                     /* protect the values */
11322 +
11323 +       unsigned long long dl_space_used;       /* used space in bytes */
11324 +       unsigned long long dl_space_total;      /* maximum space in bytes */
11325 +       unsigned long dl_inodes_used;           /* used inodes */
11326 +       unsigned long dl_inodes_total;          /* maximum inodes */
11327 +
11328 +       unsigned int dl_nrlmult;                /* non root limit mult */
11329 +};
11330 +
11331 +struct rcu_head;
11332 +
11333 +extern void rcu_free_dl_info(struct rcu_head *);
11334 +extern void unhash_dl_info(struct dl_info *);
11335 +
11336 +extern struct dl_info *locate_dl_info(struct super_block *, tag_t);
11337 +
11338 +
11339 +struct kstatfs;
11340 +
11341 +extern void vx_vsi_statfs(struct super_block *, struct kstatfs *);
11342 +
11343 +typedef uint64_t dlsize_t;
11344 +
11345 +#endif /* __KERNEL__ */
11346 +#else  /* _VX_DLIMIT_H */
11347 +#warning duplicate inclusion
11348 +#endif /* _VX_DLIMIT_H */
11349 diff -NurpP --minimal linux-2.6.29/include/linux/vserver/global.h linux-2.6.29-vs2.3.0.36.9-pre3/include/linux/vserver/global.h
11350 --- linux-2.6.29/include/linux/vserver/global.h 1970-01-01 01:00:00.000000000 +0100
11351 +++ linux-2.6.29-vs2.3.0.36.9-pre3/include/linux/vserver/global.h       2009-02-22 22:54:26.000000000 +0100
11352 @@ -0,0 +1,20 @@
11353 +#ifndef _VX_GLOBAL_H
11354 +#define _VX_GLOBAL_H
11355 +
11356 +
11357 +extern atomic_t vx_global_ctotal;
11358 +extern atomic_t vx_global_cactive;
11359 +
11360 +extern atomic_t nx_global_ctotal;
11361 +extern atomic_t nx_global_cactive;
11362 +
11363 +extern atomic_t vs_global_nsproxy;
11364 +extern atomic_t vs_global_fs;
11365 +extern atomic_t vs_global_mnt_ns;
11366 +extern atomic_t vs_global_uts_ns;
11367 +extern atomic_t vs_global_ipc_ns;
11368 +extern atomic_t vs_global_user_ns;
11369 +extern atomic_t vs_global_pid_ns;
11370 +
11371 +
11372 +#endif /* _VX_GLOBAL_H */
11373 diff -NurpP --minimal linux-2.6.29/include/linux/vserver/history.h linux-2.6.29-vs2.3.0.36.9-pre3/include/linux/vserver/history.h
11374 --- linux-2.6.29/include/linux/vserver/history.h        1970-01-01 01:00:00.000000000 +0100
11375 +++ linux-2.6.29-vs2.3.0.36.9-pre3/include/linux/vserver/history.h      2009-02-22 22:54:26.000000000 +0100
11376 @@ -0,0 +1,197 @@
11377 +#ifndef _VX_HISTORY_H
11378 +#define _VX_HISTORY_H
11379 +
11380 +
11381 +enum {
11382 +       VXH_UNUSED = 0,
11383 +       VXH_THROW_OOPS = 1,
11384 +
11385 +       VXH_GET_VX_INFO,
11386 +       VXH_PUT_VX_INFO,
11387 +       VXH_INIT_VX_INFO,
11388 +       VXH_SET_VX_INFO,
11389 +       VXH_CLR_VX_INFO,
11390 +       VXH_CLAIM_VX_INFO,
11391 +       VXH_RELEASE_VX_INFO,
11392 +       VXH_ALLOC_VX_INFO,
11393 +       VXH_DEALLOC_VX_INFO,
11394 +       VXH_HASH_VX_INFO,
11395 +       VXH_UNHASH_VX_INFO,
11396 +       VXH_LOC_VX_INFO,
11397 +       VXH_LOOKUP_VX_INFO,
11398 +       VXH_CREATE_VX_INFO,
11399 +};
11400 +
11401 +struct _vxhe_vxi {
11402 +       struct vx_info *ptr;
11403 +       unsigned xid;
11404 +       unsigned usecnt;
11405 +       unsigned tasks;
11406 +};
11407 +
11408 +struct _vxhe_set_clr {
11409 +       void *data;
11410 +};
11411 +
11412 +struct _vxhe_loc_lookup {
11413 +       unsigned arg;
11414 +};
11415 +
11416 +struct _vx_hist_entry {
11417 +       void *loc;
11418 +       unsigned short seq;
11419 +       unsigned short type;
11420 +       struct _vxhe_vxi vxi;
11421 +       union {
11422 +               struct _vxhe_set_clr sc;
11423 +               struct _vxhe_loc_lookup ll;
11424 +       };
11425 +};
11426 +
11427 +#ifdef CONFIG_VSERVER_HISTORY
11428 +
11429 +extern unsigned volatile int vxh_active;
11430 +
11431 +struct _vx_hist_entry *vxh_advance(void *loc);
11432 +
11433 +
11434 +static inline
11435 +void   __vxh_copy_vxi(struct _vx_hist_entry *entry, struct vx_info *vxi)
11436 +{
11437 +       entry->vxi.ptr = vxi;
11438 +       if (vxi) {
11439 +               entry->vxi.usecnt = atomic_read(&vxi->vx_usecnt);
11440 +               entry->vxi.tasks = atomic_read(&vxi->vx_tasks);
11441 +               entry->vxi.xid = vxi->vx_id;
11442 +       }
11443 +}
11444 +
11445 +
11446 +#define        __HERE__ current_text_addr()
11447 +
11448 +#define __VXH_BODY(__type, __data, __here)     \
11449 +       struct _vx_hist_entry *entry;           \
11450 +                                               \
11451 +       preempt_disable();                      \
11452 +       entry = vxh_advance(__here);            \
11453 +       __data;                                 \
11454 +       entry->type = __type;                   \
11455 +       preempt_enable();
11456 +
11457 +
11458 +       /* pass vxi only */
11459 +
11460 +#define __VXH_SMPL                             \
11461 +       __vxh_copy_vxi(entry, vxi)
11462 +
11463 +static inline
11464 +void   __vxh_smpl(struct vx_info *vxi, int __type, void *__here)
11465 +{
11466 +       __VXH_BODY(__type, __VXH_SMPL, __here)
11467 +}
11468 +
11469 +       /* pass vxi and data (void *) */
11470 +
11471 +#define __VXH_DATA                             \
11472 +       __vxh_copy_vxi(entry, vxi);             \
11473 +       entry->sc.data = data
11474 +
11475 +static inline
11476 +void   __vxh_data(struct vx_info *vxi, void *data,
11477 +                       int __type, void *__here)
11478 +{
11479 +       __VXH_BODY(__type, __VXH_DATA, __here)
11480 +}
11481 +
11482 +       /* pass vxi and arg (long) */
11483 +
11484 +#define __VXH_LONG                             \
11485 +       __vxh_copy_vxi(entry, vxi);             \
11486 +       entry->ll.arg = arg
11487 +
11488 +static inline
11489 +void   __vxh_long(struct vx_info *vxi, long arg,
11490 +                       int __type, void *__here)
11491 +{
11492 +       __VXH_BODY(__type, __VXH_LONG, __here)
11493 +}
11494 +
11495 +
11496 +static inline
11497 +void   __vxh_throw_oops(void *__here)
11498 +{
11499 +       __VXH_BODY(VXH_THROW_OOPS, {}, __here);
11500 +       /* prevent further acquisition */
11501 +       vxh_active = 0;
11502 +}
11503 +
11504 +
11505 +#define vxh_throw_oops()       __vxh_throw_oops(__HERE__);
11506 +
11507 +#define __vxh_get_vx_info(v, h)        __vxh_smpl(v, VXH_GET_VX_INFO, h);
11508 +#define __vxh_put_vx_info(v, h)        __vxh_smpl(v, VXH_PUT_VX_INFO, h);
11509 +
11510 +#define __vxh_init_vx_info(v, d, h) \
11511 +       __vxh_data(v, d, VXH_INIT_VX_INFO, h);
11512 +#define __vxh_set_vx_info(v, d, h) \
11513 +       __vxh_data(v, d, VXH_SET_VX_INFO, h);
11514 +#define __vxh_clr_vx_info(v, d, h) \
11515 +       __vxh_data(v, d, VXH_CLR_VX_INFO, h);
11516 +
11517 +#define __vxh_claim_vx_info(v, d, h) \
11518 +       __vxh_data(v, d, VXH_CLAIM_VX_INFO, h);
11519 +#define __vxh_release_vx_info(v, d, h) \
11520 +       __vxh_data(v, d, VXH_RELEASE_VX_INFO, h);
11521 +
11522 +#define vxh_alloc_vx_info(v) \
11523 +       __vxh_smpl(v, VXH_ALLOC_VX_INFO, __HERE__);
11524 +#define vxh_dealloc_vx_info(v) \
11525 +       __vxh_smpl(v, VXH_DEALLOC_VX_INFO, __HERE__);
11526 +
11527 +#define vxh_hash_vx_info(v) \
11528 +       __vxh_smpl(v, VXH_HASH_VX_INFO, __HERE__);
11529 +#define vxh_unhash_vx_info(v) \
11530 +       __vxh_smpl(v, VXH_UNHASH_VX_INFO, __HERE__);
11531 +
11532 +#define vxh_loc_vx_info(v, l) \
11533 +       __vxh_long(v, l, VXH_LOC_VX_INFO, __HERE__);
11534 +#define vxh_lookup_vx_info(v, l) \
11535 +       __vxh_long(v, l, VXH_LOOKUP_VX_INFO, __HERE__);
11536 +#define vxh_create_vx_info(v, l) \
11537 +       __vxh_long(v, l, VXH_CREATE_VX_INFO, __HERE__);
11538 +
11539 +extern void vxh_dump_history(void);
11540 +
11541 +
11542 +#else  /* CONFIG_VSERVER_HISTORY */
11543 +
11544 +#define        __HERE__        0
11545 +
11546 +#define vxh_throw_oops()               do { } while (0)
11547 +
11548 +#define __vxh_get_vx_info(v, h)                do { } while (0)
11549 +#define __vxh_put_vx_info(v, h)                do { } while (0)
11550 +
11551 +#define __vxh_init_vx_info(v, d, h)    do { } while (0)
11552 +#define __vxh_set_vx_info(v, d, h)     do { } while (0)
11553 +#define __vxh_clr_vx_info(v, d, h)     do { } while (0)
11554 +
11555 +#define __vxh_claim_vx_info(v, d, h)   do { } while (0)
11556 +#define __vxh_release_vx_info(v, d, h) do { } while (0)
11557 +
11558 +#define vxh_alloc_vx_info(v)           do { } while (0)
11559 +#define vxh_dealloc_vx_info(v)         do { } while (0)
11560 +
11561 +#define vxh_hash_vx_info(v)            do { } while (0)
11562 +#define vxh_unhash_vx_info(v)          do { } while (0)
11563 +
11564 +#define vxh_loc_vx_info(v, l)          do { } while (0)
11565 +#define vxh_lookup_vx_info(v, l)       do { } while (0)
11566 +#define vxh_create_vx_info(v, l)       do { } while (0)
11567 +
11568 +#define vxh_dump_history()             do { } while (0)
11569 +
11570 +
11571 +#endif /* CONFIG_VSERVER_HISTORY */
11572 +
11573 +#endif /* _VX_HISTORY_H */
11574 diff -NurpP --minimal linux-2.6.29/include/linux/vserver/inode_cmd.h linux-2.6.29-vs2.3.0.36.9-pre3/include/linux/vserver/inode_cmd.h
11575 --- linux-2.6.29/include/linux/vserver/inode_cmd.h      1970-01-01 01:00:00.000000000 +0100
11576 +++ linux-2.6.29-vs2.3.0.36.9-pre3/include/linux/vserver/inode_cmd.h    2009-02-22 22:54:26.000000000 +0100
11577 @@ -0,0 +1,59 @@
11578 +#ifndef _VX_INODE_CMD_H
11579 +#define _VX_INODE_CMD_H
11580 +
11581 +
11582 +/*  inode vserver commands */
11583 +
11584 +#define VCMD_get_iattr         VC_CMD(INODE, 1, 1)
11585 +#define VCMD_set_iattr         VC_CMD(INODE, 2, 1)
11586 +
11587 +#define VCMD_fget_iattr                VC_CMD(INODE, 3, 0)
11588 +#define VCMD_fset_iattr                VC_CMD(INODE, 4, 0)
11589 +
11590 +struct vcmd_ctx_iattr_v1 {
11591 +       const char __user *name;
11592 +       uint32_t tag;
11593 +       uint32_t flags;
11594 +       uint32_t mask;
11595 +};
11596 +
11597 +struct vcmd_ctx_fiattr_v0 {
11598 +       uint32_t tag;
11599 +       uint32_t flags;
11600 +       uint32_t mask;
11601 +};
11602 +
11603 +
11604 +#ifdef __KERNEL__
11605 +
11606 +
11607 +#ifdef CONFIG_COMPAT
11608 +
11609 +#include <asm/compat.h>
11610 +
11611 +struct vcmd_ctx_iattr_v1_x32 {
11612 +       compat_uptr_t name_ptr;
11613 +       uint32_t tag;
11614 +       uint32_t flags;
11615 +       uint32_t mask;
11616 +};
11617 +
11618 +#endif /* CONFIG_COMPAT */
11619 +
11620 +#include <linux/compiler.h>
11621 +
11622 +extern int vc_get_iattr(void __user *);
11623 +extern int vc_set_iattr(void __user *);
11624 +
11625 +extern int vc_fget_iattr(uint32_t, void __user *);
11626 +extern int vc_fset_iattr(uint32_t, void __user *);
11627 +
11628 +#ifdef CONFIG_COMPAT
11629 +
11630 +extern int vc_get_iattr_x32(void __user *);
11631 +extern int vc_set_iattr_x32(void __user *);
11632 +
11633 +#endif /* CONFIG_COMPAT */
11634 +
11635 +#endif /* __KERNEL__ */
11636 +#endif /* _VX_INODE_CMD_H */
11637 diff -NurpP --minimal linux-2.6.29/include/linux/vserver/inode.h linux-2.6.29-vs2.3.0.36.9-pre3/include/linux/vserver/inode.h
11638 --- linux-2.6.29/include/linux/vserver/inode.h  1970-01-01 01:00:00.000000000 +0100
11639 +++ linux-2.6.29-vs2.3.0.36.9-pre3/include/linux/vserver/inode.h        2009-02-22 22:54:26.000000000 +0100
11640 @@ -0,0 +1,38 @@
11641 +#ifndef _VX_INODE_H
11642 +#define _VX_INODE_H
11643 +
11644 +
11645 +#define IATTR_TAG      0x01000000
11646 +
11647 +#define IATTR_ADMIN    0x00000001
11648 +#define IATTR_WATCH    0x00000002
11649 +#define IATTR_HIDE     0x00000004
11650 +#define IATTR_FLAGS    0x00000007
11651 +
11652 +#define IATTR_BARRIER  0x00010000
11653 +#define IATTR_IXUNLINK 0x00020000
11654 +#define IATTR_IMMUTABLE 0x00040000
11655 +
11656 +#ifdef __KERNEL__
11657 +
11658 +
11659 +#ifdef CONFIG_VSERVER_PROC_SECURE
11660 +#define IATTR_PROC_DEFAULT     ( IATTR_ADMIN | IATTR_HIDE )
11661 +#define IATTR_PROC_SYMLINK     ( IATTR_ADMIN )
11662 +#else
11663 +#define IATTR_PROC_DEFAULT     ( IATTR_ADMIN )
11664 +#define IATTR_PROC_SYMLINK     ( IATTR_ADMIN )
11665 +#endif
11666 +
11667 +#define vx_hide_check(c, m)    (((m) & IATTR_HIDE) ? vx_check(c, m) : 1)
11668 +
11669 +#endif /* __KERNEL__ */
11670 +
11671 +/* inode ioctls */
11672 +
11673 +#define FIOC_GETXFLG   _IOR('x', 5, long)
11674 +#define FIOC_SETXFLG   _IOW('x', 6, long)
11675 +
11676 +#else  /* _VX_INODE_H */
11677 +#warning duplicate inclusion
11678 +#endif /* _VX_INODE_H */
11679 diff -NurpP --minimal linux-2.6.29/include/linux/vserver/Kbuild linux-2.6.29-vs2.3.0.36.9-pre3/include/linux/vserver/Kbuild
11680 --- linux-2.6.29/include/linux/vserver/Kbuild   1970-01-01 01:00:00.000000000 +0100
11681 +++ linux-2.6.29-vs2.3.0.36.9-pre3/include/linux/vserver/Kbuild 2009-02-22 22:54:26.000000000 +0100
11682 @@ -0,0 +1,8 @@
11683 +
11684 +unifdef-y += context_cmd.h network_cmd.h space_cmd.h \
11685 +       cacct_cmd.h cvirt_cmd.h limit_cmd.h dlimit_cmd.h \
11686 +       inode_cmd.h tag_cmd.h sched_cmd.h signal_cmd.h \
11687 +       debug_cmd.h device_cmd.h
11688 +
11689 +unifdef-y += switch.h network.h monitor.h inode.h device.h
11690 +
11691 diff -NurpP --minimal linux-2.6.29/include/linux/vserver/limit_cmd.h linux-2.6.29-vs2.3.0.36.9-pre3/include/linux/vserver/limit_cmd.h
11692 --- linux-2.6.29/include/linux/vserver/limit_cmd.h      1970-01-01 01:00:00.000000000 +0100
11693 +++ linux-2.6.29-vs2.3.0.36.9-pre3/include/linux/vserver/limit_cmd.h    2009-02-22 22:54:26.000000000 +0100
11694 @@ -0,0 +1,69 @@
11695 +#ifndef _VX_LIMIT_CMD_H
11696 +#define _VX_LIMIT_CMD_H
11697 +
11698 +
11699 +/*  rlimit vserver commands */
11700 +
11701 +#define VCMD_get_rlimit                VC_CMD(RLIMIT, 1, 0)
11702 +#define VCMD_set_rlimit                VC_CMD(RLIMIT, 2, 0)
11703 +#define VCMD_get_rlimit_mask   VC_CMD(RLIMIT, 3, 0)
11704 +#define VCMD_reset_minmax      VC_CMD(RLIMIT, 9, 0)
11705 +
11706 +struct vcmd_ctx_rlimit_v0 {
11707 +       uint32_t id;
11708 +       uint64_t minimum;
11709 +       uint64_t softlimit;
11710 +       uint64_t maximum;
11711 +};
11712 +
11713 +struct vcmd_ctx_rlimit_mask_v0 {
11714 +       uint32_t minimum;
11715 +       uint32_t softlimit;
11716 +       uint32_t maximum;
11717 +};
11718 +
11719 +#define VCMD_rlimit_stat       VC_CMD(VSTAT, 1, 0)
11720 +
11721 +struct vcmd_rlimit_stat_v0 {
11722 +       uint32_t id;
11723 +       uint32_t hits;
11724 +       uint64_t value;
11725 +       uint64_t minimum;
11726 +       uint64_t maximum;
11727 +};
11728 +
11729 +#define CRLIM_UNSET            (0ULL)
11730 +#define CRLIM_INFINITY         (~0ULL)
11731 +#define CRLIM_KEEP             (~1ULL)
11732 +
11733 +#ifdef __KERNEL__
11734 +
11735 +#ifdef CONFIG_IA32_EMULATION
11736 +
11737 +struct vcmd_ctx_rlimit_v0_x32 {
11738 +       uint32_t id;
11739 +       uint64_t minimum;
11740 +       uint64_t softlimit;
11741 +       uint64_t maximum;
11742 +} __attribute__ ((packed));
11743 +
11744 +#endif /* CONFIG_IA32_EMULATION */
11745 +
11746 +#include <linux/compiler.h>
11747 +
11748 +extern int vc_get_rlimit_mask(uint32_t, void __user *);
11749 +extern int vc_get_rlimit(struct vx_info *, void __user *);
11750 +extern int vc_set_rlimit(struct vx_info *, void __user *);
11751 +extern int vc_reset_minmax(struct vx_info *, void __user *);
11752 +
11753 +extern int vc_rlimit_stat(struct vx_info *, void __user *);
11754 +
11755 +#ifdef CONFIG_IA32_EMULATION
11756 +
11757 +extern int vc_get_rlimit_x32(struct vx_info *, void __user *);
11758 +extern int vc_set_rlimit_x32(struct vx_info *, void __user *);
11759 +
11760 +#endif /* CONFIG_IA32_EMULATION */
11761 +
11762 +#endif /* __KERNEL__ */
11763 +#endif /* _VX_LIMIT_CMD_H */
11764 diff -NurpP --minimal linux-2.6.29/include/linux/vserver/limit_def.h linux-2.6.29-vs2.3.0.36.9-pre3/include/linux/vserver/limit_def.h
11765 --- linux-2.6.29/include/linux/vserver/limit_def.h      1970-01-01 01:00:00.000000000 +0100
11766 +++ linux-2.6.29-vs2.3.0.36.9-pre3/include/linux/vserver/limit_def.h    2009-02-22 22:54:26.000000000 +0100
11767 @@ -0,0 +1,47 @@
11768 +#ifndef _VX_LIMIT_DEF_H
11769 +#define _VX_LIMIT_DEF_H
11770 +
11771 +#include <asm/atomic.h>
11772 +#include <asm/resource.h>
11773 +
11774 +#include "limit.h"
11775 +
11776 +
11777 +struct _vx_res_limit {
11778 +       rlim_t soft;            /* Context soft limit */
11779 +       rlim_t hard;            /* Context hard limit */
11780 +
11781 +       rlim_atomic_t rcur;     /* Current value */
11782 +       rlim_t rmin;            /* Context minimum */
11783 +       rlim_t rmax;            /* Context maximum */
11784 +
11785 +       atomic_t lhit;          /* Limit hits */
11786 +};
11787 +
11788 +/* context sub struct */
11789 +
11790 +struct _vx_limit {
11791 +       struct _vx_res_limit res[NUM_LIMITS];
11792 +};
11793 +
11794 +#ifdef CONFIG_VSERVER_DEBUG
11795 +
11796 +static inline void __dump_vx_limit(struct _vx_limit *limit)
11797 +{
11798 +       int i;
11799 +
11800 +       printk("\t_vx_limit:");
11801 +       for (i = 0; i < NUM_LIMITS; i++) {
11802 +               printk("\t [%2d] = %8lu %8lu/%8lu, %8ld/%8ld, %8d\n",
11803 +                       i, (unsigned long)__rlim_get(limit, i),
11804 +                       (unsigned long)__rlim_rmin(limit, i),
11805 +                       (unsigned long)__rlim_rmax(limit, i),
11806 +                       (long)__rlim_soft(limit, i),
11807 +                       (long)__rlim_hard(limit, i),
11808 +                       atomic_read(&__rlim_lhit(limit, i)));
11809 +       }
11810 +}
11811 +
11812 +#endif
11813 +
11814 +#endif /* _VX_LIMIT_DEF_H */
11815 diff -NurpP --minimal linux-2.6.29/include/linux/vserver/limit.h linux-2.6.29-vs2.3.0.36.9-pre3/include/linux/vserver/limit.h
11816 --- linux-2.6.29/include/linux/vserver/limit.h  1970-01-01 01:00:00.000000000 +0100
11817 +++ linux-2.6.29-vs2.3.0.36.9-pre3/include/linux/vserver/limit.h        2009-02-22 22:54:26.000000000 +0100
11818 @@ -0,0 +1,70 @@
11819 +#ifndef _VX_LIMIT_H
11820 +#define _VX_LIMIT_H
11821 +
11822 +#define VLIMIT_NSOCK   16
11823 +#define VLIMIT_OPENFD  17
11824 +#define VLIMIT_ANON    18
11825 +#define VLIMIT_SHMEM   19
11826 +#define VLIMIT_SEMARY  20
11827 +#define VLIMIT_NSEMS   21
11828 +#define VLIMIT_DENTRY  22
11829 +#define VLIMIT_MAPPED  23
11830 +
11831 +
11832 +#ifdef __KERNEL__
11833 +
11834 +#define        VLIM_NOCHECK    ((1L << VLIMIT_DENTRY) | (1L << RLIMIT_RSS))
11835 +
11836 +/*     keep in sync with CRLIM_INFINITY */
11837 +
11838 +#define        VLIM_INFINITY   (~0ULL)
11839 +
11840 +#include <asm/atomic.h>
11841 +#include <asm/resource.h>
11842 +
11843 +#ifndef RLIM_INFINITY
11844 +#warning RLIM_INFINITY is undefined
11845 +#endif
11846 +
11847 +#define __rlim_val(l, r, v)    ((l)->res[r].v)
11848 +
11849 +#define __rlim_soft(l, r)      __rlim_val(l, r, soft)
11850 +#define __rlim_hard(l, r)      __rlim_val(l, r, hard)
11851 +
11852 +#define __rlim_rcur(l, r)      __rlim_val(l, r, rcur)
11853 +#define __rlim_rmin(l, r)      __rlim_val(l, r, rmin)
11854 +#define __rlim_rmax(l, r)      __rlim_val(l, r, rmax)
11855 +
11856 +#define __rlim_lhit(l, r)      __rlim_val(l, r, lhit)
11857 +#define __rlim_hit(l, r)       atomic_inc(&__rlim_lhit(l, r))
11858 +
11859 +typedef atomic_long_t rlim_atomic_t;
11860 +typedef unsigned long rlim_t;
11861 +
11862 +#define __rlim_get(l, r)       atomic_long_read(&__rlim_rcur(l, r))
11863 +#define __rlim_set(l, r, v)    atomic_long_set(&__rlim_rcur(l, r), v)
11864 +#define __rlim_inc(l, r)       atomic_long_inc(&__rlim_rcur(l, r))
11865 +#define __rlim_dec(l, r)       atomic_long_dec(&__rlim_rcur(l, r))
11866 +#define __rlim_add(l, r, v)    atomic_long_add(v, &__rlim_rcur(l, r))
11867 +#define __rlim_sub(l, r, v)    atomic_long_sub(v, &__rlim_rcur(l, r))
11868 +
11869 +
11870 +#if    (RLIM_INFINITY == VLIM_INFINITY)
11871 +#define        VX_VLIM(r) ((long long)(long)(r))
11872 +#define        VX_RLIM(v) ((rlim_t)(v))
11873 +#else
11874 +#define        VX_VLIM(r) (((r) == RLIM_INFINITY) \
11875 +               ? VLIM_INFINITY : (long long)(r))
11876 +#define        VX_RLIM(v) (((v) == VLIM_INFINITY) \
11877 +               ? RLIM_INFINITY : (rlim_t)(v))
11878 +#endif
11879 +
11880 +struct sysinfo;
11881 +
11882 +void vx_vsi_meminfo(struct sysinfo *);
11883 +void vx_vsi_swapinfo(struct sysinfo *);
11884 +
11885 +#define NUM_LIMITS     24
11886 +
11887 +#endif /* __KERNEL__ */
11888 +#endif /* _VX_LIMIT_H */
11889 diff -NurpP --minimal linux-2.6.29/include/linux/vserver/limit_int.h linux-2.6.29-vs2.3.0.36.9-pre3/include/linux/vserver/limit_int.h
11890 --- linux-2.6.29/include/linux/vserver/limit_int.h      1970-01-01 01:00:00.000000000 +0100
11891 +++ linux-2.6.29-vs2.3.0.36.9-pre3/include/linux/vserver/limit_int.h    2009-02-22 22:54:26.000000000 +0100
11892 @@ -0,0 +1,198 @@
11893 +#ifndef _VX_LIMIT_INT_H
11894 +#define _VX_LIMIT_INT_H
11895 +
11896 +#include "context.h"
11897 +
11898 +#ifdef __KERNEL__
11899 +
11900 +#define VXD_RCRES_COND(r)      VXD_CBIT(cres, r)
11901 +#define VXD_RLIMIT_COND(r)     VXD_CBIT(limit, r)
11902 +
11903 +extern const char *vlimit_name[NUM_LIMITS];
11904 +
11905 +static inline void __vx_acc_cres(struct vx_info *vxi,
11906 +       int res, int dir, void *_data, char *_file, int _line)
11907 +{
11908 +       if (VXD_RCRES_COND(res))
11909 +               vxlprintk(1, "vx_acc_cres[%5d,%s,%2d]: %5ld%s (%p)",
11910 +                       (vxi ? vxi->vx_id : -1), vlimit_name[res], res,
11911 +                       (vxi ? (long)__rlim_get(&vxi->limit, res) : 0),
11912 +                       (dir > 0) ? "++" : "--", _data, _file, _line);
11913 +       if (!vxi)
11914 +               return;
11915 +
11916 +       if (dir > 0)
11917 +               __rlim_inc(&vxi->limit, res);
11918 +       else
11919 +               __rlim_dec(&vxi->limit, res);
11920 +}
11921 +
11922 +static inline void __vx_add_cres(struct vx_info *vxi,
11923 +       int res, int amount, void *_data, char *_file, int _line)
11924 +{
11925 +       if (VXD_RCRES_COND(res))
11926 +               vxlprintk(1, "vx_add_cres[%5d,%s,%2d]: %5ld += %5d (%p)",
11927 +                       (vxi ? vxi->vx_id : -1), vlimit_name[res], res,
11928 +                       (vxi ? (long)__rlim_get(&vxi->limit, res) : 0),
11929 +                       amount, _data, _file, _line);
11930 +       if (amount == 0)
11931 +               return;
11932 +       if (!vxi)
11933 +               return;
11934 +       __rlim_add(&vxi->limit, res, amount);
11935 +}
11936 +
11937 +static inline
11938 +int __vx_cres_adjust_max(struct _vx_limit *limit, int res, rlim_t value)
11939 +{
11940 +       int cond = (value > __rlim_rmax(limit, res));
11941 +
11942 +       if (cond)
11943 +               __rlim_rmax(limit, res) = value;
11944 +       return cond;
11945 +}
11946 +
11947 +static inline
11948 +int __vx_cres_adjust_min(struct _vx_limit *limit, int res, rlim_t value)
11949 +{
11950 +       int cond = (value < __rlim_rmin(limit, res));
11951 +
11952 +       if (cond)
11953 +               __rlim_rmin(limit, res) = value;
11954 +       return cond;
11955 +}
11956 +
11957 +static inline
11958 +void __vx_cres_fixup(struct _vx_limit *limit, int res, rlim_t value)
11959 +{
11960 +       if (!__vx_cres_adjust_max(limit, res, value))
11961 +               __vx_cres_adjust_min(limit, res, value);
11962 +}
11963 +
11964 +
11965 +/*     return values:
11966 +        +1 ... no limit hit
11967 +        -1 ... over soft limit
11968 +         0 ... over hard limit         */
11969 +
11970 +static inline int __vx_cres_avail(struct vx_info *vxi,
11971 +       int res, int num, char *_file, int _line)
11972 +{
11973 +       struct _vx_limit *limit;
11974 +       rlim_t value;
11975 +
11976 +       if (VXD_RLIMIT_COND(res))
11977 +               vxlprintk(1, "vx_cres_avail[%5d,%s,%2d]: %5ld/%5ld > %5ld + %5d",
11978 +                       (vxi ? vxi->vx_id : -1), vlimit_name[res], res,
11979 +                       (vxi ? (long)__rlim_soft(&vxi->limit, res) : -1),
11980 +                       (vxi ? (long)__rlim_hard(&vxi->limit, res) : -1),
11981 +                       (vxi ? (long)__rlim_get(&vxi->limit, res) : 0),
11982 +                       num, _file, _line);
11983 +       if (!vxi)
11984 +               return 1;
11985 +
11986 +       limit = &vxi->limit;
11987 +       value = __rlim_get(limit, res);
11988 +
11989 +       if (!__vx_cres_adjust_max(limit, res, value))
11990 +               __vx_cres_adjust_min(limit, res, value);
11991 +
11992 +       if (num == 0)
11993 +               return 1;
11994 +
11995 +       if (__rlim_soft(limit, res) == RLIM_INFINITY)
11996 +               return -1;
11997 +       if (value + num <= __rlim_soft(limit, res))
11998 +               return -1;
11999 +
12000 +       if (__rlim_hard(limit, res) == RLIM_INFINITY)
12001 +               return 1;
12002 +       if (value + num <= __rlim_hard(limit, res))
12003 +               return 1;
12004 +
12005 +       __rlim_hit(limit, res);
12006 +       return 0;
12007 +}
12008 +
12009 +
12010 +static const int VLA_RSS[] = { RLIMIT_RSS, VLIMIT_ANON, VLIMIT_MAPPED, 0 };
12011 +
12012 +static inline
12013 +rlim_t __vx_cres_array_sum(struct _vx_limit *limit, const int *array)
12014 +{
12015 +       rlim_t value, sum = 0;
12016 +       int res;
12017 +
12018 +       while ((res = *array++)) {
12019 +               value = __rlim_get(limit, res);
12020 +               __vx_cres_fixup(limit, res, value);
12021 +               sum += value;
12022 +       }
12023 +       return sum;
12024 +}
12025 +
12026 +static inline
12027 +rlim_t __vx_cres_array_fixup(struct _vx_limit *limit, const int *array)
12028 +{
12029 +       rlim_t value = __vx_cres_array_sum(limit, array + 1);
12030 +       int res = *array;
12031 +
12032 +       if (value == __rlim_get(limit, res))
12033 +               return value;
12034 +
12035 +       __rlim_set(limit, res, value);
12036 +       /* now adjust min/max */
12037 +       if (!__vx_cres_adjust_max(limit, res, value))
12038 +               __vx_cres_adjust_min(limit, res, value);
12039 +
12040 +       return value;
12041 +}
12042 +
12043 +static inline int __vx_cres_array_avail(struct vx_info *vxi,
12044 +       const int *array, int num, char *_file, int _line)
12045 +{
12046 +       struct _vx_limit *limit;
12047 +       rlim_t value = 0;
12048 +       int res;
12049 +
12050 +       if (num == 0)
12051 +               return 1;
12052 +       if (!vxi)
12053 +               return 1;
12054 +
12055 +       limit = &vxi->limit;
12056 +       res = *array;
12057 +       value = __vx_cres_array_sum(limit, array + 1);
12058 +
12059 +       __rlim_set(limit, res, value);
12060 +       __vx_cres_fixup(limit, res, value);
12061 +
12062 +       return __vx_cres_avail(vxi, res, num, _file, _line);
12063 +}
12064 +
12065 +
12066 +static inline void vx_limit_fixup(struct _vx_limit *limit, int id)
12067 +{
12068 +       rlim_t value;
12069 +       int res;
12070 +
12071 +       /* complex resources first */
12072 +       if ((id < 0) || (id == RLIMIT_RSS))
12073 +               __vx_cres_array_fixup(limit, VLA_RSS);
12074 +
12075 +       for (res = 0; res < NUM_LIMITS; res++) {
12076 +               if ((id > 0) && (res != id))
12077 +                       continue;
12078 +
12079 +               value = __rlim_get(limit, res);
12080 +               __vx_cres_fixup(limit, res, value);
12081 +
12082 +               /* not supposed to happen, maybe warn? */
12083 +               if (__rlim_rmax(limit, res) > __rlim_hard(limit, res))
12084 +                       __rlim_rmax(limit, res) = __rlim_hard(limit, res);
12085 +       }
12086 +}
12087 +
12088 +
12089 +#endif /* __KERNEL__ */
12090 +#endif /* _VX_LIMIT_INT_H */
12091 diff -NurpP --minimal linux-2.6.29/include/linux/vserver/monitor.h linux-2.6.29-vs2.3.0.36.9-pre3/include/linux/vserver/monitor.h
12092 --- linux-2.6.29/include/linux/vserver/monitor.h        1970-01-01 01:00:00.000000000 +0100
12093 +++ linux-2.6.29-vs2.3.0.36.9-pre3/include/linux/vserver/monitor.h      2009-02-22 22:54:26.000000000 +0100
12094 @@ -0,0 +1,96 @@
12095 +#ifndef _VX_MONITOR_H
12096 +#define _VX_MONITOR_H
12097 +
12098 +#include <linux/types.h>
12099 +
12100 +enum {
12101 +       VXM_UNUSED = 0,
12102 +
12103 +       VXM_SYNC = 0x10,
12104 +
12105 +       VXM_UPDATE = 0x20,
12106 +       VXM_UPDATE_1,
12107 +       VXM_UPDATE_2,
12108 +
12109 +       VXM_RQINFO_1 = 0x24,
12110 +       VXM_RQINFO_2,
12111 +
12112 +       VXM_ACTIVATE = 0x40,
12113 +       VXM_DEACTIVATE,
12114 +       VXM_IDLE,
12115 +
12116 +       VXM_HOLD = 0x44,
12117 +       VXM_UNHOLD,
12118 +
12119 +       VXM_MIGRATE = 0x48,
12120 +       VXM_RESCHED,
12121 +
12122 +       /* all other bits are flags */
12123 +       VXM_SCHED = 0x80,
12124 +};
12125 +
12126 +struct _vxm_update_1 {
12127 +       uint32_t tokens_max;
12128 +       uint32_t fill_rate;
12129 +       uint32_t interval;
12130 +};
12131 +
12132 +struct _vxm_update_2 {
12133 +       uint32_t tokens_min;
12134 +       uint32_t fill_rate;
12135 +       uint32_t interval;
12136 +};
12137 +
12138 +struct _vxm_rqinfo_1 {
12139 +       uint16_t running;
12140 +       uint16_t onhold;
12141 +       uint16_t iowait;
12142 +       uint16_t uintr;
12143 +       uint32_t idle_tokens;
12144 +};
12145 +
12146 +struct _vxm_rqinfo_2 {
12147 +       uint32_t norm_time;
12148 +       uint32_t idle_time;
12149 +       uint32_t idle_skip;
12150 +};
12151 +
12152 +struct _vxm_sched {
12153 +       uint32_t tokens;
12154 +       uint32_t norm_time;
12155 +       uint32_t idle_time;
12156 +};
12157 +
12158 +struct _vxm_task {
12159 +       uint16_t pid;
12160 +       uint16_t state;
12161 +};
12162 +
12163 +struct _vxm_event {
12164 +       uint32_t jif;
12165 +       union {
12166 +               uint32_t seq;
12167 +               uint32_t sec;
12168 +       };
12169 +       union {
12170 +               uint32_t tokens;
12171 +               uint32_t nsec;
12172 +               struct _vxm_task tsk;
12173 +       };
12174 +};
12175 +
12176 +struct _vx_mon_entry {
12177 +       uint16_t type;
12178 +       uint16_t xid;
12179 +       union {
12180 +               struct _vxm_event ev;
12181 +               struct _vxm_sched sd;
12182 +               struct _vxm_update_1 u1;
12183 +               struct _vxm_update_2 u2;
12184 +               struct _vxm_rqinfo_1 q1;
12185 +               struct _vxm_rqinfo_2 q2;
12186 +       };
12187 +};
12188 +
12189 +
12190 +#endif /* _VX_MONITOR_H */
12191 diff -NurpP --minimal linux-2.6.29/include/linux/vserver/network_cmd.h linux-2.6.29-vs2.3.0.36.9-pre3/include/linux/vserver/network_cmd.h
12192 --- linux-2.6.29/include/linux/vserver/network_cmd.h    1970-01-01 01:00:00.000000000 +0100
12193 +++ linux-2.6.29-vs2.3.0.36.9-pre3/include/linux/vserver/network_cmd.h  2009-02-22 22:54:26.000000000 +0100
12194 @@ -0,0 +1,150 @@
12195 +#ifndef _VX_NETWORK_CMD_H
12196 +#define _VX_NETWORK_CMD_H
12197 +
12198 +
12199 +/* vinfo commands */
12200 +
12201 +#define VCMD_task_nid          VC_CMD(VINFO, 2, 0)
12202 +
12203 +#ifdef __KERNEL__
12204 +extern int vc_task_nid(uint32_t);
12205 +
12206 +#endif /* __KERNEL__ */
12207 +
12208 +#define VCMD_nx_info           VC_CMD(VINFO, 6, 0)
12209 +
12210 +struct vcmd_nx_info_v0 {
12211 +       uint32_t nid;
12212 +       /* more to come */
12213 +};
12214 +
12215 +#ifdef __KERNEL__
12216 +extern int vc_nx_info(struct nx_info *, void __user *);
12217 +
12218 +#endif /* __KERNEL__ */
12219 +
12220 +#include <linux/in.h>
12221 +#include <linux/in6.h>
12222 +
12223 +#define VCMD_net_create_v0     VC_CMD(VNET, 1, 0)
12224 +#define VCMD_net_create                VC_CMD(VNET, 1, 1)
12225 +
12226 +struct  vcmd_net_create {
12227 +       uint64_t flagword;
12228 +};
12229 +
12230 +#define VCMD_net_migrate       VC_CMD(NETMIG, 1, 0)
12231 +
12232 +#define VCMD_net_add           VC_CMD(NETALT, 1, 0)
12233 +#define VCMD_net_remove                VC_CMD(NETALT, 2, 0)
12234 +
12235 +struct vcmd_net_addr_v0 {
12236 +       uint16_t type;
12237 +       uint16_t count;
12238 +       struct in_addr ip[4];
12239 +       struct in_addr mask[4];
12240 +};
12241 +
12242 +#define VCMD_net_add_ipv4      VC_CMD(NETALT, 1, 1)
12243 +#define VCMD_net_remove_ipv4   VC_CMD(NETALT, 2, 1)
12244 +
12245 +struct vcmd_net_addr_ipv4_v1 {
12246 +       uint16_t type;
12247 +       uint16_t flags;
12248 +       struct in_addr ip;
12249 +       struct in_addr mask;
12250 +};
12251 +
12252 +#define VCMD_net_add_ipv6      VC_CMD(NETALT, 3, 1)
12253 +#define VCMD_net_remove_ipv6   VC_CMD(NETALT, 4, 1)
12254 +
12255 +struct vcmd_net_addr_ipv6_v1 {
12256 +       uint16_t type;
12257 +       uint16_t flags;
12258 +       uint32_t prefix;
12259 +       struct in6_addr ip;
12260 +       struct in6_addr mask;
12261 +};
12262 +
12263 +#define VCMD_add_match_ipv4    VC_CMD(NETALT, 5, 0)
12264 +#define VCMD_get_match_ipv4    VC_CMD(NETALT, 6, 0)
12265 +
12266 +struct vcmd_match_ipv4_v0 {
12267 +       uint16_t type;
12268 +       uint16_t flags;
12269 +       uint16_t parent;
12270 +       uint16_t prefix;
12271 +       struct in_addr ip;
12272 +       struct in_addr ip2;
12273 +       struct in_addr mask;
12274 +};
12275 +
12276 +#define VCMD_add_match_ipv6    VC_CMD(NETALT, 7, 0)
12277 +#define VCMD_get_match_ipv6    VC_CMD(NETALT, 8, 0)
12278 +
12279 +struct vcmd_match_ipv6_v0 {
12280 +       uint16_t type;
12281 +       uint16_t flags;
12282 +       uint16_t parent;
12283 +       uint16_t prefix;
12284 +       struct in6_addr ip;
12285 +       struct in6_addr ip2;
12286 +       struct in6_addr mask;
12287 +};
12288 +
12289 +
12290 +#ifdef __KERNEL__
12291 +extern int vc_net_create(uint32_t, void __user *);
12292 +extern int vc_net_migrate(struct nx_info *, void __user *);
12293 +
12294 +extern int vc_net_add(struct nx_info *, void __user *);
12295 +extern int vc_net_remove(struct nx_info *, void __user *);
12296 +
12297 +extern int vc_net_add_ipv4(struct nx_info *, void __user *);
12298 +extern int vc_net_remove_ipv4(struct nx_info *, void __user *);
12299 +
12300 +extern int vc_net_add_ipv6(struct nx_info *, void __user *);
12301 +extern int vc_net_remove_ipv6(struct nx_info *, void __user *);
12302 +
12303 +extern int vc_add_match_ipv4(struct nx_info *, void __user *);
12304 +extern int vc_get_match_ipv4(struct nx_info *, void __user *);
12305 +
12306 +extern int vc_add_match_ipv6(struct nx_info *, void __user *);
12307 +extern int vc_get_match_ipv6(struct nx_info *, void __user *);
12308 +
12309 +#endif /* __KERNEL__ */
12310 +
12311 +
12312 +/* flag commands */
12313 +
12314 +#define VCMD_get_nflags                VC_CMD(FLAGS, 5, 0)
12315 +#define VCMD_set_nflags                VC_CMD(FLAGS, 6, 0)
12316 +
12317 +struct vcmd_net_flags_v0 {
12318 +       uint64_t flagword;
12319 +       uint64_t mask;
12320 +};
12321 +
12322 +#ifdef __KERNEL__
12323 +extern int vc_get_nflags(struct nx_info *, void __user *);
12324 +extern int vc_set_nflags(struct nx_info *, void __user *);
12325 +
12326 +#endif /* __KERNEL__ */
12327 +
12328 +
12329 +/* network caps commands */
12330 +
12331 +#define VCMD_get_ncaps         VC_CMD(FLAGS, 7, 0)
12332 +#define VCMD_set_ncaps         VC_CMD(FLAGS, 8, 0)
12333 +
12334 +struct vcmd_net_caps_v0 {
12335 +       uint64_t ncaps;
12336 +       uint64_t cmask;
12337 +};
12338 +
12339 +#ifdef __KERNEL__
12340 +extern int vc_get_ncaps(struct nx_info *, void __user *);
12341 +extern int vc_set_ncaps(struct nx_info *, void __user *);
12342 +
12343 +#endif /* __KERNEL__ */
12344 +#endif /* _VX_CONTEXT_CMD_H */
12345 diff -NurpP --minimal linux-2.6.29/include/linux/vserver/network.h linux-2.6.29-vs2.3.0.36.9-pre3/include/linux/vserver/network.h
12346 --- linux-2.6.29/include/linux/vserver/network.h        1970-01-01 01:00:00.000000000 +0100
12347 +++ linux-2.6.29-vs2.3.0.36.9-pre3/include/linux/vserver/network.h      2009-02-22 22:54:26.000000000 +0100
12348 @@ -0,0 +1,146 @@
12349 +#ifndef _VX_NETWORK_H
12350 +#define _VX_NETWORK_H
12351 +
12352 +#include <linux/types.h>
12353 +
12354 +
12355 +#define MAX_N_CONTEXT  65535   /* Arbitrary limit */
12356 +
12357 +
12358 +/* network flags */
12359 +
12360 +#define NXF_INFO_PRIVATE       0x00000008
12361 +
12362 +#define NXF_SINGLE_IP          0x00000100
12363 +#define NXF_LBACK_REMAP                0x00000200
12364 +#define NXF_LBACK_ALLOW                0x00000400
12365 +
12366 +#define NXF_HIDE_NETIF         0x02000000
12367 +#define NXF_HIDE_LBACK         0x04000000
12368 +
12369 +#define NXF_STATE_SETUP                (1ULL << 32)
12370 +#define NXF_STATE_ADMIN                (1ULL << 34)
12371 +
12372 +#define NXF_SC_HELPER          (1ULL << 36)
12373 +#define NXF_PERSISTENT         (1ULL << 38)
12374 +
12375 +#define NXF_ONE_TIME           (0x0005ULL << 32)
12376 +
12377 +
12378 +#define        NXF_INIT_SET            (__nxf_init_set())
12379 +
12380 +static inline uint64_t __nxf_init_set(void) {
12381 +       return    NXF_STATE_ADMIN
12382 +#ifdef CONFIG_VSERVER_AUTO_LBACK
12383 +               | NXF_LBACK_REMAP
12384 +               | NXF_HIDE_LBACK
12385 +#endif
12386 +#ifdef CONFIG_VSERVER_AUTO_SINGLE
12387 +               | NXF_SINGLE_IP
12388 +#endif
12389 +               | NXF_HIDE_NETIF;
12390 +}
12391 +
12392 +
12393 +/* network caps */
12394 +
12395 +#define NXC_TUN_CREATE         0x00000001
12396 +
12397 +#define NXC_RAW_ICMP           0x00000100
12398 +
12399 +
12400 +/* address types */
12401 +
12402 +#define NXA_TYPE_IPV4          0x0001
12403 +#define NXA_TYPE_IPV6          0x0002
12404 +
12405 +#define NXA_TYPE_NONE          0x0000
12406 +#define NXA_TYPE_ANY           0x00FF
12407 +
12408 +#define NXA_TYPE_ADDR          0x0010
12409 +#define NXA_TYPE_MASK          0x0020
12410 +#define NXA_TYPE_RANGE         0x0040
12411 +
12412 +#define NXA_MASK_ALL           (NXA_TYPE_ADDR | NXA_TYPE_MASK | NXA_TYPE_RANGE)
12413 +
12414 +#define NXA_MOD_BCAST          0x0100
12415 +#define NXA_MOD_LBACK          0x0200
12416 +
12417 +#define NXA_LOOPBACK           0x1000
12418 +
12419 +#define NXA_MASK_BIND          (NXA_MASK_ALL | NXA_MOD_BCAST | NXA_MOD_LBACK)
12420 +#define NXA_MASK_SHOW          (NXA_MASK_ALL | NXA_LOOPBACK)
12421 +
12422 +#ifdef __KERNEL__
12423 +
12424 +#include <linux/list.h>
12425 +#include <linux/spinlock.h>
12426 +#include <linux/rcupdate.h>
12427 +#include <linux/in.h>
12428 +#include <linux/in6.h>
12429 +#include <asm/atomic.h>
12430 +
12431 +struct nx_addr_v4 {
12432 +       struct nx_addr_v4 *next;
12433 +       struct in_addr ip[2];
12434 +       struct in_addr mask;
12435 +       uint16_t type;
12436 +       uint16_t flags;
12437 +};
12438 +
12439 +struct nx_addr_v6 {
12440 +       struct nx_addr_v6 *next;
12441 +       struct in6_addr ip;
12442 +       struct in6_addr mask;
12443 +       uint32_t prefix;
12444 +       uint16_t type;
12445 +       uint16_t flags;
12446 +};
12447 +
12448 +struct nx_info {
12449 +       struct hlist_node nx_hlist;     /* linked list of nxinfos */
12450 +       nid_t nx_id;                    /* vnet id */
12451 +       atomic_t nx_usecnt;             /* usage count */
12452 +       atomic_t nx_tasks;              /* tasks count */
12453 +       int nx_state;                   /* context state */
12454 +
12455 +       uint64_t nx_flags;              /* network flag word */
12456 +       uint64_t nx_ncaps;              /* network capabilities */
12457 +
12458 +       struct in_addr v4_lback;        /* Loopback address */
12459 +       struct in_addr v4_bcast;        /* Broadcast address */
12460 +       struct nx_addr_v4 v4;           /* First/Single ipv4 address */
12461 +#ifdef CONFIG_IPV6
12462 +       struct nx_addr_v6 v6;           /* First/Single ipv6 address */
12463 +#endif
12464 +       char nx_name[65];               /* network context name */
12465 +};
12466 +
12467 +
12468 +/* status flags */
12469 +
12470 +#define NXS_HASHED      0x0001
12471 +#define NXS_SHUTDOWN    0x0100
12472 +#define NXS_RELEASED    0x8000
12473 +
12474 +extern struct nx_info *lookup_nx_info(int);
12475 +
12476 +extern int get_nid_list(int, unsigned int *, int);
12477 +extern int nid_is_hashed(nid_t);
12478 +
12479 +extern int nx_migrate_task(struct task_struct *, struct nx_info *);
12480 +
12481 +extern long vs_net_change(struct nx_info *, unsigned int);
12482 +
12483 +struct sock;
12484 +
12485 +
12486 +#define NX_IPV4(n)     ((n)->v4.type != NXA_TYPE_NONE)
12487 +#ifdef  CONFIG_IPV6
12488 +#define NX_IPV6(n)     ((n)->v6.type != NXA_TYPE_NONE)
12489 +#else
12490 +#define NX_IPV6(n)     (0)
12491 +#endif
12492 +
12493 +#endif /* __KERNEL__ */
12494 +#endif /* _VX_NETWORK_H */
12495 diff -NurpP --minimal linux-2.6.29/include/linux/vserver/percpu.h linux-2.6.29-vs2.3.0.36.9-pre3/include/linux/vserver/percpu.h
12496 --- linux-2.6.29/include/linux/vserver/percpu.h 1970-01-01 01:00:00.000000000 +0100
12497 +++ linux-2.6.29-vs2.3.0.36.9-pre3/include/linux/vserver/percpu.h       2009-02-22 22:54:26.000000000 +0100
12498 @@ -0,0 +1,14 @@
12499 +#ifndef _VX_PERCPU_H
12500 +#define _VX_PERCPU_H
12501 +
12502 +#include "cvirt_def.h"
12503 +#include "sched_def.h"
12504 +
12505 +struct _vx_percpu {
12506 +       struct _vx_cvirt_pc cvirt;
12507 +       struct _vx_sched_pc sched;
12508 +};
12509 +
12510 +#define        PERCPU_PERCTX   (sizeof(struct _vx_percpu))
12511 +
12512 +#endif /* _VX_PERCPU_H */
12513 diff -NurpP --minimal linux-2.6.29/include/linux/vserver/pid.h linux-2.6.29-vs2.3.0.36.9-pre3/include/linux/vserver/pid.h
12514 --- linux-2.6.29/include/linux/vserver/pid.h    1970-01-01 01:00:00.000000000 +0100
12515 +++ linux-2.6.29-vs2.3.0.36.9-pre3/include/linux/vserver/pid.h  2009-02-22 22:54:26.000000000 +0100
12516 @@ -0,0 +1,51 @@
12517 +#ifndef _VSERVER_PID_H
12518 +#define _VSERVER_PID_H
12519 +
12520 +/* pid faking stuff */
12521 +
12522 +#define vx_info_map_pid(v, p) \
12523 +       __vx_info_map_pid((v), (p), __func__, __FILE__, __LINE__)
12524 +#define vx_info_map_tgid(v,p)  vx_info_map_pid(v,p)
12525 +#define vx_map_pid(p) vx_info_map_pid(current->vx_info, p)
12526 +#define vx_map_tgid(p) vx_map_pid(p)
12527 +
12528 +static inline int __vx_info_map_pid(struct vx_info *vxi, int pid,
12529 +       const char *func, const char *file, int line)
12530 +{
12531 +       if (vx_info_flags(vxi, VXF_INFO_INIT, 0)) {
12532 +               vxfprintk(VXD_CBIT(cvirt, 2),
12533 +                       "vx_map_tgid: %p/%llx: %d -> %d",
12534 +                       vxi, (long long)vxi->vx_flags, pid,
12535 +                       (pid && pid == vxi->vx_initpid) ? 1 : pid,
12536 +                       func, file, line);
12537 +               if (pid == 0)
12538 +                       return 0;
12539 +               if (pid == vxi->vx_initpid)
12540 +                       return 1;
12541 +       }
12542 +       return pid;
12543 +}
12544 +
12545 +#define vx_info_rmap_pid(v, p) \
12546 +       __vx_info_rmap_pid((v), (p), __func__, __FILE__, __LINE__)
12547 +#define vx_rmap_pid(p) vx_info_rmap_pid(current->vx_info, p)
12548 +#define vx_rmap_tgid(p) vx_rmap_pid(p)
12549 +
12550 +static inline int __vx_info_rmap_pid(struct vx_info *vxi, int pid,
12551 +       const char *func, const char *file, int line)
12552 +{
12553 +       if (vx_info_flags(vxi, VXF_INFO_INIT, 0)) {
12554 +               vxfprintk(VXD_CBIT(cvirt, 2),
12555 +                       "vx_rmap_tgid: %p/%llx: %d -> %d",
12556 +                       vxi, (long long)vxi->vx_flags, pid,
12557 +                       (pid == 1) ? vxi->vx_initpid : pid,
12558 +                       func, file, line);
12559 +               if ((pid == 1) && vxi->vx_initpid)
12560 +                       return vxi->vx_initpid;
12561 +               if (pid == vxi->vx_initpid)
12562 +                       return ~0U;
12563 +       }
12564 +       return pid;
12565 +}
12566 +
12567 +#endif
12568 diff -NurpP --minimal linux-2.6.29/include/linux/vserver/sched_cmd.h linux-2.6.29-vs2.3.0.36.9-pre3/include/linux/vserver/sched_cmd.h
12569 --- linux-2.6.29/include/linux/vserver/sched_cmd.h      1970-01-01 01:00:00.000000000 +0100
12570 +++ linux-2.6.29-vs2.3.0.36.9-pre3/include/linux/vserver/sched_cmd.h    2009-02-22 22:54:26.000000000 +0100
12571 @@ -0,0 +1,108 @@
12572 +#ifndef _VX_SCHED_CMD_H
12573 +#define _VX_SCHED_CMD_H
12574 +
12575 +
12576 +/*  sched vserver commands */
12577 +
12578 +#define VCMD_set_sched_v2      VC_CMD(SCHED, 1, 2)
12579 +#define VCMD_set_sched_v3      VC_CMD(SCHED, 1, 3)
12580 +#define VCMD_set_sched_v4      VC_CMD(SCHED, 1, 4)
12581 +
12582 +struct vcmd_set_sched_v2 {
12583 +       int32_t fill_rate;
12584 +       int32_t interval;
12585 +       int32_t tokens;
12586 +       int32_t tokens_min;
12587 +       int32_t tokens_max;
12588 +       uint64_t cpu_mask;
12589 +};
12590 +
12591 +struct vcmd_set_sched_v3 {
12592 +       uint32_t set_mask;
12593 +       int32_t fill_rate;
12594 +       int32_t interval;
12595 +       int32_t tokens;
12596 +       int32_t tokens_min;
12597 +       int32_t tokens_max;
12598 +       int32_t priority_bias;
12599 +};
12600 +
12601 +struct vcmd_set_sched_v4 {
12602 +       uint32_t set_mask;
12603 +       int32_t fill_rate;
12604 +       int32_t interval;
12605 +       int32_t tokens;
12606 +       int32_t tokens_min;
12607 +       int32_t tokens_max;
12608 +       int32_t prio_bias;
12609 +       int32_t cpu_id;
12610 +       int32_t bucket_id;
12611 +};
12612 +
12613 +#define VCMD_set_sched         VC_CMD(SCHED, 1, 5)
12614 +#define VCMD_get_sched         VC_CMD(SCHED, 2, 5)
12615 +
12616 +struct vcmd_sched_v5 {
12617 +       uint32_t mask;
12618 +       int32_t cpu_id;
12619 +       int32_t bucket_id;
12620 +       int32_t fill_rate[2];
12621 +       int32_t interval[2];
12622 +       int32_t tokens;
12623 +       int32_t tokens_min;
12624 +       int32_t tokens_max;
12625 +       int32_t prio_bias;
12626 +};
12627 +
12628 +#define VXSM_FILL_RATE         0x0001
12629 +#define VXSM_INTERVAL          0x0002
12630 +#define VXSM_FILL_RATE2                0x0004
12631 +#define VXSM_INTERVAL2         0x0008
12632 +#define VXSM_TOKENS            0x0010
12633 +#define VXSM_TOKENS_MIN                0x0020
12634 +#define VXSM_TOKENS_MAX                0x0040
12635 +#define VXSM_PRIO_BIAS         0x0100
12636 +
12637 +#define VXSM_IDLE_TIME         0x0200
12638 +#define VXSM_FORCE             0x0400
12639 +
12640 +#define        VXSM_V3_MASK            0x0173
12641 +#define        VXSM_SET_MASK           0x01FF
12642 +
12643 +#define VXSM_CPU_ID            0x1000
12644 +#define VXSM_BUCKET_ID         0x2000
12645 +
12646 +#define VXSM_MSEC              0x4000
12647 +
12648 +#define SCHED_KEEP             (-2)    /* only for v2 */
12649 +
12650 +#ifdef __KERNEL__
12651 +
12652 +#include <linux/compiler.h>
12653 +
12654 +extern int vc_set_sched_v2(struct vx_info *, void __user *);
12655 +extern int vc_set_sched_v3(struct vx_info *, void __user *);
12656 +extern int vc_set_sched_v4(struct vx_info *, void __user *);
12657 +extern int vc_set_sched(struct vx_info *, void __user *);
12658 +extern int vc_get_sched(struct vx_info *, void __user *);
12659 +
12660 +#endif /* __KERNEL__ */
12661 +
12662 +#define VCMD_sched_info                VC_CMD(SCHED, 3, 0)
12663 +
12664 +struct vcmd_sched_info {
12665 +       int32_t cpu_id;
12666 +       int32_t bucket_id;
12667 +       uint64_t user_msec;
12668 +       uint64_t sys_msec;
12669 +       uint64_t hold_msec;
12670 +       uint32_t token_usec;
12671 +       int32_t vavavoom;
12672 +};
12673 +
12674 +#ifdef __KERNEL__
12675 +
12676 +extern int vc_sched_info(struct vx_info *, void __user *);
12677 +
12678 +#endif /* __KERNEL__ */
12679 +#endif /* _VX_SCHED_CMD_H */
12680 diff -NurpP --minimal linux-2.6.29/include/linux/vserver/sched_def.h linux-2.6.29-vs2.3.0.36.9-pre3/include/linux/vserver/sched_def.h
12681 --- linux-2.6.29/include/linux/vserver/sched_def.h      1970-01-01 01:00:00.000000000 +0100
12682 +++ linux-2.6.29-vs2.3.0.36.9-pre3/include/linux/vserver/sched_def.h    2009-02-22 22:54:26.000000000 +0100
12683 @@ -0,0 +1,68 @@
12684 +#ifndef _VX_SCHED_DEF_H
12685 +#define _VX_SCHED_DEF_H
12686 +
12687 +#include <linux/spinlock.h>
12688 +#include <linux/jiffies.h>
12689 +#include <linux/cpumask.h>
12690 +#include <asm/atomic.h>
12691 +#include <asm/param.h>
12692 +
12693 +
12694 +/* context sub struct */
12695 +
12696 +struct _vx_sched {
12697 +       spinlock_t tokens_lock;         /* lock for token bucket */
12698 +
12699 +       int tokens;                     /* number of CPU tokens */
12700 +       int fill_rate[2];               /* Fill rate: add X tokens... */
12701 +       int interval[2];                /* Divisor:   per Y jiffies   */
12702 +       int tokens_min;                 /* Limit:     minimum for unhold */
12703 +       int tokens_max;                 /* Limit:     no more than N tokens */
12704 +
12705 +       int prio_bias;                  /* bias offset for priority */
12706 +
12707 +       unsigned update_mask;           /* which features should be updated */
12708 +       cpumask_t update;               /* CPUs which should update */
12709 +};
12710 +
12711 +struct _vx_sched_pc {
12712 +       int tokens;                     /* number of CPU tokens */
12713 +       int flags;                      /* bucket flags */
12714 +
12715 +       int fill_rate[2];               /* Fill rate: add X tokens... */
12716 +       int interval[2];                /* Divisor:   per Y jiffies   */
12717 +       int tokens_min;                 /* Limit:     minimum for unhold */
12718 +       int tokens_max;                 /* Limit:     no more than N tokens */
12719 +
12720 +       int prio_bias;                  /* bias offset for priority */
12721 +       int vavavoom;                   /* last calculated vavavoom */
12722 +
12723 +       unsigned long norm_time;        /* last time accounted */
12724 +       unsigned long idle_time;        /* non linear time for fair sched */
12725 +       unsigned long token_time;       /* token time for accounting */
12726 +       unsigned long onhold;           /* jiffies when put on hold */
12727 +
12728 +       uint64_t user_ticks;            /* token tick events */
12729 +       uint64_t sys_ticks;             /* token tick events */
12730 +       uint64_t hold_ticks;            /* token ticks paused */
12731 +};
12732 +
12733 +
12734 +#define VXSF_ONHOLD    0x0001
12735 +#define VXSF_IDLE_TIME 0x0100
12736 +
12737 +#ifdef CONFIG_VSERVER_DEBUG
12738 +
12739 +static inline void __dump_vx_sched(struct _vx_sched *sched)
12740 +{
12741 +       printk("\t_vx_sched:\n");
12742 +       printk("\t tokens: %4d/%4d, %4d/%4d, %4d, %4d\n",
12743 +               sched->fill_rate[0], sched->interval[0],
12744 +               sched->fill_rate[1], sched->interval[1],
12745 +               sched->tokens_min, sched->tokens_max);
12746 +       printk("\t priority = %4d\n", sched->prio_bias);
12747 +}
12748 +
12749 +#endif
12750 +
12751 +#endif /* _VX_SCHED_DEF_H */
12752 diff -NurpP --minimal linux-2.6.29/include/linux/vserver/sched.h linux-2.6.29-vs2.3.0.36.9-pre3/include/linux/vserver/sched.h
12753 --- linux-2.6.29/include/linux/vserver/sched.h  1970-01-01 01:00:00.000000000 +0100
12754 +++ linux-2.6.29-vs2.3.0.36.9-pre3/include/linux/vserver/sched.h        2009-02-22 22:54:26.000000000 +0100
12755 @@ -0,0 +1,26 @@
12756 +#ifndef _VX_SCHED_H
12757 +#define _VX_SCHED_H
12758 +
12759 +
12760 +#ifdef __KERNEL__
12761 +
12762 +struct timespec;
12763 +
12764 +void vx_vsi_uptime(struct timespec *, struct timespec *);
12765 +
12766 +
12767 +struct vx_info;
12768 +
12769 +void vx_update_load(struct vx_info *);
12770 +
12771 +
12772 +int vx_tokens_recalc(struct _vx_sched_pc *,
12773 +       unsigned long *, unsigned long *, int [2]);
12774 +
12775 +void vx_update_sched_param(struct _vx_sched *sched,
12776 +       struct _vx_sched_pc *sched_pc);
12777 +
12778 +#endif /* __KERNEL__ */
12779 +#else  /* _VX_SCHED_H */
12780 +#warning duplicate inclusion
12781 +#endif /* _VX_SCHED_H */
12782 diff -NurpP --minimal linux-2.6.29/include/linux/vserver/signal_cmd.h linux-2.6.29-vs2.3.0.36.9-pre3/include/linux/vserver/signal_cmd.h
12783 --- linux-2.6.29/include/linux/vserver/signal_cmd.h     1970-01-01 01:00:00.000000000 +0100
12784 +++ linux-2.6.29-vs2.3.0.36.9-pre3/include/linux/vserver/signal_cmd.h   2009-02-22 22:54:26.000000000 +0100
12785 @@ -0,0 +1,43 @@
12786 +#ifndef _VX_SIGNAL_CMD_H
12787 +#define _VX_SIGNAL_CMD_H
12788 +
12789 +
12790 +/*  signalling vserver commands */
12791 +
12792 +#define VCMD_ctx_kill          VC_CMD(PROCTRL, 1, 0)
12793 +#define VCMD_wait_exit         VC_CMD(EVENT, 99, 0)
12794 +
12795 +struct vcmd_ctx_kill_v0 {
12796 +       int32_t pid;
12797 +       int32_t sig;
12798 +};
12799 +
12800 +struct vcmd_wait_exit_v0 {
12801 +       int32_t reboot_cmd;
12802 +       int32_t exit_code;
12803 +};
12804 +
12805 +#ifdef __KERNEL__
12806 +
12807 +extern int vc_ctx_kill(struct vx_info *, void __user *);
12808 +extern int vc_wait_exit(struct vx_info *, void __user *);
12809 +
12810 +#endif /* __KERNEL__ */
12811 +
12812 +/*  process alteration commands */
12813 +
12814 +#define VCMD_get_pflags                VC_CMD(PROCALT, 5, 0)
12815 +#define VCMD_set_pflags                VC_CMD(PROCALT, 6, 0)
12816 +
12817 +struct vcmd_pflags_v0 {
12818 +       uint32_t flagword;
12819 +       uint32_t mask;
12820 +};
12821 +
12822 +#ifdef __KERNEL__
12823 +
12824 +extern int vc_get_pflags(uint32_t pid, void __user *);
12825 +extern int vc_set_pflags(uint32_t pid, void __user *);
12826 +
12827 +#endif /* __KERNEL__ */
12828 +#endif /* _VX_SIGNAL_CMD_H */
12829 diff -NurpP --minimal linux-2.6.29/include/linux/vserver/signal.h linux-2.6.29-vs2.3.0.36.9-pre3/include/linux/vserver/signal.h
12830 --- linux-2.6.29/include/linux/vserver/signal.h 1970-01-01 01:00:00.000000000 +0100
12831 +++ linux-2.6.29-vs2.3.0.36.9-pre3/include/linux/vserver/signal.h       2009-02-22 22:54:26.000000000 +0100
12832 @@ -0,0 +1,14 @@
12833 +#ifndef _VX_SIGNAL_H
12834 +#define _VX_SIGNAL_H
12835 +
12836 +
12837 +#ifdef __KERNEL__
12838 +
12839 +struct vx_info;
12840 +
12841 +int vx_info_kill(struct vx_info *, int, int);
12842 +
12843 +#endif /* __KERNEL__ */
12844 +#else  /* _VX_SIGNAL_H */
12845 +#warning duplicate inclusion
12846 +#endif /* _VX_SIGNAL_H */
12847 diff -NurpP --minimal linux-2.6.29/include/linux/vserver/space_cmd.h linux-2.6.29-vs2.3.0.36.9-pre3/include/linux/vserver/space_cmd.h
12848 --- linux-2.6.29/include/linux/vserver/space_cmd.h      1970-01-01 01:00:00.000000000 +0100
12849 +++ linux-2.6.29-vs2.3.0.36.9-pre3/include/linux/vserver/space_cmd.h    2009-02-22 22:54:26.000000000 +0100
12850 @@ -0,0 +1,38 @@
12851 +#ifndef _VX_SPACE_CMD_H
12852 +#define _VX_SPACE_CMD_H
12853 +
12854 +
12855 +#define VCMD_enter_space_v0    VC_CMD(PROCALT, 1, 0)
12856 +#define VCMD_enter_space_v1    VC_CMD(PROCALT, 1, 1)
12857 +#define VCMD_enter_space       VC_CMD(PROCALT, 1, 2)
12858 +
12859 +#define VCMD_set_space_v0      VC_CMD(PROCALT, 3, 0)
12860 +#define VCMD_set_space_v1      VC_CMD(PROCALT, 3, 1)
12861 +#define VCMD_set_space         VC_CMD(PROCALT, 3, 2)
12862 +
12863 +#define VCMD_get_space_mask_v0 VC_CMD(PROCALT, 4, 0)
12864 +
12865 +#define VCMD_get_space_mask    VC_CMD(VSPACE, 0, 1)
12866 +#define VCMD_get_space_default VC_CMD(VSPACE, 1, 0)
12867 +
12868 +
12869 +struct vcmd_space_mask_v1 {
12870 +       uint64_t mask;
12871 +};
12872 +
12873 +struct vcmd_space_mask_v2 {
12874 +       uint64_t mask;
12875 +       uint32_t index;
12876 +};
12877 +
12878 +
12879 +#ifdef __KERNEL__
12880 +
12881 +extern int vc_enter_space_v1(struct vx_info *, void __user *);
12882 +extern int vc_set_space_v1(struct vx_info *, void __user *);
12883 +extern int vc_enter_space(struct vx_info *, void __user *);
12884 +extern int vc_set_space(struct vx_info *, void __user *);
12885 +extern int vc_get_space_mask(void __user *, int);
12886 +
12887 +#endif /* __KERNEL__ */
12888 +#endif /* _VX_SPACE_CMD_H */
12889 diff -NurpP --minimal linux-2.6.29/include/linux/vserver/space.h linux-2.6.29-vs2.3.0.36.9-pre3/include/linux/vserver/space.h
12890 --- linux-2.6.29/include/linux/vserver/space.h  1970-01-01 01:00:00.000000000 +0100
12891 +++ linux-2.6.29-vs2.3.0.36.9-pre3/include/linux/vserver/space.h        2009-02-22 22:54:26.000000000 +0100
12892 @@ -0,0 +1,12 @@
12893 +#ifndef _VX_SPACE_H
12894 +#define _VX_SPACE_H
12895 +
12896 +#include <linux/types.h>
12897 +
12898 +struct vx_info;
12899 +
12900 +int vx_set_space(struct vx_info *vxi, unsigned long mask, unsigned index);
12901 +
12902 +#else  /* _VX_SPACE_H */
12903 +#warning duplicate inclusion
12904 +#endif /* _VX_SPACE_H */
12905 diff -NurpP --minimal linux-2.6.29/include/linux/vserver/switch.h linux-2.6.29-vs2.3.0.36.9-pre3/include/linux/vserver/switch.h
12906 --- linux-2.6.29/include/linux/vserver/switch.h 1970-01-01 01:00:00.000000000 +0100
12907 +++ linux-2.6.29-vs2.3.0.36.9-pre3/include/linux/vserver/switch.h       2009-02-22 22:54:26.000000000 +0100
12908 @@ -0,0 +1,98 @@
12909 +#ifndef _VX_SWITCH_H
12910 +#define _VX_SWITCH_H
12911 +
12912 +#include <linux/types.h>
12913 +
12914 +
12915 +#define VC_CATEGORY(c)         (((c) >> 24) & 0x3F)
12916 +#define VC_COMMAND(c)          (((c) >> 16) & 0xFF)
12917 +#define VC_VERSION(c)          ((c) & 0xFFF)
12918 +
12919 +#define VC_CMD(c, i, v)                ((((VC_CAT_ ## c) & 0x3F) << 24) \
12920 +                               | (((i) & 0xFF) << 16) | ((v) & 0xFFF))
12921 +
12922 +/*
12923 +
12924 +  Syscall Matrix V2.8
12925 +
12926 +        |VERSION|CREATE |MODIFY |MIGRATE|CONTROL|EXPERIM| |SPECIAL|SPECIAL|
12927 +        |STATS  |DESTROY|ALTER  |CHANGE |LIMIT  |TEST   | |       |       |
12928 +        |INFO   |SETUP  |       |MOVE   |       |       | |       |       |
12929 +  -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
12930 +  SYSTEM |VERSION|VSETUP |VHOST  |       |       |       | |DEVICE |       |
12931 +  HOST   |     00|     01|     02|     03|     04|     05| |     06|     07|
12932 +  -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
12933 +  CPU    |       |VPROC  |PROCALT|PROCMIG|PROCTRL|       | |SCHED. |       |
12934 +  PROCESS|     08|     09|     10|     11|     12|     13| |     14|     15|
12935 +  -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
12936 +  MEMORY |       |       |       |       |MEMCTRL|       | |SWAP   |       |
12937 +        |     16|     17|     18|     19|     20|     21| |     22|     23|
12938 +  -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
12939 +  NETWORK|       |VNET   |NETALT |NETMIG |NETCTL |       | |SERIAL |       |
12940 +        |     24|     25|     26|     27|     28|     29| |     30|     31|
12941 +  -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
12942 +  DISK   |       |       |       |TAGMIG |DLIMIT |       | |INODE  |       |
12943 +  VFS    |     32|     33|     34|     35|     36|     37| |     38|     39|
12944 +  -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
12945 +  OTHER  |VSTAT  |       |       |       |       |       | |VINFO  |       |
12946 +        |     40|     41|     42|     43|     44|     45| |     46|     47|
12947 +  =======+=======+=======+=======+=======+=======+=======+ +=======+=======+
12948 +  SPECIAL|EVENT  |       |       |       |FLAGS  |       | |VSPACE |       |
12949 +        |     48|     49|     50|     51|     52|     53| |     54|     55|
12950 +  -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
12951 +  SPECIAL|DEBUG  |       |       |       |RLIMIT |SYSCALL| |       |COMPAT |
12952 +        |     56|     57|     58|     59|     60|TEST 61| |     62|     63|
12953 +  -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
12954 +
12955 +*/
12956 +
12957 +#define VC_CAT_VERSION         0
12958 +
12959 +#define VC_CAT_VSETUP          1
12960 +#define VC_CAT_VHOST           2
12961 +
12962 +#define VC_CAT_DEVICE          6
12963 +
12964 +#define VC_CAT_VPROC           9
12965 +#define VC_CAT_PROCALT         10
12966 +#define VC_CAT_PROCMIG         11
12967 +#define VC_CAT_PROCTRL         12
12968 +
12969 +#define VC_CAT_SCHED           14
12970 +#define VC_CAT_MEMCTRL         20
12971 +
12972 +#define VC_CAT_VNET            25
12973 +#define VC_CAT_NETALT          26
12974 +#define VC_CAT_NETMIG          27
12975 +#define VC_CAT_NETCTRL         28
12976 +
12977 +#define VC_CAT_TAGMIG          35
12978 +#define VC_CAT_DLIMIT          36
12979 +#define VC_CAT_INODE           38
12980 +
12981 +#define VC_CAT_VSTAT           40
12982 +#define VC_CAT_VINFO           46
12983 +#define VC_CAT_EVENT           48
12984 +
12985 +#define VC_CAT_FLAGS           52
12986 +#define VC_CAT_VSPACE          54
12987 +#define VC_CAT_DEBUG           56
12988 +#define VC_CAT_RLIMIT          60
12989 +
12990 +#define VC_CAT_SYSTEST         61
12991 +#define VC_CAT_COMPAT          63
12992 +
12993 +/*  query version */
12994 +
12995 +#define VCMD_get_version       VC_CMD(VERSION, 0, 0)
12996 +#define VCMD_get_vci           VC_CMD(VERSION, 1, 0)
12997 +
12998 +
12999 +#ifdef __KERNEL__
13000 +
13001 +#include <linux/errno.h>
13002 +
13003 +#endif /* __KERNEL__ */
13004 +
13005 +#endif /* _VX_SWITCH_H */
13006 +
13007 diff -NurpP --minimal linux-2.6.29/include/linux/vserver/tag_cmd.h linux-2.6.29-vs2.3.0.36.9-pre3/include/linux/vserver/tag_cmd.h
13008 --- linux-2.6.29/include/linux/vserver/tag_cmd.h        1970-01-01 01:00:00.000000000 +0100
13009 +++ linux-2.6.29-vs2.3.0.36.9-pre3/include/linux/vserver/tag_cmd.h      2009-02-22 22:54:26.000000000 +0100
13010 @@ -0,0 +1,22 @@
13011 +#ifndef _VX_TAG_CMD_H
13012 +#define _VX_TAG_CMD_H
13013 +
13014 +
13015 +/* vinfo commands */
13016 +
13017 +#define VCMD_task_tag          VC_CMD(VINFO, 3, 0)
13018 +
13019 +#ifdef __KERNEL__
13020 +extern int vc_task_tag(uint32_t);
13021 +
13022 +#endif /* __KERNEL__ */
13023 +
13024 +/* context commands */
13025 +
13026 +#define VCMD_tag_migrate       VC_CMD(TAGMIG, 1, 0)
13027 +
13028 +#ifdef __KERNEL__
13029 +extern int vc_tag_migrate(uint32_t);
13030 +
13031 +#endif /* __KERNEL__ */
13032 +#endif /* _VX_TAG_CMD_H */
13033 diff -NurpP --minimal linux-2.6.29/include/linux/vserver/tag.h linux-2.6.29-vs2.3.0.36.9-pre3/include/linux/vserver/tag.h
13034 --- linux-2.6.29/include/linux/vserver/tag.h    1970-01-01 01:00:00.000000000 +0100
13035 +++ linux-2.6.29-vs2.3.0.36.9-pre3/include/linux/vserver/tag.h  2009-02-22 22:54:26.000000000 +0100
13036 @@ -0,0 +1,143 @@
13037 +#ifndef _DX_TAG_H
13038 +#define _DX_TAG_H
13039 +
13040 +#include <linux/types.h>
13041 +
13042 +
13043 +#define DX_TAG(in)     (IS_TAGGED(in))
13044 +
13045 +
13046 +#ifdef CONFIG_TAG_NFSD
13047 +#define DX_TAG_NFSD    1
13048 +#else
13049 +#define DX_TAG_NFSD    0
13050 +#endif
13051 +
13052 +
13053 +#ifdef CONFIG_TAGGING_NONE
13054 +
13055 +#define MAX_UID                0xFFFFFFFF
13056 +#define MAX_GID                0xFFFFFFFF
13057 +
13058 +#define INOTAG_TAG(cond, uid, gid, tag)        (0)
13059 +
13060 +#define TAGINO_UID(cond, uid, tag)     (uid)
13061 +#define TAGINO_GID(cond, gid, tag)     (gid)
13062 +
13063 +#endif
13064 +
13065 +
13066 +#ifdef CONFIG_TAGGING_GID16
13067 +
13068 +#define MAX_UID                0xFFFFFFFF
13069 +#define MAX_GID                0x0000FFFF
13070 +
13071 +#define INOTAG_TAG(cond, uid, gid, tag)        \
13072 +       ((cond) ? (((gid) >> 16) & 0xFFFF) : 0)
13073 +
13074 +#define TAGINO_UID(cond, uid, tag)     (uid)
13075 +#define TAGINO_GID(cond, gid, tag)     \
13076 +       ((cond) ? (((gid) & 0xFFFF) | ((tag) << 16)) : (gid))
13077 +
13078 +#endif
13079 +
13080 +
13081 +#ifdef CONFIG_TAGGING_ID24
13082 +
13083 +#define MAX_UID                0x00FFFFFF
13084 +#define MAX_GID                0x00FFFFFF
13085 +
13086 +#define INOTAG_TAG(cond, uid, gid, tag)        \
13087 +       ((cond) ? ((((uid) >> 16) & 0xFF00) | (((gid) >> 24) & 0xFF)) : 0)
13088 +
13089 +#define TAGINO_UID(cond, uid, tag)     \
13090 +       ((cond) ? (((uid) & 0xFFFFFF) | (((tag) & 0xFF00) << 16)) : (uid))
13091 +#define TAGINO_GID(cond, gid, tag)     \
13092 +       ((cond) ? (((gid) & 0xFFFFFF) | (((tag) & 0x00FF) << 24)) : (gid))
13093 +
13094 +#endif
13095 +
13096 +
13097 +#ifdef CONFIG_TAGGING_UID16
13098 +
13099 +#define MAX_UID                0x0000FFFF
13100 +#define MAX_GID                0xFFFFFFFF
13101 +
13102 +#define INOTAG_TAG(cond, uid, gid, tag)        \
13103 +       ((cond) ? (((uid) >> 16) & 0xFFFF) : 0)
13104 +
13105 +#define TAGINO_UID(cond, uid, tag)     \
13106 +       ((cond) ? (((uid) & 0xFFFF) | ((tag) << 16)) : (uid))
13107 +#define TAGINO_GID(cond, gid, tag)     (gid)
13108 +
13109 +#endif
13110 +
13111 +
13112 +#ifdef CONFIG_TAGGING_INTERN
13113 +
13114 +#define MAX_UID                0xFFFFFFFF
13115 +#define MAX_GID                0xFFFFFFFF
13116 +
13117 +#define INOTAG_TAG(cond, uid, gid, tag)        \
13118 +       ((cond) ? (tag) : 0)
13119 +
13120 +#define TAGINO_UID(cond, uid, tag)     (uid)
13121 +#define TAGINO_GID(cond, gid, tag)     (gid)
13122 +
13123 +#endif
13124 +
13125 +
13126 +#ifndef CONFIG_TAGGING_NONE
13127 +#define dx_current_fstag(sb)   \
13128 +       ((sb)->s_flags & MS_TAGGED ? dx_current_tag() : 0)
13129 +#else
13130 +#define dx_current_fstag(sb)   (0)
13131 +#endif
13132 +
13133 +#ifndef CONFIG_TAGGING_INTERN
13134 +#define TAGINO_TAG(cond, tag)  (0)
13135 +#else
13136 +#define TAGINO_TAG(cond, tag)  ((cond) ? (tag) : 0)
13137 +#endif
13138 +
13139 +#define INOTAG_UID(cond, uid, gid)     \
13140 +       ((cond) ? ((uid) & MAX_UID) : (uid))
13141 +#define INOTAG_GID(cond, uid, gid)     \
13142 +       ((cond) ? ((gid) & MAX_GID) : (gid))
13143 +
13144 +
13145 +static inline uid_t dx_map_uid(uid_t uid)
13146 +{
13147 +       if ((uid > MAX_UID) && (uid != -1))
13148 +               uid = -2;
13149 +       return (uid & MAX_UID);
13150 +}
13151 +
13152 +static inline gid_t dx_map_gid(gid_t gid)
13153 +{
13154 +       if ((gid > MAX_GID) && (gid != -1))
13155 +               gid = -2;
13156 +       return (gid & MAX_GID);
13157 +}
13158 +
13159 +struct peer_tag {
13160 +       int32_t xid;
13161 +       int32_t nid;
13162 +};
13163 +
13164 +#define dx_notagcheck(sb) ((sb) && ((sb)->s_flags & MS_NOTAGCHECK))
13165 +
13166 +int dx_parse_tag(char *string, tag_t *tag, int remove, int *mnt_flags,
13167 +                unsigned long *flags);
13168 +
13169 +#ifdef CONFIG_PROPAGATE
13170 +
13171 +void __dx_propagate_tag(struct nameidata *nd, struct inode *inode);
13172 +
13173 +#define dx_propagate_tag(n, i) __dx_propagate_tag(n, i)
13174 +
13175 +#else
13176 +#define dx_propagate_tag(n, i) do { } while (0)
13177 +#endif
13178 +
13179 +#endif /* _DX_TAG_H */
13180 diff -NurpP --minimal linux-2.6.29/include/linux/vs_inet6.h linux-2.6.29-vs2.3.0.36.9-pre3/include/linux/vs_inet6.h
13181 --- linux-2.6.29/include/linux/vs_inet6.h       1970-01-01 01:00:00.000000000 +0100
13182 +++ linux-2.6.29-vs2.3.0.36.9-pre3/include/linux/vs_inet6.h     2009-03-25 00:46:50.000000000 +0100
13183 @@ -0,0 +1,246 @@
13184 +#ifndef _VS_INET6_H
13185 +#define _VS_INET6_H
13186 +
13187 +#include "vserver/base.h"
13188 +#include "vserver/network.h"
13189 +#include "vserver/debug.h"
13190 +
13191 +#include <net/ipv6.h>
13192 +
13193 +#define NXAV6(a)       &(a)->ip, &(a)->mask, (a)->prefix, (a)->type
13194 +#define NXAV6_FMT      "[%pI6/%pI6/%d:%04x]"
13195 +
13196 +
13197 +#ifdef CONFIG_IPV6
13198 +
13199 +static inline
13200 +int v6_addr_match(struct nx_addr_v6 *nxa,
13201 +       const struct in6_addr *addr, uint16_t mask)
13202 +{
13203 +       int ret = 0;
13204 +
13205 +       switch (nxa->type & mask) {
13206 +       case NXA_TYPE_MASK:
13207 +               ret = ipv6_masked_addr_cmp(&nxa->ip, &nxa->mask, addr);
13208 +               break;
13209 +       case NXA_TYPE_ADDR:
13210 +               ret = ipv6_addr_equal(&nxa->ip, addr);
13211 +               break;
13212 +       case NXA_TYPE_ANY:
13213 +               ret = 1;
13214 +               break;
13215 +       }
13216 +       vxdprintk(VXD_CBIT(net, 0),
13217 +               "v6_addr_match(%p" NXAV6_FMT ",%pI6,%04x) = %d",
13218 +               nxa, NXAV6(nxa), addr, mask, ret);
13219 +       return ret;
13220 +}
13221 +
13222 +static inline
13223 +int v6_addr_in_nx_info(struct nx_info *nxi,
13224 +       const struct in6_addr *addr, uint16_t mask)
13225 +{
13226 +       struct nx_addr_v6 *nxa;
13227 +       int ret = 1;
13228 +
13229 +       if (!nxi)
13230 +               goto out;
13231 +       for (nxa = &nxi->v6; nxa; nxa = nxa->next)
13232 +               if (v6_addr_match(nxa, addr, mask))
13233 +                       goto out;
13234 +       ret = 0;
13235 +out:
13236 +       vxdprintk(VXD_CBIT(net, 0),
13237 +               "v6_addr_in_nx_info(%p[#%u],%pI6,%04x) = %d",
13238 +               nxi, nxi ? nxi->nx_id : 0, addr, mask, ret);
13239 +       return ret;
13240 +}
13241 +
13242 +static inline
13243 +int v6_nx_addr_match(struct nx_addr_v6 *nxa, struct nx_addr_v6 *addr, uint16_t mask)
13244 +{
13245 +       /* FIXME: needs full range checks */
13246 +       return v6_addr_match(nxa, &addr->ip, mask);
13247 +}
13248 +
13249 +static inline
13250 +int v6_nx_addr_in_nx_info(struct nx_info *nxi, struct nx_addr_v6 *nxa, uint16_t mask)
13251 +{
13252 +       struct nx_addr_v6 *ptr;
13253 +
13254 +       for (ptr = &nxi->v6; ptr; ptr = ptr->next)
13255 +               if (v6_nx_addr_match(ptr, nxa, mask))
13256 +                       return 1;
13257 +       return 0;
13258 +}
13259 +
13260 +
13261 +/*
13262 + *     Check if a given address matches for a socket
13263 + *
13264 + *     nxi:            the socket's nx_info if any
13265 + *     addr:           to be verified address
13266 + */
13267 +static inline
13268 +int v6_sock_addr_match (
13269 +       struct nx_info *nxi,
13270 +       struct inet_sock *inet,
13271 +       struct in6_addr *addr)
13272 +{
13273 +       struct sock *sk = &inet->sk;
13274 +       struct in6_addr *saddr = inet6_rcv_saddr(sk);
13275 +
13276 +       if (!ipv6_addr_any(addr) &&
13277 +               ipv6_addr_equal(saddr, addr))
13278 +               return 1;
13279 +       if (ipv6_addr_any(saddr))
13280 +               return v6_addr_in_nx_info(nxi, addr, -1);
13281 +       return 0;
13282 +}
13283 +
13284 +/*
13285 + *     check if address is covered by socket
13286 + *
13287 + *     sk:     the socket to check against
13288 + *     addr:   the address in question (must be != 0)
13289 + */
13290 +
13291 +static inline
13292 +int __v6_addr_match_socket(const struct sock *sk, struct nx_addr_v6 *nxa)
13293 +{
13294 +       struct nx_info *nxi = sk->sk_nx_info;
13295 +       struct in6_addr *saddr = inet6_rcv_saddr(sk);
13296 +
13297 +       vxdprintk(VXD_CBIT(net, 5),
13298 +               "__v6_addr_in_socket(%p," NXAV6_FMT ") %p:%pI6 %p;%lx",
13299 +               sk, NXAV6(nxa), nxi, saddr, sk->sk_socket,
13300 +               (sk->sk_socket?sk->sk_socket->flags:0));
13301 +
13302 +       if (!ipv6_addr_any(saddr)) {    /* direct address match */
13303 +               return v6_addr_match(nxa, saddr, -1);
13304 +       } else if (nxi) {               /* match against nx_info */
13305 +               return v6_nx_addr_in_nx_info(nxi, nxa, -1);
13306 +       } else {                        /* unrestricted any socket */
13307 +               return 1;
13308 +       }
13309 +}
13310 +
13311 +
13312 +/* inet related checks and helpers */
13313 +
13314 +
13315 +struct in_ifaddr;
13316 +struct net_device;
13317 +struct sock;
13318 +
13319 +
13320 +#include <linux/netdevice.h>
13321 +#include <linux/inetdevice.h>
13322 +#include <net/inet_timewait_sock.h>
13323 +
13324 +
13325 +int dev_in_nx_info(struct net_device *, struct nx_info *);
13326 +int v6_dev_in_nx_info(struct net_device *, struct nx_info *);
13327 +int nx_v6_addr_conflict(struct nx_info *, struct nx_info *);
13328 +
13329 +
13330 +
13331 +static inline
13332 +int v6_ifa_in_nx_info(struct inet6_ifaddr *ifa, struct nx_info *nxi)
13333 +{
13334 +       if (!nxi)
13335 +               return 1;
13336 +       if (!ifa)
13337 +               return 0;
13338 +       return v6_addr_in_nx_info(nxi, &ifa->addr, -1);
13339 +}
13340 +
13341 +static inline
13342 +int nx_v6_ifa_visible(struct nx_info *nxi, struct inet6_ifaddr *ifa)
13343 +{
13344 +       vxdprintk(VXD_CBIT(net, 1), "nx_v6_ifa_visible(%p[#%u],%p) %d",
13345 +               nxi, nxi ? nxi->nx_id : 0, ifa,
13346 +               nxi ? v6_ifa_in_nx_info(ifa, nxi) : 0);
13347 +
13348 +       if (!nx_info_flags(nxi, NXF_HIDE_NETIF, 0))
13349 +               return 1;
13350 +       if (v6_ifa_in_nx_info(ifa, nxi))
13351 +               return 1;
13352 +       return 0;
13353 +}
13354 +
13355 +
13356 +struct nx_v6_sock_addr {
13357 +       struct in6_addr saddr;  /* Address used for validation */
13358 +       struct in6_addr baddr;  /* Address used for socket bind */
13359 +};
13360 +
13361 +static inline
13362 +int v6_map_sock_addr(struct inet_sock *inet, struct sockaddr_in6 *addr,
13363 +       struct nx_v6_sock_addr *nsa)
13364 +{
13365 +       // struct sock *sk = &inet->sk;
13366 +       // struct nx_info *nxi = sk->sk_nx_info;
13367 +       struct in6_addr saddr = addr->sin6_addr;
13368 +       struct in6_addr baddr = saddr;
13369 +
13370 +       nsa->saddr = saddr;
13371 +       nsa->baddr = baddr;
13372 +       return 0;
13373 +}
13374 +
13375 +static inline
13376 +void v6_set_sock_addr(struct inet_sock *inet, struct nx_v6_sock_addr *nsa)
13377 +{
13378 +       // struct sock *sk = &inet->sk;
13379 +       // struct in6_addr *saddr = inet6_rcv_saddr(sk);
13380 +
13381 +       // *saddr = nsa->baddr;
13382 +       // inet->saddr = nsa->baddr;
13383 +}
13384 +
13385 +static inline
13386 +int nx_info_has_v6(struct nx_info *nxi)
13387 +{
13388 +       if (!nxi)
13389 +               return 1;
13390 +       if (NX_IPV6(nxi))
13391 +               return 1;
13392 +       return 0;
13393 +}
13394 +
13395 +#else /* CONFIG_IPV6 */
13396 +
13397 +static inline
13398 +int nx_v6_dev_visible(struct nx_info *n, struct net_device *d)
13399 +{
13400 +       return 1;
13401 +}
13402 +
13403 +
13404 +static inline
13405 +int nx_v6_addr_conflict(struct nx_info *n, uint32_t a, const struct sock *s)
13406 +{
13407 +       return 1;
13408 +}
13409 +
13410 +static inline
13411 +int v6_ifa_in_nx_info(struct in_ifaddr *a, struct nx_info *n)
13412 +{
13413 +       return 1;
13414 +}
13415 +
13416 +static inline
13417 +int nx_info_has_v6(struct nx_info *nxi)
13418 +{
13419 +       return 0;
13420 +}
13421 +
13422 +#endif /* CONFIG_IPV6 */
13423 +
13424 +#define current_nx_info_has_v6() \
13425 +       nx_info_has_v6(current_nx_info())
13426 +
13427 +#else
13428 +#warning duplicate inclusion
13429 +#endif
13430 diff -NurpP --minimal linux-2.6.29/include/linux/vs_inet.h linux-2.6.29-vs2.3.0.36.9-pre3/include/linux/vs_inet.h
13431 --- linux-2.6.29/include/linux/vs_inet.h        1970-01-01 01:00:00.000000000 +0100
13432 +++ linux-2.6.29-vs2.3.0.36.9-pre3/include/linux/vs_inet.h      2009-02-22 22:54:26.000000000 +0100
13433 @@ -0,0 +1,342 @@
13434 +#ifndef _VS_INET_H
13435 +#define _VS_INET_H
13436 +
13437 +#include "vserver/base.h"
13438 +#include "vserver/network.h"
13439 +#include "vserver/debug.h"
13440 +
13441 +#define IPI_LOOPBACK   htonl(INADDR_LOOPBACK)
13442 +
13443 +#define NXAV4(a)       NIPQUAD((a)->ip[0]), NIPQUAD((a)->ip[1]), \
13444 +                       NIPQUAD((a)->mask), (a)->type
13445 +#define NXAV4_FMT      "[" NIPQUAD_FMT "-" NIPQUAD_FMT "/" NIPQUAD_FMT ":%04x]"
13446 +
13447 +
13448 +static inline
13449 +int v4_addr_match(struct nx_addr_v4 *nxa, __be32 addr, uint16_t tmask)
13450 +{
13451 +       __be32 ip = nxa->ip[0].s_addr;
13452 +       __be32 mask = nxa->mask.s_addr;
13453 +       __be32 bcast = ip | ~mask;
13454 +       int ret = 0;
13455 +
13456 +       switch (nxa->type & tmask) {
13457 +       case NXA_TYPE_MASK:
13458 +               ret = (ip == (addr & mask));
13459 +               break;
13460 +       case NXA_TYPE_ADDR:
13461 +               ret = 3;
13462 +               if (addr == ip)
13463 +                       break;
13464 +               /* fall through to broadcast */
13465 +       case NXA_MOD_BCAST:
13466 +               ret = ((tmask & NXA_MOD_BCAST) && (addr == bcast));
13467 +               break;
13468 +       case NXA_TYPE_RANGE:
13469 +               ret = ((nxa->ip[0].s_addr <= addr) &&
13470 +                       (nxa->ip[1].s_addr > addr));
13471 +               break;
13472 +       case NXA_TYPE_ANY:
13473 +               ret = 2;
13474 +               break;
13475 +       }
13476 +
13477 +       vxdprintk(VXD_CBIT(net, 0),
13478 +               "v4_addr_match(%p" NXAV4_FMT "," NIPQUAD_FMT ",%04x) = %d",
13479 +               nxa, NXAV4(nxa), NIPQUAD(addr), tmask, ret);
13480 +       return ret;
13481 +}
13482 +
13483 +static inline
13484 +int v4_addr_in_nx_info(struct nx_info *nxi, __be32 addr, uint16_t tmask)
13485 +{
13486 +       struct nx_addr_v4 *nxa;
13487 +       int ret = 1;
13488 +
13489 +       if (!nxi)
13490 +               goto out;
13491 +
13492 +       ret = 2;
13493 +       /* allow 127.0.0.1 when remapping lback */
13494 +       if ((tmask & NXA_LOOPBACK) &&
13495 +               (addr == IPI_LOOPBACK) &&
13496 +               nx_info_flags(nxi, NXF_LBACK_REMAP, 0))
13497 +               goto out;
13498 +       ret = 3;
13499 +       /* check for lback address */
13500 +       if ((tmask & NXA_MOD_LBACK) &&
13501 +               (nxi->v4_lback.s_addr == addr))
13502 +               goto out;
13503 +       ret = 4;
13504 +       /* check for broadcast address */
13505 +       if ((tmask & NXA_MOD_BCAST) &&
13506 +               (nxi->v4_bcast.s_addr == addr))
13507 +               goto out;
13508 +       ret = 5;
13509 +       /* check for v4 addresses */
13510 +       for (nxa = &nxi->v4; nxa; nxa = nxa->next)
13511 +               if (v4_addr_match(nxa, addr, tmask))
13512 +                       goto out;
13513 +       ret = 0;
13514 +out:
13515 +       vxdprintk(VXD_CBIT(net, 0),
13516 +               "v4_addr_in_nx_info(%p[#%u]," NIPQUAD_FMT ",%04x) = %d",
13517 +               nxi, nxi ? nxi->nx_id : 0, NIPQUAD(addr), tmask, ret);
13518 +       return ret;
13519 +}
13520 +
13521 +static inline
13522 +int v4_nx_addr_match(struct nx_addr_v4 *nxa, struct nx_addr_v4 *addr, uint16_t mask)
13523 +{
13524 +       /* FIXME: needs full range checks */
13525 +       return v4_addr_match(nxa, addr->ip[0].s_addr, mask);
13526 +}
13527 +
13528 +static inline
13529 +int v4_nx_addr_in_nx_info(struct nx_info *nxi, struct nx_addr_v4 *nxa, uint16_t mask)
13530 +{
13531 +       struct nx_addr_v4 *ptr;
13532 +
13533 +       for (ptr = &nxi->v4; ptr; ptr = ptr->next)
13534 +               if (v4_nx_addr_match(ptr, nxa, mask))
13535 +                       return 1;
13536 +       return 0;
13537 +}
13538 +
13539 +#include <net/inet_sock.h>
13540 +
13541 +/*
13542 + *     Check if a given address matches for a socket
13543 + *
13544 + *     nxi:            the socket's nx_info if any
13545 + *     addr:           to be verified address
13546 + */
13547 +static inline
13548 +int v4_sock_addr_match (
13549 +       struct nx_info *nxi,
13550 +       struct inet_sock *inet,
13551 +       __be32 addr)
13552 +{
13553 +       __be32 saddr = inet->rcv_saddr;
13554 +       __be32 bcast = nxi ? nxi->v4_bcast.s_addr : INADDR_BROADCAST;
13555 +
13556 +       if (addr && (saddr == addr || bcast == addr))
13557 +               return 1;
13558 +       if (!saddr)
13559 +               return v4_addr_in_nx_info(nxi, addr, NXA_MASK_BIND);
13560 +       return 0;
13561 +}
13562 +
13563 +
13564 +/* inet related checks and helpers */
13565 +
13566 +
13567 +struct in_ifaddr;
13568 +struct net_device;
13569 +struct sock;
13570 +
13571 +#ifdef CONFIG_INET
13572 +
13573 +#include <linux/netdevice.h>
13574 +#include <linux/inetdevice.h>
13575 +#include <net/inet_sock.h>
13576 +#include <net/inet_timewait_sock.h>
13577 +
13578 +
13579 +int dev_in_nx_info(struct net_device *, struct nx_info *);
13580 +int v4_dev_in_nx_info(struct net_device *, struct nx_info *);
13581 +int nx_v4_addr_conflict(struct nx_info *, struct nx_info *);
13582 +
13583 +
13584 +/*
13585 + *     check if address is covered by socket
13586 + *
13587 + *     sk:     the socket to check against
13588 + *     addr:   the address in question (must be != 0)
13589 + */
13590 +
13591 +static inline
13592 +int __v4_addr_match_socket(const struct sock *sk, struct nx_addr_v4 *nxa)
13593 +{
13594 +       struct nx_info *nxi = sk->sk_nx_info;
13595 +       __be32 saddr = inet_rcv_saddr(sk);
13596 +
13597 +       vxdprintk(VXD_CBIT(net, 5),
13598 +               "__v4_addr_in_socket(%p," NXAV4_FMT ") %p:" NIPQUAD_FMT " %p;%lx",
13599 +               sk, NXAV4(nxa), nxi, NIPQUAD(saddr), sk->sk_socket,
13600 +               (sk->sk_socket?sk->sk_socket->flags:0));
13601 +
13602 +       if (saddr) {            /* direct address match */
13603 +               return v4_addr_match(nxa, saddr, -1);
13604 +       } else if (nxi) {       /* match against nx_info */
13605 +               return v4_nx_addr_in_nx_info(nxi, nxa, -1);
13606 +       } else {                /* unrestricted any socket */
13607 +               return 1;
13608 +       }
13609 +}
13610 +
13611 +
13612 +
13613 +static inline
13614 +int nx_dev_visible(struct nx_info *nxi, struct net_device *dev)
13615 +{
13616 +       vxdprintk(VXD_CBIT(net, 1), "nx_dev_visible(%p[#%u],%p Â»%s«) %d",
13617 +               nxi, nxi ? nxi->nx_id : 0, dev, dev->name,
13618 +               nxi ? dev_in_nx_info(dev, nxi) : 0);
13619 +
13620 +       if (!nx_info_flags(nxi, NXF_HIDE_NETIF, 0))
13621 +               return 1;
13622 +       if (dev_in_nx_info(dev, nxi))
13623 +               return 1;
13624 +       return 0;
13625 +}
13626 +
13627 +
13628 +static inline
13629 +int v4_ifa_in_nx_info(struct in_ifaddr *ifa, struct nx_info *nxi)
13630 +{
13631 +       if (!nxi)
13632 +               return 1;
13633 +       if (!ifa)
13634 +               return 0;
13635 +       return v4_addr_in_nx_info(nxi, ifa->ifa_local, NXA_MASK_SHOW);
13636 +}
13637 +
13638 +static inline
13639 +int nx_v4_ifa_visible(struct nx_info *nxi, struct in_ifaddr *ifa)
13640 +{
13641 +       vxdprintk(VXD_CBIT(net, 1), "nx_v4_ifa_visible(%p[#%u],%p) %d",
13642 +               nxi, nxi ? nxi->nx_id : 0, ifa,
13643 +               nxi ? v4_ifa_in_nx_info(ifa, nxi) : 0);
13644 +
13645 +       if (!nx_info_flags(nxi, NXF_HIDE_NETIF, 0))
13646 +               return 1;
13647 +       if (v4_ifa_in_nx_info(ifa, nxi))
13648 +               return 1;
13649 +       return 0;
13650 +}
13651 +
13652 +
13653 +struct nx_v4_sock_addr {
13654 +       __be32 saddr;   /* Address used for validation */
13655 +       __be32 baddr;   /* Address used for socket bind */
13656 +};
13657 +
13658 +static inline
13659 +int v4_map_sock_addr(struct inet_sock *inet, struct sockaddr_in *addr,
13660 +       struct nx_v4_sock_addr *nsa)
13661 +{
13662 +       struct sock *sk = &inet->sk;
13663 +       struct nx_info *nxi = sk->sk_nx_info;
13664 +       __be32 saddr = addr->sin_addr.s_addr;
13665 +       __be32 baddr = saddr;
13666 +
13667 +       vxdprintk(VXD_CBIT(net, 3),
13668 +               "inet_bind(%p)* %p,%p;%lx " NIPQUAD_FMT,
13669 +               sk, sk->sk_nx_info, sk->sk_socket,
13670 +               (sk->sk_socket ? sk->sk_socket->flags : 0),
13671 +               NIPQUAD(saddr));
13672 +
13673 +       if (nxi) {
13674 +               if (saddr == INADDR_ANY) {
13675 +                       if (nx_info_flags(nxi, NXF_SINGLE_IP, 0))
13676 +                               baddr = nxi->v4.ip[0].s_addr;
13677 +               } else if (saddr == IPI_LOOPBACK) {
13678 +                       if (nx_info_flags(nxi, NXF_LBACK_REMAP, 0))
13679 +                               baddr = nxi->v4_lback.s_addr;
13680 +               } else {        /* normal address bind */
13681 +                       if (!v4_addr_in_nx_info(nxi, saddr, NXA_MASK_BIND))
13682 +                               return -EADDRNOTAVAIL;
13683 +               }
13684 +       }
13685 +
13686 +       vxdprintk(VXD_CBIT(net, 3),
13687 +               "inet_bind(%p) " NIPQUAD_FMT ", " NIPQUAD_FMT,
13688 +               sk, NIPQUAD(saddr), NIPQUAD(baddr));
13689 +
13690 +       nsa->saddr = saddr;
13691 +       nsa->baddr = baddr;
13692 +       return 0;
13693 +}
13694 +
13695 +static inline
13696 +void v4_set_sock_addr(struct inet_sock *inet, struct nx_v4_sock_addr *nsa)
13697 +{
13698 +       inet->saddr = nsa->baddr;
13699 +       inet->rcv_saddr = nsa->baddr;
13700 +}
13701 +
13702 +
13703 +/*
13704 + *      helper to simplify inet_lookup_listener
13705 + *
13706 + *      nxi:   the socket's nx_info if any
13707 + *      addr:  to be verified address
13708 + *      saddr: socket address
13709 + */
13710 +static inline int v4_inet_addr_match (
13711 +       struct nx_info *nxi,
13712 +       __be32 addr,
13713 +       __be32 saddr)
13714 +{
13715 +       if (addr && (saddr == addr))
13716 +               return 1;
13717 +       if (!saddr)
13718 +               return nxi ? v4_addr_in_nx_info(nxi, addr, NXA_MASK_BIND) : 1;
13719 +       return 0;
13720 +}
13721 +
13722 +static inline __be32 nx_map_sock_lback(struct nx_info *nxi, __be32 addr)
13723 +{
13724 +       if (nx_info_flags(nxi, NXF_HIDE_LBACK, 0) &&
13725 +               (addr == nxi->v4_lback.s_addr))
13726 +               return IPI_LOOPBACK;
13727 +       return addr;
13728 +}
13729 +
13730 +static inline
13731 +int nx_info_has_v4(struct nx_info *nxi)
13732 +{
13733 +       if (!nxi)
13734 +               return 1;
13735 +       if (NX_IPV4(nxi))
13736 +               return 1;
13737 +       if (nx_info_flags(nxi, NXF_LBACK_REMAP, 0))
13738 +               return 1;
13739 +       return 0;
13740 +}
13741 +
13742 +#else /* CONFIG_INET */
13743 +
13744 +static inline
13745 +int nx_dev_visible(struct nx_info *n, struct net_device *d)
13746 +{
13747 +       return 1;
13748 +}
13749 +
13750 +static inline
13751 +int nx_v4_addr_conflict(struct nx_info *n, uint32_t a, const struct sock *s)
13752 +{
13753 +       return 1;
13754 +}
13755 +
13756 +static inline
13757 +int v4_ifa_in_nx_info(struct in_ifaddr *a, struct nx_info *n)
13758 +{
13759 +       return 1;
13760 +}
13761 +
13762 +static inline
13763 +int nx_info_has_v4(struct nx_info *nxi)
13764 +{
13765 +       return 0;
13766 +}
13767 +
13768 +#endif /* CONFIG_INET */
13769 +
13770 +#define current_nx_info_has_v4() \
13771 +       nx_info_has_v4(current_nx_info())
13772 +
13773 +#else
13774 +// #warning duplicate inclusion
13775 +#endif
13776 diff -NurpP --minimal linux-2.6.29/include/linux/vs_limit.h linux-2.6.29-vs2.3.0.36.9-pre3/include/linux/vs_limit.h
13777 --- linux-2.6.29/include/linux/vs_limit.h       1970-01-01 01:00:00.000000000 +0100
13778 +++ linux-2.6.29-vs2.3.0.36.9-pre3/include/linux/vs_limit.h     2009-02-22 22:54:26.000000000 +0100
13779 @@ -0,0 +1,140 @@
13780 +#ifndef _VS_LIMIT_H
13781 +#define _VS_LIMIT_H
13782 +
13783 +#include "vserver/limit.h"
13784 +#include "vserver/base.h"
13785 +#include "vserver/context.h"
13786 +#include "vserver/debug.h"
13787 +#include "vserver/context.h"
13788 +#include "vserver/limit_int.h"
13789 +
13790 +
13791 +#define vx_acc_cres(v, d, p, r) \
13792 +       __vx_acc_cres(v, r, d, p, __FILE__, __LINE__)
13793 +
13794 +#define vx_acc_cres_cond(x, d, p, r) \
13795 +       __vx_acc_cres(((x) == vx_current_xid()) ? current->vx_info : 0, \
13796 +       r, d, p, __FILE__, __LINE__)
13797 +
13798 +
13799 +#define vx_add_cres(v, a, p, r) \
13800 +       __vx_add_cres(v, r, a, p, __FILE__, __LINE__)
13801 +#define vx_sub_cres(v, a, p, r)                vx_add_cres(v, -(a), p, r)
13802 +
13803 +#define vx_add_cres_cond(x, a, p, r) \
13804 +       __vx_add_cres(((x) == vx_current_xid()) ? current->vx_info : 0, \
13805 +       r, a, p, __FILE__, __LINE__)
13806 +#define vx_sub_cres_cond(x, a, p, r)   vx_add_cres_cond(x, -(a), p, r)
13807 +
13808 +
13809 +/* process and file limits */
13810 +
13811 +#define vx_nproc_inc(p) \
13812 +       vx_acc_cres((p)->vx_info, 1, p, RLIMIT_NPROC)
13813 +
13814 +#define vx_nproc_dec(p) \
13815 +       vx_acc_cres((p)->vx_info,-1, p, RLIMIT_NPROC)
13816 +
13817 +#define vx_files_inc(f) \
13818 +       vx_acc_cres_cond((f)->f_xid, 1, f, RLIMIT_NOFILE)
13819 +
13820 +#define vx_files_dec(f) \
13821 +       vx_acc_cres_cond((f)->f_xid,-1, f, RLIMIT_NOFILE)
13822 +
13823 +#define vx_locks_inc(l) \
13824 +       vx_acc_cres_cond((l)->fl_xid, 1, l, RLIMIT_LOCKS)
13825 +
13826 +#define vx_locks_dec(l) \
13827 +       vx_acc_cres_cond((l)->fl_xid,-1, l, RLIMIT_LOCKS)
13828 +
13829 +#define vx_openfd_inc(f) \
13830 +       vx_acc_cres(current->vx_info, 1, (void *)(long)(f), VLIMIT_OPENFD)
13831 +
13832 +#define vx_openfd_dec(f) \
13833 +       vx_acc_cres(current->vx_info,-1, (void *)(long)(f), VLIMIT_OPENFD)
13834 +
13835 +
13836 +#define vx_cres_avail(v, n, r) \
13837 +       __vx_cres_avail(v, r, n, __FILE__, __LINE__)
13838 +
13839 +
13840 +#define vx_nproc_avail(n) \
13841 +       vx_cres_avail(current->vx_info, n, RLIMIT_NPROC)
13842 +
13843 +#define vx_files_avail(n) \
13844 +       vx_cres_avail(current->vx_info, n, RLIMIT_NOFILE)
13845 +
13846 +#define vx_locks_avail(n) \
13847 +       vx_cres_avail(current->vx_info, n, RLIMIT_LOCKS)
13848 +
13849 +#define vx_openfd_avail(n) \
13850 +       vx_cres_avail(current->vx_info, n, VLIMIT_OPENFD)
13851 +
13852 +
13853 +/* dentry limits */
13854 +
13855 +#define vx_dentry_inc(d) do {                                          \
13856 +       if (atomic_read(&d->d_count) == 1)                              \
13857 +               vx_acc_cres(current->vx_info, 1, d, VLIMIT_DENTRY);     \
13858 +       } while (0)
13859 +
13860 +#define vx_dentry_dec(d) do {                                          \
13861 +       if (atomic_read(&d->d_count) == 0)                              \
13862 +               vx_acc_cres(current->vx_info,-1, d, VLIMIT_DENTRY);     \
13863 +       } while (0)
13864 +
13865 +#define vx_dentry_avail(n) \
13866 +       vx_cres_avail(current->vx_info, n, VLIMIT_DENTRY)
13867 +
13868 +
13869 +/* socket limits */
13870 +
13871 +#define vx_sock_inc(s) \
13872 +       vx_acc_cres((s)->sk_vx_info, 1, s, VLIMIT_NSOCK)
13873 +
13874 +#define vx_sock_dec(s) \
13875 +       vx_acc_cres((s)->sk_vx_info,-1, s, VLIMIT_NSOCK)
13876 +
13877 +#define vx_sock_avail(n) \
13878 +       vx_cres_avail(current->vx_info, n, VLIMIT_NSOCK)
13879 +
13880 +
13881 +/* ipc resource limits */
13882 +
13883 +#define vx_ipcmsg_add(v, u, a) \
13884 +       vx_add_cres(v, a, u, RLIMIT_MSGQUEUE)
13885 +
13886 +#define vx_ipcmsg_sub(v, u, a) \
13887 +       vx_sub_cres(v, a, u, RLIMIT_MSGQUEUE)
13888 +
13889 +#define vx_ipcmsg_avail(v, a) \
13890 +       vx_cres_avail(v, a, RLIMIT_MSGQUEUE)
13891 +
13892 +
13893 +#define vx_ipcshm_add(v, k, a) \
13894 +       vx_add_cres(v, a, (void *)(long)(k), VLIMIT_SHMEM)
13895 +
13896 +#define vx_ipcshm_sub(v, k, a) \
13897 +       vx_sub_cres(v, a, (void *)(long)(k), VLIMIT_SHMEM)
13898 +
13899 +#define vx_ipcshm_avail(v, a) \
13900 +       vx_cres_avail(v, a, VLIMIT_SHMEM)
13901 +
13902 +
13903 +#define vx_semary_inc(a) \
13904 +       vx_acc_cres(current->vx_info, 1, a, VLIMIT_SEMARY)
13905 +
13906 +#define vx_semary_dec(a) \
13907 +       vx_acc_cres(current->vx_info, -1, a, VLIMIT_SEMARY)
13908 +
13909 +
13910 +#define vx_nsems_add(a,n) \
13911 +       vx_add_cres(current->vx_info, n, a, VLIMIT_NSEMS)
13912 +
13913 +#define vx_nsems_sub(a,n) \
13914 +       vx_sub_cres(current->vx_info, n, a, VLIMIT_NSEMS)
13915 +
13916 +
13917 +#else
13918 +#warning duplicate inclusion
13919 +#endif
13920 diff -NurpP --minimal linux-2.6.29/include/linux/vs_memory.h linux-2.6.29-vs2.3.0.36.9-pre3/include/linux/vs_memory.h
13921 --- linux-2.6.29/include/linux/vs_memory.h      1970-01-01 01:00:00.000000000 +0100
13922 +++ linux-2.6.29-vs2.3.0.36.9-pre3/include/linux/vs_memory.h    2009-02-22 22:54:26.000000000 +0100
13923 @@ -0,0 +1,159 @@
13924 +#ifndef _VS_MEMORY_H
13925 +#define _VS_MEMORY_H
13926 +
13927 +#include "vserver/limit.h"
13928 +#include "vserver/base.h"
13929 +#include "vserver/context.h"
13930 +#include "vserver/debug.h"
13931 +#include "vserver/context.h"
13932 +#include "vserver/limit_int.h"
13933 +
13934 +
13935 +#define __acc_add_long(a, v)   (*(v) += (a))
13936 +#define __acc_inc_long(v)      (++*(v))
13937 +#define __acc_dec_long(v)      (--*(v))
13938 +
13939 +#if    NR_CPUS >= CONFIG_SPLIT_PTLOCK_CPUS
13940 +#define __acc_add_atomic(a, v) atomic_long_add(a, v)
13941 +#define __acc_inc_atomic(v)    atomic_long_inc(v)
13942 +#define __acc_dec_atomic(v)    atomic_long_dec(v)
13943 +#else  /* NR_CPUS < CONFIG_SPLIT_PTLOCK_CPUS */
13944 +#define __acc_add_atomic(a, v) __acc_add_long(a, v)
13945 +#define __acc_inc_atomic(v)    __acc_inc_long(v)
13946 +#define __acc_dec_atomic(v)    __acc_dec_long(v)
13947 +#endif /* NR_CPUS < CONFIG_SPLIT_PTLOCK_CPUS */
13948 +
13949 +
13950 +#define vx_acc_page(m, d, v, r) do {                                   \
13951 +       if ((d) > 0)                                                    \
13952 +               __acc_inc_long(&(m)->v);                                \
13953 +       else                                                            \
13954 +               __acc_dec_long(&(m)->v);                                \
13955 +       __vx_acc_cres(m->mm_vx_info, r, d, m, __FILE__, __LINE__);      \
13956 +} while (0)
13957 +
13958 +#define vx_acc_page_atomic(m, d, v, r) do {                            \
13959 +       if ((d) > 0)                                                    \
13960 +               __acc_inc_atomic(&(m)->v);                              \
13961 +       else                                                            \
13962 +               __acc_dec_atomic(&(m)->v);                              \
13963 +       __vx_acc_cres(m->mm_vx_info, r, d, m, __FILE__, __LINE__);      \
13964 +} while (0)
13965 +
13966 +
13967 +#define vx_acc_pages(m, p, v, r) do {                                  \
13968 +       unsigned long __p = (p);                                        \
13969 +       __acc_add_long(__p, &(m)->v);                                   \
13970 +       __vx_add_cres(m->mm_vx_info, r, __p, m, __FILE__, __LINE__);    \
13971 +} while (0)
13972 +
13973 +#define vx_acc_pages_atomic(m, p, v, r) do {                           \
13974 +       unsigned long __p = (p);                                        \
13975 +       __acc_add_atomic(__p, &(m)->v);                                 \
13976 +       __vx_add_cres(m->mm_vx_info, r, __p, m, __FILE__, __LINE__);    \
13977 +} while (0)
13978 +
13979 +
13980 +
13981 +#define vx_acc_vmpage(m, d) \
13982 +       vx_acc_page(m, d, total_vm,  RLIMIT_AS)
13983 +#define vx_acc_vmlpage(m, d) \
13984 +       vx_acc_page(m, d, locked_vm, RLIMIT_MEMLOCK)
13985 +#define vx_acc_file_rsspage(m, d) \
13986 +       vx_acc_page_atomic(m, d, _file_rss, VLIMIT_MAPPED)
13987 +#define vx_acc_anon_rsspage(m, d) \
13988 +       vx_acc_page_atomic(m, d, _anon_rss, VLIMIT_ANON)
13989 +
13990 +#define vx_acc_vmpages(m, p) \
13991 +       vx_acc_pages(m, p, total_vm,  RLIMIT_AS)
13992 +#define vx_acc_vmlpages(m, p) \
13993 +       vx_acc_pages(m, p, locked_vm, RLIMIT_MEMLOCK)
13994 +#define vx_acc_file_rsspages(m, p) \
13995 +       vx_acc_pages_atomic(m, p, _file_rss, VLIMIT_MAPPED)
13996 +#define vx_acc_anon_rsspages(m, p) \
13997 +       vx_acc_pages_atomic(m, p, _anon_rss, VLIMIT_ANON)
13998 +
13999 +#define vx_pages_add(s, r, p)  __vx_add_cres(s, r, p, 0, __FILE__, __LINE__)
14000 +#define vx_pages_sub(s, r, p)  vx_pages_add(s, r, -(p))
14001 +
14002 +#define vx_vmpages_inc(m)              vx_acc_vmpage(m, 1)
14003 +#define vx_vmpages_dec(m)              vx_acc_vmpage(m, -1)
14004 +#define vx_vmpages_add(m, p)           vx_acc_vmpages(m, p)
14005 +#define vx_vmpages_sub(m, p)           vx_acc_vmpages(m, -(p))
14006 +
14007 +#define vx_vmlocked_inc(m)             vx_acc_vmlpage(m, 1)
14008 +#define vx_vmlocked_dec(m)             vx_acc_vmlpage(m, -1)
14009 +#define vx_vmlocked_add(m, p)          vx_acc_vmlpages(m, p)
14010 +#define vx_vmlocked_sub(m, p)          vx_acc_vmlpages(m, -(p))
14011 +
14012 +#define vx_file_rsspages_inc(m)                vx_acc_file_rsspage(m, 1)
14013 +#define vx_file_rsspages_dec(m)                vx_acc_file_rsspage(m, -1)
14014 +#define vx_file_rsspages_add(m, p)     vx_acc_file_rsspages(m, p)
14015 +#define vx_file_rsspages_sub(m, p)     vx_acc_file_rsspages(m, -(p))
14016 +
14017 +#define vx_anon_rsspages_inc(m)                vx_acc_anon_rsspage(m, 1)
14018 +#define vx_anon_rsspages_dec(m)                vx_acc_anon_rsspage(m, -1)
14019 +#define vx_anon_rsspages_add(m, p)     vx_acc_anon_rsspages(m, p)
14020 +#define vx_anon_rsspages_sub(m, p)     vx_acc_anon_rsspages(m, -(p))
14021 +
14022 +
14023 +#define vx_pages_avail(m, p, r) \
14024 +       __vx_cres_avail((m)->mm_vx_info, r, p, __FILE__, __LINE__)
14025 +
14026 +#define vx_vmpages_avail(m, p) vx_pages_avail(m, p, RLIMIT_AS)
14027 +#define vx_vmlocked_avail(m, p)        vx_pages_avail(m, p, RLIMIT_MEMLOCK)
14028 +#define vx_anon_avail(m, p)    vx_pages_avail(m, p, VLIMIT_ANON)
14029 +#define vx_mapped_avail(m, p)  vx_pages_avail(m, p, VLIMIT_MAPPED)
14030 +
14031 +#define vx_rss_avail(m, p) \
14032 +       __vx_cres_array_avail((m)->mm_vx_info, VLA_RSS, p, __FILE__, __LINE__)
14033 +
14034 +
14035 +enum {
14036 +       VXPT_UNKNOWN = 0,
14037 +       VXPT_ANON,
14038 +       VXPT_NONE,
14039 +       VXPT_FILE,
14040 +       VXPT_SWAP,
14041 +       VXPT_WRITE
14042 +};
14043 +
14044 +#if 0
14045 +#define        vx_page_fault(mm, vma, type, ret)
14046 +#else
14047 +
14048 +static inline
14049 +void __vx_page_fault(struct mm_struct *mm,
14050 +       struct vm_area_struct *vma, int type, int ret)
14051 +{
14052 +       struct vx_info *vxi = mm->mm_vx_info;
14053 +       int what;
14054 +/*
14055 +       static char *page_type[6] =
14056 +               { "UNKNOWN", "ANON", "NONE", "FILE", "SWAP", "WRITE" };
14057 +       static char *page_what[4] =
14058 +               { "FAULT_OOM", "FAULT_SIGBUS", "FAULT_MINOR", "FAULT_MAJOR" };
14059 +*/
14060 +
14061 +       if (!vxi)
14062 +               return;
14063 +
14064 +       what = (ret & 0x3);
14065 +
14066 +/*     printk("[%d] page[%d][%d] %2x %s %s\n", vxi->vx_id,
14067 +               type, what, ret, page_type[type], page_what[what]);
14068 +*/
14069 +       if (ret & VM_FAULT_WRITE)
14070 +               what |= 0x4;
14071 +       atomic_inc(&vxi->cacct.page[type][what]);
14072 +}
14073 +
14074 +#define        vx_page_fault(mm, vma, type, ret)       __vx_page_fault(mm, vma, type, ret)
14075 +#endif
14076 +
14077 +
14078 +extern unsigned long vx_badness(struct task_struct *task, struct mm_struct *mm);
14079 +
14080 +#else
14081 +#warning duplicate inclusion
14082 +#endif
14083 diff -NurpP --minimal linux-2.6.29/include/linux/vs_network.h linux-2.6.29-vs2.3.0.36.9-pre3/include/linux/vs_network.h
14084 --- linux-2.6.29/include/linux/vs_network.h     1970-01-01 01:00:00.000000000 +0100
14085 +++ linux-2.6.29-vs2.3.0.36.9-pre3/include/linux/vs_network.h   2009-02-22 22:54:26.000000000 +0100
14086 @@ -0,0 +1,169 @@
14087 +#ifndef _NX_VS_NETWORK_H
14088 +#define _NX_VS_NETWORK_H
14089 +
14090 +#include "vserver/context.h"
14091 +#include "vserver/network.h"
14092 +#include "vserver/base.h"
14093 +#include "vserver/check.h"
14094 +#include "vserver/debug.h"
14095 +
14096 +#include <linux/sched.h>
14097 +
14098 +
14099 +#define get_nx_info(i) __get_nx_info(i, __FILE__, __LINE__)
14100 +
14101 +static inline struct nx_info *__get_nx_info(struct nx_info *nxi,
14102 +       const char *_file, int _line)
14103 +{
14104 +       if (!nxi)
14105 +               return NULL;
14106 +
14107 +       vxlprintk(VXD_CBIT(nid, 2), "get_nx_info(%p[#%d.%d])",
14108 +               nxi, nxi ? nxi->nx_id : 0,
14109 +               nxi ? atomic_read(&nxi->nx_usecnt) : 0,
14110 +               _file, _line);
14111 +
14112 +       atomic_inc(&nxi->nx_usecnt);
14113 +       return nxi;
14114 +}
14115 +
14116 +
14117 +extern void free_nx_info(struct nx_info *);
14118 +
14119 +#define put_nx_info(i) __put_nx_info(i, __FILE__, __LINE__)
14120 +
14121 +static inline void __put_nx_info(struct nx_info *nxi, const char *_file, int _line)
14122 +{
14123 +       if (!nxi)
14124 +               return;
14125 +
14126 +       vxlprintk(VXD_CBIT(nid, 2), "put_nx_info(%p[#%d.%d])",
14127 +               nxi, nxi ? nxi->nx_id : 0,
14128 +               nxi ? atomic_read(&nxi->nx_usecnt) : 0,
14129 +               _file, _line);
14130 +
14131 +       if (atomic_dec_and_test(&nxi->nx_usecnt))
14132 +               free_nx_info(nxi);
14133 +}
14134 +
14135 +
14136 +#define init_nx_info(p, i) __init_nx_info(p, i, __FILE__, __LINE__)
14137 +
14138 +static inline void __init_nx_info(struct nx_info **nxp, struct nx_info *nxi,
14139 +               const char *_file, int _line)
14140 +{
14141 +       if (nxi) {
14142 +               vxlprintk(VXD_CBIT(nid, 3),
14143 +                       "init_nx_info(%p[#%d.%d])",
14144 +                       nxi, nxi ? nxi->nx_id : 0,
14145 +                       nxi ? atomic_read(&nxi->nx_usecnt) : 0,
14146 +                       _file, _line);
14147 +
14148 +               atomic_inc(&nxi->nx_usecnt);
14149 +       }
14150 +       *nxp = nxi;
14151 +}
14152 +
14153 +
14154 +#define set_nx_info(p, i) __set_nx_info(p, i, __FILE__, __LINE__)
14155 +
14156 +static inline void __set_nx_info(struct nx_info **nxp, struct nx_info *nxi,
14157 +       const char *_file, int _line)
14158 +{
14159 +       struct nx_info *nxo;
14160 +
14161 +       if (!nxi)
14162 +               return;
14163 +
14164 +       vxlprintk(VXD_CBIT(nid, 3), "set_nx_info(%p[#%d.%d])",
14165 +               nxi, nxi ? nxi->nx_id : 0,
14166 +               nxi ? atomic_read(&nxi->nx_usecnt) : 0,
14167 +               _file, _line);
14168 +
14169 +       atomic_inc(&nxi->nx_usecnt);
14170 +       nxo = xchg(nxp, nxi);
14171 +       BUG_ON(nxo);
14172 +}
14173 +
14174 +#define clr_nx_info(p) __clr_nx_info(p, __FILE__, __LINE__)
14175 +
14176 +static inline void __clr_nx_info(struct nx_info **nxp,
14177 +       const char *_file, int _line)
14178 +{
14179 +       struct nx_info *nxo;
14180 +
14181 +       nxo = xchg(nxp, NULL);
14182 +       if (!nxo)
14183 +               return;
14184 +
14185 +       vxlprintk(VXD_CBIT(nid, 3), "clr_nx_info(%p[#%d.%d])",
14186 +               nxo, nxo ? nxo->nx_id : 0,
14187 +               nxo ? atomic_read(&nxo->nx_usecnt) : 0,
14188 +               _file, _line);
14189 +
14190 +       if (atomic_dec_and_test(&nxo->nx_usecnt))
14191 +               free_nx_info(nxo);
14192 +}
14193 +
14194 +
14195 +#define claim_nx_info(v, p) __claim_nx_info(v, p, __FILE__, __LINE__)
14196 +
14197 +static inline void __claim_nx_info(struct nx_info *nxi,
14198 +       struct task_struct *task, const char *_file, int _line)
14199 +{
14200 +       vxlprintk(VXD_CBIT(nid, 3), "claim_nx_info(%p[#%d.%d.%d]) %p",
14201 +               nxi, nxi ? nxi->nx_id : 0,
14202 +               nxi?atomic_read(&nxi->nx_usecnt):0,
14203 +               nxi?atomic_read(&nxi->nx_tasks):0,
14204 +               task, _file, _line);
14205 +
14206 +       atomic_inc(&nxi->nx_tasks);
14207 +}
14208 +
14209 +
14210 +extern void unhash_nx_info(struct nx_info *);
14211 +
14212 +#define release_nx_info(v, p) __release_nx_info(v, p, __FILE__, __LINE__)
14213 +
14214 +static inline void __release_nx_info(struct nx_info *nxi,
14215 +       struct task_struct *task, const char *_file, int _line)
14216 +{
14217 +       vxlprintk(VXD_CBIT(nid, 3), "release_nx_info(%p[#%d.%d.%d]) %p",
14218 +               nxi, nxi ? nxi->nx_id : 0,
14219 +               nxi ? atomic_read(&nxi->nx_usecnt) : 0,
14220 +               nxi ? atomic_read(&nxi->nx_tasks) : 0,
14221 +               task, _file, _line);
14222 +
14223 +       might_sleep();
14224 +
14225 +       if (atomic_dec_and_test(&nxi->nx_tasks))
14226 +               unhash_nx_info(nxi);
14227 +}
14228 +
14229 +
14230 +#define task_get_nx_info(i)    __task_get_nx_info(i, __FILE__, __LINE__)
14231 +
14232 +static __inline__ struct nx_info *__task_get_nx_info(struct task_struct *p,
14233 +       const char *_file, int _line)
14234 +{
14235 +       struct nx_info *nxi;
14236 +
14237 +       task_lock(p);
14238 +       vxlprintk(VXD_CBIT(nid, 5), "task_get_nx_info(%p)",
14239 +               p, _file, _line);
14240 +       nxi = __get_nx_info(p->nx_info, _file, _line);
14241 +       task_unlock(p);
14242 +       return nxi;
14243 +}
14244 +
14245 +
14246 +static inline void exit_nx_info(struct task_struct *p)
14247 +{
14248 +       if (p->nx_info)
14249 +               release_nx_info(p->nx_info, p);
14250 +}
14251 +
14252 +
14253 +#else
14254 +#warning duplicate inclusion
14255 +#endif
14256 diff -NurpP --minimal linux-2.6.29/include/linux/vs_pid.h linux-2.6.29-vs2.3.0.36.9-pre3/include/linux/vs_pid.h
14257 --- linux-2.6.29/include/linux/vs_pid.h 1970-01-01 01:00:00.000000000 +0100
14258 +++ linux-2.6.29-vs2.3.0.36.9-pre3/include/linux/vs_pid.h       2009-02-22 22:54:26.000000000 +0100
14259 @@ -0,0 +1,95 @@
14260 +#ifndef _VS_PID_H
14261 +#define _VS_PID_H
14262 +
14263 +#include "vserver/base.h"
14264 +#include "vserver/check.h"
14265 +#include "vserver/context.h"
14266 +#include "vserver/debug.h"
14267 +#include "vserver/pid.h"
14268 +#include <linux/pid_namespace.h>
14269 +
14270 +
14271 +#define VXF_FAKE_INIT  (VXF_INFO_INIT | VXF_STATE_INIT)
14272 +
14273 +static inline
14274 +int vx_proc_task_visible(struct task_struct *task)
14275 +{
14276 +       if ((task->pid == 1) &&
14277 +               !vx_flags(VXF_FAKE_INIT, VXF_FAKE_INIT))
14278 +               /* show a blend through init */
14279 +               goto visible;
14280 +       if (vx_check(vx_task_xid(task), VS_WATCH | VS_IDENT))
14281 +               goto visible;
14282 +       return 0;
14283 +visible:
14284 +       return 1;
14285 +}
14286 +
14287 +#define find_task_by_real_pid(pid) find_task_by_pid_ns(pid, &init_pid_ns)
14288 +
14289 +#if 0
14290 +
14291 +static inline
14292 +struct task_struct *vx_find_proc_task_by_pid(int pid)
14293 +{
14294 +       struct task_struct *task = find_task_by_real_pid(pid);
14295 +
14296 +       if (task && !vx_proc_task_visible(task)) {
14297 +               vxdprintk(VXD_CBIT(misc, 6),
14298 +                       "dropping task (find) %p[#%u,%u] for %p[#%u,%u]",
14299 +                       task, task->xid, task->pid,
14300 +                       current, current->xid, current->pid);
14301 +               task = NULL;
14302 +       }
14303 +       return task;
14304 +}
14305 +
14306 +#endif
14307 +
14308 +static inline
14309 +struct task_struct *vx_get_proc_task(struct inode *inode, struct pid *pid)
14310 +{
14311 +       struct task_struct *task = get_pid_task(pid, PIDTYPE_PID);
14312 +
14313 +       if (task && !vx_proc_task_visible(task)) {
14314 +               vxdprintk(VXD_CBIT(misc, 6),
14315 +                       "dropping task (get) %p[#%u,%u] for %p[#%u,%u]",
14316 +                       task, task->xid, task->pid,
14317 +                       current, current->xid, current->pid);
14318 +               put_task_struct(task);
14319 +               task = NULL;
14320 +       }
14321 +       return task;
14322 +}
14323 +
14324 +#if 0
14325 +
14326 +static inline
14327 +struct task_struct *vx_child_reaper(struct task_struct *p)
14328 +{
14329 +       struct vx_info *vxi = p->vx_info;
14330 +       struct task_struct *reaper = child_reaper(p);
14331 +
14332 +       if (!vxi)
14333 +               goto out;
14334 +
14335 +       BUG_ON(!p->vx_info->vx_reaper);
14336 +
14337 +       /* child reaper for the guest reaper */
14338 +       if (vxi->vx_reaper == p)
14339 +               goto out;
14340 +
14341 +       reaper = vxi->vx_reaper;
14342 +out:
14343 +       vxdprintk(VXD_CBIT(xid, 7),
14344 +               "vx_child_reaper(%p[#%u,%u]) = %p[#%u,%u]",
14345 +               p, p->xid, p->pid, reaper, reaper->xid, reaper->pid);
14346 +       return reaper;
14347 +}
14348 +
14349 +#endif
14350 +
14351 +
14352 +#else
14353 +#warning duplicate inclusion
14354 +#endif
14355 diff -NurpP --minimal linux-2.6.29/include/linux/vs_sched.h linux-2.6.29-vs2.3.0.36.9-pre3/include/linux/vs_sched.h
14356 --- linux-2.6.29/include/linux/vs_sched.h       1970-01-01 01:00:00.000000000 +0100
14357 +++ linux-2.6.29-vs2.3.0.36.9-pre3/include/linux/vs_sched.h     2009-02-22 22:54:26.000000000 +0100
14358 @@ -0,0 +1,110 @@
14359 +#ifndef _VS_SCHED_H
14360 +#define _VS_SCHED_H
14361 +
14362 +#include "vserver/base.h"
14363 +#include "vserver/context.h"
14364 +#include "vserver/sched.h"
14365 +
14366 +
14367 +#define VAVAVOOM_RATIO          50
14368 +
14369 +#define MAX_PRIO_BIAS           20
14370 +#define MIN_PRIO_BIAS          -20
14371 +
14372 +
14373 +#ifdef CONFIG_VSERVER_HARDCPU
14374 +
14375 +/*
14376 + * effective_prio - return the priority that is based on the static
14377 + * priority but is modified by bonuses/penalties.
14378 + *
14379 + * We scale the actual sleep average [0 .... MAX_SLEEP_AVG]
14380 + * into a -4 ... 0 ... +4 bonus/penalty range.
14381 + *
14382 + * Additionally, we scale another amount based on the number of
14383 + * CPU tokens currently held by the context, if the process is
14384 + * part of a context (and the appropriate SCHED flag is set).
14385 + * This ranges from -5 ... 0 ... +15, quadratically.
14386 + *
14387 + * So, the total bonus is -9 .. 0 .. +19
14388 + * We use ~50% of the full 0...39 priority range so that:
14389 + *
14390 + * 1) nice +19 interactive tasks do not preempt nice 0 CPU hogs.
14391 + * 2) nice -20 CPU hogs do not get preempted by nice 0 tasks.
14392 + *    unless that context is far exceeding its CPU allocation.
14393 + *
14394 + * Both properties are important to certain workloads.
14395 + */
14396 +static inline
14397 +int vx_effective_vavavoom(struct _vx_sched_pc *sched_pc, int max_prio)
14398 +{
14399 +       int vavavoom, max;
14400 +
14401 +       /* lots of tokens = lots of vavavoom
14402 +        *      no tokens = no vavavoom      */
14403 +       if ((vavavoom = sched_pc->tokens) >= 0) {
14404 +               max = sched_pc->tokens_max;
14405 +               vavavoom = max - vavavoom;
14406 +               max = max * max;
14407 +               vavavoom = max_prio * VAVAVOOM_RATIO / 100
14408 +                       * (vavavoom*vavavoom - (max >> 2)) / max;
14409 +               return vavavoom;
14410 +       }
14411 +       return 0;
14412 +}
14413 +
14414 +
14415 +static inline
14416 +int vx_adjust_prio(struct task_struct *p, int prio, int max_user)
14417 +{
14418 +       struct vx_info *vxi = p->vx_info;
14419 +       struct _vx_sched_pc *sched_pc;
14420 +
14421 +       if (!vxi)
14422 +               return prio;
14423 +
14424 +       sched_pc = &vx_cpu(vxi, sched_pc);
14425 +       if (vx_info_flags(vxi, VXF_SCHED_PRIO, 0)) {
14426 +               int vavavoom = vx_effective_vavavoom(sched_pc, max_user);
14427 +
14428 +               sched_pc->vavavoom = vavavoom;
14429 +               prio += vavavoom;
14430 +       }
14431 +       prio += sched_pc->prio_bias;
14432 +       return prio;
14433 +}
14434 +
14435 +#else /* !CONFIG_VSERVER_HARDCPU */
14436 +
14437 +static inline
14438 +int vx_adjust_prio(struct task_struct *p, int prio, int max_user)
14439 +{
14440 +       struct vx_info *vxi = p->vx_info;
14441 +
14442 +       if (vxi)
14443 +               prio += vx_cpu(vxi, sched_pc).prio_bias;
14444 +       return prio;
14445 +}
14446 +
14447 +#endif /* CONFIG_VSERVER_HARDCPU */
14448 +
14449 +
14450 +static inline void vx_account_user(struct vx_info *vxi,
14451 +       cputime_t cputime, int nice)
14452 +{
14453 +       if (!vxi)
14454 +               return;
14455 +       vx_cpu(vxi, sched_pc).user_ticks += cputime;
14456 +}
14457 +
14458 +static inline void vx_account_system(struct vx_info *vxi,
14459 +       cputime_t cputime, int idle)
14460 +{
14461 +       if (!vxi)
14462 +               return;
14463 +       vx_cpu(vxi, sched_pc).sys_ticks += cputime;
14464 +}
14465 +
14466 +#else
14467 +#warning duplicate inclusion
14468 +#endif
14469 diff -NurpP --minimal linux-2.6.29/include/linux/vs_socket.h linux-2.6.29-vs2.3.0.36.9-pre3/include/linux/vs_socket.h
14470 --- linux-2.6.29/include/linux/vs_socket.h      1970-01-01 01:00:00.000000000 +0100
14471 +++ linux-2.6.29-vs2.3.0.36.9-pre3/include/linux/vs_socket.h    2009-02-22 22:54:26.000000000 +0100
14472 @@ -0,0 +1,67 @@
14473 +#ifndef _VS_SOCKET_H
14474 +#define _VS_SOCKET_H
14475 +
14476 +#include "vserver/debug.h"
14477 +#include "vserver/base.h"
14478 +#include "vserver/cacct.h"
14479 +#include "vserver/context.h"
14480 +#include "vserver/tag.h"
14481 +
14482 +
14483 +/* socket accounting */
14484 +
14485 +#include <linux/socket.h>
14486 +
14487 +static inline int vx_sock_type(int family)
14488 +{
14489 +       switch (family) {
14490 +       case PF_UNSPEC:
14491 +               return VXA_SOCK_UNSPEC;
14492 +       case PF_UNIX:
14493 +               return VXA_SOCK_UNIX;
14494 +       case PF_INET:
14495 +               return VXA_SOCK_INET;
14496 +       case PF_INET6:
14497 +               return VXA_SOCK_INET6;
14498 +       case PF_PACKET:
14499 +               return VXA_SOCK_PACKET;
14500 +       default:
14501 +               return VXA_SOCK_OTHER;
14502 +       }
14503 +}
14504 +
14505 +#define vx_acc_sock(v, f, p, s) \
14506 +       __vx_acc_sock(v, f, p, s, __FILE__, __LINE__)
14507 +
14508 +static inline void __vx_acc_sock(struct vx_info *vxi,
14509 +       int family, int pos, int size, char *file, int line)
14510 +{
14511 +       if (vxi) {
14512 +               int type = vx_sock_type(family);
14513 +
14514 +               atomic_long_inc(&vxi->cacct.sock[type][pos].count);
14515 +               atomic_long_add(size, &vxi->cacct.sock[type][pos].total);
14516 +       }
14517 +}
14518 +
14519 +#define vx_sock_recv(sk, s) \
14520 +       vx_acc_sock((sk)->sk_vx_info, (sk)->sk_family, 0, s)
14521 +#define vx_sock_send(sk, s) \
14522 +       vx_acc_sock((sk)->sk_vx_info, (sk)->sk_family, 1, s)
14523 +#define vx_sock_fail(sk, s) \
14524 +       vx_acc_sock((sk)->sk_vx_info, (sk)->sk_family, 2, s)
14525 +
14526 +
14527 +#define sock_vx_init(s) do {           \
14528 +       (s)->sk_xid = 0;                \
14529 +       (s)->sk_vx_info = NULL;         \
14530 +       } while (0)
14531 +
14532 +#define sock_nx_init(s) do {           \
14533 +       (s)->sk_nid = 0;                \
14534 +       (s)->sk_nx_info = NULL;         \
14535 +       } while (0)
14536 +
14537 +#else
14538 +#warning duplicate inclusion
14539 +#endif
14540 diff -NurpP --minimal linux-2.6.29/include/linux/vs_tag.h linux-2.6.29-vs2.3.0.36.9-pre3/include/linux/vs_tag.h
14541 --- linux-2.6.29/include/linux/vs_tag.h 1970-01-01 01:00:00.000000000 +0100
14542 +++ linux-2.6.29-vs2.3.0.36.9-pre3/include/linux/vs_tag.h       2009-02-22 22:54:26.000000000 +0100
14543 @@ -0,0 +1,47 @@
14544 +#ifndef _VS_TAG_H
14545 +#define _VS_TAG_H
14546 +
14547 +#include <linux/vserver/tag.h>
14548 +
14549 +/* check conditions */
14550 +
14551 +#define DX_ADMIN       0x0001
14552 +#define DX_WATCH       0x0002
14553 +#define DX_HOSTID      0x0008
14554 +
14555 +#define DX_IDENT       0x0010
14556 +
14557 +#define DX_ARG_MASK    0x0010
14558 +
14559 +
14560 +#define dx_task_tag(t) ((t)->tag)
14561 +
14562 +#define dx_current_tag() dx_task_tag(current)
14563 +
14564 +#define dx_check(c, m) __dx_check(dx_current_tag(), c, m)
14565 +
14566 +#define dx_weak_check(c, m)    ((m) ? dx_check(c, m) : 1)
14567 +
14568 +
14569 +/*
14570 + * check current context for ADMIN/WATCH and
14571 + * optionally against supplied argument
14572 + */
14573 +static inline int __dx_check(tag_t cid, tag_t id, unsigned int mode)
14574 +{
14575 +       if (mode & DX_ARG_MASK) {
14576 +               if ((mode & DX_IDENT) && (id == cid))
14577 +                       return 1;
14578 +       }
14579 +       return (((mode & DX_ADMIN) && (cid == 0)) ||
14580 +               ((mode & DX_WATCH) && (cid == 1)) ||
14581 +               ((mode & DX_HOSTID) && (id == 0)));
14582 +}
14583 +
14584 +struct inode;
14585 +int dx_permission(struct inode *inode, int mask);
14586 +
14587 +
14588 +#else
14589 +#warning duplicate inclusion
14590 +#endif
14591 diff -NurpP --minimal linux-2.6.29/include/linux/vs_time.h linux-2.6.29-vs2.3.0.36.9-pre3/include/linux/vs_time.h
14592 --- linux-2.6.29/include/linux/vs_time.h        1970-01-01 01:00:00.000000000 +0100
14593 +++ linux-2.6.29-vs2.3.0.36.9-pre3/include/linux/vs_time.h      2009-02-22 22:54:26.000000000 +0100
14594 @@ -0,0 +1,19 @@
14595 +#ifndef _VS_TIME_H
14596 +#define _VS_TIME_H
14597 +
14598 +
14599 +/* time faking stuff */
14600 +
14601 +#ifdef CONFIG_VSERVER_VTIME
14602 +
14603 +extern void vx_gettimeofday(struct timeval *tv);
14604 +extern int vx_settimeofday(struct timespec *ts);
14605 +
14606 +#else
14607 +#define        vx_gettimeofday(t)      do_gettimeofday(t)
14608 +#define        vx_settimeofday(t)      do_settimeofday(t)
14609 +#endif
14610 +
14611 +#else
14612 +#warning duplicate inclusion
14613 +#endif
14614 diff -NurpP --minimal linux-2.6.29/include/net/addrconf.h linux-2.6.29-vs2.3.0.36.9-pre3/include/net/addrconf.h
14615 --- linux-2.6.29/include/net/addrconf.h 2008-12-25 00:26:37.000000000 +0100
14616 +++ linux-2.6.29-vs2.3.0.36.9-pre3/include/net/addrconf.h       2009-02-22 22:54:26.000000000 +0100
14617 @@ -84,7 +84,8 @@ extern int                    ipv6_dev_get_saddr(struct n
14618                                                struct net_device *dev,
14619                                                const struct in6_addr *daddr,
14620                                                unsigned int srcprefs,
14621 -                                              struct in6_addr *saddr);
14622 +                                              struct in6_addr *saddr,
14623 +                                              struct nx_info *nxi);
14624  extern int                     ipv6_get_lladdr(struct net_device *dev,
14625                                                 struct in6_addr *addr,
14626                                                 unsigned char banned_flags);
14627 diff -NurpP --minimal linux-2.6.29/include/net/af_unix.h linux-2.6.29-vs2.3.0.36.9-pre3/include/net/af_unix.h
14628 --- linux-2.6.29/include/net/af_unix.h  2008-12-25 00:26:37.000000000 +0100
14629 +++ linux-2.6.29-vs2.3.0.36.9-pre3/include/net/af_unix.h        2009-02-22 22:54:26.000000000 +0100
14630 @@ -4,6 +4,7 @@
14631  #include <linux/socket.h>
14632  #include <linux/un.h>
14633  #include <linux/mutex.h>
14634 +#include <linux/vs_base.h>
14635  #include <net/sock.h>
14636  
14637  extern void unix_inflight(struct file *fp);
14638 diff -NurpP --minimal linux-2.6.29/include/net/inet_timewait_sock.h linux-2.6.29-vs2.3.0.36.9-pre3/include/net/inet_timewait_sock.h
14639 --- linux-2.6.29/include/net/inet_timewait_sock.h       2009-03-24 14:22:44.000000000 +0100
14640 +++ linux-2.6.29-vs2.3.0.36.9-pre3/include/net/inet_timewait_sock.h     2009-03-24 14:48:36.000000000 +0100
14641 @@ -15,15 +15,14 @@
14642  #ifndef _INET_TIMEWAIT_SOCK_
14643  #define _INET_TIMEWAIT_SOCK_
14644  
14645 +// #include <net/inet_sock.h>
14646 +#include <net/sock.h>
14647  
14648  #include <linux/list.h>
14649  #include <linux/module.h>
14650  #include <linux/timer.h>
14651  #include <linux/types.h>
14652  #include <linux/workqueue.h>
14653 -
14654 -#include <net/inet_sock.h>
14655 -#include <net/sock.h>
14656  #include <net/tcp_states.h>
14657  #include <net/timewait_sock.h>
14658  
14659 @@ -116,6 +115,10 @@ struct inet_timewait_sock {
14660  #define tw_hash                        __tw_common.skc_hash
14661  #define tw_prot                        __tw_common.skc_prot
14662  #define tw_net                 __tw_common.skc_net
14663 +#define tw_xid                 __tw_common.skc_xid
14664 +#define tw_vx_info             __tw_common.skc_vx_info
14665 +#define tw_nid                 __tw_common.skc_nid
14666 +#define tw_nx_info             __tw_common.skc_nx_info
14667         int                     tw_timeout;
14668         volatile unsigned char  tw_substate;
14669         /* 3 bits hole, try to pack */
14670 diff -NurpP --minimal linux-2.6.29/include/net/route.h linux-2.6.29-vs2.3.0.36.9-pre3/include/net/route.h
14671 --- linux-2.6.29/include/net/route.h    2008-12-25 00:26:37.000000000 +0100
14672 +++ linux-2.6.29-vs2.3.0.36.9-pre3/include/net/route.h  2009-02-22 22:54:26.000000000 +0100
14673 @@ -135,6 +135,9 @@ static inline void ip_rt_put(struct rtab
14674                 dst_release(&rt->u.dst);
14675  }
14676  
14677 +#include <linux/vs_base.h>
14678 +#include <linux/vs_inet.h>
14679 +
14680  #define IPTOS_RT_MASK  (IPTOS_TOS_MASK & ~3)
14681  
14682  extern const __u8 ip_tos2prio[16];
14683 @@ -144,6 +147,9 @@ static inline char rt_tos2priority(u8 to
14684         return ip_tos2prio[IPTOS_TOS(tos)>>1];
14685  }
14686  
14687 +extern int ip_v4_find_src(struct net *net, struct nx_info *,
14688 +       struct rtable **, struct flowi *);
14689 +
14690  static inline int ip_route_connect(struct rtable **rp, __be32 dst,
14691                                    __be32 src, u32 tos, int oif, u8 protocol,
14692                                    __be16 sport, __be16 dport, struct sock *sk,
14693 @@ -161,11 +167,24 @@ static inline int ip_route_connect(struc
14694  
14695         int err;
14696         struct net *net = sock_net(sk);
14697 +       struct nx_info *nx_info = current->nx_info;
14698  
14699         if (inet_sk(sk)->transparent)
14700                 fl.flags |= FLOWI_FLAG_ANYSRC;
14701  
14702 -       if (!dst || !src) {
14703 +       if (sk)
14704 +               nx_info = sk->sk_nx_info;
14705 +
14706 +       vxdprintk(VXD_CBIT(net, 4),
14707 +               "ip_route_connect(%p) %p,%p;%lx",
14708 +               sk, nx_info, sk->sk_socket,
14709 +               (sk->sk_socket?sk->sk_socket->flags:0));
14710 +
14711 +       err = ip_v4_find_src(net, nx_info, rp, &fl);
14712 +       if (err)
14713 +               return err;
14714 +
14715 +       if (!fl.fl4_dst || !fl.fl4_src) {
14716                 err = __ip_route_output_key(net, rp, &fl);
14717                 if (err)
14718                         return err;
14719 diff -NurpP --minimal linux-2.6.29/include/net/sock.h linux-2.6.29-vs2.3.0.36.9-pre3/include/net/sock.h
14720 --- linux-2.6.29/include/net/sock.h     2009-03-24 14:22:44.000000000 +0100
14721 +++ linux-2.6.29-vs2.3.0.36.9-pre3/include/net/sock.h   2009-03-24 14:48:36.000000000 +0100
14722 @@ -134,6 +134,10 @@ struct sock_common {
14723  #ifdef CONFIG_NET_NS
14724         struct net              *skc_net;
14725  #endif
14726 +       xid_t                   skc_xid;
14727 +       struct vx_info          *skc_vx_info;
14728 +       nid_t                   skc_nid;
14729 +       struct nx_info          *skc_nx_info;
14730  };
14731  
14732  /**
14733 @@ -218,6 +222,10 @@ struct sock {
14734  #define sk_hash                        __sk_common.skc_hash
14735  #define sk_prot                        __sk_common.skc_prot
14736  #define sk_net                 __sk_common.skc_net
14737 +#define sk_xid                 __sk_common.skc_xid
14738 +#define sk_vx_info             __sk_common.skc_vx_info
14739 +#define sk_nid                 __sk_common.skc_nid
14740 +#define sk_nx_info             __sk_common.skc_nx_info
14741         unsigned char           sk_shutdown : 2,
14742                                 sk_no_check : 2,
14743                                 sk_userlocks : 4;
14744 diff -NurpP --minimal linux-2.6.29/init/main.c linux-2.6.29-vs2.3.0.36.9-pre3/init/main.c
14745 --- linux-2.6.29/init/main.c    2009-03-24 14:22:44.000000000 +0100
14746 +++ linux-2.6.29-vs2.3.0.36.9-pre3/init/main.c  2009-03-24 17:22:37.000000000 +0100
14747 @@ -64,6 +64,7 @@
14748  #include <linux/ftrace.h>
14749  #include <linux/async.h>
14750  #include <trace/boot.h>
14751 +#include <linux/vserver/percpu.h>
14752  
14753  #include <asm/io.h>
14754  #include <asm/bugs.h>
14755 @@ -381,12 +382,14 @@ EXPORT_SYMBOL(__per_cpu_offset);
14756  
14757  static void __init setup_per_cpu_areas(void)
14758  {
14759 -       unsigned long size, i;
14760 +       unsigned long size, vspc, i;
14761         char *ptr;
14762         unsigned long nr_possible_cpus = num_possible_cpus();
14763  
14764 +       vspc = PERCPU_PERCTX * CONFIG_VSERVER_CONTEXTS;
14765 +
14766         /* Copy section for each CPU (we discard the original) */
14767 -       size = ALIGN(PERCPU_ENOUGH_ROOM, PAGE_SIZE);
14768 +       size = ALIGN(PERCPU_ENOUGH_ROOM + vspc, PAGE_SIZE);
14769         ptr = alloc_bootmem_pages(size * nr_possible_cpus);
14770  
14771         for_each_possible_cpu(i) {
14772 diff -NurpP --minimal linux-2.6.29/ipc/mqueue.c linux-2.6.29-vs2.3.0.36.9-pre3/ipc/mqueue.c
14773 --- linux-2.6.29/ipc/mqueue.c   2009-03-24 14:22:44.000000000 +0100
14774 +++ linux-2.6.29-vs2.3.0.36.9-pre3/ipc/mqueue.c 2009-03-24 17:24:19.000000000 +0100
14775 @@ -31,6 +31,8 @@
14776  #include <linux/mutex.h>
14777  #include <linux/nsproxy.h>
14778  #include <linux/pid.h>
14779 +#include <linux/vs_context.h>
14780 +#include <linux/vs_limit.h>
14781  
14782  #include <net/sock.h>
14783  #include "util.h"
14784 @@ -79,6 +81,7 @@ struct mqueue_inode_info {
14785         struct sigevent notify;
14786         struct pid* notify_owner;
14787         struct user_struct *user;       /* user who created, for accounting */
14788 +       struct vx_info *vxi;
14789         struct sock *notify_sock;
14790         struct sk_buff *notify_cookie;
14791  
14792 @@ -126,6 +129,7 @@ static struct inode *mqueue_get_inode(st
14793                 if (S_ISREG(mode)) {
14794                         struct mqueue_inode_info *info;
14795                         struct task_struct *p = current;
14796 +                       struct vx_info *vxi = p->vx_info;
14797                         unsigned long mq_bytes, mq_msg_tblsz;
14798  
14799                         inode->i_fop = &mqueue_file_operations;
14800 @@ -140,6 +144,7 @@ static struct inode *mqueue_get_inode(st
14801                         info->notify_owner = NULL;
14802                         info->qsize = 0;
14803                         info->user = NULL;      /* set when all is ok */
14804 +                       info->vxi = NULL;
14805                         memset(&info->attr, 0, sizeof(info->attr));
14806                         info->attr.mq_maxmsg = msg_max;
14807                         info->attr.mq_msgsize = msgsize_max;
14808 @@ -154,22 +159,26 @@ static struct inode *mqueue_get_inode(st
14809                         spin_lock(&mq_lock);
14810                         if (u->mq_bytes + mq_bytes < u->mq_bytes ||
14811                             u->mq_bytes + mq_bytes >
14812 -                           p->signal->rlim[RLIMIT_MSGQUEUE].rlim_cur) {
14813 +                           p->signal->rlim[RLIMIT_MSGQUEUE].rlim_cur ||
14814 +                           !vx_ipcmsg_avail(vxi, mq_bytes)) {
14815                                 spin_unlock(&mq_lock);
14816                                 goto out_inode;
14817                         }
14818                         u->mq_bytes += mq_bytes;
14819 +                       vx_ipcmsg_add(vxi, u, mq_bytes);
14820                         spin_unlock(&mq_lock);
14821  
14822                         info->messages = kmalloc(mq_msg_tblsz, GFP_KERNEL);
14823                         if (!info->messages) {
14824                                 spin_lock(&mq_lock);
14825                                 u->mq_bytes -= mq_bytes;
14826 +                               vx_ipcmsg_sub(vxi, u, mq_bytes);
14827                                 spin_unlock(&mq_lock);
14828                                 goto out_inode;
14829                         }
14830                         /* all is ok */
14831                         info->user = get_uid(u);
14832 +                       info->vxi = get_vx_info(vxi);
14833                 } else if (S_ISDIR(mode)) {
14834                         inc_nlink(inode);
14835                         /* Some things misbehave if size == 0 on a directory */
14836 @@ -260,10 +269,14 @@ static void mqueue_delete_inode(struct i
14837                    (info->attr.mq_maxmsg * info->attr.mq_msgsize));
14838         user = info->user;
14839         if (user) {
14840 +               struct vx_info *vxi = info->vxi;
14841 +
14842                 spin_lock(&mq_lock);
14843                 user->mq_bytes -= mq_bytes;
14844 +               vx_ipcmsg_sub(vxi, user, mq_bytes);
14845                 queues_count--;
14846                 spin_unlock(&mq_lock);
14847 +               put_vx_info(vxi);
14848                 free_uid(user);
14849         }
14850  }
14851 diff -NurpP --minimal linux-2.6.29/ipc/msg.c linux-2.6.29-vs2.3.0.36.9-pre3/ipc/msg.c
14852 --- linux-2.6.29/ipc/msg.c      2009-03-24 14:22:44.000000000 +0100
14853 +++ linux-2.6.29-vs2.3.0.36.9-pre3/ipc/msg.c    2009-02-22 22:54:26.000000000 +0100
14854 @@ -38,6 +38,7 @@
14855  #include <linux/rwsem.h>
14856  #include <linux/nsproxy.h>
14857  #include <linux/ipc_namespace.h>
14858 +#include <linux/vs_base.h>
14859  
14860  #include <asm/current.h>
14861  #include <asm/uaccess.h>
14862 @@ -190,6 +191,7 @@ static int newque(struct ipc_namespace *
14863  
14864         msq->q_perm.mode = msgflg & S_IRWXUGO;
14865         msq->q_perm.key = key;
14866 +       msq->q_perm.xid = vx_current_xid();
14867  
14868         msq->q_perm.security = NULL;
14869         retval = security_msg_queue_alloc(msq);
14870 diff -NurpP --minimal linux-2.6.29/ipc/namespace.c linux-2.6.29-vs2.3.0.36.9-pre3/ipc/namespace.c
14871 --- linux-2.6.29/ipc/namespace.c        2008-12-25 00:26:37.000000000 +0100
14872 +++ linux-2.6.29-vs2.3.0.36.9-pre3/ipc/namespace.c      2009-02-22 22:54:26.000000000 +0100
14873 @@ -9,6 +9,8 @@
14874  #include <linux/rcupdate.h>
14875  #include <linux/nsproxy.h>
14876  #include <linux/slab.h>
14877 +#include <linux/vs_base.h>
14878 +#include <linux/vserver/global.h>
14879  
14880  #include "util.h"
14881  
14882 @@ -35,6 +37,7 @@ static struct ipc_namespace *clone_ipc_n
14883         register_ipcns_notifier(ns);
14884  
14885         kref_init(&ns->kref);
14886 +       atomic_inc(&vs_global_ipc_ns);
14887         return ns;
14888  }
14889  
14890 @@ -101,6 +104,7 @@ void free_ipc_ns(struct kref *kref)
14891         sem_exit_ns(ns);
14892         msg_exit_ns(ns);
14893         shm_exit_ns(ns);
14894 +       atomic_dec(&vs_global_ipc_ns);
14895         kfree(ns);
14896         atomic_dec(&nr_ipc_ns);
14897  
14898 diff -NurpP --minimal linux-2.6.29/ipc/sem.c linux-2.6.29-vs2.3.0.36.9-pre3/ipc/sem.c
14899 --- linux-2.6.29/ipc/sem.c      2009-03-24 14:22:44.000000000 +0100
14900 +++ linux-2.6.29-vs2.3.0.36.9-pre3/ipc/sem.c    2009-03-31 23:31:33.000000000 +0200
14901 @@ -83,6 +83,8 @@
14902  #include <linux/rwsem.h>
14903  #include <linux/nsproxy.h>
14904  #include <linux/ipc_namespace.h>
14905 +#include <linux/vs_base.h>
14906 +#include <linux/vs_limit.h>
14907  
14908  #include <asm/uaccess.h>
14909  #include "util.h"
14910 @@ -255,6 +257,7 @@ static int newary(struct ipc_namespace *
14911  
14912         sma->sem_perm.mode = (semflg & S_IRWXUGO);
14913         sma->sem_perm.key = key;
14914 +       sma->sem_perm.xid = vx_current_xid();
14915  
14916         sma->sem_perm.security = NULL;
14917         retval = security_sem_alloc(sma);
14918 @@ -270,6 +273,9 @@ static int newary(struct ipc_namespace *
14919                 return id;
14920         }
14921         ns->used_sems += nsems;
14922 +       /* FIXME: obsoleted? */
14923 +       vx_semary_inc(sma);
14924 +       vx_nsems_add(sma, nsems);
14925  
14926         sma->sem_base = (struct sem *) &sma[1];
14927         INIT_LIST_HEAD(&sma->sem_pending);
14928 @@ -546,6 +552,9 @@ static void freeary(struct ipc_namespace
14929         sem_unlock(sma);
14930  
14931         ns->used_sems -= sma->sem_nsems;
14932 +       /* FIXME: obsoleted? */
14933 +       vx_nsems_sub(sma, sma->sem_nsems);
14934 +       vx_semary_dec(sma);
14935         security_sem_free(sma);
14936         ipc_rcu_putref(sma);
14937  }
14938 diff -NurpP --minimal linux-2.6.29/ipc/shm.c linux-2.6.29-vs2.3.0.36.9-pre3/ipc/shm.c
14939 --- linux-2.6.29/ipc/shm.c      2009-03-24 14:22:44.000000000 +0100
14940 +++ linux-2.6.29-vs2.3.0.36.9-pre3/ipc/shm.c    2009-03-24 14:48:36.000000000 +0100
14941 @@ -39,6 +39,8 @@
14942  #include <linux/nsproxy.h>
14943  #include <linux/mount.h>
14944  #include <linux/ipc_namespace.h>
14945 +#include <linux/vs_context.h>
14946 +#include <linux/vs_limit.h>
14947  
14948  #include <asm/uaccess.h>
14949  
14950 @@ -168,7 +170,12 @@ static void shm_open(struct vm_area_stru
14951   */
14952  static void shm_destroy(struct ipc_namespace *ns, struct shmid_kernel *shp)
14953  {
14954 -       ns->shm_tot -= (shp->shm_segsz + PAGE_SIZE - 1) >> PAGE_SHIFT;
14955 +       struct vx_info *vxi = lookup_vx_info(shp->shm_perm.xid);
14956 +       int numpages = (shp->shm_segsz + PAGE_SIZE - 1) >> PAGE_SHIFT;
14957 +
14958 +       vx_ipcshm_sub(vxi, shp, numpages);
14959 +       ns->shm_tot -= numpages;
14960 +
14961         shm_rmid(ns, shp);
14962         shm_unlock(shp);
14963         if (!is_file_hugepages(shp->shm_file))
14964 @@ -178,6 +185,7 @@ static void shm_destroy(struct ipc_names
14965                                                 shp->mlock_user);
14966         fput (shp->shm_file);
14967         security_shm_free(shp);
14968 +       put_vx_info(vxi);
14969         ipc_rcu_putref(shp);
14970  }
14971  
14972 @@ -348,11 +356,15 @@ static int newseg(struct ipc_namespace *
14973         if (ns->shm_tot + numpages > ns->shm_ctlall)
14974                 return -ENOSPC;
14975  
14976 +       if (!vx_ipcshm_avail(current->vx_info, numpages))
14977 +               return -ENOSPC;
14978 +
14979         shp = ipc_rcu_alloc(sizeof(*shp));
14980         if (!shp)
14981                 return -ENOMEM;
14982  
14983         shp->shm_perm.key = key;
14984 +       shp->shm_perm.xid = vx_current_xid();
14985         shp->shm_perm.mode = (shmflg & S_IRWXUGO);
14986         shp->mlock_user = NULL;
14987  
14988 @@ -406,6 +418,7 @@ static int newseg(struct ipc_namespace *
14989         ns->shm_tot += numpages;
14990         error = shp->shm_perm.id;
14991         shm_unlock(shp);
14992 +       vx_ipcshm_add(current->vx_info, key, numpages);
14993         return error;
14994  
14995  no_id:
14996 diff -NurpP --minimal linux-2.6.29/kernel/capability.c linux-2.6.29-vs2.3.0.36.9-pre3/kernel/capability.c
14997 --- linux-2.6.29/kernel/capability.c    2009-03-24 14:22:44.000000000 +0100
14998 +++ linux-2.6.29-vs2.3.0.36.9-pre3/kernel/capability.c  2009-03-24 17:27:28.000000000 +0100
14999 @@ -14,6 +14,7 @@
15000  #include <linux/security.h>
15001  #include <linux/syscalls.h>
15002  #include <linux/pid_namespace.h>
15003 +#include <linux/vs_context.h>
15004  #include <asm/uaccess.h>
15005  #include "cred-internals.h"
15006  
15007 @@ -122,6 +123,7 @@ static int cap_validate_magic(cap_user_h
15008         return 0;
15009  }
15010  
15011 +
15012  /*
15013   * The only thing that can change the capabilities of the current
15014   * process is the current process. As such, we can't be in this code
15015 @@ -289,6 +291,8 @@ error:
15016         return ret;
15017  }
15018  
15019 +#include <linux/vserver/base.h>
15020 +
15021  /**
15022   * capable - Determine if the current task has a superior capability in effect
15023   * @cap: The capability to be tested for
15024 @@ -301,6 +305,9 @@ error:
15025   */
15026  int capable(int cap)
15027  {
15028 +       /* here for now so we don't require task locking */
15029 +       if (vs_check_bit(VXC_CAP_MASK, cap) && !vx_mcaps(1L << cap))
15030 +               return 0;
15031         if (unlikely(!cap_valid(cap))) {
15032                 printk(KERN_CRIT "capable() called with invalid cap=%u\n", cap);
15033                 BUG();
15034 diff -NurpP --minimal linux-2.6.29/kernel/compat.c linux-2.6.29-vs2.3.0.36.9-pre3/kernel/compat.c
15035 --- linux-2.6.29/kernel/compat.c        2009-03-24 14:22:44.000000000 +0100
15036 +++ linux-2.6.29-vs2.3.0.36.9-pre3/kernel/compat.c      2009-03-24 14:48:36.000000000 +0100
15037 @@ -891,7 +891,7 @@ asmlinkage long compat_sys_time(compat_t
15038         compat_time_t i;
15039         struct timeval tv;
15040  
15041 -       do_gettimeofday(&tv);
15042 +       vx_gettimeofday(&tv);
15043         i = tv.tv_sec;
15044  
15045         if (tloc) {
15046 @@ -916,7 +916,7 @@ asmlinkage long compat_sys_stime(compat_
15047         if (err)
15048                 return err;
15049  
15050 -       do_settimeofday(&tv);
15051 +       vx_settimeofday(&tv);
15052         return 0;
15053  }
15054  
15055 diff -NurpP --minimal linux-2.6.29/kernel/exit.c linux-2.6.29-vs2.3.0.36.9-pre3/kernel/exit.c
15056 --- linux-2.6.29/kernel/exit.c  2009-03-24 14:22:44.000000000 +0100
15057 +++ linux-2.6.29-vs2.3.0.36.9-pre3/kernel/exit.c        2009-03-24 17:28:40.000000000 +0100
15058 @@ -47,6 +47,11 @@
15059  #include <linux/task_io_accounting_ops.h>
15060  #include <linux/tracehook.h>
15061  #include <linux/init_task.h>
15062 +#include <linux/vs_limit.h>
15063 +#include <linux/vs_context.h>
15064 +#include <linux/vs_network.h>
15065 +#include <linux/vs_pid.h>
15066 +#include <linux/vserver/global.h>
15067  #include <trace/sched.h>
15068  
15069  #include <asm/uaccess.h>
15070 @@ -502,9 +507,11 @@ static void close_files(struct files_str
15071                                         filp_close(file, files);
15072                                         cond_resched();
15073                                 }
15074 +                               vx_openfd_dec(i);
15075                         }
15076                         i++;
15077                         set >>= 1;
15078 +                       cond_resched();
15079                 }
15080         }
15081  }
15082 @@ -571,6 +578,7 @@ void put_fs_struct(struct fs_struct *fs)
15083         if (atomic_dec_and_test(&fs->count)) {
15084                 path_put(&fs->root);
15085                 path_put(&fs->pwd);
15086 +               atomic_dec(&vs_global_fs);
15087                 kmem_cache_free(fs_cachep, fs);
15088         }
15089  }
15090 @@ -1122,10 +1130,15 @@ NORET_TYPE void do_exit(long code)
15091         if (tsk->splice_pipe)
15092                 __free_pipe_info(tsk->splice_pipe);
15093  
15094 +       /* needs to stay after exit_notify() */
15095 +       exit_vx_info(tsk, code);
15096 +       exit_nx_info(tsk);
15097 +
15098         preempt_disable();
15099         /* causes final put_task_struct in finish_task_switch(). */
15100         tsk->state = TASK_DEAD;
15101         schedule();
15102 +       printk("bad task: %p [%lx]\n", current, current->state);
15103         BUG();
15104         /* Avoid "noreturn function does return".  */
15105         for (;;)
15106 diff -NurpP --minimal linux-2.6.29/kernel/fork.c linux-2.6.29-vs2.3.0.36.9-pre3/kernel/fork.c
15107 --- linux-2.6.29/kernel/fork.c  2009-03-24 14:22:44.000000000 +0100
15108 +++ linux-2.6.29-vs2.3.0.36.9-pre3/kernel/fork.c        2009-03-24 17:31:42.000000000 +0100
15109 @@ -60,6 +60,11 @@
15110  #include <linux/tty.h>
15111  #include <linux/proc_fs.h>
15112  #include <linux/blkdev.h>
15113 +#include <linux/vs_context.h>
15114 +#include <linux/vs_network.h>
15115 +#include <linux/vs_limit.h>
15116 +#include <linux/vs_memory.h>
15117 +#include <linux/vserver/global.h>
15118  #include <trace/sched.h>
15119  
15120  #include <asm/pgtable.h>
15121 @@ -140,6 +145,8 @@ void free_task(struct task_struct *tsk)
15122         prop_local_destroy_single(&tsk->dirties);
15123         free_thread_info(tsk->stack);
15124         rt_mutex_debug_task_free(tsk);
15125 +       clr_vx_info(&tsk->vx_info);
15126 +       clr_nx_info(&tsk->nx_info);
15127         ftrace_graph_exit_task(tsk);
15128         free_task_struct(tsk);
15129  }
15130 @@ -279,6 +286,8 @@ static int dup_mmap(struct mm_struct *mm
15131         mm->free_area_cache = oldmm->mmap_base;
15132         mm->cached_hole_size = ~0UL;
15133         mm->map_count = 0;
15134 +       __set_mm_counter(mm, file_rss, 0);
15135 +       __set_mm_counter(mm, anon_rss, 0);
15136         cpus_clear(mm->cpu_vm_mask);
15137         mm->mm_rb = RB_ROOT;
15138         rb_link = &mm->mm_rb.rb_node;
15139 @@ -290,7 +299,7 @@ static int dup_mmap(struct mm_struct *mm
15140  
15141                 if (mpnt->vm_flags & VM_DONTCOPY) {
15142                         long pages = vma_pages(mpnt);
15143 -                       mm->total_vm -= pages;
15144 +                       vx_vmpages_sub(mm, pages);
15145                         vm_stat_account(mm, mpnt->vm_flags, mpnt->vm_file,
15146                                                                 -pages);
15147                         continue;
15148 @@ -423,8 +432,8 @@ static struct mm_struct * mm_init(struct
15149         mm->flags = (current->mm) ? current->mm->flags : default_dump_filter;
15150         mm->core_state = NULL;
15151         mm->nr_ptes = 0;
15152 -       set_mm_counter(mm, file_rss, 0);
15153 -       set_mm_counter(mm, anon_rss, 0);
15154 +       __set_mm_counter(mm, file_rss, 0);
15155 +       __set_mm_counter(mm, anon_rss, 0);
15156         spin_lock_init(&mm->page_table_lock);
15157         spin_lock_init(&mm->ioctx_lock);
15158         INIT_HLIST_HEAD(&mm->ioctx_list);
15159 @@ -435,6 +444,7 @@ static struct mm_struct * mm_init(struct
15160         if (likely(!mm_alloc_pgd(mm))) {
15161                 mm->def_flags = 0;
15162                 mmu_notifier_mm_init(mm);
15163 +               set_vx_info(&mm->mm_vx_info, p->vx_info);
15164                 return mm;
15165         }
15166  
15167 @@ -468,6 +478,7 @@ void __mmdrop(struct mm_struct *mm)
15168         mm_free_pgd(mm);
15169         destroy_context(mm);
15170         mmu_notifier_mm_destroy(mm);
15171 +       clr_vx_info(&mm->mm_vx_info);
15172         free_mm(mm);
15173  }
15174  EXPORT_SYMBOL_GPL(__mmdrop);
15175 @@ -594,6 +605,7 @@ struct mm_struct *dup_mm(struct task_str
15176                 goto fail_nomem;
15177  
15178         memcpy(mm, oldmm, sizeof(*mm));
15179 +       mm->mm_vx_info = NULL;
15180  
15181         /* Initializing for Swap token stuff */
15182         mm->token_priority = 0;
15183 @@ -627,6 +639,7 @@ fail_nocontext:
15184          * If init_new_context() failed, we cannot use mmput() to free the mm
15185          * because it calls destroy_context()
15186          */
15187 +       clr_vx_info(&mm->mm_vx_info);
15188         mm_free_pgd(mm);
15189         free_mm(mm);
15190         return NULL;
15191 @@ -690,6 +703,7 @@ static struct fs_struct *__copy_fs_struc
15192                 fs->pwd = old->pwd;
15193                 path_get(&old->pwd);
15194                 read_unlock(&old->lock);
15195 +               atomic_inc(&vs_global_fs);
15196         }
15197         return fs;
15198  }
15199 @@ -955,6 +969,8 @@ static struct task_struct *copy_process(
15200         int retval;
15201         struct task_struct *p;
15202         int cgroup_callbacks_done = 0;
15203 +       struct vx_info *vxi;
15204 +       struct nx_info *nxi;
15205  
15206         if ((clone_flags & (CLONE_NEWNS|CLONE_FS)) == (CLONE_NEWNS|CLONE_FS))
15207                 return ERR_PTR(-EINVAL);
15208 @@ -989,12 +1005,28 @@ static struct task_struct *copy_process(
15209         DEBUG_LOCKS_WARN_ON(!p->hardirqs_enabled);
15210         DEBUG_LOCKS_WARN_ON(!p->softirqs_enabled);
15211  #endif
15212 +       init_vx_info(&p->vx_info, current->vx_info);
15213 +       init_nx_info(&p->nx_info, current->nx_info);
15214 +
15215 +       /* check vserver memory */
15216 +       if (p->mm && !(clone_flags & CLONE_VM)) {
15217 +               if (vx_vmpages_avail(p->mm, p->mm->total_vm))
15218 +                       vx_pages_add(p->vx_info, RLIMIT_AS, p->mm->total_vm);
15219 +               else
15220 +                       goto bad_fork_free;
15221 +       }
15222 +       if (p->mm && vx_flags(VXF_FORK_RSS, 0)) {
15223 +               if (!vx_rss_avail(p->mm, get_mm_counter(p->mm, file_rss)))
15224 +                       goto bad_fork_cleanup_vm;
15225 +       }
15226         retval = -EAGAIN;
15227 +       if (!vx_nproc_avail(1))
15228 +               goto bad_fork_cleanup_vm;
15229         if (atomic_read(&p->real_cred->user->processes) >=
15230                         p->signal->rlim[RLIMIT_NPROC].rlim_cur) {
15231                 if (!capable(CAP_SYS_ADMIN) && !capable(CAP_SYS_RESOURCE) &&
15232                     p->real_cred->user != INIT_USER)
15233 -                       goto bad_fork_free;
15234 +                       goto bad_fork_cleanup_vm;
15235         }
15236  
15237         retval = copy_creds(p, clone_flags);
15238 @@ -1271,6 +1303,18 @@ static struct task_struct *copy_process(
15239  
15240         total_forks++;
15241         spin_unlock(&current->sighand->siglock);
15242 +
15243 +       /* p is copy of current */
15244 +       vxi = p->vx_info;
15245 +       if (vxi) {
15246 +               claim_vx_info(vxi, p);
15247 +               atomic_inc(&vxi->cvirt.nr_threads);
15248 +               atomic_inc(&vxi->cvirt.total_forks);
15249 +               vx_nproc_inc(p);
15250 +       }
15251 +       nxi = p->nx_info;
15252 +       if (nxi)
15253 +               claim_nx_info(nxi, p);
15254         write_unlock_irq(&tasklist_lock);
15255         proc_fork_connector(p);
15256         cgroup_post_fork(p);
15257 @@ -1315,6 +1359,9 @@ bad_fork_cleanup_count:
15258         atomic_dec(&p->cred->user->processes);
15259         put_cred(p->real_cred);
15260         put_cred(p->cred);
15261 +bad_fork_cleanup_vm:
15262 +       if (p->mm && !(clone_flags & CLONE_VM))
15263 +               vx_pages_sub(p->vx_info, RLIMIT_AS, p->mm->total_vm);
15264  bad_fork_free:
15265         free_task(p);
15266  fork_out:
15267 diff -NurpP --minimal linux-2.6.29/kernel/kthread.c linux-2.6.29-vs2.3.0.36.9-pre3/kernel/kthread.c
15268 --- linux-2.6.29/kernel/kthread.c       2009-03-24 14:22:44.000000000 +0100
15269 +++ linux-2.6.29-vs2.3.0.36.9-pre3/kernel/kthread.c     2009-03-24 14:48:36.000000000 +0100
15270 @@ -13,6 +13,7 @@
15271  #include <linux/file.h>
15272  #include <linux/module.h>
15273  #include <linux/mutex.h>
15274 +#include <linux/vs_pid.h>
15275  #include <trace/sched.h>
15276  
15277  #define KTHREAD_NICE_LEVEL (-5)
15278 @@ -102,7 +103,7 @@ static void create_kthread(struct kthrea
15279                 struct sched_param param = { .sched_priority = 0 };
15280                 wait_for_completion(&create->started);
15281                 read_lock(&tasklist_lock);
15282 -               create->result = find_task_by_pid_ns(pid, &init_pid_ns);
15283 +               create->result = find_task_by_real_pid(pid);
15284                 read_unlock(&tasklist_lock);
15285                 /*
15286                  * root may have changed our (kthreadd's) priority or CPU mask.
15287 diff -NurpP --minimal linux-2.6.29/kernel/Makefile linux-2.6.29-vs2.3.0.36.9-pre3/kernel/Makefile
15288 --- linux-2.6.29/kernel/Makefile        2009-03-24 14:22:44.000000000 +0100
15289 +++ linux-2.6.29-vs2.3.0.36.9-pre3/kernel/Makefile      2009-03-24 14:48:36.000000000 +0100
15290 @@ -22,6 +22,7 @@ CFLAGS_REMOVE_cgroup-debug.o = -pg
15291  CFLAGS_REMOVE_sched_clock.o = -pg
15292  endif
15293  
15294 +obj-y += vserver/
15295  obj-$(CONFIG_FREEZER) += freezer.o
15296  obj-$(CONFIG_PROFILING) += profile.o
15297  obj-$(CONFIG_SYSCTL_SYSCALL_CHECK) += sysctl_check.o
15298 diff -NurpP --minimal linux-2.6.29/kernel/nsproxy.c linux-2.6.29-vs2.3.0.36.9-pre3/kernel/nsproxy.c
15299 --- linux-2.6.29/kernel/nsproxy.c       2009-03-24 14:22:44.000000000 +0100
15300 +++ linux-2.6.29-vs2.3.0.36.9-pre3/kernel/nsproxy.c     2009-03-25 00:39:02.000000000 +0100
15301 @@ -19,6 +19,8 @@
15302  #include <linux/mnt_namespace.h>
15303  #include <linux/utsname.h>
15304  #include <linux/pid_namespace.h>
15305 +#include <linux/vserver/global.h>
15306 +#include <linux/vserver/debug.h>
15307  #include <net/net_namespace.h>
15308  #include <linux/ipc_namespace.h>
15309  
15310 @@ -37,6 +39,9 @@ static inline struct nsproxy *clone_nspr
15311         if (ns) {
15312                 memcpy(ns, orig, sizeof(struct nsproxy));
15313                 atomic_set(&ns->count, 1);
15314 +               vxdprintk(VXD_CBIT(space, 2), "clone_nsproxy(%p[%u] = %p[1]",
15315 +                       orig, atomic_read(&orig->count), ns);
15316 +               atomic_inc(&vs_global_nsproxy);
15317         }
15318         return ns;
15319  }
15320 @@ -46,41 +51,52 @@ static inline struct nsproxy *clone_nspr
15321   * Return the newly created nsproxy.  Do not attach this to the task,
15322   * leave it to the caller to do proper locking and attach it to task.
15323   */
15324 -static struct nsproxy *create_new_namespaces(unsigned long flags,
15325 -                       struct task_struct *tsk, struct fs_struct *new_fs)
15326 +static struct nsproxy *unshare_namespaces(unsigned long flags,
15327 +                       struct nsproxy *orig, struct fs_struct *new_fs)
15328  {
15329         struct nsproxy *new_nsp;
15330         int err;
15331  
15332 -       new_nsp = clone_nsproxy(tsk->nsproxy);
15333 +       vxdprintk(VXD_CBIT(space, 4),
15334 +               "unshare_namespaces(0x%08lx,%p,%p)",
15335 +               flags, orig, new_fs);
15336 +
15337 +       new_nsp = clone_nsproxy(orig);
15338         if (!new_nsp)
15339                 return ERR_PTR(-ENOMEM);
15340  
15341 -       new_nsp->mnt_ns = copy_mnt_ns(flags, tsk->nsproxy->mnt_ns, new_fs);
15342 +       new_nsp->mnt_ns = copy_mnt_ns(flags, orig->mnt_ns, new_fs);
15343         if (IS_ERR(new_nsp->mnt_ns)) {
15344                 err = PTR_ERR(new_nsp->mnt_ns);
15345                 goto out_ns;
15346         }
15347  
15348 -       new_nsp->uts_ns = copy_utsname(flags, tsk->nsproxy->uts_ns);
15349 +       new_nsp->uts_ns = copy_utsname(flags, orig->uts_ns);
15350         if (IS_ERR(new_nsp->uts_ns)) {
15351                 err = PTR_ERR(new_nsp->uts_ns);
15352                 goto out_uts;
15353         }
15354  
15355 -       new_nsp->ipc_ns = copy_ipcs(flags, tsk->nsproxy->ipc_ns);
15356 +       new_nsp->ipc_ns = copy_ipcs(flags, orig->ipc_ns);
15357         if (IS_ERR(new_nsp->ipc_ns)) {
15358                 err = PTR_ERR(new_nsp->ipc_ns);
15359                 goto out_ipc;
15360         }
15361  
15362 -       new_nsp->pid_ns = copy_pid_ns(flags, task_active_pid_ns(tsk));
15363 +       new_nsp->pid_ns = copy_pid_ns(flags, orig->pid_ns);
15364         if (IS_ERR(new_nsp->pid_ns)) {
15365                 err = PTR_ERR(new_nsp->pid_ns);
15366                 goto out_pid;
15367         }
15368  
15369 -       new_nsp->net_ns = copy_net_ns(flags, tsk->nsproxy->net_ns);
15370 +       /* disabled now?
15371 +       new_nsp->user_ns = copy_user_ns(flags, orig->user_ns);
15372 +       if (IS_ERR(new_nsp->user_ns)) {
15373 +               err = PTR_ERR(new_nsp->user_ns);
15374 +               goto out_user;
15375 +       } */
15376 +
15377 +       new_nsp->net_ns = copy_net_ns(flags, orig->net_ns);
15378         if (IS_ERR(new_nsp->net_ns)) {
15379                 err = PTR_ERR(new_nsp->net_ns);
15380                 goto out_net;
15381 @@ -105,6 +121,35 @@ out_ns:
15382         return ERR_PTR(err);
15383  }
15384  
15385 +static struct nsproxy *create_new_namespaces(int flags, struct task_struct *tsk,
15386 +                       struct fs_struct *new_fs)
15387 +{
15388 +       return unshare_namespaces(flags, tsk->nsproxy, new_fs);
15389 +}
15390 +
15391 +/*
15392 + * copies the nsproxy, setting refcount to 1, and grabbing a
15393 + * reference to all contained namespaces.
15394 + */
15395 +struct nsproxy *copy_nsproxy(struct nsproxy *orig)
15396 +{
15397 +       struct nsproxy *ns = clone_nsproxy(orig);
15398 +
15399 +       if (ns) {
15400 +               if (ns->mnt_ns)
15401 +                       get_mnt_ns(ns->mnt_ns);
15402 +               if (ns->uts_ns)
15403 +                       get_uts_ns(ns->uts_ns);
15404 +               if (ns->ipc_ns)
15405 +                       get_ipc_ns(ns->ipc_ns);
15406 +               if (ns->pid_ns)
15407 +                       get_pid_ns(ns->pid_ns);
15408 +               if (ns->net_ns)
15409 +                       get_net(ns->net_ns);
15410 +       }
15411 +       return ns;
15412 +}
15413 +
15414  /*
15415   * called from clone.  This now handles copy for nsproxy and all
15416   * namespaces therein.
15417 @@ -112,9 +157,12 @@ out_ns:
15418  int copy_namespaces(unsigned long flags, struct task_struct *tsk)
15419  {
15420         struct nsproxy *old_ns = tsk->nsproxy;
15421 -       struct nsproxy *new_ns;
15422 +       struct nsproxy *new_ns = NULL;
15423         int err = 0;
15424  
15425 +       vxdprintk(VXD_CBIT(space, 7), "copy_namespaces(0x%08lx,%p[%p])",
15426 +               flags, tsk, old_ns);
15427 +
15428         if (!old_ns)
15429                 return 0;
15430  
15431 @@ -151,6 +199,9 @@ int copy_namespaces(unsigned long flags,
15432  
15433  out:
15434         put_nsproxy(old_ns);
15435 +       vxdprintk(VXD_CBIT(space, 3),
15436 +               "copy_namespaces(0x%08lx,%p[%p]) = %d [%p]",
15437 +               flags, tsk, old_ns, err, new_ns);
15438         return err;
15439  }
15440  
15441 @@ -164,7 +215,9 @@ void free_nsproxy(struct nsproxy *ns)
15442                 put_ipc_ns(ns->ipc_ns);
15443         if (ns->pid_ns)
15444                 put_pid_ns(ns->pid_ns);
15445 -       put_net(ns->net_ns);
15446 +       if (ns->net_ns)
15447 +               put_net(ns->net_ns);
15448 +       atomic_dec(&vs_global_nsproxy);
15449         kmem_cache_free(nsproxy_cachep, ns);
15450  }
15451  
15452 @@ -177,6 +230,10 @@ int unshare_nsproxy_namespaces(unsigned 
15453  {
15454         int err = 0;
15455  
15456 +       vxdprintk(VXD_CBIT(space, 4),
15457 +               "unshare_nsproxy_namespaces(0x%08lx,[%p])",
15458 +               unshare_flags, current->nsproxy);
15459 +
15460         if (!(unshare_flags & (CLONE_NEWNS | CLONE_NEWUTS | CLONE_NEWIPC |
15461                                CLONE_NEWNET)))
15462                 return 0;
15463 diff -NurpP --minimal linux-2.6.29/kernel/pid.c linux-2.6.29-vs2.3.0.36.9-pre3/kernel/pid.c
15464 --- linux-2.6.29/kernel/pid.c   2009-03-24 14:22:44.000000000 +0100
15465 +++ linux-2.6.29-vs2.3.0.36.9-pre3/kernel/pid.c 2009-03-24 14:48:36.000000000 +0100
15466 @@ -36,6 +36,8 @@
15467  #include <linux/pid_namespace.h>
15468  #include <linux/init_task.h>
15469  #include <linux/syscalls.h>
15470 +#include <linux/vs_pid.h>
15471 +#include <linux/vserver/global.h>
15472  
15473  #define pid_hashfn(nr, ns)     \
15474         hash_long((unsigned long)nr + (unsigned long)ns, pidhash_shift)
15475 @@ -305,7 +307,7 @@ EXPORT_SYMBOL_GPL(find_pid_ns);
15476  
15477  struct pid *find_vpid(int nr)
15478  {
15479 -       return find_pid_ns(nr, current->nsproxy->pid_ns);
15480 +       return find_pid_ns(vx_rmap_pid(nr), current->nsproxy->pid_ns);
15481  }
15482  EXPORT_SYMBOL_GPL(find_vpid);
15483  
15484 @@ -365,6 +367,9 @@ void transfer_pid(struct task_struct *ol
15485  struct task_struct *pid_task(struct pid *pid, enum pid_type type)
15486  {
15487         struct task_struct *result = NULL;
15488 +
15489 +       if (type == PIDTYPE_REALPID)
15490 +               type = PIDTYPE_PID;
15491         if (pid) {
15492                 struct hlist_node *first;
15493                 first = rcu_dereference(pid->tasks[type].first);
15494 @@ -388,14 +393,14 @@ EXPORT_SYMBOL(find_task_by_pid_type_ns);
15495  
15496  struct task_struct *find_task_by_vpid(pid_t vnr)
15497  {
15498 -       return find_task_by_pid_type_ns(PIDTYPE_PID, vnr,
15499 +       return find_task_by_pid_type_ns(PIDTYPE_PID, vx_rmap_pid(vnr),
15500                         current->nsproxy->pid_ns);
15501  }
15502  EXPORT_SYMBOL(find_task_by_vpid);
15503  
15504  struct task_struct *find_task_by_pid_ns(pid_t nr, struct pid_namespace *ns)
15505  {
15506 -       return find_task_by_pid_type_ns(PIDTYPE_PID, nr, ns);
15507 +       return find_task_by_pid_type_ns(PIDTYPE_PID, vx_rmap_pid(nr), ns);
15508  }
15509  EXPORT_SYMBOL(find_task_by_pid_ns);
15510  
15511 @@ -431,7 +436,7 @@ struct pid *find_get_pid(pid_t nr)
15512  }
15513  EXPORT_SYMBOL_GPL(find_get_pid);
15514  
15515 -pid_t pid_nr_ns(struct pid *pid, struct pid_namespace *ns)
15516 +pid_t pid_unmapped_nr_ns(struct pid *pid, struct pid_namespace *ns)
15517  {
15518         struct upid *upid;
15519         pid_t nr = 0;
15520 @@ -444,6 +449,11 @@ pid_t pid_nr_ns(struct pid *pid, struct 
15521         return nr;
15522  }
15523  
15524 +pid_t pid_nr_ns(struct pid *pid, struct pid_namespace *ns)
15525 +{
15526 +       return vx_map_pid(pid_unmapped_nr_ns(pid, ns));
15527 +}
15528 +
15529  pid_t pid_vnr(struct pid *pid)
15530  {
15531         return pid_nr_ns(pid, current->nsproxy->pid_ns);
15532 diff -NurpP --minimal linux-2.6.29/kernel/pid_namespace.c linux-2.6.29-vs2.3.0.36.9-pre3/kernel/pid_namespace.c
15533 --- linux-2.6.29/kernel/pid_namespace.c 2008-12-25 00:26:37.000000000 +0100
15534 +++ linux-2.6.29-vs2.3.0.36.9-pre3/kernel/pid_namespace.c       2009-02-22 22:54:26.000000000 +0100
15535 @@ -13,6 +13,7 @@
15536  #include <linux/syscalls.h>
15537  #include <linux/err.h>
15538  #include <linux/acct.h>
15539 +#include <linux/vserver/global.h>
15540  
15541  #define BITS_PER_PAGE          (PAGE_SIZE*8)
15542  
15543 @@ -85,6 +86,7 @@ static struct pid_namespace *create_pid_
15544                 goto out_free_map;
15545  
15546         kref_init(&ns->kref);
15547 +       atomic_inc(&vs_global_pid_ns);
15548         ns->level = level;
15549  
15550         set_bit(0, ns->pidmap[0].page);
15551 @@ -109,6 +111,7 @@ static void destroy_pid_namespace(struct
15552  
15553         for (i = 0; i < PIDMAP_ENTRIES; i++)
15554                 kfree(ns->pidmap[i].page);
15555 +       atomic_dec(&vs_global_pid_ns);
15556         kmem_cache_free(pid_ns_cachep, ns);
15557  }
15558  
15559 diff -NurpP --minimal linux-2.6.29/kernel/posix-timers.c linux-2.6.29-vs2.3.0.36.9-pre3/kernel/posix-timers.c
15560 --- linux-2.6.29/kernel/posix-timers.c  2009-03-24 14:22:44.000000000 +0100
15561 +++ linux-2.6.29-vs2.3.0.36.9-pre3/kernel/posix-timers.c        2009-03-24 17:36:18.000000000 +0100
15562 @@ -46,6 +46,7 @@
15563  #include <linux/wait.h>
15564  #include <linux/workqueue.h>
15565  #include <linux/module.h>
15566 +#include <linux/vs_context.h>
15567  
15568  /*
15569   * Management arrays for POSIX timers.  Timers are kept in slab memory
15570 @@ -321,6 +322,12 @@ int posix_timer_event(struct k_itimer *t
15571  {
15572         struct task_struct *task;
15573         int shared, ret = -1;
15574 +       struct vx_info_save vxis;
15575 +       struct vx_info *vxi;
15576 +
15577 +       /* FIXME: move that down where we have the task */
15578 +       vxi = task_get_vx_info(timr->it_process);
15579 +       enter_vx_info(vxi, &vxis);
15580         /*
15581          * FIXME: if ->sigq is queued we can race with
15582          * dequeue_signal()->do_schedule_next_timer().
15583 @@ -341,6 +348,9 @@ int posix_timer_event(struct k_itimer *t
15584                 ret = send_sigqueue(timr->sigq, task, shared);
15585         }
15586         rcu_read_unlock();
15587 +
15588 +       leave_vx_info(&vxis);
15589 +       put_vx_info(vxi);
15590         /* If we failed to send the signal the timer stops. */
15591         return ret > 0;
15592  }
15593 diff -NurpP --minimal linux-2.6.29/kernel/printk.c linux-2.6.29-vs2.3.0.36.9-pre3/kernel/printk.c
15594 --- linux-2.6.29/kernel/printk.c        2009-03-24 14:22:44.000000000 +0100
15595 +++ linux-2.6.29-vs2.3.0.36.9-pre3/kernel/printk.c      2009-03-24 14:48:36.000000000 +0100
15596 @@ -32,6 +32,7 @@
15597  #include <linux/security.h>
15598  #include <linux/bootmem.h>
15599  #include <linux/syscalls.h>
15600 +#include <linux/vs_cvirt.h>
15601  
15602  #include <asm/uaccess.h>
15603  
15604 @@ -251,18 +252,13 @@ int do_syslog(int type, char __user *buf
15605         unsigned i, j, limit, count;
15606         int do_clear = 0;
15607         char c;
15608 -       int error = 0;
15609 +       int error;
15610  
15611         error = security_syslog(type);
15612         if (error)
15613                 return error;
15614  
15615 -       switch (type) {
15616 -       case 0:         /* Close log */
15617 -               break;
15618 -       case 1:         /* Open log */
15619 -               break;
15620 -       case 2:         /* Read from log */
15621 +       if ((type >= 2) && (type <= 4)) {
15622                 error = -EINVAL;
15623                 if (!buf || len < 0)
15624                         goto out;
15625 @@ -273,6 +269,16 @@ int do_syslog(int type, char __user *buf
15626                         error = -EFAULT;
15627                         goto out;
15628                 }
15629 +       }
15630 +       if (!vx_check(0, VS_ADMIN|VS_WATCH))
15631 +               return vx_do_syslog(type, buf, len);
15632 +
15633 +       switch (type) {
15634 +       case 0:         /* Close log */
15635 +               break;
15636 +       case 1:         /* Open log */
15637 +               break;
15638 +       case 2:         /* Read from log */
15639                 error = wait_event_interruptible(log_wait,
15640                                                         (log_start - log_end));
15641                 if (error)
15642 @@ -297,16 +303,6 @@ int do_syslog(int type, char __user *buf
15643                 do_clear = 1;
15644                 /* FALL THRU */
15645         case 3:         /* Read last kernel messages */
15646 -               error = -EINVAL;
15647 -               if (!buf || len < 0)
15648 -                       goto out;
15649 -               error = 0;
15650 -               if (!len)
15651 -                       goto out;
15652 -               if (!access_ok(VERIFY_WRITE, buf, len)) {
15653 -                       error = -EFAULT;
15654 -                       goto out;
15655 -               }
15656                 count = len;
15657                 if (count > log_buf_len)
15658                         count = log_buf_len;
15659 diff -NurpP --minimal linux-2.6.29/kernel/ptrace.c linux-2.6.29-vs2.3.0.36.9-pre3/kernel/ptrace.c
15660 --- linux-2.6.29/kernel/ptrace.c        2009-03-24 14:22:44.000000000 +0100
15661 +++ linux-2.6.29-vs2.3.0.36.9-pre3/kernel/ptrace.c      2009-03-24 14:48:36.000000000 +0100
15662 @@ -21,6 +21,7 @@
15663  #include <linux/audit.h>
15664  #include <linux/pid_namespace.h>
15665  #include <linux/syscalls.h>
15666 +#include <linux/vs_context.h>
15667  
15668  #include <asm/pgtable.h>
15669  #include <asm/uaccess.h>
15670 @@ -159,6 +160,11 @@ int __ptrace_may_access(struct task_stru
15671                 dumpable = get_dumpable(task->mm);
15672         if (!dumpable && !capable(CAP_SYS_PTRACE))
15673                 return -EPERM;
15674 +       if (!vx_check(task->xid, VS_ADMIN_P|VS_IDENT))
15675 +               return -EPERM;
15676 +       if (!vx_check(task->xid, VS_IDENT) &&
15677 +               !task_vx_flags(task, VXF_STATE_ADMIN, 0))
15678 +               return -EACCES;
15679  
15680         return security_ptrace_may_access(task, mode);
15681  }
15682 @@ -596,6 +602,10 @@ SYSCALL_DEFINE4(ptrace, long, request, l
15683                 goto out;
15684         }
15685  
15686 +       ret = -EPERM;
15687 +       if (!vx_check(vx_task_xid(child), VS_WATCH_P | VS_IDENT))
15688 +               goto out_put_task_struct;
15689 +
15690         if (request == PTRACE_ATTACH) {
15691                 ret = ptrace_attach(child);
15692                 /*
15693 diff -NurpP --minimal linux-2.6.29/kernel/sched.c linux-2.6.29-vs2.3.0.36.9-pre3/kernel/sched.c
15694 --- linux-2.6.29/kernel/sched.c 2009-03-24 14:22:44.000000000 +0100
15695 +++ linux-2.6.29-vs2.3.0.36.9-pre3/kernel/sched.c       2009-03-24 21:52:21.000000000 +0100
15696 @@ -72,6 +72,8 @@
15697  #include <linux/debugfs.h>
15698  #include <linux/ctype.h>
15699  #include <linux/ftrace.h>
15700 +#include <linux/vs_sched.h>
15701 +#include <linux/vs_cvirt.h>
15702  #include <trace/sched.h>
15703  
15704  #include <asm/tlb.h>
15705 @@ -610,6 +612,16 @@ struct rq {
15706  #endif
15707         struct hrtimer hrtick_timer;
15708  #endif
15709 +       unsigned long norm_time;
15710 +       unsigned long idle_time;
15711 +#ifdef CONFIG_VSERVER_IDLETIME
15712 +       int idle_skip;
15713 +#endif
15714 +#ifdef CONFIG_VSERVER_HARDCPU
15715 +       struct list_head hold_queue;
15716 +       unsigned long nr_onhold;
15717 +       int idle_tokens;
15718 +#endif
15719  
15720  #ifdef CONFIG_SCHEDSTATS
15721         /* latency stats */
15722 @@ -1705,6 +1717,7 @@ static void update_avg(u64 *avg, u64 sam
15723  
15724  static void enqueue_task(struct rq *rq, struct task_struct *p, int wakeup)
15725  {
15726 +       // BUG_ON(p->state & TASK_ONHOLD);
15727         sched_info_queued(p);
15728         p->sched_class->enqueue_task(rq, p, wakeup);
15729         p->se.on_rq = 1;
15730 @@ -1828,6 +1841,8 @@ static inline void check_class_changed(s
15731                 p->sched_class->prio_changed(rq, p, oldprio, running);
15732  }
15733  
15734 +#include "sched_mon.h"
15735 +
15736  #ifdef CONFIG_SMP
15737  
15738  /* Used instead of source_load when we know the type == 0 */
15739 @@ -1915,6 +1930,7 @@ migrate_task(struct task_struct *p, int 
15740  {
15741         struct rq *rq = task_rq(p);
15742  
15743 +       vxm_migrate_task(p, rq, dest_cpu);
15744         /*
15745          * If the task is not on a runqueue (and not running), then
15746          * it is sufficient to simply update the task's cpu field.
15747 @@ -2242,6 +2258,8 @@ static int sched_balance_self(int cpu, i
15748  
15749  #endif /* CONFIG_SMP */
15750  
15751 +#include "sched_hard.h"
15752 +
15753  /***
15754   * try_to_wake_up - wake up a thread
15755   * @p: the to-be-woken-up thread
15756 @@ -2286,6 +2304,13 @@ static int try_to_wake_up(struct task_st
15757         rq = task_rq_lock(p, &flags);
15758         update_rq_clock(rq);
15759         old_state = p->state;
15760 +
15761 +       /* we need to unhold suspended tasks */
15762 +       if (old_state & TASK_ONHOLD) {
15763 +               vx_unhold_task(p, rq);
15764 +               old_state = p->state;
15765 +       }
15766 +
15767         if (!(old_state & state))
15768                 goto out;
15769  
15770 @@ -2307,6 +2332,12 @@ static int try_to_wake_up(struct task_st
15771                 /* might preempt at this point */
15772                 rq = task_rq_lock(p, &flags);
15773                 old_state = p->state;
15774 +
15775 +       /* we need to unhold suspended tasks
15776 +       if (old_state & TASK_ONHOLD) {
15777 +               vx_unhold_task(p, rq);
15778 +               old_state = p->state;
15779 +       } */
15780                 if (!(old_state & state))
15781                         goto out;
15782                 if (p->se.on_rq)
15783 @@ -4169,16 +4200,19 @@ void account_user_time(struct task_struc
15784                        cputime_t cputime_scaled)
15785  {
15786         struct cpu_usage_stat *cpustat = &kstat_this_cpu.cpustat;
15787 +       struct vx_info *vxi = p->vx_info;  /* p is _always_ current */
15788         cputime64_t tmp;
15789 +       int nice = (TASK_NICE(p) > 0);
15790  
15791         /* Add user time to process. */
15792         p->utime = cputime_add(p->utime, cputime);
15793         p->utimescaled = cputime_add(p->utimescaled, cputime_scaled);
15794 +       vx_account_user(vxi, cputime, nice);
15795         account_group_user_time(p, cputime);
15796  
15797         /* Add user time to cpustat. */
15798         tmp = cputime_to_cputime64(cputime);
15799 -       if (TASK_NICE(p) > 0)
15800 +       if (nice)
15801                 cpustat->nice = cputime64_add(cpustat->nice, tmp);
15802         else
15803                 cpustat->user = cputime64_add(cpustat->user, tmp);
15804 @@ -4222,6 +4256,7 @@ void account_system_time(struct task_str
15805                          cputime_t cputime, cputime_t cputime_scaled)
15806  {
15807         struct cpu_usage_stat *cpustat = &kstat_this_cpu.cpustat;
15808 +       struct vx_info *vxi = p->vx_info;  /* p is _always_ current */
15809         cputime64_t tmp;
15810  
15811         if ((p->flags & PF_VCPU) && (irq_count() - hardirq_offset == 0)) {
15812 @@ -4232,6 +4267,7 @@ void account_system_time(struct task_str
15813         /* Add system time to process. */
15814         p->stime = cputime_add(p->stime, cputime);
15815         p->stimescaled = cputime_add(p->stimescaled, cputime_scaled);
15816 +       vx_account_system(vxi, cputime, 0 /* do we have idle time? */);
15817         account_group_system_time(p, cputime);
15818  
15819         /* Add system time to cpustat. */
15820 @@ -4587,6 +4623,11 @@ need_resched_nonpreemptible:
15821                 idle_balance(cpu, rq);
15822  
15823         prev->sched_class->put_prev_task(rq, prev);
15824 +
15825 +       vx_set_rq_time(rq, jiffies);    /* update time */
15826 +       vx_schedule(prev, rq, cpu);     /* hold if over limit */
15827 +       vx_try_unhold(rq, cpu);         /* unhold if refilled */
15828 +
15829         next = pick_next_task(rq, prev);
15830  
15831         if (likely(prev != next)) {
15832 @@ -5152,7 +5193,7 @@ SYSCALL_DEFINE1(nice, int, increment)
15833                 nice = 19;
15834  
15835         if (increment < 0 && !can_nice(current, nice))
15836 -               return -EPERM;
15837 +               return vx_flags(VXF_IGNEG_NICE, 0) ? 0 : -EPERM;
15838  
15839         retval = security_task_setnice(current, nice);
15840         if (retval)
15841 @@ -8428,7 +8469,10 @@ void __init sched_init(void)
15842  
15843  #endif
15844  #endif /* CONFIG_FAIR_GROUP_SCHED */
15845 -
15846 +#ifdef CONFIG_VSERVER_HARDCPU
15847 +               INIT_LIST_HEAD(&rq->hold_queue);
15848 +               rq->nr_onhold = 0;
15849 +#endif
15850                 rq->rt.rt_runtime = def_rt_bandwidth.rt_runtime;
15851  #ifdef CONFIG_RT_GROUP_SCHED
15852                 INIT_LIST_HEAD(&rq->leaf_rt_rq_list);
15853 diff -NurpP --minimal linux-2.6.29/kernel/sched_fair.c linux-2.6.29-vs2.3.0.36.9-pre3/kernel/sched_fair.c
15854 --- linux-2.6.29/kernel/sched_fair.c    2009-03-24 14:22:45.000000000 +0100
15855 +++ linux-2.6.29-vs2.3.0.36.9-pre3/kernel/sched_fair.c  2009-03-24 14:48:36.000000000 +0100
15856 @@ -717,6 +717,9 @@ enqueue_entity(struct cfs_rq *cfs_rq, st
15857         check_spread(cfs_rq, se);
15858         if (se != cfs_rq->curr)
15859                 __enqueue_entity(cfs_rq, se);
15860 +
15861 +       if (entity_is_task(se))
15862 +               vx_activate_task(task_of(se));
15863  }
15864  
15865  static void __clear_buddies(struct cfs_rq *cfs_rq, struct sched_entity *se)
15866 @@ -760,6 +763,8 @@ dequeue_entity(struct cfs_rq *cfs_rq, st
15867  
15868         if (se != cfs_rq->curr)
15869                 __dequeue_entity(cfs_rq, se);
15870 +       if (entity_is_task(se))
15871 +               vx_deactivate_task(task_of(se));
15872         account_entity_dequeue(cfs_rq, se);
15873         update_min_vruntime(cfs_rq);
15874  }
15875 diff -NurpP --minimal linux-2.6.29/kernel/sched_hard.h linux-2.6.29-vs2.3.0.36.9-pre3/kernel/sched_hard.h
15876 --- linux-2.6.29/kernel/sched_hard.h    1970-01-01 01:00:00.000000000 +0100
15877 +++ linux-2.6.29-vs2.3.0.36.9-pre3/kernel/sched_hard.h  2009-02-22 22:54:26.000000000 +0100
15878 @@ -0,0 +1,353 @@
15879 +
15880 +#ifdef CONFIG_VSERVER_IDLELIMIT
15881 +
15882 +/*
15883 + * vx_idle_resched - reschedule after maxidle
15884 + */
15885 +static inline
15886 +void vx_idle_resched(struct rq *rq)
15887 +{
15888 +       /* maybe have a better criterion for paused */
15889 +       if (!--rq->idle_tokens && !list_empty(&rq->hold_queue))
15890 +               set_need_resched();
15891 +}
15892 +
15893 +#else /* !CONFIG_VSERVER_IDLELIMIT */
15894 +
15895 +#define vx_idle_resched(rq)
15896 +
15897 +#endif /* CONFIG_VSERVER_IDLELIMIT */
15898 +
15899 +
15900 +
15901 +#ifdef CONFIG_VSERVER_IDLETIME
15902 +
15903 +#define vx_set_rq_min_skip(rq, min)            \
15904 +       (rq)->idle_skip = (min)
15905 +
15906 +#define vx_save_min_skip(ret, min, val)                \
15907 +       __vx_save_min_skip(ret, min, val)
15908 +
15909 +static inline
15910 +void __vx_save_min_skip(int ret, int *min, int val)
15911 +{
15912 +       if (ret > -2)
15913 +               return;
15914 +       if ((*min > val) || !*min)
15915 +               *min = val;
15916 +}
15917 +
15918 +static inline
15919 +int vx_try_skip(struct rq *rq, int cpu)
15920 +{
15921 +       /* artificially advance time */
15922 +       if (rq->idle_skip > 0) {
15923 +               vxdprintk(list_empty(&rq->hold_queue),
15924 +                       "hold queue empty on cpu %d", cpu);
15925 +               rq->idle_time += rq->idle_skip;
15926 +               vxm_idle_skip(rq, cpu);
15927 +               return 1;
15928 +       }
15929 +       return 0;
15930 +}
15931 +
15932 +#else /* !CONFIG_VSERVER_IDLETIME */
15933 +
15934 +#define vx_set_rq_min_skip(rq, min)            \
15935 +       ({ int dummy = (min); dummy; })
15936 +
15937 +#define vx_save_min_skip(ret, min, val)
15938 +
15939 +static inline
15940 +int vx_try_skip(struct rq *rq, int cpu)
15941 +{
15942 +       return 0;
15943 +}
15944 +
15945 +#endif /* CONFIG_VSERVER_IDLETIME */
15946 +
15947 +
15948 +
15949 +#ifdef CONFIG_VSERVER_HARDCPU
15950 +
15951 +#define vx_set_rq_max_idle(rq, max)            \
15952 +       (rq)->idle_tokens = (max)
15953 +
15954 +#define vx_save_max_idle(ret, min, val)                \
15955 +       __vx_save_max_idle(ret, min, val)
15956 +
15957 +static inline
15958 +void __vx_save_max_idle(int ret, int *min, int val)
15959 +{
15960 +       if (*min > val)
15961 +               *min = val;
15962 +}
15963 +
15964 +
15965 +/*
15966 + * vx_hold_task - put a task on the hold queue
15967 + */
15968 +static inline
15969 +void vx_hold_task(struct task_struct *p, struct rq *rq)
15970 +{
15971 +       // printk("@ hold_task(%p[%lx])\n", p, p->state);
15972 +
15973 +       /* ignore dead/killed tasks */
15974 +       if (unlikely(p->state & (TASK_DEAD | TASK_WAKEKILL)))
15975 +               return;
15976 +
15977 +       /* ignore sleeping tasks */
15978 +       if (unlikely(p->state & TASK_NORMAL))
15979 +               return;
15980 +
15981 +       /* remove task from runqueue */
15982 +       if (likely(p->se.on_rq))
15983 +               dequeue_task(rq, p, 0);
15984 +       else
15985 +               printk("@ woops, task %p not on runqueue?\n", p);
15986 +
15987 +       p->state |= TASK_ONHOLD;
15988 +       /* a new one on hold */
15989 +       rq->nr_onhold++;
15990 +       vxm_hold_task(p, rq);
15991 +       list_add_tail(&p->hq, &rq->hold_queue);
15992 +       // list_add_tail(&p->run_list, &rq->hold_queue);
15993 +}
15994 +
15995 +/*
15996 + * vx_unhold_task - put a task back to the runqueue
15997 + */
15998 +static inline
15999 +void vx_unhold_task(struct task_struct *p, struct rq *rq)
16000 +{
16001 +       // printk("@ unhold_task(%p[%lx])\n", p, p->state);
16002 +       list_del_init(&p->hq);
16003 +       // list_del(&p->run_list);
16004 +       /* one less waiting */
16005 +       rq->nr_onhold--;
16006 +       p->state &= ~TASK_ONHOLD;
16007 +       enqueue_task(rq, p, 0);
16008 +       // ? inc_nr_running(p, rq);
16009 +       vxm_unhold_task(p, rq);
16010 +}
16011 +
16012 +/*
16013 + * vx_remove_hold - remove a task from the hold queue
16014 + */
16015 +static inline
16016 +void vx_remove_hold(struct task_struct *p, struct rq *rq)
16017 +{
16018 +       printk("@ remove_hold(%p[%lx])\n", p, p->state);
16019 +       list_del_init(&p->hq);
16020 +       // list_del(&p->run_list);
16021 +       /* one less waiting */
16022 +       rq->nr_onhold--;
16023 +       p->state &= ~TASK_ONHOLD;
16024 +}
16025 +
16026 +unsigned long nr_onhold(void)
16027 +{
16028 +       unsigned long i, sum = 0;
16029 +
16030 +       for_each_online_cpu(i)
16031 +               sum += cpu_rq(i)->nr_onhold;
16032 +
16033 +       return sum;
16034 +}
16035 +
16036 +
16037 +
16038 +static inline
16039 +int __vx_tokens_avail(struct _vx_sched_pc *sched_pc)
16040 +{
16041 +       return sched_pc->tokens;
16042 +}
16043 +
16044 +static inline
16045 +void __vx_consume_token(struct _vx_sched_pc *sched_pc)
16046 +{
16047 +       sched_pc->tokens--;
16048 +}
16049 +
16050 +static inline
16051 +int vx_need_resched(struct task_struct *p, int slice, int cpu)
16052 +{
16053 +       struct vx_info *vxi = p->vx_info;
16054 +
16055 +       if (vx_info_flags(vxi, VXF_SCHED_HARD|VXF_SCHED_PRIO, 0)) {
16056 +               struct _vx_sched_pc *sched_pc =
16057 +                       &vx_per_cpu(vxi, sched_pc, cpu);
16058 +               int tokens;
16059 +
16060 +               /* maybe we can simplify that to decrement
16061 +                  the token counter unconditional? */
16062 +
16063 +               if ((tokens = __vx_tokens_avail(sched_pc)) > 0)
16064 +                       __vx_consume_token(sched_pc);
16065 +
16066 +               /* for tokens > 0, one token was consumed */
16067 +               if (tokens < 2)
16068 +                       slice = 0;
16069 +       }
16070 +       vxm_need_resched(p, slice, cpu);
16071 +       return (slice == 0);
16072 +}
16073 +
16074 +
16075 +#define vx_set_rq_time(rq, time) do {  \
16076 +       rq->norm_time = time;           \
16077 +} while (0)
16078 +
16079 +
16080 +static inline
16081 +void vx_try_unhold(struct rq *rq, int cpu)
16082 +{
16083 +       struct vx_info *vxi = NULL;
16084 +       struct list_head *l, *n;
16085 +       int maxidle = HZ;
16086 +       int minskip = 0;
16087 +
16088 +       /* nothing to do? what about pause? */
16089 +       if (list_empty(&rq->hold_queue))
16090 +               return;
16091 +
16092 +       list_for_each_safe(l, n, &rq->hold_queue) {
16093 +               int ret, delta_min[2];
16094 +               struct _vx_sched_pc *sched_pc;
16095 +               struct task_struct *p;
16096 +
16097 +               p = list_entry(l, struct task_struct, hq);
16098 +               /* don't bother with same context */
16099 +               if (vxi == p->vx_info)
16100 +                       continue;
16101 +
16102 +               vxi = p->vx_info;
16103 +               /* ignore paused contexts */
16104 +               if (vx_info_flags(vxi, VXF_SCHED_PAUSE, 0))
16105 +                       continue;
16106 +
16107 +               sched_pc = &vx_per_cpu(vxi, sched_pc, cpu);
16108 +
16109 +               /* recalc tokens */
16110 +               vxm_sched_info(sched_pc, vxi, cpu);
16111 +               ret = vx_tokens_recalc(sched_pc,
16112 +                       &rq->norm_time, &rq->idle_time, delta_min);
16113 +               vxm_tokens_recalc(sched_pc, rq, vxi, cpu);
16114 +
16115 +               if (ret > 0) {
16116 +                       /* we found a runable context */
16117 +                       vx_unhold_task(p, rq);
16118 +                       break;
16119 +               }
16120 +               vx_save_max_idle(ret, &maxidle, delta_min[0]);
16121 +               vx_save_min_skip(ret, &minskip, delta_min[1]);
16122 +       }
16123 +       vx_set_rq_max_idle(rq, maxidle);
16124 +       vx_set_rq_min_skip(rq, minskip);
16125 +       vxm_rq_max_min(rq, cpu);
16126 +}
16127 +
16128 +
16129 +static inline
16130 +int vx_schedule(struct task_struct *next, struct rq *rq, int cpu)
16131 +{
16132 +       struct vx_info *vxi = next->vx_info;
16133 +       struct _vx_sched_pc *sched_pc;
16134 +       int delta_min[2];
16135 +       int flags, ret;
16136 +
16137 +       if (!vxi)
16138 +               return 1;
16139 +
16140 +       flags = vxi->vx_flags;
16141 +
16142 +       if (unlikely(vs_check_flags(flags, VXF_SCHED_PAUSE, 0)))
16143 +               goto put_on_hold;
16144 +       if (!vs_check_flags(flags, VXF_SCHED_HARD | VXF_SCHED_PRIO, 0))
16145 +               return 1;
16146 +
16147 +       sched_pc = &vx_per_cpu(vxi, sched_pc, cpu);
16148 +#ifdef CONFIG_SMP
16149 +       /* update scheduler params */
16150 +       if (cpu_isset(cpu, vxi->sched.update)) {
16151 +               vx_update_sched_param(&vxi->sched, sched_pc);
16152 +               vxm_update_sched(sched_pc, vxi, cpu);
16153 +               cpu_clear(cpu, vxi->sched.update);
16154 +       }
16155 +#endif
16156 +       vxm_sched_info(sched_pc, vxi, cpu);
16157 +       ret  = vx_tokens_recalc(sched_pc,
16158 +               &rq->norm_time, &rq->idle_time, delta_min);
16159 +       vxm_tokens_recalc(sched_pc, rq, vxi, cpu);
16160 +
16161 +       if (!vs_check_flags(flags, VXF_SCHED_HARD, 0))
16162 +               return 1;
16163 +
16164 +       if (unlikely(ret < 0)) {
16165 +               vx_save_max_idle(ret, &rq->idle_tokens, delta_min[0]);
16166 +               vx_save_min_skip(ret, &rq->idle_skip, delta_min[1]);
16167 +               vxm_rq_max_min(rq, cpu);
16168 +       put_on_hold:
16169 +               vx_hold_task(next, rq);
16170 +               return 0;
16171 +       }
16172 +       return 1;
16173 +}
16174 +
16175 +
16176 +#else /* CONFIG_VSERVER_HARDCPU */
16177 +
16178 +static inline
16179 +void vx_hold_task(struct task_struct *p, struct rq *rq)
16180 +{
16181 +       return;
16182 +}
16183 +
16184 +static inline
16185 +void vx_unhold_task(struct task_struct *p, struct rq *rq)
16186 +{
16187 +       return;
16188 +}
16189 +
16190 +unsigned long nr_onhold(void)
16191 +{
16192 +       return 0;
16193 +}
16194 +
16195 +
16196 +static inline
16197 +int vx_need_resched(struct task_struct *p, int slice, int cpu)
16198 +{
16199 +       return (slice == 0);
16200 +}
16201 +
16202 +
16203 +#define vx_set_rq_time(rq, time)
16204 +
16205 +static inline
16206 +void vx_try_unhold(struct rq *rq, int cpu)
16207 +{
16208 +       return;
16209 +}
16210 +
16211 +static inline
16212 +int vx_schedule(struct task_struct *next, struct rq *rq, int cpu)
16213 +{
16214 +       struct vx_info *vxi = next->vx_info;
16215 +       struct _vx_sched_pc *sched_pc;
16216 +       int delta_min[2];
16217 +       int ret;
16218 +
16219 +       if (!vx_info_flags(vxi, VXF_SCHED_PRIO, 0))
16220 +               return 1;
16221 +
16222 +       sched_pc = &vx_per_cpu(vxi, sched_pc, cpu);
16223 +       vxm_sched_info(sched_pc, vxi, cpu);
16224 +       ret  = vx_tokens_recalc(sched_pc,
16225 +               &rq->norm_time, &rq->idle_time, delta_min);
16226 +       vxm_tokens_recalc(sched_pc, rq, vxi, cpu);
16227 +       return 1;
16228 +}
16229 +
16230 +#endif /* CONFIG_VSERVER_HARDCPU */
16231 +
16232 diff -NurpP --minimal linux-2.6.29/kernel/sched_mon.h linux-2.6.29-vs2.3.0.36.9-pre3/kernel/sched_mon.h
16233 --- linux-2.6.29/kernel/sched_mon.h     1970-01-01 01:00:00.000000000 +0100
16234 +++ linux-2.6.29-vs2.3.0.36.9-pre3/kernel/sched_mon.h   2009-02-22 22:54:26.000000000 +0100
16235 @@ -0,0 +1,200 @@
16236 +
16237 +#include <linux/vserver/monitor.h>
16238 +
16239 +#ifdef  CONFIG_VSERVER_MONITOR
16240 +
16241 +#ifdef CONFIG_VSERVER_HARDCPU
16242 +#define HARDCPU(x) (x)
16243 +#else
16244 +#define HARDCPU(x) (0)
16245 +#endif
16246 +
16247 +#ifdef CONFIG_VSERVER_IDLETIME
16248 +#define IDLETIME(x) (x)
16249 +#else
16250 +#define IDLETIME(x) (0)
16251 +#endif
16252 +
16253 +struct _vx_mon_entry *vxm_advance(int cpu);
16254 +
16255 +
16256 +static inline
16257 +void   __vxm_basic(struct _vx_mon_entry *entry, xid_t xid, int type)
16258 +{
16259 +       entry->type = type;
16260 +       entry->xid = xid;
16261 +}
16262 +
16263 +static inline
16264 +void   __vxm_sync(int cpu)
16265 +{
16266 +       struct _vx_mon_entry *entry = vxm_advance(cpu);
16267 +
16268 +       __vxm_basic(entry, 0, VXM_SYNC);
16269 +       entry->ev.sec = xtime.tv_sec;
16270 +       entry->ev.nsec = xtime.tv_nsec;
16271 +}
16272 +
16273 +static inline
16274 +void   __vxm_task(struct task_struct *p, int type)
16275 +{
16276 +       struct _vx_mon_entry *entry = vxm_advance(task_cpu(p));
16277 +
16278 +       __vxm_basic(entry, p->xid, type);
16279 +       entry->ev.tsk.pid = p->pid;
16280 +       entry->ev.tsk.state = p->state;
16281 +}
16282 +
16283 +static inline
16284 +void   __vxm_sched(struct _vx_sched_pc *s, struct vx_info *vxi, int cpu)
16285 +{
16286 +       struct _vx_mon_entry *entry = vxm_advance(cpu);
16287 +
16288 +       __vxm_basic(entry, vxi->vx_id, (VXM_SCHED | s->flags));
16289 +       entry->sd.tokens = s->tokens;
16290 +       entry->sd.norm_time = s->norm_time;
16291 +       entry->sd.idle_time = s->idle_time;
16292 +}
16293 +
16294 +static inline
16295 +void   __vxm_rqinfo1(struct rq *q, int cpu)
16296 +{
16297 +       struct _vx_mon_entry *entry = vxm_advance(cpu);
16298 +
16299 +       entry->type = VXM_RQINFO_1;
16300 +       entry->xid = ((unsigned long)q >> 16) & 0xffff;
16301 +       entry->q1.running = q->nr_running;
16302 +       entry->q1.onhold = HARDCPU(q->nr_onhold);
16303 +       entry->q1.iowait = atomic_read(&q->nr_iowait);
16304 +       entry->q1.uintr = q->nr_uninterruptible;
16305 +       entry->q1.idle_tokens = IDLETIME(q->idle_tokens);
16306 +}
16307 +
16308 +static inline
16309 +void   __vxm_rqinfo2(struct rq *q, int cpu)
16310 +{
16311 +       struct _vx_mon_entry *entry = vxm_advance(cpu);
16312 +
16313 +       entry->type = VXM_RQINFO_2;
16314 +       entry->xid = (unsigned long)q & 0xffff;
16315 +       entry->q2.norm_time = q->norm_time;
16316 +       entry->q2.idle_time = q->idle_time;
16317 +       entry->q2.idle_skip = IDLETIME(q->idle_skip);
16318 +}
16319 +
16320 +static inline
16321 +void   __vxm_update(struct _vx_sched_pc *s, struct vx_info *vxi, int cpu)
16322 +{
16323 +       struct _vx_mon_entry *entry = vxm_advance(cpu);
16324 +
16325 +       __vxm_basic(entry, vxi->vx_id, VXM_UPDATE);
16326 +       entry->ev.tokens = s->tokens;
16327 +}
16328 +
16329 +static inline
16330 +void   __vxm_update1(struct _vx_sched_pc *s, struct vx_info *vxi, int cpu)
16331 +{
16332 +       struct _vx_mon_entry *entry = vxm_advance(cpu);
16333 +
16334 +       __vxm_basic(entry, vxi->vx_id, VXM_UPDATE_1);
16335 +       entry->u1.tokens_max = s->tokens_max;
16336 +       entry->u1.fill_rate = s->fill_rate[0];
16337 +       entry->u1.interval = s->interval[0];
16338 +}
16339 +
16340 +static inline
16341 +void   __vxm_update2(struct _vx_sched_pc *s, struct vx_info *vxi, int cpu)
16342 +{
16343 +       struct _vx_mon_entry *entry = vxm_advance(cpu);
16344 +
16345 +       __vxm_basic(entry, vxi->vx_id, VXM_UPDATE_2);
16346 +       entry->u2.tokens_min = s->tokens_min;
16347 +       entry->u2.fill_rate = s->fill_rate[1];
16348 +       entry->u2.interval = s->interval[1];
16349 +}
16350 +
16351 +
16352 +#define        vxm_activate_task(p,q)          __vxm_task(p, VXM_ACTIVATE)
16353 +#define        vxm_activate_idle(p,q)          __vxm_task(p, VXM_IDLE)
16354 +#define        vxm_deactivate_task(p,q)        __vxm_task(p, VXM_DEACTIVATE)
16355 +#define        vxm_hold_task(p,q)              __vxm_task(p, VXM_HOLD)
16356 +#define        vxm_unhold_task(p,q)            __vxm_task(p, VXM_UNHOLD)
16357 +
16358 +static inline
16359 +void   vxm_migrate_task(struct task_struct *p, struct rq *rq, int dest)
16360 +{
16361 +       __vxm_task(p, VXM_MIGRATE);
16362 +       __vxm_rqinfo1(rq, task_cpu(p));
16363 +       __vxm_rqinfo2(rq, task_cpu(p));
16364 +}
16365 +
16366 +static inline
16367 +void   vxm_idle_skip(struct rq *rq, int cpu)
16368 +{
16369 +       __vxm_rqinfo1(rq, cpu);
16370 +       __vxm_rqinfo2(rq, cpu);
16371 +}
16372 +
16373 +static inline
16374 +void   vxm_need_resched(struct task_struct *p, int slice, int cpu)
16375 +{
16376 +       if (slice)
16377 +               return;
16378 +
16379 +       __vxm_task(p, VXM_RESCHED);
16380 +}
16381 +
16382 +static inline
16383 +void   vxm_sync(unsigned long now, int cpu)
16384 +{
16385 +       if (!CONFIG_VSERVER_MONITOR_SYNC ||
16386 +               (now % CONFIG_VSERVER_MONITOR_SYNC))
16387 +               return;
16388 +
16389 +       __vxm_sync(cpu);
16390 +}
16391 +
16392 +#define        vxm_sched_info(s,v,c)           __vxm_sched(s,v,c)
16393 +
16394 +static inline
16395 +void   vxm_tokens_recalc(struct _vx_sched_pc *s, struct rq *rq,
16396 +       struct vx_info *vxi, int cpu)
16397 +{
16398 +       __vxm_sched(s, vxi, cpu);
16399 +       __vxm_rqinfo2(rq, cpu);
16400 +}
16401 +
16402 +static inline
16403 +void   vxm_update_sched(struct _vx_sched_pc *s, struct vx_info *vxi, int cpu)
16404 +{
16405 +       __vxm_sched(s, vxi, cpu);
16406 +       __vxm_update(s, vxi, cpu);
16407 +       __vxm_update1(s, vxi, cpu);
16408 +       __vxm_update2(s, vxi, cpu);
16409 +}
16410 +
16411 +static inline
16412 +void   vxm_rq_max_min(struct rq *rq, int cpu)
16413 +{
16414 +       __vxm_rqinfo1(rq, cpu);
16415 +       __vxm_rqinfo2(rq, cpu);
16416 +}
16417 +
16418 +#else  /* CONFIG_VSERVER_MONITOR */
16419 +
16420 +#define        vxm_activate_task(t,q)          do { } while (0)
16421 +#define        vxm_activate_idle(t,q)          do { } while (0)
16422 +#define        vxm_deactivate_task(t,q)        do { } while (0)
16423 +#define        vxm_hold_task(t,q)              do { } while (0)
16424 +#define        vxm_unhold_task(t,q)            do { } while (0)
16425 +#define        vxm_migrate_task(t,q,d)         do { } while (0)
16426 +#define        vxm_idle_skip(q,c)              do { } while (0)
16427 +#define        vxm_need_resched(t,s,c)         do { } while (0)
16428 +#define        vxm_sync(s,c)                   do { } while (0)
16429 +#define        vxm_sched_info(s,v,c)           do { } while (0)
16430 +#define        vxm_tokens_recalc(s,q,v,c)      do { } while (0)
16431 +#define        vxm_update_sched(s,v,c)         do { } while (0)
16432 +#define        vxm_rq_max_min(q,c)             do { } while (0)
16433 +
16434 +#endif /* CONFIG_VSERVER_MONITOR */
16435 +
16436 diff -NurpP --minimal linux-2.6.29/kernel/signal.c linux-2.6.29-vs2.3.0.36.9-pre3/kernel/signal.c
16437 --- linux-2.6.29/kernel/signal.c        2009-03-24 14:22:45.000000000 +0100
16438 +++ linux-2.6.29-vs2.3.0.36.9-pre3/kernel/signal.c      2009-03-24 14:48:36.000000000 +0100
16439 @@ -27,6 +27,8 @@
16440  #include <linux/freezer.h>
16441  #include <linux/pid_namespace.h>
16442  #include <linux/nsproxy.h>
16443 +#include <linux/vs_context.h>
16444 +#include <linux/vs_pid.h>
16445  #include <trace/sched.h>
16446  
16447  #include <asm/param.h>
16448 @@ -584,6 +586,14 @@ static int check_kill_permission(int sig
16449         if (!valid_signal(sig))
16450                 return -EINVAL;
16451  
16452 +       if ((info != SEND_SIG_NOINFO) &&
16453 +               (is_si_special(info) || !SI_FROMUSER(info)))
16454 +               goto skip;
16455 +
16456 +       vxdprintk(VXD_CBIT(misc, 7),
16457 +               "check_kill_permission(%d,%p,%p[#%u,%u])",
16458 +               sig, info, t, vx_task_xid(t), t->pid);
16459 +
16460         if (info != SEND_SIG_NOINFO && (is_si_special(info) || SI_FROMKERNEL(info)))
16461                 return 0;
16462  
16463 @@ -611,6 +621,18 @@ static int check_kill_permission(int sig
16464                 }
16465         }
16466  
16467 +       error = -EPERM;
16468 +       if (t->pid == 1 && current->xid)
16469 +               return error;
16470 +
16471 +       error = -ESRCH;
16472 +       if (!vx_check(vx_task_xid(t), VS_WATCH_P | VS_IDENT)) {
16473 +               vxdprintk(current->xid || VXD_CBIT(misc, 7),
16474 +                       "signal %d[%p] xid mismatch %p[#%u,%u] xid=#%u",
16475 +                       sig, info, t, vx_task_xid(t), t->pid, current->xid);
16476 +               return error;
16477 +       }
16478 +skip:
16479         return security_task_kill(t, info, sig, 0);
16480  }
16481  
16482 @@ -1076,7 +1098,7 @@ int kill_pid_info(int sig, struct siginf
16483         rcu_read_lock();
16484  retry:
16485         p = pid_task(pid, PIDTYPE_PID);
16486 -       if (p) {
16487 +       if (p && vx_check(vx_task_xid(p), VS_ADMIN | VS_IDENT)) {
16488                 error = group_send_sig_info(sig, info, p);
16489                 if (unlikely(error == -ESRCH))
16490                         /*
16491 @@ -1115,7 +1137,7 @@ int kill_pid_info_as_uid(int sig, struct
16492  
16493         read_lock(&tasklist_lock);
16494         p = pid_task(pid, PIDTYPE_PID);
16495 -       if (!p) {
16496 +       if (!p || !vx_check(vx_task_xid(p), VS_IDENT)) {
16497                 ret = -ESRCH;
16498                 goto out_unlock;
16499         }
16500 @@ -1169,8 +1191,10 @@ static int kill_something_info(int sig, 
16501                 struct task_struct * p;
16502  
16503                 for_each_process(p) {
16504 -                       if (task_pid_vnr(p) > 1 &&
16505 -                                       !same_thread_group(p, current)) {
16506 +                       if (vx_check(vx_task_xid(p), VS_ADMIN|VS_IDENT) &&
16507 +                               task_pid_vnr(p) > 1 &&
16508 +                               !same_thread_group(p, current) &&
16509 +                               !vx_current_initpid(p->pid)) {
16510                                 int err = group_send_sig_info(sig, info, p);
16511                                 ++count;
16512                                 if (err != -EPERM)
16513 @@ -1849,6 +1873,11 @@ relock:
16514                     !signal_group_exit(signal))
16515                         continue;
16516  
16517 +               /* virtual init is protected against user signals */
16518 +               if ((info->si_code == SI_USER) &&
16519 +                       vx_current_initpid(current->pid))
16520 +                       continue;
16521 +
16522                 if (sig_kernel_stop(signr)) {
16523                         /*
16524                          * The default action is to stop all threads in
16525 diff -NurpP --minimal linux-2.6.29/kernel/softirq.c linux-2.6.29-vs2.3.0.36.9-pre3/kernel/softirq.c
16526 --- linux-2.6.29/kernel/softirq.c       2009-03-24 14:22:45.000000000 +0100
16527 +++ linux-2.6.29-vs2.3.0.36.9-pre3/kernel/softirq.c     2009-03-24 14:48:36.000000000 +0100
16528 @@ -23,6 +23,7 @@
16529  #include <linux/rcupdate.h>
16530  #include <linux/smp.h>
16531  #include <linux/tick.h>
16532 +#include <linux/vs_context.h>
16533  
16534  #include <asm/irq.h>
16535  /*
16536 diff -NurpP --minimal linux-2.6.29/kernel/sys.c linux-2.6.29-vs2.3.0.36.9-pre3/kernel/sys.c
16537 --- linux-2.6.29/kernel/sys.c   2009-03-24 14:22:45.000000000 +0100
16538 +++ linux-2.6.29-vs2.3.0.36.9-pre3/kernel/sys.c 2009-03-24 14:48:36.000000000 +0100
16539 @@ -39,6 +39,7 @@
16540  #include <linux/syscalls.h>
16541  #include <linux/kprobes.h>
16542  #include <linux/user_namespace.h>
16543 +#include <linux/vs_pid.h>
16544  
16545  #include <asm/uaccess.h>
16546  #include <asm/io.h>
16547 @@ -128,7 +129,10 @@ static int set_one_prio(struct task_stru
16548                 goto out;
16549         }
16550         if (niceval < task_nice(p) && !can_nice(p, niceval)) {
16551 -               error = -EACCES;
16552 +               if (vx_flags(VXF_IGNEG_NICE, 0))
16553 +                       error = 0;
16554 +               else
16555 +                       error = -EACCES;
16556                 goto out;
16557         }
16558         no_nice = security_task_setnice(p, niceval);
16559 @@ -177,6 +181,8 @@ SYSCALL_DEFINE3(setpriority, int, which,
16560                         else
16561                                 pgrp = task_pgrp(current);
16562                         do_each_pid_thread(pgrp, PIDTYPE_PGID, p) {
16563 +                               if (!vx_check(p->xid, VS_ADMIN_P | VS_IDENT))
16564 +                                       continue;
16565                                 error = set_one_prio(p, niceval, error);
16566                         } while_each_pid_thread(pgrp, PIDTYPE_PGID, p);
16567                         break;
16568 @@ -238,6 +244,8 @@ SYSCALL_DEFINE2(getpriority, int, which,
16569                         else
16570                                 pgrp = task_pgrp(current);
16571                         do_each_pid_thread(pgrp, PIDTYPE_PGID, p) {
16572 +                               if (!vx_check(p->xid, VS_ADMIN_P | VS_IDENT))
16573 +                                       continue;
16574                                 niceval = 20 - task_nice(p);
16575                                 if (niceval > retval)
16576                                         retval = niceval;
16577 @@ -347,6 +355,9 @@ void kernel_power_off(void)
16578         machine_power_off();
16579  }
16580  EXPORT_SYMBOL_GPL(kernel_power_off);
16581 +
16582 +long vs_reboot(unsigned int, void __user *);
16583 +
16584  /*
16585   * Reboot system call: for obvious reasons only root may call it,
16586   * and even root needs to set up some magic numbers in the registers
16587 @@ -378,6 +389,9 @@ SYSCALL_DEFINE4(reboot, int, magic1, int
16588         if ((cmd == LINUX_REBOOT_CMD_POWER_OFF) && !pm_power_off)
16589                 cmd = LINUX_REBOOT_CMD_HALT;
16590  
16591 +       if (!vx_check(0, VS_ADMIN|VS_WATCH))
16592 +               return vs_reboot(cmd, arg);
16593 +
16594         lock_kernel();
16595         switch (cmd) {
16596         case LINUX_REBOOT_CMD_RESTART:
16597 @@ -1420,7 +1434,7 @@ SYSCALL_DEFINE2(sethostname, char __user
16598         int errno;
16599         char tmp[__NEW_UTS_LEN];
16600  
16601 -       if (!capable(CAP_SYS_ADMIN))
16602 +       if (!vx_capable(CAP_SYS_ADMIN, VXC_SET_UTSNAME))
16603                 return -EPERM;
16604         if (len < 0 || len > __NEW_UTS_LEN)
16605                 return -EINVAL;
16606 @@ -1469,7 +1483,7 @@ SYSCALL_DEFINE2(setdomainname, char __us
16607         int errno;
16608         char tmp[__NEW_UTS_LEN];
16609  
16610 -       if (!capable(CAP_SYS_ADMIN))
16611 +       if (!vx_capable(CAP_SYS_ADMIN, VXC_SET_UTSNAME))
16612                 return -EPERM;
16613         if (len < 0 || len > __NEW_UTS_LEN)
16614                 return -EINVAL;
16615 @@ -1538,7 +1552,7 @@ SYSCALL_DEFINE2(setrlimit, unsigned int,
16616                 return -EINVAL;
16617         old_rlim = current->signal->rlim + resource;
16618         if ((new_rlim.rlim_max > old_rlim->rlim_max) &&
16619 -           !capable(CAP_SYS_RESOURCE))
16620 +           !vx_capable(CAP_SYS_RESOURCE, VXC_SET_RLIMIT))
16621                 return -EPERM;
16622         if (resource == RLIMIT_NOFILE && new_rlim.rlim_max > sysctl_nr_open)
16623                 return -EPERM;
16624 diff -NurpP --minimal linux-2.6.29/kernel/sysctl.c linux-2.6.29-vs2.3.0.36.9-pre3/kernel/sysctl.c
16625 --- linux-2.6.29/kernel/sysctl.c        2009-03-24 14:22:45.000000000 +0100
16626 +++ linux-2.6.29-vs2.3.0.36.9-pre3/kernel/sysctl.c      2009-03-24 14:48:36.000000000 +0100
16627 @@ -114,6 +114,7 @@ static int ngroups_max = NGROUPS_MAX;
16628  #ifdef CONFIG_MODULES
16629  extern char modprobe_path[];
16630  #endif
16631 +extern char vshelper_path[];
16632  #ifdef CONFIG_CHR_DEV_SG
16633  extern int sg_big_buff;
16634  #endif
16635 @@ -545,6 +546,15 @@ static struct ctl_table kern_table[] = {
16636                 .strategy       = &sysctl_string,
16637         },
16638  #endif
16639 +       {
16640 +               .ctl_name       = KERN_VSHELPER,
16641 +               .procname       = "vshelper",
16642 +               .data           = &vshelper_path,
16643 +               .maxlen         = 256,
16644 +               .mode           = 0644,
16645 +               .proc_handler   = &proc_dostring,
16646 +               .strategy       = &sysctl_string,
16647 +       },
16648  #ifdef CONFIG_CHR_DEV_SG
16649         {
16650                 .ctl_name       = KERN_SG_BIG_BUFF,
16651 diff -NurpP --minimal linux-2.6.29/kernel/sysctl_check.c linux-2.6.29-vs2.3.0.36.9-pre3/kernel/sysctl_check.c
16652 --- linux-2.6.29/kernel/sysctl_check.c  2009-03-24 14:22:45.000000000 +0100
16653 +++ linux-2.6.29-vs2.3.0.36.9-pre3/kernel/sysctl_check.c        2009-03-24 14:48:36.000000000 +0100
16654 @@ -39,6 +39,7 @@ static const struct trans_ctl_table tran
16655  
16656         { KERN_PANIC,                   "panic" },
16657         { KERN_REALROOTDEV,             "real-root-dev" },
16658 +       { KERN_VSHELPER,                "vshelper", },
16659  
16660         { KERN_SPARC_REBOOT,            "reboot-cmd" },
16661         { KERN_CTLALTDEL,               "ctrl-alt-del" },
16662 @@ -1216,6 +1217,22 @@ static const struct trans_ctl_table tran
16663         {}
16664  };
16665  
16666 +static struct trans_ctl_table trans_vserver_table[] = {
16667 +       { 1,    "debug_switch" },
16668 +       { 2,    "debug_xid" },
16669 +       { 3,    "debug_nid" },
16670 +       { 4,    "debug_tag" },
16671 +       { 5,    "debug_net" },
16672 +       { 6,    "debug_limit" },
16673 +       { 7,    "debug_cres" },
16674 +       { 8,    "debug_dlim" },
16675 +       { 9,    "debug_quota" },
16676 +       { 10,   "debug_cvirt" },
16677 +       { 11,   "debug_space" },
16678 +       { 12,   "debug_misc" },
16679 +       {}
16680 +};
16681 +
16682  static const struct trans_ctl_table trans_root_table[] = {
16683         { CTL_KERN,     "kernel",       trans_kern_table },
16684         { CTL_VM,       "vm",           trans_vm_table },
16685 @@ -1232,6 +1249,7 @@ static const struct trans_ctl_table tran
16686         { CTL_SUNRPC,   "sunrpc",       trans_sunrpc_table },
16687         { CTL_PM,       "pm",           trans_pm_table },
16688         { CTL_FRV,      "frv",          trans_frv_table },
16689 +       { CTL_VSERVER,  "vserver",      trans_vserver_table },
16690         {}
16691  };
16692  
16693 diff -NurpP --minimal linux-2.6.29/kernel/time.c linux-2.6.29-vs2.3.0.36.9-pre3/kernel/time.c
16694 --- linux-2.6.29/kernel/time.c  2009-03-24 14:22:45.000000000 +0100
16695 +++ linux-2.6.29-vs2.3.0.36.9-pre3/kernel/time.c        2009-03-24 14:48:36.000000000 +0100
16696 @@ -63,6 +63,7 @@ EXPORT_SYMBOL(sys_tz);
16697  SYSCALL_DEFINE1(time, time_t __user *, tloc)
16698  {
16699         time_t i = get_seconds();
16700 +/*     FIXME: do_gettimeofday(&tv) -> vx_gettimeofday(&tv) */
16701  
16702         if (tloc) {
16703                 if (put_user(i,tloc))
16704 @@ -93,7 +94,7 @@ SYSCALL_DEFINE1(stime, time_t __user *, 
16705         if (err)
16706                 return err;
16707  
16708 -       do_settimeofday(&tv);
16709 +       vx_settimeofday(&tv);
16710         return 0;
16711  }
16712  
16713 @@ -104,7 +105,7 @@ SYSCALL_DEFINE2(gettimeofday, struct tim
16714  {
16715         if (likely(tv != NULL)) {
16716                 struct timeval ktv;
16717 -               do_gettimeofday(&ktv);
16718 +               vx_gettimeofday(&ktv);
16719                 if (copy_to_user(tv, &ktv, sizeof(ktv)))
16720                         return -EFAULT;
16721         }
16722 @@ -179,7 +180,7 @@ int do_sys_settimeofday(struct timespec 
16723                 /* SMP safe, again the code in arch/foo/time.c should
16724                  * globally block out interrupts when it runs.
16725                  */
16726 -               return do_settimeofday(tv);
16727 +               return vx_settimeofday(tv);
16728         }
16729         return 0;
16730  }
16731 @@ -311,7 +312,7 @@ void getnstimeofday(struct timespec *tv)
16732  {
16733         struct timeval x;
16734  
16735 -       do_gettimeofday(&x);
16736 +       vx_gettimeofday(&x);
16737         tv->tv_sec = x.tv_sec;
16738         tv->tv_nsec = x.tv_usec * NSEC_PER_USEC;
16739  }
16740 diff -NurpP --minimal linux-2.6.29/kernel/timer.c linux-2.6.29-vs2.3.0.36.9-pre3/kernel/timer.c
16741 --- linux-2.6.29/kernel/timer.c 2009-03-24 14:22:45.000000000 +0100
16742 +++ linux-2.6.29-vs2.3.0.36.9-pre3/kernel/timer.c       2009-03-24 17:41:02.000000000 +0100
16743 @@ -37,6 +37,10 @@
16744  #include <linux/delay.h>
16745  #include <linux/tick.h>
16746  #include <linux/kallsyms.h>
16747 +#include <linux/vs_base.h>
16748 +#include <linux/vs_cvirt.h>
16749 +#include <linux/vs_pid.h>
16750 +#include <linux/vserver/sched.h>
16751  
16752  #include <asm/uaccess.h>
16753  #include <asm/unistd.h>
16754 @@ -1018,6 +1022,25 @@ unsigned long get_next_timer_interrupt(u
16755  }
16756  #endif
16757  
16758 +static inline
16759 +void __vx_consume_token(struct _vx_sched_pc *sched_pc)
16760 +{
16761 +       sched_pc->tokens--;
16762 +}
16763 +
16764 +static inline
16765 +void vx_hard_tick(struct task_struct *p, int cpu)
16766 +{
16767 +       struct vx_info *vxi = p->vx_info;
16768 +
16769 +       if (vx_info_flags(vxi, VXF_SCHED_HARD|VXF_SCHED_PRIO, 0)) {
16770 +               struct _vx_sched_pc *sched_pc =
16771 +                       &vx_per_cpu(vxi, sched_pc, cpu);
16772 +
16773 +               __vx_consume_token(sched_pc);
16774 +       }
16775 +}
16776 +
16777  /*
16778   * Called from the timer interrupt handler to charge one tick to the current
16779   * process.  user_tick is 1 if the tick is user time, 0 for system.
16780 @@ -1034,6 +1057,7 @@ void update_process_times(int user_tick)
16781                 rcu_check_callbacks(cpu, user_tick);
16782         printk_tick();
16783         scheduler_tick();
16784 +       vx_hard_tick(p, cpu);
16785         run_posix_cpu_timers(p);
16786  }
16787  
16788 @@ -1136,12 +1160,6 @@ SYSCALL_DEFINE1(alarm, unsigned int, sec
16789  
16790  #endif
16791  
16792 -#ifndef __alpha__
16793 -
16794 -/*
16795 - * The Alpha uses getxpid, getxuid, and getxgid instead.  Maybe this
16796 - * should be moved into arch/i386 instead?
16797 - */
16798  
16799  /**
16800   * sys_getpid - return the thread group id of the current process
16801 @@ -1170,10 +1188,23 @@ SYSCALL_DEFINE0(getppid)
16802         rcu_read_lock();
16803         pid = task_tgid_vnr(current->real_parent);
16804         rcu_read_unlock();
16805 +       return vx_map_pid(pid);
16806 +}
16807  
16808 -       return pid;
16809 +#ifdef __alpha__
16810 +
16811 +/*
16812 + * The Alpha uses getxpid, getxuid, and getxgid instead.
16813 + */
16814 +
16815 +asmlinkage long do_getxpid(long *ppid)
16816 +{
16817 +       *ppid = sys_getppid();
16818 +       return sys_getpid();
16819  }
16820  
16821 +#else /* _alpha_ */
16822 +
16823  SYSCALL_DEFINE0(getuid)
16824  {
16825         /* Only we change this so SMP safe */
16826 @@ -1344,6 +1375,8 @@ int do_sysinfo(struct sysinfo *info)
16827                         tp.tv_nsec = tp.tv_nsec - NSEC_PER_SEC;
16828                         tp.tv_sec++;
16829                 }
16830 +               if (vx_flags(VXF_VIRT_UPTIME, 0))
16831 +                       vx_vsi_uptime(&tp, NULL);
16832                 info->uptime = tp.tv_sec + (tp.tv_nsec ? 1 : 0);
16833  
16834                 info->loads[0] = avenrun[0] << (SI_LOAD_SHIFT - FSHIFT);
16835 diff -NurpP --minimal linux-2.6.29/kernel/user.c linux-2.6.29-vs2.3.0.36.9-pre3/kernel/user.c
16836 --- linux-2.6.29/kernel/user.c  2009-03-24 14:22:45.000000000 +0100
16837 +++ linux-2.6.29-vs2.3.0.36.9-pre3/kernel/user.c        2009-03-24 17:47:32.000000000 +0100
16838 @@ -249,10 +249,10 @@ static struct kobj_type uids_ktype = {
16839   *
16840   * See Documentation/scheduler/sched-design-CFS.txt for ramifications.
16841   */
16842 -static int uids_user_create(struct user_struct *up)
16843 +static int uids_user_create(struct user_namespace *ns, struct user_struct *up)
16844  {
16845         struct kobject *kobj = &up->kobj;
16846 -       int error;
16847 +       int error = 0;
16848  
16849         memset(kobj, 0, sizeof(struct kobject));
16850         if (up->user_ns != &init_user_ns)
16851 @@ -280,7 +280,7 @@ int __init uids_sysfs_init(void)
16852         if (!uids_kset)
16853                 return -ENOMEM;
16854  
16855 -       return uids_user_create(&root_user);
16856 +       return uids_user_create(NULL, &root_user);
16857  }
16858  
16859  /* work function to remove sysfs directory for a user and free up
16860 @@ -342,7 +342,8 @@ static void free_user(struct user_struct
16861  #else  /* CONFIG_USER_SCHED && CONFIG_SYSFS */
16862  
16863  int uids_sysfs_init(void) { return 0; }
16864 -static inline int uids_user_create(struct user_struct *up) { return 0; }
16865 +static inline int uids_user_create(struct user_namespace *ns,
16866 +       struct user_struct *up) { return 0; }
16867  static inline void uids_mutex_lock(void) { }
16868  static inline void uids_mutex_unlock(void) { }
16869  
16870 @@ -439,7 +440,7 @@ struct user_struct *alloc_uid(struct use
16871  
16872                 new->user_ns = get_user_ns(ns);
16873  
16874 -               if (uids_user_create(new))
16875 +               if (uids_user_create(ns, new))
16876                         goto out_destoy_sched;
16877  
16878                 /*
16879 diff -NurpP --minimal linux-2.6.29/kernel/user_namespace.c linux-2.6.29-vs2.3.0.36.9-pre3/kernel/user_namespace.c
16880 --- linux-2.6.29/kernel/user_namespace.c        2009-03-24 14:22:45.000000000 +0100
16881 +++ linux-2.6.29-vs2.3.0.36.9-pre3/kernel/user_namespace.c      2009-03-24 18:05:19.000000000 +0100
16882 @@ -10,6 +10,7 @@
16883  #include <linux/slab.h>
16884  #include <linux/user_namespace.h>
16885  #include <linux/cred.h>
16886 +#include <linux/vserver/global.h>
16887  
16888  /*
16889   * Create a new user namespace, deriving the creator from the user in the
16890 @@ -30,6 +31,7 @@ int create_user_ns(struct cred *new)
16891                 return -ENOMEM;
16892  
16893         kref_init(&ns->kref);
16894 +       atomic_inc(&vs_global_user_ns);
16895  
16896         for (n = 0; n < UIDHASH_SZ; ++n)
16897                 INIT_HLIST_HEAD(ns->uidhash_table + n);
16898 @@ -78,6 +80,8 @@ void free_user_ns(struct kref *kref)
16899         struct user_namespace *ns =
16900                 container_of(kref, struct user_namespace, kref);
16901  
16902 +       /* FIXME: maybe move into destroyer? */
16903 +       atomic_dec(&vs_global_user_ns);
16904         INIT_WORK(&ns->destroyer, free_user_ns_work);
16905         schedule_work(&ns->destroyer);
16906  }
16907 diff -NurpP --minimal linux-2.6.29/kernel/utsname.c linux-2.6.29-vs2.3.0.36.9-pre3/kernel/utsname.c
16908 --- linux-2.6.29/kernel/utsname.c       2008-12-25 00:26:37.000000000 +0100
16909 +++ linux-2.6.29-vs2.3.0.36.9-pre3/kernel/utsname.c     2009-02-22 22:54:26.000000000 +0100
16910 @@ -14,6 +14,7 @@
16911  #include <linux/utsname.h>
16912  #include <linux/err.h>
16913  #include <linux/slab.h>
16914 +#include <linux/vserver/global.h>
16915  
16916  /*
16917   * Clone a new ns copying an original utsname, setting refcount to 1
16918 @@ -32,6 +33,7 @@ static struct uts_namespace *clone_uts_n
16919         memcpy(&ns->name, &old_ns->name, sizeof(ns->name));
16920         up_read(&uts_sem);
16921         kref_init(&ns->kref);
16922 +       atomic_inc(&vs_global_uts_ns);
16923         return ns;
16924  }
16925  
16926 @@ -62,5 +64,6 @@ void free_uts_ns(struct kref *kref)
16927         struct uts_namespace *ns;
16928  
16929         ns = container_of(kref, struct uts_namespace, kref);
16930 +       atomic_dec(&vs_global_uts_ns);
16931         kfree(ns);
16932  }
16933 diff -NurpP --minimal linux-2.6.29/kernel/vserver/cacct.c linux-2.6.29-vs2.3.0.36.9-pre3/kernel/vserver/cacct.c
16934 --- linux-2.6.29/kernel/vserver/cacct.c 1970-01-01 01:00:00.000000000 +0100
16935 +++ linux-2.6.29-vs2.3.0.36.9-pre3/kernel/vserver/cacct.c       2009-02-22 22:54:26.000000000 +0100
16936 @@ -0,0 +1,42 @@
16937 +/*
16938 + *  linux/kernel/vserver/cacct.c
16939 + *
16940 + *  Virtual Server: Context Accounting
16941 + *
16942 + *  Copyright (C) 2006-2007 Herbert Pötzl
16943 + *
16944 + *  V0.01  added accounting stats
16945 + *
16946 + */
16947 +
16948 +#include <linux/types.h>
16949 +#include <linux/vs_context.h>
16950 +#include <linux/vserver/cacct_cmd.h>
16951 +#include <linux/vserver/cacct_int.h>
16952 +
16953 +#include <asm/errno.h>
16954 +#include <asm/uaccess.h>
16955 +
16956 +
16957 +int vc_sock_stat(struct vx_info *vxi, void __user *data)
16958 +{
16959 +       struct vcmd_sock_stat_v0 vc_data;
16960 +       int j, field;
16961 +
16962 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
16963 +               return -EFAULT;
16964 +
16965 +       field = vc_data.field;
16966 +       if ((field < 0) || (field >= VXA_SOCK_SIZE))
16967 +               return -EINVAL;
16968 +
16969 +       for (j = 0; j < 3; j++) {
16970 +               vc_data.count[j] = vx_sock_count(&vxi->cacct, field, j);
16971 +               vc_data.total[j] = vx_sock_total(&vxi->cacct, field, j);
16972 +       }
16973 +
16974 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
16975 +               return -EFAULT;
16976 +       return 0;
16977 +}
16978 +
16979 diff -NurpP --minimal linux-2.6.29/kernel/vserver/cacct_init.h linux-2.6.29-vs2.3.0.36.9-pre3/kernel/vserver/cacct_init.h
16980 --- linux-2.6.29/kernel/vserver/cacct_init.h    1970-01-01 01:00:00.000000000 +0100
16981 +++ linux-2.6.29-vs2.3.0.36.9-pre3/kernel/vserver/cacct_init.h  2009-02-22 22:54:26.000000000 +0100
16982 @@ -0,0 +1,25 @@
16983 +
16984 +
16985 +static inline void vx_info_init_cacct(struct _vx_cacct *cacct)
16986 +{
16987 +       int i, j;
16988 +
16989 +
16990 +       for (i = 0; i < VXA_SOCK_SIZE; i++) {
16991 +               for (j = 0; j < 3; j++) {
16992 +                       atomic_set(&cacct->sock[i][j].count, 0);
16993 +                       atomic_set(&cacct->sock[i][j].total, 0);
16994 +               }
16995 +       }
16996 +       for (i = 0; i < 8; i++)
16997 +               atomic_set(&cacct->slab[i], 0);
16998 +       for (i = 0; i < 5; i++)
16999 +               for (j = 0; j < 4; j++)
17000 +                       atomic_set(&cacct->page[i][j], 0);
17001 +}
17002 +
17003 +static inline void vx_info_exit_cacct(struct _vx_cacct *cacct)
17004 +{
17005 +       return;
17006 +}
17007 +
17008 diff -NurpP --minimal linux-2.6.29/kernel/vserver/cacct_proc.h linux-2.6.29-vs2.3.0.36.9-pre3/kernel/vserver/cacct_proc.h
17009 --- linux-2.6.29/kernel/vserver/cacct_proc.h    1970-01-01 01:00:00.000000000 +0100
17010 +++ linux-2.6.29-vs2.3.0.36.9-pre3/kernel/vserver/cacct_proc.h  2009-02-22 22:54:26.000000000 +0100
17011 @@ -0,0 +1,53 @@
17012 +#ifndef _VX_CACCT_PROC_H
17013 +#define _VX_CACCT_PROC_H
17014 +
17015 +#include <linux/vserver/cacct_int.h>
17016 +
17017 +
17018 +#define VX_SOCKA_TOP   \
17019 +       "Type\t    recv #/bytes\t\t   send #/bytes\t\t    fail #/bytes\n"
17020 +
17021 +static inline int vx_info_proc_cacct(struct _vx_cacct *cacct, char *buffer)
17022 +{
17023 +       int i, j, length = 0;
17024 +       static char *type[VXA_SOCK_SIZE] = {
17025 +               "UNSPEC", "UNIX", "INET", "INET6", "PACKET", "OTHER"
17026 +       };
17027 +
17028 +       length += sprintf(buffer + length, VX_SOCKA_TOP);
17029 +       for (i = 0; i < VXA_SOCK_SIZE; i++) {
17030 +               length += sprintf(buffer + length, "%s:", type[i]);
17031 +               for (j = 0; j < 3; j++) {
17032 +                       length += sprintf(buffer + length,
17033 +                               "\t%10lu/%-10lu",
17034 +                               vx_sock_count(cacct, i, j),
17035 +                               vx_sock_total(cacct, i, j));
17036 +               }
17037 +               buffer[length++] = '\n';
17038 +       }
17039 +
17040 +       length += sprintf(buffer + length, "\n");
17041 +       length += sprintf(buffer + length,
17042 +               "slab:\t %8u %8u %8u %8u\n",
17043 +               atomic_read(&cacct->slab[1]),
17044 +               atomic_read(&cacct->slab[4]),
17045 +               atomic_read(&cacct->slab[0]),
17046 +               atomic_read(&cacct->slab[2]));
17047 +
17048 +       length += sprintf(buffer + length, "\n");
17049 +       for (i = 0; i < 5; i++) {
17050 +               length += sprintf(buffer + length,
17051 +                       "page[%d]: %8u %8u %8u %8u\t %8u %8u %8u %8u\n", i,
17052 +                       atomic_read(&cacct->page[i][0]),
17053 +                       atomic_read(&cacct->page[i][1]),
17054 +                       atomic_read(&cacct->page[i][2]),
17055 +                       atomic_read(&cacct->page[i][3]),
17056 +                       atomic_read(&cacct->page[i][4]),
17057 +                       atomic_read(&cacct->page[i][5]),
17058 +                       atomic_read(&cacct->page[i][6]),
17059 +                       atomic_read(&cacct->page[i][7]));
17060 +       }
17061 +       return length;
17062 +}
17063 +
17064 +#endif /* _VX_CACCT_PROC_H */
17065 diff -NurpP --minimal linux-2.6.29/kernel/vserver/context.c linux-2.6.29-vs2.3.0.36.9-pre3/kernel/vserver/context.c
17066 --- linux-2.6.29/kernel/vserver/context.c       1970-01-01 01:00:00.000000000 +0100
17067 +++ linux-2.6.29-vs2.3.0.36.9-pre3/kernel/vserver/context.c     2009-03-31 22:25:17.000000000 +0200
17068 @@ -0,0 +1,1018 @@
17069 +/*
17070 + *  linux/kernel/vserver/context.c
17071 + *
17072 + *  Virtual Server: Context Support
17073 + *
17074 + *  Copyright (C) 2003-2007  Herbert Pötzl
17075 + *
17076 + *  V0.01  context helper
17077 + *  V0.02  vx_ctx_kill syscall command
17078 + *  V0.03  replaced context_info calls
17079 + *  V0.04  redesign of struct (de)alloc
17080 + *  V0.05  rlimit basic implementation
17081 + *  V0.06  task_xid and info commands
17082 + *  V0.07  context flags and caps
17083 + *  V0.08  switch to RCU based hash
17084 + *  V0.09  revert to non RCU for now
17085 + *  V0.10  and back to working RCU hash
17086 + *  V0.11  and back to locking again
17087 + *  V0.12  referenced context store
17088 + *  V0.13  separate per cpu data
17089 + *  V0.14  changed vcmds to vxi arg
17090 + *  V0.15  added context stat
17091 + *  V0.16  have __create claim() the vxi
17092 + *  V0.17  removed older and legacy stuff
17093 + *
17094 + */
17095 +
17096 +#include <linux/slab.h>
17097 +#include <linux/types.h>
17098 +#include <linux/security.h>
17099 +#include <linux/pid_namespace.h>
17100 +
17101 +#include <linux/vserver/context.h>
17102 +#include <linux/vserver/network.h>
17103 +#include <linux/vserver/debug.h>
17104 +#include <linux/vserver/limit.h>
17105 +#include <linux/vserver/limit_int.h>
17106 +#include <linux/vserver/space.h>
17107 +
17108 +#include <linux/vs_context.h>
17109 +#include <linux/vs_limit.h>
17110 +#include <linux/vs_pid.h>
17111 +#include <linux/vserver/context_cmd.h>
17112 +
17113 +#include "cvirt_init.h"
17114 +#include "cacct_init.h"
17115 +#include "limit_init.h"
17116 +#include "sched_init.h"
17117 +
17118 +
17119 +atomic_t vx_global_ctotal      = ATOMIC_INIT(0);
17120 +atomic_t vx_global_cactive     = ATOMIC_INIT(0);
17121 +
17122 +
17123 +/*     now inactive context structures */
17124 +
17125 +static struct hlist_head vx_info_inactive = HLIST_HEAD_INIT;
17126 +
17127 +static spinlock_t vx_info_inactive_lock = SPIN_LOCK_UNLOCKED;
17128 +
17129 +
17130 +/*     __alloc_vx_info()
17131 +
17132 +       * allocate an initialized vx_info struct
17133 +       * doesn't make it visible (hash)                        */
17134 +
17135 +static struct vx_info *__alloc_vx_info(xid_t xid)
17136 +{
17137 +       struct vx_info *new = NULL;
17138 +       int cpu;
17139 +
17140 +       vxdprintk(VXD_CBIT(xid, 0), "alloc_vx_info(%d)*", xid);
17141 +
17142 +       /* would this benefit from a slab cache? */
17143 +       new = kmalloc(sizeof(struct vx_info), GFP_KERNEL);
17144 +       if (!new)
17145 +               return 0;
17146 +
17147 +       memset(new, 0, sizeof(struct vx_info));
17148 +#ifdef CONFIG_SMP
17149 +       new->ptr_pc = alloc_percpu(struct _vx_info_pc);
17150 +       if (!new->ptr_pc)
17151 +               goto error;
17152 +#endif
17153 +       new->vx_id = xid;
17154 +       INIT_HLIST_NODE(&new->vx_hlist);
17155 +       atomic_set(&new->vx_usecnt, 0);
17156 +       atomic_set(&new->vx_tasks, 0);
17157 +       new->vx_parent = NULL;
17158 +       new->vx_state = 0;
17159 +       init_waitqueue_head(&new->vx_wait);
17160 +
17161 +       /* prepare reaper */
17162 +       get_task_struct(init_pid_ns.child_reaper);
17163 +       new->vx_reaper = init_pid_ns.child_reaper;
17164 +       new->vx_badness_bias = 0;
17165 +
17166 +       /* rest of init goes here */
17167 +       vx_info_init_limit(&new->limit);
17168 +       vx_info_init_sched(&new->sched);
17169 +       vx_info_init_cvirt(&new->cvirt);
17170 +       vx_info_init_cacct(&new->cacct);
17171 +
17172 +       /* per cpu data structures */
17173 +       for_each_possible_cpu(cpu) {
17174 +               vx_info_init_sched_pc(
17175 +                       &vx_per_cpu(new, sched_pc, cpu), cpu);
17176 +               vx_info_init_cvirt_pc(
17177 +                       &vx_per_cpu(new, cvirt_pc, cpu), cpu);
17178 +       }
17179 +
17180 +       new->vx_flags = VXF_INIT_SET;
17181 +       cap_set_init_eff(new->vx_bcaps);
17182 +       new->vx_ccaps = 0;
17183 +       // new->vx_cap_bset = current->cap_bset;
17184 +
17185 +       new->reboot_cmd = 0;
17186 +       new->exit_code = 0;
17187 +
17188 +       vxdprintk(VXD_CBIT(xid, 0),
17189 +               "alloc_vx_info(%d) = %p", xid, new);
17190 +       vxh_alloc_vx_info(new);
17191 +       atomic_inc(&vx_global_ctotal);
17192 +       return new;
17193 +#ifdef CONFIG_SMP
17194 +error:
17195 +       kfree(new);
17196 +       return 0;
17197 +#endif
17198 +}
17199 +
17200 +/*     __dealloc_vx_info()
17201 +
17202 +       * final disposal of vx_info                             */
17203 +
17204 +static void __dealloc_vx_info(struct vx_info *vxi)
17205 +{
17206 +       struct vx_info_save vxis;
17207 +       int cpu;
17208 +
17209 +       vxdprintk(VXD_CBIT(xid, 0),
17210 +               "dealloc_vx_info(%p)", vxi);
17211 +       vxh_dealloc_vx_info(vxi);
17212 +
17213 +#ifdef CONFIG_VSERVER_WARN
17214 +       enter_vx_info(vxi, &vxis);
17215 +       vx_info_exit_limit(&vxi->limit);
17216 +       vx_info_exit_sched(&vxi->sched);
17217 +       vx_info_exit_cvirt(&vxi->cvirt);
17218 +       vx_info_exit_cacct(&vxi->cacct);
17219 +
17220 +       for_each_possible_cpu(cpu) {
17221 +               vx_info_exit_sched_pc(
17222 +                       &vx_per_cpu(vxi, sched_pc, cpu), cpu);
17223 +               vx_info_exit_cvirt_pc(
17224 +                       &vx_per_cpu(vxi, cvirt_pc, cpu), cpu);
17225 +       }
17226 +       leave_vx_info(&vxis);
17227 +#endif
17228 +
17229 +       vxi->vx_id = -1;
17230 +       vxi->vx_state |= VXS_RELEASED;
17231 +
17232 +#ifdef CONFIG_SMP
17233 +       free_percpu(vxi->ptr_pc);
17234 +#endif
17235 +       kfree(vxi);
17236 +       atomic_dec(&vx_global_ctotal);
17237 +}
17238 +
17239 +static void __shutdown_vx_info(struct vx_info *vxi)
17240 +{
17241 +       struct nsproxy *nsproxy;
17242 +       struct fs_struct *fs;
17243 +       int index;
17244 +
17245 +       might_sleep();
17246 +
17247 +       vxi->vx_state |= VXS_SHUTDOWN;
17248 +       vs_state_change(vxi, VSC_SHUTDOWN);
17249 +
17250 +       for (index = 0; index < VX_SPACES; index++) {
17251 +               nsproxy = xchg(&vxi->vx_nsproxy[index], NULL);
17252 +               if (nsproxy)
17253 +                       put_nsproxy(nsproxy);
17254 +
17255 +               fs = xchg(&vxi->vx_fs[index], NULL);
17256 +               if (fs)
17257 +                       put_fs_struct(fs);
17258 +       }
17259 +}
17260 +
17261 +/* exported stuff */
17262 +
17263 +void free_vx_info(struct vx_info *vxi)
17264 +{
17265 +       unsigned long flags;
17266 +       unsigned index;
17267 +
17268 +       /* check for reference counts first */
17269 +       BUG_ON(atomic_read(&vxi->vx_usecnt));
17270 +       BUG_ON(atomic_read(&vxi->vx_tasks));
17271 +
17272 +       /* context must not be hashed */
17273 +       BUG_ON(vx_info_state(vxi, VXS_HASHED));
17274 +
17275 +       /* context shutdown is mandatory */
17276 +       BUG_ON(!vx_info_state(vxi, VXS_SHUTDOWN));
17277 +
17278 +       /* nsproxy and fs check */
17279 +       for (index = 0; index < VX_SPACES; index++) {
17280 +               BUG_ON(vxi->vx_nsproxy[index]);
17281 +               BUG_ON(vxi->vx_fs[index]);
17282 +       }
17283 +
17284 +       spin_lock_irqsave(&vx_info_inactive_lock, flags);
17285 +       hlist_del(&vxi->vx_hlist);
17286 +       spin_unlock_irqrestore(&vx_info_inactive_lock, flags);
17287 +
17288 +       __dealloc_vx_info(vxi);
17289 +}
17290 +
17291 +
17292 +/*     hash table for vx_info hash */
17293 +
17294 +#define VX_HASH_SIZE   13
17295 +
17296 +static struct hlist_head vx_info_hash[VX_HASH_SIZE] =
17297 +       { [0 ... VX_HASH_SIZE-1] = HLIST_HEAD_INIT };
17298 +
17299 +static spinlock_t vx_info_hash_lock = SPIN_LOCK_UNLOCKED;
17300 +
17301 +
17302 +static inline unsigned int __hashval(xid_t xid)
17303 +{
17304 +       return (xid % VX_HASH_SIZE);
17305 +}
17306 +
17307 +
17308 +
17309 +/*     __hash_vx_info()
17310 +
17311 +       * add the vxi to the global hash table
17312 +       * requires the hash_lock to be held                     */
17313 +
17314 +static inline void __hash_vx_info(struct vx_info *vxi)
17315 +{
17316 +       struct hlist_head *head;
17317 +
17318 +       vxd_assert_lock(&vx_info_hash_lock);
17319 +       vxdprintk(VXD_CBIT(xid, 4),
17320 +               "__hash_vx_info: %p[#%d]", vxi, vxi->vx_id);
17321 +       vxh_hash_vx_info(vxi);
17322 +
17323 +       /* context must not be hashed */
17324 +       BUG_ON(vx_info_state(vxi, VXS_HASHED));
17325 +
17326 +       vxi->vx_state |= VXS_HASHED;
17327 +       head = &vx_info_hash[__hashval(vxi->vx_id)];
17328 +       hlist_add_head(&vxi->vx_hlist, head);
17329 +       atomic_inc(&vx_global_cactive);
17330 +}
17331 +
17332 +/*     __unhash_vx_info()
17333 +
17334 +       * remove the vxi from the global hash table
17335 +       * requires the hash_lock to be held                     */
17336 +
17337 +static inline void __unhash_vx_info(struct vx_info *vxi)
17338 +{
17339 +       unsigned long flags;
17340 +
17341 +       vxd_assert_lock(&vx_info_hash_lock);
17342 +       vxdprintk(VXD_CBIT(xid, 4),
17343 +               "__unhash_vx_info: %p[#%d.%d.%d]", vxi, vxi->vx_id,
17344 +               atomic_read(&vxi->vx_usecnt), atomic_read(&vxi->vx_tasks));
17345 +       vxh_unhash_vx_info(vxi);
17346 +
17347 +       /* context must be hashed */
17348 +       BUG_ON(!vx_info_state(vxi, VXS_HASHED));
17349 +       /* but without tasks */
17350 +       BUG_ON(atomic_read(&vxi->vx_tasks));
17351 +
17352 +       vxi->vx_state &= ~VXS_HASHED;
17353 +       hlist_del_init(&vxi->vx_hlist);
17354 +       spin_lock_irqsave(&vx_info_inactive_lock, flags);
17355 +       hlist_add_head(&vxi->vx_hlist, &vx_info_inactive);
17356 +       spin_unlock_irqrestore(&vx_info_inactive_lock, flags);
17357 +       atomic_dec(&vx_global_cactive);
17358 +}
17359 +
17360 +
17361 +/*     __lookup_vx_info()
17362 +
17363 +       * requires the hash_lock to be held
17364 +       * doesn't increment the vx_refcnt                       */
17365 +
17366 +static inline struct vx_info *__lookup_vx_info(xid_t xid)
17367 +{
17368 +       struct hlist_head *head = &vx_info_hash[__hashval(xid)];
17369 +       struct hlist_node *pos;
17370 +       struct vx_info *vxi;
17371 +
17372 +       vxd_assert_lock(&vx_info_hash_lock);
17373 +       hlist_for_each(pos, head) {
17374 +               vxi = hlist_entry(pos, struct vx_info, vx_hlist);
17375 +
17376 +               if (vxi->vx_id == xid)
17377 +                       goto found;
17378 +       }
17379 +       vxi = NULL;
17380 +found:
17381 +       vxdprintk(VXD_CBIT(xid, 0),
17382 +               "__lookup_vx_info(#%u): %p[#%u]",
17383 +               xid, vxi, vxi ? vxi->vx_id : 0);
17384 +       vxh_lookup_vx_info(vxi, xid);
17385 +       return vxi;
17386 +}
17387 +
17388 +
17389 +/*     __create_vx_info()
17390 +
17391 +       * create the requested context
17392 +       * get(), claim() and hash it                            */
17393 +
17394 +static struct vx_info *__create_vx_info(int id)
17395 +{
17396 +       struct vx_info *new, *vxi = NULL;
17397 +
17398 +       vxdprintk(VXD_CBIT(xid, 1), "create_vx_info(%d)*", id);
17399 +
17400 +       if (!(new = __alloc_vx_info(id)))
17401 +               return ERR_PTR(-ENOMEM);
17402 +
17403 +       /* required to make dynamic xids unique */
17404 +       spin_lock(&vx_info_hash_lock);
17405 +
17406 +       /* static context requested */
17407 +       if ((vxi = __lookup_vx_info(id))) {
17408 +               vxdprintk(VXD_CBIT(xid, 0),
17409 +                       "create_vx_info(%d) = %p (already there)", id, vxi);
17410 +               if (vx_info_flags(vxi, VXF_STATE_SETUP, 0))
17411 +                       vxi = ERR_PTR(-EBUSY);
17412 +               else
17413 +                       vxi = ERR_PTR(-EEXIST);
17414 +               goto out_unlock;
17415 +       }
17416 +       /* new context */
17417 +       vxdprintk(VXD_CBIT(xid, 0),
17418 +               "create_vx_info(%d) = %p (new)", id, new);
17419 +       claim_vx_info(new, NULL);
17420 +       __hash_vx_info(get_vx_info(new));
17421 +       vxi = new, new = NULL;
17422 +
17423 +out_unlock:
17424 +       spin_unlock(&vx_info_hash_lock);
17425 +       vxh_create_vx_info(IS_ERR(vxi) ? NULL : vxi, id);
17426 +       if (new)
17427 +               __dealloc_vx_info(new);
17428 +       return vxi;
17429 +}
17430 +
17431 +
17432 +/*     exported stuff                                          */
17433 +
17434 +
17435 +void unhash_vx_info(struct vx_info *vxi)
17436 +{
17437 +       __shutdown_vx_info(vxi);
17438 +       spin_lock(&vx_info_hash_lock);
17439 +       __unhash_vx_info(vxi);
17440 +       spin_unlock(&vx_info_hash_lock);
17441 +       __wakeup_vx_info(vxi);
17442 +}
17443 +
17444 +
17445 +/*     lookup_vx_info()
17446 +
17447 +       * search for a vx_info and get() it
17448 +       * negative id means current                             */
17449 +
17450 +struct vx_info *lookup_vx_info(int id)
17451 +{
17452 +       struct vx_info *vxi = NULL;
17453 +
17454 +       if (id < 0) {
17455 +               vxi = get_vx_info(current->vx_info);
17456 +       } else if (id > 1) {
17457 +               spin_lock(&vx_info_hash_lock);
17458 +               vxi = get_vx_info(__lookup_vx_info(id));
17459 +               spin_unlock(&vx_info_hash_lock);
17460 +       }
17461 +       return vxi;
17462 +}
17463 +
17464 +/*     xid_is_hashed()
17465 +
17466 +       * verify that xid is still hashed                       */
17467 +
17468 +int xid_is_hashed(xid_t xid)
17469 +{
17470 +       int hashed;
17471 +
17472 +       spin_lock(&vx_info_hash_lock);
17473 +       hashed = (__lookup_vx_info(xid) != NULL);
17474 +       spin_unlock(&vx_info_hash_lock);
17475 +       return hashed;
17476 +}
17477 +
17478 +#ifdef CONFIG_PROC_FS
17479 +
17480 +/*     get_xid_list()
17481 +
17482 +       * get a subset of hashed xids for proc
17483 +       * assumes size is at least one                          */
17484 +
17485 +int get_xid_list(int index, unsigned int *xids, int size)
17486 +{
17487 +       int hindex, nr_xids = 0;
17488 +
17489 +       /* only show current and children */
17490 +       if (!vx_check(0, VS_ADMIN | VS_WATCH)) {
17491 +               if (index > 0)
17492 +                       return 0;
17493 +               xids[nr_xids] = vx_current_xid();
17494 +               return 1;
17495 +       }
17496 +
17497 +       for (hindex = 0; hindex < VX_HASH_SIZE; hindex++) {
17498 +               struct hlist_head *head = &vx_info_hash[hindex];
17499 +               struct hlist_node *pos;
17500 +
17501 +               spin_lock(&vx_info_hash_lock);
17502 +               hlist_for_each(pos, head) {
17503 +                       struct vx_info *vxi;
17504 +
17505 +                       if (--index > 0)
17506 +                               continue;
17507 +
17508 +                       vxi = hlist_entry(pos, struct vx_info, vx_hlist);
17509 +                       xids[nr_xids] = vxi->vx_id;
17510 +                       if (++nr_xids >= size) {
17511 +                               spin_unlock(&vx_info_hash_lock);
17512 +                               goto out;
17513 +                       }
17514 +               }
17515 +               /* keep the lock time short */
17516 +               spin_unlock(&vx_info_hash_lock);
17517 +       }
17518 +out:
17519 +       return nr_xids;
17520 +}
17521 +#endif
17522 +
17523 +#ifdef CONFIG_VSERVER_DEBUG
17524 +
17525 +void   dump_vx_info_inactive(int level)
17526 +{
17527 +       struct hlist_node *entry, *next;
17528 +
17529 +       hlist_for_each_safe(entry, next, &vx_info_inactive) {
17530 +               struct vx_info *vxi =
17531 +                       list_entry(entry, struct vx_info, vx_hlist);
17532 +
17533 +               dump_vx_info(vxi, level);
17534 +       }
17535 +}
17536 +
17537 +#endif
17538 +
17539 +#if 0
17540 +int vx_migrate_user(struct task_struct *p, struct vx_info *vxi)
17541 +{
17542 +       struct user_struct *new_user, *old_user;
17543 +
17544 +       if (!p || !vxi)
17545 +               BUG();
17546 +
17547 +       if (vx_info_flags(vxi, VXF_INFO_PRIVATE, 0))
17548 +               return -EACCES;
17549 +
17550 +       new_user = alloc_uid(vxi->vx_id, p->uid);
17551 +       if (!new_user)
17552 +               return -ENOMEM;
17553 +
17554 +       old_user = p->user;
17555 +       if (new_user != old_user) {
17556 +               atomic_inc(&new_user->processes);
17557 +               atomic_dec(&old_user->processes);
17558 +               p->user = new_user;
17559 +       }
17560 +       free_uid(old_user);
17561 +       return 0;
17562 +}
17563 +#endif
17564 +
17565 +#if 0
17566 +void vx_mask_cap_bset(struct vx_info *vxi, struct task_struct *p)
17567 +{
17568 +       // p->cap_effective &= vxi->vx_cap_bset;
17569 +       p->cap_effective =
17570 +               cap_intersect(p->cap_effective, vxi->cap_bset);
17571 +       // p->cap_inheritable &= vxi->vx_cap_bset;
17572 +       p->cap_inheritable =
17573 +               cap_intersect(p->cap_inheritable, vxi->cap_bset);
17574 +       // p->cap_permitted &= vxi->vx_cap_bset;
17575 +       p->cap_permitted =
17576 +               cap_intersect(p->cap_permitted, vxi->cap_bset);
17577 +}
17578 +#endif
17579 +
17580 +
17581 +#include <linux/file.h>
17582 +#include <linux/fdtable.h>
17583 +
17584 +static int vx_openfd_task(struct task_struct *tsk)
17585 +{
17586 +       struct files_struct *files = tsk->files;
17587 +       struct fdtable *fdt;
17588 +       const unsigned long *bptr;
17589 +       int count, total;
17590 +
17591 +       /* no rcu_read_lock() because of spin_lock() */
17592 +       spin_lock(&files->file_lock);
17593 +       fdt = files_fdtable(files);
17594 +       bptr = fdt->open_fds->fds_bits;
17595 +       count = fdt->max_fds / (sizeof(unsigned long) * 8);
17596 +       for (total = 0; count > 0; count--) {
17597 +               if (*bptr)
17598 +                       total += hweight_long(*bptr);
17599 +               bptr++;
17600 +       }
17601 +       spin_unlock(&files->file_lock);
17602 +       return total;
17603 +}
17604 +
17605 +
17606 +/*     for *space compatibility */
17607 +
17608 +asmlinkage long sys_unshare(unsigned long);
17609 +
17610 +/*
17611 + *     migrate task to new context
17612 + *     gets vxi, puts old_vxi on change
17613 + *     optionally unshares namespaces (hack)
17614 + */
17615 +
17616 +int vx_migrate_task(struct task_struct *p, struct vx_info *vxi, int unshare)
17617 +{
17618 +       struct vx_info *old_vxi;
17619 +       int ret = 0;
17620 +
17621 +       if (!p || !vxi)
17622 +               BUG();
17623 +
17624 +       vxdprintk(VXD_CBIT(xid, 5),
17625 +               "vx_migrate_task(%p,%p[#%d.%d])", p, vxi,
17626 +               vxi->vx_id, atomic_read(&vxi->vx_usecnt));
17627 +
17628 +       if (vx_info_flags(vxi, VXF_INFO_PRIVATE, 0) &&
17629 +               !vx_info_flags(vxi, VXF_STATE_SETUP, 0))
17630 +               return -EACCES;
17631 +
17632 +       if (vx_info_state(vxi, VXS_SHUTDOWN))
17633 +               return -EFAULT;
17634 +
17635 +       old_vxi = task_get_vx_info(p);
17636 +       if (old_vxi == vxi)
17637 +               goto out;
17638 +
17639 +//     if (!(ret = vx_migrate_user(p, vxi))) {
17640 +       {
17641 +               int openfd;
17642 +
17643 +               task_lock(p);
17644 +               openfd = vx_openfd_task(p);
17645 +
17646 +               if (old_vxi) {
17647 +                       atomic_dec(&old_vxi->cvirt.nr_threads);
17648 +                       atomic_dec(&old_vxi->cvirt.nr_running);
17649 +                       __rlim_dec(&old_vxi->limit, RLIMIT_NPROC);
17650 +                       /* FIXME: what about the struct files here? */
17651 +                       __rlim_sub(&old_vxi->limit, VLIMIT_OPENFD, openfd);
17652 +                       /* account for the executable */
17653 +                       __rlim_dec(&old_vxi->limit, VLIMIT_DENTRY);
17654 +               }
17655 +               atomic_inc(&vxi->cvirt.nr_threads);
17656 +               atomic_inc(&vxi->cvirt.nr_running);
17657 +               __rlim_inc(&vxi->limit, RLIMIT_NPROC);
17658 +               /* FIXME: what about the struct files here? */
17659 +               __rlim_add(&vxi->limit, VLIMIT_OPENFD, openfd);
17660 +               /* account for the executable */
17661 +               __rlim_inc(&vxi->limit, VLIMIT_DENTRY);
17662 +
17663 +               if (old_vxi) {
17664 +                       release_vx_info(old_vxi, p);
17665 +                       clr_vx_info(&p->vx_info);
17666 +               }
17667 +               claim_vx_info(vxi, p);
17668 +               set_vx_info(&p->vx_info, vxi);
17669 +               p->xid = vxi->vx_id;
17670 +
17671 +               vxdprintk(VXD_CBIT(xid, 5),
17672 +                       "moved task %p into vxi:%p[#%d]",
17673 +                       p, vxi, vxi->vx_id);
17674 +
17675 +               // vx_mask_cap_bset(vxi, p);
17676 +               task_unlock(p);
17677 +
17678 +               /* hack for *spaces to provide compatibility */
17679 +               if (unshare) {
17680 +                       struct nsproxy *old_nsp, *new_nsp;
17681 +
17682 +                       ret = unshare_nsproxy_namespaces(
17683 +                               CLONE_NEWUTS | CLONE_NEWIPC,
17684 +                               &new_nsp, NULL);
17685 +                       if (ret)
17686 +                               goto out;
17687 +
17688 +                       old_nsp = xchg(&p->nsproxy, new_nsp);
17689 +                       vx_set_space(vxi,
17690 +                               CLONE_NEWUTS | CLONE_NEWIPC, 0);
17691 +                       put_nsproxy(old_nsp);
17692 +               }
17693 +       }
17694 +out:
17695 +       put_vx_info(old_vxi);
17696 +       return ret;
17697 +}
17698 +
17699 +int vx_set_reaper(struct vx_info *vxi, struct task_struct *p)
17700 +{
17701 +       struct task_struct *old_reaper;
17702 +
17703 +       if (!vxi)
17704 +               return -EINVAL;
17705 +
17706 +       vxdprintk(VXD_CBIT(xid, 6),
17707 +               "vx_set_reaper(%p[#%d],%p[#%d,%d])",
17708 +               vxi, vxi->vx_id, p, p->xid, p->pid);
17709 +
17710 +       old_reaper = vxi->vx_reaper;
17711 +       if (old_reaper == p)
17712 +               return 0;
17713 +
17714 +       /* set new child reaper */
17715 +       get_task_struct(p);
17716 +       vxi->vx_reaper = p;
17717 +       put_task_struct(old_reaper);
17718 +       return 0;
17719 +}
17720 +
17721 +int vx_set_init(struct vx_info *vxi, struct task_struct *p)
17722 +{
17723 +       if (!vxi)
17724 +               return -EINVAL;
17725 +
17726 +       vxdprintk(VXD_CBIT(xid, 6),
17727 +               "vx_set_init(%p[#%d],%p[#%d,%d,%d])",
17728 +               vxi, vxi->vx_id, p, p->xid, p->pid, p->tgid);
17729 +
17730 +       vxi->vx_flags &= ~VXF_STATE_INIT;
17731 +       vxi->vx_initpid = p->tgid;
17732 +       return 0;
17733 +}
17734 +
17735 +void vx_exit_init(struct vx_info *vxi, struct task_struct *p, int code)
17736 +{
17737 +       vxdprintk(VXD_CBIT(xid, 6),
17738 +               "vx_exit_init(%p[#%d],%p[#%d,%d,%d])",
17739 +               vxi, vxi->vx_id, p, p->xid, p->pid, p->tgid);
17740 +
17741 +       vxi->exit_code = code;
17742 +       vxi->vx_initpid = 0;
17743 +}
17744 +
17745 +
17746 +void vx_set_persistent(struct vx_info *vxi)
17747 +{
17748 +       vxdprintk(VXD_CBIT(xid, 6),
17749 +               "vx_set_persistent(%p[#%d])", vxi, vxi->vx_id);
17750 +
17751 +       get_vx_info(vxi);
17752 +       claim_vx_info(vxi, NULL);
17753 +}
17754 +
17755 +void vx_clear_persistent(struct vx_info *vxi)
17756 +{
17757 +       vxdprintk(VXD_CBIT(xid, 6),
17758 +               "vx_clear_persistent(%p[#%d])", vxi, vxi->vx_id);
17759 +
17760 +       release_vx_info(vxi, NULL);
17761 +       put_vx_info(vxi);
17762 +}
17763 +
17764 +void vx_update_persistent(struct vx_info *vxi)
17765 +{
17766 +       if (vx_info_flags(vxi, VXF_PERSISTENT, 0))
17767 +               vx_set_persistent(vxi);
17768 +       else
17769 +               vx_clear_persistent(vxi);
17770 +}
17771 +
17772 +
17773 +/*     task must be current or locked          */
17774 +
17775 +void   exit_vx_info(struct task_struct *p, int code)
17776 +{
17777 +       struct vx_info *vxi = p->vx_info;
17778 +
17779 +       if (vxi) {
17780 +               atomic_dec(&vxi->cvirt.nr_threads);
17781 +               vx_nproc_dec(p);
17782 +
17783 +               vxi->exit_code = code;
17784 +               release_vx_info(vxi, p);
17785 +       }
17786 +}
17787 +
17788 +void   exit_vx_info_early(struct task_struct *p, int code)
17789 +{
17790 +       struct vx_info *vxi = p->vx_info;
17791 +
17792 +       if (vxi) {
17793 +               if (vxi->vx_initpid == p->tgid)
17794 +                       vx_exit_init(vxi, p, code);
17795 +               if (vxi->vx_reaper == p)
17796 +                       vx_set_reaper(vxi, init_pid_ns.child_reaper);
17797 +       }
17798 +}
17799 +
17800 +
17801 +/* vserver syscall commands below here */
17802 +
17803 +/* taks xid and vx_info functions */
17804 +
17805 +#include <asm/uaccess.h>
17806 +
17807 +
17808 +int vc_task_xid(uint32_t id)
17809 +{
17810 +       xid_t xid;
17811 +
17812 +       if (id) {
17813 +               struct task_struct *tsk;
17814 +
17815 +               read_lock(&tasklist_lock);
17816 +               tsk = find_task_by_real_pid(id);
17817 +               xid = (tsk) ? tsk->xid : -ESRCH;
17818 +               read_unlock(&tasklist_lock);
17819 +       } else
17820 +               xid = vx_current_xid();
17821 +       return xid;
17822 +}
17823 +
17824 +
17825 +int vc_vx_info(struct vx_info *vxi, void __user *data)
17826 +{
17827 +       struct vcmd_vx_info_v0 vc_data;
17828 +
17829 +       vc_data.xid = vxi->vx_id;
17830 +       vc_data.initpid = vxi->vx_initpid;
17831 +
17832 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
17833 +               return -EFAULT;
17834 +       return 0;
17835 +}
17836 +
17837 +
17838 +int vc_ctx_stat(struct vx_info *vxi, void __user *data)
17839 +{
17840 +       struct vcmd_ctx_stat_v0 vc_data;
17841 +
17842 +       vc_data.usecnt = atomic_read(&vxi->vx_usecnt);
17843 +       vc_data.tasks = atomic_read(&vxi->vx_tasks);
17844 +
17845 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
17846 +               return -EFAULT;
17847 +       return 0;
17848 +}
17849 +
17850 +
17851 +/* context functions */
17852 +
17853 +int vc_ctx_create(uint32_t xid, void __user *data)
17854 +{
17855 +       struct vcmd_ctx_create vc_data = { .flagword = VXF_INIT_SET };
17856 +       struct vx_info *new_vxi;
17857 +       int ret;
17858 +
17859 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
17860 +               return -EFAULT;
17861 +
17862 +       if ((xid > MAX_S_CONTEXT) || (xid < 2))
17863 +               return -EINVAL;
17864 +
17865 +       new_vxi = __create_vx_info(xid);
17866 +       if (IS_ERR(new_vxi))
17867 +               return PTR_ERR(new_vxi);
17868 +
17869 +       /* initial flags */
17870 +       new_vxi->vx_flags = vc_data.flagword;
17871 +
17872 +       ret = -ENOEXEC;
17873 +       if (vs_state_change(new_vxi, VSC_STARTUP))
17874 +               goto out;
17875 +
17876 +       ret = vx_migrate_task(current, new_vxi, (!data));
17877 +       if (ret)
17878 +               goto out;
17879 +
17880 +       /* return context id on success */
17881 +       ret = new_vxi->vx_id;
17882 +
17883 +       /* get a reference for persistent contexts */
17884 +       if ((vc_data.flagword & VXF_PERSISTENT))
17885 +               vx_set_persistent(new_vxi);
17886 +out:
17887 +       release_vx_info(new_vxi, NULL);
17888 +       put_vx_info(new_vxi);
17889 +       return ret;
17890 +}
17891 +
17892 +
17893 +int vc_ctx_migrate(struct vx_info *vxi, void __user *data)
17894 +{
17895 +       struct vcmd_ctx_migrate vc_data = { .flagword = 0 };
17896 +       int ret;
17897 +
17898 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
17899 +               return -EFAULT;
17900 +
17901 +       ret = vx_migrate_task(current, vxi, 0);
17902 +       if (ret)
17903 +               return ret;
17904 +       if (vc_data.flagword & VXM_SET_INIT)
17905 +               ret = vx_set_init(vxi, current);
17906 +       if (ret)
17907 +               return ret;
17908 +       if (vc_data.flagword & VXM_SET_REAPER)
17909 +               ret = vx_set_reaper(vxi, current);
17910 +       return ret;
17911 +}
17912 +
17913 +
17914 +int vc_get_cflags(struct vx_info *vxi, void __user *data)
17915 +{
17916 +       struct vcmd_ctx_flags_v0 vc_data;
17917 +
17918 +       vc_data.flagword = vxi->vx_flags;
17919 +
17920 +       /* special STATE flag handling */
17921 +       vc_data.mask = vs_mask_flags(~0ULL, vxi->vx_flags, VXF_ONE_TIME);
17922 +
17923 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
17924 +               return -EFAULT;
17925 +       return 0;
17926 +}
17927 +
17928 +int vc_set_cflags(struct vx_info *vxi, void __user *data)
17929 +{
17930 +       struct vcmd_ctx_flags_v0 vc_data;
17931 +       uint64_t mask, trigger;
17932 +
17933 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
17934 +               return -EFAULT;
17935 +
17936 +       /* special STATE flag handling */
17937 +       mask = vs_mask_mask(vc_data.mask, vxi->vx_flags, VXF_ONE_TIME);
17938 +       trigger = (mask & vxi->vx_flags) ^ (mask & vc_data.flagword);
17939 +
17940 +       if (vxi == current->vx_info) {
17941 +               /* if (trigger & VXF_STATE_SETUP)
17942 +                       vx_mask_cap_bset(vxi, current); */
17943 +               if (trigger & VXF_STATE_INIT) {
17944 +                       int ret;
17945 +
17946 +                       ret = vx_set_init(vxi, current);
17947 +                       if (ret)
17948 +                               return ret;
17949 +                       ret = vx_set_reaper(vxi, current);
17950 +                       if (ret)
17951 +                               return ret;
17952 +               }
17953 +       }
17954 +
17955 +       vxi->vx_flags = vs_mask_flags(vxi->vx_flags,
17956 +               vc_data.flagword, mask);
17957 +       if (trigger & VXF_PERSISTENT)
17958 +               vx_update_persistent(vxi);
17959 +
17960 +       return 0;
17961 +}
17962 +
17963 +
17964 +static inline uint64_t caps_from_cap_t(kernel_cap_t c)
17965 +{
17966 +       uint64_t v = c.cap[0] | ((uint64_t)c.cap[1] << 32);
17967 +
17968 +       // printk("caps_from_cap_t(%08x:%08x) = %016llx\n", c.cap[1], c.cap[0], v);
17969 +       return v;
17970 +}
17971 +
17972 +static inline kernel_cap_t cap_t_from_caps(uint64_t v)
17973 +{
17974 +       kernel_cap_t c = __cap_empty_set;
17975 +
17976 +       c.cap[0] = v & 0xFFFFFFFF;
17977 +       c.cap[1] = (v >> 32) & 0xFFFFFFFF;
17978 +
17979 +       // printk("cap_t_from_caps(%016llx) = %08x:%08x\n", v, c.cap[1], c.cap[0]);
17980 +       return c;
17981 +}
17982 +
17983 +
17984 +static int do_get_caps(struct vx_info *vxi, uint64_t *bcaps, uint64_t *ccaps)
17985 +{
17986 +       if (bcaps)
17987 +               *bcaps = caps_from_cap_t(vxi->vx_bcaps);
17988 +       if (ccaps)
17989 +               *ccaps = vxi->vx_ccaps;
17990 +
17991 +       return 0;
17992 +}
17993 +
17994 +int vc_get_ccaps(struct vx_info *vxi, void __user *data)
17995 +{
17996 +       struct vcmd_ctx_caps_v1 vc_data;
17997 +       int ret;
17998 +
17999 +       ret = do_get_caps(vxi, NULL, &vc_data.ccaps);
18000 +       if (ret)
18001 +               return ret;
18002 +       vc_data.cmask = ~0ULL;
18003 +
18004 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
18005 +               return -EFAULT;
18006 +       return 0;
18007 +}
18008 +
18009 +static int do_set_caps(struct vx_info *vxi,
18010 +       uint64_t bcaps, uint64_t bmask, uint64_t ccaps, uint64_t cmask)
18011 +{
18012 +       uint64_t bcold = caps_from_cap_t(vxi->vx_bcaps);
18013 +
18014 +#if 0
18015 +       printk("do_set_caps(%16llx, %16llx, %16llx, %16llx)\n",
18016 +               bcaps, bmask, ccaps, cmask);
18017 +#endif
18018 +       vxi->vx_bcaps = cap_t_from_caps(
18019 +               vs_mask_flags(bcold, bcaps, bmask));
18020 +       vxi->vx_ccaps = vs_mask_flags(vxi->vx_ccaps, ccaps, cmask);
18021 +
18022 +       return 0;
18023 +}
18024 +
18025 +int vc_set_ccaps(struct vx_info *vxi, void __user *data)
18026 +{
18027 +       struct vcmd_ctx_caps_v1 vc_data;
18028 +
18029 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18030 +               return -EFAULT;
18031 +
18032 +       return do_set_caps(vxi, 0, 0, vc_data.ccaps, vc_data.cmask);
18033 +}
18034 +
18035 +int vc_get_bcaps(struct vx_info *vxi, void __user *data)
18036 +{
18037 +       struct vcmd_bcaps vc_data;
18038 +       int ret;
18039 +
18040 +       ret = do_get_caps(vxi, &vc_data.bcaps, NULL);
18041 +       if (ret)
18042 +               return ret;
18043 +       vc_data.bmask = ~0ULL;
18044 +
18045 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
18046 +               return -EFAULT;
18047 +       return 0;
18048 +}
18049 +
18050 +int vc_set_bcaps(struct vx_info *vxi, void __user *data)
18051 +{
18052 +       struct vcmd_bcaps vc_data;
18053 +
18054 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18055 +               return -EFAULT;
18056 +
18057 +       return do_set_caps(vxi, vc_data.bcaps, vc_data.bmask, 0, 0);
18058 +}
18059 +
18060 +
18061 +int vc_get_badness(struct vx_info *vxi, void __user *data)
18062 +{
18063 +       struct vcmd_badness_v0 vc_data;
18064 +
18065 +       vc_data.bias = vxi->vx_badness_bias;
18066 +
18067 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
18068 +               return -EFAULT;
18069 +       return 0;
18070 +}
18071 +
18072 +int vc_set_badness(struct vx_info *vxi, void __user *data)
18073 +{
18074 +       struct vcmd_badness_v0 vc_data;
18075 +
18076 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18077 +               return -EFAULT;
18078 +
18079 +       vxi->vx_badness_bias = vc_data.bias;
18080 +       return 0;
18081 +}
18082 +
18083 +#include <linux/module.h>
18084 +
18085 +EXPORT_SYMBOL_GPL(free_vx_info);
18086 +
18087 diff -NurpP --minimal linux-2.6.29/kernel/vserver/cvirt.c linux-2.6.29-vs2.3.0.36.9-pre3/kernel/vserver/cvirt.c
18088 --- linux-2.6.29/kernel/vserver/cvirt.c 1970-01-01 01:00:00.000000000 +0100
18089 +++ linux-2.6.29-vs2.3.0.36.9-pre3/kernel/vserver/cvirt.c       2009-02-22 22:54:26.000000000 +0100
18090 @@ -0,0 +1,300 @@
18091 +/*
18092 + *  linux/kernel/vserver/cvirt.c
18093 + *
18094 + *  Virtual Server: Context Virtualization
18095 + *
18096 + *  Copyright (C) 2004-2007  Herbert Pötzl
18097 + *
18098 + *  V0.01  broken out from limit.c
18099 + *  V0.02  added utsname stuff
18100 + *  V0.03  changed vcmds to vxi arg
18101 + *
18102 + */
18103 +
18104 +#include <linux/types.h>
18105 +#include <linux/utsname.h>
18106 +#include <linux/vs_cvirt.h>
18107 +#include <linux/vserver/switch.h>
18108 +#include <linux/vserver/cvirt_cmd.h>
18109 +
18110 +#include <asm/uaccess.h>
18111 +
18112 +
18113 +void vx_vsi_uptime(struct timespec *uptime, struct timespec *idle)
18114 +{
18115 +       struct vx_info *vxi = current->vx_info;
18116 +
18117 +       set_normalized_timespec(uptime,
18118 +               uptime->tv_sec - vxi->cvirt.bias_uptime.tv_sec,
18119 +               uptime->tv_nsec - vxi->cvirt.bias_uptime.tv_nsec);
18120 +       if (!idle)
18121 +               return;
18122 +       set_normalized_timespec(idle,
18123 +               idle->tv_sec - vxi->cvirt.bias_idle.tv_sec,
18124 +               idle->tv_nsec - vxi->cvirt.bias_idle.tv_nsec);
18125 +       return;
18126 +}
18127 +
18128 +uint64_t vx_idle_jiffies(void)
18129 +{
18130 +       return init_task.utime + init_task.stime;
18131 +}
18132 +
18133 +
18134 +
18135 +static inline uint32_t __update_loadavg(uint32_t load,
18136 +       int wsize, int delta, int n)
18137 +{
18138 +       unsigned long long calc, prev;
18139 +
18140 +       /* just set it to n */
18141 +       if (unlikely(delta >= wsize))
18142 +               return (n << FSHIFT);
18143 +
18144 +       calc = delta * n;
18145 +       calc <<= FSHIFT;
18146 +       prev = (wsize - delta);
18147 +       prev *= load;
18148 +       calc += prev;
18149 +       do_div(calc, wsize);
18150 +       return calc;
18151 +}
18152 +
18153 +
18154 +void vx_update_load(struct vx_info *vxi)
18155 +{
18156 +       uint32_t now, last, delta;
18157 +       unsigned int nr_running, nr_uninterruptible;
18158 +       unsigned int total;
18159 +       unsigned long flags;
18160 +
18161 +       spin_lock_irqsave(&vxi->cvirt.load_lock, flags);
18162 +
18163 +       now = jiffies;
18164 +       last = vxi->cvirt.load_last;
18165 +       delta = now - last;
18166 +
18167 +       if (delta < 5*HZ)
18168 +               goto out;
18169 +
18170 +       nr_running = atomic_read(&vxi->cvirt.nr_running);
18171 +       nr_uninterruptible = atomic_read(&vxi->cvirt.nr_uninterruptible);
18172 +       total = nr_running + nr_uninterruptible;
18173 +
18174 +       vxi->cvirt.load[0] = __update_loadavg(vxi->cvirt.load[0],
18175 +               60*HZ, delta, total);
18176 +       vxi->cvirt.load[1] = __update_loadavg(vxi->cvirt.load[1],
18177 +               5*60*HZ, delta, total);
18178 +       vxi->cvirt.load[2] = __update_loadavg(vxi->cvirt.load[2],
18179 +               15*60*HZ, delta, total);
18180 +
18181 +       vxi->cvirt.load_last = now;
18182 +out:
18183 +       atomic_inc(&vxi->cvirt.load_updates);
18184 +       spin_unlock_irqrestore(&vxi->cvirt.load_lock, flags);
18185 +}
18186 +
18187 +
18188 +/*
18189 + * Commands to do_syslog:
18190 + *
18191 + *      0 -- Close the log.  Currently a NOP.
18192 + *      1 -- Open the log. Currently a NOP.
18193 + *      2 -- Read from the log.
18194 + *      3 -- Read all messages remaining in the ring buffer.
18195 + *      4 -- Read and clear all messages remaining in the ring buffer
18196 + *      5 -- Clear ring buffer.
18197 + *      6 -- Disable printk's to console
18198 + *      7 -- Enable printk's to console
18199 + *      8 -- Set level of messages printed to console
18200 + *      9 -- Return number of unread characters in the log buffer
18201 + *     10 -- Return size of the log buffer
18202 + */
18203 +int vx_do_syslog(int type, char __user *buf, int len)
18204 +{
18205 +       int error = 0;
18206 +       int do_clear = 0;
18207 +       struct vx_info *vxi = current->vx_info;
18208 +       struct _vx_syslog *log;
18209 +
18210 +       if (!vxi)
18211 +               return -EINVAL;
18212 +       log = &vxi->cvirt.syslog;
18213 +
18214 +       switch (type) {
18215 +       case 0:         /* Close log */
18216 +       case 1:         /* Open log */
18217 +               break;
18218 +       case 2:         /* Read from log */
18219 +               error = wait_event_interruptible(log->log_wait,
18220 +                       (log->log_start - log->log_end));
18221 +               if (error)
18222 +                       break;
18223 +               spin_lock_irq(&log->logbuf_lock);
18224 +               spin_unlock_irq(&log->logbuf_lock);
18225 +               break;
18226 +       case 4:         /* Read/clear last kernel messages */
18227 +               do_clear = 1;
18228 +               /* fall through */
18229 +       case 3:         /* Read last kernel messages */
18230 +               return 0;
18231 +
18232 +       case 5:         /* Clear ring buffer */
18233 +               return 0;
18234 +
18235 +       case 6:         /* Disable logging to console */
18236 +       case 7:         /* Enable logging to console */
18237 +       case 8:         /* Set level of messages printed to console */
18238 +               break;
18239 +
18240 +       case 9:         /* Number of chars in the log buffer */
18241 +               return 0;
18242 +       case 10:        /* Size of the log buffer */
18243 +               return 0;
18244 +       default:
18245 +               error = -EINVAL;
18246 +               break;
18247 +       }
18248 +       return error;
18249 +}
18250 +
18251 +
18252 +/* virtual host info names */
18253 +
18254 +static char *vx_vhi_name(struct vx_info *vxi, int id)
18255 +{
18256 +       struct nsproxy *nsproxy;
18257 +       struct uts_namespace *uts;
18258 +
18259 +       if (id == VHIN_CONTEXT)
18260 +               return vxi->vx_name;
18261 +
18262 +       nsproxy = vxi->vx_nsproxy[0];
18263 +       if (!nsproxy)
18264 +               return NULL;
18265 +
18266 +       uts = nsproxy->uts_ns;
18267 +       if (!uts)
18268 +               return NULL;
18269 +
18270 +       switch (id) {
18271 +       case VHIN_SYSNAME:
18272 +               return uts->name.sysname;
18273 +       case VHIN_NODENAME:
18274 +               return uts->name.nodename;
18275 +       case VHIN_RELEASE:
18276 +               return uts->name.release;
18277 +       case VHIN_VERSION:
18278 +               return uts->name.version;
18279 +       case VHIN_MACHINE:
18280 +               return uts->name.machine;
18281 +       case VHIN_DOMAINNAME:
18282 +               return uts->name.domainname;
18283 +       default:
18284 +               return NULL;
18285 +       }
18286 +       return NULL;
18287 +}
18288 +
18289 +int vc_set_vhi_name(struct vx_info *vxi, void __user *data)
18290 +{
18291 +       struct vcmd_vhi_name_v0 vc_data;
18292 +       char *name;
18293 +
18294 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18295 +               return -EFAULT;
18296 +
18297 +       name = vx_vhi_name(vxi, vc_data.field);
18298 +       if (!name)
18299 +               return -EINVAL;
18300 +
18301 +       memcpy(name, vc_data.name, 65);
18302 +       return 0;
18303 +}
18304 +
18305 +int vc_get_vhi_name(struct vx_info *vxi, void __user *data)
18306 +{
18307 +       struct vcmd_vhi_name_v0 vc_data;
18308 +       char *name;
18309 +
18310 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18311 +               return -EFAULT;
18312 +
18313 +       name = vx_vhi_name(vxi, vc_data.field);
18314 +       if (!name)
18315 +               return -EINVAL;
18316 +
18317 +       memcpy(vc_data.name, name, 65);
18318 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
18319 +               return -EFAULT;
18320 +       return 0;
18321 +}
18322 +
18323 +
18324 +int vc_virt_stat(struct vx_info *vxi, void __user *data)
18325 +{
18326 +       struct vcmd_virt_stat_v0 vc_data;
18327 +       struct _vx_cvirt *cvirt = &vxi->cvirt;
18328 +       struct timespec uptime;
18329 +
18330 +       do_posix_clock_monotonic_gettime(&uptime);
18331 +       set_normalized_timespec(&uptime,
18332 +               uptime.tv_sec - cvirt->bias_uptime.tv_sec,
18333 +               uptime.tv_nsec - cvirt->bias_uptime.tv_nsec);
18334 +
18335 +       vc_data.offset = timeval_to_ns(&cvirt->bias_tv);
18336 +       vc_data.uptime = timespec_to_ns(&uptime);
18337 +       vc_data.nr_threads = atomic_read(&cvirt->nr_threads);
18338 +       vc_data.nr_running = atomic_read(&cvirt->nr_running);
18339 +       vc_data.nr_uninterruptible = atomic_read(&cvirt->nr_uninterruptible);
18340 +       vc_data.nr_onhold = atomic_read(&cvirt->nr_onhold);
18341 +       vc_data.nr_forks = atomic_read(&cvirt->total_forks);
18342 +       vc_data.load[0] = cvirt->load[0];
18343 +       vc_data.load[1] = cvirt->load[1];
18344 +       vc_data.load[2] = cvirt->load[2];
18345 +
18346 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
18347 +               return -EFAULT;
18348 +       return 0;
18349 +}
18350 +
18351 +
18352 +#ifdef CONFIG_VSERVER_VTIME
18353 +
18354 +/* virtualized time base */
18355 +
18356 +void vx_gettimeofday(struct timeval *tv)
18357 +{
18358 +       do_gettimeofday(tv);
18359 +       if (!vx_flags(VXF_VIRT_TIME, 0))
18360 +               return;
18361 +
18362 +       tv->tv_sec += current->vx_info->cvirt.bias_tv.tv_sec;
18363 +       tv->tv_usec += current->vx_info->cvirt.bias_tv.tv_usec;
18364 +
18365 +       if (tv->tv_usec >= USEC_PER_SEC) {
18366 +               tv->tv_sec++;
18367 +               tv->tv_usec -= USEC_PER_SEC;
18368 +       } else if (tv->tv_usec < 0) {
18369 +               tv->tv_sec--;
18370 +               tv->tv_usec += USEC_PER_SEC;
18371 +       }
18372 +}
18373 +
18374 +int vx_settimeofday(struct timespec *ts)
18375 +{
18376 +       struct timeval tv;
18377 +
18378 +       if (!vx_flags(VXF_VIRT_TIME, 0))
18379 +               return do_settimeofday(ts);
18380 +
18381 +       do_gettimeofday(&tv);
18382 +       current->vx_info->cvirt.bias_tv.tv_sec =
18383 +               ts->tv_sec - tv.tv_sec;
18384 +       current->vx_info->cvirt.bias_tv.tv_usec =
18385 +               (ts->tv_nsec/NSEC_PER_USEC) - tv.tv_usec;
18386 +       return 0;
18387 +}
18388 +
18389 +#endif
18390 +
18391 diff -NurpP --minimal linux-2.6.29/kernel/vserver/cvirt_init.h linux-2.6.29-vs2.3.0.36.9-pre3/kernel/vserver/cvirt_init.h
18392 --- linux-2.6.29/kernel/vserver/cvirt_init.h    1970-01-01 01:00:00.000000000 +0100
18393 +++ linux-2.6.29-vs2.3.0.36.9-pre3/kernel/vserver/cvirt_init.h  2009-02-22 22:54:26.000000000 +0100
18394 @@ -0,0 +1,69 @@
18395 +
18396 +
18397 +extern uint64_t vx_idle_jiffies(void);
18398 +
18399 +static inline void vx_info_init_cvirt(struct _vx_cvirt *cvirt)
18400 +{
18401 +       uint64_t idle_jiffies = vx_idle_jiffies();
18402 +       uint64_t nsuptime;
18403 +
18404 +       do_posix_clock_monotonic_gettime(&cvirt->bias_uptime);
18405 +       nsuptime = (unsigned long long)cvirt->bias_uptime.tv_sec
18406 +               * NSEC_PER_SEC + cvirt->bias_uptime.tv_nsec;
18407 +       cvirt->bias_clock = nsec_to_clock_t(nsuptime);
18408 +       cvirt->bias_tv.tv_sec = 0;
18409 +       cvirt->bias_tv.tv_usec = 0;
18410 +
18411 +       jiffies_to_timespec(idle_jiffies, &cvirt->bias_idle);
18412 +       atomic_set(&cvirt->nr_threads, 0);
18413 +       atomic_set(&cvirt->nr_running, 0);
18414 +       atomic_set(&cvirt->nr_uninterruptible, 0);
18415 +       atomic_set(&cvirt->nr_onhold, 0);
18416 +
18417 +       spin_lock_init(&cvirt->load_lock);
18418 +       cvirt->load_last = jiffies;
18419 +       atomic_set(&cvirt->load_updates, 0);
18420 +       cvirt->load[0] = 0;
18421 +       cvirt->load[1] = 0;
18422 +       cvirt->load[2] = 0;
18423 +       atomic_set(&cvirt->total_forks, 0);
18424 +
18425 +       spin_lock_init(&cvirt->syslog.logbuf_lock);
18426 +       init_waitqueue_head(&cvirt->syslog.log_wait);
18427 +       cvirt->syslog.log_start = 0;
18428 +       cvirt->syslog.log_end = 0;
18429 +       cvirt->syslog.con_start = 0;
18430 +       cvirt->syslog.logged_chars = 0;
18431 +}
18432 +
18433 +static inline
18434 +void vx_info_init_cvirt_pc(struct _vx_cvirt_pc *cvirt_pc, int cpu)
18435 +{
18436 +       // cvirt_pc->cpustat = { 0 };
18437 +}
18438 +
18439 +static inline void vx_info_exit_cvirt(struct _vx_cvirt *cvirt)
18440 +{
18441 +       int value;
18442 +
18443 +       vxwprintk_xid((value = atomic_read(&cvirt->nr_threads)),
18444 +               "!!! cvirt: %p[nr_threads] = %d on exit.",
18445 +               cvirt, value);
18446 +       vxwprintk_xid((value = atomic_read(&cvirt->nr_running)),
18447 +               "!!! cvirt: %p[nr_running] = %d on exit.",
18448 +               cvirt, value);
18449 +       vxwprintk_xid((value = atomic_read(&cvirt->nr_uninterruptible)),
18450 +               "!!! cvirt: %p[nr_uninterruptible] = %d on exit.",
18451 +               cvirt, value);
18452 +       vxwprintk_xid((value = atomic_read(&cvirt->nr_onhold)),
18453 +               "!!! cvirt: %p[nr_onhold] = %d on exit.",
18454 +               cvirt, value);
18455 +       return;
18456 +}
18457 +
18458 +static inline
18459 +void vx_info_exit_cvirt_pc(struct _vx_cvirt_pc *cvirt_pc, int cpu)
18460 +{
18461 +       return;
18462 +}
18463 +
18464 diff -NurpP --minimal linux-2.6.29/kernel/vserver/cvirt_proc.h linux-2.6.29-vs2.3.0.36.9-pre3/kernel/vserver/cvirt_proc.h
18465 --- linux-2.6.29/kernel/vserver/cvirt_proc.h    1970-01-01 01:00:00.000000000 +0100
18466 +++ linux-2.6.29-vs2.3.0.36.9-pre3/kernel/vserver/cvirt_proc.h  2009-02-22 22:54:26.000000000 +0100
18467 @@ -0,0 +1,135 @@
18468 +#ifndef _VX_CVIRT_PROC_H
18469 +#define _VX_CVIRT_PROC_H
18470 +
18471 +#include <linux/nsproxy.h>
18472 +#include <linux/mnt_namespace.h>
18473 +#include <linux/ipc_namespace.h>
18474 +#include <linux/utsname.h>
18475 +#include <linux/ipc.h>
18476 +
18477 +
18478 +static inline
18479 +int vx_info_proc_nsproxy(struct nsproxy *nsproxy, char *buffer)
18480 +{
18481 +       struct mnt_namespace *ns;
18482 +       struct uts_namespace *uts;
18483 +       struct ipc_namespace *ipc;
18484 +       struct path path;
18485 +       char *pstr, *root;
18486 +       int length = 0;
18487 +
18488 +       if (!nsproxy)
18489 +               goto out;
18490 +
18491 +       length += sprintf(buffer + length,
18492 +               "NSProxy:\t%p [%p,%p,%p]\n",
18493 +               nsproxy, nsproxy->mnt_ns,
18494 +               nsproxy->uts_ns, nsproxy->ipc_ns);
18495 +
18496 +       ns = nsproxy->mnt_ns;
18497 +       if (!ns)
18498 +               goto skip_ns;
18499 +
18500 +       pstr = kmalloc(PATH_MAX, GFP_KERNEL);
18501 +       if (!pstr)
18502 +               goto skip_ns;
18503 +
18504 +       path.mnt = ns->root;
18505 +       path.dentry = ns->root->mnt_root;
18506 +       root = d_path(&path, pstr, PATH_MAX - 2);
18507 +       length += sprintf(buffer + length,
18508 +               "Namespace:\t%p [#%u]\n"
18509 +               "RootPath:\t%s\n",
18510 +               ns, atomic_read(&ns->count),
18511 +               root);
18512 +       kfree(pstr);
18513 +skip_ns:
18514 +
18515 +       uts = nsproxy->uts_ns;
18516 +       if (!uts)
18517 +               goto skip_uts;
18518 +
18519 +       length += sprintf(buffer + length,
18520 +               "SysName:\t%.*s\n"
18521 +               "NodeName:\t%.*s\n"
18522 +               "Release:\t%.*s\n"
18523 +               "Version:\t%.*s\n"
18524 +               "Machine:\t%.*s\n"
18525 +               "DomainName:\t%.*s\n",
18526 +               __NEW_UTS_LEN, uts->name.sysname,
18527 +               __NEW_UTS_LEN, uts->name.nodename,
18528 +               __NEW_UTS_LEN, uts->name.release,
18529 +               __NEW_UTS_LEN, uts->name.version,
18530 +               __NEW_UTS_LEN, uts->name.machine,
18531 +               __NEW_UTS_LEN, uts->name.domainname);
18532 +skip_uts:
18533 +
18534 +       ipc = nsproxy->ipc_ns;
18535 +       if (!ipc)
18536 +               goto skip_ipc;
18537 +
18538 +       length += sprintf(buffer + length,
18539 +               "SEMS:\t\t%d %d %d %d  %d\n"
18540 +               "MSG:\t\t%d %d %d\n"
18541 +               "SHM:\t\t%lu %lu  %d %d\n",
18542 +               ipc->sem_ctls[0], ipc->sem_ctls[1],
18543 +               ipc->sem_ctls[2], ipc->sem_ctls[3],
18544 +               ipc->used_sems,
18545 +               ipc->msg_ctlmax, ipc->msg_ctlmnb, ipc->msg_ctlmni,
18546 +               (unsigned long)ipc->shm_ctlmax,
18547 +               (unsigned long)ipc->shm_ctlall,
18548 +               ipc->shm_ctlmni, ipc->shm_tot);
18549 +skip_ipc:
18550 +out:
18551 +       return length;
18552 +}
18553 +
18554 +
18555 +#include <linux/sched.h>
18556 +
18557 +#define LOAD_INT(x) ((x) >> FSHIFT)
18558 +#define LOAD_FRAC(x) LOAD_INT(((x) & (FIXED_1 - 1)) * 100)
18559 +
18560 +static inline
18561 +int vx_info_proc_cvirt(struct _vx_cvirt *cvirt, char *buffer)
18562 +{
18563 +       int length = 0;
18564 +       int a, b, c;
18565 +
18566 +       length += sprintf(buffer + length,
18567 +               "BiasUptime:\t%lu.%02lu\n",
18568 +               (unsigned long)cvirt->bias_uptime.tv_sec,
18569 +               (cvirt->bias_uptime.tv_nsec / (NSEC_PER_SEC / 100)));
18570 +
18571 +       a = cvirt->load[0] + (FIXED_1 / 200);
18572 +       b = cvirt->load[1] + (FIXED_1 / 200);
18573 +       c = cvirt->load[2] + (FIXED_1 / 200);
18574 +       length += sprintf(buffer + length,
18575 +               "nr_threads:\t%d\n"
18576 +               "nr_running:\t%d\n"
18577 +               "nr_unintr:\t%d\n"
18578 +               "nr_onhold:\t%d\n"
18579 +               "load_updates:\t%d\n"
18580 +               "loadavg:\t%d.%02d %d.%02d %d.%02d\n"
18581 +               "total_forks:\t%d\n",
18582 +               atomic_read(&cvirt->nr_threads),
18583 +               atomic_read(&cvirt->nr_running),
18584 +               atomic_read(&cvirt->nr_uninterruptible),
18585 +               atomic_read(&cvirt->nr_onhold),
18586 +               atomic_read(&cvirt->load_updates),
18587 +               LOAD_INT(a), LOAD_FRAC(a),
18588 +               LOAD_INT(b), LOAD_FRAC(b),
18589 +               LOAD_INT(c), LOAD_FRAC(c),
18590 +               atomic_read(&cvirt->total_forks));
18591 +       return length;
18592 +}
18593 +
18594 +static inline
18595 +int vx_info_proc_cvirt_pc(struct _vx_cvirt_pc *cvirt_pc,
18596 +       char *buffer, int cpu)
18597 +{
18598 +       int length = 0;
18599 +       return length;
18600 +}
18601 +
18602 +#endif /* _VX_CVIRT_PROC_H */
18603 diff -NurpP --minimal linux-2.6.29/kernel/vserver/debug.c linux-2.6.29-vs2.3.0.36.9-pre3/kernel/vserver/debug.c
18604 --- linux-2.6.29/kernel/vserver/debug.c 1970-01-01 01:00:00.000000000 +0100
18605 +++ linux-2.6.29-vs2.3.0.36.9-pre3/kernel/vserver/debug.c       2009-02-22 22:54:26.000000000 +0100
18606 @@ -0,0 +1,32 @@
18607 +/*
18608 + *  kernel/vserver/debug.c
18609 + *
18610 + *  Copyright (C) 2005-2007 Herbert Pötzl
18611 + *
18612 + *  V0.01  vx_info dump support
18613 + *
18614 + */
18615 +
18616 +#include <linux/module.h>
18617 +
18618 +#include <linux/vserver/context.h>
18619 +
18620 +
18621 +void   dump_vx_info(struct vx_info *vxi, int level)
18622 +{
18623 +       printk("vx_info %p[#%d, %d.%d, %4x]\n", vxi, vxi->vx_id,
18624 +               atomic_read(&vxi->vx_usecnt),
18625 +               atomic_read(&vxi->vx_tasks),
18626 +               vxi->vx_state);
18627 +       if (level > 0) {
18628 +               __dump_vx_limit(&vxi->limit);
18629 +               __dump_vx_sched(&vxi->sched);
18630 +               __dump_vx_cvirt(&vxi->cvirt);
18631 +               __dump_vx_cacct(&vxi->cacct);
18632 +       }
18633 +       printk("---\n");
18634 +}
18635 +
18636 +
18637 +EXPORT_SYMBOL_GPL(dump_vx_info);
18638 +
18639 diff -NurpP --minimal linux-2.6.29/kernel/vserver/device.c linux-2.6.29-vs2.3.0.36.9-pre3/kernel/vserver/device.c
18640 --- linux-2.6.29/kernel/vserver/device.c        1970-01-01 01:00:00.000000000 +0100
18641 +++ linux-2.6.29-vs2.3.0.36.9-pre3/kernel/vserver/device.c      2009-02-22 22:54:26.000000000 +0100
18642 @@ -0,0 +1,443 @@
18643 +/*
18644 + *  linux/kernel/vserver/device.c
18645 + *
18646 + *  Linux-VServer: Device Support
18647 + *
18648 + *  Copyright (C) 2006  Herbert Pötzl
18649 + *  Copyright (C) 2007  Daniel Hokka Zakrisson
18650 + *
18651 + *  V0.01  device mapping basics
18652 + *  V0.02  added defaults
18653 + *
18654 + */
18655 +
18656 +#include <linux/slab.h>
18657 +#include <linux/rcupdate.h>
18658 +#include <linux/fs.h>
18659 +#include <linux/namei.h>
18660 +#include <linux/hash.h>
18661 +
18662 +#include <asm/errno.h>
18663 +#include <asm/uaccess.h>
18664 +#include <linux/vserver/base.h>
18665 +#include <linux/vserver/debug.h>
18666 +#include <linux/vserver/context.h>
18667 +#include <linux/vserver/device.h>
18668 +#include <linux/vserver/device_cmd.h>
18669 +
18670 +
18671 +#define DMAP_HASH_BITS 4
18672 +
18673 +
18674 +struct vs_mapping {
18675 +       union {
18676 +               struct hlist_node hlist;
18677 +               struct list_head list;
18678 +       } u;
18679 +#define dm_hlist       u.hlist
18680 +#define dm_list                u.list
18681 +       xid_t xid;
18682 +       dev_t device;
18683 +       struct vx_dmap_target target;
18684 +};
18685 +
18686 +
18687 +static struct hlist_head dmap_main_hash[1 << DMAP_HASH_BITS];
18688 +
18689 +static spinlock_t dmap_main_hash_lock = SPIN_LOCK_UNLOCKED;
18690 +
18691 +static struct vx_dmap_target dmap_defaults[2] = {
18692 +       { .flags = DATTR_OPEN },
18693 +       { .flags = DATTR_OPEN },
18694 +};
18695 +
18696 +
18697 +struct kmem_cache *dmap_cachep __read_mostly;
18698 +
18699 +int __init dmap_cache_init(void)
18700 +{
18701 +       dmap_cachep = kmem_cache_create("dmap_cache",
18702 +               sizeof(struct vs_mapping), 0,
18703 +               SLAB_HWCACHE_ALIGN|SLAB_PANIC, NULL);
18704 +       return 0;
18705 +}
18706 +
18707 +__initcall(dmap_cache_init);
18708 +
18709 +
18710 +static inline unsigned int __hashval(dev_t dev, int bits)
18711 +{
18712 +       return hash_long((unsigned long)dev, bits);
18713 +}
18714 +
18715 +
18716 +/*     __hash_mapping()
18717 + *     add the mapping to the hash table
18718 + */
18719 +static inline void __hash_mapping(struct vx_info *vxi, struct vs_mapping *vdm)
18720 +{
18721 +       spinlock_t *hash_lock = &dmap_main_hash_lock;
18722 +       struct hlist_head *head, *hash = dmap_main_hash;
18723 +       int device = vdm->device;
18724 +
18725 +       spin_lock(hash_lock);
18726 +       vxdprintk(VXD_CBIT(misc, 8), "__hash_mapping: %p[#%d] %08x:%08x",
18727 +               vxi, vxi ? vxi->vx_id : 0, device, vdm->target.target);
18728 +
18729 +       head = &hash[__hashval(device, DMAP_HASH_BITS)];
18730 +       hlist_add_head(&vdm->dm_hlist, head);
18731 +       spin_unlock(hash_lock);
18732 +}
18733 +
18734 +
18735 +static inline int __mode_to_default(umode_t mode)
18736 +{
18737 +       switch (mode) {
18738 +       case S_IFBLK:
18739 +               return 0;
18740 +       case S_IFCHR:
18741 +               return 1;
18742 +       default:
18743 +               BUG();
18744 +       }
18745 +}
18746 +
18747 +
18748 +/*     __set_default()
18749 + *     set a default
18750 + */
18751 +static inline void __set_default(struct vx_info *vxi, umode_t mode,
18752 +       struct vx_dmap_target *vdmt)
18753 +{
18754 +       spinlock_t *hash_lock = &dmap_main_hash_lock;
18755 +       spin_lock(hash_lock);
18756 +
18757 +       if (vxi)
18758 +               vxi->dmap.targets[__mode_to_default(mode)] = *vdmt;
18759 +       else
18760 +               dmap_defaults[__mode_to_default(mode)] = *vdmt;
18761 +
18762 +
18763 +       spin_unlock(hash_lock);
18764 +
18765 +       vxdprintk(VXD_CBIT(misc, 8), "__set_default: %p[#%u] %08x %04x",
18766 +                 vxi, vxi ? vxi->vx_id : 0, vdmt->target, vdmt->flags);
18767 +}
18768 +
18769 +
18770 +/*     __remove_default()
18771 + *     remove a default
18772 + */
18773 +static inline int __remove_default(struct vx_info *vxi, umode_t mode)
18774 +{
18775 +       spinlock_t *hash_lock = &dmap_main_hash_lock;
18776 +       spin_lock(hash_lock);
18777 +
18778 +       if (vxi)
18779 +               vxi->dmap.targets[__mode_to_default(mode)].flags = 0;
18780 +       else    /* remove == reset */
18781 +               dmap_defaults[__mode_to_default(mode)].flags = DATTR_OPEN | mode;
18782 +
18783 +       spin_unlock(hash_lock);
18784 +       return 0;
18785 +}
18786 +
18787 +
18788 +/*     __find_mapping()
18789 + *     find a mapping in the hash table
18790 + *
18791 + *     caller must hold hash_lock
18792 + */
18793 +static inline int __find_mapping(xid_t xid, dev_t device, umode_t mode,
18794 +       struct vs_mapping **local, struct vs_mapping **global)
18795 +{
18796 +       struct hlist_head *hash = dmap_main_hash;
18797 +       struct hlist_head *head = &hash[__hashval(device, DMAP_HASH_BITS)];
18798 +       struct hlist_node *pos;
18799 +       struct vs_mapping *vdm;
18800 +
18801 +       *local = NULL;
18802 +       if (global)
18803 +               *global = NULL;
18804 +
18805 +       hlist_for_each(pos, head) {
18806 +               vdm = hlist_entry(pos, struct vs_mapping, dm_hlist);
18807 +
18808 +               if ((vdm->device == device) &&
18809 +                       !((vdm->target.flags ^ mode) & S_IFMT)) {
18810 +                       if (vdm->xid == xid) {
18811 +                               *local = vdm;
18812 +                               return 1;
18813 +                       } else if (global && vdm->xid == 0)
18814 +                               *global = vdm;
18815 +               }
18816 +       }
18817 +
18818 +       if (global && *global)
18819 +               return 0;
18820 +       else
18821 +               return -ENOENT;
18822 +}
18823 +
18824 +
18825 +/*     __lookup_mapping()
18826 + *     find a mapping and store the result in target and flags
18827 + */
18828 +static inline int __lookup_mapping(struct vx_info *vxi,
18829 +       dev_t device, dev_t *target, int *flags, umode_t mode)
18830 +{
18831 +       spinlock_t *hash_lock = &dmap_main_hash_lock;
18832 +       struct vs_mapping *vdm, *global;
18833 +       struct vx_dmap_target *vdmt;
18834 +       int ret = 0;
18835 +       xid_t xid = vxi->vx_id;
18836 +       int index;
18837 +
18838 +       spin_lock(hash_lock);
18839 +       if (__find_mapping(xid, device, mode, &vdm, &global) > 0) {
18840 +               ret = 1;
18841 +               vdmt = &vdm->target;
18842 +               goto found;
18843 +       }
18844 +
18845 +       index = __mode_to_default(mode);
18846 +       if (vxi && vxi->dmap.targets[index].flags) {
18847 +               ret = 2;
18848 +               vdmt = &vxi->dmap.targets[index];
18849 +       } else if (global) {
18850 +               ret = 3;
18851 +               vdmt = &global->target;
18852 +               goto found;
18853 +       } else {
18854 +               ret = 4;
18855 +               vdmt = &dmap_defaults[index];
18856 +       }
18857 +
18858 +found:
18859 +       if (target && (vdmt->flags & DATTR_REMAP))
18860 +               *target = vdmt->target;
18861 +       else if (target)
18862 +               *target = device;
18863 +       if (flags)
18864 +               *flags = vdmt->flags;
18865 +
18866 +       spin_unlock(hash_lock);
18867 +
18868 +       return ret;
18869 +}
18870 +
18871 +
18872 +/*     __remove_mapping()
18873 + *     remove a mapping from the hash table
18874 + */
18875 +static inline int __remove_mapping(struct vx_info *vxi, dev_t device,
18876 +       umode_t mode)
18877 +{
18878 +       spinlock_t *hash_lock = &dmap_main_hash_lock;
18879 +       struct vs_mapping *vdm = NULL;
18880 +       int ret = 0;
18881 +
18882 +       spin_lock(hash_lock);
18883 +
18884 +       ret = __find_mapping((vxi ? vxi->vx_id : 0), device, mode, &vdm,
18885 +               NULL);
18886 +       vxdprintk(VXD_CBIT(misc, 8), "__remove_mapping: %p[#%d] %08x %04x",
18887 +               vxi, vxi ? vxi->vx_id : 0, device, mode);
18888 +       if (ret < 0)
18889 +               goto out;
18890 +       hlist_del(&vdm->dm_hlist);
18891 +
18892 +out:
18893 +       spin_unlock(hash_lock);
18894 +       if (vdm)
18895 +               kmem_cache_free(dmap_cachep, vdm);
18896 +       return ret;
18897 +}
18898 +
18899 +
18900 +
18901 +int vs_map_device(struct vx_info *vxi,
18902 +       dev_t device, dev_t *target, umode_t mode)
18903 +{
18904 +       int ret, flags = DATTR_MASK;
18905 +
18906 +       if (!vxi) {
18907 +               if (target)
18908 +                       *target = device;
18909 +               goto out;
18910 +       }
18911 +       ret = __lookup_mapping(vxi, device, target, &flags, mode);
18912 +       vxdprintk(VXD_CBIT(misc, 8), "vs_map_device: %08x target: %08x flags: %04x mode: %04x mapped=%d",
18913 +               device, target ? *target : 0, flags, mode, ret);
18914 +out:
18915 +       return (flags & DATTR_MASK);
18916 +}
18917 +
18918 +
18919 +
18920 +static int do_set_mapping(struct vx_info *vxi,
18921 +       dev_t device, dev_t target, int flags, umode_t mode)
18922 +{
18923 +       if (device) {
18924 +               struct vs_mapping *new;
18925 +
18926 +               new = kmem_cache_alloc(dmap_cachep, GFP_KERNEL);
18927 +               if (!new)
18928 +                       return -ENOMEM;
18929 +
18930 +               INIT_HLIST_NODE(&new->dm_hlist);
18931 +               new->device = device;
18932 +               new->target.target = target;
18933 +               new->target.flags = flags | mode;
18934 +               new->xid = (vxi ? vxi->vx_id : 0);
18935 +
18936 +               vxdprintk(VXD_CBIT(misc, 8), "do_set_mapping: %08x target: %08x flags: %04x", device, target, flags);
18937 +               __hash_mapping(vxi, new);
18938 +       } else {
18939 +               struct vx_dmap_target new = {
18940 +                       .target = target,
18941 +                       .flags = flags | mode,
18942 +               };
18943 +               __set_default(vxi, mode, &new);
18944 +       }
18945 +       return 0;
18946 +}
18947 +
18948 +
18949 +static int do_unset_mapping(struct vx_info *vxi,
18950 +       dev_t device, dev_t target, int flags, umode_t mode)
18951 +{
18952 +       int ret = -EINVAL;
18953 +
18954 +       if (device) {
18955 +               ret = __remove_mapping(vxi, device, mode);
18956 +               if (ret < 0)
18957 +                       goto out;
18958 +       } else {
18959 +               ret = __remove_default(vxi, mode);
18960 +               if (ret < 0)
18961 +                       goto out;
18962 +       }
18963 +
18964 +out:
18965 +       return ret;
18966 +}
18967 +
18968 +
18969 +static inline int __user_device(const char __user *name, dev_t *dev,
18970 +       umode_t *mode)
18971 +{
18972 +       struct nameidata nd;
18973 +       int ret;
18974 +
18975 +       if (!name) {
18976 +               *dev = 0;
18977 +               return 0;
18978 +       }
18979 +       ret = user_lpath(name, &nd.path);
18980 +       if (ret)
18981 +               return ret;
18982 +       if (nd.path.dentry->d_inode) {
18983 +               *dev = nd.path.dentry->d_inode->i_rdev;
18984 +               *mode = nd.path.dentry->d_inode->i_mode;
18985 +       }
18986 +       path_put(&nd.path);
18987 +       return 0;
18988 +}
18989 +
18990 +static inline int __mapping_mode(dev_t device, dev_t target,
18991 +       umode_t device_mode, umode_t target_mode, umode_t *mode)
18992 +{
18993 +       if (device)
18994 +               *mode = device_mode & S_IFMT;
18995 +       else if (target)
18996 +               *mode = target_mode & S_IFMT;
18997 +       else
18998 +               return -EINVAL;
18999 +
19000 +       /* if both given, device and target mode have to match */
19001 +       if (device && target &&
19002 +               ((device_mode ^ target_mode) & S_IFMT))
19003 +               return -EINVAL;
19004 +       return 0;
19005 +}
19006 +
19007 +
19008 +static inline int do_mapping(struct vx_info *vxi, const char __user *device_path,
19009 +       const char __user *target_path, int flags, int set)
19010 +{
19011 +       dev_t device = ~0, target = ~0;
19012 +       umode_t device_mode = 0, target_mode = 0, mode;
19013 +       int ret;
19014 +
19015 +       ret = __user_device(device_path, &device, &device_mode);
19016 +       if (ret)
19017 +               return ret;
19018 +       ret = __user_device(target_path, &target, &target_mode);
19019 +       if (ret)
19020 +               return ret;
19021 +
19022 +       ret = __mapping_mode(device, target,
19023 +               device_mode, target_mode, &mode);
19024 +       if (ret)
19025 +               return ret;
19026 +
19027 +       if (set)
19028 +               return do_set_mapping(vxi, device, target,
19029 +                       flags, mode);
19030 +       else
19031 +               return do_unset_mapping(vxi, device, target,
19032 +                       flags, mode);
19033 +}
19034 +
19035 +
19036 +int vc_set_mapping(struct vx_info *vxi, void __user *data)
19037 +{
19038 +       struct vcmd_set_mapping_v0 vc_data;
19039 +
19040 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19041 +               return -EFAULT;
19042 +
19043 +       return do_mapping(vxi, vc_data.device, vc_data.target,
19044 +               vc_data.flags, 1);
19045 +}
19046 +
19047 +int vc_unset_mapping(struct vx_info *vxi, void __user *data)
19048 +{
19049 +       struct vcmd_set_mapping_v0 vc_data;
19050 +
19051 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19052 +               return -EFAULT;
19053 +
19054 +       return do_mapping(vxi, vc_data.device, vc_data.target,
19055 +               vc_data.flags, 0);
19056 +}
19057 +
19058 +
19059 +#ifdef CONFIG_COMPAT
19060 +
19061 +int vc_set_mapping_x32(struct vx_info *vxi, void __user *data)
19062 +{
19063 +       struct vcmd_set_mapping_v0_x32 vc_data;
19064 +
19065 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19066 +               return -EFAULT;
19067 +
19068 +       return do_mapping(vxi, compat_ptr(vc_data.device_ptr),
19069 +               compat_ptr(vc_data.target_ptr), vc_data.flags, 1);
19070 +}
19071 +
19072 +int vc_unset_mapping_x32(struct vx_info *vxi, void __user *data)
19073 +{
19074 +       struct vcmd_set_mapping_v0_x32 vc_data;
19075 +
19076 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19077 +               return -EFAULT;
19078 +
19079 +       return do_mapping(vxi, compat_ptr(vc_data.device_ptr),
19080 +               compat_ptr(vc_data.target_ptr), vc_data.flags, 0);
19081 +}
19082 +
19083 +#endif /* CONFIG_COMPAT */
19084 +
19085 +
19086 diff -NurpP --minimal linux-2.6.29/kernel/vserver/dlimit.c linux-2.6.29-vs2.3.0.36.9-pre3/kernel/vserver/dlimit.c
19087 --- linux-2.6.29/kernel/vserver/dlimit.c        1970-01-01 01:00:00.000000000 +0100
19088 +++ linux-2.6.29-vs2.3.0.36.9-pre3/kernel/vserver/dlimit.c      2009-02-22 22:54:26.000000000 +0100
19089 @@ -0,0 +1,522 @@
19090 +/*
19091 + *  linux/kernel/vserver/dlimit.c
19092 + *
19093 + *  Virtual Server: Context Disk Limits
19094 + *
19095 + *  Copyright (C) 2004-2007  Herbert Pötzl
19096 + *
19097 + *  V0.01  initial version
19098 + *  V0.02  compat32 splitup
19099 + *
19100 + */
19101 +
19102 +#include <linux/statfs.h>
19103 +#include <linux/sched.h>
19104 +#include <linux/namei.h>
19105 +#include <linux/vs_tag.h>
19106 +#include <linux/vs_dlimit.h>
19107 +#include <linux/vserver/dlimit_cmd.h>
19108 +
19109 +#include <asm/uaccess.h>
19110 +
19111 +/*     __alloc_dl_info()
19112 +
19113 +       * allocate an initialized dl_info struct
19114 +       * doesn't make it visible (hash)                        */
19115 +
19116 +static struct dl_info *__alloc_dl_info(struct super_block *sb, tag_t tag)
19117 +{
19118 +       struct dl_info *new = NULL;
19119 +
19120 +       vxdprintk(VXD_CBIT(dlim, 5),
19121 +               "alloc_dl_info(%p,%d)*", sb, tag);
19122 +
19123 +       /* would this benefit from a slab cache? */
19124 +       new = kmalloc(sizeof(struct dl_info), GFP_KERNEL);
19125 +       if (!new)
19126 +               return 0;
19127 +
19128 +       memset(new, 0, sizeof(struct dl_info));
19129 +       new->dl_tag = tag;
19130 +       new->dl_sb = sb;
19131 +       INIT_RCU_HEAD(&new->dl_rcu);
19132 +       INIT_HLIST_NODE(&new->dl_hlist);
19133 +       spin_lock_init(&new->dl_lock);
19134 +       atomic_set(&new->dl_refcnt, 0);
19135 +       atomic_set(&new->dl_usecnt, 0);
19136 +
19137 +       /* rest of init goes here */
19138 +
19139 +       vxdprintk(VXD_CBIT(dlim, 4),
19140 +               "alloc_dl_info(%p,%d) = %p", sb, tag, new);
19141 +       return new;
19142 +}
19143 +
19144 +/*     __dealloc_dl_info()
19145 +
19146 +       * final disposal of dl_info                             */
19147 +
19148 +static void __dealloc_dl_info(struct dl_info *dli)
19149 +{
19150 +       vxdprintk(VXD_CBIT(dlim, 4),
19151 +               "dealloc_dl_info(%p)", dli);
19152 +
19153 +       dli->dl_hlist.next = LIST_POISON1;
19154 +       dli->dl_tag = -1;
19155 +       dli->dl_sb = 0;
19156 +
19157 +       BUG_ON(atomic_read(&dli->dl_usecnt));
19158 +       BUG_ON(atomic_read(&dli->dl_refcnt));
19159 +
19160 +       kfree(dli);
19161 +}
19162 +
19163 +
19164 +/*     hash table for dl_info hash */
19165 +
19166 +#define DL_HASH_SIZE   13
19167 +
19168 +struct hlist_head dl_info_hash[DL_HASH_SIZE];
19169 +
19170 +static spinlock_t dl_info_hash_lock = SPIN_LOCK_UNLOCKED;
19171 +
19172 +
19173 +static inline unsigned int __hashval(struct super_block *sb, tag_t tag)
19174 +{
19175 +       return ((tag ^ (unsigned long)sb) % DL_HASH_SIZE);
19176 +}
19177 +
19178 +
19179 +
19180 +/*     __hash_dl_info()
19181 +
19182 +       * add the dli to the global hash table
19183 +       * requires the hash_lock to be held                     */
19184 +
19185 +static inline void __hash_dl_info(struct dl_info *dli)
19186 +{
19187 +       struct hlist_head *head;
19188 +
19189 +       vxdprintk(VXD_CBIT(dlim, 6),
19190 +               "__hash_dl_info: %p[#%d]", dli, dli->dl_tag);
19191 +       get_dl_info(dli);
19192 +       head = &dl_info_hash[__hashval(dli->dl_sb, dli->dl_tag)];
19193 +       hlist_add_head_rcu(&dli->dl_hlist, head);
19194 +}
19195 +
19196 +/*     __unhash_dl_info()
19197 +
19198 +       * remove the dli from the global hash table
19199 +       * requires the hash_lock to be held                     */
19200 +
19201 +static inline void __unhash_dl_info(struct dl_info *dli)
19202 +{
19203 +       vxdprintk(VXD_CBIT(dlim, 6),
19204 +               "__unhash_dl_info: %p[#%d]", dli, dli->dl_tag);
19205 +       hlist_del_rcu(&dli->dl_hlist);
19206 +       put_dl_info(dli);
19207 +}
19208 +
19209 +
19210 +/*     __lookup_dl_info()
19211 +
19212 +       * requires the rcu_read_lock()
19213 +       * doesn't increment the dl_refcnt                       */
19214 +
19215 +static inline struct dl_info *__lookup_dl_info(struct super_block *sb, tag_t tag)
19216 +{
19217 +       struct hlist_head *head = &dl_info_hash[__hashval(sb, tag)];
19218 +       struct hlist_node *pos;
19219 +       struct dl_info *dli;
19220 +
19221 +       hlist_for_each_entry_rcu(dli, pos, head, dl_hlist) {
19222 +
19223 +               if (dli->dl_tag == tag && dli->dl_sb == sb) {
19224 +                       return dli;
19225 +               }
19226 +       }
19227 +       return NULL;
19228 +}
19229 +
19230 +
19231 +struct dl_info *locate_dl_info(struct super_block *sb, tag_t tag)
19232 +{
19233 +       struct dl_info *dli;
19234 +
19235 +       rcu_read_lock();
19236 +       dli = get_dl_info(__lookup_dl_info(sb, tag));
19237 +       vxdprintk(VXD_CBIT(dlim, 7),
19238 +               "locate_dl_info(%p,#%d) = %p", sb, tag, dli);
19239 +       rcu_read_unlock();
19240 +       return dli;
19241 +}
19242 +
19243 +void rcu_free_dl_info(struct rcu_head *head)
19244 +{
19245 +       struct dl_info *dli = container_of(head, struct dl_info, dl_rcu);
19246 +       int usecnt, refcnt;
19247 +
19248 +       BUG_ON(!dli || !head);
19249 +
19250 +       usecnt = atomic_read(&dli->dl_usecnt);
19251 +       BUG_ON(usecnt < 0);
19252 +
19253 +       refcnt = atomic_read(&dli->dl_refcnt);
19254 +       BUG_ON(refcnt < 0);
19255 +
19256 +       vxdprintk(VXD_CBIT(dlim, 3),
19257 +               "rcu_free_dl_info(%p)", dli);
19258 +       if (!usecnt)
19259 +               __dealloc_dl_info(dli);
19260 +       else
19261 +               printk("!!! rcu didn't free\n");
19262 +}
19263 +
19264 +
19265 +
19266 +
19267 +static int do_addrem_dlimit(uint32_t id, const char __user *name,
19268 +       uint32_t flags, int add)
19269 +{
19270 +       struct path path;
19271 +       int ret;
19272 +
19273 +       ret = user_lpath(name, &path);
19274 +       if (!ret) {
19275 +               struct super_block *sb;
19276 +               struct dl_info *dli;
19277 +
19278 +               ret = -EINVAL;
19279 +               if (!path.dentry->d_inode)
19280 +                       goto out_release;
19281 +               if (!(sb = path.dentry->d_inode->i_sb))
19282 +                       goto out_release;
19283 +
19284 +               if (add) {
19285 +                       dli = __alloc_dl_info(sb, id);
19286 +                       spin_lock(&dl_info_hash_lock);
19287 +
19288 +                       ret = -EEXIST;
19289 +                       if (__lookup_dl_info(sb, id))
19290 +                               goto out_unlock;
19291 +                       __hash_dl_info(dli);
19292 +                       dli = NULL;
19293 +               } else {
19294 +                       spin_lock(&dl_info_hash_lock);
19295 +                       dli = __lookup_dl_info(sb, id);
19296 +
19297 +                       ret = -ESRCH;
19298 +                       if (!dli)
19299 +                               goto out_unlock;
19300 +                       __unhash_dl_info(dli);
19301 +               }
19302 +               ret = 0;
19303 +       out_unlock:
19304 +               spin_unlock(&dl_info_hash_lock);
19305 +               if (add && dli)
19306 +                       __dealloc_dl_info(dli);
19307 +       out_release:
19308 +               path_put(&path);
19309 +       }
19310 +       return ret;
19311 +}
19312 +
19313 +int vc_add_dlimit(uint32_t id, void __user *data)
19314 +{
19315 +       struct vcmd_ctx_dlimit_base_v0 vc_data;
19316 +
19317 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19318 +               return -EFAULT;
19319 +
19320 +       return do_addrem_dlimit(id, vc_data.name, vc_data.flags, 1);
19321 +}
19322 +
19323 +int vc_rem_dlimit(uint32_t id, void __user *data)
19324 +{
19325 +       struct vcmd_ctx_dlimit_base_v0 vc_data;
19326 +
19327 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19328 +               return -EFAULT;
19329 +
19330 +       return do_addrem_dlimit(id, vc_data.name, vc_data.flags, 0);
19331 +}
19332 +
19333 +#ifdef CONFIG_COMPAT
19334 +
19335 +int vc_add_dlimit_x32(uint32_t id, void __user *data)
19336 +{
19337 +       struct vcmd_ctx_dlimit_base_v0_x32 vc_data;
19338 +
19339 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19340 +               return -EFAULT;
19341 +
19342 +       return do_addrem_dlimit(id,
19343 +               compat_ptr(vc_data.name_ptr), vc_data.flags, 1);
19344 +}
19345 +
19346 +int vc_rem_dlimit_x32(uint32_t id, void __user *data)
19347 +{
19348 +       struct vcmd_ctx_dlimit_base_v0_x32 vc_data;
19349 +
19350 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19351 +               return -EFAULT;
19352 +
19353 +       return do_addrem_dlimit(id,
19354 +               compat_ptr(vc_data.name_ptr), vc_data.flags, 0);
19355 +}
19356 +
19357 +#endif /* CONFIG_COMPAT */
19358 +
19359 +
19360 +static inline
19361 +int do_set_dlimit(uint32_t id, const char __user *name,
19362 +       uint32_t space_used, uint32_t space_total,
19363 +       uint32_t inodes_used, uint32_t inodes_total,
19364 +       uint32_t reserved, uint32_t flags)
19365 +{
19366 +       struct path path;
19367 +       int ret;
19368 +
19369 +       ret = user_lpath(name, &path);
19370 +       if (!ret) {
19371 +               struct super_block *sb;
19372 +               struct dl_info *dli;
19373 +
19374 +               ret = -EINVAL;
19375 +               if (!path.dentry->d_inode)
19376 +                       goto out_release;
19377 +               if (!(sb = path.dentry->d_inode->i_sb))
19378 +                       goto out_release;
19379 +               if ((reserved != CDLIM_KEEP &&
19380 +                       reserved > 100) ||
19381 +                       (inodes_used != CDLIM_KEEP &&
19382 +                       inodes_used > inodes_total) ||
19383 +                       (space_used != CDLIM_KEEP &&
19384 +                       space_used > space_total))
19385 +                       goto out_release;
19386 +
19387 +               ret = -ESRCH;
19388 +               dli = locate_dl_info(sb, id);
19389 +               if (!dli)
19390 +                       goto out_release;
19391 +
19392 +               spin_lock(&dli->dl_lock);
19393 +
19394 +               if (inodes_used != CDLIM_KEEP)
19395 +                       dli->dl_inodes_used = inodes_used;
19396 +               if (inodes_total != CDLIM_KEEP)
19397 +                       dli->dl_inodes_total = inodes_total;
19398 +               if (space_used != CDLIM_KEEP) {
19399 +                       dli->dl_space_used = space_used;
19400 +                       dli->dl_space_used <<= 10;
19401 +               }
19402 +               if (space_total == CDLIM_INFINITY)
19403 +                       dli->dl_space_total = DLIM_INFINITY;
19404 +               else if (space_total != CDLIM_KEEP) {
19405 +                       dli->dl_space_total = space_total;
19406 +                       dli->dl_space_total <<= 10;
19407 +               }
19408 +               if (reserved != CDLIM_KEEP)
19409 +                       dli->dl_nrlmult = (1 << 10) * (100 - reserved) / 100;
19410 +
19411 +               spin_unlock(&dli->dl_lock);
19412 +
19413 +               put_dl_info(dli);
19414 +               ret = 0;
19415 +
19416 +       out_release:
19417 +               path_put(&path);
19418 +       }
19419 +       return ret;
19420 +}
19421 +
19422 +int vc_set_dlimit(uint32_t id, void __user *data)
19423 +{
19424 +       struct vcmd_ctx_dlimit_v0 vc_data;
19425 +
19426 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19427 +               return -EFAULT;
19428 +
19429 +       return do_set_dlimit(id, vc_data.name,
19430 +               vc_data.space_used, vc_data.space_total,
19431 +               vc_data.inodes_used, vc_data.inodes_total,
19432 +               vc_data.reserved, vc_data.flags);
19433 +}
19434 +
19435 +#ifdef CONFIG_COMPAT
19436 +
19437 +int vc_set_dlimit_x32(uint32_t id, void __user *data)
19438 +{
19439 +       struct vcmd_ctx_dlimit_v0_x32 vc_data;
19440 +
19441 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19442 +               return -EFAULT;
19443 +
19444 +       return do_set_dlimit(id, compat_ptr(vc_data.name_ptr),
19445 +               vc_data.space_used, vc_data.space_total,
19446 +               vc_data.inodes_used, vc_data.inodes_total,
19447 +               vc_data.reserved, vc_data.flags);
19448 +}
19449 +
19450 +#endif /* CONFIG_COMPAT */
19451 +
19452 +
19453 +static inline
19454 +int do_get_dlimit(uint32_t id, const char __user *name,
19455 +       uint32_t *space_used, uint32_t *space_total,
19456 +       uint32_t *inodes_used, uint32_t *inodes_total,
19457 +       uint32_t *reserved, uint32_t *flags)
19458 +{
19459 +       struct path path;
19460 +       int ret;
19461 +
19462 +       ret = user_lpath(name, &path);
19463 +       if (!ret) {
19464 +               struct super_block *sb;
19465 +               struct dl_info *dli;
19466 +
19467 +               ret = -EINVAL;
19468 +               if (!path.dentry->d_inode)
19469 +                       goto out_release;
19470 +               if (!(sb = path.dentry->d_inode->i_sb))
19471 +                       goto out_release;
19472 +
19473 +               ret = -ESRCH;
19474 +               dli = locate_dl_info(sb, id);
19475 +               if (!dli)
19476 +                       goto out_release;
19477 +
19478 +               spin_lock(&dli->dl_lock);
19479 +               *inodes_used = dli->dl_inodes_used;
19480 +               *inodes_total = dli->dl_inodes_total;
19481 +               *space_used = dli->dl_space_used >> 10;
19482 +               if (dli->dl_space_total == DLIM_INFINITY)
19483 +                       *space_total = CDLIM_INFINITY;
19484 +               else
19485 +                       *space_total = dli->dl_space_total >> 10;
19486 +
19487 +               *reserved = 100 - ((dli->dl_nrlmult * 100 + 512) >> 10);
19488 +               spin_unlock(&dli->dl_lock);
19489 +
19490 +               put_dl_info(dli);
19491 +               ret = -EFAULT;
19492 +
19493 +               ret = 0;
19494 +       out_release:
19495 +               path_put(&path);
19496 +       }
19497 +       return ret;
19498 +}
19499 +
19500 +
19501 +int vc_get_dlimit(uint32_t id, void __user *data)
19502 +{
19503 +       struct vcmd_ctx_dlimit_v0 vc_data;
19504 +       int ret;
19505 +
19506 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19507 +               return -EFAULT;
19508 +
19509 +       ret = do_get_dlimit(id, vc_data.name,
19510 +               &vc_data.space_used, &vc_data.space_total,
19511 +               &vc_data.inodes_used, &vc_data.inodes_total,
19512 +               &vc_data.reserved, &vc_data.flags);
19513 +       if (ret)
19514 +               return ret;
19515 +
19516 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
19517 +               return -EFAULT;
19518 +       return 0;
19519 +}
19520 +
19521 +#ifdef CONFIG_COMPAT
19522 +
19523 +int vc_get_dlimit_x32(uint32_t id, void __user *data)
19524 +{
19525 +       struct vcmd_ctx_dlimit_v0_x32 vc_data;
19526 +       int ret;
19527 +
19528 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19529 +               return -EFAULT;
19530 +
19531 +       ret = do_get_dlimit(id, compat_ptr(vc_data.name_ptr),
19532 +               &vc_data.space_used, &vc_data.space_total,
19533 +               &vc_data.inodes_used, &vc_data.inodes_total,
19534 +               &vc_data.reserved, &vc_data.flags);
19535 +       if (ret)
19536 +               return ret;
19537 +
19538 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
19539 +               return -EFAULT;
19540 +       return 0;
19541 +}
19542 +
19543 +#endif /* CONFIG_COMPAT */
19544 +
19545 +
19546 +void vx_vsi_statfs(struct super_block *sb, struct kstatfs *buf)
19547 +{
19548 +       struct dl_info *dli;
19549 +       __u64 blimit, bfree, bavail;
19550 +       __u32 ifree;
19551 +
19552 +       dli = locate_dl_info(sb, dx_current_tag());
19553 +       if (!dli)
19554 +               return;
19555 +
19556 +       spin_lock(&dli->dl_lock);
19557 +       if (dli->dl_inodes_total == (unsigned long)DLIM_INFINITY)
19558 +               goto no_ilim;
19559 +
19560 +       /* reduce max inodes available to limit */
19561 +       if (buf->f_files > dli->dl_inodes_total)
19562 +               buf->f_files = dli->dl_inodes_total;
19563 +
19564 +       ifree = dli->dl_inodes_total - dli->dl_inodes_used;
19565 +       /* reduce free inodes to min */
19566 +       if (ifree < buf->f_ffree)
19567 +               buf->f_ffree = ifree;
19568 +
19569 +no_ilim:
19570 +       if (dli->dl_space_total == DLIM_INFINITY)
19571 +               goto no_blim;
19572 +
19573 +       blimit = dli->dl_space_total >> sb->s_blocksize_bits;
19574 +
19575 +       if (dli->dl_space_total < dli->dl_space_used)
19576 +               bfree = 0;
19577 +       else
19578 +               bfree = (dli->dl_space_total - dli->dl_space_used)
19579 +                       >> sb->s_blocksize_bits;
19580 +
19581 +       bavail = ((dli->dl_space_total >> 10) * dli->dl_nrlmult);
19582 +       if (bavail < dli->dl_space_used)
19583 +               bavail = 0;
19584 +       else
19585 +               bavail = (bavail - dli->dl_space_used)
19586 +                       >> sb->s_blocksize_bits;
19587 +
19588 +       /* reduce max space available to limit */
19589 +       if (buf->f_blocks > blimit)
19590 +               buf->f_blocks = blimit;
19591 +
19592 +       /* reduce free space to min */
19593 +       if (bfree < buf->f_bfree)
19594 +               buf->f_bfree = bfree;
19595 +
19596 +       /* reduce avail space to min */
19597 +       if (bavail < buf->f_bavail)
19598 +               buf->f_bavail = bavail;
19599 +
19600 +no_blim:
19601 +       spin_unlock(&dli->dl_lock);
19602 +       put_dl_info(dli);
19603 +
19604 +       return;
19605 +}
19606 +
19607 +#include <linux/module.h>
19608 +
19609 +EXPORT_SYMBOL_GPL(locate_dl_info);
19610 +EXPORT_SYMBOL_GPL(rcu_free_dl_info);
19611 +
19612 diff -NurpP --minimal linux-2.6.29/kernel/vserver/helper.c linux-2.6.29-vs2.3.0.36.9-pre3/kernel/vserver/helper.c
19613 --- linux-2.6.29/kernel/vserver/helper.c        1970-01-01 01:00:00.000000000 +0100
19614 +++ linux-2.6.29-vs2.3.0.36.9-pre3/kernel/vserver/helper.c      2009-03-25 00:40:43.000000000 +0100
19615 @@ -0,0 +1,199 @@
19616 +/*
19617 + *  linux/kernel/vserver/helper.c
19618 + *
19619 + *  Virtual Context Support
19620 + *
19621 + *  Copyright (C) 2004-2007  Herbert Pötzl
19622 + *
19623 + *  V0.01  basic helper
19624 + *
19625 + */
19626 +
19627 +#include <linux/kmod.h>
19628 +#include <linux/reboot.h>
19629 +#include <linux/vs_context.h>
19630 +#include <linux/vs_network.h>
19631 +#include <linux/vserver/signal.h>
19632 +
19633 +
19634 +char vshelper_path[255] = "/sbin/vshelper";
19635 +
19636 +
19637 +static int do_vshelper(char *name, char *argv[], char *envp[], int sync)
19638 +{
19639 +       int ret;
19640 +
19641 +       if ((ret = call_usermodehelper(name, argv, envp, sync))) {
19642 +               printk( KERN_WARNING
19643 +                       "%s: (%s %s) returned %s with %d\n",
19644 +                       name, argv[1], argv[2],
19645 +                       sync ? "sync" : "async", ret);
19646 +       }
19647 +       vxdprintk(VXD_CBIT(switch, 4),
19648 +               "%s: (%s %s) returned %s with %d",
19649 +               name, argv[1], argv[2], sync ? "sync" : "async", ret);
19650 +       return ret;
19651 +}
19652 +
19653 +/*
19654 + *      vshelper path is set via /proc/sys
19655 + *      invoked by vserver sys_reboot(), with
19656 + *      the following arguments
19657 + *
19658 + *      argv [0] = vshelper_path;
19659 + *      argv [1] = action: "restart", "halt", "poweroff", ...
19660 + *      argv [2] = context identifier
19661 + *
19662 + *      envp [*] = type-specific parameters
19663 + */
19664 +
19665 +long vs_reboot_helper(struct vx_info *vxi, int cmd, void __user *arg)
19666 +{
19667 +       char id_buf[8], cmd_buf[16];
19668 +       char uid_buf[16], pid_buf[16];
19669 +       int ret;
19670 +
19671 +       char *argv[] = {vshelper_path, NULL, id_buf, 0};
19672 +       char *envp[] = {"HOME=/", "TERM=linux",
19673 +                       "PATH=/sbin:/usr/sbin:/bin:/usr/bin",
19674 +                       uid_buf, pid_buf, cmd_buf, 0};
19675 +
19676 +       if (vx_info_state(vxi, VXS_HELPER))
19677 +               return -EAGAIN;
19678 +       vxi->vx_state |= VXS_HELPER;
19679 +
19680 +       snprintf(id_buf, sizeof(id_buf)-1, "%d", vxi->vx_id);
19681 +
19682 +       snprintf(cmd_buf, sizeof(cmd_buf)-1, "VS_CMD=%08x", cmd);
19683 +       snprintf(uid_buf, sizeof(uid_buf)-1, "VS_UID=%d", current_uid());
19684 +       snprintf(pid_buf, sizeof(pid_buf)-1, "VS_PID=%d", current->pid);
19685 +
19686 +       switch (cmd) {
19687 +       case LINUX_REBOOT_CMD_RESTART:
19688 +               argv[1] = "restart";
19689 +               break;
19690 +
19691 +       case LINUX_REBOOT_CMD_HALT:
19692 +               argv[1] = "halt";
19693 +               break;
19694 +
19695 +       case LINUX_REBOOT_CMD_POWER_OFF:
19696 +               argv[1] = "poweroff";
19697 +               break;
19698 +
19699 +       case LINUX_REBOOT_CMD_SW_SUSPEND:
19700 +               argv[1] = "swsusp";
19701 +               break;
19702 +
19703 +       default:
19704 +               vxi->vx_state &= ~VXS_HELPER;
19705 +               return 0;
19706 +       }
19707 +
19708 +       ret = do_vshelper(vshelper_path, argv, envp, 0);
19709 +       vxi->vx_state &= ~VXS_HELPER;
19710 +       __wakeup_vx_info(vxi);
19711 +       return (ret) ? -EPERM : 0;
19712 +}
19713 +
19714 +
19715 +long vs_reboot(unsigned int cmd, void __user *arg)
19716 +{
19717 +       struct vx_info *vxi = current->vx_info;
19718 +       long ret = 0;
19719 +
19720 +       vxdprintk(VXD_CBIT(misc, 5),
19721 +               "vs_reboot(%p[#%d],%d)",
19722 +               vxi, vxi ? vxi->vx_id : 0, cmd);
19723 +
19724 +       ret = vs_reboot_helper(vxi, cmd, arg);
19725 +       if (ret)
19726 +               return ret;
19727 +
19728 +       vxi->reboot_cmd = cmd;
19729 +       if (vx_info_flags(vxi, VXF_REBOOT_KILL, 0)) {
19730 +               switch (cmd) {
19731 +               case LINUX_REBOOT_CMD_RESTART:
19732 +               case LINUX_REBOOT_CMD_HALT:
19733 +               case LINUX_REBOOT_CMD_POWER_OFF:
19734 +                       vx_info_kill(vxi, 0, SIGKILL);
19735 +                       vx_info_kill(vxi, 1, SIGKILL);
19736 +               default:
19737 +                       break;
19738 +               }
19739 +       }
19740 +       return 0;
19741 +}
19742 +
19743 +
19744 +/*
19745 + *      argv [0] = vshelper_path;
19746 + *      argv [1] = action: "startup", "shutdown"
19747 + *      argv [2] = context identifier
19748 + *
19749 + *      envp [*] = type-specific parameters
19750 + */
19751 +
19752 +long vs_state_change(struct vx_info *vxi, unsigned int cmd)
19753 +{
19754 +       char id_buf[8], cmd_buf[16];
19755 +       char *argv[] = {vshelper_path, NULL, id_buf, 0};
19756 +       char *envp[] = {"HOME=/", "TERM=linux",
19757 +                       "PATH=/sbin:/usr/sbin:/bin:/usr/bin", cmd_buf, 0};
19758 +
19759 +       if (!vx_info_flags(vxi, VXF_SC_HELPER, 0))
19760 +               return 0;
19761 +
19762 +       snprintf(id_buf, sizeof(id_buf)-1, "%d", vxi->vx_id);
19763 +       snprintf(cmd_buf, sizeof(cmd_buf)-1, "VS_CMD=%08x", cmd);
19764 +
19765 +       switch (cmd) {
19766 +       case VSC_STARTUP:
19767 +               argv[1] = "startup";
19768 +               break;
19769 +       case VSC_SHUTDOWN:
19770 +               argv[1] = "shutdown";
19771 +               break;
19772 +       default:
19773 +               return 0;
19774 +       }
19775 +
19776 +       return do_vshelper(vshelper_path, argv, envp, 1);
19777 +}
19778 +
19779 +
19780 +/*
19781 + *      argv [0] = vshelper_path;
19782 + *      argv [1] = action: "netup", "netdown"
19783 + *      argv [2] = context identifier
19784 + *
19785 + *      envp [*] = type-specific parameters
19786 + */
19787 +
19788 +long vs_net_change(struct nx_info *nxi, unsigned int cmd)
19789 +{
19790 +       char id_buf[8], cmd_buf[16];
19791 +       char *argv[] = {vshelper_path, NULL, id_buf, 0};
19792 +       char *envp[] = {"HOME=/", "TERM=linux",
19793 +                       "PATH=/sbin:/usr/sbin:/bin:/usr/bin", cmd_buf, 0};
19794 +
19795 +       if (!nx_info_flags(nxi, NXF_SC_HELPER, 0))
19796 +               return 0;
19797 +
19798 +       snprintf(id_buf, sizeof(id_buf)-1, "%d", nxi->nx_id);
19799 +       snprintf(cmd_buf, sizeof(cmd_buf)-1, "VS_CMD=%08x", cmd);
19800 +
19801 +       switch (cmd) {
19802 +       case VSC_NETUP:
19803 +               argv[1] = "netup";
19804 +               break;
19805 +       case VSC_NETDOWN:
19806 +               argv[1] = "netdown";
19807 +               break;
19808 +       default:
19809 +               return 0;
19810 +       }
19811 +
19812 +       return do_vshelper(vshelper_path, argv, envp, 1);
19813 +}
19814 +
19815 diff -NurpP --minimal linux-2.6.29/kernel/vserver/history.c linux-2.6.29-vs2.3.0.36.9-pre3/kernel/vserver/history.c
19816 --- linux-2.6.29/kernel/vserver/history.c       1970-01-01 01:00:00.000000000 +0100
19817 +++ linux-2.6.29-vs2.3.0.36.9-pre3/kernel/vserver/history.c     2009-02-22 22:54:26.000000000 +0100
19818 @@ -0,0 +1,258 @@
19819 +/*
19820 + *  kernel/vserver/history.c
19821 + *
19822 + *  Virtual Context History Backtrace
19823 + *
19824 + *  Copyright (C) 2004-2007  Herbert Pötzl
19825 + *
19826 + *  V0.01  basic structure
19827 + *  V0.02  hash/unhash and trace
19828 + *  V0.03  preemption fixes
19829 + *
19830 + */
19831 +
19832 +#include <linux/module.h>
19833 +#include <asm/uaccess.h>
19834 +
19835 +#include <linux/vserver/context.h>
19836 +#include <linux/vserver/debug.h>
19837 +#include <linux/vserver/debug_cmd.h>
19838 +#include <linux/vserver/history.h>
19839 +
19840 +
19841 +#ifdef CONFIG_VSERVER_HISTORY
19842 +#define VXH_SIZE       CONFIG_VSERVER_HISTORY_SIZE
19843 +#else
19844 +#define VXH_SIZE       64
19845 +#endif
19846 +
19847 +struct _vx_history {
19848 +       unsigned int counter;
19849 +
19850 +       struct _vx_hist_entry entry[VXH_SIZE + 1];
19851 +};
19852 +
19853 +
19854 +DEFINE_PER_CPU(struct _vx_history, vx_history_buffer);
19855 +
19856 +unsigned volatile int vxh_active = 1;
19857 +
19858 +static atomic_t sequence = ATOMIC_INIT(0);
19859 +
19860 +
19861 +/*     vxh_advance()
19862 +
19863 +       * requires disabled preemption                          */
19864 +
19865 +struct _vx_hist_entry *vxh_advance(void *loc)
19866 +{
19867 +       unsigned int cpu = smp_processor_id();
19868 +       struct _vx_history *hist = &per_cpu(vx_history_buffer, cpu);
19869 +       struct _vx_hist_entry *entry;
19870 +       unsigned int index;
19871 +
19872 +       index = vxh_active ? (hist->counter++ % VXH_SIZE) : VXH_SIZE;
19873 +       entry = &hist->entry[index];
19874 +
19875 +       entry->seq = atomic_inc_return(&sequence);
19876 +       entry->loc = loc;
19877 +       return entry;
19878 +}
19879 +
19880 +EXPORT_SYMBOL_GPL(vxh_advance);
19881 +
19882 +
19883 +#define VXH_LOC_FMTS   "(#%04x,*%d):%p"
19884 +
19885 +#define VXH_LOC_ARGS(e)        (e)->seq, cpu, (e)->loc
19886 +
19887 +
19888 +#define VXH_VXI_FMTS   "%p[#%d,%d.%d]"
19889 +
19890 +#define VXH_VXI_ARGS(e)        (e)->vxi.ptr,                           \
19891 +                       (e)->vxi.ptr ? (e)->vxi.xid : 0,        \
19892 +                       (e)->vxi.ptr ? (e)->vxi.usecnt : 0,     \
19893 +                       (e)->vxi.ptr ? (e)->vxi.tasks : 0
19894 +
19895 +void   vxh_dump_entry(struct _vx_hist_entry *e, unsigned cpu)
19896 +{
19897 +       switch (e->type) {
19898 +       case VXH_THROW_OOPS:
19899 +               printk( VXH_LOC_FMTS " oops \n", VXH_LOC_ARGS(e));
19900 +               break;
19901 +
19902 +       case VXH_GET_VX_INFO:
19903 +       case VXH_PUT_VX_INFO:
19904 +               printk( VXH_LOC_FMTS " %s_vx_info " VXH_VXI_FMTS "\n",
19905 +                       VXH_LOC_ARGS(e),
19906 +                       (e->type == VXH_GET_VX_INFO) ? "get" : "put",
19907 +                       VXH_VXI_ARGS(e));
19908 +               break;
19909 +
19910 +       case VXH_INIT_VX_INFO:
19911 +       case VXH_SET_VX_INFO:
19912 +       case VXH_CLR_VX_INFO:
19913 +               printk( VXH_LOC_FMTS " %s_vx_info " VXH_VXI_FMTS " @%p\n",
19914 +                       VXH_LOC_ARGS(e),
19915 +                       (e->type == VXH_INIT_VX_INFO) ? "init" :
19916 +                       ((e->type == VXH_SET_VX_INFO) ? "set" : "clr"),
19917 +                       VXH_VXI_ARGS(e), e->sc.data);
19918 +               break;
19919 +
19920 +       case VXH_CLAIM_VX_INFO:
19921 +       case VXH_RELEASE_VX_INFO:
19922 +               printk( VXH_LOC_FMTS " %s_vx_info " VXH_VXI_FMTS " @%p\n",
19923 +                       VXH_LOC_ARGS(e),
19924 +                       (e->type == VXH_CLAIM_VX_INFO) ? "claim" : "release",
19925 +                       VXH_VXI_ARGS(e), e->sc.data);
19926 +               break;
19927 +
19928 +       case VXH_ALLOC_VX_INFO:
19929 +       case VXH_DEALLOC_VX_INFO:
19930 +               printk( VXH_LOC_FMTS " %s_vx_info " VXH_VXI_FMTS "\n",
19931 +                       VXH_LOC_ARGS(e),
19932 +                       (e->type == VXH_ALLOC_VX_INFO) ? "alloc" : "dealloc",
19933 +                       VXH_VXI_ARGS(e));
19934 +               break;
19935 +
19936 +       case VXH_HASH_VX_INFO:
19937 +       case VXH_UNHASH_VX_INFO:
19938 +               printk( VXH_LOC_FMTS " __%s_vx_info " VXH_VXI_FMTS "\n",
19939 +                       VXH_LOC_ARGS(e),
19940 +                       (e->type == VXH_HASH_VX_INFO) ? "hash" : "unhash",
19941 +                       VXH_VXI_ARGS(e));
19942 +               break;
19943 +
19944 +       case VXH_LOC_VX_INFO:
19945 +       case VXH_LOOKUP_VX_INFO:
19946 +       case VXH_CREATE_VX_INFO:
19947 +               printk( VXH_LOC_FMTS " __%s_vx_info [#%d] -> " VXH_VXI_FMTS "\n",
19948 +                       VXH_LOC_ARGS(e),
19949 +                       (e->type == VXH_CREATE_VX_INFO) ? "create" :
19950 +                       ((e->type == VXH_LOC_VX_INFO) ? "loc" : "lookup"),
19951 +                       e->ll.arg, VXH_VXI_ARGS(e));
19952 +               break;
19953 +       }
19954 +}
19955 +
19956 +static void __vxh_dump_history(void)
19957 +{
19958 +       unsigned int i, cpu;
19959 +
19960 +       printk("History:\tSEQ: %8x\tNR_CPUS: %d\n",
19961 +               atomic_read(&sequence), NR_CPUS);
19962 +
19963 +       for (i = 0; i < VXH_SIZE; i++) {
19964 +               for_each_online_cpu(cpu) {
19965 +                       struct _vx_history *hist =
19966 +                               &per_cpu(vx_history_buffer, cpu);
19967 +                       unsigned int index = (hist->counter - i) % VXH_SIZE;
19968 +                       struct _vx_hist_entry *entry = &hist->entry[index];
19969 +
19970 +                       vxh_dump_entry(entry, cpu);
19971 +               }
19972 +       }
19973 +}
19974 +
19975 +void   vxh_dump_history(void)
19976 +{
19977 +       vxh_active = 0;
19978 +#ifdef CONFIG_SMP
19979 +       local_irq_enable();
19980 +       smp_send_stop();
19981 +       local_irq_disable();
19982 +#endif
19983 +       __vxh_dump_history();
19984 +}
19985 +
19986 +
19987 +/* vserver syscall commands below here */
19988 +
19989 +
19990 +int vc_dump_history(uint32_t id)
19991 +{
19992 +       vxh_active = 0;
19993 +       __vxh_dump_history();
19994 +       vxh_active = 1;
19995 +
19996 +       return 0;
19997 +}
19998 +
19999 +
20000 +int do_read_history(struct __user _vx_hist_entry *data,
20001 +       int cpu, uint32_t *index, uint32_t *count)
20002 +{
20003 +       int pos, ret = 0;
20004 +       struct _vx_history *hist = &per_cpu(vx_history_buffer, cpu);
20005 +       int end = hist->counter;
20006 +       int start = end - VXH_SIZE + 2;
20007 +       int idx = *index;
20008 +
20009 +       /* special case: get current pos */
20010 +       if (!*count) {
20011 +               *index = end;
20012 +               return 0;
20013 +       }
20014 +
20015 +       /* have we lost some data? */
20016 +       if (idx < start)
20017 +               idx = start;
20018 +
20019 +       for (pos = 0; (pos < *count) && (idx < end); pos++, idx++) {
20020 +               struct _vx_hist_entry *entry =
20021 +                       &hist->entry[idx % VXH_SIZE];
20022 +
20023 +               /* send entry to userspace */
20024 +               ret = copy_to_user(&data[pos], entry, sizeof(*entry));
20025 +               if (ret)
20026 +                       break;
20027 +       }
20028 +       /* save new index and count */
20029 +       *index = idx;
20030 +       *count = pos;
20031 +       return ret ? ret : (*index < end);
20032 +}
20033 +
20034 +int vc_read_history(uint32_t id, void __user *data)
20035 +{
20036 +       struct vcmd_read_history_v0 vc_data;
20037 +       int ret;
20038 +
20039 +       if (id >= NR_CPUS)
20040 +               return -EINVAL;
20041 +
20042 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
20043 +               return -EFAULT;
20044 +
20045 +       ret = do_read_history((struct __user _vx_hist_entry *)vc_data.data,
20046 +               id, &vc_data.index, &vc_data.count);
20047 +
20048 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
20049 +               return -EFAULT;
20050 +       return ret;
20051 +}
20052 +
20053 +#ifdef CONFIG_COMPAT
20054 +
20055 +int vc_read_history_x32(uint32_t id, void __user *data)
20056 +{
20057 +       struct vcmd_read_history_v0_x32 vc_data;
20058 +       int ret;
20059 +
20060 +       if (id >= NR_CPUS)
20061 +               return -EINVAL;
20062 +
20063 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
20064 +               return -EFAULT;
20065 +
20066 +       ret = do_read_history((struct __user _vx_hist_entry *)
20067 +               compat_ptr(vc_data.data_ptr),
20068 +               id, &vc_data.index, &vc_data.count);
20069 +
20070 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
20071 +               return -EFAULT;
20072 +       return ret;
20073 +}
20074 +
20075 +#endif /* CONFIG_COMPAT */
20076 +
20077 diff -NurpP --minimal linux-2.6.29/kernel/vserver/inet.c linux-2.6.29-vs2.3.0.36.9-pre3/kernel/vserver/inet.c
20078 --- linux-2.6.29/kernel/vserver/inet.c  1970-01-01 01:00:00.000000000 +0100
20079 +++ linux-2.6.29-vs2.3.0.36.9-pre3/kernel/vserver/inet.c        2009-02-22 22:54:26.000000000 +0100
20080 @@ -0,0 +1,225 @@
20081 +
20082 +#include <linux/in.h>
20083 +#include <linux/inetdevice.h>
20084 +#include <linux/vs_inet.h>
20085 +#include <linux/vs_inet6.h>
20086 +#include <linux/vserver/debug.h>
20087 +#include <net/route.h>
20088 +#include <net/addrconf.h>
20089 +
20090 +
20091 +int nx_v4_addr_conflict(struct nx_info *nxi1, struct nx_info *nxi2)
20092 +{
20093 +       int ret = 0;
20094 +
20095 +       if (!nxi1 || !nxi2 || nxi1 == nxi2)
20096 +               ret = 1;
20097 +       else {
20098 +               struct nx_addr_v4 *ptr;
20099 +
20100 +               for (ptr = &nxi1->v4; ptr; ptr = ptr->next) {
20101 +                       if (v4_nx_addr_in_nx_info(nxi2, ptr, -1)) {
20102 +                               ret = 1;
20103 +                               break;
20104 +                       }
20105 +               }
20106 +       }
20107 +
20108 +       vxdprintk(VXD_CBIT(net, 2),
20109 +               "nx_v4_addr_conflict(%p,%p): %d",
20110 +               nxi1, nxi2, ret);
20111 +
20112 +       return ret;
20113 +}
20114 +
20115 +
20116 +#ifdef CONFIG_IPV6
20117 +
20118 +int nx_v6_addr_conflict(struct nx_info *nxi1, struct nx_info *nxi2)
20119 +{
20120 +       int ret = 0;
20121 +
20122 +       if (!nxi1 || !nxi2 || nxi1 == nxi2)
20123 +               ret = 1;
20124 +       else {
20125 +               struct nx_addr_v6 *ptr;
20126 +
20127 +               for (ptr = &nxi1->v6; ptr; ptr = ptr->next) {
20128 +                       if (v6_nx_addr_in_nx_info(nxi2, ptr, -1)) {
20129 +                               ret = 1;
20130 +                               break;
20131 +                       }
20132 +               }
20133 +       }
20134 +
20135 +       vxdprintk(VXD_CBIT(net, 2),
20136 +               "nx_v6_addr_conflict(%p,%p): %d",
20137 +               nxi1, nxi2, ret);
20138 +
20139 +       return ret;
20140 +}
20141 +
20142 +#endif
20143 +
20144 +int v4_dev_in_nx_info(struct net_device *dev, struct nx_info *nxi)
20145 +{
20146 +       struct in_device *in_dev;
20147 +       struct in_ifaddr **ifap;
20148 +       struct in_ifaddr *ifa;
20149 +       int ret = 0;
20150 +
20151 +       if (!dev)
20152 +               goto out;
20153 +       in_dev = in_dev_get(dev);
20154 +       if (!in_dev)
20155 +               goto out;
20156 +
20157 +       for (ifap = &in_dev->ifa_list; (ifa = *ifap) != NULL;
20158 +               ifap = &ifa->ifa_next) {
20159 +               if (v4_addr_in_nx_info(nxi, ifa->ifa_local, NXA_MASK_SHOW)) {
20160 +                       ret = 1;
20161 +                       break;
20162 +               }
20163 +       }
20164 +       in_dev_put(in_dev);
20165 +out:
20166 +       return ret;
20167 +}
20168 +
20169 +
20170 +#ifdef CONFIG_IPV6
20171 +
20172 +int v6_dev_in_nx_info(struct net_device *dev, struct nx_info *nxi)
20173 +{
20174 +       struct inet6_dev *in_dev;
20175 +       struct inet6_ifaddr **ifap;
20176 +       struct inet6_ifaddr *ifa;
20177 +       int ret = 0;
20178 +
20179 +       if (!dev)
20180 +               goto out;
20181 +       in_dev = in6_dev_get(dev);
20182 +       if (!in_dev)
20183 +               goto out;
20184 +
20185 +       for (ifap = &in_dev->addr_list; (ifa = *ifap) != NULL;
20186 +               ifap = &ifa->if_next) {
20187 +               if (v6_addr_in_nx_info(nxi, &ifa->addr, -1)) {
20188 +                       ret = 1;
20189 +                       break;
20190 +               }
20191 +       }
20192 +       in6_dev_put(in_dev);
20193 +out:
20194 +       return ret;
20195 +}
20196 +
20197 +#endif
20198 +
20199 +int dev_in_nx_info(struct net_device *dev, struct nx_info *nxi)
20200 +{
20201 +       int ret = 1;
20202 +
20203 +       if (!nxi)
20204 +               goto out;
20205 +       if (nxi->v4.type && v4_dev_in_nx_info(dev, nxi))
20206 +               goto out;
20207 +#ifdef CONFIG_IPV6
20208 +       ret = 2;
20209 +       if (nxi->v6.type && v6_dev_in_nx_info(dev, nxi))
20210 +               goto out;
20211 +#endif
20212 +       ret = 0;
20213 +out:
20214 +       vxdprintk(VXD_CBIT(net, 3),
20215 +               "dev_in_nx_info(%p,%p[#%d]) = %d",
20216 +               dev, nxi, nxi ? nxi->nx_id : 0, ret);
20217 +       return ret;
20218 +}
20219 +
20220 +int ip_v4_find_src(struct net *net, struct nx_info *nxi,
20221 +       struct rtable **rp, struct flowi *fl)
20222 +{
20223 +       if (!nxi)
20224 +               return 0;
20225 +
20226 +       /* FIXME: handle lback only case */
20227 +       if (!NX_IPV4(nxi))
20228 +               return -EPERM;
20229 +
20230 +       vxdprintk(VXD_CBIT(net, 4),
20231 +               "ip_v4_find_src(%p[#%u]) " NIPQUAD_FMT " -> " NIPQUAD_FMT,
20232 +               nxi, nxi ? nxi->nx_id : 0,
20233 +               NIPQUAD(fl->fl4_src), NIPQUAD(fl->fl4_dst));
20234 +
20235 +       /* single IP is unconditional */
20236 +       if (nx_info_flags(nxi, NXF_SINGLE_IP, 0) &&
20237 +               (fl->fl4_src == INADDR_ANY))
20238 +               fl->fl4_src = nxi->v4.ip[0].s_addr;
20239 +
20240 +       if (fl->fl4_src == INADDR_ANY) {
20241 +               struct nx_addr_v4 *ptr;
20242 +               __be32 found = 0;
20243 +               int err;
20244 +
20245 +               err = __ip_route_output_key(net, rp, fl);
20246 +               if (!err) {
20247 +                       found = (*rp)->rt_src;
20248 +                       ip_rt_put(*rp);
20249 +                       vxdprintk(VXD_CBIT(net, 4),
20250 +                               "ip_v4_find_src(%p[#%u]) rok[%u]: " NIPQUAD_FMT,
20251 +                               nxi, nxi ? nxi->nx_id : 0, fl->oif, NIPQUAD(found));
20252 +                       if (v4_addr_in_nx_info(nxi, found, NXA_MASK_BIND))
20253 +                               goto found;
20254 +               }
20255 +
20256 +               for (ptr = &nxi->v4; ptr; ptr = ptr->next) {
20257 +                       __be32 primary = ptr->ip[0].s_addr;
20258 +                       __be32 mask = ptr->mask.s_addr;
20259 +                       __be32 neta = primary & mask;
20260 +
20261 +                       vxdprintk(VXD_CBIT(net, 4), "ip_v4_find_src(%p[#%u]) chk: "
20262 +                               NIPQUAD_FMT "/" NIPQUAD_FMT "/" NIPQUAD_FMT,
20263 +                               nxi, nxi ? nxi->nx_id : 0, NIPQUAD(primary),
20264 +                               NIPQUAD(mask), NIPQUAD(neta));
20265 +                       if ((found & mask) != neta)
20266 +                               continue;
20267 +
20268 +                       fl->fl4_src = primary;
20269 +                       err = __ip_route_output_key(net, rp, fl);
20270 +                       vxdprintk(VXD_CBIT(net, 4),
20271 +                               "ip_v4_find_src(%p[#%u]) rok[%u]: " NIPQUAD_FMT,
20272 +                               nxi, nxi ? nxi->nx_id : 0, fl->oif, NIPQUAD(primary));
20273 +                       if (!err) {
20274 +                               found = (*rp)->rt_src;
20275 +                               ip_rt_put(*rp);
20276 +                               if (found == primary)
20277 +                                       goto found;
20278 +                       }
20279 +               }
20280 +               /* still no source ip? */
20281 +               found = ipv4_is_loopback(fl->fl4_dst)
20282 +                       ? IPI_LOOPBACK : nxi->v4.ip[0].s_addr;
20283 +       found:
20284 +               /* assign src ip to flow */
20285 +               fl->fl4_src = found;
20286 +
20287 +       } else {
20288 +               if (!v4_addr_in_nx_info(nxi, fl->fl4_src, NXA_MASK_BIND))
20289 +                       return -EPERM;
20290 +       }
20291 +
20292 +       if (nx_info_flags(nxi, NXF_LBACK_REMAP, 0)) {
20293 +               if (ipv4_is_loopback(fl->fl4_dst))
20294 +                       fl->fl4_dst = nxi->v4_lback.s_addr;
20295 +               if (ipv4_is_loopback(fl->fl4_src))
20296 +                       fl->fl4_src = nxi->v4_lback.s_addr;
20297 +       } else if (ipv4_is_loopback(fl->fl4_dst) &&
20298 +               !nx_info_flags(nxi, NXF_LBACK_ALLOW, 0))
20299 +               return -EPERM;
20300 +
20301 +       return 0;
20302 +}
20303 +
20304 +EXPORT_SYMBOL_GPL(ip_v4_find_src);
20305 +
20306 diff -NurpP --minimal linux-2.6.29/kernel/vserver/init.c linux-2.6.29-vs2.3.0.36.9-pre3/kernel/vserver/init.c
20307 --- linux-2.6.29/kernel/vserver/init.c  1970-01-01 01:00:00.000000000 +0100
20308 +++ linux-2.6.29-vs2.3.0.36.9-pre3/kernel/vserver/init.c        2009-02-22 22:54:26.000000000 +0100
20309 @@ -0,0 +1,45 @@
20310 +/*
20311 + *  linux/kernel/init.c
20312 + *
20313 + *  Virtual Server Init
20314 + *
20315 + *  Copyright (C) 2004-2007  Herbert Pötzl
20316 + *
20317 + *  V0.01  basic structure
20318 + *
20319 + */
20320 +
20321 +#include <linux/init.h>
20322 +
20323 +int    vserver_register_sysctl(void);
20324 +void   vserver_unregister_sysctl(void);
20325 +
20326 +
20327 +static int __init init_vserver(void)
20328 +{
20329 +       int ret = 0;
20330 +
20331 +#ifdef CONFIG_VSERVER_DEBUG
20332 +       vserver_register_sysctl();
20333 +#endif
20334 +       return ret;
20335 +}
20336 +
20337 +
20338 +static void __exit exit_vserver(void)
20339 +{
20340 +
20341 +#ifdef CONFIG_VSERVER_DEBUG
20342 +       vserver_unregister_sysctl();
20343 +#endif
20344 +       return;
20345 +}
20346 +
20347 +/* FIXME: GFP_ZONETYPES gone
20348 +long vx_slab[GFP_ZONETYPES]; */
20349 +long vx_area;
20350 +
20351 +
20352 +module_init(init_vserver);
20353 +module_exit(exit_vserver);
20354 +
20355 diff -NurpP --minimal linux-2.6.29/kernel/vserver/inode.c linux-2.6.29-vs2.3.0.36.9-pre3/kernel/vserver/inode.c
20356 --- linux-2.6.29/kernel/vserver/inode.c 1970-01-01 01:00:00.000000000 +0100
20357 +++ linux-2.6.29-vs2.3.0.36.9-pre3/kernel/vserver/inode.c       2009-02-22 22:54:26.000000000 +0100
20358 @@ -0,0 +1,422 @@
20359 +/*
20360 + *  linux/kernel/vserver/inode.c
20361 + *
20362 + *  Virtual Server: File System Support
20363 + *
20364 + *  Copyright (C) 2004-2007  Herbert Pötzl
20365 + *
20366 + *  V0.01  separated from vcontext V0.05
20367 + *  V0.02  moved to tag (instead of xid)
20368 + *
20369 + */
20370 +
20371 +#include <linux/tty.h>
20372 +#include <linux/proc_fs.h>
20373 +#include <linux/devpts_fs.h>
20374 +#include <linux/fs.h>
20375 +#include <linux/file.h>
20376 +#include <linux/mount.h>
20377 +#include <linux/parser.h>
20378 +#include <linux/namei.h>
20379 +#include <linux/vserver/inode.h>
20380 +#include <linux/vserver/inode_cmd.h>
20381 +#include <linux/vs_base.h>
20382 +#include <linux/vs_tag.h>
20383 +
20384 +#include <asm/uaccess.h>
20385 +
20386 +
20387 +static int __vc_get_iattr(struct inode *in, uint32_t *tag, uint32_t *flags, uint32_t *mask)
20388 +{
20389 +       struct proc_dir_entry *entry;
20390 +
20391 +       if (!in || !in->i_sb)
20392 +               return -ESRCH;
20393 +
20394 +       *flags = IATTR_TAG
20395 +               | (IS_BARRIER(in) ? IATTR_BARRIER : 0)
20396 +               | (IS_IXUNLINK(in) ? IATTR_IXUNLINK : 0)
20397 +               | (IS_IMMUTABLE(in) ? IATTR_IMMUTABLE : 0);
20398 +       *mask = IATTR_IXUNLINK | IATTR_IMMUTABLE;
20399 +
20400 +       if (S_ISDIR(in->i_mode))
20401 +               *mask |= IATTR_BARRIER;
20402 +
20403 +       if (IS_TAGGED(in)) {
20404 +               *tag = in->i_tag;
20405 +               *mask |= IATTR_TAG;
20406 +       }
20407 +
20408 +       switch (in->i_sb->s_magic) {
20409 +       case PROC_SUPER_MAGIC:
20410 +               entry = PROC_I(in)->pde;
20411 +
20412 +               /* check for specific inodes? */
20413 +               if (entry)
20414 +                       *mask |= IATTR_FLAGS;
20415 +               if (entry)
20416 +                       *flags |= (entry->vx_flags & IATTR_FLAGS);
20417 +               else
20418 +                       *flags |= (PROC_I(in)->vx_flags & IATTR_FLAGS);
20419 +               break;
20420 +
20421 +       case DEVPTS_SUPER_MAGIC:
20422 +               *tag = in->i_tag;
20423 +               *mask |= IATTR_TAG;
20424 +               break;
20425 +
20426 +       default:
20427 +               break;
20428 +       }
20429 +       return 0;
20430 +}
20431 +
20432 +int vc_get_iattr(void __user *data)
20433 +{
20434 +       struct path path;
20435 +       struct vcmd_ctx_iattr_v1 vc_data = { .tag = -1 };
20436 +       int ret;
20437 +
20438 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
20439 +               return -EFAULT;
20440 +
20441 +       ret = user_lpath(vc_data.name, &path);
20442 +       if (!ret) {
20443 +               ret = __vc_get_iattr(path.dentry->d_inode,
20444 +                       &vc_data.tag, &vc_data.flags, &vc_data.mask);
20445 +               path_put(&path);
20446 +       }
20447 +       if (ret)
20448 +               return ret;
20449 +
20450 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
20451 +               ret = -EFAULT;
20452 +       return ret;
20453 +}
20454 +
20455 +#ifdef CONFIG_COMPAT
20456 +
20457 +int vc_get_iattr_x32(void __user *data)
20458 +{
20459 +       struct path path;
20460 +       struct vcmd_ctx_iattr_v1_x32 vc_data = { .tag = -1 };
20461 +       int ret;
20462 +
20463 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
20464 +               return -EFAULT;
20465 +
20466 +       ret = user_lpath(compat_ptr(vc_data.name_ptr), &path);
20467 +       if (!ret) {
20468 +               ret = __vc_get_iattr(path.dentry->d_inode,
20469 +                       &vc_data.tag, &vc_data.flags, &vc_data.mask);
20470 +               path_put(&path);
20471 +       }
20472 +       if (ret)
20473 +               return ret;
20474 +
20475 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
20476 +               ret = -EFAULT;
20477 +       return ret;
20478 +}
20479 +
20480 +#endif /* CONFIG_COMPAT */
20481 +
20482 +
20483 +int vc_fget_iattr(uint32_t fd, void __user *data)
20484 +{
20485 +       struct file *filp;
20486 +       struct vcmd_ctx_fiattr_v0 vc_data = { .tag = -1 };
20487 +       int ret;
20488 +
20489 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
20490 +               return -EFAULT;
20491 +
20492 +       filp = fget(fd);
20493 +       if (!filp || !filp->f_dentry || !filp->f_dentry->d_inode)
20494 +               return -EBADF;
20495 +
20496 +       ret = __vc_get_iattr(filp->f_dentry->d_inode,
20497 +               &vc_data.tag, &vc_data.flags, &vc_data.mask);
20498 +
20499 +       fput(filp);
20500 +
20501 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
20502 +               ret = -EFAULT;
20503 +       return ret;
20504 +}
20505 +
20506 +
20507 +static int __vc_set_iattr(struct dentry *de, uint32_t *tag, uint32_t *flags, uint32_t *mask)
20508 +{
20509 +       struct inode *in = de->d_inode;
20510 +       int error = 0, is_proc = 0, has_tag = 0;
20511 +       struct iattr attr = { 0 };
20512 +
20513 +       if (!in || !in->i_sb)
20514 +               return -ESRCH;
20515 +
20516 +       is_proc = (in->i_sb->s_magic == PROC_SUPER_MAGIC);
20517 +       if ((*mask & IATTR_FLAGS) && !is_proc)
20518 +               return -EINVAL;
20519 +
20520 +       has_tag = IS_TAGGED(in) ||
20521 +               (in->i_sb->s_magic == DEVPTS_SUPER_MAGIC);
20522 +       if ((*mask & IATTR_TAG) && !has_tag)
20523 +               return -EINVAL;
20524 +
20525 +       mutex_lock(&in->i_mutex);
20526 +       if (*mask & IATTR_TAG) {
20527 +               attr.ia_tag = *tag;
20528 +               attr.ia_valid |= ATTR_TAG;
20529 +       }
20530 +
20531 +       if (*mask & IATTR_FLAGS) {
20532 +               struct proc_dir_entry *entry = PROC_I(in)->pde;
20533 +               unsigned int iflags = PROC_I(in)->vx_flags;
20534 +
20535 +               iflags = (iflags & ~(*mask & IATTR_FLAGS))
20536 +                       | (*flags & IATTR_FLAGS);
20537 +               PROC_I(in)->vx_flags = iflags;
20538 +               if (entry)
20539 +                       entry->vx_flags = iflags;
20540 +       }
20541 +
20542 +       if (*mask & (IATTR_BARRIER | IATTR_IXUNLINK | IATTR_IMMUTABLE)) {
20543 +               if (*mask & IATTR_IMMUTABLE) {
20544 +                       if (*flags & IATTR_IMMUTABLE)
20545 +                               in->i_flags |= S_IMMUTABLE;
20546 +                       else
20547 +                               in->i_flags &= ~S_IMMUTABLE;
20548 +               }
20549 +               if (*mask & IATTR_IXUNLINK) {
20550 +                       if (*flags & IATTR_IXUNLINK)
20551 +                               in->i_flags |= S_IXUNLINK;
20552 +                       else
20553 +                               in->i_flags &= ~S_IXUNLINK;
20554 +               }
20555 +               if (S_ISDIR(in->i_mode) && (*mask & IATTR_BARRIER)) {
20556 +                       if (*flags & IATTR_BARRIER)
20557 +                               in->i_vflags |= V_BARRIER;
20558 +                       else
20559 +                               in->i_vflags &= ~V_BARRIER;
20560 +               }
20561 +               if (in->i_op && in->i_op->sync_flags) {
20562 +                       error = in->i_op->sync_flags(in);
20563 +                       if (error)
20564 +                               goto out;
20565 +               }
20566 +       }
20567 +
20568 +       if (attr.ia_valid) {
20569 +               if (in->i_op && in->i_op->setattr)
20570 +                       error = in->i_op->setattr(de, &attr);
20571 +               else {
20572 +                       error = inode_change_ok(in, &attr);
20573 +                       if (!error)
20574 +                               error = inode_setattr(in, &attr);
20575 +               }
20576 +       }
20577 +
20578 +out:
20579 +       mutex_unlock(&in->i_mutex);
20580 +       return error;
20581 +}
20582 +
20583 +int vc_set_iattr(void __user *data)
20584 +{
20585 +       struct path path;
20586 +       struct vcmd_ctx_iattr_v1 vc_data;
20587 +       int ret;
20588 +
20589 +       if (!capable(CAP_LINUX_IMMUTABLE))
20590 +               return -EPERM;
20591 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
20592 +               return -EFAULT;
20593 +
20594 +       ret = user_lpath(vc_data.name, &path);
20595 +       if (!ret) {
20596 +               ret = __vc_set_iattr(path.dentry,
20597 +                       &vc_data.tag, &vc_data.flags, &vc_data.mask);
20598 +               path_put(&path);
20599 +       }
20600 +
20601 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
20602 +               ret = -EFAULT;
20603 +       return ret;
20604 +}
20605 +
20606 +#ifdef CONFIG_COMPAT
20607 +
20608 +int vc_set_iattr_x32(void __user *data)
20609 +{
20610 +       struct path path;
20611 +       struct vcmd_ctx_iattr_v1_x32 vc_data;
20612 +       int ret;
20613 +
20614 +       if (!capable(CAP_LINUX_IMMUTABLE))
20615 +               return -EPERM;
20616 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
20617 +               return -EFAULT;
20618 +
20619 +       ret = user_lpath(compat_ptr(vc_data.name_ptr), &path);
20620 +       if (!ret) {
20621 +               ret = __vc_set_iattr(path.dentry,
20622 +                       &vc_data.tag, &vc_data.flags, &vc_data.mask);
20623 +               path_put(&path);
20624 +       }
20625 +
20626 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
20627 +               ret = -EFAULT;
20628 +       return ret;
20629 +}
20630 +
20631 +#endif /* CONFIG_COMPAT */
20632 +
20633 +int vc_fset_iattr(uint32_t fd, void __user *data)
20634 +{
20635 +       struct file *filp;
20636 +       struct vcmd_ctx_fiattr_v0 vc_data;
20637 +       int ret;
20638 +
20639 +       if (!capable(CAP_LINUX_IMMUTABLE))
20640 +               return -EPERM;
20641 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
20642 +               return -EFAULT;
20643 +
20644 +       filp = fget(fd);
20645 +       if (!filp || !filp->f_dentry || !filp->f_dentry->d_inode)
20646 +               return -EBADF;
20647 +
20648 +       ret = __vc_set_iattr(filp->f_dentry, &vc_data.tag,
20649 +               &vc_data.flags, &vc_data.mask);
20650 +
20651 +       fput(filp);
20652 +
20653 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
20654 +               return -EFAULT;
20655 +       return ret;
20656 +}
20657 +
20658 +
20659 +enum { Opt_notagcheck, Opt_tag, Opt_notag, Opt_tagid, Opt_err };
20660 +
20661 +static match_table_t tokens = {
20662 +       {Opt_notagcheck, "notagcheck"},
20663 +#ifdef CONFIG_PROPAGATE
20664 +       {Opt_notag, "notag"},
20665 +       {Opt_tag, "tag"},
20666 +       {Opt_tagid, "tagid=%u"},
20667 +#endif
20668 +       {Opt_err, NULL}
20669 +};
20670 +
20671 +
20672 +static void __dx_parse_remove(char *string, char *opt)
20673 +{
20674 +       char *p = strstr(string, opt);
20675 +       char *q = p;
20676 +
20677 +       if (p) {
20678 +               while (*q != '\0' && *q != ',')
20679 +                       q++;
20680 +               while (*q)
20681 +                       *p++ = *q++;
20682 +               while (*p)
20683 +                       *p++ = '\0';
20684 +       }
20685 +}
20686 +
20687 +int dx_parse_tag(char *string, tag_t *tag, int remove, int *mnt_flags,
20688 +                unsigned long *flags)
20689 +{
20690 +       int set = 0;
20691 +       substring_t args[MAX_OPT_ARGS];
20692 +       int token, option = 0;
20693 +       char *s, *p, *opts;
20694 +
20695 +       if (!string)
20696 +               return 0;
20697 +       s = kstrdup(string, GFP_KERNEL | GFP_ATOMIC);
20698 +       if (!s)
20699 +               return 0;
20700 +
20701 +       opts = s;
20702 +       while ((p = strsep(&opts, ",")) != NULL) {
20703 +               token = match_token(p, tokens, args);
20704 +
20705 +               vxdprintk(VXD_CBIT(tag, 7),
20706 +                       "dx_parse_tag(»%s«): %d:#%d",
20707 +                       p, token, option);
20708 +
20709 +               switch (token) {
20710 +#ifdef CONFIG_PROPAGATE
20711 +               case Opt_tag:
20712 +                       if (tag)
20713 +                               *tag = 0;
20714 +                       if (remove)
20715 +                               __dx_parse_remove(s, "tag");
20716 +                       *mnt_flags |= MNT_TAGID;
20717 +                       set |= MNT_TAGID;
20718 +                       break;
20719 +               case Opt_notag:
20720 +                       if (remove)
20721 +                               __dx_parse_remove(s, "notag");
20722 +                       *mnt_flags |= MNT_NOTAG;
20723 +                       set |= MNT_NOTAG;
20724 +                       break;
20725 +               case Opt_tagid:
20726 +                       if (tag && !match_int(args, &option))
20727 +                               *tag = option;
20728 +                       if (remove)
20729 +                               __dx_parse_remove(s, "tagid");
20730 +                       *mnt_flags |= MNT_TAGID;
20731 +                       set |= MNT_TAGID;
20732 +                       break;
20733 +#endif
20734 +               case Opt_notagcheck:
20735 +                       if (remove)
20736 +                               __dx_parse_remove(s, "notagcheck");
20737 +                       *flags |= MS_NOTAGCHECK;
20738 +                       set |= MS_NOTAGCHECK;
20739 +                       break;
20740 +               }
20741 +       }
20742 +       if (set)
20743 +               strcpy(string, s);
20744 +       kfree(s);
20745 +       return set;
20746 +}
20747 +
20748 +#ifdef CONFIG_PROPAGATE
20749 +
20750 +void __dx_propagate_tag(struct nameidata *nd, struct inode *inode)
20751 +{
20752 +       tag_t new_tag = 0;
20753 +       struct vfsmount *mnt;
20754 +       int propagate;
20755 +
20756 +       if (!nd)
20757 +               return;
20758 +       mnt = nd->path.mnt;
20759 +       if (!mnt)
20760 +               return;
20761 +
20762 +       propagate = (mnt->mnt_flags & MNT_TAGID);
20763 +       if (propagate)
20764 +               new_tag = mnt->mnt_tag;
20765 +
20766 +       vxdprintk(VXD_CBIT(tag, 7),
20767 +               "dx_propagate_tag(%p[#%lu.%d]): %d,%d",
20768 +               inode, inode->i_ino, inode->i_tag,
20769 +               new_tag, (propagate) ? 1 : 0);
20770 +
20771 +       if (propagate)
20772 +               inode->i_tag = new_tag;
20773 +}
20774 +
20775 +#include <linux/module.h>
20776 +
20777 +EXPORT_SYMBOL_GPL(__dx_propagate_tag);
20778 +
20779 +#endif /* CONFIG_PROPAGATE */
20780 +
20781 diff -NurpP --minimal linux-2.6.29/kernel/vserver/Kconfig linux-2.6.29-vs2.3.0.36.9-pre3/kernel/vserver/Kconfig
20782 --- linux-2.6.29/kernel/vserver/Kconfig 1970-01-01 01:00:00.000000000 +0100
20783 +++ linux-2.6.29-vs2.3.0.36.9-pre3/kernel/vserver/Kconfig       2009-02-22 22:54:26.000000000 +0100
20784 @@ -0,0 +1,251 @@
20785 +#
20786 +# Linux VServer configuration
20787 +#
20788 +
20789 +menu "Linux VServer"
20790 +
20791 +config VSERVER_AUTO_LBACK
20792 +       bool    "Automatically Assign Loopback IP"
20793 +       default y
20794 +       help
20795 +         Automatically assign a guest specific loopback
20796 +         IP and add it to the kernel network stack on
20797 +         startup.
20798 +
20799 +config VSERVER_AUTO_SINGLE
20800 +       bool    "Automatic Single IP Special Casing"
20801 +       depends on EXPERIMENTAL
20802 +       default y
20803 +       help
20804 +         This allows network contexts with a single IP to
20805 +         automatically remap 0.0.0.0 bindings to that IP,
20806 +         avoiding further network checks and improving
20807 +         performance.
20808 +
20809 +         (note: such guests do not allow to change the ip
20810 +          on the fly and do not show loopback addresses)
20811 +
20812 +config VSERVER_COWBL
20813 +       bool    "Enable COW Immutable Link Breaking"
20814 +       default y
20815 +       help
20816 +         This enables the COW (Copy-On-Write) link break code.
20817 +         It allows you to treat unified files like normal files
20818 +         when writing to them (which will implicitely break the
20819 +         link and create a copy of the unified file)
20820 +
20821 +config VSERVER_VTIME
20822 +       bool    "Enable Virtualized Guest Time"
20823 +       depends on EXPERIMENTAL
20824 +       default n
20825 +       help
20826 +         This enables per guest time offsets to allow for
20827 +         adjusting the system clock individually per guest.
20828 +         this adds some overhead to the time functions and
20829 +         therefore should not be enabled without good reason.
20830 +
20831 +config VSERVER_DEVICE
20832 +       bool    "Enable Guest Device Mapping"
20833 +       depends on EXPERIMENTAL
20834 +       default n
20835 +       help
20836 +         This enables generic device remapping.
20837 +
20838 +config VSERVER_PROC_SECURE
20839 +       bool    "Enable Proc Security"
20840 +       depends on PROC_FS
20841 +       default y
20842 +       help
20843 +         This configures ProcFS security to initially hide
20844 +         non-process entries for all contexts except the main and
20845 +         spectator context (i.e. for all guests), which is a secure
20846 +         default.
20847 +
20848 +         (note: on 1.2x the entries were visible by default)
20849 +
20850 +config VSERVER_HARDCPU
20851 +       bool    "Enable Hard CPU Limits"
20852 +       default y
20853 +       help
20854 +         Activate the Hard CPU Limits
20855 +
20856 +         This will compile in code that allows the Token Bucket
20857 +         Scheduler to put processes on hold when a context's
20858 +         tokens are depleted (provided that its per-context
20859 +         sched_hard flag is set).
20860 +
20861 +         Processes belonging to that context will not be able
20862 +         to consume CPU resources again until a per-context
20863 +         configured minimum of tokens has been reached.
20864 +
20865 +config VSERVER_IDLETIME
20866 +       bool    "Avoid idle CPUs by skipping Time"
20867 +       depends on VSERVER_HARDCPU
20868 +       default y
20869 +       help
20870 +         This option allows the scheduler to artificially
20871 +         advance time (per cpu) when otherwise the idle
20872 +         task would be scheduled, thus keeping the cpu
20873 +         busy and sharing the available resources among
20874 +         certain contexts.
20875 +
20876 +config VSERVER_IDLELIMIT
20877 +       bool    "Limit the IDLE task"
20878 +       depends on VSERVER_HARDCPU
20879 +       default n
20880 +       help
20881 +         Limit the idle slices, so the the next context
20882 +         will be scheduled as soon as possible.
20883 +
20884 +         This might improve interactivity and latency, but
20885 +         will also marginally increase scheduling overhead.
20886 +
20887 +choice
20888 +       prompt  "Persistent Inode Tagging"
20889 +       default TAGGING_ID24
20890 +       help
20891 +         This adds persistent context information to filesystems
20892 +         mounted with the tagxid option. Tagging is a requirement
20893 +         for per-context disk limits and per-context quota.
20894 +
20895 +
20896 +config TAGGING_NONE
20897 +       bool    "Disabled"
20898 +       help
20899 +         do not store per-context information in inodes.
20900 +
20901 +config TAGGING_UID16
20902 +       bool    "UID16/GID32"
20903 +       help
20904 +         reduces UID to 16 bit, but leaves GID at 32 bit.
20905 +
20906 +config TAGGING_GID16
20907 +       bool    "UID32/GID16"
20908 +       help
20909 +         reduces GID to 16 bit, but leaves UID at 32 bit.
20910 +
20911 +config TAGGING_ID24
20912 +       bool    "UID24/GID24"
20913 +       help
20914 +         uses the upper 8bit from UID and GID for XID tagging
20915 +         which leaves 24bit for UID/GID each, which should be
20916 +         more than sufficient for normal use.
20917 +
20918 +config TAGGING_INTERN
20919 +       bool    "UID32/GID32"
20920 +       help
20921 +         this uses otherwise reserved inode fields in the on
20922 +         disk representation, which limits the use to a few
20923 +         filesystems (currently ext2 and ext3)
20924 +
20925 +endchoice
20926 +
20927 +config TAG_NFSD
20928 +       bool    "Tag NFSD User Auth and Files"
20929 +       default n
20930 +       help
20931 +         Enable this if you do want the in-kernel NFS
20932 +         Server to use the tagging specified above.
20933 +         (will require patched clients too)
20934 +
20935 +config VSERVER_PRIVACY
20936 +       bool    "Honor Privacy Aspects of Guests"
20937 +       default n
20938 +       help
20939 +         When enabled, most context checks will disallow
20940 +         access to structures assigned to a specific context,
20941 +         like ptys or loop devices.
20942 +
20943 +config VSERVER_CONTEXTS
20944 +       int     "Maximum number of Contexts (1-65533)"  if EMBEDDED
20945 +       range 1 65533
20946 +       default "768"   if 64BIT
20947 +       default "256"
20948 +       help
20949 +         This setting will optimize certain data structures
20950 +         and memory allocations according to the expected
20951 +         maximum.
20952 +
20953 +         note: this is not a strict upper limit.
20954 +
20955 +config VSERVER_WARN
20956 +       bool    "VServer Warnings"
20957 +       default y
20958 +       help
20959 +         This enables various runtime warnings, which will
20960 +         notify about potential manipulation attempts or
20961 +         resource shortage. It is generally considered to
20962 +         be a good idea to have that enabled.
20963 +
20964 +config VSERVER_DEBUG
20965 +       bool    "VServer Debugging Code"
20966 +       default n
20967 +       help
20968 +         Set this to yes if you want to be able to activate
20969 +         debugging output at runtime. It adds a very small
20970 +         overhead to all vserver related functions and
20971 +         increases the kernel size by about 20k.
20972 +
20973 +config VSERVER_HISTORY
20974 +       bool    "VServer History Tracing"
20975 +       depends on VSERVER_DEBUG
20976 +       default n
20977 +       help
20978 +         Set this to yes if you want to record the history of
20979 +         linux-vserver activities, so they can be replayed in
20980 +         the event of a kernel panic or oops.
20981 +
20982 +config VSERVER_HISTORY_SIZE
20983 +       int     "Per-CPU History Size (32-65536)"
20984 +       depends on VSERVER_HISTORY
20985 +       range 32 65536
20986 +       default 64
20987 +       help
20988 +         This allows you to specify the number of entries in
20989 +         the per-CPU history buffer.
20990 +
20991 +config VSERVER_MONITOR
20992 +       bool    "VServer Scheduling Monitor"
20993 +       depends on VSERVER_DISABLED
20994 +       default n
20995 +       help
20996 +         Set this to yes if you want to record the scheduling
20997 +         decisions, so that they can be relayed to userspace
20998 +         for detailed analysis.
20999 +
21000 +config VSERVER_MONITOR_SIZE
21001 +       int     "Per-CPU Monitor Queue Size (32-65536)"
21002 +       depends on VSERVER_MONITOR
21003 +       range 32 65536
21004 +       default 1024
21005 +       help
21006 +         This allows you to specify the number of entries in
21007 +         the per-CPU scheduling monitor buffer.
21008 +
21009 +config VSERVER_MONITOR_SYNC
21010 +       int     "Per-CPU Monitor Sync Interval (0-65536)"
21011 +       depends on VSERVER_MONITOR
21012 +       range 0 65536
21013 +       default 256
21014 +       help
21015 +         This allows you to specify the interval in ticks
21016 +         when a time sync entry is inserted.
21017 +
21018 +endmenu
21019 +
21020 +
21021 +config VSERVER
21022 +       bool
21023 +       default y
21024 +       select NAMESPACES
21025 +       select UTS_NS
21026 +       select IPC_NS
21027 +       select USER_NS
21028 +       select SYSVIPC
21029 +
21030 +config VSERVER_SECURITY
21031 +       bool
21032 +       depends on SECURITY
21033 +       default y
21034 +       select SECURITY_CAPABILITIES
21035 +
21036 diff -NurpP --minimal linux-2.6.29/kernel/vserver/limit.c linux-2.6.29-vs2.3.0.36.9-pre3/kernel/vserver/limit.c
21037 --- linux-2.6.29/kernel/vserver/limit.c 1970-01-01 01:00:00.000000000 +0100
21038 +++ linux-2.6.29-vs2.3.0.36.9-pre3/kernel/vserver/limit.c       2009-02-22 22:54:26.000000000 +0100
21039 @@ -0,0 +1,319 @@
21040 +/*
21041 + *  linux/kernel/vserver/limit.c
21042 + *
21043 + *  Virtual Server: Context Limits
21044 + *
21045 + *  Copyright (C) 2004-2007  Herbert Pötzl
21046 + *
21047 + *  V0.01  broken out from vcontext V0.05
21048 + *  V0.02  changed vcmds to vxi arg
21049 + *
21050 + */
21051 +
21052 +#include <linux/sched.h>
21053 +#include <linux/module.h>
21054 +#include <linux/vs_limit.h>
21055 +#include <linux/vserver/limit.h>
21056 +#include <linux/vserver/limit_cmd.h>
21057 +
21058 +#include <asm/uaccess.h>
21059 +
21060 +
21061 +const char *vlimit_name[NUM_LIMITS] = {
21062 +       [RLIMIT_CPU]            = "CPU",
21063 +       [RLIMIT_RSS]            = "RSS",
21064 +       [RLIMIT_NPROC]          = "NPROC",
21065 +       [RLIMIT_NOFILE]         = "NOFILE",
21066 +       [RLIMIT_MEMLOCK]        = "VML",
21067 +       [RLIMIT_AS]             = "VM",
21068 +       [RLIMIT_LOCKS]          = "LOCKS",
21069 +       [RLIMIT_SIGPENDING]     = "SIGP",
21070 +       [RLIMIT_MSGQUEUE]       = "MSGQ",
21071 +
21072 +       [VLIMIT_NSOCK]          = "NSOCK",
21073 +       [VLIMIT_OPENFD]         = "OPENFD",
21074 +       [VLIMIT_ANON]           = "ANON",
21075 +       [VLIMIT_SHMEM]          = "SHMEM",
21076 +       [VLIMIT_DENTRY]         = "DENTRY",
21077 +};
21078 +
21079 +EXPORT_SYMBOL_GPL(vlimit_name);
21080 +
21081 +#define MASK_ENTRY(x)  (1 << (x))
21082 +
21083 +const struct vcmd_ctx_rlimit_mask_v0 vlimit_mask = {
21084 +               /* minimum */
21085 +       0
21086 +       ,       /* softlimit */
21087 +       MASK_ENTRY( RLIMIT_RSS          ) |
21088 +       MASK_ENTRY( VLIMIT_ANON         ) |
21089 +       0
21090 +       ,       /* maximum */
21091 +       MASK_ENTRY( RLIMIT_RSS          ) |
21092 +       MASK_ENTRY( RLIMIT_NPROC        ) |
21093 +       MASK_ENTRY( RLIMIT_NOFILE       ) |
21094 +       MASK_ENTRY( RLIMIT_MEMLOCK      ) |
21095 +       MASK_ENTRY( RLIMIT_AS           ) |
21096 +       MASK_ENTRY( RLIMIT_LOCKS        ) |
21097 +       MASK_ENTRY( RLIMIT_MSGQUEUE     ) |
21098 +
21099 +       MASK_ENTRY( VLIMIT_NSOCK        ) |
21100 +       MASK_ENTRY( VLIMIT_OPENFD       ) |
21101 +       MASK_ENTRY( VLIMIT_ANON         ) |
21102 +       MASK_ENTRY( VLIMIT_SHMEM        ) |
21103 +       MASK_ENTRY( VLIMIT_DENTRY       ) |
21104 +       0
21105 +};
21106 +               /* accounting only */
21107 +uint32_t account_mask =
21108 +       MASK_ENTRY( VLIMIT_SEMARY       ) |
21109 +       MASK_ENTRY( VLIMIT_NSEMS        ) |
21110 +       MASK_ENTRY( VLIMIT_MAPPED       ) |
21111 +       0;
21112 +
21113 +
21114 +static int is_valid_vlimit(int id)
21115 +{
21116 +       uint32_t mask = vlimit_mask.minimum |
21117 +               vlimit_mask.softlimit | vlimit_mask.maximum;
21118 +       return mask & (1 << id);
21119 +}
21120 +
21121 +static int is_accounted_vlimit(int id)
21122 +{
21123 +       if (is_valid_vlimit(id))
21124 +               return 1;
21125 +       return account_mask & (1 << id);
21126 +}
21127 +
21128 +
21129 +static inline uint64_t vc_get_soft(struct vx_info *vxi, int id)
21130 +{
21131 +       rlim_t limit = __rlim_soft(&vxi->limit, id);
21132 +       return VX_VLIM(limit);
21133 +}
21134 +
21135 +static inline uint64_t vc_get_hard(struct vx_info *vxi, int id)
21136 +{
21137 +       rlim_t limit = __rlim_hard(&vxi->limit, id);
21138 +       return VX_VLIM(limit);
21139 +}
21140 +
21141 +static int do_get_rlimit(struct vx_info *vxi, uint32_t id,
21142 +       uint64_t *minimum, uint64_t *softlimit, uint64_t *maximum)
21143 +{
21144 +       if (!is_valid_vlimit(id))
21145 +               return -EINVAL;
21146 +
21147 +       if (minimum)
21148 +               *minimum = CRLIM_UNSET;
21149 +       if (softlimit)
21150 +               *softlimit = vc_get_soft(vxi, id);
21151 +       if (maximum)
21152 +               *maximum = vc_get_hard(vxi, id);
21153 +       return 0;
21154 +}
21155 +
21156 +int vc_get_rlimit(struct vx_info *vxi, void __user *data)
21157 +{
21158 +       struct vcmd_ctx_rlimit_v0 vc_data;
21159 +       int ret;
21160 +
21161 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
21162 +               return -EFAULT;
21163 +
21164 +       ret = do_get_rlimit(vxi, vc_data.id,
21165 +               &vc_data.minimum, &vc_data.softlimit, &vc_data.maximum);
21166 +       if (ret)
21167 +               return ret;
21168 +
21169 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
21170 +               return -EFAULT;
21171 +       return 0;
21172 +}
21173 +
21174 +static int do_set_rlimit(struct vx_info *vxi, uint32_t id,
21175 +       uint64_t minimum, uint64_t softlimit, uint64_t maximum)
21176 +{
21177 +       if (!is_valid_vlimit(id))
21178 +               return -EINVAL;
21179 +
21180 +       if (maximum != CRLIM_KEEP)
21181 +               __rlim_hard(&vxi->limit, id) = VX_RLIM(maximum);
21182 +       if (softlimit != CRLIM_KEEP)
21183 +               __rlim_soft(&vxi->limit, id) = VX_RLIM(softlimit);
21184 +
21185 +       /* clamp soft limit */
21186 +       if (__rlim_soft(&vxi->limit, id) > __rlim_hard(&vxi->limit, id))
21187 +               __rlim_soft(&vxi->limit, id) = __rlim_hard(&vxi->limit, id);
21188 +
21189 +       return 0;
21190 +}
21191 +
21192 +int vc_set_rlimit(struct vx_info *vxi, void __user *data)
21193 +{
21194 +       struct vcmd_ctx_rlimit_v0 vc_data;
21195 +
21196 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
21197 +               return -EFAULT;
21198 +
21199 +       return do_set_rlimit(vxi, vc_data.id,
21200 +               vc_data.minimum, vc_data.softlimit, vc_data.maximum);
21201 +}
21202 +
21203 +#ifdef CONFIG_IA32_EMULATION
21204 +
21205 +int vc_set_rlimit_x32(struct vx_info *vxi, void __user *data)
21206 +{
21207 +       struct vcmd_ctx_rlimit_v0_x32 vc_data;
21208 +
21209 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
21210 +               return -EFAULT;
21211 +
21212 +       return do_set_rlimit(vxi, vc_data.id,
21213 +               vc_data.minimum, vc_data.softlimit, vc_data.maximum);
21214 +}
21215 +
21216 +int vc_get_rlimit_x32(struct vx_info *vxi, void __user *data)
21217 +{
21218 +       struct vcmd_ctx_rlimit_v0_x32 vc_data;
21219 +       int ret;
21220 +
21221 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
21222 +               return -EFAULT;
21223 +
21224 +       ret = do_get_rlimit(vxi, vc_data.id,
21225 +               &vc_data.minimum, &vc_data.softlimit, &vc_data.maximum);
21226 +       if (ret)
21227 +               return ret;
21228 +
21229 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
21230 +               return -EFAULT;
21231 +       return 0;
21232 +}
21233 +
21234 +#endif /* CONFIG_IA32_EMULATION */
21235 +
21236 +
21237 +int vc_get_rlimit_mask(uint32_t id, void __user *data)
21238 +{
21239 +       if (copy_to_user(data, &vlimit_mask, sizeof(vlimit_mask)))
21240 +               return -EFAULT;
21241 +       return 0;
21242 +}
21243 +
21244 +
21245 +static inline void vx_reset_minmax(struct _vx_limit *limit)
21246 +{
21247 +       rlim_t value;
21248 +       int lim;
21249 +
21250 +       for (lim = 0; lim < NUM_LIMITS; lim++) {
21251 +               value = __rlim_get(limit, lim);
21252 +               __rlim_rmax(limit, lim) = value;
21253 +               __rlim_rmin(limit, lim) = value;
21254 +       }
21255 +}
21256 +
21257 +
21258 +int vc_reset_minmax(struct vx_info *vxi, void __user *data)
21259 +{
21260 +       vx_reset_minmax(&vxi->limit);
21261 +       return 0;
21262 +}
21263 +
21264 +
21265 +int vc_rlimit_stat(struct vx_info *vxi, void __user *data)
21266 +{
21267 +       struct vcmd_rlimit_stat_v0 vc_data;
21268 +       struct _vx_limit *limit = &vxi->limit;
21269 +       int id;
21270 +
21271 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
21272 +               return -EFAULT;
21273 +
21274 +       id = vc_data.id;
21275 +       if (!is_accounted_vlimit(id))
21276 +               return -EINVAL;
21277 +
21278 +       vx_limit_fixup(limit, id);
21279 +       vc_data.hits = atomic_read(&__rlim_lhit(limit, id));
21280 +       vc_data.value = __rlim_get(limit, id);
21281 +       vc_data.minimum = __rlim_rmin(limit, id);
21282 +       vc_data.maximum = __rlim_rmax(limit, id);
21283 +
21284 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
21285 +               return -EFAULT;
21286 +       return 0;
21287 +}
21288 +
21289 +
21290 +void vx_vsi_meminfo(struct sysinfo *val)
21291 +{
21292 +       struct vx_info *vxi = current->vx_info;
21293 +       unsigned long totalram, freeram;
21294 +       rlim_t v;
21295 +
21296 +       /* we blindly accept the max */
21297 +       v = __rlim_soft(&vxi->limit, RLIMIT_RSS);
21298 +       totalram = (v != RLIM_INFINITY) ? v : val->totalram;
21299 +
21300 +       /* total minus used equals free */
21301 +       v = __vx_cres_array_fixup(&vxi->limit, VLA_RSS);
21302 +       freeram = (v < totalram) ? totalram - v : 0;
21303 +
21304 +       val->totalram = totalram;
21305 +       val->freeram = freeram;
21306 +       val->bufferram = 0;
21307 +       val->totalhigh = 0;
21308 +       val->freehigh = 0;
21309 +       return;
21310 +}
21311 +
21312 +void vx_vsi_swapinfo(struct sysinfo *val)
21313 +{
21314 +       struct vx_info *vxi = current->vx_info;
21315 +       unsigned long totalswap, freeswap;
21316 +       rlim_t v, w;
21317 +
21318 +       v = __rlim_soft(&vxi->limit, RLIMIT_RSS);
21319 +       if (v == RLIM_INFINITY) {
21320 +               val->freeswap = val->totalswap;
21321 +               return;
21322 +       }
21323 +
21324 +       /* we blindly accept the max */
21325 +       w = __rlim_hard(&vxi->limit, RLIMIT_RSS);
21326 +       totalswap = (w != RLIM_INFINITY) ? (w - v) : val->totalswap;
21327 +
21328 +       /* currently 'used' swap */
21329 +       w = __vx_cres_array_fixup(&vxi->limit, VLA_RSS);
21330 +       w -= (w > v) ? v : w;
21331 +
21332 +       /* total minus used equals free */
21333 +       freeswap = (w < totalswap) ? totalswap - w : 0;
21334 +
21335 +       val->totalswap = totalswap;
21336 +       val->freeswap = freeswap;
21337 +       return;
21338 +}
21339 +
21340 +
21341 +unsigned long vx_badness(struct task_struct *task, struct mm_struct *mm)
21342 +{
21343 +       struct vx_info *vxi = mm->mm_vx_info;
21344 +       unsigned long points;
21345 +       rlim_t v, w;
21346 +
21347 +       if (!vxi)
21348 +               return 0;
21349 +
21350 +       points = vxi->vx_badness_bias;
21351 +
21352 +       v = __vx_cres_array_fixup(&vxi->limit, VLA_RSS);
21353 +       w = __rlim_soft(&vxi->limit, RLIMIT_RSS);
21354 +       points += (v > w) ? (v - w) : 0;
21355 +
21356 +       return points;
21357 +}
21358 +
21359 diff -NurpP --minimal linux-2.6.29/kernel/vserver/limit_init.h linux-2.6.29-vs2.3.0.36.9-pre3/kernel/vserver/limit_init.h
21360 --- linux-2.6.29/kernel/vserver/limit_init.h    1970-01-01 01:00:00.000000000 +0100
21361 +++ linux-2.6.29-vs2.3.0.36.9-pre3/kernel/vserver/limit_init.h  2009-02-22 22:54:26.000000000 +0100
21362 @@ -0,0 +1,31 @@
21363 +
21364 +
21365 +static inline void vx_info_init_limit(struct _vx_limit *limit)
21366 +{
21367 +       int lim;
21368 +
21369 +       for (lim = 0; lim < NUM_LIMITS; lim++) {
21370 +               __rlim_soft(limit, lim) = RLIM_INFINITY;
21371 +               __rlim_hard(limit, lim) = RLIM_INFINITY;
21372 +               __rlim_set(limit, lim, 0);
21373 +               atomic_set(&__rlim_lhit(limit, lim), 0);
21374 +               __rlim_rmin(limit, lim) = 0;
21375 +               __rlim_rmax(limit, lim) = 0;
21376 +       }
21377 +}
21378 +
21379 +static inline void vx_info_exit_limit(struct _vx_limit *limit)
21380 +{
21381 +       rlim_t value;
21382 +       int lim;
21383 +
21384 +       for (lim = 0; lim < NUM_LIMITS; lim++) {
21385 +               if ((1 << lim) & VLIM_NOCHECK)
21386 +                       continue;
21387 +               value = __rlim_get(limit, lim);
21388 +               vxwprintk_xid(value,
21389 +                       "!!! limit: %p[%s,%d] = %ld on exit.",
21390 +                       limit, vlimit_name[lim], lim, (long)value);
21391 +       }
21392 +}
21393 +
21394 diff -NurpP --minimal linux-2.6.29/kernel/vserver/limit_proc.h linux-2.6.29-vs2.3.0.36.9-pre3/kernel/vserver/limit_proc.h
21395 --- linux-2.6.29/kernel/vserver/limit_proc.h    1970-01-01 01:00:00.000000000 +0100
21396 +++ linux-2.6.29-vs2.3.0.36.9-pre3/kernel/vserver/limit_proc.h  2009-02-22 22:54:26.000000000 +0100
21397 @@ -0,0 +1,57 @@
21398 +#ifndef _VX_LIMIT_PROC_H
21399 +#define _VX_LIMIT_PROC_H
21400 +
21401 +#include <linux/vserver/limit_int.h>
21402 +
21403 +
21404 +#define VX_LIMIT_FMT   ":\t%8ld\t%8ld/%8ld\t%8lld/%8lld\t%6d\n"
21405 +#define VX_LIMIT_TOP   \
21406 +       "Limit\t current\t     min/max\t\t    soft/hard\t\thits\n"
21407 +
21408 +#define VX_LIMIT_ARG(r)                                \
21409 +       (unsigned long)__rlim_get(limit, r),    \
21410 +       (unsigned long)__rlim_rmin(limit, r),   \
21411 +       (unsigned long)__rlim_rmax(limit, r),   \
21412 +       VX_VLIM(__rlim_soft(limit, r)),         \
21413 +       VX_VLIM(__rlim_hard(limit, r)),         \
21414 +       atomic_read(&__rlim_lhit(limit, r))
21415 +
21416 +static inline int vx_info_proc_limit(struct _vx_limit *limit, char *buffer)
21417 +{
21418 +       vx_limit_fixup(limit, -1);
21419 +       return sprintf(buffer, VX_LIMIT_TOP
21420 +               "PROC"  VX_LIMIT_FMT
21421 +               "VM"    VX_LIMIT_FMT
21422 +               "VML"   VX_LIMIT_FMT
21423 +               "RSS"   VX_LIMIT_FMT
21424 +               "ANON"  VX_LIMIT_FMT
21425 +               "RMAP"  VX_LIMIT_FMT
21426 +               "FILES" VX_LIMIT_FMT
21427 +               "OFD"   VX_LIMIT_FMT
21428 +               "LOCKS" VX_LIMIT_FMT
21429 +               "SOCK"  VX_LIMIT_FMT
21430 +               "MSGQ"  VX_LIMIT_FMT
21431 +               "SHM"   VX_LIMIT_FMT
21432 +               "SEMA"  VX_LIMIT_FMT
21433 +               "SEMS"  VX_LIMIT_FMT
21434 +               "DENT"  VX_LIMIT_FMT,
21435 +               VX_LIMIT_ARG(RLIMIT_NPROC),
21436 +               VX_LIMIT_ARG(RLIMIT_AS),
21437 +               VX_LIMIT_ARG(RLIMIT_MEMLOCK),
21438 +               VX_LIMIT_ARG(RLIMIT_RSS),
21439 +               VX_LIMIT_ARG(VLIMIT_ANON),
21440 +               VX_LIMIT_ARG(VLIMIT_MAPPED),
21441 +               VX_LIMIT_ARG(RLIMIT_NOFILE),
21442 +               VX_LIMIT_ARG(VLIMIT_OPENFD),
21443 +               VX_LIMIT_ARG(RLIMIT_LOCKS),
21444 +               VX_LIMIT_ARG(VLIMIT_NSOCK),
21445 +               VX_LIMIT_ARG(RLIMIT_MSGQUEUE),
21446 +               VX_LIMIT_ARG(VLIMIT_SHMEM),
21447 +               VX_LIMIT_ARG(VLIMIT_SEMARY),
21448 +               VX_LIMIT_ARG(VLIMIT_NSEMS),
21449 +               VX_LIMIT_ARG(VLIMIT_DENTRY));
21450 +}
21451 +
21452 +#endif /* _VX_LIMIT_PROC_H */
21453 +
21454 +
21455 diff -NurpP --minimal linux-2.6.29/kernel/vserver/Makefile linux-2.6.29-vs2.3.0.36.9-pre3/kernel/vserver/Makefile
21456 --- linux-2.6.29/kernel/vserver/Makefile        1970-01-01 01:00:00.000000000 +0100
21457 +++ linux-2.6.29-vs2.3.0.36.9-pre3/kernel/vserver/Makefile      2009-02-22 22:54:26.000000000 +0100
21458 @@ -0,0 +1,18 @@
21459 +#
21460 +# Makefile for the Linux vserver routines.
21461 +#
21462 +
21463 +
21464 +obj-y          += vserver.o
21465 +
21466 +vserver-y      := switch.o context.o space.o sched.o network.o inode.o \
21467 +                  limit.o cvirt.o cacct.o signal.o helper.o init.o \
21468 +                  dlimit.o tag.o
21469 +
21470 +vserver-$(CONFIG_INET) += inet.o
21471 +vserver-$(CONFIG_PROC_FS) += proc.o
21472 +vserver-$(CONFIG_VSERVER_DEBUG) += sysctl.o debug.o
21473 +vserver-$(CONFIG_VSERVER_HISTORY) += history.o
21474 +vserver-$(CONFIG_VSERVER_MONITOR) += monitor.o
21475 +vserver-$(CONFIG_VSERVER_DEVICE) += device.o
21476 +
21477 diff -NurpP --minimal linux-2.6.29/kernel/vserver/monitor.c linux-2.6.29-vs2.3.0.36.9-pre3/kernel/vserver/monitor.c
21478 --- linux-2.6.29/kernel/vserver/monitor.c       1970-01-01 01:00:00.000000000 +0100
21479 +++ linux-2.6.29-vs2.3.0.36.9-pre3/kernel/vserver/monitor.c     2009-02-22 22:54:26.000000000 +0100
21480 @@ -0,0 +1,138 @@
21481 +/*
21482 + *  kernel/vserver/monitor.c
21483 + *
21484 + *  Virtual Context Scheduler Monitor
21485 + *
21486 + *  Copyright (C) 2006-2007 Herbert Pötzl
21487 + *
21488 + *  V0.01  basic design
21489 + *
21490 + */
21491 +
21492 +#include <linux/module.h>
21493 +#include <linux/jiffies.h>
21494 +#include <asm/uaccess.h>
21495 +#include <asm/atomic.h>
21496 +
21497 +#include <linux/vserver/monitor.h>
21498 +#include <linux/vserver/debug_cmd.h>
21499 +
21500 +
21501 +#ifdef CONFIG_VSERVER_MONITOR
21502 +#define VXM_SIZE       CONFIG_VSERVER_MONITOR_SIZE
21503 +#else
21504 +#define VXM_SIZE       64
21505 +#endif
21506 +
21507 +struct _vx_monitor {
21508 +       unsigned int counter;
21509 +
21510 +       struct _vx_mon_entry entry[VXM_SIZE+1];
21511 +};
21512 +
21513 +
21514 +DEFINE_PER_CPU(struct _vx_monitor, vx_monitor_buffer);
21515 +
21516 +unsigned volatile int vxm_active = 1;
21517 +
21518 +static atomic_t sequence = ATOMIC_INIT(0);
21519 +
21520 +
21521 +/*     vxm_advance()
21522 +
21523 +       * requires disabled preemption                          */
21524 +
21525 +struct _vx_mon_entry *vxm_advance(int cpu)
21526 +{
21527 +       struct _vx_monitor *mon = &per_cpu(vx_monitor_buffer, cpu);
21528 +       struct _vx_mon_entry *entry;
21529 +       unsigned int index;
21530 +
21531 +       index = vxm_active ? (mon->counter++ % VXM_SIZE) : VXM_SIZE;
21532 +       entry = &mon->entry[index];
21533 +
21534 +       entry->ev.seq = atomic_inc_return(&sequence);
21535 +       entry->ev.jif = jiffies;
21536 +       return entry;
21537 +}
21538 +
21539 +EXPORT_SYMBOL_GPL(vxm_advance);
21540 +
21541 +
21542 +int do_read_monitor(struct __user _vx_mon_entry *data,
21543 +       int cpu, uint32_t *index, uint32_t *count)
21544 +{
21545 +       int pos, ret = 0;
21546 +       struct _vx_monitor *mon = &per_cpu(vx_monitor_buffer, cpu);
21547 +       int end = mon->counter;
21548 +       int start = end - VXM_SIZE + 2;
21549 +       int idx = *index;
21550 +
21551 +       /* special case: get current pos */
21552 +       if (!*count) {
21553 +               *index = end;
21554 +               return 0;
21555 +       }
21556 +
21557 +       /* have we lost some data? */
21558 +       if (idx < start)
21559 +               idx = start;
21560 +
21561 +       for (pos = 0; (pos < *count) && (idx < end); pos++, idx++) {
21562 +               struct _vx_mon_entry *entry =
21563 +                       &mon->entry[idx % VXM_SIZE];
21564 +
21565 +               /* send entry to userspace */
21566 +               ret = copy_to_user(&data[pos], entry, sizeof(*entry));
21567 +               if (ret)
21568 +                       break;
21569 +       }
21570 +       /* save new index and count */
21571 +       *index = idx;
21572 +       *count = pos;
21573 +       return ret ? ret : (*index < end);
21574 +}
21575 +
21576 +int vc_read_monitor(uint32_t id, void __user *data)
21577 +{
21578 +       struct vcmd_read_monitor_v0 vc_data;
21579 +       int ret;
21580 +
21581 +       if (id >= NR_CPUS)
21582 +               return -EINVAL;
21583 +
21584 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
21585 +               return -EFAULT;
21586 +
21587 +       ret = do_read_monitor((struct __user _vx_mon_entry *)vc_data.data,
21588 +               id, &vc_data.index, &vc_data.count);
21589 +
21590 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
21591 +               return -EFAULT;
21592 +       return ret;
21593 +}
21594 +
21595 +#ifdef CONFIG_COMPAT
21596 +
21597 +int vc_read_monitor_x32(uint32_t id, void __user *data)
21598 +{
21599 +       struct vcmd_read_monitor_v0_x32 vc_data;
21600 +       int ret;
21601 +
21602 +       if (id >= NR_CPUS)
21603 +               return -EINVAL;
21604 +
21605 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
21606 +               return -EFAULT;
21607 +
21608 +       ret = do_read_monitor((struct __user _vx_mon_entry *)
21609 +               compat_ptr(vc_data.data_ptr),
21610 +               id, &vc_data.index, &vc_data.count);
21611 +
21612 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
21613 +               return -EFAULT;
21614 +       return ret;
21615 +}
21616 +
21617 +#endif /* CONFIG_COMPAT */
21618 +
21619 diff -NurpP --minimal linux-2.6.29/kernel/vserver/network.c linux-2.6.29-vs2.3.0.36.9-pre3/kernel/vserver/network.c
21620 --- linux-2.6.29/kernel/vserver/network.c       1970-01-01 01:00:00.000000000 +0100
21621 +++ linux-2.6.29-vs2.3.0.36.9-pre3/kernel/vserver/network.c     2009-02-22 22:54:26.000000000 +0100
21622 @@ -0,0 +1,864 @@
21623 +/*
21624 + *  linux/kernel/vserver/network.c
21625 + *
21626 + *  Virtual Server: Network Support
21627 + *
21628 + *  Copyright (C) 2003-2007  Herbert Pötzl
21629 + *
21630 + *  V0.01  broken out from vcontext V0.05
21631 + *  V0.02  cleaned up implementation
21632 + *  V0.03  added equiv nx commands
21633 + *  V0.04  switch to RCU based hash
21634 + *  V0.05  and back to locking again
21635 + *  V0.06  changed vcmds to nxi arg
21636 + *  V0.07  have __create claim() the nxi
21637 + *
21638 + */
21639 +
21640 +#include <linux/err.h>
21641 +#include <linux/slab.h>
21642 +#include <linux/rcupdate.h>
21643 +
21644 +#include <linux/vs_network.h>
21645 +#include <linux/vs_pid.h>
21646 +#include <linux/vserver/network_cmd.h>
21647 +
21648 +
21649 +atomic_t nx_global_ctotal      = ATOMIC_INIT(0);
21650 +atomic_t nx_global_cactive     = ATOMIC_INIT(0);
21651 +
21652 +static struct kmem_cache *nx_addr_v4_cachep = NULL;
21653 +static struct kmem_cache *nx_addr_v6_cachep = NULL;
21654 +
21655 +
21656 +static int __init init_network(void)
21657 +{
21658 +       nx_addr_v4_cachep = kmem_cache_create("nx_v4_addr_cache",
21659 +               sizeof(struct nx_addr_v4), 0,
21660 +               SLAB_HWCACHE_ALIGN|SLAB_PANIC, NULL);
21661 +       nx_addr_v6_cachep = kmem_cache_create("nx_v6_addr_cache",
21662 +               sizeof(struct nx_addr_v6), 0,
21663 +               SLAB_HWCACHE_ALIGN|SLAB_PANIC, NULL);
21664 +       return 0;
21665 +}
21666 +
21667 +
21668 +/*     __alloc_nx_addr_v4()                                    */
21669 +
21670 +static inline struct nx_addr_v4 *__alloc_nx_addr_v4(void)
21671 +{
21672 +       struct nx_addr_v4 *nxa = kmem_cache_alloc(
21673 +               nx_addr_v4_cachep, GFP_KERNEL);
21674 +
21675 +       if (!IS_ERR(nxa))
21676 +               memset(nxa, 0, sizeof(*nxa));
21677 +       return nxa;
21678 +}
21679 +
21680 +/*     __dealloc_nx_addr_v4()                                  */
21681 +
21682 +static inline void __dealloc_nx_addr_v4(struct nx_addr_v4 *nxa)
21683 +{
21684 +       kmem_cache_free(nx_addr_v4_cachep, nxa);
21685 +}
21686 +
21687 +/*     __dealloc_nx_addr_v4_all()                              */
21688 +
21689 +static inline void __dealloc_nx_addr_v4_all(struct nx_addr_v4 *nxa)
21690 +{
21691 +       while (nxa) {
21692 +               struct nx_addr_v4 *next = nxa->next;
21693 +
21694 +               __dealloc_nx_addr_v4(nxa);
21695 +               nxa = next;
21696 +       }
21697 +}
21698 +
21699 +
21700 +#ifdef CONFIG_IPV6
21701 +
21702 +/*     __alloc_nx_addr_v6()                                    */
21703 +
21704 +static inline struct nx_addr_v6 *__alloc_nx_addr_v6(void)
21705 +{
21706 +       struct nx_addr_v6 *nxa = kmem_cache_alloc(
21707 +               nx_addr_v6_cachep, GFP_KERNEL);
21708 +
21709 +       if (!IS_ERR(nxa))
21710 +               memset(nxa, 0, sizeof(*nxa));
21711 +       return nxa;
21712 +}
21713 +
21714 +/*     __dealloc_nx_addr_v6()                                  */
21715 +
21716 +static inline void __dealloc_nx_addr_v6(struct nx_addr_v6 *nxa)
21717 +{
21718 +       kmem_cache_free(nx_addr_v6_cachep, nxa);
21719 +}
21720 +
21721 +/*     __dealloc_nx_addr_v6_all()                              */
21722 +
21723 +static inline void __dealloc_nx_addr_v6_all(struct nx_addr_v6 *nxa)
21724 +{
21725 +       while (nxa) {
21726 +               struct nx_addr_v6 *next = nxa->next;
21727 +
21728 +               __dealloc_nx_addr_v6(nxa);
21729 +               nxa = next;
21730 +       }
21731 +}
21732 +
21733 +#endif /* CONFIG_IPV6 */
21734 +
21735 +/*     __alloc_nx_info()
21736 +
21737 +       * allocate an initialized nx_info struct
21738 +       * doesn't make it visible (hash)                        */
21739 +
21740 +static struct nx_info *__alloc_nx_info(nid_t nid)
21741 +{
21742 +       struct nx_info *new = NULL;
21743 +
21744 +       vxdprintk(VXD_CBIT(nid, 1), "alloc_nx_info(%d)*", nid);
21745 +
21746 +       /* would this benefit from a slab cache? */
21747 +       new = kmalloc(sizeof(struct nx_info), GFP_KERNEL);
21748 +       if (!new)
21749 +               return 0;
21750 +
21751 +       memset(new, 0, sizeof(struct nx_info));
21752 +       new->nx_id = nid;
21753 +       INIT_HLIST_NODE(&new->nx_hlist);
21754 +       atomic_set(&new->nx_usecnt, 0);
21755 +       atomic_set(&new->nx_tasks, 0);
21756 +       new->nx_state = 0;
21757 +
21758 +       new->nx_flags = NXF_INIT_SET;
21759 +
21760 +       /* rest of init goes here */
21761 +
21762 +       new->v4_lback.s_addr = htonl(INADDR_LOOPBACK);
21763 +       new->v4_bcast.s_addr = htonl(INADDR_BROADCAST);
21764 +
21765 +       vxdprintk(VXD_CBIT(nid, 0),
21766 +               "alloc_nx_info(%d) = %p", nid, new);
21767 +       atomic_inc(&nx_global_ctotal);
21768 +       return new;
21769 +}
21770 +
21771 +/*     __dealloc_nx_info()
21772 +
21773 +       * final disposal of nx_info                             */
21774 +
21775 +static void __dealloc_nx_info(struct nx_info *nxi)
21776 +{
21777 +       vxdprintk(VXD_CBIT(nid, 0),
21778 +               "dealloc_nx_info(%p)", nxi);
21779 +
21780 +       nxi->nx_hlist.next = LIST_POISON1;
21781 +       nxi->nx_id = -1;
21782 +
21783 +       BUG_ON(atomic_read(&nxi->nx_usecnt));
21784 +       BUG_ON(atomic_read(&nxi->nx_tasks));
21785 +
21786 +       __dealloc_nx_addr_v4_all(nxi->v4.next);
21787 +
21788 +       nxi->nx_state |= NXS_RELEASED;
21789 +       kfree(nxi);
21790 +       atomic_dec(&nx_global_ctotal);
21791 +}
21792 +
21793 +static void __shutdown_nx_info(struct nx_info *nxi)
21794 +{
21795 +       nxi->nx_state |= NXS_SHUTDOWN;
21796 +       vs_net_change(nxi, VSC_NETDOWN);
21797 +}
21798 +
21799 +/*     exported stuff                                          */
21800 +
21801 +void free_nx_info(struct nx_info *nxi)
21802 +{
21803 +       /* context shutdown is mandatory */
21804 +       BUG_ON(nxi->nx_state != NXS_SHUTDOWN);
21805 +
21806 +       /* context must not be hashed */
21807 +       BUG_ON(nxi->nx_state & NXS_HASHED);
21808 +
21809 +       BUG_ON(atomic_read(&nxi->nx_usecnt));
21810 +       BUG_ON(atomic_read(&nxi->nx_tasks));
21811 +
21812 +       __dealloc_nx_info(nxi);
21813 +}
21814 +
21815 +
21816 +void __nx_set_lback(struct nx_info *nxi)
21817 +{
21818 +       int nid = nxi->nx_id;
21819 +       __be32 lback = htonl(INADDR_LOOPBACK ^ ((nid & 0xFFFF) << 8));
21820 +
21821 +       nxi->v4_lback.s_addr = lback;
21822 +}
21823 +
21824 +extern int __nx_inet_add_lback(__be32 addr);
21825 +extern int __nx_inet_del_lback(__be32 addr);
21826 +
21827 +
21828 +/*     hash table for nx_info hash */
21829 +
21830 +#define NX_HASH_SIZE   13
21831 +
21832 +struct hlist_head nx_info_hash[NX_HASH_SIZE];
21833 +
21834 +static spinlock_t nx_info_hash_lock = SPIN_LOCK_UNLOCKED;
21835 +
21836 +
21837 +static inline unsigned int __hashval(nid_t nid)
21838 +{
21839 +       return (nid % NX_HASH_SIZE);
21840 +}
21841 +
21842 +
21843 +
21844 +/*     __hash_nx_info()
21845 +
21846 +       * add the nxi to the global hash table
21847 +       * requires the hash_lock to be held                     */
21848 +
21849 +static inline void __hash_nx_info(struct nx_info *nxi)
21850 +{
21851 +       struct hlist_head *head;
21852 +
21853 +       vxd_assert_lock(&nx_info_hash_lock);
21854 +       vxdprintk(VXD_CBIT(nid, 4),
21855 +               "__hash_nx_info: %p[#%d]", nxi, nxi->nx_id);
21856 +
21857 +       /* context must not be hashed */
21858 +       BUG_ON(nx_info_state(nxi, NXS_HASHED));
21859 +
21860 +       nxi->nx_state |= NXS_HASHED;
21861 +       head = &nx_info_hash[__hashval(nxi->nx_id)];
21862 +       hlist_add_head(&nxi->nx_hlist, head);
21863 +       atomic_inc(&nx_global_cactive);
21864 +}
21865 +
21866 +/*     __unhash_nx_info()
21867 +
21868 +       * remove the nxi from the global hash table
21869 +       * requires the hash_lock to be held                     */
21870 +
21871 +static inline void __unhash_nx_info(struct nx_info *nxi)
21872 +{
21873 +       vxd_assert_lock(&nx_info_hash_lock);
21874 +       vxdprintk(VXD_CBIT(nid, 4),
21875 +               "__unhash_nx_info: %p[#%d.%d.%d]", nxi, nxi->nx_id,
21876 +               atomic_read(&nxi->nx_usecnt), atomic_read(&nxi->nx_tasks));
21877 +
21878 +       /* context must be hashed */
21879 +       BUG_ON(!nx_info_state(nxi, NXS_HASHED));
21880 +       /* but without tasks */
21881 +       BUG_ON(atomic_read(&nxi->nx_tasks));
21882 +
21883 +       nxi->nx_state &= ~NXS_HASHED;
21884 +       hlist_del(&nxi->nx_hlist);
21885 +       atomic_dec(&nx_global_cactive);
21886 +}
21887 +
21888 +
21889 +/*     __lookup_nx_info()
21890 +
21891 +       * requires the hash_lock to be held
21892 +       * doesn't increment the nx_refcnt                       */
21893 +
21894 +static inline struct nx_info *__lookup_nx_info(nid_t nid)
21895 +{
21896 +       struct hlist_head *head = &nx_info_hash[__hashval(nid)];
21897 +       struct hlist_node *pos;
21898 +       struct nx_info *nxi;
21899 +
21900 +       vxd_assert_lock(&nx_info_hash_lock);
21901 +       hlist_for_each(pos, head) {
21902 +               nxi = hlist_entry(pos, struct nx_info, nx_hlist);
21903 +
21904 +               if (nxi->nx_id == nid)
21905 +                       goto found;
21906 +       }
21907 +       nxi = NULL;
21908 +found:
21909 +       vxdprintk(VXD_CBIT(nid, 0),
21910 +               "__lookup_nx_info(#%u): %p[#%u]",
21911 +               nid, nxi, nxi ? nxi->nx_id : 0);
21912 +       return nxi;
21913 +}
21914 +
21915 +
21916 +/*     __create_nx_info()
21917 +
21918 +       * create the requested context
21919 +       * get(), claim() and hash it                            */
21920 +
21921 +static struct nx_info *__create_nx_info(int id)
21922 +{
21923 +       struct nx_info *new, *nxi = NULL;
21924 +
21925 +       vxdprintk(VXD_CBIT(nid, 1), "create_nx_info(%d)*", id);
21926 +
21927 +       if (!(new = __alloc_nx_info(id)))
21928 +               return ERR_PTR(-ENOMEM);
21929 +
21930 +       /* required to make dynamic xids unique */
21931 +       spin_lock(&nx_info_hash_lock);
21932 +
21933 +       /* static context requested */
21934 +       if ((nxi = __lookup_nx_info(id))) {
21935 +               vxdprintk(VXD_CBIT(nid, 0),
21936 +                       "create_nx_info(%d) = %p (already there)", id, nxi);
21937 +               if (nx_info_flags(nxi, NXF_STATE_SETUP, 0))
21938 +                       nxi = ERR_PTR(-EBUSY);
21939 +               else
21940 +                       nxi = ERR_PTR(-EEXIST);
21941 +               goto out_unlock;
21942 +       }
21943 +       /* new context */
21944 +       vxdprintk(VXD_CBIT(nid, 0),
21945 +               "create_nx_info(%d) = %p (new)", id, new);
21946 +       claim_nx_info(new, NULL);
21947 +       __nx_set_lback(new);
21948 +       __hash_nx_info(get_nx_info(new));
21949 +       nxi = new, new = NULL;
21950 +
21951 +out_unlock:
21952 +       spin_unlock(&nx_info_hash_lock);
21953 +       if (new)
21954 +               __dealloc_nx_info(new);
21955 +       return nxi;
21956 +}
21957 +
21958 +
21959 +
21960 +/*     exported stuff                                          */
21961 +
21962 +
21963 +void unhash_nx_info(struct nx_info *nxi)
21964 +{
21965 +       __shutdown_nx_info(nxi);
21966 +       spin_lock(&nx_info_hash_lock);
21967 +       __unhash_nx_info(nxi);
21968 +       spin_unlock(&nx_info_hash_lock);
21969 +}
21970 +
21971 +/*     lookup_nx_info()
21972 +
21973 +       * search for a nx_info and get() it
21974 +       * negative id means current                             */
21975 +
21976 +struct nx_info *lookup_nx_info(int id)
21977 +{
21978 +       struct nx_info *nxi = NULL;
21979 +
21980 +       if (id < 0) {
21981 +               nxi = get_nx_info(current->nx_info);
21982 +       } else if (id > 1) {
21983 +               spin_lock(&nx_info_hash_lock);
21984 +               nxi = get_nx_info(__lookup_nx_info(id));
21985 +               spin_unlock(&nx_info_hash_lock);
21986 +       }
21987 +       return nxi;
21988 +}
21989 +
21990 +/*     nid_is_hashed()
21991 +
21992 +       * verify that nid is still hashed                       */
21993 +
21994 +int nid_is_hashed(nid_t nid)
21995 +{
21996 +       int hashed;
21997 +
21998 +       spin_lock(&nx_info_hash_lock);
21999 +       hashed = (__lookup_nx_info(nid) != NULL);
22000 +       spin_unlock(&nx_info_hash_lock);
22001 +       return hashed;
22002 +}
22003 +
22004 +
22005 +#ifdef CONFIG_PROC_FS
22006 +
22007 +/*     get_nid_list()
22008 +
22009 +       * get a subset of hashed nids for proc
22010 +       * assumes size is at least one                          */
22011 +
22012 +int get_nid_list(int index, unsigned int *nids, int size)
22013 +{
22014 +       int hindex, nr_nids = 0;
22015 +
22016 +       /* only show current and children */
22017 +       if (!nx_check(0, VS_ADMIN | VS_WATCH)) {
22018 +               if (index > 0)
22019 +                       return 0;
22020 +               nids[nr_nids] = nx_current_nid();
22021 +               return 1;
22022 +       }
22023 +
22024 +       for (hindex = 0; hindex < NX_HASH_SIZE; hindex++) {
22025 +               struct hlist_head *head = &nx_info_hash[hindex];
22026 +               struct hlist_node *pos;
22027 +
22028 +               spin_lock(&nx_info_hash_lock);
22029 +               hlist_for_each(pos, head) {
22030 +                       struct nx_info *nxi;
22031 +
22032 +                       if (--index > 0)
22033 +                               continue;
22034 +
22035 +                       nxi = hlist_entry(pos, struct nx_info, nx_hlist);
22036 +                       nids[nr_nids] = nxi->nx_id;
22037 +                       if (++nr_nids >= size) {
22038 +                               spin_unlock(&nx_info_hash_lock);
22039 +                               goto out;
22040 +                       }
22041 +               }
22042 +               /* keep the lock time short */
22043 +               spin_unlock(&nx_info_hash_lock);
22044 +       }
22045 +out:
22046 +       return nr_nids;
22047 +}
22048 +#endif
22049 +
22050 +
22051 +/*
22052 + *     migrate task to new network
22053 + *     gets nxi, puts old_nxi on change
22054 + */
22055 +
22056 +int nx_migrate_task(struct task_struct *p, struct nx_info *nxi)
22057 +{
22058 +       struct nx_info *old_nxi;
22059 +       int ret = 0;
22060 +
22061 +       if (!p || !nxi)
22062 +               BUG();
22063 +
22064 +       vxdprintk(VXD_CBIT(nid, 5),
22065 +               "nx_migrate_task(%p,%p[#%d.%d.%d])",
22066 +               p, nxi, nxi->nx_id,
22067 +               atomic_read(&nxi->nx_usecnt),
22068 +               atomic_read(&nxi->nx_tasks));
22069 +
22070 +       if (nx_info_flags(nxi, NXF_INFO_PRIVATE, 0) &&
22071 +               !nx_info_flags(nxi, NXF_STATE_SETUP, 0))
22072 +               return -EACCES;
22073 +
22074 +       if (nx_info_state(nxi, NXS_SHUTDOWN))
22075 +               return -EFAULT;
22076 +
22077 +       /* maybe disallow this completely? */
22078 +       old_nxi = task_get_nx_info(p);
22079 +       if (old_nxi == nxi)
22080 +               goto out;
22081 +
22082 +       task_lock(p);
22083 +       if (old_nxi)
22084 +               clr_nx_info(&p->nx_info);
22085 +       claim_nx_info(nxi, p);
22086 +       set_nx_info(&p->nx_info, nxi);
22087 +       p->nid = nxi->nx_id;
22088 +       task_unlock(p);
22089 +
22090 +       vxdprintk(VXD_CBIT(nid, 5),
22091 +               "moved task %p into nxi:%p[#%d]",
22092 +               p, nxi, nxi->nx_id);
22093 +
22094 +       if (old_nxi)
22095 +               release_nx_info(old_nxi, p);
22096 +       ret = 0;
22097 +out:
22098 +       put_nx_info(old_nxi);
22099 +       return ret;
22100 +}
22101 +
22102 +
22103 +void nx_set_persistent(struct nx_info *nxi)
22104 +{
22105 +       vxdprintk(VXD_CBIT(nid, 6),
22106 +               "nx_set_persistent(%p[#%d])", nxi, nxi->nx_id);
22107 +
22108 +       get_nx_info(nxi);
22109 +       claim_nx_info(nxi, NULL);
22110 +}
22111 +
22112 +void nx_clear_persistent(struct nx_info *nxi)
22113 +{
22114 +       vxdprintk(VXD_CBIT(nid, 6),
22115 +               "nx_clear_persistent(%p[#%d])", nxi, nxi->nx_id);
22116 +
22117 +       release_nx_info(nxi, NULL);
22118 +       put_nx_info(nxi);
22119 +}
22120 +
22121 +void nx_update_persistent(struct nx_info *nxi)
22122 +{
22123 +       if (nx_info_flags(nxi, NXF_PERSISTENT, 0))
22124 +               nx_set_persistent(nxi);
22125 +       else
22126 +               nx_clear_persistent(nxi);
22127 +}
22128 +
22129 +/* vserver syscall commands below here */
22130 +
22131 +/* taks nid and nx_info functions */
22132 +
22133 +#include <asm/uaccess.h>
22134 +
22135 +
22136 +int vc_task_nid(uint32_t id)
22137 +{
22138 +       nid_t nid;
22139 +
22140 +       if (id) {
22141 +               struct task_struct *tsk;
22142 +
22143 +               read_lock(&tasklist_lock);
22144 +               tsk = find_task_by_real_pid(id);
22145 +               nid = (tsk) ? tsk->nid : -ESRCH;
22146 +               read_unlock(&tasklist_lock);
22147 +       } else
22148 +               nid = nx_current_nid();
22149 +       return nid;
22150 +}
22151 +
22152 +
22153 +int vc_nx_info(struct nx_info *nxi, void __user *data)
22154 +{
22155 +       struct vcmd_nx_info_v0 vc_data;
22156 +
22157 +       vc_data.nid = nxi->nx_id;
22158 +
22159 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
22160 +               return -EFAULT;
22161 +       return 0;
22162 +}
22163 +
22164 +
22165 +/* network functions */
22166 +
22167 +int vc_net_create(uint32_t nid, void __user *data)
22168 +{
22169 +       struct vcmd_net_create vc_data = { .flagword = NXF_INIT_SET };
22170 +       struct nx_info *new_nxi;
22171 +       int ret;
22172 +
22173 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
22174 +               return -EFAULT;
22175 +
22176 +       if ((nid > MAX_S_CONTEXT) || (nid < 2))
22177 +               return -EINVAL;
22178 +
22179 +       new_nxi = __create_nx_info(nid);
22180 +       if (IS_ERR(new_nxi))
22181 +               return PTR_ERR(new_nxi);
22182 +
22183 +       /* initial flags */
22184 +       new_nxi->nx_flags = vc_data.flagword;
22185 +
22186 +       ret = -ENOEXEC;
22187 +       if (vs_net_change(new_nxi, VSC_NETUP))
22188 +               goto out;
22189 +
22190 +       ret = nx_migrate_task(current, new_nxi);
22191 +       if (ret)
22192 +               goto out;
22193 +
22194 +       /* return context id on success */
22195 +       ret = new_nxi->nx_id;
22196 +
22197 +       /* get a reference for persistent contexts */
22198 +       if ((vc_data.flagword & NXF_PERSISTENT))
22199 +               nx_set_persistent(new_nxi);
22200 +out:
22201 +       release_nx_info(new_nxi, NULL);
22202 +       put_nx_info(new_nxi);
22203 +       return ret;
22204 +}
22205 +
22206 +
22207 +int vc_net_migrate(struct nx_info *nxi, void __user *data)
22208 +{
22209 +       return nx_migrate_task(current, nxi);
22210 +}
22211 +
22212 +
22213 +
22214 +int do_add_v4_addr(struct nx_info *nxi, __be32 ip, __be32 ip2, __be32 mask,
22215 +       uint16_t type, uint16_t flags)
22216 +{
22217 +       struct nx_addr_v4 *nxa = &nxi->v4;
22218 +
22219 +       if (NX_IPV4(nxi)) {
22220 +               /* locate last entry */
22221 +               for (; nxa->next; nxa = nxa->next);
22222 +               nxa->next = __alloc_nx_addr_v4();
22223 +               nxa = nxa->next;
22224 +
22225 +               if (IS_ERR(nxa))
22226 +                       return PTR_ERR(nxa);
22227 +       }
22228 +
22229 +       if (nxi->v4.next)
22230 +               /* remove single ip for ip list */
22231 +               nxi->nx_flags &= ~NXF_SINGLE_IP;
22232 +
22233 +       nxa->ip[0].s_addr = ip;
22234 +       nxa->ip[1].s_addr = ip2;
22235 +       nxa->mask.s_addr = mask;
22236 +       nxa->type = type;
22237 +       nxa->flags = flags;
22238 +       return 0;
22239 +}
22240 +
22241 +
22242 +int vc_net_add(struct nx_info *nxi, void __user *data)
22243 +{
22244 +       struct vcmd_net_addr_v0 vc_data;
22245 +       int index, ret = 0;
22246 +
22247 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
22248 +               return -EFAULT;
22249 +
22250 +       switch (vc_data.type) {
22251 +       case NXA_TYPE_IPV4:
22252 +               if ((vc_data.count < 1) || (vc_data.count > 4))
22253 +                       return -EINVAL;
22254 +
22255 +               index = 0;
22256 +               while (index < vc_data.count) {
22257 +                       ret = do_add_v4_addr(nxi, vc_data.ip[index].s_addr, 0,
22258 +                               vc_data.mask[index].s_addr, NXA_TYPE_ADDR, 0);
22259 +                       if (ret)
22260 +                               return ret;
22261 +                       index++;
22262 +               }
22263 +               ret = index;
22264 +               break;
22265 +
22266 +       case NXA_TYPE_IPV4|NXA_MOD_BCAST:
22267 +               nxi->v4_bcast = vc_data.ip[0];
22268 +               ret = 1;
22269 +               break;
22270 +
22271 +       case NXA_TYPE_IPV4|NXA_MOD_LBACK:
22272 +               nxi->v4_lback = vc_data.ip[0];
22273 +               ret = 1;
22274 +               break;
22275 +
22276 +       default:
22277 +               ret = -EINVAL;
22278 +               break;
22279 +       }
22280 +       return ret;
22281 +}
22282 +
22283 +int vc_net_remove(struct nx_info *nxi, void __user *data)
22284 +{
22285 +       struct vcmd_net_addr_v0 vc_data;
22286 +
22287 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
22288 +               return -EFAULT;
22289 +
22290 +       switch (vc_data.type) {
22291 +       case NXA_TYPE_ANY:
22292 +               __dealloc_nx_addr_v4_all(xchg(&nxi->v4.next, NULL));
22293 +               memset(&nxi->v4, 0, sizeof(nxi->v4));
22294 +               break;
22295 +
22296 +       default:
22297 +               return -EINVAL;
22298 +       }
22299 +       return 0;
22300 +}
22301 +
22302 +
22303 +int vc_net_add_ipv4(struct nx_info *nxi, void __user *data)
22304 +{
22305 +       struct vcmd_net_addr_ipv4_v1 vc_data;
22306 +
22307 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
22308 +               return -EFAULT;
22309 +
22310 +       switch (vc_data.type) {
22311 +       case NXA_TYPE_ADDR:
22312 +       case NXA_TYPE_RANGE:
22313 +       case NXA_TYPE_MASK:
22314 +               return do_add_v4_addr(nxi, vc_data.ip.s_addr, 0,
22315 +                       vc_data.mask.s_addr, vc_data.type, vc_data.flags);
22316 +
22317 +       case NXA_TYPE_ADDR | NXA_MOD_BCAST:
22318 +               nxi->v4_bcast = vc_data.ip;
22319 +               break;
22320 +
22321 +       case NXA_TYPE_ADDR | NXA_MOD_LBACK:
22322 +               nxi->v4_lback = vc_data.ip;
22323 +               break;
22324 +
22325 +       default:
22326 +               return -EINVAL;
22327 +       }
22328 +       return 0;
22329 +}
22330 +
22331 +int vc_net_remove_ipv4(struct nx_info *nxi, void __user *data)
22332 +{
22333 +       struct vcmd_net_addr_ipv4_v1 vc_data;
22334 +
22335 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
22336 +               return -EFAULT;
22337 +
22338 +       switch (vc_data.type) {
22339 +/*     case NXA_TYPE_ADDR:
22340 +               break;          */
22341 +
22342 +       case NXA_TYPE_ANY:
22343 +               __dealloc_nx_addr_v4_all(xchg(&nxi->v4.next, NULL));
22344 +               memset(&nxi->v4, 0, sizeof(nxi->v4));
22345 +               break;
22346 +
22347 +       default:
22348 +               return -EINVAL;
22349 +       }
22350 +       return 0;
22351 +}
22352 +
22353 +
22354 +#ifdef CONFIG_IPV6
22355 +
22356 +int do_add_v6_addr(struct nx_info *nxi,
22357 +       struct in6_addr *ip, struct in6_addr *mask,
22358 +       uint32_t prefix, uint16_t type, uint16_t flags)
22359 +{
22360 +       struct nx_addr_v6 *nxa = &nxi->v6;
22361 +
22362 +       if (NX_IPV6(nxi)) {
22363 +               /* locate last entry */
22364 +               for (; nxa->next; nxa = nxa->next);
22365 +               nxa->next = __alloc_nx_addr_v6();
22366 +               nxa = nxa->next;
22367 +
22368 +               if (IS_ERR(nxa))
22369 +                       return PTR_ERR(nxa);
22370 +       }
22371 +
22372 +       nxa->ip = *ip;
22373 +       nxa->mask = *mask;
22374 +       nxa->prefix = prefix;
22375 +       nxa->type = type;
22376 +       nxa->flags = flags;
22377 +       return 0;
22378 +}
22379 +
22380 +
22381 +int vc_net_add_ipv6(struct nx_info *nxi, void __user *data)
22382 +{
22383 +       struct vcmd_net_addr_ipv6_v1 vc_data;
22384 +
22385 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
22386 +               return -EFAULT;
22387 +
22388 +       switch (vc_data.type) {
22389 +       case NXA_TYPE_ADDR:
22390 +       case NXA_TYPE_MASK:
22391 +               return do_add_v6_addr(nxi, &vc_data.ip, &vc_data.mask,
22392 +                       vc_data.prefix, vc_data.type, vc_data.flags);
22393 +       default:
22394 +               return -EINVAL;
22395 +       }
22396 +       return 0;
22397 +}
22398 +
22399 +int vc_net_remove_ipv6(struct nx_info *nxi, void __user *data)
22400 +{
22401 +       struct vcmd_net_addr_ipv6_v1 vc_data;
22402 +
22403 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
22404 +               return -EFAULT;
22405 +
22406 +       switch (vc_data.type) {
22407 +       case NXA_TYPE_ANY:
22408 +               __dealloc_nx_addr_v6_all(xchg(&nxi->v6.next, NULL));
22409 +               memset(&nxi->v6, 0, sizeof(nxi->v6));
22410 +               break;
22411 +
22412 +       default:
22413 +               return -EINVAL;
22414 +       }
22415 +       return 0;
22416 +}
22417 +
22418 +#endif /* CONFIG_IPV6 */
22419 +
22420 +
22421 +int vc_get_nflags(struct nx_info *nxi, void __user *data)
22422 +{
22423 +       struct vcmd_net_flags_v0 vc_data;
22424 +
22425 +       vc_data.flagword = nxi->nx_flags;
22426 +
22427 +       /* special STATE flag handling */
22428 +       vc_data.mask = vs_mask_flags(~0ULL, nxi->nx_flags, NXF_ONE_TIME);
22429 +
22430 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
22431 +               return -EFAULT;
22432 +       return 0;
22433 +}
22434 +
22435 +int vc_set_nflags(struct nx_info *nxi, void __user *data)
22436 +{
22437 +       struct vcmd_net_flags_v0 vc_data;
22438 +       uint64_t mask, trigger;
22439 +
22440 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
22441 +               return -EFAULT;
22442 +
22443 +       /* special STATE flag handling */
22444 +       mask = vs_mask_mask(vc_data.mask, nxi->nx_flags, NXF_ONE_TIME);
22445 +       trigger = (mask & nxi->nx_flags) ^ (mask & vc_data.flagword);
22446 +
22447 +       nxi->nx_flags = vs_mask_flags(nxi->nx_flags,
22448 +               vc_data.flagword, mask);
22449 +       if (trigger & NXF_PERSISTENT)
22450 +               nx_update_persistent(nxi);
22451 +
22452 +       return 0;
22453 +}
22454 +
22455 +int vc_get_ncaps(struct nx_info *nxi, void __user *data)
22456 +{
22457 +       struct vcmd_net_caps_v0 vc_data;
22458 +
22459 +       vc_data.ncaps = nxi->nx_ncaps;
22460 +       vc_data.cmask = ~0ULL;
22461 +
22462 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
22463 +               return -EFAULT;
22464 +       return 0;
22465 +}
22466 +
22467 +int vc_set_ncaps(struct nx_info *nxi, void __user *data)
22468 +{
22469 +       struct vcmd_net_caps_v0 vc_data;
22470 +
22471 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
22472 +               return -EFAULT;
22473 +
22474 +       nxi->nx_ncaps = vs_mask_flags(nxi->nx_ncaps,
22475 +               vc_data.ncaps, vc_data.cmask);
22476 +       return 0;
22477 +}
22478 +
22479 +
22480 +#include <linux/module.h>
22481 +
22482 +module_init(init_network);
22483 +
22484 +EXPORT_SYMBOL_GPL(free_nx_info);
22485 +EXPORT_SYMBOL_GPL(unhash_nx_info);
22486 +
22487 diff -NurpP --minimal linux-2.6.29/kernel/vserver/proc.c linux-2.6.29-vs2.3.0.36.9-pre3/kernel/vserver/proc.c
22488 --- linux-2.6.29/kernel/vserver/proc.c  1970-01-01 01:00:00.000000000 +0100
22489 +++ linux-2.6.29-vs2.3.0.36.9-pre3/kernel/vserver/proc.c        2009-02-22 22:54:26.000000000 +0100
22490 @@ -0,0 +1,1092 @@
22491 +/*
22492 + *  linux/kernel/vserver/proc.c
22493 + *
22494 + *  Virtual Context Support
22495 + *
22496 + *  Copyright (C) 2003-2007  Herbert Pötzl
22497 + *
22498 + *  V0.01  basic structure
22499 + *  V0.02  adaptation vs1.3.0
22500 + *  V0.03  proc permissions
22501 + *  V0.04  locking/generic
22502 + *  V0.05  next generation procfs
22503 + *  V0.06  inode validation
22504 + *  V0.07  generic rewrite vid
22505 + *  V0.08  remove inode type
22506 + *
22507 + */
22508 +
22509 +#include <linux/proc_fs.h>
22510 +#include <asm/unistd.h>
22511 +
22512 +#include <linux/vs_context.h>
22513 +#include <linux/vs_network.h>
22514 +#include <linux/vs_cvirt.h>
22515 +
22516 +#include <linux/in.h>
22517 +#include <linux/inetdevice.h>
22518 +#include <linux/vs_inet.h>
22519 +#include <linux/vs_inet6.h>
22520 +
22521 +#include <linux/vserver/global.h>
22522 +
22523 +#include "cvirt_proc.h"
22524 +#include "cacct_proc.h"
22525 +#include "limit_proc.h"
22526 +#include "sched_proc.h"
22527 +#include "vci_config.h"
22528 +
22529 +
22530 +static inline char *print_cap_t(char *buffer, kernel_cap_t *c)
22531 +{
22532 +       unsigned __capi;
22533 +
22534 +       CAP_FOR_EACH_U32(__capi) {
22535 +               buffer += sprintf(buffer, "%08x",
22536 +                       c->cap[(_KERNEL_CAPABILITY_U32S-1) - __capi]);
22537 +       }
22538 +       return buffer;
22539 +}
22540 +
22541 +
22542 +static struct proc_dir_entry *proc_virtual;
22543 +
22544 +static struct proc_dir_entry *proc_virtnet;
22545 +
22546 +
22547 +/* first the actual feeds */
22548 +
22549 +
22550 +static int proc_vci(char *buffer)
22551 +{
22552 +       return sprintf(buffer,
22553 +               "VCIVersion:\t%04x:%04x\n"
22554 +               "VCISyscall:\t%d\n"
22555 +               "VCIKernel:\t%08x\n",
22556 +               VCI_VERSION >> 16,
22557 +               VCI_VERSION & 0xFFFF,
22558 +               __NR_vserver,
22559 +               vci_kernel_config());
22560 +}
22561 +
22562 +static int proc_virtual_info(char *buffer)
22563 +{
22564 +       return proc_vci(buffer);
22565 +}
22566 +
22567 +static int proc_virtual_status(char *buffer)
22568 +{
22569 +       return sprintf(buffer,
22570 +               "#CTotal:\t%d\n"
22571 +               "#CActive:\t%d\n"
22572 +               "#NSProxy:\t%d\t%d %d %d %d %d %d\n",
22573 +               atomic_read(&vx_global_ctotal),
22574 +               atomic_read(&vx_global_cactive),
22575 +               atomic_read(&vs_global_nsproxy),
22576 +               atomic_read(&vs_global_fs),
22577 +               atomic_read(&vs_global_mnt_ns),
22578 +               atomic_read(&vs_global_uts_ns),
22579 +               atomic_read(&vs_global_ipc_ns),
22580 +               atomic_read(&vs_global_user_ns),
22581 +               atomic_read(&vs_global_pid_ns));
22582 +}
22583 +
22584 +
22585 +int proc_vxi_info(struct vx_info *vxi, char *buffer)
22586 +{
22587 +       int length;
22588 +
22589 +       length = sprintf(buffer,
22590 +               "ID:\t%d\n"
22591 +               "Info:\t%p\n"
22592 +               "Init:\t%d\n"
22593 +               "OOM:\t%lld\n",
22594 +               vxi->vx_id,
22595 +               vxi,
22596 +               vxi->vx_initpid,
22597 +               vxi->vx_badness_bias);
22598 +       return length;
22599 +}
22600 +
22601 +int proc_vxi_status(struct vx_info *vxi, char *buffer)
22602 +{
22603 +       char *orig = buffer;
22604 +
22605 +       buffer += sprintf(buffer,
22606 +               "UseCnt:\t%d\n"
22607 +               "Tasks:\t%d\n"
22608 +               "Flags:\t%016llx\n",
22609 +               atomic_read(&vxi->vx_usecnt),
22610 +               atomic_read(&vxi->vx_tasks),
22611 +               (unsigned long long)vxi->vx_flags);
22612 +
22613 +       buffer += sprintf(buffer, "BCaps:\t");
22614 +       buffer = print_cap_t(buffer, &vxi->vx_bcaps);
22615 +       buffer += sprintf(buffer, "\n");
22616 +
22617 +       buffer += sprintf(buffer,
22618 +               "CCaps:\t%016llx\n"
22619 +               "Spaces:\t%08lx %08lx\n",
22620 +               (unsigned long long)vxi->vx_ccaps,
22621 +               vxi->vx_nsmask[0], vxi->vx_nsmask[1]);
22622 +       return buffer - orig;
22623 +}
22624 +
22625 +int proc_vxi_limit(struct vx_info *vxi, char *buffer)
22626 +{
22627 +       return vx_info_proc_limit(&vxi->limit, buffer);
22628 +}
22629 +
22630 +int proc_vxi_sched(struct vx_info *vxi, char *buffer)
22631 +{
22632 +       int cpu, length;
22633 +
22634 +       length = vx_info_proc_sched(&vxi->sched, buffer);
22635 +       for_each_online_cpu(cpu) {
22636 +               length += vx_info_proc_sched_pc(
22637 +                       &vx_per_cpu(vxi, sched_pc, cpu),
22638 +                       buffer + length, cpu);
22639 +       }
22640 +       return length;
22641 +}
22642 +
22643 +int proc_vxi_nsproxy0(struct vx_info *vxi, char *buffer)
22644 +{
22645 +       return vx_info_proc_nsproxy(vxi->vx_nsproxy[0], buffer);
22646 +}
22647 +
22648 +int proc_vxi_nsproxy1(struct vx_info *vxi, char *buffer)
22649 +{
22650 +       return vx_info_proc_nsproxy(vxi->vx_nsproxy[1], buffer);
22651 +}
22652 +
22653 +int proc_vxi_cvirt(struct vx_info *vxi, char *buffer)
22654 +{
22655 +       int cpu, length;
22656 +
22657 +       vx_update_load(vxi);
22658 +       length = vx_info_proc_cvirt(&vxi->cvirt, buffer);
22659 +       for_each_online_cpu(cpu) {
22660 +               length += vx_info_proc_cvirt_pc(
22661 +                       &vx_per_cpu(vxi, cvirt_pc, cpu),
22662 +                       buffer + length, cpu);
22663 +       }
22664 +       return length;
22665 +}
22666 +
22667 +int proc_vxi_cacct(struct vx_info *vxi, char *buffer)
22668 +{
22669 +       return vx_info_proc_cacct(&vxi->cacct, buffer);
22670 +}
22671 +
22672 +
22673 +static int proc_virtnet_info(char *buffer)
22674 +{
22675 +       return proc_vci(buffer);
22676 +}
22677 +
22678 +static int proc_virtnet_status(char *buffer)
22679 +{
22680 +       return sprintf(buffer,
22681 +               "#CTotal:\t%d\n"
22682 +               "#CActive:\t%d\n",
22683 +               atomic_read(&nx_global_ctotal),
22684 +               atomic_read(&nx_global_cactive));
22685 +}
22686 +
22687 +int proc_nxi_info(struct nx_info *nxi, char *buffer)
22688 +{
22689 +       struct nx_addr_v4 *v4a;
22690 +#ifdef CONFIG_IPV6
22691 +       struct nx_addr_v6 *v6a;
22692 +#endif
22693 +       int length, i;
22694 +
22695 +       length = sprintf(buffer,
22696 +               "ID:\t%d\n"
22697 +               "Info:\t%p\n"
22698 +               "Bcast:\t" NIPQUAD_FMT "\n"
22699 +               "Lback:\t" NIPQUAD_FMT "\n",
22700 +               nxi->nx_id,
22701 +               nxi,
22702 +               NIPQUAD(nxi->v4_bcast.s_addr),
22703 +               NIPQUAD(nxi->v4_lback.s_addr));
22704 +
22705 +       if (!NX_IPV4(nxi))
22706 +               goto skip_v4;
22707 +       for (i = 0, v4a = &nxi->v4; v4a; i++, v4a = v4a->next)
22708 +               length += sprintf(buffer + length, "%d:\t" NXAV4_FMT "\n",
22709 +                       i, NXAV4(v4a));
22710 +skip_v4:
22711 +#ifdef CONFIG_IPV6
22712 +       if (!NX_IPV6(nxi))
22713 +               goto skip_v6;
22714 +       for (i = 0, v6a = &nxi->v6; v6a; i++, v6a = v6a->next)
22715 +               length += sprintf(buffer + length, "%d:\t" NXAV6_FMT "\n",
22716 +                       i, NXAV6(v6a));
22717 +skip_v6:
22718 +#endif
22719 +       return length;
22720 +}
22721 +
22722 +int proc_nxi_status(struct nx_info *nxi, char *buffer)
22723 +{
22724 +       int length;
22725 +
22726 +       length = sprintf(buffer,
22727 +               "UseCnt:\t%d\n"
22728 +               "Tasks:\t%d\n"
22729 +               "Flags:\t%016llx\n"
22730 +               "NCaps:\t%016llx\n",
22731 +               atomic_read(&nxi->nx_usecnt),
22732 +               atomic_read(&nxi->nx_tasks),
22733 +               (unsigned long long)nxi->nx_flags,
22734 +               (unsigned long long)nxi->nx_ncaps);
22735 +       return length;
22736 +}
22737 +
22738 +
22739 +
22740 +/* here the inode helpers */
22741 +
22742 +struct vs_entry {
22743 +       int len;
22744 +       char *name;
22745 +       mode_t mode;
22746 +       struct inode_operations *iop;
22747 +       struct file_operations *fop;
22748 +       union proc_op op;
22749 +};
22750 +
22751 +static struct inode *vs_proc_make_inode(struct super_block *sb, struct vs_entry *p)
22752 +{
22753 +       struct inode *inode = new_inode(sb);
22754 +
22755 +       if (!inode)
22756 +               goto out;
22757 +
22758 +       inode->i_mode = p->mode;
22759 +       if (p->iop)
22760 +               inode->i_op = p->iop;
22761 +       if (p->fop)
22762 +               inode->i_fop = p->fop;
22763 +
22764 +       inode->i_nlink = (p->mode & S_IFDIR) ? 2 : 1;
22765 +       inode->i_flags |= S_IMMUTABLE;
22766 +
22767 +       inode->i_mtime = inode->i_atime = inode->i_ctime = CURRENT_TIME;
22768 +
22769 +       inode->i_uid = 0;
22770 +       inode->i_gid = 0;
22771 +       inode->i_tag = 0;
22772 +out:
22773 +       return inode;
22774 +}
22775 +
22776 +static struct dentry *vs_proc_instantiate(struct inode *dir,
22777 +       struct dentry *dentry, int id, void *ptr)
22778 +{
22779 +       struct vs_entry *p = ptr;
22780 +       struct inode *inode = vs_proc_make_inode(dir->i_sb, p);
22781 +       struct dentry *error = ERR_PTR(-EINVAL);
22782 +
22783 +       if (!inode)
22784 +               goto out;
22785 +
22786 +       PROC_I(inode)->op = p->op;
22787 +       PROC_I(inode)->fd = id;
22788 +       d_add(dentry, inode);
22789 +       error = NULL;
22790 +out:
22791 +       return error;
22792 +}
22793 +
22794 +/* Lookups */
22795 +
22796 +typedef struct dentry *instantiate_t(struct inode *, struct dentry *, int, void *);
22797 +
22798 +/*
22799 + * Fill a directory entry.
22800 + *
22801 + * If possible create the dcache entry and derive our inode number and
22802 + * file type from dcache entry.
22803 + *
22804 + * Since all of the proc inode numbers are dynamically generated, the inode
22805 + * numbers do not exist until the inode is cache.  This means creating the
22806 + * the dcache entry in readdir is necessary to keep the inode numbers
22807 + * reported by readdir in sync with the inode numbers reported
22808 + * by stat.
22809 + */
22810 +static int proc_fill_cache(struct file *filp, void *dirent, filldir_t filldir,
22811 +       char *name, int len, instantiate_t instantiate, int id, void *ptr)
22812 +{
22813 +       struct dentry *child, *dir = filp->f_dentry;
22814 +       struct inode *inode;
22815 +       struct qstr qname;
22816 +       ino_t ino = 0;
22817 +       unsigned type = DT_UNKNOWN;
22818 +
22819 +       qname.name = name;
22820 +       qname.len  = len;
22821 +       qname.hash = full_name_hash(name, len);
22822 +
22823 +       child = d_lookup(dir, &qname);
22824 +       if (!child) {
22825 +               struct dentry *new;
22826 +               new = d_alloc(dir, &qname);
22827 +               if (new) {
22828 +                       child = instantiate(dir->d_inode, new, id, ptr);
22829 +                       if (child)
22830 +                               dput(new);
22831 +                       else
22832 +                               child = new;
22833 +               }
22834 +       }
22835 +       if (!child || IS_ERR(child) || !child->d_inode)
22836 +               goto end_instantiate;
22837 +       inode = child->d_inode;
22838 +       if (inode) {
22839 +               ino = inode->i_ino;
22840 +               type = inode->i_mode >> 12;
22841 +       }
22842 +       dput(child);
22843 +end_instantiate:
22844 +       if (!ino)
22845 +               ino = find_inode_number(dir, &qname);
22846 +       if (!ino)
22847 +               ino = 1;
22848 +       return filldir(dirent, name, len, filp->f_pos, ino, type);
22849 +}
22850 +
22851 +
22852 +
22853 +/* get and revalidate vx_info/xid */
22854 +
22855 +static inline
22856 +struct vx_info *get_proc_vx_info(struct inode *inode)
22857 +{
22858 +       return lookup_vx_info(PROC_I(inode)->fd);
22859 +}
22860 +
22861 +static int proc_xid_revalidate(struct dentry *dentry, struct nameidata *nd)
22862 +{
22863 +       struct inode *inode = dentry->d_inode;
22864 +       xid_t xid = PROC_I(inode)->fd;
22865 +
22866 +       if (!xid || xid_is_hashed(xid))
22867 +               return 1;
22868 +       d_drop(dentry);
22869 +       return 0;
22870 +}
22871 +
22872 +
22873 +/* get and revalidate nx_info/nid */
22874 +
22875 +static int proc_nid_revalidate(struct dentry *dentry, struct nameidata *nd)
22876 +{
22877 +       struct inode *inode = dentry->d_inode;
22878 +       nid_t nid = PROC_I(inode)->fd;
22879 +
22880 +       if (!nid || nid_is_hashed(nid))
22881 +               return 1;
22882 +       d_drop(dentry);
22883 +       return 0;
22884 +}
22885 +
22886 +
22887 +
22888 +#define PROC_BLOCK_SIZE (PAGE_SIZE - 1024)
22889 +
22890 +static ssize_t proc_vs_info_read(struct file *file, char __user *buf,
22891 +                         size_t count, loff_t *ppos)
22892 +{
22893 +       struct inode *inode = file->f_dentry->d_inode;
22894 +       unsigned long page;
22895 +       ssize_t length = 0;
22896 +
22897 +       if (count > PROC_BLOCK_SIZE)
22898 +               count = PROC_BLOCK_SIZE;
22899 +
22900 +       /* fade that out as soon as stable */
22901 +       WARN_ON(PROC_I(inode)->fd);
22902 +
22903 +       if (!(page = __get_free_page(GFP_KERNEL)))
22904 +               return -ENOMEM;
22905 +
22906 +       BUG_ON(!PROC_I(inode)->op.proc_vs_read);
22907 +       length = PROC_I(inode)->op.proc_vs_read((char *)page);
22908 +
22909 +       if (length >= 0)
22910 +               length = simple_read_from_buffer(buf, count, ppos,
22911 +                       (char *)page, length);
22912 +
22913 +       free_page(page);
22914 +       return length;
22915 +}
22916 +
22917 +static ssize_t proc_vx_info_read(struct file *file, char __user *buf,
22918 +                         size_t count, loff_t *ppos)
22919 +{
22920 +       struct inode *inode = file->f_dentry->d_inode;
22921 +       struct vx_info *vxi = NULL;
22922 +       xid_t xid = PROC_I(inode)->fd;
22923 +       unsigned long page;
22924 +       ssize_t length = 0;
22925 +
22926 +       if (count > PROC_BLOCK_SIZE)
22927 +               count = PROC_BLOCK_SIZE;
22928 +
22929 +       /* fade that out as soon as stable */
22930 +       WARN_ON(!xid);
22931 +       vxi = lookup_vx_info(xid);
22932 +       if (!vxi)
22933 +               goto out;
22934 +
22935 +       length = -ENOMEM;
22936 +       if (!(page = __get_free_page(GFP_KERNEL)))
22937 +               goto out_put;
22938 +
22939 +       BUG_ON(!PROC_I(inode)->op.proc_vxi_read);
22940 +       length = PROC_I(inode)->op.proc_vxi_read(vxi, (char *)page);
22941 +
22942 +       if (length >= 0)
22943 +               length = simple_read_from_buffer(buf, count, ppos,
22944 +                       (char *)page, length);
22945 +
22946 +       free_page(page);
22947 +out_put:
22948 +       put_vx_info(vxi);
22949 +out:
22950 +       return length;
22951 +}
22952 +
22953 +static ssize_t proc_nx_info_read(struct file *file, char __user *buf,
22954 +                         size_t count, loff_t *ppos)
22955 +{
22956 +       struct inode *inode = file->f_dentry->d_inode;
22957 +       struct nx_info *nxi = NULL;
22958 +       nid_t nid = PROC_I(inode)->fd;
22959 +       unsigned long page;
22960 +       ssize_t length = 0;
22961 +
22962 +       if (count > PROC_BLOCK_SIZE)
22963 +               count = PROC_BLOCK_SIZE;
22964 +
22965 +       /* fade that out as soon as stable */
22966 +       WARN_ON(!nid);
22967 +       nxi = lookup_nx_info(nid);
22968 +       if (!nxi)
22969 +               goto out;
22970 +
22971 +       length = -ENOMEM;
22972 +       if (!(page = __get_free_page(GFP_KERNEL)))
22973 +               goto out_put;
22974 +
22975 +       BUG_ON(!PROC_I(inode)->op.proc_nxi_read);
22976 +       length = PROC_I(inode)->op.proc_nxi_read(nxi, (char *)page);
22977 +
22978 +       if (length >= 0)
22979 +               length = simple_read_from_buffer(buf, count, ppos,
22980 +                       (char *)page, length);
22981 +
22982 +       free_page(page);
22983 +out_put:
22984 +       put_nx_info(nxi);
22985 +out:
22986 +       return length;
22987 +}
22988 +
22989 +
22990 +
22991 +/* here comes the lower level */
22992 +
22993 +
22994 +#define NOD(NAME, MODE, IOP, FOP, OP) {        \
22995 +       .len  = sizeof(NAME) - 1,       \
22996 +       .name = (NAME),                 \
22997 +       .mode = MODE,                   \
22998 +       .iop  = IOP,                    \
22999 +       .fop  = FOP,                    \
23000 +       .op   = OP,                     \
23001 +}
23002 +
23003 +
23004 +#define DIR(NAME, MODE, OTYPE)                         \
23005 +       NOD(NAME, (S_IFDIR | (MODE)),                   \
23006 +               &proc_ ## OTYPE ## _inode_operations,   \
23007 +               &proc_ ## OTYPE ## _file_operations, { } )
23008 +
23009 +#define INF(NAME, MODE, OTYPE)                         \
23010 +       NOD(NAME, (S_IFREG | (MODE)), NULL,             \
23011 +               &proc_vs_info_file_operations,          \
23012 +               { .proc_vs_read = &proc_##OTYPE } )
23013 +
23014 +#define VINF(NAME, MODE, OTYPE)                                \
23015 +       NOD(NAME, (S_IFREG | (MODE)), NULL,             \
23016 +               &proc_vx_info_file_operations,          \
23017 +               { .proc_vxi_read = &proc_##OTYPE } )
23018 +
23019 +#define NINF(NAME, MODE, OTYPE)                                \
23020 +       NOD(NAME, (S_IFREG | (MODE)), NULL,             \
23021 +               &proc_nx_info_file_operations,          \
23022 +               { .proc_nxi_read = &proc_##OTYPE } )
23023 +
23024 +
23025 +static struct file_operations proc_vs_info_file_operations = {
23026 +       .read =         proc_vs_info_read,
23027 +};
23028 +
23029 +static struct file_operations proc_vx_info_file_operations = {
23030 +       .read =         proc_vx_info_read,
23031 +};
23032 +
23033 +static struct dentry_operations proc_xid_dentry_operations = {
23034 +       .d_revalidate = proc_xid_revalidate,
23035 +};
23036 +
23037 +static struct vs_entry vx_base_stuff[] = {
23038 +       VINF("info",    S_IRUGO, vxi_info),
23039 +       VINF("status",  S_IRUGO, vxi_status),
23040 +       VINF("limit",   S_IRUGO, vxi_limit),
23041 +       VINF("sched",   S_IRUGO, vxi_sched),
23042 +       VINF("nsproxy", S_IRUGO, vxi_nsproxy0),
23043 +       VINF("nsproxy1",S_IRUGO, vxi_nsproxy1),
23044 +       VINF("cvirt",   S_IRUGO, vxi_cvirt),
23045 +       VINF("cacct",   S_IRUGO, vxi_cacct),
23046 +       {}
23047 +};
23048 +
23049 +
23050 +
23051 +
23052 +static struct dentry *proc_xid_instantiate(struct inode *dir,
23053 +       struct dentry *dentry, int id, void *ptr)
23054 +{
23055 +       dentry->d_op = &proc_xid_dentry_operations;
23056 +       return vs_proc_instantiate(dir, dentry, id, ptr);
23057 +}
23058 +
23059 +static struct dentry *proc_xid_lookup(struct inode *dir,
23060 +       struct dentry *dentry, struct nameidata *nd)
23061 +{
23062 +       struct vs_entry *p = vx_base_stuff;
23063 +       struct dentry *error = ERR_PTR(-ENOENT);
23064 +
23065 +       for (; p->name; p++) {
23066 +               if (p->len != dentry->d_name.len)
23067 +                       continue;
23068 +               if (!memcmp(dentry->d_name.name, p->name, p->len))
23069 +                       break;
23070 +       }
23071 +       if (!p->name)
23072 +               goto out;
23073 +
23074 +       error = proc_xid_instantiate(dir, dentry, PROC_I(dir)->fd, p);
23075 +out:
23076 +       return error;
23077 +}
23078 +
23079 +static int proc_xid_readdir(struct file *filp,
23080 +       void *dirent, filldir_t filldir)
23081 +{
23082 +       struct dentry *dentry = filp->f_dentry;
23083 +       struct inode *inode = dentry->d_inode;
23084 +       struct vs_entry *p = vx_base_stuff;
23085 +       int size = sizeof(vx_base_stuff) / sizeof(struct vs_entry);
23086 +       int pos, index;
23087 +       u64 ino;
23088 +
23089 +       pos = filp->f_pos;
23090 +       switch (pos) {
23091 +       case 0:
23092 +               ino = inode->i_ino;
23093 +               if (filldir(dirent, ".", 1, pos, ino, DT_DIR) < 0)
23094 +                       goto out;
23095 +               pos++;
23096 +               /* fall through */
23097 +       case 1:
23098 +               ino = parent_ino(dentry);
23099 +               if (filldir(dirent, "..", 2, pos, ino, DT_DIR) < 0)
23100 +                       goto out;
23101 +               pos++;
23102 +               /* fall through */
23103 +       default:
23104 +               index = pos - 2;
23105 +               if (index >= size)
23106 +                       goto out;
23107 +               for (p += index; p->name; p++) {
23108 +                       if (proc_fill_cache(filp, dirent, filldir, p->name, p->len,
23109 +                               vs_proc_instantiate, PROC_I(inode)->fd, p))
23110 +                               goto out;
23111 +                       pos++;
23112 +               }
23113 +       }
23114 +out:
23115 +       filp->f_pos = pos;
23116 +       return 1;
23117 +}
23118 +
23119 +
23120 +
23121 +static struct file_operations proc_nx_info_file_operations = {
23122 +       .read =         proc_nx_info_read,
23123 +};
23124 +
23125 +static struct dentry_operations proc_nid_dentry_operations = {
23126 +       .d_revalidate = proc_nid_revalidate,
23127 +};
23128 +
23129 +static struct vs_entry nx_base_stuff[] = {
23130 +       NINF("info",    S_IRUGO, nxi_info),
23131 +       NINF("status",  S_IRUGO, nxi_status),
23132 +       {}
23133 +};
23134 +
23135 +
23136 +static struct dentry *proc_nid_instantiate(struct inode *dir,
23137 +       struct dentry *dentry, int id, void *ptr)
23138 +{
23139 +       dentry->d_op = &proc_nid_dentry_operations;
23140 +       return vs_proc_instantiate(dir, dentry, id, ptr);
23141 +}
23142 +
23143 +static struct dentry *proc_nid_lookup(struct inode *dir,
23144 +       struct dentry *dentry, struct nameidata *nd)
23145 +{
23146 +       struct vs_entry *p = nx_base_stuff;
23147 +       struct dentry *error = ERR_PTR(-ENOENT);
23148 +
23149 +       for (; p->name; p++) {
23150 +               if (p->len != dentry->d_name.len)
23151 +                       continue;
23152 +               if (!memcmp(dentry->d_name.name, p->name, p->len))
23153 +                       break;
23154 +       }
23155 +       if (!p->name)
23156 +               goto out;
23157 +
23158 +       error = proc_nid_instantiate(dir, dentry, PROC_I(dir)->fd, p);
23159 +out:
23160 +       return error;
23161 +}
23162 +
23163 +static int proc_nid_readdir(struct file *filp,
23164 +       void *dirent, filldir_t filldir)
23165 +{
23166 +       struct dentry *dentry = filp->f_dentry;
23167 +       struct inode *inode = dentry->d_inode;
23168 +       struct vs_entry *p = nx_base_stuff;
23169 +       int size = sizeof(nx_base_stuff) / sizeof(struct vs_entry);
23170 +       int pos, index;
23171 +       u64 ino;
23172 +
23173 +       pos = filp->f_pos;
23174 +       switch (pos) {
23175 +       case 0:
23176 +               ino = inode->i_ino;
23177 +               if (filldir(dirent, ".", 1, pos, ino, DT_DIR) < 0)
23178 +                       goto out;
23179 +               pos++;
23180 +               /* fall through */
23181 +       case 1:
23182 +               ino = parent_ino(dentry);
23183 +               if (filldir(dirent, "..", 2, pos, ino, DT_DIR) < 0)
23184 +                       goto out;
23185 +               pos++;
23186 +               /* fall through */
23187 +       default:
23188 +               index = pos - 2;
23189 +               if (index >= size)
23190 +                       goto out;
23191 +               for (p += index; p->name; p++) {
23192 +                       if (proc_fill_cache(filp, dirent, filldir, p->name, p->len,
23193 +                               vs_proc_instantiate, PROC_I(inode)->fd, p))
23194 +                               goto out;
23195 +                       pos++;
23196 +               }
23197 +       }
23198 +out:
23199 +       filp->f_pos = pos;
23200 +       return 1;
23201 +}
23202 +
23203 +
23204 +#define MAX_MULBY10    ((~0U - 9) / 10)
23205 +
23206 +static inline int atovid(const char *str, int len)
23207 +{
23208 +       int vid, c;
23209 +
23210 +       vid = 0;
23211 +       while (len-- > 0) {
23212 +               c = *str - '0';
23213 +               str++;
23214 +               if (c > 9)
23215 +                       return -1;
23216 +               if (vid >= MAX_MULBY10)
23217 +                       return -1;
23218 +               vid *= 10;
23219 +               vid += c;
23220 +               if (!vid)
23221 +                       return -1;
23222 +       }
23223 +       return vid;
23224 +}
23225 +
23226 +/* now the upper level (virtual) */
23227 +
23228 +
23229 +static struct file_operations proc_xid_file_operations = {
23230 +       .read =         generic_read_dir,
23231 +       .readdir =      proc_xid_readdir,
23232 +};
23233 +
23234 +static struct inode_operations proc_xid_inode_operations = {
23235 +       .lookup =       proc_xid_lookup,
23236 +};
23237 +
23238 +static struct vs_entry vx_virtual_stuff[] = {
23239 +       INF("info",     S_IRUGO, virtual_info),
23240 +       INF("status",   S_IRUGO, virtual_status),
23241 +       DIR(NULL,       S_IRUGO | S_IXUGO, xid),
23242 +};
23243 +
23244 +
23245 +static struct dentry *proc_virtual_lookup(struct inode *dir,
23246 +       struct dentry *dentry, struct nameidata *nd)
23247 +{
23248 +       struct vs_entry *p = vx_virtual_stuff;
23249 +       struct dentry *error = ERR_PTR(-ENOENT);
23250 +       int id = 0;
23251 +
23252 +       for (; p->name; p++) {
23253 +               if (p->len != dentry->d_name.len)
23254 +                       continue;
23255 +               if (!memcmp(dentry->d_name.name, p->name, p->len))
23256 +                       break;
23257 +       }
23258 +       if (p->name)
23259 +               goto instantiate;
23260 +
23261 +       id = atovid(dentry->d_name.name, dentry->d_name.len);
23262 +       if ((id < 0) || !xid_is_hashed(id))
23263 +               goto out;
23264 +
23265 +instantiate:
23266 +       error = proc_xid_instantiate(dir, dentry, id, p);
23267 +out:
23268 +       return error;
23269 +}
23270 +
23271 +static struct file_operations proc_nid_file_operations = {
23272 +       .read =         generic_read_dir,
23273 +       .readdir =      proc_nid_readdir,
23274 +};
23275 +
23276 +static struct inode_operations proc_nid_inode_operations = {
23277 +       .lookup =       proc_nid_lookup,
23278 +};
23279 +
23280 +static struct vs_entry nx_virtnet_stuff[] = {
23281 +       INF("info",     S_IRUGO, virtnet_info),
23282 +       INF("status",   S_IRUGO, virtnet_status),
23283 +       DIR(NULL,       S_IRUGO | S_IXUGO, nid),
23284 +};
23285 +
23286 +
23287 +static struct dentry *proc_virtnet_lookup(struct inode *dir,
23288 +       struct dentry *dentry, struct nameidata *nd)
23289 +{
23290 +       struct vs_entry *p = nx_virtnet_stuff;
23291 +       struct dentry *error = ERR_PTR(-ENOENT);
23292 +       int id = 0;
23293 +
23294 +       for (; p->name; p++) {
23295 +               if (p->len != dentry->d_name.len)
23296 +                       continue;
23297 +               if (!memcmp(dentry->d_name.name, p->name, p->len))
23298 +                       break;
23299 +       }
23300 +       if (p->name)
23301 +               goto instantiate;
23302 +
23303 +       id = atovid(dentry->d_name.name, dentry->d_name.len);
23304 +       if ((id < 0) || !nid_is_hashed(id))
23305 +               goto out;
23306 +
23307 +instantiate:
23308 +       error = proc_nid_instantiate(dir, dentry, id, p);
23309 +out:
23310 +       return error;
23311 +}
23312 +
23313 +
23314 +#define PROC_MAXVIDS 32
23315 +
23316 +int proc_virtual_readdir(struct file *filp,
23317 +       void *dirent, filldir_t filldir)
23318 +{
23319 +       struct dentry *dentry = filp->f_dentry;
23320 +       struct inode *inode = dentry->d_inode;
23321 +       struct vs_entry *p = vx_virtual_stuff;
23322 +       int size = sizeof(vx_virtual_stuff) / sizeof(struct vs_entry);
23323 +       int pos, index;
23324 +       unsigned int xid_array[PROC_MAXVIDS];
23325 +       char buf[PROC_NUMBUF];
23326 +       unsigned int nr_xids, i;
23327 +       u64 ino;
23328 +
23329 +       pos = filp->f_pos;
23330 +       switch (pos) {
23331 +       case 0:
23332 +               ino = inode->i_ino;
23333 +               if (filldir(dirent, ".", 1, pos, ino, DT_DIR) < 0)
23334 +                       goto out;
23335 +               pos++;
23336 +               /* fall through */
23337 +       case 1:
23338 +               ino = parent_ino(dentry);
23339 +               if (filldir(dirent, "..", 2, pos, ino, DT_DIR) < 0)
23340 +                       goto out;
23341 +               pos++;
23342 +               /* fall through */
23343 +       default:
23344 +               index = pos - 2;
23345 +               if (index >= size)
23346 +                       goto entries;
23347 +               for (p += index; p->name; p++) {
23348 +                       if (proc_fill_cache(filp, dirent, filldir, p->name, p->len,
23349 +                               vs_proc_instantiate, 0, p))
23350 +                               goto out;
23351 +                       pos++;
23352 +               }
23353 +       entries:
23354 +               index = pos - size;
23355 +               p = &vx_virtual_stuff[size - 1];
23356 +               nr_xids = get_xid_list(index, xid_array, PROC_MAXVIDS);
23357 +               for (i = 0; i < nr_xids; i++) {
23358 +                       int n, xid = xid_array[i];
23359 +                       unsigned int j = PROC_NUMBUF;
23360 +
23361 +                       n = xid;
23362 +                       do
23363 +                               buf[--j] = '0' + (n % 10);
23364 +                       while (n /= 10);
23365 +
23366 +                       if (proc_fill_cache(filp, dirent, filldir,
23367 +                               buf + j, PROC_NUMBUF - j,
23368 +                               vs_proc_instantiate, xid, p))
23369 +                               goto out;
23370 +                       pos++;
23371 +               }
23372 +       }
23373 +out:
23374 +       filp->f_pos = pos;
23375 +       return 0;
23376 +}
23377 +
23378 +static int proc_virtual_getattr(struct vfsmount *mnt,
23379 +       struct dentry *dentry, struct kstat *stat)
23380 +{
23381 +       struct inode *inode = dentry->d_inode;
23382 +
23383 +       generic_fillattr(inode, stat);
23384 +       stat->nlink = 2 + atomic_read(&vx_global_cactive);
23385 +       return 0;
23386 +}
23387 +
23388 +static struct file_operations proc_virtual_dir_operations = {
23389 +       .read =         generic_read_dir,
23390 +       .readdir =      proc_virtual_readdir,
23391 +};
23392 +
23393 +static struct inode_operations proc_virtual_dir_inode_operations = {
23394 +       .getattr =      proc_virtual_getattr,
23395 +       .lookup =       proc_virtual_lookup,
23396 +};
23397 +
23398 +
23399 +
23400 +
23401 +
23402 +int proc_virtnet_readdir(struct file *filp,
23403 +       void *dirent, filldir_t filldir)
23404 +{
23405 +       struct dentry *dentry = filp->f_dentry;
23406 +       struct inode *inode = dentry->d_inode;
23407 +       struct vs_entry *p = nx_virtnet_stuff;
23408 +       int size = sizeof(nx_virtnet_stuff) / sizeof(struct vs_entry);
23409 +       int pos, index;
23410 +       unsigned int nid_array[PROC_MAXVIDS];
23411 +       char buf[PROC_NUMBUF];
23412 +       unsigned int nr_nids, i;
23413 +       u64 ino;
23414 +
23415 +       pos = filp->f_pos;
23416 +       switch (pos) {
23417 +       case 0:
23418 +               ino = inode->i_ino;
23419 +               if (filldir(dirent, ".", 1, pos, ino, DT_DIR) < 0)
23420 +                       goto out;
23421 +               pos++;
23422 +               /* fall through */
23423 +       case 1:
23424 +               ino = parent_ino(dentry);
23425 +               if (filldir(dirent, "..", 2, pos, ino, DT_DIR) < 0)
23426 +                       goto out;
23427 +               pos++;
23428 +               /* fall through */
23429 +       default:
23430 +               index = pos - 2;
23431 +               if (index >= size)
23432 +                       goto entries;
23433 +               for (p += index; p->name; p++) {
23434 +                       if (proc_fill_cache(filp, dirent, filldir, p->name, p->len,
23435 +                               vs_proc_instantiate, 0, p))
23436 +                               goto out;
23437 +                       pos++;
23438 +               }
23439 +       entries:
23440 +               index = pos - size;
23441 +               p = &nx_virtnet_stuff[size - 1];
23442 +               nr_nids = get_nid_list(index, nid_array, PROC_MAXVIDS);
23443 +               for (i = 0; i < nr_nids; i++) {
23444 +                       int n, nid = nid_array[i];
23445 +                       unsigned int j = PROC_NUMBUF;
23446 +
23447 +                       n = nid;
23448 +                       do
23449 +                               buf[--j] = '0' + (n % 10);
23450 +                       while (n /= 10);
23451 +
23452 +                       if (proc_fill_cache(filp, dirent, filldir,
23453 +                               buf + j, PROC_NUMBUF - j,
23454 +                               vs_proc_instantiate, nid, p))
23455 +                               goto out;
23456 +                       pos++;
23457 +               }
23458 +       }
23459 +out:
23460 +       filp->f_pos = pos;
23461 +       return 0;
23462 +}
23463 +
23464 +static int proc_virtnet_getattr(struct vfsmount *mnt,
23465 +       struct dentry *dentry, struct kstat *stat)
23466 +{
23467 +       struct inode *inode = dentry->d_inode;
23468 +
23469 +       generic_fillattr(inode, stat);
23470 +       stat->nlink = 2 + atomic_read(&nx_global_cactive);
23471 +       return 0;
23472 +}
23473 +
23474 +static struct file_operations proc_virtnet_dir_operations = {
23475 +       .read =         generic_read_dir,
23476 +       .readdir =      proc_virtnet_readdir,
23477 +};
23478 +
23479 +static struct inode_operations proc_virtnet_dir_inode_operations = {
23480 +       .getattr =      proc_virtnet_getattr,
23481 +       .lookup =       proc_virtnet_lookup,
23482 +};
23483 +
23484 +
23485 +
23486 +void proc_vx_init(void)
23487 +{
23488 +       struct proc_dir_entry *ent;
23489 +
23490 +       ent = proc_mkdir("virtual", 0);
23491 +       if (ent) {
23492 +               ent->proc_fops = &proc_virtual_dir_operations;
23493 +               ent->proc_iops = &proc_virtual_dir_inode_operations;
23494 +       }
23495 +       proc_virtual = ent;
23496 +
23497 +       ent = proc_mkdir("virtnet", 0);
23498 +       if (ent) {
23499 +               ent->proc_fops = &proc_virtnet_dir_operations;
23500 +               ent->proc_iops = &proc_virtnet_dir_inode_operations;
23501 +       }
23502 +       proc_virtnet = ent;
23503 +}
23504 +
23505 +
23506 +
23507 +
23508 +/* per pid info */
23509 +
23510 +
23511 +int proc_pid_vx_info(struct task_struct *p, char *buffer)
23512 +{
23513 +       struct vx_info *vxi;
23514 +       char *orig = buffer;
23515 +
23516 +       buffer += sprintf(buffer, "XID:\t%d\n", vx_task_xid(p));
23517 +
23518 +       vxi = task_get_vx_info(p);
23519 +       if (!vxi)
23520 +               goto out;
23521 +
23522 +       buffer += sprintf(buffer, "BCaps:\t");
23523 +       buffer = print_cap_t(buffer, &vxi->vx_bcaps);
23524 +       buffer += sprintf(buffer, "\n");
23525 +       buffer += sprintf(buffer, "CCaps:\t%016llx\n",
23526 +               (unsigned long long)vxi->vx_ccaps);
23527 +       buffer += sprintf(buffer, "CFlags:\t%016llx\n",
23528 +               (unsigned long long)vxi->vx_flags);
23529 +       buffer += sprintf(buffer, "CIPid:\t%d\n", vxi->vx_initpid);
23530 +
23531 +       put_vx_info(vxi);
23532 +out:
23533 +       return buffer - orig;
23534 +}
23535 +
23536 +
23537 +int proc_pid_nx_info(struct task_struct *p, char *buffer)
23538 +{
23539 +       struct nx_info *nxi;
23540 +       struct nx_addr_v4 *v4a;
23541 +#ifdef CONFIG_IPV6
23542 +       struct nx_addr_v6 *v6a;
23543 +#endif
23544 +       char *orig = buffer;
23545 +       int i;
23546 +
23547 +       buffer += sprintf(buffer, "NID:\t%d\n", nx_task_nid(p));
23548 +
23549 +       nxi = task_get_nx_info(p);
23550 +       if (!nxi)
23551 +               goto out;
23552 +
23553 +       buffer += sprintf(buffer, "NCaps:\t%016llx\n",
23554 +               (unsigned long long)nxi->nx_ncaps);
23555 +       buffer += sprintf(buffer, "NFlags:\t%016llx\n",
23556 +               (unsigned long long)nxi->nx_flags);
23557 +
23558 +       buffer += sprintf(buffer,
23559 +               "V4Root[bcast]:\t" NIPQUAD_FMT "\n",
23560 +               NIPQUAD(nxi->v4_bcast.s_addr));
23561 +       buffer += sprintf (buffer,
23562 +               "V4Root[lback]:\t" NIPQUAD_FMT "\n",
23563 +               NIPQUAD(nxi->v4_lback.s_addr));
23564 +       if (!NX_IPV4(nxi))
23565 +               goto skip_v4;
23566 +       for (i = 0, v4a = &nxi->v4; v4a; i++, v4a = v4a->next)
23567 +               buffer += sprintf(buffer, "V4Root[%d]:\t" NXAV4_FMT "\n",
23568 +                       i, NXAV4(v4a));
23569 +skip_v4:
23570 +#ifdef CONFIG_IPV6
23571 +       if (!NX_IPV6(nxi))
23572 +               goto skip_v6;
23573 +       for (i = 0, v6a = &nxi->v6; v6a; i++, v6a = v6a->next)
23574 +               buffer += sprintf(buffer, "V6Root[%d]:\t" NXAV6_FMT "\n",
23575 +                       i, NXAV6(v6a));
23576 +skip_v6:
23577 +#endif
23578 +       put_nx_info(nxi);
23579 +out:
23580 +       return buffer - orig;
23581 +}
23582 +
23583 diff -NurpP --minimal linux-2.6.29/kernel/vserver/sched.c linux-2.6.29-vs2.3.0.36.9-pre3/kernel/vserver/sched.c
23584 --- linux-2.6.29/kernel/vserver/sched.c 1970-01-01 01:00:00.000000000 +0100
23585 +++ linux-2.6.29-vs2.3.0.36.9-pre3/kernel/vserver/sched.c       2009-02-22 22:54:26.000000000 +0100
23586 @@ -0,0 +1,414 @@
23587 +/*
23588 + *  linux/kernel/vserver/sched.c
23589 + *
23590 + *  Virtual Server: Scheduler Support
23591 + *
23592 + *  Copyright (C) 2004-2007  Herbert Pötzl
23593 + *
23594 + *  V0.01  adapted Sam Vilains version to 2.6.3
23595 + *  V0.02  removed legacy interface
23596 + *  V0.03  changed vcmds to vxi arg
23597 + *  V0.04  removed older and legacy interfaces
23598 + *
23599 + */
23600 +
23601 +#include <linux/vs_context.h>
23602 +#include <linux/vs_sched.h>
23603 +#include <linux/vserver/sched_cmd.h>
23604 +
23605 +#include <asm/uaccess.h>
23606 +
23607 +
23608 +#define vxd_check_range(val, min, max) do {            \
23609 +       vxlprintk((val < min) || (val > max),           \
23610 +               "check_range(%ld,%ld,%ld)",             \
23611 +               (long)val, (long)min, (long)max,        \
23612 +               __FILE__, __LINE__);                    \
23613 +       } while (0)
23614 +
23615 +
23616 +void vx_update_sched_param(struct _vx_sched *sched,
23617 +       struct _vx_sched_pc *sched_pc)
23618 +{
23619 +       unsigned int set_mask = sched->update_mask;
23620 +
23621 +       if (set_mask & VXSM_FILL_RATE)
23622 +               sched_pc->fill_rate[0] = sched->fill_rate[0];
23623 +       if (set_mask & VXSM_INTERVAL)
23624 +               sched_pc->interval[0] = sched->interval[0];
23625 +       if (set_mask & VXSM_FILL_RATE2)
23626 +               sched_pc->fill_rate[1] = sched->fill_rate[1];
23627 +       if (set_mask & VXSM_INTERVAL2)
23628 +               sched_pc->interval[1] = sched->interval[1];
23629 +       if (set_mask & VXSM_TOKENS)
23630 +               sched_pc->tokens = sched->tokens;
23631 +       if (set_mask & VXSM_TOKENS_MIN)
23632 +               sched_pc->tokens_min = sched->tokens_min;
23633 +       if (set_mask & VXSM_TOKENS_MAX)
23634 +               sched_pc->tokens_max = sched->tokens_max;
23635 +       if (set_mask & VXSM_PRIO_BIAS)
23636 +               sched_pc->prio_bias = sched->prio_bias;
23637 +
23638 +       if (set_mask & VXSM_IDLE_TIME)
23639 +               sched_pc->flags |= VXSF_IDLE_TIME;
23640 +       else
23641 +               sched_pc->flags &= ~VXSF_IDLE_TIME;
23642 +
23643 +       /* reset time */
23644 +       sched_pc->norm_time = jiffies;
23645 +}
23646 +
23647 +
23648 +/*
23649 + * recalculate the context's scheduling tokens
23650 + *
23651 + * ret > 0 : number of tokens available
23652 + * ret < 0 : on hold, check delta_min[]
23653 + *          -1 only jiffies
23654 + *          -2 also idle time
23655 + *
23656 + */
23657 +int vx_tokens_recalc(struct _vx_sched_pc *sched_pc,
23658 +       unsigned long *norm_time, unsigned long *idle_time, int delta_min[2])
23659 +{
23660 +       long delta;
23661 +       long tokens = 0;
23662 +       int flags = sched_pc->flags;
23663 +
23664 +       /* how much time did pass? */
23665 +       delta = *norm_time - sched_pc->norm_time;
23666 +       // printk("@ %ld, %ld, %ld\n", *norm_time, sched_pc->norm_time, jiffies);
23667 +       vxd_check_range(delta, 0, INT_MAX);
23668 +
23669 +       if (delta >= sched_pc->interval[0]) {
23670 +               long tokens, integral;
23671 +
23672 +               /* calc integral token part */
23673 +               tokens = delta / sched_pc->interval[0];
23674 +               integral = tokens * sched_pc->interval[0];
23675 +               tokens *= sched_pc->fill_rate[0];
23676 +#ifdef CONFIG_VSERVER_HARDCPU
23677 +               delta_min[0] = delta - integral;
23678 +               vxd_check_range(delta_min[0], 0, sched_pc->interval[0]);
23679 +#endif
23680 +               /* advance time */
23681 +               sched_pc->norm_time += delta;
23682 +
23683 +               /* add tokens */
23684 +               sched_pc->tokens += tokens;
23685 +               sched_pc->token_time += tokens;
23686 +       } else
23687 +               delta_min[0] = delta;
23688 +
23689 +#ifdef CONFIG_VSERVER_IDLETIME
23690 +       if (!(flags & VXSF_IDLE_TIME))
23691 +               goto skip_idle;
23692 +
23693 +       /* how much was the idle skip? */
23694 +       delta = *idle_time - sched_pc->idle_time;
23695 +       vxd_check_range(delta, 0, INT_MAX);
23696 +
23697 +       if (delta >= sched_pc->interval[1]) {
23698 +               long tokens, integral;
23699 +
23700 +               /* calc fair share token part */
23701 +               tokens = delta / sched_pc->interval[1];
23702 +               integral = tokens * sched_pc->interval[1];
23703 +               tokens *= sched_pc->fill_rate[1];
23704 +               delta_min[1] = delta - integral;
23705 +               vxd_check_range(delta_min[1], 0, sched_pc->interval[1]);
23706 +
23707 +               /* advance idle time */
23708 +               sched_pc->idle_time += integral;
23709 +
23710 +               /* add tokens */
23711 +               sched_pc->tokens += tokens;
23712 +               sched_pc->token_time += tokens;
23713 +       } else
23714 +               delta_min[1] = delta;
23715 +skip_idle:
23716 +#endif
23717 +
23718 +       /* clip at maximum */
23719 +       if (sched_pc->tokens > sched_pc->tokens_max)
23720 +               sched_pc->tokens = sched_pc->tokens_max;
23721 +       tokens = sched_pc->tokens;
23722 +
23723 +       if ((flags & VXSF_ONHOLD)) {
23724 +               /* can we unhold? */
23725 +               if (tokens >= sched_pc->tokens_min) {
23726 +                       flags &= ~VXSF_ONHOLD;
23727 +                       sched_pc->hold_ticks +=
23728 +                               *norm_time - sched_pc->onhold;
23729 +               } else
23730 +                       goto on_hold;
23731 +       } else {
23732 +               /* put on hold? */
23733 +               if (tokens <= 0) {
23734 +                       flags |= VXSF_ONHOLD;
23735 +                       sched_pc->onhold = *norm_time;
23736 +                       goto on_hold;
23737 +               }
23738 +       }
23739 +       sched_pc->flags = flags;
23740 +       return tokens;
23741 +
23742 +on_hold:
23743 +       tokens = sched_pc->tokens_min - tokens;
23744 +       sched_pc->flags = flags;
23745 +       // BUG_ON(tokens < 0); probably doesn't hold anymore
23746 +
23747 +#ifdef CONFIG_VSERVER_HARDCPU
23748 +       /* next interval? */
23749 +       if (!sched_pc->fill_rate[0])
23750 +               delta_min[0] = HZ;
23751 +       else if (tokens > sched_pc->fill_rate[0])
23752 +               delta_min[0] += sched_pc->interval[0] *
23753 +                       tokens / sched_pc->fill_rate[0];
23754 +       else
23755 +               delta_min[0] = sched_pc->interval[0] - delta_min[0];
23756 +       vxd_check_range(delta_min[0], 0, INT_MAX);
23757 +
23758 +#ifdef CONFIG_VSERVER_IDLETIME
23759 +       if (!(flags & VXSF_IDLE_TIME))
23760 +               return -1;
23761 +
23762 +       /* next interval? */
23763 +       if (!sched_pc->fill_rate[1])
23764 +               delta_min[1] = HZ;
23765 +       else if (tokens > sched_pc->fill_rate[1])
23766 +               delta_min[1] += sched_pc->interval[1] *
23767 +                       tokens / sched_pc->fill_rate[1];
23768 +       else
23769 +               delta_min[1] = sched_pc->interval[1] - delta_min[1];
23770 +       vxd_check_range(delta_min[1], 0, INT_MAX);
23771 +
23772 +       return -2;
23773 +#else
23774 +       return -1;
23775 +#endif /* CONFIG_VSERVER_IDLETIME */
23776 +#else
23777 +       return 0;
23778 +#endif /* CONFIG_VSERVER_HARDCPU */
23779 +}
23780 +
23781 +static inline unsigned long msec_to_ticks(unsigned long msec)
23782 +{
23783 +       return msecs_to_jiffies(msec);
23784 +}
23785 +
23786 +static inline unsigned long ticks_to_msec(unsigned long ticks)
23787 +{
23788 +       return jiffies_to_msecs(ticks);
23789 +}
23790 +
23791 +static inline unsigned long ticks_to_usec(unsigned long ticks)
23792 +{
23793 +       return jiffies_to_usecs(ticks);
23794 +}
23795 +
23796 +
23797 +static int do_set_sched(struct vx_info *vxi, struct vcmd_sched_v5 *data)
23798 +{
23799 +       unsigned int set_mask = data->mask;
23800 +       unsigned int update_mask;
23801 +       int i, cpu;
23802 +
23803 +       /* Sanity check data values */
23804 +       if (data->tokens_max <= 0)
23805 +               data->tokens_max = HZ;
23806 +       if (data->tokens_min < 0)
23807 +               data->tokens_min = HZ / 3;
23808 +       if (data->tokens_min >= data->tokens_max)
23809 +               data->tokens_min = data->tokens_max;
23810 +
23811 +       if (data->prio_bias > MAX_PRIO_BIAS)
23812 +               data->prio_bias = MAX_PRIO_BIAS;
23813 +       if (data->prio_bias < MIN_PRIO_BIAS)
23814 +               data->prio_bias = MIN_PRIO_BIAS;
23815 +
23816 +       spin_lock(&vxi->sched.tokens_lock);
23817 +
23818 +       /* sync up on delayed updates */
23819 +       for_each_cpu_mask(cpu, vxi->sched.update)
23820 +               vx_update_sched_param(&vxi->sched,
23821 +                       &vx_per_cpu(vxi, sched_pc, cpu));
23822 +
23823 +       if (set_mask & VXSM_FILL_RATE)
23824 +               vxi->sched.fill_rate[0] = data->fill_rate[0];
23825 +       if (set_mask & VXSM_FILL_RATE2)
23826 +               vxi->sched.fill_rate[1] = data->fill_rate[1];
23827 +       if (set_mask & VXSM_INTERVAL)
23828 +               vxi->sched.interval[0] = (set_mask & VXSM_MSEC) ?
23829 +                       msec_to_ticks(data->interval[0]) : data->interval[0];
23830 +       if (set_mask & VXSM_INTERVAL2)
23831 +               vxi->sched.interval[1] = (set_mask & VXSM_MSEC) ?
23832 +                       msec_to_ticks(data->interval[1]) : data->interval[1];
23833 +       if (set_mask & VXSM_TOKENS)
23834 +               vxi->sched.tokens = data->tokens;
23835 +       if (set_mask & VXSM_TOKENS_MIN)
23836 +               vxi->sched.tokens_min = data->tokens_min;
23837 +       if (set_mask & VXSM_TOKENS_MAX)
23838 +               vxi->sched.tokens_max = data->tokens_max;
23839 +       if (set_mask & VXSM_PRIO_BIAS)
23840 +               vxi->sched.prio_bias = data->prio_bias;
23841 +
23842 +       /* Sanity check rate/interval */
23843 +       for (i = 0; i < 2; i++) {
23844 +               if (data->fill_rate[i] < 0)
23845 +                       data->fill_rate[i] = 0;
23846 +               if (data->interval[i] <= 0)
23847 +                       data->interval[i] = HZ;
23848 +       }
23849 +
23850 +       update_mask = vxi->sched.update_mask & VXSM_SET_MASK;
23851 +       update_mask |= (set_mask & (VXSM_SET_MASK | VXSM_IDLE_TIME));
23852 +       vxi->sched.update_mask = update_mask;
23853 +
23854 +#ifdef CONFIG_SMP
23855 +       rmb();
23856 +       if (set_mask & VXSM_CPU_ID) {
23857 +               vxi->sched.update = cpumask_of_cpu(data->cpu_id);
23858 +               cpus_and(vxi->sched.update, cpu_online_map,
23859 +                       vxi->sched.update);
23860 +       } else
23861 +               vxi->sched.update = cpu_online_map;
23862 +
23863 +       /* forced reload? */
23864 +       if (set_mask & VXSM_FORCE) {
23865 +               for_each_cpu_mask(cpu, vxi->sched.update)
23866 +                       vx_update_sched_param(&vxi->sched,
23867 +                               &vx_per_cpu(vxi, sched_pc, cpu));
23868 +               vxi->sched.update = CPU_MASK_NONE;
23869 +       }
23870 +#else
23871 +       /* on UP we update immediately */
23872 +       vx_update_sched_param(&vxi->sched,
23873 +               &vx_per_cpu(vxi, sched_pc, 0));
23874 +#endif
23875 +
23876 +       spin_unlock(&vxi->sched.tokens_lock);
23877 +       return 0;
23878 +}
23879 +
23880 +
23881 +#define COPY_IDS(C) C(cpu_id); C(bucket_id)
23882 +#define COPY_PRI(C) C(prio_bias)
23883 +#define COPY_TOK(C) C(tokens); C(tokens_min); C(tokens_max)
23884 +#define COPY_FRI(C) C(fill_rate[0]); C(interval[0]);   \
23885 +                   C(fill_rate[1]); C(interval[1]);
23886 +
23887 +#define COPY_VALUE(name) vc_data.name = data->name
23888 +
23889 +static int do_set_sched_v4(struct vx_info *vxi, struct vcmd_set_sched_v4 *data)
23890 +{
23891 +       struct vcmd_sched_v5 vc_data;
23892 +
23893 +       vc_data.mask = data->set_mask;
23894 +       COPY_IDS(COPY_VALUE);
23895 +       COPY_PRI(COPY_VALUE);
23896 +       COPY_TOK(COPY_VALUE);
23897 +       vc_data.fill_rate[0] = vc_data.fill_rate[1] = data->fill_rate;
23898 +       vc_data.interval[0] = vc_data.interval[1] = data->interval;
23899 +       return do_set_sched(vxi, &vc_data);
23900 +}
23901 +
23902 +int vc_set_sched_v4(struct vx_info *vxi, void __user *data)
23903 +{
23904 +       struct vcmd_set_sched_v4 vc_data;
23905 +
23906 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
23907 +               return -EFAULT;
23908 +
23909 +       return do_set_sched_v4(vxi, &vc_data);
23910 +}
23911 +
23912 +       /* latest interface is v5 */
23913 +
23914 +int vc_set_sched(struct vx_info *vxi, void __user *data)
23915 +{
23916 +       struct vcmd_sched_v5 vc_data;
23917 +
23918 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
23919 +               return -EFAULT;
23920 +
23921 +       return do_set_sched(vxi, &vc_data);
23922 +}
23923 +
23924 +
23925 +#define COPY_PRI(C) C(prio_bias)
23926 +#define COPY_TOK(C) C(tokens); C(tokens_min); C(tokens_max)
23927 +#define COPY_FRI(C) C(fill_rate[0]); C(interval[0]);    \
23928 +                   C(fill_rate[1]); C(interval[1]);
23929 +
23930 +#define COPY_VALUE(name) vc_data.name = data->name
23931 +
23932 +
23933 +int vc_get_sched(struct vx_info *vxi, void __user *data)
23934 +{
23935 +       struct vcmd_sched_v5 vc_data;
23936 +
23937 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
23938 +               return -EFAULT;
23939 +
23940 +       if (vc_data.mask & VXSM_CPU_ID) {
23941 +               int cpu = vc_data.cpu_id;
23942 +               struct _vx_sched_pc *data;
23943 +
23944 +               if (!cpu_possible(cpu))
23945 +                       return -EINVAL;
23946 +
23947 +               data = &vx_per_cpu(vxi, sched_pc, cpu);
23948 +               COPY_TOK(COPY_VALUE);
23949 +               COPY_PRI(COPY_VALUE);
23950 +               COPY_FRI(COPY_VALUE);
23951 +
23952 +               if (data->flags & VXSF_IDLE_TIME)
23953 +                       vc_data.mask |= VXSM_IDLE_TIME;
23954 +       } else {
23955 +               struct _vx_sched *data = &vxi->sched;
23956 +
23957 +               COPY_TOK(COPY_VALUE);
23958 +               COPY_PRI(COPY_VALUE);
23959 +               COPY_FRI(COPY_VALUE);
23960 +       }
23961 +
23962 +       if (vc_data.mask & VXSM_MSEC) {
23963 +               vc_data.interval[0] = ticks_to_msec(vc_data.interval[0]);
23964 +               vc_data.interval[1] = ticks_to_msec(vc_data.interval[1]);
23965 +       }
23966 +
23967 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
23968 +               return -EFAULT;
23969 +       return 0;
23970 +}
23971 +
23972 +
23973 +int vc_sched_info(struct vx_info *vxi, void __user *data)
23974 +{
23975 +       struct vcmd_sched_info vc_data;
23976 +       int cpu;
23977 +
23978 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
23979 +               return -EFAULT;
23980 +
23981 +       cpu = vc_data.cpu_id;
23982 +       if (!cpu_possible(cpu))
23983 +               return -EINVAL;
23984 +
23985 +       if (vxi) {
23986 +               struct _vx_sched_pc *sched_pc =
23987 +                       &vx_per_cpu(vxi, sched_pc, cpu);
23988 +
23989 +               vc_data.user_msec = ticks_to_msec(sched_pc->user_ticks);
23990 +               vc_data.sys_msec = ticks_to_msec(sched_pc->sys_ticks);
23991 +               vc_data.hold_msec = ticks_to_msec(sched_pc->hold_ticks);
23992 +               vc_data.vavavoom = sched_pc->vavavoom;
23993 +       }
23994 +       vc_data.token_usec = ticks_to_usec(1);
23995 +
23996 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
23997 +               return -EFAULT;
23998 +       return 0;
23999 +}
24000 +
24001 diff -NurpP --minimal linux-2.6.29/kernel/vserver/sched_init.h linux-2.6.29-vs2.3.0.36.9-pre3/kernel/vserver/sched_init.h
24002 --- linux-2.6.29/kernel/vserver/sched_init.h    1970-01-01 01:00:00.000000000 +0100
24003 +++ linux-2.6.29-vs2.3.0.36.9-pre3/kernel/vserver/sched_init.h  2009-02-22 22:54:26.000000000 +0100
24004 @@ -0,0 +1,50 @@
24005 +
24006 +static inline void vx_info_init_sched(struct _vx_sched *sched)
24007 +{
24008 +       static struct lock_class_key tokens_lock_key;
24009 +
24010 +       /* scheduling; hard code starting values as constants */
24011 +       sched->fill_rate[0]     = 1;
24012 +       sched->interval[0]      = 4;
24013 +       sched->fill_rate[1]     = 1;
24014 +       sched->interval[1]      = 8;
24015 +       sched->tokens           = HZ >> 2;
24016 +       sched->tokens_min       = HZ >> 4;
24017 +       sched->tokens_max       = HZ >> 1;
24018 +       sched->tokens_lock      = SPIN_LOCK_UNLOCKED;
24019 +       sched->prio_bias        = 0;
24020 +
24021 +       lockdep_set_class(&sched->tokens_lock, &tokens_lock_key);
24022 +}
24023 +
24024 +static inline
24025 +void vx_info_init_sched_pc(struct _vx_sched_pc *sched_pc, int cpu)
24026 +{
24027 +       sched_pc->fill_rate[0]  = 1;
24028 +       sched_pc->interval[0]   = 4;
24029 +       sched_pc->fill_rate[1]  = 1;
24030 +       sched_pc->interval[1]   = 8;
24031 +       sched_pc->tokens        = HZ >> 2;
24032 +       sched_pc->tokens_min    = HZ >> 4;
24033 +       sched_pc->tokens_max    = HZ >> 1;
24034 +       sched_pc->prio_bias     = 0;
24035 +       sched_pc->vavavoom      = 0;
24036 +       sched_pc->token_time    = 0;
24037 +       sched_pc->idle_time     = 0;
24038 +       sched_pc->norm_time     = jiffies;
24039 +
24040 +       sched_pc->user_ticks = 0;
24041 +       sched_pc->sys_ticks = 0;
24042 +       sched_pc->hold_ticks = 0;
24043 +}
24044 +
24045 +static inline void vx_info_exit_sched(struct _vx_sched *sched)
24046 +{
24047 +       return;
24048 +}
24049 +
24050 +static inline
24051 +void vx_info_exit_sched_pc(struct _vx_sched_pc *sched_pc, int cpu)
24052 +{
24053 +       return;
24054 +}
24055 diff -NurpP --minimal linux-2.6.29/kernel/vserver/sched_proc.h linux-2.6.29-vs2.3.0.36.9-pre3/kernel/vserver/sched_proc.h
24056 --- linux-2.6.29/kernel/vserver/sched_proc.h    1970-01-01 01:00:00.000000000 +0100
24057 +++ linux-2.6.29-vs2.3.0.36.9-pre3/kernel/vserver/sched_proc.h  2009-02-22 22:54:26.000000000 +0100
24058 @@ -0,0 +1,57 @@
24059 +#ifndef _VX_SCHED_PROC_H
24060 +#define _VX_SCHED_PROC_H
24061 +
24062 +
24063 +static inline
24064 +int vx_info_proc_sched(struct _vx_sched *sched, char *buffer)
24065 +{
24066 +       int length = 0;
24067 +
24068 +       length += sprintf(buffer,
24069 +               "FillRate:\t%8d,%d\n"
24070 +               "Interval:\t%8d,%d\n"
24071 +               "TokensMin:\t%8d\n"
24072 +               "TokensMax:\t%8d\n"
24073 +               "PrioBias:\t%8d\n",
24074 +               sched->fill_rate[0],
24075 +               sched->fill_rate[1],
24076 +               sched->interval[0],
24077 +               sched->interval[1],
24078 +               sched->tokens_min,
24079 +               sched->tokens_max,
24080 +               sched->prio_bias);
24081 +       return length;
24082 +}
24083 +
24084 +static inline
24085 +int vx_info_proc_sched_pc(struct _vx_sched_pc *sched_pc,
24086 +       char *buffer, int cpu)
24087 +{
24088 +       int length = 0;
24089 +
24090 +       length += sprintf(buffer + length,
24091 +               "cpu %d: %lld %lld %lld %ld %ld", cpu,
24092 +               (unsigned long long)sched_pc->user_ticks,
24093 +               (unsigned long long)sched_pc->sys_ticks,
24094 +               (unsigned long long)sched_pc->hold_ticks,
24095 +               sched_pc->token_time,
24096 +               sched_pc->idle_time);
24097 +       length += sprintf(buffer + length,
24098 +               " %c%c %d %d %d %d/%d %d/%d",
24099 +               (sched_pc->flags & VXSF_ONHOLD) ? 'H' : 'R',
24100 +               (sched_pc->flags & VXSF_IDLE_TIME) ? 'I' : '-',
24101 +               sched_pc->tokens,
24102 +               sched_pc->tokens_min,
24103 +               sched_pc->tokens_max,
24104 +               sched_pc->fill_rate[0],
24105 +               sched_pc->interval[0],
24106 +               sched_pc->fill_rate[1],
24107 +               sched_pc->interval[1]);
24108 +       length += sprintf(buffer + length,
24109 +               " %d %d\n",
24110 +               sched_pc->prio_bias,
24111 +               sched_pc->vavavoom);
24112 +       return length;
24113 +}
24114 +
24115 +#endif /* _VX_SCHED_PROC_H */
24116 diff -NurpP --minimal linux-2.6.29/kernel/vserver/signal.c linux-2.6.29-vs2.3.0.36.9-pre3/kernel/vserver/signal.c
24117 --- linux-2.6.29/kernel/vserver/signal.c        1970-01-01 01:00:00.000000000 +0100
24118 +++ linux-2.6.29-vs2.3.0.36.9-pre3/kernel/vserver/signal.c      2009-02-22 22:54:26.000000000 +0100
24119 @@ -0,0 +1,132 @@
24120 +/*
24121 + *  linux/kernel/vserver/signal.c
24122 + *
24123 + *  Virtual Server: Signal Support
24124 + *
24125 + *  Copyright (C) 2003-2007  Herbert Pötzl
24126 + *
24127 + *  V0.01  broken out from vcontext V0.05
24128 + *  V0.02  changed vcmds to vxi arg
24129 + *  V0.03  adjusted siginfo for kill
24130 + *
24131 + */
24132 +
24133 +#include <asm/uaccess.h>
24134 +
24135 +#include <linux/vs_context.h>
24136 +#include <linux/vs_pid.h>
24137 +#include <linux/vserver/signal_cmd.h>
24138 +
24139 +
24140 +int vx_info_kill(struct vx_info *vxi, int pid, int sig)
24141 +{
24142 +       int retval, count = 0;
24143 +       struct task_struct *p;
24144 +       struct siginfo *sip = SEND_SIG_PRIV;
24145 +
24146 +       retval = -ESRCH;
24147 +       vxdprintk(VXD_CBIT(misc, 4),
24148 +               "vx_info_kill(%p[#%d],%d,%d)*",
24149 +               vxi, vxi->vx_id, pid, sig);
24150 +       read_lock(&tasklist_lock);
24151 +       switch (pid) {
24152 +       case  0:
24153 +       case -1:
24154 +               for_each_process(p) {
24155 +                       int err = 0;
24156 +
24157 +                       if (vx_task_xid(p) != vxi->vx_id || p->pid <= 1 ||
24158 +                               (pid && vxi->vx_initpid == p->pid))
24159 +                               continue;
24160 +
24161 +                       err = group_send_sig_info(sig, sip, p);
24162 +                       ++count;
24163 +                       if (err != -EPERM)
24164 +                               retval = err;
24165 +               }
24166 +               break;
24167 +
24168 +       case 1:
24169 +               if (vxi->vx_initpid) {
24170 +                       pid = vxi->vx_initpid;
24171 +                       /* for now, only SIGINT to private init ... */
24172 +                       if (!vx_info_flags(vxi, VXF_STATE_ADMIN, 0) &&
24173 +                               /* ... as long as there are tasks left */
24174 +                               (atomic_read(&vxi->vx_tasks) > 1))
24175 +                               sig = SIGINT;
24176 +               }
24177 +               /* fallthrough */
24178 +       default:
24179 +               p = find_task_by_real_pid(pid);
24180 +               if (p) {
24181 +                       if (vx_task_xid(p) == vxi->vx_id)
24182 +                               retval = group_send_sig_info(sig, sip, p);
24183 +               }
24184 +               break;
24185 +       }
24186 +       read_unlock(&tasklist_lock);
24187 +       vxdprintk(VXD_CBIT(misc, 4),
24188 +               "vx_info_kill(%p[#%d],%d,%d,%ld) = %d",
24189 +               vxi, vxi->vx_id, pid, sig, (long)sip, retval);
24190 +       return retval;
24191 +}
24192 +
24193 +int vc_ctx_kill(struct vx_info *vxi, void __user *data)
24194 +{
24195 +       struct vcmd_ctx_kill_v0 vc_data;
24196 +
24197 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
24198 +               return -EFAULT;
24199 +
24200 +       /* special check to allow guest shutdown */
24201 +       if (!vx_info_flags(vxi, VXF_STATE_ADMIN, 0) &&
24202 +               /* forbid killall pid=0 when init is present */
24203 +               (((vc_data.pid < 1) && vxi->vx_initpid) ||
24204 +               (vc_data.pid > 1)))
24205 +               return -EACCES;
24206 +
24207 +       return vx_info_kill(vxi, vc_data.pid, vc_data.sig);
24208 +}
24209 +
24210 +
24211 +static int __wait_exit(struct vx_info *vxi)
24212 +{
24213 +       DECLARE_WAITQUEUE(wait, current);
24214 +       int ret = 0;
24215 +
24216 +       add_wait_queue(&vxi->vx_wait, &wait);
24217 +       set_current_state(TASK_INTERRUPTIBLE);
24218 +
24219 +wait:
24220 +       if (vx_info_state(vxi,
24221 +               VXS_SHUTDOWN | VXS_HASHED | VXS_HELPER) == VXS_SHUTDOWN)
24222 +               goto out;
24223 +       if (signal_pending(current)) {
24224 +               ret = -ERESTARTSYS;
24225 +               goto out;
24226 +       }
24227 +       schedule();
24228 +       goto wait;
24229 +
24230 +out:
24231 +       set_current_state(TASK_RUNNING);
24232 +       remove_wait_queue(&vxi->vx_wait, &wait);
24233 +       return ret;
24234 +}
24235 +
24236 +
24237 +
24238 +int vc_wait_exit(struct vx_info *vxi, void __user *data)
24239 +{
24240 +       struct vcmd_wait_exit_v0 vc_data;
24241 +       int ret;
24242 +
24243 +       ret = __wait_exit(vxi);
24244 +       vc_data.reboot_cmd = vxi->reboot_cmd;
24245 +       vc_data.exit_code = vxi->exit_code;
24246 +
24247 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
24248 +               ret = -EFAULT;
24249 +       return ret;
24250 +}
24251 +
24252 diff -NurpP --minimal linux-2.6.29/kernel/vserver/space.c linux-2.6.29-vs2.3.0.36.9-pre3/kernel/vserver/space.c
24253 --- linux-2.6.29/kernel/vserver/space.c 1970-01-01 01:00:00.000000000 +0100
24254 +++ linux-2.6.29-vs2.3.0.36.9-pre3/kernel/vserver/space.c       2009-03-31 23:05:11.000000000 +0200
24255 @@ -0,0 +1,387 @@
24256 +/*
24257 + *  linux/kernel/vserver/space.c
24258 + *
24259 + *  Virtual Server: Context Space Support
24260 + *
24261 + *  Copyright (C) 2003-2007  Herbert Pötzl
24262 + *
24263 + *  V0.01  broken out from context.c 0.07
24264 + *  V0.02  added task locking for namespace
24265 + *  V0.03  broken out vx_enter_namespace
24266 + *  V0.04  added *space support and commands
24267 + *
24268 + */
24269 +
24270 +#include <linux/utsname.h>
24271 +#include <linux/nsproxy.h>
24272 +#include <linux/err.h>
24273 +#include <asm/uaccess.h>
24274 +
24275 +#include <linux/vs_context.h>
24276 +#include <linux/vserver/space.h>
24277 +#include <linux/vserver/space_cmd.h>
24278 +
24279 +atomic_t vs_global_nsproxy     = ATOMIC_INIT(0);
24280 +atomic_t vs_global_fs          = ATOMIC_INIT(0);
24281 +atomic_t vs_global_mnt_ns      = ATOMIC_INIT(0);
24282 +atomic_t vs_global_uts_ns      = ATOMIC_INIT(0);
24283 +atomic_t vs_global_ipc_ns      = ATOMIC_INIT(0);
24284 +atomic_t vs_global_user_ns     = ATOMIC_INIT(0);
24285 +atomic_t vs_global_pid_ns      = ATOMIC_INIT(0);
24286 +
24287 +
24288 +/* namespace functions */
24289 +
24290 +#include <linux/mnt_namespace.h>
24291 +#include <linux/user_namespace.h>
24292 +#include <linux/pid_namespace.h>
24293 +#include <linux/ipc_namespace.h>
24294 +#include <net/net_namespace.h>
24295 +
24296 +
24297 +static const struct vcmd_space_mask_v1 space_mask_v0 = {
24298 +       .mask = CLONE_FS |
24299 +               CLONE_NEWNS |
24300 +               CLONE_NEWUTS |
24301 +               CLONE_NEWIPC |
24302 +               /* CLONE_NEWUSER | */
24303 +               0
24304 +};
24305 +
24306 +static const struct vcmd_space_mask_v1 space_mask = {
24307 +       .mask = CLONE_FS |
24308 +               CLONE_NEWNS |
24309 +               CLONE_NEWUTS |
24310 +               CLONE_NEWIPC |
24311 +               /* CLONE_NEWUSER | */
24312 +#ifdef CONFIG_PID_NS
24313 +               CLONE_NEWPID |
24314 +#endif
24315 +#ifdef CONFIG_NET_NS
24316 +               CLONE_NEWNET |
24317 +#endif
24318 +               0
24319 +};
24320 +
24321 +static const struct vcmd_space_mask_v1 default_space_mask = {
24322 +       .mask = CLONE_FS |
24323 +               CLONE_NEWNS |
24324 +               CLONE_NEWUTS |
24325 +               CLONE_NEWIPC |
24326 +               /* CLONE_NEWUSER | */
24327 +#ifdef CONFIG_PID_NS
24328 +//             CLONE_NEWPID |
24329 +#endif
24330 +               0
24331 +};
24332 +
24333 +/*
24334 + *     build a new nsproxy mix
24335 + *      assumes that both proxies are 'const'
24336 + *     does not touch nsproxy refcounts
24337 + *     will hold a reference on the result.
24338 + */
24339 +
24340 +struct nsproxy *vs_mix_nsproxy(struct nsproxy *old_nsproxy,
24341 +       struct nsproxy *new_nsproxy, unsigned long mask)
24342 +{
24343 +       struct mnt_namespace *old_ns;
24344 +       struct uts_namespace *old_uts;
24345 +       struct ipc_namespace *old_ipc;
24346 +#ifdef CONFIG_PID_NS
24347 +       struct pid_namespace *old_pid;
24348 +#endif
24349 +#ifdef CONFIG_NET_NS
24350 +       struct net *old_net;
24351 +#endif
24352 +       struct nsproxy *nsproxy;
24353 +
24354 +       nsproxy = copy_nsproxy(old_nsproxy);
24355 +       if (!nsproxy)
24356 +               goto out;
24357 +
24358 +       if (mask & CLONE_NEWNS) {
24359 +               old_ns = nsproxy->mnt_ns;
24360 +               nsproxy->mnt_ns = new_nsproxy->mnt_ns;
24361 +               if (nsproxy->mnt_ns)
24362 +                       get_mnt_ns(nsproxy->mnt_ns);
24363 +       } else
24364 +               old_ns = NULL;
24365 +
24366 +       if (mask & CLONE_NEWUTS) {
24367 +               old_uts = nsproxy->uts_ns;
24368 +               nsproxy->uts_ns = new_nsproxy->uts_ns;
24369 +               if (nsproxy->uts_ns)
24370 +                       get_uts_ns(nsproxy->uts_ns);
24371 +       } else
24372 +               old_uts = NULL;
24373 +
24374 +       if (mask & CLONE_NEWIPC) {
24375 +               old_ipc = nsproxy->ipc_ns;
24376 +               nsproxy->ipc_ns = new_nsproxy->ipc_ns;
24377 +               if (nsproxy->ipc_ns)
24378 +                       get_ipc_ns(nsproxy->ipc_ns);
24379 +       } else
24380 +               old_ipc = NULL;
24381 +
24382 +#ifdef CONFIG_PID_NS
24383 +       if (mask & CLONE_NEWPID) {
24384 +               old_pid = nsproxy->pid_ns;
24385 +               nsproxy->pid_ns = new_nsproxy->pid_ns;
24386 +               if (nsproxy->pid_ns)
24387 +                       get_pid_ns(nsproxy->pid_ns);
24388 +       } else
24389 +               old_pid = NULL;
24390 +#endif
24391 +#ifdef CONFIG_NET_NS
24392 +       if (mask & CLONE_NEWNET) {
24393 +               old_net = nsproxy->net_ns;
24394 +               nsproxy->net_ns = new_nsproxy->net_ns;
24395 +               if (nsproxy->net_ns)
24396 +                       get_net(nsproxy->net_ns);
24397 +       } else
24398 +               old_net = NULL;
24399 +#endif
24400 +       if (old_ns)
24401 +               put_mnt_ns(old_ns);
24402 +       if (old_uts)
24403 +               put_uts_ns(old_uts);
24404 +       if (old_ipc)
24405 +               put_ipc_ns(old_ipc);
24406 +#ifdef CONFIG_PID_NS
24407 +       if (old_pid)
24408 +               put_pid_ns(old_pid);
24409 +#endif
24410 +#ifdef CONFIG_NET_NS
24411 +       if (old_net)
24412 +               put_net(old_net);
24413 +#endif
24414 +out:
24415 +       return nsproxy;
24416 +}
24417 +
24418 +
24419 +/*
24420 + *     merge two nsproxy structs into a new one.
24421 + *     will hold a reference on the result.
24422 + */
24423 +
24424 +static inline
24425 +struct nsproxy *__vs_merge_nsproxy(struct nsproxy *old,
24426 +       struct nsproxy *proxy, unsigned long mask)
24427 +{
24428 +       struct nsproxy null_proxy = { .mnt_ns = NULL };
24429 +
24430 +       if (!proxy)
24431 +               return NULL;
24432 +
24433 +       if (mask) {
24434 +               /* vs_mix_nsproxy returns with reference */
24435 +               return vs_mix_nsproxy(old ? old : &null_proxy,
24436 +                       proxy, mask);
24437 +       }
24438 +       get_nsproxy(proxy);
24439 +       return proxy;
24440 +}
24441 +
24442 +/*
24443 + *     merge two fs structs into a new one.
24444 + *     will take a reference on the result.
24445 + */
24446 +
24447 +static inline
24448 +struct fs_struct *__vs_merge_fs(struct fs_struct *old,
24449 +       struct fs_struct *fs, unsigned long mask)
24450 +{
24451 +       if (!(mask & CLONE_FS)) {
24452 +               if (old)
24453 +                       atomic_inc(&old->count);
24454 +               return old;
24455 +       }
24456 +
24457 +       if (!fs)
24458 +               return NULL;
24459 +
24460 +       return copy_fs_struct(fs);
24461 +}
24462 +
24463 +
24464 +int vx_enter_space(struct vx_info *vxi, unsigned long mask, unsigned index)
24465 +{
24466 +       struct nsproxy *proxy, *proxy_cur, *proxy_new;
24467 +       struct fs_struct *fs, *fs_cur, *fs_new;
24468 +       int ret;
24469 +
24470 +       vxdprintk(VXD_CBIT(space, 8), "vx_enter_space(%p[#%u],0x%08lx,%d)",
24471 +               vxi, vxi->vx_id, mask, index);
24472 +
24473 +       if (vx_info_flags(vxi, VXF_INFO_PRIVATE, 0))
24474 +               return -EACCES;
24475 +
24476 +       if (!mask)
24477 +               mask = vxi->vx_nsmask[index];
24478 +
24479 +       if ((mask & vxi->vx_nsmask[index]) != mask)
24480 +               return -EINVAL;
24481 +
24482 +       proxy = vxi->vx_nsproxy[index];
24483 +       fs = vxi->vx_fs[index];
24484 +
24485 +       task_lock(current);
24486 +       fs_cur = current->fs;
24487 +       atomic_inc(&fs_cur->count);
24488 +       proxy_cur = current->nsproxy;
24489 +       get_nsproxy(proxy_cur);
24490 +       task_unlock(current);
24491 +
24492 +       fs_new = __vs_merge_fs(fs_cur, fs, mask);
24493 +       if (IS_ERR(fs_new)) {
24494 +               ret = PTR_ERR(fs_new);
24495 +               goto out_put;
24496 +       }
24497 +
24498 +       proxy_new = __vs_merge_nsproxy(proxy_cur, proxy, mask);
24499 +       if (IS_ERR(proxy_new)) {
24500 +               ret = PTR_ERR(proxy_new);
24501 +               goto out_put_fs;
24502 +       }
24503 +
24504 +       fs_new = xchg(&current->fs, fs_new);
24505 +       proxy_new = xchg(&current->nsproxy, proxy_new);
24506 +       ret = 0;
24507 +
24508 +       if (proxy_new)
24509 +               put_nsproxy(proxy_new);
24510 +out_put_fs:
24511 +       if (fs_new)
24512 +               put_fs_struct(fs_new);
24513 +out_put:
24514 +       if (proxy_cur)
24515 +               put_nsproxy(proxy_cur);
24516 +       if (fs_cur)
24517 +               put_fs_struct(fs_cur);
24518 +       return ret;
24519 +}
24520 +
24521 +
24522 +int vx_set_space(struct vx_info *vxi, unsigned long mask, unsigned index)
24523 +{
24524 +       struct nsproxy *proxy_vxi, *proxy_cur, *proxy_new;
24525 +       struct fs_struct *fs_vxi, *fs_cur, *fs_new;
24526 +       int ret;
24527 +
24528 +       vxdprintk(VXD_CBIT(space, 8), "vx_set_space(%p[#%u],0x%08lx,%d)",
24529 +               vxi, vxi->vx_id, mask, index);
24530 +#if 0
24531 +       if (!mask)
24532 +               mask = default_space_mask.mask;
24533 +#endif
24534 +       if ((mask & space_mask.mask) != mask)
24535 +               return -EINVAL;
24536 +
24537 +       proxy_vxi = vxi->vx_nsproxy[index];
24538 +       fs_vxi = vxi->vx_fs[index];
24539 +
24540 +       task_lock(current);
24541 +       fs_cur = current->fs;
24542 +       atomic_inc(&fs_cur->count);
24543 +       proxy_cur = current->nsproxy;
24544 +       get_nsproxy(proxy_cur);
24545 +       task_unlock(current);
24546 +
24547 +       fs_new = __vs_merge_fs(fs_vxi, fs_cur, mask);
24548 +       if (IS_ERR(fs_new)) {
24549 +               ret = PTR_ERR(fs_new);
24550 +               goto out_put;
24551 +       }
24552 +
24553 +       proxy_new = __vs_merge_nsproxy(proxy_vxi, proxy_cur, mask);
24554 +       if (IS_ERR(proxy_new)) {
24555 +               ret = PTR_ERR(proxy_new);
24556 +               goto out_put_fs;
24557 +       }
24558 +
24559 +       fs_new = xchg(&vxi->vx_fs[index], fs_new);
24560 +       proxy_new = xchg(&vxi->vx_nsproxy[index], proxy_new);
24561 +       vxi->vx_nsmask[index] |= mask;
24562 +       ret = 0;
24563 +
24564 +       if (proxy_new)
24565 +               put_nsproxy(proxy_new);
24566 +out_put_fs:
24567 +       if (fs_new)
24568 +               put_fs_struct(fs_new);
24569 +out_put:
24570 +       if (proxy_cur)
24571 +               put_nsproxy(proxy_cur);
24572 +       if (fs_cur)
24573 +               put_fs_struct(fs_cur);
24574 +       return ret;
24575 +}
24576 +
24577 +
24578 +int vc_enter_space_v1(struct vx_info *vxi, void __user *data)
24579 +{
24580 +       struct vcmd_space_mask_v1 vc_data = { .mask = 0 };
24581 +
24582 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
24583 +               return -EFAULT;
24584 +
24585 +       return vx_enter_space(vxi, vc_data.mask, 0);
24586 +}
24587 +
24588 +int vc_enter_space(struct vx_info *vxi, void __user *data)
24589 +{
24590 +       struct vcmd_space_mask_v2 vc_data = { .mask = 0 };
24591 +
24592 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
24593 +               return -EFAULT;
24594 +
24595 +       if (vc_data.index >= VX_SPACES)
24596 +               return -EINVAL;
24597 +
24598 +       return vx_enter_space(vxi, vc_data.mask, vc_data.index);
24599 +}
24600 +
24601 +int vc_set_space_v1(struct vx_info *vxi, void __user *data)
24602 +{
24603 +       struct vcmd_space_mask_v1 vc_data = { .mask = 0 };
24604 +
24605 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
24606 +               return -EFAULT;
24607 +
24608 +       return vx_set_space(vxi, vc_data.mask, 0);
24609 +}
24610 +
24611 +int vc_set_space(struct vx_info *vxi, void __user *data)
24612 +{
24613 +       struct vcmd_space_mask_v2 vc_data = { .mask = 0 };
24614 +
24615 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
24616 +               return -EFAULT;
24617 +
24618 +       if (vc_data.index >= VX_SPACES)
24619 +               return -EINVAL;
24620 +
24621 +       return vx_set_space(vxi, vc_data.mask, vc_data.index);
24622 +}
24623 +
24624 +int vc_get_space_mask(void __user *data, int type)
24625 +{
24626 +       const struct vcmd_space_mask_v1 *mask;
24627 +
24628 +       if (type == 0)
24629 +               mask = &space_mask_v0;
24630 +       else if (type == 1)
24631 +               mask = &space_mask;
24632 +       else
24633 +               mask = &default_space_mask;
24634 +
24635 +       vxdprintk(VXD_CBIT(space, 10),
24636 +               "vc_get_space_mask(%d) = %08llx", type, mask->mask);
24637 +
24638 +       if (copy_to_user(data, mask, sizeof(*mask)))
24639 +               return -EFAULT;
24640 +       return 0;
24641 +}
24642 +
24643 diff -NurpP --minimal linux-2.6.29/kernel/vserver/switch.c linux-2.6.29-vs2.3.0.36.9-pre3/kernel/vserver/switch.c
24644 --- linux-2.6.29/kernel/vserver/switch.c        1970-01-01 01:00:00.000000000 +0100
24645 +++ linux-2.6.29-vs2.3.0.36.9-pre3/kernel/vserver/switch.c      2009-03-24 14:59:18.000000000 +0100
24646 @@ -0,0 +1,543 @@
24647 +/*
24648 + *  linux/kernel/vserver/switch.c
24649 + *
24650 + *  Virtual Server: Syscall Switch
24651 + *
24652 + *  Copyright (C) 2003-2007  Herbert Pötzl
24653 + *
24654 + *  V0.01  syscall switch
24655 + *  V0.02  added signal to context
24656 + *  V0.03  added rlimit functions
24657 + *  V0.04  added iattr, task/xid functions
24658 + *  V0.05  added debug/history stuff
24659 + *  V0.06  added compat32 layer
24660 + *  V0.07  vcmd args and perms
24661 + *  V0.08  added status commands
24662 + *  V0.09  added tag commands
24663 + *  V0.10  added oom bias
24664 + *  V0.11  added device commands
24665 + *
24666 + */
24667 +
24668 +#include <linux/vs_context.h>
24669 +#include <linux/vs_network.h>
24670 +#include <linux/vserver/switch.h>
24671 +
24672 +#include "vci_config.h"
24673 +
24674 +
24675 +static inline
24676 +int vc_get_version(uint32_t id)
24677 +{
24678 +       return VCI_VERSION;
24679 +}
24680 +
24681 +static inline
24682 +int vc_get_vci(uint32_t id)
24683 +{
24684 +       return vci_kernel_config();
24685 +}
24686 +
24687 +#include <linux/vserver/context_cmd.h>
24688 +#include <linux/vserver/cvirt_cmd.h>
24689 +#include <linux/vserver/cacct_cmd.h>
24690 +#include <linux/vserver/limit_cmd.h>
24691 +#include <linux/vserver/network_cmd.h>
24692 +#include <linux/vserver/sched_cmd.h>
24693 +#include <linux/vserver/debug_cmd.h>
24694 +#include <linux/vserver/inode_cmd.h>
24695 +#include <linux/vserver/dlimit_cmd.h>
24696 +#include <linux/vserver/signal_cmd.h>
24697 +#include <linux/vserver/space_cmd.h>
24698 +#include <linux/vserver/tag_cmd.h>
24699 +#include <linux/vserver/device_cmd.h>
24700 +
24701 +#include <linux/vserver/inode.h>
24702 +#include <linux/vserver/dlimit.h>
24703 +
24704 +
24705 +#ifdef CONFIG_COMPAT
24706 +#define __COMPAT(name, id, data, compat)       \
24707 +       (compat) ? name ## _x32(id, data) : name(id, data)
24708 +#define __COMPAT_NO_ID(name, data, compat)     \
24709 +       (compat) ? name ## _x32(data) : name(data)
24710 +#else
24711 +#define __COMPAT(name, id, data, compat)       \
24712 +       name(id, data)
24713 +#define __COMPAT_NO_ID(name, data, compat)     \
24714 +       name(data)
24715 +#endif
24716 +
24717 +
24718 +static inline
24719 +long do_vcmd(uint32_t cmd, uint32_t id,
24720 +       struct vx_info *vxi, struct nx_info *nxi,
24721 +       void __user *data, int compat)
24722 +{
24723 +       switch (cmd) {
24724 +
24725 +       case VCMD_get_version:
24726 +               return vc_get_version(id);
24727 +       case VCMD_get_vci:
24728 +               return vc_get_vci(id);
24729 +
24730 +       case VCMD_task_xid:
24731 +               return vc_task_xid(id);
24732 +       case VCMD_vx_info:
24733 +               return vc_vx_info(vxi, data);
24734 +
24735 +       case VCMD_task_nid:
24736 +               return vc_task_nid(id);
24737 +       case VCMD_nx_info:
24738 +               return vc_nx_info(nxi, data);
24739 +
24740 +       case VCMD_task_tag:
24741 +               return vc_task_tag(id);
24742 +
24743 +       case VCMD_set_space_v1:
24744 +               return vc_set_space_v1(vxi, data);
24745 +       /* this is version 2 */
24746 +       case VCMD_set_space:
24747 +               return vc_set_space(vxi, data);
24748 +
24749 +       case VCMD_get_space_mask_v0:
24750 +               return vc_get_space_mask(data, 0);
24751 +       /* this is version 1 */
24752 +       case VCMD_get_space_mask:
24753 +               return vc_get_space_mask(data, 1);
24754 +
24755 +       case VCMD_get_space_default:
24756 +               return vc_get_space_mask(data, -1);
24757 +
24758 +#ifdef CONFIG_IA32_EMULATION
24759 +       case VCMD_get_rlimit:
24760 +               return __COMPAT(vc_get_rlimit, vxi, data, compat);
24761 +       case VCMD_set_rlimit:
24762 +               return __COMPAT(vc_set_rlimit, vxi, data, compat);
24763 +#else
24764 +       case VCMD_get_rlimit:
24765 +               return vc_get_rlimit(vxi, data);
24766 +       case VCMD_set_rlimit:
24767 +               return vc_set_rlimit(vxi, data);
24768 +#endif
24769 +       case VCMD_get_rlimit_mask:
24770 +               return vc_get_rlimit_mask(id, data);
24771 +       case VCMD_reset_minmax:
24772 +               return vc_reset_minmax(vxi, data);
24773 +
24774 +       case VCMD_get_vhi_name:
24775 +               return vc_get_vhi_name(vxi, data);
24776 +       case VCMD_set_vhi_name:
24777 +               return vc_set_vhi_name(vxi, data);
24778 +
24779 +       case VCMD_ctx_stat:
24780 +               return vc_ctx_stat(vxi, data);
24781 +       case VCMD_virt_stat:
24782 +               return vc_virt_stat(vxi, data);
24783 +       case VCMD_sock_stat:
24784 +               return vc_sock_stat(vxi, data);
24785 +       case VCMD_rlimit_stat:
24786 +               return vc_rlimit_stat(vxi, data);
24787 +
24788 +       case VCMD_set_cflags:
24789 +               return vc_set_cflags(vxi, data);
24790 +       case VCMD_get_cflags:
24791 +               return vc_get_cflags(vxi, data);
24792 +
24793 +       /* this is version 1 */
24794 +       case VCMD_set_ccaps:
24795 +               return vc_set_ccaps(vxi, data);
24796 +       /* this is version 1 */
24797 +       case VCMD_get_ccaps:
24798 +               return vc_get_ccaps(vxi, data);
24799 +       case VCMD_set_bcaps:
24800 +               return vc_set_bcaps(vxi, data);
24801 +       case VCMD_get_bcaps:
24802 +               return vc_get_bcaps(vxi, data);
24803 +
24804 +       case VCMD_set_badness:
24805 +               return vc_set_badness(vxi, data);
24806 +       case VCMD_get_badness:
24807 +               return vc_get_badness(vxi, data);
24808 +
24809 +       case VCMD_set_nflags:
24810 +               return vc_set_nflags(nxi, data);
24811 +       case VCMD_get_nflags:
24812 +               return vc_get_nflags(nxi, data);
24813 +
24814 +       case VCMD_set_ncaps:
24815 +               return vc_set_ncaps(nxi, data);
24816 +       case VCMD_get_ncaps:
24817 +               return vc_get_ncaps(nxi, data);
24818 +
24819 +       case VCMD_set_sched_v4:
24820 +               return vc_set_sched_v4(vxi, data);
24821 +       /* this is version 5 */
24822 +       case VCMD_set_sched:
24823 +               return vc_set_sched(vxi, data);
24824 +       case VCMD_get_sched:
24825 +               return vc_get_sched(vxi, data);
24826 +       case VCMD_sched_info:
24827 +               return vc_sched_info(vxi, data);
24828 +
24829 +       case VCMD_add_dlimit:
24830 +               return __COMPAT(vc_add_dlimit, id, data, compat);
24831 +       case VCMD_rem_dlimit:
24832 +               return __COMPAT(vc_rem_dlimit, id, data, compat);
24833 +       case VCMD_set_dlimit:
24834 +               return __COMPAT(vc_set_dlimit, id, data, compat);
24835 +       case VCMD_get_dlimit:
24836 +               return __COMPAT(vc_get_dlimit, id, data, compat);
24837 +
24838 +       case VCMD_ctx_kill:
24839 +               return vc_ctx_kill(vxi, data);
24840 +
24841 +       case VCMD_wait_exit:
24842 +               return vc_wait_exit(vxi, data);
24843 +
24844 +       case VCMD_get_iattr:
24845 +               return __COMPAT_NO_ID(vc_get_iattr, data, compat);
24846 +       case VCMD_set_iattr:
24847 +               return __COMPAT_NO_ID(vc_set_iattr, data, compat);
24848 +
24849 +       case VCMD_fget_iattr:
24850 +               return vc_fget_iattr(id, data);
24851 +       case VCMD_fset_iattr:
24852 +               return vc_fset_iattr(id, data);
24853 +
24854 +       case VCMD_enter_space_v0:
24855 +               return vc_enter_space_v1(vxi, NULL);
24856 +       case VCMD_enter_space_v1:
24857 +               return vc_enter_space_v1(vxi, data);
24858 +       /* this is version 2 */
24859 +       case VCMD_enter_space:
24860 +               return vc_enter_space(vxi, data);
24861 +
24862 +       case VCMD_ctx_create_v0:
24863 +               return vc_ctx_create(id, NULL);
24864 +       case VCMD_ctx_create:
24865 +               return vc_ctx_create(id, data);
24866 +       case VCMD_ctx_migrate_v0:
24867 +               return vc_ctx_migrate(vxi, NULL);
24868 +       case VCMD_ctx_migrate:
24869 +               return vc_ctx_migrate(vxi, data);
24870 +
24871 +       case VCMD_net_create_v0:
24872 +               return vc_net_create(id, NULL);
24873 +       case VCMD_net_create:
24874 +               return vc_net_create(id, data);
24875 +       case VCMD_net_migrate:
24876 +               return vc_net_migrate(nxi, data);
24877 +
24878 +       case VCMD_tag_migrate:
24879 +               return vc_tag_migrate(id);
24880 +
24881 +       case VCMD_net_add:
24882 +               return vc_net_add(nxi, data);
24883 +       case VCMD_net_remove:
24884 +               return vc_net_remove(nxi, data);
24885 +
24886 +       case VCMD_net_add_ipv4:
24887 +               return vc_net_add_ipv4(nxi, data);
24888 +       case VCMD_net_remove_ipv4:
24889 +               return vc_net_remove_ipv4(nxi, data);
24890 +#ifdef CONFIG_IPV6
24891 +       case VCMD_net_add_ipv6:
24892 +               return vc_net_add_ipv6(nxi, data);
24893 +       case VCMD_net_remove_ipv6:
24894 +               return vc_net_remove_ipv6(nxi, data);
24895 +#endif
24896 +/*     case VCMD_add_match_ipv4:
24897 +               return vc_add_match_ipv4(nxi, data);
24898 +       case VCMD_get_match_ipv4:
24899 +               return vc_get_match_ipv4(nxi, data);
24900 +#ifdef CONFIG_IPV6
24901 +       case VCMD_add_match_ipv6:
24902 +               return vc_add_match_ipv6(nxi, data);
24903 +       case VCMD_get_match_ipv6:
24904 +               return vc_get_match_ipv6(nxi, data);
24905 +#endif */
24906 +
24907 +#ifdef CONFIG_VSERVER_DEVICE
24908 +       case VCMD_set_mapping:
24909 +               return __COMPAT(vc_set_mapping, vxi, data, compat);
24910 +       case VCMD_unset_mapping:
24911 +               return __COMPAT(vc_unset_mapping, vxi, data, compat);
24912 +#endif
24913 +#ifdef CONFIG_VSERVER_HISTORY
24914 +       case VCMD_dump_history:
24915 +               return vc_dump_history(id);
24916 +       case VCMD_read_history:
24917 +               return __COMPAT(vc_read_history, id, data, compat);
24918 +#endif
24919 +#ifdef CONFIG_VSERVER_MONITOR
24920 +       case VCMD_read_monitor:
24921 +               return __COMPAT(vc_read_monitor, id, data, compat);
24922 +#endif
24923 +       default:
24924 +               vxwprintk_task(1, "unimplemented VCMD_%02d_%d[%d]",
24925 +                       VC_CATEGORY(cmd), VC_COMMAND(cmd), VC_VERSION(cmd));
24926 +       }
24927 +       return -ENOSYS;
24928 +}
24929 +
24930 +
24931 +#define        __VCMD(vcmd, _perm, _args, _flags)              \
24932 +       case VCMD_ ## vcmd: perm = _perm;               \
24933 +               args = _args; flags = _flags; break
24934 +
24935 +
24936 +#define VCA_NONE       0x00
24937 +#define VCA_VXI                0x01
24938 +#define VCA_NXI                0x02
24939 +
24940 +#define VCF_NONE       0x00
24941 +#define VCF_INFO       0x01
24942 +#define VCF_ADMIN      0x02
24943 +#define VCF_ARES       0x06    /* includes admin */
24944 +#define VCF_SETUP      0x08
24945 +
24946 +#define VCF_ZIDOK      0x10    /* zero id okay */
24947 +
24948 +
24949 +static inline
24950 +long do_vserver(uint32_t cmd, uint32_t id, void __user *data, int compat)
24951 +{
24952 +       long ret;
24953 +       int permit = -1, state = 0;
24954 +       int perm = -1, args = 0, flags = 0;
24955 +       struct vx_info *vxi = NULL;
24956 +       struct nx_info *nxi = NULL;
24957 +
24958 +       switch (cmd) {
24959 +       /* unpriviledged commands */
24960 +       __VCMD(get_version,      0, VCA_NONE,   0);
24961 +       __VCMD(get_vci,          0, VCA_NONE,   0);
24962 +       __VCMD(get_rlimit_mask,  0, VCA_NONE,   0);
24963 +       __VCMD(get_space_mask_v0,0, VCA_NONE,   0);
24964 +       __VCMD(get_space_mask,   0, VCA_NONE,   0);
24965 +       __VCMD(get_space_default,0, VCA_NONE,   0);
24966 +
24967 +       /* info commands */
24968 +       __VCMD(task_xid,         2, VCA_NONE,   0);
24969 +       __VCMD(reset_minmax,     2, VCA_VXI,    0);
24970 +       __VCMD(vx_info,          3, VCA_VXI,    VCF_INFO);
24971 +       __VCMD(get_bcaps,        3, VCA_VXI,    VCF_INFO);
24972 +       __VCMD(get_ccaps,        3, VCA_VXI,    VCF_INFO);
24973 +       __VCMD(get_cflags,       3, VCA_VXI,    VCF_INFO);
24974 +       __VCMD(get_badness,      3, VCA_VXI,    VCF_INFO);
24975 +       __VCMD(get_vhi_name,     3, VCA_VXI,    VCF_INFO);
24976 +       __VCMD(get_rlimit,       3, VCA_VXI,    VCF_INFO);
24977 +
24978 +       __VCMD(ctx_stat,         3, VCA_VXI,    VCF_INFO);
24979 +       __VCMD(virt_stat,        3, VCA_VXI,    VCF_INFO);
24980 +       __VCMD(sock_stat,        3, VCA_VXI,    VCF_INFO);
24981 +       __VCMD(rlimit_stat,      3, VCA_VXI,    VCF_INFO);
24982 +
24983 +       __VCMD(task_nid,         2, VCA_NONE,   0);
24984 +       __VCMD(nx_info,          3, VCA_NXI,    VCF_INFO);
24985 +       __VCMD(get_ncaps,        3, VCA_NXI,    VCF_INFO);
24986 +       __VCMD(get_nflags,       3, VCA_NXI,    VCF_INFO);
24987 +
24988 +       __VCMD(task_tag,         2, VCA_NONE,   0);
24989 +
24990 +       __VCMD(get_iattr,        2, VCA_NONE,   0);
24991 +       __VCMD(fget_iattr,       2, VCA_NONE,   0);
24992 +       __VCMD(get_dlimit,       3, VCA_NONE,   VCF_INFO);
24993 +       __VCMD(get_sched,        3, VCA_VXI,    VCF_INFO);
24994 +       __VCMD(sched_info,       3, VCA_VXI,    VCF_INFO | VCF_ZIDOK);
24995 +
24996 +       /* lower admin commands */
24997 +       __VCMD(wait_exit,        4, VCA_VXI,    VCF_INFO);
24998 +       __VCMD(ctx_create_v0,    5, VCA_NONE,   0);
24999 +       __VCMD(ctx_create,       5, VCA_NONE,   0);
25000 +       __VCMD(ctx_migrate_v0,   5, VCA_VXI,    VCF_ADMIN);
25001 +       __VCMD(ctx_migrate,      5, VCA_VXI,    VCF_ADMIN);
25002 +       __VCMD(enter_space_v0,   5, VCA_VXI,    VCF_ADMIN);
25003 +       __VCMD(enter_space_v1,   5, VCA_VXI,    VCF_ADMIN);
25004 +       __VCMD(enter_space,      5, VCA_VXI,    VCF_ADMIN);
25005 +
25006 +       __VCMD(net_create_v0,    5, VCA_NONE,   0);
25007 +       __VCMD(net_create,       5, VCA_NONE,   0);
25008 +       __VCMD(net_migrate,      5, VCA_NXI,    VCF_ADMIN);
25009 +
25010 +       __VCMD(tag_migrate,      5, VCA_NONE,   VCF_ADMIN);
25011 +
25012 +       /* higher admin commands */
25013 +       __VCMD(ctx_kill,         6, VCA_VXI,    VCF_ARES);
25014 +       __VCMD(set_space_v1,     7, VCA_VXI,    VCF_ARES | VCF_SETUP);
25015 +       __VCMD(set_space,        7, VCA_VXI,    VCF_ARES | VCF_SETUP);
25016 +
25017 +       __VCMD(set_ccaps,        7, VCA_VXI,    VCF_ARES | VCF_SETUP);
25018 +       __VCMD(set_bcaps,        7, VCA_VXI,    VCF_ARES | VCF_SETUP);
25019 +       __VCMD(set_cflags,       7, VCA_VXI,    VCF_ARES | VCF_SETUP);
25020 +       __VCMD(set_badness,      7, VCA_VXI,    VCF_ARES | VCF_SETUP);
25021 +
25022 +       __VCMD(set_vhi_name,     7, VCA_VXI,    VCF_ARES | VCF_SETUP);
25023 +       __VCMD(set_rlimit,       7, VCA_VXI,    VCF_ARES | VCF_SETUP);
25024 +       __VCMD(set_sched,        7, VCA_VXI,    VCF_ARES | VCF_SETUP);
25025 +       __VCMD(set_sched_v4,     7, VCA_VXI,    VCF_ARES | VCF_SETUP);
25026 +
25027 +       __VCMD(set_ncaps,        7, VCA_NXI,    VCF_ARES | VCF_SETUP);
25028 +       __VCMD(set_nflags,       7, VCA_NXI,    VCF_ARES | VCF_SETUP);
25029 +       __VCMD(net_add,          8, VCA_NXI,    VCF_ARES | VCF_SETUP);
25030 +       __VCMD(net_remove,       8, VCA_NXI,    VCF_ARES | VCF_SETUP);
25031 +       __VCMD(net_add_ipv4,     8, VCA_NXI,    VCF_ARES | VCF_SETUP);
25032 +       __VCMD(net_remove_ipv4,  8, VCA_NXI,    VCF_ARES | VCF_SETUP);
25033 +#ifdef CONFIG_IPV6
25034 +       __VCMD(net_add_ipv6,     8, VCA_NXI,    VCF_ARES | VCF_SETUP);
25035 +       __VCMD(net_remove_ipv6,  8, VCA_NXI,    VCF_ARES | VCF_SETUP);
25036 +#endif
25037 +       __VCMD(set_iattr,        7, VCA_NONE,   0);
25038 +       __VCMD(fset_iattr,       7, VCA_NONE,   0);
25039 +       __VCMD(set_dlimit,       7, VCA_NONE,   VCF_ARES);
25040 +       __VCMD(add_dlimit,       8, VCA_NONE,   VCF_ARES);
25041 +       __VCMD(rem_dlimit,       8, VCA_NONE,   VCF_ARES);
25042 +
25043 +#ifdef CONFIG_VSERVER_DEVICE
25044 +       __VCMD(set_mapping,      8, VCA_VXI,    VCF_ARES|VCF_ZIDOK);
25045 +       __VCMD(unset_mapping,    8, VCA_VXI,    VCF_ARES|VCF_ZIDOK);
25046 +#endif
25047 +       /* debug level admin commands */
25048 +#ifdef CONFIG_VSERVER_HISTORY
25049 +       __VCMD(dump_history,     9, VCA_NONE,   0);
25050 +       __VCMD(read_history,     9, VCA_NONE,   0);
25051 +#endif
25052 +#ifdef CONFIG_VSERVER_MONITOR
25053 +       __VCMD(read_monitor,     9, VCA_NONE,   0);
25054 +#endif
25055 +
25056 +       default:
25057 +               perm = -1;
25058 +       }
25059 +
25060 +       vxdprintk(VXD_CBIT(switch, 0),
25061 +               "vc: VCMD_%02d_%d[%d], %d,%p [%d,%d,%x,%x]",
25062 +               VC_CATEGORY(cmd), VC_COMMAND(cmd),
25063 +               VC_VERSION(cmd), id, data, compat,
25064 +               perm, args, flags);
25065 +
25066 +       ret = -ENOSYS;
25067 +       if (perm < 0)
25068 +               goto out;
25069 +
25070 +       state = 1;
25071 +       if (!capable(CAP_CONTEXT))
25072 +               goto out;
25073 +
25074 +       state = 2;
25075 +       /* moved here from the individual commands */
25076 +       ret = -EPERM;
25077 +       if ((perm > 1) && !capable(CAP_SYS_ADMIN))
25078 +               goto out;
25079 +
25080 +       state = 3;
25081 +       /* vcmd involves resource management  */
25082 +       ret = -EPERM;
25083 +       if ((flags & VCF_ARES) && !capable(CAP_SYS_RESOURCE))
25084 +               goto out;
25085 +
25086 +       state = 4;
25087 +       /* various legacy exceptions */
25088 +       switch (cmd) {
25089 +       /* will go away when spectator is a cap */
25090 +       case VCMD_ctx_migrate_v0:
25091 +       case VCMD_ctx_migrate:
25092 +               if (id == 1) {
25093 +                       current->xid = 1;
25094 +                       ret = 1;
25095 +                       goto out;
25096 +               }
25097 +               break;
25098 +
25099 +       /* will go away when spectator is a cap */
25100 +       case VCMD_net_migrate:
25101 +               if (id == 1) {
25102 +                       current->nid = 1;
25103 +                       ret = 1;
25104 +                       goto out;
25105 +               }
25106 +               break;
25107 +       }
25108 +
25109 +       /* vcmds are fine by default */
25110 +       permit = 1;
25111 +
25112 +       /* admin type vcmds require admin ... */
25113 +       if (flags & VCF_ADMIN)
25114 +               permit = vx_check(0, VS_ADMIN) ? 1 : 0;
25115 +
25116 +       /* ... but setup type vcmds override that */
25117 +       if (!permit && (flags & VCF_SETUP))
25118 +               permit = vx_flags(VXF_STATE_SETUP, 0) ? 2 : 0;
25119 +
25120 +       state = 5;
25121 +       ret = -EPERM;
25122 +       if (!permit)
25123 +               goto out;
25124 +
25125 +       state = 6;
25126 +       if (!id && (flags & VCF_ZIDOK))
25127 +               goto skip_id;
25128 +
25129 +       ret = -ESRCH;
25130 +       if (args & VCA_VXI) {
25131 +               vxi = lookup_vx_info(id);
25132 +               if (!vxi)
25133 +                       goto out;
25134 +
25135 +               if ((flags & VCF_ADMIN) &&
25136 +                       /* special case kill for shutdown */
25137 +                       (cmd != VCMD_ctx_kill) &&
25138 +                       /* can context be administrated? */
25139 +                       !vx_info_flags(vxi, VXF_STATE_ADMIN, 0)) {
25140 +                       ret = -EACCES;
25141 +                       goto out_vxi;
25142 +               }
25143 +       }
25144 +       state = 7;
25145 +       if (args & VCA_NXI) {
25146 +               nxi = lookup_nx_info(id);
25147 +               if (!nxi)
25148 +                       goto out_vxi;
25149 +
25150 +               if ((flags & VCF_ADMIN) &&
25151 +                       /* can context be administrated? */
25152 +                       !nx_info_flags(nxi, NXF_STATE_ADMIN, 0)) {
25153 +                       ret = -EACCES;
25154 +                       goto out_nxi;
25155 +               }
25156 +       }
25157 +skip_id:
25158 +       state = 8;
25159 +       ret = do_vcmd(cmd, id, vxi, nxi, data, compat);
25160 +
25161 +out_nxi:
25162 +       if ((args & VCA_NXI) && nxi)
25163 +               put_nx_info(nxi);
25164 +out_vxi:
25165 +       if ((args & VCA_VXI) && vxi)
25166 +               put_vx_info(vxi);
25167 +out:
25168 +       vxdprintk(VXD_CBIT(switch, 1),
25169 +               "vc: VCMD_%02d_%d[%d] = %08lx(%ld) [%d,%d]",
25170 +               VC_CATEGORY(cmd), VC_COMMAND(cmd),
25171 +               VC_VERSION(cmd), ret, ret, state, permit);
25172 +       return ret;
25173 +}
25174 +
25175 +asmlinkage long
25176 +sys_vserver(uint32_t cmd, uint32_t id, void __user *data)
25177 +{
25178 +       return do_vserver(cmd, id, data, 0);
25179 +}
25180 +
25181 +#ifdef CONFIG_COMPAT
25182 +
25183 +asmlinkage long
25184 +sys32_vserver(uint32_t cmd, uint32_t id, void __user *data)
25185 +{
25186 +       return do_vserver(cmd, id, data, 1);
25187 +}
25188 +
25189 +#endif /* CONFIG_COMPAT */
25190 diff -NurpP --minimal linux-2.6.29/kernel/vserver/sysctl.c linux-2.6.29-vs2.3.0.36.9-pre3/kernel/vserver/sysctl.c
25191 --- linux-2.6.29/kernel/vserver/sysctl.c        1970-01-01 01:00:00.000000000 +0100
25192 +++ linux-2.6.29-vs2.3.0.36.9-pre3/kernel/vserver/sysctl.c      2009-02-22 22:54:26.000000000 +0100
25193 @@ -0,0 +1,244 @@
25194 +/*
25195 + *  kernel/vserver/sysctl.c
25196 + *
25197 + *  Virtual Context Support
25198 + *
25199 + *  Copyright (C) 2004-2007  Herbert Pötzl
25200 + *
25201 + *  V0.01  basic structure
25202 + *
25203 + */
25204 +
25205 +#include <linux/module.h>
25206 +#include <linux/ctype.h>
25207 +#include <linux/sysctl.h>
25208 +#include <linux/parser.h>
25209 +#include <asm/uaccess.h>
25210 +
25211 +
25212 +enum {
25213 +       CTL_DEBUG_ERROR         = 0,
25214 +       CTL_DEBUG_SWITCH        = 1,
25215 +       CTL_DEBUG_XID,
25216 +       CTL_DEBUG_NID,
25217 +       CTL_DEBUG_TAG,
25218 +       CTL_DEBUG_NET,
25219 +       CTL_DEBUG_LIMIT,
25220 +       CTL_DEBUG_CRES,
25221 +       CTL_DEBUG_DLIM,
25222 +       CTL_DEBUG_QUOTA,
25223 +       CTL_DEBUG_CVIRT,
25224 +       CTL_DEBUG_SPACE,
25225 +       CTL_DEBUG_MISC,
25226 +};
25227 +
25228 +
25229 +unsigned int vx_debug_switch   = 0;
25230 +unsigned int vx_debug_xid      = 0;
25231 +unsigned int vx_debug_nid      = 0;
25232 +unsigned int vx_debug_tag      = 0;
25233 +unsigned int vx_debug_net      = 0;
25234 +unsigned int vx_debug_limit    = 0;
25235 +unsigned int vx_debug_cres     = 0;
25236 +unsigned int vx_debug_dlim     = 0;
25237 +unsigned int vx_debug_quota    = 0;
25238 +unsigned int vx_debug_cvirt    = 0;
25239 +unsigned int vx_debug_space    = 0;
25240 +unsigned int vx_debug_misc     = 0;
25241 +
25242 +
25243 +static struct ctl_table_header *vserver_table_header;
25244 +static ctl_table vserver_root_table[];
25245 +
25246 +
25247 +void vserver_register_sysctl(void)
25248 +{
25249 +       if (!vserver_table_header) {
25250 +               vserver_table_header = register_sysctl_table(vserver_root_table);
25251 +       }
25252 +
25253 +}
25254 +
25255 +void vserver_unregister_sysctl(void)
25256 +{
25257 +       if (vserver_table_header) {
25258 +               unregister_sysctl_table(vserver_table_header);
25259 +               vserver_table_header = NULL;
25260 +       }
25261 +}
25262 +
25263 +
25264 +static int proc_dodebug(ctl_table *table, int write,
25265 +       struct file *filp, void __user *buffer, size_t *lenp, loff_t *ppos)
25266 +{
25267 +       char            tmpbuf[20], *p, c;
25268 +       unsigned int    value;
25269 +       size_t          left, len;
25270 +
25271 +       if ((*ppos && !write) || !*lenp) {
25272 +               *lenp = 0;
25273 +               return 0;
25274 +       }
25275 +
25276 +       left = *lenp;
25277 +
25278 +       if (write) {
25279 +               if (!access_ok(VERIFY_READ, buffer, left))
25280 +                       return -EFAULT;
25281 +               p = (char *)buffer;
25282 +               while (left && __get_user(c, p) >= 0 && isspace(c))
25283 +                       left--, p++;
25284 +               if (!left)
25285 +                       goto done;
25286 +
25287 +               if (left > sizeof(tmpbuf) - 1)
25288 +                       return -EINVAL;
25289 +               if (copy_from_user(tmpbuf, p, left))
25290 +                       return -EFAULT;
25291 +               tmpbuf[left] = '\0';
25292 +
25293 +               for (p = tmpbuf, value = 0; '0' <= *p && *p <= '9'; p++, left--)
25294 +                       value = 10 * value + (*p - '0');
25295 +               if (*p && !isspace(*p))
25296 +                       return -EINVAL;
25297 +               while (left && isspace(*p))
25298 +                       left--, p++;
25299 +               *(unsigned int *)table->data = value;
25300 +       } else {
25301 +               if (!access_ok(VERIFY_WRITE, buffer, left))
25302 +                       return -EFAULT;
25303 +               len = sprintf(tmpbuf, "%d", *(unsigned int *)table->data);
25304 +               if (len > left)
25305 +                       len = left;
25306 +               if (__copy_to_user(buffer, tmpbuf, len))
25307 +                       return -EFAULT;
25308 +               if ((left -= len) > 0) {
25309 +                       if (put_user('\n', (char *)buffer + len))
25310 +                               return -EFAULT;
25311 +                       left--;
25312 +               }
25313 +       }
25314 +
25315 +done:
25316 +       *lenp -= left;
25317 +       *ppos += *lenp;
25318 +       return 0;
25319 +}
25320 +
25321 +static int zero;
25322 +
25323 +#define        CTL_ENTRY(ctl, name)                            \
25324 +       {                                               \
25325 +               .ctl_name       = ctl,                  \
25326 +               .procname       = #name,                \
25327 +               .data           = &vx_ ## name,         \
25328 +               .maxlen         = sizeof(int),          \
25329 +               .mode           = 0644,                 \
25330 +               .proc_handler   = &proc_dodebug,        \
25331 +               .strategy       = &sysctl_intvec,       \
25332 +               .extra1         = &zero,                \
25333 +       }
25334 +
25335 +static ctl_table vserver_debug_table[] = {
25336 +       CTL_ENTRY(CTL_DEBUG_SWITCH,     debug_switch),
25337 +       CTL_ENTRY(CTL_DEBUG_XID,        debug_xid),
25338 +       CTL_ENTRY(CTL_DEBUG_NID,        debug_nid),
25339 +       CTL_ENTRY(CTL_DEBUG_TAG,        debug_tag),
25340 +       CTL_ENTRY(CTL_DEBUG_NET,        debug_net),
25341 +       CTL_ENTRY(CTL_DEBUG_LIMIT,      debug_limit),
25342 +       CTL_ENTRY(CTL_DEBUG_CRES,       debug_cres),
25343 +       CTL_ENTRY(CTL_DEBUG_DLIM,       debug_dlim),
25344 +       CTL_ENTRY(CTL_DEBUG_QUOTA,      debug_quota),
25345 +       CTL_ENTRY(CTL_DEBUG_CVIRT,      debug_cvirt),
25346 +       CTL_ENTRY(CTL_DEBUG_SPACE,      debug_space),
25347 +       CTL_ENTRY(CTL_DEBUG_MISC,       debug_misc),
25348 +       { .ctl_name = 0 }
25349 +};
25350 +
25351 +static ctl_table vserver_root_table[] = {
25352 +       {
25353 +               .ctl_name       = CTL_VSERVER,
25354 +               .procname       = "vserver",
25355 +               .mode           = 0555,
25356 +               .child          = vserver_debug_table
25357 +       },
25358 +       { .ctl_name = 0 }
25359 +};
25360 +
25361 +
25362 +static match_table_t tokens = {
25363 +       { CTL_DEBUG_SWITCH,     "switch=%x"     },
25364 +       { CTL_DEBUG_XID,        "xid=%x"        },
25365 +       { CTL_DEBUG_NID,        "nid=%x"        },
25366 +       { CTL_DEBUG_TAG,        "tag=%x"        },
25367 +       { CTL_DEBUG_NET,        "net=%x"        },
25368 +       { CTL_DEBUG_LIMIT,      "limit=%x"      },
25369 +       { CTL_DEBUG_CRES,       "cres=%x"       },
25370 +       { CTL_DEBUG_DLIM,       "dlim=%x"       },
25371 +       { CTL_DEBUG_QUOTA,      "quota=%x"      },
25372 +       { CTL_DEBUG_CVIRT,      "cvirt=%x"      },
25373 +       { CTL_DEBUG_SPACE,      "space=%x"      },
25374 +       { CTL_DEBUG_MISC,       "misc=%x"       },
25375 +       { CTL_DEBUG_ERROR,      NULL            }
25376 +};
25377 +
25378 +#define        HANDLE_CASE(id, name, val)                              \
25379 +       case CTL_DEBUG_ ## id:                                  \
25380 +               vx_debug_ ## name = val;                        \
25381 +               printk("vs_debug_" #name "=0x%x\n", val);       \
25382 +               break
25383 +
25384 +
25385 +static int __init vs_debug_setup(char *str)
25386 +{
25387 +       char *p;
25388 +       int token;
25389 +
25390 +       printk("vs_debug_setup(%s)\n", str);
25391 +       while ((p = strsep(&str, ",")) != NULL) {
25392 +               substring_t args[MAX_OPT_ARGS];
25393 +               unsigned int value;
25394 +
25395 +               if (!*p)
25396 +                       continue;
25397 +
25398 +               token = match_token(p, tokens, args);
25399 +               value = (token > 0) ? simple_strtoul(args[0].from, NULL, 0) : 0;
25400 +
25401 +               switch (token) {
25402 +               HANDLE_CASE(SWITCH, switch, value);
25403 +               HANDLE_CASE(XID,    xid,    value);
25404 +               HANDLE_CASE(NID,    nid,    value);
25405 +               HANDLE_CASE(TAG,    tag,    value);
25406 +               HANDLE_CASE(NET,    net,    value);
25407 +               HANDLE_CASE(LIMIT,  limit,  value);
25408 +               HANDLE_CASE(CRES,   cres,   value);
25409 +               HANDLE_CASE(DLIM,   dlim,   value);
25410 +               HANDLE_CASE(QUOTA,  quota,  value);
25411 +               HANDLE_CASE(CVIRT,  cvirt,  value);
25412 +               HANDLE_CASE(SPACE,  space,  value);
25413 +               HANDLE_CASE(MISC,   misc,   value);
25414 +               default:
25415 +                       return -EINVAL;
25416 +                       break;
25417 +               }
25418 +       }
25419 +       return 1;
25420 +}
25421 +
25422 +__setup("vsdebug=", vs_debug_setup);
25423 +
25424 +
25425 +
25426 +EXPORT_SYMBOL_GPL(vx_debug_switch);
25427 +EXPORT_SYMBOL_GPL(vx_debug_xid);
25428 +EXPORT_SYMBOL_GPL(vx_debug_nid);
25429 +EXPORT_SYMBOL_GPL(vx_debug_net);
25430 +EXPORT_SYMBOL_GPL(vx_debug_limit);
25431 +EXPORT_SYMBOL_GPL(vx_debug_cres);
25432 +EXPORT_SYMBOL_GPL(vx_debug_dlim);
25433 +EXPORT_SYMBOL_GPL(vx_debug_quota);
25434 +EXPORT_SYMBOL_GPL(vx_debug_cvirt);
25435 +EXPORT_SYMBOL_GPL(vx_debug_space);
25436 +EXPORT_SYMBOL_GPL(vx_debug_misc);
25437 +
25438 diff -NurpP --minimal linux-2.6.29/kernel/vserver/tag.c linux-2.6.29-vs2.3.0.36.9-pre3/kernel/vserver/tag.c
25439 --- linux-2.6.29/kernel/vserver/tag.c   1970-01-01 01:00:00.000000000 +0100
25440 +++ linux-2.6.29-vs2.3.0.36.9-pre3/kernel/vserver/tag.c 2009-02-22 22:54:26.000000000 +0100
25441 @@ -0,0 +1,63 @@
25442 +/*
25443 + *  linux/kernel/vserver/tag.c
25444 + *
25445 + *  Virtual Server: Shallow Tag Space
25446 + *
25447 + *  Copyright (C) 2007  Herbert Pötzl
25448 + *
25449 + *  V0.01  basic implementation
25450 + *
25451 + */
25452 +
25453 +#include <linux/sched.h>
25454 +#include <linux/vserver/debug.h>
25455 +#include <linux/vs_pid.h>
25456 +#include <linux/vs_tag.h>
25457 +
25458 +#include <linux/vserver/tag_cmd.h>
25459 +
25460 +
25461 +int dx_migrate_task(struct task_struct *p, tag_t tag)
25462 +{
25463 +       if (!p)
25464 +               BUG();
25465 +
25466 +       vxdprintk(VXD_CBIT(tag, 5),
25467 +               "dx_migrate_task(%p[#%d],#%d)", p, p->tag, tag);
25468 +
25469 +       task_lock(p);
25470 +       p->tag = tag;
25471 +       task_unlock(p);
25472 +
25473 +       vxdprintk(VXD_CBIT(tag, 5),
25474 +               "moved task %p into [#%d]", p, tag);
25475 +       return 0;
25476 +}
25477 +
25478 +/* vserver syscall commands below here */
25479 +
25480 +/* taks xid and vx_info functions */
25481 +
25482 +
25483 +int vc_task_tag(uint32_t id)
25484 +{
25485 +       tag_t tag;
25486 +
25487 +       if (id) {
25488 +               struct task_struct *tsk;
25489 +               read_lock(&tasklist_lock);
25490 +               tsk = find_task_by_real_pid(id);
25491 +               tag = (tsk) ? tsk->tag : -ESRCH;
25492 +               read_unlock(&tasklist_lock);
25493 +       } else
25494 +               tag = dx_current_tag();
25495 +       return tag;
25496 +}
25497 +
25498 +
25499 +int vc_tag_migrate(uint32_t tag)
25500 +{
25501 +       return dx_migrate_task(current, tag & 0xFFFF);
25502 +}
25503 +
25504 +
25505 diff -NurpP --minimal linux-2.6.29/kernel/vserver/vci_config.h linux-2.6.29-vs2.3.0.36.9-pre3/kernel/vserver/vci_config.h
25506 --- linux-2.6.29/kernel/vserver/vci_config.h    1970-01-01 01:00:00.000000000 +0100
25507 +++ linux-2.6.29-vs2.3.0.36.9-pre3/kernel/vserver/vci_config.h  2009-02-22 22:54:26.000000000 +0100
25508 @@ -0,0 +1,81 @@
25509 +
25510 +/*  interface version */
25511 +
25512 +#define VCI_VERSION            0x00020304
25513 +
25514 +
25515 +enum {
25516 +       VCI_KCBIT_NO_DYNAMIC = 0,
25517 +
25518 +       VCI_KCBIT_PROC_SECURE = 4,
25519 +       VCI_KCBIT_HARDCPU = 5,
25520 +       VCI_KCBIT_IDLELIMIT = 6,
25521 +       VCI_KCBIT_IDLETIME = 7,
25522 +
25523 +       VCI_KCBIT_COWBL = 8,
25524 +       VCI_KCBIT_FULLCOWBL = 9,
25525 +       VCI_KCBIT_SPACES = 10,
25526 +       VCI_KCBIT_NETV2 = 11,
25527 +
25528 +       VCI_KCBIT_DEBUG = 16,
25529 +       VCI_KCBIT_HISTORY = 20,
25530 +       VCI_KCBIT_TAGGED = 24,
25531 +       VCI_KCBIT_PPTAG = 28,
25532 +
25533 +       VCI_KCBIT_MORE = 31,
25534 +};
25535 +
25536 +
25537 +static inline uint32_t vci_kernel_config(void)
25538 +{
25539 +       return
25540 +       (1 << VCI_KCBIT_NO_DYNAMIC) |
25541 +
25542 +       /* configured features */
25543 +#ifdef CONFIG_VSERVER_PROC_SECURE
25544 +       (1 << VCI_KCBIT_PROC_SECURE) |
25545 +#endif
25546 +#ifdef CONFIG_VSERVER_HARDCPU
25547 +       (1 << VCI_KCBIT_HARDCPU) |
25548 +#endif
25549 +#ifdef CONFIG_VSERVER_IDLELIMIT
25550 +       (1 << VCI_KCBIT_IDLELIMIT) |
25551 +#endif
25552 +#ifdef CONFIG_VSERVER_IDLETIME
25553 +       (1 << VCI_KCBIT_IDLETIME) |
25554 +#endif
25555 +#ifdef CONFIG_VSERVER_COWBL
25556 +       (1 << VCI_KCBIT_COWBL) |
25557 +       (1 << VCI_KCBIT_FULLCOWBL) |
25558 +#endif
25559 +       (1 << VCI_KCBIT_SPACES) |
25560 +       (1 << VCI_KCBIT_NETV2) |
25561 +
25562 +       /* debug options */
25563 +#ifdef CONFIG_VSERVER_DEBUG
25564 +       (1 << VCI_KCBIT_DEBUG) |
25565 +#endif
25566 +#ifdef CONFIG_VSERVER_HISTORY
25567 +       (1 << VCI_KCBIT_HISTORY) |
25568 +#endif
25569 +
25570 +       /* inode context tagging */
25571 +#if    defined(CONFIG_TAGGING_NONE)
25572 +       (0 << VCI_KCBIT_TAGGED) |
25573 +#elif  defined(CONFIG_TAGGING_UID16)
25574 +       (1 << VCI_KCBIT_TAGGED) |
25575 +#elif  defined(CONFIG_TAGGING_GID16)
25576 +       (2 << VCI_KCBIT_TAGGED) |
25577 +#elif  defined(CONFIG_TAGGING_ID24)
25578 +       (3 << VCI_KCBIT_TAGGED) |
25579 +#elif  defined(CONFIG_TAGGING_INTERN)
25580 +       (4 << VCI_KCBIT_TAGGED) |
25581 +#elif  defined(CONFIG_TAGGING_RUNTIME)
25582 +       (5 << VCI_KCBIT_TAGGED) |
25583 +#else
25584 +       (7 << VCI_KCBIT_TAGGED) |
25585 +#endif
25586 +       (1 << VCI_KCBIT_PPTAG) |
25587 +       0;
25588 +}
25589 +
25590 diff -NurpP --minimal linux-2.6.29/mm/filemap_xip.c linux-2.6.29-vs2.3.0.36.9-pre3/mm/filemap_xip.c
25591 --- linux-2.6.29/mm/filemap_xip.c       2009-03-24 14:22:45.000000000 +0100
25592 +++ linux-2.6.29-vs2.3.0.36.9-pre3/mm/filemap_xip.c     2009-03-24 14:48:36.000000000 +0100
25593 @@ -17,6 +17,7 @@
25594  #include <linux/sched.h>
25595  #include <linux/seqlock.h>
25596  #include <linux/mutex.h>
25597 +#include <linux/vs_memory.h>
25598  #include <asm/tlbflush.h>
25599  #include <asm/io.h>
25600  
25601 diff -NurpP --minimal linux-2.6.29/mm/fremap.c linux-2.6.29-vs2.3.0.36.9-pre3/mm/fremap.c
25602 --- linux-2.6.29/mm/fremap.c    2009-03-24 14:22:45.000000000 +0100
25603 +++ linux-2.6.29-vs2.3.0.36.9-pre3/mm/fremap.c  2009-03-24 14:48:36.000000000 +0100
25604 @@ -16,6 +16,7 @@
25605  #include <linux/module.h>
25606  #include <linux/syscalls.h>
25607  #include <linux/mmu_notifier.h>
25608 +#include <linux/vs_memory.h>
25609  
25610  #include <asm/mmu_context.h>
25611  #include <asm/cacheflush.h>
25612 diff -NurpP --minimal linux-2.6.29/mm/hugetlb.c linux-2.6.29-vs2.3.0.36.9-pre3/mm/hugetlb.c
25613 --- linux-2.6.29/mm/hugetlb.c   2009-03-24 14:22:45.000000000 +0100
25614 +++ linux-2.6.29-vs2.3.0.36.9-pre3/mm/hugetlb.c 2009-03-24 14:48:36.000000000 +0100
25615 @@ -24,6 +24,7 @@
25616  #include <asm/io.h>
25617  
25618  #include <linux/hugetlb.h>
25619 +#include <linux/vs_memory.h>
25620  #include "internal.h"
25621  
25622  const unsigned long hugetlb_zero = 0, hugetlb_infinity = ~0UL;
25623 diff -NurpP --minimal linux-2.6.29/mm/memory.c linux-2.6.29-vs2.3.0.36.9-pre3/mm/memory.c
25624 --- linux-2.6.29/mm/memory.c    2009-03-24 14:22:45.000000000 +0100
25625 +++ linux-2.6.29-vs2.3.0.36.9-pre3/mm/memory.c  2009-03-24 14:48:36.000000000 +0100
25626 @@ -612,6 +612,9 @@ static int copy_pte_range(struct mm_stru
25627         int progress = 0;
25628         int rss[2];
25629  
25630 +       if (!vx_rss_avail(dst_mm, ((end - addr)/PAGE_SIZE + 1)))
25631 +               return -ENOMEM;
25632 +
25633  again:
25634         rss[1] = rss[0] = 0;
25635         dst_pte = pte_alloc_map_lock(dst_mm, dst_pmd, addr, &dst_ptl);
25636 @@ -2433,6 +2436,11 @@ static int do_swap_page(struct mm_struct
25637                 count_vm_event(PGMAJFAULT);
25638         }
25639  
25640 +       if (!vx_rss_avail(mm, 1)) {
25641 +               ret = VM_FAULT_OOM;
25642 +               goto out;
25643 +       }
25644 +
25645         mark_page_accessed(page);
25646  
25647         lock_page(page);
25648 @@ -2524,6 +2532,8 @@ static int do_anonymous_page(struct mm_s
25649         /* Allocate our own private page. */
25650         pte_unmap(page_table);
25651  
25652 +       if (!vx_rss_avail(mm, 1))
25653 +               goto oom;
25654         if (unlikely(anon_vma_prepare(vma)))
25655                 goto oom;
25656         page = alloc_zeroed_user_highpage_movable(vma, address);
25657 @@ -2791,6 +2801,7 @@ static inline int handle_pte_fault(struc
25658  {
25659         pte_t entry;
25660         spinlock_t *ptl;
25661 +       int ret = 0, type = VXPT_UNKNOWN;
25662  
25663         entry = *pte;
25664         if (!pte_present(entry)) {
25665 @@ -2815,9 +2826,12 @@ static inline int handle_pte_fault(struc
25666         if (unlikely(!pte_same(*pte, entry)))
25667                 goto unlock;
25668         if (write_access) {
25669 -               if (!pte_write(entry))
25670 -                       return do_wp_page(mm, vma, address,
25671 +               if (!pte_write(entry)) {
25672 +                       ret = do_wp_page(mm, vma, address,
25673                                         pte, pmd, ptl, entry);
25674 +                       type = VXPT_WRITE;
25675 +                       goto out;
25676 +               }
25677                 entry = pte_mkdirty(entry);
25678         }
25679         entry = pte_mkyoung(entry);
25680 @@ -2835,7 +2849,10 @@ static inline int handle_pte_fault(struc
25681         }
25682  unlock:
25683         pte_unmap_unlock(pte, ptl);
25684 -       return 0;
25685 +       ret = 0;
25686 +out:
25687 +       vx_page_fault(mm, vma, type, ret);
25688 +       return ret;
25689  }
25690  
25691  /*
25692 diff -NurpP --minimal linux-2.6.29/mm/mlock.c linux-2.6.29-vs2.3.0.36.9-pre3/mm/mlock.c
25693 --- linux-2.6.29/mm/mlock.c     2009-03-24 14:22:45.000000000 +0100
25694 +++ linux-2.6.29-vs2.3.0.36.9-pre3/mm/mlock.c   2009-03-28 05:08:26.000000000 +0100
25695 @@ -18,6 +18,7 @@
25696  #include <linux/rmap.h>
25697  #include <linux/mmzone.h>
25698  #include <linux/hugetlb.h>
25699 +#include <linux/vs_memory.h>
25700  
25701  #include "internal.h"
25702  
25703 @@ -415,7 +416,7 @@ success:
25704         nr_pages = (end - start) >> PAGE_SHIFT;
25705         if (!lock)
25706                 nr_pages = -nr_pages;
25707 -       mm->locked_vm += nr_pages;
25708 +       vx_vmlocked_add(mm, nr_pages);
25709  
25710         /*
25711          * vm_flags is protected by the mmap_sem held in write mode.
25712 @@ -492,7 +493,7 @@ static int do_mlock(unsigned long start,
25713  
25714  SYSCALL_DEFINE2(mlock, unsigned long, start, size_t, len)
25715  {
25716 -       unsigned long locked;
25717 +       unsigned long locked, grow;
25718         unsigned long lock_limit;
25719         int error = -ENOMEM;
25720  
25721 @@ -505,8 +506,10 @@ SYSCALL_DEFINE2(mlock, unsigned long, st
25722         len = PAGE_ALIGN(len + (start & ~PAGE_MASK));
25723         start &= PAGE_MASK;
25724  
25725 -       locked = len >> PAGE_SHIFT;
25726 -       locked += current->mm->locked_vm;
25727 +       grow = len >> PAGE_SHIFT;
25728 +       if (!vx_vmlocked_avail(current->mm, grow))
25729 +               goto out;
25730 +       locked = current->mm->locked_vm + grow;
25731  
25732         lock_limit = current->signal->rlim[RLIMIT_MEMLOCK].rlim_cur;
25733         lock_limit >>= PAGE_SHIFT;
25734 @@ -514,6 +517,7 @@ SYSCALL_DEFINE2(mlock, unsigned long, st
25735         /* check against resource limits */
25736         if ((locked <= lock_limit) || capable(CAP_IPC_LOCK))
25737                 error = do_mlock(start, len, 1);
25738 +out:
25739         up_write(&current->mm->mmap_sem);
25740         return error;
25741  }
25742 @@ -575,6 +579,8 @@ SYSCALL_DEFINE1(mlockall, int, flags)
25743         lock_limit >>= PAGE_SHIFT;
25744  
25745         ret = -ENOMEM;
25746 +       if (!vx_vmlocked_avail(current->mm, current->mm->total_vm))
25747 +               goto out;
25748         if (!(flags & MCL_CURRENT) || (current->mm->total_vm <= lock_limit) ||
25749             capable(CAP_IPC_LOCK))
25750                 ret = do_mlockall(flags);
25751 @@ -652,8 +658,10 @@ void *alloc_locked_buffer(size_t size)
25752         if (!buffer)
25753                 goto out;
25754  
25755 -       current->mm->total_vm  += pgsz;
25756 -       current->mm->locked_vm += pgsz;
25757 +       // current->mm->total_vm  += pgsz;
25758 +       vx_vmpages_add(current->mm, pgsz);
25759 +       // current->mm->locked_vm += pgsz;
25760 +       vx_vmlocked_add(current->mm, pgsz);
25761  
25762   out:
25763         up_write(&current->mm->mmap_sem);
25764 @@ -666,8 +674,10 @@ void release_locked_buffer(void *buffer,
25765  
25766         down_write(&current->mm->mmap_sem);
25767  
25768 -       current->mm->total_vm  -= pgsz;
25769 -       current->mm->locked_vm -= pgsz;
25770 +       // current->mm->total_vm  -= pgsz;
25771 +       vx_vmpages_sub(current->mm, pgsz);
25772 +       // current->mm->locked_vm -= pgsz;
25773 +       vx_vmlocked_sub(current->mm, pgsz);
25774  
25775         up_write(&current->mm->mmap_sem);
25776  }
25777 diff -NurpP --minimal linux-2.6.29/mm/mmap.c linux-2.6.29-vs2.3.0.36.9-pre3/mm/mmap.c
25778 --- linux-2.6.29/mm/mmap.c      2009-03-24 14:22:45.000000000 +0100
25779 +++ linux-2.6.29-vs2.3.0.36.9-pre3/mm/mmap.c    2009-03-24 14:48:36.000000000 +0100
25780 @@ -1219,7 +1219,8 @@ munmap_back:
25781         if (correct_wcount)
25782                 atomic_inc(&inode->i_writecount);
25783  out:
25784 -       mm->total_vm += len >> PAGE_SHIFT;
25785 +       // mm->total_vm += len >> PAGE_SHIFT;
25786 +       vx_vmpages_add(mm, len >> PAGE_SHIFT);
25787         vm_stat_account(mm, vm_flags, file, len >> PAGE_SHIFT);
25788         if (vm_flags & VM_LOCKED) {
25789                 /*
25790 @@ -1228,7 +1229,8 @@ out:
25791                 long nr_pages = mlock_vma_pages_range(vma, addr, addr + len);
25792                 if (nr_pages < 0)
25793                         return nr_pages;        /* vma gone! */
25794 -               mm->locked_vm += (len >> PAGE_SHIFT) - nr_pages;
25795 +               // mm->locked_vm += (len >> PAGE_SHIFT) - nr_pages;
25796 +               vx_vmlocked_add(mm, (len >> PAGE_SHIFT) - nr_pages);
25797         } else if ((flags & MAP_POPULATE) && !(flags & MAP_NONBLOCK))
25798                 make_pages_present(addr, addr + len);
25799         return addr;
25800 @@ -1575,9 +1577,9 @@ static int acct_stack_growth(struct vm_a
25801                 return -ENOMEM;
25802  
25803         /* Ok, everything looks good - let it rip */
25804 -       mm->total_vm += grow;
25805 +       vx_vmpages_add(mm, grow);
25806         if (vma->vm_flags & VM_LOCKED)
25807 -               mm->locked_vm += grow;
25808 +               vx_vmlocked_add(mm, grow);
25809         vm_stat_account(mm, vma->vm_flags, vma->vm_file, grow);
25810         return 0;
25811  }
25812 @@ -1752,7 +1754,8 @@ static void remove_vma_list(struct mm_st
25813         do {
25814                 long nrpages = vma_pages(vma);
25815  
25816 -               mm->total_vm -= nrpages;
25817 +               // mm->total_vm -= nrpages;
25818 +               vx_vmpages_sub(mm, nrpages);
25819                 vm_stat_account(mm, vma->vm_flags, vma->vm_file, -nrpages);
25820                 vma = remove_vma(vma);
25821         } while (vma);
25822 @@ -1924,7 +1927,8 @@ int do_munmap(struct mm_struct *mm, unsi
25823                 struct vm_area_struct *tmp = vma;
25824                 while (tmp && tmp->vm_start < end) {
25825                         if (tmp->vm_flags & VM_LOCKED) {
25826 -                               mm->locked_vm -= vma_pages(tmp);
25827 +                               // mm->locked_vm -= vma_pages(tmp);
25828 +                               vx_vmlocked_sub(mm, vma_pages(tmp));
25829                                 munlock_vma_pages_all(tmp);
25830                         }
25831                         tmp = tmp->vm_next;
25832 @@ -2013,6 +2017,8 @@ unsigned long do_brk(unsigned long addr,
25833                 lock_limit >>= PAGE_SHIFT;
25834                 if (locked > lock_limit && !capable(CAP_IPC_LOCK))
25835                         return -EAGAIN;
25836 +               if (!vx_vmlocked_avail(mm, len >> PAGE_SHIFT))
25837 +                       return -ENOMEM;
25838         }
25839  
25840         /*
25841 @@ -2039,7 +2045,8 @@ unsigned long do_brk(unsigned long addr,
25842         if (mm->map_count > sysctl_max_map_count)
25843                 return -ENOMEM;
25844  
25845 -       if (security_vm_enough_memory(len >> PAGE_SHIFT))
25846 +       if (security_vm_enough_memory(len >> PAGE_SHIFT) ||
25847 +               !vx_vmpages_avail(mm, len >> PAGE_SHIFT))
25848                 return -ENOMEM;
25849  
25850         /* Can we just expand an old private anonymous mapping? */
25851 @@ -2065,10 +2072,13 @@ unsigned long do_brk(unsigned long addr,
25852         vma->vm_page_prot = vm_get_page_prot(flags);
25853         vma_link(mm, vma, prev, rb_link, rb_parent);
25854  out:
25855 -       mm->total_vm += len >> PAGE_SHIFT;
25856 +       // mm->total_vm += len >> PAGE_SHIFT;
25857 +       vx_vmpages_add(mm, len >> PAGE_SHIFT);
25858 +
25859         if (flags & VM_LOCKED) {
25860                 if (!mlock_vma_pages_range(vma, addr, addr + len))
25861 -                       mm->locked_vm += (len >> PAGE_SHIFT);
25862 +                       // mm->locked_vm += (len >> PAGE_SHIFT);
25863 +                       vx_vmlocked_add(mm, len >> PAGE_SHIFT);
25864         }
25865         return addr;
25866  }
25867 @@ -2111,6 +2121,11 @@ void exit_mmap(struct mm_struct *mm)
25868         free_pgtables(tlb, vma, FIRST_USER_ADDRESS, 0);
25869         tlb_finish_mmu(tlb, 0, end);
25870  
25871 +       set_mm_counter(mm, file_rss, 0);
25872 +       set_mm_counter(mm, anon_rss, 0);
25873 +       vx_vmpages_sub(mm, mm->total_vm);
25874 +       vx_vmlocked_sub(mm, mm->locked_vm);
25875 +
25876         /*
25877          * Walk the list again, actually closing and freeing it,
25878          * with preemption enabled, without holding any MM locks.
25879 @@ -2150,7 +2165,8 @@ int insert_vm_struct(struct mm_struct * 
25880         if (__vma && __vma->vm_start < vma->vm_end)
25881                 return -ENOMEM;
25882         if ((vma->vm_flags & VM_ACCOUNT) &&
25883 -            security_vm_enough_memory_mm(mm, vma_pages(vma)))
25884 +               (security_vm_enough_memory_mm(mm, vma_pages(vma)) ||
25885 +               !vx_vmpages_avail(mm, vma_pages(vma))))
25886                 return -ENOMEM;
25887         vma_link(mm, vma, prev, rb_link, rb_parent);
25888         return 0;
25889 @@ -2226,6 +2242,8 @@ int may_expand_vm(struct mm_struct *mm, 
25890  
25891         if (cur + npages > lim)
25892                 return 0;
25893 +       if (!vx_vmpages_avail(mm, npages))
25894 +               return 0;
25895         return 1;
25896  }
25897  
25898 @@ -2303,8 +2321,7 @@ int install_special_mapping(struct mm_st
25899                 return -ENOMEM;
25900         }
25901  
25902 -       mm->total_vm += len >> PAGE_SHIFT;
25903 -
25904 +       vx_vmpages_add(mm, len >> PAGE_SHIFT);
25905         return 0;
25906  }
25907  
25908 diff -NurpP --minimal linux-2.6.29/mm/mremap.c linux-2.6.29-vs2.3.0.36.9-pre3/mm/mremap.c
25909 --- linux-2.6.29/mm/mremap.c    2009-03-24 14:22:45.000000000 +0100
25910 +++ linux-2.6.29-vs2.3.0.36.9-pre3/mm/mremap.c  2009-03-24 14:48:36.000000000 +0100
25911 @@ -19,6 +19,7 @@
25912  #include <linux/security.h>
25913  #include <linux/syscalls.h>
25914  #include <linux/mmu_notifier.h>
25915 +#include <linux/vs_memory.h>
25916  
25917  #include <asm/uaccess.h>
25918  #include <asm/cacheflush.h>
25919 @@ -220,7 +221,7 @@ static unsigned long move_vma(struct vm_
25920          * If this were a serious issue, we'd add a flag to do_munmap().
25921          */
25922         hiwater_vm = mm->hiwater_vm;
25923 -       mm->total_vm += new_len >> PAGE_SHIFT;
25924 +       vx_vmpages_add(mm, new_len >> PAGE_SHIFT);
25925         vm_stat_account(mm, vma->vm_flags, vma->vm_file, new_len>>PAGE_SHIFT);
25926  
25927         if (do_munmap(mm, old_addr, old_len) < 0) {
25928 @@ -238,7 +239,7 @@ static unsigned long move_vma(struct vm_
25929         }
25930  
25931         if (vm_flags & VM_LOCKED) {
25932 -               mm->locked_vm += new_len >> PAGE_SHIFT;
25933 +               vx_vmlocked_add(mm, new_len >> PAGE_SHIFT);
25934                 if (new_len > old_len)
25935                         mlock_vma_pages_range(new_vma, new_addr + old_len,
25936                                                        new_addr + new_len);
25937 @@ -349,6 +350,9 @@ unsigned long do_mremap(unsigned long ad
25938                 ret = -EAGAIN;
25939                 if (locked > lock_limit && !capable(CAP_IPC_LOCK))
25940                         goto out;
25941 +               if (!vx_vmlocked_avail(current->mm,
25942 +                       (new_len - old_len) >> PAGE_SHIFT))
25943 +                       goto out;
25944         }
25945         if (!may_expand_vm(mm, (new_len - old_len) >> PAGE_SHIFT)) {
25946                 ret = -ENOMEM;
25947 @@ -377,10 +381,12 @@ unsigned long do_mremap(unsigned long ad
25948                         vma_adjust(vma, vma->vm_start,
25949                                 addr + new_len, vma->vm_pgoff, NULL);
25950  
25951 -                       mm->total_vm += pages;
25952 +                       // mm->total_vm += pages;
25953 +                       vx_vmpages_add(mm, pages);
25954                         vm_stat_account(mm, vma->vm_flags, vma->vm_file, pages);
25955                         if (vma->vm_flags & VM_LOCKED) {
25956 -                               mm->locked_vm += pages;
25957 +                               // mm->locked_vm += pages;
25958 +                               vx_vmlocked_add(mm, pages);
25959                                 mlock_vma_pages_range(vma, addr + old_len,
25960                                                    addr + new_len);
25961                         }
25962 diff -NurpP --minimal linux-2.6.29/mm/nommu.c linux-2.6.29-vs2.3.0.36.9-pre3/mm/nommu.c
25963 --- linux-2.6.29/mm/nommu.c     2009-03-24 14:22:45.000000000 +0100
25964 +++ linux-2.6.29-vs2.3.0.36.9-pre3/mm/nommu.c   2009-03-24 18:25:55.000000000 +0100
25965 @@ -1348,7 +1348,7 @@ unsigned long do_mmap_pgoff(struct file 
25966         /* okay... we have a mapping; now we have to register it */
25967         result = vma->vm_start;
25968  
25969 -       current->mm->total_vm += len >> PAGE_SHIFT;
25970 +       vx_vmpages_add(current->mm, len >> PAGE_SHIFT);
25971  
25972  share:
25973         add_vma_to_mm(current->mm, vma);
25974 @@ -1614,7 +1614,7 @@ void exit_mmap(struct mm_struct *mm)
25975  
25976         kenter("");
25977  
25978 -       mm->total_vm = 0;
25979 +       vx_vmpages_sub(mm, mm->total_vm);
25980  
25981         while ((vma = mm->mmap)) {
25982                 mm->mmap = vma->vm_next;
25983 diff -NurpP --minimal linux-2.6.29/mm/oom_kill.c linux-2.6.29-vs2.3.0.36.9-pre3/mm/oom_kill.c
25984 --- linux-2.6.29/mm/oom_kill.c  2009-03-24 14:22:45.000000000 +0100
25985 +++ linux-2.6.29-vs2.3.0.36.9-pre3/mm/oom_kill.c        2009-03-24 14:48:36.000000000 +0100
25986 @@ -27,6 +27,7 @@
25987  #include <linux/notifier.h>
25988  #include <linux/memcontrol.h>
25989  #include <linux/security.h>
25990 +#include <linux/vs_memory.h>
25991  
25992  int sysctl_panic_on_oom;
25993  int sysctl_oom_kill_allocating_task;
25994 @@ -72,6 +73,12 @@ unsigned long badness(struct task_struct
25995         points = mm->total_vm;
25996  
25997         /*
25998 +        * add points for context badness
25999 +        */
26000 +
26001 +       points += vx_badness(p, mm);
26002 +
26003 +       /*
26004          * After this unlock we can no longer dereference local variable `mm'
26005          */
26006         task_unlock(p);
26007 @@ -162,8 +169,8 @@ unsigned long badness(struct task_struct
26008         }
26009  
26010  #ifdef DEBUG
26011 -       printk(KERN_DEBUG "OOMkill: task %d (%s) got %lu points\n",
26012 -       p->pid, p->comm, points);
26013 +       printk(KERN_DEBUG "OOMkill: task %d:#%u (%s) got %d points\n",
26014 +               task_pid_nr(p), p->xid, p->comm, points);
26015  #endif
26016         return points;
26017  }
26018 @@ -326,8 +333,8 @@ static void __oom_kill_task(struct task_
26019         }
26020  
26021         if (verbose)
26022 -               printk(KERN_ERR "Killed process %d (%s)\n",
26023 -                               task_pid_nr(p), p->comm);
26024 +               printk(KERN_ERR "Killed process %d:#%u (%s)\n",
26025 +                               task_pid_nr(p), p->xid, p->comm);
26026  
26027         /*
26028          * We give our sacrificial lamb high priority and access to
26029 @@ -410,8 +417,8 @@ static int oom_kill_process(struct task_
26030                 return 0;
26031         }
26032  
26033 -       printk(KERN_ERR "%s: kill process %d (%s) score %li or a child\n",
26034 -                                       message, task_pid_nr(p), p->comm, points);
26035 +       printk(KERN_ERR "%s: kill process %d:#%u (%s) score %li or a child\n",
26036 +                               message, task_pid_nr(p), p->xid, p->comm, points);
26037  
26038         /* Try to kill a child first */
26039         list_for_each_entry(c, &p->children, sibling) {
26040 diff -NurpP --minimal linux-2.6.29/mm/page_alloc.c linux-2.6.29-vs2.3.0.36.9-pre3/mm/page_alloc.c
26041 --- linux-2.6.29/mm/page_alloc.c        2009-03-24 14:22:45.000000000 +0100
26042 +++ linux-2.6.29-vs2.3.0.36.9-pre3/mm/page_alloc.c      2009-03-24 14:48:36.000000000 +0100
26043 @@ -46,6 +46,8 @@
26044  #include <linux/page-isolation.h>
26045  #include <linux/page_cgroup.h>
26046  #include <linux/debugobjects.h>
26047 +#include <linux/vs_base.h>
26048 +#include <linux/vs_limit.h>
26049  
26050  #include <asm/tlbflush.h>
26051  #include <asm/div64.h>
26052 @@ -1839,6 +1841,9 @@ void si_meminfo(struct sysinfo *val)
26053         val->totalhigh = totalhigh_pages;
26054         val->freehigh = nr_free_highpages();
26055         val->mem_unit = PAGE_SIZE;
26056 +
26057 +       if (vx_flags(VXF_VIRT_MEM, 0))
26058 +               vx_vsi_meminfo(val);
26059  }
26060  
26061  EXPORT_SYMBOL(si_meminfo);
26062 @@ -1859,6 +1864,9 @@ void si_meminfo_node(struct sysinfo *val
26063         val->freehigh = 0;
26064  #endif
26065         val->mem_unit = PAGE_SIZE;
26066 +
26067 +       if (vx_flags(VXF_VIRT_MEM, 0))
26068 +               vx_vsi_meminfo(val);
26069  }
26070  #endif
26071  
26072 diff -NurpP --minimal linux-2.6.29/mm/rmap.c linux-2.6.29-vs2.3.0.36.9-pre3/mm/rmap.c
26073 --- linux-2.6.29/mm/rmap.c      2009-03-24 14:22:45.000000000 +0100
26074 +++ linux-2.6.29-vs2.3.0.36.9-pre3/mm/rmap.c    2009-03-24 18:26:27.000000000 +0100
26075 @@ -50,6 +50,7 @@
26076  #include <linux/memcontrol.h>
26077  #include <linux/mmu_notifier.h>
26078  #include <linux/migrate.h>
26079 +#include <linux/vs_memory.h>
26080  
26081  #include <asm/tlbflush.h>
26082  
26083 diff -NurpP --minimal linux-2.6.29/mm/shmem.c linux-2.6.29-vs2.3.0.36.9-pre3/mm/shmem.c
26084 --- linux-2.6.29/mm/shmem.c     2009-03-24 14:22:45.000000000 +0100
26085 +++ linux-2.6.29-vs2.3.0.36.9-pre3/mm/shmem.c   2009-03-24 14:48:36.000000000 +0100
26086 @@ -1757,7 +1757,7 @@ static int shmem_statfs(struct dentry *d
26087  {
26088         struct shmem_sb_info *sbinfo = SHMEM_SB(dentry->d_sb);
26089  
26090 -       buf->f_type = TMPFS_MAGIC;
26091 +       buf->f_type = TMPFS_SUPER_MAGIC;
26092         buf->f_bsize = PAGE_CACHE_SIZE;
26093         buf->f_namelen = NAME_MAX;
26094         spin_lock(&sbinfo->stat_lock);
26095 @@ -2326,7 +2326,7 @@ static int shmem_fill_super(struct super
26096         sb->s_maxbytes = SHMEM_MAX_BYTES;
26097         sb->s_blocksize = PAGE_CACHE_SIZE;
26098         sb->s_blocksize_bits = PAGE_CACHE_SHIFT;
26099 -       sb->s_magic = TMPFS_MAGIC;
26100 +       sb->s_magic = TMPFS_SUPER_MAGIC;
26101         sb->s_op = &shmem_ops;
26102         sb->s_time_gran = 1;
26103  #ifdef CONFIG_TMPFS_POSIX_ACL
26104 diff -NurpP --minimal linux-2.6.29/mm/slab.c linux-2.6.29-vs2.3.0.36.9-pre3/mm/slab.c
26105 --- linux-2.6.29/mm/slab.c      2009-03-24 14:22:45.000000000 +0100
26106 +++ linux-2.6.29-vs2.3.0.36.9-pre3/mm/slab.c    2009-03-24 14:48:36.000000000 +0100
26107 @@ -509,6 +509,8 @@ struct kmem_cache {
26108  #define STATS_INC_FREEMISS(x)  do { } while (0)
26109  #endif
26110  
26111 +#include "slab_vs.h"
26112 +
26113  #if DEBUG
26114  
26115  /*
26116 @@ -3275,6 +3277,7 @@ retry:
26117  
26118         obj = slab_get_obj(cachep, slabp, nodeid);
26119         check_slabp(cachep, slabp);
26120 +       vx_slab_alloc(cachep, flags);
26121         l3->free_objects--;
26122         /* move slabp to correct slabp list: */
26123         list_del(&slabp->list);
26124 @@ -3347,6 +3350,7 @@ __cache_alloc_node(struct kmem_cache *ca
26125         /* ___cache_alloc_node can fall back to other nodes */
26126         ptr = ____cache_alloc_node(cachep, flags, nodeid);
26127    out:
26128 +       vx_slab_alloc(cachep, flags);
26129         local_irq_restore(save_flags);
26130         ptr = cache_alloc_debugcheck_after(cachep, flags, ptr, caller);
26131  
26132 @@ -3518,6 +3522,7 @@ static inline void __cache_free(struct k
26133  
26134         check_irq_off();
26135         objp = cache_free_debugcheck(cachep, objp, __builtin_return_address(0));
26136 +       vx_slab_free(cachep);
26137  
26138         /*
26139          * Skip calling cache_free_alien() when the platform is not numa.
26140 diff -NurpP --minimal linux-2.6.29/mm/slab_vs.h linux-2.6.29-vs2.3.0.36.9-pre3/mm/slab_vs.h
26141 --- linux-2.6.29/mm/slab_vs.h   1970-01-01 01:00:00.000000000 +0100
26142 +++ linux-2.6.29-vs2.3.0.36.9-pre3/mm/slab_vs.h 2009-02-22 22:54:26.000000000 +0100
26143 @@ -0,0 +1,27 @@
26144 +
26145 +#include <linux/vserver/context.h>
26146 +
26147 +#include <linux/vs_context.h>
26148 +
26149 +static inline
26150 +void vx_slab_alloc(struct kmem_cache *cachep, gfp_t flags)
26151 +{
26152 +       int what = gfp_zone(cachep->gfpflags);
26153 +
26154 +       if (!current->vx_info)
26155 +               return;
26156 +
26157 +       atomic_add(cachep->buffer_size, &current->vx_info->cacct.slab[what]);
26158 +}
26159 +
26160 +static inline
26161 +void vx_slab_free(struct kmem_cache *cachep)
26162 +{
26163 +       int what = gfp_zone(cachep->gfpflags);
26164 +
26165 +       if (!current->vx_info)
26166 +               return;
26167 +
26168 +       atomic_sub(cachep->buffer_size, &current->vx_info->cacct.slab[what]);
26169 +}
26170 +
26171 diff -NurpP --minimal linux-2.6.29/mm/swapfile.c linux-2.6.29-vs2.3.0.36.9-pre3/mm/swapfile.c
26172 --- linux-2.6.29/mm/swapfile.c  2009-03-24 14:22:45.000000000 +0100
26173 +++ linux-2.6.29-vs2.3.0.36.9-pre3/mm/swapfile.c        2009-03-24 18:27:15.000000000 +0100
26174 @@ -34,6 +34,8 @@
26175  #include <asm/tlbflush.h>
26176  #include <linux/swapops.h>
26177  #include <linux/page_cgroup.h>
26178 +#include <linux/vs_base.h>
26179 +#include <linux/vs_memory.h>
26180  
26181  static DEFINE_SPINLOCK(swap_lock);
26182  static unsigned int nr_swapfiles;
26183 @@ -1935,6 +1937,8 @@ void si_swapinfo(struct sysinfo *val)
26184         val->freeswap = nr_swap_pages + nr_to_be_unused;
26185         val->totalswap = total_swap_pages + nr_to_be_unused;
26186         spin_unlock(&swap_lock);
26187 +       if (vx_flags(VXF_VIRT_MEM, 0))
26188 +               vx_vsi_swapinfo(val);
26189  }
26190  
26191  /*
26192 diff -NurpP --minimal linux-2.6.29/net/core/dev.c linux-2.6.29-vs2.3.0.36.9-pre3/net/core/dev.c
26193 --- linux-2.6.29/net/core/dev.c 2009-03-24 14:22:46.000000000 +0100
26194 +++ linux-2.6.29-vs2.3.0.36.9-pre3/net/core/dev.c       2009-03-24 18:28:15.000000000 +0100
26195 @@ -126,6 +126,7 @@
26196  #include <linux/in.h>
26197  #include <linux/jhash.h>
26198  #include <linux/random.h>
26199 +#include <linux/vs_inet.h>
26200  
26201  #include "net-sysfs.h"
26202  
26203 @@ -2856,6 +2857,8 @@ static int dev_ifconf(struct net *net, c
26204  
26205         total = 0;
26206         for_each_netdev(net, dev) {
26207 +               if (!nx_dev_visible(current->nx_info, dev))
26208 +                       continue;
26209                 for (i = 0; i < NPROTO; i++) {
26210                         if (gifconf_list[i]) {
26211                                 int done;
26212 @@ -2924,6 +2927,9 @@ static void dev_seq_printf_stats(struct 
26213  {
26214         const struct net_device_stats *stats = dev_get_stats(dev);
26215  
26216 +       if (!nx_dev_visible(current->nx_info, dev))
26217 +               return;
26218 +
26219         seq_printf(seq, "%6s:%8lu %7lu %4lu %4lu %4lu %5lu %10lu %9lu "
26220                    "%8lu %7lu %4lu %4lu %4lu %5lu %7lu %10lu\n",
26221                    dev->name, stats->rx_bytes, stats->rx_packets,
26222 @@ -4865,6 +4871,15 @@ int dev_change_net_namespace(struct net_
26223                 goto out;
26224  #endif
26225  
26226 +#ifdef CONFIG_SYSFS
26227 +       /* Don't allow real devices to be moved when sysfs
26228 +        * is enabled.
26229 +        */
26230 +       err = -EINVAL;
26231 +       if (dev->dev.parent)
26232 +               goto out;
26233 +#endif
26234 +
26235         /* Ensure the device has been registrered */
26236         err = -EINVAL;
26237         if (dev->reg_state != NETREG_REGISTERED)
26238 @@ -4924,6 +4939,8 @@ int dev_change_net_namespace(struct net_
26239  
26240         netdev_unregister_kobject(dev);
26241  
26242 +       netdev_unregister_kobject(dev);
26243 +
26244         /* Actually switch the network namespace */
26245         dev_net_set(dev, net);
26246  
26247 diff -NurpP --minimal linux-2.6.29/net/core/net-sysfs.c linux-2.6.29-vs2.3.0.36.9-pre3/net/core/net-sysfs.c
26248 --- linux-2.6.29/net/core/net-sysfs.c   2009-03-24 14:22:46.000000000 +0100
26249 +++ linux-2.6.29-vs2.3.0.36.9-pre3/net/core/net-sysfs.c 2009-03-24 18:30:01.000000000 +0100
26250 @@ -512,6 +512,9 @@ int netdev_register_kobject(struct net_d
26251         if (dev_net(net) != &init_net)
26252                 return 0;
26253  
26254 +       if (dev_net(net) != &init_net)
26255 +               return 0;
26256 +
26257         return device_add(dev);
26258  }
26259  
26260 diff -NurpP --minimal linux-2.6.29/net/core/rtnetlink.c linux-2.6.29-vs2.3.0.36.9-pre3/net/core/rtnetlink.c
26261 --- linux-2.6.29/net/core/rtnetlink.c   2009-03-24 14:22:46.000000000 +0100
26262 +++ linux-2.6.29-vs2.3.0.36.9-pre3/net/core/rtnetlink.c 2009-03-24 14:48:36.000000000 +0100
26263 @@ -690,6 +690,8 @@ static int rtnl_dump_ifinfo(struct sk_bu
26264  
26265         idx = 0;
26266         for_each_netdev(net, dev) {
26267 +               if (!nx_dev_visible(skb->sk->sk_nx_info, dev))
26268 +                       continue;
26269                 if (idx < s_idx)
26270                         goto cont;
26271                 if (rtnl_fill_ifinfo(skb, dev, RTM_NEWLINK,
26272 @@ -1235,6 +1237,9 @@ void rtmsg_ifinfo(int type, struct net_d
26273         struct sk_buff *skb;
26274         int err = -ENOBUFS;
26275  
26276 +       if (!nx_dev_visible(current->nx_info, dev))
26277 +               return;
26278 +
26279         skb = nlmsg_new(if_nlmsg_size(dev), GFP_KERNEL);
26280         if (skb == NULL)
26281                 goto errout;
26282 diff -NurpP --minimal linux-2.6.29/net/core/sock.c linux-2.6.29-vs2.3.0.36.9-pre3/net/core/sock.c
26283 --- linux-2.6.29/net/core/sock.c        2009-03-24 14:22:46.000000000 +0100
26284 +++ linux-2.6.29-vs2.3.0.36.9-pre3/net/core/sock.c      2009-03-24 14:48:36.000000000 +0100
26285 @@ -124,6 +124,10 @@
26286  #include <linux/ipsec.h>
26287  
26288  #include <linux/filter.h>
26289 +#include <linux/vs_socket.h>
26290 +#include <linux/vs_limit.h>
26291 +#include <linux/vs_context.h>
26292 +#include <linux/vs_network.h>
26293  
26294  #ifdef CONFIG_INET
26295  #include <net/tcp.h>
26296 @@ -900,6 +904,8 @@ static struct sock *sk_prot_alloc(struct
26297                 if (!try_module_get(prot->owner))
26298                         goto out_free_sec;
26299         }
26300 +               sock_vx_init(sk);
26301 +               sock_nx_init(sk);
26302  
26303         return sk;
26304  
26305 @@ -976,6 +982,11 @@ void sk_free(struct sock *sk)
26306                        __func__, atomic_read(&sk->sk_omem_alloc));
26307  
26308         put_net(sock_net(sk));
26309 +       vx_sock_dec(sk);
26310 +       clr_vx_info(&sk->sk_vx_info);
26311 +       sk->sk_xid = -1;
26312 +       clr_nx_info(&sk->sk_nx_info);
26313 +       sk->sk_nid = -1;
26314         sk_prot_free(sk->sk_prot_creator, sk);
26315  }
26316  
26317 @@ -1011,6 +1022,8 @@ struct sock *sk_clone(const struct sock 
26318  
26319                 /* SANITY */
26320                 get_net(sock_net(newsk));
26321 +               sock_vx_init(newsk);
26322 +               sock_nx_init(newsk);
26323                 sk_node_init(&newsk->sk_node);
26324                 sock_lock_init(newsk);
26325                 bh_lock_sock(newsk);
26326 @@ -1057,6 +1070,12 @@ struct sock *sk_clone(const struct sock 
26327                 newsk->sk_priority = 0;
26328                 atomic_set(&newsk->sk_refcnt, 2);
26329  
26330 +               set_vx_info(&newsk->sk_vx_info, sk->sk_vx_info);
26331 +               newsk->sk_xid = sk->sk_xid;
26332 +               vx_sock_inc(newsk);
26333 +               set_nx_info(&newsk->sk_nx_info, sk->sk_nx_info);
26334 +               newsk->sk_nid = sk->sk_nid;
26335 +
26336                 /*
26337                  * Increment the counter in the same struct proto as the master
26338                  * sock (sk_refcnt_debug_inc uses newsk->sk_prot->socks, that
26339 @@ -1744,6 +1763,11 @@ void sock_init_data(struct socket *sock,
26340  
26341         sk->sk_stamp = ktime_set(-1L, 0);
26342  
26343 +       set_vx_info(&sk->sk_vx_info, current->vx_info);
26344 +       sk->sk_xid = vx_current_xid();
26345 +       vx_sock_inc(sk);
26346 +       set_nx_info(&sk->sk_nx_info, current->nx_info);
26347 +       sk->sk_nid = nx_current_nid();
26348         atomic_set(&sk->sk_refcnt, 1);
26349         atomic_set(&sk->sk_drops, 0);
26350  }
26351 diff -NurpP --minimal linux-2.6.29/net/ipv4/af_inet.c linux-2.6.29-vs2.3.0.36.9-pre3/net/ipv4/af_inet.c
26352 --- linux-2.6.29/net/ipv4/af_inet.c     2009-03-24 14:22:46.000000000 +0100
26353 +++ linux-2.6.29-vs2.3.0.36.9-pre3/net/ipv4/af_inet.c   2009-03-24 14:48:37.000000000 +0100
26354 @@ -115,6 +115,7 @@
26355  #ifdef CONFIG_IP_MROUTE
26356  #include <linux/mroute.h>
26357  #endif
26358 +#include <linux/vs_limit.h>
26359  
26360  extern void ip_mc_drop_socket(struct sock *sk);
26361  
26362 @@ -325,9 +326,12 @@ lookup_protocol:
26363         }
26364  
26365         err = -EPERM;
26366 +       if ((protocol == IPPROTO_ICMP) &&
26367 +               nx_capable(answer->capability, NXC_RAW_ICMP))
26368 +               goto override;
26369         if (answer->capability > 0 && !capable(answer->capability))
26370                 goto out_rcu_unlock;
26371 -
26372 +override:
26373         err = -EAFNOSUPPORT;
26374         if (!inet_netns_ok(net, protocol))
26375                 goto out_rcu_unlock;
26376 @@ -445,6 +449,7 @@ int inet_bind(struct socket *sock, struc
26377         struct sockaddr_in *addr = (struct sockaddr_in *)uaddr;
26378         struct sock *sk = sock->sk;
26379         struct inet_sock *inet = inet_sk(sk);
26380 +       struct nx_v4_sock_addr nsa;
26381         unsigned short snum;
26382         int chk_addr_ret;
26383         int err;
26384 @@ -458,7 +463,11 @@ int inet_bind(struct socket *sock, struc
26385         if (addr_len < sizeof(struct sockaddr_in))
26386                 goto out;
26387  
26388 -       chk_addr_ret = inet_addr_type(sock_net(sk), addr->sin_addr.s_addr);
26389 +       err = v4_map_sock_addr(inet, addr, &nsa);
26390 +       if (err)
26391 +               goto out;
26392 +
26393 +       chk_addr_ret = inet_addr_type(sock_net(sk), nsa.saddr);
26394  
26395         /* Not specified by any standard per-se, however it breaks too
26396          * many applications when removed.  It is unfortunate since
26397 @@ -470,7 +479,7 @@ int inet_bind(struct socket *sock, struc
26398         err = -EADDRNOTAVAIL;
26399         if (!sysctl_ip_nonlocal_bind &&
26400             !(inet->freebind || inet->transparent) &&
26401 -           addr->sin_addr.s_addr != htonl(INADDR_ANY) &&
26402 +           nsa.saddr != htonl(INADDR_ANY) &&
26403             chk_addr_ret != RTN_LOCAL &&
26404             chk_addr_ret != RTN_MULTICAST &&
26405             chk_addr_ret != RTN_BROADCAST)
26406 @@ -495,7 +504,7 @@ int inet_bind(struct socket *sock, struc
26407         if (sk->sk_state != TCP_CLOSE || inet->num)
26408                 goto out_release_sock;
26409  
26410 -       inet->rcv_saddr = inet->saddr = addr->sin_addr.s_addr;
26411 +       v4_set_sock_addr(inet, &nsa);
26412         if (chk_addr_ret == RTN_MULTICAST || chk_addr_ret == RTN_BROADCAST)
26413                 inet->saddr = 0;  /* Use device */
26414  
26415 @@ -688,11 +697,13 @@ int inet_getname(struct socket *sock, st
26416                      peer == 1))
26417                         return -ENOTCONN;
26418                 sin->sin_port = inet->dport;
26419 -               sin->sin_addr.s_addr = inet->daddr;
26420 +               sin->sin_addr.s_addr =
26421 +                       nx_map_sock_lback(sk->sk_nx_info, inet->daddr);
26422         } else {
26423                 __be32 addr = inet->rcv_saddr;
26424                 if (!addr)
26425                         addr = inet->saddr;
26426 +               addr = nx_map_sock_lback(sk->sk_nx_info, addr);
26427                 sin->sin_port = inet->sport;
26428                 sin->sin_addr.s_addr = addr;
26429         }
26430 diff -NurpP --minimal linux-2.6.29/net/ipv4/devinet.c linux-2.6.29-vs2.3.0.36.9-pre3/net/ipv4/devinet.c
26431 --- linux-2.6.29/net/ipv4/devinet.c     2009-03-24 14:22:46.000000000 +0100
26432 +++ linux-2.6.29-vs2.3.0.36.9-pre3/net/ipv4/devinet.c   2009-03-24 14:48:37.000000000 +0100
26433 @@ -413,6 +413,7 @@ struct in_device *inetdev_by_index(struc
26434         return in_dev;
26435  }
26436  
26437 +
26438  /* Called only from RTNL semaphored context. No locks. */
26439  
26440  struct in_ifaddr *inet_ifa_byprefix(struct in_device *in_dev, __be32 prefix,
26441 @@ -653,6 +654,8 @@ int devinet_ioctl(struct net *net, unsig
26442                 *colon = ':';
26443  
26444         if ((in_dev = __in_dev_get_rtnl(dev)) != NULL) {
26445 +               struct nx_info *nxi = current->nx_info;
26446 +
26447                 if (tryaddrmatch) {
26448                         /* Matthias Andree */
26449                         /* compare label and address (4.4BSD style) */
26450 @@ -661,6 +664,8 @@ int devinet_ioctl(struct net *net, unsig
26451                            This is checked above. */
26452                         for (ifap = &in_dev->ifa_list; (ifa = *ifap) != NULL;
26453                              ifap = &ifa->ifa_next) {
26454 +                               if (!nx_v4_ifa_visible(nxi, ifa))
26455 +                                       continue;
26456                                 if (!strcmp(ifr.ifr_name, ifa->ifa_label) &&
26457                                     sin_orig.sin_addr.s_addr ==
26458                                                         ifa->ifa_address) {
26459 @@ -673,9 +678,12 @@ int devinet_ioctl(struct net *net, unsig
26460                    comparing just the label */
26461                 if (!ifa) {
26462                         for (ifap = &in_dev->ifa_list; (ifa = *ifap) != NULL;
26463 -                            ifap = &ifa->ifa_next)
26464 +                            ifap = &ifa->ifa_next) {
26465 +                               if (!nx_v4_ifa_visible(nxi, ifa))
26466 +                                       continue;
26467                                 if (!strcmp(ifr.ifr_name, ifa->ifa_label))
26468                                         break;
26469 +                       }
26470                 }
26471         }
26472  
26473 @@ -826,6 +834,8 @@ static int inet_gifconf(struct net_devic
26474                 goto out;
26475  
26476         for (; ifa; ifa = ifa->ifa_next) {
26477 +               if (!nx_v4_ifa_visible(current->nx_info, ifa))
26478 +                       continue;
26479                 if (!buf) {
26480                         done += sizeof(ifr);
26481                         continue;
26482 @@ -1156,6 +1166,7 @@ static int inet_dump_ifaddr(struct sk_bu
26483         struct net_device *dev;
26484         struct in_device *in_dev;
26485         struct in_ifaddr *ifa;
26486 +       struct sock *sk = skb->sk;
26487         int s_ip_idx, s_idx = cb->args[0];
26488  
26489         s_ip_idx = ip_idx = cb->args[1];
26490 @@ -1170,6 +1181,8 @@ static int inet_dump_ifaddr(struct sk_bu
26491  
26492                 for (ifa = in_dev->ifa_list, ip_idx = 0; ifa;
26493                      ifa = ifa->ifa_next, ip_idx++) {
26494 +                       if (sk && !nx_v4_ifa_visible(sk->sk_nx_info, ifa))
26495 +                               continue;
26496                         if (ip_idx < s_ip_idx)
26497                                 continue;
26498                         if (inet_fill_ifaddr(skb, ifa, NETLINK_CB(cb->skb).pid,
26499 diff -NurpP --minimal linux-2.6.29/net/ipv4/fib_hash.c linux-2.6.29-vs2.3.0.36.9-pre3/net/ipv4/fib_hash.c
26500 --- linux-2.6.29/net/ipv4/fib_hash.c    2009-03-24 14:22:46.000000000 +0100
26501 +++ linux-2.6.29-vs2.3.0.36.9-pre3/net/ipv4/fib_hash.c  2009-03-24 14:48:37.000000000 +0100
26502 @@ -1022,7 +1022,7 @@ static int fib_seq_show(struct seq_file 
26503         prefix  = f->fn_key;
26504         mask    = FZ_MASK(iter->zone);
26505         flags   = fib_flag_trans(fa->fa_type, mask, fi);
26506 -       if (fi)
26507 +       if (fi && nx_dev_visible(current->nx_info, fi->fib_dev))
26508                 seq_printf(seq,
26509                          "%s\t%08X\t%08X\t%04X\t%d\t%u\t%d\t%08X\t%d\t%u\t%u%n",
26510                          fi->fib_dev ? fi->fib_dev->name : "*", prefix,
26511 diff -NurpP --minimal linux-2.6.29/net/ipv4/inet_connection_sock.c linux-2.6.29-vs2.3.0.36.9-pre3/net/ipv4/inet_connection_sock.c
26512 --- linux-2.6.29/net/ipv4/inet_connection_sock.c        2009-03-24 14:22:46.000000000 +0100
26513 +++ linux-2.6.29-vs2.3.0.36.9-pre3/net/ipv4/inet_connection_sock.c      2009-03-24 14:48:37.000000000 +0100
26514 @@ -49,10 +49,40 @@ void inet_get_local_port_range(int *low,
26515  }
26516  EXPORT_SYMBOL(inet_get_local_port_range);
26517  
26518 +int ipv4_rcv_saddr_equal(const struct sock *sk1, const struct sock *sk2)
26519 +{
26520 +       __be32  sk1_rcv_saddr = inet_rcv_saddr(sk1),
26521 +               sk2_rcv_saddr = inet_rcv_saddr(sk2);
26522 +
26523 +       if (inet_v6_ipv6only(sk2))
26524 +               return 0;
26525 +
26526 +       if (sk1_rcv_saddr &&
26527 +           sk2_rcv_saddr &&
26528 +           sk1_rcv_saddr == sk2_rcv_saddr)
26529 +               return 1;
26530 +
26531 +       if (sk1_rcv_saddr &&
26532 +           !sk2_rcv_saddr &&
26533 +           v4_addr_in_nx_info(sk2->sk_nx_info, sk1_rcv_saddr, NXA_MASK_BIND))
26534 +               return 1;
26535 +
26536 +       if (sk2_rcv_saddr &&
26537 +           !sk1_rcv_saddr &&
26538 +           v4_addr_in_nx_info(sk1->sk_nx_info, sk2_rcv_saddr, NXA_MASK_BIND))
26539 +               return 1;
26540 +
26541 +       if (!sk1_rcv_saddr &&
26542 +           !sk2_rcv_saddr &&
26543 +           nx_v4_addr_conflict(sk1->sk_nx_info, sk2->sk_nx_info))
26544 +               return 1;
26545 +
26546 +       return 0;
26547 +}
26548 +
26549  int inet_csk_bind_conflict(const struct sock *sk,
26550                            const struct inet_bind_bucket *tb)
26551  {
26552 -       const __be32 sk_rcv_saddr = inet_rcv_saddr(sk);
26553         struct sock *sk2;
26554         struct hlist_node *node;
26555         int reuse = sk->sk_reuse;
26556 @@ -72,9 +102,7 @@ int inet_csk_bind_conflict(const struct 
26557                      sk->sk_bound_dev_if == sk2->sk_bound_dev_if)) {
26558                         if (!reuse || !sk2->sk_reuse ||
26559                             sk2->sk_state == TCP_LISTEN) {
26560 -                               const __be32 sk2_rcv_saddr = inet_rcv_saddr(sk2);
26561 -                               if (!sk2_rcv_saddr || !sk_rcv_saddr ||
26562 -                                   sk2_rcv_saddr == sk_rcv_saddr)
26563 +                               if (ipv4_rcv_saddr_equal(sk, sk2))
26564                                         break;
26565                         }
26566                 }
26567 diff -NurpP --minimal linux-2.6.29/net/ipv4/inet_diag.c linux-2.6.29-vs2.3.0.36.9-pre3/net/ipv4/inet_diag.c
26568 --- linux-2.6.29/net/ipv4/inet_diag.c   2009-03-24 14:22:46.000000000 +0100
26569 +++ linux-2.6.29-vs2.3.0.36.9-pre3/net/ipv4/inet_diag.c 2009-03-24 14:48:37.000000000 +0100
26570 @@ -32,6 +32,8 @@
26571  #include <linux/stddef.h>
26572  
26573  #include <linux/inet_diag.h>
26574 +#include <linux/vs_network.h>
26575 +#include <linux/vs_inet.h>
26576  
26577  static const struct inet_diag_handler **inet_diag_table;
26578  
26579 @@ -118,8 +120,8 @@ static int inet_csk_diag_fill(struct soc
26580  
26581         r->id.idiag_sport = inet->sport;
26582         r->id.idiag_dport = inet->dport;
26583 -       r->id.idiag_src[0] = inet->rcv_saddr;
26584 -       r->id.idiag_dst[0] = inet->daddr;
26585 +       r->id.idiag_src[0] = nx_map_sock_lback(sk->sk_nx_info, inet->rcv_saddr);
26586 +       r->id.idiag_dst[0] = nx_map_sock_lback(sk->sk_nx_info, inet->daddr);
26587  
26588  #if defined(CONFIG_IPV6) || defined (CONFIG_IPV6_MODULE)
26589         if (r->idiag_family == AF_INET6) {
26590 @@ -206,8 +208,8 @@ static int inet_twsk_diag_fill(struct in
26591         r->id.idiag_cookie[1] = (u32)(((unsigned long)tw >> 31) >> 1);
26592         r->id.idiag_sport     = tw->tw_sport;
26593         r->id.idiag_dport     = tw->tw_dport;
26594 -       r->id.idiag_src[0]    = tw->tw_rcv_saddr;
26595 -       r->id.idiag_dst[0]    = tw->tw_daddr;
26596 +       r->id.idiag_src[0]    = nx_map_sock_lback(tw->tw_nx_info, tw->tw_rcv_saddr);
26597 +       r->id.idiag_dst[0]    = nx_map_sock_lback(tw->tw_nx_info, tw->tw_daddr);
26598         r->idiag_state        = tw->tw_substate;
26599         r->idiag_timer        = 3;
26600         r->idiag_expires      = DIV_ROUND_UP(tmo * 1000, HZ);
26601 @@ -264,6 +266,7 @@ static int inet_diag_get_exact(struct sk
26602         err = -EINVAL;
26603  
26604         if (req->idiag_family == AF_INET) {
26605 +               /* TODO: lback */
26606                 sk = inet_lookup(&init_net, hashinfo, req->id.idiag_dst[0],
26607                                  req->id.idiag_dport, req->id.idiag_src[0],
26608                                  req->id.idiag_sport, req->id.idiag_if);
26609 @@ -506,6 +509,7 @@ static int inet_csk_diag_dump(struct soc
26610                 } else
26611  #endif
26612                 {
26613 +                       /* TODO: lback */
26614                         entry.saddr = &inet->rcv_saddr;
26615                         entry.daddr = &inet->daddr;
26616                 }
26617 @@ -542,6 +546,7 @@ static int inet_twsk_diag_dump(struct in
26618                 } else
26619  #endif
26620                 {
26621 +                       /* TODO: lback */
26622                         entry.saddr = &tw->tw_rcv_saddr;
26623                         entry.daddr = &tw->tw_daddr;
26624                 }
26625 @@ -588,8 +593,8 @@ static int inet_diag_fill_req(struct sk_
26626  
26627         r->id.idiag_sport = inet->sport;
26628         r->id.idiag_dport = ireq->rmt_port;
26629 -       r->id.idiag_src[0] = ireq->loc_addr;
26630 -       r->id.idiag_dst[0] = ireq->rmt_addr;
26631 +       r->id.idiag_src[0] = nx_map_sock_lback(sk->sk_nx_info, ireq->loc_addr);
26632 +       r->id.idiag_dst[0] = nx_map_sock_lback(sk->sk_nx_info, ireq->rmt_addr);
26633         r->idiag_expires = jiffies_to_msecs(tmo);
26634         r->idiag_rqueue = 0;
26635         r->idiag_wqueue = 0;
26636 @@ -659,6 +664,7 @@ static int inet_diag_dump_reqs(struct sk
26637                                 continue;
26638  
26639                         if (bc) {
26640 +                               /* TODO: lback */
26641                                 entry.saddr =
26642  #if defined(CONFIG_IPV6) || defined (CONFIG_IPV6_MODULE)
26643                                         (entry.family == AF_INET6) ?
26644 @@ -729,6 +735,8 @@ static int inet_diag_dump(struct sk_buff
26645                         sk_nulls_for_each(sk, node, &ilb->head) {
26646                                 struct inet_sock *inet = inet_sk(sk);
26647  
26648 +                               if (!nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
26649 +                                       continue;
26650                                 if (num < s_num) {
26651                                         num++;
26652                                         continue;
26653 @@ -795,6 +803,8 @@ skip_listen_ht:
26654                 sk_nulls_for_each(sk, node, &head->chain) {
26655                         struct inet_sock *inet = inet_sk(sk);
26656  
26657 +                       if (!nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
26658 +                               continue;
26659                         if (num < s_num)
26660                                 goto next_normal;
26661                         if (!(r->idiag_states & (1 << sk->sk_state)))
26662 @@ -819,6 +829,8 @@ next_normal:
26663                         inet_twsk_for_each(tw, node,
26664                                     &head->twchain) {
26665  
26666 +                               if (!nx_check(tw->tw_nid, VS_WATCH_P | VS_IDENT))
26667 +                                       continue;
26668                                 if (num < s_num)
26669                                         goto next_dying;
26670                                 if (r->id.idiag_sport != tw->tw_sport &&
26671 diff -NurpP --minimal linux-2.6.29/net/ipv4/inet_hashtables.c linux-2.6.29-vs2.3.0.36.9-pre3/net/ipv4/inet_hashtables.c
26672 --- linux-2.6.29/net/ipv4/inet_hashtables.c     2009-03-24 14:22:46.000000000 +0100
26673 +++ linux-2.6.29-vs2.3.0.36.9-pre3/net/ipv4/inet_hashtables.c   2009-03-24 19:35:10.000000000 +0100
26674 @@ -21,6 +21,7 @@
26675  
26676  #include <net/inet_connection_sock.h>
26677  #include <net/inet_hashtables.h>
26678 +#include <net/route.h>
26679  #include <net/ip.h>
26680  
26681  /*
26682 @@ -142,7 +143,6 @@ static inline int compute_score(struct s
26683   * wildcarded during the search since they can never be otherwise.
26684   */
26685  
26686 -
26687  struct sock *__inet_lookup_listener(struct net *net,
26688                                     struct inet_hashinfo *hashinfo,
26689                                     const __be32 daddr, const unsigned short hnum,
26690 @@ -165,6 +165,7 @@ begin:
26691                         hiscore = score;
26692                 }
26693         }
26694 +
26695         /*
26696          * if the nulls value we got at the end of this lookup is
26697          * not the expected one, we must restart lookup.
26698 diff -NurpP --minimal linux-2.6.29/net/ipv4/netfilter/nf_nat_helper.c linux-2.6.29-vs2.3.0.36.9-pre3/net/ipv4/netfilter/nf_nat_helper.c
26699 --- linux-2.6.29/net/ipv4/netfilter/nf_nat_helper.c     2008-12-25 00:26:37.000000000 +0100
26700 +++ linux-2.6.29-vs2.3.0.36.9-pre3/net/ipv4/netfilter/nf_nat_helper.c   2009-02-22 22:54:26.000000000 +0100
26701 @@ -19,6 +19,7 @@
26702  #include <net/route.h>
26703  
26704  #include <linux/netfilter_ipv4.h>
26705 +#include <net/route.h>
26706  #include <net/netfilter/nf_conntrack.h>
26707  #include <net/netfilter/nf_conntrack_helper.h>
26708  #include <net/netfilter/nf_conntrack_ecache.h>
26709 diff -NurpP --minimal linux-2.6.29/net/ipv4/netfilter.c linux-2.6.29-vs2.3.0.36.9-pre3/net/ipv4/netfilter.c
26710 --- linux-2.6.29/net/ipv4/netfilter.c   2009-03-24 14:22:46.000000000 +0100
26711 +++ linux-2.6.29-vs2.3.0.36.9-pre3/net/ipv4/netfilter.c 2009-03-24 14:48:37.000000000 +0100
26712 @@ -4,7 +4,7 @@
26713  #include <linux/netfilter_ipv4.h>
26714  #include <linux/ip.h>
26715  #include <linux/skbuff.h>
26716 -#include <net/route.h>
26717 +// #include <net/route.h>
26718  #include <net/xfrm.h>
26719  #include <net/ip.h>
26720  #include <net/netfilter/nf_queue.h>
26721 diff -NurpP --minimal linux-2.6.29/net/ipv4/raw.c linux-2.6.29-vs2.3.0.36.9-pre3/net/ipv4/raw.c
26722 --- linux-2.6.29/net/ipv4/raw.c 2009-03-24 14:22:46.000000000 +0100
26723 +++ linux-2.6.29-vs2.3.0.36.9-pre3/net/ipv4/raw.c       2009-03-24 14:48:37.000000000 +0100
26724 @@ -117,7 +117,7 @@ static struct sock *__raw_v4_lookup(stru
26725  
26726                 if (net_eq(sock_net(sk), net) && inet->num == num       &&
26727                     !(inet->daddr && inet->daddr != raddr)              &&
26728 -                   !(inet->rcv_saddr && inet->rcv_saddr != laddr)      &&
26729 +                   v4_sock_addr_match(sk->sk_nx_info, inet, laddr)     &&
26730                     !(sk->sk_bound_dev_if && sk->sk_bound_dev_if != dif))
26731                         goto found; /* gotcha */
26732         }
26733 @@ -372,6 +372,12 @@ static int raw_send_hdrinc(struct sock *
26734                 icmp_out_count(net, ((struct icmphdr *)
26735                         skb_transport_header(skb))->type);
26736  
26737 +       err = -EPERM;
26738 +       if (!nx_check(0, VS_ADMIN) && !capable(CAP_NET_RAW) &&
26739 +               sk->sk_nx_info &&
26740 +               !v4_addr_in_nx_info(sk->sk_nx_info, iph->saddr, NXA_MASK_BIND))
26741 +               goto error_free;
26742 +
26743         err = NF_HOOK(PF_INET, NF_INET_LOCAL_OUT, skb, NULL, rt->u.dst.dev,
26744                       dst_output);
26745         if (err > 0)
26746 @@ -383,6 +389,7 @@ out:
26747  
26748  error_fault:
26749         err = -EFAULT;
26750 +error_free:
26751         kfree_skb(skb);
26752  error:
26753         IP_INC_STATS(net, IPSTATS_MIB_OUTDISCARDS);
26754 @@ -550,6 +557,13 @@ static int raw_sendmsg(struct kiocb *ioc
26755                 }
26756  
26757                 security_sk_classify_flow(sk, &fl);
26758 +               if (sk->sk_nx_info) {
26759 +                       err = ip_v4_find_src(sock_net(sk),
26760 +                               sk->sk_nx_info, &rt, &fl);
26761 +
26762 +                       if (err)
26763 +                               goto done;
26764 +               }
26765                 err = ip_route_output_flow(sock_net(sk), &rt, &fl, sk, 1);
26766         }
26767         if (err)
26768 @@ -619,17 +633,19 @@ static int raw_bind(struct sock *sk, str
26769  {
26770         struct inet_sock *inet = inet_sk(sk);
26771         struct sockaddr_in *addr = (struct sockaddr_in *) uaddr;
26772 +       struct nx_v4_sock_addr nsa = { 0 };
26773         int ret = -EINVAL;
26774         int chk_addr_ret;
26775  
26776         if (sk->sk_state != TCP_CLOSE || addr_len < sizeof(struct sockaddr_in))
26777                 goto out;
26778 -       chk_addr_ret = inet_addr_type(sock_net(sk), addr->sin_addr.s_addr);
26779 +       v4_map_sock_addr(inet, addr, &nsa);
26780 +       chk_addr_ret = inet_addr_type(sock_net(sk), nsa.saddr);
26781         ret = -EADDRNOTAVAIL;
26782 -       if (addr->sin_addr.s_addr && chk_addr_ret != RTN_LOCAL &&
26783 +       if (nsa.saddr && chk_addr_ret != RTN_LOCAL &&
26784             chk_addr_ret != RTN_MULTICAST && chk_addr_ret != RTN_BROADCAST)
26785                 goto out;
26786 -       inet->rcv_saddr = inet->saddr = addr->sin_addr.s_addr;
26787 +       v4_set_sock_addr(inet, &nsa);
26788         if (chk_addr_ret == RTN_MULTICAST || chk_addr_ret == RTN_BROADCAST)
26789                 inet->saddr = 0;  /* Use device */
26790         sk_dst_reset(sk);
26791 @@ -681,7 +697,8 @@ static int raw_recvmsg(struct kiocb *ioc
26792         /* Copy the address. */
26793         if (sin) {
26794                 sin->sin_family = AF_INET;
26795 -               sin->sin_addr.s_addr = ip_hdr(skb)->saddr;
26796 +               sin->sin_addr.s_addr =
26797 +                       nx_map_sock_lback(sk->sk_nx_info, ip_hdr(skb)->saddr);
26798                 sin->sin_port = 0;
26799                 memset(&sin->sin_zero, 0, sizeof(sin->sin_zero));
26800         }
26801 @@ -858,7 +875,8 @@ static struct sock *raw_get_first(struct
26802                 struct hlist_node *node;
26803  
26804                 sk_for_each(sk, node, &state->h->ht[state->bucket])
26805 -                       if (sock_net(sk) == seq_file_net(seq))
26806 +                       if ((sock_net(sk) == seq_file_net(seq)) &&
26807 +                               nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
26808                                 goto found;
26809         }
26810         sk = NULL;
26811 @@ -874,7 +892,8 @@ static struct sock *raw_get_next(struct 
26812                 sk = sk_next(sk);
26813  try_again:
26814                 ;
26815 -       } while (sk && sock_net(sk) != seq_file_net(seq));
26816 +       } while (sk && ((sock_net(sk) != seq_file_net(seq)) ||
26817 +               !nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT)));
26818  
26819         if (!sk && ++state->bucket < RAW_HTABLE_SIZE) {
26820                 sk = sk_head(&state->h->ht[state->bucket]);
26821 @@ -933,7 +952,10 @@ static void raw_sock_seq_show(struct seq
26822  
26823         seq_printf(seq, "%4d: %08X:%04X %08X:%04X"
26824                 " %02X %08X:%08X %02X:%08lX %08X %5d %8d %lu %d %p %d\n",
26825 -               i, src, srcp, dest, destp, sp->sk_state,
26826 +               i,
26827 +               nx_map_sock_lback(current_nx_info(), src), srcp,
26828 +               nx_map_sock_lback(current_nx_info(), dest), destp,
26829 +               sp->sk_state,
26830                 atomic_read(&sp->sk_wmem_alloc),
26831                 atomic_read(&sp->sk_rmem_alloc),
26832                 0, 0L, 0, sock_i_uid(sp), 0, sock_i_ino(sp),
26833 diff -NurpP --minimal linux-2.6.29/net/ipv4/tcp.c linux-2.6.29-vs2.3.0.36.9-pre3/net/ipv4/tcp.c
26834 --- linux-2.6.29/net/ipv4/tcp.c 2009-03-24 14:22:46.000000000 +0100
26835 +++ linux-2.6.29-vs2.3.0.36.9-pre3/net/ipv4/tcp.c       2009-03-24 14:48:37.000000000 +0100
26836 @@ -264,6 +264,7 @@
26837  #include <linux/cache.h>
26838  #include <linux/err.h>
26839  #include <linux/crypto.h>
26840 +#include <linux/in.h>
26841  
26842  #include <net/icmp.h>
26843  #include <net/tcp.h>
26844 diff -NurpP --minimal linux-2.6.29/net/ipv4/tcp_ipv4.c linux-2.6.29-vs2.3.0.36.9-pre3/net/ipv4/tcp_ipv4.c
26845 --- linux-2.6.29/net/ipv4/tcp_ipv4.c    2009-03-24 14:22:46.000000000 +0100
26846 +++ linux-2.6.29-vs2.3.0.36.9-pre3/net/ipv4/tcp_ipv4.c  2009-03-24 19:51:34.000000000 +0100
26847 @@ -1894,6 +1894,12 @@ static void *listening_get_next(struct s
26848                 req = req->dl_next;
26849                 while (1) {
26850                         while (req) {
26851 +                               vxdprintk(VXD_CBIT(net, 6),
26852 +                                       "sk,req: %p [#%d] (from %d)", req->sk,
26853 +                                       (req->sk)?req->sk->sk_nid:0, nx_current_nid());
26854 +                               if (req->sk &&
26855 +                                       !nx_check(req->sk->sk_nid, VS_WATCH_P | VS_IDENT))
26856 +                                       continue;
26857                                 if (req->rsk_ops->family == st->family) {
26858                                         cur = req;
26859                                         goto out;
26860 @@ -1918,6 +1924,10 @@ get_req:
26861         }
26862  get_sk:
26863         sk_nulls_for_each_from(sk, node) {
26864 +               vxdprintk(VXD_CBIT(net, 6), "sk: %p [#%d] (from %d)",
26865 +                       sk, sk->sk_nid, nx_current_nid());
26866 +               if (!nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
26867 +                       continue;
26868                 if (sk->sk_family == st->family && net_eq(sock_net(sk), net)) {
26869                         cur = sk;
26870                         goto out;
26871 @@ -1981,6 +1991,11 @@ static void *established_get_first(struc
26872  
26873                 spin_lock_bh(lock);
26874                 sk_nulls_for_each(sk, node, &tcp_hashinfo.ehash[st->bucket].chain) {
26875 +                       vxdprintk(VXD_CBIT(net, 6),
26876 +                               "sk,egf: %p [#%d] (from %d)",
26877 +                               sk, sk->sk_nid, nx_current_nid());
26878 +                       if (!nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
26879 +                               continue;
26880                         if (sk->sk_family != st->family ||
26881                             !net_eq(sock_net(sk), net)) {
26882                                 continue;
26883 @@ -1991,6 +2006,11 @@ static void *established_get_first(struc
26884                 st->state = TCP_SEQ_STATE_TIME_WAIT;
26885                 inet_twsk_for_each(tw, node,
26886                                    &tcp_hashinfo.ehash[st->bucket].twchain) {
26887 +                       vxdprintk(VXD_CBIT(net, 6),
26888 +                               "tw: %p [#%d] (from %d)",
26889 +                               tw, tw->tw_nid, nx_current_nid());
26890 +                       if (!nx_check(tw->tw_nid, VS_WATCH_P | VS_IDENT))
26891 +                               continue;
26892                         if (tw->tw_family != st->family ||
26893                             !net_eq(twsk_net(tw), net)) {
26894                                 continue;
26895 @@ -2019,7 +2039,9 @@ static void *established_get_next(struct
26896                 tw = cur;
26897                 tw = tw_next(tw);
26898  get_tw:
26899 -               while (tw && (tw->tw_family != st->family || !net_eq(twsk_net(tw), net))) {
26900 +               while (tw && (tw->tw_family != st->family ||
26901 +                       !net_eq(twsk_net(tw), net) ||
26902 +                       !nx_check(tw->tw_nid, VS_WATCH_P | VS_IDENT))) {
26903                         tw = tw_next(tw);
26904                 }
26905                 if (tw) {
26906 @@ -2042,6 +2064,11 @@ get_tw:
26907                 sk = sk_nulls_next(sk);
26908  
26909         sk_nulls_for_each_from(sk, node) {
26910 +               vxdprintk(VXD_CBIT(net, 6),
26911 +                       "sk,egn: %p [#%d] (from %d)",
26912 +                       sk, sk->sk_nid, nx_current_nid());
26913 +               if (!nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
26914 +                       continue;
26915                 if (sk->sk_family == st->family && net_eq(sock_net(sk), net))
26916                         goto found;
26917         }
26918 @@ -2193,9 +2220,9 @@ static void get_openreq4(struct sock *sk
26919         seq_printf(f, "%4d: %08X:%04X %08X:%04X"
26920                 " %02X %08X:%08X %02X:%08lX %08X %5d %8d %u %d %p%n",
26921                 i,
26922 -               ireq->loc_addr,
26923 +               nx_map_sock_lback(current_nx_info(), ireq->loc_addr),
26924                 ntohs(inet_sk(sk)->sport),
26925 -               ireq->rmt_addr,
26926 +               nx_map_sock_lback(current_nx_info(), ireq->rmt_addr),
26927                 ntohs(ireq->rmt_port),
26928                 TCP_SYN_RECV,
26929                 0, 0, /* could print option size, but that is af dependent. */
26930 @@ -2238,7 +2265,10 @@ static void get_tcp4_sock(struct sock *s
26931  
26932         seq_printf(f, "%4d: %08X:%04X %08X:%04X %02X %08X:%08X %02X:%08lX "
26933                         "%08X %5d %8d %lu %d %p %lu %lu %u %u %d%n",
26934 -               i, src, srcp, dest, destp, sk->sk_state,
26935 +               i,
26936 +               nx_map_sock_lback(current_nx_info(), src), srcp,
26937 +               nx_map_sock_lback(current_nx_info(), dest), destp,
26938 +               sk->sk_state,
26939                 tp->write_seq - tp->snd_una,
26940                 sk->sk_state == TCP_LISTEN ? sk->sk_ack_backlog :
26941                                              (tp->rcv_nxt - tp->copied_seq),
26942 @@ -2274,7 +2304,10 @@ static void get_timewait4_sock(struct in
26943  
26944         seq_printf(f, "%4d: %08X:%04X %08X:%04X"
26945                 " %02X %08X:%08X %02X:%08lX %08X %5d %8d %d %d %p%n",
26946 -               i, src, srcp, dest, destp, tw->tw_substate, 0, 0,
26947 +               i,
26948 +               nx_map_sock_lback(current_nx_info(), src), srcp,
26949 +               nx_map_sock_lback(current_nx_info(), dest), destp,
26950 +               tw->tw_substate, 0, 0,
26951                 3, jiffies_to_clock_t(ttd), 0, 0, 0, 0,
26952                 atomic_read(&tw->tw_refcnt), tw, len);
26953  }
26954 diff -NurpP --minimal linux-2.6.29/net/ipv4/tcp_minisocks.c linux-2.6.29-vs2.3.0.36.9-pre3/net/ipv4/tcp_minisocks.c
26955 --- linux-2.6.29/net/ipv4/tcp_minisocks.c       2009-03-24 14:22:46.000000000 +0100
26956 +++ linux-2.6.29-vs2.3.0.36.9-pre3/net/ipv4/tcp_minisocks.c     2009-03-24 14:48:37.000000000 +0100
26957 @@ -26,6 +26,10 @@
26958  #include <net/inet_common.h>
26959  #include <net/xfrm.h>
26960  
26961 +#include <linux/vs_limit.h>
26962 +#include <linux/vs_socket.h>
26963 +#include <linux/vs_context.h>
26964 +
26965  #ifdef CONFIG_SYSCTL
26966  #define SYNC_INIT 0 /* let the user enable it */
26967  #else
26968 @@ -293,6 +297,11 @@ void tcp_time_wait(struct sock *sk, int 
26969                 tcptw->tw_ts_recent     = tp->rx_opt.ts_recent;
26970                 tcptw->tw_ts_recent_stamp = tp->rx_opt.ts_recent_stamp;
26971  
26972 +               tw->tw_xid              = sk->sk_xid;
26973 +               tw->tw_vx_info          = NULL;
26974 +               tw->tw_nid              = sk->sk_nid;
26975 +               tw->tw_nx_info          = NULL;
26976 +
26977  #if defined(CONFIG_IPV6) || defined(CONFIG_IPV6_MODULE)
26978                 if (tw->tw_family == PF_INET6) {
26979                         struct ipv6_pinfo *np = inet6_sk(sk);
26980 diff -NurpP --minimal linux-2.6.29/net/ipv4/udp.c linux-2.6.29-vs2.3.0.36.9-pre3/net/ipv4/udp.c
26981 --- linux-2.6.29/net/ipv4/udp.c 2009-03-24 14:22:46.000000000 +0100
26982 +++ linux-2.6.29-vs2.3.0.36.9-pre3/net/ipv4/udp.c       2009-03-25 10:50:13.000000000 +0100
26983 @@ -222,14 +222,7 @@ fail:
26984         return error;
26985  }
26986  
26987 -static int ipv4_rcv_saddr_equal(const struct sock *sk1, const struct sock *sk2)
26988 -{
26989 -       struct inet_sock *inet1 = inet_sk(sk1), *inet2 = inet_sk(sk2);
26990 -
26991 -       return  ( !ipv6_only_sock(sk2)  &&
26992 -                 (!inet1->rcv_saddr || !inet2->rcv_saddr ||
26993 -                  inet1->rcv_saddr == inet2->rcv_saddr      ));
26994 -}
26995 +extern int ipv4_rcv_saddr_equal(const struct sock *, const struct sock *);
26996  
26997  int udp_v4_get_port(struct sock *sk, unsigned short snum)
26998  {
26999 @@ -251,6 +244,11 @@ static inline int compute_score(struct s
27000                         if (inet->rcv_saddr != daddr)
27001                                 return -1;
27002                         score += 2;
27003 +               } else {
27004 +                       /* block non nx_info ips */
27005 +                       if (!v4_addr_in_nx_info(sk->sk_nx_info,
27006 +                               daddr, NXA_MASK_BIND))
27007 +                               return -1;
27008                 }
27009                 if (inet->daddr) {
27010                         if (inet->daddr != saddr)
27011 @@ -271,6 +269,7 @@ static inline int compute_score(struct s
27012         return score;
27013  }
27014  
27015 +
27016  /* UDP is nearly always wildcards out the wazoo, it makes no sense to try
27017   * harder than this. -DaveM
27018   */
27019 @@ -292,6 +291,11 @@ begin:
27020         sk_nulls_for_each_rcu(sk, node, &hslot->head) {
27021                 score = compute_score(sk, net, saddr, hnum, sport,
27022                                       daddr, dport, dif);
27023 +               /* FIXME: disabled?
27024 +               if (score == 9) {
27025 +                       result = sk;
27026 +                       break;
27027 +               } else */
27028                 if (score > badness) {
27029                         result = sk;
27030                         badness = score;
27031 @@ -305,6 +309,7 @@ begin:
27032         if (get_nulls_value(node) != hash)
27033                 goto begin;
27034  
27035 +
27036         if (result) {
27037                 if (unlikely(!atomic_inc_not_zero(&result->sk_refcnt)))
27038                         result = NULL;
27039 @@ -314,6 +319,7 @@ begin:
27040                         goto begin;
27041                 }
27042         }
27043 +
27044         rcu_read_unlock();
27045         return result;
27046  }
27047 @@ -356,7 +362,7 @@ static inline struct sock *udp_v4_mcast_
27048                     s->sk_hash != hnum                                  ||
27049                     (inet->daddr && inet->daddr != rmt_addr)            ||
27050                     (inet->dport != rmt_port && inet->dport)            ||
27051 -                   (inet->rcv_saddr && inet->rcv_saddr != loc_addr)    ||
27052 +                   !v4_sock_addr_match(sk->sk_nx_info, inet, loc_addr) ||
27053                     ipv6_only_sock(s)                                   ||
27054                     (s->sk_bound_dev_if && s->sk_bound_dev_if != dif))
27055                         continue;
27056 @@ -694,8 +700,13 @@ int udp_sendmsg(struct kiocb *iocb, stru
27057                                                { .sport = inet->sport,
27058                                                  .dport = dport } } };
27059                 struct net *net = sock_net(sk);
27060 +               struct nx_info *nxi = sk->sk_nx_info;
27061  
27062                 security_sk_classify_flow(sk, &fl);
27063 +               err = ip_v4_find_src(net, nxi, &rt, &fl);
27064 +               if (err)
27065 +                       goto out;
27066 +
27067                 err = ip_route_output_flow(net, &rt, &fl, sk, 1);
27068                 if (err) {
27069                         if (err == -ENETUNREACH)
27070 @@ -940,7 +951,8 @@ try_again:
27071         {
27072                 sin->sin_family = AF_INET;
27073                 sin->sin_port = udp_hdr(skb)->source;
27074 -               sin->sin_addr.s_addr = ip_hdr(skb)->saddr;
27075 +               sin->sin_addr.s_addr = nx_map_sock_lback(
27076 +                       skb->sk->sk_nx_info, ip_hdr(skb)->saddr);
27077                 memset(sin->sin_zero, 0, sizeof(sin->sin_zero));
27078         }
27079         if (inet->cmsg_flags)
27080 @@ -1594,6 +1606,8 @@ static struct sock *udp_get_first(struct
27081                 sk_nulls_for_each(sk, node, &hslot->head) {
27082                         if (!net_eq(sock_net(sk), net))
27083                                 continue;
27084 +                       if (!nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
27085 +                               continue;
27086                         if (sk->sk_family == state->family)
27087                                 goto found;
27088                 }
27089 @@ -1611,7 +1625,9 @@ static struct sock *udp_get_next(struct 
27090  
27091         do {
27092                 sk = sk_nulls_next(sk);
27093 -       } while (sk && (!net_eq(sock_net(sk), net) || sk->sk_family != state->family));
27094 +       } while (sk && (!net_eq(sock_net(sk), net) ||
27095 +               sk->sk_family != state->family ||
27096 +               !nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT)));
27097  
27098         if (!sk) {
27099                 spin_unlock_bh(&state->udp_table->hash[state->bucket].lock);
27100 @@ -1712,7 +1728,10 @@ static void udp4_format_sock(struct sock
27101  
27102         seq_printf(f, "%4d: %08X:%04X %08X:%04X"
27103                 " %02X %08X:%08X %02X:%08lX %08X %5d %8d %lu %d %p %d%n",
27104 -               bucket, src, srcp, dest, destp, sp->sk_state,
27105 +               bucket,
27106 +               nx_map_sock_lback(current_nx_info(), src), srcp,
27107 +               nx_map_sock_lback(current_nx_info(), dest), destp,
27108 +               sp->sk_state,
27109                 atomic_read(&sp->sk_wmem_alloc),
27110                 atomic_read(&sp->sk_rmem_alloc),
27111                 0, 0L, 0, sock_i_uid(sp), 0, sock_i_ino(sp),
27112 diff -NurpP --minimal linux-2.6.29/net/ipv6/addrconf.c linux-2.6.29-vs2.3.0.36.9-pre3/net/ipv6/addrconf.c
27113 --- linux-2.6.29/net/ipv6/addrconf.c    2009-03-24 14:22:46.000000000 +0100
27114 +++ linux-2.6.29-vs2.3.0.36.9-pre3/net/ipv6/addrconf.c  2009-03-24 20:39:23.000000000 +0100
27115 @@ -85,6 +85,8 @@
27116  
27117  #include <linux/proc_fs.h>
27118  #include <linux/seq_file.h>
27119 +#include <linux/vs_network.h>
27120 +#include <linux/vs_inet6.h>
27121  
27122  /* Set to 3 to get tracing... */
27123  #define ACONF_DEBUG 2
27124 @@ -1111,7 +1113,7 @@ out:
27125  
27126  int ipv6_dev_get_saddr(struct net *net, struct net_device *dst_dev,
27127                        const struct in6_addr *daddr, unsigned int prefs,
27128 -                      struct in6_addr *saddr)
27129 +                      struct in6_addr *saddr, struct nx_info *nxi)
27130  {
27131         struct ipv6_saddr_score scores[2],
27132                                 *score = &scores[0], *hiscore = &scores[1];
27133 @@ -1184,6 +1186,8 @@ int ipv6_dev_get_saddr(struct net *net, 
27134                                                dev->name);
27135                                 continue;
27136                         }
27137 +                       if (!v6_addr_in_nx_info(nxi, &score->ifa->addr, -1))
27138 +                               continue;
27139  
27140                         score->rule = -1;
27141                         bitmap_zero(score->scorebits, IPV6_SADDR_RULE_MAX);
27142 @@ -1367,35 +1371,46 @@ struct inet6_ifaddr *ipv6_get_ifaddr(str
27143         return ifp;
27144  }
27145  
27146 +extern int ipv4_rcv_saddr_equal(const struct sock *sk1, const struct sock *sk2);
27147 +
27148  int ipv6_rcv_saddr_equal(const struct sock *sk, const struct sock *sk2)
27149  {
27150         const struct in6_addr *sk_rcv_saddr6 = &inet6_sk(sk)->rcv_saddr;
27151         const struct in6_addr *sk2_rcv_saddr6 = inet6_rcv_saddr(sk2);
27152 -       __be32 sk_rcv_saddr = inet_sk(sk)->rcv_saddr;
27153         __be32 sk2_rcv_saddr = inet_rcv_saddr(sk2);
27154         int sk_ipv6only = ipv6_only_sock(sk);
27155         int sk2_ipv6only = inet_v6_ipv6only(sk2);
27156         int addr_type = ipv6_addr_type(sk_rcv_saddr6);
27157         int addr_type2 = sk2_rcv_saddr6 ? ipv6_addr_type(sk2_rcv_saddr6) : IPV6_ADDR_MAPPED;
27158  
27159 -       if (!sk2_rcv_saddr && !sk_ipv6only)
27160 +       /* FIXME: needs handling for v4 ANY */
27161 +       if (!sk2_rcv_saddr && !sk_ipv6only && !sk2->sk_nx_info)
27162                 return 1;
27163  
27164         if (addr_type2 == IPV6_ADDR_ANY &&
27165 -           !(sk2_ipv6only && addr_type == IPV6_ADDR_MAPPED))
27166 +           !(sk2_ipv6only && addr_type == IPV6_ADDR_MAPPED) &&
27167 +           v6_addr_in_nx_info(sk2->sk_nx_info, sk_rcv_saddr6, -1))
27168                 return 1;
27169  
27170         if (addr_type == IPV6_ADDR_ANY &&
27171 -           !(sk_ipv6only && addr_type2 == IPV6_ADDR_MAPPED))
27172 +           !(sk_ipv6only && addr_type2 == IPV6_ADDR_MAPPED) &&
27173 +           (sk2_rcv_saddr6 && v6_addr_in_nx_info(sk->sk_nx_info, sk2_rcv_saddr6, -1)))
27174 +               return 1;
27175 +
27176 +       if (addr_type == IPV6_ADDR_ANY &&
27177 +           addr_type2 == IPV6_ADDR_ANY &&
27178 +           nx_v6_addr_conflict(sk->sk_nx_info, sk2->sk_nx_info))
27179                 return 1;
27180  
27181         if (sk2_rcv_saddr6 &&
27182 +           addr_type != IPV6_ADDR_ANY &&
27183 +           addr_type != IPV6_ADDR_ANY &&
27184             ipv6_addr_equal(sk_rcv_saddr6, sk2_rcv_saddr6))
27185                 return 1;
27186  
27187         if (addr_type == IPV6_ADDR_MAPPED &&
27188             !sk2_ipv6only &&
27189 -           (!sk2_rcv_saddr || !sk_rcv_saddr || sk_rcv_saddr == sk2_rcv_saddr))
27190 +           ipv4_rcv_saddr_equal(sk, sk2))
27191                 return 1;
27192  
27193         return 0;
27194 @@ -2993,7 +3008,10 @@ static void if6_seq_stop(struct seq_file
27195  static int if6_seq_show(struct seq_file *seq, void *v)
27196  {
27197         struct inet6_ifaddr *ifp = (struct inet6_ifaddr *)v;
27198 -       seq_printf(seq, "%pi6 %02x %02x %02x %02x %8s\n",
27199 +
27200 +       if (nx_check(0, VS_ADMIN|VS_WATCH) ||
27201 +           v6_addr_in_nx_info(current_nx_info(), &ifp->addr, -1))
27202 +               seq_printf(seq, "%pi6 %02x %02x %02x %02x %8s\n",
27203                    &ifp->addr,
27204                    ifp->idev->dev->ifindex,
27205                    ifp->prefix_len,
27206 @@ -3487,6 +3505,12 @@ static int inet6_dump_addr(struct sk_buf
27207         struct ifmcaddr6 *ifmca;
27208         struct ifacaddr6 *ifaca;
27209         struct net *net = sock_net(skb->sk);
27210 +       struct nx_info *nxi = skb->sk ? skb->sk->sk_nx_info : NULL;
27211 +
27212 +       /* disable ipv6 on non v6 guests */
27213 +       if (nxi && !nx_info_has_v6(nxi))
27214 +               return skb->len;
27215 +
27216  
27217         s_idx = cb->args[0];
27218         s_ip_idx = ip_idx = cb->args[1];
27219 @@ -3508,6 +3532,8 @@ static int inet6_dump_addr(struct sk_buf
27220                              ifa = ifa->if_next, ip_idx++) {
27221                                 if (ip_idx < s_ip_idx)
27222                                         continue;
27223 +                               if (!v6_addr_in_nx_info(nxi, &ifa->addr, -1))
27224 +                                       continue;
27225                                 err = inet6_fill_ifaddr(skb, ifa,
27226                                                         NETLINK_CB(cb->skb).pid,
27227                                                         cb->nlh->nlmsg_seq,
27228 @@ -3521,6 +3547,8 @@ static int inet6_dump_addr(struct sk_buf
27229                              ifmca = ifmca->next, ip_idx++) {
27230                                 if (ip_idx < s_ip_idx)
27231                                         continue;
27232 +                               if (!v6_addr_in_nx_info(nxi, &ifmca->mca_addr, -1))
27233 +                                       continue;
27234                                 err = inet6_fill_ifmcaddr(skb, ifmca,
27235                                                           NETLINK_CB(cb->skb).pid,
27236                                                           cb->nlh->nlmsg_seq,
27237 @@ -3534,6 +3562,8 @@ static int inet6_dump_addr(struct sk_buf
27238                              ifaca = ifaca->aca_next, ip_idx++) {
27239                                 if (ip_idx < s_ip_idx)
27240                                         continue;
27241 +                               if (!v6_addr_in_nx_info(nxi, &ifaca->aca_addr, -1))
27242 +                                       continue;
27243                                 err = inet6_fill_ifacaddr(skb, ifaca,
27244                                                           NETLINK_CB(cb->skb).pid,
27245                                                           cb->nlh->nlmsg_seq,
27246 @@ -3819,12 +3849,19 @@ static int inet6_dump_ifinfo(struct sk_b
27247         int s_idx = cb->args[0];
27248         struct net_device *dev;
27249         struct inet6_dev *idev;
27250 +       struct nx_info *nxi = skb->sk ? skb->sk->sk_nx_info : NULL;
27251 +
27252 +       /* FIXME: maybe disable ipv6 on non v6 guests?
27253 +       if (skb->sk && skb->sk->sk_vx_info)
27254 +               return skb->len; */
27255  
27256         read_lock(&dev_base_lock);
27257         idx = 0;
27258         for_each_netdev(net, dev) {
27259                 if (idx < s_idx)
27260                         goto cont;
27261 +               if (!v6_dev_in_nx_info(dev, nxi))
27262 +                       goto cont;
27263                 if ((idev = in6_dev_get(dev)) == NULL)
27264                         goto cont;
27265                 err = inet6_fill_ifinfo(skb, idev, NETLINK_CB(cb->skb).pid,
27266 diff -NurpP --minimal linux-2.6.29/net/ipv6/af_inet6.c linux-2.6.29-vs2.3.0.36.9-pre3/net/ipv6/af_inet6.c
27267 --- linux-2.6.29/net/ipv6/af_inet6.c    2009-03-24 14:22:46.000000000 +0100
27268 +++ linux-2.6.29-vs2.3.0.36.9-pre3/net/ipv6/af_inet6.c  2009-03-24 14:48:37.000000000 +0100
27269 @@ -41,6 +41,8 @@
27270  #include <linux/netdevice.h>
27271  #include <linux/icmpv6.h>
27272  #include <linux/netfilter_ipv6.h>
27273 +#include <linux/vs_inet.h>
27274 +#include <linux/vs_inet6.h>
27275  
27276  #include <net/ip.h>
27277  #include <net/ipv6.h>
27278 @@ -49,6 +51,7 @@
27279  #include <net/tcp.h>
27280  #include <net/ipip.h>
27281  #include <net/protocol.h>
27282 +#include <net/route.h>
27283  #include <net/inet_common.h>
27284  #include <net/route.h>
27285  #include <net/transp_v6.h>
27286 @@ -146,9 +149,12 @@ lookup_protocol:
27287         }
27288  
27289         err = -EPERM;
27290 +       if ((protocol == IPPROTO_ICMPV6) &&
27291 +               nx_capable(answer->capability, NXC_RAW_ICMP))
27292 +               goto override;
27293         if (answer->capability > 0 && !capable(answer->capability))
27294                 goto out_rcu_unlock;
27295 -
27296 +override:
27297         sock->ops = answer->ops;
27298         answer_prot = answer->prot;
27299         answer_no_check = answer->no_check;
27300 @@ -247,6 +253,7 @@ int inet6_bind(struct socket *sock, stru
27301         struct inet_sock *inet = inet_sk(sk);
27302         struct ipv6_pinfo *np = inet6_sk(sk);
27303         struct net *net = sock_net(sk);
27304 +       struct nx_v6_sock_addr nsa;
27305         __be32 v4addr = 0;
27306         unsigned short snum;
27307         int addr_type = 0;
27308 @@ -258,6 +265,11 @@ int inet6_bind(struct socket *sock, stru
27309  
27310         if (addr_len < SIN6_LEN_RFC2133)
27311                 return -EINVAL;
27312 +
27313 +       err = v6_map_sock_addr(inet, addr, &nsa);
27314 +       if (err)
27315 +               return err;
27316 +
27317         addr_type = ipv6_addr_type(&addr->sin6_addr);
27318         if ((addr_type & IPV6_ADDR_MULTICAST) && sock->type == SOCK_STREAM)
27319                 return -EINVAL;
27320 @@ -281,6 +293,10 @@ int inet6_bind(struct socket *sock, stru
27321                         err = -EADDRNOTAVAIL;
27322                         goto out;
27323                 }
27324 +               if (!v4_addr_in_nx_info(sk->sk_nx_info, v4addr, NXA_MASK_BIND)) {
27325 +                       err = -EADDRNOTAVAIL;
27326 +                       goto out;
27327 +               }
27328         } else {
27329                 if (addr_type != IPV6_ADDR_ANY) {
27330                         struct net_device *dev = NULL;
27331 @@ -306,6 +322,11 @@ int inet6_bind(struct socket *sock, stru
27332                                 }
27333                         }
27334  
27335 +                       if (!v6_addr_in_nx_info(sk->sk_nx_info, &addr->sin6_addr, -1)) {
27336 +                               err = -EADDRNOTAVAIL;
27337 +                               goto out;
27338 +                       }
27339 +
27340                         /* ipv4 addr of the socket is invalid.  Only the
27341                          * unspecified and mapped address have a v4 equivalent.
27342                          */
27343 @@ -324,6 +345,8 @@ int inet6_bind(struct socket *sock, stru
27344                 }
27345         }
27346  
27347 +       v6_set_sock_addr(inet, &nsa);
27348 +
27349         inet->rcv_saddr = v4addr;
27350         inet->saddr = v4addr;
27351  
27352 @@ -416,9 +439,11 @@ int inet6_getname(struct socket *sock, s
27353                         return -ENOTCONN;
27354                 sin->sin6_port = inet->dport;
27355                 ipv6_addr_copy(&sin->sin6_addr, &np->daddr);
27356 +               /* FIXME: remap lback? */
27357                 if (np->sndflow)
27358                         sin->sin6_flowinfo = np->flow_label;
27359         } else {
27360 +               /* FIXME: remap lback? */
27361                 if (ipv6_addr_any(&np->rcv_saddr))
27362                         ipv6_addr_copy(&sin->sin6_addr, &np->saddr);
27363                 else
27364 diff -NurpP --minimal linux-2.6.29/net/ipv6/fib6_rules.c linux-2.6.29-vs2.3.0.36.9-pre3/net/ipv6/fib6_rules.c
27365 --- linux-2.6.29/net/ipv6/fib6_rules.c  2008-12-25 00:26:37.000000000 +0100
27366 +++ linux-2.6.29-vs2.3.0.36.9-pre3/net/ipv6/fib6_rules.c        2009-02-22 22:54:26.000000000 +0100
27367 @@ -96,7 +96,7 @@ static int fib6_rule_action(struct fib_r
27368                         if (ipv6_dev_get_saddr(net,
27369                                                ip6_dst_idev(&rt->u.dst)->dev,
27370                                                &flp->fl6_dst, srcprefs,
27371 -                                              &saddr))
27372 +                                              &saddr, NULL))
27373                                 goto again;
27374                         if (!ipv6_prefix_equal(&saddr, &r->src.addr,
27375                                                r->src.plen))
27376 diff -NurpP --minimal linux-2.6.29/net/ipv6/inet6_hashtables.c linux-2.6.29-vs2.3.0.36.9-pre3/net/ipv6/inet6_hashtables.c
27377 --- linux-2.6.29/net/ipv6/inet6_hashtables.c    2009-03-24 14:22:46.000000000 +0100
27378 +++ linux-2.6.29-vs2.3.0.36.9-pre3/net/ipv6/inet6_hashtables.c  2009-03-24 20:50:24.000000000 +0100
27379 @@ -16,6 +16,7 @@
27380  
27381  #include <linux/module.h>
27382  #include <linux/random.h>
27383 +#include <linux/vs_inet6.h>
27384  
27385  #include <net/inet_connection_sock.h>
27386  #include <net/inet_hashtables.h>
27387 @@ -76,7 +77,6 @@ struct sock *__inet6_lookup_established(
27388         unsigned int slot = hash & (hashinfo->ehash_size - 1);
27389         struct inet_ehash_bucket *head = &hashinfo->ehash[slot];
27390  
27391 -
27392         rcu_read_lock();
27393  begin:
27394         sk_nulls_for_each_rcu(sk, node, &head->chain) {
27395 @@ -88,7 +88,7 @@ begin:
27396                                 sock_put(sk);
27397                                 goto begin;
27398                         }
27399 -               goto out;
27400 +                       goto out;
27401                 }
27402         }
27403         if (get_nulls_value(node) != slot)
27404 @@ -134,6 +134,9 @@ static int inline compute_score(struct s
27405                         if (!ipv6_addr_equal(&np->rcv_saddr, daddr))
27406                                 return -1;
27407                         score++;
27408 +               } else {
27409 +                       if (!v6_addr_in_nx_info(sk->sk_nx_info, daddr, -1))
27410 +                               return -1;
27411                 }
27412                 if (sk->sk_bound_dev_if) {
27413                         if (sk->sk_bound_dev_if != dif)
27414 diff -NurpP --minimal linux-2.6.29/net/ipv6/ip6_output.c linux-2.6.29-vs2.3.0.36.9-pre3/net/ipv6/ip6_output.c
27415 --- linux-2.6.29/net/ipv6/ip6_output.c  2009-03-24 14:22:47.000000000 +0100
27416 +++ linux-2.6.29-vs2.3.0.36.9-pre3/net/ipv6/ip6_output.c        2009-03-24 14:48:37.000000000 +0100
27417 @@ -951,7 +951,7 @@ static int ip6_dst_lookup_tail(struct so
27418                 err = ipv6_dev_get_saddr(net, ip6_dst_idev(*dst)->dev,
27419                                          &fl->fl6_dst,
27420                                          sk ? inet6_sk(sk)->srcprefs : 0,
27421 -                                        &fl->fl6_src);
27422 +                                        &fl->fl6_src, sk->sk_nx_info);
27423                 if (err)
27424                         goto out_err_release;
27425         }
27426 diff -NurpP --minimal linux-2.6.29/net/ipv6/Kconfig linux-2.6.29-vs2.3.0.36.9-pre3/net/ipv6/Kconfig
27427 --- linux-2.6.29/net/ipv6/Kconfig       2008-12-25 00:26:37.000000000 +0100
27428 +++ linux-2.6.29-vs2.3.0.36.9-pre3/net/ipv6/Kconfig     2009-02-22 22:54:26.000000000 +0100
27429 @@ -4,8 +4,8 @@
27430  
27431  #   IPv6 as module will cause a CRASH if you try to unload it
27432  menuconfig IPV6
27433 -       tristate "The IPv6 protocol"
27434 -       default m
27435 +       bool "The IPv6 protocol"
27436 +       default n
27437         ---help---
27438           This is complemental support for the IP version 6.
27439           You will still be able to do traditional IPv4 networking as well.
27440 diff -NurpP --minimal linux-2.6.29/net/ipv6/ndisc.c linux-2.6.29-vs2.3.0.36.9-pre3/net/ipv6/ndisc.c
27441 --- linux-2.6.29/net/ipv6/ndisc.c       2009-03-24 14:22:47.000000000 +0100
27442 +++ linux-2.6.29-vs2.3.0.36.9-pre3/net/ipv6/ndisc.c     2009-03-24 14:48:37.000000000 +0100
27443 @@ -589,7 +589,7 @@ static void ndisc_send_na(struct net_dev
27444         } else {
27445                 if (ipv6_dev_get_saddr(dev_net(dev), dev, daddr,
27446                                        inet6_sk(dev_net(dev)->ipv6.ndisc_sk)->srcprefs,
27447 -                                      &tmpaddr))
27448 +                                      &tmpaddr, NULL /* FIXME: ? */ ))
27449                         return;
27450                 src_addr = &tmpaddr;
27451         }
27452 diff -NurpP --minimal linux-2.6.29/net/ipv6/raw.c linux-2.6.29-vs2.3.0.36.9-pre3/net/ipv6/raw.c
27453 --- linux-2.6.29/net/ipv6/raw.c 2009-03-24 14:22:47.000000000 +0100
27454 +++ linux-2.6.29-vs2.3.0.36.9-pre3/net/ipv6/raw.c       2009-03-24 14:48:37.000000000 +0100
27455 @@ -29,6 +29,7 @@
27456  #include <linux/icmpv6.h>
27457  #include <linux/netfilter.h>
27458  #include <linux/netfilter_ipv6.h>
27459 +#include <linux/vs_inet6.h>
27460  #include <linux/skbuff.h>
27461  #include <asm/uaccess.h>
27462  #include <asm/ioctls.h>
27463 @@ -281,6 +282,13 @@ static int rawv6_bind(struct sock *sk, s
27464                         }
27465                 }
27466  
27467 +               if (!v6_addr_in_nx_info(sk->sk_nx_info, &addr->sin6_addr, -1)) {
27468 +                       err = -EADDRNOTAVAIL;
27469 +                       if (dev)
27470 +                               dev_put(dev);
27471 +                       goto out;
27472 +               }
27473 +
27474                 /* ipv4 addr of the socket is invalid.  Only the
27475                  * unspecified and mapped address have a v4 equivalent.
27476                  */
27477 diff -NurpP --minimal linux-2.6.29/net/ipv6/route.c linux-2.6.29-vs2.3.0.36.9-pre3/net/ipv6/route.c
27478 --- linux-2.6.29/net/ipv6/route.c       2009-03-24 14:22:47.000000000 +0100
27479 +++ linux-2.6.29-vs2.3.0.36.9-pre3/net/ipv6/route.c     2009-03-24 14:48:37.000000000 +0100
27480 @@ -2254,7 +2254,8 @@ static int rt6_fill_node(struct net *net
27481                 struct inet6_dev *idev = ip6_dst_idev(&rt->u.dst);
27482                 struct in6_addr saddr_buf;
27483                 if (ipv6_dev_get_saddr(net, idev ? idev->dev : NULL,
27484 -                                      dst, 0, &saddr_buf) == 0)
27485 +                       dst, 0, &saddr_buf,
27486 +                       (skb->sk ? skb->sk->sk_nx_info : NULL)) == 0)
27487                         NLA_PUT(skb, RTA_PREFSRC, 16, &saddr_buf);
27488         }
27489  
27490 diff -NurpP --minimal linux-2.6.29/net/ipv6/tcp_ipv6.c linux-2.6.29-vs2.3.0.36.9-pre3/net/ipv6/tcp_ipv6.c
27491 --- linux-2.6.29/net/ipv6/tcp_ipv6.c    2009-03-24 14:22:47.000000000 +0100
27492 +++ linux-2.6.29-vs2.3.0.36.9-pre3/net/ipv6/tcp_ipv6.c  2009-03-24 14:48:37.000000000 +0100
27493 @@ -68,6 +68,7 @@
27494  
27495  #include <linux/crypto.h>
27496  #include <linux/scatterlist.h>
27497 +#include <linux/vs_inet6.h>
27498  
27499  static void    tcp_v6_send_reset(struct sock *sk, struct sk_buff *skb);
27500  static void    tcp_v6_reqsk_send_ack(struct sock *sk, struct sk_buff *skb,
27501 @@ -156,8 +157,15 @@ static int tcp_v6_connect(struct sock *s
27502          *      connect() to INADDR_ANY means loopback (BSD'ism).
27503          */
27504  
27505 -       if(ipv6_addr_any(&usin->sin6_addr))
27506 -               usin->sin6_addr.s6_addr[15] = 0x1;
27507 +       if(ipv6_addr_any(&usin->sin6_addr)) {
27508 +               struct nx_info *nxi =  sk->sk_nx_info;
27509 +
27510 +               if (nxi && nx_info_has_v6(nxi))
27511 +                       /* FIXME: remap lback? */
27512 +                       usin->sin6_addr = nxi->v6.ip;
27513 +               else
27514 +                       usin->sin6_addr.s6_addr[15] = 0x1;
27515 +       }
27516  
27517         addr_type = ipv6_addr_type(&usin->sin6_addr);
27518  
27519 diff -NurpP --minimal linux-2.6.29/net/ipv6/udp.c linux-2.6.29-vs2.3.0.36.9-pre3/net/ipv6/udp.c
27520 --- linux-2.6.29/net/ipv6/udp.c 2009-03-24 14:22:47.000000000 +0100
27521 +++ linux-2.6.29-vs2.3.0.36.9-pre3/net/ipv6/udp.c       2009-03-24 20:56:49.000000000 +0100
27522 @@ -47,6 +47,7 @@
27523  
27524  #include <linux/proc_fs.h>
27525  #include <linux/seq_file.h>
27526 +#include <linux/vs_inet6.h>
27527  #include "udp_impl.h"
27528  
27529  int udp_v6_get_port(struct sock *sk, unsigned short snum)
27530 @@ -77,6 +78,10 @@ static inline int compute_score(struct s
27531                         if (!ipv6_addr_equal(&np->rcv_saddr, daddr))
27532                                 return -1;
27533                         score++;
27534 +               } else {
27535 +                       /* block non nx_info ips */
27536 +                       if (!v6_addr_in_nx_info(sk->sk_nx_info, daddr, -1))
27537 +                               return -1;
27538                 }
27539                 if (!ipv6_addr_any(&np->daddr)) {
27540                         if (!ipv6_addr_equal(&np->daddr, saddr))
27541 diff -NurpP --minimal linux-2.6.29/net/ipv6/xfrm6_policy.c linux-2.6.29-vs2.3.0.36.9-pre3/net/ipv6/xfrm6_policy.c
27542 --- linux-2.6.29/net/ipv6/xfrm6_policy.c        2009-03-24 14:22:47.000000000 +0100
27543 +++ linux-2.6.29-vs2.3.0.36.9-pre3/net/ipv6/xfrm6_policy.c      2009-03-24 14:48:37.000000000 +0100
27544 @@ -63,7 +63,7 @@ static int xfrm6_get_saddr(struct net *n
27545         dev = ip6_dst_idev(dst)->dev;
27546         ipv6_dev_get_saddr(dev_net(dev), dev,
27547                            (struct in6_addr *)&daddr->a6, 0,
27548 -                          (struct in6_addr *)&saddr->a6);
27549 +                          (struct in6_addr *)&saddr->a6, NULL);
27550         dst_release(dst);
27551         return 0;
27552  }
27553 diff -NurpP --minimal linux-2.6.29/net/netlink/af_netlink.c linux-2.6.29-vs2.3.0.36.9-pre3/net/netlink/af_netlink.c
27554 --- linux-2.6.29/net/netlink/af_netlink.c       2009-03-24 14:22:47.000000000 +0100
27555 +++ linux-2.6.29-vs2.3.0.36.9-pre3/net/netlink/af_netlink.c     2009-03-24 14:48:37.000000000 +0100
27556 @@ -55,6 +55,9 @@
27557  #include <linux/types.h>
27558  #include <linux/audit.h>
27559  #include <linux/mutex.h>
27560 +#include <linux/vs_context.h>
27561 +#include <linux/vs_network.h>
27562 +#include <linux/vs_limit.h>
27563  
27564  #include <net/net_namespace.h>
27565  #include <net/sock.h>
27566 @@ -1776,6 +1779,8 @@ static struct sock *netlink_seq_socket_i
27567                         sk_for_each(s, node, &hash->table[j]) {
27568                                 if (sock_net(s) != seq_file_net(seq))
27569                                         continue;
27570 +                               if (!nx_check(s->sk_nid, VS_WATCH_P | VS_IDENT))
27571 +                                       continue;
27572                                 if (off == pos) {
27573                                         iter->link = i;
27574                                         iter->hash_idx = j;
27575 @@ -1810,7 +1815,8 @@ static void *netlink_seq_next(struct seq
27576         s = v;
27577         do {
27578                 s = sk_next(s);
27579 -       } while (s && sock_net(s) != seq_file_net(seq));
27580 +       } while (s && (sock_net(s) != seq_file_net(seq) ||
27581 +               !nx_check(s->sk_nid, VS_WATCH_P | VS_IDENT)));
27582         if (s)
27583                 return s;
27584  
27585 @@ -1822,7 +1828,8 @@ static void *netlink_seq_next(struct seq
27586  
27587                 for (; j <= hash->mask; j++) {
27588                         s = sk_head(&hash->table[j]);
27589 -                       while (s && sock_net(s) != seq_file_net(seq))
27590 +                       while (s && (sock_net(s) != seq_file_net(seq) ||
27591 +                               !nx_check(s->sk_nid, VS_WATCH_P | VS_IDENT)))
27592                                 s = sk_next(s);
27593                         if (s) {
27594                                 iter->link = i;
27595 diff -NurpP --minimal linux-2.6.29/net/sctp/ipv6.c linux-2.6.29-vs2.3.0.36.9-pre3/net/sctp/ipv6.c
27596 --- linux-2.6.29/net/sctp/ipv6.c        2009-03-24 14:22:48.000000000 +0100
27597 +++ linux-2.6.29-vs2.3.0.36.9-pre3/net/sctp/ipv6.c      2009-03-24 20:58:14.000000000 +0100
27598 @@ -317,7 +317,8 @@ static void sctp_v6_get_saddr(struct sct
27599                                    dst ? ip6_dst_idev(dst)->dev : NULL,
27600                                    &daddr->v6.sin6_addr,
27601                                    inet6_sk(&sk->inet.sk)->srcprefs,
27602 -                                  &saddr->v6.sin6_addr);
27603 +                                  &saddr->v6.sin6_addr,
27604 +                                  asoc->base.sk->sk_nx_info);
27605                 SCTP_DEBUG_PRINTK("saddr from ipv6_get_saddr: %pI6\n",
27606                                   &saddr->v6.sin6_addr);
27607                 return;
27608 diff -NurpP --minimal linux-2.6.29/net/socket.c linux-2.6.29-vs2.3.0.36.9-pre3/net/socket.c
27609 --- linux-2.6.29/net/socket.c   2009-03-24 14:22:48.000000000 +0100
27610 +++ linux-2.6.29-vs2.3.0.36.9-pre3/net/socket.c 2009-03-24 14:48:37.000000000 +0100
27611 @@ -95,6 +95,10 @@
27612  
27613  #include <net/sock.h>
27614  #include <linux/netfilter.h>
27615 +#include <linux/vs_base.h>
27616 +#include <linux/vs_socket.h>
27617 +#include <linux/vs_inet.h>
27618 +#include <linux/vs_inet6.h>
27619  
27620  static int sock_no_open(struct inode *irrelevant, struct file *dontcare);
27621  static ssize_t sock_aio_read(struct kiocb *iocb, const struct iovec *iov,
27622 @@ -549,7 +553,7 @@ static inline int __sock_sendmsg(struct 
27623                                  struct msghdr *msg, size_t size)
27624  {
27625         struct sock_iocb *si = kiocb_to_siocb(iocb);
27626 -       int err;
27627 +       int err, len;
27628  
27629         si->sock = sock;
27630         si->scm = NULL;
27631 @@ -560,7 +564,22 @@ static inline int __sock_sendmsg(struct 
27632         if (err)
27633                 return err;
27634  
27635 -       return sock->ops->sendmsg(iocb, sock, msg, size);
27636 +       len = sock->ops->sendmsg(iocb, sock, msg, size);
27637 +       if (sock->sk) {
27638 +               if (len == size)
27639 +                       vx_sock_send(sock->sk, size);
27640 +               else
27641 +                       vx_sock_fail(sock->sk, size);
27642 +       }
27643 +       vxdprintk(VXD_CBIT(net, 7),
27644 +               "__sock_sendmsg: %p[%p,%p,%p;%d/%d]:%d/%d",
27645 +               sock, sock->sk,
27646 +               (sock->sk)?sock->sk->sk_nx_info:0,
27647 +               (sock->sk)?sock->sk->sk_vx_info:0,
27648 +               (sock->sk)?sock->sk->sk_xid:0,
27649 +               (sock->sk)?sock->sk->sk_nid:0,
27650 +               (unsigned int)size, len);
27651 +       return len;
27652  }
27653  
27654  int sock_sendmsg(struct socket *sock, struct msghdr *msg, size_t size)
27655 @@ -629,7 +648,7 @@ EXPORT_SYMBOL_GPL(__sock_recv_timestamp)
27656  static inline int __sock_recvmsg(struct kiocb *iocb, struct socket *sock,
27657                                  struct msghdr *msg, size_t size, int flags)
27658  {
27659 -       int err;
27660 +       int err, len;
27661         struct sock_iocb *si = kiocb_to_siocb(iocb);
27662  
27663         si->sock = sock;
27664 @@ -642,7 +661,18 @@ static inline int __sock_recvmsg(struct 
27665         if (err)
27666                 return err;
27667  
27668 -       return sock->ops->recvmsg(iocb, sock, msg, size, flags);
27669 +       len = sock->ops->recvmsg(iocb, sock, msg, size, flags);
27670 +       if ((len >= 0) && sock->sk)
27671 +               vx_sock_recv(sock->sk, len);
27672 +       vxdprintk(VXD_CBIT(net, 7),
27673 +               "__sock_recvmsg: %p[%p,%p,%p;%d/%d]:%d/%d",
27674 +               sock, sock->sk,
27675 +               (sock->sk)?sock->sk->sk_nx_info:0,
27676 +               (sock->sk)?sock->sk->sk_vx_info:0,
27677 +               (sock->sk)?sock->sk->sk_xid:0,
27678 +               (sock->sk)?sock->sk->sk_nid:0,
27679 +               (unsigned int)size, len);
27680 +       return len;
27681  }
27682  
27683  int sock_recvmsg(struct socket *sock, struct msghdr *msg,
27684 @@ -1106,6 +1136,13 @@ static int __sock_create(struct net *net
27685         if (type < 0 || type >= SOCK_MAX)
27686                 return -EINVAL;
27687  
27688 +       if (!nx_check(0, VS_ADMIN)) {
27689 +               if (family == PF_INET && !current_nx_info_has_v4())
27690 +                       return -EAFNOSUPPORT;
27691 +               if (family == PF_INET6 && !current_nx_info_has_v6())
27692 +                       return -EAFNOSUPPORT;
27693 +       }
27694 +
27695         /* Compatibility.
27696  
27697            This uglymoron is moved from INET layer to here to avoid
27698 @@ -1238,6 +1275,7 @@ SYSCALL_DEFINE3(socket, int, family, int
27699         if (retval < 0)
27700                 goto out;
27701  
27702 +       set_bit(SOCK_USER_SOCKET, &sock->flags);
27703         retval = sock_map_fd(sock, flags & (O_CLOEXEC | O_NONBLOCK));
27704         if (retval < 0)
27705                 goto out_release;
27706 @@ -1279,10 +1317,12 @@ SYSCALL_DEFINE4(socketpair, int, family,
27707         err = sock_create(family, type, protocol, &sock1);
27708         if (err < 0)
27709                 goto out;
27710 +       set_bit(SOCK_USER_SOCKET, &sock1->flags);
27711  
27712         err = sock_create(family, type, protocol, &sock2);
27713         if (err < 0)
27714                 goto out_release_1;
27715 +       set_bit(SOCK_USER_SOCKET, &sock2->flags);
27716  
27717         err = sock1->ops->socketpair(sock1, sock2);
27718         if (err < 0)
27719 diff -NurpP --minimal linux-2.6.29/net/sunrpc/auth.c linux-2.6.29-vs2.3.0.36.9-pre3/net/sunrpc/auth.c
27720 --- linux-2.6.29/net/sunrpc/auth.c      2009-03-24 14:22:48.000000000 +0100
27721 +++ linux-2.6.29-vs2.3.0.36.9-pre3/net/sunrpc/auth.c    2009-03-24 21:00:49.000000000 +0100
27722 @@ -14,6 +14,7 @@
27723  #include <linux/hash.h>
27724  #include <linux/sunrpc/clnt.h>
27725  #include <linux/spinlock.h>
27726 +#include <linux/vs_tag.h>
27727  
27728  #ifdef RPC_DEBUG
27729  # define RPCDBG_FACILITY       RPCDBG_AUTH
27730 @@ -360,6 +361,7 @@ rpcauth_lookupcred(struct rpc_auth *auth
27731         memset(&acred, 0, sizeof(acred));
27732         acred.uid = cred->fsuid;
27733         acred.gid = cred->fsgid;
27734 +       acred.tag = dx_current_tag();
27735         acred.group_info = get_group_info(((struct cred *)cred)->group_info);
27736  
27737         ret = auth->au_ops->lookup_cred(auth, &acred, flags);
27738 @@ -400,6 +402,7 @@ rpcauth_bind_root_cred(struct rpc_task *
27739         struct auth_cred acred = {
27740                 .uid = 0,
27741                 .gid = 0,
27742 +               .tag = dx_current_tag(),
27743         };
27744         struct rpc_cred *ret;
27745  
27746 diff -NurpP --minimal linux-2.6.29/net/sunrpc/auth_unix.c linux-2.6.29-vs2.3.0.36.9-pre3/net/sunrpc/auth_unix.c
27747 --- linux-2.6.29/net/sunrpc/auth_unix.c 2008-12-25 00:26:37.000000000 +0100
27748 +++ linux-2.6.29-vs2.3.0.36.9-pre3/net/sunrpc/auth_unix.c       2009-02-22 22:54:26.000000000 +0100
27749 @@ -11,12 +11,14 @@
27750  #include <linux/module.h>
27751  #include <linux/sunrpc/clnt.h>
27752  #include <linux/sunrpc/auth.h>
27753 +#include <linux/vs_tag.h>
27754  
27755  #define NFS_NGROUPS    16
27756  
27757  struct unx_cred {
27758         struct rpc_cred         uc_base;
27759         gid_t                   uc_gid;
27760 +       tag_t                   uc_tag;
27761         gid_t                   uc_gids[NFS_NGROUPS];
27762  };
27763  #define uc_uid                 uc_base.cr_uid
27764 @@ -78,6 +80,7 @@ unx_create_cred(struct rpc_auth *auth, s
27765                 groups = NFS_NGROUPS;
27766  
27767         cred->uc_gid = acred->gid;
27768 +       cred->uc_tag = acred->tag;
27769         for (i = 0; i < groups; i++)
27770                 cred->uc_gids[i] = GROUP_AT(acred->group_info, i);
27771         if (i < NFS_NGROUPS)
27772 @@ -119,7 +122,9 @@ unx_match(struct auth_cred *acred, struc
27773         unsigned int i;
27774  
27775  
27776 -       if (cred->uc_uid != acred->uid || cred->uc_gid != acred->gid)
27777 +       if (cred->uc_uid != acred->uid ||
27778 +               cred->uc_gid != acred->gid ||
27779 +               cred->uc_tag != acred->tag)
27780                 return 0;
27781  
27782         if (acred->group_info != NULL)
27783 @@ -142,7 +147,7 @@ unx_marshal(struct rpc_task *task, __be3
27784         struct rpc_clnt *clnt = task->tk_client;
27785         struct unx_cred *cred = container_of(task->tk_msg.rpc_cred, struct unx_cred, uc_base);
27786         __be32          *base, *hold;
27787 -       int             i;
27788 +       int             i, tag;
27789  
27790         *p++ = htonl(RPC_AUTH_UNIX);
27791         base = p++;
27792 @@ -152,9 +157,12 @@ unx_marshal(struct rpc_task *task, __be3
27793          * Copy the UTS nodename captured when the client was created.
27794          */
27795         p = xdr_encode_array(p, clnt->cl_nodename, clnt->cl_nodelen);
27796 +       tag = task->tk_client->cl_tag;
27797  
27798 -       *p++ = htonl((u32) cred->uc_uid);
27799 -       *p++ = htonl((u32) cred->uc_gid);
27800 +       *p++ = htonl((u32) TAGINO_UID(tag,
27801 +               cred->uc_uid, cred->uc_tag));
27802 +       *p++ = htonl((u32) TAGINO_GID(tag,
27803 +               cred->uc_gid, cred->uc_tag));
27804         hold = p++;
27805         for (i = 0; i < 16 && cred->uc_gids[i] != (gid_t) NOGROUP; i++)
27806                 *p++ = htonl((u32) cred->uc_gids[i]);
27807 diff -NurpP --minimal linux-2.6.29/net/sunrpc/clnt.c linux-2.6.29-vs2.3.0.36.9-pre3/net/sunrpc/clnt.c
27808 --- linux-2.6.29/net/sunrpc/clnt.c      2009-03-24 14:22:48.000000000 +0100
27809 +++ linux-2.6.29-vs2.3.0.36.9-pre3/net/sunrpc/clnt.c    2009-03-24 14:48:37.000000000 +0100
27810 @@ -32,6 +32,7 @@
27811  #include <linux/utsname.h>
27812  #include <linux/workqueue.h>
27813  #include <linux/in6.h>
27814 +#include <linux/vs_cvirt.h>
27815  
27816  #include <linux/sunrpc/clnt.h>
27817  #include <linux/sunrpc/rpc_pipe_fs.h>
27818 @@ -335,6 +336,9 @@ struct rpc_clnt *rpc_create(struct rpc_c
27819         if (!(args->flags & RPC_CLNT_CREATE_QUIET))
27820                 clnt->cl_chatty = 1;
27821  
27822 +       /* TODO: handle RPC_CLNT_CREATE_TAGGED
27823 +       if (args->flags & RPC_CLNT_CREATE_TAGGED)
27824 +               clnt->cl_tag = 1; */
27825         return clnt;
27826  }
27827  EXPORT_SYMBOL_GPL(rpc_create);
27828 diff -NurpP --minimal linux-2.6.29/net/unix/af_unix.c linux-2.6.29-vs2.3.0.36.9-pre3/net/unix/af_unix.c
27829 --- linux-2.6.29/net/unix/af_unix.c     2009-03-24 14:22:48.000000000 +0100
27830 +++ linux-2.6.29-vs2.3.0.36.9-pre3/net/unix/af_unix.c   2009-03-24 14:48:37.000000000 +0100
27831 @@ -114,6 +114,8 @@
27832  #include <linux/mount.h>
27833  #include <net/checksum.h>
27834  #include <linux/security.h>
27835 +#include <linux/vs_context.h>
27836 +#include <linux/vs_limit.h>
27837  
27838  static struct hlist_head unix_socket_table[UNIX_HASH_SIZE + 1];
27839  static DEFINE_SPINLOCK(unix_table_lock);
27840 @@ -258,6 +260,8 @@ static struct sock *__unix_find_socket_b
27841                 if (!net_eq(sock_net(s), net))
27842                         continue;
27843  
27844 +               if (!nx_check(s->sk_nid, VS_WATCH_P | VS_IDENT))
27845 +                       continue;
27846                 if (u->addr->len == len &&
27847                     !memcmp(u->addr->name, sunname, len))
27848                         goto found;
27849 @@ -2110,6 +2114,8 @@ static struct sock *unix_seq_idx(struct 
27850         for (s = first_unix_socket(&iter->i); s; s = next_unix_socket(&iter->i, s)) {
27851                 if (sock_net(s) != seq_file_net(seq))
27852                         continue;
27853 +               if (!nx_check(s->sk_nid, VS_WATCH_P | VS_IDENT))
27854 +                       continue;
27855                 if (off == pos)
27856                         return s;
27857                 ++off;
27858 @@ -2134,7 +2140,8 @@ static void *unix_seq_next(struct seq_fi
27859                 sk = first_unix_socket(&iter->i);
27860         else
27861                 sk = next_unix_socket(&iter->i, sk);
27862 -       while (sk && (sock_net(sk) != seq_file_net(seq)))
27863 +       while (sk && (sock_net(sk) != seq_file_net(seq) ||
27864 +               !nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT)))
27865                 sk = next_unix_socket(&iter->i, sk);
27866         return sk;
27867  }
27868 diff -NurpP --minimal linux-2.6.29/net/x25/af_x25.c linux-2.6.29-vs2.3.0.36.9-pre3/net/x25/af_x25.c
27869 --- linux-2.6.29/net/x25/af_x25.c       2008-12-25 00:26:37.000000000 +0100
27870 +++ linux-2.6.29-vs2.3.0.36.9-pre3/net/x25/af_x25.c     2009-02-22 22:54:26.000000000 +0100
27871 @@ -506,7 +506,10 @@ static int x25_create(struct net *net, s
27872  
27873         x25 = x25_sk(sk);
27874  
27875 -       sock_init_data(sock, sk);
27876 +       sk->sk_socket = sock;
27877 +       sk->sk_type = sock->type;
27878 +       sk->sk_sleep = &sock->wait;
27879 +       sock->sk = sk;
27880  
27881         x25_init_timers(sk);
27882  
27883 diff -NurpP --minimal linux-2.6.29/scripts/checksyscalls.sh linux-2.6.29-vs2.3.0.36.9-pre3/scripts/checksyscalls.sh
27884 --- linux-2.6.29/scripts/checksyscalls.sh       2008-12-25 00:26:37.000000000 +0100
27885 +++ linux-2.6.29-vs2.3.0.36.9-pre3/scripts/checksyscalls.sh     2009-02-22 22:54:26.000000000 +0100
27886 @@ -108,7 +108,6 @@ cat << EOF
27887  #define __IGNORE_afs_syscall
27888  #define __IGNORE_getpmsg
27889  #define __IGNORE_putpmsg
27890 -#define __IGNORE_vserver
27891  EOF
27892  }
27893  
27894 diff -NurpP --minimal linux-2.6.29/security/commoncap.c linux-2.6.29-vs2.3.0.36.9-pre3/security/commoncap.c
27895 --- linux-2.6.29/security/commoncap.c   2009-03-24 14:23:21.000000000 +0100
27896 +++ linux-2.6.29-vs2.3.0.36.9-pre3/security/commoncap.c 2009-03-25 00:34:48.000000000 +0100
27897 @@ -27,10 +27,11 @@
27898  #include <linux/sched.h>
27899  #include <linux/prctl.h>
27900  #include <linux/securebits.h>
27901 +#include <linux/vs_context.h>
27902  
27903  int cap_netlink_send(struct sock *sk, struct sk_buff *skb)
27904  {
27905 -       NETLINK_CB(skb).eff_cap = current_cap();
27906 +       NETLINK_CB(skb).eff_cap = vx_mbcaps(current_cap());
27907         return 0;
27908  }
27909  
27910 @@ -40,6 +41,7 @@ int cap_netlink_recv(struct sk_buff *skb
27911                 return -EPERM;
27912         return 0;
27913  }
27914 +
27915  EXPORT_SYMBOL(cap_netlink_recv);
27916  
27917  /**
27918 @@ -60,7 +62,22 @@ EXPORT_SYMBOL(cap_netlink_recv);
27919  int cap_capable(struct task_struct *tsk, const struct cred *cred, int cap,
27920                 int audit)
27921  {
27922 -       return cap_raised(cred->cap_effective, cap) ? 0 : -EPERM;
27923 +       struct vx_info *vxi = tsk->vx_info;
27924 +
27925 +#if 0
27926 +       printk("cap_capable() VXF_STATE_SETUP = %llx, raised = %x, eff = %08x:%08x\n",
27927 +               vx_info_flags(vxi, VXF_STATE_SETUP, 0),
27928 +               cap_raised(tsk->cap_effective, cap),
27929 +               tsk->cap_effective.cap[1], tsk->cap_effective.cap[0]);
27930 +#endif
27931 +
27932 +       /* special case SETUP */
27933 +       if (vx_info_flags(vxi, VXF_STATE_SETUP, 0) &&
27934 +               /* FIXME: maybe use cred instead? */
27935 +               cap_raised(tsk->cred->cap_effective, cap))
27936 +               return 0;
27937 +
27938 +       return vx_cap_raised(vxi, cred->cap_effective, cap) ? 0 : -EPERM;
27939  }
27940  
27941  /**
27942 @@ -586,7 +603,7 @@ int cap_inode_setxattr(struct dentry *de
27943  
27944         if (!strncmp(name, XATTR_SECURITY_PREFIX,
27945                      sizeof(XATTR_SECURITY_PREFIX) - 1)  &&
27946 -           !capable(CAP_SYS_ADMIN))
27947 +               !vx_capable(CAP_SYS_ADMIN, VXC_FS_SECURITY))
27948                 return -EPERM;
27949         return 0;
27950  }
27951 @@ -931,7 +948,8 @@ error:
27952   */
27953  int cap_syslog(int type)
27954  {
27955 -       if ((type != 3 && type != 10) && !capable(CAP_SYS_ADMIN))
27956 +       if ((type != 3 && type != 10) &&
27957 +               !vx_capable(CAP_SYS_ADMIN, VXC_SYSLOG))
27958                 return -EPERM;
27959         return 0;
27960  }
27961 @@ -953,3 +971,4 @@ int cap_vm_enough_memory(struct mm_struc
27962                 cap_sys_admin = 1;
27963         return __vm_enough_memory(mm, pages, cap_sys_admin);
27964  }
27965 +
27966 diff -NurpP --minimal linux-2.6.29/security/selinux/hooks.c linux-2.6.29-vs2.3.0.36.9-pre3/security/selinux/hooks.c
27967 --- linux-2.6.29/security/selinux/hooks.c       2009-03-24 14:23:21.000000000 +0100
27968 +++ linux-2.6.29-vs2.3.0.36.9-pre3/security/selinux/hooks.c     2009-03-24 14:48:37.000000000 +0100
27969 @@ -64,7 +64,6 @@
27970  #include <linux/dccp.h>
27971  #include <linux/quota.h>
27972  #include <linux/un.h>          /* for Unix socket types */
27973 -#include <net/af_unix.h>       /* for Unix socket types */
27974  #include <linux/parser.h>
27975  #include <linux/nfs_mount.h>
27976  #include <net/ipv6.h>
This page took 2.510058 seconds and 4 git commands to generate.