]> git.pld-linux.org Git - packages/kernel.git/blob - kernel-vserver-2.3.patch
- merged from LINUX_2_6
[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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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_NOCMTIME     128     /* Do not update file c/mtime */
8684  #define S_SWAPFILE     256     /* Do not truncate: swapon got its bmaps */
8685  #define S_PRIVATE      512     /* Inode is fs-internal */
8686 +#define S_IXUNLINK     1024    /* 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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/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-pre2/ipc/sem.c    2009-03-24 14:48:36.000000000 +0100
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 diff -NurpP --minimal linux-2.6.29/ipc/shm.c linux-2.6.29-vs2.3.0.36.9-pre2/ipc/shm.c
14929 --- linux-2.6.29/ipc/shm.c      2009-03-24 14:22:44.000000000 +0100
14930 +++ linux-2.6.29-vs2.3.0.36.9-pre2/ipc/shm.c    2009-03-24 14:48:36.000000000 +0100
14931 @@ -39,6 +39,8 @@
14932  #include <linux/nsproxy.h>
14933  #include <linux/mount.h>
14934  #include <linux/ipc_namespace.h>
14935 +#include <linux/vs_context.h>
14936 +#include <linux/vs_limit.h>
14937  
14938  #include <asm/uaccess.h>
14939  
14940 @@ -168,7 +170,12 @@ static void shm_open(struct vm_area_stru
14941   */
14942  static void shm_destroy(struct ipc_namespace *ns, struct shmid_kernel *shp)
14943  {
14944 -       ns->shm_tot -= (shp->shm_segsz + PAGE_SIZE - 1) >> PAGE_SHIFT;
14945 +       struct vx_info *vxi = lookup_vx_info(shp->shm_perm.xid);
14946 +       int numpages = (shp->shm_segsz + PAGE_SIZE - 1) >> PAGE_SHIFT;
14947 +
14948 +       vx_ipcshm_sub(vxi, shp, numpages);
14949 +       ns->shm_tot -= numpages;
14950 +
14951         shm_rmid(ns, shp);
14952         shm_unlock(shp);
14953         if (!is_file_hugepages(shp->shm_file))
14954 @@ -178,6 +185,7 @@ static void shm_destroy(struct ipc_names
14955                                                 shp->mlock_user);
14956         fput (shp->shm_file);
14957         security_shm_free(shp);
14958 +       put_vx_info(vxi);
14959         ipc_rcu_putref(shp);
14960  }
14961  
14962 @@ -348,11 +356,15 @@ static int newseg(struct ipc_namespace *
14963         if (ns->shm_tot + numpages > ns->shm_ctlall)
14964                 return -ENOSPC;
14965  
14966 +       if (!vx_ipcshm_avail(current->vx_info, numpages))
14967 +               return -ENOSPC;
14968 +
14969         shp = ipc_rcu_alloc(sizeof(*shp));
14970         if (!shp)
14971                 return -ENOMEM;
14972  
14973         shp->shm_perm.key = key;
14974 +       shp->shm_perm.xid = vx_current_xid();
14975         shp->shm_perm.mode = (shmflg & S_IRWXUGO);
14976         shp->mlock_user = NULL;
14977  
14978 @@ -406,6 +418,7 @@ static int newseg(struct ipc_namespace *
14979         ns->shm_tot += numpages;
14980         error = shp->shm_perm.id;
14981         shm_unlock(shp);
14982 +       vx_ipcshm_add(current->vx_info, key, numpages);
14983         return error;
14984  
14985  no_id:
14986 diff -NurpP --minimal linux-2.6.29/kernel/capability.c linux-2.6.29-vs2.3.0.36.9-pre2/kernel/capability.c
14987 --- linux-2.6.29/kernel/capability.c    2009-03-24 14:22:44.000000000 +0100
14988 +++ linux-2.6.29-vs2.3.0.36.9-pre2/kernel/capability.c  2009-03-24 17:27:28.000000000 +0100
14989 @@ -14,6 +14,7 @@
14990  #include <linux/security.h>
14991  #include <linux/syscalls.h>
14992  #include <linux/pid_namespace.h>
14993 +#include <linux/vs_context.h>
14994  #include <asm/uaccess.h>
14995  #include "cred-internals.h"
14996  
14997 @@ -122,6 +123,7 @@ static int cap_validate_magic(cap_user_h
14998         return 0;
14999  }
15000  
15001 +
15002  /*
15003   * The only thing that can change the capabilities of the current
15004   * process is the current process. As such, we can't be in this code
15005 @@ -289,6 +291,8 @@ error:
15006         return ret;
15007  }
15008  
15009 +#include <linux/vserver/base.h>
15010 +
15011  /**
15012   * capable - Determine if the current task has a superior capability in effect
15013   * @cap: The capability to be tested for
15014 @@ -301,6 +305,9 @@ error:
15015   */
15016  int capable(int cap)
15017  {
15018 +       /* here for now so we don't require task locking */
15019 +       if (vs_check_bit(VXC_CAP_MASK, cap) && !vx_mcaps(1L << cap))
15020 +               return 0;
15021         if (unlikely(!cap_valid(cap))) {
15022                 printk(KERN_CRIT "capable() called with invalid cap=%u\n", cap);
15023                 BUG();
15024 diff -NurpP --minimal linux-2.6.29/kernel/compat.c linux-2.6.29-vs2.3.0.36.9-pre2/kernel/compat.c
15025 --- linux-2.6.29/kernel/compat.c        2009-03-24 14:22:44.000000000 +0100
15026 +++ linux-2.6.29-vs2.3.0.36.9-pre2/kernel/compat.c      2009-03-24 14:48:36.000000000 +0100
15027 @@ -891,7 +891,7 @@ asmlinkage long compat_sys_time(compat_t
15028         compat_time_t i;
15029         struct timeval tv;
15030  
15031 -       do_gettimeofday(&tv);
15032 +       vx_gettimeofday(&tv);
15033         i = tv.tv_sec;
15034  
15035         if (tloc) {
15036 @@ -916,7 +916,7 @@ asmlinkage long compat_sys_stime(compat_
15037         if (err)
15038                 return err;
15039  
15040 -       do_settimeofday(&tv);
15041 +       vx_settimeofday(&tv);
15042         return 0;
15043  }
15044  
15045 diff -NurpP --minimal linux-2.6.29/kernel/exit.c linux-2.6.29-vs2.3.0.36.9-pre2/kernel/exit.c
15046 --- linux-2.6.29/kernel/exit.c  2009-03-24 14:22:44.000000000 +0100
15047 +++ linux-2.6.29-vs2.3.0.36.9-pre2/kernel/exit.c        2009-03-24 17:28:40.000000000 +0100
15048 @@ -47,6 +47,11 @@
15049  #include <linux/task_io_accounting_ops.h>
15050  #include <linux/tracehook.h>
15051  #include <linux/init_task.h>
15052 +#include <linux/vs_limit.h>
15053 +#include <linux/vs_context.h>
15054 +#include <linux/vs_network.h>
15055 +#include <linux/vs_pid.h>
15056 +#include <linux/vserver/global.h>
15057  #include <trace/sched.h>
15058  
15059  #include <asm/uaccess.h>
15060 @@ -502,9 +507,11 @@ static void close_files(struct files_str
15061                                         filp_close(file, files);
15062                                         cond_resched();
15063                                 }
15064 +                               vx_openfd_dec(i);
15065                         }
15066                         i++;
15067                         set >>= 1;
15068 +                       cond_resched();
15069                 }
15070         }
15071  }
15072 @@ -571,6 +578,7 @@ void put_fs_struct(struct fs_struct *fs)
15073         if (atomic_dec_and_test(&fs->count)) {
15074                 path_put(&fs->root);
15075                 path_put(&fs->pwd);
15076 +               atomic_dec(&vs_global_fs);
15077                 kmem_cache_free(fs_cachep, fs);
15078         }
15079  }
15080 @@ -1122,10 +1130,15 @@ NORET_TYPE void do_exit(long code)
15081         if (tsk->splice_pipe)
15082                 __free_pipe_info(tsk->splice_pipe);
15083  
15084 +       /* needs to stay after exit_notify() */
15085 +       exit_vx_info(tsk, code);
15086 +       exit_nx_info(tsk);
15087 +
15088         preempt_disable();
15089         /* causes final put_task_struct in finish_task_switch(). */
15090         tsk->state = TASK_DEAD;
15091         schedule();
15092 +       printk("bad task: %p [%lx]\n", current, current->state);
15093         BUG();
15094         /* Avoid "noreturn function does return".  */
15095         for (;;)
15096 diff -NurpP --minimal linux-2.6.29/kernel/fork.c linux-2.6.29-vs2.3.0.36.9-pre2/kernel/fork.c
15097 --- linux-2.6.29/kernel/fork.c  2009-03-24 14:22:44.000000000 +0100
15098 +++ linux-2.6.29-vs2.3.0.36.9-pre2/kernel/fork.c        2009-03-24 17:31:42.000000000 +0100
15099 @@ -60,6 +60,11 @@
15100  #include <linux/tty.h>
15101  #include <linux/proc_fs.h>
15102  #include <linux/blkdev.h>
15103 +#include <linux/vs_context.h>
15104 +#include <linux/vs_network.h>
15105 +#include <linux/vs_limit.h>
15106 +#include <linux/vs_memory.h>
15107 +#include <linux/vserver/global.h>
15108  #include <trace/sched.h>
15109  
15110  #include <asm/pgtable.h>
15111 @@ -140,6 +145,8 @@ void free_task(struct task_struct *tsk)
15112         prop_local_destroy_single(&tsk->dirties);
15113         free_thread_info(tsk->stack);
15114         rt_mutex_debug_task_free(tsk);
15115 +       clr_vx_info(&tsk->vx_info);
15116 +       clr_nx_info(&tsk->nx_info);
15117         ftrace_graph_exit_task(tsk);
15118         free_task_struct(tsk);
15119  }
15120 @@ -279,6 +286,8 @@ static int dup_mmap(struct mm_struct *mm
15121         mm->free_area_cache = oldmm->mmap_base;
15122         mm->cached_hole_size = ~0UL;
15123         mm->map_count = 0;
15124 +       __set_mm_counter(mm, file_rss, 0);
15125 +       __set_mm_counter(mm, anon_rss, 0);
15126         cpus_clear(mm->cpu_vm_mask);
15127         mm->mm_rb = RB_ROOT;
15128         rb_link = &mm->mm_rb.rb_node;
15129 @@ -290,7 +299,7 @@ static int dup_mmap(struct mm_struct *mm
15130  
15131                 if (mpnt->vm_flags & VM_DONTCOPY) {
15132                         long pages = vma_pages(mpnt);
15133 -                       mm->total_vm -= pages;
15134 +                       vx_vmpages_sub(mm, pages);
15135                         vm_stat_account(mm, mpnt->vm_flags, mpnt->vm_file,
15136                                                                 -pages);
15137                         continue;
15138 @@ -423,8 +432,8 @@ static struct mm_struct * mm_init(struct
15139         mm->flags = (current->mm) ? current->mm->flags : default_dump_filter;
15140         mm->core_state = NULL;
15141         mm->nr_ptes = 0;
15142 -       set_mm_counter(mm, file_rss, 0);
15143 -       set_mm_counter(mm, anon_rss, 0);
15144 +       __set_mm_counter(mm, file_rss, 0);
15145 +       __set_mm_counter(mm, anon_rss, 0);
15146         spin_lock_init(&mm->page_table_lock);
15147         spin_lock_init(&mm->ioctx_lock);
15148         INIT_HLIST_HEAD(&mm->ioctx_list);
15149 @@ -435,6 +444,7 @@ static struct mm_struct * mm_init(struct
15150         if (likely(!mm_alloc_pgd(mm))) {
15151                 mm->def_flags = 0;
15152                 mmu_notifier_mm_init(mm);
15153 +               set_vx_info(&mm->mm_vx_info, p->vx_info);
15154                 return mm;
15155         }
15156  
15157 @@ -468,6 +478,7 @@ void __mmdrop(struct mm_struct *mm)
15158         mm_free_pgd(mm);
15159         destroy_context(mm);
15160         mmu_notifier_mm_destroy(mm);
15161 +       clr_vx_info(&mm->mm_vx_info);
15162         free_mm(mm);
15163  }
15164  EXPORT_SYMBOL_GPL(__mmdrop);
15165 @@ -594,6 +605,7 @@ struct mm_struct *dup_mm(struct task_str
15166                 goto fail_nomem;
15167  
15168         memcpy(mm, oldmm, sizeof(*mm));
15169 +       mm->mm_vx_info = NULL;
15170  
15171         /* Initializing for Swap token stuff */
15172         mm->token_priority = 0;
15173 @@ -627,6 +639,7 @@ fail_nocontext:
15174          * If init_new_context() failed, we cannot use mmput() to free the mm
15175          * because it calls destroy_context()
15176          */
15177 +       clr_vx_info(&mm->mm_vx_info);
15178         mm_free_pgd(mm);
15179         free_mm(mm);
15180         return NULL;
15181 @@ -690,6 +703,7 @@ static struct fs_struct *__copy_fs_struc
15182                 fs->pwd = old->pwd;
15183                 path_get(&old->pwd);
15184                 read_unlock(&old->lock);
15185 +               atomic_inc(&vs_global_fs);
15186         }
15187         return fs;
15188  }
15189 @@ -955,6 +969,8 @@ static struct task_struct *copy_process(
15190         int retval;
15191         struct task_struct *p;
15192         int cgroup_callbacks_done = 0;
15193 +       struct vx_info *vxi;
15194 +       struct nx_info *nxi;
15195  
15196         if ((clone_flags & (CLONE_NEWNS|CLONE_FS)) == (CLONE_NEWNS|CLONE_FS))
15197                 return ERR_PTR(-EINVAL);
15198 @@ -989,12 +1005,28 @@ static struct task_struct *copy_process(
15199         DEBUG_LOCKS_WARN_ON(!p->hardirqs_enabled);
15200         DEBUG_LOCKS_WARN_ON(!p->softirqs_enabled);
15201  #endif
15202 +       init_vx_info(&p->vx_info, current->vx_info);
15203 +       init_nx_info(&p->nx_info, current->nx_info);
15204 +
15205 +       /* check vserver memory */
15206 +       if (p->mm && !(clone_flags & CLONE_VM)) {
15207 +               if (vx_vmpages_avail(p->mm, p->mm->total_vm))
15208 +                       vx_pages_add(p->vx_info, RLIMIT_AS, p->mm->total_vm);
15209 +               else
15210 +                       goto bad_fork_free;
15211 +       }
15212 +       if (p->mm && vx_flags(VXF_FORK_RSS, 0)) {
15213 +               if (!vx_rss_avail(p->mm, get_mm_counter(p->mm, file_rss)))
15214 +                       goto bad_fork_cleanup_vm;
15215 +       }
15216         retval = -EAGAIN;
15217 +       if (!vx_nproc_avail(1))
15218 +               goto bad_fork_cleanup_vm;
15219         if (atomic_read(&p->real_cred->user->processes) >=
15220                         p->signal->rlim[RLIMIT_NPROC].rlim_cur) {
15221                 if (!capable(CAP_SYS_ADMIN) && !capable(CAP_SYS_RESOURCE) &&
15222                     p->real_cred->user != INIT_USER)
15223 -                       goto bad_fork_free;
15224 +                       goto bad_fork_cleanup_vm;
15225         }
15226  
15227         retval = copy_creds(p, clone_flags);
15228 @@ -1271,6 +1303,18 @@ static struct task_struct *copy_process(
15229  
15230         total_forks++;
15231         spin_unlock(&current->sighand->siglock);
15232 +
15233 +       /* p is copy of current */
15234 +       vxi = p->vx_info;
15235 +       if (vxi) {
15236 +               claim_vx_info(vxi, p);
15237 +               atomic_inc(&vxi->cvirt.nr_threads);
15238 +               atomic_inc(&vxi->cvirt.total_forks);
15239 +               vx_nproc_inc(p);
15240 +       }
15241 +       nxi = p->nx_info;
15242 +       if (nxi)
15243 +               claim_nx_info(nxi, p);
15244         write_unlock_irq(&tasklist_lock);
15245         proc_fork_connector(p);
15246         cgroup_post_fork(p);
15247 @@ -1315,6 +1359,9 @@ bad_fork_cleanup_count:
15248         atomic_dec(&p->cred->user->processes);
15249         put_cred(p->real_cred);
15250         put_cred(p->cred);
15251 +bad_fork_cleanup_vm:
15252 +       if (p->mm && !(clone_flags & CLONE_VM))
15253 +               vx_pages_sub(p->vx_info, RLIMIT_AS, p->mm->total_vm);
15254  bad_fork_free:
15255         free_task(p);
15256  fork_out:
15257 diff -NurpP --minimal linux-2.6.29/kernel/kthread.c linux-2.6.29-vs2.3.0.36.9-pre2/kernel/kthread.c
15258 --- linux-2.6.29/kernel/kthread.c       2009-03-24 14:22:44.000000000 +0100
15259 +++ linux-2.6.29-vs2.3.0.36.9-pre2/kernel/kthread.c     2009-03-24 14:48:36.000000000 +0100
15260 @@ -13,6 +13,7 @@
15261  #include <linux/file.h>
15262  #include <linux/module.h>
15263  #include <linux/mutex.h>
15264 +#include <linux/vs_pid.h>
15265  #include <trace/sched.h>
15266  
15267  #define KTHREAD_NICE_LEVEL (-5)
15268 @@ -102,7 +103,7 @@ static void create_kthread(struct kthrea
15269                 struct sched_param param = { .sched_priority = 0 };
15270                 wait_for_completion(&create->started);
15271                 read_lock(&tasklist_lock);
15272 -               create->result = find_task_by_pid_ns(pid, &init_pid_ns);
15273 +               create->result = find_task_by_real_pid(pid);
15274                 read_unlock(&tasklist_lock);
15275                 /*
15276                  * root may have changed our (kthreadd's) priority or CPU mask.
15277 diff -NurpP --minimal linux-2.6.29/kernel/Makefile linux-2.6.29-vs2.3.0.36.9-pre2/kernel/Makefile
15278 --- linux-2.6.29/kernel/Makefile        2009-03-24 14:22:44.000000000 +0100
15279 +++ linux-2.6.29-vs2.3.0.36.9-pre2/kernel/Makefile      2009-03-24 14:48:36.000000000 +0100
15280 @@ -22,6 +22,7 @@ CFLAGS_REMOVE_cgroup-debug.o = -pg
15281  CFLAGS_REMOVE_sched_clock.o = -pg
15282  endif
15283  
15284 +obj-y += vserver/
15285  obj-$(CONFIG_FREEZER) += freezer.o
15286  obj-$(CONFIG_PROFILING) += profile.o
15287  obj-$(CONFIG_SYSCTL_SYSCALL_CHECK) += sysctl_check.o
15288 diff -NurpP --minimal linux-2.6.29/kernel/nsproxy.c linux-2.6.29-vs2.3.0.36.9-pre2/kernel/nsproxy.c
15289 --- linux-2.6.29/kernel/nsproxy.c       2009-03-24 14:22:44.000000000 +0100
15290 +++ linux-2.6.29-vs2.3.0.36.9-pre2/kernel/nsproxy.c     2009-03-25 00:39:02.000000000 +0100
15291 @@ -19,6 +19,8 @@
15292  #include <linux/mnt_namespace.h>
15293  #include <linux/utsname.h>
15294  #include <linux/pid_namespace.h>
15295 +#include <linux/vserver/global.h>
15296 +#include <linux/vserver/debug.h>
15297  #include <net/net_namespace.h>
15298  #include <linux/ipc_namespace.h>
15299  
15300 @@ -37,6 +39,9 @@ static inline struct nsproxy *clone_nspr
15301         if (ns) {
15302                 memcpy(ns, orig, sizeof(struct nsproxy));
15303                 atomic_set(&ns->count, 1);
15304 +               vxdprintk(VXD_CBIT(space, 2), "clone_nsproxy(%p[%u] = %p[1]",
15305 +                       orig, atomic_read(&orig->count), ns);
15306 +               atomic_inc(&vs_global_nsproxy);
15307         }
15308         return ns;
15309  }
15310 @@ -46,41 +51,52 @@ static inline struct nsproxy *clone_nspr
15311   * Return the newly created nsproxy.  Do not attach this to the task,
15312   * leave it to the caller to do proper locking and attach it to task.
15313   */
15314 -static struct nsproxy *create_new_namespaces(unsigned long flags,
15315 -                       struct task_struct *tsk, struct fs_struct *new_fs)
15316 +static struct nsproxy *unshare_namespaces(unsigned long flags,
15317 +                       struct nsproxy *orig, struct fs_struct *new_fs)
15318  {
15319         struct nsproxy *new_nsp;
15320         int err;
15321  
15322 -       new_nsp = clone_nsproxy(tsk->nsproxy);
15323 +       vxdprintk(VXD_CBIT(space, 4),
15324 +               "unshare_namespaces(0x%08lx,%p,%p)",
15325 +               flags, orig, new_fs);
15326 +
15327 +       new_nsp = clone_nsproxy(orig);
15328         if (!new_nsp)
15329                 return ERR_PTR(-ENOMEM);
15330  
15331 -       new_nsp->mnt_ns = copy_mnt_ns(flags, tsk->nsproxy->mnt_ns, new_fs);
15332 +       new_nsp->mnt_ns = copy_mnt_ns(flags, orig->mnt_ns, new_fs);
15333         if (IS_ERR(new_nsp->mnt_ns)) {
15334                 err = PTR_ERR(new_nsp->mnt_ns);
15335                 goto out_ns;
15336         }
15337  
15338 -       new_nsp->uts_ns = copy_utsname(flags, tsk->nsproxy->uts_ns);
15339 +       new_nsp->uts_ns = copy_utsname(flags, orig->uts_ns);
15340         if (IS_ERR(new_nsp->uts_ns)) {
15341                 err = PTR_ERR(new_nsp->uts_ns);
15342                 goto out_uts;
15343         }
15344  
15345 -       new_nsp->ipc_ns = copy_ipcs(flags, tsk->nsproxy->ipc_ns);
15346 +       new_nsp->ipc_ns = copy_ipcs(flags, orig->ipc_ns);
15347         if (IS_ERR(new_nsp->ipc_ns)) {
15348                 err = PTR_ERR(new_nsp->ipc_ns);
15349                 goto out_ipc;
15350         }
15351  
15352 -       new_nsp->pid_ns = copy_pid_ns(flags, task_active_pid_ns(tsk));
15353 +       new_nsp->pid_ns = copy_pid_ns(flags, orig->pid_ns);
15354         if (IS_ERR(new_nsp->pid_ns)) {
15355                 err = PTR_ERR(new_nsp->pid_ns);
15356                 goto out_pid;
15357         }
15358  
15359 -       new_nsp->net_ns = copy_net_ns(flags, tsk->nsproxy->net_ns);
15360 +       /* disabled now?
15361 +       new_nsp->user_ns = copy_user_ns(flags, orig->user_ns);
15362 +       if (IS_ERR(new_nsp->user_ns)) {
15363 +               err = PTR_ERR(new_nsp->user_ns);
15364 +               goto out_user;
15365 +       } */
15366 +
15367 +       new_nsp->net_ns = copy_net_ns(flags, orig->net_ns);
15368         if (IS_ERR(new_nsp->net_ns)) {
15369                 err = PTR_ERR(new_nsp->net_ns);
15370                 goto out_net;
15371 @@ -105,6 +121,35 @@ out_ns:
15372         return ERR_PTR(err);
15373  }
15374  
15375 +static struct nsproxy *create_new_namespaces(int flags, struct task_struct *tsk,
15376 +                       struct fs_struct *new_fs)
15377 +{
15378 +       return unshare_namespaces(flags, tsk->nsproxy, new_fs);
15379 +}
15380 +
15381 +/*
15382 + * copies the nsproxy, setting refcount to 1, and grabbing a
15383 + * reference to all contained namespaces.
15384 + */
15385 +struct nsproxy *copy_nsproxy(struct nsproxy *orig)
15386 +{
15387 +       struct nsproxy *ns = clone_nsproxy(orig);
15388 +
15389 +       if (ns) {
15390 +               if (ns->mnt_ns)
15391 +                       get_mnt_ns(ns->mnt_ns);
15392 +               if (ns->uts_ns)
15393 +                       get_uts_ns(ns->uts_ns);
15394 +               if (ns->ipc_ns)
15395 +                       get_ipc_ns(ns->ipc_ns);
15396 +               if (ns->pid_ns)
15397 +                       get_pid_ns(ns->pid_ns);
15398 +               if (ns->net_ns)
15399 +                       get_net(ns->net_ns);
15400 +       }
15401 +       return ns;
15402 +}
15403 +
15404  /*
15405   * called from clone.  This now handles copy for nsproxy and all
15406   * namespaces therein.
15407 @@ -112,9 +157,12 @@ out_ns:
15408  int copy_namespaces(unsigned long flags, struct task_struct *tsk)
15409  {
15410         struct nsproxy *old_ns = tsk->nsproxy;
15411 -       struct nsproxy *new_ns;
15412 +       struct nsproxy *new_ns = NULL;
15413         int err = 0;
15414  
15415 +       vxdprintk(VXD_CBIT(space, 7), "copy_namespaces(0x%08lx,%p[%p])",
15416 +               flags, tsk, old_ns);
15417 +
15418         if (!old_ns)
15419                 return 0;
15420  
15421 @@ -151,6 +199,9 @@ int copy_namespaces(unsigned long flags,
15422  
15423  out:
15424         put_nsproxy(old_ns);
15425 +       vxdprintk(VXD_CBIT(space, 3),
15426 +               "copy_namespaces(0x%08lx,%p[%p]) = %d [%p]",
15427 +               flags, tsk, old_ns, err, new_ns);
15428         return err;
15429  }
15430  
15431 @@ -164,7 +215,9 @@ void free_nsproxy(struct nsproxy *ns)
15432                 put_ipc_ns(ns->ipc_ns);
15433         if (ns->pid_ns)
15434                 put_pid_ns(ns->pid_ns);
15435 -       put_net(ns->net_ns);
15436 +       if (ns->net_ns)
15437 +               put_net(ns->net_ns);
15438 +       atomic_dec(&vs_global_nsproxy);
15439         kmem_cache_free(nsproxy_cachep, ns);
15440  }
15441  
15442 @@ -177,6 +230,10 @@ int unshare_nsproxy_namespaces(unsigned 
15443  {
15444         int err = 0;
15445  
15446 +       vxdprintk(VXD_CBIT(space, 4),
15447 +               "unshare_nsproxy_namespaces(0x%08lx,[%p])",
15448 +               unshare_flags, current->nsproxy);
15449 +
15450         if (!(unshare_flags & (CLONE_NEWNS | CLONE_NEWUTS | CLONE_NEWIPC |
15451                                CLONE_NEWNET)))
15452                 return 0;
15453 diff -NurpP --minimal linux-2.6.29/kernel/pid.c linux-2.6.29-vs2.3.0.36.9-pre2/kernel/pid.c
15454 --- linux-2.6.29/kernel/pid.c   2009-03-24 14:22:44.000000000 +0100
15455 +++ linux-2.6.29-vs2.3.0.36.9-pre2/kernel/pid.c 2009-03-24 14:48:36.000000000 +0100
15456 @@ -36,6 +36,8 @@
15457  #include <linux/pid_namespace.h>
15458  #include <linux/init_task.h>
15459  #include <linux/syscalls.h>
15460 +#include <linux/vs_pid.h>
15461 +#include <linux/vserver/global.h>
15462  
15463  #define pid_hashfn(nr, ns)     \
15464         hash_long((unsigned long)nr + (unsigned long)ns, pidhash_shift)
15465 @@ -305,7 +307,7 @@ EXPORT_SYMBOL_GPL(find_pid_ns);
15466  
15467  struct pid *find_vpid(int nr)
15468  {
15469 -       return find_pid_ns(nr, current->nsproxy->pid_ns);
15470 +       return find_pid_ns(vx_rmap_pid(nr), current->nsproxy->pid_ns);
15471  }
15472  EXPORT_SYMBOL_GPL(find_vpid);
15473  
15474 @@ -365,6 +367,9 @@ void transfer_pid(struct task_struct *ol
15475  struct task_struct *pid_task(struct pid *pid, enum pid_type type)
15476  {
15477         struct task_struct *result = NULL;
15478 +
15479 +       if (type == PIDTYPE_REALPID)
15480 +               type = PIDTYPE_PID;
15481         if (pid) {
15482                 struct hlist_node *first;
15483                 first = rcu_dereference(pid->tasks[type].first);
15484 @@ -388,14 +393,14 @@ EXPORT_SYMBOL(find_task_by_pid_type_ns);
15485  
15486  struct task_struct *find_task_by_vpid(pid_t vnr)
15487  {
15488 -       return find_task_by_pid_type_ns(PIDTYPE_PID, vnr,
15489 +       return find_task_by_pid_type_ns(PIDTYPE_PID, vx_rmap_pid(vnr),
15490                         current->nsproxy->pid_ns);
15491  }
15492  EXPORT_SYMBOL(find_task_by_vpid);
15493  
15494  struct task_struct *find_task_by_pid_ns(pid_t nr, struct pid_namespace *ns)
15495  {
15496 -       return find_task_by_pid_type_ns(PIDTYPE_PID, nr, ns);
15497 +       return find_task_by_pid_type_ns(PIDTYPE_PID, vx_rmap_pid(nr), ns);
15498  }
15499  EXPORT_SYMBOL(find_task_by_pid_ns);
15500  
15501 @@ -431,7 +436,7 @@ struct pid *find_get_pid(pid_t nr)
15502  }
15503  EXPORT_SYMBOL_GPL(find_get_pid);
15504  
15505 -pid_t pid_nr_ns(struct pid *pid, struct pid_namespace *ns)
15506 +pid_t pid_unmapped_nr_ns(struct pid *pid, struct pid_namespace *ns)
15507  {
15508         struct upid *upid;
15509         pid_t nr = 0;
15510 @@ -444,6 +449,11 @@ pid_t pid_nr_ns(struct pid *pid, struct 
15511         return nr;
15512  }
15513  
15514 +pid_t pid_nr_ns(struct pid *pid, struct pid_namespace *ns)
15515 +{
15516 +       return vx_map_pid(pid_unmapped_nr_ns(pid, ns));
15517 +}
15518 +
15519  pid_t pid_vnr(struct pid *pid)
15520  {
15521         return pid_nr_ns(pid, current->nsproxy->pid_ns);
15522 diff -NurpP --minimal linux-2.6.29/kernel/pid_namespace.c linux-2.6.29-vs2.3.0.36.9-pre2/kernel/pid_namespace.c
15523 --- linux-2.6.29/kernel/pid_namespace.c 2008-12-25 00:26:37.000000000 +0100
15524 +++ linux-2.6.29-vs2.3.0.36.9-pre2/kernel/pid_namespace.c       2009-02-22 22:54:26.000000000 +0100
15525 @@ -13,6 +13,7 @@
15526  #include <linux/syscalls.h>
15527  #include <linux/err.h>
15528  #include <linux/acct.h>
15529 +#include <linux/vserver/global.h>
15530  
15531  #define BITS_PER_PAGE          (PAGE_SIZE*8)
15532  
15533 @@ -85,6 +86,7 @@ static struct pid_namespace *create_pid_
15534                 goto out_free_map;
15535  
15536         kref_init(&ns->kref);
15537 +       atomic_inc(&vs_global_pid_ns);
15538         ns->level = level;
15539  
15540         set_bit(0, ns->pidmap[0].page);
15541 @@ -109,6 +111,7 @@ static void destroy_pid_namespace(struct
15542  
15543         for (i = 0; i < PIDMAP_ENTRIES; i++)
15544                 kfree(ns->pidmap[i].page);
15545 +       atomic_dec(&vs_global_pid_ns);
15546         kmem_cache_free(pid_ns_cachep, ns);
15547  }
15548  
15549 diff -NurpP --minimal linux-2.6.29/kernel/posix-timers.c linux-2.6.29-vs2.3.0.36.9-pre2/kernel/posix-timers.c
15550 --- linux-2.6.29/kernel/posix-timers.c  2009-03-24 14:22:44.000000000 +0100
15551 +++ linux-2.6.29-vs2.3.0.36.9-pre2/kernel/posix-timers.c        2009-03-24 17:36:18.000000000 +0100
15552 @@ -46,6 +46,7 @@
15553  #include <linux/wait.h>
15554  #include <linux/workqueue.h>
15555  #include <linux/module.h>
15556 +#include <linux/vs_context.h>
15557  
15558  /*
15559   * Management arrays for POSIX timers.  Timers are kept in slab memory
15560 @@ -321,6 +322,12 @@ int posix_timer_event(struct k_itimer *t
15561  {
15562         struct task_struct *task;
15563         int shared, ret = -1;
15564 +       struct vx_info_save vxis;
15565 +       struct vx_info *vxi;
15566 +
15567 +       /* FIXME: move that down where we have the task */
15568 +       vxi = task_get_vx_info(timr->it_process);
15569 +       enter_vx_info(vxi, &vxis);
15570         /*
15571          * FIXME: if ->sigq is queued we can race with
15572          * dequeue_signal()->do_schedule_next_timer().
15573 @@ -341,6 +348,9 @@ int posix_timer_event(struct k_itimer *t
15574                 ret = send_sigqueue(timr->sigq, task, shared);
15575         }
15576         rcu_read_unlock();
15577 +
15578 +       leave_vx_info(&vxis);
15579 +       put_vx_info(vxi);
15580         /* If we failed to send the signal the timer stops. */
15581         return ret > 0;
15582  }
15583 diff -NurpP --minimal linux-2.6.29/kernel/printk.c linux-2.6.29-vs2.3.0.36.9-pre2/kernel/printk.c
15584 --- linux-2.6.29/kernel/printk.c        2009-03-24 14:22:44.000000000 +0100
15585 +++ linux-2.6.29-vs2.3.0.36.9-pre2/kernel/printk.c      2009-03-24 14:48:36.000000000 +0100
15586 @@ -32,6 +32,7 @@
15587  #include <linux/security.h>
15588  #include <linux/bootmem.h>
15589  #include <linux/syscalls.h>
15590 +#include <linux/vs_cvirt.h>
15591  
15592  #include <asm/uaccess.h>
15593  
15594 @@ -251,18 +252,13 @@ int do_syslog(int type, char __user *buf
15595         unsigned i, j, limit, count;
15596         int do_clear = 0;
15597         char c;
15598 -       int error = 0;
15599 +       int error;
15600  
15601         error = security_syslog(type);
15602         if (error)
15603                 return error;
15604  
15605 -       switch (type) {
15606 -       case 0:         /* Close log */
15607 -               break;
15608 -       case 1:         /* Open log */
15609 -               break;
15610 -       case 2:         /* Read from log */
15611 +       if ((type >= 2) && (type <= 4)) {
15612                 error = -EINVAL;
15613                 if (!buf || len < 0)
15614                         goto out;
15615 @@ -273,6 +269,16 @@ int do_syslog(int type, char __user *buf
15616                         error = -EFAULT;
15617                         goto out;
15618                 }
15619 +       }
15620 +       if (!vx_check(0, VS_ADMIN|VS_WATCH))
15621 +               return vx_do_syslog(type, buf, len);
15622 +
15623 +       switch (type) {
15624 +       case 0:         /* Close log */
15625 +               break;
15626 +       case 1:         /* Open log */
15627 +               break;
15628 +       case 2:         /* Read from log */
15629                 error = wait_event_interruptible(log_wait,
15630                                                         (log_start - log_end));
15631                 if (error)
15632 @@ -297,16 +303,6 @@ int do_syslog(int type, char __user *buf
15633                 do_clear = 1;
15634                 /* FALL THRU */
15635         case 3:         /* Read last kernel messages */
15636 -               error = -EINVAL;
15637 -               if (!buf || len < 0)
15638 -                       goto out;
15639 -               error = 0;
15640 -               if (!len)
15641 -                       goto out;
15642 -               if (!access_ok(VERIFY_WRITE, buf, len)) {
15643 -                       error = -EFAULT;
15644 -                       goto out;
15645 -               }
15646                 count = len;
15647                 if (count > log_buf_len)
15648                         count = log_buf_len;
15649 diff -NurpP --minimal linux-2.6.29/kernel/ptrace.c linux-2.6.29-vs2.3.0.36.9-pre2/kernel/ptrace.c
15650 --- linux-2.6.29/kernel/ptrace.c        2009-03-24 14:22:44.000000000 +0100
15651 +++ linux-2.6.29-vs2.3.0.36.9-pre2/kernel/ptrace.c      2009-03-24 14:48:36.000000000 +0100
15652 @@ -21,6 +21,7 @@
15653  #include <linux/audit.h>
15654  #include <linux/pid_namespace.h>
15655  #include <linux/syscalls.h>
15656 +#include <linux/vs_context.h>
15657  
15658  #include <asm/pgtable.h>
15659  #include <asm/uaccess.h>
15660 @@ -159,6 +160,11 @@ int __ptrace_may_access(struct task_stru
15661                 dumpable = get_dumpable(task->mm);
15662         if (!dumpable && !capable(CAP_SYS_PTRACE))
15663                 return -EPERM;
15664 +       if (!vx_check(task->xid, VS_ADMIN_P|VS_IDENT))
15665 +               return -EPERM;
15666 +       if (!vx_check(task->xid, VS_IDENT) &&
15667 +               !task_vx_flags(task, VXF_STATE_ADMIN, 0))
15668 +               return -EACCES;
15669  
15670         return security_ptrace_may_access(task, mode);
15671  }
15672 @@ -596,6 +602,10 @@ SYSCALL_DEFINE4(ptrace, long, request, l
15673                 goto out;
15674         }
15675  
15676 +       ret = -EPERM;
15677 +       if (!vx_check(vx_task_xid(child), VS_WATCH_P | VS_IDENT))
15678 +               goto out_put_task_struct;
15679 +
15680         if (request == PTRACE_ATTACH) {
15681                 ret = ptrace_attach(child);
15682                 /*
15683 diff -NurpP --minimal linux-2.6.29/kernel/sched.c linux-2.6.29-vs2.3.0.36.9-pre2/kernel/sched.c
15684 --- linux-2.6.29/kernel/sched.c 2009-03-24 14:22:44.000000000 +0100
15685 +++ linux-2.6.29-vs2.3.0.36.9-pre2/kernel/sched.c       2009-03-24 21:52:21.000000000 +0100
15686 @@ -72,6 +72,8 @@
15687  #include <linux/debugfs.h>
15688  #include <linux/ctype.h>
15689  #include <linux/ftrace.h>
15690 +#include <linux/vs_sched.h>
15691 +#include <linux/vs_cvirt.h>
15692  #include <trace/sched.h>
15693  
15694  #include <asm/tlb.h>
15695 @@ -610,6 +612,16 @@ struct rq {
15696  #endif
15697         struct hrtimer hrtick_timer;
15698  #endif
15699 +       unsigned long norm_time;
15700 +       unsigned long idle_time;
15701 +#ifdef CONFIG_VSERVER_IDLETIME
15702 +       int idle_skip;
15703 +#endif
15704 +#ifdef CONFIG_VSERVER_HARDCPU
15705 +       struct list_head hold_queue;
15706 +       unsigned long nr_onhold;
15707 +       int idle_tokens;
15708 +#endif
15709  
15710  #ifdef CONFIG_SCHEDSTATS
15711         /* latency stats */
15712 @@ -1705,6 +1717,7 @@ static void update_avg(u64 *avg, u64 sam
15713  
15714  static void enqueue_task(struct rq *rq, struct task_struct *p, int wakeup)
15715  {
15716 +       // BUG_ON(p->state & TASK_ONHOLD);
15717         sched_info_queued(p);
15718         p->sched_class->enqueue_task(rq, p, wakeup);
15719         p->se.on_rq = 1;
15720 @@ -1828,6 +1841,8 @@ static inline void check_class_changed(s
15721                 p->sched_class->prio_changed(rq, p, oldprio, running);
15722  }
15723  
15724 +#include "sched_mon.h"
15725 +
15726  #ifdef CONFIG_SMP
15727  
15728  /* Used instead of source_load when we know the type == 0 */
15729 @@ -1915,6 +1930,7 @@ migrate_task(struct task_struct *p, int 
15730  {
15731         struct rq *rq = task_rq(p);
15732  
15733 +       vxm_migrate_task(p, rq, dest_cpu);
15734         /*
15735          * If the task is not on a runqueue (and not running), then
15736          * it is sufficient to simply update the task's cpu field.
15737 @@ -2242,6 +2258,8 @@ static int sched_balance_self(int cpu, i
15738  
15739  #endif /* CONFIG_SMP */
15740  
15741 +#include "sched_hard.h"
15742 +
15743  /***
15744   * try_to_wake_up - wake up a thread
15745   * @p: the to-be-woken-up thread
15746 @@ -2286,6 +2304,13 @@ static int try_to_wake_up(struct task_st
15747         rq = task_rq_lock(p, &flags);
15748         update_rq_clock(rq);
15749         old_state = p->state;
15750 +
15751 +       /* we need to unhold suspended tasks */
15752 +       if (old_state & TASK_ONHOLD) {
15753 +               vx_unhold_task(p, rq);
15754 +               old_state = p->state;
15755 +       }
15756 +
15757         if (!(old_state & state))
15758                 goto out;
15759  
15760 @@ -2307,6 +2332,12 @@ static int try_to_wake_up(struct task_st
15761                 /* might preempt at this point */
15762                 rq = task_rq_lock(p, &flags);
15763                 old_state = p->state;
15764 +
15765 +       /* we need to unhold suspended tasks
15766 +       if (old_state & TASK_ONHOLD) {
15767 +               vx_unhold_task(p, rq);
15768 +               old_state = p->state;
15769 +       } */
15770                 if (!(old_state & state))
15771                         goto out;
15772                 if (p->se.on_rq)
15773 @@ -4169,16 +4200,19 @@ void account_user_time(struct task_struc
15774                        cputime_t cputime_scaled)
15775  {
15776         struct cpu_usage_stat *cpustat = &kstat_this_cpu.cpustat;
15777 +       struct vx_info *vxi = p->vx_info;  /* p is _always_ current */
15778         cputime64_t tmp;
15779 +       int nice = (TASK_NICE(p) > 0);
15780  
15781         /* Add user time to process. */
15782         p->utime = cputime_add(p->utime, cputime);
15783         p->utimescaled = cputime_add(p->utimescaled, cputime_scaled);
15784 +       vx_account_user(vxi, cputime, nice);
15785         account_group_user_time(p, cputime);
15786  
15787         /* Add user time to cpustat. */
15788         tmp = cputime_to_cputime64(cputime);
15789 -       if (TASK_NICE(p) > 0)
15790 +       if (nice)
15791                 cpustat->nice = cputime64_add(cpustat->nice, tmp);
15792         else
15793                 cpustat->user = cputime64_add(cpustat->user, tmp);
15794 @@ -4222,6 +4256,7 @@ void account_system_time(struct task_str
15795                          cputime_t cputime, cputime_t cputime_scaled)
15796  {
15797         struct cpu_usage_stat *cpustat = &kstat_this_cpu.cpustat;
15798 +       struct vx_info *vxi = p->vx_info;  /* p is _always_ current */
15799         cputime64_t tmp;
15800  
15801         if ((p->flags & PF_VCPU) && (irq_count() - hardirq_offset == 0)) {
15802 @@ -4232,6 +4267,7 @@ void account_system_time(struct task_str
15803         /* Add system time to process. */
15804         p->stime = cputime_add(p->stime, cputime);
15805         p->stimescaled = cputime_add(p->stimescaled, cputime_scaled);
15806 +       vx_account_system(vxi, cputime, 0 /* do we have idle time? */);
15807         account_group_system_time(p, cputime);
15808  
15809         /* Add system time to cpustat. */
15810 @@ -4587,6 +4623,11 @@ need_resched_nonpreemptible:
15811                 idle_balance(cpu, rq);
15812  
15813         prev->sched_class->put_prev_task(rq, prev);
15814 +
15815 +       vx_set_rq_time(rq, jiffies);    /* update time */
15816 +       vx_schedule(prev, rq, cpu);     /* hold if over limit */
15817 +       vx_try_unhold(rq, cpu);         /* unhold if refilled */
15818 +
15819         next = pick_next_task(rq, prev);
15820  
15821         if (likely(prev != next)) {
15822 @@ -5152,7 +5193,7 @@ SYSCALL_DEFINE1(nice, int, increment)
15823                 nice = 19;
15824  
15825         if (increment < 0 && !can_nice(current, nice))
15826 -               return -EPERM;
15827 +               return vx_flags(VXF_IGNEG_NICE, 0) ? 0 : -EPERM;
15828  
15829         retval = security_task_setnice(current, nice);
15830         if (retval)
15831 @@ -8428,7 +8469,10 @@ void __init sched_init(void)
15832  
15833  #endif
15834  #endif /* CONFIG_FAIR_GROUP_SCHED */
15835 -
15836 +#ifdef CONFIG_VSERVER_HARDCPU
15837 +               INIT_LIST_HEAD(&rq->hold_queue);
15838 +               rq->nr_onhold = 0;
15839 +#endif
15840                 rq->rt.rt_runtime = def_rt_bandwidth.rt_runtime;
15841  #ifdef CONFIG_RT_GROUP_SCHED
15842                 INIT_LIST_HEAD(&rq->leaf_rt_rq_list);
15843 diff -NurpP --minimal linux-2.6.29/kernel/sched_fair.c linux-2.6.29-vs2.3.0.36.9-pre2/kernel/sched_fair.c
15844 --- linux-2.6.29/kernel/sched_fair.c    2009-03-24 14:22:45.000000000 +0100
15845 +++ linux-2.6.29-vs2.3.0.36.9-pre2/kernel/sched_fair.c  2009-03-24 14:48:36.000000000 +0100
15846 @@ -717,6 +717,9 @@ enqueue_entity(struct cfs_rq *cfs_rq, st
15847         check_spread(cfs_rq, se);
15848         if (se != cfs_rq->curr)
15849                 __enqueue_entity(cfs_rq, se);
15850 +
15851 +       if (entity_is_task(se))
15852 +               vx_activate_task(task_of(se));
15853  }
15854  
15855  static void __clear_buddies(struct cfs_rq *cfs_rq, struct sched_entity *se)
15856 @@ -760,6 +763,8 @@ dequeue_entity(struct cfs_rq *cfs_rq, st
15857  
15858         if (se != cfs_rq->curr)
15859                 __dequeue_entity(cfs_rq, se);
15860 +       if (entity_is_task(se))
15861 +               vx_deactivate_task(task_of(se));
15862         account_entity_dequeue(cfs_rq, se);
15863         update_min_vruntime(cfs_rq);
15864  }
15865 diff -NurpP --minimal linux-2.6.29/kernel/sched_hard.h linux-2.6.29-vs2.3.0.36.9-pre2/kernel/sched_hard.h
15866 --- linux-2.6.29/kernel/sched_hard.h    1970-01-01 01:00:00.000000000 +0100
15867 +++ linux-2.6.29-vs2.3.0.36.9-pre2/kernel/sched_hard.h  2009-02-22 22:54:26.000000000 +0100
15868 @@ -0,0 +1,353 @@
15869 +
15870 +#ifdef CONFIG_VSERVER_IDLELIMIT
15871 +
15872 +/*
15873 + * vx_idle_resched - reschedule after maxidle
15874 + */
15875 +static inline
15876 +void vx_idle_resched(struct rq *rq)
15877 +{
15878 +       /* maybe have a better criterion for paused */
15879 +       if (!--rq->idle_tokens && !list_empty(&rq->hold_queue))
15880 +               set_need_resched();
15881 +}
15882 +
15883 +#else /* !CONFIG_VSERVER_IDLELIMIT */
15884 +
15885 +#define vx_idle_resched(rq)
15886 +
15887 +#endif /* CONFIG_VSERVER_IDLELIMIT */
15888 +
15889 +
15890 +
15891 +#ifdef CONFIG_VSERVER_IDLETIME
15892 +
15893 +#define vx_set_rq_min_skip(rq, min)            \
15894 +       (rq)->idle_skip = (min)
15895 +
15896 +#define vx_save_min_skip(ret, min, val)                \
15897 +       __vx_save_min_skip(ret, min, val)
15898 +
15899 +static inline
15900 +void __vx_save_min_skip(int ret, int *min, int val)
15901 +{
15902 +       if (ret > -2)
15903 +               return;
15904 +       if ((*min > val) || !*min)
15905 +               *min = val;
15906 +}
15907 +
15908 +static inline
15909 +int vx_try_skip(struct rq *rq, int cpu)
15910 +{
15911 +       /* artificially advance time */
15912 +       if (rq->idle_skip > 0) {
15913 +               vxdprintk(list_empty(&rq->hold_queue),
15914 +                       "hold queue empty on cpu %d", cpu);
15915 +               rq->idle_time += rq->idle_skip;
15916 +               vxm_idle_skip(rq, cpu);
15917 +               return 1;
15918 +       }
15919 +       return 0;
15920 +}
15921 +
15922 +#else /* !CONFIG_VSERVER_IDLETIME */
15923 +
15924 +#define vx_set_rq_min_skip(rq, min)            \
15925 +       ({ int dummy = (min); dummy; })
15926 +
15927 +#define vx_save_min_skip(ret, min, val)
15928 +
15929 +static inline
15930 +int vx_try_skip(struct rq *rq, int cpu)
15931 +{
15932 +       return 0;
15933 +}
15934 +
15935 +#endif /* CONFIG_VSERVER_IDLETIME */
15936 +
15937 +
15938 +
15939 +#ifdef CONFIG_VSERVER_HARDCPU
15940 +
15941 +#define vx_set_rq_max_idle(rq, max)            \
15942 +       (rq)->idle_tokens = (max)
15943 +
15944 +#define vx_save_max_idle(ret, min, val)                \
15945 +       __vx_save_max_idle(ret, min, val)
15946 +
15947 +static inline
15948 +void __vx_save_max_idle(int ret, int *min, int val)
15949 +{
15950 +       if (*min > val)
15951 +               *min = val;
15952 +}
15953 +
15954 +
15955 +/*
15956 + * vx_hold_task - put a task on the hold queue
15957 + */
15958 +static inline
15959 +void vx_hold_task(struct task_struct *p, struct rq *rq)
15960 +{
15961 +       // printk("@ hold_task(%p[%lx])\n", p, p->state);
15962 +
15963 +       /* ignore dead/killed tasks */
15964 +       if (unlikely(p->state & (TASK_DEAD | TASK_WAKEKILL)))
15965 +               return;
15966 +
15967 +       /* ignore sleeping tasks */
15968 +       if (unlikely(p->state & TASK_NORMAL))
15969 +               return;
15970 +
15971 +       /* remove task from runqueue */
15972 +       if (likely(p->se.on_rq))
15973 +               dequeue_task(rq, p, 0);
15974 +       else
15975 +               printk("@ woops, task %p not on runqueue?\n", p);
15976 +
15977 +       p->state |= TASK_ONHOLD;
15978 +       /* a new one on hold */
15979 +       rq->nr_onhold++;
15980 +       vxm_hold_task(p, rq);
15981 +       list_add_tail(&p->hq, &rq->hold_queue);
15982 +       // list_add_tail(&p->run_list, &rq->hold_queue);
15983 +}
15984 +
15985 +/*
15986 + * vx_unhold_task - put a task back to the runqueue
15987 + */
15988 +static inline
15989 +void vx_unhold_task(struct task_struct *p, struct rq *rq)
15990 +{
15991 +       // printk("@ unhold_task(%p[%lx])\n", p, p->state);
15992 +       list_del_init(&p->hq);
15993 +       // list_del(&p->run_list);
15994 +       /* one less waiting */
15995 +       rq->nr_onhold--;
15996 +       p->state &= ~TASK_ONHOLD;
15997 +       enqueue_task(rq, p, 0);
15998 +       // ? inc_nr_running(p, rq);
15999 +       vxm_unhold_task(p, rq);
16000 +}
16001 +
16002 +/*
16003 + * vx_remove_hold - remove a task from the hold queue
16004 + */
16005 +static inline
16006 +void vx_remove_hold(struct task_struct *p, struct rq *rq)
16007 +{
16008 +       printk("@ remove_hold(%p[%lx])\n", p, p->state);
16009 +       list_del_init(&p->hq);
16010 +       // list_del(&p->run_list);
16011 +       /* one less waiting */
16012 +       rq->nr_onhold--;
16013 +       p->state &= ~TASK_ONHOLD;
16014 +}
16015 +
16016 +unsigned long nr_onhold(void)
16017 +{
16018 +       unsigned long i, sum = 0;
16019 +
16020 +       for_each_online_cpu(i)
16021 +               sum += cpu_rq(i)->nr_onhold;
16022 +
16023 +       return sum;
16024 +}
16025 +
16026 +
16027 +
16028 +static inline
16029 +int __vx_tokens_avail(struct _vx_sched_pc *sched_pc)
16030 +{
16031 +       return sched_pc->tokens;
16032 +}
16033 +
16034 +static inline
16035 +void __vx_consume_token(struct _vx_sched_pc *sched_pc)
16036 +{
16037 +       sched_pc->tokens--;
16038 +}
16039 +
16040 +static inline
16041 +int vx_need_resched(struct task_struct *p, int slice, int cpu)
16042 +{
16043 +       struct vx_info *vxi = p->vx_info;
16044 +
16045 +       if (vx_info_flags(vxi, VXF_SCHED_HARD|VXF_SCHED_PRIO, 0)) {
16046 +               struct _vx_sched_pc *sched_pc =
16047 +                       &vx_per_cpu(vxi, sched_pc, cpu);
16048 +               int tokens;
16049 +
16050 +               /* maybe we can simplify that to decrement
16051 +                  the token counter unconditional? */
16052 +
16053 +               if ((tokens = __vx_tokens_avail(sched_pc)) > 0)
16054 +                       __vx_consume_token(sched_pc);
16055 +
16056 +               /* for tokens > 0, one token was consumed */
16057 +               if (tokens < 2)
16058 +                       slice = 0;
16059 +       }
16060 +       vxm_need_resched(p, slice, cpu);
16061 +       return (slice == 0);
16062 +}
16063 +
16064 +
16065 +#define vx_set_rq_time(rq, time) do {  \
16066 +       rq->norm_time = time;           \
16067 +} while (0)
16068 +
16069 +
16070 +static inline
16071 +void vx_try_unhold(struct rq *rq, int cpu)
16072 +{
16073 +       struct vx_info *vxi = NULL;
16074 +       struct list_head *l, *n;
16075 +       int maxidle = HZ;
16076 +       int minskip = 0;
16077 +
16078 +       /* nothing to do? what about pause? */
16079 +       if (list_empty(&rq->hold_queue))
16080 +               return;
16081 +
16082 +       list_for_each_safe(l, n, &rq->hold_queue) {
16083 +               int ret, delta_min[2];
16084 +               struct _vx_sched_pc *sched_pc;
16085 +               struct task_struct *p;
16086 +
16087 +               p = list_entry(l, struct task_struct, hq);
16088 +               /* don't bother with same context */
16089 +               if (vxi == p->vx_info)
16090 +                       continue;
16091 +
16092 +               vxi = p->vx_info;
16093 +               /* ignore paused contexts */
16094 +               if (vx_info_flags(vxi, VXF_SCHED_PAUSE, 0))
16095 +                       continue;
16096 +
16097 +               sched_pc = &vx_per_cpu(vxi, sched_pc, cpu);
16098 +
16099 +               /* recalc tokens */
16100 +               vxm_sched_info(sched_pc, vxi, cpu);
16101 +               ret = vx_tokens_recalc(sched_pc,
16102 +                       &rq->norm_time, &rq->idle_time, delta_min);
16103 +               vxm_tokens_recalc(sched_pc, rq, vxi, cpu);
16104 +
16105 +               if (ret > 0) {
16106 +                       /* we found a runable context */
16107 +                       vx_unhold_task(p, rq);
16108 +                       break;
16109 +               }
16110 +               vx_save_max_idle(ret, &maxidle, delta_min[0]);
16111 +               vx_save_min_skip(ret, &minskip, delta_min[1]);
16112 +       }
16113 +       vx_set_rq_max_idle(rq, maxidle);
16114 +       vx_set_rq_min_skip(rq, minskip);
16115 +       vxm_rq_max_min(rq, cpu);
16116 +}
16117 +
16118 +
16119 +static inline
16120 +int vx_schedule(struct task_struct *next, struct rq *rq, int cpu)
16121 +{
16122 +       struct vx_info *vxi = next->vx_info;
16123 +       struct _vx_sched_pc *sched_pc;
16124 +       int delta_min[2];
16125 +       int flags, ret;
16126 +
16127 +       if (!vxi)
16128 +               return 1;
16129 +
16130 +       flags = vxi->vx_flags;
16131 +
16132 +       if (unlikely(vs_check_flags(flags, VXF_SCHED_PAUSE, 0)))
16133 +               goto put_on_hold;
16134 +       if (!vs_check_flags(flags, VXF_SCHED_HARD | VXF_SCHED_PRIO, 0))
16135 +               return 1;
16136 +
16137 +       sched_pc = &vx_per_cpu(vxi, sched_pc, cpu);
16138 +#ifdef CONFIG_SMP
16139 +       /* update scheduler params */
16140 +       if (cpu_isset(cpu, vxi->sched.update)) {
16141 +               vx_update_sched_param(&vxi->sched, sched_pc);
16142 +               vxm_update_sched(sched_pc, vxi, cpu);
16143 +               cpu_clear(cpu, vxi->sched.update);
16144 +       }
16145 +#endif
16146 +       vxm_sched_info(sched_pc, vxi, cpu);
16147 +       ret  = vx_tokens_recalc(sched_pc,
16148 +               &rq->norm_time, &rq->idle_time, delta_min);
16149 +       vxm_tokens_recalc(sched_pc, rq, vxi, cpu);
16150 +
16151 +       if (!vs_check_flags(flags, VXF_SCHED_HARD, 0))
16152 +               return 1;
16153 +
16154 +       if (unlikely(ret < 0)) {
16155 +               vx_save_max_idle(ret, &rq->idle_tokens, delta_min[0]);
16156 +               vx_save_min_skip(ret, &rq->idle_skip, delta_min[1]);
16157 +               vxm_rq_max_min(rq, cpu);
16158 +       put_on_hold:
16159 +               vx_hold_task(next, rq);
16160 +               return 0;
16161 +       }
16162 +       return 1;
16163 +}
16164 +
16165 +
16166 +#else /* CONFIG_VSERVER_HARDCPU */
16167 +
16168 +static inline
16169 +void vx_hold_task(struct task_struct *p, struct rq *rq)
16170 +{
16171 +       return;
16172 +}
16173 +
16174 +static inline
16175 +void vx_unhold_task(struct task_struct *p, struct rq *rq)
16176 +{
16177 +       return;
16178 +}
16179 +
16180 +unsigned long nr_onhold(void)
16181 +{
16182 +       return 0;
16183 +}
16184 +
16185 +
16186 +static inline
16187 +int vx_need_resched(struct task_struct *p, int slice, int cpu)
16188 +{
16189 +       return (slice == 0);
16190 +}
16191 +
16192 +
16193 +#define vx_set_rq_time(rq, time)
16194 +
16195 +static inline
16196 +void vx_try_unhold(struct rq *rq, int cpu)
16197 +{
16198 +       return;
16199 +}
16200 +
16201 +static inline
16202 +int vx_schedule(struct task_struct *next, struct rq *rq, int cpu)
16203 +{
16204 +       struct vx_info *vxi = next->vx_info;
16205 +       struct _vx_sched_pc *sched_pc;
16206 +       int delta_min[2];
16207 +       int ret;
16208 +
16209 +       if (!vx_info_flags(vxi, VXF_SCHED_PRIO, 0))
16210 +               return 1;
16211 +
16212 +       sched_pc = &vx_per_cpu(vxi, sched_pc, cpu);
16213 +       vxm_sched_info(sched_pc, vxi, cpu);
16214 +       ret  = vx_tokens_recalc(sched_pc,
16215 +               &rq->norm_time, &rq->idle_time, delta_min);
16216 +       vxm_tokens_recalc(sched_pc, rq, vxi, cpu);
16217 +       return 1;
16218 +}
16219 +
16220 +#endif /* CONFIG_VSERVER_HARDCPU */
16221 +
16222 diff -NurpP --minimal linux-2.6.29/kernel/sched_mon.h linux-2.6.29-vs2.3.0.36.9-pre2/kernel/sched_mon.h
16223 --- linux-2.6.29/kernel/sched_mon.h     1970-01-01 01:00:00.000000000 +0100
16224 +++ linux-2.6.29-vs2.3.0.36.9-pre2/kernel/sched_mon.h   2009-02-22 22:54:26.000000000 +0100
16225 @@ -0,0 +1,200 @@
16226 +
16227 +#include <linux/vserver/monitor.h>
16228 +
16229 +#ifdef  CONFIG_VSERVER_MONITOR
16230 +
16231 +#ifdef CONFIG_VSERVER_HARDCPU
16232 +#define HARDCPU(x) (x)
16233 +#else
16234 +#define HARDCPU(x) (0)
16235 +#endif
16236 +
16237 +#ifdef CONFIG_VSERVER_IDLETIME
16238 +#define IDLETIME(x) (x)
16239 +#else
16240 +#define IDLETIME(x) (0)
16241 +#endif
16242 +
16243 +struct _vx_mon_entry *vxm_advance(int cpu);
16244 +
16245 +
16246 +static inline
16247 +void   __vxm_basic(struct _vx_mon_entry *entry, xid_t xid, int type)
16248 +{
16249 +       entry->type = type;
16250 +       entry->xid = xid;
16251 +}
16252 +
16253 +static inline
16254 +void   __vxm_sync(int cpu)
16255 +{
16256 +       struct _vx_mon_entry *entry = vxm_advance(cpu);
16257 +
16258 +       __vxm_basic(entry, 0, VXM_SYNC);
16259 +       entry->ev.sec = xtime.tv_sec;
16260 +       entry->ev.nsec = xtime.tv_nsec;
16261 +}
16262 +
16263 +static inline
16264 +void   __vxm_task(struct task_struct *p, int type)
16265 +{
16266 +       struct _vx_mon_entry *entry = vxm_advance(task_cpu(p));
16267 +
16268 +       __vxm_basic(entry, p->xid, type);
16269 +       entry->ev.tsk.pid = p->pid;
16270 +       entry->ev.tsk.state = p->state;
16271 +}
16272 +
16273 +static inline
16274 +void   __vxm_sched(struct _vx_sched_pc *s, struct vx_info *vxi, int cpu)
16275 +{
16276 +       struct _vx_mon_entry *entry = vxm_advance(cpu);
16277 +
16278 +       __vxm_basic(entry, vxi->vx_id, (VXM_SCHED | s->flags));
16279 +       entry->sd.tokens = s->tokens;
16280 +       entry->sd.norm_time = s->norm_time;
16281 +       entry->sd.idle_time = s->idle_time;
16282 +}
16283 +
16284 +static inline
16285 +void   __vxm_rqinfo1(struct rq *q, int cpu)
16286 +{
16287 +       struct _vx_mon_entry *entry = vxm_advance(cpu);
16288 +
16289 +       entry->type = VXM_RQINFO_1;
16290 +       entry->xid = ((unsigned long)q >> 16) & 0xffff;
16291 +       entry->q1.running = q->nr_running;
16292 +       entry->q1.onhold = HARDCPU(q->nr_onhold);
16293 +       entry->q1.iowait = atomic_read(&q->nr_iowait);
16294 +       entry->q1.uintr = q->nr_uninterruptible;
16295 +       entry->q1.idle_tokens = IDLETIME(q->idle_tokens);
16296 +}
16297 +
16298 +static inline
16299 +void   __vxm_rqinfo2(struct rq *q, int cpu)
16300 +{
16301 +       struct _vx_mon_entry *entry = vxm_advance(cpu);
16302 +
16303 +       entry->type = VXM_RQINFO_2;
16304 +       entry->xid = (unsigned long)q & 0xffff;
16305 +       entry->q2.norm_time = q->norm_time;
16306 +       entry->q2.idle_time = q->idle_time;
16307 +       entry->q2.idle_skip = IDLETIME(q->idle_skip);
16308 +}
16309 +
16310 +static inline
16311 +void   __vxm_update(struct _vx_sched_pc *s, struct vx_info *vxi, int cpu)
16312 +{
16313 +       struct _vx_mon_entry *entry = vxm_advance(cpu);
16314 +
16315 +       __vxm_basic(entry, vxi->vx_id, VXM_UPDATE);
16316 +       entry->ev.tokens = s->tokens;
16317 +}
16318 +
16319 +static inline
16320 +void   __vxm_update1(struct _vx_sched_pc *s, struct vx_info *vxi, int cpu)
16321 +{
16322 +       struct _vx_mon_entry *entry = vxm_advance(cpu);
16323 +
16324 +       __vxm_basic(entry, vxi->vx_id, VXM_UPDATE_1);
16325 +       entry->u1.tokens_max = s->tokens_max;
16326 +       entry->u1.fill_rate = s->fill_rate[0];
16327 +       entry->u1.interval = s->interval[0];
16328 +}
16329 +
16330 +static inline
16331 +void   __vxm_update2(struct _vx_sched_pc *s, struct vx_info *vxi, int cpu)
16332 +{
16333 +       struct _vx_mon_entry *entry = vxm_advance(cpu);
16334 +
16335 +       __vxm_basic(entry, vxi->vx_id, VXM_UPDATE_2);
16336 +       entry->u2.tokens_min = s->tokens_min;
16337 +       entry->u2.fill_rate = s->fill_rate[1];
16338 +       entry->u2.interval = s->interval[1];
16339 +}
16340 +
16341 +
16342 +#define        vxm_activate_task(p,q)          __vxm_task(p, VXM_ACTIVATE)
16343 +#define        vxm_activate_idle(p,q)          __vxm_task(p, VXM_IDLE)
16344 +#define        vxm_deactivate_task(p,q)        __vxm_task(p, VXM_DEACTIVATE)
16345 +#define        vxm_hold_task(p,q)              __vxm_task(p, VXM_HOLD)
16346 +#define        vxm_unhold_task(p,q)            __vxm_task(p, VXM_UNHOLD)
16347 +
16348 +static inline
16349 +void   vxm_migrate_task(struct task_struct *p, struct rq *rq, int dest)
16350 +{
16351 +       __vxm_task(p, VXM_MIGRATE);
16352 +       __vxm_rqinfo1(rq, task_cpu(p));
16353 +       __vxm_rqinfo2(rq, task_cpu(p));
16354 +}
16355 +
16356 +static inline
16357 +void   vxm_idle_skip(struct rq *rq, int cpu)
16358 +{
16359 +       __vxm_rqinfo1(rq, cpu);
16360 +       __vxm_rqinfo2(rq, cpu);
16361 +}
16362 +
16363 +static inline
16364 +void   vxm_need_resched(struct task_struct *p, int slice, int cpu)
16365 +{
16366 +       if (slice)
16367 +               return;
16368 +
16369 +       __vxm_task(p, VXM_RESCHED);
16370 +}
16371 +
16372 +static inline
16373 +void   vxm_sync(unsigned long now, int cpu)
16374 +{
16375 +       if (!CONFIG_VSERVER_MONITOR_SYNC ||
16376 +               (now % CONFIG_VSERVER_MONITOR_SYNC))
16377 +               return;
16378 +
16379 +       __vxm_sync(cpu);
16380 +}
16381 +
16382 +#define        vxm_sched_info(s,v,c)           __vxm_sched(s,v,c)
16383 +
16384 +static inline
16385 +void   vxm_tokens_recalc(struct _vx_sched_pc *s, struct rq *rq,
16386 +       struct vx_info *vxi, int cpu)
16387 +{
16388 +       __vxm_sched(s, vxi, cpu);
16389 +       __vxm_rqinfo2(rq, cpu);
16390 +}
16391 +
16392 +static inline
16393 +void   vxm_update_sched(struct _vx_sched_pc *s, struct vx_info *vxi, int cpu)
16394 +{
16395 +       __vxm_sched(s, vxi, cpu);
16396 +       __vxm_update(s, vxi, cpu);
16397 +       __vxm_update1(s, vxi, cpu);
16398 +       __vxm_update2(s, vxi, cpu);
16399 +}
16400 +
16401 +static inline
16402 +void   vxm_rq_max_min(struct rq *rq, int cpu)
16403 +{
16404 +       __vxm_rqinfo1(rq, cpu);
16405 +       __vxm_rqinfo2(rq, cpu);
16406 +}
16407 +
16408 +#else  /* CONFIG_VSERVER_MONITOR */
16409 +
16410 +#define        vxm_activate_task(t,q)          do { } while (0)
16411 +#define        vxm_activate_idle(t,q)          do { } while (0)
16412 +#define        vxm_deactivate_task(t,q)        do { } while (0)
16413 +#define        vxm_hold_task(t,q)              do { } while (0)
16414 +#define        vxm_unhold_task(t,q)            do { } while (0)
16415 +#define        vxm_migrate_task(t,q,d)         do { } while (0)
16416 +#define        vxm_idle_skip(q,c)              do { } while (0)
16417 +#define        vxm_need_resched(t,s,c)         do { } while (0)
16418 +#define        vxm_sync(s,c)                   do { } while (0)
16419 +#define        vxm_sched_info(s,v,c)           do { } while (0)
16420 +#define        vxm_tokens_recalc(s,q,v,c)      do { } while (0)
16421 +#define        vxm_update_sched(s,v,c)         do { } while (0)
16422 +#define        vxm_rq_max_min(q,c)             do { } while (0)
16423 +
16424 +#endif /* CONFIG_VSERVER_MONITOR */
16425 +
16426 diff -NurpP --minimal linux-2.6.29/kernel/signal.c linux-2.6.29-vs2.3.0.36.9-pre2/kernel/signal.c
16427 --- linux-2.6.29/kernel/signal.c        2009-03-24 14:22:45.000000000 +0100
16428 +++ linux-2.6.29-vs2.3.0.36.9-pre2/kernel/signal.c      2009-03-24 14:48:36.000000000 +0100
16429 @@ -27,6 +27,8 @@
16430  #include <linux/freezer.h>
16431  #include <linux/pid_namespace.h>
16432  #include <linux/nsproxy.h>
16433 +#include <linux/vs_context.h>
16434 +#include <linux/vs_pid.h>
16435  #include <trace/sched.h>
16436  
16437  #include <asm/param.h>
16438 @@ -584,6 +586,14 @@ static int check_kill_permission(int sig
16439         if (!valid_signal(sig))
16440                 return -EINVAL;
16441  
16442 +       if ((info != SEND_SIG_NOINFO) &&
16443 +               (is_si_special(info) || !SI_FROMUSER(info)))
16444 +               goto skip;
16445 +
16446 +       vxdprintk(VXD_CBIT(misc, 7),
16447 +               "check_kill_permission(%d,%p,%p[#%u,%u])",
16448 +               sig, info, t, vx_task_xid(t), t->pid);
16449 +
16450         if (info != SEND_SIG_NOINFO && (is_si_special(info) || SI_FROMKERNEL(info)))
16451                 return 0;
16452  
16453 @@ -611,6 +621,18 @@ static int check_kill_permission(int sig
16454                 }
16455         }
16456  
16457 +       error = -EPERM;
16458 +       if (t->pid == 1 && current->xid)
16459 +               return error;
16460 +
16461 +       error = -ESRCH;
16462 +       if (!vx_check(vx_task_xid(t), VS_WATCH_P | VS_IDENT)) {
16463 +               vxdprintk(current->xid || VXD_CBIT(misc, 7),
16464 +                       "signal %d[%p] xid mismatch %p[#%u,%u] xid=#%u",
16465 +                       sig, info, t, vx_task_xid(t), t->pid, current->xid);
16466 +               return error;
16467 +       }
16468 +skip:
16469         return security_task_kill(t, info, sig, 0);
16470  }
16471  
16472 @@ -1076,7 +1098,7 @@ int kill_pid_info(int sig, struct siginf
16473         rcu_read_lock();
16474  retry:
16475         p = pid_task(pid, PIDTYPE_PID);
16476 -       if (p) {
16477 +       if (p && vx_check(vx_task_xid(p), VS_ADMIN | VS_IDENT)) {
16478                 error = group_send_sig_info(sig, info, p);
16479                 if (unlikely(error == -ESRCH))
16480                         /*
16481 @@ -1115,7 +1137,7 @@ int kill_pid_info_as_uid(int sig, struct
16482  
16483         read_lock(&tasklist_lock);
16484         p = pid_task(pid, PIDTYPE_PID);
16485 -       if (!p) {
16486 +       if (!p || !vx_check(vx_task_xid(p), VS_IDENT)) {
16487                 ret = -ESRCH;
16488                 goto out_unlock;
16489         }
16490 @@ -1169,8 +1191,10 @@ static int kill_something_info(int sig, 
16491                 struct task_struct * p;
16492  
16493                 for_each_process(p) {
16494 -                       if (task_pid_vnr(p) > 1 &&
16495 -                                       !same_thread_group(p, current)) {
16496 +                       if (vx_check(vx_task_xid(p), VS_ADMIN|VS_IDENT) &&
16497 +                               task_pid_vnr(p) > 1 &&
16498 +                               !same_thread_group(p, current) &&
16499 +                               !vx_current_initpid(p->pid)) {
16500                                 int err = group_send_sig_info(sig, info, p);
16501                                 ++count;
16502                                 if (err != -EPERM)
16503 @@ -1849,6 +1873,11 @@ relock:
16504                     !signal_group_exit(signal))
16505                         continue;
16506  
16507 +               /* virtual init is protected against user signals */
16508 +               if ((info->si_code == SI_USER) &&
16509 +                       vx_current_initpid(current->pid))
16510 +                       continue;
16511 +
16512                 if (sig_kernel_stop(signr)) {
16513                         /*
16514                          * The default action is to stop all threads in
16515 diff -NurpP --minimal linux-2.6.29/kernel/softirq.c linux-2.6.29-vs2.3.0.36.9-pre2/kernel/softirq.c
16516 --- linux-2.6.29/kernel/softirq.c       2009-03-24 14:22:45.000000000 +0100
16517 +++ linux-2.6.29-vs2.3.0.36.9-pre2/kernel/softirq.c     2009-03-24 14:48:36.000000000 +0100
16518 @@ -23,6 +23,7 @@
16519  #include <linux/rcupdate.h>
16520  #include <linux/smp.h>
16521  #include <linux/tick.h>
16522 +#include <linux/vs_context.h>
16523  
16524  #include <asm/irq.h>
16525  /*
16526 diff -NurpP --minimal linux-2.6.29/kernel/sys.c linux-2.6.29-vs2.3.0.36.9-pre2/kernel/sys.c
16527 --- linux-2.6.29/kernel/sys.c   2009-03-24 14:22:45.000000000 +0100
16528 +++ linux-2.6.29-vs2.3.0.36.9-pre2/kernel/sys.c 2009-03-24 14:48:36.000000000 +0100
16529 @@ -39,6 +39,7 @@
16530  #include <linux/syscalls.h>
16531  #include <linux/kprobes.h>
16532  #include <linux/user_namespace.h>
16533 +#include <linux/vs_pid.h>
16534  
16535  #include <asm/uaccess.h>
16536  #include <asm/io.h>
16537 @@ -128,7 +129,10 @@ static int set_one_prio(struct task_stru
16538                 goto out;
16539         }
16540         if (niceval < task_nice(p) && !can_nice(p, niceval)) {
16541 -               error = -EACCES;
16542 +               if (vx_flags(VXF_IGNEG_NICE, 0))
16543 +                       error = 0;
16544 +               else
16545 +                       error = -EACCES;
16546                 goto out;
16547         }
16548         no_nice = security_task_setnice(p, niceval);
16549 @@ -177,6 +181,8 @@ SYSCALL_DEFINE3(setpriority, int, which,
16550                         else
16551                                 pgrp = task_pgrp(current);
16552                         do_each_pid_thread(pgrp, PIDTYPE_PGID, p) {
16553 +                               if (!vx_check(p->xid, VS_ADMIN_P | VS_IDENT))
16554 +                                       continue;
16555                                 error = set_one_prio(p, niceval, error);
16556                         } while_each_pid_thread(pgrp, PIDTYPE_PGID, p);
16557                         break;
16558 @@ -238,6 +244,8 @@ SYSCALL_DEFINE2(getpriority, int, which,
16559                         else
16560                                 pgrp = task_pgrp(current);
16561                         do_each_pid_thread(pgrp, PIDTYPE_PGID, p) {
16562 +                               if (!vx_check(p->xid, VS_ADMIN_P | VS_IDENT))
16563 +                                       continue;
16564                                 niceval = 20 - task_nice(p);
16565                                 if (niceval > retval)
16566                                         retval = niceval;
16567 @@ -347,6 +355,9 @@ void kernel_power_off(void)
16568         machine_power_off();
16569  }
16570  EXPORT_SYMBOL_GPL(kernel_power_off);
16571 +
16572 +long vs_reboot(unsigned int, void __user *);
16573 +
16574  /*
16575   * Reboot system call: for obvious reasons only root may call it,
16576   * and even root needs to set up some magic numbers in the registers
16577 @@ -378,6 +389,9 @@ SYSCALL_DEFINE4(reboot, int, magic1, int
16578         if ((cmd == LINUX_REBOOT_CMD_POWER_OFF) && !pm_power_off)
16579                 cmd = LINUX_REBOOT_CMD_HALT;
16580  
16581 +       if (!vx_check(0, VS_ADMIN|VS_WATCH))
16582 +               return vs_reboot(cmd, arg);
16583 +
16584         lock_kernel();
16585         switch (cmd) {
16586         case LINUX_REBOOT_CMD_RESTART:
16587 @@ -1420,7 +1434,7 @@ SYSCALL_DEFINE2(sethostname, char __user
16588         int errno;
16589         char tmp[__NEW_UTS_LEN];
16590  
16591 -       if (!capable(CAP_SYS_ADMIN))
16592 +       if (!vx_capable(CAP_SYS_ADMIN, VXC_SET_UTSNAME))
16593                 return -EPERM;
16594         if (len < 0 || len > __NEW_UTS_LEN)
16595                 return -EINVAL;
16596 @@ -1469,7 +1483,7 @@ SYSCALL_DEFINE2(setdomainname, char __us
16597         int errno;
16598         char tmp[__NEW_UTS_LEN];
16599  
16600 -       if (!capable(CAP_SYS_ADMIN))
16601 +       if (!vx_capable(CAP_SYS_ADMIN, VXC_SET_UTSNAME))
16602                 return -EPERM;
16603         if (len < 0 || len > __NEW_UTS_LEN)
16604                 return -EINVAL;
16605 @@ -1538,7 +1552,7 @@ SYSCALL_DEFINE2(setrlimit, unsigned int,
16606                 return -EINVAL;
16607         old_rlim = current->signal->rlim + resource;
16608         if ((new_rlim.rlim_max > old_rlim->rlim_max) &&
16609 -           !capable(CAP_SYS_RESOURCE))
16610 +           !vx_capable(CAP_SYS_RESOURCE, VXC_SET_RLIMIT))
16611                 return -EPERM;
16612         if (resource == RLIMIT_NOFILE && new_rlim.rlim_max > sysctl_nr_open)
16613                 return -EPERM;
16614 diff -NurpP --minimal linux-2.6.29/kernel/sysctl.c linux-2.6.29-vs2.3.0.36.9-pre2/kernel/sysctl.c
16615 --- linux-2.6.29/kernel/sysctl.c        2009-03-24 14:22:45.000000000 +0100
16616 +++ linux-2.6.29-vs2.3.0.36.9-pre2/kernel/sysctl.c      2009-03-24 14:48:36.000000000 +0100
16617 @@ -114,6 +114,7 @@ static int ngroups_max = NGROUPS_MAX;
16618  #ifdef CONFIG_MODULES
16619  extern char modprobe_path[];
16620  #endif
16621 +extern char vshelper_path[];
16622  #ifdef CONFIG_CHR_DEV_SG
16623  extern int sg_big_buff;
16624  #endif
16625 @@ -545,6 +546,15 @@ static struct ctl_table kern_table[] = {
16626                 .strategy       = &sysctl_string,
16627         },
16628  #endif
16629 +       {
16630 +               .ctl_name       = KERN_VSHELPER,
16631 +               .procname       = "vshelper",
16632 +               .data           = &vshelper_path,
16633 +               .maxlen         = 256,
16634 +               .mode           = 0644,
16635 +               .proc_handler   = &proc_dostring,
16636 +               .strategy       = &sysctl_string,
16637 +       },
16638  #ifdef CONFIG_CHR_DEV_SG
16639         {
16640                 .ctl_name       = KERN_SG_BIG_BUFF,
16641 diff -NurpP --minimal linux-2.6.29/kernel/sysctl_check.c linux-2.6.29-vs2.3.0.36.9-pre2/kernel/sysctl_check.c
16642 --- linux-2.6.29/kernel/sysctl_check.c  2009-03-24 14:22:45.000000000 +0100
16643 +++ linux-2.6.29-vs2.3.0.36.9-pre2/kernel/sysctl_check.c        2009-03-24 14:48:36.000000000 +0100
16644 @@ -39,6 +39,7 @@ static const struct trans_ctl_table tran
16645  
16646         { KERN_PANIC,                   "panic" },
16647         { KERN_REALROOTDEV,             "real-root-dev" },
16648 +       { KERN_VSHELPER,                "vshelper", },
16649  
16650         { KERN_SPARC_REBOOT,            "reboot-cmd" },
16651         { KERN_CTLALTDEL,               "ctrl-alt-del" },
16652 @@ -1216,6 +1217,22 @@ static const struct trans_ctl_table tran
16653         {}
16654  };
16655  
16656 +static struct trans_ctl_table trans_vserver_table[] = {
16657 +       { 1,    "debug_switch" },
16658 +       { 2,    "debug_xid" },
16659 +       { 3,    "debug_nid" },
16660 +       { 4,    "debug_tag" },
16661 +       { 5,    "debug_net" },
16662 +       { 6,    "debug_limit" },
16663 +       { 7,    "debug_cres" },
16664 +       { 8,    "debug_dlim" },
16665 +       { 9,    "debug_quota" },
16666 +       { 10,   "debug_cvirt" },
16667 +       { 11,   "debug_space" },
16668 +       { 12,   "debug_misc" },
16669 +       {}
16670 +};
16671 +
16672  static const struct trans_ctl_table trans_root_table[] = {
16673         { CTL_KERN,     "kernel",       trans_kern_table },
16674         { CTL_VM,       "vm",           trans_vm_table },
16675 @@ -1232,6 +1249,7 @@ static const struct trans_ctl_table tran
16676         { CTL_SUNRPC,   "sunrpc",       trans_sunrpc_table },
16677         { CTL_PM,       "pm",           trans_pm_table },
16678         { CTL_FRV,      "frv",          trans_frv_table },
16679 +       { CTL_VSERVER,  "vserver",      trans_vserver_table },
16680         {}
16681  };
16682  
16683 diff -NurpP --minimal linux-2.6.29/kernel/time.c linux-2.6.29-vs2.3.0.36.9-pre2/kernel/time.c
16684 --- linux-2.6.29/kernel/time.c  2009-03-24 14:22:45.000000000 +0100
16685 +++ linux-2.6.29-vs2.3.0.36.9-pre2/kernel/time.c        2009-03-24 14:48:36.000000000 +0100
16686 @@ -63,6 +63,7 @@ EXPORT_SYMBOL(sys_tz);
16687  SYSCALL_DEFINE1(time, time_t __user *, tloc)
16688  {
16689         time_t i = get_seconds();
16690 +/*     FIXME: do_gettimeofday(&tv) -> vx_gettimeofday(&tv) */
16691  
16692         if (tloc) {
16693                 if (put_user(i,tloc))
16694 @@ -93,7 +94,7 @@ SYSCALL_DEFINE1(stime, time_t __user *, 
16695         if (err)
16696                 return err;
16697  
16698 -       do_settimeofday(&tv);
16699 +       vx_settimeofday(&tv);
16700         return 0;
16701  }
16702  
16703 @@ -104,7 +105,7 @@ SYSCALL_DEFINE2(gettimeofday, struct tim
16704  {
16705         if (likely(tv != NULL)) {
16706                 struct timeval ktv;
16707 -               do_gettimeofday(&ktv);
16708 +               vx_gettimeofday(&ktv);
16709                 if (copy_to_user(tv, &ktv, sizeof(ktv)))
16710                         return -EFAULT;
16711         }
16712 @@ -179,7 +180,7 @@ int do_sys_settimeofday(struct timespec 
16713                 /* SMP safe, again the code in arch/foo/time.c should
16714                  * globally block out interrupts when it runs.
16715                  */
16716 -               return do_settimeofday(tv);
16717 +               return vx_settimeofday(tv);
16718         }
16719         return 0;
16720  }
16721 @@ -311,7 +312,7 @@ void getnstimeofday(struct timespec *tv)
16722  {
16723         struct timeval x;
16724  
16725 -       do_gettimeofday(&x);
16726 +       vx_gettimeofday(&x);
16727         tv->tv_sec = x.tv_sec;
16728         tv->tv_nsec = x.tv_usec * NSEC_PER_USEC;
16729  }
16730 diff -NurpP --minimal linux-2.6.29/kernel/timer.c linux-2.6.29-vs2.3.0.36.9-pre2/kernel/timer.c
16731 --- linux-2.6.29/kernel/timer.c 2009-03-24 14:22:45.000000000 +0100
16732 +++ linux-2.6.29-vs2.3.0.36.9-pre2/kernel/timer.c       2009-03-24 17:41:02.000000000 +0100
16733 @@ -37,6 +37,10 @@
16734  #include <linux/delay.h>
16735  #include <linux/tick.h>
16736  #include <linux/kallsyms.h>
16737 +#include <linux/vs_base.h>
16738 +#include <linux/vs_cvirt.h>
16739 +#include <linux/vs_pid.h>
16740 +#include <linux/vserver/sched.h>
16741  
16742  #include <asm/uaccess.h>
16743  #include <asm/unistd.h>
16744 @@ -1018,6 +1022,25 @@ unsigned long get_next_timer_interrupt(u
16745  }
16746  #endif
16747  
16748 +static inline
16749 +void __vx_consume_token(struct _vx_sched_pc *sched_pc)
16750 +{
16751 +       sched_pc->tokens--;
16752 +}
16753 +
16754 +static inline
16755 +void vx_hard_tick(struct task_struct *p, int cpu)
16756 +{
16757 +       struct vx_info *vxi = p->vx_info;
16758 +
16759 +       if (vx_info_flags(vxi, VXF_SCHED_HARD|VXF_SCHED_PRIO, 0)) {
16760 +               struct _vx_sched_pc *sched_pc =
16761 +                       &vx_per_cpu(vxi, sched_pc, cpu);
16762 +
16763 +               __vx_consume_token(sched_pc);
16764 +       }
16765 +}
16766 +
16767  /*
16768   * Called from the timer interrupt handler to charge one tick to the current
16769   * process.  user_tick is 1 if the tick is user time, 0 for system.
16770 @@ -1034,6 +1057,7 @@ void update_process_times(int user_tick)
16771                 rcu_check_callbacks(cpu, user_tick);
16772         printk_tick();
16773         scheduler_tick();
16774 +       vx_hard_tick(p, cpu);
16775         run_posix_cpu_timers(p);
16776  }
16777  
16778 @@ -1136,12 +1160,6 @@ SYSCALL_DEFINE1(alarm, unsigned int, sec
16779  
16780  #endif
16781  
16782 -#ifndef __alpha__
16783 -
16784 -/*
16785 - * The Alpha uses getxpid, getxuid, and getxgid instead.  Maybe this
16786 - * should be moved into arch/i386 instead?
16787 - */
16788  
16789  /**
16790   * sys_getpid - return the thread group id of the current process
16791 @@ -1170,10 +1188,23 @@ SYSCALL_DEFINE0(getppid)
16792         rcu_read_lock();
16793         pid = task_tgid_vnr(current->real_parent);
16794         rcu_read_unlock();
16795 +       return vx_map_pid(pid);
16796 +}
16797  
16798 -       return pid;
16799 +#ifdef __alpha__
16800 +
16801 +/*
16802 + * The Alpha uses getxpid, getxuid, and getxgid instead.
16803 + */
16804 +
16805 +asmlinkage long do_getxpid(long *ppid)
16806 +{
16807 +       *ppid = sys_getppid();
16808 +       return sys_getpid();
16809  }
16810  
16811 +#else /* _alpha_ */
16812 +
16813  SYSCALL_DEFINE0(getuid)
16814  {
16815         /* Only we change this so SMP safe */
16816 @@ -1344,6 +1375,8 @@ int do_sysinfo(struct sysinfo *info)
16817                         tp.tv_nsec = tp.tv_nsec - NSEC_PER_SEC;
16818                         tp.tv_sec++;
16819                 }
16820 +               if (vx_flags(VXF_VIRT_UPTIME, 0))
16821 +                       vx_vsi_uptime(&tp, NULL);
16822                 info->uptime = tp.tv_sec + (tp.tv_nsec ? 1 : 0);
16823  
16824                 info->loads[0] = avenrun[0] << (SI_LOAD_SHIFT - FSHIFT);
16825 diff -NurpP --minimal linux-2.6.29/kernel/user.c linux-2.6.29-vs2.3.0.36.9-pre2/kernel/user.c
16826 --- linux-2.6.29/kernel/user.c  2009-03-24 14:22:45.000000000 +0100
16827 +++ linux-2.6.29-vs2.3.0.36.9-pre2/kernel/user.c        2009-03-24 17:47:32.000000000 +0100
16828 @@ -249,10 +249,10 @@ static struct kobj_type uids_ktype = {
16829   *
16830   * See Documentation/scheduler/sched-design-CFS.txt for ramifications.
16831   */
16832 -static int uids_user_create(struct user_struct *up)
16833 +static int uids_user_create(struct user_namespace *ns, struct user_struct *up)
16834  {
16835         struct kobject *kobj = &up->kobj;
16836 -       int error;
16837 +       int error = 0;
16838  
16839         memset(kobj, 0, sizeof(struct kobject));
16840         if (up->user_ns != &init_user_ns)
16841 @@ -280,7 +280,7 @@ int __init uids_sysfs_init(void)
16842         if (!uids_kset)
16843                 return -ENOMEM;
16844  
16845 -       return uids_user_create(&root_user);
16846 +       return uids_user_create(NULL, &root_user);
16847  }
16848  
16849  /* work function to remove sysfs directory for a user and free up
16850 @@ -342,7 +342,8 @@ static void free_user(struct user_struct
16851  #else  /* CONFIG_USER_SCHED && CONFIG_SYSFS */
16852  
16853  int uids_sysfs_init(void) { return 0; }
16854 -static inline int uids_user_create(struct user_struct *up) { return 0; }
16855 +static inline int uids_user_create(struct user_namespace *ns,
16856 +       struct user_struct *up) { return 0; }
16857  static inline void uids_mutex_lock(void) { }
16858  static inline void uids_mutex_unlock(void) { }
16859  
16860 @@ -439,7 +440,7 @@ struct user_struct *alloc_uid(struct use
16861  
16862                 new->user_ns = get_user_ns(ns);
16863  
16864 -               if (uids_user_create(new))
16865 +               if (uids_user_create(ns, new))
16866                         goto out_destoy_sched;
16867  
16868                 /*
16869 diff -NurpP --minimal linux-2.6.29/kernel/user_namespace.c linux-2.6.29-vs2.3.0.36.9-pre2/kernel/user_namespace.c
16870 --- linux-2.6.29/kernel/user_namespace.c        2009-03-24 14:22:45.000000000 +0100
16871 +++ linux-2.6.29-vs2.3.0.36.9-pre2/kernel/user_namespace.c      2009-03-24 18:05:19.000000000 +0100
16872 @@ -10,6 +10,7 @@
16873  #include <linux/slab.h>
16874  #include <linux/user_namespace.h>
16875  #include <linux/cred.h>
16876 +#include <linux/vserver/global.h>
16877  
16878  /*
16879   * Create a new user namespace, deriving the creator from the user in the
16880 @@ -30,6 +31,7 @@ int create_user_ns(struct cred *new)
16881                 return -ENOMEM;
16882  
16883         kref_init(&ns->kref);
16884 +       atomic_inc(&vs_global_user_ns);
16885  
16886         for (n = 0; n < UIDHASH_SZ; ++n)
16887                 INIT_HLIST_HEAD(ns->uidhash_table + n);
16888 @@ -78,6 +80,8 @@ void free_user_ns(struct kref *kref)
16889         struct user_namespace *ns =
16890                 container_of(kref, struct user_namespace, kref);
16891  
16892 +       /* FIXME: maybe move into destroyer? */
16893 +       atomic_dec(&vs_global_user_ns);
16894         INIT_WORK(&ns->destroyer, free_user_ns_work);
16895         schedule_work(&ns->destroyer);
16896  }
16897 diff -NurpP --minimal linux-2.6.29/kernel/utsname.c linux-2.6.29-vs2.3.0.36.9-pre2/kernel/utsname.c
16898 --- linux-2.6.29/kernel/utsname.c       2008-12-25 00:26:37.000000000 +0100
16899 +++ linux-2.6.29-vs2.3.0.36.9-pre2/kernel/utsname.c     2009-02-22 22:54:26.000000000 +0100
16900 @@ -14,6 +14,7 @@
16901  #include <linux/utsname.h>
16902  #include <linux/err.h>
16903  #include <linux/slab.h>
16904 +#include <linux/vserver/global.h>
16905  
16906  /*
16907   * Clone a new ns copying an original utsname, setting refcount to 1
16908 @@ -32,6 +33,7 @@ static struct uts_namespace *clone_uts_n
16909         memcpy(&ns->name, &old_ns->name, sizeof(ns->name));
16910         up_read(&uts_sem);
16911         kref_init(&ns->kref);
16912 +       atomic_inc(&vs_global_uts_ns);
16913         return ns;
16914  }
16915  
16916 @@ -62,5 +64,6 @@ void free_uts_ns(struct kref *kref)
16917         struct uts_namespace *ns;
16918  
16919         ns = container_of(kref, struct uts_namespace, kref);
16920 +       atomic_dec(&vs_global_uts_ns);
16921         kfree(ns);
16922  }
16923 diff -NurpP --minimal linux-2.6.29/kernel/vserver/cacct.c linux-2.6.29-vs2.3.0.36.9-pre2/kernel/vserver/cacct.c
16924 --- linux-2.6.29/kernel/vserver/cacct.c 1970-01-01 01:00:00.000000000 +0100
16925 +++ linux-2.6.29-vs2.3.0.36.9-pre2/kernel/vserver/cacct.c       2009-02-22 22:54:26.000000000 +0100
16926 @@ -0,0 +1,42 @@
16927 +/*
16928 + *  linux/kernel/vserver/cacct.c
16929 + *
16930 + *  Virtual Server: Context Accounting
16931 + *
16932 + *  Copyright (C) 2006-2007 Herbert Pötzl
16933 + *
16934 + *  V0.01  added accounting stats
16935 + *
16936 + */
16937 +
16938 +#include <linux/types.h>
16939 +#include <linux/vs_context.h>
16940 +#include <linux/vserver/cacct_cmd.h>
16941 +#include <linux/vserver/cacct_int.h>
16942 +
16943 +#include <asm/errno.h>
16944 +#include <asm/uaccess.h>
16945 +
16946 +
16947 +int vc_sock_stat(struct vx_info *vxi, void __user *data)
16948 +{
16949 +       struct vcmd_sock_stat_v0 vc_data;
16950 +       int j, field;
16951 +
16952 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
16953 +               return -EFAULT;
16954 +
16955 +       field = vc_data.field;
16956 +       if ((field < 0) || (field >= VXA_SOCK_SIZE))
16957 +               return -EINVAL;
16958 +
16959 +       for (j = 0; j < 3; j++) {
16960 +               vc_data.count[j] = vx_sock_count(&vxi->cacct, field, j);
16961 +               vc_data.total[j] = vx_sock_total(&vxi->cacct, field, j);
16962 +       }
16963 +
16964 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
16965 +               return -EFAULT;
16966 +       return 0;
16967 +}
16968 +
16969 diff -NurpP --minimal linux-2.6.29/kernel/vserver/cacct_init.h linux-2.6.29-vs2.3.0.36.9-pre2/kernel/vserver/cacct_init.h
16970 --- linux-2.6.29/kernel/vserver/cacct_init.h    1970-01-01 01:00:00.000000000 +0100
16971 +++ linux-2.6.29-vs2.3.0.36.9-pre2/kernel/vserver/cacct_init.h  2009-02-22 22:54:26.000000000 +0100
16972 @@ -0,0 +1,25 @@
16973 +
16974 +
16975 +static inline void vx_info_init_cacct(struct _vx_cacct *cacct)
16976 +{
16977 +       int i, j;
16978 +
16979 +
16980 +       for (i = 0; i < VXA_SOCK_SIZE; i++) {
16981 +               for (j = 0; j < 3; j++) {
16982 +                       atomic_set(&cacct->sock[i][j].count, 0);
16983 +                       atomic_set(&cacct->sock[i][j].total, 0);
16984 +               }
16985 +       }
16986 +       for (i = 0; i < 8; i++)
16987 +               atomic_set(&cacct->slab[i], 0);
16988 +       for (i = 0; i < 5; i++)
16989 +               for (j = 0; j < 4; j++)
16990 +                       atomic_set(&cacct->page[i][j], 0);
16991 +}
16992 +
16993 +static inline void vx_info_exit_cacct(struct _vx_cacct *cacct)
16994 +{
16995 +       return;
16996 +}
16997 +
16998 diff -NurpP --minimal linux-2.6.29/kernel/vserver/cacct_proc.h linux-2.6.29-vs2.3.0.36.9-pre2/kernel/vserver/cacct_proc.h
16999 --- linux-2.6.29/kernel/vserver/cacct_proc.h    1970-01-01 01:00:00.000000000 +0100
17000 +++ linux-2.6.29-vs2.3.0.36.9-pre2/kernel/vserver/cacct_proc.h  2009-02-22 22:54:26.000000000 +0100
17001 @@ -0,0 +1,53 @@
17002 +#ifndef _VX_CACCT_PROC_H
17003 +#define _VX_CACCT_PROC_H
17004 +
17005 +#include <linux/vserver/cacct_int.h>
17006 +
17007 +
17008 +#define VX_SOCKA_TOP   \
17009 +       "Type\t    recv #/bytes\t\t   send #/bytes\t\t    fail #/bytes\n"
17010 +
17011 +static inline int vx_info_proc_cacct(struct _vx_cacct *cacct, char *buffer)
17012 +{
17013 +       int i, j, length = 0;
17014 +       static char *type[VXA_SOCK_SIZE] = {
17015 +               "UNSPEC", "UNIX", "INET", "INET6", "PACKET", "OTHER"
17016 +       };
17017 +
17018 +       length += sprintf(buffer + length, VX_SOCKA_TOP);
17019 +       for (i = 0; i < VXA_SOCK_SIZE; i++) {
17020 +               length += sprintf(buffer + length, "%s:", type[i]);
17021 +               for (j = 0; j < 3; j++) {
17022 +                       length += sprintf(buffer + length,
17023 +                               "\t%10lu/%-10lu",
17024 +                               vx_sock_count(cacct, i, j),
17025 +                               vx_sock_total(cacct, i, j));
17026 +               }
17027 +               buffer[length++] = '\n';
17028 +       }
17029 +
17030 +       length += sprintf(buffer + length, "\n");
17031 +       length += sprintf(buffer + length,
17032 +               "slab:\t %8u %8u %8u %8u\n",
17033 +               atomic_read(&cacct->slab[1]),
17034 +               atomic_read(&cacct->slab[4]),
17035 +               atomic_read(&cacct->slab[0]),
17036 +               atomic_read(&cacct->slab[2]));
17037 +
17038 +       length += sprintf(buffer + length, "\n");
17039 +       for (i = 0; i < 5; i++) {
17040 +               length += sprintf(buffer + length,
17041 +                       "page[%d]: %8u %8u %8u %8u\t %8u %8u %8u %8u\n", i,
17042 +                       atomic_read(&cacct->page[i][0]),
17043 +                       atomic_read(&cacct->page[i][1]),
17044 +                       atomic_read(&cacct->page[i][2]),
17045 +                       atomic_read(&cacct->page[i][3]),
17046 +                       atomic_read(&cacct->page[i][4]),
17047 +                       atomic_read(&cacct->page[i][5]),
17048 +                       atomic_read(&cacct->page[i][6]),
17049 +                       atomic_read(&cacct->page[i][7]));
17050 +       }
17051 +       return length;
17052 +}
17053 +
17054 +#endif /* _VX_CACCT_PROC_H */
17055 diff -NurpP --minimal linux-2.6.29/kernel/vserver/context.c linux-2.6.29-vs2.3.0.36.9-pre2/kernel/vserver/context.c
17056 --- linux-2.6.29/kernel/vserver/context.c       1970-01-01 01:00:00.000000000 +0100
17057 +++ linux-2.6.29-vs2.3.0.36.9-pre2/kernel/vserver/context.c     2009-02-22 22:54:26.000000000 +0100
17058 @@ -0,0 +1,1018 @@
17059 +/*
17060 + *  linux/kernel/vserver/context.c
17061 + *
17062 + *  Virtual Server: Context Support
17063 + *
17064 + *  Copyright (C) 2003-2007  Herbert Pötzl
17065 + *
17066 + *  V0.01  context helper
17067 + *  V0.02  vx_ctx_kill syscall command
17068 + *  V0.03  replaced context_info calls
17069 + *  V0.04  redesign of struct (de)alloc
17070 + *  V0.05  rlimit basic implementation
17071 + *  V0.06  task_xid and info commands
17072 + *  V0.07  context flags and caps
17073 + *  V0.08  switch to RCU based hash
17074 + *  V0.09  revert to non RCU for now
17075 + *  V0.10  and back to working RCU hash
17076 + *  V0.11  and back to locking again
17077 + *  V0.12  referenced context store
17078 + *  V0.13  separate per cpu data
17079 + *  V0.14  changed vcmds to vxi arg
17080 + *  V0.15  added context stat
17081 + *  V0.16  have __create claim() the vxi
17082 + *  V0.17  removed older and legacy stuff
17083 + *
17084 + */
17085 +
17086 +#include <linux/slab.h>
17087 +#include <linux/types.h>
17088 +#include <linux/security.h>
17089 +#include <linux/pid_namespace.h>
17090 +
17091 +#include <linux/vserver/context.h>
17092 +#include <linux/vserver/network.h>
17093 +#include <linux/vserver/debug.h>
17094 +#include <linux/vserver/limit.h>
17095 +#include <linux/vserver/limit_int.h>
17096 +#include <linux/vserver/space.h>
17097 +
17098 +#include <linux/vs_context.h>
17099 +#include <linux/vs_limit.h>
17100 +#include <linux/vs_pid.h>
17101 +#include <linux/vserver/context_cmd.h>
17102 +
17103 +#include "cvirt_init.h"
17104 +#include "cacct_init.h"
17105 +#include "limit_init.h"
17106 +#include "sched_init.h"
17107 +
17108 +
17109 +atomic_t vx_global_ctotal      = ATOMIC_INIT(0);
17110 +atomic_t vx_global_cactive     = ATOMIC_INIT(0);
17111 +
17112 +
17113 +/*     now inactive context structures */
17114 +
17115 +static struct hlist_head vx_info_inactive = HLIST_HEAD_INIT;
17116 +
17117 +static spinlock_t vx_info_inactive_lock = SPIN_LOCK_UNLOCKED;
17118 +
17119 +
17120 +/*     __alloc_vx_info()
17121 +
17122 +       * allocate an initialized vx_info struct
17123 +       * doesn't make it visible (hash)                        */
17124 +
17125 +static struct vx_info *__alloc_vx_info(xid_t xid)
17126 +{
17127 +       struct vx_info *new = NULL;
17128 +       int cpu;
17129 +
17130 +       vxdprintk(VXD_CBIT(xid, 0), "alloc_vx_info(%d)*", xid);
17131 +
17132 +       /* would this benefit from a slab cache? */
17133 +       new = kmalloc(sizeof(struct vx_info), GFP_KERNEL);
17134 +       if (!new)
17135 +               return 0;
17136 +
17137 +       memset(new, 0, sizeof(struct vx_info));
17138 +#ifdef CONFIG_SMP
17139 +       new->ptr_pc = alloc_percpu(struct _vx_info_pc);
17140 +       if (!new->ptr_pc)
17141 +               goto error;
17142 +#endif
17143 +       new->vx_id = xid;
17144 +       INIT_HLIST_NODE(&new->vx_hlist);
17145 +       atomic_set(&new->vx_usecnt, 0);
17146 +       atomic_set(&new->vx_tasks, 0);
17147 +       new->vx_parent = NULL;
17148 +       new->vx_state = 0;
17149 +       init_waitqueue_head(&new->vx_wait);
17150 +
17151 +       /* prepare reaper */
17152 +       get_task_struct(init_pid_ns.child_reaper);
17153 +       new->vx_reaper = init_pid_ns.child_reaper;
17154 +       new->vx_badness_bias = 0;
17155 +
17156 +       /* rest of init goes here */
17157 +       vx_info_init_limit(&new->limit);
17158 +       vx_info_init_sched(&new->sched);
17159 +       vx_info_init_cvirt(&new->cvirt);
17160 +       vx_info_init_cacct(&new->cacct);
17161 +
17162 +       /* per cpu data structures */
17163 +       for_each_possible_cpu(cpu) {
17164 +               vx_info_init_sched_pc(
17165 +                       &vx_per_cpu(new, sched_pc, cpu), cpu);
17166 +               vx_info_init_cvirt_pc(
17167 +                       &vx_per_cpu(new, cvirt_pc, cpu), cpu);
17168 +       }
17169 +
17170 +       new->vx_flags = VXF_INIT_SET;
17171 +       cap_set_init_eff(new->vx_bcaps);
17172 +       new->vx_ccaps = 0;
17173 +       // new->vx_cap_bset = current->cap_bset;
17174 +
17175 +       new->reboot_cmd = 0;
17176 +       new->exit_code = 0;
17177 +
17178 +       vxdprintk(VXD_CBIT(xid, 0),
17179 +               "alloc_vx_info(%d) = %p", xid, new);
17180 +       vxh_alloc_vx_info(new);
17181 +       atomic_inc(&vx_global_ctotal);
17182 +       return new;
17183 +#ifdef CONFIG_SMP
17184 +error:
17185 +       kfree(new);
17186 +       return 0;
17187 +#endif
17188 +}
17189 +
17190 +/*     __dealloc_vx_info()
17191 +
17192 +       * final disposal of vx_info                             */
17193 +
17194 +static void __dealloc_vx_info(struct vx_info *vxi)
17195 +{
17196 +       struct vx_info_save vxis;
17197 +       int cpu;
17198 +
17199 +       vxdprintk(VXD_CBIT(xid, 0),
17200 +               "dealloc_vx_info(%p)", vxi);
17201 +       vxh_dealloc_vx_info(vxi);
17202 +
17203 +#ifdef CONFIG_VSERVER_WARN
17204 +       enter_vx_info(vxi, &vxis);
17205 +       vx_info_exit_limit(&vxi->limit);
17206 +       vx_info_exit_sched(&vxi->sched);
17207 +       vx_info_exit_cvirt(&vxi->cvirt);
17208 +       vx_info_exit_cacct(&vxi->cacct);
17209 +
17210 +       for_each_possible_cpu(cpu) {
17211 +               vx_info_exit_sched_pc(
17212 +                       &vx_per_cpu(vxi, sched_pc, cpu), cpu);
17213 +               vx_info_exit_cvirt_pc(
17214 +                       &vx_per_cpu(vxi, cvirt_pc, cpu), cpu);
17215 +       }
17216 +       leave_vx_info(&vxis);
17217 +#endif
17218 +
17219 +       vxi->vx_id = -1;
17220 +       vxi->vx_state |= VXS_RELEASED;
17221 +
17222 +#ifdef CONFIG_SMP
17223 +       free_percpu(vxi->ptr_pc);
17224 +#endif
17225 +       kfree(vxi);
17226 +       atomic_dec(&vx_global_ctotal);
17227 +}
17228 +
17229 +static void __shutdown_vx_info(struct vx_info *vxi)
17230 +{
17231 +       struct nsproxy *nsproxy;
17232 +       struct fs_struct *fs;
17233 +       int index;
17234 +
17235 +       might_sleep();
17236 +
17237 +       vxi->vx_state |= VXS_SHUTDOWN;
17238 +       vs_state_change(vxi, VSC_SHUTDOWN);
17239 +
17240 +       for (index = 0; index < VX_SPACES; index++) {
17241 +               nsproxy = xchg(&vxi->vx_nsproxy[index], NULL);
17242 +               if (nsproxy)
17243 +                       put_nsproxy(nsproxy);
17244 +
17245 +               fs = xchg(&vxi->vx_fs[index], NULL);
17246 +               if (fs)
17247 +                       put_fs_struct(fs);
17248 +       }
17249 +}
17250 +
17251 +/* exported stuff */
17252 +
17253 +void free_vx_info(struct vx_info *vxi)
17254 +{
17255 +       unsigned long flags;
17256 +       unsigned index;
17257 +
17258 +       /* check for reference counts first */
17259 +       BUG_ON(atomic_read(&vxi->vx_usecnt));
17260 +       BUG_ON(atomic_read(&vxi->vx_tasks));
17261 +
17262 +       /* context must not be hashed */
17263 +       BUG_ON(vx_info_state(vxi, VXS_HASHED));
17264 +
17265 +       /* context shutdown is mandatory */
17266 +       BUG_ON(!vx_info_state(vxi, VXS_SHUTDOWN));
17267 +
17268 +       /* nsproxy and fs check */
17269 +       for (index = 0; index < VX_SPACES; index++) {
17270 +               BUG_ON(vxi->vx_nsproxy[index]);
17271 +               BUG_ON(vxi->vx_fs[index]);
17272 +       }
17273 +
17274 +       spin_lock_irqsave(&vx_info_inactive_lock, flags);
17275 +       hlist_del(&vxi->vx_hlist);
17276 +       spin_unlock_irqrestore(&vx_info_inactive_lock, flags);
17277 +
17278 +       __dealloc_vx_info(vxi);
17279 +}
17280 +
17281 +
17282 +/*     hash table for vx_info hash */
17283 +
17284 +#define VX_HASH_SIZE   13
17285 +
17286 +static struct hlist_head vx_info_hash[VX_HASH_SIZE] =
17287 +       { [0 ... VX_HASH_SIZE-1] = HLIST_HEAD_INIT };
17288 +
17289 +static spinlock_t vx_info_hash_lock = SPIN_LOCK_UNLOCKED;
17290 +
17291 +
17292 +static inline unsigned int __hashval(xid_t xid)
17293 +{
17294 +       return (xid % VX_HASH_SIZE);
17295 +}
17296 +
17297 +
17298 +
17299 +/*     __hash_vx_info()
17300 +
17301 +       * add the vxi to the global hash table
17302 +       * requires the hash_lock to be held                     */
17303 +
17304 +static inline void __hash_vx_info(struct vx_info *vxi)
17305 +{
17306 +       struct hlist_head *head;
17307 +
17308 +       vxd_assert_lock(&vx_info_hash_lock);
17309 +       vxdprintk(VXD_CBIT(xid, 4),
17310 +               "__hash_vx_info: %p[#%d]", vxi, vxi->vx_id);
17311 +       vxh_hash_vx_info(vxi);
17312 +
17313 +       /* context must not be hashed */
17314 +       BUG_ON(vx_info_state(vxi, VXS_HASHED));
17315 +
17316 +       vxi->vx_state |= VXS_HASHED;
17317 +       head = &vx_info_hash[__hashval(vxi->vx_id)];
17318 +       hlist_add_head(&vxi->vx_hlist, head);
17319 +       atomic_inc(&vx_global_cactive);
17320 +}
17321 +
17322 +/*     __unhash_vx_info()
17323 +
17324 +       * remove the vxi from the global hash table
17325 +       * requires the hash_lock to be held                     */
17326 +
17327 +static inline void __unhash_vx_info(struct vx_info *vxi)
17328 +{
17329 +       unsigned long flags;
17330 +
17331 +       vxd_assert_lock(&vx_info_hash_lock);
17332 +       vxdprintk(VXD_CBIT(xid, 4),
17333 +               "__unhash_vx_info: %p[#%d.%d.%d]", vxi, vxi->vx_id,
17334 +               atomic_read(&vxi->vx_usecnt), atomic_read(&vxi->vx_tasks));
17335 +       vxh_unhash_vx_info(vxi);
17336 +
17337 +       /* context must be hashed */
17338 +       BUG_ON(!vx_info_state(vxi, VXS_HASHED));
17339 +       /* but without tasks */
17340 +       BUG_ON(atomic_read(&vxi->vx_tasks));
17341 +
17342 +       vxi->vx_state &= ~VXS_HASHED;
17343 +       hlist_del_init(&vxi->vx_hlist);
17344 +       spin_lock_irqsave(&vx_info_inactive_lock, flags);
17345 +       hlist_add_head(&vxi->vx_hlist, &vx_info_inactive);
17346 +       spin_unlock_irqrestore(&vx_info_inactive_lock, flags);
17347 +       atomic_dec(&vx_global_cactive);
17348 +}
17349 +
17350 +
17351 +/*     __lookup_vx_info()
17352 +
17353 +       * requires the hash_lock to be held
17354 +       * doesn't increment the vx_refcnt                       */
17355 +
17356 +static inline struct vx_info *__lookup_vx_info(xid_t xid)
17357 +{
17358 +       struct hlist_head *head = &vx_info_hash[__hashval(xid)];
17359 +       struct hlist_node *pos;
17360 +       struct vx_info *vxi;
17361 +
17362 +       vxd_assert_lock(&vx_info_hash_lock);
17363 +       hlist_for_each(pos, head) {
17364 +               vxi = hlist_entry(pos, struct vx_info, vx_hlist);
17365 +
17366 +               if (vxi->vx_id == xid)
17367 +                       goto found;
17368 +       }
17369 +       vxi = NULL;
17370 +found:
17371 +       vxdprintk(VXD_CBIT(xid, 0),
17372 +               "__lookup_vx_info(#%u): %p[#%u]",
17373 +               xid, vxi, vxi ? vxi->vx_id : 0);
17374 +       vxh_lookup_vx_info(vxi, xid);
17375 +       return vxi;
17376 +}
17377 +
17378 +
17379 +/*     __create_vx_info()
17380 +
17381 +       * create the requested context
17382 +       * get(), claim() and hash it                            */
17383 +
17384 +static struct vx_info *__create_vx_info(int id)
17385 +{
17386 +       struct vx_info *new, *vxi = NULL;
17387 +
17388 +       vxdprintk(VXD_CBIT(xid, 1), "create_vx_info(%d)*", id);
17389 +
17390 +       if (!(new = __alloc_vx_info(id)))
17391 +               return ERR_PTR(-ENOMEM);
17392 +
17393 +       /* required to make dynamic xids unique */
17394 +       spin_lock(&vx_info_hash_lock);
17395 +
17396 +       /* static context requested */
17397 +       if ((vxi = __lookup_vx_info(id))) {
17398 +               vxdprintk(VXD_CBIT(xid, 0),
17399 +                       "create_vx_info(%d) = %p (already there)", id, vxi);
17400 +               if (vx_info_flags(vxi, VXF_STATE_SETUP, 0))
17401 +                       vxi = ERR_PTR(-EBUSY);
17402 +               else
17403 +                       vxi = ERR_PTR(-EEXIST);
17404 +               goto out_unlock;
17405 +       }
17406 +       /* new context */
17407 +       vxdprintk(VXD_CBIT(xid, 0),
17408 +               "create_vx_info(%d) = %p (new)", id, new);
17409 +       claim_vx_info(new, NULL);
17410 +       __hash_vx_info(get_vx_info(new));
17411 +       vxi = new, new = NULL;
17412 +
17413 +out_unlock:
17414 +       spin_unlock(&vx_info_hash_lock);
17415 +       vxh_create_vx_info(IS_ERR(vxi) ? NULL : vxi, id);
17416 +       if (new)
17417 +               __dealloc_vx_info(new);
17418 +       return vxi;
17419 +}
17420 +
17421 +
17422 +/*     exported stuff                                          */
17423 +
17424 +
17425 +void unhash_vx_info(struct vx_info *vxi)
17426 +{
17427 +       __shutdown_vx_info(vxi);
17428 +       spin_lock(&vx_info_hash_lock);
17429 +       __unhash_vx_info(vxi);
17430 +       spin_unlock(&vx_info_hash_lock);
17431 +       __wakeup_vx_info(vxi);
17432 +}
17433 +
17434 +
17435 +/*     lookup_vx_info()
17436 +
17437 +       * search for a vx_info and get() it
17438 +       * negative id means current                             */
17439 +
17440 +struct vx_info *lookup_vx_info(int id)
17441 +{
17442 +       struct vx_info *vxi = NULL;
17443 +
17444 +       if (id < 0) {
17445 +               vxi = get_vx_info(current->vx_info);
17446 +       } else if (id > 1) {
17447 +               spin_lock(&vx_info_hash_lock);
17448 +               vxi = get_vx_info(__lookup_vx_info(id));
17449 +               spin_unlock(&vx_info_hash_lock);
17450 +       }
17451 +       return vxi;
17452 +}
17453 +
17454 +/*     xid_is_hashed()
17455 +
17456 +       * verify that xid is still hashed                       */
17457 +
17458 +int xid_is_hashed(xid_t xid)
17459 +{
17460 +       int hashed;
17461 +
17462 +       spin_lock(&vx_info_hash_lock);
17463 +       hashed = (__lookup_vx_info(xid) != NULL);
17464 +       spin_unlock(&vx_info_hash_lock);
17465 +       return hashed;
17466 +}
17467 +
17468 +#ifdef CONFIG_PROC_FS
17469 +
17470 +/*     get_xid_list()
17471 +
17472 +       * get a subset of hashed xids for proc
17473 +       * assumes size is at least one                          */
17474 +
17475 +int get_xid_list(int index, unsigned int *xids, int size)
17476 +{
17477 +       int hindex, nr_xids = 0;
17478 +
17479 +       /* only show current and children */
17480 +       if (!vx_check(0, VS_ADMIN | VS_WATCH)) {
17481 +               if (index > 0)
17482 +                       return 0;
17483 +               xids[nr_xids] = vx_current_xid();
17484 +               return 1;
17485 +       }
17486 +
17487 +       for (hindex = 0; hindex < VX_HASH_SIZE; hindex++) {
17488 +               struct hlist_head *head = &vx_info_hash[hindex];
17489 +               struct hlist_node *pos;
17490 +
17491 +               spin_lock(&vx_info_hash_lock);
17492 +               hlist_for_each(pos, head) {
17493 +                       struct vx_info *vxi;
17494 +
17495 +                       if (--index > 0)
17496 +                               continue;
17497 +
17498 +                       vxi = hlist_entry(pos, struct vx_info, vx_hlist);
17499 +                       xids[nr_xids] = vxi->vx_id;
17500 +                       if (++nr_xids >= size) {
17501 +                               spin_unlock(&vx_info_hash_lock);
17502 +                               goto out;
17503 +                       }
17504 +               }
17505 +               /* keep the lock time short */
17506 +               spin_unlock(&vx_info_hash_lock);
17507 +       }
17508 +out:
17509 +       return nr_xids;
17510 +}
17511 +#endif
17512 +
17513 +#ifdef CONFIG_VSERVER_DEBUG
17514 +
17515 +void   dump_vx_info_inactive(int level)
17516 +{
17517 +       struct hlist_node *entry, *next;
17518 +
17519 +       hlist_for_each_safe(entry, next, &vx_info_inactive) {
17520 +               struct vx_info *vxi =
17521 +                       list_entry(entry, struct vx_info, vx_hlist);
17522 +
17523 +               dump_vx_info(vxi, level);
17524 +       }
17525 +}
17526 +
17527 +#endif
17528 +
17529 +#if 0
17530 +int vx_migrate_user(struct task_struct *p, struct vx_info *vxi)
17531 +{
17532 +       struct user_struct *new_user, *old_user;
17533 +
17534 +       if (!p || !vxi)
17535 +               BUG();
17536 +
17537 +       if (vx_info_flags(vxi, VXF_INFO_PRIVATE, 0))
17538 +               return -EACCES;
17539 +
17540 +       new_user = alloc_uid(vxi->vx_id, p->uid);
17541 +       if (!new_user)
17542 +               return -ENOMEM;
17543 +
17544 +       old_user = p->user;
17545 +       if (new_user != old_user) {
17546 +               atomic_inc(&new_user->processes);
17547 +               atomic_dec(&old_user->processes);
17548 +               p->user = new_user;
17549 +       }
17550 +       free_uid(old_user);
17551 +       return 0;
17552 +}
17553 +#endif
17554 +
17555 +#if 0
17556 +void vx_mask_cap_bset(struct vx_info *vxi, struct task_struct *p)
17557 +{
17558 +       // p->cap_effective &= vxi->vx_cap_bset;
17559 +       p->cap_effective =
17560 +               cap_intersect(p->cap_effective, vxi->cap_bset);
17561 +       // p->cap_inheritable &= vxi->vx_cap_bset;
17562 +       p->cap_inheritable =
17563 +               cap_intersect(p->cap_inheritable, vxi->cap_bset);
17564 +       // p->cap_permitted &= vxi->vx_cap_bset;
17565 +       p->cap_permitted =
17566 +               cap_intersect(p->cap_permitted, vxi->cap_bset);
17567 +}
17568 +#endif
17569 +
17570 +
17571 +#include <linux/file.h>
17572 +#include <linux/fdtable.h>
17573 +
17574 +static int vx_openfd_task(struct task_struct *tsk)
17575 +{
17576 +       struct files_struct *files = tsk->files;
17577 +       struct fdtable *fdt;
17578 +       const unsigned long *bptr;
17579 +       int count, total;
17580 +
17581 +       /* no rcu_read_lock() because of spin_lock() */
17582 +       spin_lock(&files->file_lock);
17583 +       fdt = files_fdtable(files);
17584 +       bptr = fdt->open_fds->fds_bits;
17585 +       count = fdt->max_fds / (sizeof(unsigned long) * 8);
17586 +       for (total = 0; count > 0; count--) {
17587 +               if (*bptr)
17588 +                       total += hweight_long(*bptr);
17589 +               bptr++;
17590 +       }
17591 +       spin_unlock(&files->file_lock);
17592 +       return total;
17593 +}
17594 +
17595 +
17596 +/*     for *space compatibility */
17597 +
17598 +asmlinkage long sys_unshare(unsigned long);
17599 +
17600 +/*
17601 + *     migrate task to new context
17602 + *     gets vxi, puts old_vxi on change
17603 + *     optionally unshares namespaces (hack)
17604 + */
17605 +
17606 +int vx_migrate_task(struct task_struct *p, struct vx_info *vxi, int unshare)
17607 +{
17608 +       struct vx_info *old_vxi;
17609 +       int ret = 0;
17610 +
17611 +       if (!p || !vxi)
17612 +               BUG();
17613 +
17614 +       vxdprintk(VXD_CBIT(xid, 5),
17615 +               "vx_migrate_task(%p,%p[#%d.%d])", p, vxi,
17616 +               vxi->vx_id, atomic_read(&vxi->vx_usecnt));
17617 +
17618 +       if (vx_info_flags(vxi, VXF_INFO_PRIVATE, 0) &&
17619 +               !vx_info_flags(vxi, VXF_STATE_SETUP, 0))
17620 +               return -EACCES;
17621 +
17622 +       if (vx_info_state(vxi, VXS_SHUTDOWN))
17623 +               return -EFAULT;
17624 +
17625 +       old_vxi = task_get_vx_info(p);
17626 +       if (old_vxi == vxi)
17627 +               goto out;
17628 +
17629 +//     if (!(ret = vx_migrate_user(p, vxi))) {
17630 +       {
17631 +               int openfd;
17632 +
17633 +               task_lock(p);
17634 +               openfd = vx_openfd_task(p);
17635 +
17636 +               if (old_vxi) {
17637 +                       atomic_dec(&old_vxi->cvirt.nr_threads);
17638 +                       atomic_dec(&old_vxi->cvirt.nr_running);
17639 +                       __rlim_dec(&old_vxi->limit, RLIMIT_NPROC);
17640 +                       /* FIXME: what about the struct files here? */
17641 +                       __rlim_sub(&old_vxi->limit, VLIMIT_OPENFD, openfd);
17642 +                       /* account for the executable */
17643 +                       __rlim_dec(&old_vxi->limit, VLIMIT_DENTRY);
17644 +               }
17645 +               atomic_inc(&vxi->cvirt.nr_threads);
17646 +               atomic_inc(&vxi->cvirt.nr_running);
17647 +               __rlim_inc(&vxi->limit, RLIMIT_NPROC);
17648 +               /* FIXME: what about the struct files here? */
17649 +               __rlim_add(&vxi->limit, VLIMIT_OPENFD, openfd);
17650 +               /* account for the executable */
17651 +               __rlim_inc(&vxi->limit, VLIMIT_DENTRY);
17652 +
17653 +               if (old_vxi) {
17654 +                       release_vx_info(old_vxi, p);
17655 +                       clr_vx_info(&p->vx_info);
17656 +               }
17657 +               claim_vx_info(vxi, p);
17658 +               set_vx_info(&p->vx_info, vxi);
17659 +               p->xid = vxi->vx_id;
17660 +
17661 +               vxdprintk(VXD_CBIT(xid, 5),
17662 +                       "moved task %p into vxi:%p[#%d]",
17663 +                       p, vxi, vxi->vx_id);
17664 +
17665 +               // vx_mask_cap_bset(vxi, p);
17666 +               task_unlock(p);
17667 +
17668 +               /* hack for *spaces to provide compatibility */
17669 +               if (unshare) {
17670 +                       struct nsproxy *old_nsp, *new_nsp;
17671 +
17672 +                       ret = unshare_nsproxy_namespaces(
17673 +                               CLONE_NEWUTS | CLONE_NEWIPC | CLONE_NEWUSER,
17674 +                               &new_nsp, NULL);
17675 +                       if (ret)
17676 +                               goto out;
17677 +
17678 +                       old_nsp = xchg(&p->nsproxy, new_nsp);
17679 +                       vx_set_space(vxi,
17680 +                               CLONE_NEWUTS | CLONE_NEWIPC | CLONE_NEWUSER, 0);
17681 +                       put_nsproxy(old_nsp);
17682 +               }
17683 +       }
17684 +out:
17685 +       put_vx_info(old_vxi);
17686 +       return ret;
17687 +}
17688 +
17689 +int vx_set_reaper(struct vx_info *vxi, struct task_struct *p)
17690 +{
17691 +       struct task_struct *old_reaper;
17692 +
17693 +       if (!vxi)
17694 +               return -EINVAL;
17695 +
17696 +       vxdprintk(VXD_CBIT(xid, 6),
17697 +               "vx_set_reaper(%p[#%d],%p[#%d,%d])",
17698 +               vxi, vxi->vx_id, p, p->xid, p->pid);
17699 +
17700 +       old_reaper = vxi->vx_reaper;
17701 +       if (old_reaper == p)
17702 +               return 0;
17703 +
17704 +       /* set new child reaper */
17705 +       get_task_struct(p);
17706 +       vxi->vx_reaper = p;
17707 +       put_task_struct(old_reaper);
17708 +       return 0;
17709 +}
17710 +
17711 +int vx_set_init(struct vx_info *vxi, struct task_struct *p)
17712 +{
17713 +       if (!vxi)
17714 +               return -EINVAL;
17715 +
17716 +       vxdprintk(VXD_CBIT(xid, 6),
17717 +               "vx_set_init(%p[#%d],%p[#%d,%d,%d])",
17718 +               vxi, vxi->vx_id, p, p->xid, p->pid, p->tgid);
17719 +
17720 +       vxi->vx_flags &= ~VXF_STATE_INIT;
17721 +       vxi->vx_initpid = p->tgid;
17722 +       return 0;
17723 +}
17724 +
17725 +void vx_exit_init(struct vx_info *vxi, struct task_struct *p, int code)
17726 +{
17727 +       vxdprintk(VXD_CBIT(xid, 6),
17728 +               "vx_exit_init(%p[#%d],%p[#%d,%d,%d])",
17729 +               vxi, vxi->vx_id, p, p->xid, p->pid, p->tgid);
17730 +
17731 +       vxi->exit_code = code;
17732 +       vxi->vx_initpid = 0;
17733 +}
17734 +
17735 +
17736 +void vx_set_persistent(struct vx_info *vxi)
17737 +{
17738 +       vxdprintk(VXD_CBIT(xid, 6),
17739 +               "vx_set_persistent(%p[#%d])", vxi, vxi->vx_id);
17740 +
17741 +       get_vx_info(vxi);
17742 +       claim_vx_info(vxi, NULL);
17743 +}
17744 +
17745 +void vx_clear_persistent(struct vx_info *vxi)
17746 +{
17747 +       vxdprintk(VXD_CBIT(xid, 6),
17748 +               "vx_clear_persistent(%p[#%d])", vxi, vxi->vx_id);
17749 +
17750 +       release_vx_info(vxi, NULL);
17751 +       put_vx_info(vxi);
17752 +}
17753 +
17754 +void vx_update_persistent(struct vx_info *vxi)
17755 +{
17756 +       if (vx_info_flags(vxi, VXF_PERSISTENT, 0))
17757 +               vx_set_persistent(vxi);
17758 +       else
17759 +               vx_clear_persistent(vxi);
17760 +}
17761 +
17762 +
17763 +/*     task must be current or locked          */
17764 +
17765 +void   exit_vx_info(struct task_struct *p, int code)
17766 +{
17767 +       struct vx_info *vxi = p->vx_info;
17768 +
17769 +       if (vxi) {
17770 +               atomic_dec(&vxi->cvirt.nr_threads);
17771 +               vx_nproc_dec(p);
17772 +
17773 +               vxi->exit_code = code;
17774 +               release_vx_info(vxi, p);
17775 +       }
17776 +}
17777 +
17778 +void   exit_vx_info_early(struct task_struct *p, int code)
17779 +{
17780 +       struct vx_info *vxi = p->vx_info;
17781 +
17782 +       if (vxi) {
17783 +               if (vxi->vx_initpid == p->tgid)
17784 +                       vx_exit_init(vxi, p, code);
17785 +               if (vxi->vx_reaper == p)
17786 +                       vx_set_reaper(vxi, init_pid_ns.child_reaper);
17787 +       }
17788 +}
17789 +
17790 +
17791 +/* vserver syscall commands below here */
17792 +
17793 +/* taks xid and vx_info functions */
17794 +
17795 +#include <asm/uaccess.h>
17796 +
17797 +
17798 +int vc_task_xid(uint32_t id)
17799 +{
17800 +       xid_t xid;
17801 +
17802 +       if (id) {
17803 +               struct task_struct *tsk;
17804 +
17805 +               read_lock(&tasklist_lock);
17806 +               tsk = find_task_by_real_pid(id);
17807 +               xid = (tsk) ? tsk->xid : -ESRCH;
17808 +               read_unlock(&tasklist_lock);
17809 +       } else
17810 +               xid = vx_current_xid();
17811 +       return xid;
17812 +}
17813 +
17814 +
17815 +int vc_vx_info(struct vx_info *vxi, void __user *data)
17816 +{
17817 +       struct vcmd_vx_info_v0 vc_data;
17818 +
17819 +       vc_data.xid = vxi->vx_id;
17820 +       vc_data.initpid = vxi->vx_initpid;
17821 +
17822 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
17823 +               return -EFAULT;
17824 +       return 0;
17825 +}
17826 +
17827 +
17828 +int vc_ctx_stat(struct vx_info *vxi, void __user *data)
17829 +{
17830 +       struct vcmd_ctx_stat_v0 vc_data;
17831 +
17832 +       vc_data.usecnt = atomic_read(&vxi->vx_usecnt);
17833 +       vc_data.tasks = atomic_read(&vxi->vx_tasks);
17834 +
17835 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
17836 +               return -EFAULT;
17837 +       return 0;
17838 +}
17839 +
17840 +
17841 +/* context functions */
17842 +
17843 +int vc_ctx_create(uint32_t xid, void __user *data)
17844 +{
17845 +       struct vcmd_ctx_create vc_data = { .flagword = VXF_INIT_SET };
17846 +       struct vx_info *new_vxi;
17847 +       int ret;
17848 +
17849 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
17850 +               return -EFAULT;
17851 +
17852 +       if ((xid > MAX_S_CONTEXT) || (xid < 2))
17853 +               return -EINVAL;
17854 +
17855 +       new_vxi = __create_vx_info(xid);
17856 +       if (IS_ERR(new_vxi))
17857 +               return PTR_ERR(new_vxi);
17858 +
17859 +       /* initial flags */
17860 +       new_vxi->vx_flags = vc_data.flagword;
17861 +
17862 +       ret = -ENOEXEC;
17863 +       if (vs_state_change(new_vxi, VSC_STARTUP))
17864 +               goto out;
17865 +
17866 +       ret = vx_migrate_task(current, new_vxi, (!data));
17867 +       if (ret)
17868 +               goto out;
17869 +
17870 +       /* return context id on success */
17871 +       ret = new_vxi->vx_id;
17872 +
17873 +       /* get a reference for persistent contexts */
17874 +       if ((vc_data.flagword & VXF_PERSISTENT))
17875 +               vx_set_persistent(new_vxi);
17876 +out:
17877 +       release_vx_info(new_vxi, NULL);
17878 +       put_vx_info(new_vxi);
17879 +       return ret;
17880 +}
17881 +
17882 +
17883 +int vc_ctx_migrate(struct vx_info *vxi, void __user *data)
17884 +{
17885 +       struct vcmd_ctx_migrate vc_data = { .flagword = 0 };
17886 +       int ret;
17887 +
17888 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
17889 +               return -EFAULT;
17890 +
17891 +       ret = vx_migrate_task(current, vxi, 0);
17892 +       if (ret)
17893 +               return ret;
17894 +       if (vc_data.flagword & VXM_SET_INIT)
17895 +               ret = vx_set_init(vxi, current);
17896 +       if (ret)
17897 +               return ret;
17898 +       if (vc_data.flagword & VXM_SET_REAPER)
17899 +               ret = vx_set_reaper(vxi, current);
17900 +       return ret;
17901 +}
17902 +
17903 +
17904 +int vc_get_cflags(struct vx_info *vxi, void __user *data)
17905 +{
17906 +       struct vcmd_ctx_flags_v0 vc_data;
17907 +
17908 +       vc_data.flagword = vxi->vx_flags;
17909 +
17910 +       /* special STATE flag handling */
17911 +       vc_data.mask = vs_mask_flags(~0ULL, vxi->vx_flags, VXF_ONE_TIME);
17912 +
17913 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
17914 +               return -EFAULT;
17915 +       return 0;
17916 +}
17917 +
17918 +int vc_set_cflags(struct vx_info *vxi, void __user *data)
17919 +{
17920 +       struct vcmd_ctx_flags_v0 vc_data;
17921 +       uint64_t mask, trigger;
17922 +
17923 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
17924 +               return -EFAULT;
17925 +
17926 +       /* special STATE flag handling */
17927 +       mask = vs_mask_mask(vc_data.mask, vxi->vx_flags, VXF_ONE_TIME);
17928 +       trigger = (mask & vxi->vx_flags) ^ (mask & vc_data.flagword);
17929 +
17930 +       if (vxi == current->vx_info) {
17931 +               /* if (trigger & VXF_STATE_SETUP)
17932 +                       vx_mask_cap_bset(vxi, current); */
17933 +               if (trigger & VXF_STATE_INIT) {
17934 +                       int ret;
17935 +
17936 +                       ret = vx_set_init(vxi, current);
17937 +                       if (ret)
17938 +                               return ret;
17939 +                       ret = vx_set_reaper(vxi, current);
17940 +                       if (ret)
17941 +                               return ret;
17942 +               }
17943 +       }
17944 +
17945 +       vxi->vx_flags = vs_mask_flags(vxi->vx_flags,
17946 +               vc_data.flagword, mask);
17947 +       if (trigger & VXF_PERSISTENT)
17948 +               vx_update_persistent(vxi);
17949 +
17950 +       return 0;
17951 +}
17952 +
17953 +
17954 +static inline uint64_t caps_from_cap_t(kernel_cap_t c)
17955 +{
17956 +       uint64_t v = c.cap[0] | ((uint64_t)c.cap[1] << 32);
17957 +
17958 +       // printk("caps_from_cap_t(%08x:%08x) = %016llx\n", c.cap[1], c.cap[0], v);
17959 +       return v;
17960 +}
17961 +
17962 +static inline kernel_cap_t cap_t_from_caps(uint64_t v)
17963 +{
17964 +       kernel_cap_t c = __cap_empty_set;
17965 +
17966 +       c.cap[0] = v & 0xFFFFFFFF;
17967 +       c.cap[1] = (v >> 32) & 0xFFFFFFFF;
17968 +
17969 +       // printk("cap_t_from_caps(%016llx) = %08x:%08x\n", v, c.cap[1], c.cap[0]);
17970 +       return c;
17971 +}
17972 +
17973 +
17974 +static int do_get_caps(struct vx_info *vxi, uint64_t *bcaps, uint64_t *ccaps)
17975 +{
17976 +       if (bcaps)
17977 +               *bcaps = caps_from_cap_t(vxi->vx_bcaps);
17978 +       if (ccaps)
17979 +               *ccaps = vxi->vx_ccaps;
17980 +
17981 +       return 0;
17982 +}
17983 +
17984 +int vc_get_ccaps(struct vx_info *vxi, void __user *data)
17985 +{
17986 +       struct vcmd_ctx_caps_v1 vc_data;
17987 +       int ret;
17988 +
17989 +       ret = do_get_caps(vxi, NULL, &vc_data.ccaps);
17990 +       if (ret)
17991 +               return ret;
17992 +       vc_data.cmask = ~0ULL;
17993 +
17994 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
17995 +               return -EFAULT;
17996 +       return 0;
17997 +}
17998 +
17999 +static int do_set_caps(struct vx_info *vxi,
18000 +       uint64_t bcaps, uint64_t bmask, uint64_t ccaps, uint64_t cmask)
18001 +{
18002 +       uint64_t bcold = caps_from_cap_t(vxi->vx_bcaps);
18003 +
18004 +#if 0
18005 +       printk("do_set_caps(%16llx, %16llx, %16llx, %16llx)\n",
18006 +               bcaps, bmask, ccaps, cmask);
18007 +#endif
18008 +       vxi->vx_bcaps = cap_t_from_caps(
18009 +               vs_mask_flags(bcold, bcaps, bmask));
18010 +       vxi->vx_ccaps = vs_mask_flags(vxi->vx_ccaps, ccaps, cmask);
18011 +
18012 +       return 0;
18013 +}
18014 +
18015 +int vc_set_ccaps(struct vx_info *vxi, void __user *data)
18016 +{
18017 +       struct vcmd_ctx_caps_v1 vc_data;
18018 +
18019 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18020 +               return -EFAULT;
18021 +
18022 +       return do_set_caps(vxi, 0, 0, vc_data.ccaps, vc_data.cmask);
18023 +}
18024 +
18025 +int vc_get_bcaps(struct vx_info *vxi, void __user *data)
18026 +{
18027 +       struct vcmd_bcaps vc_data;
18028 +       int ret;
18029 +
18030 +       ret = do_get_caps(vxi, &vc_data.bcaps, NULL);
18031 +       if (ret)
18032 +               return ret;
18033 +       vc_data.bmask = ~0ULL;
18034 +
18035 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
18036 +               return -EFAULT;
18037 +       return 0;
18038 +}
18039 +
18040 +int vc_set_bcaps(struct vx_info *vxi, void __user *data)
18041 +{
18042 +       struct vcmd_bcaps vc_data;
18043 +
18044 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18045 +               return -EFAULT;
18046 +
18047 +       return do_set_caps(vxi, vc_data.bcaps, vc_data.bmask, 0, 0);
18048 +}
18049 +
18050 +
18051 +int vc_get_badness(struct vx_info *vxi, void __user *data)
18052 +{
18053 +       struct vcmd_badness_v0 vc_data;
18054 +
18055 +       vc_data.bias = vxi->vx_badness_bias;
18056 +
18057 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
18058 +               return -EFAULT;
18059 +       return 0;
18060 +}
18061 +
18062 +int vc_set_badness(struct vx_info *vxi, void __user *data)
18063 +{
18064 +       struct vcmd_badness_v0 vc_data;
18065 +
18066 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18067 +               return -EFAULT;
18068 +
18069 +       vxi->vx_badness_bias = vc_data.bias;
18070 +       return 0;
18071 +}
18072 +
18073 +#include <linux/module.h>
18074 +
18075 +EXPORT_SYMBOL_GPL(free_vx_info);
18076 +
18077 diff -NurpP --minimal linux-2.6.29/kernel/vserver/cvirt.c linux-2.6.29-vs2.3.0.36.9-pre2/kernel/vserver/cvirt.c
18078 --- linux-2.6.29/kernel/vserver/cvirt.c 1970-01-01 01:00:00.000000000 +0100
18079 +++ linux-2.6.29-vs2.3.0.36.9-pre2/kernel/vserver/cvirt.c       2009-02-22 22:54:26.000000000 +0100
18080 @@ -0,0 +1,300 @@
18081 +/*
18082 + *  linux/kernel/vserver/cvirt.c
18083 + *
18084 + *  Virtual Server: Context Virtualization
18085 + *
18086 + *  Copyright (C) 2004-2007  Herbert Pötzl
18087 + *
18088 + *  V0.01  broken out from limit.c
18089 + *  V0.02  added utsname stuff
18090 + *  V0.03  changed vcmds to vxi arg
18091 + *
18092 + */
18093 +
18094 +#include <linux/types.h>
18095 +#include <linux/utsname.h>
18096 +#include <linux/vs_cvirt.h>
18097 +#include <linux/vserver/switch.h>
18098 +#include <linux/vserver/cvirt_cmd.h>
18099 +
18100 +#include <asm/uaccess.h>
18101 +
18102 +
18103 +void vx_vsi_uptime(struct timespec *uptime, struct timespec *idle)
18104 +{
18105 +       struct vx_info *vxi = current->vx_info;
18106 +
18107 +       set_normalized_timespec(uptime,
18108 +               uptime->tv_sec - vxi->cvirt.bias_uptime.tv_sec,
18109 +               uptime->tv_nsec - vxi->cvirt.bias_uptime.tv_nsec);
18110 +       if (!idle)
18111 +               return;
18112 +       set_normalized_timespec(idle,
18113 +               idle->tv_sec - vxi->cvirt.bias_idle.tv_sec,
18114 +               idle->tv_nsec - vxi->cvirt.bias_idle.tv_nsec);
18115 +       return;
18116 +}
18117 +
18118 +uint64_t vx_idle_jiffies(void)
18119 +{
18120 +       return init_task.utime + init_task.stime;
18121 +}
18122 +
18123 +
18124 +
18125 +static inline uint32_t __update_loadavg(uint32_t load,
18126 +       int wsize, int delta, int n)
18127 +{
18128 +       unsigned long long calc, prev;
18129 +
18130 +       /* just set it to n */
18131 +       if (unlikely(delta >= wsize))
18132 +               return (n << FSHIFT);
18133 +
18134 +       calc = delta * n;
18135 +       calc <<= FSHIFT;
18136 +       prev = (wsize - delta);
18137 +       prev *= load;
18138 +       calc += prev;
18139 +       do_div(calc, wsize);
18140 +       return calc;
18141 +}
18142 +
18143 +
18144 +void vx_update_load(struct vx_info *vxi)
18145 +{
18146 +       uint32_t now, last, delta;
18147 +       unsigned int nr_running, nr_uninterruptible;
18148 +       unsigned int total;
18149 +       unsigned long flags;
18150 +
18151 +       spin_lock_irqsave(&vxi->cvirt.load_lock, flags);
18152 +
18153 +       now = jiffies;
18154 +       last = vxi->cvirt.load_last;
18155 +       delta = now - last;
18156 +
18157 +       if (delta < 5*HZ)
18158 +               goto out;
18159 +
18160 +       nr_running = atomic_read(&vxi->cvirt.nr_running);
18161 +       nr_uninterruptible = atomic_read(&vxi->cvirt.nr_uninterruptible);
18162 +       total = nr_running + nr_uninterruptible;
18163 +
18164 +       vxi->cvirt.load[0] = __update_loadavg(vxi->cvirt.load[0],
18165 +               60*HZ, delta, total);
18166 +       vxi->cvirt.load[1] = __update_loadavg(vxi->cvirt.load[1],
18167 +               5*60*HZ, delta, total);
18168 +       vxi->cvirt.load[2] = __update_loadavg(vxi->cvirt.load[2],
18169 +               15*60*HZ, delta, total);
18170 +
18171 +       vxi->cvirt.load_last = now;
18172 +out:
18173 +       atomic_inc(&vxi->cvirt.load_updates);
18174 +       spin_unlock_irqrestore(&vxi->cvirt.load_lock, flags);
18175 +}
18176 +
18177 +
18178 +/*
18179 + * Commands to do_syslog:
18180 + *
18181 + *      0 -- Close the log.  Currently a NOP.
18182 + *      1 -- Open the log. Currently a NOP.
18183 + *      2 -- Read from the log.
18184 + *      3 -- Read all messages remaining in the ring buffer.
18185 + *      4 -- Read and clear all messages remaining in the ring buffer
18186 + *      5 -- Clear ring buffer.
18187 + *      6 -- Disable printk's to console
18188 + *      7 -- Enable printk's to console
18189 + *      8 -- Set level of messages printed to console
18190 + *      9 -- Return number of unread characters in the log buffer
18191 + *     10 -- Return size of the log buffer
18192 + */
18193 +int vx_do_syslog(int type, char __user *buf, int len)
18194 +{
18195 +       int error = 0;
18196 +       int do_clear = 0;
18197 +       struct vx_info *vxi = current->vx_info;
18198 +       struct _vx_syslog *log;
18199 +
18200 +       if (!vxi)
18201 +               return -EINVAL;
18202 +       log = &vxi->cvirt.syslog;
18203 +
18204 +       switch (type) {
18205 +       case 0:         /* Close log */
18206 +       case 1:         /* Open log */
18207 +               break;
18208 +       case 2:         /* Read from log */
18209 +               error = wait_event_interruptible(log->log_wait,
18210 +                       (log->log_start - log->log_end));
18211 +               if (error)
18212 +                       break;
18213 +               spin_lock_irq(&log->logbuf_lock);
18214 +               spin_unlock_irq(&log->logbuf_lock);
18215 +               break;
18216 +       case 4:         /* Read/clear last kernel messages */
18217 +               do_clear = 1;
18218 +               /* fall through */
18219 +       case 3:         /* Read last kernel messages */
18220 +               return 0;
18221 +
18222 +       case 5:         /* Clear ring buffer */
18223 +               return 0;
18224 +
18225 +       case 6:         /* Disable logging to console */
18226 +       case 7:         /* Enable logging to console */
18227 +       case 8:         /* Set level of messages printed to console */
18228 +               break;
18229 +
18230 +       case 9:         /* Number of chars in the log buffer */
18231 +               return 0;
18232 +       case 10:        /* Size of the log buffer */
18233 +               return 0;
18234 +       default:
18235 +               error = -EINVAL;
18236 +               break;
18237 +       }
18238 +       return error;
18239 +}
18240 +
18241 +
18242 +/* virtual host info names */
18243 +
18244 +static char *vx_vhi_name(struct vx_info *vxi, int id)
18245 +{
18246 +       struct nsproxy *nsproxy;
18247 +       struct uts_namespace *uts;
18248 +
18249 +       if (id == VHIN_CONTEXT)
18250 +               return vxi->vx_name;
18251 +
18252 +       nsproxy = vxi->vx_nsproxy[0];
18253 +       if (!nsproxy)
18254 +               return NULL;
18255 +
18256 +       uts = nsproxy->uts_ns;
18257 +       if (!uts)
18258 +               return NULL;
18259 +
18260 +       switch (id) {
18261 +       case VHIN_SYSNAME:
18262 +               return uts->name.sysname;
18263 +       case VHIN_NODENAME:
18264 +               return uts->name.nodename;
18265 +       case VHIN_RELEASE:
18266 +               return uts->name.release;
18267 +       case VHIN_VERSION:
18268 +               return uts->name.version;
18269 +       case VHIN_MACHINE:
18270 +               return uts->name.machine;
18271 +       case VHIN_DOMAINNAME:
18272 +               return uts->name.domainname;
18273 +       default:
18274 +               return NULL;
18275 +       }
18276 +       return NULL;
18277 +}
18278 +
18279 +int vc_set_vhi_name(struct vx_info *vxi, void __user *data)
18280 +{
18281 +       struct vcmd_vhi_name_v0 vc_data;
18282 +       char *name;
18283 +
18284 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18285 +               return -EFAULT;
18286 +
18287 +       name = vx_vhi_name(vxi, vc_data.field);
18288 +       if (!name)
18289 +               return -EINVAL;
18290 +
18291 +       memcpy(name, vc_data.name, 65);
18292 +       return 0;
18293 +}
18294 +
18295 +int vc_get_vhi_name(struct vx_info *vxi, void __user *data)
18296 +{
18297 +       struct vcmd_vhi_name_v0 vc_data;
18298 +       char *name;
18299 +
18300 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18301 +               return -EFAULT;
18302 +
18303 +       name = vx_vhi_name(vxi, vc_data.field);
18304 +       if (!name)
18305 +               return -EINVAL;
18306 +
18307 +       memcpy(vc_data.name, name, 65);
18308 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
18309 +               return -EFAULT;
18310 +       return 0;
18311 +}
18312 +
18313 +
18314 +int vc_virt_stat(struct vx_info *vxi, void __user *data)
18315 +{
18316 +       struct vcmd_virt_stat_v0 vc_data;
18317 +       struct _vx_cvirt *cvirt = &vxi->cvirt;
18318 +       struct timespec uptime;
18319 +
18320 +       do_posix_clock_monotonic_gettime(&uptime);
18321 +       set_normalized_timespec(&uptime,
18322 +               uptime.tv_sec - cvirt->bias_uptime.tv_sec,
18323 +               uptime.tv_nsec - cvirt->bias_uptime.tv_nsec);
18324 +
18325 +       vc_data.offset = timeval_to_ns(&cvirt->bias_tv);
18326 +       vc_data.uptime = timespec_to_ns(&uptime);
18327 +       vc_data.nr_threads = atomic_read(&cvirt->nr_threads);
18328 +       vc_data.nr_running = atomic_read(&cvirt->nr_running);
18329 +       vc_data.nr_uninterruptible = atomic_read(&cvirt->nr_uninterruptible);
18330 +       vc_data.nr_onhold = atomic_read(&cvirt->nr_onhold);
18331 +       vc_data.nr_forks = atomic_read(&cvirt->total_forks);
18332 +       vc_data.load[0] = cvirt->load[0];
18333 +       vc_data.load[1] = cvirt->load[1];
18334 +       vc_data.load[2] = cvirt->load[2];
18335 +
18336 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
18337 +               return -EFAULT;
18338 +       return 0;
18339 +}
18340 +
18341 +
18342 +#ifdef CONFIG_VSERVER_VTIME
18343 +
18344 +/* virtualized time base */
18345 +
18346 +void vx_gettimeofday(struct timeval *tv)
18347 +{
18348 +       do_gettimeofday(tv);
18349 +       if (!vx_flags(VXF_VIRT_TIME, 0))
18350 +               return;
18351 +
18352 +       tv->tv_sec += current->vx_info->cvirt.bias_tv.tv_sec;
18353 +       tv->tv_usec += current->vx_info->cvirt.bias_tv.tv_usec;
18354 +
18355 +       if (tv->tv_usec >= USEC_PER_SEC) {
18356 +               tv->tv_sec++;
18357 +               tv->tv_usec -= USEC_PER_SEC;
18358 +       } else if (tv->tv_usec < 0) {
18359 +               tv->tv_sec--;
18360 +               tv->tv_usec += USEC_PER_SEC;
18361 +       }
18362 +}
18363 +
18364 +int vx_settimeofday(struct timespec *ts)
18365 +{
18366 +       struct timeval tv;
18367 +
18368 +       if (!vx_flags(VXF_VIRT_TIME, 0))
18369 +               return do_settimeofday(ts);
18370 +
18371 +       do_gettimeofday(&tv);
18372 +       current->vx_info->cvirt.bias_tv.tv_sec =
18373 +               ts->tv_sec - tv.tv_sec;
18374 +       current->vx_info->cvirt.bias_tv.tv_usec =
18375 +               (ts->tv_nsec/NSEC_PER_USEC) - tv.tv_usec;
18376 +       return 0;
18377 +}
18378 +
18379 +#endif
18380 +
18381 diff -NurpP --minimal linux-2.6.29/kernel/vserver/cvirt_init.h linux-2.6.29-vs2.3.0.36.9-pre2/kernel/vserver/cvirt_init.h
18382 --- linux-2.6.29/kernel/vserver/cvirt_init.h    1970-01-01 01:00:00.000000000 +0100
18383 +++ linux-2.6.29-vs2.3.0.36.9-pre2/kernel/vserver/cvirt_init.h  2009-02-22 22:54:26.000000000 +0100
18384 @@ -0,0 +1,69 @@
18385 +
18386 +
18387 +extern uint64_t vx_idle_jiffies(void);
18388 +
18389 +static inline void vx_info_init_cvirt(struct _vx_cvirt *cvirt)
18390 +{
18391 +       uint64_t idle_jiffies = vx_idle_jiffies();
18392 +       uint64_t nsuptime;
18393 +
18394 +       do_posix_clock_monotonic_gettime(&cvirt->bias_uptime);
18395 +       nsuptime = (unsigned long long)cvirt->bias_uptime.tv_sec
18396 +               * NSEC_PER_SEC + cvirt->bias_uptime.tv_nsec;
18397 +       cvirt->bias_clock = nsec_to_clock_t(nsuptime);
18398 +       cvirt->bias_tv.tv_sec = 0;
18399 +       cvirt->bias_tv.tv_usec = 0;
18400 +
18401 +       jiffies_to_timespec(idle_jiffies, &cvirt->bias_idle);
18402 +       atomic_set(&cvirt->nr_threads, 0);
18403 +       atomic_set(&cvirt->nr_running, 0);
18404 +       atomic_set(&cvirt->nr_uninterruptible, 0);
18405 +       atomic_set(&cvirt->nr_onhold, 0);
18406 +
18407 +       spin_lock_init(&cvirt->load_lock);
18408 +       cvirt->load_last = jiffies;
18409 +       atomic_set(&cvirt->load_updates, 0);
18410 +       cvirt->load[0] = 0;
18411 +       cvirt->load[1] = 0;
18412 +       cvirt->load[2] = 0;
18413 +       atomic_set(&cvirt->total_forks, 0);
18414 +
18415 +       spin_lock_init(&cvirt->syslog.logbuf_lock);
18416 +       init_waitqueue_head(&cvirt->syslog.log_wait);
18417 +       cvirt->syslog.log_start = 0;
18418 +       cvirt->syslog.log_end = 0;
18419 +       cvirt->syslog.con_start = 0;
18420 +       cvirt->syslog.logged_chars = 0;
18421 +}
18422 +
18423 +static inline
18424 +void vx_info_init_cvirt_pc(struct _vx_cvirt_pc *cvirt_pc, int cpu)
18425 +{
18426 +       // cvirt_pc->cpustat = { 0 };
18427 +}
18428 +
18429 +static inline void vx_info_exit_cvirt(struct _vx_cvirt *cvirt)
18430 +{
18431 +       int value;
18432 +
18433 +       vxwprintk_xid((value = atomic_read(&cvirt->nr_threads)),
18434 +               "!!! cvirt: %p[nr_threads] = %d on exit.",
18435 +               cvirt, value);
18436 +       vxwprintk_xid((value = atomic_read(&cvirt->nr_running)),
18437 +               "!!! cvirt: %p[nr_running] = %d on exit.",
18438 +               cvirt, value);
18439 +       vxwprintk_xid((value = atomic_read(&cvirt->nr_uninterruptible)),
18440 +               "!!! cvirt: %p[nr_uninterruptible] = %d on exit.",
18441 +               cvirt, value);
18442 +       vxwprintk_xid((value = atomic_read(&cvirt->nr_onhold)),
18443 +               "!!! cvirt: %p[nr_onhold] = %d on exit.",
18444 +               cvirt, value);
18445 +       return;
18446 +}
18447 +
18448 +static inline
18449 +void vx_info_exit_cvirt_pc(struct _vx_cvirt_pc *cvirt_pc, int cpu)
18450 +{
18451 +       return;
18452 +}
18453 +
18454 diff -NurpP --minimal linux-2.6.29/kernel/vserver/cvirt_proc.h linux-2.6.29-vs2.3.0.36.9-pre2/kernel/vserver/cvirt_proc.h
18455 --- linux-2.6.29/kernel/vserver/cvirt_proc.h    1970-01-01 01:00:00.000000000 +0100
18456 +++ linux-2.6.29-vs2.3.0.36.9-pre2/kernel/vserver/cvirt_proc.h  2009-02-22 22:54:26.000000000 +0100
18457 @@ -0,0 +1,135 @@
18458 +#ifndef _VX_CVIRT_PROC_H
18459 +#define _VX_CVIRT_PROC_H
18460 +
18461 +#include <linux/nsproxy.h>
18462 +#include <linux/mnt_namespace.h>
18463 +#include <linux/ipc_namespace.h>
18464 +#include <linux/utsname.h>
18465 +#include <linux/ipc.h>
18466 +
18467 +
18468 +static inline
18469 +int vx_info_proc_nsproxy(struct nsproxy *nsproxy, char *buffer)
18470 +{
18471 +       struct mnt_namespace *ns;
18472 +       struct uts_namespace *uts;
18473 +       struct ipc_namespace *ipc;
18474 +       struct path path;
18475 +       char *pstr, *root;
18476 +       int length = 0;
18477 +
18478 +       if (!nsproxy)
18479 +               goto out;
18480 +
18481 +       length += sprintf(buffer + length,
18482 +               "NSProxy:\t%p [%p,%p,%p]\n",
18483 +               nsproxy, nsproxy->mnt_ns,
18484 +               nsproxy->uts_ns, nsproxy->ipc_ns);
18485 +
18486 +       ns = nsproxy->mnt_ns;
18487 +       if (!ns)
18488 +               goto skip_ns;
18489 +
18490 +       pstr = kmalloc(PATH_MAX, GFP_KERNEL);
18491 +       if (!pstr)
18492 +               goto skip_ns;
18493 +
18494 +       path.mnt = ns->root;
18495 +       path.dentry = ns->root->mnt_root;
18496 +       root = d_path(&path, pstr, PATH_MAX - 2);
18497 +       length += sprintf(buffer + length,
18498 +               "Namespace:\t%p [#%u]\n"
18499 +               "RootPath:\t%s\n",
18500 +               ns, atomic_read(&ns->count),
18501 +               root);
18502 +       kfree(pstr);
18503 +skip_ns:
18504 +
18505 +       uts = nsproxy->uts_ns;
18506 +       if (!uts)
18507 +               goto skip_uts;
18508 +
18509 +       length += sprintf(buffer + length,
18510 +               "SysName:\t%.*s\n"
18511 +               "NodeName:\t%.*s\n"
18512 +               "Release:\t%.*s\n"
18513 +               "Version:\t%.*s\n"
18514 +               "Machine:\t%.*s\n"
18515 +               "DomainName:\t%.*s\n",
18516 +               __NEW_UTS_LEN, uts->name.sysname,
18517 +               __NEW_UTS_LEN, uts->name.nodename,
18518 +               __NEW_UTS_LEN, uts->name.release,
18519 +               __NEW_UTS_LEN, uts->name.version,
18520 +               __NEW_UTS_LEN, uts->name.machine,
18521 +               __NEW_UTS_LEN, uts->name.domainname);
18522 +skip_uts:
18523 +
18524 +       ipc = nsproxy->ipc_ns;
18525 +       if (!ipc)
18526 +               goto skip_ipc;
18527 +
18528 +       length += sprintf(buffer + length,
18529 +               "SEMS:\t\t%d %d %d %d  %d\n"
18530 +               "MSG:\t\t%d %d %d\n"
18531 +               "SHM:\t\t%lu %lu  %d %d\n",
18532 +               ipc->sem_ctls[0], ipc->sem_ctls[1],
18533 +               ipc->sem_ctls[2], ipc->sem_ctls[3],
18534 +               ipc->used_sems,
18535 +               ipc->msg_ctlmax, ipc->msg_ctlmnb, ipc->msg_ctlmni,
18536 +               (unsigned long)ipc->shm_ctlmax,
18537 +               (unsigned long)ipc->shm_ctlall,
18538 +               ipc->shm_ctlmni, ipc->shm_tot);
18539 +skip_ipc:
18540 +out:
18541 +       return length;
18542 +}
18543 +
18544 +
18545 +#include <linux/sched.h>
18546 +
18547 +#define LOAD_INT(x) ((x) >> FSHIFT)
18548 +#define LOAD_FRAC(x) LOAD_INT(((x) & (FIXED_1 - 1)) * 100)
18549 +
18550 +static inline
18551 +int vx_info_proc_cvirt(struct _vx_cvirt *cvirt, char *buffer)
18552 +{
18553 +       int length = 0;
18554 +       int a, b, c;
18555 +
18556 +       length += sprintf(buffer + length,
18557 +               "BiasUptime:\t%lu.%02lu\n",
18558 +               (unsigned long)cvirt->bias_uptime.tv_sec,
18559 +               (cvirt->bias_uptime.tv_nsec / (NSEC_PER_SEC / 100)));
18560 +
18561 +       a = cvirt->load[0] + (FIXED_1 / 200);
18562 +       b = cvirt->load[1] + (FIXED_1 / 200);
18563 +       c = cvirt->load[2] + (FIXED_1 / 200);
18564 +       length += sprintf(buffer + length,
18565 +               "nr_threads:\t%d\n"
18566 +               "nr_running:\t%d\n"
18567 +               "nr_unintr:\t%d\n"
18568 +               "nr_onhold:\t%d\n"
18569 +               "load_updates:\t%d\n"
18570 +               "loadavg:\t%d.%02d %d.%02d %d.%02d\n"
18571 +               "total_forks:\t%d\n",
18572 +               atomic_read(&cvirt->nr_threads),
18573 +               atomic_read(&cvirt->nr_running),
18574 +               atomic_read(&cvirt->nr_uninterruptible),
18575 +               atomic_read(&cvirt->nr_onhold),
18576 +               atomic_read(&cvirt->load_updates),
18577 +               LOAD_INT(a), LOAD_FRAC(a),
18578 +               LOAD_INT(b), LOAD_FRAC(b),
18579 +               LOAD_INT(c), LOAD_FRAC(c),
18580 +               atomic_read(&cvirt->total_forks));
18581 +       return length;
18582 +}
18583 +
18584 +static inline
18585 +int vx_info_proc_cvirt_pc(struct _vx_cvirt_pc *cvirt_pc,
18586 +       char *buffer, int cpu)
18587 +{
18588 +       int length = 0;
18589 +       return length;
18590 +}
18591 +
18592 +#endif /* _VX_CVIRT_PROC_H */
18593 diff -NurpP --minimal linux-2.6.29/kernel/vserver/debug.c linux-2.6.29-vs2.3.0.36.9-pre2/kernel/vserver/debug.c
18594 --- linux-2.6.29/kernel/vserver/debug.c 1970-01-01 01:00:00.000000000 +0100
18595 +++ linux-2.6.29-vs2.3.0.36.9-pre2/kernel/vserver/debug.c       2009-02-22 22:54:26.000000000 +0100
18596 @@ -0,0 +1,32 @@
18597 +/*
18598 + *  kernel/vserver/debug.c
18599 + *
18600 + *  Copyright (C) 2005-2007 Herbert Pötzl
18601 + *
18602 + *  V0.01  vx_info dump support
18603 + *
18604 + */
18605 +
18606 +#include <linux/module.h>
18607 +
18608 +#include <linux/vserver/context.h>
18609 +
18610 +
18611 +void   dump_vx_info(struct vx_info *vxi, int level)
18612 +{
18613 +       printk("vx_info %p[#%d, %d.%d, %4x]\n", vxi, vxi->vx_id,
18614 +               atomic_read(&vxi->vx_usecnt),
18615 +               atomic_read(&vxi->vx_tasks),
18616 +               vxi->vx_state);
18617 +       if (level > 0) {
18618 +               __dump_vx_limit(&vxi->limit);
18619 +               __dump_vx_sched(&vxi->sched);
18620 +               __dump_vx_cvirt(&vxi->cvirt);
18621 +               __dump_vx_cacct(&vxi->cacct);
18622 +       }
18623 +       printk("---\n");
18624 +}
18625 +
18626 +
18627 +EXPORT_SYMBOL_GPL(dump_vx_info);
18628 +
18629 diff -NurpP --minimal linux-2.6.29/kernel/vserver/device.c linux-2.6.29-vs2.3.0.36.9-pre2/kernel/vserver/device.c
18630 --- linux-2.6.29/kernel/vserver/device.c        1970-01-01 01:00:00.000000000 +0100
18631 +++ linux-2.6.29-vs2.3.0.36.9-pre2/kernel/vserver/device.c      2009-02-22 22:54:26.000000000 +0100
18632 @@ -0,0 +1,443 @@
18633 +/*
18634 + *  linux/kernel/vserver/device.c
18635 + *
18636 + *  Linux-VServer: Device Support
18637 + *
18638 + *  Copyright (C) 2006  Herbert Pötzl
18639 + *  Copyright (C) 2007  Daniel Hokka Zakrisson
18640 + *
18641 + *  V0.01  device mapping basics
18642 + *  V0.02  added defaults
18643 + *
18644 + */
18645 +
18646 +#include <linux/slab.h>
18647 +#include <linux/rcupdate.h>
18648 +#include <linux/fs.h>
18649 +#include <linux/namei.h>
18650 +#include <linux/hash.h>
18651 +
18652 +#include <asm/errno.h>
18653 +#include <asm/uaccess.h>
18654 +#include <linux/vserver/base.h>
18655 +#include <linux/vserver/debug.h>
18656 +#include <linux/vserver/context.h>
18657 +#include <linux/vserver/device.h>
18658 +#include <linux/vserver/device_cmd.h>
18659 +
18660 +
18661 +#define DMAP_HASH_BITS 4
18662 +
18663 +
18664 +struct vs_mapping {
18665 +       union {
18666 +               struct hlist_node hlist;
18667 +               struct list_head list;
18668 +       } u;
18669 +#define dm_hlist       u.hlist
18670 +#define dm_list                u.list
18671 +       xid_t xid;
18672 +       dev_t device;
18673 +       struct vx_dmap_target target;
18674 +};
18675 +
18676 +
18677 +static struct hlist_head dmap_main_hash[1 << DMAP_HASH_BITS];
18678 +
18679 +static spinlock_t dmap_main_hash_lock = SPIN_LOCK_UNLOCKED;
18680 +
18681 +static struct vx_dmap_target dmap_defaults[2] = {
18682 +       { .flags = DATTR_OPEN },
18683 +       { .flags = DATTR_OPEN },
18684 +};
18685 +
18686 +
18687 +struct kmem_cache *dmap_cachep __read_mostly;
18688 +
18689 +int __init dmap_cache_init(void)
18690 +{
18691 +       dmap_cachep = kmem_cache_create("dmap_cache",
18692 +               sizeof(struct vs_mapping), 0,
18693 +               SLAB_HWCACHE_ALIGN|SLAB_PANIC, NULL);
18694 +       return 0;
18695 +}
18696 +
18697 +__initcall(dmap_cache_init);
18698 +
18699 +
18700 +static inline unsigned int __hashval(dev_t dev, int bits)
18701 +{
18702 +       return hash_long((unsigned long)dev, bits);
18703 +}
18704 +
18705 +
18706 +/*     __hash_mapping()
18707 + *     add the mapping to the hash table
18708 + */
18709 +static inline void __hash_mapping(struct vx_info *vxi, struct vs_mapping *vdm)
18710 +{
18711 +       spinlock_t *hash_lock = &dmap_main_hash_lock;
18712 +       struct hlist_head *head, *hash = dmap_main_hash;
18713 +       int device = vdm->device;
18714 +
18715 +       spin_lock(hash_lock);
18716 +       vxdprintk(VXD_CBIT(misc, 8), "__hash_mapping: %p[#%d] %08x:%08x",
18717 +               vxi, vxi ? vxi->vx_id : 0, device, vdm->target.target);
18718 +
18719 +       head = &hash[__hashval(device, DMAP_HASH_BITS)];
18720 +       hlist_add_head(&vdm->dm_hlist, head);
18721 +       spin_unlock(hash_lock);
18722 +}
18723 +
18724 +
18725 +static inline int __mode_to_default(umode_t mode)
18726 +{
18727 +       switch (mode) {
18728 +       case S_IFBLK:
18729 +               return 0;
18730 +       case S_IFCHR:
18731 +               return 1;
18732 +       default:
18733 +               BUG();
18734 +       }
18735 +}
18736 +
18737 +
18738 +/*     __set_default()
18739 + *     set a default
18740 + */
18741 +static inline void __set_default(struct vx_info *vxi, umode_t mode,
18742 +       struct vx_dmap_target *vdmt)
18743 +{
18744 +       spinlock_t *hash_lock = &dmap_main_hash_lock;
18745 +       spin_lock(hash_lock);
18746 +
18747 +       if (vxi)
18748 +               vxi->dmap.targets[__mode_to_default(mode)] = *vdmt;
18749 +       else
18750 +               dmap_defaults[__mode_to_default(mode)] = *vdmt;
18751 +
18752 +
18753 +       spin_unlock(hash_lock);
18754 +
18755 +       vxdprintk(VXD_CBIT(misc, 8), "__set_default: %p[#%u] %08x %04x",
18756 +                 vxi, vxi ? vxi->vx_id : 0, vdmt->target, vdmt->flags);
18757 +}
18758 +
18759 +
18760 +/*     __remove_default()
18761 + *     remove a default
18762 + */
18763 +static inline int __remove_default(struct vx_info *vxi, umode_t mode)
18764 +{
18765 +       spinlock_t *hash_lock = &dmap_main_hash_lock;
18766 +       spin_lock(hash_lock);
18767 +
18768 +       if (vxi)
18769 +               vxi->dmap.targets[__mode_to_default(mode)].flags = 0;
18770 +       else    /* remove == reset */
18771 +               dmap_defaults[__mode_to_default(mode)].flags = DATTR_OPEN | mode;
18772 +
18773 +       spin_unlock(hash_lock);
18774 +       return 0;
18775 +}
18776 +
18777 +
18778 +/*     __find_mapping()
18779 + *     find a mapping in the hash table
18780 + *
18781 + *     caller must hold hash_lock
18782 + */
18783 +static inline int __find_mapping(xid_t xid, dev_t device, umode_t mode,
18784 +       struct vs_mapping **local, struct vs_mapping **global)
18785 +{
18786 +       struct hlist_head *hash = dmap_main_hash;
18787 +       struct hlist_head *head = &hash[__hashval(device, DMAP_HASH_BITS)];
18788 +       struct hlist_node *pos;
18789 +       struct vs_mapping *vdm;
18790 +
18791 +       *local = NULL;
18792 +       if (global)
18793 +               *global = NULL;
18794 +
18795 +       hlist_for_each(pos, head) {
18796 +               vdm = hlist_entry(pos, struct vs_mapping, dm_hlist);
18797 +
18798 +               if ((vdm->device == device) &&
18799 +                       !((vdm->target.flags ^ mode) & S_IFMT)) {
18800 +                       if (vdm->xid == xid) {
18801 +                               *local = vdm;
18802 +                               return 1;
18803 +                       } else if (global && vdm->xid == 0)
18804 +                               *global = vdm;
18805 +               }
18806 +       }
18807 +
18808 +       if (global && *global)
18809 +               return 0;
18810 +       else
18811 +               return -ENOENT;
18812 +}
18813 +
18814 +
18815 +/*     __lookup_mapping()
18816 + *     find a mapping and store the result in target and flags
18817 + */
18818 +static inline int __lookup_mapping(struct vx_info *vxi,
18819 +       dev_t device, dev_t *target, int *flags, umode_t mode)
18820 +{
18821 +       spinlock_t *hash_lock = &dmap_main_hash_lock;
18822 +       struct vs_mapping *vdm, *global;
18823 +       struct vx_dmap_target *vdmt;
18824 +       int ret = 0;
18825 +       xid_t xid = vxi->vx_id;
18826 +       int index;
18827 +
18828 +       spin_lock(hash_lock);
18829 +       if (__find_mapping(xid, device, mode, &vdm, &global) > 0) {
18830 +               ret = 1;
18831 +               vdmt = &vdm->target;
18832 +               goto found;
18833 +       }
18834 +
18835 +       index = __mode_to_default(mode);
18836 +       if (vxi && vxi->dmap.targets[index].flags) {
18837 +               ret = 2;
18838 +               vdmt = &vxi->dmap.targets[index];
18839 +       } else if (global) {
18840 +               ret = 3;
18841 +               vdmt = &global->target;
18842 +               goto found;
18843 +       } else {
18844 +               ret = 4;
18845 +               vdmt = &dmap_defaults[index];
18846 +       }
18847 +
18848 +found:
18849 +       if (target && (vdmt->flags & DATTR_REMAP))
18850 +               *target = vdmt->target;
18851 +       else if (target)
18852 +               *target = device;
18853 +       if (flags)
18854 +               *flags = vdmt->flags;
18855 +
18856 +       spin_unlock(hash_lock);
18857 +
18858 +       return ret;
18859 +}
18860 +
18861 +
18862 +/*     __remove_mapping()
18863 + *     remove a mapping from the hash table
18864 + */
18865 +static inline int __remove_mapping(struct vx_info *vxi, dev_t device,
18866 +       umode_t mode)
18867 +{
18868 +       spinlock_t *hash_lock = &dmap_main_hash_lock;
18869 +       struct vs_mapping *vdm = NULL;
18870 +       int ret = 0;
18871 +
18872 +       spin_lock(hash_lock);
18873 +
18874 +       ret = __find_mapping((vxi ? vxi->vx_id : 0), device, mode, &vdm,
18875 +               NULL);
18876 +       vxdprintk(VXD_CBIT(misc, 8), "__remove_mapping: %p[#%d] %08x %04x",
18877 +               vxi, vxi ? vxi->vx_id : 0, device, mode);
18878 +       if (ret < 0)
18879 +               goto out;
18880 +       hlist_del(&vdm->dm_hlist);
18881 +
18882 +out:
18883 +       spin_unlock(hash_lock);
18884 +       if (vdm)
18885 +               kmem_cache_free(dmap_cachep, vdm);
18886 +       return ret;
18887 +}
18888 +
18889 +
18890 +
18891 +int vs_map_device(struct vx_info *vxi,
18892 +       dev_t device, dev_t *target, umode_t mode)
18893 +{
18894 +       int ret, flags = DATTR_MASK;
18895 +
18896 +       if (!vxi) {
18897 +               if (target)
18898 +                       *target = device;
18899 +               goto out;
18900 +       }
18901 +       ret = __lookup_mapping(vxi, device, target, &flags, mode);
18902 +       vxdprintk(VXD_CBIT(misc, 8), "vs_map_device: %08x target: %08x flags: %04x mode: %04x mapped=%d",
18903 +               device, target ? *target : 0, flags, mode, ret);
18904 +out:
18905 +       return (flags & DATTR_MASK);
18906 +}
18907 +
18908 +
18909 +
18910 +static int do_set_mapping(struct vx_info *vxi,
18911 +       dev_t device, dev_t target, int flags, umode_t mode)
18912 +{
18913 +       if (device) {
18914 +               struct vs_mapping *new;
18915 +
18916 +               new = kmem_cache_alloc(dmap_cachep, GFP_KERNEL);
18917 +               if (!new)
18918 +                       return -ENOMEM;
18919 +
18920 +               INIT_HLIST_NODE(&new->dm_hlist);
18921 +               new->device = device;
18922 +               new->target.target = target;
18923 +               new->target.flags = flags | mode;
18924 +               new->xid = (vxi ? vxi->vx_id : 0);
18925 +
18926 +               vxdprintk(VXD_CBIT(misc, 8), "do_set_mapping: %08x target: %08x flags: %04x", device, target, flags);
18927 +               __hash_mapping(vxi, new);
18928 +       } else {
18929 +               struct vx_dmap_target new = {
18930 +                       .target = target,
18931 +                       .flags = flags | mode,
18932 +               };
18933 +               __set_default(vxi, mode, &new);
18934 +       }
18935 +       return 0;
18936 +}
18937 +
18938 +
18939 +static int do_unset_mapping(struct vx_info *vxi,
18940 +       dev_t device, dev_t target, int flags, umode_t mode)
18941 +{
18942 +       int ret = -EINVAL;
18943 +
18944 +       if (device) {
18945 +               ret = __remove_mapping(vxi, device, mode);
18946 +               if (ret < 0)
18947 +                       goto out;
18948 +       } else {
18949 +               ret = __remove_default(vxi, mode);
18950 +               if (ret < 0)
18951 +                       goto out;
18952 +       }
18953 +
18954 +out:
18955 +       return ret;
18956 +}
18957 +
18958 +
18959 +static inline int __user_device(const char __user *name, dev_t *dev,
18960 +       umode_t *mode)
18961 +{
18962 +       struct nameidata nd;
18963 +       int ret;
18964 +
18965 +       if (!name) {
18966 +               *dev = 0;
18967 +               return 0;
18968 +       }
18969 +       ret = user_lpath(name, &nd.path);
18970 +       if (ret)
18971 +               return ret;
18972 +       if (nd.path.dentry->d_inode) {
18973 +               *dev = nd.path.dentry->d_inode->i_rdev;
18974 +               *mode = nd.path.dentry->d_inode->i_mode;
18975 +       }
18976 +       path_put(&nd.path);
18977 +       return 0;
18978 +}
18979 +
18980 +static inline int __mapping_mode(dev_t device, dev_t target,
18981 +       umode_t device_mode, umode_t target_mode, umode_t *mode)
18982 +{
18983 +       if (device)
18984 +               *mode = device_mode & S_IFMT;
18985 +       else if (target)
18986 +               *mode = target_mode & S_IFMT;
18987 +       else
18988 +               return -EINVAL;
18989 +
18990 +       /* if both given, device and target mode have to match */
18991 +       if (device && target &&
18992 +               ((device_mode ^ target_mode) & S_IFMT))
18993 +               return -EINVAL;
18994 +       return 0;
18995 +}
18996 +
18997 +
18998 +static inline int do_mapping(struct vx_info *vxi, const char __user *device_path,
18999 +       const char __user *target_path, int flags, int set)
19000 +{
19001 +       dev_t device = ~0, target = ~0;
19002 +       umode_t device_mode = 0, target_mode = 0, mode;
19003 +       int ret;
19004 +
19005 +       ret = __user_device(device_path, &device, &device_mode);
19006 +       if (ret)
19007 +               return ret;
19008 +       ret = __user_device(target_path, &target, &target_mode);
19009 +       if (ret)
19010 +               return ret;
19011 +
19012 +       ret = __mapping_mode(device, target,
19013 +               device_mode, target_mode, &mode);
19014 +       if (ret)
19015 +               return ret;
19016 +
19017 +       if (set)
19018 +               return do_set_mapping(vxi, device, target,
19019 +                       flags, mode);
19020 +       else
19021 +               return do_unset_mapping(vxi, device, target,
19022 +                       flags, mode);
19023 +}
19024 +
19025 +
19026 +int vc_set_mapping(struct vx_info *vxi, void __user *data)
19027 +{
19028 +       struct vcmd_set_mapping_v0 vc_data;
19029 +
19030 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19031 +               return -EFAULT;
19032 +
19033 +       return do_mapping(vxi, vc_data.device, vc_data.target,
19034 +               vc_data.flags, 1);
19035 +}
19036 +
19037 +int vc_unset_mapping(struct vx_info *vxi, void __user *data)
19038 +{
19039 +       struct vcmd_set_mapping_v0 vc_data;
19040 +
19041 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19042 +               return -EFAULT;
19043 +
19044 +       return do_mapping(vxi, vc_data.device, vc_data.target,
19045 +               vc_data.flags, 0);
19046 +}
19047 +
19048 +
19049 +#ifdef CONFIG_COMPAT
19050 +
19051 +int vc_set_mapping_x32(struct vx_info *vxi, void __user *data)
19052 +{
19053 +       struct vcmd_set_mapping_v0_x32 vc_data;
19054 +
19055 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19056 +               return -EFAULT;
19057 +
19058 +       return do_mapping(vxi, compat_ptr(vc_data.device_ptr),
19059 +               compat_ptr(vc_data.target_ptr), vc_data.flags, 1);
19060 +}
19061 +
19062 +int vc_unset_mapping_x32(struct vx_info *vxi, void __user *data)
19063 +{
19064 +       struct vcmd_set_mapping_v0_x32 vc_data;
19065 +
19066 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19067 +               return -EFAULT;
19068 +
19069 +       return do_mapping(vxi, compat_ptr(vc_data.device_ptr),
19070 +               compat_ptr(vc_data.target_ptr), vc_data.flags, 0);
19071 +}
19072 +
19073 +#endif /* CONFIG_COMPAT */
19074 +
19075 +
19076 diff -NurpP --minimal linux-2.6.29/kernel/vserver/dlimit.c linux-2.6.29-vs2.3.0.36.9-pre2/kernel/vserver/dlimit.c
19077 --- linux-2.6.29/kernel/vserver/dlimit.c        1970-01-01 01:00:00.000000000 +0100
19078 +++ linux-2.6.29-vs2.3.0.36.9-pre2/kernel/vserver/dlimit.c      2009-02-22 22:54:26.000000000 +0100
19079 @@ -0,0 +1,522 @@
19080 +/*
19081 + *  linux/kernel/vserver/dlimit.c
19082 + *
19083 + *  Virtual Server: Context Disk Limits
19084 + *
19085 + *  Copyright (C) 2004-2007  Herbert Pötzl
19086 + *
19087 + *  V0.01  initial version
19088 + *  V0.02  compat32 splitup
19089 + *
19090 + */
19091 +
19092 +#include <linux/statfs.h>
19093 +#include <linux/sched.h>
19094 +#include <linux/namei.h>
19095 +#include <linux/vs_tag.h>
19096 +#include <linux/vs_dlimit.h>
19097 +#include <linux/vserver/dlimit_cmd.h>
19098 +
19099 +#include <asm/uaccess.h>
19100 +
19101 +/*     __alloc_dl_info()
19102 +
19103 +       * allocate an initialized dl_info struct
19104 +       * doesn't make it visible (hash)                        */
19105 +
19106 +static struct dl_info *__alloc_dl_info(struct super_block *sb, tag_t tag)
19107 +{
19108 +       struct dl_info *new = NULL;
19109 +
19110 +       vxdprintk(VXD_CBIT(dlim, 5),
19111 +               "alloc_dl_info(%p,%d)*", sb, tag);
19112 +
19113 +       /* would this benefit from a slab cache? */
19114 +       new = kmalloc(sizeof(struct dl_info), GFP_KERNEL);
19115 +       if (!new)
19116 +               return 0;
19117 +
19118 +       memset(new, 0, sizeof(struct dl_info));
19119 +       new->dl_tag = tag;
19120 +       new->dl_sb = sb;
19121 +       INIT_RCU_HEAD(&new->dl_rcu);
19122 +       INIT_HLIST_NODE(&new->dl_hlist);
19123 +       spin_lock_init(&new->dl_lock);
19124 +       atomic_set(&new->dl_refcnt, 0);
19125 +       atomic_set(&new->dl_usecnt, 0);
19126 +
19127 +       /* rest of init goes here */
19128 +
19129 +       vxdprintk(VXD_CBIT(dlim, 4),
19130 +               "alloc_dl_info(%p,%d) = %p", sb, tag, new);
19131 +       return new;
19132 +}
19133 +
19134 +/*     __dealloc_dl_info()
19135 +
19136 +       * final disposal of dl_info                             */
19137 +
19138 +static void __dealloc_dl_info(struct dl_info *dli)
19139 +{
19140 +       vxdprintk(VXD_CBIT(dlim, 4),
19141 +               "dealloc_dl_info(%p)", dli);
19142 +
19143 +       dli->dl_hlist.next = LIST_POISON1;
19144 +       dli->dl_tag = -1;
19145 +       dli->dl_sb = 0;
19146 +
19147 +       BUG_ON(atomic_read(&dli->dl_usecnt));
19148 +       BUG_ON(atomic_read(&dli->dl_refcnt));
19149 +
19150 +       kfree(dli);
19151 +}
19152 +
19153 +
19154 +/*     hash table for dl_info hash */
19155 +
19156 +#define DL_HASH_SIZE   13
19157 +
19158 +struct hlist_head dl_info_hash[DL_HASH_SIZE];
19159 +
19160 +static spinlock_t dl_info_hash_lock = SPIN_LOCK_UNLOCKED;
19161 +
19162 +
19163 +static inline unsigned int __hashval(struct super_block *sb, tag_t tag)
19164 +{
19165 +       return ((tag ^ (unsigned long)sb) % DL_HASH_SIZE);
19166 +}
19167 +
19168 +
19169 +
19170 +/*     __hash_dl_info()
19171 +
19172 +       * add the dli to the global hash table
19173 +       * requires the hash_lock to be held                     */
19174 +
19175 +static inline void __hash_dl_info(struct dl_info *dli)
19176 +{
19177 +       struct hlist_head *head;
19178 +
19179 +       vxdprintk(VXD_CBIT(dlim, 6),
19180 +               "__hash_dl_info: %p[#%d]", dli, dli->dl_tag);
19181 +       get_dl_info(dli);
19182 +       head = &dl_info_hash[__hashval(dli->dl_sb, dli->dl_tag)];
19183 +       hlist_add_head_rcu(&dli->dl_hlist, head);
19184 +}
19185 +
19186 +/*     __unhash_dl_info()
19187 +
19188 +       * remove the dli from the global hash table
19189 +       * requires the hash_lock to be held                     */
19190 +
19191 +static inline void __unhash_dl_info(struct dl_info *dli)
19192 +{
19193 +       vxdprintk(VXD_CBIT(dlim, 6),
19194 +               "__unhash_dl_info: %p[#%d]", dli, dli->dl_tag);
19195 +       hlist_del_rcu(&dli->dl_hlist);
19196 +       put_dl_info(dli);
19197 +}
19198 +
19199 +
19200 +/*     __lookup_dl_info()
19201 +
19202 +       * requires the rcu_read_lock()
19203 +       * doesn't increment the dl_refcnt                       */
19204 +
19205 +static inline struct dl_info *__lookup_dl_info(struct super_block *sb, tag_t tag)
19206 +{
19207 +       struct hlist_head *head = &dl_info_hash[__hashval(sb, tag)];
19208 +       struct hlist_node *pos;
19209 +       struct dl_info *dli;
19210 +
19211 +       hlist_for_each_entry_rcu(dli, pos, head, dl_hlist) {
19212 +
19213 +               if (dli->dl_tag == tag && dli->dl_sb == sb) {
19214 +                       return dli;
19215 +               }
19216 +       }
19217 +       return NULL;
19218 +}
19219 +
19220 +
19221 +struct dl_info *locate_dl_info(struct super_block *sb, tag_t tag)
19222 +{
19223 +       struct dl_info *dli;
19224 +
19225 +       rcu_read_lock();
19226 +       dli = get_dl_info(__lookup_dl_info(sb, tag));
19227 +       vxdprintk(VXD_CBIT(dlim, 7),
19228 +               "locate_dl_info(%p,#%d) = %p", sb, tag, dli);
19229 +       rcu_read_unlock();
19230 +       return dli;
19231 +}
19232 +
19233 +void rcu_free_dl_info(struct rcu_head *head)
19234 +{
19235 +       struct dl_info *dli = container_of(head, struct dl_info, dl_rcu);
19236 +       int usecnt, refcnt;
19237 +
19238 +       BUG_ON(!dli || !head);
19239 +
19240 +       usecnt = atomic_read(&dli->dl_usecnt);
19241 +       BUG_ON(usecnt < 0);
19242 +
19243 +       refcnt = atomic_read(&dli->dl_refcnt);
19244 +       BUG_ON(refcnt < 0);
19245 +
19246 +       vxdprintk(VXD_CBIT(dlim, 3),
19247 +               "rcu_free_dl_info(%p)", dli);
19248 +       if (!usecnt)
19249 +               __dealloc_dl_info(dli);
19250 +       else
19251 +               printk("!!! rcu didn't free\n");
19252 +}
19253 +
19254 +
19255 +
19256 +
19257 +static int do_addrem_dlimit(uint32_t id, const char __user *name,
19258 +       uint32_t flags, int add)
19259 +{
19260 +       struct path path;
19261 +       int ret;
19262 +
19263 +       ret = user_lpath(name, &path);
19264 +       if (!ret) {
19265 +               struct super_block *sb;
19266 +               struct dl_info *dli;
19267 +
19268 +               ret = -EINVAL;
19269 +               if (!path.dentry->d_inode)
19270 +                       goto out_release;
19271 +               if (!(sb = path.dentry->d_inode->i_sb))
19272 +                       goto out_release;
19273 +
19274 +               if (add) {
19275 +                       dli = __alloc_dl_info(sb, id);
19276 +                       spin_lock(&dl_info_hash_lock);
19277 +
19278 +                       ret = -EEXIST;
19279 +                       if (__lookup_dl_info(sb, id))
19280 +                               goto out_unlock;
19281 +                       __hash_dl_info(dli);
19282 +                       dli = NULL;
19283 +               } else {
19284 +                       spin_lock(&dl_info_hash_lock);
19285 +                       dli = __lookup_dl_info(sb, id);
19286 +
19287 +                       ret = -ESRCH;
19288 +                       if (!dli)
19289 +                               goto out_unlock;
19290 +                       __unhash_dl_info(dli);
19291 +               }
19292 +               ret = 0;
19293 +       out_unlock:
19294 +               spin_unlock(&dl_info_hash_lock);
19295 +               if (add && dli)
19296 +                       __dealloc_dl_info(dli);
19297 +       out_release:
19298 +               path_put(&path);
19299 +       }
19300 +       return ret;
19301 +}
19302 +
19303 +int vc_add_dlimit(uint32_t id, void __user *data)
19304 +{
19305 +       struct vcmd_ctx_dlimit_base_v0 vc_data;
19306 +
19307 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19308 +               return -EFAULT;
19309 +
19310 +       return do_addrem_dlimit(id, vc_data.name, vc_data.flags, 1);
19311 +}
19312 +
19313 +int vc_rem_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, 0);
19321 +}
19322 +
19323 +#ifdef CONFIG_COMPAT
19324 +
19325 +int vc_add_dlimit_x32(uint32_t id, void __user *data)
19326 +{
19327 +       struct vcmd_ctx_dlimit_base_v0_x32 vc_data;
19328 +
19329 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19330 +               return -EFAULT;
19331 +
19332 +       return do_addrem_dlimit(id,
19333 +               compat_ptr(vc_data.name_ptr), vc_data.flags, 1);
19334 +}
19335 +
19336 +int vc_rem_dlimit_x32(uint32_t id, void __user *data)
19337 +{
19338 +       struct vcmd_ctx_dlimit_base_v0_x32 vc_data;
19339 +
19340 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19341 +               return -EFAULT;
19342 +
19343 +       return do_addrem_dlimit(id,
19344 +               compat_ptr(vc_data.name_ptr), vc_data.flags, 0);
19345 +}
19346 +
19347 +#endif /* CONFIG_COMPAT */
19348 +
19349 +
19350 +static inline
19351 +int do_set_dlimit(uint32_t id, const char __user *name,
19352 +       uint32_t space_used, uint32_t space_total,
19353 +       uint32_t inodes_used, uint32_t inodes_total,
19354 +       uint32_t reserved, uint32_t flags)
19355 +{
19356 +       struct path path;
19357 +       int ret;
19358 +
19359 +       ret = user_lpath(name, &path);
19360 +       if (!ret) {
19361 +               struct super_block *sb;
19362 +               struct dl_info *dli;
19363 +
19364 +               ret = -EINVAL;
19365 +               if (!path.dentry->d_inode)
19366 +                       goto out_release;
19367 +               if (!(sb = path.dentry->d_inode->i_sb))
19368 +                       goto out_release;
19369 +               if ((reserved != CDLIM_KEEP &&
19370 +                       reserved > 100) ||
19371 +                       (inodes_used != CDLIM_KEEP &&
19372 +                       inodes_used > inodes_total) ||
19373 +                       (space_used != CDLIM_KEEP &&
19374 +                       space_used > space_total))
19375 +                       goto out_release;
19376 +
19377 +               ret = -ESRCH;
19378 +               dli = locate_dl_info(sb, id);
19379 +               if (!dli)
19380 +                       goto out_release;
19381 +
19382 +               spin_lock(&dli->dl_lock);
19383 +
19384 +               if (inodes_used != CDLIM_KEEP)
19385 +                       dli->dl_inodes_used = inodes_used;
19386 +               if (inodes_total != CDLIM_KEEP)
19387 +                       dli->dl_inodes_total = inodes_total;
19388 +               if (space_used != CDLIM_KEEP) {
19389 +                       dli->dl_space_used = space_used;
19390 +                       dli->dl_space_used <<= 10;
19391 +               }
19392 +               if (space_total == CDLIM_INFINITY)
19393 +                       dli->dl_space_total = DLIM_INFINITY;
19394 +               else if (space_total != CDLIM_KEEP) {
19395 +                       dli->dl_space_total = space_total;
19396 +                       dli->dl_space_total <<= 10;
19397 +               }
19398 +               if (reserved != CDLIM_KEEP)
19399 +                       dli->dl_nrlmult = (1 << 10) * (100 - reserved) / 100;
19400 +
19401 +               spin_unlock(&dli->dl_lock);
19402 +
19403 +               put_dl_info(dli);
19404 +               ret = 0;
19405 +
19406 +       out_release:
19407 +               path_put(&path);
19408 +       }
19409 +       return ret;
19410 +}
19411 +
19412 +int vc_set_dlimit(uint32_t id, void __user *data)
19413 +{
19414 +       struct vcmd_ctx_dlimit_v0 vc_data;
19415 +
19416 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19417 +               return -EFAULT;
19418 +
19419 +       return do_set_dlimit(id, vc_data.name,
19420 +               vc_data.space_used, vc_data.space_total,
19421 +               vc_data.inodes_used, vc_data.inodes_total,
19422 +               vc_data.reserved, vc_data.flags);
19423 +}
19424 +
19425 +#ifdef CONFIG_COMPAT
19426 +
19427 +int vc_set_dlimit_x32(uint32_t id, void __user *data)
19428 +{
19429 +       struct vcmd_ctx_dlimit_v0_x32 vc_data;
19430 +
19431 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19432 +               return -EFAULT;
19433 +
19434 +       return do_set_dlimit(id, compat_ptr(vc_data.name_ptr),
19435 +               vc_data.space_used, vc_data.space_total,
19436 +               vc_data.inodes_used, vc_data.inodes_total,
19437 +               vc_data.reserved, vc_data.flags);
19438 +}
19439 +
19440 +#endif /* CONFIG_COMPAT */
19441 +
19442 +
19443 +static inline
19444 +int do_get_dlimit(uint32_t id, const char __user *name,
19445 +       uint32_t *space_used, uint32_t *space_total,
19446 +       uint32_t *inodes_used, uint32_t *inodes_total,
19447 +       uint32_t *reserved, uint32_t *flags)
19448 +{
19449 +       struct path path;
19450 +       int ret;
19451 +
19452 +       ret = user_lpath(name, &path);
19453 +       if (!ret) {
19454 +               struct super_block *sb;
19455 +               struct dl_info *dli;
19456 +
19457 +               ret = -EINVAL;
19458 +               if (!path.dentry->d_inode)
19459 +                       goto out_release;
19460 +               if (!(sb = path.dentry->d_inode->i_sb))
19461 +                       goto out_release;
19462 +
19463 +               ret = -ESRCH;
19464 +               dli = locate_dl_info(sb, id);
19465 +               if (!dli)
19466 +                       goto out_release;
19467 +
19468 +               spin_lock(&dli->dl_lock);
19469 +               *inodes_used = dli->dl_inodes_used;
19470 +               *inodes_total = dli->dl_inodes_total;
19471 +               *space_used = dli->dl_space_used >> 10;
19472 +               if (dli->dl_space_total == DLIM_INFINITY)
19473 +                       *space_total = CDLIM_INFINITY;
19474 +               else
19475 +                       *space_total = dli->dl_space_total >> 10;
19476 +
19477 +               *reserved = 100 - ((dli->dl_nrlmult * 100 + 512) >> 10);
19478 +               spin_unlock(&dli->dl_lock);
19479 +
19480 +               put_dl_info(dli);
19481 +               ret = -EFAULT;
19482 +
19483 +               ret = 0;
19484 +       out_release:
19485 +               path_put(&path);
19486 +       }
19487 +       return ret;
19488 +}
19489 +
19490 +
19491 +int vc_get_dlimit(uint32_t id, void __user *data)
19492 +{
19493 +       struct vcmd_ctx_dlimit_v0 vc_data;
19494 +       int ret;
19495 +
19496 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19497 +               return -EFAULT;
19498 +
19499 +       ret = do_get_dlimit(id, vc_data.name,
19500 +               &vc_data.space_used, &vc_data.space_total,
19501 +               &vc_data.inodes_used, &vc_data.inodes_total,
19502 +               &vc_data.reserved, &vc_data.flags);
19503 +       if (ret)
19504 +               return ret;
19505 +
19506 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
19507 +               return -EFAULT;
19508 +       return 0;
19509 +}
19510 +
19511 +#ifdef CONFIG_COMPAT
19512 +
19513 +int vc_get_dlimit_x32(uint32_t id, void __user *data)
19514 +{
19515 +       struct vcmd_ctx_dlimit_v0_x32 vc_data;
19516 +       int ret;
19517 +
19518 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19519 +               return -EFAULT;
19520 +
19521 +       ret = do_get_dlimit(id, compat_ptr(vc_data.name_ptr),
19522 +               &vc_data.space_used, &vc_data.space_total,
19523 +               &vc_data.inodes_used, &vc_data.inodes_total,
19524 +               &vc_data.reserved, &vc_data.flags);
19525 +       if (ret)
19526 +               return ret;
19527 +
19528 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
19529 +               return -EFAULT;
19530 +       return 0;
19531 +}
19532 +
19533 +#endif /* CONFIG_COMPAT */
19534 +
19535 +
19536 +void vx_vsi_statfs(struct super_block *sb, struct kstatfs *buf)
19537 +{
19538 +       struct dl_info *dli;
19539 +       __u64 blimit, bfree, bavail;
19540 +       __u32 ifree;
19541 +
19542 +       dli = locate_dl_info(sb, dx_current_tag());
19543 +       if (!dli)
19544 +               return;
19545 +
19546 +       spin_lock(&dli->dl_lock);
19547 +       if (dli->dl_inodes_total == (unsigned long)DLIM_INFINITY)
19548 +               goto no_ilim;
19549 +
19550 +       /* reduce max inodes available to limit */
19551 +       if (buf->f_files > dli->dl_inodes_total)
19552 +               buf->f_files = dli->dl_inodes_total;
19553 +
19554 +       ifree = dli->dl_inodes_total - dli->dl_inodes_used;
19555 +       /* reduce free inodes to min */
19556 +       if (ifree < buf->f_ffree)
19557 +               buf->f_ffree = ifree;
19558 +
19559 +no_ilim:
19560 +       if (dli->dl_space_total == DLIM_INFINITY)
19561 +               goto no_blim;
19562 +
19563 +       blimit = dli->dl_space_total >> sb->s_blocksize_bits;
19564 +
19565 +       if (dli->dl_space_total < dli->dl_space_used)
19566 +               bfree = 0;
19567 +       else
19568 +               bfree = (dli->dl_space_total - dli->dl_space_used)
19569 +                       >> sb->s_blocksize_bits;
19570 +
19571 +       bavail = ((dli->dl_space_total >> 10) * dli->dl_nrlmult);
19572 +       if (bavail < dli->dl_space_used)
19573 +               bavail = 0;
19574 +       else
19575 +               bavail = (bavail - dli->dl_space_used)
19576 +                       >> sb->s_blocksize_bits;
19577 +
19578 +       /* reduce max space available to limit */
19579 +       if (buf->f_blocks > blimit)
19580 +               buf->f_blocks = blimit;
19581 +
19582 +       /* reduce free space to min */
19583 +       if (bfree < buf->f_bfree)
19584 +               buf->f_bfree = bfree;
19585 +
19586 +       /* reduce avail space to min */
19587 +       if (bavail < buf->f_bavail)
19588 +               buf->f_bavail = bavail;
19589 +
19590 +no_blim:
19591 +       spin_unlock(&dli->dl_lock);
19592 +       put_dl_info(dli);
19593 +
19594 +       return;
19595 +}
19596 +
19597 +#include <linux/module.h>
19598 +
19599 +EXPORT_SYMBOL_GPL(locate_dl_info);
19600 +EXPORT_SYMBOL_GPL(rcu_free_dl_info);
19601 +
19602 diff -NurpP --minimal linux-2.6.29/kernel/vserver/helper.c linux-2.6.29-vs2.3.0.36.9-pre2/kernel/vserver/helper.c
19603 --- linux-2.6.29/kernel/vserver/helper.c        1970-01-01 01:00:00.000000000 +0100
19604 +++ linux-2.6.29-vs2.3.0.36.9-pre2/kernel/vserver/helper.c      2009-03-25 00:40:43.000000000 +0100
19605 @@ -0,0 +1,199 @@
19606 +/*
19607 + *  linux/kernel/vserver/helper.c
19608 + *
19609 + *  Virtual Context Support
19610 + *
19611 + *  Copyright (C) 2004-2007  Herbert Pötzl
19612 + *
19613 + *  V0.01  basic helper
19614 + *
19615 + */
19616 +
19617 +#include <linux/kmod.h>
19618 +#include <linux/reboot.h>
19619 +#include <linux/vs_context.h>
19620 +#include <linux/vs_network.h>
19621 +#include <linux/vserver/signal.h>
19622 +
19623 +
19624 +char vshelper_path[255] = "/sbin/vshelper";
19625 +
19626 +
19627 +static int do_vshelper(char *name, char *argv[], char *envp[], int sync)
19628 +{
19629 +       int ret;
19630 +
19631 +       if ((ret = call_usermodehelper(name, argv, envp, sync))) {
19632 +               printk( KERN_WARNING
19633 +                       "%s: (%s %s) returned %s with %d\n",
19634 +                       name, argv[1], argv[2],
19635 +                       sync ? "sync" : "async", ret);
19636 +       }
19637 +       vxdprintk(VXD_CBIT(switch, 4),
19638 +               "%s: (%s %s) returned %s with %d",
19639 +               name, argv[1], argv[2], sync ? "sync" : "async", ret);
19640 +       return ret;
19641 +}
19642 +
19643 +/*
19644 + *      vshelper path is set via /proc/sys
19645 + *      invoked by vserver sys_reboot(), with
19646 + *      the following arguments
19647 + *
19648 + *      argv [0] = vshelper_path;
19649 + *      argv [1] = action: "restart", "halt", "poweroff", ...
19650 + *      argv [2] = context identifier
19651 + *
19652 + *      envp [*] = type-specific parameters
19653 + */
19654 +
19655 +long vs_reboot_helper(struct vx_info *vxi, int cmd, void __user *arg)
19656 +{
19657 +       char id_buf[8], cmd_buf[16];
19658 +       char uid_buf[16], pid_buf[16];
19659 +       int ret;
19660 +
19661 +       char *argv[] = {vshelper_path, NULL, id_buf, 0};
19662 +       char *envp[] = {"HOME=/", "TERM=linux",
19663 +                       "PATH=/sbin:/usr/sbin:/bin:/usr/bin",
19664 +                       uid_buf, pid_buf, cmd_buf, 0};
19665 +
19666 +       if (vx_info_state(vxi, VXS_HELPER))
19667 +               return -EAGAIN;
19668 +       vxi->vx_state |= VXS_HELPER;
19669 +
19670 +       snprintf(id_buf, sizeof(id_buf)-1, "%d", vxi->vx_id);
19671 +
19672 +       snprintf(cmd_buf, sizeof(cmd_buf)-1, "VS_CMD=%08x", cmd);
19673 +       snprintf(uid_buf, sizeof(uid_buf)-1, "VS_UID=%d", current_uid());
19674 +       snprintf(pid_buf, sizeof(pid_buf)-1, "VS_PID=%d", current->pid);
19675 +
19676 +       switch (cmd) {
19677 +       case LINUX_REBOOT_CMD_RESTART:
19678 +               argv[1] = "restart";
19679 +               break;
19680 +
19681 +       case LINUX_REBOOT_CMD_HALT:
19682 +               argv[1] = "halt";
19683 +               break;
19684 +
19685 +       case LINUX_REBOOT_CMD_POWER_OFF:
19686 +               argv[1] = "poweroff";
19687 +               break;
19688 +
19689 +       case LINUX_REBOOT_CMD_SW_SUSPEND:
19690 +               argv[1] = "swsusp";
19691 +               break;
19692 +
19693 +       default:
19694 +               vxi->vx_state &= ~VXS_HELPER;
19695 +               return 0;
19696 +       }
19697 +
19698 +       ret = do_vshelper(vshelper_path, argv, envp, 0);
19699 +       vxi->vx_state &= ~VXS_HELPER;
19700 +       __wakeup_vx_info(vxi);
19701 +       return (ret) ? -EPERM : 0;
19702 +}
19703 +
19704 +
19705 +long vs_reboot(unsigned int cmd, void __user *arg)
19706 +{
19707 +       struct vx_info *vxi = current->vx_info;
19708 +       long ret = 0;
19709 +
19710 +       vxdprintk(VXD_CBIT(misc, 5),
19711 +               "vs_reboot(%p[#%d],%d)",
19712 +               vxi, vxi ? vxi->vx_id : 0, cmd);
19713 +
19714 +       ret = vs_reboot_helper(vxi, cmd, arg);
19715 +       if (ret)
19716 +               return ret;
19717 +
19718 +       vxi->reboot_cmd = cmd;
19719 +       if (vx_info_flags(vxi, VXF_REBOOT_KILL, 0)) {
19720 +               switch (cmd) {
19721 +               case LINUX_REBOOT_CMD_RESTART:
19722 +               case LINUX_REBOOT_CMD_HALT:
19723 +               case LINUX_REBOOT_CMD_POWER_OFF:
19724 +                       vx_info_kill(vxi, 0, SIGKILL);
19725 +                       vx_info_kill(vxi, 1, SIGKILL);
19726 +               default:
19727 +                       break;
19728 +               }
19729 +       }
19730 +       return 0;
19731 +}
19732 +
19733 +
19734 +/*
19735 + *      argv [0] = vshelper_path;
19736 + *      argv [1] = action: "startup", "shutdown"
19737 + *      argv [2] = context identifier
19738 + *
19739 + *      envp [*] = type-specific parameters
19740 + */
19741 +
19742 +long vs_state_change(struct vx_info *vxi, unsigned int cmd)
19743 +{
19744 +       char id_buf[8], cmd_buf[16];
19745 +       char *argv[] = {vshelper_path, NULL, id_buf, 0};
19746 +       char *envp[] = {"HOME=/", "TERM=linux",
19747 +                       "PATH=/sbin:/usr/sbin:/bin:/usr/bin", cmd_buf, 0};
19748 +
19749 +       if (!vx_info_flags(vxi, VXF_SC_HELPER, 0))
19750 +               return 0;
19751 +
19752 +       snprintf(id_buf, sizeof(id_buf)-1, "%d", vxi->vx_id);
19753 +       snprintf(cmd_buf, sizeof(cmd_buf)-1, "VS_CMD=%08x", cmd);
19754 +
19755 +       switch (cmd) {
19756 +       case VSC_STARTUP:
19757 +               argv[1] = "startup";
19758 +               break;
19759 +       case VSC_SHUTDOWN:
19760 +               argv[1] = "shutdown";
19761 +               break;
19762 +       default:
19763 +               return 0;
19764 +       }
19765 +
19766 +       return do_vshelper(vshelper_path, argv, envp, 1);
19767 +}
19768 +
19769 +
19770 +/*
19771 + *      argv [0] = vshelper_path;
19772 + *      argv [1] = action: "netup", "netdown"
19773 + *      argv [2] = context identifier
19774 + *
19775 + *      envp [*] = type-specific parameters
19776 + */
19777 +
19778 +long vs_net_change(struct nx_info *nxi, unsigned int cmd)
19779 +{
19780 +       char id_buf[8], cmd_buf[16];
19781 +       char *argv[] = {vshelper_path, NULL, id_buf, 0};
19782 +       char *envp[] = {"HOME=/", "TERM=linux",
19783 +                       "PATH=/sbin:/usr/sbin:/bin:/usr/bin", cmd_buf, 0};
19784 +
19785 +       if (!nx_info_flags(nxi, NXF_SC_HELPER, 0))
19786 +               return 0;
19787 +
19788 +       snprintf(id_buf, sizeof(id_buf)-1, "%d", nxi->nx_id);
19789 +       snprintf(cmd_buf, sizeof(cmd_buf)-1, "VS_CMD=%08x", cmd);
19790 +
19791 +       switch (cmd) {
19792 +       case VSC_NETUP:
19793 +               argv[1] = "netup";
19794 +               break;
19795 +       case VSC_NETDOWN:
19796 +               argv[1] = "netdown";
19797 +               break;
19798 +       default:
19799 +               return 0;
19800 +       }
19801 +
19802 +       return do_vshelper(vshelper_path, argv, envp, 1);
19803 +}
19804 +
19805 diff -NurpP --minimal linux-2.6.29/kernel/vserver/history.c linux-2.6.29-vs2.3.0.36.9-pre2/kernel/vserver/history.c
19806 --- linux-2.6.29/kernel/vserver/history.c       1970-01-01 01:00:00.000000000 +0100
19807 +++ linux-2.6.29-vs2.3.0.36.9-pre2/kernel/vserver/history.c     2009-02-22 22:54:26.000000000 +0100
19808 @@ -0,0 +1,258 @@
19809 +/*
19810 + *  kernel/vserver/history.c
19811 + *
19812 + *  Virtual Context History Backtrace
19813 + *
19814 + *  Copyright (C) 2004-2007  Herbert Pötzl
19815 + *
19816 + *  V0.01  basic structure
19817 + *  V0.02  hash/unhash and trace
19818 + *  V0.03  preemption fixes
19819 + *
19820 + */
19821 +
19822 +#include <linux/module.h>
19823 +#include <asm/uaccess.h>
19824 +
19825 +#include <linux/vserver/context.h>
19826 +#include <linux/vserver/debug.h>
19827 +#include <linux/vserver/debug_cmd.h>
19828 +#include <linux/vserver/history.h>
19829 +
19830 +
19831 +#ifdef CONFIG_VSERVER_HISTORY
19832 +#define VXH_SIZE       CONFIG_VSERVER_HISTORY_SIZE
19833 +#else
19834 +#define VXH_SIZE       64
19835 +#endif
19836 +
19837 +struct _vx_history {
19838 +       unsigned int counter;
19839 +
19840 +       struct _vx_hist_entry entry[VXH_SIZE + 1];
19841 +};
19842 +
19843 +
19844 +DEFINE_PER_CPU(struct _vx_history, vx_history_buffer);
19845 +
19846 +unsigned volatile int vxh_active = 1;
19847 +
19848 +static atomic_t sequence = ATOMIC_INIT(0);
19849 +
19850 +
19851 +/*     vxh_advance()
19852 +
19853 +       * requires disabled preemption                          */
19854 +
19855 +struct _vx_hist_entry *vxh_advance(void *loc)
19856 +{
19857 +       unsigned int cpu = smp_processor_id();
19858 +       struct _vx_history *hist = &per_cpu(vx_history_buffer, cpu);
19859 +       struct _vx_hist_entry *entry;
19860 +       unsigned int index;
19861 +
19862 +       index = vxh_active ? (hist->counter++ % VXH_SIZE) : VXH_SIZE;
19863 +       entry = &hist->entry[index];
19864 +
19865 +       entry->seq = atomic_inc_return(&sequence);
19866 +       entry->loc = loc;
19867 +       return entry;
19868 +}
19869 +
19870 +EXPORT_SYMBOL_GPL(vxh_advance);
19871 +
19872 +
19873 +#define VXH_LOC_FMTS   "(#%04x,*%d):%p"
19874 +
19875 +#define VXH_LOC_ARGS(e)        (e)->seq, cpu, (e)->loc
19876 +
19877 +
19878 +#define VXH_VXI_FMTS   "%p[#%d,%d.%d]"
19879 +
19880 +#define VXH_VXI_ARGS(e)        (e)->vxi.ptr,                           \
19881 +                       (e)->vxi.ptr ? (e)->vxi.xid : 0,        \
19882 +                       (e)->vxi.ptr ? (e)->vxi.usecnt : 0,     \
19883 +                       (e)->vxi.ptr ? (e)->vxi.tasks : 0
19884 +
19885 +void   vxh_dump_entry(struct _vx_hist_entry *e, unsigned cpu)
19886 +{
19887 +       switch (e->type) {
19888 +       case VXH_THROW_OOPS:
19889 +               printk( VXH_LOC_FMTS " oops \n", VXH_LOC_ARGS(e));
19890 +               break;
19891 +
19892 +       case VXH_GET_VX_INFO:
19893 +       case VXH_PUT_VX_INFO:
19894 +               printk( VXH_LOC_FMTS " %s_vx_info " VXH_VXI_FMTS "\n",
19895 +                       VXH_LOC_ARGS(e),
19896 +                       (e->type == VXH_GET_VX_INFO) ? "get" : "put",
19897 +                       VXH_VXI_ARGS(e));
19898 +               break;
19899 +
19900 +       case VXH_INIT_VX_INFO:
19901 +       case VXH_SET_VX_INFO:
19902 +       case VXH_CLR_VX_INFO:
19903 +               printk( VXH_LOC_FMTS " %s_vx_info " VXH_VXI_FMTS " @%p\n",
19904 +                       VXH_LOC_ARGS(e),
19905 +                       (e->type == VXH_INIT_VX_INFO) ? "init" :
19906 +                       ((e->type == VXH_SET_VX_INFO) ? "set" : "clr"),
19907 +                       VXH_VXI_ARGS(e), e->sc.data);
19908 +               break;
19909 +
19910 +       case VXH_CLAIM_VX_INFO:
19911 +       case VXH_RELEASE_VX_INFO:
19912 +               printk( VXH_LOC_FMTS " %s_vx_info " VXH_VXI_FMTS " @%p\n",
19913 +                       VXH_LOC_ARGS(e),
19914 +                       (e->type == VXH_CLAIM_VX_INFO) ? "claim" : "release",
19915 +                       VXH_VXI_ARGS(e), e->sc.data);
19916 +               break;
19917 +
19918 +       case VXH_ALLOC_VX_INFO:
19919 +       case VXH_DEALLOC_VX_INFO:
19920 +               printk( VXH_LOC_FMTS " %s_vx_info " VXH_VXI_FMTS "\n",
19921 +                       VXH_LOC_ARGS(e),
19922 +                       (e->type == VXH_ALLOC_VX_INFO) ? "alloc" : "dealloc",
19923 +                       VXH_VXI_ARGS(e));
19924 +               break;
19925 +
19926 +       case VXH_HASH_VX_INFO:
19927 +       case VXH_UNHASH_VX_INFO:
19928 +               printk( VXH_LOC_FMTS " __%s_vx_info " VXH_VXI_FMTS "\n",
19929 +                       VXH_LOC_ARGS(e),
19930 +                       (e->type == VXH_HASH_VX_INFO) ? "hash" : "unhash",
19931 +                       VXH_VXI_ARGS(e));
19932 +               break;
19933 +
19934 +       case VXH_LOC_VX_INFO:
19935 +       case VXH_LOOKUP_VX_INFO:
19936 +       case VXH_CREATE_VX_INFO:
19937 +               printk( VXH_LOC_FMTS " __%s_vx_info [#%d] -> " VXH_VXI_FMTS "\n",
19938 +                       VXH_LOC_ARGS(e),
19939 +                       (e->type == VXH_CREATE_VX_INFO) ? "create" :
19940 +                       ((e->type == VXH_LOC_VX_INFO) ? "loc" : "lookup"),
19941 +                       e->ll.arg, VXH_VXI_ARGS(e));
19942 +               break;
19943 +       }
19944 +}
19945 +
19946 +static void __vxh_dump_history(void)
19947 +{
19948 +       unsigned int i, cpu;
19949 +
19950 +       printk("History:\tSEQ: %8x\tNR_CPUS: %d\n",
19951 +               atomic_read(&sequence), NR_CPUS);
19952 +
19953 +       for (i = 0; i < VXH_SIZE; i++) {
19954 +               for_each_online_cpu(cpu) {
19955 +                       struct _vx_history *hist =
19956 +                               &per_cpu(vx_history_buffer, cpu);
19957 +                       unsigned int index = (hist->counter - i) % VXH_SIZE;
19958 +                       struct _vx_hist_entry *entry = &hist->entry[index];
19959 +
19960 +                       vxh_dump_entry(entry, cpu);
19961 +               }
19962 +       }
19963 +}
19964 +
19965 +void   vxh_dump_history(void)
19966 +{
19967 +       vxh_active = 0;
19968 +#ifdef CONFIG_SMP
19969 +       local_irq_enable();
19970 +       smp_send_stop();
19971 +       local_irq_disable();
19972 +#endif
19973 +       __vxh_dump_history();
19974 +}
19975 +
19976 +
19977 +/* vserver syscall commands below here */
19978 +
19979 +
19980 +int vc_dump_history(uint32_t id)
19981 +{
19982 +       vxh_active = 0;
19983 +       __vxh_dump_history();
19984 +       vxh_active = 1;
19985 +
19986 +       return 0;
19987 +}
19988 +
19989 +
19990 +int do_read_history(struct __user _vx_hist_entry *data,
19991 +       int cpu, uint32_t *index, uint32_t *count)
19992 +{
19993 +       int pos, ret = 0;
19994 +       struct _vx_history *hist = &per_cpu(vx_history_buffer, cpu);
19995 +       int end = hist->counter;
19996 +       int start = end - VXH_SIZE + 2;
19997 +       int idx = *index;
19998 +
19999 +       /* special case: get current pos */
20000 +       if (!*count) {
20001 +               *index = end;
20002 +               return 0;
20003 +       }
20004 +
20005 +       /* have we lost some data? */
20006 +       if (idx < start)
20007 +               idx = start;
20008 +
20009 +       for (pos = 0; (pos < *count) && (idx < end); pos++, idx++) {
20010 +               struct _vx_hist_entry *entry =
20011 +                       &hist->entry[idx % VXH_SIZE];
20012 +
20013 +               /* send entry to userspace */
20014 +               ret = copy_to_user(&data[pos], entry, sizeof(*entry));
20015 +               if (ret)
20016 +                       break;
20017 +       }
20018 +       /* save new index and count */
20019 +       *index = idx;
20020 +       *count = pos;
20021 +       return ret ? ret : (*index < end);
20022 +}
20023 +
20024 +int vc_read_history(uint32_t id, void __user *data)
20025 +{
20026 +       struct vcmd_read_history_v0 vc_data;
20027 +       int ret;
20028 +
20029 +       if (id >= NR_CPUS)
20030 +               return -EINVAL;
20031 +
20032 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
20033 +               return -EFAULT;
20034 +
20035 +       ret = do_read_history((struct __user _vx_hist_entry *)vc_data.data,
20036 +               id, &vc_data.index, &vc_data.count);
20037 +
20038 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
20039 +               return -EFAULT;
20040 +       return ret;
20041 +}
20042 +
20043 +#ifdef CONFIG_COMPAT
20044 +
20045 +int vc_read_history_x32(uint32_t id, void __user *data)
20046 +{
20047 +       struct vcmd_read_history_v0_x32 vc_data;
20048 +       int ret;
20049 +
20050 +       if (id >= NR_CPUS)
20051 +               return -EINVAL;
20052 +
20053 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
20054 +               return -EFAULT;
20055 +
20056 +       ret = do_read_history((struct __user _vx_hist_entry *)
20057 +               compat_ptr(vc_data.data_ptr),
20058 +               id, &vc_data.index, &vc_data.count);
20059 +
20060 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
20061 +               return -EFAULT;
20062 +       return ret;
20063 +}
20064 +
20065 +#endif /* CONFIG_COMPAT */
20066 +
20067 diff -NurpP --minimal linux-2.6.29/kernel/vserver/inet.c linux-2.6.29-vs2.3.0.36.9-pre2/kernel/vserver/inet.c
20068 --- linux-2.6.29/kernel/vserver/inet.c  1970-01-01 01:00:00.000000000 +0100
20069 +++ linux-2.6.29-vs2.3.0.36.9-pre2/kernel/vserver/inet.c        2009-02-22 22:54:26.000000000 +0100
20070 @@ -0,0 +1,225 @@
20071 +
20072 +#include <linux/in.h>
20073 +#include <linux/inetdevice.h>
20074 +#include <linux/vs_inet.h>
20075 +#include <linux/vs_inet6.h>
20076 +#include <linux/vserver/debug.h>
20077 +#include <net/route.h>
20078 +#include <net/addrconf.h>
20079 +
20080 +
20081 +int nx_v4_addr_conflict(struct nx_info *nxi1, struct nx_info *nxi2)
20082 +{
20083 +       int ret = 0;
20084 +
20085 +       if (!nxi1 || !nxi2 || nxi1 == nxi2)
20086 +               ret = 1;
20087 +       else {
20088 +               struct nx_addr_v4 *ptr;
20089 +
20090 +               for (ptr = &nxi1->v4; ptr; ptr = ptr->next) {
20091 +                       if (v4_nx_addr_in_nx_info(nxi2, ptr, -1)) {
20092 +                               ret = 1;
20093 +                               break;
20094 +                       }
20095 +               }
20096 +       }
20097 +
20098 +       vxdprintk(VXD_CBIT(net, 2),
20099 +               "nx_v4_addr_conflict(%p,%p): %d",
20100 +               nxi1, nxi2, ret);
20101 +
20102 +       return ret;
20103 +}
20104 +
20105 +
20106 +#ifdef CONFIG_IPV6
20107 +
20108 +int nx_v6_addr_conflict(struct nx_info *nxi1, struct nx_info *nxi2)
20109 +{
20110 +       int ret = 0;
20111 +
20112 +       if (!nxi1 || !nxi2 || nxi1 == nxi2)
20113 +               ret = 1;
20114 +       else {
20115 +               struct nx_addr_v6 *ptr;
20116 +
20117 +               for (ptr = &nxi1->v6; ptr; ptr = ptr->next) {
20118 +                       if (v6_nx_addr_in_nx_info(nxi2, ptr, -1)) {
20119 +                               ret = 1;
20120 +                               break;
20121 +                       }
20122 +               }
20123 +       }
20124 +
20125 +       vxdprintk(VXD_CBIT(net, 2),
20126 +               "nx_v6_addr_conflict(%p,%p): %d",
20127 +               nxi1, nxi2, ret);
20128 +
20129 +       return ret;
20130 +}
20131 +
20132 +#endif
20133 +
20134 +int v4_dev_in_nx_info(struct net_device *dev, struct nx_info *nxi)
20135 +{
20136 +       struct in_device *in_dev;
20137 +       struct in_ifaddr **ifap;
20138 +       struct in_ifaddr *ifa;
20139 +       int ret = 0;
20140 +
20141 +       if (!dev)
20142 +               goto out;
20143 +       in_dev = in_dev_get(dev);
20144 +       if (!in_dev)
20145 +               goto out;
20146 +
20147 +       for (ifap = &in_dev->ifa_list; (ifa = *ifap) != NULL;
20148 +               ifap = &ifa->ifa_next) {
20149 +               if (v4_addr_in_nx_info(nxi, ifa->ifa_local, NXA_MASK_SHOW)) {
20150 +                       ret = 1;
20151 +                       break;
20152 +               }
20153 +       }
20154 +       in_dev_put(in_dev);
20155 +out:
20156 +       return ret;
20157 +}
20158 +
20159 +
20160 +#ifdef CONFIG_IPV6
20161 +
20162 +int v6_dev_in_nx_info(struct net_device *dev, struct nx_info *nxi)
20163 +{
20164 +       struct inet6_dev *in_dev;
20165 +       struct inet6_ifaddr **ifap;
20166 +       struct inet6_ifaddr *ifa;
20167 +       int ret = 0;
20168 +
20169 +       if (!dev)
20170 +               goto out;
20171 +       in_dev = in6_dev_get(dev);
20172 +       if (!in_dev)
20173 +               goto out;
20174 +
20175 +       for (ifap = &in_dev->addr_list; (ifa = *ifap) != NULL;
20176 +               ifap = &ifa->if_next) {
20177 +               if (v6_addr_in_nx_info(nxi, &ifa->addr, -1)) {
20178 +                       ret = 1;
20179 +                       break;
20180 +               }
20181 +       }
20182 +       in6_dev_put(in_dev);
20183 +out:
20184 +       return ret;
20185 +}
20186 +
20187 +#endif
20188 +
20189 +int dev_in_nx_info(struct net_device *dev, struct nx_info *nxi)
20190 +{
20191 +       int ret = 1;
20192 +
20193 +       if (!nxi)
20194 +               goto out;
20195 +       if (nxi->v4.type && v4_dev_in_nx_info(dev, nxi))
20196 +               goto out;
20197 +#ifdef CONFIG_IPV6
20198 +       ret = 2;
20199 +       if (nxi->v6.type && v6_dev_in_nx_info(dev, nxi))
20200 +               goto out;
20201 +#endif
20202 +       ret = 0;
20203 +out:
20204 +       vxdprintk(VXD_CBIT(net, 3),
20205 +               "dev_in_nx_info(%p,%p[#%d]) = %d",
20206 +               dev, nxi, nxi ? nxi->nx_id : 0, ret);
20207 +       return ret;
20208 +}
20209 +
20210 +int ip_v4_find_src(struct net *net, struct nx_info *nxi,
20211 +       struct rtable **rp, struct flowi *fl)
20212 +{
20213 +       if (!nxi)
20214 +               return 0;
20215 +
20216 +       /* FIXME: handle lback only case */
20217 +       if (!NX_IPV4(nxi))
20218 +               return -EPERM;
20219 +
20220 +       vxdprintk(VXD_CBIT(net, 4),
20221 +               "ip_v4_find_src(%p[#%u]) " NIPQUAD_FMT " -> " NIPQUAD_FMT,
20222 +               nxi, nxi ? nxi->nx_id : 0,
20223 +               NIPQUAD(fl->fl4_src), NIPQUAD(fl->fl4_dst));
20224 +
20225 +       /* single IP is unconditional */
20226 +       if (nx_info_flags(nxi, NXF_SINGLE_IP, 0) &&
20227 +               (fl->fl4_src == INADDR_ANY))
20228 +               fl->fl4_src = nxi->v4.ip[0].s_addr;
20229 +
20230 +       if (fl->fl4_src == INADDR_ANY) {
20231 +               struct nx_addr_v4 *ptr;
20232 +               __be32 found = 0;
20233 +               int err;
20234 +
20235 +               err = __ip_route_output_key(net, rp, fl);
20236 +               if (!err) {
20237 +                       found = (*rp)->rt_src;
20238 +                       ip_rt_put(*rp);
20239 +                       vxdprintk(VXD_CBIT(net, 4),
20240 +                               "ip_v4_find_src(%p[#%u]) rok[%u]: " NIPQUAD_FMT,
20241 +                               nxi, nxi ? nxi->nx_id : 0, fl->oif, NIPQUAD(found));
20242 +                       if (v4_addr_in_nx_info(nxi, found, NXA_MASK_BIND))
20243 +                               goto found;
20244 +               }
20245 +
20246 +               for (ptr = &nxi->v4; ptr; ptr = ptr->next) {
20247 +                       __be32 primary = ptr->ip[0].s_addr;
20248 +                       __be32 mask = ptr->mask.s_addr;
20249 +                       __be32 neta = primary & mask;
20250 +
20251 +                       vxdprintk(VXD_CBIT(net, 4), "ip_v4_find_src(%p[#%u]) chk: "
20252 +                               NIPQUAD_FMT "/" NIPQUAD_FMT "/" NIPQUAD_FMT,
20253 +                               nxi, nxi ? nxi->nx_id : 0, NIPQUAD(primary),
20254 +                               NIPQUAD(mask), NIPQUAD(neta));
20255 +                       if ((found & mask) != neta)
20256 +                               continue;
20257 +
20258 +                       fl->fl4_src = primary;
20259 +                       err = __ip_route_output_key(net, rp, fl);
20260 +                       vxdprintk(VXD_CBIT(net, 4),
20261 +                               "ip_v4_find_src(%p[#%u]) rok[%u]: " NIPQUAD_FMT,
20262 +                               nxi, nxi ? nxi->nx_id : 0, fl->oif, NIPQUAD(primary));
20263 +                       if (!err) {
20264 +                               found = (*rp)->rt_src;
20265 +                               ip_rt_put(*rp);
20266 +                               if (found == primary)
20267 +                                       goto found;
20268 +                       }
20269 +               }
20270 +               /* still no source ip? */
20271 +               found = ipv4_is_loopback(fl->fl4_dst)
20272 +                       ? IPI_LOOPBACK : nxi->v4.ip[0].s_addr;
20273 +       found:
20274 +               /* assign src ip to flow */
20275 +               fl->fl4_src = found;
20276 +
20277 +       } else {
20278 +               if (!v4_addr_in_nx_info(nxi, fl->fl4_src, NXA_MASK_BIND))
20279 +                       return -EPERM;
20280 +       }
20281 +
20282 +       if (nx_info_flags(nxi, NXF_LBACK_REMAP, 0)) {
20283 +               if (ipv4_is_loopback(fl->fl4_dst))
20284 +                       fl->fl4_dst = nxi->v4_lback.s_addr;
20285 +               if (ipv4_is_loopback(fl->fl4_src))
20286 +                       fl->fl4_src = nxi->v4_lback.s_addr;
20287 +       } else if (ipv4_is_loopback(fl->fl4_dst) &&
20288 +               !nx_info_flags(nxi, NXF_LBACK_ALLOW, 0))
20289 +               return -EPERM;
20290 +
20291 +       return 0;
20292 +}
20293 +
20294 +EXPORT_SYMBOL_GPL(ip_v4_find_src);
20295 +
20296 diff -NurpP --minimal linux-2.6.29/kernel/vserver/init.c linux-2.6.29-vs2.3.0.36.9-pre2/kernel/vserver/init.c
20297 --- linux-2.6.29/kernel/vserver/init.c  1970-01-01 01:00:00.000000000 +0100
20298 +++ linux-2.6.29-vs2.3.0.36.9-pre2/kernel/vserver/init.c        2009-02-22 22:54:26.000000000 +0100
20299 @@ -0,0 +1,45 @@
20300 +/*
20301 + *  linux/kernel/init.c
20302 + *
20303 + *  Virtual Server Init
20304 + *
20305 + *  Copyright (C) 2004-2007  Herbert Pötzl
20306 + *
20307 + *  V0.01  basic structure
20308 + *
20309 + */
20310 +
20311 +#include <linux/init.h>
20312 +
20313 +int    vserver_register_sysctl(void);
20314 +void   vserver_unregister_sysctl(void);
20315 +
20316 +
20317 +static int __init init_vserver(void)
20318 +{
20319 +       int ret = 0;
20320 +
20321 +#ifdef CONFIG_VSERVER_DEBUG
20322 +       vserver_register_sysctl();
20323 +#endif
20324 +       return ret;
20325 +}
20326 +
20327 +
20328 +static void __exit exit_vserver(void)
20329 +{
20330 +
20331 +#ifdef CONFIG_VSERVER_DEBUG
20332 +       vserver_unregister_sysctl();
20333 +#endif
20334 +       return;
20335 +}
20336 +
20337 +/* FIXME: GFP_ZONETYPES gone
20338 +long vx_slab[GFP_ZONETYPES]; */
20339 +long vx_area;
20340 +
20341 +
20342 +module_init(init_vserver);
20343 +module_exit(exit_vserver);
20344 +
20345 diff -NurpP --minimal linux-2.6.29/kernel/vserver/inode.c linux-2.6.29-vs2.3.0.36.9-pre2/kernel/vserver/inode.c
20346 --- linux-2.6.29/kernel/vserver/inode.c 1970-01-01 01:00:00.000000000 +0100
20347 +++ linux-2.6.29-vs2.3.0.36.9-pre2/kernel/vserver/inode.c       2009-02-22 22:54:26.000000000 +0100
20348 @@ -0,0 +1,422 @@
20349 +/*
20350 + *  linux/kernel/vserver/inode.c
20351 + *
20352 + *  Virtual Server: File System Support
20353 + *
20354 + *  Copyright (C) 2004-2007  Herbert Pötzl
20355 + *
20356 + *  V0.01  separated from vcontext V0.05
20357 + *  V0.02  moved to tag (instead of xid)
20358 + *
20359 + */
20360 +
20361 +#include <linux/tty.h>
20362 +#include <linux/proc_fs.h>
20363 +#include <linux/devpts_fs.h>
20364 +#include <linux/fs.h>
20365 +#include <linux/file.h>
20366 +#include <linux/mount.h>
20367 +#include <linux/parser.h>
20368 +#include <linux/namei.h>
20369 +#include <linux/vserver/inode.h>
20370 +#include <linux/vserver/inode_cmd.h>
20371 +#include <linux/vs_base.h>
20372 +#include <linux/vs_tag.h>
20373 +
20374 +#include <asm/uaccess.h>
20375 +
20376 +
20377 +static int __vc_get_iattr(struct inode *in, uint32_t *tag, uint32_t *flags, uint32_t *mask)
20378 +{
20379 +       struct proc_dir_entry *entry;
20380 +
20381 +       if (!in || !in->i_sb)
20382 +               return -ESRCH;
20383 +
20384 +       *flags = IATTR_TAG
20385 +               | (IS_BARRIER(in) ? IATTR_BARRIER : 0)
20386 +               | (IS_IXUNLINK(in) ? IATTR_IXUNLINK : 0)
20387 +               | (IS_IMMUTABLE(in) ? IATTR_IMMUTABLE : 0);
20388 +       *mask = IATTR_IXUNLINK | IATTR_IMMUTABLE;
20389 +
20390 +       if (S_ISDIR(in->i_mode))
20391 +               *mask |= IATTR_BARRIER;
20392 +
20393 +       if (IS_TAGGED(in)) {
20394 +               *tag = in->i_tag;
20395 +               *mask |= IATTR_TAG;
20396 +       }
20397 +
20398 +       switch (in->i_sb->s_magic) {
20399 +       case PROC_SUPER_MAGIC:
20400 +               entry = PROC_I(in)->pde;
20401 +
20402 +               /* check for specific inodes? */
20403 +               if (entry)
20404 +                       *mask |= IATTR_FLAGS;
20405 +               if (entry)
20406 +                       *flags |= (entry->vx_flags & IATTR_FLAGS);
20407 +               else
20408 +                       *flags |= (PROC_I(in)->vx_flags & IATTR_FLAGS);
20409 +               break;
20410 +
20411 +       case DEVPTS_SUPER_MAGIC:
20412 +               *tag = in->i_tag;
20413 +               *mask |= IATTR_TAG;
20414 +               break;
20415 +
20416 +       default:
20417 +               break;
20418 +       }
20419 +       return 0;
20420 +}
20421 +
20422 +int vc_get_iattr(void __user *data)
20423 +{
20424 +       struct path path;
20425 +       struct vcmd_ctx_iattr_v1 vc_data = { .tag = -1 };
20426 +       int ret;
20427 +
20428 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
20429 +               return -EFAULT;
20430 +
20431 +       ret = user_lpath(vc_data.name, &path);
20432 +       if (!ret) {
20433 +               ret = __vc_get_iattr(path.dentry->d_inode,
20434 +                       &vc_data.tag, &vc_data.flags, &vc_data.mask);
20435 +               path_put(&path);
20436 +       }
20437 +       if (ret)
20438 +               return ret;
20439 +
20440 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
20441 +               ret = -EFAULT;
20442 +       return ret;
20443 +}
20444 +
20445 +#ifdef CONFIG_COMPAT
20446 +
20447 +int vc_get_iattr_x32(void __user *data)
20448 +{
20449 +       struct path path;
20450 +       struct vcmd_ctx_iattr_v1_x32 vc_data = { .tag = -1 };
20451 +       int ret;
20452 +
20453 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
20454 +               return -EFAULT;
20455 +
20456 +       ret = user_lpath(compat_ptr(vc_data.name_ptr), &path);
20457 +       if (!ret) {
20458 +               ret = __vc_get_iattr(path.dentry->d_inode,
20459 +                       &vc_data.tag, &vc_data.flags, &vc_data.mask);
20460 +               path_put(&path);
20461 +       }
20462 +       if (ret)
20463 +               return ret;
20464 +
20465 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
20466 +               ret = -EFAULT;
20467 +       return ret;
20468 +}
20469 +
20470 +#endif /* CONFIG_COMPAT */
20471 +
20472 +
20473 +int vc_fget_iattr(uint32_t fd, void __user *data)
20474 +{
20475 +       struct file *filp;
20476 +       struct vcmd_ctx_fiattr_v0 vc_data = { .tag = -1 };
20477 +       int ret;
20478 +
20479 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
20480 +               return -EFAULT;
20481 +
20482 +       filp = fget(fd);
20483 +       if (!filp || !filp->f_dentry || !filp->f_dentry->d_inode)
20484 +               return -EBADF;
20485 +
20486 +       ret = __vc_get_iattr(filp->f_dentry->d_inode,
20487 +               &vc_data.tag, &vc_data.flags, &vc_data.mask);
20488 +
20489 +       fput(filp);
20490 +
20491 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
20492 +               ret = -EFAULT;
20493 +       return ret;
20494 +}
20495 +
20496 +
20497 +static int __vc_set_iattr(struct dentry *de, uint32_t *tag, uint32_t *flags, uint32_t *mask)
20498 +{
20499 +       struct inode *in = de->d_inode;
20500 +       int error = 0, is_proc = 0, has_tag = 0;
20501 +       struct iattr attr = { 0 };
20502 +
20503 +       if (!in || !in->i_sb)
20504 +               return -ESRCH;
20505 +
20506 +       is_proc = (in->i_sb->s_magic == PROC_SUPER_MAGIC);
20507 +       if ((*mask & IATTR_FLAGS) && !is_proc)
20508 +               return -EINVAL;
20509 +
20510 +       has_tag = IS_TAGGED(in) ||
20511 +               (in->i_sb->s_magic == DEVPTS_SUPER_MAGIC);
20512 +       if ((*mask & IATTR_TAG) && !has_tag)
20513 +               return -EINVAL;
20514 +
20515 +       mutex_lock(&in->i_mutex);
20516 +       if (*mask & IATTR_TAG) {
20517 +               attr.ia_tag = *tag;
20518 +               attr.ia_valid |= ATTR_TAG;
20519 +       }
20520 +
20521 +       if (*mask & IATTR_FLAGS) {
20522 +               struct proc_dir_entry *entry = PROC_I(in)->pde;
20523 +               unsigned int iflags = PROC_I(in)->vx_flags;
20524 +
20525 +               iflags = (iflags & ~(*mask & IATTR_FLAGS))
20526 +                       | (*flags & IATTR_FLAGS);
20527 +               PROC_I(in)->vx_flags = iflags;
20528 +               if (entry)
20529 +                       entry->vx_flags = iflags;
20530 +       }
20531 +
20532 +       if (*mask & (IATTR_BARRIER | IATTR_IXUNLINK | IATTR_IMMUTABLE)) {
20533 +               if (*mask & IATTR_IMMUTABLE) {
20534 +                       if (*flags & IATTR_IMMUTABLE)
20535 +                               in->i_flags |= S_IMMUTABLE;
20536 +                       else
20537 +                               in->i_flags &= ~S_IMMUTABLE;
20538 +               }
20539 +               if (*mask & IATTR_IXUNLINK) {
20540 +                       if (*flags & IATTR_IXUNLINK)
20541 +                               in->i_flags |= S_IXUNLINK;
20542 +                       else
20543 +                               in->i_flags &= ~S_IXUNLINK;
20544 +               }
20545 +               if (S_ISDIR(in->i_mode) && (*mask & IATTR_BARRIER)) {
20546 +                       if (*flags & IATTR_BARRIER)
20547 +                               in->i_vflags |= V_BARRIER;
20548 +                       else
20549 +                               in->i_vflags &= ~V_BARRIER;
20550 +               }
20551 +               if (in->i_op && in->i_op->sync_flags) {
20552 +                       error = in->i_op->sync_flags(in);
20553 +                       if (error)
20554 +                               goto out;
20555 +               }
20556 +       }
20557 +
20558 +       if (attr.ia_valid) {
20559 +               if (in->i_op && in->i_op->setattr)
20560 +                       error = in->i_op->setattr(de, &attr);
20561 +               else {
20562 +                       error = inode_change_ok(in, &attr);
20563 +                       if (!error)
20564 +                               error = inode_setattr(in, &attr);
20565 +               }
20566 +       }
20567 +
20568 +out:
20569 +       mutex_unlock(&in->i_mutex);
20570 +       return error;
20571 +}
20572 +
20573 +int vc_set_iattr(void __user *data)
20574 +{
20575 +       struct path path;
20576 +       struct vcmd_ctx_iattr_v1 vc_data;
20577 +       int ret;
20578 +
20579 +       if (!capable(CAP_LINUX_IMMUTABLE))
20580 +               return -EPERM;
20581 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
20582 +               return -EFAULT;
20583 +
20584 +       ret = user_lpath(vc_data.name, &path);
20585 +       if (!ret) {
20586 +               ret = __vc_set_iattr(path.dentry,
20587 +                       &vc_data.tag, &vc_data.flags, &vc_data.mask);
20588 +               path_put(&path);
20589 +       }
20590 +
20591 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
20592 +               ret = -EFAULT;
20593 +       return ret;
20594 +}
20595 +
20596 +#ifdef CONFIG_COMPAT
20597 +
20598 +int vc_set_iattr_x32(void __user *data)
20599 +{
20600 +       struct path path;
20601 +       struct vcmd_ctx_iattr_v1_x32 vc_data;
20602 +       int ret;
20603 +
20604 +       if (!capable(CAP_LINUX_IMMUTABLE))
20605 +               return -EPERM;
20606 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
20607 +               return -EFAULT;
20608 +
20609 +       ret = user_lpath(compat_ptr(vc_data.name_ptr), &path);
20610 +       if (!ret) {
20611 +               ret = __vc_set_iattr(path.dentry,
20612 +                       &vc_data.tag, &vc_data.flags, &vc_data.mask);
20613 +               path_put(&path);
20614 +       }
20615 +
20616 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
20617 +               ret = -EFAULT;
20618 +       return ret;
20619 +}
20620 +
20621 +#endif /* CONFIG_COMPAT */
20622 +
20623 +int vc_fset_iattr(uint32_t fd, void __user *data)
20624 +{
20625 +       struct file *filp;
20626 +       struct vcmd_ctx_fiattr_v0 vc_data;
20627 +       int ret;
20628 +
20629 +       if (!capable(CAP_LINUX_IMMUTABLE))
20630 +               return -EPERM;
20631 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
20632 +               return -EFAULT;
20633 +
20634 +       filp = fget(fd);
20635 +       if (!filp || !filp->f_dentry || !filp->f_dentry->d_inode)
20636 +               return -EBADF;
20637 +
20638 +       ret = __vc_set_iattr(filp->f_dentry, &vc_data.tag,
20639 +               &vc_data.flags, &vc_data.mask);
20640 +
20641 +       fput(filp);
20642 +
20643 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
20644 +               return -EFAULT;
20645 +       return ret;
20646 +}
20647 +
20648 +
20649 +enum { Opt_notagcheck, Opt_tag, Opt_notag, Opt_tagid, Opt_err };
20650 +
20651 +static match_table_t tokens = {
20652 +       {Opt_notagcheck, "notagcheck"},
20653 +#ifdef CONFIG_PROPAGATE
20654 +       {Opt_notag, "notag"},
20655 +       {Opt_tag, "tag"},
20656 +       {Opt_tagid, "tagid=%u"},
20657 +#endif
20658 +       {Opt_err, NULL}
20659 +};
20660 +
20661 +
20662 +static void __dx_parse_remove(char *string, char *opt)
20663 +{
20664 +       char *p = strstr(string, opt);
20665 +       char *q = p;
20666 +
20667 +       if (p) {
20668 +               while (*q != '\0' && *q != ',')
20669 +                       q++;
20670 +               while (*q)
20671 +                       *p++ = *q++;
20672 +               while (*p)
20673 +                       *p++ = '\0';
20674 +       }
20675 +}
20676 +
20677 +int dx_parse_tag(char *string, tag_t *tag, int remove, int *mnt_flags,
20678 +                unsigned long *flags)
20679 +{
20680 +       int set = 0;
20681 +       substring_t args[MAX_OPT_ARGS];
20682 +       int token, option = 0;
20683 +       char *s, *p, *opts;
20684 +
20685 +       if (!string)
20686 +               return 0;
20687 +       s = kstrdup(string, GFP_KERNEL | GFP_ATOMIC);
20688 +       if (!s)
20689 +               return 0;
20690 +
20691 +       opts = s;
20692 +       while ((p = strsep(&opts, ",")) != NULL) {
20693 +               token = match_token(p, tokens, args);
20694 +
20695 +               vxdprintk(VXD_CBIT(tag, 7),
20696 +                       "dx_parse_tag(»%s«): %d:#%d",
20697 +                       p, token, option);
20698 +
20699 +               switch (token) {
20700 +#ifdef CONFIG_PROPAGATE
20701 +               case Opt_tag:
20702 +                       if (tag)
20703 +                               *tag = 0;
20704 +                       if (remove)
20705 +                               __dx_parse_remove(s, "tag");
20706 +                       *mnt_flags |= MNT_TAGID;
20707 +                       set |= MNT_TAGID;
20708 +                       break;
20709 +               case Opt_notag:
20710 +                       if (remove)
20711 +                               __dx_parse_remove(s, "notag");
20712 +                       *mnt_flags |= MNT_NOTAG;
20713 +                       set |= MNT_NOTAG;
20714 +                       break;
20715 +               case Opt_tagid:
20716 +                       if (tag && !match_int(args, &option))
20717 +                               *tag = option;
20718 +                       if (remove)
20719 +                               __dx_parse_remove(s, "tagid");
20720 +                       *mnt_flags |= MNT_TAGID;
20721 +                       set |= MNT_TAGID;
20722 +                       break;
20723 +#endif
20724 +               case Opt_notagcheck:
20725 +                       if (remove)
20726 +                               __dx_parse_remove(s, "notagcheck");
20727 +                       *flags |= MS_NOTAGCHECK;
20728 +                       set |= MS_NOTAGCHECK;
20729 +                       break;
20730 +               }
20731 +       }
20732 +       if (set)
20733 +               strcpy(string, s);
20734 +       kfree(s);
20735 +       return set;
20736 +}
20737 +
20738 +#ifdef CONFIG_PROPAGATE
20739 +
20740 +void __dx_propagate_tag(struct nameidata *nd, struct inode *inode)
20741 +{
20742 +       tag_t new_tag = 0;
20743 +       struct vfsmount *mnt;
20744 +       int propagate;
20745 +
20746 +       if (!nd)
20747 +               return;
20748 +       mnt = nd->path.mnt;
20749 +       if (!mnt)
20750 +               return;
20751 +
20752 +       propagate = (mnt->mnt_flags & MNT_TAGID);
20753 +       if (propagate)
20754 +               new_tag = mnt->mnt_tag;
20755 +
20756 +       vxdprintk(VXD_CBIT(tag, 7),
20757 +               "dx_propagate_tag(%p[#%lu.%d]): %d,%d",
20758 +               inode, inode->i_ino, inode->i_tag,
20759 +               new_tag, (propagate) ? 1 : 0);
20760 +
20761 +       if (propagate)
20762 +               inode->i_tag = new_tag;
20763 +}
20764 +
20765 +#include <linux/module.h>
20766 +
20767 +EXPORT_SYMBOL_GPL(__dx_propagate_tag);
20768 +
20769 +#endif /* CONFIG_PROPAGATE */
20770 +
20771 diff -NurpP --minimal linux-2.6.29/kernel/vserver/Kconfig linux-2.6.29-vs2.3.0.36.9-pre2/kernel/vserver/Kconfig
20772 --- linux-2.6.29/kernel/vserver/Kconfig 1970-01-01 01:00:00.000000000 +0100
20773 +++ linux-2.6.29-vs2.3.0.36.9-pre2/kernel/vserver/Kconfig       2009-02-22 22:54:26.000000000 +0100
20774 @@ -0,0 +1,251 @@
20775 +#
20776 +# Linux VServer configuration
20777 +#
20778 +
20779 +menu "Linux VServer"
20780 +
20781 +config VSERVER_AUTO_LBACK
20782 +       bool    "Automatically Assign Loopback IP"
20783 +       default y
20784 +       help
20785 +         Automatically assign a guest specific loopback
20786 +         IP and add it to the kernel network stack on
20787 +         startup.
20788 +
20789 +config VSERVER_AUTO_SINGLE
20790 +       bool    "Automatic Single IP Special Casing"
20791 +       depends on EXPERIMENTAL
20792 +       default y
20793 +       help
20794 +         This allows network contexts with a single IP to
20795 +         automatically remap 0.0.0.0 bindings to that IP,
20796 +         avoiding further network checks and improving
20797 +         performance.
20798 +
20799 +         (note: such guests do not allow to change the ip
20800 +          on the fly and do not show loopback addresses)
20801 +
20802 +config VSERVER_COWBL
20803 +       bool    "Enable COW Immutable Link Breaking"
20804 +       default y
20805 +       help
20806 +         This enables the COW (Copy-On-Write) link break code.
20807 +         It allows you to treat unified files like normal files
20808 +         when writing to them (which will implicitely break the
20809 +         link and create a copy of the unified file)
20810 +
20811 +config VSERVER_VTIME
20812 +       bool    "Enable Virtualized Guest Time"
20813 +       depends on EXPERIMENTAL
20814 +       default n
20815 +       help
20816 +         This enables per guest time offsets to allow for
20817 +         adjusting the system clock individually per guest.
20818 +         this adds some overhead to the time functions and
20819 +         therefore should not be enabled without good reason.
20820 +
20821 +config VSERVER_DEVICE
20822 +       bool    "Enable Guest Device Mapping"
20823 +       depends on EXPERIMENTAL
20824 +       default n
20825 +       help
20826 +         This enables generic device remapping.
20827 +
20828 +config VSERVER_PROC_SECURE
20829 +       bool    "Enable Proc Security"
20830 +       depends on PROC_FS
20831 +       default y
20832 +       help
20833 +         This configures ProcFS security to initially hide
20834 +         non-process entries for all contexts except the main and
20835 +         spectator context (i.e. for all guests), which is a secure
20836 +         default.
20837 +
20838 +         (note: on 1.2x the entries were visible by default)
20839 +
20840 +config VSERVER_HARDCPU
20841 +       bool    "Enable Hard CPU Limits"
20842 +       default y
20843 +       help
20844 +         Activate the Hard CPU Limits
20845 +
20846 +         This will compile in code that allows the Token Bucket
20847 +         Scheduler to put processes on hold when a context's
20848 +         tokens are depleted (provided that its per-context
20849 +         sched_hard flag is set).
20850 +
20851 +         Processes belonging to that context will not be able
20852 +         to consume CPU resources again until a per-context
20853 +         configured minimum of tokens has been reached.
20854 +
20855 +config VSERVER_IDLETIME
20856 +       bool    "Avoid idle CPUs by skipping Time"
20857 +       depends on VSERVER_HARDCPU
20858 +       default y
20859 +       help
20860 +         This option allows the scheduler to artificially
20861 +         advance time (per cpu) when otherwise the idle
20862 +         task would be scheduled, thus keeping the cpu
20863 +         busy and sharing the available resources among
20864 +         certain contexts.
20865 +
20866 +config VSERVER_IDLELIMIT
20867 +       bool    "Limit the IDLE task"
20868 +       depends on VSERVER_HARDCPU
20869 +       default n
20870 +       help
20871 +         Limit the idle slices, so the the next context
20872 +         will be scheduled as soon as possible.
20873 +
20874 +         This might improve interactivity and latency, but
20875 +         will also marginally increase scheduling overhead.
20876 +
20877 +choice
20878 +       prompt  "Persistent Inode Tagging"
20879 +       default TAGGING_ID24
20880 +       help
20881 +         This adds persistent context information to filesystems
20882 +         mounted with the tagxid option. Tagging is a requirement
20883 +         for per-context disk limits and per-context quota.
20884 +
20885 +
20886 +config TAGGING_NONE
20887 +       bool    "Disabled"
20888 +       help
20889 +         do not store per-context information in inodes.
20890 +
20891 +config TAGGING_UID16
20892 +       bool    "UID16/GID32"
20893 +       help
20894 +         reduces UID to 16 bit, but leaves GID at 32 bit.
20895 +
20896 +config TAGGING_GID16
20897 +       bool    "UID32/GID16"
20898 +       help
20899 +         reduces GID to 16 bit, but leaves UID at 32 bit.
20900 +
20901 +config TAGGING_ID24
20902 +       bool    "UID24/GID24"
20903 +       help
20904 +         uses the upper 8bit from UID and GID for XID tagging
20905 +         which leaves 24bit for UID/GID each, which should be
20906 +         more than sufficient for normal use.
20907 +
20908 +config TAGGING_INTERN
20909 +       bool    "UID32/GID32"
20910 +       help
20911 +         this uses otherwise reserved inode fields in the on
20912 +         disk representation, which limits the use to a few
20913 +         filesystems (currently ext2 and ext3)
20914 +
20915 +endchoice
20916 +
20917 +config TAG_NFSD
20918 +       bool    "Tag NFSD User Auth and Files"
20919 +       default n
20920 +       help
20921 +         Enable this if you do want the in-kernel NFS
20922 +         Server to use the tagging specified above.
20923 +         (will require patched clients too)
20924 +
20925 +config VSERVER_PRIVACY
20926 +       bool    "Honor Privacy Aspects of Guests"
20927 +       default n
20928 +       help
20929 +         When enabled, most context checks will disallow
20930 +         access to structures assigned to a specific context,
20931 +         like ptys or loop devices.
20932 +
20933 +config VSERVER_CONTEXTS
20934 +       int     "Maximum number of Contexts (1-65533)"  if EMBEDDED
20935 +       range 1 65533
20936 +       default "768"   if 64BIT
20937 +       default "256"
20938 +       help
20939 +         This setting will optimize certain data structures
20940 +         and memory allocations according to the expected
20941 +         maximum.
20942 +
20943 +         note: this is not a strict upper limit.
20944 +
20945 +config VSERVER_WARN
20946 +       bool    "VServer Warnings"
20947 +       default y
20948 +       help
20949 +         This enables various runtime warnings, which will
20950 +         notify about potential manipulation attempts or
20951 +         resource shortage. It is generally considered to
20952 +         be a good idea to have that enabled.
20953 +
20954 +config VSERVER_DEBUG
20955 +       bool    "VServer Debugging Code"
20956 +       default n
20957 +       help
20958 +         Set this to yes if you want to be able to activate
20959 +         debugging output at runtime. It adds a very small
20960 +         overhead to all vserver related functions and
20961 +         increases the kernel size by about 20k.
20962 +
20963 +config VSERVER_HISTORY
20964 +       bool    "VServer History Tracing"
20965 +       depends on VSERVER_DEBUG
20966 +       default n
20967 +       help
20968 +         Set this to yes if you want to record the history of
20969 +         linux-vserver activities, so they can be replayed in
20970 +         the event of a kernel panic or oops.
20971 +
20972 +config VSERVER_HISTORY_SIZE
20973 +       int     "Per-CPU History Size (32-65536)"
20974 +       depends on VSERVER_HISTORY
20975 +       range 32 65536
20976 +       default 64
20977 +       help
20978 +         This allows you to specify the number of entries in
20979 +         the per-CPU history buffer.
20980 +
20981 +config VSERVER_MONITOR
20982 +       bool    "VServer Scheduling Monitor"
20983 +       depends on VSERVER_DISABLED
20984 +       default n
20985 +       help
20986 +         Set this to yes if you want to record the scheduling
20987 +         decisions, so that they can be relayed to userspace
20988 +         for detailed analysis.
20989 +
20990 +config VSERVER_MONITOR_SIZE
20991 +       int     "Per-CPU Monitor Queue Size (32-65536)"
20992 +       depends on VSERVER_MONITOR
20993 +       range 32 65536
20994 +       default 1024
20995 +       help
20996 +         This allows you to specify the number of entries in
20997 +         the per-CPU scheduling monitor buffer.
20998 +
20999 +config VSERVER_MONITOR_SYNC
21000 +       int     "Per-CPU Monitor Sync Interval (0-65536)"
21001 +       depends on VSERVER_MONITOR
21002 +       range 0 65536
21003 +       default 256
21004 +       help
21005 +         This allows you to specify the interval in ticks
21006 +         when a time sync entry is inserted.
21007 +
21008 +endmenu
21009 +
21010 +
21011 +config VSERVER
21012 +       bool
21013 +       default y
21014 +       select NAMESPACES
21015 +       select UTS_NS
21016 +       select IPC_NS
21017 +       select USER_NS
21018 +       select SYSVIPC
21019 +
21020 +config VSERVER_SECURITY
21021 +       bool
21022 +       depends on SECURITY
21023 +       default y
21024 +       select SECURITY_CAPABILITIES
21025 +
21026 diff -NurpP --minimal linux-2.6.29/kernel/vserver/limit.c linux-2.6.29-vs2.3.0.36.9-pre2/kernel/vserver/limit.c
21027 --- linux-2.6.29/kernel/vserver/limit.c 1970-01-01 01:00:00.000000000 +0100
21028 +++ linux-2.6.29-vs2.3.0.36.9-pre2/kernel/vserver/limit.c       2009-02-22 22:54:26.000000000 +0100
21029 @@ -0,0 +1,319 @@
21030 +/*
21031 + *  linux/kernel/vserver/limit.c
21032 + *
21033 + *  Virtual Server: Context Limits
21034 + *
21035 + *  Copyright (C) 2004-2007  Herbert Pötzl
21036 + *
21037 + *  V0.01  broken out from vcontext V0.05
21038 + *  V0.02  changed vcmds to vxi arg
21039 + *
21040 + */
21041 +
21042 +#include <linux/sched.h>
21043 +#include <linux/module.h>
21044 +#include <linux/vs_limit.h>
21045 +#include <linux/vserver/limit.h>
21046 +#include <linux/vserver/limit_cmd.h>
21047 +
21048 +#include <asm/uaccess.h>
21049 +
21050 +
21051 +const char *vlimit_name[NUM_LIMITS] = {
21052 +       [RLIMIT_CPU]            = "CPU",
21053 +       [RLIMIT_RSS]            = "RSS",
21054 +       [RLIMIT_NPROC]          = "NPROC",
21055 +       [RLIMIT_NOFILE]         = "NOFILE",
21056 +       [RLIMIT_MEMLOCK]        = "VML",
21057 +       [RLIMIT_AS]             = "VM",
21058 +       [RLIMIT_LOCKS]          = "LOCKS",
21059 +       [RLIMIT_SIGPENDING]     = "SIGP",
21060 +       [RLIMIT_MSGQUEUE]       = "MSGQ",
21061 +
21062 +       [VLIMIT_NSOCK]          = "NSOCK",
21063 +       [VLIMIT_OPENFD]         = "OPENFD",
21064 +       [VLIMIT_ANON]           = "ANON",
21065 +       [VLIMIT_SHMEM]          = "SHMEM",
21066 +       [VLIMIT_DENTRY]         = "DENTRY",
21067 +};
21068 +
21069 +EXPORT_SYMBOL_GPL(vlimit_name);
21070 +
21071 +#define MASK_ENTRY(x)  (1 << (x))
21072 +
21073 +const struct vcmd_ctx_rlimit_mask_v0 vlimit_mask = {
21074 +               /* minimum */
21075 +       0
21076 +       ,       /* softlimit */
21077 +       MASK_ENTRY( RLIMIT_RSS          ) |
21078 +       MASK_ENTRY( VLIMIT_ANON         ) |
21079 +       0
21080 +       ,       /* maximum */
21081 +       MASK_ENTRY( RLIMIT_RSS          ) |
21082 +       MASK_ENTRY( RLIMIT_NPROC        ) |
21083 +       MASK_ENTRY( RLIMIT_NOFILE       ) |
21084 +       MASK_ENTRY( RLIMIT_MEMLOCK      ) |
21085 +       MASK_ENTRY( RLIMIT_AS           ) |
21086 +       MASK_ENTRY( RLIMIT_LOCKS        ) |
21087 +       MASK_ENTRY( RLIMIT_MSGQUEUE     ) |
21088 +
21089 +       MASK_ENTRY( VLIMIT_NSOCK        ) |
21090 +       MASK_ENTRY( VLIMIT_OPENFD       ) |
21091 +       MASK_ENTRY( VLIMIT_ANON         ) |
21092 +       MASK_ENTRY( VLIMIT_SHMEM        ) |
21093 +       MASK_ENTRY( VLIMIT_DENTRY       ) |
21094 +       0
21095 +};
21096 +               /* accounting only */
21097 +uint32_t account_mask =
21098 +       MASK_ENTRY( VLIMIT_SEMARY       ) |
21099 +       MASK_ENTRY( VLIMIT_NSEMS        ) |
21100 +       MASK_ENTRY( VLIMIT_MAPPED       ) |
21101 +       0;
21102 +
21103 +
21104 +static int is_valid_vlimit(int id)
21105 +{
21106 +       uint32_t mask = vlimit_mask.minimum |
21107 +               vlimit_mask.softlimit | vlimit_mask.maximum;
21108 +       return mask & (1 << id);
21109 +}
21110 +
21111 +static int is_accounted_vlimit(int id)
21112 +{
21113 +       if (is_valid_vlimit(id))
21114 +               return 1;
21115 +       return account_mask & (1 << id);
21116 +}
21117 +
21118 +
21119 +static inline uint64_t vc_get_soft(struct vx_info *vxi, int id)
21120 +{
21121 +       rlim_t limit = __rlim_soft(&vxi->limit, id);
21122 +       return VX_VLIM(limit);
21123 +}
21124 +
21125 +static inline uint64_t vc_get_hard(struct vx_info *vxi, int id)
21126 +{
21127 +       rlim_t limit = __rlim_hard(&vxi->limit, id);
21128 +       return VX_VLIM(limit);
21129 +}
21130 +
21131 +static int do_get_rlimit(struct vx_info *vxi, uint32_t id,
21132 +       uint64_t *minimum, uint64_t *softlimit, uint64_t *maximum)
21133 +{
21134 +       if (!is_valid_vlimit(id))
21135 +               return -EINVAL;
21136 +
21137 +       if (minimum)
21138 +               *minimum = CRLIM_UNSET;
21139 +       if (softlimit)
21140 +               *softlimit = vc_get_soft(vxi, id);
21141 +       if (maximum)
21142 +               *maximum = vc_get_hard(vxi, id);
21143 +       return 0;
21144 +}
21145 +
21146 +int vc_get_rlimit(struct vx_info *vxi, void __user *data)
21147 +{
21148 +       struct vcmd_ctx_rlimit_v0 vc_data;
21149 +       int ret;
21150 +
21151 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
21152 +               return -EFAULT;
21153 +
21154 +       ret = do_get_rlimit(vxi, vc_data.id,
21155 +               &vc_data.minimum, &vc_data.softlimit, &vc_data.maximum);
21156 +       if (ret)
21157 +               return ret;
21158 +
21159 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
21160 +               return -EFAULT;
21161 +       return 0;
21162 +}
21163 +
21164 +static int do_set_rlimit(struct vx_info *vxi, uint32_t id,
21165 +       uint64_t minimum, uint64_t softlimit, uint64_t maximum)
21166 +{
21167 +       if (!is_valid_vlimit(id))
21168 +               return -EINVAL;
21169 +
21170 +       if (maximum != CRLIM_KEEP)
21171 +               __rlim_hard(&vxi->limit, id) = VX_RLIM(maximum);
21172 +       if (softlimit != CRLIM_KEEP)
21173 +               __rlim_soft(&vxi->limit, id) = VX_RLIM(softlimit);
21174 +
21175 +       /* clamp soft limit */
21176 +       if (__rlim_soft(&vxi->limit, id) > __rlim_hard(&vxi->limit, id))
21177 +               __rlim_soft(&vxi->limit, id) = __rlim_hard(&vxi->limit, id);
21178 +
21179 +       return 0;
21180 +}
21181 +
21182 +int vc_set_rlimit(struct vx_info *vxi, void __user *data)
21183 +{
21184 +       struct vcmd_ctx_rlimit_v0 vc_data;
21185 +
21186 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
21187 +               return -EFAULT;
21188 +
21189 +       return do_set_rlimit(vxi, vc_data.id,
21190 +               vc_data.minimum, vc_data.softlimit, vc_data.maximum);
21191 +}
21192 +
21193 +#ifdef CONFIG_IA32_EMULATION
21194 +
21195 +int vc_set_rlimit_x32(struct vx_info *vxi, void __user *data)
21196 +{
21197 +       struct vcmd_ctx_rlimit_v0_x32 vc_data;
21198 +
21199 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
21200 +               return -EFAULT;
21201 +
21202 +       return do_set_rlimit(vxi, vc_data.id,
21203 +               vc_data.minimum, vc_data.softlimit, vc_data.maximum);
21204 +}
21205 +
21206 +int vc_get_rlimit_x32(struct vx_info *vxi, void __user *data)
21207 +{
21208 +       struct vcmd_ctx_rlimit_v0_x32 vc_data;
21209 +       int ret;
21210 +
21211 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
21212 +               return -EFAULT;
21213 +
21214 +       ret = do_get_rlimit(vxi, vc_data.id,
21215 +               &vc_data.minimum, &vc_data.softlimit, &vc_data.maximum);
21216 +       if (ret)
21217 +               return ret;
21218 +
21219 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
21220 +               return -EFAULT;
21221 +       return 0;
21222 +}
21223 +
21224 +#endif /* CONFIG_IA32_EMULATION */
21225 +
21226 +
21227 +int vc_get_rlimit_mask(uint32_t id, void __user *data)
21228 +{
21229 +       if (copy_to_user(data, &vlimit_mask, sizeof(vlimit_mask)))
21230 +               return -EFAULT;
21231 +       return 0;
21232 +}
21233 +
21234 +
21235 +static inline void vx_reset_minmax(struct _vx_limit *limit)
21236 +{
21237 +       rlim_t value;
21238 +       int lim;
21239 +
21240 +       for (lim = 0; lim < NUM_LIMITS; lim++) {
21241 +               value = __rlim_get(limit, lim);
21242 +               __rlim_rmax(limit, lim) = value;
21243 +               __rlim_rmin(limit, lim) = value;
21244 +       }
21245 +}
21246 +
21247 +
21248 +int vc_reset_minmax(struct vx_info *vxi, void __user *data)
21249 +{
21250 +       vx_reset_minmax(&vxi->limit);
21251 +       return 0;
21252 +}
21253 +
21254 +
21255 +int vc_rlimit_stat(struct vx_info *vxi, void __user *data)
21256 +{
21257 +       struct vcmd_rlimit_stat_v0 vc_data;
21258 +       struct _vx_limit *limit = &vxi->limit;
21259 +       int id;
21260 +
21261 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
21262 +               return -EFAULT;
21263 +
21264 +       id = vc_data.id;
21265 +       if (!is_accounted_vlimit(id))
21266 +               return -EINVAL;
21267 +
21268 +       vx_limit_fixup(limit, id);
21269 +       vc_data.hits = atomic_read(&__rlim_lhit(limit, id));
21270 +       vc_data.value = __rlim_get(limit, id);
21271 +       vc_data.minimum = __rlim_rmin(limit, id);
21272 +       vc_data.maximum = __rlim_rmax(limit, id);
21273 +
21274 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
21275 +               return -EFAULT;
21276 +       return 0;
21277 +}
21278 +
21279 +
21280 +void vx_vsi_meminfo(struct sysinfo *val)
21281 +{
21282 +       struct vx_info *vxi = current->vx_info;
21283 +       unsigned long totalram, freeram;
21284 +       rlim_t v;
21285 +
21286 +       /* we blindly accept the max */
21287 +       v = __rlim_soft(&vxi->limit, RLIMIT_RSS);
21288 +       totalram = (v != RLIM_INFINITY) ? v : val->totalram;
21289 +
21290 +       /* total minus used equals free */
21291 +       v = __vx_cres_array_fixup(&vxi->limit, VLA_RSS);
21292 +       freeram = (v < totalram) ? totalram - v : 0;
21293 +
21294 +       val->totalram = totalram;
21295 +       val->freeram = freeram;
21296 +       val->bufferram = 0;
21297 +       val->totalhigh = 0;
21298 +       val->freehigh = 0;
21299 +       return;
21300 +}
21301 +
21302 +void vx_vsi_swapinfo(struct sysinfo *val)
21303 +{
21304 +       struct vx_info *vxi = current->vx_info;
21305 +       unsigned long totalswap, freeswap;
21306 +       rlim_t v, w;
21307 +
21308 +       v = __rlim_soft(&vxi->limit, RLIMIT_RSS);
21309 +       if (v == RLIM_INFINITY) {
21310 +               val->freeswap = val->totalswap;
21311 +               return;
21312 +       }
21313 +
21314 +       /* we blindly accept the max */
21315 +       w = __rlim_hard(&vxi->limit, RLIMIT_RSS);
21316 +       totalswap = (w != RLIM_INFINITY) ? (w - v) : val->totalswap;
21317 +
21318 +       /* currently 'used' swap */
21319 +       w = __vx_cres_array_fixup(&vxi->limit, VLA_RSS);
21320 +       w -= (w > v) ? v : w;
21321 +
21322 +       /* total minus used equals free */
21323 +       freeswap = (w < totalswap) ? totalswap - w : 0;
21324 +
21325 +       val->totalswap = totalswap;
21326 +       val->freeswap = freeswap;
21327 +       return;
21328 +}
21329 +
21330 +
21331 +unsigned long vx_badness(struct task_struct *task, struct mm_struct *mm)
21332 +{
21333 +       struct vx_info *vxi = mm->mm_vx_info;
21334 +       unsigned long points;
21335 +       rlim_t v, w;
21336 +
21337 +       if (!vxi)
21338 +               return 0;
21339 +
21340 +       points = vxi->vx_badness_bias;
21341 +
21342 +       v = __vx_cres_array_fixup(&vxi->limit, VLA_RSS);
21343 +       w = __rlim_soft(&vxi->limit, RLIMIT_RSS);
21344 +       points += (v > w) ? (v - w) : 0;
21345 +
21346 +       return points;
21347 +}
21348 +
21349 diff -NurpP --minimal linux-2.6.29/kernel/vserver/limit_init.h linux-2.6.29-vs2.3.0.36.9-pre2/kernel/vserver/limit_init.h
21350 --- linux-2.6.29/kernel/vserver/limit_init.h    1970-01-01 01:00:00.000000000 +0100
21351 +++ linux-2.6.29-vs2.3.0.36.9-pre2/kernel/vserver/limit_init.h  2009-02-22 22:54:26.000000000 +0100
21352 @@ -0,0 +1,31 @@
21353 +
21354 +
21355 +static inline void vx_info_init_limit(struct _vx_limit *limit)
21356 +{
21357 +       int lim;
21358 +
21359 +       for (lim = 0; lim < NUM_LIMITS; lim++) {
21360 +               __rlim_soft(limit, lim) = RLIM_INFINITY;
21361 +               __rlim_hard(limit, lim) = RLIM_INFINITY;
21362 +               __rlim_set(limit, lim, 0);
21363 +               atomic_set(&__rlim_lhit(limit, lim), 0);
21364 +               __rlim_rmin(limit, lim) = 0;
21365 +               __rlim_rmax(limit, lim) = 0;
21366 +       }
21367 +}
21368 +
21369 +static inline void vx_info_exit_limit(struct _vx_limit *limit)
21370 +{
21371 +       rlim_t value;
21372 +       int lim;
21373 +
21374 +       for (lim = 0; lim < NUM_LIMITS; lim++) {
21375 +               if ((1 << lim) & VLIM_NOCHECK)
21376 +                       continue;
21377 +               value = __rlim_get(limit, lim);
21378 +               vxwprintk_xid(value,
21379 +                       "!!! limit: %p[%s,%d] = %ld on exit.",
21380 +                       limit, vlimit_name[lim], lim, (long)value);
21381 +       }
21382 +}
21383 +
21384 diff -NurpP --minimal linux-2.6.29/kernel/vserver/limit_proc.h linux-2.6.29-vs2.3.0.36.9-pre2/kernel/vserver/limit_proc.h
21385 --- linux-2.6.29/kernel/vserver/limit_proc.h    1970-01-01 01:00:00.000000000 +0100
21386 +++ linux-2.6.29-vs2.3.0.36.9-pre2/kernel/vserver/limit_proc.h  2009-02-22 22:54:26.000000000 +0100
21387 @@ -0,0 +1,57 @@
21388 +#ifndef _VX_LIMIT_PROC_H
21389 +#define _VX_LIMIT_PROC_H
21390 +
21391 +#include <linux/vserver/limit_int.h>
21392 +
21393 +
21394 +#define VX_LIMIT_FMT   ":\t%8ld\t%8ld/%8ld\t%8lld/%8lld\t%6d\n"
21395 +#define VX_LIMIT_TOP   \
21396 +       "Limit\t current\t     min/max\t\t    soft/hard\t\thits\n"
21397 +
21398 +#define VX_LIMIT_ARG(r)                                \
21399 +       (unsigned long)__rlim_get(limit, r),    \
21400 +       (unsigned long)__rlim_rmin(limit, r),   \
21401 +       (unsigned long)__rlim_rmax(limit, r),   \
21402 +       VX_VLIM(__rlim_soft(limit, r)),         \
21403 +       VX_VLIM(__rlim_hard(limit, r)),         \
21404 +       atomic_read(&__rlim_lhit(limit, r))
21405 +
21406 +static inline int vx_info_proc_limit(struct _vx_limit *limit, char *buffer)
21407 +{
21408 +       vx_limit_fixup(limit, -1);
21409 +       return sprintf(buffer, VX_LIMIT_TOP
21410 +               "PROC"  VX_LIMIT_FMT
21411 +               "VM"    VX_LIMIT_FMT
21412 +               "VML"   VX_LIMIT_FMT
21413 +               "RSS"   VX_LIMIT_FMT
21414 +               "ANON"  VX_LIMIT_FMT
21415 +               "RMAP"  VX_LIMIT_FMT
21416 +               "FILES" VX_LIMIT_FMT
21417 +               "OFD"   VX_LIMIT_FMT
21418 +               "LOCKS" VX_LIMIT_FMT
21419 +               "SOCK"  VX_LIMIT_FMT
21420 +               "MSGQ"  VX_LIMIT_FMT
21421 +               "SHM"   VX_LIMIT_FMT
21422 +               "SEMA"  VX_LIMIT_FMT
21423 +               "SEMS"  VX_LIMIT_FMT
21424 +               "DENT"  VX_LIMIT_FMT,
21425 +               VX_LIMIT_ARG(RLIMIT_NPROC),
21426 +               VX_LIMIT_ARG(RLIMIT_AS),
21427 +               VX_LIMIT_ARG(RLIMIT_MEMLOCK),
21428 +               VX_LIMIT_ARG(RLIMIT_RSS),
21429 +               VX_LIMIT_ARG(VLIMIT_ANON),
21430 +               VX_LIMIT_ARG(VLIMIT_MAPPED),
21431 +               VX_LIMIT_ARG(RLIMIT_NOFILE),
21432 +               VX_LIMIT_ARG(VLIMIT_OPENFD),
21433 +               VX_LIMIT_ARG(RLIMIT_LOCKS),
21434 +               VX_LIMIT_ARG(VLIMIT_NSOCK),
21435 +               VX_LIMIT_ARG(RLIMIT_MSGQUEUE),
21436 +               VX_LIMIT_ARG(VLIMIT_SHMEM),
21437 +               VX_LIMIT_ARG(VLIMIT_SEMARY),
21438 +               VX_LIMIT_ARG(VLIMIT_NSEMS),
21439 +               VX_LIMIT_ARG(VLIMIT_DENTRY));
21440 +}
21441 +
21442 +#endif /* _VX_LIMIT_PROC_H */
21443 +
21444 +
21445 diff -NurpP --minimal linux-2.6.29/kernel/vserver/Makefile linux-2.6.29-vs2.3.0.36.9-pre2/kernel/vserver/Makefile
21446 --- linux-2.6.29/kernel/vserver/Makefile        1970-01-01 01:00:00.000000000 +0100
21447 +++ linux-2.6.29-vs2.3.0.36.9-pre2/kernel/vserver/Makefile      2009-02-22 22:54:26.000000000 +0100
21448 @@ -0,0 +1,18 @@
21449 +#
21450 +# Makefile for the Linux vserver routines.
21451 +#
21452 +
21453 +
21454 +obj-y          += vserver.o
21455 +
21456 +vserver-y      := switch.o context.o space.o sched.o network.o inode.o \
21457 +                  limit.o cvirt.o cacct.o signal.o helper.o init.o \
21458 +                  dlimit.o tag.o
21459 +
21460 +vserver-$(CONFIG_INET) += inet.o
21461 +vserver-$(CONFIG_PROC_FS) += proc.o
21462 +vserver-$(CONFIG_VSERVER_DEBUG) += sysctl.o debug.o
21463 +vserver-$(CONFIG_VSERVER_HISTORY) += history.o
21464 +vserver-$(CONFIG_VSERVER_MONITOR) += monitor.o
21465 +vserver-$(CONFIG_VSERVER_DEVICE) += device.o
21466 +
21467 diff -NurpP --minimal linux-2.6.29/kernel/vserver/monitor.c linux-2.6.29-vs2.3.0.36.9-pre2/kernel/vserver/monitor.c
21468 --- linux-2.6.29/kernel/vserver/monitor.c       1970-01-01 01:00:00.000000000 +0100
21469 +++ linux-2.6.29-vs2.3.0.36.9-pre2/kernel/vserver/monitor.c     2009-02-22 22:54:26.000000000 +0100
21470 @@ -0,0 +1,138 @@
21471 +/*
21472 + *  kernel/vserver/monitor.c
21473 + *
21474 + *  Virtual Context Scheduler Monitor
21475 + *
21476 + *  Copyright (C) 2006-2007 Herbert Pötzl
21477 + *
21478 + *  V0.01  basic design
21479 + *
21480 + */
21481 +
21482 +#include <linux/module.h>
21483 +#include <linux/jiffies.h>
21484 +#include <asm/uaccess.h>
21485 +#include <asm/atomic.h>
21486 +
21487 +#include <linux/vserver/monitor.h>
21488 +#include <linux/vserver/debug_cmd.h>
21489 +
21490 +
21491 +#ifdef CONFIG_VSERVER_MONITOR
21492 +#define VXM_SIZE       CONFIG_VSERVER_MONITOR_SIZE
21493 +#else
21494 +#define VXM_SIZE       64
21495 +#endif
21496 +
21497 +struct _vx_monitor {
21498 +       unsigned int counter;
21499 +
21500 +       struct _vx_mon_entry entry[VXM_SIZE+1];
21501 +};
21502 +
21503 +
21504 +DEFINE_PER_CPU(struct _vx_monitor, vx_monitor_buffer);
21505 +
21506 +unsigned volatile int vxm_active = 1;
21507 +
21508 +static atomic_t sequence = ATOMIC_INIT(0);
21509 +
21510 +
21511 +/*     vxm_advance()
21512 +
21513 +       * requires disabled preemption                          */
21514 +
21515 +struct _vx_mon_entry *vxm_advance(int cpu)
21516 +{
21517 +       struct _vx_monitor *mon = &per_cpu(vx_monitor_buffer, cpu);
21518 +       struct _vx_mon_entry *entry;
21519 +       unsigned int index;
21520 +
21521 +       index = vxm_active ? (mon->counter++ % VXM_SIZE) : VXM_SIZE;
21522 +       entry = &mon->entry[index];
21523 +
21524 +       entry->ev.seq = atomic_inc_return(&sequence);
21525 +       entry->ev.jif = jiffies;
21526 +       return entry;
21527 +}
21528 +
21529 +EXPORT_SYMBOL_GPL(vxm_advance);
21530 +
21531 +
21532 +int do_read_monitor(struct __user _vx_mon_entry *data,
21533 +       int cpu, uint32_t *index, uint32_t *count)
21534 +{
21535 +       int pos, ret = 0;
21536 +       struct _vx_monitor *mon = &per_cpu(vx_monitor_buffer, cpu);
21537 +       int end = mon->counter;
21538 +       int start = end - VXM_SIZE + 2;
21539 +       int idx = *index;
21540 +
21541 +       /* special case: get current pos */
21542 +       if (!*count) {
21543 +               *index = end;
21544 +               return 0;
21545 +       }
21546 +
21547 +       /* have we lost some data? */
21548 +       if (idx < start)
21549 +               idx = start;
21550 +
21551 +       for (pos = 0; (pos < *count) && (idx < end); pos++, idx++) {
21552 +               struct _vx_mon_entry *entry =
21553 +                       &mon->entry[idx % VXM_SIZE];
21554 +
21555 +               /* send entry to userspace */
21556 +               ret = copy_to_user(&data[pos], entry, sizeof(*entry));
21557 +               if (ret)
21558 +                       break;
21559 +       }
21560 +       /* save new index and count */
21561 +       *index = idx;
21562 +       *count = pos;
21563 +       return ret ? ret : (*index < end);
21564 +}
21565 +
21566 +int vc_read_monitor(uint32_t id, void __user *data)
21567 +{
21568 +       struct vcmd_read_monitor_v0 vc_data;
21569 +       int ret;
21570 +
21571 +       if (id >= NR_CPUS)
21572 +               return -EINVAL;
21573 +
21574 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
21575 +               return -EFAULT;
21576 +
21577 +       ret = do_read_monitor((struct __user _vx_mon_entry *)vc_data.data,
21578 +               id, &vc_data.index, &vc_data.count);
21579 +
21580 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
21581 +               return -EFAULT;
21582 +       return ret;
21583 +}
21584 +
21585 +#ifdef CONFIG_COMPAT
21586 +
21587 +int vc_read_monitor_x32(uint32_t id, void __user *data)
21588 +{
21589 +       struct vcmd_read_monitor_v0_x32 vc_data;
21590 +       int ret;
21591 +
21592 +       if (id >= NR_CPUS)
21593 +               return -EINVAL;
21594 +
21595 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
21596 +               return -EFAULT;
21597 +
21598 +       ret = do_read_monitor((struct __user _vx_mon_entry *)
21599 +               compat_ptr(vc_data.data_ptr),
21600 +               id, &vc_data.index, &vc_data.count);
21601 +
21602 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
21603 +               return -EFAULT;
21604 +       return ret;
21605 +}
21606 +
21607 +#endif /* CONFIG_COMPAT */
21608 +
21609 diff -NurpP --minimal linux-2.6.29/kernel/vserver/network.c linux-2.6.29-vs2.3.0.36.9-pre2/kernel/vserver/network.c
21610 --- linux-2.6.29/kernel/vserver/network.c       1970-01-01 01:00:00.000000000 +0100
21611 +++ linux-2.6.29-vs2.3.0.36.9-pre2/kernel/vserver/network.c     2009-02-22 22:54:26.000000000 +0100
21612 @@ -0,0 +1,864 @@
21613 +/*
21614 + *  linux/kernel/vserver/network.c
21615 + *
21616 + *  Virtual Server: Network Support
21617 + *
21618 + *  Copyright (C) 2003-2007  Herbert Pötzl
21619 + *
21620 + *  V0.01  broken out from vcontext V0.05
21621 + *  V0.02  cleaned up implementation
21622 + *  V0.03  added equiv nx commands
21623 + *  V0.04  switch to RCU based hash
21624 + *  V0.05  and back to locking again
21625 + *  V0.06  changed vcmds to nxi arg
21626 + *  V0.07  have __create claim() the nxi
21627 + *
21628 + */
21629 +
21630 +#include <linux/err.h>
21631 +#include <linux/slab.h>
21632 +#include <linux/rcupdate.h>
21633 +
21634 +#include <linux/vs_network.h>
21635 +#include <linux/vs_pid.h>
21636 +#include <linux/vserver/network_cmd.h>
21637 +
21638 +
21639 +atomic_t nx_global_ctotal      = ATOMIC_INIT(0);
21640 +atomic_t nx_global_cactive     = ATOMIC_INIT(0);
21641 +
21642 +static struct kmem_cache *nx_addr_v4_cachep = NULL;
21643 +static struct kmem_cache *nx_addr_v6_cachep = NULL;
21644 +
21645 +
21646 +static int __init init_network(void)
21647 +{
21648 +       nx_addr_v4_cachep = kmem_cache_create("nx_v4_addr_cache",
21649 +               sizeof(struct nx_addr_v4), 0,
21650 +               SLAB_HWCACHE_ALIGN|SLAB_PANIC, NULL);
21651 +       nx_addr_v6_cachep = kmem_cache_create("nx_v6_addr_cache",
21652 +               sizeof(struct nx_addr_v6), 0,
21653 +               SLAB_HWCACHE_ALIGN|SLAB_PANIC, NULL);
21654 +       return 0;
21655 +}
21656 +
21657 +
21658 +/*     __alloc_nx_addr_v4()                                    */
21659 +
21660 +static inline struct nx_addr_v4 *__alloc_nx_addr_v4(void)
21661 +{
21662 +       struct nx_addr_v4 *nxa = kmem_cache_alloc(
21663 +               nx_addr_v4_cachep, GFP_KERNEL);
21664 +
21665 +       if (!IS_ERR(nxa))
21666 +               memset(nxa, 0, sizeof(*nxa));
21667 +       return nxa;
21668 +}
21669 +
21670 +/*     __dealloc_nx_addr_v4()                                  */
21671 +
21672 +static inline void __dealloc_nx_addr_v4(struct nx_addr_v4 *nxa)
21673 +{
21674 +       kmem_cache_free(nx_addr_v4_cachep, nxa);
21675 +}
21676 +
21677 +/*     __dealloc_nx_addr_v4_all()                              */
21678 +
21679 +static inline void __dealloc_nx_addr_v4_all(struct nx_addr_v4 *nxa)
21680 +{
21681 +       while (nxa) {
21682 +               struct nx_addr_v4 *next = nxa->next;
21683 +
21684 +               __dealloc_nx_addr_v4(nxa);
21685 +               nxa = next;
21686 +       }
21687 +}
21688 +
21689 +
21690 +#ifdef CONFIG_IPV6
21691 +
21692 +/*     __alloc_nx_addr_v6()                                    */
21693 +
21694 +static inline struct nx_addr_v6 *__alloc_nx_addr_v6(void)
21695 +{
21696 +       struct nx_addr_v6 *nxa = kmem_cache_alloc(
21697 +               nx_addr_v6_cachep, GFP_KERNEL);
21698 +
21699 +       if (!IS_ERR(nxa))
21700 +               memset(nxa, 0, sizeof(*nxa));
21701 +       return nxa;
21702 +}
21703 +
21704 +/*     __dealloc_nx_addr_v6()                                  */
21705 +
21706 +static inline void __dealloc_nx_addr_v6(struct nx_addr_v6 *nxa)
21707 +{
21708 +       kmem_cache_free(nx_addr_v6_cachep, nxa);
21709 +}
21710 +
21711 +/*     __dealloc_nx_addr_v6_all()                              */
21712 +
21713 +static inline void __dealloc_nx_addr_v6_all(struct nx_addr_v6 *nxa)
21714 +{
21715 +       while (nxa) {
21716 +               struct nx_addr_v6 *next = nxa->next;
21717 +
21718 +               __dealloc_nx_addr_v6(nxa);
21719 +               nxa = next;
21720 +       }
21721 +}
21722 +
21723 +#endif /* CONFIG_IPV6 */
21724 +
21725 +/*     __alloc_nx_info()
21726 +
21727 +       * allocate an initialized nx_info struct
21728 +       * doesn't make it visible (hash)                        */
21729 +
21730 +static struct nx_info *__alloc_nx_info(nid_t nid)
21731 +{
21732 +       struct nx_info *new = NULL;
21733 +
21734 +       vxdprintk(VXD_CBIT(nid, 1), "alloc_nx_info(%d)*", nid);
21735 +
21736 +       /* would this benefit from a slab cache? */
21737 +       new = kmalloc(sizeof(struct nx_info), GFP_KERNEL);
21738 +       if (!new)
21739 +               return 0;
21740 +
21741 +       memset(new, 0, sizeof(struct nx_info));
21742 +       new->nx_id = nid;
21743 +       INIT_HLIST_NODE(&new->nx_hlist);
21744 +       atomic_set(&new->nx_usecnt, 0);
21745 +       atomic_set(&new->nx_tasks, 0);
21746 +       new->nx_state = 0;
21747 +
21748 +       new->nx_flags = NXF_INIT_SET;
21749 +
21750 +       /* rest of init goes here */
21751 +
21752 +       new->v4_lback.s_addr = htonl(INADDR_LOOPBACK);
21753 +       new->v4_bcast.s_addr = htonl(INADDR_BROADCAST);
21754 +
21755 +       vxdprintk(VXD_CBIT(nid, 0),
21756 +               "alloc_nx_info(%d) = %p", nid, new);
21757 +       atomic_inc(&nx_global_ctotal);
21758 +       return new;
21759 +}
21760 +
21761 +/*     __dealloc_nx_info()
21762 +
21763 +       * final disposal of nx_info                             */
21764 +
21765 +static void __dealloc_nx_info(struct nx_info *nxi)
21766 +{
21767 +       vxdprintk(VXD_CBIT(nid, 0),
21768 +               "dealloc_nx_info(%p)", nxi);
21769 +
21770 +       nxi->nx_hlist.next = LIST_POISON1;
21771 +       nxi->nx_id = -1;
21772 +
21773 +       BUG_ON(atomic_read(&nxi->nx_usecnt));
21774 +       BUG_ON(atomic_read(&nxi->nx_tasks));
21775 +
21776 +       __dealloc_nx_addr_v4_all(nxi->v4.next);
21777 +
21778 +       nxi->nx_state |= NXS_RELEASED;
21779 +       kfree(nxi);
21780 +       atomic_dec(&nx_global_ctotal);
21781 +}
21782 +
21783 +static void __shutdown_nx_info(struct nx_info *nxi)
21784 +{
21785 +       nxi->nx_state |= NXS_SHUTDOWN;
21786 +       vs_net_change(nxi, VSC_NETDOWN);
21787 +}
21788 +
21789 +/*     exported stuff                                          */
21790 +
21791 +void free_nx_info(struct nx_info *nxi)
21792 +{
21793 +       /* context shutdown is mandatory */
21794 +       BUG_ON(nxi->nx_state != NXS_SHUTDOWN);
21795 +
21796 +       /* context must not be hashed */
21797 +       BUG_ON(nxi->nx_state & NXS_HASHED);
21798 +
21799 +       BUG_ON(atomic_read(&nxi->nx_usecnt));
21800 +       BUG_ON(atomic_read(&nxi->nx_tasks));
21801 +
21802 +       __dealloc_nx_info(nxi);
21803 +}
21804 +
21805 +
21806 +void __nx_set_lback(struct nx_info *nxi)
21807 +{
21808 +       int nid = nxi->nx_id;
21809 +       __be32 lback = htonl(INADDR_LOOPBACK ^ ((nid & 0xFFFF) << 8));
21810 +
21811 +       nxi->v4_lback.s_addr = lback;
21812 +}
21813 +
21814 +extern int __nx_inet_add_lback(__be32 addr);
21815 +extern int __nx_inet_del_lback(__be32 addr);
21816 +
21817 +
21818 +/*     hash table for nx_info hash */
21819 +
21820 +#define NX_HASH_SIZE   13
21821 +
21822 +struct hlist_head nx_info_hash[NX_HASH_SIZE];
21823 +
21824 +static spinlock_t nx_info_hash_lock = SPIN_LOCK_UNLOCKED;
21825 +
21826 +
21827 +static inline unsigned int __hashval(nid_t nid)
21828 +{
21829 +       return (nid % NX_HASH_SIZE);
21830 +}
21831 +
21832 +
21833 +
21834 +/*     __hash_nx_info()
21835 +
21836 +       * add the nxi to the global hash table
21837 +       * requires the hash_lock to be held                     */
21838 +
21839 +static inline void __hash_nx_info(struct nx_info *nxi)
21840 +{
21841 +       struct hlist_head *head;
21842 +
21843 +       vxd_assert_lock(&nx_info_hash_lock);
21844 +       vxdprintk(VXD_CBIT(nid, 4),
21845 +               "__hash_nx_info: %p[#%d]", nxi, nxi->nx_id);
21846 +
21847 +       /* context must not be hashed */
21848 +       BUG_ON(nx_info_state(nxi, NXS_HASHED));
21849 +
21850 +       nxi->nx_state |= NXS_HASHED;
21851 +       head = &nx_info_hash[__hashval(nxi->nx_id)];
21852 +       hlist_add_head(&nxi->nx_hlist, head);
21853 +       atomic_inc(&nx_global_cactive);
21854 +}
21855 +
21856 +/*     __unhash_nx_info()
21857 +
21858 +       * remove the nxi from the global hash table
21859 +       * requires the hash_lock to be held                     */
21860 +
21861 +static inline void __unhash_nx_info(struct nx_info *nxi)
21862 +{
21863 +       vxd_assert_lock(&nx_info_hash_lock);
21864 +       vxdprintk(VXD_CBIT(nid, 4),
21865 +               "__unhash_nx_info: %p[#%d.%d.%d]", nxi, nxi->nx_id,
21866 +               atomic_read(&nxi->nx_usecnt), atomic_read(&nxi->nx_tasks));
21867 +
21868 +       /* context must be hashed */
21869 +       BUG_ON(!nx_info_state(nxi, NXS_HASHED));
21870 +       /* but without tasks */
21871 +       BUG_ON(atomic_read(&nxi->nx_tasks));
21872 +
21873 +       nxi->nx_state &= ~NXS_HASHED;
21874 +       hlist_del(&nxi->nx_hlist);
21875 +       atomic_dec(&nx_global_cactive);
21876 +}
21877 +
21878 +
21879 +/*     __lookup_nx_info()
21880 +
21881 +       * requires the hash_lock to be held
21882 +       * doesn't increment the nx_refcnt                       */
21883 +
21884 +static inline struct nx_info *__lookup_nx_info(nid_t nid)
21885 +{
21886 +       struct hlist_head *head = &nx_info_hash[__hashval(nid)];
21887 +       struct hlist_node *pos;
21888 +       struct nx_info *nxi;
21889 +
21890 +       vxd_assert_lock(&nx_info_hash_lock);
21891 +       hlist_for_each(pos, head) {
21892 +               nxi = hlist_entry(pos, struct nx_info, nx_hlist);
21893 +
21894 +               if (nxi->nx_id == nid)
21895 +                       goto found;
21896 +       }
21897 +       nxi = NULL;
21898 +found:
21899 +       vxdprintk(VXD_CBIT(nid, 0),
21900 +               "__lookup_nx_info(#%u): %p[#%u]",
21901 +               nid, nxi, nxi ? nxi->nx_id : 0);
21902 +       return nxi;
21903 +}
21904 +
21905 +
21906 +/*     __create_nx_info()
21907 +
21908 +       * create the requested context
21909 +       * get(), claim() and hash it                            */
21910 +
21911 +static struct nx_info *__create_nx_info(int id)
21912 +{
21913 +       struct nx_info *new, *nxi = NULL;
21914 +
21915 +       vxdprintk(VXD_CBIT(nid, 1), "create_nx_info(%d)*", id);
21916 +
21917 +       if (!(new = __alloc_nx_info(id)))
21918 +               return ERR_PTR(-ENOMEM);
21919 +
21920 +       /* required to make dynamic xids unique */
21921 +       spin_lock(&nx_info_hash_lock);
21922 +
21923 +       /* static context requested */
21924 +       if ((nxi = __lookup_nx_info(id))) {
21925 +               vxdprintk(VXD_CBIT(nid, 0),
21926 +                       "create_nx_info(%d) = %p (already there)", id, nxi);
21927 +               if (nx_info_flags(nxi, NXF_STATE_SETUP, 0))
21928 +                       nxi = ERR_PTR(-EBUSY);
21929 +               else
21930 +                       nxi = ERR_PTR(-EEXIST);
21931 +               goto out_unlock;
21932 +       }
21933 +       /* new context */
21934 +       vxdprintk(VXD_CBIT(nid, 0),
21935 +               "create_nx_info(%d) = %p (new)", id, new);
21936 +       claim_nx_info(new, NULL);
21937 +       __nx_set_lback(new);
21938 +       __hash_nx_info(get_nx_info(new));
21939 +       nxi = new, new = NULL;
21940 +
21941 +out_unlock:
21942 +       spin_unlock(&nx_info_hash_lock);
21943 +       if (new)
21944 +               __dealloc_nx_info(new);
21945 +       return nxi;
21946 +}
21947 +
21948 +
21949 +
21950 +/*     exported stuff                                          */
21951 +
21952 +
21953 +void unhash_nx_info(struct nx_info *nxi)
21954 +{
21955 +       __shutdown_nx_info(nxi);
21956 +       spin_lock(&nx_info_hash_lock);
21957 +       __unhash_nx_info(nxi);
21958 +       spin_unlock(&nx_info_hash_lock);
21959 +}
21960 +
21961 +/*     lookup_nx_info()
21962 +
21963 +       * search for a nx_info and get() it
21964 +       * negative id means current                             */
21965 +
21966 +struct nx_info *lookup_nx_info(int id)
21967 +{
21968 +       struct nx_info *nxi = NULL;
21969 +
21970 +       if (id < 0) {
21971 +               nxi = get_nx_info(current->nx_info);
21972 +       } else if (id > 1) {
21973 +               spin_lock(&nx_info_hash_lock);
21974 +               nxi = get_nx_info(__lookup_nx_info(id));
21975 +               spin_unlock(&nx_info_hash_lock);
21976 +       }
21977 +       return nxi;
21978 +}
21979 +
21980 +/*     nid_is_hashed()
21981 +
21982 +       * verify that nid is still hashed                       */
21983 +
21984 +int nid_is_hashed(nid_t nid)
21985 +{
21986 +       int hashed;
21987 +
21988 +       spin_lock(&nx_info_hash_lock);
21989 +       hashed = (__lookup_nx_info(nid) != NULL);
21990 +       spin_unlock(&nx_info_hash_lock);
21991 +       return hashed;
21992 +}
21993 +
21994 +
21995 +#ifdef CONFIG_PROC_FS
21996 +
21997 +/*     get_nid_list()
21998 +
21999 +       * get a subset of hashed nids for proc
22000 +       * assumes size is at least one                          */
22001 +
22002 +int get_nid_list(int index, unsigned int *nids, int size)
22003 +{
22004 +       int hindex, nr_nids = 0;
22005 +
22006 +       /* only show current and children */
22007 +       if (!nx_check(0, VS_ADMIN | VS_WATCH)) {
22008 +               if (index > 0)
22009 +                       return 0;
22010 +               nids[nr_nids] = nx_current_nid();
22011 +               return 1;
22012 +       }
22013 +
22014 +       for (hindex = 0; hindex < NX_HASH_SIZE; hindex++) {
22015 +               struct hlist_head *head = &nx_info_hash[hindex];
22016 +               struct hlist_node *pos;
22017 +
22018 +               spin_lock(&nx_info_hash_lock);
22019 +               hlist_for_each(pos, head) {
22020 +                       struct nx_info *nxi;
22021 +
22022 +                       if (--index > 0)
22023 +                               continue;
22024 +
22025 +                       nxi = hlist_entry(pos, struct nx_info, nx_hlist);
22026 +                       nids[nr_nids] = nxi->nx_id;
22027 +                       if (++nr_nids >= size) {
22028 +                               spin_unlock(&nx_info_hash_lock);
22029 +                               goto out;
22030 +                       }
22031 +               }
22032 +               /* keep the lock time short */
22033 +               spin_unlock(&nx_info_hash_lock);
22034 +       }
22035 +out:
22036 +       return nr_nids;
22037 +}
22038 +#endif
22039 +
22040 +
22041 +/*
22042 + *     migrate task to new network
22043 + *     gets nxi, puts old_nxi on change
22044 + */
22045 +
22046 +int nx_migrate_task(struct task_struct *p, struct nx_info *nxi)
22047 +{
22048 +       struct nx_info *old_nxi;
22049 +       int ret = 0;
22050 +
22051 +       if (!p || !nxi)
22052 +               BUG();
22053 +
22054 +       vxdprintk(VXD_CBIT(nid, 5),
22055 +               "nx_migrate_task(%p,%p[#%d.%d.%d])",
22056 +               p, nxi, nxi->nx_id,
22057 +               atomic_read(&nxi->nx_usecnt),
22058 +               atomic_read(&nxi->nx_tasks));
22059 +
22060 +       if (nx_info_flags(nxi, NXF_INFO_PRIVATE, 0) &&
22061 +               !nx_info_flags(nxi, NXF_STATE_SETUP, 0))
22062 +               return -EACCES;
22063 +
22064 +       if (nx_info_state(nxi, NXS_SHUTDOWN))
22065 +               return -EFAULT;
22066 +
22067 +       /* maybe disallow this completely? */
22068 +       old_nxi = task_get_nx_info(p);
22069 +       if (old_nxi == nxi)
22070 +               goto out;
22071 +
22072 +       task_lock(p);
22073 +       if (old_nxi)
22074 +               clr_nx_info(&p->nx_info);
22075 +       claim_nx_info(nxi, p);
22076 +       set_nx_info(&p->nx_info, nxi);
22077 +       p->nid = nxi->nx_id;
22078 +       task_unlock(p);
22079 +
22080 +       vxdprintk(VXD_CBIT(nid, 5),
22081 +               "moved task %p into nxi:%p[#%d]",
22082 +               p, nxi, nxi->nx_id);
22083 +
22084 +       if (old_nxi)
22085 +               release_nx_info(old_nxi, p);
22086 +       ret = 0;
22087 +out:
22088 +       put_nx_info(old_nxi);
22089 +       return ret;
22090 +}
22091 +
22092 +
22093 +void nx_set_persistent(struct nx_info *nxi)
22094 +{
22095 +       vxdprintk(VXD_CBIT(nid, 6),
22096 +               "nx_set_persistent(%p[#%d])", nxi, nxi->nx_id);
22097 +
22098 +       get_nx_info(nxi);
22099 +       claim_nx_info(nxi, NULL);
22100 +}
22101 +
22102 +void nx_clear_persistent(struct nx_info *nxi)
22103 +{
22104 +       vxdprintk(VXD_CBIT(nid, 6),
22105 +               "nx_clear_persistent(%p[#%d])", nxi, nxi->nx_id);
22106 +
22107 +       release_nx_info(nxi, NULL);
22108 +       put_nx_info(nxi);
22109 +}
22110 +
22111 +void nx_update_persistent(struct nx_info *nxi)
22112 +{
22113 +       if (nx_info_flags(nxi, NXF_PERSISTENT, 0))
22114 +               nx_set_persistent(nxi);
22115 +       else
22116 +               nx_clear_persistent(nxi);
22117 +}
22118 +
22119 +/* vserver syscall commands below here */
22120 +
22121 +/* taks nid and nx_info functions */
22122 +
22123 +#include <asm/uaccess.h>
22124 +
22125 +
22126 +int vc_task_nid(uint32_t id)
22127 +{
22128 +       nid_t nid;
22129 +
22130 +       if (id) {
22131 +               struct task_struct *tsk;
22132 +
22133 +               read_lock(&tasklist_lock);
22134 +               tsk = find_task_by_real_pid(id);
22135 +               nid = (tsk) ? tsk->nid : -ESRCH;
22136 +               read_unlock(&tasklist_lock);
22137 +       } else
22138 +               nid = nx_current_nid();
22139 +       return nid;
22140 +}
22141 +
22142 +
22143 +int vc_nx_info(struct nx_info *nxi, void __user *data)
22144 +{
22145 +       struct vcmd_nx_info_v0 vc_data;
22146 +
22147 +       vc_data.nid = nxi->nx_id;
22148 +
22149 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
22150 +               return -EFAULT;
22151 +       return 0;
22152 +}
22153 +
22154 +
22155 +/* network functions */
22156 +
22157 +int vc_net_create(uint32_t nid, void __user *data)
22158 +{
22159 +       struct vcmd_net_create vc_data = { .flagword = NXF_INIT_SET };
22160 +       struct nx_info *new_nxi;
22161 +       int ret;
22162 +
22163 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
22164 +               return -EFAULT;
22165 +
22166 +       if ((nid > MAX_S_CONTEXT) || (nid < 2))
22167 +               return -EINVAL;
22168 +
22169 +       new_nxi = __create_nx_info(nid);
22170 +       if (IS_ERR(new_nxi))
22171 +               return PTR_ERR(new_nxi);
22172 +
22173 +       /* initial flags */
22174 +       new_nxi->nx_flags = vc_data.flagword;
22175 +
22176 +       ret = -ENOEXEC;
22177 +       if (vs_net_change(new_nxi, VSC_NETUP))
22178 +               goto out;
22179 +
22180 +       ret = nx_migrate_task(current, new_nxi);
22181 +       if (ret)
22182 +               goto out;
22183 +
22184 +       /* return context id on success */
22185 +       ret = new_nxi->nx_id;
22186 +
22187 +       /* get a reference for persistent contexts */
22188 +       if ((vc_data.flagword & NXF_PERSISTENT))
22189 +               nx_set_persistent(new_nxi);
22190 +out:
22191 +       release_nx_info(new_nxi, NULL);
22192 +       put_nx_info(new_nxi);
22193 +       return ret;
22194 +}
22195 +
22196 +
22197 +int vc_net_migrate(struct nx_info *nxi, void __user *data)
22198 +{
22199 +       return nx_migrate_task(current, nxi);
22200 +}
22201 +
22202 +
22203 +
22204 +int do_add_v4_addr(struct nx_info *nxi, __be32 ip, __be32 ip2, __be32 mask,
22205 +       uint16_t type, uint16_t flags)
22206 +{
22207 +       struct nx_addr_v4 *nxa = &nxi->v4;
22208 +
22209 +       if (NX_IPV4(nxi)) {
22210 +               /* locate last entry */
22211 +               for (; nxa->next; nxa = nxa->next);
22212 +               nxa->next = __alloc_nx_addr_v4();
22213 +               nxa = nxa->next;
22214 +
22215 +               if (IS_ERR(nxa))
22216 +                       return PTR_ERR(nxa);
22217 +       }
22218 +
22219 +       if (nxi->v4.next)
22220 +               /* remove single ip for ip list */
22221 +               nxi->nx_flags &= ~NXF_SINGLE_IP;
22222 +
22223 +       nxa->ip[0].s_addr = ip;
22224 +       nxa->ip[1].s_addr = ip2;
22225 +       nxa->mask.s_addr = mask;
22226 +       nxa->type = type;
22227 +       nxa->flags = flags;
22228 +       return 0;
22229 +}
22230 +
22231 +
22232 +int vc_net_add(struct nx_info *nxi, void __user *data)
22233 +{
22234 +       struct vcmd_net_addr_v0 vc_data;
22235 +       int index, ret = 0;
22236 +
22237 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
22238 +               return -EFAULT;
22239 +
22240 +       switch (vc_data.type) {
22241 +       case NXA_TYPE_IPV4:
22242 +               if ((vc_data.count < 1) || (vc_data.count > 4))
22243 +                       return -EINVAL;
22244 +
22245 +               index = 0;
22246 +               while (index < vc_data.count) {
22247 +                       ret = do_add_v4_addr(nxi, vc_data.ip[index].s_addr, 0,
22248 +                               vc_data.mask[index].s_addr, NXA_TYPE_ADDR, 0);
22249 +                       if (ret)
22250 +                               return ret;
22251 +                       index++;
22252 +               }
22253 +               ret = index;
22254 +               break;
22255 +
22256 +       case NXA_TYPE_IPV4|NXA_MOD_BCAST:
22257 +               nxi->v4_bcast = vc_data.ip[0];
22258 +               ret = 1;
22259 +               break;
22260 +
22261 +       case NXA_TYPE_IPV4|NXA_MOD_LBACK:
22262 +               nxi->v4_lback = vc_data.ip[0];
22263 +               ret = 1;
22264 +               break;
22265 +
22266 +       default:
22267 +               ret = -EINVAL;
22268 +               break;
22269 +       }
22270 +       return ret;
22271 +}
22272 +
22273 +int vc_net_remove(struct nx_info *nxi, void __user *data)
22274 +{
22275 +       struct vcmd_net_addr_v0 vc_data;
22276 +
22277 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
22278 +               return -EFAULT;
22279 +
22280 +       switch (vc_data.type) {
22281 +       case NXA_TYPE_ANY:
22282 +               __dealloc_nx_addr_v4_all(xchg(&nxi->v4.next, NULL));
22283 +               memset(&nxi->v4, 0, sizeof(nxi->v4));
22284 +               break;
22285 +
22286 +       default:
22287 +               return -EINVAL;
22288 +       }
22289 +       return 0;
22290 +}
22291 +
22292 +
22293 +int vc_net_add_ipv4(struct nx_info *nxi, void __user *data)
22294 +{
22295 +       struct vcmd_net_addr_ipv4_v1 vc_data;
22296 +
22297 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
22298 +               return -EFAULT;
22299 +
22300 +       switch (vc_data.type) {
22301 +       case NXA_TYPE_ADDR:
22302 +       case NXA_TYPE_RANGE:
22303 +       case NXA_TYPE_MASK:
22304 +               return do_add_v4_addr(nxi, vc_data.ip.s_addr, 0,
22305 +                       vc_data.mask.s_addr, vc_data.type, vc_data.flags);
22306 +
22307 +       case NXA_TYPE_ADDR | NXA_MOD_BCAST:
22308 +               nxi->v4_bcast = vc_data.ip;
22309 +               break;
22310 +
22311 +       case NXA_TYPE_ADDR | NXA_MOD_LBACK:
22312 +               nxi->v4_lback = vc_data.ip;
22313 +               break;
22314 +
22315 +       default:
22316 +               return -EINVAL;
22317 +       }
22318 +       return 0;
22319 +}
22320 +
22321 +int vc_net_remove_ipv4(struct nx_info *nxi, void __user *data)
22322 +{
22323 +       struct vcmd_net_addr_ipv4_v1 vc_data;
22324 +
22325 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
22326 +               return -EFAULT;
22327 +
22328 +       switch (vc_data.type) {
22329 +/*     case NXA_TYPE_ADDR:
22330 +               break;          */
22331 +
22332 +       case NXA_TYPE_ANY:
22333 +               __dealloc_nx_addr_v4_all(xchg(&nxi->v4.next, NULL));
22334 +               memset(&nxi->v4, 0, sizeof(nxi->v4));
22335 +               break;
22336 +
22337 +       default:
22338 +               return -EINVAL;
22339 +       }
22340 +       return 0;
22341 +}
22342 +
22343 +
22344 +#ifdef CONFIG_IPV6
22345 +
22346 +int do_add_v6_addr(struct nx_info *nxi,
22347 +       struct in6_addr *ip, struct in6_addr *mask,
22348 +       uint32_t prefix, uint16_t type, uint16_t flags)
22349 +{
22350 +       struct nx_addr_v6 *nxa = &nxi->v6;
22351 +
22352 +       if (NX_IPV6(nxi)) {
22353 +               /* locate last entry */
22354 +               for (; nxa->next; nxa = nxa->next);
22355 +               nxa->next = __alloc_nx_addr_v6();
22356 +               nxa = nxa->next;
22357 +
22358 +               if (IS_ERR(nxa))
22359 +                       return PTR_ERR(nxa);
22360 +       }
22361 +
22362 +       nxa->ip = *ip;
22363 +       nxa->mask = *mask;
22364 +       nxa->prefix = prefix;
22365 +       nxa->type = type;
22366 +       nxa->flags = flags;
22367 +       return 0;
22368 +}
22369 +
22370 +
22371 +int vc_net_add_ipv6(struct nx_info *nxi, void __user *data)
22372 +{
22373 +       struct vcmd_net_addr_ipv6_v1 vc_data;
22374 +
22375 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
22376 +               return -EFAULT;
22377 +
22378 +       switch (vc_data.type) {
22379 +       case NXA_TYPE_ADDR:
22380 +       case NXA_TYPE_MASK:
22381 +               return do_add_v6_addr(nxi, &vc_data.ip, &vc_data.mask,
22382 +                       vc_data.prefix, vc_data.type, vc_data.flags);
22383 +       default:
22384 +               return -EINVAL;
22385 +       }
22386 +       return 0;
22387 +}
22388 +
22389 +int vc_net_remove_ipv6(struct nx_info *nxi, void __user *data)
22390 +{
22391 +       struct vcmd_net_addr_ipv6_v1 vc_data;
22392 +
22393 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
22394 +               return -EFAULT;
22395 +
22396 +       switch (vc_data.type) {
22397 +       case NXA_TYPE_ANY:
22398 +               __dealloc_nx_addr_v6_all(xchg(&nxi->v6.next, NULL));
22399 +               memset(&nxi->v6, 0, sizeof(nxi->v6));
22400 +               break;
22401 +
22402 +       default:
22403 +               return -EINVAL;
22404 +       }
22405 +       return 0;
22406 +}
22407 +
22408 +#endif /* CONFIG_IPV6 */
22409 +
22410 +
22411 +int vc_get_nflags(struct nx_info *nxi, void __user *data)
22412 +{
22413 +       struct vcmd_net_flags_v0 vc_data;
22414 +
22415 +       vc_data.flagword = nxi->nx_flags;
22416 +
22417 +       /* special STATE flag handling */
22418 +       vc_data.mask = vs_mask_flags(~0ULL, nxi->nx_flags, NXF_ONE_TIME);
22419 +
22420 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
22421 +               return -EFAULT;
22422 +       return 0;
22423 +}
22424 +
22425 +int vc_set_nflags(struct nx_info *nxi, void __user *data)
22426 +{
22427 +       struct vcmd_net_flags_v0 vc_data;
22428 +       uint64_t mask, trigger;
22429 +
22430 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
22431 +               return -EFAULT;
22432 +
22433 +       /* special STATE flag handling */
22434 +       mask = vs_mask_mask(vc_data.mask, nxi->nx_flags, NXF_ONE_TIME);
22435 +       trigger = (mask & nxi->nx_flags) ^ (mask & vc_data.flagword);
22436 +
22437 +       nxi->nx_flags = vs_mask_flags(nxi->nx_flags,
22438 +               vc_data.flagword, mask);
22439 +       if (trigger & NXF_PERSISTENT)
22440 +               nx_update_persistent(nxi);
22441 +
22442 +       return 0;
22443 +}
22444 +
22445 +int vc_get_ncaps(struct nx_info *nxi, void __user *data)
22446 +{
22447 +       struct vcmd_net_caps_v0 vc_data;
22448 +
22449 +       vc_data.ncaps = nxi->nx_ncaps;
22450 +       vc_data.cmask = ~0ULL;
22451 +
22452 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
22453 +               return -EFAULT;
22454 +       return 0;
22455 +}
22456 +
22457 +int vc_set_ncaps(struct nx_info *nxi, void __user *data)
22458 +{
22459 +       struct vcmd_net_caps_v0 vc_data;
22460 +
22461 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
22462 +               return -EFAULT;
22463 +
22464 +       nxi->nx_ncaps = vs_mask_flags(nxi->nx_ncaps,
22465 +               vc_data.ncaps, vc_data.cmask);
22466 +       return 0;
22467 +}
22468 +
22469 +
22470 +#include <linux/module.h>
22471 +
22472 +module_init(init_network);
22473 +
22474 +EXPORT_SYMBOL_GPL(free_nx_info);
22475 +EXPORT_SYMBOL_GPL(unhash_nx_info);
22476 +
22477 diff -NurpP --minimal linux-2.6.29/kernel/vserver/proc.c linux-2.6.29-vs2.3.0.36.9-pre2/kernel/vserver/proc.c
22478 --- linux-2.6.29/kernel/vserver/proc.c  1970-01-01 01:00:00.000000000 +0100
22479 +++ linux-2.6.29-vs2.3.0.36.9-pre2/kernel/vserver/proc.c        2009-02-22 22:54:26.000000000 +0100
22480 @@ -0,0 +1,1092 @@
22481 +/*
22482 + *  linux/kernel/vserver/proc.c
22483 + *
22484 + *  Virtual Context Support
22485 + *
22486 + *  Copyright (C) 2003-2007  Herbert Pötzl
22487 + *
22488 + *  V0.01  basic structure
22489 + *  V0.02  adaptation vs1.3.0
22490 + *  V0.03  proc permissions
22491 + *  V0.04  locking/generic
22492 + *  V0.05  next generation procfs
22493 + *  V0.06  inode validation
22494 + *  V0.07  generic rewrite vid
22495 + *  V0.08  remove inode type
22496 + *
22497 + */
22498 +
22499 +#include <linux/proc_fs.h>
22500 +#include <asm/unistd.h>
22501 +
22502 +#include <linux/vs_context.h>
22503 +#include <linux/vs_network.h>
22504 +#include <linux/vs_cvirt.h>
22505 +
22506 +#include <linux/in.h>
22507 +#include <linux/inetdevice.h>
22508 +#include <linux/vs_inet.h>
22509 +#include <linux/vs_inet6.h>
22510 +
22511 +#include <linux/vserver/global.h>
22512 +
22513 +#include "cvirt_proc.h"
22514 +#include "cacct_proc.h"
22515 +#include "limit_proc.h"
22516 +#include "sched_proc.h"
22517 +#include "vci_config.h"
22518 +
22519 +
22520 +static inline char *print_cap_t(char *buffer, kernel_cap_t *c)
22521 +{
22522 +       unsigned __capi;
22523 +
22524 +       CAP_FOR_EACH_U32(__capi) {
22525 +               buffer += sprintf(buffer, "%08x",
22526 +                       c->cap[(_KERNEL_CAPABILITY_U32S-1) - __capi]);
22527 +       }
22528 +       return buffer;
22529 +}
22530 +
22531 +
22532 +static struct proc_dir_entry *proc_virtual;
22533 +
22534 +static struct proc_dir_entry *proc_virtnet;
22535 +
22536 +
22537 +/* first the actual feeds */
22538 +
22539 +
22540 +static int proc_vci(char *buffer)
22541 +{
22542 +       return sprintf(buffer,
22543 +               "VCIVersion:\t%04x:%04x\n"
22544 +               "VCISyscall:\t%d\n"
22545 +               "VCIKernel:\t%08x\n",
22546 +               VCI_VERSION >> 16,
22547 +               VCI_VERSION & 0xFFFF,
22548 +               __NR_vserver,
22549 +               vci_kernel_config());
22550 +}
22551 +
22552 +static int proc_virtual_info(char *buffer)
22553 +{
22554 +       return proc_vci(buffer);
22555 +}
22556 +
22557 +static int proc_virtual_status(char *buffer)
22558 +{
22559 +       return sprintf(buffer,
22560 +               "#CTotal:\t%d\n"
22561 +               "#CActive:\t%d\n"
22562 +               "#NSProxy:\t%d\t%d %d %d %d %d %d\n",
22563 +               atomic_read(&vx_global_ctotal),
22564 +               atomic_read(&vx_global_cactive),
22565 +               atomic_read(&vs_global_nsproxy),
22566 +               atomic_read(&vs_global_fs),
22567 +               atomic_read(&vs_global_mnt_ns),
22568 +               atomic_read(&vs_global_uts_ns),
22569 +               atomic_read(&vs_global_ipc_ns),
22570 +               atomic_read(&vs_global_user_ns),
22571 +               atomic_read(&vs_global_pid_ns));
22572 +}
22573 +
22574 +
22575 +int proc_vxi_info(struct vx_info *vxi, char *buffer)
22576 +{
22577 +       int length;
22578 +
22579 +       length = sprintf(buffer,
22580 +               "ID:\t%d\n"
22581 +               "Info:\t%p\n"
22582 +               "Init:\t%d\n"
22583 +               "OOM:\t%lld\n",
22584 +               vxi->vx_id,
22585 +               vxi,
22586 +               vxi->vx_initpid,
22587 +               vxi->vx_badness_bias);
22588 +       return length;
22589 +}
22590 +
22591 +int proc_vxi_status(struct vx_info *vxi, char *buffer)
22592 +{
22593 +       char *orig = buffer;
22594 +
22595 +       buffer += sprintf(buffer,
22596 +               "UseCnt:\t%d\n"
22597 +               "Tasks:\t%d\n"
22598 +               "Flags:\t%016llx\n",
22599 +               atomic_read(&vxi->vx_usecnt),
22600 +               atomic_read(&vxi->vx_tasks),
22601 +               (unsigned long long)vxi->vx_flags);
22602 +
22603 +       buffer += sprintf(buffer, "BCaps:\t");
22604 +       buffer = print_cap_t(buffer, &vxi->vx_bcaps);
22605 +       buffer += sprintf(buffer, "\n");
22606 +
22607 +       buffer += sprintf(buffer,
22608 +               "CCaps:\t%016llx\n"
22609 +               "Spaces:\t%08lx %08lx\n",
22610 +               (unsigned long long)vxi->vx_ccaps,
22611 +               vxi->vx_nsmask[0], vxi->vx_nsmask[1]);
22612 +       return buffer - orig;
22613 +}
22614 +
22615 +int proc_vxi_limit(struct vx_info *vxi, char *buffer)
22616 +{
22617 +       return vx_info_proc_limit(&vxi->limit, buffer);
22618 +}
22619 +
22620 +int proc_vxi_sched(struct vx_info *vxi, char *buffer)
22621 +{
22622 +       int cpu, length;
22623 +
22624 +       length = vx_info_proc_sched(&vxi->sched, buffer);
22625 +       for_each_online_cpu(cpu) {
22626 +               length += vx_info_proc_sched_pc(
22627 +                       &vx_per_cpu(vxi, sched_pc, cpu),
22628 +                       buffer + length, cpu);
22629 +       }
22630 +       return length;
22631 +}
22632 +
22633 +int proc_vxi_nsproxy0(struct vx_info *vxi, char *buffer)
22634 +{
22635 +       return vx_info_proc_nsproxy(vxi->vx_nsproxy[0], buffer);
22636 +}
22637 +
22638 +int proc_vxi_nsproxy1(struct vx_info *vxi, char *buffer)
22639 +{
22640 +       return vx_info_proc_nsproxy(vxi->vx_nsproxy[1], buffer);
22641 +}
22642 +
22643 +int proc_vxi_cvirt(struct vx_info *vxi, char *buffer)
22644 +{
22645 +       int cpu, length;
22646 +
22647 +       vx_update_load(vxi);
22648 +       length = vx_info_proc_cvirt(&vxi->cvirt, buffer);
22649 +       for_each_online_cpu(cpu) {
22650 +               length += vx_info_proc_cvirt_pc(
22651 +                       &vx_per_cpu(vxi, cvirt_pc, cpu),
22652 +                       buffer + length, cpu);
22653 +       }
22654 +       return length;
22655 +}
22656 +
22657 +int proc_vxi_cacct(struct vx_info *vxi, char *buffer)
22658 +{
22659 +       return vx_info_proc_cacct(&vxi->cacct, buffer);
22660 +}
22661 +
22662 +
22663 +static int proc_virtnet_info(char *buffer)
22664 +{
22665 +       return proc_vci(buffer);
22666 +}
22667 +
22668 +static int proc_virtnet_status(char *buffer)
22669 +{
22670 +       return sprintf(buffer,
22671 +               "#CTotal:\t%d\n"
22672 +               "#CActive:\t%d\n",
22673 +               atomic_read(&nx_global_ctotal),
22674 +               atomic_read(&nx_global_cactive));
22675 +}
22676 +
22677 +int proc_nxi_info(struct nx_info *nxi, char *buffer)
22678 +{
22679 +       struct nx_addr_v4 *v4a;
22680 +#ifdef CONFIG_IPV6
22681 +       struct nx_addr_v6 *v6a;
22682 +#endif
22683 +       int length, i;
22684 +
22685 +       length = sprintf(buffer,
22686 +               "ID:\t%d\n"
22687 +               "Info:\t%p\n"
22688 +               "Bcast:\t" NIPQUAD_FMT "\n"
22689 +               "Lback:\t" NIPQUAD_FMT "\n",
22690 +               nxi->nx_id,
22691 +               nxi,
22692 +               NIPQUAD(nxi->v4_bcast.s_addr),
22693 +               NIPQUAD(nxi->v4_lback.s_addr));
22694 +
22695 +       if (!NX_IPV4(nxi))
22696 +               goto skip_v4;
22697 +       for (i = 0, v4a = &nxi->v4; v4a; i++, v4a = v4a->next)
22698 +               length += sprintf(buffer + length, "%d:\t" NXAV4_FMT "\n",
22699 +                       i, NXAV4(v4a));
22700 +skip_v4:
22701 +#ifdef CONFIG_IPV6
22702 +       if (!NX_IPV6(nxi))
22703 +               goto skip_v6;
22704 +       for (i = 0, v6a = &nxi->v6; v6a; i++, v6a = v6a->next)
22705 +               length += sprintf(buffer + length, "%d:\t" NXAV6_FMT "\n",
22706 +                       i, NXAV6(v6a));
22707 +skip_v6:
22708 +#endif
22709 +       return length;
22710 +}
22711 +
22712 +int proc_nxi_status(struct nx_info *nxi, char *buffer)
22713 +{
22714 +       int length;
22715 +
22716 +       length = sprintf(buffer,
22717 +               "UseCnt:\t%d\n"
22718 +               "Tasks:\t%d\n"
22719 +               "Flags:\t%016llx\n"
22720 +               "NCaps:\t%016llx\n",
22721 +               atomic_read(&nxi->nx_usecnt),
22722 +               atomic_read(&nxi->nx_tasks),
22723 +               (unsigned long long)nxi->nx_flags,
22724 +               (unsigned long long)nxi->nx_ncaps);
22725 +       return length;
22726 +}
22727 +
22728 +
22729 +
22730 +/* here the inode helpers */
22731 +
22732 +struct vs_entry {
22733 +       int len;
22734 +       char *name;
22735 +       mode_t mode;
22736 +       struct inode_operations *iop;
22737 +       struct file_operations *fop;
22738 +       union proc_op op;
22739 +};
22740 +
22741 +static struct inode *vs_proc_make_inode(struct super_block *sb, struct vs_entry *p)
22742 +{
22743 +       struct inode *inode = new_inode(sb);
22744 +
22745 +       if (!inode)
22746 +               goto out;
22747 +
22748 +       inode->i_mode = p->mode;
22749 +       if (p->iop)
22750 +               inode->i_op = p->iop;
22751 +       if (p->fop)
22752 +               inode->i_fop = p->fop;
22753 +
22754 +       inode->i_nlink = (p->mode & S_IFDIR) ? 2 : 1;
22755 +       inode->i_flags |= S_IMMUTABLE;
22756 +
22757 +       inode->i_mtime = inode->i_atime = inode->i_ctime = CURRENT_TIME;
22758 +
22759 +       inode->i_uid = 0;
22760 +       inode->i_gid = 0;
22761 +       inode->i_tag = 0;
22762 +out:
22763 +       return inode;
22764 +}
22765 +
22766 +static struct dentry *vs_proc_instantiate(struct inode *dir,
22767 +       struct dentry *dentry, int id, void *ptr)
22768 +{
22769 +       struct vs_entry *p = ptr;
22770 +       struct inode *inode = vs_proc_make_inode(dir->i_sb, p);
22771 +       struct dentry *error = ERR_PTR(-EINVAL);
22772 +
22773 +       if (!inode)
22774 +               goto out;
22775 +
22776 +       PROC_I(inode)->op = p->op;
22777 +       PROC_I(inode)->fd = id;
22778 +       d_add(dentry, inode);
22779 +       error = NULL;
22780 +out:
22781 +       return error;
22782 +}
22783 +
22784 +/* Lookups */
22785 +
22786 +typedef struct dentry *instantiate_t(struct inode *, struct dentry *, int, void *);
22787 +
22788 +/*
22789 + * Fill a directory entry.
22790 + *
22791 + * If possible create the dcache entry and derive our inode number and
22792 + * file type from dcache entry.
22793 + *
22794 + * Since all of the proc inode numbers are dynamically generated, the inode
22795 + * numbers do not exist until the inode is cache.  This means creating the
22796 + * the dcache entry in readdir is necessary to keep the inode numbers
22797 + * reported by readdir in sync with the inode numbers reported
22798 + * by stat.
22799 + */
22800 +static int proc_fill_cache(struct file *filp, void *dirent, filldir_t filldir,
22801 +       char *name, int len, instantiate_t instantiate, int id, void *ptr)
22802 +{
22803 +       struct dentry *child, *dir = filp->f_dentry;
22804 +       struct inode *inode;
22805 +       struct qstr qname;
22806 +       ino_t ino = 0;
22807 +       unsigned type = DT_UNKNOWN;
22808 +
22809 +       qname.name = name;
22810 +       qname.len  = len;
22811 +       qname.hash = full_name_hash(name, len);
22812 +
22813 +       child = d_lookup(dir, &qname);
22814 +       if (!child) {
22815 +               struct dentry *new;
22816 +               new = d_alloc(dir, &qname);
22817 +               if (new) {
22818 +                       child = instantiate(dir->d_inode, new, id, ptr);
22819 +                       if (child)
22820 +                               dput(new);
22821 +                       else
22822 +                               child = new;
22823 +               }
22824 +       }
22825 +       if (!child || IS_ERR(child) || !child->d_inode)
22826 +               goto end_instantiate;
22827 +       inode = child->d_inode;
22828 +       if (inode) {
22829 +               ino = inode->i_ino;
22830 +               type = inode->i_mode >> 12;
22831 +       }
22832 +       dput(child);
22833 +end_instantiate:
22834 +       if (!ino)
22835 +               ino = find_inode_number(dir, &qname);
22836 +       if (!ino)
22837 +               ino = 1;
22838 +       return filldir(dirent, name, len, filp->f_pos, ino, type);
22839 +}
22840 +
22841 +
22842 +
22843 +/* get and revalidate vx_info/xid */
22844 +
22845 +static inline
22846 +struct vx_info *get_proc_vx_info(struct inode *inode)
22847 +{
22848 +       return lookup_vx_info(PROC_I(inode)->fd);
22849 +}
22850 +
22851 +static int proc_xid_revalidate(struct dentry *dentry, struct nameidata *nd)
22852 +{
22853 +       struct inode *inode = dentry->d_inode;
22854 +       xid_t xid = PROC_I(inode)->fd;
22855 +
22856 +       if (!xid || xid_is_hashed(xid))
22857 +               return 1;
22858 +       d_drop(dentry);
22859 +       return 0;
22860 +}
22861 +
22862 +
22863 +/* get and revalidate nx_info/nid */
22864 +
22865 +static int proc_nid_revalidate(struct dentry *dentry, struct nameidata *nd)
22866 +{
22867 +       struct inode *inode = dentry->d_inode;
22868 +       nid_t nid = PROC_I(inode)->fd;
22869 +
22870 +       if (!nid || nid_is_hashed(nid))
22871 +               return 1;
22872 +       d_drop(dentry);
22873 +       return 0;
22874 +}
22875 +
22876 +
22877 +
22878 +#define PROC_BLOCK_SIZE (PAGE_SIZE - 1024)
22879 +
22880 +static ssize_t proc_vs_info_read(struct file *file, char __user *buf,
22881 +                         size_t count, loff_t *ppos)
22882 +{
22883 +       struct inode *inode = file->f_dentry->d_inode;
22884 +       unsigned long page;
22885 +       ssize_t length = 0;
22886 +
22887 +       if (count > PROC_BLOCK_SIZE)
22888 +               count = PROC_BLOCK_SIZE;
22889 +
22890 +       /* fade that out as soon as stable */
22891 +       WARN_ON(PROC_I(inode)->fd);
22892 +
22893 +       if (!(page = __get_free_page(GFP_KERNEL)))
22894 +               return -ENOMEM;
22895 +
22896 +       BUG_ON(!PROC_I(inode)->op.proc_vs_read);
22897 +       length = PROC_I(inode)->op.proc_vs_read((char *)page);
22898 +
22899 +       if (length >= 0)
22900 +               length = simple_read_from_buffer(buf, count, ppos,
22901 +                       (char *)page, length);
22902 +
22903 +       free_page(page);
22904 +       return length;
22905 +}
22906 +
22907 +static ssize_t proc_vx_info_read(struct file *file, char __user *buf,
22908 +                         size_t count, loff_t *ppos)
22909 +{
22910 +       struct inode *inode = file->f_dentry->d_inode;
22911 +       struct vx_info *vxi = NULL;
22912 +       xid_t xid = PROC_I(inode)->fd;
22913 +       unsigned long page;
22914 +       ssize_t length = 0;
22915 +
22916 +       if (count > PROC_BLOCK_SIZE)
22917 +               count = PROC_BLOCK_SIZE;
22918 +
22919 +       /* fade that out as soon as stable */
22920 +       WARN_ON(!xid);
22921 +       vxi = lookup_vx_info(xid);
22922 +       if (!vxi)
22923 +               goto out;
22924 +
22925 +       length = -ENOMEM;
22926 +       if (!(page = __get_free_page(GFP_KERNEL)))
22927 +               goto out_put;
22928 +
22929 +       BUG_ON(!PROC_I(inode)->op.proc_vxi_read);
22930 +       length = PROC_I(inode)->op.proc_vxi_read(vxi, (char *)page);
22931 +
22932 +       if (length >= 0)
22933 +               length = simple_read_from_buffer(buf, count, ppos,
22934 +                       (char *)page, length);
22935 +
22936 +       free_page(page);
22937 +out_put:
22938 +       put_vx_info(vxi);
22939 +out:
22940 +       return length;
22941 +}
22942 +
22943 +static ssize_t proc_nx_info_read(struct file *file, char __user *buf,
22944 +                         size_t count, loff_t *ppos)
22945 +{
22946 +       struct inode *inode = file->f_dentry->d_inode;
22947 +       struct nx_info *nxi = NULL;
22948 +       nid_t nid = PROC_I(inode)->fd;
22949 +       unsigned long page;
22950 +       ssize_t length = 0;
22951 +
22952 +       if (count > PROC_BLOCK_SIZE)
22953 +               count = PROC_BLOCK_SIZE;
22954 +
22955 +       /* fade that out as soon as stable */
22956 +       WARN_ON(!nid);
22957 +       nxi = lookup_nx_info(nid);
22958 +       if (!nxi)
22959 +               goto out;
22960 +
22961 +       length = -ENOMEM;
22962 +       if (!(page = __get_free_page(GFP_KERNEL)))
22963 +               goto out_put;
22964 +
22965 +       BUG_ON(!PROC_I(inode)->op.proc_nxi_read);
22966 +       length = PROC_I(inode)->op.proc_nxi_read(nxi, (char *)page);
22967 +
22968 +       if (length >= 0)
22969 +               length = simple_read_from_buffer(buf, count, ppos,
22970 +                       (char *)page, length);
22971 +
22972 +       free_page(page);
22973 +out_put:
22974 +       put_nx_info(nxi);
22975 +out:
22976 +       return length;
22977 +}
22978 +
22979 +
22980 +
22981 +/* here comes the lower level */
22982 +
22983 +
22984 +#define NOD(NAME, MODE, IOP, FOP, OP) {        \
22985 +       .len  = sizeof(NAME) - 1,       \
22986 +       .name = (NAME),                 \
22987 +       .mode = MODE,                   \
22988 +       .iop  = IOP,                    \
22989 +       .fop  = FOP,                    \
22990 +       .op   = OP,                     \
22991 +}
22992 +
22993 +
22994 +#define DIR(NAME, MODE, OTYPE)                         \
22995 +       NOD(NAME, (S_IFDIR | (MODE)),                   \
22996 +               &proc_ ## OTYPE ## _inode_operations,   \
22997 +               &proc_ ## OTYPE ## _file_operations, { } )
22998 +
22999 +#define INF(NAME, MODE, OTYPE)                         \
23000 +       NOD(NAME, (S_IFREG | (MODE)), NULL,             \
23001 +               &proc_vs_info_file_operations,          \
23002 +               { .proc_vs_read = &proc_##OTYPE } )
23003 +
23004 +#define VINF(NAME, MODE, OTYPE)                                \
23005 +       NOD(NAME, (S_IFREG | (MODE)), NULL,             \
23006 +               &proc_vx_info_file_operations,          \
23007 +               { .proc_vxi_read = &proc_##OTYPE } )
23008 +
23009 +#define NINF(NAME, MODE, OTYPE)                                \
23010 +       NOD(NAME, (S_IFREG | (MODE)), NULL,             \
23011 +               &proc_nx_info_file_operations,          \
23012 +               { .proc_nxi_read = &proc_##OTYPE } )
23013 +
23014 +
23015 +static struct file_operations proc_vs_info_file_operations = {
23016 +       .read =         proc_vs_info_read,
23017 +};
23018 +
23019 +static struct file_operations proc_vx_info_file_operations = {
23020 +       .read =         proc_vx_info_read,
23021 +};
23022 +
23023 +static struct dentry_operations proc_xid_dentry_operations = {
23024 +       .d_revalidate = proc_xid_revalidate,
23025 +};
23026 +
23027 +static struct vs_entry vx_base_stuff[] = {
23028 +       VINF("info",    S_IRUGO, vxi_info),
23029 +       VINF("status",  S_IRUGO, vxi_status),
23030 +       VINF("limit",   S_IRUGO, vxi_limit),
23031 +       VINF("sched",   S_IRUGO, vxi_sched),
23032 +       VINF("nsproxy", S_IRUGO, vxi_nsproxy0),
23033 +       VINF("nsproxy1",S_IRUGO, vxi_nsproxy1),
23034 +       VINF("cvirt",   S_IRUGO, vxi_cvirt),
23035 +       VINF("cacct",   S_IRUGO, vxi_cacct),
23036 +       {}
23037 +};
23038 +
23039 +
23040 +
23041 +
23042 +static struct dentry *proc_xid_instantiate(struct inode *dir,
23043 +       struct dentry *dentry, int id, void *ptr)
23044 +{
23045 +       dentry->d_op = &proc_xid_dentry_operations;
23046 +       return vs_proc_instantiate(dir, dentry, id, ptr);
23047 +}
23048 +
23049 +static struct dentry *proc_xid_lookup(struct inode *dir,
23050 +       struct dentry *dentry, struct nameidata *nd)
23051 +{
23052 +       struct vs_entry *p = vx_base_stuff;
23053 +       struct dentry *error = ERR_PTR(-ENOENT);
23054 +
23055 +       for (; p->name; p++) {
23056 +               if (p->len != dentry->d_name.len)
23057 +                       continue;
23058 +               if (!memcmp(dentry->d_name.name, p->name, p->len))
23059 +                       break;
23060 +       }
23061 +       if (!p->name)
23062 +               goto out;
23063 +
23064 +       error = proc_xid_instantiate(dir, dentry, PROC_I(dir)->fd, p);
23065 +out:
23066 +       return error;
23067 +}
23068 +
23069 +static int proc_xid_readdir(struct file *filp,
23070 +       void *dirent, filldir_t filldir)
23071 +{
23072 +       struct dentry *dentry = filp->f_dentry;
23073 +       struct inode *inode = dentry->d_inode;
23074 +       struct vs_entry *p = vx_base_stuff;
23075 +       int size = sizeof(vx_base_stuff) / sizeof(struct vs_entry);
23076 +       int pos, index;
23077 +       u64 ino;
23078 +
23079 +       pos = filp->f_pos;
23080 +       switch (pos) {
23081 +       case 0:
23082 +               ino = inode->i_ino;
23083 +               if (filldir(dirent, ".", 1, pos, ino, DT_DIR) < 0)
23084 +                       goto out;
23085 +               pos++;
23086 +               /* fall through */
23087 +       case 1:
23088 +               ino = parent_ino(dentry);
23089 +               if (filldir(dirent, "..", 2, pos, ino, DT_DIR) < 0)
23090 +                       goto out;
23091 +               pos++;
23092 +               /* fall through */
23093 +       default:
23094 +               index = pos - 2;
23095 +               if (index >= size)
23096 +                       goto out;
23097 +               for (p += index; p->name; p++) {
23098 +                       if (proc_fill_cache(filp, dirent, filldir, p->name, p->len,
23099 +                               vs_proc_instantiate, PROC_I(inode)->fd, p))
23100 +                               goto out;
23101 +                       pos++;
23102 +               }
23103 +       }
23104 +out:
23105 +       filp->f_pos = pos;
23106 +       return 1;
23107 +}
23108 +
23109 +
23110 +
23111 +static struct file_operations proc_nx_info_file_operations = {
23112 +       .read =         proc_nx_info_read,
23113 +};
23114 +
23115 +static struct dentry_operations proc_nid_dentry_operations = {
23116 +       .d_revalidate = proc_nid_revalidate,
23117 +};
23118 +
23119 +static struct vs_entry nx_base_stuff[] = {
23120 +       NINF("info",    S_IRUGO, nxi_info),
23121 +       NINF("status",  S_IRUGO, nxi_status),
23122 +       {}
23123 +};
23124 +
23125 +
23126 +static struct dentry *proc_nid_instantiate(struct inode *dir,
23127 +       struct dentry *dentry, int id, void *ptr)
23128 +{
23129 +       dentry->d_op = &proc_nid_dentry_operations;
23130 +       return vs_proc_instantiate(dir, dentry, id, ptr);
23131 +}
23132 +
23133 +static struct dentry *proc_nid_lookup(struct inode *dir,
23134 +       struct dentry *dentry, struct nameidata *nd)
23135 +{
23136 +       struct vs_entry *p = nx_base_stuff;
23137 +       struct dentry *error = ERR_PTR(-ENOENT);
23138 +
23139 +       for (; p->name; p++) {
23140 +               if (p->len != dentry->d_name.len)
23141 +                       continue;
23142 +               if (!memcmp(dentry->d_name.name, p->name, p->len))
23143 +                       break;
23144 +       }
23145 +       if (!p->name)
23146 +               goto out;
23147 +
23148 +       error = proc_nid_instantiate(dir, dentry, PROC_I(dir)->fd, p);
23149 +out:
23150 +       return error;
23151 +}
23152 +
23153 +static int proc_nid_readdir(struct file *filp,
23154 +       void *dirent, filldir_t filldir)
23155 +{
23156 +       struct dentry *dentry = filp->f_dentry;
23157 +       struct inode *inode = dentry->d_inode;
23158 +       struct vs_entry *p = nx_base_stuff;
23159 +       int size = sizeof(nx_base_stuff) / sizeof(struct vs_entry);
23160 +       int pos, index;
23161 +       u64 ino;
23162 +
23163 +       pos = filp->f_pos;
23164 +       switch (pos) {
23165 +       case 0:
23166 +               ino = inode->i_ino;
23167 +               if (filldir(dirent, ".", 1, pos, ino, DT_DIR) < 0)
23168 +                       goto out;
23169 +               pos++;
23170 +               /* fall through */
23171 +       case 1:
23172 +               ino = parent_ino(dentry);
23173 +               if (filldir(dirent, "..", 2, pos, ino, DT_DIR) < 0)
23174 +                       goto out;
23175 +               pos++;
23176 +               /* fall through */
23177 +       default:
23178 +               index = pos - 2;
23179 +               if (index >= size)
23180 +                       goto out;
23181 +               for (p += index; p->name; p++) {
23182 +                       if (proc_fill_cache(filp, dirent, filldir, p->name, p->len,
23183 +                               vs_proc_instantiate, PROC_I(inode)->fd, p))
23184 +                               goto out;
23185 +                       pos++;
23186 +               }
23187 +       }
23188 +out:
23189 +       filp->f_pos = pos;
23190 +       return 1;
23191 +}
23192 +
23193 +
23194 +#define MAX_MULBY10    ((~0U - 9) / 10)
23195 +
23196 +static inline int atovid(const char *str, int len)
23197 +{
23198 +       int vid, c;
23199 +
23200 +       vid = 0;
23201 +       while (len-- > 0) {
23202 +               c = *str - '0';
23203 +               str++;
23204 +               if (c > 9)
23205 +                       return -1;
23206 +               if (vid >= MAX_MULBY10)
23207 +                       return -1;
23208 +               vid *= 10;
23209 +               vid += c;
23210 +               if (!vid)
23211 +                       return -1;
23212 +       }
23213 +       return vid;
23214 +}
23215 +
23216 +/* now the upper level (virtual) */
23217 +
23218 +
23219 +static struct file_operations proc_xid_file_operations = {
23220 +       .read =         generic_read_dir,
23221 +       .readdir =      proc_xid_readdir,
23222 +};
23223 +
23224 +static struct inode_operations proc_xid_inode_operations = {
23225 +       .lookup =       proc_xid_lookup,
23226 +};
23227 +
23228 +static struct vs_entry vx_virtual_stuff[] = {
23229 +       INF("info",     S_IRUGO, virtual_info),
23230 +       INF("status",   S_IRUGO, virtual_status),
23231 +       DIR(NULL,       S_IRUGO | S_IXUGO, xid),
23232 +};
23233 +
23234 +
23235 +static struct dentry *proc_virtual_lookup(struct inode *dir,
23236 +       struct dentry *dentry, struct nameidata *nd)
23237 +{
23238 +       struct vs_entry *p = vx_virtual_stuff;
23239 +       struct dentry *error = ERR_PTR(-ENOENT);
23240 +       int id = 0;
23241 +
23242 +       for (; p->name; p++) {
23243 +               if (p->len != dentry->d_name.len)
23244 +                       continue;
23245 +               if (!memcmp(dentry->d_name.name, p->name, p->len))
23246 +                       break;
23247 +       }
23248 +       if (p->name)
23249 +               goto instantiate;
23250 +
23251 +       id = atovid(dentry->d_name.name, dentry->d_name.len);
23252 +       if ((id < 0) || !xid_is_hashed(id))
23253 +               goto out;
23254 +
23255 +instantiate:
23256 +       error = proc_xid_instantiate(dir, dentry, id, p);
23257 +out:
23258 +       return error;
23259 +}
23260 +
23261 +static struct file_operations proc_nid_file_operations = {
23262 +       .read =         generic_read_dir,
23263 +       .readdir =      proc_nid_readdir,
23264 +};
23265 +
23266 +static struct inode_operations proc_nid_inode_operations = {
23267 +       .lookup =       proc_nid_lookup,
23268 +};
23269 +
23270 +static struct vs_entry nx_virtnet_stuff[] = {
23271 +       INF("info",     S_IRUGO, virtnet_info),
23272 +       INF("status",   S_IRUGO, virtnet_status),
23273 +       DIR(NULL,       S_IRUGO | S_IXUGO, nid),
23274 +};
23275 +
23276 +
23277 +static struct dentry *proc_virtnet_lookup(struct inode *dir,
23278 +       struct dentry *dentry, struct nameidata *nd)
23279 +{
23280 +       struct vs_entry *p = nx_virtnet_stuff;
23281 +       struct dentry *error = ERR_PTR(-ENOENT);
23282 +       int id = 0;
23283 +
23284 +       for (; p->name; p++) {
23285 +               if (p->len != dentry->d_name.len)
23286 +                       continue;
23287 +               if (!memcmp(dentry->d_name.name, p->name, p->len))
23288 +                       break;
23289 +       }
23290 +       if (p->name)
23291 +               goto instantiate;
23292 +
23293 +       id = atovid(dentry->d_name.name, dentry->d_name.len);
23294 +       if ((id < 0) || !nid_is_hashed(id))
23295 +               goto out;
23296 +
23297 +instantiate:
23298 +       error = proc_nid_instantiate(dir, dentry, id, p);
23299 +out:
23300 +       return error;
23301 +}
23302 +
23303 +
23304 +#define PROC_MAXVIDS 32
23305 +
23306 +int proc_virtual_readdir(struct file *filp,
23307 +       void *dirent, filldir_t filldir)
23308 +{
23309 +       struct dentry *dentry = filp->f_dentry;
23310 +       struct inode *inode = dentry->d_inode;
23311 +       struct vs_entry *p = vx_virtual_stuff;
23312 +       int size = sizeof(vx_virtual_stuff) / sizeof(struct vs_entry);
23313 +       int pos, index;
23314 +       unsigned int xid_array[PROC_MAXVIDS];
23315 +       char buf[PROC_NUMBUF];
23316 +       unsigned int nr_xids, i;
23317 +       u64 ino;
23318 +
23319 +       pos = filp->f_pos;
23320 +       switch (pos) {
23321 +       case 0:
23322 +               ino = inode->i_ino;
23323 +               if (filldir(dirent, ".", 1, pos, ino, DT_DIR) < 0)
23324 +                       goto out;
23325 +               pos++;
23326 +               /* fall through */
23327 +       case 1:
23328 +               ino = parent_ino(dentry);
23329 +               if (filldir(dirent, "..", 2, pos, ino, DT_DIR) < 0)
23330 +                       goto out;
23331 +               pos++;
23332 +               /* fall through */
23333 +       default:
23334 +               index = pos - 2;
23335 +               if (index >= size)
23336 +                       goto entries;
23337 +               for (p += index; p->name; p++) {
23338 +                       if (proc_fill_cache(filp, dirent, filldir, p->name, p->len,
23339 +                               vs_proc_instantiate, 0, p))
23340 +                               goto out;
23341 +                       pos++;
23342 +               }
23343 +       entries:
23344 +               index = pos - size;
23345 +               p = &vx_virtual_stuff[size - 1];
23346 +               nr_xids = get_xid_list(index, xid_array, PROC_MAXVIDS);
23347 +               for (i = 0; i < nr_xids; i++) {
23348 +                       int n, xid = xid_array[i];
23349 +                       unsigned int j = PROC_NUMBUF;
23350 +
23351 +                       n = xid;
23352 +                       do
23353 +                               buf[--j] = '0' + (n % 10);
23354 +                       while (n /= 10);
23355 +
23356 +                       if (proc_fill_cache(filp, dirent, filldir,
23357 +                               buf + j, PROC_NUMBUF - j,
23358 +                               vs_proc_instantiate, xid, p))
23359 +                               goto out;
23360 +                       pos++;
23361 +               }
23362 +       }
23363 +out:
23364 +       filp->f_pos = pos;
23365 +       return 0;
23366 +}
23367 +
23368 +static int proc_virtual_getattr(struct vfsmount *mnt,
23369 +       struct dentry *dentry, struct kstat *stat)
23370 +{
23371 +       struct inode *inode = dentry->d_inode;
23372 +
23373 +       generic_fillattr(inode, stat);
23374 +       stat->nlink = 2 + atomic_read(&vx_global_cactive);
23375 +       return 0;
23376 +}
23377 +
23378 +static struct file_operations proc_virtual_dir_operations = {
23379 +       .read =         generic_read_dir,
23380 +       .readdir =      proc_virtual_readdir,
23381 +};
23382 +
23383 +static struct inode_operations proc_virtual_dir_inode_operations = {
23384 +       .getattr =      proc_virtual_getattr,
23385 +       .lookup =       proc_virtual_lookup,
23386 +};
23387 +
23388 +
23389 +
23390 +
23391 +
23392 +int proc_virtnet_readdir(struct file *filp,
23393 +       void *dirent, filldir_t filldir)
23394 +{
23395 +       struct dentry *dentry = filp->f_dentry;
23396 +       struct inode *inode = dentry->d_inode;
23397 +       struct vs_entry *p = nx_virtnet_stuff;
23398 +       int size = sizeof(nx_virtnet_stuff) / sizeof(struct vs_entry);
23399 +       int pos, index;
23400 +       unsigned int nid_array[PROC_MAXVIDS];
23401 +       char buf[PROC_NUMBUF];
23402 +       unsigned int nr_nids, i;
23403 +       u64 ino;
23404 +
23405 +       pos = filp->f_pos;
23406 +       switch (pos) {
23407 +       case 0:
23408 +               ino = inode->i_ino;
23409 +               if (filldir(dirent, ".", 1, pos, ino, DT_DIR) < 0)
23410 +                       goto out;
23411 +               pos++;
23412 +               /* fall through */
23413 +       case 1:
23414 +               ino = parent_ino(dentry);
23415 +               if (filldir(dirent, "..", 2, pos, ino, DT_DIR) < 0)
23416 +                       goto out;
23417 +               pos++;
23418 +               /* fall through */
23419 +       default:
23420 +               index = pos - 2;
23421 +               if (index >= size)
23422 +                       goto entries;
23423 +               for (p += index; p->name; p++) {
23424 +                       if (proc_fill_cache(filp, dirent, filldir, p->name, p->len,
23425 +                               vs_proc_instantiate, 0, p))
23426 +                               goto out;
23427 +                       pos++;
23428 +               }
23429 +       entries:
23430 +               index = pos - size;
23431 +               p = &nx_virtnet_stuff[size - 1];
23432 +               nr_nids = get_nid_list(index, nid_array, PROC_MAXVIDS);
23433 +               for (i = 0; i < nr_nids; i++) {
23434 +                       int n, nid = nid_array[i];
23435 +                       unsigned int j = PROC_NUMBUF;
23436 +
23437 +                       n = nid;
23438 +                       do
23439 +                               buf[--j] = '0' + (n % 10);
23440 +                       while (n /= 10);
23441 +
23442 +                       if (proc_fill_cache(filp, dirent, filldir,
23443 +                               buf + j, PROC_NUMBUF - j,
23444 +                               vs_proc_instantiate, nid, p))
23445 +                               goto out;
23446 +                       pos++;
23447 +               }
23448 +       }
23449 +out:
23450 +       filp->f_pos = pos;
23451 +       return 0;
23452 +}
23453 +
23454 +static int proc_virtnet_getattr(struct vfsmount *mnt,
23455 +       struct dentry *dentry, struct kstat *stat)
23456 +{
23457 +       struct inode *inode = dentry->d_inode;
23458 +
23459 +       generic_fillattr(inode, stat);
23460 +       stat->nlink = 2 + atomic_read(&nx_global_cactive);
23461 +       return 0;
23462 +}
23463 +
23464 +static struct file_operations proc_virtnet_dir_operations = {
23465 +       .read =         generic_read_dir,
23466 +       .readdir =      proc_virtnet_readdir,
23467 +};
23468 +
23469 +static struct inode_operations proc_virtnet_dir_inode_operations = {
23470 +       .getattr =      proc_virtnet_getattr,
23471 +       .lookup =       proc_virtnet_lookup,
23472 +};
23473 +
23474 +
23475 +
23476 +void proc_vx_init(void)
23477 +{
23478 +       struct proc_dir_entry *ent;
23479 +
23480 +       ent = proc_mkdir("virtual", 0);
23481 +       if (ent) {
23482 +               ent->proc_fops = &proc_virtual_dir_operations;
23483 +               ent->proc_iops = &proc_virtual_dir_inode_operations;
23484 +       }
23485 +       proc_virtual = ent;
23486 +
23487 +       ent = proc_mkdir("virtnet", 0);
23488 +       if (ent) {
23489 +               ent->proc_fops = &proc_virtnet_dir_operations;
23490 +               ent->proc_iops = &proc_virtnet_dir_inode_operations;
23491 +       }
23492 +       proc_virtnet = ent;
23493 +}
23494 +
23495 +
23496 +
23497 +
23498 +/* per pid info */
23499 +
23500 +
23501 +int proc_pid_vx_info(struct task_struct *p, char *buffer)
23502 +{
23503 +       struct vx_info *vxi;
23504 +       char *orig = buffer;
23505 +
23506 +       buffer += sprintf(buffer, "XID:\t%d\n", vx_task_xid(p));
23507 +
23508 +       vxi = task_get_vx_info(p);
23509 +       if (!vxi)
23510 +               goto out;
23511 +
23512 +       buffer += sprintf(buffer, "BCaps:\t");
23513 +       buffer = print_cap_t(buffer, &vxi->vx_bcaps);
23514 +       buffer += sprintf(buffer, "\n");
23515 +       buffer += sprintf(buffer, "CCaps:\t%016llx\n",
23516 +               (unsigned long long)vxi->vx_ccaps);
23517 +       buffer += sprintf(buffer, "CFlags:\t%016llx\n",
23518 +               (unsigned long long)vxi->vx_flags);
23519 +       buffer += sprintf(buffer, "CIPid:\t%d\n", vxi->vx_initpid);
23520 +
23521 +       put_vx_info(vxi);
23522 +out:
23523 +       return buffer - orig;
23524 +}
23525 +
23526 +
23527 +int proc_pid_nx_info(struct task_struct *p, char *buffer)
23528 +{
23529 +       struct nx_info *nxi;
23530 +       struct nx_addr_v4 *v4a;
23531 +#ifdef CONFIG_IPV6
23532 +       struct nx_addr_v6 *v6a;
23533 +#endif
23534 +       char *orig = buffer;
23535 +       int i;
23536 +
23537 +       buffer += sprintf(buffer, "NID:\t%d\n", nx_task_nid(p));
23538 +
23539 +       nxi = task_get_nx_info(p);
23540 +       if (!nxi)
23541 +               goto out;
23542 +
23543 +       buffer += sprintf(buffer, "NCaps:\t%016llx\n",
23544 +               (unsigned long long)nxi->nx_ncaps);
23545 +       buffer += sprintf(buffer, "NFlags:\t%016llx\n",
23546 +               (unsigned long long)nxi->nx_flags);
23547 +
23548 +       buffer += sprintf(buffer,
23549 +               "V4Root[bcast]:\t" NIPQUAD_FMT "\n",
23550 +               NIPQUAD(nxi->v4_bcast.s_addr));
23551 +       buffer += sprintf (buffer,
23552 +               "V4Root[lback]:\t" NIPQUAD_FMT "\n",
23553 +               NIPQUAD(nxi->v4_lback.s_addr));
23554 +       if (!NX_IPV4(nxi))
23555 +               goto skip_v4;
23556 +       for (i = 0, v4a = &nxi->v4; v4a; i++, v4a = v4a->next)
23557 +               buffer += sprintf(buffer, "V4Root[%d]:\t" NXAV4_FMT "\n",
23558 +                       i, NXAV4(v4a));
23559 +skip_v4:
23560 +#ifdef CONFIG_IPV6
23561 +       if (!NX_IPV6(nxi))
23562 +               goto skip_v6;
23563 +       for (i = 0, v6a = &nxi->v6; v6a; i++, v6a = v6a->next)
23564 +               buffer += sprintf(buffer, "V6Root[%d]:\t" NXAV6_FMT "\n",
23565 +                       i, NXAV6(v6a));
23566 +skip_v6:
23567 +#endif
23568 +       put_nx_info(nxi);
23569 +out:
23570 +       return buffer - orig;
23571 +}
23572 +
23573 diff -NurpP --minimal linux-2.6.29/kernel/vserver/sched.c linux-2.6.29-vs2.3.0.36.9-pre2/kernel/vserver/sched.c
23574 --- linux-2.6.29/kernel/vserver/sched.c 1970-01-01 01:00:00.000000000 +0100
23575 +++ linux-2.6.29-vs2.3.0.36.9-pre2/kernel/vserver/sched.c       2009-02-22 22:54:26.000000000 +0100
23576 @@ -0,0 +1,414 @@
23577 +/*
23578 + *  linux/kernel/vserver/sched.c
23579 + *
23580 + *  Virtual Server: Scheduler Support
23581 + *
23582 + *  Copyright (C) 2004-2007  Herbert Pötzl
23583 + *
23584 + *  V0.01  adapted Sam Vilains version to 2.6.3
23585 + *  V0.02  removed legacy interface
23586 + *  V0.03  changed vcmds to vxi arg
23587 + *  V0.04  removed older and legacy interfaces
23588 + *
23589 + */
23590 +
23591 +#include <linux/vs_context.h>
23592 +#include <linux/vs_sched.h>
23593 +#include <linux/vserver/sched_cmd.h>
23594 +
23595 +#include <asm/uaccess.h>
23596 +
23597 +
23598 +#define vxd_check_range(val, min, max) do {            \
23599 +       vxlprintk((val < min) || (val > max),           \
23600 +               "check_range(%ld,%ld,%ld)",             \
23601 +               (long)val, (long)min, (long)max,        \
23602 +               __FILE__, __LINE__);                    \
23603 +       } while (0)
23604 +
23605 +
23606 +void vx_update_sched_param(struct _vx_sched *sched,
23607 +       struct _vx_sched_pc *sched_pc)
23608 +{
23609 +       unsigned int set_mask = sched->update_mask;
23610 +
23611 +       if (set_mask & VXSM_FILL_RATE)
23612 +               sched_pc->fill_rate[0] = sched->fill_rate[0];
23613 +       if (set_mask & VXSM_INTERVAL)
23614 +               sched_pc->interval[0] = sched->interval[0];
23615 +       if (set_mask & VXSM_FILL_RATE2)
23616 +               sched_pc->fill_rate[1] = sched->fill_rate[1];
23617 +       if (set_mask & VXSM_INTERVAL2)
23618 +               sched_pc->interval[1] = sched->interval[1];
23619 +       if (set_mask & VXSM_TOKENS)
23620 +               sched_pc->tokens = sched->tokens;
23621 +       if (set_mask & VXSM_TOKENS_MIN)
23622 +               sched_pc->tokens_min = sched->tokens_min;
23623 +       if (set_mask & VXSM_TOKENS_MAX)
23624 +               sched_pc->tokens_max = sched->tokens_max;
23625 +       if (set_mask & VXSM_PRIO_BIAS)
23626 +               sched_pc->prio_bias = sched->prio_bias;
23627 +
23628 +       if (set_mask & VXSM_IDLE_TIME)
23629 +               sched_pc->flags |= VXSF_IDLE_TIME;
23630 +       else
23631 +               sched_pc->flags &= ~VXSF_IDLE_TIME;
23632 +
23633 +       /* reset time */
23634 +       sched_pc->norm_time = jiffies;
23635 +}
23636 +
23637 +
23638 +/*
23639 + * recalculate the context's scheduling tokens
23640 + *
23641 + * ret > 0 : number of tokens available
23642 + * ret < 0 : on hold, check delta_min[]
23643 + *          -1 only jiffies
23644 + *          -2 also idle time
23645 + *
23646 + */
23647 +int vx_tokens_recalc(struct _vx_sched_pc *sched_pc,
23648 +       unsigned long *norm_time, unsigned long *idle_time, int delta_min[2])
23649 +{
23650 +       long delta;
23651 +       long tokens = 0;
23652 +       int flags = sched_pc->flags;
23653 +
23654 +       /* how much time did pass? */
23655 +       delta = *norm_time - sched_pc->norm_time;
23656 +       // printk("@ %ld, %ld, %ld\n", *norm_time, sched_pc->norm_time, jiffies);
23657 +       vxd_check_range(delta, 0, INT_MAX);
23658 +
23659 +       if (delta >= sched_pc->interval[0]) {
23660 +               long tokens, integral;
23661 +
23662 +               /* calc integral token part */
23663 +               tokens = delta / sched_pc->interval[0];
23664 +               integral = tokens * sched_pc->interval[0];
23665 +               tokens *= sched_pc->fill_rate[0];
23666 +#ifdef CONFIG_VSERVER_HARDCPU
23667 +               delta_min[0] = delta - integral;
23668 +               vxd_check_range(delta_min[0], 0, sched_pc->interval[0]);
23669 +#endif
23670 +               /* advance time */
23671 +               sched_pc->norm_time += delta;
23672 +
23673 +               /* add tokens */
23674 +               sched_pc->tokens += tokens;
23675 +               sched_pc->token_time += tokens;
23676 +       } else
23677 +               delta_min[0] = delta;
23678 +
23679 +#ifdef CONFIG_VSERVER_IDLETIME
23680 +       if (!(flags & VXSF_IDLE_TIME))
23681 +               goto skip_idle;
23682 +
23683 +       /* how much was the idle skip? */
23684 +       delta = *idle_time - sched_pc->idle_time;
23685 +       vxd_check_range(delta, 0, INT_MAX);
23686 +
23687 +       if (delta >= sched_pc->interval[1]) {
23688 +               long tokens, integral;
23689 +
23690 +               /* calc fair share token part */
23691 +               tokens = delta / sched_pc->interval[1];
23692 +               integral = tokens * sched_pc->interval[1];
23693 +               tokens *= sched_pc->fill_rate[1];
23694 +               delta_min[1] = delta - integral;
23695 +               vxd_check_range(delta_min[1], 0, sched_pc->interval[1]);
23696 +
23697 +               /* advance idle time */
23698 +               sched_pc->idle_time += integral;
23699 +
23700 +               /* add tokens */
23701 +               sched_pc->tokens += tokens;
23702 +               sched_pc->token_time += tokens;
23703 +       } else
23704 +               delta_min[1] = delta;
23705 +skip_idle:
23706 +#endif
23707 +
23708 +       /* clip at maximum */
23709 +       if (sched_pc->tokens > sched_pc->tokens_max)
23710 +               sched_pc->tokens = sched_pc->tokens_max;
23711 +       tokens = sched_pc->tokens;
23712 +
23713 +       if ((flags & VXSF_ONHOLD)) {
23714 +               /* can we unhold? */
23715 +               if (tokens >= sched_pc->tokens_min) {
23716 +                       flags &= ~VXSF_ONHOLD;
23717 +                       sched_pc->hold_ticks +=
23718 +                               *norm_time - sched_pc->onhold;
23719 +               } else
23720 +                       goto on_hold;
23721 +       } else {
23722 +               /* put on hold? */
23723 +               if (tokens <= 0) {
23724 +                       flags |= VXSF_ONHOLD;
23725 +                       sched_pc->onhold = *norm_time;
23726 +                       goto on_hold;
23727 +               }
23728 +       }
23729 +       sched_pc->flags = flags;
23730 +       return tokens;
23731 +
23732 +on_hold:
23733 +       tokens = sched_pc->tokens_min - tokens;
23734 +       sched_pc->flags = flags;
23735 +       // BUG_ON(tokens < 0); probably doesn't hold anymore
23736 +
23737 +#ifdef CONFIG_VSERVER_HARDCPU
23738 +       /* next interval? */
23739 +       if (!sched_pc->fill_rate[0])
23740 +               delta_min[0] = HZ;
23741 +       else if (tokens > sched_pc->fill_rate[0])
23742 +               delta_min[0] += sched_pc->interval[0] *
23743 +                       tokens / sched_pc->fill_rate[0];
23744 +       else
23745 +               delta_min[0] = sched_pc->interval[0] - delta_min[0];
23746 +       vxd_check_range(delta_min[0], 0, INT_MAX);
23747 +
23748 +#ifdef CONFIG_VSERVER_IDLETIME
23749 +       if (!(flags & VXSF_IDLE_TIME))
23750 +               return -1;
23751 +
23752 +       /* next interval? */
23753 +       if (!sched_pc->fill_rate[1])
23754 +               delta_min[1] = HZ;
23755 +       else if (tokens > sched_pc->fill_rate[1])
23756 +               delta_min[1] += sched_pc->interval[1] *
23757 +                       tokens / sched_pc->fill_rate[1];
23758 +       else
23759 +               delta_min[1] = sched_pc->interval[1] - delta_min[1];
23760 +       vxd_check_range(delta_min[1], 0, INT_MAX);
23761 +
23762 +       return -2;
23763 +#else
23764 +       return -1;
23765 +#endif /* CONFIG_VSERVER_IDLETIME */
23766 +#else
23767 +       return 0;
23768 +#endif /* CONFIG_VSERVER_HARDCPU */
23769 +}
23770 +
23771 +static inline unsigned long msec_to_ticks(unsigned long msec)
23772 +{
23773 +       return msecs_to_jiffies(msec);
23774 +}
23775 +
23776 +static inline unsigned long ticks_to_msec(unsigned long ticks)
23777 +{
23778 +       return jiffies_to_msecs(ticks);
23779 +}
23780 +
23781 +static inline unsigned long ticks_to_usec(unsigned long ticks)
23782 +{
23783 +       return jiffies_to_usecs(ticks);
23784 +}
23785 +
23786 +
23787 +static int do_set_sched(struct vx_info *vxi, struct vcmd_sched_v5 *data)
23788 +{
23789 +       unsigned int set_mask = data->mask;
23790 +       unsigned int update_mask;
23791 +       int i, cpu;
23792 +
23793 +       /* Sanity check data values */
23794 +       if (data->tokens_max <= 0)
23795 +               data->tokens_max = HZ;
23796 +       if (data->tokens_min < 0)
23797 +               data->tokens_min = HZ / 3;
23798 +       if (data->tokens_min >= data->tokens_max)
23799 +               data->tokens_min = data->tokens_max;
23800 +
23801 +       if (data->prio_bias > MAX_PRIO_BIAS)
23802 +               data->prio_bias = MAX_PRIO_BIAS;
23803 +       if (data->prio_bias < MIN_PRIO_BIAS)
23804 +               data->prio_bias = MIN_PRIO_BIAS;
23805 +
23806 +       spin_lock(&vxi->sched.tokens_lock);
23807 +
23808 +       /* sync up on delayed updates */
23809 +       for_each_cpu_mask(cpu, vxi->sched.update)
23810 +               vx_update_sched_param(&vxi->sched,
23811 +                       &vx_per_cpu(vxi, sched_pc, cpu));
23812 +
23813 +       if (set_mask & VXSM_FILL_RATE)
23814 +               vxi->sched.fill_rate[0] = data->fill_rate[0];
23815 +       if (set_mask & VXSM_FILL_RATE2)
23816 +               vxi->sched.fill_rate[1] = data->fill_rate[1];
23817 +       if (set_mask & VXSM_INTERVAL)
23818 +               vxi->sched.interval[0] = (set_mask & VXSM_MSEC) ?
23819 +                       msec_to_ticks(data->interval[0]) : data->interval[0];
23820 +       if (set_mask & VXSM_INTERVAL2)
23821 +               vxi->sched.interval[1] = (set_mask & VXSM_MSEC) ?
23822 +                       msec_to_ticks(data->interval[1]) : data->interval[1];
23823 +       if (set_mask & VXSM_TOKENS)
23824 +               vxi->sched.tokens = data->tokens;
23825 +       if (set_mask & VXSM_TOKENS_MIN)
23826 +               vxi->sched.tokens_min = data->tokens_min;
23827 +       if (set_mask & VXSM_TOKENS_MAX)
23828 +               vxi->sched.tokens_max = data->tokens_max;
23829 +       if (set_mask & VXSM_PRIO_BIAS)
23830 +               vxi->sched.prio_bias = data->prio_bias;
23831 +
23832 +       /* Sanity check rate/interval */
23833 +       for (i = 0; i < 2; i++) {
23834 +               if (data->fill_rate[i] < 0)
23835 +                       data->fill_rate[i] = 0;
23836 +               if (data->interval[i] <= 0)
23837 +                       data->interval[i] = HZ;
23838 +       }
23839 +
23840 +       update_mask = vxi->sched.update_mask & VXSM_SET_MASK;
23841 +       update_mask |= (set_mask & (VXSM_SET_MASK | VXSM_IDLE_TIME));
23842 +       vxi->sched.update_mask = update_mask;
23843 +
23844 +#ifdef CONFIG_SMP
23845 +       rmb();
23846 +       if (set_mask & VXSM_CPU_ID) {
23847 +               vxi->sched.update = cpumask_of_cpu(data->cpu_id);
23848 +               cpus_and(vxi->sched.update, cpu_online_map,
23849 +                       vxi->sched.update);
23850 +       } else
23851 +               vxi->sched.update = cpu_online_map;
23852 +
23853 +       /* forced reload? */
23854 +       if (set_mask & VXSM_FORCE) {
23855 +               for_each_cpu_mask(cpu, vxi->sched.update)
23856 +                       vx_update_sched_param(&vxi->sched,
23857 +                               &vx_per_cpu(vxi, sched_pc, cpu));
23858 +               vxi->sched.update = CPU_MASK_NONE;
23859 +       }
23860 +#else
23861 +       /* on UP we update immediately */
23862 +       vx_update_sched_param(&vxi->sched,
23863 +               &vx_per_cpu(vxi, sched_pc, 0));
23864 +#endif
23865 +
23866 +       spin_unlock(&vxi->sched.tokens_lock);
23867 +       return 0;
23868 +}
23869 +
23870 +
23871 +#define COPY_IDS(C) C(cpu_id); C(bucket_id)
23872 +#define COPY_PRI(C) C(prio_bias)
23873 +#define COPY_TOK(C) C(tokens); C(tokens_min); C(tokens_max)
23874 +#define COPY_FRI(C) C(fill_rate[0]); C(interval[0]);   \
23875 +                   C(fill_rate[1]); C(interval[1]);
23876 +
23877 +#define COPY_VALUE(name) vc_data.name = data->name
23878 +
23879 +static int do_set_sched_v4(struct vx_info *vxi, struct vcmd_set_sched_v4 *data)
23880 +{
23881 +       struct vcmd_sched_v5 vc_data;
23882 +
23883 +       vc_data.mask = data->set_mask;
23884 +       COPY_IDS(COPY_VALUE);
23885 +       COPY_PRI(COPY_VALUE);
23886 +       COPY_TOK(COPY_VALUE);
23887 +       vc_data.fill_rate[0] = vc_data.fill_rate[1] = data->fill_rate;
23888 +       vc_data.interval[0] = vc_data.interval[1] = data->interval;
23889 +       return do_set_sched(vxi, &vc_data);
23890 +}
23891 +
23892 +int vc_set_sched_v4(struct vx_info *vxi, void __user *data)
23893 +{
23894 +       struct vcmd_set_sched_v4 vc_data;
23895 +
23896 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
23897 +               return -EFAULT;
23898 +
23899 +       return do_set_sched_v4(vxi, &vc_data);
23900 +}
23901 +
23902 +       /* latest interface is v5 */
23903 +
23904 +int vc_set_sched(struct vx_info *vxi, void __user *data)
23905 +{
23906 +       struct vcmd_sched_v5 vc_data;
23907 +
23908 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
23909 +               return -EFAULT;
23910 +
23911 +       return do_set_sched(vxi, &vc_data);
23912 +}
23913 +
23914 +
23915 +#define COPY_PRI(C) C(prio_bias)
23916 +#define COPY_TOK(C) C(tokens); C(tokens_min); C(tokens_max)
23917 +#define COPY_FRI(C) C(fill_rate[0]); C(interval[0]);    \
23918 +                   C(fill_rate[1]); C(interval[1]);
23919 +
23920 +#define COPY_VALUE(name) vc_data.name = data->name
23921 +
23922 +
23923 +int vc_get_sched(struct vx_info *vxi, void __user *data)
23924 +{
23925 +       struct vcmd_sched_v5 vc_data;
23926 +
23927 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
23928 +               return -EFAULT;
23929 +
23930 +       if (vc_data.mask & VXSM_CPU_ID) {
23931 +               int cpu = vc_data.cpu_id;
23932 +               struct _vx_sched_pc *data;
23933 +
23934 +               if (!cpu_possible(cpu))
23935 +                       return -EINVAL;
23936 +
23937 +               data = &vx_per_cpu(vxi, sched_pc, cpu);
23938 +               COPY_TOK(COPY_VALUE);
23939 +               COPY_PRI(COPY_VALUE);
23940 +               COPY_FRI(COPY_VALUE);
23941 +
23942 +               if (data->flags & VXSF_IDLE_TIME)
23943 +                       vc_data.mask |= VXSM_IDLE_TIME;
23944 +       } else {
23945 +               struct _vx_sched *data = &vxi->sched;
23946 +
23947 +               COPY_TOK(COPY_VALUE);
23948 +               COPY_PRI(COPY_VALUE);
23949 +               COPY_FRI(COPY_VALUE);
23950 +       }
23951 +
23952 +       if (vc_data.mask & VXSM_MSEC) {
23953 +               vc_data.interval[0] = ticks_to_msec(vc_data.interval[0]);
23954 +               vc_data.interval[1] = ticks_to_msec(vc_data.interval[1]);
23955 +       }
23956 +
23957 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
23958 +               return -EFAULT;
23959 +       return 0;
23960 +}
23961 +
23962 +
23963 +int vc_sched_info(struct vx_info *vxi, void __user *data)
23964 +{
23965 +       struct vcmd_sched_info vc_data;
23966 +       int cpu;
23967 +
23968 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
23969 +               return -EFAULT;
23970 +
23971 +       cpu = vc_data.cpu_id;
23972 +       if (!cpu_possible(cpu))
23973 +               return -EINVAL;
23974 +
23975 +       if (vxi) {
23976 +               struct _vx_sched_pc *sched_pc =
23977 +                       &vx_per_cpu(vxi, sched_pc, cpu);
23978 +
23979 +               vc_data.user_msec = ticks_to_msec(sched_pc->user_ticks);
23980 +               vc_data.sys_msec = ticks_to_msec(sched_pc->sys_ticks);
23981 +               vc_data.hold_msec = ticks_to_msec(sched_pc->hold_ticks);
23982 +               vc_data.vavavoom = sched_pc->vavavoom;
23983 +       }
23984 +       vc_data.token_usec = ticks_to_usec(1);
23985 +
23986 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
23987 +               return -EFAULT;
23988 +       return 0;
23989 +}
23990 +
23991 diff -NurpP --minimal linux-2.6.29/kernel/vserver/sched_init.h linux-2.6.29-vs2.3.0.36.9-pre2/kernel/vserver/sched_init.h
23992 --- linux-2.6.29/kernel/vserver/sched_init.h    1970-01-01 01:00:00.000000000 +0100
23993 +++ linux-2.6.29-vs2.3.0.36.9-pre2/kernel/vserver/sched_init.h  2009-02-22 22:54:26.000000000 +0100
23994 @@ -0,0 +1,50 @@
23995 +
23996 +static inline void vx_info_init_sched(struct _vx_sched *sched)
23997 +{
23998 +       static struct lock_class_key tokens_lock_key;
23999 +
24000 +       /* scheduling; hard code starting values as constants */
24001 +       sched->fill_rate[0]     = 1;
24002 +       sched->interval[0]      = 4;
24003 +       sched->fill_rate[1]     = 1;
24004 +       sched->interval[1]      = 8;
24005 +       sched->tokens           = HZ >> 2;
24006 +       sched->tokens_min       = HZ >> 4;
24007 +       sched->tokens_max       = HZ >> 1;
24008 +       sched->tokens_lock      = SPIN_LOCK_UNLOCKED;
24009 +       sched->prio_bias        = 0;
24010 +
24011 +       lockdep_set_class(&sched->tokens_lock, &tokens_lock_key);
24012 +}
24013 +
24014 +static inline
24015 +void vx_info_init_sched_pc(struct _vx_sched_pc *sched_pc, int cpu)
24016 +{
24017 +       sched_pc->fill_rate[0]  = 1;
24018 +       sched_pc->interval[0]   = 4;
24019 +       sched_pc->fill_rate[1]  = 1;
24020 +       sched_pc->interval[1]   = 8;
24021 +       sched_pc->tokens        = HZ >> 2;
24022 +       sched_pc->tokens_min    = HZ >> 4;
24023 +       sched_pc->tokens_max    = HZ >> 1;
24024 +       sched_pc->prio_bias     = 0;
24025 +       sched_pc->vavavoom      = 0;
24026 +       sched_pc->token_time    = 0;
24027 +       sched_pc->idle_time     = 0;
24028 +       sched_pc->norm_time     = jiffies;
24029 +
24030 +       sched_pc->user_ticks = 0;
24031 +       sched_pc->sys_ticks = 0;
24032 +       sched_pc->hold_ticks = 0;
24033 +}
24034 +
24035 +static inline void vx_info_exit_sched(struct _vx_sched *sched)
24036 +{
24037 +       return;
24038 +}
24039 +
24040 +static inline
24041 +void vx_info_exit_sched_pc(struct _vx_sched_pc *sched_pc, int cpu)
24042 +{
24043 +       return;
24044 +}
24045 diff -NurpP --minimal linux-2.6.29/kernel/vserver/sched_proc.h linux-2.6.29-vs2.3.0.36.9-pre2/kernel/vserver/sched_proc.h
24046 --- linux-2.6.29/kernel/vserver/sched_proc.h    1970-01-01 01:00:00.000000000 +0100
24047 +++ linux-2.6.29-vs2.3.0.36.9-pre2/kernel/vserver/sched_proc.h  2009-02-22 22:54:26.000000000 +0100
24048 @@ -0,0 +1,57 @@
24049 +#ifndef _VX_SCHED_PROC_H
24050 +#define _VX_SCHED_PROC_H
24051 +
24052 +
24053 +static inline
24054 +int vx_info_proc_sched(struct _vx_sched *sched, char *buffer)
24055 +{
24056 +       int length = 0;
24057 +
24058 +       length += sprintf(buffer,
24059 +               "FillRate:\t%8d,%d\n"
24060 +               "Interval:\t%8d,%d\n"
24061 +               "TokensMin:\t%8d\n"
24062 +               "TokensMax:\t%8d\n"
24063 +               "PrioBias:\t%8d\n",
24064 +               sched->fill_rate[0],
24065 +               sched->fill_rate[1],
24066 +               sched->interval[0],
24067 +               sched->interval[1],
24068 +               sched->tokens_min,
24069 +               sched->tokens_max,
24070 +               sched->prio_bias);
24071 +       return length;
24072 +}
24073 +
24074 +static inline
24075 +int vx_info_proc_sched_pc(struct _vx_sched_pc *sched_pc,
24076 +       char *buffer, int cpu)
24077 +{
24078 +       int length = 0;
24079 +
24080 +       length += sprintf(buffer + length,
24081 +               "cpu %d: %lld %lld %lld %ld %ld", cpu,
24082 +               (unsigned long long)sched_pc->user_ticks,
24083 +               (unsigned long long)sched_pc->sys_ticks,
24084 +               (unsigned long long)sched_pc->hold_ticks,
24085 +               sched_pc->token_time,
24086 +               sched_pc->idle_time);
24087 +       length += sprintf(buffer + length,
24088 +               " %c%c %d %d %d %d/%d %d/%d",
24089 +               (sched_pc->flags & VXSF_ONHOLD) ? 'H' : 'R',
24090 +               (sched_pc->flags & VXSF_IDLE_TIME) ? 'I' : '-',
24091 +               sched_pc->tokens,
24092 +               sched_pc->tokens_min,
24093 +               sched_pc->tokens_max,
24094 +               sched_pc->fill_rate[0],
24095 +               sched_pc->interval[0],
24096 +               sched_pc->fill_rate[1],
24097 +               sched_pc->interval[1]);
24098 +       length += sprintf(buffer + length,
24099 +               " %d %d\n",
24100 +               sched_pc->prio_bias,
24101 +               sched_pc->vavavoom);
24102 +       return length;
24103 +}
24104 +
24105 +#endif /* _VX_SCHED_PROC_H */
24106 diff -NurpP --minimal linux-2.6.29/kernel/vserver/signal.c linux-2.6.29-vs2.3.0.36.9-pre2/kernel/vserver/signal.c
24107 --- linux-2.6.29/kernel/vserver/signal.c        1970-01-01 01:00:00.000000000 +0100
24108 +++ linux-2.6.29-vs2.3.0.36.9-pre2/kernel/vserver/signal.c      2009-02-22 22:54:26.000000000 +0100
24109 @@ -0,0 +1,132 @@
24110 +/*
24111 + *  linux/kernel/vserver/signal.c
24112 + *
24113 + *  Virtual Server: Signal Support
24114 + *
24115 + *  Copyright (C) 2003-2007  Herbert Pötzl
24116 + *
24117 + *  V0.01  broken out from vcontext V0.05
24118 + *  V0.02  changed vcmds to vxi arg
24119 + *  V0.03  adjusted siginfo for kill
24120 + *
24121 + */
24122 +
24123 +#include <asm/uaccess.h>
24124 +
24125 +#include <linux/vs_context.h>
24126 +#include <linux/vs_pid.h>
24127 +#include <linux/vserver/signal_cmd.h>
24128 +
24129 +
24130 +int vx_info_kill(struct vx_info *vxi, int pid, int sig)
24131 +{
24132 +       int retval, count = 0;
24133 +       struct task_struct *p;
24134 +       struct siginfo *sip = SEND_SIG_PRIV;
24135 +
24136 +       retval = -ESRCH;
24137 +       vxdprintk(VXD_CBIT(misc, 4),
24138 +               "vx_info_kill(%p[#%d],%d,%d)*",
24139 +               vxi, vxi->vx_id, pid, sig);
24140 +       read_lock(&tasklist_lock);
24141 +       switch (pid) {
24142 +       case  0:
24143 +       case -1:
24144 +               for_each_process(p) {
24145 +                       int err = 0;
24146 +
24147 +                       if (vx_task_xid(p) != vxi->vx_id || p->pid <= 1 ||
24148 +                               (pid && vxi->vx_initpid == p->pid))
24149 +                               continue;
24150 +
24151 +                       err = group_send_sig_info(sig, sip, p);
24152 +                       ++count;
24153 +                       if (err != -EPERM)
24154 +                               retval = err;
24155 +               }
24156 +               break;
24157 +
24158 +       case 1:
24159 +               if (vxi->vx_initpid) {
24160 +                       pid = vxi->vx_initpid;
24161 +                       /* for now, only SIGINT to private init ... */
24162 +                       if (!vx_info_flags(vxi, VXF_STATE_ADMIN, 0) &&
24163 +                               /* ... as long as there are tasks left */
24164 +                               (atomic_read(&vxi->vx_tasks) > 1))
24165 +                               sig = SIGINT;
24166 +               }
24167 +               /* fallthrough */
24168 +       default:
24169 +               p = find_task_by_real_pid(pid);
24170 +               if (p) {
24171 +                       if (vx_task_xid(p) == vxi->vx_id)
24172 +                               retval = group_send_sig_info(sig, sip, p);
24173 +               }
24174 +               break;
24175 +       }
24176 +       read_unlock(&tasklist_lock);
24177 +       vxdprintk(VXD_CBIT(misc, 4),
24178 +               "vx_info_kill(%p[#%d],%d,%d,%ld) = %d",
24179 +               vxi, vxi->vx_id, pid, sig, (long)sip, retval);
24180 +       return retval;
24181 +}
24182 +
24183 +int vc_ctx_kill(struct vx_info *vxi, void __user *data)
24184 +{
24185 +       struct vcmd_ctx_kill_v0 vc_data;
24186 +
24187 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
24188 +               return -EFAULT;
24189 +
24190 +       /* special check to allow guest shutdown */
24191 +       if (!vx_info_flags(vxi, VXF_STATE_ADMIN, 0) &&
24192 +               /* forbid killall pid=0 when init is present */
24193 +               (((vc_data.pid < 1) && vxi->vx_initpid) ||
24194 +               (vc_data.pid > 1)))
24195 +               return -EACCES;
24196 +
24197 +       return vx_info_kill(vxi, vc_data.pid, vc_data.sig);
24198 +}
24199 +
24200 +
24201 +static int __wait_exit(struct vx_info *vxi)
24202 +{
24203 +       DECLARE_WAITQUEUE(wait, current);
24204 +       int ret = 0;
24205 +
24206 +       add_wait_queue(&vxi->vx_wait, &wait);
24207 +       set_current_state(TASK_INTERRUPTIBLE);
24208 +
24209 +wait:
24210 +       if (vx_info_state(vxi,
24211 +               VXS_SHUTDOWN | VXS_HASHED | VXS_HELPER) == VXS_SHUTDOWN)
24212 +               goto out;
24213 +       if (signal_pending(current)) {
24214 +               ret = -ERESTARTSYS;
24215 +               goto out;
24216 +       }
24217 +       schedule();
24218 +       goto wait;
24219 +
24220 +out:
24221 +       set_current_state(TASK_RUNNING);
24222 +       remove_wait_queue(&vxi->vx_wait, &wait);
24223 +       return ret;
24224 +}
24225 +
24226 +
24227 +
24228 +int vc_wait_exit(struct vx_info *vxi, void __user *data)
24229 +{
24230 +       struct vcmd_wait_exit_v0 vc_data;
24231 +       int ret;
24232 +
24233 +       ret = __wait_exit(vxi);
24234 +       vc_data.reboot_cmd = vxi->reboot_cmd;
24235 +       vc_data.exit_code = vxi->exit_code;
24236 +
24237 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
24238 +               ret = -EFAULT;
24239 +       return ret;
24240 +}
24241 +
24242 diff -NurpP --minimal linux-2.6.29/kernel/vserver/space.c linux-2.6.29-vs2.3.0.36.9-pre2/kernel/vserver/space.c
24243 --- linux-2.6.29/kernel/vserver/space.c 1970-01-01 01:00:00.000000000 +0100
24244 +++ linux-2.6.29-vs2.3.0.36.9-pre2/kernel/vserver/space.c       2009-03-25 00:39:55.000000000 +0100
24245 @@ -0,0 +1,387 @@
24246 +/*
24247 + *  linux/kernel/vserver/space.c
24248 + *
24249 + *  Virtual Server: Context Space Support
24250 + *
24251 + *  Copyright (C) 2003-2007  Herbert Pötzl
24252 + *
24253 + *  V0.01  broken out from context.c 0.07
24254 + *  V0.02  added task locking for namespace
24255 + *  V0.03  broken out vx_enter_namespace
24256 + *  V0.04  added *space support and commands
24257 + *
24258 + */
24259 +
24260 +#include <linux/utsname.h>
24261 +#include <linux/nsproxy.h>
24262 +#include <linux/err.h>
24263 +#include <asm/uaccess.h>
24264 +
24265 +#include <linux/vs_context.h>
24266 +#include <linux/vserver/space.h>
24267 +#include <linux/vserver/space_cmd.h>
24268 +
24269 +atomic_t vs_global_nsproxy     = ATOMIC_INIT(0);
24270 +atomic_t vs_global_fs          = ATOMIC_INIT(0);
24271 +atomic_t vs_global_mnt_ns      = ATOMIC_INIT(0);
24272 +atomic_t vs_global_uts_ns      = ATOMIC_INIT(0);
24273 +atomic_t vs_global_ipc_ns      = ATOMIC_INIT(0);
24274 +atomic_t vs_global_user_ns     = ATOMIC_INIT(0);
24275 +atomic_t vs_global_pid_ns      = ATOMIC_INIT(0);
24276 +
24277 +
24278 +/* namespace functions */
24279 +
24280 +#include <linux/mnt_namespace.h>
24281 +#include <linux/user_namespace.h>
24282 +#include <linux/pid_namespace.h>
24283 +#include <linux/ipc_namespace.h>
24284 +#include <net/net_namespace.h>
24285 +
24286 +
24287 +static const struct vcmd_space_mask_v1 space_mask_v0 = {
24288 +       .mask = CLONE_FS |
24289 +               CLONE_NEWNS |
24290 +               CLONE_NEWUTS |
24291 +               CLONE_NEWIPC |
24292 +               CLONE_NEWUSER |
24293 +               0
24294 +};
24295 +
24296 +static const struct vcmd_space_mask_v1 space_mask = {
24297 +       .mask = CLONE_FS |
24298 +               CLONE_NEWNS |
24299 +               CLONE_NEWUTS |
24300 +               CLONE_NEWIPC |
24301 +               CLONE_NEWUSER |
24302 +#ifdef CONFIG_PID_NS
24303 +               CLONE_NEWPID |
24304 +#endif
24305 +#ifdef CONFIG_NET_NS
24306 +               CLONE_NEWNET |
24307 +#endif
24308 +               0
24309 +};
24310 +
24311 +static const struct vcmd_space_mask_v1 default_space_mask = {
24312 +       .mask = CLONE_FS |
24313 +               CLONE_NEWNS |
24314 +               CLONE_NEWUTS |
24315 +               CLONE_NEWIPC |
24316 +               CLONE_NEWUSER |
24317 +#ifdef CONFIG_PID_NS
24318 +//             CLONE_NEWPID |
24319 +#endif
24320 +               0
24321 +};
24322 +
24323 +/*
24324 + *     build a new nsproxy mix
24325 + *      assumes that both proxies are 'const'
24326 + *     does not touch nsproxy refcounts
24327 + *     will hold a reference on the result.
24328 + */
24329 +
24330 +struct nsproxy *vs_mix_nsproxy(struct nsproxy *old_nsproxy,
24331 +       struct nsproxy *new_nsproxy, unsigned long mask)
24332 +{
24333 +       struct mnt_namespace *old_ns;
24334 +       struct uts_namespace *old_uts;
24335 +       struct ipc_namespace *old_ipc;
24336 +#ifdef CONFIG_PID_NS
24337 +       struct pid_namespace *old_pid;
24338 +#endif
24339 +#ifdef CONFIG_NET_NS
24340 +       struct net *old_net;
24341 +#endif
24342 +       struct nsproxy *nsproxy;
24343 +
24344 +       nsproxy = copy_nsproxy(old_nsproxy);
24345 +       if (!nsproxy)
24346 +               goto out;
24347 +
24348 +       if (mask & CLONE_NEWNS) {
24349 +               old_ns = nsproxy->mnt_ns;
24350 +               nsproxy->mnt_ns = new_nsproxy->mnt_ns;
24351 +               if (nsproxy->mnt_ns)
24352 +                       get_mnt_ns(nsproxy->mnt_ns);
24353 +       } else
24354 +               old_ns = NULL;
24355 +
24356 +       if (mask & CLONE_NEWUTS) {
24357 +               old_uts = nsproxy->uts_ns;
24358 +               nsproxy->uts_ns = new_nsproxy->uts_ns;
24359 +               if (nsproxy->uts_ns)
24360 +                       get_uts_ns(nsproxy->uts_ns);
24361 +       } else
24362 +               old_uts = NULL;
24363 +
24364 +       if (mask & CLONE_NEWIPC) {
24365 +               old_ipc = nsproxy->ipc_ns;
24366 +               nsproxy->ipc_ns = new_nsproxy->ipc_ns;
24367 +               if (nsproxy->ipc_ns)
24368 +                       get_ipc_ns(nsproxy->ipc_ns);
24369 +       } else
24370 +               old_ipc = NULL;
24371 +
24372 +#ifdef CONFIG_PID_NS
24373 +       if (mask & CLONE_NEWPID) {
24374 +               old_pid = nsproxy->pid_ns;
24375 +               nsproxy->pid_ns = new_nsproxy->pid_ns;
24376 +               if (nsproxy->pid_ns)
24377 +                       get_pid_ns(nsproxy->pid_ns);
24378 +       } else
24379 +               old_pid = NULL;
24380 +#endif
24381 +#ifdef CONFIG_NET_NS
24382 +       if (mask & CLONE_NEWNET) {
24383 +               old_net = nsproxy->net_ns;
24384 +               nsproxy->net_ns = new_nsproxy->net_ns;
24385 +               if (nsproxy->net_ns)
24386 +                       get_net(nsproxy->net_ns);
24387 +       } else
24388 +               old_net = NULL;
24389 +#endif
24390 +       if (old_ns)
24391 +               put_mnt_ns(old_ns);
24392 +       if (old_uts)
24393 +               put_uts_ns(old_uts);
24394 +       if (old_ipc)
24395 +               put_ipc_ns(old_ipc);
24396 +#ifdef CONFIG_PID_NS
24397 +       if (old_pid)
24398 +               put_pid_ns(old_pid);
24399 +#endif
24400 +#ifdef CONFIG_NET_NS
24401 +       if (old_net)
24402 +               put_net(old_net);
24403 +#endif
24404 +out:
24405 +       return nsproxy;
24406 +}
24407 +
24408 +
24409 +/*
24410 + *     merge two nsproxy structs into a new one.
24411 + *     will hold a reference on the result.
24412 + */
24413 +
24414 +static inline
24415 +struct nsproxy *__vs_merge_nsproxy(struct nsproxy *old,
24416 +       struct nsproxy *proxy, unsigned long mask)
24417 +{
24418 +       struct nsproxy null_proxy = { .mnt_ns = NULL };
24419 +
24420 +       if (!proxy)
24421 +               return NULL;
24422 +
24423 +       if (mask) {
24424 +               /* vs_mix_nsproxy returns with reference */
24425 +               return vs_mix_nsproxy(old ? old : &null_proxy,
24426 +                       proxy, mask);
24427 +       }
24428 +       get_nsproxy(proxy);
24429 +       return proxy;
24430 +}
24431 +
24432 +/*
24433 + *     merge two fs structs into a new one.
24434 + *     will take a reference on the result.
24435 + */
24436 +
24437 +static inline
24438 +struct fs_struct *__vs_merge_fs(struct fs_struct *old,
24439 +       struct fs_struct *fs, unsigned long mask)
24440 +{
24441 +       if (!(mask & CLONE_FS)) {
24442 +               if (old)
24443 +                       atomic_inc(&old->count);
24444 +               return old;
24445 +       }
24446 +
24447 +       if (!fs)
24448 +               return NULL;
24449 +
24450 +       return copy_fs_struct(fs);
24451 +}
24452 +
24453 +
24454 +int vx_enter_space(struct vx_info *vxi, unsigned long mask, unsigned index)
24455 +{
24456 +       struct nsproxy *proxy, *proxy_cur, *proxy_new;
24457 +       struct fs_struct *fs, *fs_cur, *fs_new;
24458 +       int ret;
24459 +
24460 +       vxdprintk(VXD_CBIT(space, 8), "vx_enter_space(%p[#%u],0x%08lx,%d)",
24461 +               vxi, vxi->vx_id, mask, index);
24462 +
24463 +       if (vx_info_flags(vxi, VXF_INFO_PRIVATE, 0))
24464 +               return -EACCES;
24465 +
24466 +       if (!mask)
24467 +               mask = vxi->vx_nsmask[index];
24468 +
24469 +       if ((mask & vxi->vx_nsmask[index]) != mask)
24470 +               return -EINVAL;
24471 +
24472 +       proxy = vxi->vx_nsproxy[index];
24473 +       fs = vxi->vx_fs[index];
24474 +
24475 +       task_lock(current);
24476 +       fs_cur = current->fs;
24477 +       atomic_inc(&fs_cur->count);
24478 +       proxy_cur = current->nsproxy;
24479 +       get_nsproxy(proxy_cur);
24480 +       task_unlock(current);
24481 +
24482 +       fs_new = __vs_merge_fs(fs_cur, fs, mask);
24483 +       if (IS_ERR(fs_new)) {
24484 +               ret = PTR_ERR(fs_new);
24485 +               goto out_put;
24486 +       }
24487 +
24488 +       proxy_new = __vs_merge_nsproxy(proxy_cur, proxy, mask);
24489 +       if (IS_ERR(proxy_new)) {
24490 +               ret = PTR_ERR(proxy_new);
24491 +               goto out_put_fs;
24492 +       }
24493 +
24494 +       fs_new = xchg(&current->fs, fs_new);
24495 +       proxy_new = xchg(&current->nsproxy, proxy_new);
24496 +       ret = 0;
24497 +
24498 +       if (proxy_new)
24499 +               put_nsproxy(proxy_new);
24500 +out_put_fs:
24501 +       if (fs_new)
24502 +               put_fs_struct(fs_new);
24503 +out_put:
24504 +       if (proxy_cur)
24505 +               put_nsproxy(proxy_cur);
24506 +       if (fs_cur)
24507 +               put_fs_struct(fs_cur);
24508 +       return ret;
24509 +}
24510 +
24511 +
24512 +int vx_set_space(struct vx_info *vxi, unsigned long mask, unsigned index)
24513 +{
24514 +       struct nsproxy *proxy_vxi, *proxy_cur, *proxy_new;
24515 +       struct fs_struct *fs_vxi, *fs_cur, *fs_new;
24516 +       int ret;
24517 +
24518 +       vxdprintk(VXD_CBIT(space, 8), "vx_set_space(%p[#%u],0x%08lx,%d)",
24519 +               vxi, vxi->vx_id, mask, index);
24520 +#if 0
24521 +       if (!mask)
24522 +               mask = default_space_mask.mask;
24523 +#endif
24524 +       if ((mask & space_mask.mask) != mask)
24525 +               return -EINVAL;
24526 +
24527 +       proxy_vxi = vxi->vx_nsproxy[index];
24528 +       fs_vxi = vxi->vx_fs[index];
24529 +
24530 +       task_lock(current);
24531 +       fs_cur = current->fs;
24532 +       atomic_inc(&fs_cur->count);
24533 +       proxy_cur = current->nsproxy;
24534 +       get_nsproxy(proxy_cur);
24535 +       task_unlock(current);
24536 +
24537 +       fs_new = __vs_merge_fs(fs_vxi, fs_cur, mask);
24538 +       if (IS_ERR(fs_new)) {
24539 +               ret = PTR_ERR(fs_new);
24540 +               goto out_put;
24541 +       }
24542 +
24543 +       proxy_new = __vs_merge_nsproxy(proxy_vxi, proxy_cur, mask);
24544 +       if (IS_ERR(proxy_new)) {
24545 +               ret = PTR_ERR(proxy_new);
24546 +               goto out_put_fs;
24547 +       }
24548 +
24549 +       fs_new = xchg(&vxi->vx_fs[index], fs_new);
24550 +       proxy_new = xchg(&vxi->vx_nsproxy[index], proxy_new);
24551 +       vxi->vx_nsmask[index] |= mask;
24552 +       ret = 0;
24553 +
24554 +       if (proxy_new)
24555 +               put_nsproxy(proxy_new);
24556 +out_put_fs:
24557 +       if (fs_new)
24558 +               put_fs_struct(fs_new);
24559 +out_put:
24560 +       if (proxy_cur)
24561 +               put_nsproxy(proxy_cur);
24562 +       if (fs_cur)
24563 +               put_fs_struct(fs_cur);
24564 +       return ret;
24565 +}
24566 +
24567 +
24568 +int vc_enter_space_v1(struct vx_info *vxi, void __user *data)
24569 +{
24570 +       struct vcmd_space_mask_v1 vc_data = { .mask = 0 };
24571 +
24572 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
24573 +               return -EFAULT;
24574 +
24575 +       return vx_enter_space(vxi, vc_data.mask, 0);
24576 +}
24577 +
24578 +int vc_enter_space(struct vx_info *vxi, void __user *data)
24579 +{
24580 +       struct vcmd_space_mask_v2 vc_data = { .mask = 0 };
24581 +
24582 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
24583 +               return -EFAULT;
24584 +
24585 +       if (vc_data.index >= VX_SPACES)
24586 +               return -EINVAL;
24587 +
24588 +       return vx_enter_space(vxi, vc_data.mask, vc_data.index);
24589 +}
24590 +
24591 +int vc_set_space_v1(struct vx_info *vxi, void __user *data)
24592 +{
24593 +       struct vcmd_space_mask_v1 vc_data = { .mask = 0 };
24594 +
24595 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
24596 +               return -EFAULT;
24597 +
24598 +       return vx_set_space(vxi, vc_data.mask, 0);
24599 +}
24600 +
24601 +int vc_set_space(struct vx_info *vxi, void __user *data)
24602 +{
24603 +       struct vcmd_space_mask_v2 vc_data = { .mask = 0 };
24604 +
24605 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
24606 +               return -EFAULT;
24607 +
24608 +       if (vc_data.index >= VX_SPACES)
24609 +               return -EINVAL;
24610 +
24611 +       return vx_set_space(vxi, vc_data.mask, vc_data.index);
24612 +}
24613 +
24614 +int vc_get_space_mask(void __user *data, int type)
24615 +{
24616 +       const struct vcmd_space_mask_v1 *mask;
24617 +
24618 +       if (type == 0)
24619 +               mask = &space_mask_v0;
24620 +       else if (type == 1)
24621 +               mask = &space_mask;
24622 +       else
24623 +               mask = &default_space_mask;
24624 +
24625 +       vxdprintk(VXD_CBIT(space, 10),
24626 +               "vc_get_space_mask(%d) = %08llx", type, mask->mask);
24627 +
24628 +       if (copy_to_user(data, mask, sizeof(*mask)))
24629 +               return -EFAULT;
24630 +       return 0;
24631 +}
24632 +
24633 diff -NurpP --minimal linux-2.6.29/kernel/vserver/switch.c linux-2.6.29-vs2.3.0.36.9-pre2/kernel/vserver/switch.c
24634 --- linux-2.6.29/kernel/vserver/switch.c        1970-01-01 01:00:00.000000000 +0100
24635 +++ linux-2.6.29-vs2.3.0.36.9-pre2/kernel/vserver/switch.c      2009-03-24 14:59:18.000000000 +0100
24636 @@ -0,0 +1,543 @@
24637 +/*
24638 + *  linux/kernel/vserver/switch.c
24639 + *
24640 + *  Virtual Server: Syscall Switch
24641 + *
24642 + *  Copyright (C) 2003-2007  Herbert Pötzl
24643 + *
24644 + *  V0.01  syscall switch
24645 + *  V0.02  added signal to context
24646 + *  V0.03  added rlimit functions
24647 + *  V0.04  added iattr, task/xid functions
24648 + *  V0.05  added debug/history stuff
24649 + *  V0.06  added compat32 layer
24650 + *  V0.07  vcmd args and perms
24651 + *  V0.08  added status commands
24652 + *  V0.09  added tag commands
24653 + *  V0.10  added oom bias
24654 + *  V0.11  added device commands
24655 + *
24656 + */
24657 +
24658 +#include <linux/vs_context.h>
24659 +#include <linux/vs_network.h>
24660 +#include <linux/vserver/switch.h>
24661 +
24662 +#include "vci_config.h"
24663 +
24664 +
24665 +static inline
24666 +int vc_get_version(uint32_t id)
24667 +{
24668 +       return VCI_VERSION;
24669 +}
24670 +
24671 +static inline
24672 +int vc_get_vci(uint32_t id)
24673 +{
24674 +       return vci_kernel_config();
24675 +}
24676 +
24677 +#include <linux/vserver/context_cmd.h>
24678 +#include <linux/vserver/cvirt_cmd.h>
24679 +#include <linux/vserver/cacct_cmd.h>
24680 +#include <linux/vserver/limit_cmd.h>
24681 +#include <linux/vserver/network_cmd.h>
24682 +#include <linux/vserver/sched_cmd.h>
24683 +#include <linux/vserver/debug_cmd.h>
24684 +#include <linux/vserver/inode_cmd.h>
24685 +#include <linux/vserver/dlimit_cmd.h>
24686 +#include <linux/vserver/signal_cmd.h>
24687 +#include <linux/vserver/space_cmd.h>
24688 +#include <linux/vserver/tag_cmd.h>
24689 +#include <linux/vserver/device_cmd.h>
24690 +
24691 +#include <linux/vserver/inode.h>
24692 +#include <linux/vserver/dlimit.h>
24693 +
24694 +
24695 +#ifdef CONFIG_COMPAT
24696 +#define __COMPAT(name, id, data, compat)       \
24697 +       (compat) ? name ## _x32(id, data) : name(id, data)
24698 +#define __COMPAT_NO_ID(name, data, compat)     \
24699 +       (compat) ? name ## _x32(data) : name(data)
24700 +#else
24701 +#define __COMPAT(name, id, data, compat)       \
24702 +       name(id, data)
24703 +#define __COMPAT_NO_ID(name, data, compat)     \
24704 +       name(data)
24705 +#endif
24706 +
24707 +
24708 +static inline
24709 +long do_vcmd(uint32_t cmd, uint32_t id,
24710 +       struct vx_info *vxi, struct nx_info *nxi,
24711 +       void __user *data, int compat)
24712 +{
24713 +       switch (cmd) {
24714 +
24715 +       case VCMD_get_version:
24716 +               return vc_get_version(id);
24717 +       case VCMD_get_vci:
24718 +               return vc_get_vci(id);
24719 +
24720 +       case VCMD_task_xid:
24721 +               return vc_task_xid(id);
24722 +       case VCMD_vx_info:
24723 +               return vc_vx_info(vxi, data);
24724 +
24725 +       case VCMD_task_nid:
24726 +               return vc_task_nid(id);
24727 +       case VCMD_nx_info:
24728 +               return vc_nx_info(nxi, data);
24729 +
24730 +       case VCMD_task_tag:
24731 +               return vc_task_tag(id);
24732 +
24733 +       case VCMD_set_space_v1:
24734 +               return vc_set_space_v1(vxi, data);
24735 +       /* this is version 2 */
24736 +       case VCMD_set_space:
24737 +               return vc_set_space(vxi, data);
24738 +
24739 +       case VCMD_get_space_mask_v0:
24740 +               return vc_get_space_mask(data, 0);
24741 +       /* this is version 1 */
24742 +       case VCMD_get_space_mask:
24743 +               return vc_get_space_mask(data, 1);
24744 +
24745 +       case VCMD_get_space_default:
24746 +               return vc_get_space_mask(data, -1);
24747 +
24748 +#ifdef CONFIG_IA32_EMULATION
24749 +       case VCMD_get_rlimit:
24750 +               return __COMPAT(vc_get_rlimit, vxi, data, compat);
24751 +       case VCMD_set_rlimit:
24752 +               return __COMPAT(vc_set_rlimit, vxi, data, compat);
24753 +#else
24754 +       case VCMD_get_rlimit:
24755 +               return vc_get_rlimit(vxi, data);
24756 +       case VCMD_set_rlimit:
24757 +               return vc_set_rlimit(vxi, data);
24758 +#endif
24759 +       case VCMD_get_rlimit_mask:
24760 +               return vc_get_rlimit_mask(id, data);
24761 +       case VCMD_reset_minmax:
24762 +               return vc_reset_minmax(vxi, data);
24763 +
24764 +       case VCMD_get_vhi_name:
24765 +               return vc_get_vhi_name(vxi, data);
24766 +       case VCMD_set_vhi_name:
24767 +               return vc_set_vhi_name(vxi, data);
24768 +
24769 +       case VCMD_ctx_stat:
24770 +               return vc_ctx_stat(vxi, data);
24771 +       case VCMD_virt_stat:
24772 +               return vc_virt_stat(vxi, data);
24773 +       case VCMD_sock_stat:
24774 +               return vc_sock_stat(vxi, data);
24775 +       case VCMD_rlimit_stat:
24776 +               return vc_rlimit_stat(vxi, data);
24777 +
24778 +       case VCMD_set_cflags:
24779 +               return vc_set_cflags(vxi, data);
24780 +       case VCMD_get_cflags:
24781 +               return vc_get_cflags(vxi, data);
24782 +
24783 +       /* this is version 1 */
24784 +       case VCMD_set_ccaps:
24785 +               return vc_set_ccaps(vxi, data);
24786 +       /* this is version 1 */
24787 +       case VCMD_get_ccaps:
24788 +               return vc_get_ccaps(vxi, data);
24789 +       case VCMD_set_bcaps:
24790 +               return vc_set_bcaps(vxi, data);
24791 +       case VCMD_get_bcaps:
24792 +               return vc_get_bcaps(vxi, data);
24793 +
24794 +       case VCMD_set_badness:
24795 +               return vc_set_badness(vxi, data);
24796 +       case VCMD_get_badness:
24797 +               return vc_get_badness(vxi, data);
24798 +
24799 +       case VCMD_set_nflags:
24800 +               return vc_set_nflags(nxi, data);
24801 +       case VCMD_get_nflags:
24802 +               return vc_get_nflags(nxi, data);
24803 +
24804 +       case VCMD_set_ncaps:
24805 +               return vc_set_ncaps(nxi, data);
24806 +       case VCMD_get_ncaps:
24807 +               return vc_get_ncaps(nxi, data);
24808 +
24809 +       case VCMD_set_sched_v4:
24810 +               return vc_set_sched_v4(vxi, data);
24811 +       /* this is version 5 */
24812 +       case VCMD_set_sched:
24813 +               return vc_set_sched(vxi, data);
24814 +       case VCMD_get_sched:
24815 +               return vc_get_sched(vxi, data);
24816 +       case VCMD_sched_info:
24817 +               return vc_sched_info(vxi, data);
24818 +
24819 +       case VCMD_add_dlimit:
24820 +               return __COMPAT(vc_add_dlimit, id, data, compat);
24821 +       case VCMD_rem_dlimit:
24822 +               return __COMPAT(vc_rem_dlimit, id, data, compat);
24823 +       case VCMD_set_dlimit:
24824 +               return __COMPAT(vc_set_dlimit, id, data, compat);
24825 +       case VCMD_get_dlimit:
24826 +               return __COMPAT(vc_get_dlimit, id, data, compat);
24827 +
24828 +       case VCMD_ctx_kill:
24829 +               return vc_ctx_kill(vxi, data);
24830 +
24831 +       case VCMD_wait_exit:
24832 +               return vc_wait_exit(vxi, data);
24833 +
24834 +       case VCMD_get_iattr:
24835 +               return __COMPAT_NO_ID(vc_get_iattr, data, compat);
24836 +       case VCMD_set_iattr:
24837 +               return __COMPAT_NO_ID(vc_set_iattr, data, compat);
24838 +
24839 +       case VCMD_fget_iattr:
24840 +               return vc_fget_iattr(id, data);
24841 +       case VCMD_fset_iattr:
24842 +               return vc_fset_iattr(id, data);
24843 +
24844 +       case VCMD_enter_space_v0:
24845 +               return vc_enter_space_v1(vxi, NULL);
24846 +       case VCMD_enter_space_v1:
24847 +               return vc_enter_space_v1(vxi, data);
24848 +       /* this is version 2 */
24849 +       case VCMD_enter_space:
24850 +               return vc_enter_space(vxi, data);
24851 +
24852 +       case VCMD_ctx_create_v0:
24853 +               return vc_ctx_create(id, NULL);
24854 +       case VCMD_ctx_create:
24855 +               return vc_ctx_create(id, data);
24856 +       case VCMD_ctx_migrate_v0:
24857 +               return vc_ctx_migrate(vxi, NULL);
24858 +       case VCMD_ctx_migrate:
24859 +               return vc_ctx_migrate(vxi, data);
24860 +
24861 +       case VCMD_net_create_v0:
24862 +               return vc_net_create(id, NULL);
24863 +       case VCMD_net_create:
24864 +               return vc_net_create(id, data);
24865 +       case VCMD_net_migrate:
24866 +               return vc_net_migrate(nxi, data);
24867 +
24868 +       case VCMD_tag_migrate:
24869 +               return vc_tag_migrate(id);
24870 +
24871 +       case VCMD_net_add:
24872 +               return vc_net_add(nxi, data);
24873 +       case VCMD_net_remove:
24874 +               return vc_net_remove(nxi, data);
24875 +
24876 +       case VCMD_net_add_ipv4:
24877 +               return vc_net_add_ipv4(nxi, data);
24878 +       case VCMD_net_remove_ipv4:
24879 +               return vc_net_remove_ipv4(nxi, data);
24880 +#ifdef CONFIG_IPV6
24881 +       case VCMD_net_add_ipv6:
24882 +               return vc_net_add_ipv6(nxi, data);
24883 +       case VCMD_net_remove_ipv6:
24884 +               return vc_net_remove_ipv6(nxi, data);
24885 +#endif
24886 +/*     case VCMD_add_match_ipv4:
24887 +               return vc_add_match_ipv4(nxi, data);
24888 +       case VCMD_get_match_ipv4:
24889 +               return vc_get_match_ipv4(nxi, data);
24890 +#ifdef CONFIG_IPV6
24891 +       case VCMD_add_match_ipv6:
24892 +               return vc_add_match_ipv6(nxi, data);
24893 +       case VCMD_get_match_ipv6:
24894 +               return vc_get_match_ipv6(nxi, data);
24895 +#endif */
24896 +
24897 +#ifdef CONFIG_VSERVER_DEVICE
24898 +       case VCMD_set_mapping:
24899 +               return __COMPAT(vc_set_mapping, vxi, data, compat);
24900 +       case VCMD_unset_mapping:
24901 +               return __COMPAT(vc_unset_mapping, vxi, data, compat);
24902 +#endif
24903 +#ifdef CONFIG_VSERVER_HISTORY
24904 +       case VCMD_dump_history:
24905 +               return vc_dump_history(id);
24906 +       case VCMD_read_history:
24907 +               return __COMPAT(vc_read_history, id, data, compat);
24908 +#endif
24909 +#ifdef CONFIG_VSERVER_MONITOR
24910 +       case VCMD_read_monitor:
24911 +               return __COMPAT(vc_read_monitor, id, data, compat);
24912 +#endif
24913 +       default:
24914 +               vxwprintk_task(1, "unimplemented VCMD_%02d_%d[%d]",
24915 +                       VC_CATEGORY(cmd), VC_COMMAND(cmd), VC_VERSION(cmd));
24916 +       }
24917 +       return -ENOSYS;
24918 +}
24919 +
24920 +
24921 +#define        __VCMD(vcmd, _perm, _args, _flags)              \
24922 +       case VCMD_ ## vcmd: perm = _perm;               \
24923 +               args = _args; flags = _flags; break
24924 +
24925 +
24926 +#define VCA_NONE       0x00
24927 +#define VCA_VXI                0x01
24928 +#define VCA_NXI                0x02
24929 +
24930 +#define VCF_NONE       0x00
24931 +#define VCF_INFO       0x01
24932 +#define VCF_ADMIN      0x02
24933 +#define VCF_ARES       0x06    /* includes admin */
24934 +#define VCF_SETUP      0x08
24935 +
24936 +#define VCF_ZIDOK      0x10    /* zero id okay */
24937 +
24938 +
24939 +static inline
24940 +long do_vserver(uint32_t cmd, uint32_t id, void __user *data, int compat)
24941 +{
24942 +       long ret;
24943 +       int permit = -1, state = 0;
24944 +       int perm = -1, args = 0, flags = 0;
24945 +       struct vx_info *vxi = NULL;
24946 +       struct nx_info *nxi = NULL;
24947 +
24948 +       switch (cmd) {
24949 +       /* unpriviledged commands */
24950 +       __VCMD(get_version,      0, VCA_NONE,   0);
24951 +       __VCMD(get_vci,          0, VCA_NONE,   0);
24952 +       __VCMD(get_rlimit_mask,  0, VCA_NONE,   0);
24953 +       __VCMD(get_space_mask_v0,0, VCA_NONE,   0);
24954 +       __VCMD(get_space_mask,   0, VCA_NONE,   0);
24955 +       __VCMD(get_space_default,0, VCA_NONE,   0);
24956 +
24957 +       /* info commands */
24958 +       __VCMD(task_xid,         2, VCA_NONE,   0);
24959 +       __VCMD(reset_minmax,     2, VCA_VXI,    0);
24960 +       __VCMD(vx_info,          3, VCA_VXI,    VCF_INFO);
24961 +       __VCMD(get_bcaps,        3, VCA_VXI,    VCF_INFO);
24962 +       __VCMD(get_ccaps,        3, VCA_VXI,    VCF_INFO);
24963 +       __VCMD(get_cflags,       3, VCA_VXI,    VCF_INFO);
24964 +       __VCMD(get_badness,      3, VCA_VXI,    VCF_INFO);
24965 +       __VCMD(get_vhi_name,     3, VCA_VXI,    VCF_INFO);
24966 +       __VCMD(get_rlimit,       3, VCA_VXI,    VCF_INFO);
24967 +
24968 +       __VCMD(ctx_stat,         3, VCA_VXI,    VCF_INFO);
24969 +       __VCMD(virt_stat,        3, VCA_VXI,    VCF_INFO);
24970 +       __VCMD(sock_stat,        3, VCA_VXI,    VCF_INFO);
24971 +       __VCMD(rlimit_stat,      3, VCA_VXI,    VCF_INFO);
24972 +
24973 +       __VCMD(task_nid,         2, VCA_NONE,   0);
24974 +       __VCMD(nx_info,          3, VCA_NXI,    VCF_INFO);
24975 +       __VCMD(get_ncaps,        3, VCA_NXI,    VCF_INFO);
24976 +       __VCMD(get_nflags,       3, VCA_NXI,    VCF_INFO);
24977 +
24978 +       __VCMD(task_tag,         2, VCA_NONE,   0);
24979 +
24980 +       __VCMD(get_iattr,        2, VCA_NONE,   0);
24981 +       __VCMD(fget_iattr,       2, VCA_NONE,   0);
24982 +       __VCMD(get_dlimit,       3, VCA_NONE,   VCF_INFO);
24983 +       __VCMD(get_sched,        3, VCA_VXI,    VCF_INFO);
24984 +       __VCMD(sched_info,       3, VCA_VXI,    VCF_INFO | VCF_ZIDOK);
24985 +
24986 +       /* lower admin commands */
24987 +       __VCMD(wait_exit,        4, VCA_VXI,    VCF_INFO);
24988 +       __VCMD(ctx_create_v0,    5, VCA_NONE,   0);
24989 +       __VCMD(ctx_create,       5, VCA_NONE,   0);
24990 +       __VCMD(ctx_migrate_v0,   5, VCA_VXI,    VCF_ADMIN);
24991 +       __VCMD(ctx_migrate,      5, VCA_VXI,    VCF_ADMIN);
24992 +       __VCMD(enter_space_v0,   5, VCA_VXI,    VCF_ADMIN);
24993 +       __VCMD(enter_space_v1,   5, VCA_VXI,    VCF_ADMIN);
24994 +       __VCMD(enter_space,      5, VCA_VXI,    VCF_ADMIN);
24995 +
24996 +       __VCMD(net_create_v0,    5, VCA_NONE,   0);
24997 +       __VCMD(net_create,       5, VCA_NONE,   0);
24998 +       __VCMD(net_migrate,      5, VCA_NXI,    VCF_ADMIN);
24999 +
25000 +       __VCMD(tag_migrate,      5, VCA_NONE,   VCF_ADMIN);
25001 +
25002 +       /* higher admin commands */
25003 +       __VCMD(ctx_kill,         6, VCA_VXI,    VCF_ARES);
25004 +       __VCMD(set_space_v1,     7, VCA_VXI,    VCF_ARES | VCF_SETUP);
25005 +       __VCMD(set_space,        7, VCA_VXI,    VCF_ARES | VCF_SETUP);
25006 +
25007 +       __VCMD(set_ccaps,        7, VCA_VXI,    VCF_ARES | VCF_SETUP);
25008 +       __VCMD(set_bcaps,        7, VCA_VXI,    VCF_ARES | VCF_SETUP);
25009 +       __VCMD(set_cflags,       7, VCA_VXI,    VCF_ARES | VCF_SETUP);
25010 +       __VCMD(set_badness,      7, VCA_VXI,    VCF_ARES | VCF_SETUP);
25011 +
25012 +       __VCMD(set_vhi_name,     7, VCA_VXI,    VCF_ARES | VCF_SETUP);
25013 +       __VCMD(set_rlimit,       7, VCA_VXI,    VCF_ARES | VCF_SETUP);
25014 +       __VCMD(set_sched,        7, VCA_VXI,    VCF_ARES | VCF_SETUP);
25015 +       __VCMD(set_sched_v4,     7, VCA_VXI,    VCF_ARES | VCF_SETUP);
25016 +
25017 +       __VCMD(set_ncaps,        7, VCA_NXI,    VCF_ARES | VCF_SETUP);
25018 +       __VCMD(set_nflags,       7, VCA_NXI,    VCF_ARES | VCF_SETUP);
25019 +       __VCMD(net_add,          8, VCA_NXI,    VCF_ARES | VCF_SETUP);
25020 +       __VCMD(net_remove,       8, VCA_NXI,    VCF_ARES | VCF_SETUP);
25021 +       __VCMD(net_add_ipv4,     8, VCA_NXI,    VCF_ARES | VCF_SETUP);
25022 +       __VCMD(net_remove_ipv4,  8, VCA_NXI,    VCF_ARES | VCF_SETUP);
25023 +#ifdef CONFIG_IPV6
25024 +       __VCMD(net_add_ipv6,     8, VCA_NXI,    VCF_ARES | VCF_SETUP);
25025 +       __VCMD(net_remove_ipv6,  8, VCA_NXI,    VCF_ARES | VCF_SETUP);
25026 +#endif
25027 +       __VCMD(set_iattr,        7, VCA_NONE,   0);
25028 +       __VCMD(fset_iattr,       7, VCA_NONE,   0);
25029 +       __VCMD(set_dlimit,       7, VCA_NONE,   VCF_ARES);
25030 +       __VCMD(add_dlimit,       8, VCA_NONE,   VCF_ARES);
25031 +       __VCMD(rem_dlimit,       8, VCA_NONE,   VCF_ARES);
25032 +
25033 +#ifdef CONFIG_VSERVER_DEVICE
25034 +       __VCMD(set_mapping,      8, VCA_VXI,    VCF_ARES|VCF_ZIDOK);
25035 +       __VCMD(unset_mapping,    8, VCA_VXI,    VCF_ARES|VCF_ZIDOK);
25036 +#endif
25037 +       /* debug level admin commands */
25038 +#ifdef CONFIG_VSERVER_HISTORY
25039 +       __VCMD(dump_history,     9, VCA_NONE,   0);
25040 +       __VCMD(read_history,     9, VCA_NONE,   0);
25041 +#endif
25042 +#ifdef CONFIG_VSERVER_MONITOR
25043 +       __VCMD(read_monitor,     9, VCA_NONE,   0);
25044 +#endif
25045 +
25046 +       default:
25047 +               perm = -1;
25048 +       }
25049 +
25050 +       vxdprintk(VXD_CBIT(switch, 0),
25051 +               "vc: VCMD_%02d_%d[%d], %d,%p [%d,%d,%x,%x]",
25052 +               VC_CATEGORY(cmd), VC_COMMAND(cmd),
25053 +               VC_VERSION(cmd), id, data, compat,
25054 +               perm, args, flags);
25055 +
25056 +       ret = -ENOSYS;
25057 +       if (perm < 0)
25058 +               goto out;
25059 +
25060 +       state = 1;
25061 +       if (!capable(CAP_CONTEXT))
25062 +               goto out;
25063 +
25064 +       state = 2;
25065 +       /* moved here from the individual commands */
25066 +       ret = -EPERM;
25067 +       if ((perm > 1) && !capable(CAP_SYS_ADMIN))
25068 +               goto out;
25069 +
25070 +       state = 3;
25071 +       /* vcmd involves resource management  */
25072 +       ret = -EPERM;
25073 +       if ((flags & VCF_ARES) && !capable(CAP_SYS_RESOURCE))
25074 +               goto out;
25075 +
25076 +       state = 4;
25077 +       /* various legacy exceptions */
25078 +       switch (cmd) {
25079 +       /* will go away when spectator is a cap */
25080 +       case VCMD_ctx_migrate_v0:
25081 +       case VCMD_ctx_migrate:
25082 +               if (id == 1) {
25083 +                       current->xid = 1;
25084 +                       ret = 1;
25085 +                       goto out;
25086 +               }
25087 +               break;
25088 +
25089 +       /* will go away when spectator is a cap */
25090 +       case VCMD_net_migrate:
25091 +               if (id == 1) {
25092 +                       current->nid = 1;
25093 +                       ret = 1;
25094 +                       goto out;
25095 +               }
25096 +               break;
25097 +       }
25098 +
25099 +       /* vcmds are fine by default */
25100 +       permit = 1;
25101 +
25102 +       /* admin type vcmds require admin ... */
25103 +       if (flags & VCF_ADMIN)
25104 +               permit = vx_check(0, VS_ADMIN) ? 1 : 0;
25105 +
25106 +       /* ... but setup type vcmds override that */
25107 +       if (!permit && (flags & VCF_SETUP))
25108 +               permit = vx_flags(VXF_STATE_SETUP, 0) ? 2 : 0;
25109 +
25110 +       state = 5;
25111 +       ret = -EPERM;
25112 +       if (!permit)
25113 +               goto out;
25114 +
25115 +       state = 6;
25116 +       if (!id && (flags & VCF_ZIDOK))
25117 +               goto skip_id;
25118 +
25119 +       ret = -ESRCH;
25120 +       if (args & VCA_VXI) {
25121 +               vxi = lookup_vx_info(id);
25122 +               if (!vxi)
25123 +                       goto out;
25124 +
25125 +               if ((flags & VCF_ADMIN) &&
25126 +                       /* special case kill for shutdown */
25127 +                       (cmd != VCMD_ctx_kill) &&
25128 +                       /* can context be administrated? */
25129 +                       !vx_info_flags(vxi, VXF_STATE_ADMIN, 0)) {
25130 +                       ret = -EACCES;
25131 +                       goto out_vxi;
25132 +               }
25133 +       }
25134 +       state = 7;
25135 +       if (args & VCA_NXI) {
25136 +               nxi = lookup_nx_info(id);
25137 +               if (!nxi)
25138 +                       goto out_vxi;
25139 +
25140 +               if ((flags & VCF_ADMIN) &&
25141 +                       /* can context be administrated? */
25142 +                       !nx_info_flags(nxi, NXF_STATE_ADMIN, 0)) {
25143 +                       ret = -EACCES;
25144 +                       goto out_nxi;
25145 +               }
25146 +       }
25147 +skip_id:
25148 +       state = 8;
25149 +       ret = do_vcmd(cmd, id, vxi, nxi, data, compat);
25150 +
25151 +out_nxi:
25152 +       if ((args & VCA_NXI) && nxi)
25153 +               put_nx_info(nxi);
25154 +out_vxi:
25155 +       if ((args & VCA_VXI) && vxi)
25156 +               put_vx_info(vxi);
25157 +out:
25158 +       vxdprintk(VXD_CBIT(switch, 1),
25159 +               "vc: VCMD_%02d_%d[%d] = %08lx(%ld) [%d,%d]",
25160 +               VC_CATEGORY(cmd), VC_COMMAND(cmd),
25161 +               VC_VERSION(cmd), ret, ret, state, permit);
25162 +       return ret;
25163 +}
25164 +
25165 +asmlinkage long
25166 +sys_vserver(uint32_t cmd, uint32_t id, void __user *data)
25167 +{
25168 +       return do_vserver(cmd, id, data, 0);
25169 +}
25170 +
25171 +#ifdef CONFIG_COMPAT
25172 +
25173 +asmlinkage long
25174 +sys32_vserver(uint32_t cmd, uint32_t id, void __user *data)
25175 +{
25176 +       return do_vserver(cmd, id, data, 1);
25177 +}
25178 +
25179 +#endif /* CONFIG_COMPAT */
25180 diff -NurpP --minimal linux-2.6.29/kernel/vserver/sysctl.c linux-2.6.29-vs2.3.0.36.9-pre2/kernel/vserver/sysctl.c
25181 --- linux-2.6.29/kernel/vserver/sysctl.c        1970-01-01 01:00:00.000000000 +0100
25182 +++ linux-2.6.29-vs2.3.0.36.9-pre2/kernel/vserver/sysctl.c      2009-02-22 22:54:26.000000000 +0100
25183 @@ -0,0 +1,244 @@
25184 +/*
25185 + *  kernel/vserver/sysctl.c
25186 + *
25187 + *  Virtual Context Support
25188 + *
25189 + *  Copyright (C) 2004-2007  Herbert Pötzl
25190 + *
25191 + *  V0.01  basic structure
25192 + *
25193 + */
25194 +
25195 +#include <linux/module.h>
25196 +#include <linux/ctype.h>
25197 +#include <linux/sysctl.h>
25198 +#include <linux/parser.h>
25199 +#include <asm/uaccess.h>
25200 +
25201 +
25202 +enum {
25203 +       CTL_DEBUG_ERROR         = 0,
25204 +       CTL_DEBUG_SWITCH        = 1,
25205 +       CTL_DEBUG_XID,
25206 +       CTL_DEBUG_NID,
25207 +       CTL_DEBUG_TAG,
25208 +       CTL_DEBUG_NET,
25209 +       CTL_DEBUG_LIMIT,
25210 +       CTL_DEBUG_CRES,
25211 +       CTL_DEBUG_DLIM,
25212 +       CTL_DEBUG_QUOTA,
25213 +       CTL_DEBUG_CVIRT,
25214 +       CTL_DEBUG_SPACE,
25215 +       CTL_DEBUG_MISC,
25216 +};
25217 +
25218 +
25219 +unsigned int vx_debug_switch   = 0;
25220 +unsigned int vx_debug_xid      = 0;
25221 +unsigned int vx_debug_nid      = 0;
25222 +unsigned int vx_debug_tag      = 0;
25223 +unsigned int vx_debug_net      = 0;
25224 +unsigned int vx_debug_limit    = 0;
25225 +unsigned int vx_debug_cres     = 0;
25226 +unsigned int vx_debug_dlim     = 0;
25227 +unsigned int vx_debug_quota    = 0;
25228 +unsigned int vx_debug_cvirt    = 0;
25229 +unsigned int vx_debug_space    = 0;
25230 +unsigned int vx_debug_misc     = 0;
25231 +
25232 +
25233 +static struct ctl_table_header *vserver_table_header;
25234 +static ctl_table vserver_root_table[];
25235 +
25236 +
25237 +void vserver_register_sysctl(void)
25238 +{
25239 +       if (!vserver_table_header) {
25240 +               vserver_table_header = register_sysctl_table(vserver_root_table);
25241 +       }
25242 +
25243 +}
25244 +
25245 +void vserver_unregister_sysctl(void)
25246 +{
25247 +       if (vserver_table_header) {
25248 +               unregister_sysctl_table(vserver_table_header);
25249 +               vserver_table_header = NULL;
25250 +       }
25251 +}
25252 +
25253 +
25254 +static int proc_dodebug(ctl_table *table, int write,
25255 +       struct file *filp, void __user *buffer, size_t *lenp, loff_t *ppos)
25256 +{
25257 +       char            tmpbuf[20], *p, c;
25258 +       unsigned int    value;
25259 +       size_t          left, len;
25260 +
25261 +       if ((*ppos && !write) || !*lenp) {
25262 +               *lenp = 0;
25263 +               return 0;
25264 +       }
25265 +
25266 +       left = *lenp;
25267 +
25268 +       if (write) {
25269 +               if (!access_ok(VERIFY_READ, buffer, left))
25270 +                       return -EFAULT;
25271 +               p = (char *)buffer;
25272 +               while (left && __get_user(c, p) >= 0 && isspace(c))
25273 +                       left--, p++;
25274 +               if (!left)
25275 +                       goto done;
25276 +
25277 +               if (left > sizeof(tmpbuf) - 1)
25278 +                       return -EINVAL;
25279 +               if (copy_from_user(tmpbuf, p, left))
25280 +                       return -EFAULT;
25281 +               tmpbuf[left] = '\0';
25282 +
25283 +               for (p = tmpbuf, value = 0; '0' <= *p && *p <= '9'; p++, left--)
25284 +                       value = 10 * value + (*p - '0');
25285 +               if (*p && !isspace(*p))
25286 +                       return -EINVAL;
25287 +               while (left && isspace(*p))
25288 +                       left--, p++;
25289 +               *(unsigned int *)table->data = value;
25290 +       } else {
25291 +               if (!access_ok(VERIFY_WRITE, buffer, left))
25292 +                       return -EFAULT;
25293 +               len = sprintf(tmpbuf, "%d", *(unsigned int *)table->data);
25294 +               if (len > left)
25295 +                       len = left;
25296 +               if (__copy_to_user(buffer, tmpbuf, len))
25297 +                       return -EFAULT;
25298 +               if ((left -= len) > 0) {
25299 +                       if (put_user('\n', (char *)buffer + len))
25300 +                               return -EFAULT;
25301 +                       left--;
25302 +               }
25303 +       }
25304 +
25305 +done:
25306 +       *lenp -= left;
25307 +       *ppos += *lenp;
25308 +       return 0;
25309 +}
25310 +
25311 +static int zero;
25312 +
25313 +#define        CTL_ENTRY(ctl, name)                            \
25314 +       {                                               \
25315 +               .ctl_name       = ctl,                  \
25316 +               .procname       = #name,                \
25317 +               .data           = &vx_ ## name,         \
25318 +               .maxlen         = sizeof(int),          \
25319 +               .mode           = 0644,                 \
25320 +               .proc_handler   = &proc_dodebug,        \
25321 +               .strategy       = &sysctl_intvec,       \
25322 +               .extra1         = &zero,                \
25323 +       }
25324 +
25325 +static ctl_table vserver_debug_table[] = {
25326 +       CTL_ENTRY(CTL_DEBUG_SWITCH,     debug_switch),
25327 +       CTL_ENTRY(CTL_DEBUG_XID,        debug_xid),
25328 +       CTL_ENTRY(CTL_DEBUG_NID,        debug_nid),
25329 +       CTL_ENTRY(CTL_DEBUG_TAG,        debug_tag),
25330 +       CTL_ENTRY(CTL_DEBUG_NET,        debug_net),
25331 +       CTL_ENTRY(CTL_DEBUG_LIMIT,      debug_limit),
25332 +       CTL_ENTRY(CTL_DEBUG_CRES,       debug_cres),
25333 +       CTL_ENTRY(CTL_DEBUG_DLIM,       debug_dlim),
25334 +       CTL_ENTRY(CTL_DEBUG_QUOTA,      debug_quota),
25335 +       CTL_ENTRY(CTL_DEBUG_CVIRT,      debug_cvirt),
25336 +       CTL_ENTRY(CTL_DEBUG_SPACE,      debug_space),
25337 +       CTL_ENTRY(CTL_DEBUG_MISC,       debug_misc),
25338 +       { .ctl_name = 0 }
25339 +};
25340 +
25341 +static ctl_table vserver_root_table[] = {
25342 +       {
25343 +               .ctl_name       = CTL_VSERVER,
25344 +               .procname       = "vserver",
25345 +               .mode           = 0555,
25346 +               .child          = vserver_debug_table
25347 +       },
25348 +       { .ctl_name = 0 }
25349 +};
25350 +
25351 +
25352 +static match_table_t tokens = {
25353 +       { CTL_DEBUG_SWITCH,     "switch=%x"     },
25354 +       { CTL_DEBUG_XID,        "xid=%x"        },
25355 +       { CTL_DEBUG_NID,        "nid=%x"        },
25356 +       { CTL_DEBUG_TAG,        "tag=%x"        },
25357 +       { CTL_DEBUG_NET,        "net=%x"        },
25358 +       { CTL_DEBUG_LIMIT,      "limit=%x"      },
25359 +       { CTL_DEBUG_CRES,       "cres=%x"       },
25360 +       { CTL_DEBUG_DLIM,       "dlim=%x"       },
25361 +       { CTL_DEBUG_QUOTA,      "quota=%x"      },
25362 +       { CTL_DEBUG_CVIRT,      "cvirt=%x"      },
25363 +       { CTL_DEBUG_SPACE,      "space=%x"      },
25364 +       { CTL_DEBUG_MISC,       "misc=%x"       },
25365 +       { CTL_DEBUG_ERROR,      NULL            }
25366 +};
25367 +
25368 +#define        HANDLE_CASE(id, name, val)                              \
25369 +       case CTL_DEBUG_ ## id:                                  \
25370 +               vx_debug_ ## name = val;                        \
25371 +               printk("vs_debug_" #name "=0x%x\n", val);       \
25372 +               break
25373 +
25374 +
25375 +static int __init vs_debug_setup(char *str)
25376 +{
25377 +       char *p;
25378 +       int token;
25379 +
25380 +       printk("vs_debug_setup(%s)\n", str);
25381 +       while ((p = strsep(&str, ",")) != NULL) {
25382 +               substring_t args[MAX_OPT_ARGS];
25383 +               unsigned int value;
25384 +
25385 +               if (!*p)
25386 +                       continue;
25387 +
25388 +               token = match_token(p, tokens, args);
25389 +               value = (token > 0) ? simple_strtoul(args[0].from, NULL, 0) : 0;
25390 +
25391 +               switch (token) {
25392 +               HANDLE_CASE(SWITCH, switch, value);
25393 +               HANDLE_CASE(XID,    xid,    value);
25394 +               HANDLE_CASE(NID,    nid,    value);
25395 +               HANDLE_CASE(TAG,    tag,    value);
25396 +               HANDLE_CASE(NET,    net,    value);
25397 +               HANDLE_CASE(LIMIT,  limit,  value);
25398 +               HANDLE_CASE(CRES,   cres,   value);
25399 +               HANDLE_CASE(DLIM,   dlim,   value);
25400 +               HANDLE_CASE(QUOTA,  quota,  value);
25401 +               HANDLE_CASE(CVIRT,  cvirt,  value);
25402 +               HANDLE_CASE(SPACE,  space,  value);
25403 +               HANDLE_CASE(MISC,   misc,   value);
25404 +               default:
25405 +                       return -EINVAL;
25406 +                       break;
25407 +               }
25408 +       }
25409 +       return 1;
25410 +}
25411 +
25412 +__setup("vsdebug=", vs_debug_setup);
25413 +
25414 +
25415 +
25416 +EXPORT_SYMBOL_GPL(vx_debug_switch);
25417 +EXPORT_SYMBOL_GPL(vx_debug_xid);
25418 +EXPORT_SYMBOL_GPL(vx_debug_nid);
25419 +EXPORT_SYMBOL_GPL(vx_debug_net);
25420 +EXPORT_SYMBOL_GPL(vx_debug_limit);
25421 +EXPORT_SYMBOL_GPL(vx_debug_cres);
25422 +EXPORT_SYMBOL_GPL(vx_debug_dlim);
25423 +EXPORT_SYMBOL_GPL(vx_debug_quota);
25424 +EXPORT_SYMBOL_GPL(vx_debug_cvirt);
25425 +EXPORT_SYMBOL_GPL(vx_debug_space);
25426 +EXPORT_SYMBOL_GPL(vx_debug_misc);
25427 +
25428 diff -NurpP --minimal linux-2.6.29/kernel/vserver/tag.c linux-2.6.29-vs2.3.0.36.9-pre2/kernel/vserver/tag.c
25429 --- linux-2.6.29/kernel/vserver/tag.c   1970-01-01 01:00:00.000000000 +0100
25430 +++ linux-2.6.29-vs2.3.0.36.9-pre2/kernel/vserver/tag.c 2009-02-22 22:54:26.000000000 +0100
25431 @@ -0,0 +1,63 @@
25432 +/*
25433 + *  linux/kernel/vserver/tag.c
25434 + *
25435 + *  Virtual Server: Shallow Tag Space
25436 + *
25437 + *  Copyright (C) 2007  Herbert Pötzl
25438 + *
25439 + *  V0.01  basic implementation
25440 + *
25441 + */
25442 +
25443 +#include <linux/sched.h>
25444 +#include <linux/vserver/debug.h>
25445 +#include <linux/vs_pid.h>
25446 +#include <linux/vs_tag.h>
25447 +
25448 +#include <linux/vserver/tag_cmd.h>
25449 +
25450 +
25451 +int dx_migrate_task(struct task_struct *p, tag_t tag)
25452 +{
25453 +       if (!p)
25454 +               BUG();
25455 +
25456 +       vxdprintk(VXD_CBIT(tag, 5),
25457 +               "dx_migrate_task(%p[#%d],#%d)", p, p->tag, tag);
25458 +
25459 +       task_lock(p);
25460 +       p->tag = tag;
25461 +       task_unlock(p);
25462 +
25463 +       vxdprintk(VXD_CBIT(tag, 5),
25464 +               "moved task %p into [#%d]", p, tag);
25465 +       return 0;
25466 +}
25467 +
25468 +/* vserver syscall commands below here */
25469 +
25470 +/* taks xid and vx_info functions */
25471 +
25472 +
25473 +int vc_task_tag(uint32_t id)
25474 +{
25475 +       tag_t tag;
25476 +
25477 +       if (id) {
25478 +               struct task_struct *tsk;
25479 +               read_lock(&tasklist_lock);
25480 +               tsk = find_task_by_real_pid(id);
25481 +               tag = (tsk) ? tsk->tag : -ESRCH;
25482 +               read_unlock(&tasklist_lock);
25483 +       } else
25484 +               tag = dx_current_tag();
25485 +       return tag;
25486 +}
25487 +
25488 +
25489 +int vc_tag_migrate(uint32_t tag)
25490 +{
25491 +       return dx_migrate_task(current, tag & 0xFFFF);
25492 +}
25493 +
25494 +
25495 diff -NurpP --minimal linux-2.6.29/kernel/vserver/vci_config.h linux-2.6.29-vs2.3.0.36.9-pre2/kernel/vserver/vci_config.h
25496 --- linux-2.6.29/kernel/vserver/vci_config.h    1970-01-01 01:00:00.000000000 +0100
25497 +++ linux-2.6.29-vs2.3.0.36.9-pre2/kernel/vserver/vci_config.h  2009-02-22 22:54:26.000000000 +0100
25498 @@ -0,0 +1,81 @@
25499 +
25500 +/*  interface version */
25501 +
25502 +#define VCI_VERSION            0x00020304
25503 +
25504 +
25505 +enum {
25506 +       VCI_KCBIT_NO_DYNAMIC = 0,
25507 +
25508 +       VCI_KCBIT_PROC_SECURE = 4,
25509 +       VCI_KCBIT_HARDCPU = 5,
25510 +       VCI_KCBIT_IDLELIMIT = 6,
25511 +       VCI_KCBIT_IDLETIME = 7,
25512 +
25513 +       VCI_KCBIT_COWBL = 8,
25514 +       VCI_KCBIT_FULLCOWBL = 9,
25515 +       VCI_KCBIT_SPACES = 10,
25516 +       VCI_KCBIT_NETV2 = 11,
25517 +
25518 +       VCI_KCBIT_DEBUG = 16,
25519 +       VCI_KCBIT_HISTORY = 20,
25520 +       VCI_KCBIT_TAGGED = 24,
25521 +       VCI_KCBIT_PPTAG = 28,
25522 +
25523 +       VCI_KCBIT_MORE = 31,
25524 +};
25525 +
25526 +
25527 +static inline uint32_t vci_kernel_config(void)
25528 +{
25529 +       return
25530 +       (1 << VCI_KCBIT_NO_DYNAMIC) |
25531 +
25532 +       /* configured features */
25533 +#ifdef CONFIG_VSERVER_PROC_SECURE
25534 +       (1 << VCI_KCBIT_PROC_SECURE) |
25535 +#endif
25536 +#ifdef CONFIG_VSERVER_HARDCPU
25537 +       (1 << VCI_KCBIT_HARDCPU) |
25538 +#endif
25539 +#ifdef CONFIG_VSERVER_IDLELIMIT
25540 +       (1 << VCI_KCBIT_IDLELIMIT) |
25541 +#endif
25542 +#ifdef CONFIG_VSERVER_IDLETIME
25543 +       (1 << VCI_KCBIT_IDLETIME) |
25544 +#endif
25545 +#ifdef CONFIG_VSERVER_COWBL
25546 +       (1 << VCI_KCBIT_COWBL) |
25547 +       (1 << VCI_KCBIT_FULLCOWBL) |
25548 +#endif
25549 +       (1 << VCI_KCBIT_SPACES) |
25550 +       (1 << VCI_KCBIT_NETV2) |
25551 +
25552 +       /* debug options */
25553 +#ifdef CONFIG_VSERVER_DEBUG
25554 +       (1 << VCI_KCBIT_DEBUG) |
25555 +#endif
25556 +#ifdef CONFIG_VSERVER_HISTORY
25557 +       (1 << VCI_KCBIT_HISTORY) |
25558 +#endif
25559 +
25560 +       /* inode context tagging */
25561 +#if    defined(CONFIG_TAGGING_NONE)
25562 +       (0 << VCI_KCBIT_TAGGED) |
25563 +#elif  defined(CONFIG_TAGGING_UID16)
25564 +       (1 << VCI_KCBIT_TAGGED) |
25565 +#elif  defined(CONFIG_TAGGING_GID16)
25566 +       (2 << VCI_KCBIT_TAGGED) |
25567 +#elif  defined(CONFIG_TAGGING_ID24)
25568 +       (3 << VCI_KCBIT_TAGGED) |
25569 +#elif  defined(CONFIG_TAGGING_INTERN)
25570 +       (4 << VCI_KCBIT_TAGGED) |
25571 +#elif  defined(CONFIG_TAGGING_RUNTIME)
25572 +       (5 << VCI_KCBIT_TAGGED) |
25573 +#else
25574 +       (7 << VCI_KCBIT_TAGGED) |
25575 +#endif
25576 +       (1 << VCI_KCBIT_PPTAG) |
25577 +       0;
25578 +}
25579 +
25580 diff -NurpP --minimal linux-2.6.29/mm/filemap_xip.c linux-2.6.29-vs2.3.0.36.9-pre2/mm/filemap_xip.c
25581 --- linux-2.6.29/mm/filemap_xip.c       2009-03-24 14:22:45.000000000 +0100
25582 +++ linux-2.6.29-vs2.3.0.36.9-pre2/mm/filemap_xip.c     2009-03-24 14:48:36.000000000 +0100
25583 @@ -17,6 +17,7 @@
25584  #include <linux/sched.h>
25585  #include <linux/seqlock.h>
25586  #include <linux/mutex.h>
25587 +#include <linux/vs_memory.h>
25588  #include <asm/tlbflush.h>
25589  #include <asm/io.h>
25590  
25591 diff -NurpP --minimal linux-2.6.29/mm/fremap.c linux-2.6.29-vs2.3.0.36.9-pre2/mm/fremap.c
25592 --- linux-2.6.29/mm/fremap.c    2009-03-24 14:22:45.000000000 +0100
25593 +++ linux-2.6.29-vs2.3.0.36.9-pre2/mm/fremap.c  2009-03-24 14:48:36.000000000 +0100
25594 @@ -16,6 +16,7 @@
25595  #include <linux/module.h>
25596  #include <linux/syscalls.h>
25597  #include <linux/mmu_notifier.h>
25598 +#include <linux/vs_memory.h>
25599  
25600  #include <asm/mmu_context.h>
25601  #include <asm/cacheflush.h>
25602 diff -NurpP --minimal linux-2.6.29/mm/hugetlb.c linux-2.6.29-vs2.3.0.36.9-pre2/mm/hugetlb.c
25603 --- linux-2.6.29/mm/hugetlb.c   2009-03-24 14:22:45.000000000 +0100
25604 +++ linux-2.6.29-vs2.3.0.36.9-pre2/mm/hugetlb.c 2009-03-24 14:48:36.000000000 +0100
25605 @@ -24,6 +24,7 @@
25606  #include <asm/io.h>
25607  
25608  #include <linux/hugetlb.h>
25609 +#include <linux/vs_memory.h>
25610  #include "internal.h"
25611  
25612  const unsigned long hugetlb_zero = 0, hugetlb_infinity = ~0UL;
25613 diff -NurpP --minimal linux-2.6.29/mm/memory.c linux-2.6.29-vs2.3.0.36.9-pre2/mm/memory.c
25614 --- linux-2.6.29/mm/memory.c    2009-03-24 14:22:45.000000000 +0100
25615 +++ linux-2.6.29-vs2.3.0.36.9-pre2/mm/memory.c  2009-03-24 14:48:36.000000000 +0100
25616 @@ -612,6 +612,9 @@ static int copy_pte_range(struct mm_stru
25617         int progress = 0;
25618         int rss[2];
25619  
25620 +       if (!vx_rss_avail(dst_mm, ((end - addr)/PAGE_SIZE + 1)))
25621 +               return -ENOMEM;
25622 +
25623  again:
25624         rss[1] = rss[0] = 0;
25625         dst_pte = pte_alloc_map_lock(dst_mm, dst_pmd, addr, &dst_ptl);
25626 @@ -2433,6 +2436,11 @@ static int do_swap_page(struct mm_struct
25627                 count_vm_event(PGMAJFAULT);
25628         }
25629  
25630 +       if (!vx_rss_avail(mm, 1)) {
25631 +               ret = VM_FAULT_OOM;
25632 +               goto out;
25633 +       }
25634 +
25635         mark_page_accessed(page);
25636  
25637         lock_page(page);
25638 @@ -2524,6 +2532,8 @@ static int do_anonymous_page(struct mm_s
25639         /* Allocate our own private page. */
25640         pte_unmap(page_table);
25641  
25642 +       if (!vx_rss_avail(mm, 1))
25643 +               goto oom;
25644         if (unlikely(anon_vma_prepare(vma)))
25645                 goto oom;
25646         page = alloc_zeroed_user_highpage_movable(vma, address);
25647 @@ -2791,6 +2801,7 @@ static inline int handle_pte_fault(struc
25648  {
25649         pte_t entry;
25650         spinlock_t *ptl;
25651 +       int ret = 0, type = VXPT_UNKNOWN;
25652  
25653         entry = *pte;
25654         if (!pte_present(entry)) {
25655 @@ -2815,9 +2826,12 @@ static inline int handle_pte_fault(struc
25656         if (unlikely(!pte_same(*pte, entry)))
25657                 goto unlock;
25658         if (write_access) {
25659 -               if (!pte_write(entry))
25660 -                       return do_wp_page(mm, vma, address,
25661 +               if (!pte_write(entry)) {
25662 +                       ret = do_wp_page(mm, vma, address,
25663                                         pte, pmd, ptl, entry);
25664 +                       type = VXPT_WRITE;
25665 +                       goto out;
25666 +               }
25667                 entry = pte_mkdirty(entry);
25668         }
25669         entry = pte_mkyoung(entry);
25670 @@ -2835,7 +2849,10 @@ static inline int handle_pte_fault(struc
25671         }
25672  unlock:
25673         pte_unmap_unlock(pte, ptl);
25674 -       return 0;
25675 +       ret = 0;
25676 +out:
25677 +       vx_page_fault(mm, vma, type, ret);
25678 +       return ret;
25679  }
25680  
25681  /*
25682 diff -NurpP --minimal linux-2.6.29/mm/mlock.c linux-2.6.29-vs2.3.0.36.9-pre2/mm/mlock.c
25683 --- linux-2.6.29/mm/mlock.c     2009-03-24 14:22:45.000000000 +0100
25684 +++ linux-2.6.29-vs2.3.0.36.9-pre2/mm/mlock.c   2009-03-28 05:08:26.000000000 +0100
25685 @@ -18,6 +18,7 @@
25686  #include <linux/rmap.h>
25687  #include <linux/mmzone.h>
25688  #include <linux/hugetlb.h>
25689 +#include <linux/vs_memory.h>
25690  
25691  #include "internal.h"
25692  
25693 @@ -415,7 +416,7 @@ success:
25694         nr_pages = (end - start) >> PAGE_SHIFT;
25695         if (!lock)
25696                 nr_pages = -nr_pages;
25697 -       mm->locked_vm += nr_pages;
25698 +       vx_vmlocked_add(mm, nr_pages);
25699  
25700         /*
25701          * vm_flags is protected by the mmap_sem held in write mode.
25702 @@ -492,7 +493,7 @@ static int do_mlock(unsigned long start,
25703  
25704  SYSCALL_DEFINE2(mlock, unsigned long, start, size_t, len)
25705  {
25706 -       unsigned long locked;
25707 +       unsigned long locked, grow;
25708         unsigned long lock_limit;
25709         int error = -ENOMEM;
25710  
25711 @@ -505,8 +506,10 @@ SYSCALL_DEFINE2(mlock, unsigned long, st
25712         len = PAGE_ALIGN(len + (start & ~PAGE_MASK));
25713         start &= PAGE_MASK;
25714  
25715 -       locked = len >> PAGE_SHIFT;
25716 -       locked += current->mm->locked_vm;
25717 +       grow = len >> PAGE_SHIFT;
25718 +       if (!vx_vmlocked_avail(current->mm, grow))
25719 +               goto out;
25720 +       locked = current->mm->locked_vm + grow;
25721  
25722         lock_limit = current->signal->rlim[RLIMIT_MEMLOCK].rlim_cur;
25723         lock_limit >>= PAGE_SHIFT;
25724 @@ -514,6 +517,7 @@ SYSCALL_DEFINE2(mlock, unsigned long, st
25725         /* check against resource limits */
25726         if ((locked <= lock_limit) || capable(CAP_IPC_LOCK))
25727                 error = do_mlock(start, len, 1);
25728 +out:
25729         up_write(&current->mm->mmap_sem);
25730         return error;
25731  }
25732 @@ -575,6 +579,8 @@ SYSCALL_DEFINE1(mlockall, int, flags)
25733         lock_limit >>= PAGE_SHIFT;
25734  
25735         ret = -ENOMEM;
25736 +       if (!vx_vmlocked_avail(current->mm, current->mm->total_vm))
25737 +               goto out;
25738         if (!(flags & MCL_CURRENT) || (current->mm->total_vm <= lock_limit) ||
25739             capable(CAP_IPC_LOCK))
25740                 ret = do_mlockall(flags);
25741 @@ -652,8 +658,10 @@ void *alloc_locked_buffer(size_t size)
25742         if (!buffer)
25743                 goto out;
25744  
25745 -       current->mm->total_vm  += pgsz;
25746 -       current->mm->locked_vm += pgsz;
25747 +       // current->mm->total_vm  += pgsz;
25748 +       vx_vmpages_add(current->mm, pgsz);
25749 +       // current->mm->locked_vm += pgsz;
25750 +       vx_vmlocked_add(current->mm, pgsz);
25751  
25752   out:
25753         up_write(&current->mm->mmap_sem);
25754 @@ -666,8 +674,10 @@ void release_locked_buffer(void *buffer,
25755  
25756         down_write(&current->mm->mmap_sem);
25757  
25758 -       current->mm->total_vm  -= pgsz;
25759 -       current->mm->locked_vm -= pgsz;
25760 +       // current->mm->total_vm  -= pgsz;
25761 +       vx_vmpages_sub(current->mm, pgsz);
25762 +       // current->mm->locked_vm -= pgsz;
25763 +       vx_vmlocked_sub(current->mm, pgsz);
25764  
25765         up_write(&current->mm->mmap_sem);
25766  }
25767 diff -NurpP --minimal linux-2.6.29/mm/mmap.c linux-2.6.29-vs2.3.0.36.9-pre2/mm/mmap.c
25768 --- linux-2.6.29/mm/mmap.c      2009-03-24 14:22:45.000000000 +0100
25769 +++ linux-2.6.29-vs2.3.0.36.9-pre2/mm/mmap.c    2009-03-24 14:48:36.000000000 +0100
25770 @@ -1219,7 +1219,8 @@ munmap_back:
25771         if (correct_wcount)
25772                 atomic_inc(&inode->i_writecount);
25773  out:
25774 -       mm->total_vm += len >> PAGE_SHIFT;
25775 +       // mm->total_vm += len >> PAGE_SHIFT;
25776 +       vx_vmpages_add(mm, len >> PAGE_SHIFT);
25777         vm_stat_account(mm, vm_flags, file, len >> PAGE_SHIFT);
25778         if (vm_flags & VM_LOCKED) {
25779                 /*
25780 @@ -1228,7 +1229,8 @@ out:
25781                 long nr_pages = mlock_vma_pages_range(vma, addr, addr + len);
25782                 if (nr_pages < 0)
25783                         return nr_pages;        /* vma gone! */
25784 -               mm->locked_vm += (len >> PAGE_SHIFT) - nr_pages;
25785 +               // mm->locked_vm += (len >> PAGE_SHIFT) - nr_pages;
25786 +               vx_vmlocked_add(mm, (len >> PAGE_SHIFT) - nr_pages);
25787         } else if ((flags & MAP_POPULATE) && !(flags & MAP_NONBLOCK))
25788                 make_pages_present(addr, addr + len);
25789         return addr;
25790 @@ -1575,9 +1577,9 @@ static int acct_stack_growth(struct vm_a
25791                 return -ENOMEM;
25792  
25793         /* Ok, everything looks good - let it rip */
25794 -       mm->total_vm += grow;
25795 +       vx_vmpages_add(mm, grow);
25796         if (vma->vm_flags & VM_LOCKED)
25797 -               mm->locked_vm += grow;
25798 +               vx_vmlocked_add(mm, grow);
25799         vm_stat_account(mm, vma->vm_flags, vma->vm_file, grow);
25800         return 0;
25801  }
25802 @@ -1752,7 +1754,8 @@ static void remove_vma_list(struct mm_st
25803         do {
25804                 long nrpages = vma_pages(vma);
25805  
25806 -               mm->total_vm -= nrpages;
25807 +               // mm->total_vm -= nrpages;
25808 +               vx_vmpages_sub(mm, nrpages);
25809                 vm_stat_account(mm, vma->vm_flags, vma->vm_file, -nrpages);
25810                 vma = remove_vma(vma);
25811         } while (vma);
25812 @@ -1924,7 +1927,8 @@ int do_munmap(struct mm_struct *mm, unsi
25813                 struct vm_area_struct *tmp = vma;
25814                 while (tmp && tmp->vm_start < end) {
25815                         if (tmp->vm_flags & VM_LOCKED) {
25816 -                               mm->locked_vm -= vma_pages(tmp);
25817 +                               // mm->locked_vm -= vma_pages(tmp);
25818 +                               vx_vmlocked_sub(mm, vma_pages(tmp));
25819                                 munlock_vma_pages_all(tmp);
25820                         }
25821                         tmp = tmp->vm_next;
25822 @@ -2013,6 +2017,8 @@ unsigned long do_brk(unsigned long addr,
25823                 lock_limit >>= PAGE_SHIFT;
25824                 if (locked > lock_limit && !capable(CAP_IPC_LOCK))
25825                         return -EAGAIN;
25826 +               if (!vx_vmlocked_avail(mm, len >> PAGE_SHIFT))
25827 +                       return -ENOMEM;
25828         }
25829  
25830         /*
25831 @@ -2039,7 +2045,8 @@ unsigned long do_brk(unsigned long addr,
25832         if (mm->map_count > sysctl_max_map_count)
25833                 return -ENOMEM;
25834  
25835 -       if (security_vm_enough_memory(len >> PAGE_SHIFT))
25836 +       if (security_vm_enough_memory(len >> PAGE_SHIFT) ||
25837 +               !vx_vmpages_avail(mm, len >> PAGE_SHIFT))
25838                 return -ENOMEM;
25839  
25840         /* Can we just expand an old private anonymous mapping? */
25841 @@ -2065,10 +2072,13 @@ unsigned long do_brk(unsigned long addr,
25842         vma->vm_page_prot = vm_get_page_prot(flags);
25843         vma_link(mm, vma, prev, rb_link, rb_parent);
25844  out:
25845 -       mm->total_vm += len >> PAGE_SHIFT;
25846 +       // mm->total_vm += len >> PAGE_SHIFT;
25847 +       vx_vmpages_add(mm, len >> PAGE_SHIFT);
25848 +
25849         if (flags & VM_LOCKED) {
25850                 if (!mlock_vma_pages_range(vma, addr, addr + len))
25851 -                       mm->locked_vm += (len >> PAGE_SHIFT);
25852 +                       // mm->locked_vm += (len >> PAGE_SHIFT);
25853 +                       vx_vmlocked_add(mm, len >> PAGE_SHIFT);
25854         }
25855         return addr;
25856  }
25857 @@ -2111,6 +2121,11 @@ void exit_mmap(struct mm_struct *mm)
25858         free_pgtables(tlb, vma, FIRST_USER_ADDRESS, 0);
25859         tlb_finish_mmu(tlb, 0, end);
25860  
25861 +       set_mm_counter(mm, file_rss, 0);
25862 +       set_mm_counter(mm, anon_rss, 0);
25863 +       vx_vmpages_sub(mm, mm->total_vm);
25864 +       vx_vmlocked_sub(mm, mm->locked_vm);
25865 +
25866         /*
25867          * Walk the list again, actually closing and freeing it,
25868          * with preemption enabled, without holding any MM locks.
25869 @@ -2150,7 +2165,8 @@ int insert_vm_struct(struct mm_struct * 
25870         if (__vma && __vma->vm_start < vma->vm_end)
25871                 return -ENOMEM;
25872         if ((vma->vm_flags & VM_ACCOUNT) &&
25873 -            security_vm_enough_memory_mm(mm, vma_pages(vma)))
25874 +               (security_vm_enough_memory_mm(mm, vma_pages(vma)) ||
25875 +               !vx_vmpages_avail(mm, vma_pages(vma))))
25876                 return -ENOMEM;
25877         vma_link(mm, vma, prev, rb_link, rb_parent);
25878         return 0;
25879 @@ -2226,6 +2242,8 @@ int may_expand_vm(struct mm_struct *mm, 
25880  
25881         if (cur + npages > lim)
25882                 return 0;
25883 +       if (!vx_vmpages_avail(mm, npages))
25884 +               return 0;
25885         return 1;
25886  }
25887  
25888 @@ -2303,8 +2321,7 @@ int install_special_mapping(struct mm_st
25889                 return -ENOMEM;
25890         }
25891  
25892 -       mm->total_vm += len >> PAGE_SHIFT;
25893 -
25894 +       vx_vmpages_add(mm, len >> PAGE_SHIFT);
25895         return 0;
25896  }
25897  
25898 diff -NurpP --minimal linux-2.6.29/mm/mremap.c linux-2.6.29-vs2.3.0.36.9-pre2/mm/mremap.c
25899 --- linux-2.6.29/mm/mremap.c    2009-03-24 14:22:45.000000000 +0100
25900 +++ linux-2.6.29-vs2.3.0.36.9-pre2/mm/mremap.c  2009-03-24 14:48:36.000000000 +0100
25901 @@ -19,6 +19,7 @@
25902  #include <linux/security.h>
25903  #include <linux/syscalls.h>
25904  #include <linux/mmu_notifier.h>
25905 +#include <linux/vs_memory.h>
25906  
25907  #include <asm/uaccess.h>
25908  #include <asm/cacheflush.h>
25909 @@ -220,7 +221,7 @@ static unsigned long move_vma(struct vm_
25910          * If this were a serious issue, we'd add a flag to do_munmap().
25911          */
25912         hiwater_vm = mm->hiwater_vm;
25913 -       mm->total_vm += new_len >> PAGE_SHIFT;
25914 +       vx_vmpages_add(mm, new_len >> PAGE_SHIFT);
25915         vm_stat_account(mm, vma->vm_flags, vma->vm_file, new_len>>PAGE_SHIFT);
25916  
25917         if (do_munmap(mm, old_addr, old_len) < 0) {
25918 @@ -238,7 +239,7 @@ static unsigned long move_vma(struct vm_
25919         }
25920  
25921         if (vm_flags & VM_LOCKED) {
25922 -               mm->locked_vm += new_len >> PAGE_SHIFT;
25923 +               vx_vmlocked_add(mm, new_len >> PAGE_SHIFT);
25924                 if (new_len > old_len)
25925                         mlock_vma_pages_range(new_vma, new_addr + old_len,
25926                                                        new_addr + new_len);
25927 @@ -349,6 +350,9 @@ unsigned long do_mremap(unsigned long ad
25928                 ret = -EAGAIN;
25929                 if (locked > lock_limit && !capable(CAP_IPC_LOCK))
25930                         goto out;
25931 +               if (!vx_vmlocked_avail(current->mm,
25932 +                       (new_len - old_len) >> PAGE_SHIFT))
25933 +                       goto out;
25934         }
25935         if (!may_expand_vm(mm, (new_len - old_len) >> PAGE_SHIFT)) {
25936                 ret = -ENOMEM;
25937 @@ -377,10 +381,12 @@ unsigned long do_mremap(unsigned long ad
25938                         vma_adjust(vma, vma->vm_start,
25939                                 addr + new_len, vma->vm_pgoff, NULL);
25940  
25941 -                       mm->total_vm += pages;
25942 +                       // mm->total_vm += pages;
25943 +                       vx_vmpages_add(mm, pages);
25944                         vm_stat_account(mm, vma->vm_flags, vma->vm_file, pages);
25945                         if (vma->vm_flags & VM_LOCKED) {
25946 -                               mm->locked_vm += pages;
25947 +                               // mm->locked_vm += pages;
25948 +                               vx_vmlocked_add(mm, pages);
25949                                 mlock_vma_pages_range(vma, addr + old_len,
25950                                                    addr + new_len);
25951                         }
25952 diff -NurpP --minimal linux-2.6.29/mm/nommu.c linux-2.6.29-vs2.3.0.36.9-pre2/mm/nommu.c
25953 --- linux-2.6.29/mm/nommu.c     2009-03-24 14:22:45.000000000 +0100
25954 +++ linux-2.6.29-vs2.3.0.36.9-pre2/mm/nommu.c   2009-03-24 18:25:55.000000000 +0100
25955 @@ -1348,7 +1348,7 @@ unsigned long do_mmap_pgoff(struct file 
25956         /* okay... we have a mapping; now we have to register it */
25957         result = vma->vm_start;
25958  
25959 -       current->mm->total_vm += len >> PAGE_SHIFT;
25960 +       vx_vmpages_add(current->mm, len >> PAGE_SHIFT);
25961  
25962  share:
25963         add_vma_to_mm(current->mm, vma);
25964 @@ -1614,7 +1614,7 @@ void exit_mmap(struct mm_struct *mm)
25965  
25966         kenter("");
25967  
25968 -       mm->total_vm = 0;
25969 +       vx_vmpages_sub(mm, mm->total_vm);
25970  
25971         while ((vma = mm->mmap)) {
25972                 mm->mmap = vma->vm_next;
25973 diff -NurpP --minimal linux-2.6.29/mm/oom_kill.c linux-2.6.29-vs2.3.0.36.9-pre2/mm/oom_kill.c
25974 --- linux-2.6.29/mm/oom_kill.c  2009-03-24 14:22:45.000000000 +0100
25975 +++ linux-2.6.29-vs2.3.0.36.9-pre2/mm/oom_kill.c        2009-03-24 14:48:36.000000000 +0100
25976 @@ -27,6 +27,7 @@
25977  #include <linux/notifier.h>
25978  #include <linux/memcontrol.h>
25979  #include <linux/security.h>
25980 +#include <linux/vs_memory.h>
25981  
25982  int sysctl_panic_on_oom;
25983  int sysctl_oom_kill_allocating_task;
25984 @@ -72,6 +73,12 @@ unsigned long badness(struct task_struct
25985         points = mm->total_vm;
25986  
25987         /*
25988 +        * add points for context badness
25989 +        */
25990 +
25991 +       points += vx_badness(p, mm);
25992 +
25993 +       /*
25994          * After this unlock we can no longer dereference local variable `mm'
25995          */
25996         task_unlock(p);
25997 @@ -162,8 +169,8 @@ unsigned long badness(struct task_struct
25998         }
25999  
26000  #ifdef DEBUG
26001 -       printk(KERN_DEBUG "OOMkill: task %d (%s) got %lu points\n",
26002 -       p->pid, p->comm, points);
26003 +       printk(KERN_DEBUG "OOMkill: task %d:#%u (%s) got %d points\n",
26004 +               task_pid_nr(p), p->xid, p->comm, points);
26005  #endif
26006         return points;
26007  }
26008 @@ -326,8 +333,8 @@ static void __oom_kill_task(struct task_
26009         }
26010  
26011         if (verbose)
26012 -               printk(KERN_ERR "Killed process %d (%s)\n",
26013 -                               task_pid_nr(p), p->comm);
26014 +               printk(KERN_ERR "Killed process %d:#%u (%s)\n",
26015 +                               task_pid_nr(p), p->xid, p->comm);
26016  
26017         /*
26018          * We give our sacrificial lamb high priority and access to
26019 @@ -410,8 +417,8 @@ static int oom_kill_process(struct task_
26020                 return 0;
26021         }
26022  
26023 -       printk(KERN_ERR "%s: kill process %d (%s) score %li or a child\n",
26024 -                                       message, task_pid_nr(p), p->comm, points);
26025 +       printk(KERN_ERR "%s: kill process %d:#%u (%s) score %li or a child\n",
26026 +                               message, task_pid_nr(p), p->xid, p->comm, points);
26027  
26028         /* Try to kill a child first */
26029         list_for_each_entry(c, &p->children, sibling) {
26030 diff -NurpP --minimal linux-2.6.29/mm/page_alloc.c linux-2.6.29-vs2.3.0.36.9-pre2/mm/page_alloc.c
26031 --- linux-2.6.29/mm/page_alloc.c        2009-03-24 14:22:45.000000000 +0100
26032 +++ linux-2.6.29-vs2.3.0.36.9-pre2/mm/page_alloc.c      2009-03-24 14:48:36.000000000 +0100
26033 @@ -46,6 +46,8 @@
26034  #include <linux/page-isolation.h>
26035  #include <linux/page_cgroup.h>
26036  #include <linux/debugobjects.h>
26037 +#include <linux/vs_base.h>
26038 +#include <linux/vs_limit.h>
26039  
26040  #include <asm/tlbflush.h>
26041  #include <asm/div64.h>
26042 @@ -1839,6 +1841,9 @@ void si_meminfo(struct sysinfo *val)
26043         val->totalhigh = totalhigh_pages;
26044         val->freehigh = nr_free_highpages();
26045         val->mem_unit = PAGE_SIZE;
26046 +
26047 +       if (vx_flags(VXF_VIRT_MEM, 0))
26048 +               vx_vsi_meminfo(val);
26049  }
26050  
26051  EXPORT_SYMBOL(si_meminfo);
26052 @@ -1859,6 +1864,9 @@ void si_meminfo_node(struct sysinfo *val
26053         val->freehigh = 0;
26054  #endif
26055         val->mem_unit = PAGE_SIZE;
26056 +
26057 +       if (vx_flags(VXF_VIRT_MEM, 0))
26058 +               vx_vsi_meminfo(val);
26059  }
26060  #endif
26061  
26062 diff -NurpP --minimal linux-2.6.29/mm/rmap.c linux-2.6.29-vs2.3.0.36.9-pre2/mm/rmap.c
26063 --- linux-2.6.29/mm/rmap.c      2009-03-24 14:22:45.000000000 +0100
26064 +++ linux-2.6.29-vs2.3.0.36.9-pre2/mm/rmap.c    2009-03-24 18:26:27.000000000 +0100
26065 @@ -50,6 +50,7 @@
26066  #include <linux/memcontrol.h>
26067  #include <linux/mmu_notifier.h>
26068  #include <linux/migrate.h>
26069 +#include <linux/vs_memory.h>
26070  
26071  #include <asm/tlbflush.h>
26072  
26073 diff -NurpP --minimal linux-2.6.29/mm/shmem.c linux-2.6.29-vs2.3.0.36.9-pre2/mm/shmem.c
26074 --- linux-2.6.29/mm/shmem.c     2009-03-24 14:22:45.000000000 +0100
26075 +++ linux-2.6.29-vs2.3.0.36.9-pre2/mm/shmem.c   2009-03-24 14:48:36.000000000 +0100
26076 @@ -1757,7 +1757,7 @@ static int shmem_statfs(struct dentry *d
26077  {
26078         struct shmem_sb_info *sbinfo = SHMEM_SB(dentry->d_sb);
26079  
26080 -       buf->f_type = TMPFS_MAGIC;
26081 +       buf->f_type = TMPFS_SUPER_MAGIC;
26082         buf->f_bsize = PAGE_CACHE_SIZE;
26083         buf->f_namelen = NAME_MAX;
26084         spin_lock(&sbinfo->stat_lock);
26085 @@ -2326,7 +2326,7 @@ static int shmem_fill_super(struct super
26086         sb->s_maxbytes = SHMEM_MAX_BYTES;
26087         sb->s_blocksize = PAGE_CACHE_SIZE;
26088         sb->s_blocksize_bits = PAGE_CACHE_SHIFT;
26089 -       sb->s_magic = TMPFS_MAGIC;
26090 +       sb->s_magic = TMPFS_SUPER_MAGIC;
26091         sb->s_op = &shmem_ops;
26092         sb->s_time_gran = 1;
26093  #ifdef CONFIG_TMPFS_POSIX_ACL
26094 diff -NurpP --minimal linux-2.6.29/mm/slab.c linux-2.6.29-vs2.3.0.36.9-pre2/mm/slab.c
26095 --- linux-2.6.29/mm/slab.c      2009-03-24 14:22:45.000000000 +0100
26096 +++ linux-2.6.29-vs2.3.0.36.9-pre2/mm/slab.c    2009-03-24 14:48:36.000000000 +0100
26097 @@ -509,6 +509,8 @@ struct kmem_cache {
26098  #define STATS_INC_FREEMISS(x)  do { } while (0)
26099  #endif
26100  
26101 +#include "slab_vs.h"
26102 +
26103  #if DEBUG
26104  
26105  /*
26106 @@ -3275,6 +3277,7 @@ retry:
26107  
26108         obj = slab_get_obj(cachep, slabp, nodeid);
26109         check_slabp(cachep, slabp);
26110 +       vx_slab_alloc(cachep, flags);
26111         l3->free_objects--;
26112         /* move slabp to correct slabp list: */
26113         list_del(&slabp->list);
26114 @@ -3347,6 +3350,7 @@ __cache_alloc_node(struct kmem_cache *ca
26115         /* ___cache_alloc_node can fall back to other nodes */
26116         ptr = ____cache_alloc_node(cachep, flags, nodeid);
26117    out:
26118 +       vx_slab_alloc(cachep, flags);
26119         local_irq_restore(save_flags);
26120         ptr = cache_alloc_debugcheck_after(cachep, flags, ptr, caller);
26121  
26122 @@ -3518,6 +3522,7 @@ static inline void __cache_free(struct k
26123  
26124         check_irq_off();
26125         objp = cache_free_debugcheck(cachep, objp, __builtin_return_address(0));
26126 +       vx_slab_free(cachep);
26127  
26128         /*
26129          * Skip calling cache_free_alien() when the platform is not numa.
26130 diff -NurpP --minimal linux-2.6.29/mm/slab_vs.h linux-2.6.29-vs2.3.0.36.9-pre2/mm/slab_vs.h
26131 --- linux-2.6.29/mm/slab_vs.h   1970-01-01 01:00:00.000000000 +0100
26132 +++ linux-2.6.29-vs2.3.0.36.9-pre2/mm/slab_vs.h 2009-02-22 22:54:26.000000000 +0100
26133 @@ -0,0 +1,27 @@
26134 +
26135 +#include <linux/vserver/context.h>
26136 +
26137 +#include <linux/vs_context.h>
26138 +
26139 +static inline
26140 +void vx_slab_alloc(struct kmem_cache *cachep, gfp_t flags)
26141 +{
26142 +       int what = gfp_zone(cachep->gfpflags);
26143 +
26144 +       if (!current->vx_info)
26145 +               return;
26146 +
26147 +       atomic_add(cachep->buffer_size, &current->vx_info->cacct.slab[what]);
26148 +}
26149 +
26150 +static inline
26151 +void vx_slab_free(struct kmem_cache *cachep)
26152 +{
26153 +       int what = gfp_zone(cachep->gfpflags);
26154 +
26155 +       if (!current->vx_info)
26156 +               return;
26157 +
26158 +       atomic_sub(cachep->buffer_size, &current->vx_info->cacct.slab[what]);
26159 +}
26160 +
26161 diff -NurpP --minimal linux-2.6.29/mm/swapfile.c linux-2.6.29-vs2.3.0.36.9-pre2/mm/swapfile.c
26162 --- linux-2.6.29/mm/swapfile.c  2009-03-24 14:22:45.000000000 +0100
26163 +++ linux-2.6.29-vs2.3.0.36.9-pre2/mm/swapfile.c        2009-03-24 18:27:15.000000000 +0100
26164 @@ -34,6 +34,8 @@
26165  #include <asm/tlbflush.h>
26166  #include <linux/swapops.h>
26167  #include <linux/page_cgroup.h>
26168 +#include <linux/vs_base.h>
26169 +#include <linux/vs_memory.h>
26170  
26171  static DEFINE_SPINLOCK(swap_lock);
26172  static unsigned int nr_swapfiles;
26173 @@ -1935,6 +1937,8 @@ void si_swapinfo(struct sysinfo *val)
26174         val->freeswap = nr_swap_pages + nr_to_be_unused;
26175         val->totalswap = total_swap_pages + nr_to_be_unused;
26176         spin_unlock(&swap_lock);
26177 +       if (vx_flags(VXF_VIRT_MEM, 0))
26178 +               vx_vsi_swapinfo(val);
26179  }
26180  
26181  /*
26182 diff -NurpP --minimal linux-2.6.29/net/core/dev.c linux-2.6.29-vs2.3.0.36.9-pre2/net/core/dev.c
26183 --- linux-2.6.29/net/core/dev.c 2009-03-24 14:22:46.000000000 +0100
26184 +++ linux-2.6.29-vs2.3.0.36.9-pre2/net/core/dev.c       2009-03-24 18:28:15.000000000 +0100
26185 @@ -126,6 +126,7 @@
26186  #include <linux/in.h>
26187  #include <linux/jhash.h>
26188  #include <linux/random.h>
26189 +#include <linux/vs_inet.h>
26190  
26191  #include "net-sysfs.h"
26192  
26193 @@ -2856,6 +2857,8 @@ static int dev_ifconf(struct net *net, c
26194  
26195         total = 0;
26196         for_each_netdev(net, dev) {
26197 +               if (!nx_dev_visible(current->nx_info, dev))
26198 +                       continue;
26199                 for (i = 0; i < NPROTO; i++) {
26200                         if (gifconf_list[i]) {
26201                                 int done;
26202 @@ -2924,6 +2927,9 @@ static void dev_seq_printf_stats(struct 
26203  {
26204         const struct net_device_stats *stats = dev_get_stats(dev);
26205  
26206 +       if (!nx_dev_visible(current->nx_info, dev))
26207 +               return;
26208 +
26209         seq_printf(seq, "%6s:%8lu %7lu %4lu %4lu %4lu %5lu %10lu %9lu "
26210                    "%8lu %7lu %4lu %4lu %4lu %5lu %7lu %10lu\n",
26211                    dev->name, stats->rx_bytes, stats->rx_packets,
26212 @@ -4865,6 +4871,15 @@ int dev_change_net_namespace(struct net_
26213                 goto out;
26214  #endif
26215  
26216 +#ifdef CONFIG_SYSFS
26217 +       /* Don't allow real devices to be moved when sysfs
26218 +        * is enabled.
26219 +        */
26220 +       err = -EINVAL;
26221 +       if (dev->dev.parent)
26222 +               goto out;
26223 +#endif
26224 +
26225         /* Ensure the device has been registrered */
26226         err = -EINVAL;
26227         if (dev->reg_state != NETREG_REGISTERED)
26228 @@ -4924,6 +4939,8 @@ int dev_change_net_namespace(struct net_
26229  
26230         netdev_unregister_kobject(dev);
26231  
26232 +       netdev_unregister_kobject(dev);
26233 +
26234         /* Actually switch the network namespace */
26235         dev_net_set(dev, net);
26236  
26237 diff -NurpP --minimal linux-2.6.29/net/core/net-sysfs.c linux-2.6.29-vs2.3.0.36.9-pre2/net/core/net-sysfs.c
26238 --- linux-2.6.29/net/core/net-sysfs.c   2009-03-24 14:22:46.000000000 +0100
26239 +++ linux-2.6.29-vs2.3.0.36.9-pre2/net/core/net-sysfs.c 2009-03-24 18:30:01.000000000 +0100
26240 @@ -512,6 +512,9 @@ int netdev_register_kobject(struct net_d
26241         if (dev_net(net) != &init_net)
26242                 return 0;
26243  
26244 +       if (dev_net(net) != &init_net)
26245 +               return 0;
26246 +
26247         return device_add(dev);
26248  }
26249  
26250 diff -NurpP --minimal linux-2.6.29/net/core/rtnetlink.c linux-2.6.29-vs2.3.0.36.9-pre2/net/core/rtnetlink.c
26251 --- linux-2.6.29/net/core/rtnetlink.c   2009-03-24 14:22:46.000000000 +0100
26252 +++ linux-2.6.29-vs2.3.0.36.9-pre2/net/core/rtnetlink.c 2009-03-24 14:48:36.000000000 +0100
26253 @@ -690,6 +690,8 @@ static int rtnl_dump_ifinfo(struct sk_bu
26254  
26255         idx = 0;
26256         for_each_netdev(net, dev) {
26257 +               if (!nx_dev_visible(skb->sk->sk_nx_info, dev))
26258 +                       continue;
26259                 if (idx < s_idx)
26260                         goto cont;
26261                 if (rtnl_fill_ifinfo(skb, dev, RTM_NEWLINK,
26262 @@ -1235,6 +1237,9 @@ void rtmsg_ifinfo(int type, struct net_d
26263         struct sk_buff *skb;
26264         int err = -ENOBUFS;
26265  
26266 +       if (!nx_dev_visible(current->nx_info, dev))
26267 +               return;
26268 +
26269         skb = nlmsg_new(if_nlmsg_size(dev), GFP_KERNEL);
26270         if (skb == NULL)
26271                 goto errout;
26272 diff -NurpP --minimal linux-2.6.29/net/core/sock.c linux-2.6.29-vs2.3.0.36.9-pre2/net/core/sock.c
26273 --- linux-2.6.29/net/core/sock.c        2009-03-24 14:22:46.000000000 +0100
26274 +++ linux-2.6.29-vs2.3.0.36.9-pre2/net/core/sock.c      2009-03-24 14:48:36.000000000 +0100
26275 @@ -124,6 +124,10 @@
26276  #include <linux/ipsec.h>
26277  
26278  #include <linux/filter.h>
26279 +#include <linux/vs_socket.h>
26280 +#include <linux/vs_limit.h>
26281 +#include <linux/vs_context.h>
26282 +#include <linux/vs_network.h>
26283  
26284  #ifdef CONFIG_INET
26285  #include <net/tcp.h>
26286 @@ -900,6 +904,8 @@ static struct sock *sk_prot_alloc(struct
26287                 if (!try_module_get(prot->owner))
26288                         goto out_free_sec;
26289         }
26290 +               sock_vx_init(sk);
26291 +               sock_nx_init(sk);
26292  
26293         return sk;
26294  
26295 @@ -976,6 +982,11 @@ void sk_free(struct sock *sk)
26296                        __func__, atomic_read(&sk->sk_omem_alloc));
26297  
26298         put_net(sock_net(sk));
26299 +       vx_sock_dec(sk);
26300 +       clr_vx_info(&sk->sk_vx_info);
26301 +       sk->sk_xid = -1;
26302 +       clr_nx_info(&sk->sk_nx_info);
26303 +       sk->sk_nid = -1;
26304         sk_prot_free(sk->sk_prot_creator, sk);
26305  }
26306  
26307 @@ -1011,6 +1022,8 @@ struct sock *sk_clone(const struct sock 
26308  
26309                 /* SANITY */
26310                 get_net(sock_net(newsk));
26311 +               sock_vx_init(newsk);
26312 +               sock_nx_init(newsk);
26313                 sk_node_init(&newsk->sk_node);
26314                 sock_lock_init(newsk);
26315                 bh_lock_sock(newsk);
26316 @@ -1057,6 +1070,12 @@ struct sock *sk_clone(const struct sock 
26317                 newsk->sk_priority = 0;
26318                 atomic_set(&newsk->sk_refcnt, 2);
26319  
26320 +               set_vx_info(&newsk->sk_vx_info, sk->sk_vx_info);
26321 +               newsk->sk_xid = sk->sk_xid;
26322 +               vx_sock_inc(newsk);
26323 +               set_nx_info(&newsk->sk_nx_info, sk->sk_nx_info);
26324 +               newsk->sk_nid = sk->sk_nid;
26325 +
26326                 /*
26327                  * Increment the counter in the same struct proto as the master
26328                  * sock (sk_refcnt_debug_inc uses newsk->sk_prot->socks, that
26329 @@ -1744,6 +1763,11 @@ void sock_init_data(struct socket *sock,
26330  
26331         sk->sk_stamp = ktime_set(-1L, 0);
26332  
26333 +       set_vx_info(&sk->sk_vx_info, current->vx_info);
26334 +       sk->sk_xid = vx_current_xid();
26335 +       vx_sock_inc(sk);
26336 +       set_nx_info(&sk->sk_nx_info, current->nx_info);
26337 +       sk->sk_nid = nx_current_nid();
26338         atomic_set(&sk->sk_refcnt, 1);
26339         atomic_set(&sk->sk_drops, 0);
26340  }
26341 diff -NurpP --minimal linux-2.6.29/net/ipv4/af_inet.c linux-2.6.29-vs2.3.0.36.9-pre2/net/ipv4/af_inet.c
26342 --- linux-2.6.29/net/ipv4/af_inet.c     2009-03-24 14:22:46.000000000 +0100
26343 +++ linux-2.6.29-vs2.3.0.36.9-pre2/net/ipv4/af_inet.c   2009-03-24 14:48:37.000000000 +0100
26344 @@ -115,6 +115,7 @@
26345  #ifdef CONFIG_IP_MROUTE
26346  #include <linux/mroute.h>
26347  #endif
26348 +#include <linux/vs_limit.h>
26349  
26350  extern void ip_mc_drop_socket(struct sock *sk);
26351  
26352 @@ -325,9 +326,12 @@ lookup_protocol:
26353         }
26354  
26355         err = -EPERM;
26356 +       if ((protocol == IPPROTO_ICMP) &&
26357 +               nx_capable(answer->capability, NXC_RAW_ICMP))
26358 +               goto override;
26359         if (answer->capability > 0 && !capable(answer->capability))
26360                 goto out_rcu_unlock;
26361 -
26362 +override:
26363         err = -EAFNOSUPPORT;
26364         if (!inet_netns_ok(net, protocol))
26365                 goto out_rcu_unlock;
26366 @@ -445,6 +449,7 @@ int inet_bind(struct socket *sock, struc
26367         struct sockaddr_in *addr = (struct sockaddr_in *)uaddr;
26368         struct sock *sk = sock->sk;
26369         struct inet_sock *inet = inet_sk(sk);
26370 +       struct nx_v4_sock_addr nsa;
26371         unsigned short snum;
26372         int chk_addr_ret;
26373         int err;
26374 @@ -458,7 +463,11 @@ int inet_bind(struct socket *sock, struc
26375         if (addr_len < sizeof(struct sockaddr_in))
26376                 goto out;
26377  
26378 -       chk_addr_ret = inet_addr_type(sock_net(sk), addr->sin_addr.s_addr);
26379 +       err = v4_map_sock_addr(inet, addr, &nsa);
26380 +       if (err)
26381 +               goto out;
26382 +
26383 +       chk_addr_ret = inet_addr_type(sock_net(sk), nsa.saddr);
26384  
26385         /* Not specified by any standard per-se, however it breaks too
26386          * many applications when removed.  It is unfortunate since
26387 @@ -470,7 +479,7 @@ int inet_bind(struct socket *sock, struc
26388         err = -EADDRNOTAVAIL;
26389         if (!sysctl_ip_nonlocal_bind &&
26390             !(inet->freebind || inet->transparent) &&
26391 -           addr->sin_addr.s_addr != htonl(INADDR_ANY) &&
26392 +           nsa.saddr != htonl(INADDR_ANY) &&
26393             chk_addr_ret != RTN_LOCAL &&
26394             chk_addr_ret != RTN_MULTICAST &&
26395             chk_addr_ret != RTN_BROADCAST)
26396 @@ -495,7 +504,7 @@ int inet_bind(struct socket *sock, struc
26397         if (sk->sk_state != TCP_CLOSE || inet->num)
26398                 goto out_release_sock;
26399  
26400 -       inet->rcv_saddr = inet->saddr = addr->sin_addr.s_addr;
26401 +       v4_set_sock_addr(inet, &nsa);
26402         if (chk_addr_ret == RTN_MULTICAST || chk_addr_ret == RTN_BROADCAST)
26403                 inet->saddr = 0;  /* Use device */
26404  
26405 @@ -688,11 +697,13 @@ int inet_getname(struct socket *sock, st
26406                      peer == 1))
26407                         return -ENOTCONN;
26408                 sin->sin_port = inet->dport;
26409 -               sin->sin_addr.s_addr = inet->daddr;
26410 +               sin->sin_addr.s_addr =
26411 +                       nx_map_sock_lback(sk->sk_nx_info, inet->daddr);
26412         } else {
26413                 __be32 addr = inet->rcv_saddr;
26414                 if (!addr)
26415                         addr = inet->saddr;
26416 +               addr = nx_map_sock_lback(sk->sk_nx_info, addr);
26417                 sin->sin_port = inet->sport;
26418                 sin->sin_addr.s_addr = addr;
26419         }
26420 diff -NurpP --minimal linux-2.6.29/net/ipv4/devinet.c linux-2.6.29-vs2.3.0.36.9-pre2/net/ipv4/devinet.c
26421 --- linux-2.6.29/net/ipv4/devinet.c     2009-03-24 14:22:46.000000000 +0100
26422 +++ linux-2.6.29-vs2.3.0.36.9-pre2/net/ipv4/devinet.c   2009-03-24 14:48:37.000000000 +0100
26423 @@ -413,6 +413,7 @@ struct in_device *inetdev_by_index(struc
26424         return in_dev;
26425  }
26426  
26427 +
26428  /* Called only from RTNL semaphored context. No locks. */
26429  
26430  struct in_ifaddr *inet_ifa_byprefix(struct in_device *in_dev, __be32 prefix,
26431 @@ -653,6 +654,8 @@ int devinet_ioctl(struct net *net, unsig
26432                 *colon = ':';
26433  
26434         if ((in_dev = __in_dev_get_rtnl(dev)) != NULL) {
26435 +               struct nx_info *nxi = current->nx_info;
26436 +
26437                 if (tryaddrmatch) {
26438                         /* Matthias Andree */
26439                         /* compare label and address (4.4BSD style) */
26440 @@ -661,6 +664,8 @@ int devinet_ioctl(struct net *net, unsig
26441                            This is checked above. */
26442                         for (ifap = &in_dev->ifa_list; (ifa = *ifap) != NULL;
26443                              ifap = &ifa->ifa_next) {
26444 +                               if (!nx_v4_ifa_visible(nxi, ifa))
26445 +                                       continue;
26446                                 if (!strcmp(ifr.ifr_name, ifa->ifa_label) &&
26447                                     sin_orig.sin_addr.s_addr ==
26448                                                         ifa->ifa_address) {
26449 @@ -673,9 +678,12 @@ int devinet_ioctl(struct net *net, unsig
26450                    comparing just the label */
26451                 if (!ifa) {
26452                         for (ifap = &in_dev->ifa_list; (ifa = *ifap) != NULL;
26453 -                            ifap = &ifa->ifa_next)
26454 +                            ifap = &ifa->ifa_next) {
26455 +                               if (!nx_v4_ifa_visible(nxi, ifa))
26456 +                                       continue;
26457                                 if (!strcmp(ifr.ifr_name, ifa->ifa_label))
26458                                         break;
26459 +                       }
26460                 }
26461         }
26462  
26463 @@ -826,6 +834,8 @@ static int inet_gifconf(struct net_devic
26464                 goto out;
26465  
26466         for (; ifa; ifa = ifa->ifa_next) {
26467 +               if (!nx_v4_ifa_visible(current->nx_info, ifa))
26468 +                       continue;
26469                 if (!buf) {
26470                         done += sizeof(ifr);
26471                         continue;
26472 @@ -1156,6 +1166,7 @@ static int inet_dump_ifaddr(struct sk_bu
26473         struct net_device *dev;
26474         struct in_device *in_dev;
26475         struct in_ifaddr *ifa;
26476 +       struct sock *sk = skb->sk;
26477         int s_ip_idx, s_idx = cb->args[0];
26478  
26479         s_ip_idx = ip_idx = cb->args[1];
26480 @@ -1170,6 +1181,8 @@ static int inet_dump_ifaddr(struct sk_bu
26481  
26482                 for (ifa = in_dev->ifa_list, ip_idx = 0; ifa;
26483                      ifa = ifa->ifa_next, ip_idx++) {
26484 +                       if (sk && !nx_v4_ifa_visible(sk->sk_nx_info, ifa))
26485 +                               continue;
26486                         if (ip_idx < s_ip_idx)
26487                                 continue;
26488                         if (inet_fill_ifaddr(skb, ifa, NETLINK_CB(cb->skb).pid,
26489 diff -NurpP --minimal linux-2.6.29/net/ipv4/fib_hash.c linux-2.6.29-vs2.3.0.36.9-pre2/net/ipv4/fib_hash.c
26490 --- linux-2.6.29/net/ipv4/fib_hash.c    2009-03-24 14:22:46.000000000 +0100
26491 +++ linux-2.6.29-vs2.3.0.36.9-pre2/net/ipv4/fib_hash.c  2009-03-24 14:48:37.000000000 +0100
26492 @@ -1022,7 +1022,7 @@ static int fib_seq_show(struct seq_file 
26493         prefix  = f->fn_key;
26494         mask    = FZ_MASK(iter->zone);
26495         flags   = fib_flag_trans(fa->fa_type, mask, fi);
26496 -       if (fi)
26497 +       if (fi && nx_dev_visible(current->nx_info, fi->fib_dev))
26498                 seq_printf(seq,
26499                          "%s\t%08X\t%08X\t%04X\t%d\t%u\t%d\t%08X\t%d\t%u\t%u%n",
26500                          fi->fib_dev ? fi->fib_dev->name : "*", prefix,
26501 diff -NurpP --minimal linux-2.6.29/net/ipv4/inet_connection_sock.c linux-2.6.29-vs2.3.0.36.9-pre2/net/ipv4/inet_connection_sock.c
26502 --- linux-2.6.29/net/ipv4/inet_connection_sock.c        2009-03-24 14:22:46.000000000 +0100
26503 +++ linux-2.6.29-vs2.3.0.36.9-pre2/net/ipv4/inet_connection_sock.c      2009-03-24 14:48:37.000000000 +0100
26504 @@ -49,10 +49,40 @@ void inet_get_local_port_range(int *low,
26505  }
26506  EXPORT_SYMBOL(inet_get_local_port_range);
26507  
26508 +int ipv4_rcv_saddr_equal(const struct sock *sk1, const struct sock *sk2)
26509 +{
26510 +       __be32  sk1_rcv_saddr = inet_rcv_saddr(sk1),
26511 +               sk2_rcv_saddr = inet_rcv_saddr(sk2);
26512 +
26513 +       if (inet_v6_ipv6only(sk2))
26514 +               return 0;
26515 +
26516 +       if (sk1_rcv_saddr &&
26517 +           sk2_rcv_saddr &&
26518 +           sk1_rcv_saddr == sk2_rcv_saddr)
26519 +               return 1;
26520 +
26521 +       if (sk1_rcv_saddr &&
26522 +           !sk2_rcv_saddr &&
26523 +           v4_addr_in_nx_info(sk2->sk_nx_info, sk1_rcv_saddr, NXA_MASK_BIND))
26524 +               return 1;
26525 +
26526 +       if (sk2_rcv_saddr &&
26527 +           !sk1_rcv_saddr &&
26528 +           v4_addr_in_nx_info(sk1->sk_nx_info, sk2_rcv_saddr, NXA_MASK_BIND))
26529 +               return 1;
26530 +
26531 +       if (!sk1_rcv_saddr &&
26532 +           !sk2_rcv_saddr &&
26533 +           nx_v4_addr_conflict(sk1->sk_nx_info, sk2->sk_nx_info))
26534 +               return 1;
26535 +
26536 +       return 0;
26537 +}
26538 +
26539  int inet_csk_bind_conflict(const struct sock *sk,
26540                            const struct inet_bind_bucket *tb)
26541  {
26542 -       const __be32 sk_rcv_saddr = inet_rcv_saddr(sk);
26543         struct sock *sk2;
26544         struct hlist_node *node;
26545         int reuse = sk->sk_reuse;
26546 @@ -72,9 +102,7 @@ int inet_csk_bind_conflict(const struct 
26547                      sk->sk_bound_dev_if == sk2->sk_bound_dev_if)) {
26548                         if (!reuse || !sk2->sk_reuse ||
26549                             sk2->sk_state == TCP_LISTEN) {
26550 -                               const __be32 sk2_rcv_saddr = inet_rcv_saddr(sk2);
26551 -                               if (!sk2_rcv_saddr || !sk_rcv_saddr ||
26552 -                                   sk2_rcv_saddr == sk_rcv_saddr)
26553 +                               if (ipv4_rcv_saddr_equal(sk, sk2))
26554                                         break;
26555                         }
26556                 }
26557 diff -NurpP --minimal linux-2.6.29/net/ipv4/inet_diag.c linux-2.6.29-vs2.3.0.36.9-pre2/net/ipv4/inet_diag.c
26558 --- linux-2.6.29/net/ipv4/inet_diag.c   2009-03-24 14:22:46.000000000 +0100
26559 +++ linux-2.6.29-vs2.3.0.36.9-pre2/net/ipv4/inet_diag.c 2009-03-24 14:48:37.000000000 +0100
26560 @@ -32,6 +32,8 @@
26561  #include <linux/stddef.h>
26562  
26563  #include <linux/inet_diag.h>
26564 +#include <linux/vs_network.h>
26565 +#include <linux/vs_inet.h>
26566  
26567  static const struct inet_diag_handler **inet_diag_table;
26568  
26569 @@ -118,8 +120,8 @@ static int inet_csk_diag_fill(struct soc
26570  
26571         r->id.idiag_sport = inet->sport;
26572         r->id.idiag_dport = inet->dport;
26573 -       r->id.idiag_src[0] = inet->rcv_saddr;
26574 -       r->id.idiag_dst[0] = inet->daddr;
26575 +       r->id.idiag_src[0] = nx_map_sock_lback(sk->sk_nx_info, inet->rcv_saddr);
26576 +       r->id.idiag_dst[0] = nx_map_sock_lback(sk->sk_nx_info, inet->daddr);
26577  
26578  #if defined(CONFIG_IPV6) || defined (CONFIG_IPV6_MODULE)
26579         if (r->idiag_family == AF_INET6) {
26580 @@ -206,8 +208,8 @@ static int inet_twsk_diag_fill(struct in
26581         r->id.idiag_cookie[1] = (u32)(((unsigned long)tw >> 31) >> 1);
26582         r->id.idiag_sport     = tw->tw_sport;
26583         r->id.idiag_dport     = tw->tw_dport;
26584 -       r->id.idiag_src[0]    = tw->tw_rcv_saddr;
26585 -       r->id.idiag_dst[0]    = tw->tw_daddr;
26586 +       r->id.idiag_src[0]    = nx_map_sock_lback(tw->tw_nx_info, tw->tw_rcv_saddr);
26587 +       r->id.idiag_dst[0]    = nx_map_sock_lback(tw->tw_nx_info, tw->tw_daddr);
26588         r->idiag_state        = tw->tw_substate;
26589         r->idiag_timer        = 3;
26590         r->idiag_expires      = DIV_ROUND_UP(tmo * 1000, HZ);
26591 @@ -264,6 +266,7 @@ static int inet_diag_get_exact(struct sk
26592         err = -EINVAL;
26593  
26594         if (req->idiag_family == AF_INET) {
26595 +               /* TODO: lback */
26596                 sk = inet_lookup(&init_net, hashinfo, req->id.idiag_dst[0],
26597                                  req->id.idiag_dport, req->id.idiag_src[0],
26598                                  req->id.idiag_sport, req->id.idiag_if);
26599 @@ -506,6 +509,7 @@ static int inet_csk_diag_dump(struct soc
26600                 } else
26601  #endif
26602                 {
26603 +                       /* TODO: lback */
26604                         entry.saddr = &inet->rcv_saddr;
26605                         entry.daddr = &inet->daddr;
26606                 }
26607 @@ -542,6 +546,7 @@ static int inet_twsk_diag_dump(struct in
26608                 } else
26609  #endif
26610                 {
26611 +                       /* TODO: lback */
26612                         entry.saddr = &tw->tw_rcv_saddr;
26613                         entry.daddr = &tw->tw_daddr;
26614                 }
26615 @@ -588,8 +593,8 @@ static int inet_diag_fill_req(struct sk_
26616  
26617         r->id.idiag_sport = inet->sport;
26618         r->id.idiag_dport = ireq->rmt_port;
26619 -       r->id.idiag_src[0] = ireq->loc_addr;
26620 -       r->id.idiag_dst[0] = ireq->rmt_addr;
26621 +       r->id.idiag_src[0] = nx_map_sock_lback(sk->sk_nx_info, ireq->loc_addr);
26622 +       r->id.idiag_dst[0] = nx_map_sock_lback(sk->sk_nx_info, ireq->rmt_addr);
26623         r->idiag_expires = jiffies_to_msecs(tmo);
26624         r->idiag_rqueue = 0;
26625         r->idiag_wqueue = 0;
26626 @@ -659,6 +664,7 @@ static int inet_diag_dump_reqs(struct sk
26627                                 continue;
26628  
26629                         if (bc) {
26630 +                               /* TODO: lback */
26631                                 entry.saddr =
26632  #if defined(CONFIG_IPV6) || defined (CONFIG_IPV6_MODULE)
26633                                         (entry.family == AF_INET6) ?
26634 @@ -729,6 +735,8 @@ static int inet_diag_dump(struct sk_buff
26635                         sk_nulls_for_each(sk, node, &ilb->head) {
26636                                 struct inet_sock *inet = inet_sk(sk);
26637  
26638 +                               if (!nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
26639 +                                       continue;
26640                                 if (num < s_num) {
26641                                         num++;
26642                                         continue;
26643 @@ -795,6 +803,8 @@ skip_listen_ht:
26644                 sk_nulls_for_each(sk, node, &head->chain) {
26645                         struct inet_sock *inet = inet_sk(sk);
26646  
26647 +                       if (!nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
26648 +                               continue;
26649                         if (num < s_num)
26650                                 goto next_normal;
26651                         if (!(r->idiag_states & (1 << sk->sk_state)))
26652 @@ -819,6 +829,8 @@ next_normal:
26653                         inet_twsk_for_each(tw, node,
26654                                     &head->twchain) {
26655  
26656 +                               if (!nx_check(tw->tw_nid, VS_WATCH_P | VS_IDENT))
26657 +                                       continue;
26658                                 if (num < s_num)
26659                                         goto next_dying;
26660                                 if (r->id.idiag_sport != tw->tw_sport &&
26661 diff -NurpP --minimal linux-2.6.29/net/ipv4/inet_hashtables.c linux-2.6.29-vs2.3.0.36.9-pre2/net/ipv4/inet_hashtables.c
26662 --- linux-2.6.29/net/ipv4/inet_hashtables.c     2009-03-24 14:22:46.000000000 +0100
26663 +++ linux-2.6.29-vs2.3.0.36.9-pre2/net/ipv4/inet_hashtables.c   2009-03-24 19:35:10.000000000 +0100
26664 @@ -21,6 +21,7 @@
26665  
26666  #include <net/inet_connection_sock.h>
26667  #include <net/inet_hashtables.h>
26668 +#include <net/route.h>
26669  #include <net/ip.h>
26670  
26671  /*
26672 @@ -142,7 +143,6 @@ static inline int compute_score(struct s
26673   * wildcarded during the search since they can never be otherwise.
26674   */
26675  
26676 -
26677  struct sock *__inet_lookup_listener(struct net *net,
26678                                     struct inet_hashinfo *hashinfo,
26679                                     const __be32 daddr, const unsigned short hnum,
26680 @@ -165,6 +165,7 @@ begin:
26681                         hiscore = score;
26682                 }
26683         }
26684 +
26685         /*
26686          * if the nulls value we got at the end of this lookup is
26687          * not the expected one, we must restart lookup.
26688 diff -NurpP --minimal linux-2.6.29/net/ipv4/netfilter/nf_nat_helper.c linux-2.6.29-vs2.3.0.36.9-pre2/net/ipv4/netfilter/nf_nat_helper.c
26689 --- linux-2.6.29/net/ipv4/netfilter/nf_nat_helper.c     2008-12-25 00:26:37.000000000 +0100
26690 +++ linux-2.6.29-vs2.3.0.36.9-pre2/net/ipv4/netfilter/nf_nat_helper.c   2009-02-22 22:54:26.000000000 +0100
26691 @@ -19,6 +19,7 @@
26692  #include <net/route.h>
26693  
26694  #include <linux/netfilter_ipv4.h>
26695 +#include <net/route.h>
26696  #include <net/netfilter/nf_conntrack.h>
26697  #include <net/netfilter/nf_conntrack_helper.h>
26698  #include <net/netfilter/nf_conntrack_ecache.h>
26699 diff -NurpP --minimal linux-2.6.29/net/ipv4/netfilter.c linux-2.6.29-vs2.3.0.36.9-pre2/net/ipv4/netfilter.c
26700 --- linux-2.6.29/net/ipv4/netfilter.c   2009-03-24 14:22:46.000000000 +0100
26701 +++ linux-2.6.29-vs2.3.0.36.9-pre2/net/ipv4/netfilter.c 2009-03-24 14:48:37.000000000 +0100
26702 @@ -4,7 +4,7 @@
26703  #include <linux/netfilter_ipv4.h>
26704  #include <linux/ip.h>
26705  #include <linux/skbuff.h>
26706 -#include <net/route.h>
26707 +// #include <net/route.h>
26708  #include <net/xfrm.h>
26709  #include <net/ip.h>
26710  #include <net/netfilter/nf_queue.h>
26711 diff -NurpP --minimal linux-2.6.29/net/ipv4/raw.c linux-2.6.29-vs2.3.0.36.9-pre2/net/ipv4/raw.c
26712 --- linux-2.6.29/net/ipv4/raw.c 2009-03-24 14:22:46.000000000 +0100
26713 +++ linux-2.6.29-vs2.3.0.36.9-pre2/net/ipv4/raw.c       2009-03-24 14:48:37.000000000 +0100
26714 @@ -117,7 +117,7 @@ static struct sock *__raw_v4_lookup(stru
26715  
26716                 if (net_eq(sock_net(sk), net) && inet->num == num       &&
26717                     !(inet->daddr && inet->daddr != raddr)              &&
26718 -                   !(inet->rcv_saddr && inet->rcv_saddr != laddr)      &&
26719 +                   v4_sock_addr_match(sk->sk_nx_info, inet, laddr)     &&
26720                     !(sk->sk_bound_dev_if && sk->sk_bound_dev_if != dif))
26721                         goto found; /* gotcha */
26722         }
26723 @@ -372,6 +372,12 @@ static int raw_send_hdrinc(struct sock *
26724                 icmp_out_count(net, ((struct icmphdr *)
26725                         skb_transport_header(skb))->type);
26726  
26727 +       err = -EPERM;
26728 +       if (!nx_check(0, VS_ADMIN) && !capable(CAP_NET_RAW) &&
26729 +               sk->sk_nx_info &&
26730 +               !v4_addr_in_nx_info(sk->sk_nx_info, iph->saddr, NXA_MASK_BIND))
26731 +               goto error_free;
26732 +
26733         err = NF_HOOK(PF_INET, NF_INET_LOCAL_OUT, skb, NULL, rt->u.dst.dev,
26734                       dst_output);
26735         if (err > 0)
26736 @@ -383,6 +389,7 @@ out:
26737  
26738  error_fault:
26739         err = -EFAULT;
26740 +error_free:
26741         kfree_skb(skb);
26742  error:
26743         IP_INC_STATS(net, IPSTATS_MIB_OUTDISCARDS);
26744 @@ -550,6 +557,13 @@ static int raw_sendmsg(struct kiocb *ioc
26745                 }
26746  
26747                 security_sk_classify_flow(sk, &fl);
26748 +               if (sk->sk_nx_info) {
26749 +                       err = ip_v4_find_src(sock_net(sk),
26750 +                               sk->sk_nx_info, &rt, &fl);
26751 +
26752 +                       if (err)
26753 +                               goto done;
26754 +               }
26755                 err = ip_route_output_flow(sock_net(sk), &rt, &fl, sk, 1);
26756         }
26757         if (err)
26758 @@ -619,17 +633,19 @@ static int raw_bind(struct sock *sk, str
26759  {
26760         struct inet_sock *inet = inet_sk(sk);
26761         struct sockaddr_in *addr = (struct sockaddr_in *) uaddr;
26762 +       struct nx_v4_sock_addr nsa = { 0 };
26763         int ret = -EINVAL;
26764         int chk_addr_ret;
26765  
26766         if (sk->sk_state != TCP_CLOSE || addr_len < sizeof(struct sockaddr_in))
26767                 goto out;
26768 -       chk_addr_ret = inet_addr_type(sock_net(sk), addr->sin_addr.s_addr);
26769 +       v4_map_sock_addr(inet, addr, &nsa);
26770 +       chk_addr_ret = inet_addr_type(sock_net(sk), nsa.saddr);
26771         ret = -EADDRNOTAVAIL;
26772 -       if (addr->sin_addr.s_addr && chk_addr_ret != RTN_LOCAL &&
26773 +       if (nsa.saddr && chk_addr_ret != RTN_LOCAL &&
26774             chk_addr_ret != RTN_MULTICAST && chk_addr_ret != RTN_BROADCAST)
26775                 goto out;
26776 -       inet->rcv_saddr = inet->saddr = addr->sin_addr.s_addr;
26777 +       v4_set_sock_addr(inet, &nsa);
26778         if (chk_addr_ret == RTN_MULTICAST || chk_addr_ret == RTN_BROADCAST)
26779                 inet->saddr = 0;  /* Use device */
26780         sk_dst_reset(sk);
26781 @@ -681,7 +697,8 @@ static int raw_recvmsg(struct kiocb *ioc
26782         /* Copy the address. */
26783         if (sin) {
26784                 sin->sin_family = AF_INET;
26785 -               sin->sin_addr.s_addr = ip_hdr(skb)->saddr;
26786 +               sin->sin_addr.s_addr =
26787 +                       nx_map_sock_lback(sk->sk_nx_info, ip_hdr(skb)->saddr);
26788                 sin->sin_port = 0;
26789                 memset(&sin->sin_zero, 0, sizeof(sin->sin_zero));
26790         }
26791 @@ -858,7 +875,8 @@ static struct sock *raw_get_first(struct
26792                 struct hlist_node *node;
26793  
26794                 sk_for_each(sk, node, &state->h->ht[state->bucket])
26795 -                       if (sock_net(sk) == seq_file_net(seq))
26796 +                       if ((sock_net(sk) == seq_file_net(seq)) &&
26797 +                               nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
26798                                 goto found;
26799         }
26800         sk = NULL;
26801 @@ -874,7 +892,8 @@ static struct sock *raw_get_next(struct 
26802                 sk = sk_next(sk);
26803  try_again:
26804                 ;
26805 -       } while (sk && sock_net(sk) != seq_file_net(seq));
26806 +       } while (sk && ((sock_net(sk) != seq_file_net(seq)) ||
26807 +               !nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT)));
26808  
26809         if (!sk && ++state->bucket < RAW_HTABLE_SIZE) {
26810                 sk = sk_head(&state->h->ht[state->bucket]);
26811 @@ -933,7 +952,10 @@ static void raw_sock_seq_show(struct seq
26812  
26813         seq_printf(seq, "%4d: %08X:%04X %08X:%04X"
26814                 " %02X %08X:%08X %02X:%08lX %08X %5d %8d %lu %d %p %d\n",
26815 -               i, src, srcp, dest, destp, sp->sk_state,
26816 +               i,
26817 +               nx_map_sock_lback(current_nx_info(), src), srcp,
26818 +               nx_map_sock_lback(current_nx_info(), dest), destp,
26819 +               sp->sk_state,
26820                 atomic_read(&sp->sk_wmem_alloc),
26821                 atomic_read(&sp->sk_rmem_alloc),
26822                 0, 0L, 0, sock_i_uid(sp), 0, sock_i_ino(sp),
26823 diff -NurpP --minimal linux-2.6.29/net/ipv4/tcp.c linux-2.6.29-vs2.3.0.36.9-pre2/net/ipv4/tcp.c
26824 --- linux-2.6.29/net/ipv4/tcp.c 2009-03-24 14:22:46.000000000 +0100
26825 +++ linux-2.6.29-vs2.3.0.36.9-pre2/net/ipv4/tcp.c       2009-03-24 14:48:37.000000000 +0100
26826 @@ -264,6 +264,7 @@
26827  #include <linux/cache.h>
26828  #include <linux/err.h>
26829  #include <linux/crypto.h>
26830 +#include <linux/in.h>
26831  
26832  #include <net/icmp.h>
26833  #include <net/tcp.h>
26834 diff -NurpP --minimal linux-2.6.29/net/ipv4/tcp_ipv4.c linux-2.6.29-vs2.3.0.36.9-pre2/net/ipv4/tcp_ipv4.c
26835 --- linux-2.6.29/net/ipv4/tcp_ipv4.c    2009-03-24 14:22:46.000000000 +0100
26836 +++ linux-2.6.29-vs2.3.0.36.9-pre2/net/ipv4/tcp_ipv4.c  2009-03-24 19:51:34.000000000 +0100
26837 @@ -1894,6 +1894,12 @@ static void *listening_get_next(struct s
26838                 req = req->dl_next;
26839                 while (1) {
26840                         while (req) {
26841 +                               vxdprintk(VXD_CBIT(net, 6),
26842 +                                       "sk,req: %p [#%d] (from %d)", req->sk,
26843 +                                       (req->sk)?req->sk->sk_nid:0, nx_current_nid());
26844 +                               if (req->sk &&
26845 +                                       !nx_check(req->sk->sk_nid, VS_WATCH_P | VS_IDENT))
26846 +                                       continue;
26847                                 if (req->rsk_ops->family == st->family) {
26848                                         cur = req;
26849                                         goto out;
26850 @@ -1918,6 +1924,10 @@ get_req:
26851         }
26852  get_sk:
26853         sk_nulls_for_each_from(sk, node) {
26854 +               vxdprintk(VXD_CBIT(net, 6), "sk: %p [#%d] (from %d)",
26855 +                       sk, sk->sk_nid, nx_current_nid());
26856 +               if (!nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
26857 +                       continue;
26858                 if (sk->sk_family == st->family && net_eq(sock_net(sk), net)) {
26859                         cur = sk;
26860                         goto out;
26861 @@ -1981,6 +1991,11 @@ static void *established_get_first(struc
26862  
26863                 spin_lock_bh(lock);
26864                 sk_nulls_for_each(sk, node, &tcp_hashinfo.ehash[st->bucket].chain) {
26865 +                       vxdprintk(VXD_CBIT(net, 6),
26866 +                               "sk,egf: %p [#%d] (from %d)",
26867 +                               sk, sk->sk_nid, nx_current_nid());
26868 +                       if (!nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
26869 +                               continue;
26870                         if (sk->sk_family != st->family ||
26871                             !net_eq(sock_net(sk), net)) {
26872                                 continue;
26873 @@ -1991,6 +2006,11 @@ static void *established_get_first(struc
26874                 st->state = TCP_SEQ_STATE_TIME_WAIT;
26875                 inet_twsk_for_each(tw, node,
26876                                    &tcp_hashinfo.ehash[st->bucket].twchain) {
26877 +                       vxdprintk(VXD_CBIT(net, 6),
26878 +                               "tw: %p [#%d] (from %d)",
26879 +                               tw, tw->tw_nid, nx_current_nid());
26880 +                       if (!nx_check(tw->tw_nid, VS_WATCH_P | VS_IDENT))
26881 +                               continue;
26882                         if (tw->tw_family != st->family ||
26883                             !net_eq(twsk_net(tw), net)) {
26884                                 continue;
26885 @@ -2019,7 +2039,9 @@ static void *established_get_next(struct
26886                 tw = cur;
26887                 tw = tw_next(tw);
26888  get_tw:
26889 -               while (tw && (tw->tw_family != st->family || !net_eq(twsk_net(tw), net))) {
26890 +               while (tw && (tw->tw_family != st->family ||
26891 +                       !net_eq(twsk_net(tw), net) ||
26892 +                       !nx_check(tw->tw_nid, VS_WATCH_P | VS_IDENT))) {
26893                         tw = tw_next(tw);
26894                 }
26895                 if (tw) {
26896 @@ -2042,6 +2064,11 @@ get_tw:
26897                 sk = sk_nulls_next(sk);
26898  
26899         sk_nulls_for_each_from(sk, node) {
26900 +               vxdprintk(VXD_CBIT(net, 6),
26901 +                       "sk,egn: %p [#%d] (from %d)",
26902 +                       sk, sk->sk_nid, nx_current_nid());
26903 +               if (!nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
26904 +                       continue;
26905                 if (sk->sk_family == st->family && net_eq(sock_net(sk), net))
26906                         goto found;
26907         }
26908 @@ -2193,9 +2220,9 @@ static void get_openreq4(struct sock *sk
26909         seq_printf(f, "%4d: %08X:%04X %08X:%04X"
26910                 " %02X %08X:%08X %02X:%08lX %08X %5d %8d %u %d %p%n",
26911                 i,
26912 -               ireq->loc_addr,
26913 +               nx_map_sock_lback(current_nx_info(), ireq->loc_addr),
26914                 ntohs(inet_sk(sk)->sport),
26915 -               ireq->rmt_addr,
26916 +               nx_map_sock_lback(current_nx_info(), ireq->rmt_addr),
26917                 ntohs(ireq->rmt_port),
26918                 TCP_SYN_RECV,
26919                 0, 0, /* could print option size, but that is af dependent. */
26920 @@ -2238,7 +2265,10 @@ static void get_tcp4_sock(struct sock *s
26921  
26922         seq_printf(f, "%4d: %08X:%04X %08X:%04X %02X %08X:%08X %02X:%08lX "
26923                         "%08X %5d %8d %lu %d %p %lu %lu %u %u %d%n",
26924 -               i, src, srcp, dest, destp, sk->sk_state,
26925 +               i,
26926 +               nx_map_sock_lback(current_nx_info(), src), srcp,
26927 +               nx_map_sock_lback(current_nx_info(), dest), destp,
26928 +               sk->sk_state,
26929                 tp->write_seq - tp->snd_una,
26930                 sk->sk_state == TCP_LISTEN ? sk->sk_ack_backlog :
26931                                              (tp->rcv_nxt - tp->copied_seq),
26932 @@ -2274,7 +2304,10 @@ static void get_timewait4_sock(struct in
26933  
26934         seq_printf(f, "%4d: %08X:%04X %08X:%04X"
26935                 " %02X %08X:%08X %02X:%08lX %08X %5d %8d %d %d %p%n",
26936 -               i, src, srcp, dest, destp, tw->tw_substate, 0, 0,
26937 +               i,
26938 +               nx_map_sock_lback(current_nx_info(), src), srcp,
26939 +               nx_map_sock_lback(current_nx_info(), dest), destp,
26940 +               tw->tw_substate, 0, 0,
26941                 3, jiffies_to_clock_t(ttd), 0, 0, 0, 0,
26942                 atomic_read(&tw->tw_refcnt), tw, len);
26943  }
26944 diff -NurpP --minimal linux-2.6.29/net/ipv4/tcp_minisocks.c linux-2.6.29-vs2.3.0.36.9-pre2/net/ipv4/tcp_minisocks.c
26945 --- linux-2.6.29/net/ipv4/tcp_minisocks.c       2009-03-24 14:22:46.000000000 +0100
26946 +++ linux-2.6.29-vs2.3.0.36.9-pre2/net/ipv4/tcp_minisocks.c     2009-03-24 14:48:37.000000000 +0100
26947 @@ -26,6 +26,10 @@
26948  #include <net/inet_common.h>
26949  #include <net/xfrm.h>
26950  
26951 +#include <linux/vs_limit.h>
26952 +#include <linux/vs_socket.h>
26953 +#include <linux/vs_context.h>
26954 +
26955  #ifdef CONFIG_SYSCTL
26956  #define SYNC_INIT 0 /* let the user enable it */
26957  #else
26958 @@ -293,6 +297,11 @@ void tcp_time_wait(struct sock *sk, int 
26959                 tcptw->tw_ts_recent     = tp->rx_opt.ts_recent;
26960                 tcptw->tw_ts_recent_stamp = tp->rx_opt.ts_recent_stamp;
26961  
26962 +               tw->tw_xid              = sk->sk_xid;
26963 +               tw->tw_vx_info          = NULL;
26964 +               tw->tw_nid              = sk->sk_nid;
26965 +               tw->tw_nx_info          = NULL;
26966 +
26967  #if defined(CONFIG_IPV6) || defined(CONFIG_IPV6_MODULE)
26968                 if (tw->tw_family == PF_INET6) {
26969                         struct ipv6_pinfo *np = inet6_sk(sk);
26970 diff -NurpP --minimal linux-2.6.29/net/ipv4/udp.c linux-2.6.29-vs2.3.0.36.9-pre2/net/ipv4/udp.c
26971 --- linux-2.6.29/net/ipv4/udp.c 2009-03-24 14:22:46.000000000 +0100
26972 +++ linux-2.6.29-vs2.3.0.36.9-pre2/net/ipv4/udp.c       2009-03-25 10:50:13.000000000 +0100
26973 @@ -222,14 +222,7 @@ fail:
26974         return error;
26975  }
26976  
26977 -static int ipv4_rcv_saddr_equal(const struct sock *sk1, const struct sock *sk2)
26978 -{
26979 -       struct inet_sock *inet1 = inet_sk(sk1), *inet2 = inet_sk(sk2);
26980 -
26981 -       return  ( !ipv6_only_sock(sk2)  &&
26982 -                 (!inet1->rcv_saddr || !inet2->rcv_saddr ||
26983 -                  inet1->rcv_saddr == inet2->rcv_saddr      ));
26984 -}
26985 +extern int ipv4_rcv_saddr_equal(const struct sock *, const struct sock *);
26986  
26987  int udp_v4_get_port(struct sock *sk, unsigned short snum)
26988  {
26989 @@ -251,6 +244,11 @@ static inline int compute_score(struct s
26990                         if (inet->rcv_saddr != daddr)
26991                                 return -1;
26992                         score += 2;
26993 +               } else {
26994 +                       /* block non nx_info ips */
26995 +                       if (!v4_addr_in_nx_info(sk->sk_nx_info,
26996 +                               daddr, NXA_MASK_BIND))
26997 +                               return -1;
26998                 }
26999                 if (inet->daddr) {
27000                         if (inet->daddr != saddr)
27001 @@ -271,6 +269,7 @@ static inline int compute_score(struct s
27002         return score;
27003  }
27004  
27005 +
27006  /* UDP is nearly always wildcards out the wazoo, it makes no sense to try
27007   * harder than this. -DaveM
27008   */
27009 @@ -292,6 +291,11 @@ begin:
27010         sk_nulls_for_each_rcu(sk, node, &hslot->head) {
27011                 score = compute_score(sk, net, saddr, hnum, sport,
27012                                       daddr, dport, dif);
27013 +               /* FIXME: disabled?
27014 +               if (score == 9) {
27015 +                       result = sk;
27016 +                       break;
27017 +               } else */
27018                 if (score > badness) {
27019                         result = sk;
27020                         badness = score;
27021 @@ -305,6 +309,7 @@ begin:
27022         if (get_nulls_value(node) != hash)
27023                 goto begin;
27024  
27025 +
27026         if (result) {
27027                 if (unlikely(!atomic_inc_not_zero(&result->sk_refcnt)))
27028                         result = NULL;
27029 @@ -314,6 +319,7 @@ begin:
27030                         goto begin;
27031                 }
27032         }
27033 +
27034         rcu_read_unlock();
27035         return result;
27036  }
27037 @@ -356,7 +362,7 @@ static inline struct sock *udp_v4_mcast_
27038                     s->sk_hash != hnum                                  ||
27039                     (inet->daddr && inet->daddr != rmt_addr)            ||
27040                     (inet->dport != rmt_port && inet->dport)            ||
27041 -                   (inet->rcv_saddr && inet->rcv_saddr != loc_addr)    ||
27042 +                   !v4_sock_addr_match(sk->sk_nx_info, inet, loc_addr) ||
27043                     ipv6_only_sock(s)                                   ||
27044                     (s->sk_bound_dev_if && s->sk_bound_dev_if != dif))
27045                         continue;
27046 @@ -694,8 +700,13 @@ int udp_sendmsg(struct kiocb *iocb, stru
27047                                                { .sport = inet->sport,
27048                                                  .dport = dport } } };
27049                 struct net *net = sock_net(sk);
27050 +               struct nx_info *nxi = sk->sk_nx_info;
27051  
27052                 security_sk_classify_flow(sk, &fl);
27053 +               err = ip_v4_find_src(net, nxi, &rt, &fl);
27054 +               if (err)
27055 +                       goto out;
27056 +
27057                 err = ip_route_output_flow(net, &rt, &fl, sk, 1);
27058                 if (err) {
27059                         if (err == -ENETUNREACH)
27060 @@ -940,7 +951,8 @@ try_again:
27061         {
27062                 sin->sin_family = AF_INET;
27063                 sin->sin_port = udp_hdr(skb)->source;
27064 -               sin->sin_addr.s_addr = ip_hdr(skb)->saddr;
27065 +               sin->sin_addr.s_addr = nx_map_sock_lback(
27066 +                       skb->sk->sk_nx_info, ip_hdr(skb)->saddr);
27067                 memset(sin->sin_zero, 0, sizeof(sin->sin_zero));
27068         }
27069         if (inet->cmsg_flags)
27070 @@ -1594,6 +1606,8 @@ static struct sock *udp_get_first(struct
27071                 sk_nulls_for_each(sk, node, &hslot->head) {
27072                         if (!net_eq(sock_net(sk), net))
27073                                 continue;
27074 +                       if (!nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
27075 +                               continue;
27076                         if (sk->sk_family == state->family)
27077                                 goto found;
27078                 }
27079 @@ -1611,7 +1625,9 @@ static struct sock *udp_get_next(struct 
27080  
27081         do {
27082                 sk = sk_nulls_next(sk);
27083 -       } while (sk && (!net_eq(sock_net(sk), net) || sk->sk_family != state->family));
27084 +       } while (sk && (!net_eq(sock_net(sk), net) ||
27085 +               sk->sk_family != state->family ||
27086 +               !nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT)));
27087  
27088         if (!sk) {
27089                 spin_unlock_bh(&state->udp_table->hash[state->bucket].lock);
27090 @@ -1712,7 +1728,10 @@ static void udp4_format_sock(struct sock
27091  
27092         seq_printf(f, "%4d: %08X:%04X %08X:%04X"
27093                 " %02X %08X:%08X %02X:%08lX %08X %5d %8d %lu %d %p %d%n",
27094 -               bucket, src, srcp, dest, destp, sp->sk_state,
27095 +               bucket,
27096 +               nx_map_sock_lback(current_nx_info(), src), srcp,
27097 +               nx_map_sock_lback(current_nx_info(), dest), destp,
27098 +               sp->sk_state,
27099                 atomic_read(&sp->sk_wmem_alloc),
27100                 atomic_read(&sp->sk_rmem_alloc),
27101                 0, 0L, 0, sock_i_uid(sp), 0, sock_i_ino(sp),
27102 diff -NurpP --minimal linux-2.6.29/net/ipv6/addrconf.c linux-2.6.29-vs2.3.0.36.9-pre2/net/ipv6/addrconf.c
27103 --- linux-2.6.29/net/ipv6/addrconf.c    2009-03-24 14:22:46.000000000 +0100
27104 +++ linux-2.6.29-vs2.3.0.36.9-pre2/net/ipv6/addrconf.c  2009-03-24 20:39:23.000000000 +0100
27105 @@ -85,6 +85,8 @@
27106  
27107  #include <linux/proc_fs.h>
27108  #include <linux/seq_file.h>
27109 +#include <linux/vs_network.h>
27110 +#include <linux/vs_inet6.h>
27111  
27112  /* Set to 3 to get tracing... */
27113  #define ACONF_DEBUG 2
27114 @@ -1111,7 +1113,7 @@ out:
27115  
27116  int ipv6_dev_get_saddr(struct net *net, struct net_device *dst_dev,
27117                        const struct in6_addr *daddr, unsigned int prefs,
27118 -                      struct in6_addr *saddr)
27119 +                      struct in6_addr *saddr, struct nx_info *nxi)
27120  {
27121         struct ipv6_saddr_score scores[2],
27122                                 *score = &scores[0], *hiscore = &scores[1];
27123 @@ -1184,6 +1186,8 @@ int ipv6_dev_get_saddr(struct net *net, 
27124                                                dev->name);
27125                                 continue;
27126                         }
27127 +                       if (!v6_addr_in_nx_info(nxi, &score->ifa->addr, -1))
27128 +                               continue;
27129  
27130                         score->rule = -1;
27131                         bitmap_zero(score->scorebits, IPV6_SADDR_RULE_MAX);
27132 @@ -1367,35 +1371,46 @@ struct inet6_ifaddr *ipv6_get_ifaddr(str
27133         return ifp;
27134  }
27135  
27136 +extern int ipv4_rcv_saddr_equal(const struct sock *sk1, const struct sock *sk2);
27137 +
27138  int ipv6_rcv_saddr_equal(const struct sock *sk, const struct sock *sk2)
27139  {
27140         const struct in6_addr *sk_rcv_saddr6 = &inet6_sk(sk)->rcv_saddr;
27141         const struct in6_addr *sk2_rcv_saddr6 = inet6_rcv_saddr(sk2);
27142 -       __be32 sk_rcv_saddr = inet_sk(sk)->rcv_saddr;
27143         __be32 sk2_rcv_saddr = inet_rcv_saddr(sk2);
27144         int sk_ipv6only = ipv6_only_sock(sk);
27145         int sk2_ipv6only = inet_v6_ipv6only(sk2);
27146         int addr_type = ipv6_addr_type(sk_rcv_saddr6);
27147         int addr_type2 = sk2_rcv_saddr6 ? ipv6_addr_type(sk2_rcv_saddr6) : IPV6_ADDR_MAPPED;
27148  
27149 -       if (!sk2_rcv_saddr && !sk_ipv6only)
27150 +       /* FIXME: needs handling for v4 ANY */
27151 +       if (!sk2_rcv_saddr && !sk_ipv6only && !sk2->sk_nx_info)
27152                 return 1;
27153  
27154         if (addr_type2 == IPV6_ADDR_ANY &&
27155 -           !(sk2_ipv6only && addr_type == IPV6_ADDR_MAPPED))
27156 +           !(sk2_ipv6only && addr_type == IPV6_ADDR_MAPPED) &&
27157 +           v6_addr_in_nx_info(sk2->sk_nx_info, sk_rcv_saddr6, -1))
27158                 return 1;
27159  
27160         if (addr_type == IPV6_ADDR_ANY &&
27161 -           !(sk_ipv6only && addr_type2 == IPV6_ADDR_MAPPED))
27162 +           !(sk_ipv6only && addr_type2 == IPV6_ADDR_MAPPED) &&
27163 +           (sk2_rcv_saddr6 && v6_addr_in_nx_info(sk->sk_nx_info, sk2_rcv_saddr6, -1)))
27164 +               return 1;
27165 +
27166 +       if (addr_type == IPV6_ADDR_ANY &&
27167 +           addr_type2 == IPV6_ADDR_ANY &&
27168 +           nx_v6_addr_conflict(sk->sk_nx_info, sk2->sk_nx_info))
27169                 return 1;
27170  
27171         if (sk2_rcv_saddr6 &&
27172 +           addr_type != IPV6_ADDR_ANY &&
27173 +           addr_type != IPV6_ADDR_ANY &&
27174             ipv6_addr_equal(sk_rcv_saddr6, sk2_rcv_saddr6))
27175                 return 1;
27176  
27177         if (addr_type == IPV6_ADDR_MAPPED &&
27178             !sk2_ipv6only &&
27179 -           (!sk2_rcv_saddr || !sk_rcv_saddr || sk_rcv_saddr == sk2_rcv_saddr))
27180 +           ipv4_rcv_saddr_equal(sk, sk2))
27181                 return 1;
27182  
27183         return 0;
27184 @@ -2993,7 +3008,10 @@ static void if6_seq_stop(struct seq_file
27185  static int if6_seq_show(struct seq_file *seq, void *v)
27186  {
27187         struct inet6_ifaddr *ifp = (struct inet6_ifaddr *)v;
27188 -       seq_printf(seq, "%pi6 %02x %02x %02x %02x %8s\n",
27189 +
27190 +       if (nx_check(0, VS_ADMIN|VS_WATCH) ||
27191 +           v6_addr_in_nx_info(current_nx_info(), &ifp->addr, -1))
27192 +               seq_printf(seq, "%pi6 %02x %02x %02x %02x %8s\n",
27193                    &ifp->addr,
27194                    ifp->idev->dev->ifindex,
27195                    ifp->prefix_len,
27196 @@ -3487,6 +3505,12 @@ static int inet6_dump_addr(struct sk_buf
27197         struct ifmcaddr6 *ifmca;
27198         struct ifacaddr6 *ifaca;
27199         struct net *net = sock_net(skb->sk);
27200 +       struct nx_info *nxi = skb->sk ? skb->sk->sk_nx_info : NULL;
27201 +
27202 +       /* disable ipv6 on non v6 guests */
27203 +       if (nxi && !nx_info_has_v6(nxi))
27204 +               return skb->len;
27205 +
27206  
27207         s_idx = cb->args[0];
27208         s_ip_idx = ip_idx = cb->args[1];
27209 @@ -3508,6 +3532,8 @@ static int inet6_dump_addr(struct sk_buf
27210                              ifa = ifa->if_next, ip_idx++) {
27211                                 if (ip_idx < s_ip_idx)
27212                                         continue;
27213 +                               if (!v6_addr_in_nx_info(nxi, &ifa->addr, -1))
27214 +                                       continue;
27215                                 err = inet6_fill_ifaddr(skb, ifa,
27216                                                         NETLINK_CB(cb->skb).pid,
27217                                                         cb->nlh->nlmsg_seq,
27218 @@ -3521,6 +3547,8 @@ static int inet6_dump_addr(struct sk_buf
27219                              ifmca = ifmca->next, ip_idx++) {
27220                                 if (ip_idx < s_ip_idx)
27221                                         continue;
27222 +                               if (!v6_addr_in_nx_info(nxi, &ifmca->mca_addr, -1))
27223 +                                       continue;
27224                                 err = inet6_fill_ifmcaddr(skb, ifmca,
27225                                                           NETLINK_CB(cb->skb).pid,
27226                                                           cb->nlh->nlmsg_seq,
27227 @@ -3534,6 +3562,8 @@ static int inet6_dump_addr(struct sk_buf
27228                              ifaca = ifaca->aca_next, ip_idx++) {
27229                                 if (ip_idx < s_ip_idx)
27230                                         continue;
27231 +                               if (!v6_addr_in_nx_info(nxi, &ifaca->aca_addr, -1))
27232 +                                       continue;
27233                                 err = inet6_fill_ifacaddr(skb, ifaca,
27234                                                           NETLINK_CB(cb->skb).pid,
27235                                                           cb->nlh->nlmsg_seq,
27236 @@ -3819,12 +3849,19 @@ static int inet6_dump_ifinfo(struct sk_b
27237         int s_idx = cb->args[0];
27238         struct net_device *dev;
27239         struct inet6_dev *idev;
27240 +       struct nx_info *nxi = skb->sk ? skb->sk->sk_nx_info : NULL;
27241 +
27242 +       /* FIXME: maybe disable ipv6 on non v6 guests?
27243 +       if (skb->sk && skb->sk->sk_vx_info)
27244 +               return skb->len; */
27245  
27246         read_lock(&dev_base_lock);
27247         idx = 0;
27248         for_each_netdev(net, dev) {
27249                 if (idx < s_idx)
27250                         goto cont;
27251 +               if (!v6_dev_in_nx_info(dev, nxi))
27252 +                       goto cont;
27253                 if ((idev = in6_dev_get(dev)) == NULL)
27254                         goto cont;
27255                 err = inet6_fill_ifinfo(skb, idev, NETLINK_CB(cb->skb).pid,
27256 diff -NurpP --minimal linux-2.6.29/net/ipv6/af_inet6.c linux-2.6.29-vs2.3.0.36.9-pre2/net/ipv6/af_inet6.c
27257 --- linux-2.6.29/net/ipv6/af_inet6.c    2009-03-24 14:22:46.000000000 +0100
27258 +++ linux-2.6.29-vs2.3.0.36.9-pre2/net/ipv6/af_inet6.c  2009-03-24 14:48:37.000000000 +0100
27259 @@ -41,6 +41,8 @@
27260  #include <linux/netdevice.h>
27261  #include <linux/icmpv6.h>
27262  #include <linux/netfilter_ipv6.h>
27263 +#include <linux/vs_inet.h>
27264 +#include <linux/vs_inet6.h>
27265  
27266  #include <net/ip.h>
27267  #include <net/ipv6.h>
27268 @@ -49,6 +51,7 @@
27269  #include <net/tcp.h>
27270  #include <net/ipip.h>
27271  #include <net/protocol.h>
27272 +#include <net/route.h>
27273  #include <net/inet_common.h>
27274  #include <net/route.h>
27275  #include <net/transp_v6.h>
27276 @@ -146,9 +149,12 @@ lookup_protocol:
27277         }
27278  
27279         err = -EPERM;
27280 +       if ((protocol == IPPROTO_ICMPV6) &&
27281 +               nx_capable(answer->capability, NXC_RAW_ICMP))
27282 +               goto override;
27283         if (answer->capability > 0 && !capable(answer->capability))
27284                 goto out_rcu_unlock;
27285 -
27286 +override:
27287         sock->ops = answer->ops;
27288         answer_prot = answer->prot;
27289         answer_no_check = answer->no_check;
27290 @@ -247,6 +253,7 @@ int inet6_bind(struct socket *sock, stru
27291         struct inet_sock *inet = inet_sk(sk);
27292         struct ipv6_pinfo *np = inet6_sk(sk);
27293         struct net *net = sock_net(sk);
27294 +       struct nx_v6_sock_addr nsa;
27295         __be32 v4addr = 0;
27296         unsigned short snum;
27297         int addr_type = 0;
27298 @@ -258,6 +265,11 @@ int inet6_bind(struct socket *sock, stru
27299  
27300         if (addr_len < SIN6_LEN_RFC2133)
27301                 return -EINVAL;
27302 +
27303 +       err = v6_map_sock_addr(inet, addr, &nsa);
27304 +       if (err)
27305 +               return err;
27306 +
27307         addr_type = ipv6_addr_type(&addr->sin6_addr);
27308         if ((addr_type & IPV6_ADDR_MULTICAST) && sock->type == SOCK_STREAM)
27309                 return -EINVAL;
27310 @@ -281,6 +293,10 @@ int inet6_bind(struct socket *sock, stru
27311                         err = -EADDRNOTAVAIL;
27312                         goto out;
27313                 }
27314 +               if (!v4_addr_in_nx_info(sk->sk_nx_info, v4addr, NXA_MASK_BIND)) {
27315 +                       err = -EADDRNOTAVAIL;
27316 +                       goto out;
27317 +               }
27318         } else {
27319                 if (addr_type != IPV6_ADDR_ANY) {
27320                         struct net_device *dev = NULL;
27321 @@ -306,6 +322,11 @@ int inet6_bind(struct socket *sock, stru
27322                                 }
27323                         }
27324  
27325 +                       if (!v6_addr_in_nx_info(sk->sk_nx_info, &addr->sin6_addr, -1)) {
27326 +                               err = -EADDRNOTAVAIL;
27327 +                               goto out;
27328 +                       }
27329 +
27330                         /* ipv4 addr of the socket is invalid.  Only the
27331                          * unspecified and mapped address have a v4 equivalent.
27332                          */
27333 @@ -324,6 +345,8 @@ int inet6_bind(struct socket *sock, stru
27334                 }
27335         }
27336  
27337 +       v6_set_sock_addr(inet, &nsa);
27338 +
27339         inet->rcv_saddr = v4addr;
27340         inet->saddr = v4addr;
27341  
27342 @@ -416,9 +439,11 @@ int inet6_getname(struct socket *sock, s
27343                         return -ENOTCONN;
27344                 sin->sin6_port = inet->dport;
27345                 ipv6_addr_copy(&sin->sin6_addr, &np->daddr);
27346 +               /* FIXME: remap lback? */
27347                 if (np->sndflow)
27348                         sin->sin6_flowinfo = np->flow_label;
27349         } else {
27350 +               /* FIXME: remap lback? */
27351                 if (ipv6_addr_any(&np->rcv_saddr))
27352                         ipv6_addr_copy(&sin->sin6_addr, &np->saddr);
27353                 else
27354 diff -NurpP --minimal linux-2.6.29/net/ipv6/fib6_rules.c linux-2.6.29-vs2.3.0.36.9-pre2/net/ipv6/fib6_rules.c
27355 --- linux-2.6.29/net/ipv6/fib6_rules.c  2008-12-25 00:26:37.000000000 +0100
27356 +++ linux-2.6.29-vs2.3.0.36.9-pre2/net/ipv6/fib6_rules.c        2009-02-22 22:54:26.000000000 +0100
27357 @@ -96,7 +96,7 @@ static int fib6_rule_action(struct fib_r
27358                         if (ipv6_dev_get_saddr(net,
27359                                                ip6_dst_idev(&rt->u.dst)->dev,
27360                                                &flp->fl6_dst, srcprefs,
27361 -                                              &saddr))
27362 +                                              &saddr, NULL))
27363                                 goto again;
27364                         if (!ipv6_prefix_equal(&saddr, &r->src.addr,
27365                                                r->src.plen))
27366 diff -NurpP --minimal linux-2.6.29/net/ipv6/inet6_hashtables.c linux-2.6.29-vs2.3.0.36.9-pre2/net/ipv6/inet6_hashtables.c
27367 --- linux-2.6.29/net/ipv6/inet6_hashtables.c    2009-03-24 14:22:46.000000000 +0100
27368 +++ linux-2.6.29-vs2.3.0.36.9-pre2/net/ipv6/inet6_hashtables.c  2009-03-24 20:50:24.000000000 +0100
27369 @@ -16,6 +16,7 @@
27370  
27371  #include <linux/module.h>
27372  #include <linux/random.h>
27373 +#include <linux/vs_inet6.h>
27374  
27375  #include <net/inet_connection_sock.h>
27376  #include <net/inet_hashtables.h>
27377 @@ -76,7 +77,6 @@ struct sock *__inet6_lookup_established(
27378         unsigned int slot = hash & (hashinfo->ehash_size - 1);
27379         struct inet_ehash_bucket *head = &hashinfo->ehash[slot];
27380  
27381 -
27382         rcu_read_lock();
27383  begin:
27384         sk_nulls_for_each_rcu(sk, node, &head->chain) {
27385 @@ -88,7 +88,7 @@ begin:
27386                                 sock_put(sk);
27387                                 goto begin;
27388                         }
27389 -               goto out;
27390 +                       goto out;
27391                 }
27392         }
27393         if (get_nulls_value(node) != slot)
27394 @@ -134,6 +134,9 @@ static int inline compute_score(struct s
27395                         if (!ipv6_addr_equal(&np->rcv_saddr, daddr))
27396                                 return -1;
27397                         score++;
27398 +               } else {
27399 +                       if (!v6_addr_in_nx_info(sk->sk_nx_info, daddr, -1))
27400 +                               return -1;
27401                 }
27402                 if (sk->sk_bound_dev_if) {
27403                         if (sk->sk_bound_dev_if != dif)
27404 diff -NurpP --minimal linux-2.6.29/net/ipv6/ip6_output.c linux-2.6.29-vs2.3.0.36.9-pre2/net/ipv6/ip6_output.c
27405 --- linux-2.6.29/net/ipv6/ip6_output.c  2009-03-24 14:22:47.000000000 +0100
27406 +++ linux-2.6.29-vs2.3.0.36.9-pre2/net/ipv6/ip6_output.c        2009-03-24 14:48:37.000000000 +0100
27407 @@ -951,7 +951,7 @@ static int ip6_dst_lookup_tail(struct so
27408                 err = ipv6_dev_get_saddr(net, ip6_dst_idev(*dst)->dev,
27409                                          &fl->fl6_dst,
27410                                          sk ? inet6_sk(sk)->srcprefs : 0,
27411 -                                        &fl->fl6_src);
27412 +                                        &fl->fl6_src, sk->sk_nx_info);
27413                 if (err)
27414                         goto out_err_release;
27415         }
27416 diff -NurpP --minimal linux-2.6.29/net/ipv6/Kconfig linux-2.6.29-vs2.3.0.36.9-pre2/net/ipv6/Kconfig
27417 --- linux-2.6.29/net/ipv6/Kconfig       2008-12-25 00:26:37.000000000 +0100
27418 +++ linux-2.6.29-vs2.3.0.36.9-pre2/net/ipv6/Kconfig     2009-02-22 22:54:26.000000000 +0100
27419 @@ -4,8 +4,8 @@
27420  
27421  #   IPv6 as module will cause a CRASH if you try to unload it
27422  menuconfig IPV6
27423 -       tristate "The IPv6 protocol"
27424 -       default m
27425 +       bool "The IPv6 protocol"
27426 +       default n
27427         ---help---
27428           This is complemental support for the IP version 6.
27429           You will still be able to do traditional IPv4 networking as well.
27430 diff -NurpP --minimal linux-2.6.29/net/ipv6/ndisc.c linux-2.6.29-vs2.3.0.36.9-pre2/net/ipv6/ndisc.c
27431 --- linux-2.6.29/net/ipv6/ndisc.c       2009-03-24 14:22:47.000000000 +0100
27432 +++ linux-2.6.29-vs2.3.0.36.9-pre2/net/ipv6/ndisc.c     2009-03-24 14:48:37.000000000 +0100
27433 @@ -589,7 +589,7 @@ static void ndisc_send_na(struct net_dev
27434         } else {
27435                 if (ipv6_dev_get_saddr(dev_net(dev), dev, daddr,
27436                                        inet6_sk(dev_net(dev)->ipv6.ndisc_sk)->srcprefs,
27437 -                                      &tmpaddr))
27438 +                                      &tmpaddr, NULL /* FIXME: ? */ ))
27439                         return;
27440                 src_addr = &tmpaddr;
27441         }
27442 diff -NurpP --minimal linux-2.6.29/net/ipv6/raw.c linux-2.6.29-vs2.3.0.36.9-pre2/net/ipv6/raw.c
27443 --- linux-2.6.29/net/ipv6/raw.c 2009-03-24 14:22:47.000000000 +0100
27444 +++ linux-2.6.29-vs2.3.0.36.9-pre2/net/ipv6/raw.c       2009-03-24 14:48:37.000000000 +0100
27445 @@ -29,6 +29,7 @@
27446  #include <linux/icmpv6.h>
27447  #include <linux/netfilter.h>
27448  #include <linux/netfilter_ipv6.h>
27449 +#include <linux/vs_inet6.h>
27450  #include <linux/skbuff.h>
27451  #include <asm/uaccess.h>
27452  #include <asm/ioctls.h>
27453 @@ -281,6 +282,13 @@ static int rawv6_bind(struct sock *sk, s
27454                         }
27455                 }
27456  
27457 +               if (!v6_addr_in_nx_info(sk->sk_nx_info, &addr->sin6_addr, -1)) {
27458 +                       err = -EADDRNOTAVAIL;
27459 +                       if (dev)
27460 +                               dev_put(dev);
27461 +                       goto out;
27462 +               }
27463 +
27464                 /* ipv4 addr of the socket is invalid.  Only the
27465                  * unspecified and mapped address have a v4 equivalent.
27466                  */
27467 diff -NurpP --minimal linux-2.6.29/net/ipv6/route.c linux-2.6.29-vs2.3.0.36.9-pre2/net/ipv6/route.c
27468 --- linux-2.6.29/net/ipv6/route.c       2009-03-24 14:22:47.000000000 +0100
27469 +++ linux-2.6.29-vs2.3.0.36.9-pre2/net/ipv6/route.c     2009-03-24 14:48:37.000000000 +0100
27470 @@ -2254,7 +2254,8 @@ static int rt6_fill_node(struct net *net
27471                 struct inet6_dev *idev = ip6_dst_idev(&rt->u.dst);
27472                 struct in6_addr saddr_buf;
27473                 if (ipv6_dev_get_saddr(net, idev ? idev->dev : NULL,
27474 -                                      dst, 0, &saddr_buf) == 0)
27475 +                       dst, 0, &saddr_buf,
27476 +                       (skb->sk ? skb->sk->sk_nx_info : NULL)) == 0)
27477                         NLA_PUT(skb, RTA_PREFSRC, 16, &saddr_buf);
27478         }
27479  
27480 diff -NurpP --minimal linux-2.6.29/net/ipv6/tcp_ipv6.c linux-2.6.29-vs2.3.0.36.9-pre2/net/ipv6/tcp_ipv6.c
27481 --- linux-2.6.29/net/ipv6/tcp_ipv6.c    2009-03-24 14:22:47.000000000 +0100
27482 +++ linux-2.6.29-vs2.3.0.36.9-pre2/net/ipv6/tcp_ipv6.c  2009-03-24 14:48:37.000000000 +0100
27483 @@ -68,6 +68,7 @@
27484  
27485  #include <linux/crypto.h>
27486  #include <linux/scatterlist.h>
27487 +#include <linux/vs_inet6.h>
27488  
27489  static void    tcp_v6_send_reset(struct sock *sk, struct sk_buff *skb);
27490  static void    tcp_v6_reqsk_send_ack(struct sock *sk, struct sk_buff *skb,
27491 @@ -156,8 +157,15 @@ static int tcp_v6_connect(struct sock *s
27492          *      connect() to INADDR_ANY means loopback (BSD'ism).
27493          */
27494  
27495 -       if(ipv6_addr_any(&usin->sin6_addr))
27496 -               usin->sin6_addr.s6_addr[15] = 0x1;
27497 +       if(ipv6_addr_any(&usin->sin6_addr)) {
27498 +               struct nx_info *nxi =  sk->sk_nx_info;
27499 +
27500 +               if (nxi && nx_info_has_v6(nxi))
27501 +                       /* FIXME: remap lback? */
27502 +                       usin->sin6_addr = nxi->v6.ip;
27503 +               else
27504 +                       usin->sin6_addr.s6_addr[15] = 0x1;
27505 +       }
27506  
27507         addr_type = ipv6_addr_type(&usin->sin6_addr);
27508  
27509 diff -NurpP --minimal linux-2.6.29/net/ipv6/udp.c linux-2.6.29-vs2.3.0.36.9-pre2/net/ipv6/udp.c
27510 --- linux-2.6.29/net/ipv6/udp.c 2009-03-24 14:22:47.000000000 +0100
27511 +++ linux-2.6.29-vs2.3.0.36.9-pre2/net/ipv6/udp.c       2009-03-24 20:56:49.000000000 +0100
27512 @@ -47,6 +47,7 @@
27513  
27514  #include <linux/proc_fs.h>
27515  #include <linux/seq_file.h>
27516 +#include <linux/vs_inet6.h>
27517  #include "udp_impl.h"
27518  
27519  int udp_v6_get_port(struct sock *sk, unsigned short snum)
27520 @@ -77,6 +78,10 @@ static inline int compute_score(struct s
27521                         if (!ipv6_addr_equal(&np->rcv_saddr, daddr))
27522                                 return -1;
27523                         score++;
27524 +               } else {
27525 +                       /* block non nx_info ips */
27526 +                       if (!v6_addr_in_nx_info(sk->sk_nx_info, daddr, -1))
27527 +                               return -1;
27528                 }
27529                 if (!ipv6_addr_any(&np->daddr)) {
27530                         if (!ipv6_addr_equal(&np->daddr, saddr))
27531 diff -NurpP --minimal linux-2.6.29/net/ipv6/xfrm6_policy.c linux-2.6.29-vs2.3.0.36.9-pre2/net/ipv6/xfrm6_policy.c
27532 --- linux-2.6.29/net/ipv6/xfrm6_policy.c        2009-03-24 14:22:47.000000000 +0100
27533 +++ linux-2.6.29-vs2.3.0.36.9-pre2/net/ipv6/xfrm6_policy.c      2009-03-24 14:48:37.000000000 +0100
27534 @@ -63,7 +63,7 @@ static int xfrm6_get_saddr(struct net *n
27535         dev = ip6_dst_idev(dst)->dev;
27536         ipv6_dev_get_saddr(dev_net(dev), dev,
27537                            (struct in6_addr *)&daddr->a6, 0,
27538 -                          (struct in6_addr *)&saddr->a6);
27539 +                          (struct in6_addr *)&saddr->a6, NULL);
27540         dst_release(dst);
27541         return 0;
27542  }
27543 diff -NurpP --minimal linux-2.6.29/net/netlink/af_netlink.c linux-2.6.29-vs2.3.0.36.9-pre2/net/netlink/af_netlink.c
27544 --- linux-2.6.29/net/netlink/af_netlink.c       2009-03-24 14:22:47.000000000 +0100
27545 +++ linux-2.6.29-vs2.3.0.36.9-pre2/net/netlink/af_netlink.c     2009-03-24 14:48:37.000000000 +0100
27546 @@ -55,6 +55,9 @@
27547  #include <linux/types.h>
27548  #include <linux/audit.h>
27549  #include <linux/mutex.h>
27550 +#include <linux/vs_context.h>
27551 +#include <linux/vs_network.h>
27552 +#include <linux/vs_limit.h>
27553  
27554  #include <net/net_namespace.h>
27555  #include <net/sock.h>
27556 @@ -1776,6 +1779,8 @@ static struct sock *netlink_seq_socket_i
27557                         sk_for_each(s, node, &hash->table[j]) {
27558                                 if (sock_net(s) != seq_file_net(seq))
27559                                         continue;
27560 +                               if (!nx_check(s->sk_nid, VS_WATCH_P | VS_IDENT))
27561 +                                       continue;
27562                                 if (off == pos) {
27563                                         iter->link = i;
27564                                         iter->hash_idx = j;
27565 @@ -1810,7 +1815,8 @@ static void *netlink_seq_next(struct seq
27566         s = v;
27567         do {
27568                 s = sk_next(s);
27569 -       } while (s && sock_net(s) != seq_file_net(seq));
27570 +       } while (s && (sock_net(s) != seq_file_net(seq) ||
27571 +               !nx_check(s->sk_nid, VS_WATCH_P | VS_IDENT)));
27572         if (s)
27573                 return s;
27574  
27575 @@ -1822,7 +1828,8 @@ static void *netlink_seq_next(struct seq
27576  
27577                 for (; j <= hash->mask; j++) {
27578                         s = sk_head(&hash->table[j]);
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                                 s = sk_next(s);
27583                         if (s) {
27584                                 iter->link = i;
27585 diff -NurpP --minimal linux-2.6.29/net/sctp/ipv6.c linux-2.6.29-vs2.3.0.36.9-pre2/net/sctp/ipv6.c
27586 --- linux-2.6.29/net/sctp/ipv6.c        2009-03-24 14:22:48.000000000 +0100
27587 +++ linux-2.6.29-vs2.3.0.36.9-pre2/net/sctp/ipv6.c      2009-03-24 20:58:14.000000000 +0100
27588 @@ -317,7 +317,8 @@ static void sctp_v6_get_saddr(struct sct
27589                                    dst ? ip6_dst_idev(dst)->dev : NULL,
27590                                    &daddr->v6.sin6_addr,
27591                                    inet6_sk(&sk->inet.sk)->srcprefs,
27592 -                                  &saddr->v6.sin6_addr);
27593 +                                  &saddr->v6.sin6_addr,
27594 +                                  asoc->base.sk->sk_nx_info);
27595                 SCTP_DEBUG_PRINTK("saddr from ipv6_get_saddr: %pI6\n",
27596                                   &saddr->v6.sin6_addr);
27597                 return;
27598 diff -NurpP --minimal linux-2.6.29/net/socket.c linux-2.6.29-vs2.3.0.36.9-pre2/net/socket.c
27599 --- linux-2.6.29/net/socket.c   2009-03-24 14:22:48.000000000 +0100
27600 +++ linux-2.6.29-vs2.3.0.36.9-pre2/net/socket.c 2009-03-24 14:48:37.000000000 +0100
27601 @@ -95,6 +95,10 @@
27602  
27603  #include <net/sock.h>
27604  #include <linux/netfilter.h>
27605 +#include <linux/vs_base.h>
27606 +#include <linux/vs_socket.h>
27607 +#include <linux/vs_inet.h>
27608 +#include <linux/vs_inet6.h>
27609  
27610  static int sock_no_open(struct inode *irrelevant, struct file *dontcare);
27611  static ssize_t sock_aio_read(struct kiocb *iocb, const struct iovec *iov,
27612 @@ -549,7 +553,7 @@ static inline int __sock_sendmsg(struct 
27613                                  struct msghdr *msg, size_t size)
27614  {
27615         struct sock_iocb *si = kiocb_to_siocb(iocb);
27616 -       int err;
27617 +       int err, len;
27618  
27619         si->sock = sock;
27620         si->scm = NULL;
27621 @@ -560,7 +564,22 @@ static inline int __sock_sendmsg(struct 
27622         if (err)
27623                 return err;
27624  
27625 -       return sock->ops->sendmsg(iocb, sock, msg, size);
27626 +       len = sock->ops->sendmsg(iocb, sock, msg, size);
27627 +       if (sock->sk) {
27628 +               if (len == size)
27629 +                       vx_sock_send(sock->sk, size);
27630 +               else
27631 +                       vx_sock_fail(sock->sk, size);
27632 +       }
27633 +       vxdprintk(VXD_CBIT(net, 7),
27634 +               "__sock_sendmsg: %p[%p,%p,%p;%d/%d]:%d/%d",
27635 +               sock, sock->sk,
27636 +               (sock->sk)?sock->sk->sk_nx_info:0,
27637 +               (sock->sk)?sock->sk->sk_vx_info:0,
27638 +               (sock->sk)?sock->sk->sk_xid:0,
27639 +               (sock->sk)?sock->sk->sk_nid:0,
27640 +               (unsigned int)size, len);
27641 +       return len;
27642  }
27643  
27644  int sock_sendmsg(struct socket *sock, struct msghdr *msg, size_t size)
27645 @@ -629,7 +648,7 @@ EXPORT_SYMBOL_GPL(__sock_recv_timestamp)
27646  static inline int __sock_recvmsg(struct kiocb *iocb, struct socket *sock,
27647                                  struct msghdr *msg, size_t size, int flags)
27648  {
27649 -       int err;
27650 +       int err, len;
27651         struct sock_iocb *si = kiocb_to_siocb(iocb);
27652  
27653         si->sock = sock;
27654 @@ -642,7 +661,18 @@ static inline int __sock_recvmsg(struct 
27655         if (err)
27656                 return err;
27657  
27658 -       return sock->ops->recvmsg(iocb, sock, msg, size, flags);
27659 +       len = sock->ops->recvmsg(iocb, sock, msg, size, flags);
27660 +       if ((len >= 0) && sock->sk)
27661 +               vx_sock_recv(sock->sk, len);
27662 +       vxdprintk(VXD_CBIT(net, 7),
27663 +               "__sock_recvmsg: %p[%p,%p,%p;%d/%d]:%d/%d",
27664 +               sock, sock->sk,
27665 +               (sock->sk)?sock->sk->sk_nx_info:0,
27666 +               (sock->sk)?sock->sk->sk_vx_info:0,
27667 +               (sock->sk)?sock->sk->sk_xid:0,
27668 +               (sock->sk)?sock->sk->sk_nid:0,
27669 +               (unsigned int)size, len);
27670 +       return len;
27671  }
27672  
27673  int sock_recvmsg(struct socket *sock, struct msghdr *msg,
27674 @@ -1106,6 +1136,13 @@ static int __sock_create(struct net *net
27675         if (type < 0 || type >= SOCK_MAX)
27676                 return -EINVAL;
27677  
27678 +       if (!nx_check(0, VS_ADMIN)) {
27679 +               if (family == PF_INET && !current_nx_info_has_v4())
27680 +                       return -EAFNOSUPPORT;
27681 +               if (family == PF_INET6 && !current_nx_info_has_v6())
27682 +                       return -EAFNOSUPPORT;
27683 +       }
27684 +
27685         /* Compatibility.
27686  
27687            This uglymoron is moved from INET layer to here to avoid
27688 @@ -1238,6 +1275,7 @@ SYSCALL_DEFINE3(socket, int, family, int
27689         if (retval < 0)
27690                 goto out;
27691  
27692 +       set_bit(SOCK_USER_SOCKET, &sock->flags);
27693         retval = sock_map_fd(sock, flags & (O_CLOEXEC | O_NONBLOCK));
27694         if (retval < 0)
27695                 goto out_release;
27696 @@ -1279,10 +1317,12 @@ SYSCALL_DEFINE4(socketpair, int, family,
27697         err = sock_create(family, type, protocol, &sock1);
27698         if (err < 0)
27699                 goto out;
27700 +       set_bit(SOCK_USER_SOCKET, &sock1->flags);
27701  
27702         err = sock_create(family, type, protocol, &sock2);
27703         if (err < 0)
27704                 goto out_release_1;
27705 +       set_bit(SOCK_USER_SOCKET, &sock2->flags);
27706  
27707         err = sock1->ops->socketpair(sock1, sock2);
27708         if (err < 0)
27709 diff -NurpP --minimal linux-2.6.29/net/sunrpc/auth.c linux-2.6.29-vs2.3.0.36.9-pre2/net/sunrpc/auth.c
27710 --- linux-2.6.29/net/sunrpc/auth.c      2009-03-24 14:22:48.000000000 +0100
27711 +++ linux-2.6.29-vs2.3.0.36.9-pre2/net/sunrpc/auth.c    2009-03-24 21:00:49.000000000 +0100
27712 @@ -14,6 +14,7 @@
27713  #include <linux/hash.h>
27714  #include <linux/sunrpc/clnt.h>
27715  #include <linux/spinlock.h>
27716 +#include <linux/vs_tag.h>
27717  
27718  #ifdef RPC_DEBUG
27719  # define RPCDBG_FACILITY       RPCDBG_AUTH
27720 @@ -360,6 +361,7 @@ rpcauth_lookupcred(struct rpc_auth *auth
27721         memset(&acred, 0, sizeof(acred));
27722         acred.uid = cred->fsuid;
27723         acred.gid = cred->fsgid;
27724 +       acred.tag = dx_current_tag();
27725         acred.group_info = get_group_info(((struct cred *)cred)->group_info);
27726  
27727         ret = auth->au_ops->lookup_cred(auth, &acred, flags);
27728 @@ -400,6 +402,7 @@ rpcauth_bind_root_cred(struct rpc_task *
27729         struct auth_cred acred = {
27730                 .uid = 0,
27731                 .gid = 0,
27732 +               .tag = dx_current_tag(),
27733         };
27734         struct rpc_cred *ret;
27735  
27736 diff -NurpP --minimal linux-2.6.29/net/sunrpc/auth_unix.c linux-2.6.29-vs2.3.0.36.9-pre2/net/sunrpc/auth_unix.c
27737 --- linux-2.6.29/net/sunrpc/auth_unix.c 2008-12-25 00:26:37.000000000 +0100
27738 +++ linux-2.6.29-vs2.3.0.36.9-pre2/net/sunrpc/auth_unix.c       2009-02-22 22:54:26.000000000 +0100
27739 @@ -11,12 +11,14 @@
27740  #include <linux/module.h>
27741  #include <linux/sunrpc/clnt.h>
27742  #include <linux/sunrpc/auth.h>
27743 +#include <linux/vs_tag.h>
27744  
27745  #define NFS_NGROUPS    16
27746  
27747  struct unx_cred {
27748         struct rpc_cred         uc_base;
27749         gid_t                   uc_gid;
27750 +       tag_t                   uc_tag;
27751         gid_t                   uc_gids[NFS_NGROUPS];
27752  };
27753  #define uc_uid                 uc_base.cr_uid
27754 @@ -78,6 +80,7 @@ unx_create_cred(struct rpc_auth *auth, s
27755                 groups = NFS_NGROUPS;
27756  
27757         cred->uc_gid = acred->gid;
27758 +       cred->uc_tag = acred->tag;
27759         for (i = 0; i < groups; i++)
27760                 cred->uc_gids[i] = GROUP_AT(acred->group_info, i);
27761         if (i < NFS_NGROUPS)
27762 @@ -119,7 +122,9 @@ unx_match(struct auth_cred *acred, struc
27763         unsigned int i;
27764  
27765  
27766 -       if (cred->uc_uid != acred->uid || cred->uc_gid != acred->gid)
27767 +       if (cred->uc_uid != acred->uid ||
27768 +               cred->uc_gid != acred->gid ||
27769 +               cred->uc_tag != acred->tag)
27770                 return 0;
27771  
27772         if (acred->group_info != NULL)
27773 @@ -142,7 +147,7 @@ unx_marshal(struct rpc_task *task, __be3
27774         struct rpc_clnt *clnt = task->tk_client;
27775         struct unx_cred *cred = container_of(task->tk_msg.rpc_cred, struct unx_cred, uc_base);
27776         __be32          *base, *hold;
27777 -       int             i;
27778 +       int             i, tag;
27779  
27780         *p++ = htonl(RPC_AUTH_UNIX);
27781         base = p++;
27782 @@ -152,9 +157,12 @@ unx_marshal(struct rpc_task *task, __be3
27783          * Copy the UTS nodename captured when the client was created.
27784          */
27785         p = xdr_encode_array(p, clnt->cl_nodename, clnt->cl_nodelen);
27786 +       tag = task->tk_client->cl_tag;
27787  
27788 -       *p++ = htonl((u32) cred->uc_uid);
27789 -       *p++ = htonl((u32) cred->uc_gid);
27790 +       *p++ = htonl((u32) TAGINO_UID(tag,
27791 +               cred->uc_uid, cred->uc_tag));
27792 +       *p++ = htonl((u32) TAGINO_GID(tag,
27793 +               cred->uc_gid, cred->uc_tag));
27794         hold = p++;
27795         for (i = 0; i < 16 && cred->uc_gids[i] != (gid_t) NOGROUP; i++)
27796                 *p++ = htonl((u32) cred->uc_gids[i]);
27797 diff -NurpP --minimal linux-2.6.29/net/sunrpc/clnt.c linux-2.6.29-vs2.3.0.36.9-pre2/net/sunrpc/clnt.c
27798 --- linux-2.6.29/net/sunrpc/clnt.c      2009-03-24 14:22:48.000000000 +0100
27799 +++ linux-2.6.29-vs2.3.0.36.9-pre2/net/sunrpc/clnt.c    2009-03-24 14:48:37.000000000 +0100
27800 @@ -32,6 +32,7 @@
27801  #include <linux/utsname.h>
27802  #include <linux/workqueue.h>
27803  #include <linux/in6.h>
27804 +#include <linux/vs_cvirt.h>
27805  
27806  #include <linux/sunrpc/clnt.h>
27807  #include <linux/sunrpc/rpc_pipe_fs.h>
27808 @@ -335,6 +336,9 @@ struct rpc_clnt *rpc_create(struct rpc_c
27809         if (!(args->flags & RPC_CLNT_CREATE_QUIET))
27810                 clnt->cl_chatty = 1;
27811  
27812 +       /* TODO: handle RPC_CLNT_CREATE_TAGGED
27813 +       if (args->flags & RPC_CLNT_CREATE_TAGGED)
27814 +               clnt->cl_tag = 1; */
27815         return clnt;
27816  }
27817  EXPORT_SYMBOL_GPL(rpc_create);
27818 diff -NurpP --minimal linux-2.6.29/net/unix/af_unix.c linux-2.6.29-vs2.3.0.36.9-pre2/net/unix/af_unix.c
27819 --- linux-2.6.29/net/unix/af_unix.c     2009-03-24 14:22:48.000000000 +0100
27820 +++ linux-2.6.29-vs2.3.0.36.9-pre2/net/unix/af_unix.c   2009-03-24 14:48:37.000000000 +0100
27821 @@ -114,6 +114,8 @@
27822  #include <linux/mount.h>
27823  #include <net/checksum.h>
27824  #include <linux/security.h>
27825 +#include <linux/vs_context.h>
27826 +#include <linux/vs_limit.h>
27827  
27828  static struct hlist_head unix_socket_table[UNIX_HASH_SIZE + 1];
27829  static DEFINE_SPINLOCK(unix_table_lock);
27830 @@ -258,6 +260,8 @@ static struct sock *__unix_find_socket_b
27831                 if (!net_eq(sock_net(s), net))
27832                         continue;
27833  
27834 +               if (!nx_check(s->sk_nid, VS_WATCH_P | VS_IDENT))
27835 +                       continue;
27836                 if (u->addr->len == len &&
27837                     !memcmp(u->addr->name, sunname, len))
27838                         goto found;
27839 @@ -2110,6 +2114,8 @@ static struct sock *unix_seq_idx(struct 
27840         for (s = first_unix_socket(&iter->i); s; s = next_unix_socket(&iter->i, s)) {
27841                 if (sock_net(s) != seq_file_net(seq))
27842                         continue;
27843 +               if (!nx_check(s->sk_nid, VS_WATCH_P | VS_IDENT))
27844 +                       continue;
27845                 if (off == pos)
27846                         return s;
27847                 ++off;
27848 @@ -2134,7 +2140,8 @@ static void *unix_seq_next(struct seq_fi
27849                 sk = first_unix_socket(&iter->i);
27850         else
27851                 sk = next_unix_socket(&iter->i, sk);
27852 -       while (sk && (sock_net(sk) != seq_file_net(seq)))
27853 +       while (sk && (sock_net(sk) != seq_file_net(seq) ||
27854 +               !nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT)))
27855                 sk = next_unix_socket(&iter->i, sk);
27856         return sk;
27857  }
27858 diff -NurpP --minimal linux-2.6.29/net/x25/af_x25.c linux-2.6.29-vs2.3.0.36.9-pre2/net/x25/af_x25.c
27859 --- linux-2.6.29/net/x25/af_x25.c       2008-12-25 00:26:37.000000000 +0100
27860 +++ linux-2.6.29-vs2.3.0.36.9-pre2/net/x25/af_x25.c     2009-02-22 22:54:26.000000000 +0100
27861 @@ -506,7 +506,10 @@ static int x25_create(struct net *net, s
27862  
27863         x25 = x25_sk(sk);
27864  
27865 -       sock_init_data(sock, sk);
27866 +       sk->sk_socket = sock;
27867 +       sk->sk_type = sock->type;
27868 +       sk->sk_sleep = &sock->wait;
27869 +       sock->sk = sk;
27870  
27871         x25_init_timers(sk);
27872  
27873 diff -NurpP --minimal linux-2.6.29/scripts/checksyscalls.sh linux-2.6.29-vs2.3.0.36.9-pre2/scripts/checksyscalls.sh
27874 --- linux-2.6.29/scripts/checksyscalls.sh       2008-12-25 00:26:37.000000000 +0100
27875 +++ linux-2.6.29-vs2.3.0.36.9-pre2/scripts/checksyscalls.sh     2009-02-22 22:54:26.000000000 +0100
27876 @@ -108,7 +108,6 @@ cat << EOF
27877  #define __IGNORE_afs_syscall
27878  #define __IGNORE_getpmsg
27879  #define __IGNORE_putpmsg
27880 -#define __IGNORE_vserver
27881  EOF
27882  }
27883  
27884 diff -NurpP --minimal linux-2.6.29/security/commoncap.c linux-2.6.29-vs2.3.0.36.9-pre2/security/commoncap.c
27885 --- linux-2.6.29/security/commoncap.c   2009-03-24 14:23:21.000000000 +0100
27886 +++ linux-2.6.29-vs2.3.0.36.9-pre2/security/commoncap.c 2009-03-25 00:34:48.000000000 +0100
27887 @@ -27,10 +27,11 @@
27888  #include <linux/sched.h>
27889  #include <linux/prctl.h>
27890  #include <linux/securebits.h>
27891 +#include <linux/vs_context.h>
27892  
27893  int cap_netlink_send(struct sock *sk, struct sk_buff *skb)
27894  {
27895 -       NETLINK_CB(skb).eff_cap = current_cap();
27896 +       NETLINK_CB(skb).eff_cap = vx_mbcaps(current_cap());
27897         return 0;
27898  }
27899  
27900 @@ -40,6 +41,7 @@ int cap_netlink_recv(struct sk_buff *skb
27901                 return -EPERM;
27902         return 0;
27903  }
27904 +
27905  EXPORT_SYMBOL(cap_netlink_recv);
27906  
27907  /**
27908 @@ -60,7 +62,22 @@ EXPORT_SYMBOL(cap_netlink_recv);
27909  int cap_capable(struct task_struct *tsk, const struct cred *cred, int cap,
27910                 int audit)
27911  {
27912 -       return cap_raised(cred->cap_effective, cap) ? 0 : -EPERM;
27913 +       struct vx_info *vxi = tsk->vx_info;
27914 +
27915 +#if 0
27916 +       printk("cap_capable() VXF_STATE_SETUP = %llx, raised = %x, eff = %08x:%08x\n",
27917 +               vx_info_flags(vxi, VXF_STATE_SETUP, 0),
27918 +               cap_raised(tsk->cap_effective, cap),
27919 +               tsk->cap_effective.cap[1], tsk->cap_effective.cap[0]);
27920 +#endif
27921 +
27922 +       /* special case SETUP */
27923 +       if (vx_info_flags(vxi, VXF_STATE_SETUP, 0) &&
27924 +               /* FIXME: maybe use cred instead? */
27925 +               cap_raised(tsk->cred->cap_effective, cap))
27926 +               return 0;
27927 +
27928 +       return vx_cap_raised(vxi, cred->cap_effective, cap) ? 0 : -EPERM;
27929  }
27930  
27931  /**
27932 @@ -586,7 +603,7 @@ int cap_inode_setxattr(struct dentry *de
27933  
27934         if (!strncmp(name, XATTR_SECURITY_PREFIX,
27935                      sizeof(XATTR_SECURITY_PREFIX) - 1)  &&
27936 -           !capable(CAP_SYS_ADMIN))
27937 +               !vx_capable(CAP_SYS_ADMIN, VXC_FS_SECURITY))
27938                 return -EPERM;
27939         return 0;
27940  }
27941 @@ -931,7 +948,8 @@ error:
27942   */
27943  int cap_syslog(int type)
27944  {
27945 -       if ((type != 3 && type != 10) && !capable(CAP_SYS_ADMIN))
27946 +       if ((type != 3 && type != 10) &&
27947 +               !vx_capable(CAP_SYS_ADMIN, VXC_SYSLOG))
27948                 return -EPERM;
27949         return 0;
27950  }
27951 @@ -953,3 +971,4 @@ int cap_vm_enough_memory(struct mm_struc
27952                 cap_sys_admin = 1;
27953         return __vm_enough_memory(mm, pages, cap_sys_admin);
27954  }
27955 +
27956 diff -NurpP --minimal linux-2.6.29/security/selinux/hooks.c linux-2.6.29-vs2.3.0.36.9-pre2/security/selinux/hooks.c
27957 --- linux-2.6.29/security/selinux/hooks.c       2009-03-24 14:23:21.000000000 +0100
27958 +++ linux-2.6.29-vs2.3.0.36.9-pre2/security/selinux/hooks.c     2009-03-24 14:48:37.000000000 +0100
27959 @@ -64,7 +64,6 @@
27960  #include <linux/dccp.h>
27961  #include <linux/quota.h>
27962  #include <linux/un.h>          /* for Unix socket types */
27963 -#include <net/af_unix.h>       /* for Unix socket types */
27964  #include <linux/parser.h>
27965  #include <linux/nfs_mount.h>
27966  #include <net/ipv6.h>
This page took 2.254406 seconds and 4 git commands to generate.