]> git.pld-linux.org Git - packages/kernel.git/blob - kernel-vserver-2.3.patch
- resolved conflict with tuxonice
[packages/kernel.git] / kernel-vserver-2.3.patch
1 diff -NurpP --minimal linux-2.6.29.1/arch/alpha/Kconfig linux-2.6.29.1-vs2.3.0.36.9-pre5/arch/alpha/Kconfig
2 --- linux-2.6.29.1/arch/alpha/Kconfig   2009-03-24 14:18:07.000000000 +0100
3 +++ linux-2.6.29.1-vs2.3.0.36.9-pre5/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.1/arch/alpha/kernel/entry.S linux-2.6.29.1-vs2.3.0.36.9-pre5/arch/alpha/kernel/entry.S
14 --- linux-2.6.29.1/arch/alpha/kernel/entry.S    2009-03-24 14:18:07.000000000 +0100
15 +++ linux-2.6.29.1-vs2.3.0.36.9-pre5/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.1/arch/alpha/kernel/osf_sys.c linux-2.6.29.1-vs2.3.0.36.9-pre5/arch/alpha/kernel/osf_sys.c
49 --- linux-2.6.29.1/arch/alpha/kernel/osf_sys.c  2009-03-24 14:18:07.000000000 +0100
50 +++ linux-2.6.29.1-vs2.3.0.36.9-pre5/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.1/arch/alpha/kernel/ptrace.c linux-2.6.29.1-vs2.3.0.36.9-pre5/arch/alpha/kernel/ptrace.c
61 --- linux-2.6.29.1/arch/alpha/kernel/ptrace.c   2008-12-25 00:26:37.000000000 +0100
62 +++ linux-2.6.29.1-vs2.3.0.36.9-pre5/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.1/arch/alpha/kernel/systbls.S linux-2.6.29.1-vs2.3.0.36.9-pre5/arch/alpha/kernel/systbls.S
72 --- linux-2.6.29.1/arch/alpha/kernel/systbls.S  2009-03-24 14:18:08.000000000 +0100
73 +++ linux-2.6.29.1-vs2.3.0.36.9-pre5/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.1/arch/alpha/kernel/traps.c linux-2.6.29.1-vs2.3.0.36.9-pre5/arch/alpha/kernel/traps.c
84 --- linux-2.6.29.1/arch/alpha/kernel/traps.c    2008-12-25 00:26:37.000000000 +0100
85 +++ linux-2.6.29.1-vs2.3.0.36.9-pre5/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.1/arch/alpha/mm/fault.c linux-2.6.29.1-vs2.3.0.36.9-pre5/arch/alpha/mm/fault.c
97 --- linux-2.6.29.1/arch/alpha/mm/fault.c        2008-12-25 00:26:37.000000000 +0100
98 +++ linux-2.6.29.1-vs2.3.0.36.9-pre5/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.1/arch/arm/Kconfig linux-2.6.29.1-vs2.3.0.36.9-pre5/arch/arm/Kconfig
111 --- linux-2.6.29.1/arch/arm/Kconfig     2009-03-24 14:18:08.000000000 +0100
112 +++ linux-2.6.29.1-vs2.3.0.36.9-pre5/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.1/arch/arm/kernel/calls.S linux-2.6.29.1-vs2.3.0.36.9-pre5/arch/arm/kernel/calls.S
123 --- linux-2.6.29.1/arch/arm/kernel/calls.S      2009-03-24 14:18:09.000000000 +0100
124 +++ linux-2.6.29.1-vs2.3.0.36.9-pre5/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.1/arch/arm/kernel/process.c linux-2.6.29.1-vs2.3.0.36.9-pre5/arch/arm/kernel/process.c
135 --- linux-2.6.29.1/arch/arm/kernel/process.c    2008-12-25 00:26:37.000000000 +0100
136 +++ linux-2.6.29.1-vs2.3.0.36.9-pre5/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.1/arch/arm/kernel/traps.c linux-2.6.29.1-vs2.3.0.36.9-pre5/arch/arm/kernel/traps.c
148 --- linux-2.6.29.1/arch/arm/kernel/traps.c      2008-12-25 00:26:37.000000000 +0100
149 +++ linux-2.6.29.1-vs2.3.0.36.9-pre5/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.1/arch/arm/mm/fault.c linux-2.6.29.1-vs2.3.0.36.9-pre5/arch/arm/mm/fault.c
162 --- linux-2.6.29.1/arch/arm/mm/fault.c  2009-03-24 14:18:17.000000000 +0100
163 +++ linux-2.6.29.1-vs2.3.0.36.9-pre5/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.1/arch/cris/Kconfig linux-2.6.29.1-vs2.3.0.36.9-pre5/arch/cris/Kconfig
175 --- linux-2.6.29.1/arch/cris/Kconfig    2009-03-24 14:18:23.000000000 +0100
176 +++ linux-2.6.29.1-vs2.3.0.36.9-pre5/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.1/arch/frv/kernel/kernel_thread.S linux-2.6.29.1-vs2.3.0.36.9-pre5/arch/frv/kernel/kernel_thread.S
187 --- linux-2.6.29.1/arch/frv/kernel/kernel_thread.S      2008-12-25 00:26:37.000000000 +0100
188 +++ linux-2.6.29.1-vs2.3.0.36.9-pre5/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.1/arch/h8300/Kconfig linux-2.6.29.1-vs2.3.0.36.9-pre5/arch/h8300/Kconfig
199 --- linux-2.6.29.1/arch/h8300/Kconfig   2009-03-24 14:18:24.000000000 +0100
200 +++ linux-2.6.29.1-vs2.3.0.36.9-pre5/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.1/arch/ia64/ia32/ia32_entry.S linux-2.6.29.1-vs2.3.0.36.9-pre5/arch/ia64/ia32/ia32_entry.S
211 --- linux-2.6.29.1/arch/ia64/ia32/ia32_entry.S  2009-03-24 14:18:24.000000000 +0100
212 +++ linux-2.6.29.1-vs2.3.0.36.9-pre5/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.1/arch/ia64/Kconfig linux-2.6.29.1-vs2.3.0.36.9-pre5/arch/ia64/Kconfig
223 --- linux-2.6.29.1/arch/ia64/Kconfig    2009-03-24 14:18:24.000000000 +0100
224 +++ linux-2.6.29.1-vs2.3.0.36.9-pre5/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.1/arch/ia64/kernel/entry.S linux-2.6.29.1-vs2.3.0.36.9-pre5/arch/ia64/kernel/entry.S
235 --- linux-2.6.29.1/arch/ia64/kernel/entry.S     2009-03-24 14:18:25.000000000 +0100
236 +++ linux-2.6.29.1-vs2.3.0.36.9-pre5/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.1/arch/ia64/kernel/perfmon.c linux-2.6.29.1-vs2.3.0.36.9-pre5/arch/ia64/kernel/perfmon.c
247 --- linux-2.6.29.1/arch/ia64/kernel/perfmon.c   2009-03-24 14:18:25.000000000 +0100
248 +++ linux-2.6.29.1-vs2.3.0.36.9-pre5/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.1/arch/ia64/kernel/process.c linux-2.6.29.1-vs2.3.0.36.9-pre5/arch/ia64/kernel/process.c
267 --- linux-2.6.29.1/arch/ia64/kernel/process.c   2008-12-25 00:26:37.000000000 +0100
268 +++ linux-2.6.29.1-vs2.3.0.36.9-pre5/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.1/arch/ia64/kernel/ptrace.c linux-2.6.29.1-vs2.3.0.36.9-pre5/arch/ia64/kernel/ptrace.c
281 --- linux-2.6.29.1/arch/ia64/kernel/ptrace.c    2008-12-25 00:26:37.000000000 +0100
282 +++ linux-2.6.29.1-vs2.3.0.36.9-pre5/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.1/arch/ia64/kernel/traps.c linux-2.6.29.1-vs2.3.0.36.9-pre5/arch/ia64/kernel/traps.c
292 --- linux-2.6.29.1/arch/ia64/kernel/traps.c     2008-12-25 00:26:37.000000000 +0100
293 +++ linux-2.6.29.1-vs2.3.0.36.9-pre5/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.1/arch/ia64/mm/fault.c linux-2.6.29.1-vs2.3.0.36.9-pre5/arch/ia64/mm/fault.c
319 --- linux-2.6.29.1/arch/ia64/mm/fault.c 2008-12-25 00:26:37.000000000 +0100
320 +++ linux-2.6.29.1-vs2.3.0.36.9-pre5/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.1/arch/m32r/kernel/traps.c linux-2.6.29.1-vs2.3.0.36.9-pre5/arch/m32r/kernel/traps.c
330 --- linux-2.6.29.1/arch/m32r/kernel/traps.c     2008-12-25 00:26:37.000000000 +0100
331 +++ linux-2.6.29.1-vs2.3.0.36.9-pre5/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.1/arch/m68k/Kconfig linux-2.6.29.1-vs2.3.0.36.9-pre5/arch/m68k/Kconfig
345 --- linux-2.6.29.1/arch/m68k/Kconfig    2009-03-24 14:18:26.000000000 +0100
346 +++ linux-2.6.29.1-vs2.3.0.36.9-pre5/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.1/arch/m68k/kernel/ptrace.c linux-2.6.29.1-vs2.3.0.36.9-pre5/arch/m68k/kernel/ptrace.c
357 --- linux-2.6.29.1/arch/m68k/kernel/ptrace.c    2008-12-25 00:26:37.000000000 +0100
358 +++ linux-2.6.29.1-vs2.3.0.36.9-pre5/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.1/arch/m68k/kernel/traps.c linux-2.6.29.1-vs2.3.0.36.9-pre5/arch/m68k/kernel/traps.c
377 --- linux-2.6.29.1/arch/m68k/kernel/traps.c     2009-03-24 14:18:26.000000000 +0100
378 +++ linux-2.6.29.1-vs2.3.0.36.9-pre5/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.1/arch/m68knommu/Kconfig linux-2.6.29.1-vs2.3.0.36.9-pre5/arch/m68knommu/Kconfig
391 --- linux-2.6.29.1/arch/m68knommu/Kconfig       2009-03-24 14:18:27.000000000 +0100
392 +++ linux-2.6.29.1-vs2.3.0.36.9-pre5/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.1/arch/m68knommu/kernel/traps.c linux-2.6.29.1-vs2.3.0.36.9-pre5/arch/m68knommu/kernel/traps.c
403 --- linux-2.6.29.1/arch/m68knommu/kernel/traps.c        2008-12-25 00:26:37.000000000 +0100
404 +++ linux-2.6.29.1-vs2.3.0.36.9-pre5/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.1/arch/mips/Kconfig linux-2.6.29.1-vs2.3.0.36.9-pre5/arch/mips/Kconfig
418 --- linux-2.6.29.1/arch/mips/Kconfig    2009-03-24 14:18:29.000000000 +0100
419 +++ linux-2.6.29.1-vs2.3.0.36.9-pre5/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.1/arch/mips/kernel/ptrace.c linux-2.6.29.1-vs2.3.0.36.9-pre5/arch/mips/kernel/ptrace.c
430 --- linux-2.6.29.1/arch/mips/kernel/ptrace.c    2008-12-25 00:26:37.000000000 +0100
431 +++ linux-2.6.29.1-vs2.3.0.36.9-pre5/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.1/arch/mips/kernel/scall32-o32.S linux-2.6.29.1-vs2.3.0.36.9-pre5/arch/mips/kernel/scall32-o32.S
451 --- linux-2.6.29.1/arch/mips/kernel/scall32-o32.S       2009-03-24 14:18:31.000000000 +0100
452 +++ linux-2.6.29.1-vs2.3.0.36.9-pre5/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.1/arch/mips/kernel/scall64-64.S linux-2.6.29.1-vs2.3.0.36.9-pre5/arch/mips/kernel/scall64-64.S
463 --- linux-2.6.29.1/arch/mips/kernel/scall64-64.S        2009-03-24 14:18:31.000000000 +0100
464 +++ linux-2.6.29.1-vs2.3.0.36.9-pre5/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.1/arch/mips/kernel/scall64-n32.S linux-2.6.29.1-vs2.3.0.36.9-pre5/arch/mips/kernel/scall64-n32.S
475 --- linux-2.6.29.1/arch/mips/kernel/scall64-n32.S       2009-03-24 14:18:31.000000000 +0100
476 +++ linux-2.6.29.1-vs2.3.0.36.9-pre5/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.1/arch/mips/kernel/scall64-o32.S linux-2.6.29.1-vs2.3.0.36.9-pre5/arch/mips/kernel/scall64-o32.S
487 --- linux-2.6.29.1/arch/mips/kernel/scall64-o32.S       2009-03-24 14:18:31.000000000 +0100
488 +++ linux-2.6.29.1-vs2.3.0.36.9-pre5/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.1/arch/mips/kernel/traps.c linux-2.6.29.1-vs2.3.0.36.9-pre5/arch/mips/kernel/traps.c
499 --- linux-2.6.29.1/arch/mips/kernel/traps.c     2009-03-24 14:18:31.000000000 +0100
500 +++ linux-2.6.29.1-vs2.3.0.36.9-pre5/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.1/arch/parisc/Kconfig linux-2.6.29.1-vs2.3.0.36.9-pre5/arch/parisc/Kconfig
516 --- linux-2.6.29.1/arch/parisc/Kconfig  2009-03-24 14:18:32.000000000 +0100
517 +++ linux-2.6.29.1-vs2.3.0.36.9-pre5/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.1/arch/parisc/kernel/syscall_table.S linux-2.6.29.1-vs2.3.0.36.9-pre5/arch/parisc/kernel/syscall_table.S
528 --- linux-2.6.29.1/arch/parisc/kernel/syscall_table.S   2008-12-25 00:26:37.000000000 +0100
529 +++ linux-2.6.29.1-vs2.3.0.36.9-pre5/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.1/arch/parisc/kernel/traps.c linux-2.6.29.1-vs2.3.0.36.9-pre5/arch/parisc/kernel/traps.c
540 --- linux-2.6.29.1/arch/parisc/kernel/traps.c   2009-03-24 14:18:32.000000000 +0100
541 +++ linux-2.6.29.1-vs2.3.0.36.9-pre5/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.1/arch/parisc/mm/fault.c linux-2.6.29.1-vs2.3.0.36.9-pre5/arch/parisc/mm/fault.c
566 --- linux-2.6.29.1/arch/parisc/mm/fault.c       2009-03-24 14:18:33.000000000 +0100
567 +++ linux-2.6.29.1-vs2.3.0.36.9-pre5/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.1/arch/powerpc/Kconfig linux-2.6.29.1-vs2.3.0.36.9-pre5/arch/powerpc/Kconfig
591 --- linux-2.6.29.1/arch/powerpc/Kconfig 2009-03-24 14:18:33.000000000 +0100
592 +++ linux-2.6.29.1-vs2.3.0.36.9-pre5/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.1/arch/powerpc/kernel/irq.c linux-2.6.29.1-vs2.3.0.36.9-pre5/arch/powerpc/kernel/irq.c
603 --- linux-2.6.29.1/arch/powerpc/kernel/irq.c    2009-03-24 14:18:35.000000000 +0100
604 +++ linux-2.6.29.1-vs2.3.0.36.9-pre5/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.1/arch/powerpc/kernel/process.c linux-2.6.29.1-vs2.3.0.36.9-pre5/arch/powerpc/kernel/process.c
614 --- linux-2.6.29.1/arch/powerpc/kernel/process.c        2009-03-24 14:18:35.000000000 +0100
615 +++ linux-2.6.29.1-vs2.3.0.36.9-pre5/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.1/arch/powerpc/kernel/traps.c linux-2.6.29.1-vs2.3.0.36.9-pre5/arch/powerpc/kernel/traps.c
629 --- linux-2.6.29.1/arch/powerpc/kernel/traps.c  2009-03-24 14:18:35.000000000 +0100
630 +++ linux-2.6.29.1-vs2.3.0.36.9-pre5/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.1/arch/powerpc/kernel/vdso.c linux-2.6.29.1-vs2.3.0.36.9-pre5/arch/powerpc/kernel/vdso.c
644 --- linux-2.6.29.1/arch/powerpc/kernel/vdso.c   2009-03-24 14:18:35.000000000 +0100
645 +++ linux-2.6.29.1-vs2.3.0.36.9-pre5/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.1/arch/powerpc/mm/fault.c linux-2.6.29.1-vs2.3.0.36.9-pre5/arch/powerpc/mm/fault.c
655 --- linux-2.6.29.1/arch/powerpc/mm/fault.c      2009-03-24 14:18:36.000000000 +0100
656 +++ linux-2.6.29.1-vs2.3.0.36.9-pre5/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.1/arch/s390/Kconfig linux-2.6.29.1-vs2.3.0.36.9-pre5/arch/s390/Kconfig
668 --- linux-2.6.29.1/arch/s390/Kconfig    2009-03-24 14:18:38.000000000 +0100
669 +++ linux-2.6.29.1-vs2.3.0.36.9-pre5/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.1/arch/s390/kernel/ptrace.c linux-2.6.29.1-vs2.3.0.36.9-pre5/arch/s390/kernel/ptrace.c
680 --- linux-2.6.29.1/arch/s390/kernel/ptrace.c    2009-03-24 14:18:40.000000000 +0100
681 +++ linux-2.6.29.1-vs2.3.0.36.9-pre5/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.1/arch/s390/kernel/syscalls.S linux-2.6.29.1-vs2.3.0.36.9-pre5/arch/s390/kernel/syscalls.S
691 --- linux-2.6.29.1/arch/s390/kernel/syscalls.S  2009-03-24 14:18:40.000000000 +0100
692 +++ linux-2.6.29.1-vs2.3.0.36.9-pre5/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.1/arch/s390/mm/fault.c linux-2.6.29.1-vs2.3.0.36.9-pre5/arch/s390/mm/fault.c
703 --- linux-2.6.29.1/arch/s390/mm/fault.c 2008-12-25 00:26:37.000000000 +0100
704 +++ linux-2.6.29.1-vs2.3.0.36.9-pre5/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.1/arch/sh/Kconfig linux-2.6.29.1-vs2.3.0.36.9-pre5/arch/sh/Kconfig
716 --- linux-2.6.29.1/arch/sh/Kconfig      2009-03-24 14:18:40.000000000 +0100
717 +++ linux-2.6.29.1-vs2.3.0.36.9-pre5/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.1/arch/sh/kernel/irq.c linux-2.6.29.1-vs2.3.0.36.9-pre5/arch/sh/kernel/irq.c
728 --- linux-2.6.29.1/arch/sh/kernel/irq.c 2008-12-25 00:26:37.000000000 +0100
729 +++ linux-2.6.29.1-vs2.3.0.36.9-pre5/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.1/arch/sh/kernel/vsyscall/vsyscall.c linux-2.6.29.1-vs2.3.0.36.9-pre5/arch/sh/kernel/vsyscall/vsyscall.c
739 --- linux-2.6.29.1/arch/sh/kernel/vsyscall/vsyscall.c   2009-03-24 14:18:42.000000000 +0100
740 +++ linux-2.6.29.1-vs2.3.0.36.9-pre5/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.1/arch/sparc/include/asm/tlb_64.h linux-2.6.29.1-vs2.3.0.36.9-pre5/arch/sparc/include/asm/tlb_64.h
750 --- linux-2.6.29.1/arch/sparc/include/asm/tlb_64.h      2009-04-15 22:53:11.000000000 +0200
751 +++ linux-2.6.29.1-vs2.3.0.36.9-pre5/arch/sparc/include/asm/tlb_64.h    2009-04-15 22:58:30.000000000 +0200
752 @@ -3,6 +3,7 @@
753  
754  #include <linux/swap.h>
755  #include <linux/pagemap.h>
756 +#include <linux/vs_memory.h>
757  #include <asm/pgalloc.h>
758  #include <asm/tlbflush.h>
759  #include <asm/mmu_context.h>
760 diff -NurpP --minimal linux-2.6.29.1/arch/sparc/include/asm/unistd.h linux-2.6.29.1-vs2.3.0.36.9-pre5/arch/sparc/include/asm/unistd.h
761 --- linux-2.6.29.1/arch/sparc/include/asm/unistd.h      2009-03-24 14:18:44.000000000 +0100
762 +++ linux-2.6.29.1-vs2.3.0.36.9-pre5/arch/sparc/include/asm/unistd.h    2009-04-08 15:52:53.000000000 +0200
763 @@ -335,7 +335,7 @@
764  #define __NR_timer_getoverrun  264
765  #define __NR_timer_delete      265
766  #define __NR_timer_create      266
767 -/* #define __NR_vserver                267 Reserved for VSERVER */
768 +#define __NR_vserver           267
769  #define __NR_io_setup          268
770  #define __NR_io_destroy                269
771  #define __NR_io_submit         270
772 diff -NurpP --minimal linux-2.6.29.1/arch/sparc/Kconfig linux-2.6.29.1-vs2.3.0.36.9-pre5/arch/sparc/Kconfig
773 --- linux-2.6.29.1/arch/sparc/Kconfig   2009-03-24 14:18:43.000000000 +0100
774 +++ linux-2.6.29.1-vs2.3.0.36.9-pre5/arch/sparc/Kconfig 2009-03-24 14:48:22.000000000 +0100
775 @@ -522,6 +522,8 @@ source "fs/Kconfig"
776  
777  source "arch/sparc/Kconfig.debug"
778  
779 +source "kernel/vserver/Kconfig"
780 +
781  source "security/Kconfig"
782  
783  source "crypto/Kconfig"
784 diff -NurpP --minimal linux-2.6.29.1/arch/sparc/kernel/systbls_32.S linux-2.6.29.1-vs2.3.0.36.9-pre5/arch/sparc/kernel/systbls_32.S
785 --- linux-2.6.29.1/arch/sparc/kernel/systbls_32.S       2009-03-24 14:18:45.000000000 +0100
786 +++ linux-2.6.29.1-vs2.3.0.36.9-pre5/arch/sparc/kernel/systbls_32.S     2009-04-08 15:57:59.000000000 +0200
787 @@ -70,7 +70,7 @@ sys_call_table:
788  /*250*/        .long sparc_mremap, sys_sysctl, sys_getsid, sys_fdatasync, sys_nfsservctl
789  /*255*/        .long sys_sync_file_range, sys_clock_settime, sys_clock_gettime, sys_clock_getres, sys_clock_nanosleep
790  /*260*/        .long sys_sched_getaffinity, sys_sched_setaffinity, sys_timer_settime, sys_timer_gettime, sys_timer_getoverrun
791 -/*265*/        .long sys_timer_delete, sys_timer_create, sys_nis_syscall, sys_io_setup, sys_io_destroy
792 +/*265*/        .long sys_timer_delete, sys_timer_create, sys_vserver, sys_io_setup, sys_io_destroy
793  /*270*/        .long sys_io_submit, sys_io_cancel, sys_io_getevents, sys_mq_open, sys_mq_unlink
794  /*275*/        .long sys_mq_timedsend, sys_mq_timedreceive, sys_mq_notify, sys_mq_getsetattr, sys_waitid
795  /*280*/        .long sys_tee, sys_add_key, sys_request_key, sys_keyctl, sys_openat
796 diff -NurpP --minimal linux-2.6.29.1/arch/sparc/kernel/systbls_64.S linux-2.6.29.1-vs2.3.0.36.9-pre5/arch/sparc/kernel/systbls_64.S
797 --- linux-2.6.29.1/arch/sparc/kernel/systbls_64.S       2009-03-24 14:18:45.000000000 +0100
798 +++ linux-2.6.29.1-vs2.3.0.36.9-pre5/arch/sparc/kernel/systbls_64.S     2009-04-08 15:56:23.000000000 +0200
799 @@ -71,7 +71,7 @@ sys_call_table32:
800  /*250*/        .word sys32_mremap, sys32_sysctl, sys32_getsid, sys_fdatasync, sys32_nfsservctl
801         .word sys32_sync_file_range, compat_sys_clock_settime, compat_sys_clock_gettime, compat_sys_clock_getres, sys32_clock_nanosleep
802  /*260*/        .word compat_sys_sched_getaffinity, compat_sys_sched_setaffinity, sys32_timer_settime, compat_sys_timer_gettime, sys_timer_getoverrun
803 -       .word sys_timer_delete, compat_sys_timer_create, sys_ni_syscall, compat_sys_io_setup, sys_io_destroy
804 +       .word sys_timer_delete, compat_sys_timer_create, sys32_vserver, compat_sys_io_setup, sys_io_destroy
805  /*270*/        .word sys32_io_submit, sys_io_cancel, compat_sys_io_getevents, sys32_mq_open, sys_mq_unlink
806         .word compat_sys_mq_timedsend, compat_sys_mq_timedreceive, compat_sys_mq_notify, compat_sys_mq_getsetattr, compat_sys_waitid
807  /*280*/        .word sys32_tee, sys_add_key, sys_request_key, sys_keyctl, compat_sys_openat
808 @@ -145,7 +145,7 @@ sys_call_table:
809  /*250*/        .word sys_64_mremap, sys_sysctl, sys_getsid, sys_fdatasync, sys_nfsservctl
810         .word sys_sync_file_range, sys_clock_settime, sys_clock_gettime, sys_clock_getres, sys_clock_nanosleep
811  /*260*/        .word sys_sched_getaffinity, sys_sched_setaffinity, sys_timer_settime, sys_timer_gettime, sys_timer_getoverrun
812 -       .word sys_timer_delete, sys_timer_create, sys_ni_syscall, sys_io_setup, sys_io_destroy
813 +       .word sys_timer_delete, sys_timer_create, sys_vserver, sys_io_setup, sys_io_destroy
814  /*270*/        .word sys_io_submit, sys_io_cancel, sys_io_getevents, sys_mq_open, sys_mq_unlink
815         .word sys_mq_timedsend, sys_mq_timedreceive, sys_mq_notify, sys_mq_getsetattr, sys_waitid
816  /*280*/        .word sys_tee, sys_add_key, sys_request_key, sys_keyctl, sys_openat
817 diff -NurpP --minimal linux-2.6.29.1/arch/x86/ia32/ia32entry.S linux-2.6.29.1-vs2.3.0.36.9-pre5/arch/x86/ia32/ia32entry.S
818 --- linux-2.6.29.1/arch/x86/ia32/ia32entry.S    2009-03-24 14:18:48.000000000 +0100
819 +++ linux-2.6.29.1-vs2.3.0.36.9-pre5/arch/x86/ia32/ia32entry.S  2009-03-22 23:29:11.000000000 +0100
820 @@ -768,7 +768,7 @@ ia32_sys_call_table:
821         .quad sys_tgkill                /* 270 */
822         .quad compat_sys_utimes
823         .quad sys32_fadvise64_64
824 -       .quad quiet_ni_syscall  /* sys_vserver */
825 +       .quad sys32_vserver
826         .quad sys_mbind
827         .quad compat_sys_get_mempolicy  /* 275 */
828         .quad sys_set_mempolicy
829 diff -NurpP --minimal linux-2.6.29.1/arch/x86/include/asm/unistd_64.h linux-2.6.29.1-vs2.3.0.36.9-pre5/arch/x86/include/asm/unistd_64.h
830 --- linux-2.6.29.1/arch/x86/include/asm/unistd_64.h     2008-12-25 00:26:37.000000000 +0100
831 +++ linux-2.6.29.1-vs2.3.0.36.9-pre5/arch/x86/include/asm/unistd_64.h   2009-02-22 22:54:24.000000000 +0100
832 @@ -535,7 +535,7 @@ __SYSCALL(__NR_tgkill, sys_tgkill)
833  #define __NR_utimes                            235
834  __SYSCALL(__NR_utimes, sys_utimes)
835  #define __NR_vserver                           236
836 -__SYSCALL(__NR_vserver, sys_ni_syscall)
837 +__SYSCALL(__NR_vserver, sys_vserver)
838  #define __NR_mbind                             237
839  __SYSCALL(__NR_mbind, sys_mbind)
840  #define __NR_set_mempolicy                     238
841 diff -NurpP --minimal linux-2.6.29.1/arch/x86/Kconfig linux-2.6.29.1-vs2.3.0.36.9-pre5/arch/x86/Kconfig
842 --- linux-2.6.29.1/arch/x86/Kconfig     2009-03-24 14:18:47.000000000 +0100
843 +++ linux-2.6.29.1-vs2.3.0.36.9-pre5/arch/x86/Kconfig   2009-03-24 14:48:23.000000000 +0100
844 @@ -1990,6 +1990,8 @@ source "fs/Kconfig"
845  
846  source "arch/x86/Kconfig.debug"
847  
848 +source "kernel/vserver/Kconfig"
849 +
850  source "security/Kconfig"
851  
852  source "crypto/Kconfig"
853 diff -NurpP --minimal linux-2.6.29.1/arch/x86/kernel/syscall_table_32.S linux-2.6.29.1-vs2.3.0.36.9-pre5/arch/x86/kernel/syscall_table_32.S
854 --- linux-2.6.29.1/arch/x86/kernel/syscall_table_32.S   2009-03-24 14:18:51.000000000 +0100
855 +++ linux-2.6.29.1-vs2.3.0.36.9-pre5/arch/x86/kernel/syscall_table_32.S 2009-02-22 22:54:24.000000000 +0100
856 @@ -272,7 +272,7 @@ ENTRY(sys_call_table)
857         .long sys_tgkill        /* 270 */
858         .long sys_utimes
859         .long sys_fadvise64_64
860 -       .long sys_ni_syscall    /* sys_vserver */
861 +       .long sys_vserver
862         .long sys_mbind
863         .long sys_get_mempolicy
864         .long sys_set_mempolicy
865 diff -NurpP --minimal linux-2.6.29.1/Documentation/vserver/debug.txt linux-2.6.29.1-vs2.3.0.36.9-pre5/Documentation/vserver/debug.txt
866 --- linux-2.6.29.1/Documentation/vserver/debug.txt      1970-01-01 01:00:00.000000000 +0100
867 +++ linux-2.6.29.1-vs2.3.0.36.9-pre5/Documentation/vserver/debug.txt    2009-02-22 22:54:24.000000000 +0100
868 @@ -0,0 +1,154 @@
869 +
870 +debug_cvirt:
871 +
872 + 2   4 "vx_map_tgid: %p/%llx: %d -> %d"
873 +       "vx_rmap_tgid: %p/%llx: %d -> %d"
874 +
875 +debug_dlim:
876 +
877 + 0   1 "ALLOC (%p,#%d)%c inode (%d)"
878 +       "FREE  (%p,#%d)%c inode"
879 + 1   2 "ALLOC (%p,#%d)%c %lld bytes (%d)"
880 +       "FREE  (%p,#%d)%c %lld bytes"
881 + 2   4 "ADJUST: %lld,%lld on %ld,%ld [mult=%d]"
882 + 3   8 "ext3_has_free_blocks(%p): %lu<%lu+1, %c, %u!=%u r=%d"
883 +       "ext3_has_free_blocks(%p): free=%lu, root=%lu"
884 +       "rcu_free_dl_info(%p)"
885 + 4  10 "alloc_dl_info(%p,%d) = %p"
886 +       "dealloc_dl_info(%p)"
887 +       "get_dl_info(%p[#%d.%d])"
888 +       "put_dl_info(%p[#%d.%d])"
889 + 5  20 "alloc_dl_info(%p,%d)*"
890 + 6  40 "__hash_dl_info: %p[#%d]"
891 +       "__unhash_dl_info: %p[#%d]"
892 + 7  80 "locate_dl_info(%p,#%d) = %p"
893 +
894 +debug_misc:
895 +
896 + 0   1 "destroy_dqhash: %p [#0x%08x] c=%d"
897 +       "new_dqhash: %p [#0x%08x]"
898 +       "vroot[%d]_clr_dev: dev=%p[%lu,%d:%d]"
899 +       "vroot[%d]_get_real_bdev: dev=%p[%lu,%d:%d]"
900 +       "vroot[%d]_set_dev: dev=%p[%lu,%d:%d]"
901 +       "vroot_get_real_bdev not set"
902 + 1   2 "cow_break_link(»%s«)"
903 +       "temp copy Â»%s«"
904 + 2   4 "dentry_open(new): %p"
905 +       "dentry_open(old): %p"
906 +       "lookup_create(new): %p"
907 +       "old path Â»%s«"
908 +       "path_lookup(old): %d"
909 +       "vfs_create(new): %d"
910 +       "vfs_rename: %d"
911 +       "vfs_sendfile: %d"
912 + 3   8 "fput(new_file=%p[#%d])"
913 +       "fput(old_file=%p[#%d])"
914 + 4  10 "vx_info_kill(%p[#%d],%d,%d) = %d"
915 +       "vx_info_kill(%p[#%d],%d,%d)*"
916 + 5  20 "vs_reboot(%p[#%d],%d)"
917 + 6  40 "dropping task %p[#%u,%u] for %p[#%u,%u]"
918 +
919 +debug_net:
920 +
921 + 2   4 "nx_addr_conflict(%p,%p) %d.%d,%d.%d"
922 + 3   8 "inet_bind(%p) %d.%d.%d.%d, %d.%d.%d.%d, %d.%d.%d.%d"
923 +       "inet_bind(%p)* %p,%p;%lx %d.%d.%d.%d"
924 + 4  10 "ip_route_connect(%p) %p,%p;%lx"
925 + 5  20 "__addr_in_socket(%p,%d.%d.%d.%d) %p:%d.%d.%d.%d %p;%lx"
926 + 6  40 "sk,egf: %p [#%d] (from %d)"
927 +       "sk,egn: %p [#%d] (from %d)"
928 +       "sk,req: %p [#%d] (from %d)"
929 +       "sk: %p [#%d] (from %d)"
930 +       "tw: %p [#%d] (from %d)"
931 + 7  80 "__sock_recvmsg: %p[%p,%p,%p;%d]:%d/%d"
932 +       "__sock_sendmsg: %p[%p,%p,%p;%d]:%d/%d"
933 +
934 +debug_nid:
935 +
936 + 0   1 "__lookup_nx_info(#%u): %p[#%u]"
937 +       "alloc_nx_info(%d) = %p"
938 +       "create_nx_info(%d) (dynamic rejected)"
939 +       "create_nx_info(%d) = %p (already there)"
940 +       "create_nx_info(%d) = %p (new)"
941 +       "dealloc_nx_info(%p)"
942 + 1   2 "alloc_nx_info(%d)*"
943 +       "create_nx_info(%d)*"
944 + 2   4 "get_nx_info(%p[#%d.%d])"
945 +       "put_nx_info(%p[#%d.%d])"
946 + 3   8 "claim_nx_info(%p[#%d.%d.%d]) %p"
947 +       "clr_nx_info(%p[#%d.%d])"
948 +       "init_nx_info(%p[#%d.%d])"
949 +       "release_nx_info(%p[#%d.%d.%d]) %p"
950 +       "set_nx_info(%p[#%d.%d])"
951 + 4  10 "__hash_nx_info: %p[#%d]"
952 +       "__nx_dynamic_id: [#%d]"
953 +       "__unhash_nx_info: %p[#%d.%d.%d]"
954 + 5  20 "moved task %p into nxi:%p[#%d]"
955 +       "nx_migrate_task(%p,%p[#%d.%d.%d])"
956 +       "task_get_nx_info(%p)"
957 + 6  40 "nx_clear_persistent(%p[#%d])"
958 +
959 +debug_quota:
960 +
961 + 0   1 "quota_sync_dqh(%p,%d) discard inode %p"
962 + 1   2 "quota_sync_dqh(%p,%d)"
963 +       "sync_dquots(%p,%d)"
964 +       "sync_dquots_dqh(%p,%d)"
965 + 3   8 "do_quotactl(%p,%d,cmd=%d,id=%d,%p)"
966 +
967 +debug_switch:
968 +
969 + 0   1 "vc: VCMD_%02d_%d[%d], %d,%p [%d,%d,%x,%x]"
970 + 1   2 "vc: VCMD_%02d_%d[%d] = %08lx(%ld) [%d,%d]"
971 + 4  10 "%s: (%s %s) returned %s with %d"
972 +
973 +debug_tag:
974 +
975 + 7  80 "dx_parse_tag(»%s«): %d:#%d"
976 +       "dx_propagate_tag(%p[#%lu.%d]): %d,%d"
977 +
978 +debug_xid:
979 +
980 + 0   1 "__lookup_vx_info(#%u): %p[#%u]"
981 +       "alloc_vx_info(%d) = %p"
982 +       "alloc_vx_info(%d)*"
983 +       "create_vx_info(%d) (dynamic rejected)"
984 +       "create_vx_info(%d) = %p (already there)"
985 +       "create_vx_info(%d) = %p (new)"
986 +       "dealloc_vx_info(%p)"
987 +       "loc_vx_info(%d) = %p (found)"
988 +       "loc_vx_info(%d) = %p (new)"
989 +       "loc_vx_info(%d) = %p (not available)"
990 + 1   2 "create_vx_info(%d)*"
991 +       "loc_vx_info(%d)*"
992 + 2   4 "get_vx_info(%p[#%d.%d])"
993 +       "put_vx_info(%p[#%d.%d])"
994 + 3   8 "claim_vx_info(%p[#%d.%d.%d]) %p"
995 +       "clr_vx_info(%p[#%d.%d])"
996 +       "init_vx_info(%p[#%d.%d])"
997 +       "release_vx_info(%p[#%d.%d.%d]) %p"
998 +       "set_vx_info(%p[#%d.%d])"
999 + 4  10 "__hash_vx_info: %p[#%d]"
1000 +       "__unhash_vx_info: %p[#%d.%d.%d]"
1001 +       "__vx_dynamic_id: [#%d]"
1002 + 5  20 "enter_vx_info(%p[#%d],%p) %p[#%d,%p]"
1003 +       "leave_vx_info(%p[#%d,%p]) %p[#%d,%p]"
1004 +       "moved task %p into vxi:%p[#%d]"
1005 +       "task_get_vx_info(%p)"
1006 +       "vx_migrate_task(%p,%p[#%d.%d])"
1007 + 6  40 "vx_clear_persistent(%p[#%d])"
1008 +       "vx_exit_init(%p[#%d],%p[#%d,%d,%d])"
1009 +       "vx_set_init(%p[#%d],%p[#%d,%d,%d])"
1010 +       "vx_set_persistent(%p[#%d])"
1011 +       "vx_set_reaper(%p[#%d],%p[#%d,%d])"
1012 + 7  80 "vx_child_reaper(%p[#%u,%u]) = %p[#%u,%u]"
1013 +
1014 +
1015 +debug_limit:
1016 +
1017 + n 2^n "vx_acc_cres[%5d,%s,%2d]: %5d%s"
1018 +       "vx_cres_avail[%5d,%s,%2d]: %5ld > %5d + %5d"
1019 +
1020 + m 2^m "vx_acc_page[%5d,%s,%2d]: %5d%s"
1021 +       "vx_acc_pages[%5d,%s,%2d]: %5d += %5d"
1022 +       "vx_pages_avail[%5d,%s,%2d]: %5ld > %5d + %5d"
1023 diff -NurpP --minimal linux-2.6.29.1/drivers/block/Kconfig linux-2.6.29.1-vs2.3.0.36.9-pre5/drivers/block/Kconfig
1024 --- linux-2.6.29.1/drivers/block/Kconfig        2008-12-25 00:26:37.000000000 +0100
1025 +++ linux-2.6.29.1-vs2.3.0.36.9-pre5/drivers/block/Kconfig      2009-02-22 22:54:24.000000000 +0100
1026 @@ -264,6 +264,13 @@ config BLK_DEV_CRYPTOLOOP
1027           instead, which can be configured to be on-disk compatible with the
1028           cryptoloop device.
1029  
1030 +config BLK_DEV_VROOT
1031 +       tristate "Virtual Root device support"
1032 +       depends on QUOTACTL
1033 +       ---help---
1034 +         Saying Y here will allow you to use quota/fs ioctls on a shared
1035 +         partition within a virtual server without compromising security.
1036 +
1037  config BLK_DEV_NBD
1038         tristate "Network block device support"
1039         depends on NET
1040 diff -NurpP --minimal linux-2.6.29.1/drivers/block/loop.c linux-2.6.29.1-vs2.3.0.36.9-pre5/drivers/block/loop.c
1041 --- linux-2.6.29.1/drivers/block/loop.c 2009-03-24 14:18:56.000000000 +0100
1042 +++ linux-2.6.29.1-vs2.3.0.36.9-pre5/drivers/block/loop.c       2009-03-24 15:09:29.000000000 +0100
1043 @@ -75,6 +75,7 @@
1044  #include <linux/gfp.h>
1045  #include <linux/kthread.h>
1046  #include <linux/splice.h>
1047 +#include <linux/vs_context.h>
1048  
1049  #include <asm/uaccess.h>
1050  
1051 @@ -809,6 +810,7 @@ static int loop_set_fd(struct loop_devic
1052         lo->lo_blocksize = lo_blocksize;
1053         lo->lo_device = bdev;
1054         lo->lo_flags = lo_flags;
1055 +       lo->lo_xid = vx_current_xid();
1056         lo->lo_backing_file = file;
1057         lo->transfer = transfer_none;
1058         lo->ioctl = NULL;
1059 @@ -931,6 +933,7 @@ static int loop_clr_fd(struct loop_devic
1060         lo->lo_encrypt_key_size = 0;
1061         lo->lo_flags = 0;
1062         lo->lo_thread = NULL;
1063 +       lo->lo_xid = 0;
1064         memset(lo->lo_encrypt_key, 0, LO_KEY_SIZE);
1065         memset(lo->lo_crypt_name, 0, LO_NAME_SIZE);
1066         memset(lo->lo_file_name, 0, LO_NAME_SIZE);
1067 @@ -958,7 +961,7 @@ loop_set_status(struct loop_device *lo, 
1068  
1069         if (lo->lo_encrypt_key_size &&
1070             lo->lo_key_owner != uid &&
1071 -           !capable(CAP_SYS_ADMIN))
1072 +           !vx_capable(CAP_SYS_ADMIN, VXC_ADMIN_CLOOP))
1073                 return -EPERM;
1074         if (lo->lo_state != Lo_bound)
1075                 return -ENXIO;
1076 @@ -1042,7 +1045,8 @@ loop_get_status(struct loop_device *lo, 
1077         memcpy(info->lo_crypt_name, lo->lo_crypt_name, LO_NAME_SIZE);
1078         info->lo_encrypt_type =
1079                 lo->lo_encryption ? lo->lo_encryption->number : 0;
1080 -       if (lo->lo_encrypt_key_size && capable(CAP_SYS_ADMIN)) {
1081 +       if (lo->lo_encrypt_key_size &&
1082 +               vx_capable(CAP_SYS_ADMIN, VXC_ADMIN_CLOOP)) {
1083                 info->lo_encrypt_key_size = lo->lo_encrypt_key_size;
1084                 memcpy(info->lo_encrypt_key, lo->lo_encrypt_key,
1085                        lo->lo_encrypt_key_size);
1086 @@ -1351,6 +1355,9 @@ static int lo_open(struct block_device *
1087  {
1088         struct loop_device *lo = bdev->bd_disk->private_data;
1089  
1090 +       if (!vx_check(lo->lo_xid, VS_IDENT|VS_HOSTID|VS_ADMIN_P))
1091 +               return -EACCES;
1092 +
1093         mutex_lock(&lo->lo_ctl_mutex);
1094         lo->lo_refcnt++;
1095         mutex_unlock(&lo->lo_ctl_mutex);
1096 diff -NurpP --minimal linux-2.6.29.1/drivers/block/Makefile linux-2.6.29.1-vs2.3.0.36.9-pre5/drivers/block/Makefile
1097 --- linux-2.6.29.1/drivers/block/Makefile       2009-03-24 14:18:55.000000000 +0100
1098 +++ linux-2.6.29.1-vs2.3.0.36.9-pre5/drivers/block/Makefile     2009-03-24 14:48:25.000000000 +0100
1099 @@ -31,5 +31,6 @@ obj-$(CONFIG_VIODASD)         += viodasd.o
1100  obj-$(CONFIG_BLK_DEV_SX8)      += sx8.o
1101  obj-$(CONFIG_BLK_DEV_UB)       += ub.o
1102  obj-$(CONFIG_BLK_DEV_HD)       += hd.o
1103 +obj-$(CONFIG_BLK_DEV_VROOT)    += vroot.o
1104  
1105  obj-$(CONFIG_XEN_BLKDEV_FRONTEND)      += xen-blkfront.o
1106 diff -NurpP --minimal linux-2.6.29.1/drivers/block/vroot.c linux-2.6.29.1-vs2.3.0.36.9-pre5/drivers/block/vroot.c
1107 --- linux-2.6.29.1/drivers/block/vroot.c        1970-01-01 01:00:00.000000000 +0100
1108 +++ linux-2.6.29.1-vs2.3.0.36.9-pre5/drivers/block/vroot.c      2009-02-22 22:54:24.000000000 +0100
1109 @@ -0,0 +1,281 @@
1110 +/*
1111 + *  linux/drivers/block/vroot.c
1112 + *
1113 + *  written by Herbert Pötzl, 9/11/2002
1114 + *  ported to 2.6.10 by Herbert Pötzl, 30/12/2004
1115 + *
1116 + *  based on the loop.c code by Theodore Ts'o.
1117 + *
1118 + * Copyright (C) 2002-2007 by Herbert Pötzl.
1119 + * Redistribution of this file is permitted under the
1120 + * GNU General Public License.
1121 + *
1122 + */
1123 +
1124 +#include <linux/module.h>
1125 +#include <linux/moduleparam.h>
1126 +#include <linux/file.h>
1127 +#include <linux/major.h>
1128 +#include <linux/blkdev.h>
1129 +
1130 +#include <linux/vroot.h>
1131 +#include <linux/vs_context.h>
1132 +
1133 +
1134 +static int max_vroot = 8;
1135 +
1136 +static struct vroot_device *vroot_dev;
1137 +static struct gendisk **disks;
1138 +
1139 +
1140 +static int vroot_set_dev(
1141 +       struct vroot_device *vr,
1142 +       struct block_device *bdev,
1143 +       unsigned int arg)
1144 +{
1145 +       struct block_device *real_bdev;
1146 +       struct file *file;
1147 +       struct inode *inode;
1148 +       int error;
1149 +
1150 +       error = -EBUSY;
1151 +       if (vr->vr_state != Vr_unbound)
1152 +               goto out;
1153 +
1154 +       error = -EBADF;
1155 +       file = fget(arg);
1156 +       if (!file)
1157 +               goto out;
1158 +
1159 +       error = -EINVAL;
1160 +       inode = file->f_dentry->d_inode;
1161 +
1162 +
1163 +       if (S_ISBLK(inode->i_mode)) {
1164 +               real_bdev = inode->i_bdev;
1165 +               vr->vr_device = real_bdev;
1166 +               __iget(real_bdev->bd_inode);
1167 +       } else
1168 +               goto out_fput;
1169 +
1170 +       vxdprintk(VXD_CBIT(misc, 0),
1171 +               "vroot[%d]_set_dev: dev=" VXF_DEV,
1172 +               vr->vr_number, VXD_DEV(real_bdev));
1173 +
1174 +       vr->vr_state = Vr_bound;
1175 +       error = 0;
1176 +
1177 + out_fput:
1178 +       fput(file);
1179 + out:
1180 +       return error;
1181 +}
1182 +
1183 +static int vroot_clr_dev(
1184 +       struct vroot_device *vr,
1185 +       struct block_device *bdev)
1186 +{
1187 +       struct block_device *real_bdev;
1188 +
1189 +       if (vr->vr_state != Vr_bound)
1190 +               return -ENXIO;
1191 +       if (vr->vr_refcnt > 1)  /* we needed one fd for the ioctl */
1192 +               return -EBUSY;
1193 +
1194 +       real_bdev = vr->vr_device;
1195 +
1196 +       vxdprintk(VXD_CBIT(misc, 0),
1197 +               "vroot[%d]_clr_dev: dev=" VXF_DEV,
1198 +               vr->vr_number, VXD_DEV(real_bdev));
1199 +
1200 +       bdput(real_bdev);
1201 +       vr->vr_state = Vr_unbound;
1202 +       vr->vr_device = NULL;
1203 +       return 0;
1204 +}
1205 +
1206 +
1207 +static int vr_ioctl(struct block_device *bdev, fmode_t mode,
1208 +       unsigned int cmd, unsigned long arg)
1209 +{
1210 +       struct vroot_device *vr = bdev->bd_disk->private_data;
1211 +       int err;
1212 +
1213 +       down(&vr->vr_ctl_mutex);
1214 +       switch (cmd) {
1215 +       case VROOT_SET_DEV:
1216 +               err = vroot_set_dev(vr, bdev, arg);
1217 +               break;
1218 +       case VROOT_CLR_DEV:
1219 +               err = vroot_clr_dev(vr, bdev);
1220 +               break;
1221 +       default:
1222 +               err = -EINVAL;
1223 +               break;
1224 +       }
1225 +       up(&vr->vr_ctl_mutex);
1226 +       return err;
1227 +}
1228 +
1229 +static int vr_open(struct block_device *bdev, fmode_t mode)
1230 +{
1231 +       struct vroot_device *vr = bdev->bd_disk->private_data;
1232 +
1233 +       down(&vr->vr_ctl_mutex);
1234 +       vr->vr_refcnt++;
1235 +       up(&vr->vr_ctl_mutex);
1236 +       return 0;
1237 +}
1238 +
1239 +static int vr_release(struct gendisk *disk, fmode_t mode)
1240 +{
1241 +       struct vroot_device *vr = disk->private_data;
1242 +
1243 +       down(&vr->vr_ctl_mutex);
1244 +       --vr->vr_refcnt;
1245 +       up(&vr->vr_ctl_mutex);
1246 +       return 0;
1247 +}
1248 +
1249 +static struct block_device_operations vr_fops = {
1250 +       .owner =        THIS_MODULE,
1251 +       .open =         vr_open,
1252 +       .release =      vr_release,
1253 +       .ioctl =        vr_ioctl,
1254 +};
1255 +
1256 +struct block_device *__vroot_get_real_bdev(struct block_device *bdev)
1257 +{
1258 +       struct inode *inode = bdev->bd_inode;
1259 +       struct vroot_device *vr;
1260 +       struct block_device *real_bdev;
1261 +       int minor = iminor(inode);
1262 +
1263 +       vr = &vroot_dev[minor];
1264 +       real_bdev = vr->vr_device;
1265 +
1266 +       vxdprintk(VXD_CBIT(misc, 0),
1267 +               "vroot[%d]_get_real_bdev: dev=" VXF_DEV,
1268 +               vr->vr_number, VXD_DEV(real_bdev));
1269 +
1270 +       if (vr->vr_state != Vr_bound)
1271 +               return ERR_PTR(-ENXIO);
1272 +
1273 +       __iget(real_bdev->bd_inode);
1274 +       return real_bdev;
1275 +}
1276 +
1277 +/*
1278 + * And now the modules code and kernel interface.
1279 + */
1280 +
1281 +module_param(max_vroot, int, 0);
1282 +
1283 +MODULE_PARM_DESC(max_vroot, "Maximum number of vroot devices (1-256)");
1284 +MODULE_LICENSE("GPL");
1285 +MODULE_ALIAS_BLOCKDEV_MAJOR(VROOT_MAJOR);
1286 +
1287 +MODULE_AUTHOR ("Herbert Pötzl");
1288 +MODULE_DESCRIPTION ("Virtual Root Device Mapper");
1289 +
1290 +
1291 +int __init vroot_init(void)
1292 +{
1293 +       int err, i;
1294 +
1295 +       if (max_vroot < 1 || max_vroot > 256) {
1296 +               max_vroot = MAX_VROOT_DEFAULT;
1297 +               printk(KERN_WARNING "vroot: invalid max_vroot "
1298 +                       "(must be between 1 and 256), "
1299 +                       "using default (%d)\n", max_vroot);
1300 +       }
1301 +
1302 +       if (register_blkdev(VROOT_MAJOR, "vroot"))
1303 +               return -EIO;
1304 +
1305 +       err = -ENOMEM;
1306 +       vroot_dev = kmalloc(max_vroot * sizeof(struct vroot_device), GFP_KERNEL);
1307 +       if (!vroot_dev)
1308 +               goto out_mem1;
1309 +       memset(vroot_dev, 0, max_vroot * sizeof(struct vroot_device));
1310 +
1311 +       disks = kmalloc(max_vroot * sizeof(struct gendisk *), GFP_KERNEL);
1312 +       if (!disks)
1313 +               goto out_mem2;
1314 +
1315 +       for (i = 0; i < max_vroot; i++) {
1316 +               disks[i] = alloc_disk(1);
1317 +               if (!disks[i])
1318 +                       goto out_mem3;
1319 +               disks[i]->queue = blk_alloc_queue(GFP_KERNEL);
1320 +               if (!disks[i]->queue)
1321 +                       goto out_mem3;
1322 +       }
1323 +
1324 +       for (i = 0; i < max_vroot; i++) {
1325 +               struct vroot_device *vr = &vroot_dev[i];
1326 +               struct gendisk *disk = disks[i];
1327 +
1328 +               memset(vr, 0, sizeof(*vr));
1329 +               init_MUTEX(&vr->vr_ctl_mutex);
1330 +               vr->vr_number = i;
1331 +               disk->major = VROOT_MAJOR;
1332 +               disk->first_minor = i;
1333 +               disk->fops = &vr_fops;
1334 +               sprintf(disk->disk_name, "vroot%d", i);
1335 +               disk->private_data = vr;
1336 +       }
1337 +
1338 +       err = register_vroot_grb(&__vroot_get_real_bdev);
1339 +       if (err)
1340 +               goto out_mem3;
1341 +
1342 +       for (i = 0; i < max_vroot; i++)
1343 +               add_disk(disks[i]);
1344 +       printk(KERN_INFO "vroot: loaded (max %d devices)\n", max_vroot);
1345 +       return 0;
1346 +
1347 +out_mem3:
1348 +       while (i--)
1349 +               put_disk(disks[i]);
1350 +       kfree(disks);
1351 +out_mem2:
1352 +       kfree(vroot_dev);
1353 +out_mem1:
1354 +       unregister_blkdev(VROOT_MAJOR, "vroot");
1355 +       printk(KERN_ERR "vroot: ran out of memory\n");
1356 +       return err;
1357 +}
1358 +
1359 +void vroot_exit(void)
1360 +{
1361 +       int i;
1362 +
1363 +       if (unregister_vroot_grb(&__vroot_get_real_bdev))
1364 +               printk(KERN_WARNING "vroot: cannot unregister grb\n");
1365 +
1366 +       for (i = 0; i < max_vroot; i++) {
1367 +               del_gendisk(disks[i]);
1368 +               put_disk(disks[i]);
1369 +       }
1370 +       unregister_blkdev(VROOT_MAJOR, "vroot");
1371 +
1372 +       kfree(disks);
1373 +       kfree(vroot_dev);
1374 +}
1375 +
1376 +module_init(vroot_init);
1377 +module_exit(vroot_exit);
1378 +
1379 +#ifndef MODULE
1380 +
1381 +static int __init max_vroot_setup(char *str)
1382 +{
1383 +       max_vroot = simple_strtol(str, NULL, 0);
1384 +       return 1;
1385 +}
1386 +
1387 +__setup("max_vroot=", max_vroot_setup);
1388 +
1389 +#endif
1390 +
1391 diff -NurpP --minimal linux-2.6.29.1/drivers/char/sysrq.c linux-2.6.29.1-vs2.3.0.36.9-pre5/drivers/char/sysrq.c
1392 --- linux-2.6.29.1/drivers/char/sysrq.c 2009-03-24 14:18:57.000000000 +0100
1393 +++ linux-2.6.29.1-vs2.3.0.36.9-pre5/drivers/char/sysrq.c       2009-03-24 15:15:27.000000000 +0100
1394 @@ -38,6 +38,7 @@
1395  #include <linux/irq.h>
1396  #include <linux/hrtimer.h>
1397  #include <linux/oom.h>
1398 +#include <linux/vserver/debug.h>
1399  
1400  #include <asm/ptrace.h>
1401  #include <asm/irq_regs.h>
1402 @@ -369,6 +370,21 @@ static struct sysrq_key_op sysrq_unrt_op
1403         .enable_mask    = SYSRQ_ENABLE_RTNICE,
1404  };
1405  
1406 +
1407 +#ifdef CONFIG_VSERVER_DEBUG
1408 +static void sysrq_handle_vxinfo(int key, struct tty_struct *tty)
1409 +{
1410 +       dump_vx_info_inactive((key == 'x')?0:1);
1411 +}
1412 +
1413 +static struct sysrq_key_op sysrq_showvxinfo_op = {
1414 +       .handler        = sysrq_handle_vxinfo,
1415 +       .help_msg       = "conteXt",
1416 +       .action_msg     = "Show Context Info",
1417 +       .enable_mask    = SYSRQ_ENABLE_DUMP,
1418 +};
1419 +#endif
1420 +
1421  /* Key Operations table and lock */
1422  static DEFINE_SPINLOCK(sysrq_key_table_lock);
1423  
1424 @@ -419,7 +435,11 @@ static struct sysrq_key_op *sysrq_key_ta
1425         NULL,                           /* v */
1426         &sysrq_showstate_blocked_op,    /* w */
1427         /* x: May be registered on ppc/powerpc for xmon */
1428 +#ifdef CONFIG_VSERVER_DEBUG
1429 +       &sysrq_showvxinfo_op,           /* x */
1430 +#else
1431         NULL,                           /* x */
1432 +#endif
1433         /* y: May be registered on sparc64 for global register dump */
1434         NULL,                           /* y */
1435         &sysrq_ftrace_dump_op,          /* z */
1436 @@ -434,6 +454,8 @@ static int sysrq_key_table_key2index(int
1437                 retval = key - '0';
1438         else if ((key >= 'a') && (key <= 'z'))
1439                 retval = key + 10 - 'a';
1440 +       else if ((key >= 'A') && (key <= 'Z'))
1441 +               retval = key + 10 - 'A';
1442         else
1443                 retval = -1;
1444         return retval;
1445 diff -NurpP --minimal linux-2.6.29.1/drivers/char/tty_io.c linux-2.6.29.1-vs2.3.0.36.9-pre5/drivers/char/tty_io.c
1446 --- linux-2.6.29.1/drivers/char/tty_io.c        2009-03-24 14:18:57.000000000 +0100
1447 +++ linux-2.6.29.1-vs2.3.0.36.9-pre5/drivers/char/tty_io.c      2009-03-24 14:48:25.000000000 +0100
1448 @@ -106,6 +106,7 @@
1449  
1450  #include <linux/kmod.h>
1451  #include <linux/nsproxy.h>
1452 +#include <linux/vs_pid.h>
1453  
1454  #undef TTY_DEBUG_HANGUP
1455  
1456 @@ -2303,6 +2304,7 @@ static int tiocspgrp(struct tty_struct *
1457                 return -ENOTTY;
1458         if (get_user(pgrp_nr, p))
1459                 return -EFAULT;
1460 +       pgrp_nr = vx_rmap_pid(pgrp_nr);
1461         if (pgrp_nr < 0)
1462                 return -EINVAL;
1463         rcu_read_lock();
1464 diff -NurpP --minimal linux-2.6.29.1/drivers/infiniband/hw/ipath/ipath_user_pages.c linux-2.6.29.1-vs2.3.0.36.9-pre5/drivers/infiniband/hw/ipath/ipath_user_pages.c
1465 --- linux-2.6.29.1/drivers/infiniband/hw/ipath/ipath_user_pages.c       2008-12-25 00:26:37.000000000 +0100
1466 +++ linux-2.6.29.1-vs2.3.0.36.9-pre5/drivers/infiniband/hw/ipath/ipath_user_pages.c     2009-02-22 22:54:24.000000000 +0100
1467 @@ -33,6 +33,7 @@
1468  
1469  #include <linux/mm.h>
1470  #include <linux/device.h>
1471 +#include <linux/vs_memory.h>
1472  
1473  #include "ipath_kernel.h"
1474  
1475 @@ -61,7 +62,8 @@ static int __get_user_pages(unsigned lon
1476         lock_limit = current->signal->rlim[RLIMIT_MEMLOCK].rlim_cur >>
1477                 PAGE_SHIFT;
1478  
1479 -       if (num_pages > lock_limit) {
1480 +       if (num_pages > lock_limit ||
1481 +               !vx_vmlocked_avail(current->mm, num_pages)) {
1482                 ret = -ENOMEM;
1483                 goto bail;
1484         }
1485 @@ -78,7 +80,7 @@ static int __get_user_pages(unsigned lon
1486                         goto bail_release;
1487         }
1488  
1489 -       current->mm->locked_vm += num_pages;
1490 +       vx_vmlocked_add(current->mm, num_pages);
1491  
1492         ret = 0;
1493         goto bail;
1494 @@ -177,7 +179,7 @@ void ipath_release_user_pages(struct pag
1495  
1496         __ipath_release_user_pages(p, num_pages, 1);
1497  
1498 -       current->mm->locked_vm -= num_pages;
1499 +       vx_vmlocked_sub(current->mm, num_pages);
1500  
1501         up_write(&current->mm->mmap_sem);
1502  }
1503 @@ -194,7 +196,7 @@ static void user_pages_account(struct wo
1504                 container_of(_work, struct ipath_user_pages_work, work);
1505  
1506         down_write(&work->mm->mmap_sem);
1507 -       work->mm->locked_vm -= work->num_pages;
1508 +       vx_vmlocked_sub(work->mm, work->num_pages);
1509         up_write(&work->mm->mmap_sem);
1510         mmput(work->mm);
1511         kfree(work);
1512 diff -NurpP --minimal linux-2.6.29.1/drivers/md/dm.c linux-2.6.29.1-vs2.3.0.36.9-pre5/drivers/md/dm.c
1513 --- linux-2.6.29.1/drivers/md/dm.c      2009-03-24 14:19:05.000000000 +0100
1514 +++ linux-2.6.29.1-vs2.3.0.36.9-pre5/drivers/md/dm.c    2009-03-24 15:15:57.000000000 +0100
1515 @@ -22,6 +22,7 @@
1516  #include <linux/hdreg.h>
1517  #include <linux/blktrace_api.h>
1518  #include <trace/block.h>
1519 +#include <linux/vs_base.h>
1520  
1521  #define DM_MSG_PREFIX "core"
1522  
1523 @@ -115,6 +116,7 @@ struct mapped_device {
1524         rwlock_t map_lock;
1525         atomic_t holders;
1526         atomic_t open_count;
1527 +       xid_t xid;
1528  
1529         unsigned long flags;
1530  
1531 @@ -295,6 +297,7 @@ static void __exit dm_exit(void)
1532  static int dm_blk_open(struct block_device *bdev, fmode_t mode)
1533  {
1534         struct mapped_device *md;
1535 +       int ret = -ENXIO;
1536  
1537         spin_lock(&_minor_lock);
1538  
1539 @@ -303,18 +306,19 @@ static int dm_blk_open(struct block_devi
1540                 goto out;
1541  
1542         if (test_bit(DMF_FREEING, &md->flags) ||
1543 -           test_bit(DMF_DELETING, &md->flags)) {
1544 -               md = NULL;
1545 +           test_bit(DMF_DELETING, &md->flags))
1546 +               goto out;
1547 +
1548 +       ret = -EACCES;
1549 +       if (!vx_check(md->xid, VS_IDENT|VS_HOSTID))
1550                 goto out;
1551 -       }
1552  
1553         dm_get(md);
1554         atomic_inc(&md->open_count);
1555 -
1556 +       ret = 0;
1557  out:
1558         spin_unlock(&_minor_lock);
1559 -
1560 -       return md ? 0 : -ENXIO;
1561 +       return ret;
1562  }
1563  
1564  static int dm_blk_close(struct gendisk *disk, fmode_t mode)
1565 @@ -504,6 +508,14 @@ int dm_set_geometry(struct mapped_device
1566         return 0;
1567  }
1568  
1569 +/*
1570 + * Get the xid associated with a dm device
1571 + */
1572 +xid_t dm_get_xid(struct mapped_device *md)
1573 +{
1574 +       return md->xid;
1575 +}
1576 +
1577  /*-----------------------------------------------------------------
1578   * CRUD START:
1579   *   A more elegant soln is in the works that uses the queue
1580 @@ -1110,6 +1122,7 @@ static struct mapped_device *alloc_dev(i
1581         INIT_LIST_HEAD(&md->uevent_list);
1582         spin_lock_init(&md->uevent_lock);
1583  
1584 +       md->xid = vx_current_xid();
1585         md->queue = blk_alloc_queue(GFP_KERNEL);
1586         if (!md->queue)
1587                 goto bad_queue;
1588 diff -NurpP --minimal linux-2.6.29.1/drivers/md/dm.h linux-2.6.29.1-vs2.3.0.36.9-pre5/drivers/md/dm.h
1589 --- linux-2.6.29.1/drivers/md/dm.h      2009-03-24 14:19:05.000000000 +0100
1590 +++ linux-2.6.29.1-vs2.3.0.36.9-pre5/drivers/md/dm.h    2009-03-24 14:48:26.000000000 +0100
1591 @@ -54,6 +54,8 @@ int dm_table_any_congested(struct dm_tab
1592  #define dm_target_is_valid(t) ((t)->table)
1593  int dm_table_barrier_ok(struct dm_table *t);
1594  
1595 +xid_t dm_get_xid(struct mapped_device *md);
1596 +
1597  /*-----------------------------------------------------------------
1598   * A registry of target types.
1599   *---------------------------------------------------------------*/
1600 diff -NurpP --minimal linux-2.6.29.1/drivers/md/dm-ioctl.c linux-2.6.29.1-vs2.3.0.36.9-pre5/drivers/md/dm-ioctl.c
1601 --- linux-2.6.29.1/drivers/md/dm-ioctl.c        2009-03-24 14:19:05.000000000 +0100
1602 +++ linux-2.6.29.1-vs2.3.0.36.9-pre5/drivers/md/dm-ioctl.c      2009-03-24 14:48:26.000000000 +0100
1603 @@ -16,6 +16,7 @@
1604  #include <linux/dm-ioctl.h>
1605  #include <linux/hdreg.h>
1606  #include <linux/compat.h>
1607 +#include <linux/vs_context.h>
1608  
1609  #include <asm/uaccess.h>
1610  
1611 @@ -101,7 +102,8 @@ static struct hash_cell *__get_name_cell
1612         unsigned int h = hash_str(str);
1613  
1614         list_for_each_entry (hc, _name_buckets + h, name_list)
1615 -               if (!strcmp(hc->name, str)) {
1616 +               if (vx_check(dm_get_xid(hc->md), VS_WATCH_P | VS_IDENT) &&
1617 +                       !strcmp(hc->name, str)) {
1618                         dm_get(hc->md);
1619                         return hc;
1620                 }
1621 @@ -115,7 +117,8 @@ static struct hash_cell *__get_uuid_cell
1622         unsigned int h = hash_str(str);
1623  
1624         list_for_each_entry (hc, _uuid_buckets + h, uuid_list)
1625 -               if (!strcmp(hc->uuid, str)) {
1626 +               if (vx_check(dm_get_xid(hc->md), VS_WATCH_P | VS_IDENT) &&
1627 +                       !strcmp(hc->uuid, str)) {
1628                         dm_get(hc->md);
1629                         return hc;
1630                 }
1631 @@ -352,6 +355,9 @@ typedef int (*ioctl_fn)(struct dm_ioctl 
1632  
1633  static int remove_all(struct dm_ioctl *param, size_t param_size)
1634  {
1635 +       if (!vx_check(0, VS_ADMIN))
1636 +               return -EPERM;
1637 +
1638         dm_hash_remove_all(1);
1639         param->data_size = 0;
1640         return 0;
1641 @@ -399,6 +405,8 @@ static int list_devices(struct dm_ioctl 
1642          */
1643         for (i = 0; i < NUM_BUCKETS; i++) {
1644                 list_for_each_entry (hc, _name_buckets + i, name_list) {
1645 +                       if (!vx_check(dm_get_xid(hc->md), VS_WATCH_P | VS_IDENT))
1646 +                               continue;
1647                         needed += sizeof(struct dm_name_list);
1648                         needed += strlen(hc->name) + 1;
1649                         needed += ALIGN_MASK;
1650 @@ -422,6 +430,8 @@ static int list_devices(struct dm_ioctl 
1651          */
1652         for (i = 0; i < NUM_BUCKETS; i++) {
1653                 list_for_each_entry (hc, _name_buckets + i, name_list) {
1654 +                       if (!vx_check(dm_get_xid(hc->md), VS_WATCH_P | VS_IDENT))
1655 +                               continue;
1656                         if (old_nl)
1657                                 old_nl->next = (uint32_t) ((void *) nl -
1658                                                            (void *) old_nl);
1659 @@ -612,10 +622,11 @@ static struct hash_cell *__find_device_h
1660         if (!md)
1661                 goto out;
1662  
1663 -       mdptr = dm_get_mdptr(md);
1664 +       if (vx_check(dm_get_xid(md), VS_WATCH_P | VS_IDENT))
1665 +               mdptr = dm_get_mdptr(md);
1666 +
1667         if (!mdptr)
1668                 dm_put(md);
1669 -
1670  out:
1671         return mdptr;
1672  }
1673 @@ -1405,8 +1416,8 @@ static int ctl_ioctl(uint command, struc
1674         ioctl_fn fn = NULL;
1675         size_t param_size;
1676  
1677 -       /* only root can play with this */
1678 -       if (!capable(CAP_SYS_ADMIN))
1679 +       /* only root and certain contexts can play with this */
1680 +       if (!vx_capable(CAP_SYS_ADMIN, VXC_ADMIN_MAPPER))
1681                 return -EACCES;
1682  
1683         if (_IOC_TYPE(command) != DM_IOCTL)
1684 diff -NurpP --minimal linux-2.6.29.1/drivers/net/tun.c linux-2.6.29.1-vs2.3.0.36.9-pre5/drivers/net/tun.c
1685 --- linux-2.6.29.1/drivers/net/tun.c    2009-03-24 14:19:23.000000000 +0100
1686 +++ linux-2.6.29.1-vs2.3.0.36.9-pre5/drivers/net/tun.c  2009-03-25 01:51:59.000000000 +0100
1687 @@ -61,6 +61,7 @@
1688  #include <linux/crc32.h>
1689  #include <linux/nsproxy.h>
1690  #include <linux/virtio_net.h>
1691 +#include <linux/vs_network.h>
1692  #include <net/net_namespace.h>
1693  #include <net/netns/generic.h>
1694  
1695 @@ -93,6 +94,7 @@ struct tun_struct {
1696         int                     attached;
1697         uid_t                   owner;
1698         gid_t                   group;
1699 +       nid_t                   nid;
1700  
1701         wait_queue_head_t       read_wait;
1702         struct sk_buff_head     readq;
1703 @@ -697,6 +699,7 @@ static void tun_setup(struct net_device 
1704  
1705         tun->owner = -1;
1706         tun->group = -1;
1707 +       tun->nid = current->nid;
1708  
1709         dev->ethtool_ops = &tun_ethtool_ops;
1710         dev->destructor = free_netdev;
1711 @@ -727,6 +730,9 @@ static int tun_set_iff(struct net *net, 
1712         tn = net_generic(net, tun_net_id);
1713         tun = tun_get_by_name(tn, ifr->ifr_name);
1714         if (tun) {
1715 +               if (!nx_check(tun->nid, VS_IDENT | VS_HOSTID | VS_ADMIN_P))
1716 +                       return -EPERM;
1717 +
1718                 if (tun->attached)
1719                         return -EBUSY;
1720  
1721 @@ -735,7 +741,7 @@ static int tun_set_iff(struct net *net, 
1722                       cred->euid != tun->owner) ||
1723                      (tun->group != -1 &&
1724                       cred->egid != tun->group)) &&
1725 -                   !capable(CAP_NET_ADMIN)) {
1726 +                    !cap_raised(current_cap(), CAP_NET_ADMIN)) {
1727                         return -EPERM;
1728                 }
1729         }
1730 @@ -747,7 +753,7 @@ static int tun_set_iff(struct net *net, 
1731  
1732                 err = -EINVAL;
1733  
1734 -               if (!capable(CAP_NET_ADMIN))
1735 +               if (!nx_capable(CAP_NET_ADMIN, NXC_TUN_CREATE))
1736                         return -EPERM;
1737  
1738                 /* Set dev type */
1739 @@ -987,6 +993,16 @@ static int tun_chr_ioctl(struct inode *i
1740                 DBG(KERN_INFO "%s: group set to %d\n", tun->dev->name, tun->group);
1741                 break;
1742  
1743 +       case TUNSETNID:
1744 +               if (!capable(CAP_CONTEXT))
1745 +                       return -EPERM;
1746 +
1747 +               /* Set nid owner of the device */
1748 +               tun->nid = (nid_t) arg;
1749 +
1750 +               DBG(KERN_INFO "%s: nid owner set to %u\n", tun->dev->name, tun->nid);
1751 +               break;
1752 +
1753         case TUNSETLINK:
1754                 /* Only allow setting the type when the interface is down */
1755                 rtnl_lock();
1756 diff -NurpP --minimal linux-2.6.29.1/fs/attr.c linux-2.6.29.1-vs2.3.0.36.9-pre5/fs/attr.c
1757 --- linux-2.6.29.1/fs/attr.c    2009-03-24 14:22:24.000000000 +0100
1758 +++ linux-2.6.29.1-vs2.3.0.36.9-pre5/fs/attr.c  2009-03-24 14:48:34.000000000 +0100
1759 @@ -14,6 +14,9 @@
1760  #include <linux/fcntl.h>
1761  #include <linux/quotaops.h>
1762  #include <linux/security.h>
1763 +#include <linux/proc_fs.h>
1764 +#include <linux/devpts_fs.h>
1765 +#include <linux/vs_tag.h>
1766  
1767  /* Taken over from the old code... */
1768  
1769 @@ -55,6 +58,10 @@ int inode_change_ok(struct inode *inode,
1770                 if (!is_owner_or_cap(inode))
1771                         goto error;
1772         }
1773 +
1774 +       if (dx_permission(inode, MAY_WRITE))
1775 +               goto error;
1776 +
1777  fine:
1778         retval = 0;
1779  error:
1780 @@ -78,6 +85,8 @@ int inode_setattr(struct inode * inode, 
1781                 inode->i_uid = attr->ia_uid;
1782         if (ia_valid & ATTR_GID)
1783                 inode->i_gid = attr->ia_gid;
1784 +       if ((ia_valid & ATTR_TAG) && IS_TAGGED(inode))
1785 +               inode->i_tag = attr->ia_tag;
1786         if (ia_valid & ATTR_ATIME)
1787                 inode->i_atime = timespec_trunc(attr->ia_atime,
1788                                                 inode->i_sb->s_time_gran);
1789 @@ -172,7 +181,8 @@ int notify_change(struct dentry * dentry
1790                 error = inode_change_ok(inode, attr);
1791                 if (!error) {
1792                         if ((ia_valid & ATTR_UID && attr->ia_uid != inode->i_uid) ||
1793 -                           (ia_valid & ATTR_GID && attr->ia_gid != inode->i_gid))
1794 +                           (ia_valid & ATTR_GID && attr->ia_gid != inode->i_gid) ||
1795 +                           (ia_valid & ATTR_TAG && attr->ia_tag != inode->i_tag))
1796                                 error = DQUOT_TRANSFER(inode, attr) ? -EDQUOT : 0;
1797                         if (!error)
1798                                 error = inode_setattr(inode, attr);
1799 diff -NurpP --minimal linux-2.6.29.1/fs/binfmt_aout.c linux-2.6.29.1-vs2.3.0.36.9-pre5/fs/binfmt_aout.c
1800 --- linux-2.6.29.1/fs/binfmt_aout.c     2009-03-24 14:22:24.000000000 +0100
1801 +++ linux-2.6.29.1-vs2.3.0.36.9-pre5/fs/binfmt_aout.c   2009-03-24 14:48:34.000000000 +0100
1802 @@ -24,6 +24,7 @@
1803  #include <linux/binfmts.h>
1804  #include <linux/personality.h>
1805  #include <linux/init.h>
1806 +#include <linux/vs_memory.h>
1807  
1808  #include <asm/system.h>
1809  #include <asm/uaccess.h>
1810 diff -NurpP --minimal linux-2.6.29.1/fs/binfmt_elf.c linux-2.6.29.1-vs2.3.0.36.9-pre5/fs/binfmt_elf.c
1811 --- linux-2.6.29.1/fs/binfmt_elf.c      2009-03-24 14:22:24.000000000 +0100
1812 +++ linux-2.6.29.1-vs2.3.0.36.9-pre5/fs/binfmt_elf.c    2009-03-24 14:48:34.000000000 +0100
1813 @@ -38,6 +38,7 @@
1814  #include <linux/random.h>
1815  #include <linux/elf.h>
1816  #include <linux/utsname.h>
1817 +#include <linux/vs_memory.h>
1818  #include <asm/uaccess.h>
1819  #include <asm/param.h>
1820  #include <asm/page.h>
1821 diff -NurpP --minimal linux-2.6.29.1/fs/binfmt_flat.c linux-2.6.29.1-vs2.3.0.36.9-pre5/fs/binfmt_flat.c
1822 --- linux-2.6.29.1/fs/binfmt_flat.c     2009-03-24 14:22:24.000000000 +0100
1823 +++ linux-2.6.29.1-vs2.3.0.36.9-pre5/fs/binfmt_flat.c   2009-03-24 14:48:34.000000000 +0100
1824 @@ -35,6 +35,7 @@
1825  #include <linux/init.h>
1826  #include <linux/flat.h>
1827  #include <linux/syscalls.h>
1828 +#include <linux/vs_memory.h>
1829  
1830  #include <asm/byteorder.h>
1831  #include <asm/system.h>
1832 diff -NurpP --minimal linux-2.6.29.1/fs/binfmt_som.c linux-2.6.29.1-vs2.3.0.36.9-pre5/fs/binfmt_som.c
1833 --- linux-2.6.29.1/fs/binfmt_som.c      2009-03-24 14:22:24.000000000 +0100
1834 +++ linux-2.6.29.1-vs2.3.0.36.9-pre5/fs/binfmt_som.c    2009-03-24 14:48:34.000000000 +0100
1835 @@ -28,6 +28,7 @@
1836  #include <linux/shm.h>
1837  #include <linux/personality.h>
1838  #include <linux/init.h>
1839 +#include <linux/vs_memory.h>
1840  
1841  #include <asm/uaccess.h>
1842  #include <asm/pgtable.h>
1843 diff -NurpP --minimal linux-2.6.29.1/fs/block_dev.c linux-2.6.29.1-vs2.3.0.36.9-pre5/fs/block_dev.c
1844 --- linux-2.6.29.1/fs/block_dev.c       2009-03-24 14:22:24.000000000 +0100
1845 +++ linux-2.6.29.1-vs2.3.0.36.9-pre5/fs/block_dev.c     2009-03-24 14:48:34.000000000 +0100
1846 @@ -24,6 +24,7 @@
1847  #include <linux/uio.h>
1848  #include <linux/namei.h>
1849  #include <linux/log2.h>
1850 +#include <linux/vs_device.h>
1851  #include <asm/uaccess.h>
1852  #include "internal.h"
1853  
1854 @@ -392,6 +393,7 @@ struct block_device *bdget(dev_t dev)
1855                 bdev->bd_invalidated = 0;
1856                 inode->i_mode = S_IFBLK;
1857                 inode->i_rdev = dev;
1858 +               inode->i_mdev = dev;
1859                 inode->i_bdev = bdev;
1860                 inode->i_data.a_ops = &def_blk_aops;
1861                 mapping_set_gfp_mask(&inode->i_data, GFP_USER);
1862 @@ -428,6 +430,11 @@ EXPORT_SYMBOL(bdput);
1863  static struct block_device *bd_acquire(struct inode *inode)
1864  {
1865         struct block_device *bdev;
1866 +       dev_t mdev;
1867 +
1868 +       if (!vs_map_blkdev(inode->i_rdev, &mdev, DATTR_OPEN))
1869 +               return NULL;
1870 +       inode->i_mdev = mdev;
1871  
1872         spin_lock(&bdev_lock);
1873         bdev = inode->i_bdev;
1874 @@ -438,7 +445,7 @@ static struct block_device *bd_acquire(s
1875         }
1876         spin_unlock(&bdev_lock);
1877  
1878 -       bdev = bdget(inode->i_rdev);
1879 +       bdev = bdget(mdev);
1880         if (bdev) {
1881                 spin_lock(&bdev_lock);
1882                 if (!inode->i_bdev) {
1883 diff -NurpP --minimal linux-2.6.29.1/fs/char_dev.c linux-2.6.29.1-vs2.3.0.36.9-pre5/fs/char_dev.c
1884 --- linux-2.6.29.1/fs/char_dev.c        2009-03-24 14:22:25.000000000 +0100
1885 +++ linux-2.6.29.1-vs2.3.0.36.9-pre5/fs/char_dev.c      2009-03-24 14:48:35.000000000 +0100
1886 @@ -21,6 +21,8 @@
1887  #include <linux/cdev.h>
1888  #include <linux/mutex.h>
1889  #include <linux/backing-dev.h>
1890 +#include <linux/vs_context.h>
1891 +#include <linux/vs_device.h>
1892  
1893  #include "internal.h"
1894  
1895 @@ -358,14 +360,21 @@ static int chrdev_open(struct inode *ino
1896         struct cdev *p;
1897         struct cdev *new = NULL;
1898         int ret = 0;
1899 +       dev_t mdev;
1900 +
1901 +       if (!vs_map_chrdev(inode->i_rdev, &mdev, DATTR_OPEN))
1902 +               return -EPERM;
1903 +       inode->i_mdev = mdev;
1904  
1905         spin_lock(&cdev_lock);
1906         p = inode->i_cdev;
1907         if (!p) {
1908                 struct kobject *kobj;
1909                 int idx;
1910 +
1911                 spin_unlock(&cdev_lock);
1912 -               kobj = kobj_lookup(cdev_map, inode->i_rdev, &idx);
1913 +
1914 +               kobj = kobj_lookup(cdev_map, mdev, &idx);
1915                 if (!kobj)
1916                         return -ENXIO;
1917                 new = container_of(kobj, struct cdev, kobj);
1918 diff -NurpP --minimal linux-2.6.29.1/fs/dcache.c linux-2.6.29.1-vs2.3.0.36.9-pre5/fs/dcache.c
1919 --- linux-2.6.29.1/fs/dcache.c  2009-03-24 14:22:25.000000000 +0100
1920 +++ linux-2.6.29.1-vs2.3.0.36.9-pre5/fs/dcache.c        2009-03-24 14:48:35.000000000 +0100
1921 @@ -32,6 +32,7 @@
1922  #include <linux/seqlock.h>
1923  #include <linux/swap.h>
1924  #include <linux/bootmem.h>
1925 +#include <linux/vs_limit.h>
1926  #include "internal.h"
1927  
1928  int sysctl_vfs_cache_pressure __read_mostly = 100;
1929 @@ -229,6 +230,8 @@ repeat:
1930                 return;
1931         }
1932  
1933 +       vx_dentry_dec(dentry);
1934 +
1935         /*
1936          * AV: ->d_delete() is _NOT_ allowed to block now.
1937          */
1938 @@ -320,6 +323,7 @@ static inline struct dentry * __dget_loc
1939  {
1940         atomic_inc(&dentry->d_count);
1941         dentry_lru_del_init(dentry);
1942 +       vx_dentry_inc(dentry);
1943         return dentry;
1944  }
1945  
1946 @@ -918,6 +922,9 @@ struct dentry *d_alloc(struct dentry * p
1947         struct dentry *dentry;
1948         char *dname;
1949  
1950 +       if (!vx_dentry_avail(1))
1951 +               return NULL;
1952 +
1953         dentry = kmem_cache_alloc(dentry_cache, GFP_KERNEL);
1954         if (!dentry)
1955                 return NULL;
1956 @@ -963,6 +970,7 @@ struct dentry *d_alloc(struct dentry * p
1957         if (parent)
1958                 list_add(&dentry->d_u.d_child, &parent->d_subdirs);
1959         dentry_stat.nr_dentry++;
1960 +       vx_dentry_inc(dentry);
1961         spin_unlock(&dcache_lock);
1962  
1963         return dentry;
1964 @@ -1418,6 +1426,7 @@ struct dentry * __d_lookup(struct dentry
1965                 }
1966  
1967                 atomic_inc(&dentry->d_count);
1968 +               vx_dentry_inc(dentry);
1969                 found = dentry;
1970                 spin_unlock(&dentry->d_lock);
1971                 break;
1972 diff -NurpP --minimal linux-2.6.29.1/fs/devpts/inode.c linux-2.6.29.1-vs2.3.0.36.9-pre5/fs/devpts/inode.c
1973 --- linux-2.6.29.1/fs/devpts/inode.c    2009-03-24 14:22:25.000000000 +0100
1974 +++ linux-2.6.29.1-vs2.3.0.36.9-pre5/fs/devpts/inode.c  2009-03-24 15:32:47.000000000 +0100
1975 @@ -19,12 +19,12 @@
1976  #include <linux/tty.h>
1977  #include <linux/mutex.h>
1978  #include <linux/idr.h>
1979 +#include <linux/magic.h>
1980  #include <linux/devpts_fs.h>
1981  #include <linux/parser.h>
1982  #include <linux/fsnotify.h>
1983  #include <linux/seq_file.h>
1984 -
1985 -#define DEVPTS_SUPER_MAGIC 0x1cd1
1986 +#include <linux/vs_base.h>
1987  
1988  #define DEVPTS_DEFAULT_MODE 0600
1989  /*
1990 @@ -36,6 +36,20 @@
1991  #define DEVPTS_DEFAULT_PTMX_MODE 0000
1992  #define PTMX_MINOR     2
1993  
1994 +static int devpts_permission(struct inode *inode, int mask)
1995 +{
1996 +       int ret = -EACCES;
1997 +
1998 +       /* devpts is xid tagged */
1999 +       if (vx_check((xid_t)inode->i_tag, VS_WATCH_P | VS_IDENT))
2000 +               ret = generic_permission(inode, mask, NULL);
2001 +       return ret;
2002 +}
2003 +
2004 +static struct inode_operations devpts_file_inode_operations = {
2005 +       .permission     = devpts_permission,
2006 +};
2007 +
2008  extern int pty_limit;                  /* Config limit on Unix98 ptys */
2009  static DEFINE_MUTEX(allocated_ptys_lock);
2010  
2011 @@ -254,6 +268,25 @@ static int devpts_show_options(struct se
2012         return 0;
2013  }
2014  
2015 +static int devpts_filter(struct dentry *de)
2016 +{
2017 +       /* devpts is xid tagged */
2018 +       return vx_check((xid_t)de->d_inode->i_tag, VS_WATCH_P | VS_IDENT);
2019 +}
2020 +
2021 +static int devpts_readdir(struct file * filp, void * dirent, filldir_t filldir)
2022 +{
2023 +       return dcache_readdir_filter(filp, dirent, filldir, devpts_filter);
2024 +}
2025 +
2026 +static struct file_operations devpts_dir_operations = {
2027 +       .open           = dcache_dir_open,
2028 +       .release        = dcache_dir_close,
2029 +       .llseek         = dcache_dir_lseek,
2030 +       .read           = generic_read_dir,
2031 +       .readdir        = devpts_readdir,
2032 +};
2033 +
2034  static const struct super_operations devpts_sops = {
2035         .statfs         = simple_statfs,
2036         .remount_fs     = devpts_remount,
2037 @@ -293,12 +326,15 @@ devpts_fill_super(struct super_block *s,
2038         inode = new_inode(s);
2039         if (!inode)
2040                 goto free_fsi;
2041 +
2042         inode->i_ino = 1;
2043         inode->i_mtime = inode->i_atime = inode->i_ctime = CURRENT_TIME;
2044         inode->i_mode = S_IFDIR | S_IRUGO | S_IXUGO | S_IWUSR;
2045         inode->i_op = &simple_dir_inode_operations;
2046 -       inode->i_fop = &simple_dir_operations;
2047 +       inode->i_fop = &devpts_dir_operations;
2048         inode->i_nlink = 2;
2049 +       /* devpts is xid tagged */
2050 +       inode->i_tag = (tag_t)vx_current_xid();
2051  
2052         s->s_root = d_alloc_root(inode);
2053         if (s->s_root)
2054 @@ -479,6 +515,7 @@ static int init_pts_mount(struct file_sy
2055         return err;
2056  }
2057  
2058 +
2059  static int devpts_get_sb(struct file_system_type *fs_type,
2060         int flags, const char *dev_name, void *data, struct vfsmount *mnt)
2061  {
2062 @@ -590,6 +627,9 @@ int devpts_pty_new(struct inode *ptmx_in
2063         inode->i_gid = opts->setgid ? opts->gid : current_fsgid();
2064         inode->i_mtime = inode->i_atime = inode->i_ctime = CURRENT_TIME;
2065         init_special_inode(inode, S_IFCHR|opts->mode, device);
2066 +       /* devpts is xid tagged */
2067 +       inode->i_tag = (tag_t)vx_current_xid();
2068 +       inode->i_op = &devpts_file_inode_operations;
2069         inode->i_private = tty;
2070         tty->driver_data = inode;
2071  
2072 diff -NurpP --minimal linux-2.6.29.1/fs/exec.c linux-2.6.29.1-vs2.3.0.36.9-pre5/fs/exec.c
2073 --- linux-2.6.29.1/fs/exec.c    2009-03-24 14:22:25.000000000 +0100
2074 +++ linux-2.6.29.1-vs2.3.0.36.9-pre5/fs/exec.c  2009-03-24 15:34:21.000000000 +0100
2075 @@ -257,7 +257,9 @@ static int __bprm_mm_init(struct linux_b
2076         if (err)
2077                 goto err;
2078  
2079 -       mm->stack_vm = mm->total_vm = 1;
2080 +       mm->total_vm = 0;
2081 +       vx_vmpages_inc(mm);
2082 +       mm->stack_vm = 1;
2083         up_write(&mm->mmap_sem);
2084         bprm->p = vma->vm_end - sizeof(void *);
2085         return 0;
2086 @@ -1450,7 +1452,7 @@ static int format_corename(char *corenam
2087                         /* UNIX time of coredump */
2088                         case 't': {
2089                                 struct timeval tv;
2090 -                               do_gettimeofday(&tv);
2091 +                               vx_gettimeofday(&tv);
2092                                 rc = snprintf(out_ptr, out_end - out_ptr,
2093                                               "%lu", tv.tv_sec);
2094                                 if (rc > out_end - out_ptr)
2095 diff -NurpP --minimal linux-2.6.29.1/fs/ext2/balloc.c linux-2.6.29.1-vs2.3.0.36.9-pre5/fs/ext2/balloc.c
2096 --- linux-2.6.29.1/fs/ext2/balloc.c     2009-03-24 14:22:25.000000000 +0100
2097 +++ linux-2.6.29.1-vs2.3.0.36.9-pre5/fs/ext2/balloc.c   2009-03-24 14:48:35.000000000 +0100
2098 @@ -16,6 +16,8 @@
2099  #include <linux/sched.h>
2100  #include <linux/buffer_head.h>
2101  #include <linux/capability.h>
2102 +#include <linux/vs_dlimit.h>
2103 +#include <linux/vs_tag.h>
2104  
2105  /*
2106   * balloc.c contains the blocks allocation and deallocation routines
2107 @@ -569,6 +571,7 @@ do_more:
2108         }
2109  error_return:
2110         brelse(bitmap_bh);
2111 +       DLIMIT_FREE_BLOCK(inode, freed);
2112         release_blocks(sb, freed);
2113         DQUOT_FREE_BLOCK(inode, freed);
2114  }
2115 @@ -701,7 +704,6 @@ ext2_try_to_allocate(struct super_block 
2116                         start = 0;
2117                 end = EXT2_BLOCKS_PER_GROUP(sb);
2118         }
2119 -
2120         BUG_ON(start > EXT2_BLOCKS_PER_GROUP(sb));
2121  
2122  repeat:
2123 @@ -1251,6 +1253,11 @@ ext2_fsblk_t ext2_new_blocks(struct inod
2124                 *errp = -EDQUOT;
2125                 return 0;
2126         }
2127 +       if (DLIMIT_ALLOC_BLOCK(inode, num)) {
2128 +               *errp = -ENOSPC;
2129 +               DQUOT_FREE_BLOCK(inode, num);
2130 +               return 0;
2131 +       }
2132  
2133         sbi = EXT2_SB(sb);
2134         es = EXT2_SB(sb)->s_es;
2135 @@ -1409,6 +1416,7 @@ allocated:
2136  
2137         *errp = 0;
2138         brelse(bitmap_bh);
2139 +       DLIMIT_FREE_BLOCK(inode, *count-num);
2140         DQUOT_FREE_BLOCK(inode, *count-num);
2141         *count = num;
2142         return ret_block;
2143 @@ -1419,8 +1427,10 @@ out:
2144         /*
2145          * Undo the block allocation
2146          */
2147 -       if (!performed_allocation)
2148 +       if (!performed_allocation) {
2149 +               DLIMIT_FREE_BLOCK(inode, *count);
2150                 DQUOT_FREE_BLOCK(inode, *count);
2151 +       }
2152         brelse(bitmap_bh);
2153         return 0;
2154  }
2155 diff -NurpP --minimal linux-2.6.29.1/fs/ext2/ext2.h linux-2.6.29.1-vs2.3.0.36.9-pre5/fs/ext2/ext2.h
2156 --- linux-2.6.29.1/fs/ext2/ext2.h       2008-12-25 00:26:37.000000000 +0100
2157 +++ linux-2.6.29.1-vs2.3.0.36.9-pre5/fs/ext2/ext2.h     2009-02-22 22:54:25.000000000 +0100
2158 @@ -170,6 +170,7 @@ extern const struct file_operations ext2
2159  extern const struct address_space_operations ext2_aops;
2160  extern const struct address_space_operations ext2_aops_xip;
2161  extern const struct address_space_operations ext2_nobh_aops;
2162 +extern int ext2_sync_flags(struct inode *inode);
2163  
2164  /* namei.c */
2165  extern const struct inode_operations ext2_dir_inode_operations;
2166 diff -NurpP --minimal linux-2.6.29.1/fs/ext2/file.c linux-2.6.29.1-vs2.3.0.36.9-pre5/fs/ext2/file.c
2167 --- linux-2.6.29.1/fs/ext2/file.c       2008-12-25 00:26:37.000000000 +0100
2168 +++ linux-2.6.29.1-vs2.3.0.36.9-pre5/fs/ext2/file.c     2009-02-22 22:54:25.000000000 +0100
2169 @@ -87,4 +87,5 @@ const struct inode_operations ext2_file_
2170         .setattr        = ext2_setattr,
2171         .permission     = ext2_permission,
2172         .fiemap         = ext2_fiemap,
2173 +       .sync_flags     = ext2_sync_flags,
2174  };
2175 diff -NurpP --minimal linux-2.6.29.1/fs/ext2/ialloc.c linux-2.6.29.1-vs2.3.0.36.9-pre5/fs/ext2/ialloc.c
2176 --- linux-2.6.29.1/fs/ext2/ialloc.c     2009-03-24 14:22:25.000000000 +0100
2177 +++ linux-2.6.29.1-vs2.3.0.36.9-pre5/fs/ext2/ialloc.c   2009-03-24 15:36:12.000000000 +0100
2178 @@ -17,6 +17,8 @@
2179  #include <linux/backing-dev.h>
2180  #include <linux/buffer_head.h>
2181  #include <linux/random.h>
2182 +#include <linux/vs_dlimit.h>
2183 +#include <linux/vs_tag.h>
2184  #include "ext2.h"
2185  #include "xattr.h"
2186  #include "acl.h"
2187 @@ -123,6 +125,7 @@ void ext2_free_inode (struct inode * ino
2188                 ext2_xattr_delete_inode(inode);
2189                 DQUOT_FREE_INODE(inode);
2190                 DQUOT_DROP(inode);
2191 +               DLIMIT_FREE_INODE(inode);
2192         }
2193  
2194         es = EXT2_SB(sb)->s_es;
2195 @@ -454,6 +457,11 @@ struct inode *ext2_new_inode(struct inod
2196         if (!inode)
2197                 return ERR_PTR(-ENOMEM);
2198  
2199 +       inode->i_tag = dx_current_fstag(sb);
2200 +       if (DLIMIT_ALLOC_INODE(inode)) {
2201 +               err = -ENOSPC;
2202 +               goto fail_dlim;
2203 +       }
2204         ei = EXT2_I(inode);
2205         sbi = EXT2_SB(sb);
2206         es = sbi->s_es;
2207 @@ -609,6 +617,7 @@ fail_free_drop:
2208  
2209  fail_drop:
2210         DQUOT_DROP(inode);
2211 +       DLIMIT_FREE_INODE(inode);
2212         inode->i_flags |= S_NOQUOTA;
2213         inode->i_nlink = 0;
2214         unlock_new_inode(inode);
2215 @@ -616,6 +625,8 @@ fail_drop:
2216         return ERR_PTR(err);
2217  
2218  fail:
2219 +       DLIMIT_FREE_INODE(inode);
2220 +fail_dlim:
2221         make_bad_inode(inode);
2222         iput(inode);
2223         return ERR_PTR(err);
2224 diff -NurpP --minimal linux-2.6.29.1/fs/ext2/inode.c linux-2.6.29.1-vs2.3.0.36.9-pre5/fs/ext2/inode.c
2225 --- linux-2.6.29.1/fs/ext2/inode.c      2009-03-24 14:22:25.000000000 +0100
2226 +++ linux-2.6.29.1-vs2.3.0.36.9-pre5/fs/ext2/inode.c    2009-03-24 15:41:38.000000000 +0100
2227 @@ -33,6 +33,7 @@
2228  #include <linux/mpage.h>
2229  #include <linux/fiemap.h>
2230  #include <linux/namei.h>
2231 +#include <linux/vs_tag.h>
2232  #include "ext2.h"
2233  #include "acl.h"
2234  #include "xip.h"
2235 @@ -1018,7 +1019,7 @@ void ext2_truncate(struct inode *inode)
2236                 return;
2237         if (ext2_inode_is_fast_symlink(inode))
2238                 return;
2239 -       if (IS_APPEND(inode) || IS_IMMUTABLE(inode))
2240 +       if (IS_APPEND(inode) || IS_IXORUNLINK(inode))
2241                 return;
2242  
2243         blocksize = inode->i_sb->s_blocksize;
2244 @@ -1156,38 +1157,72 @@ void ext2_set_inode_flags(struct inode *
2245  {
2246         unsigned int flags = EXT2_I(inode)->i_flags;
2247  
2248 -       inode->i_flags &= ~(S_SYNC|S_APPEND|S_IMMUTABLE|S_NOATIME|S_DIRSYNC);
2249 +       inode->i_flags &= ~(S_IMMUTABLE | S_IXUNLINK |
2250 +               S_SYNC | S_APPEND | S_NOATIME | S_DIRSYNC);
2251 +
2252 +
2253 +       if (flags & EXT2_IMMUTABLE_FL)
2254 +               inode->i_flags |= S_IMMUTABLE;
2255 +       if (flags & EXT2_IXUNLINK_FL)
2256 +               inode->i_flags |= S_IXUNLINK;
2257 +
2258         if (flags & EXT2_SYNC_FL)
2259                 inode->i_flags |= S_SYNC;
2260         if (flags & EXT2_APPEND_FL)
2261                 inode->i_flags |= S_APPEND;
2262 -       if (flags & EXT2_IMMUTABLE_FL)
2263 -               inode->i_flags |= S_IMMUTABLE;
2264         if (flags & EXT2_NOATIME_FL)
2265                 inode->i_flags |= S_NOATIME;
2266         if (flags & EXT2_DIRSYNC_FL)
2267                 inode->i_flags |= S_DIRSYNC;
2268 +
2269 +       inode->i_vflags &= ~(V_BARRIER | V_COW);
2270 +
2271 +       if (flags & EXT2_BARRIER_FL)
2272 +               inode->i_vflags |= V_BARRIER;
2273 +       if (flags & EXT2_COW_FL)
2274 +               inode->i_vflags |= V_COW;
2275  }
2276  
2277  /* Propagate flags from i_flags to EXT2_I(inode)->i_flags */
2278  void ext2_get_inode_flags(struct ext2_inode_info *ei)
2279  {
2280         unsigned int flags = ei->vfs_inode.i_flags;
2281 +       unsigned int vflags = ei->vfs_inode.i_vflags;
2282 +
2283 +       ei->i_flags &= ~(EXT2_SYNC_FL | EXT2_APPEND_FL |
2284 +                       EXT2_IMMUTABLE_FL | EXT2_IXUNLINK_FL |
2285 +                       EXT2_NOATIME_FL | EXT2_DIRSYNC_FL |
2286 +                       EXT2_BARRIER_FL | EXT2_COW_FL);
2287 +
2288 +       if (flags & S_IMMUTABLE)
2289 +               ei->i_flags |= EXT2_IMMUTABLE_FL;
2290 +       if (flags & S_IXUNLINK)
2291 +               ei->i_flags |= EXT2_IXUNLINK_FL;
2292  
2293 -       ei->i_flags &= ~(EXT2_SYNC_FL|EXT2_APPEND_FL|
2294 -                       EXT2_IMMUTABLE_FL|EXT2_NOATIME_FL|EXT2_DIRSYNC_FL);
2295         if (flags & S_SYNC)
2296                 ei->i_flags |= EXT2_SYNC_FL;
2297         if (flags & S_APPEND)
2298                 ei->i_flags |= EXT2_APPEND_FL;
2299 -       if (flags & S_IMMUTABLE)
2300 -               ei->i_flags |= EXT2_IMMUTABLE_FL;
2301         if (flags & S_NOATIME)
2302                 ei->i_flags |= EXT2_NOATIME_FL;
2303         if (flags & S_DIRSYNC)
2304                 ei->i_flags |= EXT2_DIRSYNC_FL;
2305 +
2306 +       if (vflags & V_BARRIER)
2307 +               ei->i_flags |= EXT2_BARRIER_FL;
2308 +       if (vflags & V_COW)
2309 +               ei->i_flags |= EXT2_COW_FL;
2310  }
2311  
2312 +int ext2_sync_flags(struct inode *inode)
2313 +{
2314 +       ext2_get_inode_flags(EXT2_I(inode));
2315 +       inode->i_ctime = CURRENT_TIME;
2316 +       mark_inode_dirty(inode);
2317 +       return 0;
2318 +}
2319 +
2320 +
2321  struct inode *ext2_iget (struct super_block *sb, unsigned long ino)
2322  {
2323         struct ext2_inode_info *ei;
2324 @@ -1195,6 +1230,8 @@ struct inode *ext2_iget (struct super_bl
2325         struct ext2_inode *raw_inode;
2326         struct inode *inode;
2327         long ret = -EIO;
2328 +       uid_t uid;
2329 +       gid_t gid;
2330         int n;
2331  
2332         inode = iget_locked(sb, ino);
2333 @@ -1217,12 +1254,17 @@ struct inode *ext2_iget (struct super_bl
2334         }
2335  
2336         inode->i_mode = le16_to_cpu(raw_inode->i_mode);
2337 -       inode->i_uid = (uid_t)le16_to_cpu(raw_inode->i_uid_low);
2338 -       inode->i_gid = (gid_t)le16_to_cpu(raw_inode->i_gid_low);
2339 +       uid = (uid_t)le16_to_cpu(raw_inode->i_uid_low);
2340 +       gid = (gid_t)le16_to_cpu(raw_inode->i_gid_low);
2341         if (!(test_opt (inode->i_sb, NO_UID32))) {
2342 -               inode->i_uid |= le16_to_cpu(raw_inode->i_uid_high) << 16;
2343 -               inode->i_gid |= le16_to_cpu(raw_inode->i_gid_high) << 16;
2344 +               uid |= le16_to_cpu(raw_inode->i_uid_high) << 16;
2345 +               gid |= le16_to_cpu(raw_inode->i_gid_high) << 16;
2346         }
2347 +       inode->i_uid = INOTAG_UID(DX_TAG(inode), uid, gid);
2348 +       inode->i_gid = INOTAG_GID(DX_TAG(inode), uid, gid);
2349 +       inode->i_tag = INOTAG_TAG(DX_TAG(inode), uid, gid,
2350 +               le16_to_cpu(raw_inode->i_raw_tag));
2351 +
2352         inode->i_nlink = le16_to_cpu(raw_inode->i_links_count);
2353         inode->i_size = le32_to_cpu(raw_inode->i_size);
2354         inode->i_atime.tv_sec = (signed)le32_to_cpu(raw_inode->i_atime);
2355 @@ -1320,8 +1362,8 @@ static int ext2_update_inode(struct inod
2356         struct ext2_inode_info *ei = EXT2_I(inode);
2357         struct super_block *sb = inode->i_sb;
2358         ino_t ino = inode->i_ino;
2359 -       uid_t uid = inode->i_uid;
2360 -       gid_t gid = inode->i_gid;
2361 +       uid_t uid = TAGINO_UID(DX_TAG(inode), inode->i_uid, inode->i_tag);
2362 +       gid_t gid = TAGINO_GID(DX_TAG(inode), inode->i_gid, inode->i_tag);
2363         struct buffer_head * bh;
2364         struct ext2_inode * raw_inode = ext2_get_inode(sb, ino, &bh);
2365         int n;
2366 @@ -1357,6 +1399,9 @@ static int ext2_update_inode(struct inod
2367                 raw_inode->i_uid_high = 0;
2368                 raw_inode->i_gid_high = 0;
2369         }
2370 +#ifdef CONFIG_TAGGING_INTERN
2371 +       raw_inode->i_raw_tag = cpu_to_le16(inode->i_tag);
2372 +#endif
2373         raw_inode->i_links_count = cpu_to_le16(inode->i_nlink);
2374         raw_inode->i_size = cpu_to_le32(inode->i_size);
2375         raw_inode->i_atime = cpu_to_le32(inode->i_atime.tv_sec);
2376 @@ -1443,7 +1488,8 @@ int ext2_setattr(struct dentry *dentry, 
2377         if (error)
2378                 return error;
2379         if ((iattr->ia_valid & ATTR_UID && iattr->ia_uid != inode->i_uid) ||
2380 -           (iattr->ia_valid & ATTR_GID && iattr->ia_gid != inode->i_gid)) {
2381 +           (iattr->ia_valid & ATTR_GID && iattr->ia_gid != inode->i_gid) ||
2382 +           (iattr->ia_valid & ATTR_TAG && iattr->ia_tag != inode->i_tag)) {
2383                 error = DQUOT_TRANSFER(inode, iattr) ? -EDQUOT : 0;
2384                 if (error)
2385                         return error;
2386 diff -NurpP --minimal linux-2.6.29.1/fs/ext2/ioctl.c linux-2.6.29.1-vs2.3.0.36.9-pre5/fs/ext2/ioctl.c
2387 --- linux-2.6.29.1/fs/ext2/ioctl.c      2009-03-24 14:22:25.000000000 +0100
2388 +++ linux-2.6.29.1-vs2.3.0.36.9-pre5/fs/ext2/ioctl.c    2009-03-24 14:48:35.000000000 +0100
2389 @@ -14,6 +14,7 @@
2390  #include <linux/compat.h>
2391  #include <linux/mount.h>
2392  #include <linux/smp_lock.h>
2393 +#include <linux/mount.h>
2394  #include <asm/current.h>
2395  #include <asm/uaccess.h>
2396  
2397 @@ -52,6 +53,11 @@ long ext2_ioctl(struct file *filp, unsig
2398  
2399                 flags = ext2_mask_flags(inode->i_mode, flags);
2400  
2401 +               if (IS_BARRIER(inode)) {
2402 +                       vxwprintk_task(1, "messing with the barrier.");
2403 +                       return -EACCES;
2404 +               }
2405 +
2406                 mutex_lock(&inode->i_mutex);
2407                 /* Is it quota file? Do not allow user to mess with it */
2408                 if (IS_NOQUOTA(inode)) {
2409 @@ -67,7 +73,9 @@ long ext2_ioctl(struct file *filp, unsig
2410                  *
2411                  * This test looks nicer. Thanks to Pauline Middelink
2412                  */
2413 -               if ((flags ^ oldflags) & (EXT2_APPEND_FL | EXT2_IMMUTABLE_FL)) {
2414 +               if ((oldflags & EXT2_IMMUTABLE_FL) ||
2415 +                       ((flags ^ oldflags) & (EXT2_APPEND_FL |
2416 +                       EXT2_IMMUTABLE_FL | EXT2_IXUNLINK_FL))) {
2417                         if (!capable(CAP_LINUX_IMMUTABLE)) {
2418                                 mutex_unlock(&inode->i_mutex);
2419                                 ret = -EPERM;
2420 diff -NurpP --minimal linux-2.6.29.1/fs/ext2/namei.c linux-2.6.29.1-vs2.3.0.36.9-pre5/fs/ext2/namei.c
2421 --- linux-2.6.29.1/fs/ext2/namei.c      2009-03-24 14:22:25.000000000 +0100
2422 +++ linux-2.6.29.1-vs2.3.0.36.9-pre5/fs/ext2/namei.c    2009-03-24 14:48:35.000000000 +0100
2423 @@ -31,6 +31,7 @@
2424   */
2425  
2426  #include <linux/pagemap.h>
2427 +#include <linux/vs_tag.h>
2428  #include "ext2.h"
2429  #include "xattr.h"
2430  #include "acl.h"
2431 @@ -68,6 +69,7 @@ static struct dentry *ext2_lookup(struct
2432                 inode = ext2_iget(dir->i_sb, ino);
2433                 if (IS_ERR(inode))
2434                         return ERR_CAST(inode);
2435 +               dx_propagate_tag(nd, inode);
2436         }
2437         return d_splice_alias(inode, dentry);
2438  }
2439 @@ -388,6 +390,7 @@ const struct inode_operations ext2_dir_i
2440  #endif
2441         .setattr        = ext2_setattr,
2442         .permission     = ext2_permission,
2443 +       .sync_flags     = ext2_sync_flags,
2444  };
2445  
2446  const struct inode_operations ext2_special_inode_operations = {
2447 @@ -399,4 +402,5 @@ const struct inode_operations ext2_speci
2448  #endif
2449         .setattr        = ext2_setattr,
2450         .permission     = ext2_permission,
2451 +       .sync_flags     = ext2_sync_flags,
2452  };
2453 diff -NurpP --minimal linux-2.6.29.1/fs/ext2/super.c linux-2.6.29.1-vs2.3.0.36.9-pre5/fs/ext2/super.c
2454 --- linux-2.6.29.1/fs/ext2/super.c      2009-03-24 14:22:25.000000000 +0100
2455 +++ linux-2.6.29.1-vs2.3.0.36.9-pre5/fs/ext2/super.c    2009-03-24 14:48:35.000000000 +0100
2456 @@ -391,7 +391,8 @@ enum {
2457         Opt_err_ro, Opt_nouid32, Opt_nocheck, Opt_debug,
2458         Opt_oldalloc, Opt_orlov, Opt_nobh, Opt_user_xattr, Opt_nouser_xattr,
2459         Opt_acl, Opt_noacl, Opt_xip, Opt_ignore, Opt_err, Opt_quota,
2460 -       Opt_usrquota, Opt_grpquota, Opt_reservation, Opt_noreservation
2461 +       Opt_usrquota, Opt_grpquota, Opt_reservation, Opt_noreservation,
2462 +       Opt_tag, Opt_notag, Opt_tagid
2463  };
2464  
2465  static const match_table_t tokens = {
2466 @@ -419,6 +420,9 @@ static const match_table_t tokens = {
2467         {Opt_acl, "acl"},
2468         {Opt_noacl, "noacl"},
2469         {Opt_xip, "xip"},
2470 +       {Opt_tag, "tag"},
2471 +       {Opt_notag, "notag"},
2472 +       {Opt_tagid, "tagid=%u"},
2473         {Opt_grpquota, "grpquota"},
2474         {Opt_ignore, "noquota"},
2475         {Opt_quota, "quota"},
2476 @@ -489,6 +493,20 @@ static int parse_options (char * options
2477                 case Opt_nouid32:
2478                         set_opt (sbi->s_mount_opt, NO_UID32);
2479                         break;
2480 +#ifndef CONFIG_TAGGING_NONE
2481 +               case Opt_tag:
2482 +                       set_opt (sbi->s_mount_opt, TAGGED);
2483 +                       break;
2484 +               case Opt_notag:
2485 +                       clear_opt (sbi->s_mount_opt, TAGGED);
2486 +                       break;
2487 +#endif
2488 +#ifdef CONFIG_PROPAGATE
2489 +               case Opt_tagid:
2490 +                       /* use args[0] */
2491 +                       set_opt (sbi->s_mount_opt, TAGGED);
2492 +                       break;
2493 +#endif
2494                 case Opt_nocheck:
2495                         clear_opt (sbi->s_mount_opt, CHECK);
2496                         break;
2497 @@ -838,6 +856,8 @@ static int ext2_fill_super(struct super_
2498         if (!parse_options ((char *) data, sbi))
2499                 goto failed_mount;
2500  
2501 +       if (EXT2_SB(sb)->s_mount_opt & EXT2_MOUNT_TAGGED)
2502 +               sb->s_flags |= MS_TAGGED;
2503         sb->s_flags = (sb->s_flags & ~MS_POSIXACL) |
2504                 ((EXT2_SB(sb)->s_mount_opt & EXT2_MOUNT_POSIX_ACL) ?
2505                  MS_POSIXACL : 0);
2506 @@ -1170,6 +1190,13 @@ static int ext2_remount (struct super_bl
2507                 goto restore_opts;
2508         }
2509  
2510 +       if ((sbi->s_mount_opt & EXT2_MOUNT_TAGGED) &&
2511 +               !(sb->s_flags & MS_TAGGED)) {
2512 +               printk("EXT2-fs: %s: tagging not permitted on remount.\n",
2513 +                      sb->s_id);
2514 +               return -EINVAL;
2515 +       }
2516 +
2517         sb->s_flags = (sb->s_flags & ~MS_POSIXACL) |
2518                 ((sbi->s_mount_opt & EXT2_MOUNT_POSIX_ACL) ? MS_POSIXACL : 0);
2519  
2520 diff -NurpP --minimal linux-2.6.29.1/fs/ext2/symlink.c linux-2.6.29.1-vs2.3.0.36.9-pre5/fs/ext2/symlink.c
2521 --- linux-2.6.29.1/fs/ext2/symlink.c    2008-12-25 00:26:37.000000000 +0100
2522 +++ linux-2.6.29.1-vs2.3.0.36.9-pre5/fs/ext2/symlink.c  2009-02-22 22:54:25.000000000 +0100
2523 @@ -38,6 +38,7 @@ const struct inode_operations ext2_symli
2524         .listxattr      = ext2_listxattr,
2525         .removexattr    = generic_removexattr,
2526  #endif
2527 +       .sync_flags     = ext2_sync_flags,
2528  };
2529   
2530  const struct inode_operations ext2_fast_symlink_inode_operations = {
2531 @@ -49,4 +50,5 @@ const struct inode_operations ext2_fast_
2532         .listxattr      = ext2_listxattr,
2533         .removexattr    = generic_removexattr,
2534  #endif
2535 +       .sync_flags     = ext2_sync_flags,
2536  };
2537 diff -NurpP --minimal linux-2.6.29.1/fs/ext2/xattr.c linux-2.6.29.1-vs2.3.0.36.9-pre5/fs/ext2/xattr.c
2538 --- linux-2.6.29.1/fs/ext2/xattr.c      2008-12-25 00:26:37.000000000 +0100
2539 +++ linux-2.6.29.1-vs2.3.0.36.9-pre5/fs/ext2/xattr.c    2009-02-22 22:54:25.000000000 +0100
2540 @@ -60,6 +60,7 @@
2541  #include <linux/mbcache.h>
2542  #include <linux/quotaops.h>
2543  #include <linux/rwsem.h>
2544 +#include <linux/vs_dlimit.h>
2545  #include "ext2.h"
2546  #include "xattr.h"
2547  #include "acl.h"
2548 @@ -641,8 +642,12 @@ ext2_xattr_set2(struct inode *inode, str
2549                                    the inode.  */
2550                                 ea_bdebug(new_bh, "reusing block");
2551  
2552 +                               error = -ENOSPC;
2553 +                               if (DLIMIT_ALLOC_BLOCK(inode, 1))
2554 +                                       goto cleanup;
2555                                 error = -EDQUOT;
2556                                 if (DQUOT_ALLOC_BLOCK(inode, 1)) {
2557 +                                       DLIMIT_FREE_BLOCK(inode, 1);
2558                                         unlock_buffer(new_bh);
2559                                         goto cleanup;
2560                                 }
2561 @@ -731,6 +736,7 @@ ext2_xattr_set2(struct inode *inode, str
2562                         le32_add_cpu(&HDR(old_bh)->h_refcount, -1);
2563                         if (ce)
2564                                 mb_cache_entry_release(ce);
2565 +                       DLIMIT_FREE_BLOCK(inode, 1);
2566                         DQUOT_FREE_BLOCK(inode, 1);
2567                         mark_buffer_dirty(old_bh);
2568                         ea_bdebug(old_bh, "refcount now=%d",
2569 @@ -794,6 +800,7 @@ ext2_xattr_delete_inode(struct inode *in
2570                 mark_buffer_dirty(bh);
2571                 if (IS_SYNC(inode))
2572                         sync_dirty_buffer(bh);
2573 +               DLIMIT_FREE_BLOCK(inode, 1);
2574                 DQUOT_FREE_BLOCK(inode, 1);
2575         }
2576         EXT2_I(inode)->i_file_acl = 0;
2577 diff -NurpP --minimal linux-2.6.29.1/fs/ext3/balloc.c linux-2.6.29.1-vs2.3.0.36.9-pre5/fs/ext3/balloc.c
2578 --- linux-2.6.29.1/fs/ext3/balloc.c     2009-03-24 14:22:25.000000000 +0100
2579 +++ linux-2.6.29.1-vs2.3.0.36.9-pre5/fs/ext3/balloc.c   2009-03-25 00:53:20.000000000 +0100
2580 @@ -19,6 +19,8 @@
2581  #include <linux/ext3_jbd.h>
2582  #include <linux/quotaops.h>
2583  #include <linux/buffer_head.h>
2584 +#include <linux/vs_dlimit.h>
2585 +#include <linux/vs_tag.h>
2586  
2587  /*
2588   * balloc.c contains the blocks allocation and deallocation routines
2589 @@ -675,8 +677,10 @@ void ext3_free_blocks(handle_t *handle, 
2590                 return;
2591         }
2592         ext3_free_blocks_sb(handle, sb, block, count, &dquot_freed_blocks);
2593 -       if (dquot_freed_blocks)
2594 +       if (dquot_freed_blocks) {
2595 +               DLIMIT_FREE_BLOCK(inode, dquot_freed_blocks);
2596                 DQUOT_FREE_BLOCK(inode, dquot_freed_blocks);
2597 +       }
2598         return;
2599  }
2600  
2601 @@ -1415,18 +1419,33 @@ out:
2602   *
2603   * Check if filesystem has at least 1 free block available for allocation.
2604   */
2605 -static int ext3_has_free_blocks(struct ext3_sb_info *sbi)
2606 +static int ext3_has_free_blocks(struct super_block *sb)
2607  {
2608 -       ext3_fsblk_t free_blocks, root_blocks;
2609 +       struct ext3_sb_info *sbi = EXT3_SB(sb);
2610 +       unsigned long long free_blocks, root_blocks;
2611 +       int cond;
2612  
2613         free_blocks = percpu_counter_read_positive(&sbi->s_freeblocks_counter);
2614         root_blocks = le32_to_cpu(sbi->s_es->s_r_blocks_count);
2615 -       if (free_blocks < root_blocks + 1 && !capable(CAP_SYS_RESOURCE) &&
2616 +
2617 +       vxdprintk(VXD_CBIT(dlim, 3),
2618 +               "ext3_has_free_blocks(%p): free=%llu, root=%llu",
2619 +               sb, free_blocks, root_blocks);
2620 +
2621 +       DLIMIT_ADJUST_BLOCK(sb, dx_current_tag(), &free_blocks, &root_blocks);
2622 +
2623 +       cond = (free_blocks < root_blocks + 1 &&
2624 +               !capable(CAP_SYS_RESOURCE) &&
2625                 sbi->s_resuid != current_fsuid() &&
2626 -               (sbi->s_resgid == 0 || !in_group_p (sbi->s_resgid))) {
2627 -               return 0;
2628 -       }
2629 -       return 1;
2630 +               (sbi->s_resgid == 0 || !in_group_p (sbi->s_resgid)));
2631 +
2632 +       vxdprintk(VXD_CBIT(dlim, 3),
2633 +               "ext3_has_free_blocks(%p): %llu<%llu+1, %c, %u!=%u r=%d",
2634 +               sb, free_blocks, root_blocks,
2635 +               !capable(CAP_SYS_RESOURCE)?'1':'0',
2636 +               sbi->s_resuid, current_fsuid(), cond?0:1);
2637 +
2638 +       return (cond ? 0 : 1);
2639  }
2640  
2641  /**
2642 @@ -1443,7 +1462,7 @@ static int ext3_has_free_blocks(struct e
2643   */
2644  int ext3_should_retry_alloc(struct super_block *sb, int *retries)
2645  {
2646 -       if (!ext3_has_free_blocks(EXT3_SB(sb)) || (*retries)++ > 3)
2647 +       if (!ext3_has_free_blocks(sb) || (*retries)++ > 3)
2648                 return 0;
2649  
2650         jbd_debug(1, "%s: retrying operation after ENOSPC\n", sb->s_id);
2651 @@ -1506,6 +1525,8 @@ ext3_fsblk_t ext3_new_blocks(handle_t *h
2652                 *errp = -EDQUOT;
2653                 return 0;
2654         }
2655 +       if (DLIMIT_ALLOC_BLOCK(inode, num))
2656 +           goto out_dlimit;
2657  
2658         sbi = EXT3_SB(sb);
2659         es = EXT3_SB(sb)->s_es;
2660 @@ -1522,7 +1543,7 @@ ext3_fsblk_t ext3_new_blocks(handle_t *h
2661         if (block_i && ((windowsz = block_i->rsv_window_node.rsv_goal_size) > 0))
2662                 my_rsv = &block_i->rsv_window_node;
2663  
2664 -       if (!ext3_has_free_blocks(sbi)) {
2665 +       if (!ext3_has_free_blocks(sb)) {
2666                 *errp = -ENOSPC;
2667                 goto out;
2668         }
2669 @@ -1715,12 +1736,16 @@ allocated:
2670         *errp = 0;
2671         brelse(bitmap_bh);
2672         DQUOT_FREE_BLOCK(inode, *count-num);
2673 +       DLIMIT_FREE_BLOCK(inode, *count-num);
2674         *count = num;
2675         return ret_block;
2676  
2677  io_error:
2678         *errp = -EIO;
2679  out:
2680 +       if (!performed_allocation)
2681 +               DLIMIT_FREE_BLOCK(inode, *count);
2682 +out_dlimit:
2683         if (fatal) {
2684                 *errp = fatal;
2685                 ext3_std_error(sb, fatal);
2686 diff -NurpP --minimal linux-2.6.29.1/fs/ext3/file.c linux-2.6.29.1-vs2.3.0.36.9-pre5/fs/ext3/file.c
2687 --- linux-2.6.29.1/fs/ext3/file.c       2008-12-25 00:26:37.000000000 +0100
2688 +++ linux-2.6.29.1-vs2.3.0.36.9-pre5/fs/ext3/file.c     2009-02-22 22:54:25.000000000 +0100
2689 @@ -135,5 +135,6 @@ const struct inode_operations ext3_file_
2690  #endif
2691         .permission     = ext3_permission,
2692         .fiemap         = ext3_fiemap,
2693 +       .sync_flags     = ext3_sync_flags,
2694  };
2695  
2696 diff -NurpP --minimal linux-2.6.29.1/fs/ext3/ialloc.c linux-2.6.29.1-vs2.3.0.36.9-pre5/fs/ext3/ialloc.c
2697 --- linux-2.6.29.1/fs/ext3/ialloc.c     2009-03-24 14:22:25.000000000 +0100
2698 +++ linux-2.6.29.1-vs2.3.0.36.9-pre5/fs/ext3/ialloc.c   2009-03-24 15:44:06.000000000 +0100
2699 @@ -23,6 +23,8 @@
2700  #include <linux/buffer_head.h>
2701  #include <linux/random.h>
2702  #include <linux/bitops.h>
2703 +#include <linux/vs_dlimit.h>
2704 +#include <linux/vs_tag.h>
2705  
2706  #include <asm/byteorder.h>
2707  
2708 @@ -127,6 +129,7 @@ void ext3_free_inode (handle_t *handle, 
2709         ext3_xattr_delete_inode(handle, inode);
2710         DQUOT_FREE_INODE(inode);
2711         DQUOT_DROP(inode);
2712 +       DLIMIT_FREE_INODE(inode);
2713  
2714         is_directory = S_ISDIR(inode->i_mode);
2715  
2716 @@ -440,6 +443,12 @@ struct inode *ext3_new_inode(handle_t *h
2717         inode = new_inode(sb);
2718         if (!inode)
2719                 return ERR_PTR(-ENOMEM);
2720 +
2721 +       inode->i_tag = dx_current_fstag(sb);
2722 +       if (DLIMIT_ALLOC_INODE(inode)) {
2723 +               err = -ENOSPC;
2724 +               goto out_dlimit;
2725 +       }
2726         ei = EXT3_I(inode);
2727  
2728         sbi = EXT3_SB(sb);
2729 @@ -613,6 +622,8 @@ got:
2730  fail:
2731         ext3_std_error(sb, err);
2732  out:
2733 +       DLIMIT_FREE_INODE(inode);
2734 +out_dlimit:
2735         iput(inode);
2736         ret = ERR_PTR(err);
2737  really_out:
2738 @@ -624,6 +635,7 @@ fail_free_drop:
2739  
2740  fail_drop:
2741         DQUOT_DROP(inode);
2742 +       DLIMIT_FREE_INODE(inode);
2743         inode->i_flags |= S_NOQUOTA;
2744         inode->i_nlink = 0;
2745         unlock_new_inode(inode);
2746 diff -NurpP --minimal linux-2.6.29.1/fs/ext3/inode.c linux-2.6.29.1-vs2.3.0.36.9-pre5/fs/ext3/inode.c
2747 --- linux-2.6.29.1/fs/ext3/inode.c      2009-03-24 14:22:25.000000000 +0100
2748 +++ linux-2.6.29.1-vs2.3.0.36.9-pre5/fs/ext3/inode.c    2009-03-24 15:44:29.000000000 +0100
2749 @@ -38,6 +38,7 @@
2750  #include <linux/bio.h>
2751  #include <linux/fiemap.h>
2752  #include <linux/namei.h>
2753 +#include <linux/vs_tag.h>
2754  #include "xattr.h"
2755  #include "acl.h"
2756  
2757 @@ -2288,7 +2289,7 @@ static void ext3_free_branches(handle_t 
2758  
2759  int ext3_can_truncate(struct inode *inode)
2760  {
2761 -       if (IS_APPEND(inode) || IS_IMMUTABLE(inode))
2762 +       if (IS_APPEND(inode) || IS_IXORUNLINK(inode))
2763                 return 0;
2764         if (S_ISREG(inode->i_mode))
2765                 return 1;
2766 @@ -2662,36 +2663,84 @@ void ext3_set_inode_flags(struct inode *
2767  {
2768         unsigned int flags = EXT3_I(inode)->i_flags;
2769  
2770 -       inode->i_flags &= ~(S_SYNC|S_APPEND|S_IMMUTABLE|S_NOATIME|S_DIRSYNC);
2771 +       inode->i_flags &= ~(S_IMMUTABLE | S_IXUNLINK |
2772 +               S_SYNC | S_APPEND | S_NOATIME | S_DIRSYNC);
2773 +
2774 +       if (flags & EXT3_IMMUTABLE_FL)
2775 +               inode->i_flags |= S_IMMUTABLE;
2776 +       if (flags & EXT3_IXUNLINK_FL)
2777 +               inode->i_flags |= S_IXUNLINK;
2778 +
2779         if (flags & EXT3_SYNC_FL)
2780                 inode->i_flags |= S_SYNC;
2781         if (flags & EXT3_APPEND_FL)
2782                 inode->i_flags |= S_APPEND;
2783 -       if (flags & EXT3_IMMUTABLE_FL)
2784 -               inode->i_flags |= S_IMMUTABLE;
2785         if (flags & EXT3_NOATIME_FL)
2786                 inode->i_flags |= S_NOATIME;
2787         if (flags & EXT3_DIRSYNC_FL)
2788                 inode->i_flags |= S_DIRSYNC;
2789 +
2790 +       inode->i_vflags &= ~(V_BARRIER | V_COW);
2791 +
2792 +       if (flags & EXT3_BARRIER_FL)
2793 +               inode->i_vflags |= V_BARRIER;
2794 +       if (flags & EXT3_COW_FL)
2795 +               inode->i_vflags |= V_COW;
2796  }
2797  
2798  /* Propagate flags from i_flags to EXT3_I(inode)->i_flags */
2799  void ext3_get_inode_flags(struct ext3_inode_info *ei)
2800  {
2801         unsigned int flags = ei->vfs_inode.i_flags;
2802 +       unsigned int vflags = ei->vfs_inode.i_vflags;
2803 +
2804 +       ei->i_flags &= ~(EXT3_SYNC_FL | EXT3_APPEND_FL |
2805 +                       EXT3_IMMUTABLE_FL | EXT3_IXUNLINK_FL |
2806 +                       EXT3_NOATIME_FL | EXT3_DIRSYNC_FL |
2807 +                       EXT3_BARRIER_FL | EXT3_COW_FL);
2808 +
2809 +       if (flags & S_IMMUTABLE)
2810 +               ei->i_flags |= EXT3_IMMUTABLE_FL;
2811 +       if (flags & S_IXUNLINK)
2812 +               ei->i_flags |= EXT3_IXUNLINK_FL;
2813  
2814 -       ei->i_flags &= ~(EXT3_SYNC_FL|EXT3_APPEND_FL|
2815 -                       EXT3_IMMUTABLE_FL|EXT3_NOATIME_FL|EXT3_DIRSYNC_FL);
2816         if (flags & S_SYNC)
2817                 ei->i_flags |= EXT3_SYNC_FL;
2818         if (flags & S_APPEND)
2819                 ei->i_flags |= EXT3_APPEND_FL;
2820 -       if (flags & S_IMMUTABLE)
2821 -               ei->i_flags |= EXT3_IMMUTABLE_FL;
2822         if (flags & S_NOATIME)
2823                 ei->i_flags |= EXT3_NOATIME_FL;
2824         if (flags & S_DIRSYNC)
2825                 ei->i_flags |= EXT3_DIRSYNC_FL;
2826 +
2827 +       if (vflags & V_BARRIER)
2828 +               ei->i_flags |= EXT3_BARRIER_FL;
2829 +       if (vflags & V_COW)
2830 +               ei->i_flags |= EXT3_COW_FL;
2831 +}
2832 +
2833 +int ext3_sync_flags(struct inode *inode)
2834 +{
2835 +       struct ext3_iloc iloc;
2836 +       handle_t *handle;
2837 +       int err;
2838 +
2839 +       handle = ext3_journal_start(inode, 1);
2840 +       if (IS_ERR(handle))
2841 +               return PTR_ERR(handle);
2842 +       if (IS_SYNC(inode))
2843 +               handle->h_sync = 1;
2844 +       err = ext3_reserve_inode_write(handle, inode, &iloc);
2845 +       if (err)
2846 +               goto flags_err;
2847 +
2848 +       ext3_get_inode_flags(EXT3_I(inode));
2849 +       inode->i_ctime = CURRENT_TIME;
2850 +
2851 +       err = ext3_mark_iloc_dirty(handle, inode, &iloc);
2852 +flags_err:
2853 +       ext3_journal_stop(handle);
2854 +       return err;
2855  }
2856  
2857  struct inode *ext3_iget(struct super_block *sb, unsigned long ino)
2858 @@ -2703,6 +2752,8 @@ struct inode *ext3_iget(struct super_blo
2859         struct inode *inode;
2860         long ret;
2861         int block;
2862 +       uid_t uid;
2863 +       gid_t gid;
2864  
2865         inode = iget_locked(sb, ino);
2866         if (!inode)
2867 @@ -2723,12 +2774,17 @@ struct inode *ext3_iget(struct super_blo
2868         bh = iloc.bh;
2869         raw_inode = ext3_raw_inode(&iloc);
2870         inode->i_mode = le16_to_cpu(raw_inode->i_mode);
2871 -       inode->i_uid = (uid_t)le16_to_cpu(raw_inode->i_uid_low);
2872 -       inode->i_gid = (gid_t)le16_to_cpu(raw_inode->i_gid_low);
2873 +       uid = (uid_t)le16_to_cpu(raw_inode->i_uid_low);
2874 +       gid = (gid_t)le16_to_cpu(raw_inode->i_gid_low);
2875         if(!(test_opt (inode->i_sb, NO_UID32))) {
2876 -               inode->i_uid |= le16_to_cpu(raw_inode->i_uid_high) << 16;
2877 -               inode->i_gid |= le16_to_cpu(raw_inode->i_gid_high) << 16;
2878 +               uid |= le16_to_cpu(raw_inode->i_uid_high) << 16;
2879 +               gid |= le16_to_cpu(raw_inode->i_gid_high) << 16;
2880         }
2881 +       inode->i_uid = INOTAG_UID(DX_TAG(inode), uid, gid);
2882 +       inode->i_gid = INOTAG_GID(DX_TAG(inode), uid, gid);
2883 +       inode->i_tag = INOTAG_TAG(DX_TAG(inode), uid, gid,
2884 +               le16_to_cpu(raw_inode->i_raw_tag));
2885 +
2886         inode->i_nlink = le16_to_cpu(raw_inode->i_links_count);
2887         inode->i_size = le32_to_cpu(raw_inode->i_size);
2888         inode->i_atime.tv_sec = (signed)le32_to_cpu(raw_inode->i_atime);
2889 @@ -2859,6 +2915,8 @@ static int ext3_do_update_inode(handle_t
2890         struct ext3_inode *raw_inode = ext3_raw_inode(iloc);
2891         struct ext3_inode_info *ei = EXT3_I(inode);
2892         struct buffer_head *bh = iloc->bh;
2893 +       uid_t uid = TAGINO_UID(DX_TAG(inode), inode->i_uid, inode->i_tag);
2894 +       gid_t gid = TAGINO_GID(DX_TAG(inode), inode->i_gid, inode->i_tag);
2895         int err = 0, rc, block;
2896  
2897         /* For fields not not tracking in the in-memory inode,
2898 @@ -2869,29 +2927,32 @@ static int ext3_do_update_inode(handle_t
2899         ext3_get_inode_flags(ei);
2900         raw_inode->i_mode = cpu_to_le16(inode->i_mode);
2901         if(!(test_opt(inode->i_sb, NO_UID32))) {
2902 -               raw_inode->i_uid_low = cpu_to_le16(low_16_bits(inode->i_uid));
2903 -               raw_inode->i_gid_low = cpu_to_le16(low_16_bits(inode->i_gid));
2904 +               raw_inode->i_uid_low = cpu_to_le16(low_16_bits(uid));
2905 +               raw_inode->i_gid_low = cpu_to_le16(low_16_bits(gid));
2906  /*
2907   * Fix up interoperability with old kernels. Otherwise, old inodes get
2908   * re-used with the upper 16 bits of the uid/gid intact
2909   */
2910                 if(!ei->i_dtime) {
2911                         raw_inode->i_uid_high =
2912 -                               cpu_to_le16(high_16_bits(inode->i_uid));
2913 +                               cpu_to_le16(high_16_bits(uid));
2914                         raw_inode->i_gid_high =
2915 -                               cpu_to_le16(high_16_bits(inode->i_gid));
2916 +                               cpu_to_le16(high_16_bits(gid));
2917                 } else {
2918                         raw_inode->i_uid_high = 0;
2919                         raw_inode->i_gid_high = 0;
2920                 }
2921         } else {
2922                 raw_inode->i_uid_low =
2923 -                       cpu_to_le16(fs_high2lowuid(inode->i_uid));
2924 +                       cpu_to_le16(fs_high2lowuid(uid));
2925                 raw_inode->i_gid_low =
2926 -                       cpu_to_le16(fs_high2lowgid(inode->i_gid));
2927 +                       cpu_to_le16(fs_high2lowgid(gid));
2928                 raw_inode->i_uid_high = 0;
2929                 raw_inode->i_gid_high = 0;
2930         }
2931 +#ifdef CONFIG_TAGGING_INTERN
2932 +       raw_inode->i_raw_tag = cpu_to_le16(inode->i_tag);
2933 +#endif
2934         raw_inode->i_links_count = cpu_to_le16(inode->i_nlink);
2935         raw_inode->i_size = cpu_to_le32(ei->i_disksize);
2936         raw_inode->i_atime = cpu_to_le32(inode->i_atime.tv_sec);
2937 @@ -3044,7 +3105,8 @@ int ext3_setattr(struct dentry *dentry, 
2938                 return error;
2939  
2940         if ((ia_valid & ATTR_UID && attr->ia_uid != inode->i_uid) ||
2941 -               (ia_valid & ATTR_GID && attr->ia_gid != inode->i_gid)) {
2942 +               (ia_valid & ATTR_GID && attr->ia_gid != inode->i_gid) ||
2943 +               (ia_valid & ATTR_TAG && attr->ia_tag != inode->i_tag)) {
2944                 handle_t *handle;
2945  
2946                 /* (user+group)*(old+new) structure, inode write (sb,
2947 @@ -3066,6 +3128,8 @@ int ext3_setattr(struct dentry *dentry, 
2948                         inode->i_uid = attr->ia_uid;
2949                 if (attr->ia_valid & ATTR_GID)
2950                         inode->i_gid = attr->ia_gid;
2951 +               if ((attr->ia_valid & ATTR_TAG) && IS_TAGGED(inode))
2952 +                       inode->i_tag = attr->ia_tag;
2953                 error = ext3_mark_inode_dirty(handle, inode);
2954                 ext3_journal_stop(handle);
2955         }
2956 diff -NurpP --minimal linux-2.6.29.1/fs/ext3/ioctl.c linux-2.6.29.1-vs2.3.0.36.9-pre5/fs/ext3/ioctl.c
2957 --- linux-2.6.29.1/fs/ext3/ioctl.c      2009-03-24 14:22:25.000000000 +0100
2958 +++ linux-2.6.29.1-vs2.3.0.36.9-pre5/fs/ext3/ioctl.c    2009-03-24 14:48:35.000000000 +0100
2959 @@ -8,6 +8,7 @@
2960   */
2961  
2962  #include <linux/fs.h>
2963 +#include <linux/mount.h>
2964  #include <linux/jbd.h>
2965  #include <linux/capability.h>
2966  #include <linux/ext3_fs.h>
2967 @@ -16,6 +17,7 @@
2968  #include <linux/time.h>
2969  #include <linux/compat.h>
2970  #include <linux/smp_lock.h>
2971 +#include <linux/vs_tag.h>
2972  #include <asm/uaccess.h>
2973  
2974  int ext3_ioctl (struct inode * inode, struct file * filp, unsigned int cmd,
2975 @@ -55,6 +57,11 @@ int ext3_ioctl (struct inode * inode, st
2976  
2977                 flags = ext3_mask_flags(inode->i_mode, flags);
2978  
2979 +               if (IS_BARRIER(inode)) {
2980 +                       vxwprintk_task(1, "messing with the barrier.");
2981 +                       return -EACCES;
2982 +               }
2983 +
2984                 mutex_lock(&inode->i_mutex);
2985                 /* Is it quota file? Do not allow user to mess with it */
2986                 if (IS_NOQUOTA(inode)) {
2987 @@ -73,7 +80,9 @@ int ext3_ioctl (struct inode * inode, st
2988                  *
2989                  * This test looks nicer. Thanks to Pauline Middelink
2990                  */
2991 -               if ((flags ^ oldflags) & (EXT3_APPEND_FL | EXT3_IMMUTABLE_FL)) {
2992 +               if ((oldflags & EXT3_IMMUTABLE_FL) ||
2993 +                       ((flags ^ oldflags) & (EXT3_APPEND_FL |
2994 +                       EXT3_IMMUTABLE_FL | EXT3_IXUNLINK_FL))) {
2995                         if (!capable(CAP_LINUX_IMMUTABLE)) {
2996                                 mutex_unlock(&inode->i_mutex);
2997                                 err = -EPERM;
2998 diff -NurpP --minimal linux-2.6.29.1/fs/ext3/namei.c linux-2.6.29.1-vs2.3.0.36.9-pre5/fs/ext3/namei.c
2999 --- linux-2.6.29.1/fs/ext3/namei.c      2009-03-24 14:22:25.000000000 +0100
3000 +++ linux-2.6.29.1-vs2.3.0.36.9-pre5/fs/ext3/namei.c    2009-03-24 14:48:35.000000000 +0100
3001 @@ -36,6 +36,7 @@
3002  #include <linux/quotaops.h>
3003  #include <linux/buffer_head.h>
3004  #include <linux/bio.h>
3005 +#include <linux/vs_tag.h>
3006  
3007  #include "namei.h"
3008  #include "xattr.h"
3009 @@ -912,6 +913,7 @@ restart:
3010                                 if (bh)
3011                                         ll_rw_block(READ_META, 1, &bh);
3012                         }
3013 +               dx_propagate_tag(nd, inode);
3014                 }
3015                 if ((bh = bh_use[ra_ptr++]) == NULL)
3016                         goto next;
3017 @@ -2433,6 +2435,7 @@ const struct inode_operations ext3_dir_i
3018         .removexattr    = generic_removexattr,
3019  #endif
3020         .permission     = ext3_permission,
3021 +       .sync_flags     = ext3_sync_flags,
3022  };
3023  
3024  const struct inode_operations ext3_special_inode_operations = {
3025 @@ -2444,4 +2447,5 @@ const struct inode_operations ext3_speci
3026         .removexattr    = generic_removexattr,
3027  #endif
3028         .permission     = ext3_permission,
3029 +       .sync_flags     = ext3_sync_flags,
3030  };
3031 diff -NurpP --minimal linux-2.6.29.1/fs/ext3/super.c linux-2.6.29.1-vs2.3.0.36.9-pre5/fs/ext3/super.c
3032 --- linux-2.6.29.1/fs/ext3/super.c      2009-03-24 14:22:25.000000000 +0100
3033 +++ linux-2.6.29.1-vs2.3.0.36.9-pre5/fs/ext3/super.c    2009-03-24 14:48:35.000000000 +0100
3034 @@ -790,7 +790,7 @@ enum {
3035         Opt_usrjquota, Opt_grpjquota, Opt_offusrjquota, Opt_offgrpjquota,
3036         Opt_jqfmt_vfsold, Opt_jqfmt_vfsv0, Opt_quota, Opt_noquota,
3037         Opt_ignore, Opt_barrier, Opt_err, Opt_resize, Opt_usrquota,
3038 -       Opt_grpquota
3039 +       Opt_grpquota, Opt_tag, Opt_notag, Opt_tagid
3040  };
3041  
3042  static const match_table_t tokens = {
3043 @@ -843,6 +843,9 @@ static const match_table_t tokens = {
3044         {Opt_usrquota, "usrquota"},
3045         {Opt_barrier, "barrier=%u"},
3046         {Opt_resize, "resize"},
3047 +       {Opt_tag, "tag"},
3048 +       {Opt_notag, "notag"},
3049 +       {Opt_tagid, "tagid=%u"},
3050         {Opt_err, NULL},
3051  };
3052  
3053 @@ -935,6 +938,20 @@ static int parse_options (char *options,
3054                 case Opt_nouid32:
3055                         set_opt (sbi->s_mount_opt, NO_UID32);
3056                         break;
3057 +#ifndef CONFIG_TAGGING_NONE
3058 +               case Opt_tag:
3059 +                       set_opt (sbi->s_mount_opt, TAGGED);
3060 +                       break;
3061 +               case Opt_notag:
3062 +                       clear_opt (sbi->s_mount_opt, TAGGED);
3063 +                       break;
3064 +#endif
3065 +#ifdef CONFIG_PROPAGATE
3066 +               case Opt_tagid:
3067 +                       /* use args[0] */
3068 +                       set_opt (sbi->s_mount_opt, TAGGED);
3069 +                       break;
3070 +#endif
3071                 case Opt_nocheck:
3072                         clear_opt (sbi->s_mount_opt, CHECK);
3073                         break;
3074 @@ -1653,6 +1670,9 @@ static int ext3_fill_super (struct super
3075                             NULL, 0))
3076                 goto failed_mount;
3077  
3078 +       if (EXT3_SB(sb)->s_mount_opt & EXT3_MOUNT_TAGGED)
3079 +               sb->s_flags |= MS_TAGGED;
3080 +
3081         sb->s_flags = (sb->s_flags & ~MS_POSIXACL) |
3082                 ((sbi->s_mount_opt & EXT3_MOUNT_POSIX_ACL) ? MS_POSIXACL : 0);
3083  
3084 @@ -2527,6 +2547,13 @@ static int ext3_remount (struct super_bl
3085         if (sbi->s_mount_opt & EXT3_MOUNT_ABORT)
3086                 ext3_abort(sb, __func__, "Abort forced by user");
3087  
3088 +       if ((sbi->s_mount_opt & EXT3_MOUNT_TAGGED) &&
3089 +               !(sb->s_flags & MS_TAGGED)) {
3090 +               printk("EXT3-fs: %s: tagging not permitted on remount.\n",
3091 +                       sb->s_id);
3092 +               return -EINVAL;
3093 +       }
3094 +
3095         sb->s_flags = (sb->s_flags & ~MS_POSIXACL) |
3096                 ((sbi->s_mount_opt & EXT3_MOUNT_POSIX_ACL) ? MS_POSIXACL : 0);
3097  
3098 diff -NurpP --minimal linux-2.6.29.1/fs/ext3/symlink.c linux-2.6.29.1-vs2.3.0.36.9-pre5/fs/ext3/symlink.c
3099 --- linux-2.6.29.1/fs/ext3/symlink.c    2008-12-25 00:26:37.000000000 +0100
3100 +++ linux-2.6.29.1-vs2.3.0.36.9-pre5/fs/ext3/symlink.c  2009-02-22 22:54:25.000000000 +0100
3101 @@ -40,6 +40,7 @@ const struct inode_operations ext3_symli
3102         .listxattr      = ext3_listxattr,
3103         .removexattr    = generic_removexattr,
3104  #endif
3105 +       .sync_flags     = ext3_sync_flags,
3106  };
3107  
3108  const struct inode_operations ext3_fast_symlink_inode_operations = {
3109 @@ -51,4 +52,5 @@ const struct inode_operations ext3_fast_
3110         .listxattr      = ext3_listxattr,
3111         .removexattr    = generic_removexattr,
3112  #endif
3113 +       .sync_flags     = ext3_sync_flags,
3114  };
3115 diff -NurpP --minimal linux-2.6.29.1/fs/ext3/xattr.c linux-2.6.29.1-vs2.3.0.36.9-pre5/fs/ext3/xattr.c
3116 --- linux-2.6.29.1/fs/ext3/xattr.c      2008-12-25 00:26:37.000000000 +0100
3117 +++ linux-2.6.29.1-vs2.3.0.36.9-pre5/fs/ext3/xattr.c    2009-02-22 22:54:25.000000000 +0100
3118 @@ -58,6 +58,7 @@
3119  #include <linux/mbcache.h>
3120  #include <linux/quotaops.h>
3121  #include <linux/rwsem.h>
3122 +#include <linux/vs_dlimit.h>
3123  #include "xattr.h"
3124  #include "acl.h"
3125  
3126 @@ -498,6 +499,7 @@ ext3_xattr_release_block(handle_t *handl
3127                 error = ext3_journal_dirty_metadata(handle, bh);
3128                 if (IS_SYNC(inode))
3129                         handle->h_sync = 1;
3130 +                       DLIMIT_FREE_BLOCK(inode, 1);
3131                 DQUOT_FREE_BLOCK(inode, 1);
3132                 ea_bdebug(bh, "refcount now=%d; releasing",
3133                           le32_to_cpu(BHDR(bh)->h_refcount));
3134 @@ -771,11 +773,14 @@ inserted:
3135                         if (new_bh == bs->bh)
3136                                 ea_bdebug(new_bh, "keeping");
3137                         else {
3138 +                               error = -ENOSPC;
3139 +                               if (DLIMIT_ALLOC_BLOCK(inode, 1))
3140 +                                       goto cleanup;
3141                                 /* The old block is released after updating
3142                                    the inode. */
3143                                 error = -EDQUOT;
3144                                 if (DQUOT_ALLOC_BLOCK(inode, 1))
3145 -                                       goto cleanup;
3146 +                                       goto cleanup_dlimit;
3147                                 error = ext3_journal_get_write_access(handle,
3148                                                                       new_bh);
3149                                 if (error)
3150 @@ -849,6 +854,8 @@ cleanup:
3151  
3152  cleanup_dquot:
3153         DQUOT_FREE_BLOCK(inode, 1);
3154 +cleanup_dlimit:
3155 +       DLIMIT_FREE_BLOCK(inode, 1);
3156         goto cleanup;
3157  
3158  bad_block:
3159 diff -NurpP --minimal linux-2.6.29.1/fs/ext4/balloc.c linux-2.6.29.1-vs2.3.0.36.9-pre5/fs/ext4/balloc.c
3160 --- linux-2.6.29.1/fs/ext4/balloc.c     2009-03-24 14:22:25.000000000 +0100
3161 +++ linux-2.6.29.1-vs2.3.0.36.9-pre5/fs/ext4/balloc.c   2009-03-24 14:48:35.000000000 +0100
3162 @@ -17,6 +17,8 @@
3163  #include <linux/jbd2.h>
3164  #include <linux/quotaops.h>
3165  #include <linux/buffer_head.h>
3166 +#include <linux/vs_dlimit.h>
3167 +#include <linux/vs_tag.h>
3168  #include "ext4.h"
3169  #include "ext4_jbd2.h"
3170  #include "group.h"
3171 @@ -535,8 +537,10 @@ void ext4_free_blocks(handle_t *handle, 
3172  
3173         ext4_mb_free_blocks(handle, inode, block, count,
3174                             metadata, &dquot_freed_blocks);
3175 -       if (dquot_freed_blocks)
3176 +       if (dquot_freed_blocks) {
3177 +               DLIMIT_FREE_BLOCK(inode, dquot_freed_blocks);
3178                 DQUOT_FREE_BLOCK(inode, dquot_freed_blocks);
3179 +       }
3180         return;
3181  }
3182  
3183 diff -NurpP --minimal linux-2.6.29.1/fs/ext4/ext4.h linux-2.6.29.1-vs2.3.0.36.9-pre5/fs/ext4/ext4.h
3184 --- linux-2.6.29.1/fs/ext4/ext4.h       2009-03-24 14:22:25.000000000 +0100
3185 +++ linux-2.6.29.1-vs2.3.0.36.9-pre5/fs/ext4/ext4.h     2009-03-24 15:44:56.000000000 +0100
3186 @@ -243,8 +243,12 @@ struct flex_groups {
3187  #define EXT4_HUGE_FILE_FL               0x00040000 /* Set to each huge file */
3188  #define EXT4_EXTENTS_FL                        0x00080000 /* Inode uses extents */
3189  #define EXT4_EXT_MIGRATE               0x00100000 /* Inode is migrating */
3190 +#define EXT4_IXUNLINK_FL               0x08000000 /* Immutable invert on unlink */
3191  #define EXT4_RESERVED_FL               0x80000000 /* reserved for ext4 lib */
3192  
3193 +#define EXT4_BARRIER_FL                        0x04000000 /* Barrier for chroot() */
3194 +#define EXT4_COW_FL                    0x20000000 /* Copy on Write marker */
3195 +
3196  #define EXT4_FL_USER_VISIBLE           0x000BDFFF /* User visible flags */
3197  #define EXT4_FL_USER_MODIFIABLE                0x000B80FF /* User modifiable flags */
3198  
3199 @@ -541,6 +545,7 @@ do {                                                                               \
3200  #define EXT4_MOUNT_I_VERSION            0x2000000 /* i_version support */
3201  #define EXT4_MOUNT_DELALLOC            0x8000000 /* Delalloc support */
3202  #define EXT4_MOUNT_DATA_ERR_ABORT      0x10000000 /* Abort on file data write */
3203 +#define EXT4_MOUNT_TAGGED              (1<<24) /* Enable Context Tags */
3204  
3205  /* Compatibility, for having both ext2_fs.h and ext4_fs.h included at once */
3206  #ifndef _LINUX_EXT2_FS_H
3207 @@ -1076,6 +1081,7 @@ struct buffer_head *ext4_bread(handle_t 
3208                                                 ext4_lblk_t, int, int *);
3209  int ext4_get_block(struct inode *inode, sector_t iblock,
3210                                 struct buffer_head *bh_result, int create);
3211 +extern int ext4_sync_flags(struct inode *inode);
3212  
3213  extern struct inode *ext4_iget(struct super_block *, unsigned long);
3214  extern int  ext4_write_inode(struct inode *, int);
3215 diff -NurpP --minimal linux-2.6.29.1/fs/ext4/file.c linux-2.6.29.1-vs2.3.0.36.9-pre5/fs/ext4/file.c
3216 --- linux-2.6.29.1/fs/ext4/file.c       2009-03-24 14:22:25.000000000 +0100
3217 +++ linux-2.6.29.1-vs2.3.0.36.9-pre5/fs/ext4/file.c     2009-03-24 14:48:35.000000000 +0100
3218 @@ -171,5 +171,6 @@ const struct inode_operations ext4_file_
3219         .permission     = ext4_permission,
3220         .fallocate      = ext4_fallocate,
3221         .fiemap         = ext4_fiemap,
3222 +       .sync_flags     = ext4_sync_flags,
3223  };
3224  
3225 diff -NurpP --minimal linux-2.6.29.1/fs/ext4/ialloc.c linux-2.6.29.1-vs2.3.0.36.9-pre5/fs/ext4/ialloc.c
3226 --- linux-2.6.29.1/fs/ext4/ialloc.c     2009-03-24 14:22:25.000000000 +0100
3227 +++ linux-2.6.29.1-vs2.3.0.36.9-pre5/fs/ext4/ialloc.c   2009-03-24 14:48:35.000000000 +0100
3228 @@ -22,6 +22,8 @@
3229  #include <linux/random.h>
3230  #include <linux/bitops.h>
3231  #include <linux/blkdev.h>
3232 +#include <linux/vs_dlimit.h>
3233 +#include <linux/vs_tag.h>
3234  #include <asm/byteorder.h>
3235  #include "ext4.h"
3236  #include "ext4_jbd2.h"
3237 @@ -224,6 +226,7 @@ void ext4_free_inode(handle_t *handle, s
3238         ext4_xattr_delete_inode(handle, inode);
3239         DQUOT_FREE_INODE(inode);
3240         DQUOT_DROP(inode);
3241 +       DLIMIT_FREE_INODE(inode);
3242  
3243         is_directory = S_ISDIR(inode->i_mode);
3244  
3245 @@ -711,6 +714,12 @@ struct inode *ext4_new_inode(handle_t *h
3246         inode = new_inode(sb);
3247         if (!inode)
3248                 return ERR_PTR(-ENOMEM);
3249 +
3250 +       inode->i_tag = dx_current_fstag(sb);
3251 +       if (DLIMIT_ALLOC_INODE(inode)) {
3252 +               err = -ENOSPC;
3253 +               goto out_dlimit;
3254 +       }
3255         ei = EXT4_I(inode);
3256  
3257         sbi = EXT4_SB(sb);
3258 @@ -889,7 +898,8 @@ got:
3259          * newly created directory and file only if -o extent mount option is
3260          * specified
3261          */
3262 -       ei->i_flags = EXT4_I(dir)->i_flags & ~(EXT4_INDEX_FL|EXT4_EXTENTS_FL);
3263 +       ei->i_flags = EXT4_I(dir)->i_flags &
3264 +               ~(EXT4_INDEX_FL|EXT4_EXTENTS_FL|EXT4_IXUNLINK_FL|EXT4_BARRIER_FL);
3265         if (S_ISLNK(mode))
3266                 ei->i_flags &= ~(EXT4_IMMUTABLE_FL|EXT4_APPEND_FL);
3267         /* dirsync only applies to directories */
3268 @@ -949,6 +959,8 @@ got:
3269  fail:
3270         ext4_std_error(sb, err);
3271  out:
3272 +       DLIMIT_FREE_INODE(inode);
3273 +out_dlimit:
3274         iput(inode);
3275         ret = ERR_PTR(err);
3276  really_out:
3277 @@ -960,6 +972,7 @@ fail_free_drop:
3278  
3279  fail_drop:
3280         DQUOT_DROP(inode);
3281 +       DLIMIT_FREE_INODE(inode);
3282         inode->i_flags |= S_NOQUOTA;
3283         inode->i_nlink = 0;
3284         unlock_new_inode(inode);
3285 diff -NurpP --minimal linux-2.6.29.1/fs/ext4/inode.c linux-2.6.29.1-vs2.3.0.36.9-pre5/fs/ext4/inode.c
3286 --- linux-2.6.29.1/fs/ext4/inode.c      2009-03-24 14:22:25.000000000 +0100
3287 +++ linux-2.6.29.1-vs2.3.0.36.9-pre5/fs/ext4/inode.c    2009-03-24 14:48:35.000000000 +0100
3288 @@ -37,6 +37,7 @@
3289  #include <linux/namei.h>
3290  #include <linux/uio.h>
3291  #include <linux/bio.h>
3292 +#include <linux/vs_tag.h>
3293  #include "ext4_jbd2.h"
3294  #include "xattr.h"
3295  #include "acl.h"
3296 @@ -3781,7 +3782,7 @@ static void ext4_free_branches(handle_t 
3297  
3298  int ext4_can_truncate(struct inode *inode)
3299  {
3300 -       if (IS_APPEND(inode) || IS_IMMUTABLE(inode))
3301 +       if (IS_APPEND(inode) || IS_IXORUNLINK(inode))
3302                 return 0;
3303         if (S_ISREG(inode->i_mode))
3304                 return 1;
3305 @@ -4134,37 +4135,86 @@ void ext4_set_inode_flags(struct inode *
3306  {
3307         unsigned int flags = EXT4_I(inode)->i_flags;
3308  
3309 -       inode->i_flags &= ~(S_SYNC|S_APPEND|S_IMMUTABLE|S_NOATIME|S_DIRSYNC);
3310 +       inode->i_flags &= ~(S_IMMUTABLE | S_IXUNLINK |
3311 +               S_SYNC | S_APPEND | S_NOATIME | S_DIRSYNC);
3312 +
3313 +       if (flags & EXT4_IMMUTABLE_FL)
3314 +               inode->i_flags |= S_IMMUTABLE;
3315 +       if (flags & EXT4_IXUNLINK_FL)
3316 +               inode->i_flags |= S_IXUNLINK;
3317 +
3318         if (flags & EXT4_SYNC_FL)
3319                 inode->i_flags |= S_SYNC;
3320         if (flags & EXT4_APPEND_FL)
3321                 inode->i_flags |= S_APPEND;
3322 -       if (flags & EXT4_IMMUTABLE_FL)
3323 -               inode->i_flags |= S_IMMUTABLE;
3324         if (flags & EXT4_NOATIME_FL)
3325                 inode->i_flags |= S_NOATIME;
3326         if (flags & EXT4_DIRSYNC_FL)
3327                 inode->i_flags |= S_DIRSYNC;
3328 +
3329 +       inode->i_vflags &= ~(V_BARRIER | V_COW);
3330 +
3331 +       if (flags & EXT4_BARRIER_FL)
3332 +               inode->i_vflags |= V_BARRIER;
3333 +       if (flags & EXT4_COW_FL)
3334 +               inode->i_vflags |= V_COW;
3335  }
3336  
3337  /* Propagate flags from i_flags to EXT4_I(inode)->i_flags */
3338  void ext4_get_inode_flags(struct ext4_inode_info *ei)
3339  {
3340         unsigned int flags = ei->vfs_inode.i_flags;
3341 +       unsigned int vflags = ei->vfs_inode.i_vflags;
3342 +
3343 +       ei->i_flags &= ~(EXT4_SYNC_FL | EXT4_APPEND_FL |
3344 +                       EXT4_IMMUTABLE_FL | EXT4_IXUNLINK_FL |
3345 +                       EXT4_NOATIME_FL | EXT4_DIRSYNC_FL |
3346 +                       EXT4_BARRIER_FL | EXT4_COW_FL);
3347 +
3348 +       if (flags & S_IMMUTABLE)
3349 +               ei->i_flags |= EXT4_IMMUTABLE_FL;
3350 +       if (flags & S_IXUNLINK)
3351 +               ei->i_flags |= EXT4_IXUNLINK_FL;
3352  
3353 -       ei->i_flags &= ~(EXT4_SYNC_FL|EXT4_APPEND_FL|
3354 -                       EXT4_IMMUTABLE_FL|EXT4_NOATIME_FL|EXT4_DIRSYNC_FL);
3355         if (flags & S_SYNC)
3356                 ei->i_flags |= EXT4_SYNC_FL;
3357         if (flags & S_APPEND)
3358                 ei->i_flags |= EXT4_APPEND_FL;
3359 -       if (flags & S_IMMUTABLE)
3360 -               ei->i_flags |= EXT4_IMMUTABLE_FL;
3361         if (flags & S_NOATIME)
3362                 ei->i_flags |= EXT4_NOATIME_FL;
3363         if (flags & S_DIRSYNC)
3364                 ei->i_flags |= EXT4_DIRSYNC_FL;
3365 +
3366 +       if (vflags & V_BARRIER)
3367 +               ei->i_flags |= EXT4_BARRIER_FL;
3368 +       if (vflags & V_COW)
3369 +               ei->i_flags |= EXT4_COW_FL;
3370 +}
3371 +
3372 +int ext4_sync_flags(struct inode *inode)
3373 +{
3374 +       struct ext4_iloc iloc;
3375 +       handle_t *handle;
3376 +       int err;
3377 +
3378 +       handle = ext4_journal_start(inode, 1);
3379 +       if (IS_ERR(handle))
3380 +               return PTR_ERR(handle);
3381 +       if (IS_SYNC(inode))
3382 +               handle->h_sync = 1;
3383 +       err = ext4_reserve_inode_write(handle, inode, &iloc);
3384 +       if (err)
3385 +               goto flags_err;
3386 +
3387 +       ext4_get_inode_flags(EXT4_I(inode));
3388 +       inode->i_ctime = CURRENT_TIME;
3389 +
3390 +       err = ext4_mark_iloc_dirty(handle, inode, &iloc);
3391 +flags_err:
3392 +       ext4_journal_stop(handle);
3393 +       return err;
3394  }
3395 +
3396  static blkcnt_t ext4_inode_blocks(struct ext4_inode *raw_inode,
3397                                         struct ext4_inode_info *ei)
3398  {
3399 @@ -4197,6 +4247,8 @@ struct inode *ext4_iget(struct super_blo
3400         struct inode *inode;
3401         long ret;
3402         int block;
3403 +       uid_t uid;
3404 +       gid_t gid;
3405  
3406         inode = iget_locked(sb, ino);
3407         if (!inode)
3408 @@ -4216,12 +4268,16 @@ struct inode *ext4_iget(struct super_blo
3409         bh = iloc.bh;
3410         raw_inode = ext4_raw_inode(&iloc);
3411         inode->i_mode = le16_to_cpu(raw_inode->i_mode);
3412 -       inode->i_uid = (uid_t)le16_to_cpu(raw_inode->i_uid_low);
3413 -       inode->i_gid = (gid_t)le16_to_cpu(raw_inode->i_gid_low);
3414 +       uid = (uid_t)le16_to_cpu(raw_inode->i_uid_low);
3415 +       gid = (gid_t)le16_to_cpu(raw_inode->i_gid_low);
3416         if (!(test_opt(inode->i_sb, NO_UID32))) {
3417 -               inode->i_uid |= le16_to_cpu(raw_inode->i_uid_high) << 16;
3418 -               inode->i_gid |= le16_to_cpu(raw_inode->i_gid_high) << 16;
3419 +               uid |= le16_to_cpu(raw_inode->i_uid_high) << 16;
3420 +               gid |= le16_to_cpu(raw_inode->i_gid_high) << 16;
3421         }
3422 +       inode->i_uid = INOTAG_UID(DX_TAG(inode), uid, gid);
3423 +       inode->i_gid = INOTAG_GID(DX_TAG(inode), uid, gid);
3424 +       inode->i_tag = INOTAG_TAG(DX_TAG(inode), uid, gid,
3425 +               le16_to_cpu(raw_inode->i_raw_tag));
3426         inode->i_nlink = le16_to_cpu(raw_inode->i_links_count);
3427  
3428         ei->i_state = 0;
3429 @@ -4387,6 +4443,8 @@ static int ext4_do_update_inode(handle_t
3430         struct ext4_inode *raw_inode = ext4_raw_inode(iloc);
3431         struct ext4_inode_info *ei = EXT4_I(inode);
3432         struct buffer_head *bh = iloc->bh;
3433 +       uid_t uid = TAGINO_UID(DX_TAG(inode), inode->i_uid, inode->i_tag);
3434 +       gid_t gid = TAGINO_GID(DX_TAG(inode), inode->i_gid, inode->i_tag);
3435         int err = 0, rc, block;
3436  
3437         /* For fields not not tracking in the in-memory inode,
3438 @@ -4397,29 +4455,32 @@ static int ext4_do_update_inode(handle_t
3439         ext4_get_inode_flags(ei);
3440         raw_inode->i_mode = cpu_to_le16(inode->i_mode);
3441         if (!(test_opt(inode->i_sb, NO_UID32))) {
3442 -               raw_inode->i_uid_low = cpu_to_le16(low_16_bits(inode->i_uid));
3443 -               raw_inode->i_gid_low = cpu_to_le16(low_16_bits(inode->i_gid));
3444 +               raw_inode->i_uid_low = cpu_to_le16(low_16_bits(uid));
3445 +               raw_inode->i_gid_low = cpu_to_le16(low_16_bits(gid));
3446  /*
3447   * Fix up interoperability with old kernels. Otherwise, old inodes get
3448   * re-used with the upper 16 bits of the uid/gid intact
3449   */
3450                 if (!ei->i_dtime) {
3451                         raw_inode->i_uid_high =
3452 -                               cpu_to_le16(high_16_bits(inode->i_uid));
3453 +                               cpu_to_le16(high_16_bits(uid));
3454                         raw_inode->i_gid_high =
3455 -                               cpu_to_le16(high_16_bits(inode->i_gid));
3456 +                               cpu_to_le16(high_16_bits(gid));
3457                 } else {
3458                         raw_inode->i_uid_high = 0;
3459                         raw_inode->i_gid_high = 0;
3460                 }
3461         } else {
3462                 raw_inode->i_uid_low =
3463 -                       cpu_to_le16(fs_high2lowuid(inode->i_uid));
3464 +                       cpu_to_le16(fs_high2lowuid(uid));
3465                 raw_inode->i_gid_low =
3466 -                       cpu_to_le16(fs_high2lowgid(inode->i_gid));
3467 +                       cpu_to_le16(fs_high2lowgid(gid));
3468                 raw_inode->i_uid_high = 0;
3469                 raw_inode->i_gid_high = 0;
3470         }
3471 +#ifdef CONFIG_TAGGING_INTERN
3472 +       raw_inode->i_raw_tag = cpu_to_le16(inode->i_tag);
3473 +#endif
3474         raw_inode->i_links_count = cpu_to_le16(inode->i_nlink);
3475  
3476         EXT4_INODE_SET_XTIME(i_ctime, inode, raw_inode);
3477 @@ -4601,7 +4662,8 @@ int ext4_setattr(struct dentry *dentry, 
3478                 return error;
3479  
3480         if ((ia_valid & ATTR_UID && attr->ia_uid != inode->i_uid) ||
3481 -               (ia_valid & ATTR_GID && attr->ia_gid != inode->i_gid)) {
3482 +               (ia_valid & ATTR_GID && attr->ia_gid != inode->i_gid) ||
3483 +               (ia_valid & ATTR_TAG && attr->ia_tag != inode->i_tag)) {
3484                 handle_t *handle;
3485  
3486                 /* (user+group)*(old+new) structure, inode write (sb,
3487 @@ -4623,6 +4685,8 @@ int ext4_setattr(struct dentry *dentry, 
3488                         inode->i_uid = attr->ia_uid;
3489                 if (attr->ia_valid & ATTR_GID)
3490                         inode->i_gid = attr->ia_gid;
3491 +               if ((attr->ia_valid & ATTR_TAG) && IS_TAGGED(inode))
3492 +                       inode->i_tag = attr->ia_tag;
3493                 error = ext4_mark_inode_dirty(handle, inode);
3494                 ext4_journal_stop(handle);
3495         }
3496 diff -NurpP --minimal linux-2.6.29.1/fs/ext4/ioctl.c linux-2.6.29.1-vs2.3.0.36.9-pre5/fs/ext4/ioctl.c
3497 --- linux-2.6.29.1/fs/ext4/ioctl.c      2009-03-24 14:22:25.000000000 +0100
3498 +++ linux-2.6.29.1-vs2.3.0.36.9-pre5/fs/ext4/ioctl.c    2009-03-24 14:48:35.000000000 +0100
3499 @@ -8,12 +8,14 @@
3500   */
3501  
3502  #include <linux/fs.h>
3503 +#include <linux/mount.h>
3504  #include <linux/jbd2.h>
3505  #include <linux/capability.h>
3506  #include <linux/time.h>
3507  #include <linux/compat.h>
3508  #include <linux/smp_lock.h>
3509  #include <linux/mount.h>
3510 +#include <linux/vs_tag.h>
3511  #include <asm/uaccess.h>
3512  #include "ext4_jbd2.h"
3513  #include "ext4.h"
3514 @@ -51,6 +53,11 @@ long ext4_ioctl(struct file *filp, unsig
3515                 if (!S_ISDIR(inode->i_mode))
3516                         flags &= ~EXT4_DIRSYNC_FL;
3517  
3518 +               if (IS_BARRIER(inode)) {
3519 +                       vxwprintk_task(1, "messing with the barrier.");
3520 +                       return -EACCES;
3521 +               }
3522 +
3523                 err = -EPERM;
3524                 mutex_lock(&inode->i_mutex);
3525                 /* Is it quota file? Do not allow user to mess with it */
3526 @@ -68,7 +75,9 @@ long ext4_ioctl(struct file *filp, unsig
3527                  *
3528                  * This test looks nicer. Thanks to Pauline Middelink
3529                  */
3530 -               if ((flags ^ oldflags) & (EXT4_APPEND_FL | EXT4_IMMUTABLE_FL)) {
3531 +               if ((oldflags & EXT4_IMMUTABLE_FL) ||
3532 +                       ((flags ^ oldflags) & (EXT4_APPEND_FL |
3533 +                       EXT4_IMMUTABLE_FL | EXT4_IXUNLINK_FL))) {
3534                         if (!capable(CAP_LINUX_IMMUTABLE))
3535                                 goto flags_out;
3536                 }
3537 diff -NurpP --minimal linux-2.6.29.1/fs/ext4/namei.c linux-2.6.29.1-vs2.3.0.36.9-pre5/fs/ext4/namei.c
3538 --- linux-2.6.29.1/fs/ext4/namei.c      2009-03-24 14:22:25.000000000 +0100
3539 +++ linux-2.6.29.1-vs2.3.0.36.9-pre5/fs/ext4/namei.c    2009-03-24 14:48:35.000000000 +0100
3540 @@ -34,6 +34,7 @@
3541  #include <linux/quotaops.h>
3542  #include <linux/buffer_head.h>
3543  #include <linux/bio.h>
3544 +#include <linux/vs_tag.h>
3545  #include "ext4.h"
3546  #include "ext4_jbd2.h"
3547  
3548 @@ -917,6 +918,7 @@ restart:
3549                                 if (bh)
3550                                         ll_rw_block(READ_META, 1, &bh);
3551                         }
3552 +               dx_propagate_tag(nd, inode);
3553                 }
3554                 if ((bh = bh_use[ra_ptr++]) == NULL)
3555                         goto next;
3556 @@ -2481,6 +2483,7 @@ const struct inode_operations ext4_dir_i
3557         .removexattr    = generic_removexattr,
3558  #endif
3559         .permission     = ext4_permission,
3560 +       .sync_flags     = ext4_sync_flags,
3561  };
3562  
3563  const struct inode_operations ext4_special_inode_operations = {
3564 @@ -2492,4 +2495,5 @@ const struct inode_operations ext4_speci
3565         .removexattr    = generic_removexattr,
3566  #endif
3567         .permission     = ext4_permission,
3568 +       .sync_flags     = ext4_sync_flags,
3569  };
3570 diff -NurpP --minimal linux-2.6.29.1/fs/ext4/super.c linux-2.6.29.1-vs2.3.0.36.9-pre5/fs/ext4/super.c
3571 --- linux-2.6.29.1/fs/ext4/super.c      2009-03-24 14:22:25.000000000 +0100
3572 +++ linux-2.6.29.1-vs2.3.0.36.9-pre5/fs/ext4/super.c    2009-03-24 15:46:48.000000000 +0100
3573 @@ -1013,7 +1013,8 @@ enum {
3574         Opt_ignore, Opt_barrier, Opt_err, Opt_resize, Opt_usrquota,
3575         Opt_grpquota, Opt_i_version,
3576         Opt_stripe, Opt_delalloc, Opt_nodelalloc,
3577 -       Opt_inode_readahead_blks, Opt_journal_ioprio
3578 +       Opt_inode_readahead_blks, Opt_journal_ioprio,
3579 +       Opt_tag, Opt_notag, Opt_tagid
3580  };
3581  
3582  static const match_table_t tokens = {
3583 @@ -1073,6 +1074,9 @@ static const match_table_t tokens = {
3584         {Opt_nodelalloc, "nodelalloc"},
3585         {Opt_inode_readahead_blks, "inode_readahead_blks=%u"},
3586         {Opt_journal_ioprio, "journal_ioprio=%u"},
3587 +       {Opt_tag, "tag"},
3588 +       {Opt_notag, "notag"},
3589 +       {Opt_tagid, "tagid=%u"},
3590         {Opt_err, NULL},
3591  };
3592  
3593 @@ -1168,6 +1172,20 @@ static int parse_options(char *options, 
3594                 case Opt_nouid32:
3595                         set_opt(sbi->s_mount_opt, NO_UID32);
3596                         break;
3597 +#ifndef CONFIG_TAGGING_NONE
3598 +               case Opt_tag:
3599 +                       set_opt (sbi->s_mount_opt, TAGGED);
3600 +                       break;
3601 +               case Opt_notag:
3602 +                       clear_opt (sbi->s_mount_opt, TAGGED);
3603 +                       break;
3604 +#endif
3605 +#ifdef CONFIG_PROPAGATE
3606 +               case Opt_tagid:
3607 +                       /* use args[0] */
3608 +                       set_opt (sbi->s_mount_opt, TAGGED);
3609 +                       break;
3610 +#endif
3611                 case Opt_debug:
3612                         set_opt(sbi->s_mount_opt, DEBUG);
3613                         break;
3614 @@ -2113,6 +2131,9 @@ static int ext4_fill_super(struct super_
3615                            &journal_ioprio, NULL, 0))
3616                 goto failed_mount;
3617  
3618 +       if (EXT4_SB(sb)->s_mount_opt & EXT4_MOUNT_TAGGED)
3619 +               sb->s_flags |= MS_TAGGED;
3620 +
3621         sb->s_flags = (sb->s_flags & ~MS_POSIXACL) |
3622                 ((sbi->s_mount_opt & EXT4_MOUNT_POSIX_ACL) ? MS_POSIXACL : 0);
3623  
3624 @@ -3160,6 +3181,13 @@ static int ext4_remount(struct super_blo
3625         if (sbi->s_mount_opt & EXT4_MOUNT_ABORT)
3626                 ext4_abort(sb, __func__, "Abort forced by user");
3627  
3628 +       if ((sbi->s_mount_opt & EXT4_MOUNT_TAGGED) &&
3629 +               !(sb->s_flags & MS_TAGGED)) {
3630 +               printk("EXT4-fs: %s: tagging not permitted on remount.\n",
3631 +                       sb->s_id);
3632 +               return -EINVAL;
3633 +       }
3634 +
3635         sb->s_flags = (sb->s_flags & ~MS_POSIXACL) |
3636                 ((sbi->s_mount_opt & EXT4_MOUNT_POSIX_ACL) ? MS_POSIXACL : 0);
3637  
3638 diff -NurpP --minimal linux-2.6.29.1/fs/ext4/symlink.c linux-2.6.29.1-vs2.3.0.36.9-pre5/fs/ext4/symlink.c
3639 --- linux-2.6.29.1/fs/ext4/symlink.c    2008-12-25 00:26:37.000000000 +0100
3640 +++ linux-2.6.29.1-vs2.3.0.36.9-pre5/fs/ext4/symlink.c  2009-02-22 22:54:25.000000000 +0100
3641 @@ -40,6 +40,7 @@ const struct inode_operations ext4_symli
3642         .listxattr      = ext4_listxattr,
3643         .removexattr    = generic_removexattr,
3644  #endif
3645 +       .sync_flags     = ext4_sync_flags,
3646  };
3647  
3648  const struct inode_operations ext4_fast_symlink_inode_operations = {
3649 @@ -51,4 +52,5 @@ const struct inode_operations ext4_fast_
3650         .listxattr      = ext4_listxattr,
3651         .removexattr    = generic_removexattr,
3652  #endif
3653 +       .sync_flags     = ext4_sync_flags,
3654  };
3655 diff -NurpP --minimal linux-2.6.29.1/fs/ext4/xattr.c linux-2.6.29.1-vs2.3.0.36.9-pre5/fs/ext4/xattr.c
3656 --- linux-2.6.29.1/fs/ext4/xattr.c      2009-03-24 14:22:25.000000000 +0100
3657 +++ linux-2.6.29.1-vs2.3.0.36.9-pre5/fs/ext4/xattr.c    2009-03-24 15:47:44.000000000 +0100
3658 @@ -56,6 +56,7 @@
3659  #include <linux/mbcache.h>
3660  #include <linux/quotaops.h>
3661  #include <linux/rwsem.h>
3662 +#include <linux/vs_dlimit.h>
3663  #include "ext4_jbd2.h"
3664  #include "ext4.h"
3665  #include "xattr.h"
3666 @@ -490,6 +491,7 @@ ext4_xattr_release_block(handle_t *handl
3667                 error = ext4_handle_dirty_metadata(handle, inode, bh);
3668                 if (IS_SYNC(inode))
3669                         ext4_handle_sync(handle);
3670 +               DLIMIT_FREE_BLOCK(inode, 1);
3671                 DQUOT_FREE_BLOCK(inode, 1);
3672                 ea_bdebug(bh, "refcount now=%d; releasing",
3673                           le32_to_cpu(BHDR(bh)->h_refcount));
3674 @@ -781,11 +783,14 @@ inserted:
3675                         if (new_bh == bs->bh)
3676                                 ea_bdebug(new_bh, "keeping");
3677                         else {
3678 +                               error = -ENOSPC;
3679 +                               if (DLIMIT_ALLOC_BLOCK(inode, 1))
3680 +                                       goto cleanup;
3681                                 /* The old block is released after updating
3682                                    the inode. */
3683                                 error = -EDQUOT;
3684                                 if (DQUOT_ALLOC_BLOCK(inode, 1))
3685 -                                       goto cleanup;
3686 +                                       goto cleanup_dlimit;
3687                                 error = ext4_journal_get_write_access(handle,
3688                                                                       new_bh);
3689                                 if (error)
3690 @@ -861,6 +866,8 @@ cleanup:
3691  
3692  cleanup_dquot:
3693         DQUOT_FREE_BLOCK(inode, 1);
3694 +cleanup_dlimit:
3695 +       DLIMIT_FREE_BLOCK(inode, 1);
3696         goto cleanup;
3697  
3698  bad_block:
3699 diff -NurpP --minimal linux-2.6.29.1/fs/fcntl.c linux-2.6.29.1-vs2.3.0.36.9-pre5/fs/fcntl.c
3700 --- linux-2.6.29.1/fs/fcntl.c   2009-03-24 14:22:25.000000000 +0100
3701 +++ linux-2.6.29.1-vs2.3.0.36.9-pre5/fs/fcntl.c 2009-03-24 14:48:35.000000000 +0100
3702 @@ -20,6 +20,7 @@
3703  #include <linux/rcupdate.h>
3704  #include <linux/pid_namespace.h>
3705  #include <linux/smp_lock.h>
3706 +#include <linux/vs_limit.h>
3707  
3708  #include <asm/poll.h>
3709  #include <asm/siginfo.h>
3710 @@ -103,6 +104,8 @@ SYSCALL_DEFINE3(dup3, unsigned int, oldf
3711  
3712         if (tofree)
3713                 filp_close(tofree, files);
3714 +       else
3715 +               vx_openfd_inc(newfd);   /* fd was unused */
3716  
3717         return newfd;
3718  
3719 @@ -343,6 +346,8 @@ SYSCALL_DEFINE3(fcntl, unsigned int, fd,
3720         filp = fget(fd);
3721         if (!filp)
3722                 goto out;
3723 +       if (!vx_files_avail(1))
3724 +               goto out;
3725  
3726         err = security_file_fcntl(filp, cmd, arg);
3727         if (err) {
3728 diff -NurpP --minimal linux-2.6.29.1/fs/file.c linux-2.6.29.1-vs2.3.0.36.9-pre5/fs/file.c
3729 --- linux-2.6.29.1/fs/file.c    2008-12-25 00:26:37.000000000 +0100
3730 +++ linux-2.6.29.1-vs2.3.0.36.9-pre5/fs/file.c  2009-02-22 22:54:25.000000000 +0100
3731 @@ -19,6 +19,7 @@
3732  #include <linux/spinlock.h>
3733  #include <linux/rcupdate.h>
3734  #include <linux/workqueue.h>
3735 +#include <linux/vs_limit.h>
3736  
3737  struct fdtable_defer {
3738         spinlock_t lock;
3739 @@ -367,6 +368,8 @@ struct files_struct *dup_fd(struct files
3740                 struct file *f = *old_fds++;
3741                 if (f) {
3742                         get_file(f);
3743 +                       /* TODO: sum it first for check and performance */
3744 +                       vx_openfd_inc(open_files - i);
3745                 } else {
3746                         /*
3747                          * The fd may be claimed in the fd bitmap but not yet
3748 @@ -475,6 +478,7 @@ repeat:
3749         else
3750                 FD_CLR(fd, fdt->close_on_exec);
3751         error = fd;
3752 +       vx_openfd_inc(fd);
3753  #if 1
3754         /* Sanity check */
3755         if (rcu_dereference(fdt->fd[fd]) != NULL) {
3756 diff -NurpP --minimal linux-2.6.29.1/fs/file_table.c linux-2.6.29.1-vs2.3.0.36.9-pre5/fs/file_table.c
3757 --- linux-2.6.29.1/fs/file_table.c      2009-03-24 14:22:25.000000000 +0100
3758 +++ linux-2.6.29.1-vs2.3.0.36.9-pre5/fs/file_table.c    2009-03-24 14:48:35.000000000 +0100
3759 @@ -21,6 +21,8 @@
3760  #include <linux/fsnotify.h>
3761  #include <linux/sysctl.h>
3762  #include <linux/percpu_counter.h>
3763 +#include <linux/vs_limit.h>
3764 +#include <linux/vs_context.h>
3765  
3766  #include <asm/atomic.h>
3767  
3768 @@ -129,6 +131,8 @@ struct file *get_empty_filp(void)
3769         f->f_cred = get_cred(cred);
3770         eventpoll_init_file(f);
3771         /* f->f_version: 0 */
3772 +       f->f_xid = vx_current_xid();
3773 +       vx_files_inc(f);
3774         return f;
3775  
3776  over:
3777 @@ -283,6 +287,8 @@ void __fput(struct file *file)
3778                 cdev_put(inode->i_cdev);
3779         fops_put(file->f_op);
3780         put_pid(file->f_owner.pid);
3781 +       vx_files_dec(file);
3782 +       file->f_xid = 0;
3783         file_kill(file);
3784         if (file->f_mode & FMODE_WRITE)
3785                 drop_file_write_access(file);
3786 @@ -350,6 +356,8 @@ void put_filp(struct file *file)
3787  {
3788         if (atomic_long_dec_and_test(&file->f_count)) {
3789                 security_file_free(file);
3790 +               vx_files_dec(file);
3791 +               file->f_xid = 0;
3792                 file_kill(file);
3793                 file_free(file);
3794         }
3795 diff -NurpP --minimal linux-2.6.29.1/fs/hfsplus/ioctl.c linux-2.6.29.1-vs2.3.0.36.9-pre5/fs/hfsplus/ioctl.c
3796 --- linux-2.6.29.1/fs/hfsplus/ioctl.c   2008-12-25 00:26:37.000000000 +0100
3797 +++ linux-2.6.29.1-vs2.3.0.36.9-pre5/fs/hfsplus/ioctl.c 2009-02-22 22:54:25.000000000 +0100
3798 @@ -17,6 +17,7 @@
3799  #include <linux/mount.h>
3800  #include <linux/sched.h>
3801  #include <linux/xattr.h>
3802 +#include <linux/mount.h>
3803  #include <asm/uaccess.h>
3804  #include "hfsplus_fs.h"
3805  
3806 diff -NurpP --minimal linux-2.6.29.1/fs/inode.c linux-2.6.29.1-vs2.3.0.36.9-pre5/fs/inode.c
3807 --- linux-2.6.29.1/fs/inode.c   2009-03-24 14:22:26.000000000 +0100
3808 +++ linux-2.6.29.1-vs2.3.0.36.9-pre5/fs/inode.c 2009-03-25 00:51:55.000000000 +0100
3809 @@ -126,6 +126,9 @@ struct inode *inode_init_always(struct s
3810         struct address_space * const mapping = &inode->i_data;
3811  
3812         inode->i_sb = sb;
3813 +
3814 +       /* essential because of inode slab reuse */
3815 +       inode->i_tag = 0;
3816         inode->i_blkbits = sb->s_blocksize_bits;
3817         inode->i_flags = 0;
3818         atomic_set(&inode->i_count, 1);
3819 @@ -146,6 +149,7 @@ struct inode *inode_init_always(struct s
3820         inode->i_bdev = NULL;
3821         inode->i_cdev = NULL;
3822         inode->i_rdev = 0;
3823 +       inode->i_mdev = 0;
3824         inode->dirtied_when = 0;
3825         if (security_inode_alloc(inode)) {
3826                 if (inode->i_sb->s_op->destroy_inode)
3827 @@ -267,6 +271,8 @@ void __iget(struct inode * inode)
3828         inodes_stat.nr_unused--;
3829  }
3830  
3831 +EXPORT_SYMBOL_GPL(__iget);
3832 +
3833  /**
3834   * clear_inode - clear an inode
3835   * @inode: inode to clear
3836 @@ -1539,9 +1545,11 @@ void init_special_inode(struct inode *in
3837         if (S_ISCHR(mode)) {
3838                 inode->i_fop = &def_chr_fops;
3839                 inode->i_rdev = rdev;
3840 +               inode->i_mdev = rdev;
3841         } else if (S_ISBLK(mode)) {
3842                 inode->i_fop = &def_blk_fops;
3843                 inode->i_rdev = rdev;
3844 +               inode->i_mdev = rdev;
3845         } else if (S_ISFIFO(mode))
3846                 inode->i_fop = &def_fifo_fops;
3847         else if (S_ISSOCK(mode))
3848 diff -NurpP --minimal linux-2.6.29.1/fs/ioctl.c linux-2.6.29.1-vs2.3.0.36.9-pre5/fs/ioctl.c
3849 --- linux-2.6.29.1/fs/ioctl.c   2009-03-24 14:22:26.000000000 +0100
3850 +++ linux-2.6.29.1-vs2.3.0.36.9-pre5/fs/ioctl.c 2009-03-24 14:48:35.000000000 +0100
3851 @@ -15,6 +15,9 @@
3852  #include <linux/uaccess.h>
3853  #include <linux/writeback.h>
3854  #include <linux/buffer_head.h>
3855 +#include <linux/proc_fs.h>
3856 +#include <linux/vserver/inode.h>
3857 +#include <linux/vs_tag.h>
3858  
3859  #include <asm/ioctls.h>
3860  
3861 diff -NurpP --minimal linux-2.6.29.1/fs/ioprio.c linux-2.6.29.1-vs2.3.0.36.9-pre5/fs/ioprio.c
3862 --- linux-2.6.29.1/fs/ioprio.c  2009-03-24 14:22:26.000000000 +0100
3863 +++ linux-2.6.29.1-vs2.3.0.36.9-pre5/fs/ioprio.c        2009-03-24 14:48:35.000000000 +0100
3864 @@ -26,6 +26,7 @@
3865  #include <linux/syscalls.h>
3866  #include <linux/security.h>
3867  #include <linux/pid_namespace.h>
3868 +#include <linux/vs_base.h>
3869  
3870  int set_task_ioprio(struct task_struct *task, int ioprio)
3871  {
3872 @@ -123,6 +124,8 @@ SYSCALL_DEFINE3(ioprio_set, int, which, 
3873                         else
3874                                 pgrp = find_vpid(who);
3875                         do_each_pid_thread(pgrp, PIDTYPE_PGID, p) {
3876 +                               if (!vx_check(p->xid, VS_ADMIN_P | VS_IDENT))
3877 +                                       continue;
3878                                 ret = set_task_ioprio(p, ioprio);
3879                                 if (ret)
3880                                         break;
3881 @@ -212,6 +215,8 @@ SYSCALL_DEFINE2(ioprio_get, int, which, 
3882                         else
3883                                 pgrp = find_vpid(who);
3884                         do_each_pid_thread(pgrp, PIDTYPE_PGID, p) {
3885 +                               if (!vx_check(p->xid, VS_ADMIN_P | VS_IDENT))
3886 +                                       continue;
3887                                 tmpio = get_task_ioprio(p);
3888                                 if (tmpio < 0)
3889                                         continue;
3890 diff -NurpP --minimal linux-2.6.29.1/fs/jfs/acl.c linux-2.6.29.1-vs2.3.0.36.9-pre5/fs/jfs/acl.c
3891 --- linux-2.6.29.1/fs/jfs/acl.c 2008-12-25 00:26:37.000000000 +0100
3892 +++ linux-2.6.29.1-vs2.3.0.36.9-pre5/fs/jfs/acl.c       2009-02-22 22:54:25.000000000 +0100
3893 @@ -232,7 +232,8 @@ int jfs_setattr(struct dentry *dentry, s
3894                 return rc;
3895  
3896         if ((iattr->ia_valid & ATTR_UID && iattr->ia_uid != inode->i_uid) ||
3897 -           (iattr->ia_valid & ATTR_GID && iattr->ia_gid != inode->i_gid)) {
3898 +           (iattr->ia_valid & ATTR_GID && iattr->ia_gid != inode->i_gid) ||
3899 +           (iattr->ia_valid & ATTR_TAG && iattr->ia_tag != inode->i_tag)) {
3900                 if (DQUOT_TRANSFER(inode, iattr))
3901                         return -EDQUOT;
3902         }
3903 diff -NurpP --minimal linux-2.6.29.1/fs/jfs/file.c linux-2.6.29.1-vs2.3.0.36.9-pre5/fs/jfs/file.c
3904 --- linux-2.6.29.1/fs/jfs/file.c        2008-12-25 00:26:37.000000000 +0100
3905 +++ linux-2.6.29.1-vs2.3.0.36.9-pre5/fs/jfs/file.c      2009-02-22 22:54:25.000000000 +0100
3906 @@ -98,6 +98,7 @@ const struct inode_operations jfs_file_i
3907         .setattr        = jfs_setattr,
3908         .permission     = jfs_permission,
3909  #endif
3910 +       .sync_flags     = jfs_sync_flags,
3911  };
3912  
3913  const struct file_operations jfs_file_operations = {
3914 diff -NurpP --minimal linux-2.6.29.1/fs/jfs/inode.c linux-2.6.29.1-vs2.3.0.36.9-pre5/fs/jfs/inode.c
3915 --- linux-2.6.29.1/fs/jfs/inode.c       2009-03-24 14:22:26.000000000 +0100
3916 +++ linux-2.6.29.1-vs2.3.0.36.9-pre5/fs/jfs/inode.c     2009-03-24 14:48:35.000000000 +0100
3917 @@ -22,6 +22,7 @@
3918  #include <linux/buffer_head.h>
3919  #include <linux/pagemap.h>
3920  #include <linux/quotaops.h>
3921 +#include <linux/vs_dlimit.h>
3922  #include "jfs_incore.h"
3923  #include "jfs_inode.h"
3924  #include "jfs_filsys.h"
3925 @@ -161,6 +162,7 @@ void jfs_delete_inode(struct inode *inod
3926                 DQUOT_INIT(inode);
3927                 DQUOT_FREE_INODE(inode);
3928                 DQUOT_DROP(inode);
3929 +               DLIMIT_FREE_INODE(inode);
3930         }
3931  
3932         clear_inode(inode);
3933 diff -NurpP --minimal linux-2.6.29.1/fs/jfs/ioctl.c linux-2.6.29.1-vs2.3.0.36.9-pre5/fs/jfs/ioctl.c
3934 --- linux-2.6.29.1/fs/jfs/ioctl.c       2008-12-25 00:26:37.000000000 +0100
3935 +++ linux-2.6.29.1-vs2.3.0.36.9-pre5/fs/jfs/ioctl.c     2009-02-22 22:54:25.000000000 +0100
3936 @@ -11,6 +11,7 @@
3937  #include <linux/mount.h>
3938  #include <linux/time.h>
3939  #include <linux/sched.h>
3940 +#include <linux/mount.h>
3941  #include <asm/current.h>
3942  #include <asm/uaccess.h>
3943  
3944 @@ -85,6 +86,11 @@ long jfs_ioctl(struct file *filp, unsign
3945                 if (!S_ISDIR(inode->i_mode))
3946                         flags &= ~JFS_DIRSYNC_FL;
3947  
3948 +               if (IS_BARRIER(inode)) {
3949 +                       vxwprintk_task(1, "messing with the barrier.");
3950 +                       return -EACCES;
3951 +               }
3952 +
3953                 /* Is it quota file? Do not allow user to mess with it */
3954                 if (IS_NOQUOTA(inode)) {
3955                         err = -EPERM;
3956 @@ -102,8 +108,8 @@ long jfs_ioctl(struct file *filp, unsign
3957                  * the relevant capability.
3958                  */
3959                 if ((oldflags & JFS_IMMUTABLE_FL) ||
3960 -                       ((flags ^ oldflags) &
3961 -                       (JFS_APPEND_FL | JFS_IMMUTABLE_FL))) {
3962 +                       ((flags ^ oldflags) & (JFS_APPEND_FL |
3963 +                       JFS_IMMUTABLE_FL | JFS_IXUNLINK_FL))) {
3964                         if (!capable(CAP_LINUX_IMMUTABLE)) {
3965                                 mutex_unlock(&inode->i_mutex);
3966                                 err = -EPERM;
3967 diff -NurpP --minimal linux-2.6.29.1/fs/jfs/jfs_dinode.h linux-2.6.29.1-vs2.3.0.36.9-pre5/fs/jfs/jfs_dinode.h
3968 --- linux-2.6.29.1/fs/jfs/jfs_dinode.h  2008-12-25 00:26:37.000000000 +0100
3969 +++ linux-2.6.29.1-vs2.3.0.36.9-pre5/fs/jfs/jfs_dinode.h        2009-02-22 22:54:25.000000000 +0100
3970 @@ -161,9 +161,13 @@ struct dinode {
3971  
3972  #define JFS_APPEND_FL          0x01000000 /* writes to file may only append */
3973  #define JFS_IMMUTABLE_FL       0x02000000 /* Immutable file */
3974 +#define JFS_IXUNLINK_FL                0x08000000 /* Immutable invert on unlink */
3975  
3976 -#define JFS_FL_USER_VISIBLE    0x03F80000
3977 -#define JFS_FL_USER_MODIFIABLE 0x03F80000
3978 +#define JFS_BARRIER_FL         0x04000000 /* Barrier for chroot() */
3979 +#define JFS_COW_FL             0x20000000 /* Copy on Write marker */
3980 +
3981 +#define JFS_FL_USER_VISIBLE    0x07F80000
3982 +#define JFS_FL_USER_MODIFIABLE 0x07F80000
3983  #define JFS_FL_INHERIT         0x03C80000
3984  
3985  /* These are identical to EXT[23]_IOC_GETFLAGS/SETFLAGS */
3986 diff -NurpP --minimal linux-2.6.29.1/fs/jfs/jfs_dtree.c linux-2.6.29.1-vs2.3.0.36.9-pre5/fs/jfs/jfs_dtree.c
3987 --- linux-2.6.29.1/fs/jfs/jfs_dtree.c   2008-12-25 00:26:37.000000000 +0100
3988 +++ linux-2.6.29.1-vs2.3.0.36.9-pre5/fs/jfs/jfs_dtree.c 2009-02-22 22:54:25.000000000 +0100
3989 @@ -102,6 +102,7 @@
3990  
3991  #include <linux/fs.h>
3992  #include <linux/quotaops.h>
3993 +#include <linux/vs_dlimit.h>
3994  #include "jfs_incore.h"
3995  #include "jfs_superblock.h"
3996  #include "jfs_filsys.h"
3997 @@ -383,10 +384,10 @@ static u32 add_index(tid_t tid, struct i
3998                  */
3999                 if (DQUOT_ALLOC_BLOCK(ip, sbi->nbperpage))
4000                         goto clean_up;
4001 -               if (dbAlloc(ip, 0, sbi->nbperpage, &xaddr)) {
4002 -                       DQUOT_FREE_BLOCK(ip, sbi->nbperpage);
4003 -                       goto clean_up;
4004 -               }
4005 +               if (DLIMIT_ALLOC_BLOCK(ip, sbi->nbperpage))
4006 +                       goto clean_up_dquot;
4007 +               if (dbAlloc(ip, 0, sbi->nbperpage, &xaddr))
4008 +                       goto clean_up_dlimit;
4009  
4010                 /*
4011                  * Save the table, we're going to overwrite it with the
4012 @@ -480,6 +481,12 @@ static u32 add_index(tid_t tid, struct i
4013  
4014         return index;
4015  
4016 +      clean_up_dlimit:
4017 +       DLIMIT_FREE_BLOCK(ip, sbi->nbperpage);
4018 +
4019 +      clean_up_dquot:
4020 +       DQUOT_FREE_BLOCK(ip, sbi->nbperpage);
4021 +
4022        clean_up:
4023  
4024         jfs_ip->next_index--;
4025 @@ -951,6 +958,7 @@ static int dtSplitUp(tid_t tid,
4026         struct tlock *tlck;
4027         struct lv *lv;
4028         int quota_allocation = 0;
4029 +       int dlimit_allocation = 0;
4030  
4031         /* get split page */
4032         smp = split->mp;
4033 @@ -1033,6 +1041,12 @@ static int dtSplitUp(tid_t tid,
4034                 }
4035                 quota_allocation += n;
4036  
4037 +               if (DLIMIT_ALLOC_BLOCK(ip, n)) {
4038 +                       rc = -ENOSPC;
4039 +                       goto extendOut;
4040 +               }
4041 +               dlimit_allocation += n;
4042 +
4043                 if ((rc = dbReAlloc(sbi->ipbmap, xaddr, (s64) xlen,
4044                                     (s64) n, &nxaddr)))
4045                         goto extendOut;
4046 @@ -1306,6 +1320,9 @@ static int dtSplitUp(tid_t tid,
4047        freeKeyName:
4048         kfree(key.name);
4049  
4050 +       /* Rollback dlimit allocation */
4051 +       if (rc && dlimit_allocation)
4052 +               DLIMIT_FREE_BLOCK(ip, dlimit_allocation);
4053         /* Rollback quota allocation */
4054         if (rc && quota_allocation)
4055                 DQUOT_FREE_BLOCK(ip, quota_allocation);
4056 @@ -1373,6 +1390,12 @@ static int dtSplitPage(tid_t tid, struct
4057                 release_metapage(rmp);
4058                 return -EDQUOT;
4059         }
4060 +       /* Allocate blocks to dlimit. */
4061 +       if (DLIMIT_ALLOC_BLOCK(ip, lengthPXD(pxd))) {
4062 +               DQUOT_FREE_BLOCK(ip, lengthPXD(pxd));
4063 +               release_metapage(rmp);
4064 +               return -ENOSPC;
4065 +       }
4066  
4067         jfs_info("dtSplitPage: ip:0x%p smp:0x%p rmp:0x%p", ip, smp, rmp);
4068  
4069 @@ -1920,6 +1943,12 @@ static int dtSplitRoot(tid_t tid,
4070                 release_metapage(rmp);
4071                 return -EDQUOT;
4072         }
4073 +       /* Allocate blocks to dlimit. */
4074 +       if (DLIMIT_ALLOC_BLOCK(ip, lengthPXD(pxd))) {
4075 +               DQUOT_FREE_BLOCK(ip, lengthPXD(pxd));
4076 +               release_metapage(rmp);
4077 +               return -ENOSPC;
4078 +       }
4079  
4080         BT_MARK_DIRTY(rmp, ip);
4081         /*
4082 @@ -2286,6 +2315,8 @@ static int dtDeleteUp(tid_t tid, struct 
4083  
4084         xlen = lengthPXD(&fp->header.self);
4085  
4086 +       /* Free dlimit allocation. */
4087 +       DLIMIT_FREE_BLOCK(ip, xlen);
4088         /* Free quota allocation. */
4089         DQUOT_FREE_BLOCK(ip, xlen);
4090  
4091 @@ -2362,6 +2393,8 @@ static int dtDeleteUp(tid_t tid, struct 
4092  
4093                                 xlen = lengthPXD(&p->header.self);
4094  
4095 +                               /* Free dlimit allocation */
4096 +                               DLIMIT_FREE_BLOCK(ip, xlen);
4097                                 /* Free quota allocation */
4098                                 DQUOT_FREE_BLOCK(ip, xlen);
4099  
4100 diff -NurpP --minimal linux-2.6.29.1/fs/jfs/jfs_extent.c linux-2.6.29.1-vs2.3.0.36.9-pre5/fs/jfs/jfs_extent.c
4101 --- linux-2.6.29.1/fs/jfs/jfs_extent.c  2008-12-25 00:26:37.000000000 +0100
4102 +++ linux-2.6.29.1-vs2.3.0.36.9-pre5/fs/jfs/jfs_extent.c        2009-02-22 22:54:25.000000000 +0100
4103 @@ -18,6 +18,7 @@
4104  
4105  #include <linux/fs.h>
4106  #include <linux/quotaops.h>
4107 +#include <linux/vs_dlimit.h>
4108  #include "jfs_incore.h"
4109  #include "jfs_inode.h"
4110  #include "jfs_superblock.h"
4111 @@ -147,6 +148,14 @@ extAlloc(struct inode *ip, s64 xlen, s64
4112                 return -EDQUOT;
4113         }
4114  
4115 +       /* Allocate blocks to dlimit. */
4116 +       if (DLIMIT_ALLOC_BLOCK(ip, nxlen)) {
4117 +               DQUOT_FREE_BLOCK(ip, nxlen);
4118 +               dbFree(ip, nxaddr, (s64) nxlen);
4119 +               mutex_unlock(&JFS_IP(ip)->commit_mutex);
4120 +               return -ENOSPC;
4121 +       }
4122 +
4123         /* determine the value of the extent flag */
4124         xflag = abnr ? XAD_NOTRECORDED : 0;
4125  
4126 @@ -164,6 +173,7 @@ extAlloc(struct inode *ip, s64 xlen, s64
4127          */
4128         if (rc) {
4129                 dbFree(ip, nxaddr, nxlen);
4130 +               DLIMIT_FREE_BLOCK(ip, nxlen);
4131                 DQUOT_FREE_BLOCK(ip, nxlen);
4132                 mutex_unlock(&JFS_IP(ip)->commit_mutex);
4133                 return (rc);
4134 @@ -261,6 +271,13 @@ int extRealloc(struct inode *ip, s64 nxl
4135                 mutex_unlock(&JFS_IP(ip)->commit_mutex);
4136                 return -EDQUOT;
4137         }
4138 +       /* Allocate blocks to dlimit. */
4139 +       if (DLIMIT_ALLOC_BLOCK(ip, nxlen)) {
4140 +               DQUOT_FREE_BLOCK(ip, nxlen);
4141 +               dbFree(ip, nxaddr, (s64) nxlen);
4142 +               up(&JFS_IP(ip)->commit_sem);
4143 +               return -ENOSPC;
4144 +       }
4145  
4146         delta = nxlen - xlen;
4147  
4148 @@ -297,6 +314,7 @@ int extRealloc(struct inode *ip, s64 nxl
4149                 /* extend the extent */
4150                 if ((rc = xtExtend(0, ip, xoff + xlen, (int) nextend, 0))) {
4151                         dbFree(ip, xaddr + xlen, delta);
4152 +                       DLIMIT_FREE_BLOCK(ip, nxlen);
4153                         DQUOT_FREE_BLOCK(ip, nxlen);
4154                         goto exit;
4155                 }
4156 @@ -308,6 +326,7 @@ int extRealloc(struct inode *ip, s64 nxl
4157                  */
4158                 if ((rc = xtTailgate(0, ip, xoff, (int) ntail, nxaddr, 0))) {
4159                         dbFree(ip, nxaddr, nxlen);
4160 +                       DLIMIT_FREE_BLOCK(ip, nxlen);
4161                         DQUOT_FREE_BLOCK(ip, nxlen);
4162                         goto exit;
4163                 }
4164 diff -NurpP --minimal linux-2.6.29.1/fs/jfs/jfs_filsys.h linux-2.6.29.1-vs2.3.0.36.9-pre5/fs/jfs/jfs_filsys.h
4165 --- linux-2.6.29.1/fs/jfs/jfs_filsys.h  2008-12-25 00:26:37.000000000 +0100
4166 +++ linux-2.6.29.1-vs2.3.0.36.9-pre5/fs/jfs/jfs_filsys.h        2009-02-22 22:54:25.000000000 +0100
4167 @@ -263,6 +263,7 @@
4168  #define JFS_NAME_MAX   255
4169  #define JFS_PATH_MAX   BPSIZE
4170  
4171 +#define JFS_TAGGED             0x00800000      /* Context Tagging */
4172  
4173  /*
4174   *     file system state (superblock state)
4175 diff -NurpP --minimal linux-2.6.29.1/fs/jfs/jfs_imap.c linux-2.6.29.1-vs2.3.0.36.9-pre5/fs/jfs/jfs_imap.c
4176 --- linux-2.6.29.1/fs/jfs/jfs_imap.c    2009-03-24 14:22:26.000000000 +0100
4177 +++ linux-2.6.29.1-vs2.3.0.36.9-pre5/fs/jfs/jfs_imap.c  2009-03-24 14:48:35.000000000 +0100
4178 @@ -45,6 +45,7 @@
4179  #include <linux/buffer_head.h>
4180  #include <linux/pagemap.h>
4181  #include <linux/quotaops.h>
4182 +#include <linux/vs_tag.h>
4183  
4184  #include "jfs_incore.h"
4185  #include "jfs_inode.h"
4186 @@ -3062,6 +3063,8 @@ static int copy_from_dinode(struct dinod
4187  {
4188         struct jfs_inode_info *jfs_ip = JFS_IP(ip);
4189         struct jfs_sb_info *sbi = JFS_SBI(ip->i_sb);
4190 +       uid_t uid;
4191 +       gid_t gid;
4192  
4193         jfs_ip->fileset = le32_to_cpu(dip->di_fileset);
4194         jfs_ip->mode2 = le32_to_cpu(dip->di_mode);
4195 @@ -3082,14 +3085,18 @@ static int copy_from_dinode(struct dinod
4196         }
4197         ip->i_nlink = le32_to_cpu(dip->di_nlink);
4198  
4199 -       jfs_ip->saved_uid = le32_to_cpu(dip->di_uid);
4200 +       uid = le32_to_cpu(dip->di_uid);
4201 +       gid = le32_to_cpu(dip->di_gid);
4202 +       ip->i_tag = INOTAG_TAG(DX_TAG(ip), uid, gid, 0);
4203 +
4204 +       jfs_ip->saved_uid = INOTAG_UID(DX_TAG(ip), uid, gid);
4205         if (sbi->uid == -1)
4206                 ip->i_uid = jfs_ip->saved_uid;
4207         else {
4208                 ip->i_uid = sbi->uid;
4209         }
4210  
4211 -       jfs_ip->saved_gid = le32_to_cpu(dip->di_gid);
4212 +       jfs_ip->saved_gid = INOTAG_GID(DX_TAG(ip), uid, gid);
4213         if (sbi->gid == -1)
4214                 ip->i_gid = jfs_ip->saved_gid;
4215         else {
4216 @@ -3154,14 +3161,12 @@ static void copy_to_dinode(struct dinode
4217         dip->di_size = cpu_to_le64(ip->i_size);
4218         dip->di_nblocks = cpu_to_le64(PBLK2LBLK(ip->i_sb, ip->i_blocks));
4219         dip->di_nlink = cpu_to_le32(ip->i_nlink);
4220 -       if (sbi->uid == -1)
4221 -               dip->di_uid = cpu_to_le32(ip->i_uid);
4222 -       else
4223 -               dip->di_uid = cpu_to_le32(jfs_ip->saved_uid);
4224 -       if (sbi->gid == -1)
4225 -               dip->di_gid = cpu_to_le32(ip->i_gid);
4226 -       else
4227 -               dip->di_gid = cpu_to_le32(jfs_ip->saved_gid);
4228 +
4229 +       dip->di_uid = cpu_to_le32(TAGINO_UID(DX_TAG(ip),
4230 +               (sbi->uid == -1) ? ip->i_uid : jfs_ip->saved_uid, ip->i_tag));
4231 +       dip->di_gid = cpu_to_le32(TAGINO_GID(DX_TAG(ip),
4232 +               (sbi->gid == -1) ? ip->i_gid : jfs_ip->saved_gid, ip->i_tag));
4233 +
4234         jfs_get_inode_flags(jfs_ip);
4235         /*
4236          * mode2 is only needed for storing the higher order bits.
4237 diff -NurpP --minimal linux-2.6.29.1/fs/jfs/jfs_inode.c linux-2.6.29.1-vs2.3.0.36.9-pre5/fs/jfs/jfs_inode.c
4238 --- linux-2.6.29.1/fs/jfs/jfs_inode.c   2009-03-24 14:22:26.000000000 +0100
4239 +++ linux-2.6.29.1-vs2.3.0.36.9-pre5/fs/jfs/jfs_inode.c 2009-03-24 15:58:01.000000000 +0100
4240 @@ -18,6 +18,8 @@
4241  
4242  #include <linux/fs.h>
4243  #include <linux/quotaops.h>
4244 +#include <linux/vs_dlimit.h>
4245 +#include <linux/vs_tag.h>
4246  #include "jfs_incore.h"
4247  #include "jfs_inode.h"
4248  #include "jfs_filsys.h"
4249 @@ -30,29 +32,46 @@ void jfs_set_inode_flags(struct inode *i
4250  {
4251         unsigned int flags = JFS_IP(inode)->mode2;
4252  
4253 -       inode->i_flags &= ~(S_IMMUTABLE | S_APPEND |
4254 -               S_NOATIME | S_DIRSYNC | S_SYNC);
4255 +       inode->i_flags &= ~(S_IMMUTABLE | S_IXUNLINK |
4256 +               S_SYNC | S_APPEND | S_NOATIME | S_DIRSYNC);
4257  
4258         if (flags & JFS_IMMUTABLE_FL)
4259                 inode->i_flags |= S_IMMUTABLE;
4260 +       if (flags & JFS_IXUNLINK_FL)
4261 +               inode->i_flags |= S_IXUNLINK;
4262 +
4263 +       if (flags & JFS_SYNC_FL)
4264 +               inode->i_flags |= S_SYNC;
4265         if (flags & JFS_APPEND_FL)
4266                 inode->i_flags |= S_APPEND;
4267         if (flags & JFS_NOATIME_FL)
4268                 inode->i_flags |= S_NOATIME;
4269         if (flags & JFS_DIRSYNC_FL)
4270                 inode->i_flags |= S_DIRSYNC;
4271 -       if (flags & JFS_SYNC_FL)
4272 -               inode->i_flags |= S_SYNC;
4273 +
4274 +       inode->i_vflags &= ~(V_BARRIER | V_COW);
4275 +
4276 +       if (flags & JFS_BARRIER_FL)
4277 +               inode->i_vflags |= V_BARRIER;
4278 +       if (flags & JFS_COW_FL)
4279 +               inode->i_vflags |= V_COW;
4280  }
4281  
4282  void jfs_get_inode_flags(struct jfs_inode_info *jfs_ip)
4283  {
4284         unsigned int flags = jfs_ip->vfs_inode.i_flags;
4285 +       unsigned int vflags = jfs_ip->vfs_inode.i_vflags;
4286 +
4287 +       jfs_ip->mode2 &= ~(JFS_IMMUTABLE_FL | JFS_IXUNLINK_FL |
4288 +                          JFS_APPEND_FL | JFS_NOATIME_FL |
4289 +                          JFS_DIRSYNC_FL | JFS_SYNC_FL |
4290 +                          JFS_BARRIER_FL | JFS_COW_FL);
4291  
4292 -       jfs_ip->mode2 &= ~(JFS_IMMUTABLE_FL | JFS_APPEND_FL | JFS_NOATIME_FL |
4293 -                          JFS_DIRSYNC_FL | JFS_SYNC_FL);
4294         if (flags & S_IMMUTABLE)
4295                 jfs_ip->mode2 |= JFS_IMMUTABLE_FL;
4296 +       if (flags & S_IXUNLINK)
4297 +               jfs_ip->mode2 |= JFS_IXUNLINK_FL;
4298 +
4299         if (flags & S_APPEND)
4300                 jfs_ip->mode2 |= JFS_APPEND_FL;
4301         if (flags & S_NOATIME)
4302 @@ -61,6 +80,19 @@ void jfs_get_inode_flags(struct jfs_inod
4303                 jfs_ip->mode2 |= JFS_DIRSYNC_FL;
4304         if (flags & S_SYNC)
4305                 jfs_ip->mode2 |= JFS_SYNC_FL;
4306 +
4307 +       if (vflags & V_BARRIER)
4308 +               jfs_ip->mode2 |= JFS_BARRIER_FL;
4309 +       if (vflags & V_COW)
4310 +               jfs_ip->mode2 |= JFS_COW_FL;
4311 +}
4312 +
4313 +int jfs_sync_flags(struct inode *inode)
4314 +{
4315 +       jfs_get_inode_flags(JFS_IP(inode));
4316 +       inode->i_ctime = CURRENT_TIME;
4317 +       mark_inode_dirty(inode);
4318 +       return 0;
4319  }
4320  
4321  /*
4322 @@ -113,6 +145,12 @@ struct inode *ialloc(struct inode *paren
4323         jfs_inode->saved_uid = inode->i_uid;
4324         jfs_inode->saved_gid = inode->i_gid;
4325  
4326 +       inode->i_tag = dx_current_fstag(sb);
4327 +       if (DLIMIT_ALLOC_INODE(inode)) {
4328 +               rc = -ENOSPC;
4329 +               goto fail_drop2;
4330 +       }
4331 +
4332         /*
4333          * Allocate inode to quota.
4334          */
4335 @@ -162,6 +200,8 @@ struct inode *ialloc(struct inode *paren
4336         return inode;
4337  
4338  fail_drop:
4339 +       DLIMIT_FREE_INODE(inode);
4340 +fail_drop2:
4341         DQUOT_DROP(inode);
4342         inode->i_flags |= S_NOQUOTA;
4343  fail_unlock:
4344 diff -NurpP --minimal linux-2.6.29.1/fs/jfs/jfs_inode.h linux-2.6.29.1-vs2.3.0.36.9-pre5/fs/jfs/jfs_inode.h
4345 --- linux-2.6.29.1/fs/jfs/jfs_inode.h   2008-12-25 00:26:37.000000000 +0100
4346 +++ linux-2.6.29.1-vs2.3.0.36.9-pre5/fs/jfs/jfs_inode.h 2009-02-22 22:54:25.000000000 +0100
4347 @@ -39,6 +39,7 @@ extern struct dentry *jfs_fh_to_dentry(s
4348  extern struct dentry *jfs_fh_to_parent(struct super_block *sb, struct fid *fid,
4349         int fh_len, int fh_type);
4350  extern void jfs_set_inode_flags(struct inode *);
4351 +extern int jfs_sync_flags(struct inode *);
4352  extern int jfs_get_block(struct inode *, sector_t, struct buffer_head *, int);
4353  
4354  extern const struct address_space_operations jfs_aops;
4355 diff -NurpP --minimal linux-2.6.29.1/fs/jfs/jfs_xtree.c linux-2.6.29.1-vs2.3.0.36.9-pre5/fs/jfs/jfs_xtree.c
4356 --- linux-2.6.29.1/fs/jfs/jfs_xtree.c   2008-12-25 00:26:37.000000000 +0100
4357 +++ linux-2.6.29.1-vs2.3.0.36.9-pre5/fs/jfs/jfs_xtree.c 2009-02-22 22:54:25.000000000 +0100
4358 @@ -23,6 +23,7 @@
4359  #include <linux/module.h>
4360  #include <linux/quotaops.h>
4361  #include <linux/seq_file.h>
4362 +#include <linux/vs_dlimit.h>
4363  #include "jfs_incore.h"
4364  #include "jfs_filsys.h"
4365  #include "jfs_metapage.h"
4366 @@ -848,7 +849,12 @@ int xtInsert(tid_t tid,            /* transaction 
4367                         hint = 0;
4368                 if ((rc = DQUOT_ALLOC_BLOCK(ip, xlen)))
4369                         goto out;
4370 +               if ((rc = DLIMIT_ALLOC_BLOCK(ip, xlen))) {
4371 +                       DQUOT_FREE_BLOCK(ip, xlen);
4372 +                       goto out;
4373 +               }
4374                 if ((rc = dbAlloc(ip, hint, (s64) xlen, &xaddr))) {
4375 +                       DLIMIT_FREE_BLOCK(ip, xlen);
4376                         DQUOT_FREE_BLOCK(ip, xlen);
4377                         goto out;
4378                 }
4379 @@ -878,6 +884,7 @@ int xtInsert(tid_t tid,             /* transaction 
4380                         /* undo data extent allocation */
4381                         if (*xaddrp == 0) {
4382                                 dbFree(ip, xaddr, (s64) xlen);
4383 +                               DLIMIT_FREE_BLOCK(ip, xlen);
4384                                 DQUOT_FREE_BLOCK(ip, xlen);
4385                         }
4386                         return rc;
4387 @@ -1234,6 +1241,7 @@ xtSplitPage(tid_t tid, struct inode *ip,
4388         struct tlock *tlck;
4389         struct xtlock *sxtlck = NULL, *rxtlck = NULL;
4390         int quota_allocation = 0;
4391 +       int dlimit_allocation = 0;
4392  
4393         smp = split->mp;
4394         sp = XT_PAGE(ip, smp);
4395 @@ -1253,6 +1261,13 @@ xtSplitPage(tid_t tid, struct inode *ip,
4396  
4397         quota_allocation += lengthPXD(pxd);
4398  
4399 +       /* Allocate blocks to dlimit. */
4400 +       if (DLIMIT_ALLOC_BLOCK(ip, lengthPXD(pxd))) {
4401 +              rc = -ENOSPC;
4402 +              goto clean_up;
4403 +       }
4404 +       dlimit_allocation += lengthPXD(pxd);
4405 +
4406         /*
4407          * allocate the new right page for the split
4408          */
4409 @@ -1454,6 +1469,9 @@ xtSplitPage(tid_t tid, struct inode *ip,
4410  
4411        clean_up:
4412  
4413 +       /* Rollback dlimit allocation. */
4414 +       if (dlimit_allocation)
4415 +               DLIMIT_FREE_BLOCK(ip, dlimit_allocation);
4416         /* Rollback quota allocation. */
4417         if (quota_allocation)
4418                 DQUOT_FREE_BLOCK(ip, quota_allocation);
4419 @@ -1517,6 +1535,12 @@ xtSplitRoot(tid_t tid,
4420                 release_metapage(rmp);
4421                 return -EDQUOT;
4422         }
4423 +       /* Allocate blocks to dlimit. */
4424 +       if (DLIMIT_ALLOC_BLOCK(ip, lengthPXD(pxd))) {
4425 +               DQUOT_FREE_BLOCK(ip, lengthPXD(pxd));
4426 +               release_metapage(rmp);
4427 +               return -ENOSPC;
4428 +       }
4429  
4430         jfs_info("xtSplitRoot: ip:0x%p rmp:0x%p", ip, rmp);
4431  
4432 @@ -3940,6 +3964,8 @@ s64 xtTruncate(tid_t tid, struct inode *
4433         else
4434                 ip->i_size = newsize;
4435  
4436 +       /* update dlimit allocation to reflect freed blocks */
4437 +       DLIMIT_FREE_BLOCK(ip, nfreed);
4438         /* update quota allocation to reflect freed blocks */
4439         DQUOT_FREE_BLOCK(ip, nfreed);
4440  
4441 diff -NurpP --minimal linux-2.6.29.1/fs/jfs/namei.c linux-2.6.29.1-vs2.3.0.36.9-pre5/fs/jfs/namei.c
4442 --- linux-2.6.29.1/fs/jfs/namei.c       2009-03-24 14:22:26.000000000 +0100
4443 +++ linux-2.6.29.1-vs2.3.0.36.9-pre5/fs/jfs/namei.c     2009-03-24 14:48:35.000000000 +0100
4444 @@ -21,6 +21,7 @@
4445  #include <linux/ctype.h>
4446  #include <linux/quotaops.h>
4447  #include <linux/exportfs.h>
4448 +#include <linux/vs_tag.h>
4449  #include "jfs_incore.h"
4450  #include "jfs_superblock.h"
4451  #include "jfs_inode.h"
4452 @@ -1476,6 +1477,7 @@ static struct dentry *jfs_lookup(struct 
4453                 return ERR_CAST(ip);
4454         }
4455  
4456 +       dx_propagate_tag(nd, ip);
4457         dentry = d_splice_alias(ip, dentry);
4458  
4459         if (dentry && (JFS_SBI(dip->i_sb)->mntflag & JFS_OS2))
4460 @@ -1545,6 +1547,7 @@ const struct inode_operations jfs_dir_in
4461         .setattr        = jfs_setattr,
4462         .permission     = jfs_permission,
4463  #endif
4464 +       .sync_flags     = jfs_sync_flags,
4465  };
4466  
4467  const struct file_operations jfs_dir_operations = {
4468 diff -NurpP --minimal linux-2.6.29.1/fs/jfs/super.c linux-2.6.29.1-vs2.3.0.36.9-pre5/fs/jfs/super.c
4469 --- linux-2.6.29.1/fs/jfs/super.c       2009-03-24 14:22:26.000000000 +0100
4470 +++ linux-2.6.29.1-vs2.3.0.36.9-pre5/fs/jfs/super.c     2009-03-24 14:48:35.000000000 +0100
4471 @@ -196,7 +196,8 @@ static void jfs_put_super(struct super_b
4472  enum {
4473         Opt_integrity, Opt_nointegrity, Opt_iocharset, Opt_resize,
4474         Opt_resize_nosize, Opt_errors, Opt_ignore, Opt_err, Opt_quota,
4475 -       Opt_usrquota, Opt_grpquota, Opt_uid, Opt_gid, Opt_umask
4476 +       Opt_usrquota, Opt_grpquota, Opt_uid, Opt_gid, Opt_umask,
4477 +       Opt_tag, Opt_notag, Opt_tagid
4478  };
4479  
4480  static const match_table_t tokens = {
4481 @@ -206,6 +207,10 @@ static const match_table_t tokens = {
4482         {Opt_resize, "resize=%u"},
4483         {Opt_resize_nosize, "resize"},
4484         {Opt_errors, "errors=%s"},
4485 +       {Opt_tag, "tag"},
4486 +       {Opt_notag, "notag"},
4487 +       {Opt_tagid, "tagid=%u"},
4488 +       {Opt_tag, "tagxid"},
4489         {Opt_ignore, "noquota"},
4490         {Opt_ignore, "quota"},
4491         {Opt_usrquota, "usrquota"},
4492 @@ -340,6 +345,20 @@ static int parse_options(char *options, 
4493                         }
4494                         break;
4495                 }
4496 +#ifndef CONFIG_TAGGING_NONE
4497 +               case Opt_tag:
4498 +                       *flag |= JFS_TAGGED;
4499 +                       break;
4500 +               case Opt_notag:
4501 +                       *flag &= JFS_TAGGED;
4502 +                       break;
4503 +#endif
4504 +#ifdef CONFIG_PROPAGATE
4505 +               case Opt_tagid:
4506 +                       /* use args[0] */
4507 +                       *flag |= JFS_TAGGED;
4508 +                       break;
4509 +#endif
4510                 default:
4511                         printk("jfs: Unrecognized mount option \"%s\" "
4512                                         " or missing value\n", p);
4513 @@ -370,6 +389,13 @@ static int jfs_remount(struct super_bloc
4514         if (!parse_options(data, sb, &newLVSize, &flag)) {
4515                 return -EINVAL;
4516         }
4517 +
4518 +       if ((flag & JFS_TAGGED) && !(sb->s_flags & MS_TAGGED)) {
4519 +               printk(KERN_ERR "JFS: %s: tagging not permitted on remount.\n",
4520 +                       sb->s_id);
4521 +               return -EINVAL;
4522 +       }
4523 +
4524         if (newLVSize) {
4525                 if (sb->s_flags & MS_RDONLY) {
4526                         printk(KERN_ERR
4527 @@ -441,6 +467,9 @@ static int jfs_fill_super(struct super_b
4528  #ifdef CONFIG_JFS_POSIX_ACL
4529         sb->s_flags |= MS_POSIXACL;
4530  #endif
4531 +       /* map mount option tagxid */
4532 +       if (sbi->flag & JFS_TAGGED)
4533 +               sb->s_flags |= MS_TAGGED;
4534  
4535         if (newLVSize) {
4536                 printk(KERN_ERR "resize option for remount only\n");
4537 diff -NurpP --minimal linux-2.6.29.1/fs/jfs/xattr.c linux-2.6.29.1-vs2.3.0.36.9-pre5/fs/jfs/xattr.c
4538 --- linux-2.6.29.1/fs/jfs/xattr.c       2008-12-25 00:26:37.000000000 +0100
4539 +++ linux-2.6.29.1-vs2.3.0.36.9-pre5/fs/jfs/xattr.c     2009-02-22 22:54:25.000000000 +0100
4540 @@ -23,6 +23,7 @@
4541  #include <linux/posix_acl_xattr.h>
4542  #include <linux/quotaops.h>
4543  #include <linux/security.h>
4544 +#include <linux/vs_dlimit.h>
4545  #include "jfs_incore.h"
4546  #include "jfs_superblock.h"
4547  #include "jfs_dmap.h"
4548 @@ -263,9 +264,16 @@ static int ea_write(struct inode *ip, st
4549         if (DQUOT_ALLOC_BLOCK(ip, nblocks)) {
4550                 return -EDQUOT;
4551         }
4552 +       /* Allocate new blocks to dlimit. */
4553 +       if (DLIMIT_ALLOC_BLOCK(ip, nblocks)) {
4554 +               DQUOT_FREE_BLOCK(ip, nblocks);
4555 +               return -ENOSPC;
4556 +       }
4557  
4558         rc = dbAlloc(ip, INOHINT(ip), nblocks, &blkno);
4559         if (rc) {
4560 +               /*Rollback dlimit allocation. */
4561 +               DLIMIT_FREE_BLOCK(ip, nblocks);
4562                 /*Rollback quota allocation. */
4563                 DQUOT_FREE_BLOCK(ip, nblocks);
4564                 return rc;
4565 @@ -332,6 +340,8 @@ static int ea_write(struct inode *ip, st
4566  
4567        failed:
4568         /* Rollback quota allocation. */
4569 +       DLIMIT_FREE_BLOCK(ip, nblocks);
4570 +       /* Rollback quota allocation. */
4571         DQUOT_FREE_BLOCK(ip, nblocks);
4572  
4573         dbFree(ip, blkno, nblocks);
4574 @@ -468,6 +478,7 @@ static int ea_get(struct inode *inode, s
4575         s64 blkno;
4576         int rc;
4577         int quota_allocation = 0;
4578 +       int dlimit_allocation = 0;
4579  
4580         /* When fsck.jfs clears a bad ea, it doesn't clear the size */
4581         if (ji->ea.flag == 0)
4582 @@ -543,6 +554,12 @@ static int ea_get(struct inode *inode, s
4583  
4584                 quota_allocation = blocks_needed;
4585  
4586 +               /* Allocate new blocks to dlimit. */
4587 +               rc = -ENOSPC;
4588 +               if (DLIMIT_ALLOC_BLOCK(inode, blocks_needed))
4589 +                       goto clean_up;
4590 +               dlimit_allocation = blocks_needed;
4591 +
4592                 rc = dbAlloc(inode, INOHINT(inode), (s64) blocks_needed,
4593                              &blkno);
4594                 if (rc)
4595 @@ -600,6 +617,9 @@ static int ea_get(struct inode *inode, s
4596         return ea_size;
4597  
4598        clean_up:
4599 +       /* Rollback dlimit allocation */
4600 +       if (dlimit_allocation)
4601 +               DLIMIT_FREE_BLOCK(inode, dlimit_allocation);
4602         /* Rollback quota allocation */
4603         if (quota_allocation)
4604                 DQUOT_FREE_BLOCK(inode, quota_allocation);
4605 @@ -676,8 +696,10 @@ static int ea_put(tid_t tid, struct inod
4606         }
4607  
4608         /* If old blocks exist, they must be removed from quota allocation. */
4609 -       if (old_blocks)
4610 +       if (old_blocks) {
4611 +               DLIMIT_FREE_BLOCK(inode, old_blocks);
4612                 DQUOT_FREE_BLOCK(inode, old_blocks);
4613 +       }
4614  
4615         inode->i_ctime = CURRENT_TIME;
4616  
4617 diff -NurpP --minimal linux-2.6.29.1/fs/libfs.c linux-2.6.29.1-vs2.3.0.36.9-pre5/fs/libfs.c
4618 --- linux-2.6.29.1/fs/libfs.c   2009-03-24 14:22:26.000000000 +0100
4619 +++ linux-2.6.29.1-vs2.3.0.36.9-pre5/fs/libfs.c 2009-03-24 14:48:35.000000000 +0100
4620 @@ -125,7 +125,8 @@ static inline unsigned char dt_type(stru
4621   * both impossible due to the lock on directory.
4622   */
4623  
4624 -int dcache_readdir(struct file * filp, void * dirent, filldir_t filldir)
4625 +static inline int do_dcache_readdir_filter(struct file *filp,
4626 +       void *dirent, filldir_t filldir, int (*filter)(struct dentry *dentry))
4627  {
4628         struct dentry *dentry = filp->f_path.dentry;
4629         struct dentry *cursor = filp->private_data;
4630 @@ -158,6 +159,8 @@ int dcache_readdir(struct file * filp, v
4631                                 next = list_entry(p, struct dentry, d_u.d_child);
4632                                 if (d_unhashed(next) || !next->d_inode)
4633                                         continue;
4634 +                               if (filter && !filter(next))
4635 +                                       continue;
4636  
4637                                 spin_unlock(&dcache_lock);
4638                                 if (filldir(dirent, next->d_name.name, 
4639 @@ -176,6 +179,18 @@ int dcache_readdir(struct file * filp, v
4640         return 0;
4641  }
4642  
4643 +int dcache_readdir(struct file *filp, void *dirent, filldir_t filldir)
4644 +{
4645 +       return do_dcache_readdir_filter(filp, dirent, filldir, NULL);
4646 +}
4647 +
4648 +int dcache_readdir_filter(struct file *filp, void *dirent, filldir_t filldir,
4649 +       int (*filter)(struct dentry *))
4650 +{
4651 +       return do_dcache_readdir_filter(filp, dirent, filldir, filter);
4652 +}
4653 +
4654 +
4655  ssize_t generic_read_dir(struct file *filp, char __user *buf, size_t siz, loff_t *ppos)
4656  {
4657         return -EISDIR;
4658 @@ -796,6 +811,7 @@ EXPORT_SYMBOL(dcache_dir_close);
4659  EXPORT_SYMBOL(dcache_dir_lseek);
4660  EXPORT_SYMBOL(dcache_dir_open);
4661  EXPORT_SYMBOL(dcache_readdir);
4662 +EXPORT_SYMBOL(dcache_readdir_filter);
4663  EXPORT_SYMBOL(generic_read_dir);
4664  EXPORT_SYMBOL(get_sb_pseudo);
4665  EXPORT_SYMBOL(simple_write_begin);
4666 diff -NurpP --minimal linux-2.6.29.1/fs/locks.c linux-2.6.29.1-vs2.3.0.36.9-pre5/fs/locks.c
4667 --- linux-2.6.29.1/fs/locks.c   2009-03-24 14:22:26.000000000 +0100
4668 +++ linux-2.6.29.1-vs2.3.0.36.9-pre5/fs/locks.c 2009-03-24 14:48:35.000000000 +0100
4669 @@ -127,6 +127,8 @@
4670  #include <linux/time.h>
4671  #include <linux/rcupdate.h>
4672  #include <linux/pid_namespace.h>
4673 +#include <linux/vs_base.h>
4674 +#include <linux/vs_limit.h>
4675  
4676  #include <asm/uaccess.h>
4677  
4678 @@ -148,6 +150,8 @@ static struct kmem_cache *filelock_cache
4679  /* Allocate an empty lock structure. */
4680  static struct file_lock *locks_alloc_lock(void)
4681  {
4682 +       if (!vx_locks_avail(1))
4683 +               return NULL;
4684         return kmem_cache_alloc(filelock_cache, GFP_KERNEL);
4685  }
4686  
4687 @@ -173,6 +177,7 @@ static void locks_free_lock(struct file_
4688         BUG_ON(!list_empty(&fl->fl_block));
4689         BUG_ON(!list_empty(&fl->fl_link));
4690  
4691 +       vx_locks_dec(fl);
4692         locks_release_private(fl);
4693         kmem_cache_free(filelock_cache, fl);
4694  }
4695 @@ -193,6 +198,7 @@ void locks_init_lock(struct file_lock *f
4696         fl->fl_start = fl->fl_end = 0;
4697         fl->fl_ops = NULL;
4698         fl->fl_lmops = NULL;
4699 +       fl->fl_xid = -1;
4700  }
4701  
4702  EXPORT_SYMBOL(locks_init_lock);
4703 @@ -247,6 +253,7 @@ void locks_copy_lock(struct file_lock *n
4704         new->fl_file = fl->fl_file;
4705         new->fl_ops = fl->fl_ops;
4706         new->fl_lmops = fl->fl_lmops;
4707 +       new->fl_xid = fl->fl_xid;
4708  
4709         locks_copy_private(new, fl);
4710  }
4711 @@ -285,6 +292,11 @@ static int flock_make_lock(struct file *
4712         fl->fl_flags = FL_FLOCK;
4713         fl->fl_type = type;
4714         fl->fl_end = OFFSET_MAX;
4715 +
4716 +       vxd_assert(filp->f_xid == vx_current_xid(),
4717 +               "f_xid(%d) == current(%d)", filp->f_xid, vx_current_xid());
4718 +       fl->fl_xid = filp->f_xid;
4719 +       vx_locks_inc(fl);
4720         
4721         *lock = fl;
4722         return 0;
4723 @@ -450,6 +462,7 @@ static int lease_init(struct file *filp,
4724  
4725         fl->fl_owner = current->files;
4726         fl->fl_pid = current->tgid;
4727 +       fl->fl_xid = vx_current_xid();
4728  
4729         fl->fl_file = filp;
4730         fl->fl_flags = FL_LEASE;
4731 @@ -469,6 +482,11 @@ static struct file_lock *lease_alloc(str
4732         if (fl == NULL)
4733                 return ERR_PTR(error);
4734  
4735 +       fl->fl_xid = vx_current_xid();
4736 +       if (filp)
4737 +               vxd_assert(filp->f_xid == fl->fl_xid,
4738 +                       "f_xid(%d) == fl_xid(%d)", filp->f_xid, fl->fl_xid);
4739 +       vx_locks_inc(fl);
4740         error = lease_init(filp, type, fl);
4741         if (error) {
4742                 locks_free_lock(fl);
4743 @@ -769,6 +787,7 @@ static int flock_lock_file(struct file *
4744         if (found)
4745                 cond_resched_bkl();
4746  
4747 +       new_fl->fl_xid = -1;
4748  find_conflict:
4749         for_each_lock(inode, before) {
4750                 struct file_lock *fl = *before;
4751 @@ -789,6 +808,7 @@ find_conflict:
4752                 goto out;
4753         locks_copy_lock(new_fl, request);
4754         locks_insert_lock(before, new_fl);
4755 +       vx_locks_inc(new_fl);
4756         new_fl = NULL;
4757         error = 0;
4758  
4759 @@ -799,7 +819,8 @@ out:
4760         return error;
4761  }
4762  
4763 -static int __posix_lock_file(struct inode *inode, struct file_lock *request, struct file_lock *conflock)
4764 +static int __posix_lock_file(struct inode *inode, struct file_lock *request,
4765 +       struct file_lock *conflock, xid_t xid)
4766  {
4767         struct file_lock *fl;
4768         struct file_lock *new_fl = NULL;
4769 @@ -809,6 +830,8 @@ static int __posix_lock_file(struct inod
4770         struct file_lock **before;
4771         int error, added = 0;
4772  
4773 +       vxd_assert(xid == vx_current_xid(),
4774 +               "xid(%d) == current(%d)", xid, vx_current_xid());
4775         /*
4776          * We may need two file_lock structures for this operation,
4777          * so we get them in advance to avoid races.
4778 @@ -819,7 +842,11 @@ static int __posix_lock_file(struct inod
4779             (request->fl_type != F_UNLCK ||
4780              request->fl_start != 0 || request->fl_end != OFFSET_MAX)) {
4781                 new_fl = locks_alloc_lock();
4782 +               new_fl->fl_xid = xid;
4783 +               vx_locks_inc(new_fl);
4784                 new_fl2 = locks_alloc_lock();
4785 +               new_fl2->fl_xid = xid;
4786 +               vx_locks_inc(new_fl2);
4787         }
4788  
4789         lock_kernel();
4790 @@ -1018,7 +1045,8 @@ static int __posix_lock_file(struct inod
4791  int posix_lock_file(struct file *filp, struct file_lock *fl,
4792                         struct file_lock *conflock)
4793  {
4794 -       return __posix_lock_file(filp->f_path.dentry->d_inode, fl, conflock);
4795 +       return __posix_lock_file(filp->f_path.dentry->d_inode,
4796 +               fl, conflock, filp->f_xid);
4797  }
4798  EXPORT_SYMBOL(posix_lock_file);
4799  
4800 @@ -1108,7 +1136,7 @@ int locks_mandatory_area(int read_write,
4801         fl.fl_end = offset + count - 1;
4802  
4803         for (;;) {
4804 -               error = __posix_lock_file(inode, &fl, NULL);
4805 +               error = __posix_lock_file(inode, &fl, NULL, filp->f_xid);
4806                 if (error != FILE_LOCK_DEFERRED)
4807                         break;
4808                 error = wait_event_interruptible(fl.fl_wait, !fl.fl_next);
4809 @@ -1423,6 +1451,7 @@ int generic_setlease(struct file *filp, 
4810  
4811         locks_copy_lock(new_fl, lease);
4812         locks_insert_lock(before, new_fl);
4813 +       vx_locks_inc(new_fl);
4814  
4815         *flp = new_fl;
4816         return 0;
4817 @@ -1778,6 +1807,11 @@ int fcntl_setlk(unsigned int fd, struct 
4818         if (file_lock == NULL)
4819                 return -ENOLCK;
4820  
4821 +       vxd_assert(filp->f_xid == vx_current_xid(),
4822 +               "f_xid(%d) == current(%d)", filp->f_xid, vx_current_xid());
4823 +       file_lock->fl_xid = filp->f_xid;
4824 +       vx_locks_inc(file_lock);
4825 +
4826         /*
4827          * This might block, so we do it before checking the inode.
4828          */
4829 @@ -1896,6 +1930,11 @@ int fcntl_setlk64(unsigned int fd, struc
4830         if (file_lock == NULL)
4831                 return -ENOLCK;
4832  
4833 +       vxd_assert(filp->f_xid == vx_current_xid(),
4834 +               "f_xid(%d) == current(%d)", filp->f_xid, vx_current_xid());
4835 +       file_lock->fl_xid = filp->f_xid;
4836 +       vx_locks_inc(file_lock);
4837 +
4838         /*
4839          * This might block, so we do it before checking the inode.
4840          */
4841 @@ -2161,8 +2200,11 @@ static int locks_show(struct seq_file *f
4842  
4843         lock_get_status(f, fl, (long)f->private, "");
4844  
4845 -       list_for_each_entry(bfl, &fl->fl_block, fl_block)
4846 +       list_for_each_entry(bfl, &fl->fl_block, fl_block) {
4847 +               if (!vx_check(fl->fl_xid, VS_WATCH_P | VS_IDENT))
4848 +                       continue;
4849                 lock_get_status(f, bfl, (long)f->private, " ->");
4850 +       }
4851  
4852         f->private++;
4853         return 0;
4854 diff -NurpP --minimal linux-2.6.29.1/fs/namei.c linux-2.6.29.1-vs2.3.0.36.9-pre5/fs/namei.c
4855 --- linux-2.6.29.1/fs/namei.c   2009-03-24 14:22:26.000000000 +0100
4856 +++ linux-2.6.29.1-vs2.3.0.36.9-pre5/fs/namei.c 2009-03-25 00:50:11.000000000 +0100
4857 @@ -31,6 +31,14 @@
4858  #include <linux/file.h>
4859  #include <linux/fcntl.h>
4860  #include <linux/device_cgroup.h>
4861 +#include <linux/proc_fs.h>
4862 +#include <linux/vserver/inode.h>
4863 +#include <linux/vs_base.h>
4864 +#include <linux/vs_tag.h>
4865 +#include <linux/vs_cowbl.h>
4866 +#include <linux/vs_device.h>
4867 +#include <linux/vs_context.h>
4868 +#include <linux/pid_namespace.h>
4869  #include <asm/uaccess.h>
4870  
4871  #define ACC_MODE(x) ("\000\004\002\006"[(x)&O_ACCMODE])
4872 @@ -167,6 +175,77 @@ void putname(const char *name)
4873  EXPORT_SYMBOL(putname);
4874  #endif
4875  
4876 +static inline int dx_barrier(struct inode *inode)
4877 +{
4878 +       if (IS_BARRIER(inode) && !vx_check(0, VS_ADMIN | VS_WATCH)) {
4879 +               vxwprintk_task(1, "did hit the barrier.");
4880 +               return 1;
4881 +       }
4882 +       return 0;
4883 +}
4884 +
4885 +static int __dx_permission(struct inode *inode, int mask)
4886 +{
4887 +       if (dx_barrier(inode))
4888 +               return -EACCES;
4889 +
4890 +       if (inode->i_sb->s_magic == DEVPTS_SUPER_MAGIC) {
4891 +               /* devpts is xid tagged */
4892 +               if (S_ISDIR(inode->i_mode) ||
4893 +                   vx_check((xid_t)inode->i_tag, VS_IDENT | VS_WATCH_P))
4894 +                       return 0;
4895 +       }
4896 +       else if (inode->i_sb->s_magic == PROC_SUPER_MAGIC) {
4897 +               struct proc_dir_entry *de = PDE(inode);
4898 +
4899 +               if (de && !vx_hide_check(0, de->vx_flags))
4900 +                       goto out;
4901 +
4902 +               if ((mask & (MAY_WRITE | MAY_APPEND))) {
4903 +                       struct pid *pid;
4904 +                       struct task_struct *tsk;
4905 +
4906 +                       if (vx_check(0, VS_ADMIN | VS_WATCH_P) ||
4907 +                           vx_flags(VXF_STATE_SETUP, 0))
4908 +                               return 0;
4909 +
4910 +                       pid = PROC_I(inode)->pid;
4911 +                       if (!pid)
4912 +                               goto out;
4913 +
4914 +                       tsk = pid_task(pid, PIDTYPE_PID);
4915 +                       vxdprintk(VXD_CBIT(tag, 0), "accessing %p[#%u]",
4916 +                                 tsk, (tsk ? vx_task_xid(tsk) : 0));
4917 +                       if (tsk && vx_check(vx_task_xid(tsk), VS_IDENT | VS_WATCH_P))
4918 +                               return 0;
4919 +               }
4920 +               else {
4921 +                       /* FIXME: Should we block some entries here? */
4922 +                       return 0;
4923 +               }
4924 +       }
4925 +       else {
4926 +               if (dx_notagcheck(inode->i_sb) ||
4927 +                   dx_check(inode->i_tag, DX_HOSTID | DX_ADMIN | DX_WATCH |
4928 +                            DX_IDENT))
4929 +                       return 0;
4930 +       }
4931 +
4932 +out:
4933 +       return -EACCES;
4934 +}
4935 +
4936 +int dx_permission(struct inode *inode, int mask)
4937 +{
4938 +       int ret = __dx_permission(inode, mask);
4939 +       if (unlikely(ret)) {
4940 +               vxwprintk_task(1, "denied %x access to %s:%p[#%d,%lu]",
4941 +                       mask, inode->i_sb->s_id, inode, inode->i_tag,
4942 +                       inode->i_ino);
4943 +       }
4944 +       return ret;
4945 +}
4946 +
4947  
4948  /**
4949   * generic_permission  -  check for access rights on a Posix-like filesystem
4950 @@ -253,10 +332,14 @@ int inode_permission(struct inode *inode
4951                 /*
4952                  * Nobody gets write access to an immutable file.
4953                  */
4954 -               if (IS_IMMUTABLE(inode))
4955 +               if (IS_IMMUTABLE(inode) && !IS_COW(inode))
4956                         return -EACCES;
4957         }
4958  
4959 +       retval = dx_permission(inode, mask);
4960 +       if (retval)
4961 +               return retval;
4962 +
4963         if (inode->i_op->permission)
4964                 retval = inode->i_op->permission(inode, mask);
4965         else
4966 @@ -432,6 +515,8 @@ static int exec_permission_lite(struct i
4967  {
4968         umode_t mode = inode->i_mode;
4969  
4970 +       if (dx_barrier(inode))
4971 +               return -EACCES;
4972         if (inode->i_op->permission)
4973                 return -EAGAIN;
4974  
4975 @@ -749,7 +834,8 @@ static __always_inline void follow_dotdo
4976                 if (nd->path.dentry == fs->root.dentry &&
4977                     nd->path.mnt == fs->root.mnt) {
4978                          read_unlock(&fs->lock);
4979 -                       break;
4980 +                       /* for sane '/' avoid follow_mount() */
4981 +                       return;
4982                 }
4983                  read_unlock(&fs->lock);
4984                 spin_lock(&dcache_lock);
4985 @@ -786,16 +872,30 @@ static int do_lookup(struct nameidata *n
4986  {
4987         struct vfsmount *mnt = nd->path.mnt;
4988         struct dentry *dentry = __d_lookup(nd->path.dentry, name);
4989 +       struct inode *inode;
4990  
4991         if (!dentry)
4992                 goto need_lookup;
4993         if (dentry->d_op && dentry->d_op->d_revalidate)
4994                 goto need_revalidate;
4995 +       inode = dentry->d_inode;
4996 +       if (!inode)
4997 +               goto done;
4998 +
4999 +       if (__dx_permission(inode, MAY_ACCESS))
5000 +               goto hidden;
5001 +
5002  done:
5003         path->mnt = mnt;
5004         path->dentry = dentry;
5005         __follow_mount(path);
5006         return 0;
5007 +hidden:
5008 +       vxwprintk_task(1, "did lookup hidden %s:%p[#%d,%lu] Â»%s«.",
5009 +               inode->i_sb->s_id, inode, inode->i_tag, inode->i_ino,
5010 +               vxd_path(&nd->path));
5011 +       dput(dentry);
5012 +       return -ENOENT;
5013  
5014  need_lookup:
5015         dentry = real_lookup(nd->path.dentry, name, nd);
5016 @@ -1364,7 +1464,7 @@ static int may_delete(struct inode *dir,
5017         if (IS_APPEND(dir))
5018                 return -EPERM;
5019         if (check_sticky(dir, victim->d_inode)||IS_APPEND(victim->d_inode)||
5020 -           IS_IMMUTABLE(victim->d_inode) || IS_SWAPFILE(victim->d_inode))
5021 +               IS_IXORUNLINK(victim->d_inode) || IS_SWAPFILE(victim->d_inode))
5022                 return -EPERM;
5023         if (isdir) {
5024                 if (!S_ISDIR(victim->d_inode->i_mode))
5025 @@ -1506,6 +1606,14 @@ int may_open(struct path *path, int acc_
5026                 flag &= ~O_TRUNC;
5027         }
5028  
5029 +#ifdef CONFIG_VSERVER_COWBL
5030 +       if (IS_COW(inode) && (flag & FMODE_WRITE)) {
5031 +               if (IS_COW_LINK(inode))
5032 +                       return -EMLINK;
5033 +               inode->i_flags &= ~(S_IXUNLINK|S_IMMUTABLE);
5034 +               mark_inode_dirty(inode);
5035 +       }
5036 +#endif
5037         error = inode_permission(inode, acc_mode);
5038         if (error)
5039                 return error;
5040 @@ -1639,6 +1747,11 @@ struct file *do_filp_open(int dfd, const
5041         int will_write;
5042         int flag = open_to_namei_flags(open_flag);
5043  
5044 +#ifdef CONFIG_VSERVER_COWBL
5045 +       int rflag = flag;
5046 +       int rmode = mode;
5047 +restart:
5048 +#endif
5049         acc_mode = MAY_OPEN | ACC_MODE(flag);
5050  
5051         /* O_TRUNC implies we need access checks for write permissions */
5052 @@ -1771,6 +1884,25 @@ ok:
5053                         goto exit;
5054         }
5055         error = may_open(&nd.path, acc_mode, flag);
5056 +#ifdef CONFIG_VSERVER_COWBL
5057 +       if (error == -EMLINK) {
5058 +               struct dentry *dentry;
5059 +               dentry = cow_break_link(pathname);
5060 +               if (IS_ERR(dentry)) {
5061 +                       error = PTR_ERR(dentry);
5062 +                       goto exit_cow;
5063 +               }
5064 +               dput(dentry);
5065 +               if (will_write)
5066 +                       mnt_drop_write(nd.path.mnt);
5067 +               release_open_intent(&nd);
5068 +               path_put(&nd.path);
5069 +               flag = rflag;
5070 +               mode = rmode;
5071 +               goto restart;
5072 +       }
5073 +exit_cow:
5074 +#endif
5075         if (error) {
5076                 if (will_write)
5077                         mnt_drop_write(nd.path.mnt);
5078 @@ -1924,9 +2056,17 @@ int vfs_mknod(struct inode *dir, struct 
5079         if (error)
5080                 return error;
5081  
5082 -       if ((S_ISCHR(mode) || S_ISBLK(mode)) && !capable(CAP_MKNOD))
5083 +       if (!(S_ISCHR(mode) || S_ISBLK(mode)))
5084 +               goto okay;
5085 +
5086 +       if (!capable(CAP_MKNOD))
5087                 return -EPERM;
5088  
5089 +       if (S_ISCHR(mode) && !vs_chrdev_perm(dev, DATTR_CREATE))
5090 +               return -EPERM;
5091 +       if (S_ISBLK(mode) && !vs_blkdev_perm(dev, DATTR_CREATE))
5092 +               return -EPERM;
5093 +okay:
5094         if (!dir->i_op->mknod)
5095                 return -EPERM;
5096  
5097 @@ -2393,7 +2533,7 @@ int vfs_link(struct dentry *old_dentry, 
5098         /*
5099          * A link to an append-only or immutable file cannot be created.
5100          */
5101 -       if (IS_APPEND(inode) || IS_IMMUTABLE(inode))
5102 +       if (IS_APPEND(inode) || IS_IXORUNLINK(inode))
5103                 return -EPERM;
5104         if (!dir->i_op->link)
5105                 return -EPERM;
5106 @@ -2766,6 +2906,219 @@ int vfs_follow_link(struct nameidata *nd
5107         return __vfs_follow_link(nd, link);
5108  }
5109  
5110 +
5111 +#ifdef CONFIG_VSERVER_COWBL
5112 +
5113 +#include <linux/file.h>
5114 +
5115 +static inline
5116 +long do_cow_splice(struct file *in, struct file *out, size_t len)
5117 +{
5118 +       loff_t ppos = 0;
5119 +
5120 +       return do_splice_direct(in, &ppos, out, len, 0);
5121 +}
5122 +
5123 +struct dentry *cow_break_link(const char *pathname)
5124 +{
5125 +       int ret, mode, pathlen, redo = 0;
5126 +       struct nameidata old_nd, dir_nd;
5127 +       struct path old_path, new_path;
5128 +       struct dentry *dir, *res = NULL;
5129 +       struct file *old_file;
5130 +       struct file *new_file;
5131 +       char *to, *path, pad='\251';
5132 +       loff_t size;
5133 +
5134 +       vxdprintk(VXD_CBIT(misc, 1), "cow_break_link(»%s«)", pathname);
5135 +       path = kmalloc(PATH_MAX, GFP_KERNEL);
5136 +       ret = -ENOMEM;
5137 +       if (!path)
5138 +               goto out;
5139 +
5140 +       /* old_nd will have refs to dentry and mnt */
5141 +       ret = path_lookup(pathname, LOOKUP_FOLLOW, &old_nd);
5142 +       vxdprintk(VXD_CBIT(misc, 2), "path_lookup(old): %d", ret);
5143 +       if (ret < 0)
5144 +               goto out_free_path;
5145 +
5146 +       old_path = old_nd.path;
5147 +       mode = old_path.dentry->d_inode->i_mode;
5148 +
5149 +       to = d_path(&old_path, path, PATH_MAX-2);
5150 +       pathlen = strlen(to);
5151 +       vxdprintk(VXD_CBIT(misc, 2), "old path Â»%s« [»%.*s«:%d]", to,
5152 +               old_path.dentry->d_name.len, old_path.dentry->d_name.name,
5153 +               old_path.dentry->d_name.len);
5154 +
5155 +       to[pathlen + 1] = 0;
5156 +retry:
5157 +       to[pathlen] = pad--;
5158 +       ret = -EMLINK;
5159 +       if (pad <= '\240')
5160 +               goto out_rel_old;
5161 +
5162 +       vxdprintk(VXD_CBIT(misc, 1), "temp copy Â»%s«", to);
5163 +       /* dir_nd will have refs to dentry and mnt */
5164 +       ret = path_lookup(to,
5165 +               LOOKUP_PARENT | LOOKUP_OPEN | LOOKUP_CREATE, &dir_nd);
5166 +       vxdprintk(VXD_CBIT(misc, 2),
5167 +               "path_lookup(new): %d", ret);
5168 +       if (ret < 0)
5169 +               goto retry;
5170 +
5171 +       /* this puppy downs the inode mutex */
5172 +       new_path.dentry = lookup_create(&dir_nd, 0);
5173 +       if (!new_path.dentry || IS_ERR(new_path.dentry)) {
5174 +               vxdprintk(VXD_CBIT(misc, 2),
5175 +                       "lookup_create(new): %p", new_path.dentry);
5176 +               mutex_unlock(&dir_nd.path.dentry->d_inode->i_mutex);
5177 +               path_put(&dir_nd.path);
5178 +               goto retry;
5179 +       }
5180 +       vxdprintk(VXD_CBIT(misc, 2),
5181 +               "lookup_create(new): %p [»%.*s«:%d]", new_path.dentry,
5182 +               new_path.dentry->d_name.len, new_path.dentry->d_name.name,
5183 +               new_path.dentry->d_name.len);
5184 +       dir = dir_nd.path.dentry;
5185 +
5186 +       ret = vfs_create(dir_nd.path.dentry->d_inode, new_path.dentry, mode, &dir_nd);
5187 +       vxdprintk(VXD_CBIT(misc, 2),
5188 +               "vfs_create(new): %d", ret);
5189 +       if (ret == -EEXIST) {
5190 +               mutex_unlock(&dir->d_inode->i_mutex);
5191 +               dput(new_path.dentry);
5192 +               path_put(&dir_nd.path);
5193 +               goto retry;
5194 +       }
5195 +       else if (ret < 0)
5196 +               goto out_unlock_new;
5197 +
5198 +       /* drop out early, ret passes ENOENT */
5199 +       ret = -ENOENT;
5200 +       if ((redo = d_unhashed(old_path.dentry)))
5201 +               goto out_unlock_new;
5202 +
5203 +       new_path.mnt = dir_nd.path.mnt;
5204 +       dget(old_path.dentry);
5205 +       mntget(old_path.mnt);
5206 +       /* this one cleans up the dentry/mnt in case of failure */
5207 +       old_file = dentry_open(old_path.dentry, old_path.mnt,
5208 +               O_RDONLY, current_cred());
5209 +       vxdprintk(VXD_CBIT(misc, 2),
5210 +               "dentry_open(old): %p", old_file);
5211 +       if (!old_file || IS_ERR(old_file)) {
5212 +               res = IS_ERR(old_file) ? (void *) old_file : res;
5213 +               goto out_unlock_new;
5214 +       }
5215 +
5216 +       dget(new_path.dentry);
5217 +       mntget(new_path.mnt);
5218 +       /* this one cleans up the dentry/mnt in case of failure */
5219 +       new_file = dentry_open(new_path.dentry, new_path.mnt,
5220 +               O_WRONLY, current_cred());
5221 +       vxdprintk(VXD_CBIT(misc, 2),
5222 +               "dentry_open(new): %p", new_file);
5223 +
5224 +       ret = IS_ERR(new_file) ? PTR_ERR(new_file) : -ENOENT;
5225 +       if (!new_file || IS_ERR(new_file))
5226 +               goto out_fput_old;
5227 +
5228 +       size = i_size_read(old_file->f_dentry->d_inode);
5229 +       ret = do_cow_splice(old_file, new_file, size);
5230 +       vxdprintk(VXD_CBIT(misc, 2), "do_splice_direct: %d", ret);
5231 +       if (ret < 0) {
5232 +               goto out_fput_both;
5233 +       } else if (ret < size) {
5234 +               ret = -ENOSPC;
5235 +               goto out_fput_both;
5236 +       } else {
5237 +               struct inode *old_inode = old_path.dentry->d_inode;
5238 +               struct inode *new_inode = new_path.dentry->d_inode;
5239 +               struct iattr attr = {
5240 +                       .ia_uid = old_inode->i_uid,
5241 +                       .ia_gid = old_inode->i_gid,
5242 +                       .ia_valid = ATTR_UID | ATTR_GID
5243 +                       };
5244 +
5245 +               ret = inode_setattr(new_inode, &attr);
5246 +               if (ret)
5247 +                       goto out_fput_both;
5248 +       }
5249 +
5250 +       mutex_lock(&old_path.dentry->d_inode->i_sb->s_vfs_rename_mutex);
5251 +
5252 +       /* drop out late */
5253 +       ret = -ENOENT;
5254 +       if ((redo = d_unhashed(old_path.dentry)))
5255 +               goto out_unlock;
5256 +
5257 +       vxdprintk(VXD_CBIT(misc, 2),
5258 +               "vfs_rename: [»%*s«:%d] -> [»%*s«:%d]",
5259 +               new_path.dentry->d_name.len, new_path.dentry->d_name.name,
5260 +               new_path.dentry->d_name.len,
5261 +               old_path.dentry->d_name.len, old_path.dentry->d_name.name,
5262 +               old_path.dentry->d_name.len);
5263 +       ret = vfs_rename(dir_nd.path.dentry->d_inode, new_path.dentry,
5264 +               old_nd.path.dentry->d_parent->d_inode, old_path.dentry);
5265 +       vxdprintk(VXD_CBIT(misc, 2), "vfs_rename: %d", ret);
5266 +       res = new_path.dentry;
5267 +
5268 +out_unlock:
5269 +       mutex_unlock(&old_path.dentry->d_inode->i_sb->s_vfs_rename_mutex);
5270 +
5271 +out_fput_both:
5272 +       vxdprintk(VXD_CBIT(misc, 3),
5273 +               "fput(new_file=%p[#%ld])", new_file,
5274 +               atomic_read(&new_file->f_count));
5275 +       fput(new_file);
5276 +
5277 +out_fput_old:
5278 +       vxdprintk(VXD_CBIT(misc, 3),
5279 +               "fput(old_file=%p[#%ld])", old_file,
5280 +               atomic_read(&old_file->f_count));
5281 +       fput(old_file);
5282 +
5283 +out_unlock_new:
5284 +       mutex_unlock(&dir->d_inode->i_mutex);
5285 +       if (!ret)
5286 +               goto out_redo;
5287 +
5288 +       /* error path cleanup */
5289 +       vfs_unlink(dir->d_inode, new_path.dentry);
5290 +       dput(new_path.dentry);
5291 +
5292 +out_redo:
5293 +       if (!redo)
5294 +               goto out_rel_both;
5295 +       /* lookup dentry once again */
5296 +       path_put(&old_nd.path);
5297 +       ret = path_lookup(pathname, LOOKUP_FOLLOW, &old_nd);
5298 +       if (ret)
5299 +               goto out_rel_both;
5300 +
5301 +       new_path.dentry = old_nd.path.dentry;
5302 +       vxdprintk(VXD_CBIT(misc, 2),
5303 +               "path_lookup(redo): %p [»%.*s«:%d]", new_path.dentry,
5304 +               new_path.dentry->d_name.len, new_path.dentry->d_name.name,
5305 +               new_path.dentry->d_name.len);
5306 +       dget(new_path.dentry);
5307 +       res = new_path.dentry;
5308 +
5309 +out_rel_both:
5310 +       path_put(&dir_nd.path);
5311 +out_rel_old:
5312 +       path_put(&old_nd.path);
5313 +out_free_path:
5314 +       kfree(path);
5315 +out:
5316 +       if (ret)
5317 +               res = ERR_PTR(ret);
5318 +       return res;
5319 +}
5320 +
5321 +#endif
5322 +
5323  /* get the link contents into pagecache */
5324  static char *page_getlink(struct dentry * dentry, struct page **ppage)
5325  {
5326 diff -NurpP --minimal linux-2.6.29.1/fs/namespace.c linux-2.6.29.1-vs2.3.0.36.9-pre5/fs/namespace.c
5327 --- linux-2.6.29.1/fs/namespace.c       2009-03-24 14:22:26.000000000 +0100
5328 +++ linux-2.6.29.1-vs2.3.0.36.9-pre5/fs/namespace.c     2009-04-10 23:15:11.000000000 +0200
5329 @@ -27,6 +27,11 @@
5330  #include <linux/ramfs.h>
5331  #include <linux/log2.h>
5332  #include <linux/idr.h>
5333 +#include <linux/vs_base.h>
5334 +#include <linux/vs_context.h>
5335 +#include <linux/vs_tag.h>
5336 +#include <linux/vserver/space.h>
5337 +#include <linux/vserver/global.h>
5338  #include <asm/uaccess.h>
5339  #include <asm/unistd.h>
5340  #include "pnode.h"
5341 @@ -573,6 +578,7 @@ static struct vfsmount *clone_mnt(struct
5342                 mnt->mnt_root = dget(root);
5343                 mnt->mnt_mountpoint = mnt->mnt_root;
5344                 mnt->mnt_parent = mnt;
5345 +               mnt->mnt_tag = old->mnt_tag;
5346  
5347                 if (flag & CL_SLAVE) {
5348                         list_add(&mnt->mnt_slave, &old->mnt_slave_list);
5349 @@ -687,6 +693,31 @@ static inline void mangle(struct seq_fil
5350         seq_escape(m, s, " \t\n\\");
5351  }
5352  
5353 +static int mnt_is_reachable(struct vfsmount *mnt)
5354 +{
5355 +       struct path root;
5356 +       struct dentry *point;
5357 +       int ret;
5358 +
5359 +       if (mnt == mnt->mnt_ns->root)
5360 +               return 1;
5361 +
5362 +       spin_lock(&vfsmount_lock);
5363 +       root = current->fs->root;
5364 +       point = root.dentry;
5365 +
5366 +       while ((mnt != mnt->mnt_parent) && (mnt != root.mnt)) {
5367 +               point = mnt->mnt_mountpoint;
5368 +               mnt = mnt->mnt_parent;
5369 +       }
5370 +
5371 +       ret = (mnt == root.mnt) && is_subdir(point, root.dentry);
5372 +
5373 +       spin_unlock(&vfsmount_lock);
5374 +
5375 +       return ret;
5376 +}
5377 +
5378  /*
5379   * Simple .show_options callback for filesystems which don't want to
5380   * implement more complex mount option showing.
5381 @@ -759,6 +790,8 @@ static int show_sb_opts(struct seq_file 
5382                 { MS_SYNCHRONOUS, ",sync" },
5383                 { MS_DIRSYNC, ",dirsync" },
5384                 { MS_MANDLOCK, ",mand" },
5385 +               { MS_TAGGED, ",tag" },
5386 +               { MS_NOTAGCHECK, ",notagcheck" },
5387                 { 0, NULL }
5388         };
5389         const struct proc_fs_info *fs_infop;
5390 @@ -805,10 +838,20 @@ static int show_vfsmnt(struct seq_file *
5391         int err = 0;
5392         struct path mnt_path = { .dentry = mnt->mnt_root, .mnt = mnt };
5393  
5394 -       mangle(m, mnt->mnt_devname ? mnt->mnt_devname : "none");
5395 -       seq_putc(m, ' ');
5396 -       seq_path(m, &mnt_path, " \t\n\\");
5397 -       seq_putc(m, ' ');
5398 +       if (vx_flags(VXF_HIDE_MOUNT, 0))
5399 +               return SEQ_SKIP;
5400 +       if (!mnt_is_reachable(mnt) && !vx_check(0, VS_WATCH_P))
5401 +               return SEQ_SKIP;
5402 +
5403 +       if (!vx_check(0, VS_ADMIN|VS_WATCH) &&
5404 +               mnt == current->fs->root.mnt) {
5405 +               seq_puts(m, "/dev/root / ");
5406 +       } else {
5407 +               mangle(m, mnt->mnt_devname ? mnt->mnt_devname : "none");
5408 +               seq_putc(m, ' ');
5409 +               seq_path(m, &mnt_path, " \t\n\\");
5410 +               seq_putc(m, ' ');
5411 +       }
5412         show_type(m, mnt->mnt_sb);
5413         seq_puts(m, __mnt_is_readonly(mnt) ? " ro" : " rw");
5414         err = show_sb_opts(m, mnt->mnt_sb);
5415 @@ -838,6 +881,11 @@ static int show_mountinfo(struct seq_fil
5416         struct path root = p->root;
5417         int err = 0;
5418  
5419 +       if (vx_flags(VXF_HIDE_MOUNT, 0))
5420 +               return SEQ_SKIP;
5421 +       if (!mnt_is_reachable(mnt) && !vx_check(0, VS_WATCH_P))
5422 +               return SEQ_SKIP;
5423 +
5424         seq_printf(m, "%i %i %u:%u ", mnt->mnt_id, mnt->mnt_parent->mnt_id,
5425                    MAJOR(sb->s_dev), MINOR(sb->s_dev));
5426         seq_dentry(m, mnt->mnt_root, " \t\n\\");
5427 @@ -896,17 +944,27 @@ static int show_vfsstat(struct seq_file 
5428         struct path mnt_path = { .dentry = mnt->mnt_root, .mnt = mnt };
5429         int err = 0;
5430  
5431 -       /* device */
5432 -       if (mnt->mnt_devname) {
5433 -               seq_puts(m, "device ");
5434 -               mangle(m, mnt->mnt_devname);
5435 -       } else
5436 -               seq_puts(m, "no device");
5437 +       if (vx_flags(VXF_HIDE_MOUNT, 0))
5438 +               return SEQ_SKIP;
5439 +       if (!mnt_is_reachable(mnt) && !vx_check(0, VS_WATCH_P))
5440 +               return SEQ_SKIP;
5441  
5442 -       /* mount point */
5443 -       seq_puts(m, " mounted on ");
5444 -       seq_path(m, &mnt_path, " \t\n\\");
5445 -       seq_putc(m, ' ');
5446 +       if (!vx_check(0, VS_ADMIN|VS_WATCH) &&
5447 +               mnt == current->fs->root.mnt) {
5448 +               seq_puts(m, "device /dev/root mounted on / ");
5449 +       } else {
5450 +               /* device */
5451 +               if (mnt->mnt_devname) {
5452 +                       seq_puts(m, "device ");
5453 +                       mangle(m, mnt->mnt_devname);
5454 +               } else
5455 +                       seq_puts(m, "no device");
5456 +
5457 +               /* mount point */
5458 +               seq_puts(m, " mounted on ");
5459 +               seq_path(m, &mnt_path, " \t\n\\");
5460 +               seq_putc(m, ' ');
5461 +       }
5462  
5463         /* file system type */
5464         seq_puts(m, "with fstype ");
5465 @@ -1145,7 +1203,7 @@ SYSCALL_DEFINE2(umount, char __user *, n
5466                 goto dput_and_out;
5467  
5468         retval = -EPERM;
5469 -       if (!capable(CAP_SYS_ADMIN))
5470 +       if (!vx_capable(CAP_SYS_ADMIN, VXC_SECURE_MOUNT))
5471                 goto dput_and_out;
5472  
5473         retval = do_umount(path.mnt, flags);
5474 @@ -1171,7 +1229,7 @@ SYSCALL_DEFINE1(oldumount, char __user *
5475  
5476  static int mount_is_safe(struct path *path)
5477  {
5478 -       if (capable(CAP_SYS_ADMIN))
5479 +       if (vx_capable(CAP_SYS_ADMIN, VXC_SECURE_MOUNT))
5480                 return 0;
5481         return -EPERM;
5482  #ifdef notyet
5483 @@ -1462,11 +1520,13 @@ static int do_change_type(struct path *p
5484   * do loopback mount.
5485   */
5486  static int do_loopback(struct path *path, char *old_name,
5487 -                               int recurse)
5488 +       tag_t tag, unsigned long flags, int mnt_flags)
5489  {
5490         struct path old_path;
5491         struct vfsmount *mnt = NULL;
5492         int err = mount_is_safe(path);
5493 +       int recurse = flags & MS_REC;
5494 +
5495         if (err)
5496                 return err;
5497         if (!old_name || !*old_name)
5498 @@ -1500,6 +1560,7 @@ static int do_loopback(struct path *path
5499                 spin_unlock(&vfsmount_lock);
5500                 release_mounts(&umount_list);
5501         }
5502 +       mnt->mnt_flags = mnt_flags;
5503  
5504  out:
5505         up_write(&namespace_sem);
5506 @@ -1530,12 +1591,12 @@ static int change_mount_flags(struct vfs
5507   * on it - tough luck.
5508   */
5509  static int do_remount(struct path *path, int flags, int mnt_flags,
5510 -                     void *data)
5511 +       void *data, xid_t xid)
5512  {
5513         int err;
5514         struct super_block *sb = path->mnt->mnt_sb;
5515  
5516 -       if (!capable(CAP_SYS_ADMIN))
5517 +       if (!vx_capable(CAP_SYS_ADMIN, VXC_SECURE_REMOUNT))
5518                 return -EPERM;
5519  
5520         if (!check_mnt(path->mnt))
5521 @@ -1577,7 +1638,7 @@ static int do_move_mount(struct path *pa
5522         struct path old_path, parent_path;
5523         struct vfsmount *p;
5524         int err = 0;
5525 -       if (!capable(CAP_SYS_ADMIN))
5526 +       if (!vx_capable(CAP_SYS_ADMIN, VXC_SECURE_MOUNT))
5527                 return -EPERM;
5528         if (!old_name || !*old_name)
5529                 return -EINVAL;
5530 @@ -1659,7 +1720,7 @@ static int do_new_mount(struct path *pat
5531                 return -EINVAL;
5532  
5533         /* we need capabilities... */
5534 -       if (!capable(CAP_SYS_ADMIN))
5535 +       if (!vx_capable(CAP_SYS_ADMIN, VXC_SECURE_MOUNT))
5536                 return -EPERM;
5537  
5538         mnt = do_kern_mount(type, flags, name, data);
5539 @@ -1904,6 +1965,7 @@ long do_mount(char *dev_name, char *dir_
5540         struct path path;
5541         int retval = 0;
5542         int mnt_flags = 0;
5543 +       tag_t tag = 0;
5544  
5545         /* Discard magic */
5546         if ((flags & MS_MGC_MSK) == MS_MGC_VAL)
5547 @@ -1919,6 +1981,12 @@ long do_mount(char *dev_name, char *dir_
5548         if (data_page)
5549                 ((char *)data_page)[PAGE_SIZE - 1] = 0;
5550  
5551 +       if (dx_parse_tag(data_page, &tag, 1, &mnt_flags, &flags)) {
5552 +               /* FIXME: bind and re-mounts get the tag flag? */
5553 +               if (flags & (MS_BIND|MS_REMOUNT))
5554 +                       flags |= MS_TAGID;
5555 +       }
5556 +
5557         /* Separate the per-mountpoint flags */
5558         if (flags & MS_NOSUID)
5559                 mnt_flags |= MNT_NOSUID;
5560 @@ -1935,6 +2003,8 @@ long do_mount(char *dev_name, char *dir_
5561         if (flags & MS_RDONLY)
5562                 mnt_flags |= MNT_READONLY;
5563  
5564 +       if (!capable(CAP_SYS_ADMIN))
5565 +               mnt_flags |= MNT_NODEV;
5566         flags &= ~(MS_NOSUID | MS_NOEXEC | MS_NODEV | MS_ACTIVE |
5567                    MS_NOATIME | MS_NODIRATIME | MS_RELATIME| MS_KERNMOUNT);
5568  
5569 @@ -1950,9 +2020,9 @@ long do_mount(char *dev_name, char *dir_
5570  
5571         if (flags & MS_REMOUNT)
5572                 retval = do_remount(&path, flags & ~MS_REMOUNT, mnt_flags,
5573 -                                   data_page);
5574 +                                   data_page, tag);
5575         else if (flags & MS_BIND)
5576 -               retval = do_loopback(&path, dev_name, flags & MS_REC);
5577 +               retval = do_loopback(&path, dev_name, tag, flags, mnt_flags);
5578         else if (flags & (MS_SHARED | MS_PRIVATE | MS_SLAVE | MS_UNBINDABLE))
5579                 retval = do_change_type(&path, flags);
5580         else if (flags & MS_MOVE)
5581 @@ -2021,6 +2091,7 @@ static struct mnt_namespace *dup_mnt_ns(
5582                 q = next_mnt(q, new_ns->root);
5583         }
5584         up_write(&namespace_sem);
5585 +       atomic_inc(&vs_global_mnt_ns);
5586  
5587         if (rootmnt)
5588                 mntput(rootmnt);
5589 @@ -2207,9 +2278,10 @@ SYSCALL_DEFINE2(pivot_root, const char _
5590         down_write(&namespace_sem);
5591         mutex_lock(&old.dentry->d_inode->i_mutex);
5592         error = -EINVAL;
5593 -       if (IS_MNT_SHARED(old.mnt) ||
5594 +       if ((IS_MNT_SHARED(old.mnt) ||
5595                 IS_MNT_SHARED(new.mnt->mnt_parent) ||
5596 -               IS_MNT_SHARED(root.mnt->mnt_parent))
5597 +               IS_MNT_SHARED(root.mnt->mnt_parent)) &&
5598 +               !vx_flags(VXF_STATE_SETUP, 0))
5599                 goto out2;
5600         if (!check_mnt(root.mnt))
5601                 goto out2;
5602 @@ -2348,5 +2420,6 @@ void __put_mnt_ns(struct mnt_namespace *
5603         spin_unlock(&vfsmount_lock);
5604         up_write(&namespace_sem);
5605         release_mounts(&umount_list);
5606 +       atomic_dec(&vs_global_mnt_ns);
5607         kfree(ns);
5608  }
5609 diff -NurpP --minimal linux-2.6.29.1/fs/nfs/client.c linux-2.6.29.1-vs2.3.0.36.9-pre5/fs/nfs/client.c
5610 --- linux-2.6.29.1/fs/nfs/client.c      2009-03-24 14:22:26.000000000 +0100
5611 +++ linux-2.6.29.1-vs2.3.0.36.9-pre5/fs/nfs/client.c    2009-03-24 14:48:35.000000000 +0100
5612 @@ -696,6 +696,9 @@ static int nfs_init_server_rpcclient(str
5613         if (server->flags & NFS_MOUNT_SOFT)
5614                 server->client->cl_softrtry = 1;
5615  
5616 +       server->client->cl_tag = 0;
5617 +       if (server->flags & NFS_MOUNT_TAGGED)
5618 +               server->client->cl_tag = 1;
5619         return 0;
5620  }
5621  
5622 @@ -862,6 +865,10 @@ static void nfs_server_set_fsinfo(struct
5623                 server->acdirmin = server->acdirmax = 0;
5624         }
5625  
5626 +       /* FIXME: needs fsinfo
5627 +       if (server->flags & NFS_MOUNT_TAGGED)
5628 +               sb->s_flags |= MS_TAGGED;       */
5629 +
5630         server->maxfilesize = fsinfo->maxfilesize;
5631  
5632         /* We're airborne Set socket buffersize */
5633 diff -NurpP --minimal linux-2.6.29.1/fs/nfs/dir.c linux-2.6.29.1-vs2.3.0.36.9-pre5/fs/nfs/dir.c
5634 --- linux-2.6.29.1/fs/nfs/dir.c 2009-03-24 14:22:26.000000000 +0100
5635 +++ linux-2.6.29.1-vs2.3.0.36.9-pre5/fs/nfs/dir.c       2009-03-24 14:48:35.000000000 +0100
5636 @@ -34,6 +34,7 @@
5637  #include <linux/namei.h>
5638  #include <linux/mount.h>
5639  #include <linux/sched.h>
5640 +#include <linux/vs_tag.h>
5641  
5642  #include "nfs4_fs.h"
5643  #include "delegation.h"
5644 @@ -950,6 +951,7 @@ static struct dentry *nfs_lookup(struct 
5645         if (IS_ERR(res))
5646                 goto out_unblock_sillyrename;
5647  
5648 +       dx_propagate_tag(nd, inode);
5649  no_entry:
5650         res = d_materialise_unique(dentry, inode);
5651         if (res != NULL) {
5652 diff -NurpP --minimal linux-2.6.29.1/fs/nfs/inode.c linux-2.6.29.1-vs2.3.0.36.9-pre5/fs/nfs/inode.c
5653 --- linux-2.6.29.1/fs/nfs/inode.c       2009-03-24 14:22:26.000000000 +0100
5654 +++ linux-2.6.29.1-vs2.3.0.36.9-pre5/fs/nfs/inode.c     2009-03-24 14:48:35.000000000 +0100
5655 @@ -37,6 +37,7 @@
5656  #include <linux/vfs.h>
5657  #include <linux/inet.h>
5658  #include <linux/nfs_xdr.h>
5659 +#include <linux/vs_tag.h>
5660  
5661  #include <asm/system.h>
5662  #include <asm/uaccess.h>
5663 @@ -313,8 +314,10 @@ nfs_fhget(struct super_block *sb, struct
5664                         nfsi->change_attr = fattr->change_attr;
5665                 inode->i_size = nfs_size_to_loff_t(fattr->size);
5666                 inode->i_nlink = fattr->nlink;
5667 -               inode->i_uid = fattr->uid;
5668 -               inode->i_gid = fattr->gid;
5669 +               inode->i_uid = INOTAG_UID(DX_TAG(inode), fattr->uid, fattr->gid);
5670 +               inode->i_gid = INOTAG_GID(DX_TAG(inode), fattr->uid, fattr->gid);
5671 +               inode->i_tag = INOTAG_TAG(DX_TAG(inode), fattr->uid, fattr->gid, 0);
5672 +                                        /* maybe fattr->xid someday */
5673                 if (fattr->valid & (NFS_ATTR_FATTR_V3 | NFS_ATTR_FATTR_V4)) {
5674                         /*
5675                          * report the blocks in 512byte units
5676 @@ -462,6 +465,8 @@ void nfs_setattr_update_inode(struct ino
5677                         inode->i_uid = attr->ia_uid;
5678                 if ((attr->ia_valid & ATTR_GID) != 0)
5679                         inode->i_gid = attr->ia_gid;
5680 +               if ((attr->ia_valid & ATTR_TAG) && IS_TAGGED(inode))
5681 +                       inode->i_tag = attr->ia_tag;
5682                 NFS_I(inode)->cache_validity |= NFS_INO_INVALID_ACCESS|NFS_INO_INVALID_ACL;
5683                 spin_unlock(&inode->i_lock);
5684         }
5685 @@ -850,6 +855,9 @@ static int nfs_check_inode_attributes(st
5686         struct nfs_inode *nfsi = NFS_I(inode);
5687         loff_t cur_size, new_isize;
5688         unsigned long invalid = 0;
5689 +       uid_t uid;
5690 +       gid_t gid;
5691 +       tag_t tag;
5692  
5693  
5694         /* Has the inode gone and changed behind our back? */
5695 @@ -871,10 +879,15 @@ static int nfs_check_inode_attributes(st
5696         if (cur_size != new_isize && nfsi->npages == 0)
5697                 invalid |= NFS_INO_INVALID_ATTR|NFS_INO_REVAL_PAGECACHE;
5698  
5699 +       uid = INOTAG_UID(DX_TAG(inode), fattr->uid, fattr->gid);
5700 +       gid = INOTAG_GID(DX_TAG(inode), fattr->uid, fattr->gid);
5701 +       tag = INOTAG_TAG(DX_TAG(inode), fattr->uid, fattr->gid, 0);
5702 +
5703         /* Have any file permissions changed? */
5704         if ((inode->i_mode & S_IALLUGO) != (fattr->mode & S_IALLUGO)
5705 -                       || inode->i_uid != fattr->uid
5706 -                       || inode->i_gid != fattr->gid)
5707 +                       || inode->i_uid != uid
5708 +                       || inode->i_gid != gid
5709 +                       || inode->i_tag != tag)
5710                 invalid |= NFS_INO_INVALID_ATTR | NFS_INO_INVALID_ACCESS | NFS_INO_INVALID_ACL;
5711  
5712         /* Has the link count changed? */
5713 @@ -1073,6 +1086,9 @@ static int nfs_update_inode(struct inode
5714         loff_t cur_isize, new_isize;
5715         unsigned long invalid = 0;
5716         unsigned long now = jiffies;
5717 +       uid_t uid;
5718 +       gid_t gid;
5719 +       tag_t tag;
5720  
5721         dfprintk(VFS, "NFS: %s(%s/%ld ct=%d info=0x%x)\n",
5722                         __func__, inode->i_sb->s_id, inode->i_ino,
5723 @@ -1146,9 +1162,14 @@ static int nfs_update_inode(struct inode
5724         memcpy(&inode->i_atime, &fattr->atime, sizeof(inode->i_atime));
5725         nfsi->change_attr = fattr->change_attr;
5726  
5727 +       uid = INOTAG_UID(DX_TAG(inode), fattr->uid, fattr->gid);
5728 +       gid = INOTAG_GID(DX_TAG(inode), fattr->uid, fattr->gid);
5729 +       tag = INOTAG_TAG(DX_TAG(inode), fattr->uid, fattr->gid, 0);
5730 +
5731         if ((inode->i_mode & S_IALLUGO) != (fattr->mode & S_IALLUGO) ||
5732 -           inode->i_uid != fattr->uid ||
5733 -           inode->i_gid != fattr->gid)
5734 +           inode->i_uid != uid ||
5735 +           inode->i_gid != gid ||
5736 +           inode->i_tag != tag)
5737                 invalid |= NFS_INO_INVALID_ATTR|NFS_INO_INVALID_ACCESS|NFS_INO_INVALID_ACL;
5738  
5739         if (inode->i_nlink != fattr->nlink)
5740 @@ -1156,8 +1177,9 @@ static int nfs_update_inode(struct inode
5741  
5742         inode->i_mode = fattr->mode;
5743         inode->i_nlink = fattr->nlink;
5744 -       inode->i_uid = fattr->uid;
5745 -       inode->i_gid = fattr->gid;
5746 +       inode->i_uid = uid;
5747 +       inode->i_gid = gid;
5748 +       inode->i_tag = tag;
5749  
5750         if (fattr->valid & (NFS_ATTR_FATTR_V3 | NFS_ATTR_FATTR_V4)) {
5751                 /*
5752 diff -NurpP --minimal linux-2.6.29.1/fs/nfs/nfs3xdr.c linux-2.6.29.1-vs2.3.0.36.9-pre5/fs/nfs/nfs3xdr.c
5753 --- linux-2.6.29.1/fs/nfs/nfs3xdr.c     2009-03-24 14:22:26.000000000 +0100
5754 +++ linux-2.6.29.1-vs2.3.0.36.9-pre5/fs/nfs/nfs3xdr.c   2009-03-24 14:48:35.000000000 +0100
5755 @@ -22,6 +22,7 @@
5756  #include <linux/nfs3.h>
5757  #include <linux/nfs_fs.h>
5758  #include <linux/nfsacl.h>
5759 +#include <linux/vs_tag.h>
5760  #include "internal.h"
5761  
5762  #define NFSDBG_FACILITY                NFSDBG_XDR
5763 @@ -182,7 +183,7 @@ xdr_decode_fattr(__be32 *p, struct nfs_f
5764  }
5765  
5766  static inline __be32 *
5767 -xdr_encode_sattr(__be32 *p, struct iattr *attr)
5768 +xdr_encode_sattr(__be32 *p, struct iattr *attr, int tag)
5769  {
5770         if (attr->ia_valid & ATTR_MODE) {
5771                 *p++ = xdr_one;
5772 @@ -190,15 +191,17 @@ xdr_encode_sattr(__be32 *p, struct iattr
5773         } else {
5774                 *p++ = xdr_zero;
5775         }
5776 -       if (attr->ia_valid & ATTR_UID) {
5777 +       if (attr->ia_valid & ATTR_UID ||
5778 +               (tag && (attr->ia_valid & ATTR_TAG))) {
5779                 *p++ = xdr_one;
5780 -               *p++ = htonl(attr->ia_uid);
5781 +               *p++ = htonl(TAGINO_UID(tag, attr->ia_uid, attr->ia_tag));
5782         } else {
5783                 *p++ = xdr_zero;
5784         }
5785 -       if (attr->ia_valid & ATTR_GID) {
5786 +       if (attr->ia_valid & ATTR_GID ||
5787 +               (tag && (attr->ia_valid & ATTR_TAG))) {
5788                 *p++ = xdr_one;
5789 -               *p++ = htonl(attr->ia_gid);
5790 +               *p++ = htonl(TAGINO_GID(tag, attr->ia_gid, attr->ia_tag));
5791         } else {
5792                 *p++ = xdr_zero;
5793         }
5794 @@ -283,7 +286,8 @@ static int
5795  nfs3_xdr_sattrargs(struct rpc_rqst *req, __be32 *p, struct nfs3_sattrargs *args)
5796  {
5797         p = xdr_encode_fhandle(p, args->fh);
5798 -       p = xdr_encode_sattr(p, args->sattr);
5799 +       p = xdr_encode_sattr(p, args->sattr,
5800 +               req->rq_task->tk_client->cl_tag);
5801         *p++ = htonl(args->guard);
5802         if (args->guard)
5803                 p = xdr_encode_time3(p, &args->guardtime);
5804 @@ -388,7 +392,8 @@ nfs3_xdr_createargs(struct rpc_rqst *req
5805                 *p++ = args->verifier[0];
5806                 *p++ = args->verifier[1];
5807         } else
5808 -               p = xdr_encode_sattr(p, args->sattr);
5809 +               p = xdr_encode_sattr(p, args->sattr,
5810 +                       req->rq_task->tk_client->cl_tag);
5811  
5812         req->rq_slen = xdr_adjust_iovec(req->rq_svec, p);
5813         return 0;
5814 @@ -402,7 +407,8 @@ nfs3_xdr_mkdirargs(struct rpc_rqst *req,
5815  {
5816         p = xdr_encode_fhandle(p, args->fh);
5817         p = xdr_encode_array(p, args->name, args->len);
5818 -       p = xdr_encode_sattr(p, args->sattr);
5819 +       p = xdr_encode_sattr(p, args->sattr,
5820 +               req->rq_task->tk_client->cl_tag);
5821         req->rq_slen = xdr_adjust_iovec(req->rq_svec, p);
5822         return 0;
5823  }
5824 @@ -415,7 +421,8 @@ nfs3_xdr_symlinkargs(struct rpc_rqst *re
5825  {
5826         p = xdr_encode_fhandle(p, args->fromfh);
5827         p = xdr_encode_array(p, args->fromname, args->fromlen);
5828 -       p = xdr_encode_sattr(p, args->sattr);
5829 +       p = xdr_encode_sattr(p, args->sattr,
5830 +               req->rq_task->tk_client->cl_tag);
5831         *p++ = htonl(args->pathlen);
5832         req->rq_slen = xdr_adjust_iovec(req->rq_svec, p);
5833  
5834 @@ -433,7 +440,8 @@ nfs3_xdr_mknodargs(struct rpc_rqst *req,
5835         p = xdr_encode_fhandle(p, args->fh);
5836         p = xdr_encode_array(p, args->name, args->len);
5837         *p++ = htonl(args->type);
5838 -       p = xdr_encode_sattr(p, args->sattr);
5839 +       p = xdr_encode_sattr(p, args->sattr,
5840 +               req->rq_task->tk_client->cl_tag);
5841         if (args->type == NF3CHR || args->type == NF3BLK) {
5842                 *p++ = htonl(MAJOR(args->rdev));
5843                 *p++ = htonl(MINOR(args->rdev));
5844 diff -NurpP --minimal linux-2.6.29.1/fs/nfs/nfsroot.c linux-2.6.29.1-vs2.3.0.36.9-pre5/fs/nfs/nfsroot.c
5845 --- linux-2.6.29.1/fs/nfs/nfsroot.c     2009-03-24 14:22:26.000000000 +0100
5846 +++ linux-2.6.29.1-vs2.3.0.36.9-pre5/fs/nfs/nfsroot.c   2009-03-24 14:48:35.000000000 +0100
5847 @@ -119,12 +119,12 @@ static int mount_port __initdata = 0;             /
5848  enum {
5849         /* Options that take integer arguments */
5850         Opt_port, Opt_rsize, Opt_wsize, Opt_timeo, Opt_retrans, Opt_acregmin,
5851 -       Opt_acregmax, Opt_acdirmin, Opt_acdirmax,
5852 +       Opt_acregmax, Opt_acdirmin, Opt_acdirmax, Opt_tagid,
5853         /* Options that take no arguments */
5854         Opt_soft, Opt_hard, Opt_intr,
5855         Opt_nointr, Opt_posix, Opt_noposix, Opt_cto, Opt_nocto, Opt_ac, 
5856         Opt_noac, Opt_lock, Opt_nolock, Opt_v2, Opt_v3, Opt_udp, Opt_tcp,
5857 -       Opt_acl, Opt_noacl,
5858 +       Opt_acl, Opt_noacl, Opt_tag, Opt_notag,
5859         /* Error token */
5860         Opt_err
5861  };
5862 @@ -161,6 +161,9 @@ static match_table_t __initconst tokens 
5863         {Opt_tcp, "tcp"},
5864         {Opt_acl, "acl"},
5865         {Opt_noacl, "noacl"},
5866 +       {Opt_tag, "tag"},
5867 +       {Opt_notag, "notag"},
5868 +       {Opt_tagid, "tagid=%u"},
5869         {Opt_err, NULL}
5870         
5871  };
5872 @@ -272,6 +275,20 @@ static int __init root_nfs_parse(char *n
5873                         case Opt_noacl:
5874                                 nfs_data.flags |= NFS_MOUNT_NOACL;
5875                                 break;
5876 +#ifndef CONFIG_TAGGING_NONE
5877 +                       case Opt_tag:
5878 +                               nfs_data.flags |= NFS_MOUNT_TAGGED;
5879 +                               break;
5880 +                       case Opt_notag:
5881 +                               nfs_data.flags &= ~NFS_MOUNT_TAGGED;
5882 +                               break;
5883 +#endif
5884 +#ifdef CONFIG_PROPAGATE
5885 +                       case Opt_tagid:
5886 +                               /* use args[0] */
5887 +                               nfs_data.flags |= NFS_MOUNT_TAGGED;
5888 +                               break;
5889 +#endif
5890                         default:
5891                                 printk(KERN_WARNING "Root-NFS: unknown "
5892                                         "option: %s\n", p);
5893 diff -NurpP --minimal linux-2.6.29.1/fs/nfs/super.c linux-2.6.29.1-vs2.3.0.36.9-pre5/fs/nfs/super.c
5894 --- linux-2.6.29.1/fs/nfs/super.c       2009-03-24 14:22:26.000000000 +0100
5895 +++ linux-2.6.29.1-vs2.3.0.36.9-pre5/fs/nfs/super.c     2009-03-24 16:02:06.000000000 +0100
5896 @@ -51,6 +51,7 @@
5897  #include <linux/nfs_xdr.h>
5898  #include <linux/magic.h>
5899  #include <linux/parser.h>
5900 +#include <linux/vs_tag.h>
5901  
5902  #include <asm/system.h>
5903  #include <asm/uaccess.h>
5904 @@ -517,6 +518,7 @@ static void nfs_show_mount_options(struc
5905                 { NFS_MOUNT_NORDIRPLUS, ",nordirplus", "" },
5906                 { NFS_MOUNT_UNSHARED, ",nosharecache", "" },
5907                 { NFS_MOUNT_NORESVPORT, ",noresvport", "" },
5908 +               { NFS_MOUNT_TAGGED, ",tag", "" },
5909                 { 0, NULL, NULL }
5910         };
5911         const struct proc_nfs_info *nfs_infop;
5912 diff -NurpP --minimal linux-2.6.29.1/fs/nfsd/auth.c linux-2.6.29.1-vs2.3.0.36.9-pre5/fs/nfsd/auth.c
5913 --- linux-2.6.29.1/fs/nfsd/auth.c       2009-03-24 14:22:26.000000000 +0100
5914 +++ linux-2.6.29.1-vs2.3.0.36.9-pre5/fs/nfsd/auth.c     2009-03-24 16:09:39.000000000 +0100
5915 @@ -10,6 +10,7 @@
5916  #include <linux/sunrpc/svcauth.h>
5917  #include <linux/nfsd/nfsd.h>
5918  #include <linux/nfsd/export.h>
5919 +#include <linux/vs_tag.h>
5920  #include "auth.h"
5921  
5922  int nfsexp_flags(struct svc_rqst *rqstp, struct svc_export *exp)
5923 @@ -42,6 +43,9 @@ int nfsd_setuser(struct svc_rqst *rqstp,
5924  
5925         new->fsuid = rqstp->rq_cred.cr_uid;
5926         new->fsgid = rqstp->rq_cred.cr_gid;
5927 +       /* FIXME: this desperately needs a tag :)
5928 +       new->xid = (xid_t)INOTAG_TAG(DX_TAG_NFSD, cred.cr_uid, cred.cr_gid, 0);
5929 +                       */
5930  
5931         rqgi = rqstp->rq_cred.cr_group_info;
5932  
5933 @@ -69,7 +73,7 @@ int nfsd_setuser(struct svc_rqst *rqstp,
5934                 }
5935         } else {
5936                 gi = get_group_info(rqgi);
5937 -       }
5938 +       }
5939  
5940         if (new->fsuid == (uid_t) -1)
5941                 new->fsuid = exp->ex_anon_uid;
5942 @@ -94,6 +98,6 @@ oom:
5943         ret = -ENOMEM;
5944  error:
5945         abort_creds(new);
5946 -       return ret;
5947 +       return ret;
5948  }
5949  
5950 diff -NurpP --minimal linux-2.6.29.1/fs/nfsd/nfs3xdr.c linux-2.6.29.1-vs2.3.0.36.9-pre5/fs/nfsd/nfs3xdr.c
5951 --- linux-2.6.29.1/fs/nfsd/nfs3xdr.c    2008-12-25 00:26:37.000000000 +0100
5952 +++ linux-2.6.29.1-vs2.3.0.36.9-pre5/fs/nfsd/nfs3xdr.c  2009-02-22 22:54:25.000000000 +0100
5953 @@ -21,6 +21,7 @@
5954  #include <linux/sunrpc/svc.h>
5955  #include <linux/nfsd/nfsd.h>
5956  #include <linux/nfsd/xdr3.h>
5957 +#include <linux/vs_tag.h>
5958  #include "auth.h"
5959  
5960  #define NFSDDBG_FACILITY               NFSDDBG_XDR
5961 @@ -108,6 +109,8 @@ static __be32 *
5962  decode_sattr3(__be32 *p, struct iattr *iap)
5963  {
5964         u32     tmp;
5965 +       uid_t   uid = 0;
5966 +       gid_t   gid = 0;
5967  
5968         iap->ia_valid = 0;
5969  
5970 @@ -117,12 +120,15 @@ decode_sattr3(__be32 *p, struct iattr *i
5971         }
5972         if (*p++) {
5973                 iap->ia_valid |= ATTR_UID;
5974 -               iap->ia_uid = ntohl(*p++);
5975 +               uid = ntohl(*p++);
5976         }
5977         if (*p++) {
5978                 iap->ia_valid |= ATTR_GID;
5979 -               iap->ia_gid = ntohl(*p++);
5980 +               gid = ntohl(*p++);
5981         }
5982 +       iap->ia_uid = INOTAG_UID(DX_TAG_NFSD, uid, gid);
5983 +       iap->ia_gid = INOTAG_GID(DX_TAG_NFSD, uid, gid);
5984 +       iap->ia_tag = INOTAG_TAG(DX_TAG_NFSD, uid, gid, 0);
5985         if (*p++) {
5986                 u64     newsize;
5987  
5988 @@ -178,8 +184,12 @@ encode_fattr3(struct svc_rqst *rqstp, __
5989         *p++ = htonl(nfs3_ftypes[(stat->mode & S_IFMT) >> 12]);
5990         *p++ = htonl((u32) stat->mode);
5991         *p++ = htonl((u32) stat->nlink);
5992 -       *p++ = htonl((u32) nfsd_ruid(rqstp, stat->uid));
5993 -       *p++ = htonl((u32) nfsd_rgid(rqstp, stat->gid));
5994 +       *p++ = htonl((u32) nfsd_ruid(rqstp,
5995 +               TAGINO_UID(0 /* FIXME: DX_TAG(dentry->d_inode) */,
5996 +               stat->uid, stat->tag)));
5997 +       *p++ = htonl((u32) nfsd_rgid(rqstp,
5998 +               TAGINO_GID(0 /* FIXME: DX_TAG(dentry->d_inode) */,
5999 +               stat->gid, stat->tag)));
6000         if (S_ISLNK(stat->mode) && stat->size > NFS3_MAXPATHLEN) {
6001                 p = xdr_encode_hyper(p, (u64) NFS3_MAXPATHLEN);
6002         } else {
6003 diff -NurpP --minimal linux-2.6.29.1/fs/nfsd/nfs4xdr.c linux-2.6.29.1-vs2.3.0.36.9-pre5/fs/nfsd/nfs4xdr.c
6004 --- linux-2.6.29.1/fs/nfsd/nfs4xdr.c    2009-03-24 14:22:26.000000000 +0100
6005 +++ linux-2.6.29.1-vs2.3.0.36.9-pre5/fs/nfsd/nfs4xdr.c  2009-03-24 14:48:35.000000000 +0100
6006 @@ -56,6 +56,7 @@
6007  #include <linux/nfs4_acl.h>
6008  #include <linux/sunrpc/gss_api.h>
6009  #include <linux/sunrpc/svcauth_gss.h>
6010 +#include <linux/vs_tag.h>
6011  
6012  #define NFSDDBG_FACILITY               NFSDDBG_XDR
6013  
6014 @@ -1714,14 +1715,18 @@ out_acl:
6015                 WRITE32(stat.nlink);
6016         }
6017         if (bmval1 & FATTR4_WORD1_OWNER) {
6018 -               status = nfsd4_encode_user(rqstp, stat.uid, &p, &buflen);
6019 +               status = nfsd4_encode_user(rqstp,
6020 +                       TAGINO_UID(DX_TAG(dentry->d_inode),
6021 +                       stat.uid, stat.tag), &p, &buflen);
6022                 if (status == nfserr_resource)
6023                         goto out_resource;
6024                 if (status)
6025                         goto out;
6026         }
6027         if (bmval1 & FATTR4_WORD1_OWNER_GROUP) {
6028 -               status = nfsd4_encode_group(rqstp, stat.gid, &p, &buflen);
6029 +               status = nfsd4_encode_group(rqstp,
6030 +                       TAGINO_GID(DX_TAG(dentry->d_inode),
6031 +                       stat.gid, stat.tag), &p, &buflen);
6032                 if (status == nfserr_resource)
6033                         goto out_resource;
6034                 if (status)
6035 diff -NurpP --minimal linux-2.6.29.1/fs/nfsd/nfsxdr.c linux-2.6.29.1-vs2.3.0.36.9-pre5/fs/nfsd/nfsxdr.c
6036 --- linux-2.6.29.1/fs/nfsd/nfsxdr.c     2008-12-25 00:26:37.000000000 +0100
6037 +++ linux-2.6.29.1-vs2.3.0.36.9-pre5/fs/nfsd/nfsxdr.c   2009-02-22 22:54:25.000000000 +0100
6038 @@ -15,6 +15,7 @@
6039  #include <linux/nfsd/nfsd.h>
6040  #include <linux/nfsd/xdr.h>
6041  #include <linux/mm.h>
6042 +#include <linux/vs_tag.h>
6043  #include "auth.h"
6044  
6045  #define NFSDDBG_FACILITY               NFSDDBG_XDR
6046 @@ -98,6 +99,8 @@ static __be32 *
6047  decode_sattr(__be32 *p, struct iattr *iap)
6048  {
6049         u32     tmp, tmp1;
6050 +       uid_t   uid = 0;
6051 +       gid_t   gid = 0;
6052  
6053         iap->ia_valid = 0;
6054  
6055 @@ -111,12 +114,15 @@ decode_sattr(__be32 *p, struct iattr *ia
6056         }
6057         if ((tmp = ntohl(*p++)) != (u32)-1) {
6058                 iap->ia_valid |= ATTR_UID;
6059 -               iap->ia_uid = tmp;
6060 +               uid = tmp;
6061         }
6062         if ((tmp = ntohl(*p++)) != (u32)-1) {
6063                 iap->ia_valid |= ATTR_GID;
6064 -               iap->ia_gid = tmp;
6065 +               gid = tmp;
6066         }
6067 +       iap->ia_uid = INOTAG_UID(DX_TAG_NFSD, uid, gid);
6068 +       iap->ia_gid = INOTAG_GID(DX_TAG_NFSD, uid, gid);
6069 +       iap->ia_tag = INOTAG_TAG(DX_TAG_NFSD, uid, gid, 0);
6070         if ((tmp = ntohl(*p++)) != (u32)-1) {
6071                 iap->ia_valid |= ATTR_SIZE;
6072                 iap->ia_size = tmp;
6073 @@ -161,8 +167,10 @@ encode_fattr(struct svc_rqst *rqstp, __b
6074         *p++ = htonl(nfs_ftypes[type >> 12]);
6075         *p++ = htonl((u32) stat->mode);
6076         *p++ = htonl((u32) stat->nlink);
6077 -       *p++ = htonl((u32) nfsd_ruid(rqstp, stat->uid));
6078 -       *p++ = htonl((u32) nfsd_rgid(rqstp, stat->gid));
6079 +       *p++ = htonl((u32) nfsd_ruid(rqstp,
6080 +               TAGINO_UID(DX_TAG(dentry->d_inode), stat->uid, stat->tag)));
6081 +       *p++ = htonl((u32) nfsd_rgid(rqstp,
6082 +               TAGINO_GID(DX_TAG(dentry->d_inode), stat->gid, stat->tag)));
6083  
6084         if (S_ISLNK(type) && stat->size > NFS_MAXPATHLEN) {
6085                 *p++ = htonl(NFS_MAXPATHLEN);
6086 diff -NurpP --minimal linux-2.6.29.1/fs/ocfs2/dlm/dlmfs.c linux-2.6.29.1-vs2.3.0.36.9-pre5/fs/ocfs2/dlm/dlmfs.c
6087 --- linux-2.6.29.1/fs/ocfs2/dlm/dlmfs.c 2009-03-24 14:22:27.000000000 +0100
6088 +++ linux-2.6.29.1-vs2.3.0.36.9-pre5/fs/ocfs2/dlm/dlmfs.c       2009-03-24 16:10:48.000000000 +0100
6089 @@ -43,6 +43,7 @@
6090  #include <linux/init.h>
6091  #include <linux/string.h>
6092  #include <linux/backing-dev.h>
6093 +#include <linux/vs_tag.h>
6094  
6095  #include <asm/uaccess.h>
6096  
6097 @@ -341,6 +342,7 @@ static struct inode *dlmfs_get_root_inod
6098                 inode->i_mode = mode;
6099                 inode->i_uid = current_fsuid();
6100                 inode->i_gid = current_fsgid();
6101 +               inode->i_tag = dx_current_fstag(sb);
6102                 inode->i_mapping->backing_dev_info = &dlmfs_backing_dev_info;
6103                 inode->i_atime = inode->i_mtime = inode->i_ctime = CURRENT_TIME;
6104                 inc_nlink(inode);
6105 @@ -366,6 +368,7 @@ static struct inode *dlmfs_get_inode(str
6106         inode->i_mode = mode;
6107         inode->i_uid = current_fsuid();
6108         inode->i_gid = current_fsgid();
6109 +       inode->i_tag = dx_current_fstag(sb);
6110         inode->i_mapping->backing_dev_info = &dlmfs_backing_dev_info;
6111         inode->i_atime = inode->i_mtime = inode->i_ctime = CURRENT_TIME;
6112  
6113 diff -NurpP --minimal linux-2.6.29.1/fs/ocfs2/dlmglue.c linux-2.6.29.1-vs2.3.0.36.9-pre5/fs/ocfs2/dlmglue.c
6114 --- linux-2.6.29.1/fs/ocfs2/dlmglue.c   2009-03-24 14:22:27.000000000 +0100
6115 +++ linux-2.6.29.1-vs2.3.0.36.9-pre5/fs/ocfs2/dlmglue.c 2009-03-24 14:48:35.000000000 +0100
6116 @@ -1885,6 +1885,7 @@ static void __ocfs2_stuff_meta_lvb(struc
6117         lvb->lvb_iclusters = cpu_to_be32(oi->ip_clusters);
6118         lvb->lvb_iuid      = cpu_to_be32(inode->i_uid);
6119         lvb->lvb_igid      = cpu_to_be32(inode->i_gid);
6120 +       lvb->lvb_itag      = cpu_to_be16(inode->i_tag);
6121         lvb->lvb_imode     = cpu_to_be16(inode->i_mode);
6122         lvb->lvb_inlink    = cpu_to_be16(inode->i_nlink);
6123         lvb->lvb_iatime_packed  =
6124 @@ -1939,6 +1940,7 @@ static void ocfs2_refresh_inode_from_lvb
6125  
6126         inode->i_uid     = be32_to_cpu(lvb->lvb_iuid);
6127         inode->i_gid     = be32_to_cpu(lvb->lvb_igid);
6128 +       inode->i_tag     = be16_to_cpu(lvb->lvb_itag);
6129         inode->i_mode    = be16_to_cpu(lvb->lvb_imode);
6130         inode->i_nlink   = be16_to_cpu(lvb->lvb_inlink);
6131         ocfs2_unpack_timespec(&inode->i_atime,
6132 diff -NurpP --minimal linux-2.6.29.1/fs/ocfs2/dlmglue.h linux-2.6.29.1-vs2.3.0.36.9-pre5/fs/ocfs2/dlmglue.h
6133 --- linux-2.6.29.1/fs/ocfs2/dlmglue.h   2009-03-24 14:22:27.000000000 +0100
6134 +++ linux-2.6.29.1-vs2.3.0.36.9-pre5/fs/ocfs2/dlmglue.h 2009-03-24 14:48:35.000000000 +0100
6135 @@ -46,7 +46,8 @@ struct ocfs2_meta_lvb {
6136         __be16       lvb_inlink;
6137         __be32       lvb_iattr;
6138         __be32       lvb_igeneration;
6139 -       __be32       lvb_reserved2;
6140 +       __be16       lvb_itag;
6141 +       __be16       lvb_reserved2;
6142  };
6143  
6144  #define OCFS2_QINFO_LVB_VERSION 1
6145 diff -NurpP --minimal linux-2.6.29.1/fs/ocfs2/file.c linux-2.6.29.1-vs2.3.0.36.9-pre5/fs/ocfs2/file.c
6146 --- linux-2.6.29.1/fs/ocfs2/file.c      2009-03-24 14:22:27.000000000 +0100
6147 +++ linux-2.6.29.1-vs2.3.0.36.9-pre5/fs/ocfs2/file.c    2009-03-24 14:48:35.000000000 +0100
6148 @@ -911,13 +911,15 @@ int ocfs2_setattr(struct dentry *dentry,
6149                 mlog(0, "uid change: %d\n", attr->ia_uid);
6150         if (attr->ia_valid & ATTR_GID)
6151                 mlog(0, "gid change: %d\n", attr->ia_gid);
6152 +       if (attr->ia_valid & ATTR_TAG)
6153 +               mlog(0, "tag change: %d\n", attr->ia_tag);
6154         if (attr->ia_valid & ATTR_SIZE)
6155                 mlog(0, "size change...\n");
6156         if (attr->ia_valid & (ATTR_ATIME | ATTR_MTIME | ATTR_CTIME))
6157                 mlog(0, "time change...\n");
6158  
6159  #define OCFS2_VALID_ATTRS (ATTR_ATIME | ATTR_MTIME | ATTR_CTIME | ATTR_SIZE \
6160 -                          | ATTR_GID | ATTR_UID | ATTR_MODE)
6161 +                          | ATTR_GID | ATTR_UID | ATTR_TAG | ATTR_MODE)
6162         if (!(attr->ia_valid & OCFS2_VALID_ATTRS)) {
6163                 mlog(0, "can't handle attrs: 0x%x\n", attr->ia_valid);
6164                 return 0;
6165 @@ -2070,6 +2072,7 @@ const struct inode_operations ocfs2_file
6166         .removexattr    = generic_removexattr,
6167         .fallocate      = ocfs2_fallocate,
6168         .fiemap         = ocfs2_fiemap,
6169 +       .sync_flags     = ocfs2_sync_flags,
6170  };
6171  
6172  const struct inode_operations ocfs2_special_file_iops = {
6173 diff -NurpP --minimal linux-2.6.29.1/fs/ocfs2/inode.c linux-2.6.29.1-vs2.3.0.36.9-pre5/fs/ocfs2/inode.c
6174 --- linux-2.6.29.1/fs/ocfs2/inode.c     2009-03-24 14:22:27.000000000 +0100
6175 +++ linux-2.6.29.1-vs2.3.0.36.9-pre5/fs/ocfs2/inode.c   2009-03-24 16:11:11.000000000 +0100
6176 @@ -29,6 +29,7 @@
6177  #include <linux/highmem.h>
6178  #include <linux/pagemap.h>
6179  #include <linux/quotaops.h>
6180 +#include <linux/vs_tag.h>
6181  
6182  #include <asm/byteorder.h>
6183  
6184 @@ -44,6 +45,7 @@
6185  #include "file.h"
6186  #include "heartbeat.h"
6187  #include "inode.h"
6188 +#include "ioctl.h"
6189  #include "journal.h"
6190  #include "namei.h"
6191  #include "suballoc.h"
6192 @@ -77,11 +79,13 @@ void ocfs2_set_inode_flags(struct inode 
6193  {
6194         unsigned int flags = OCFS2_I(inode)->ip_attr;
6195  
6196 -       inode->i_flags &= ~(S_IMMUTABLE |
6197 +       inode->i_flags &= ~(S_IMMUTABLE | S_IXUNLINK |
6198                 S_SYNC | S_APPEND | S_NOATIME | S_DIRSYNC);
6199  
6200         if (flags & OCFS2_IMMUTABLE_FL)
6201                 inode->i_flags |= S_IMMUTABLE;
6202 +       if (flags & OCFS2_IXUNLINK_FL)
6203 +               inode->i_flags |= S_IXUNLINK;
6204  
6205         if (flags & OCFS2_SYNC_FL)
6206                 inode->i_flags |= S_SYNC;
6207 @@ -91,25 +95,85 @@ void ocfs2_set_inode_flags(struct inode 
6208                 inode->i_flags |= S_NOATIME;
6209         if (flags & OCFS2_DIRSYNC_FL)
6210                 inode->i_flags |= S_DIRSYNC;
6211 +
6212 +       inode->i_vflags &= ~(V_BARRIER | V_COW);
6213 +
6214 +       if (flags & OCFS2_BARRIER_FL)
6215 +               inode->i_vflags |= V_BARRIER;
6216 +       if (flags & OCFS2_COW_FL)
6217 +               inode->i_vflags |= V_COW;
6218  }
6219  
6220  /* Propagate flags from i_flags to OCFS2_I(inode)->ip_attr */
6221  void ocfs2_get_inode_flags(struct ocfs2_inode_info *oi)
6222  {
6223         unsigned int flags = oi->vfs_inode.i_flags;
6224 +       unsigned int vflags = oi->vfs_inode.i_vflags;
6225 +
6226 +       oi->ip_attr &= ~(OCFS2_SYNC_FL | OCFS2_APPEND_FL |
6227 +                       OCFS2_IMMUTABLE_FL | OCFS2_IXUNLINK_FL |
6228 +                       OCFS2_NOATIME_FL | OCFS2_DIRSYNC_FL |
6229 +                       OCFS2_BARRIER_FL | OCFS2_COW_FL);
6230 +
6231 +       if (flags & S_IMMUTABLE)
6232 +               oi->ip_attr |= OCFS2_IMMUTABLE_FL;
6233 +       if (flags & S_IXUNLINK)
6234 +               oi->ip_attr |= OCFS2_IXUNLINK_FL;
6235  
6236 -       oi->ip_attr &= ~(OCFS2_SYNC_FL|OCFS2_APPEND_FL|
6237 -                       OCFS2_IMMUTABLE_FL|OCFS2_NOATIME_FL|OCFS2_DIRSYNC_FL);
6238         if (flags & S_SYNC)
6239                 oi->ip_attr |= OCFS2_SYNC_FL;
6240         if (flags & S_APPEND)
6241                 oi->ip_attr |= OCFS2_APPEND_FL;
6242 -       if (flags & S_IMMUTABLE)
6243 -               oi->ip_attr |= OCFS2_IMMUTABLE_FL;
6244         if (flags & S_NOATIME)
6245                 oi->ip_attr |= OCFS2_NOATIME_FL;
6246         if (flags & S_DIRSYNC)
6247                 oi->ip_attr |= OCFS2_DIRSYNC_FL;
6248 +
6249 +       if (vflags & V_BARRIER)
6250 +               oi->ip_attr |= OCFS2_BARRIER_FL;
6251 +       if (vflags & V_COW)
6252 +               oi->ip_attr |= OCFS2_COW_FL;
6253 +}
6254 +
6255 +int ocfs2_sync_flags(struct inode *inode)
6256 +{
6257 +       struct ocfs2_inode_info *ocfs2_inode = OCFS2_I(inode);
6258 +       struct ocfs2_super *osb = OCFS2_SB(inode->i_sb);
6259 +       handle_t *handle = NULL;
6260 +       struct buffer_head *bh = NULL;
6261 +       int status;
6262 +
6263 +       status = ocfs2_inode_lock(inode, &bh, 1);
6264 +       if (status < 0) {
6265 +               mlog_errno(status);
6266 +               goto bail;
6267 +       }
6268 +
6269 +       status = -EROFS;
6270 +       if (IS_RDONLY(inode))
6271 +               goto bail_unlock;
6272 +
6273 +       handle = ocfs2_start_trans(osb, OCFS2_INODE_UPDATE_CREDITS);
6274 +       if (IS_ERR(handle)) {
6275 +               status = PTR_ERR(handle);
6276 +               mlog_errno(status);
6277 +               goto bail_unlock;
6278 +       }
6279 +
6280 +       ocfs2_get_inode_flags(ocfs2_inode);
6281 +       status = ocfs2_mark_inode_dirty(handle, inode, bh);
6282 +       if (status < 0)
6283 +               mlog_errno(status);
6284 +
6285 +       ocfs2_commit_trans(osb, handle);
6286 +bail_unlock:
6287 +       ocfs2_inode_unlock(inode, 1);
6288 +bail:
6289 +       if (bh)
6290 +               brelse(bh);
6291 +
6292 +       mlog_exit(status);
6293 +       return status;
6294  }
6295  
6296  struct inode *ocfs2_iget(struct ocfs2_super *osb, u64 blkno, unsigned flags,
6297 @@ -222,6 +286,8 @@ void ocfs2_populate_inode(struct inode *
6298         struct super_block *sb;
6299         struct ocfs2_super *osb;
6300         int use_plocks = 1;
6301 +       uid_t uid;
6302 +       gid_t gid;
6303  
6304         mlog_entry("(0x%p, size:%llu)\n", inode,
6305                    (unsigned long long)le64_to_cpu(fe->i_size));
6306 @@ -253,8 +319,12 @@ void ocfs2_populate_inode(struct inode *
6307         inode->i_generation = le32_to_cpu(fe->i_generation);
6308         inode->i_rdev = huge_decode_dev(le64_to_cpu(fe->id1.dev1.i_rdev));
6309         inode->i_mode = le16_to_cpu(fe->i_mode);
6310 -       inode->i_uid = le32_to_cpu(fe->i_uid);
6311 -       inode->i_gid = le32_to_cpu(fe->i_gid);
6312 +       uid = le32_to_cpu(fe->i_uid);
6313 +       gid = le32_to_cpu(fe->i_gid);
6314 +       inode->i_uid = INOTAG_UID(DX_TAG(inode), uid, gid);
6315 +       inode->i_gid = INOTAG_GID(DX_TAG(inode), uid, gid);
6316 +       inode->i_tag = INOTAG_TAG(DX_TAG(inode), uid, gid,
6317 +               /* le16_to_cpu(raw_inode->i_raw_tag)i */ 0);
6318  
6319         /* Fast symlinks will have i_size but no allocated clusters. */
6320         if (S_ISLNK(inode->i_mode) && !fe->i_clusters)
6321 @@ -1206,8 +1276,11 @@ int ocfs2_mark_inode_dirty(handle_t *han
6322  
6323         fe->i_size = cpu_to_le64(i_size_read(inode));
6324         fe->i_links_count = cpu_to_le16(inode->i_nlink);
6325 -       fe->i_uid = cpu_to_le32(inode->i_uid);
6326 -       fe->i_gid = cpu_to_le32(inode->i_gid);
6327 +       fe->i_uid = cpu_to_le32(TAGINO_UID(DX_TAG(inode),
6328 +               inode->i_uid, inode->i_tag));
6329 +       fe->i_gid = cpu_to_le32(TAGINO_GID(DX_TAG(inode),
6330 +               inode->i_gid, inode->i_tag));
6331 +       /* i_tag = = cpu_to_le16(inode->i_tag); */
6332         fe->i_mode = cpu_to_le16(inode->i_mode);
6333         fe->i_atime = cpu_to_le64(inode->i_atime.tv_sec);
6334         fe->i_atime_nsec = cpu_to_le32(inode->i_atime.tv_nsec);
6335 @@ -1235,16 +1308,25 @@ leave:
6336  void ocfs2_refresh_inode(struct inode *inode,
6337                          struct ocfs2_dinode *fe)
6338  {
6339 +       uid_t uid;
6340 +       gid_t gid;
6341 +
6342         spin_lock(&OCFS2_I(inode)->ip_lock);
6343  
6344         OCFS2_I(inode)->ip_clusters = le32_to_cpu(fe->i_clusters);
6345         OCFS2_I(inode)->ip_attr = le32_to_cpu(fe->i_attr);
6346 +       /* OCFS2_I(inode)->ip_flags &= ~OCFS2_FL_MASK;
6347 +          OCFS2_I(inode)->ip_flags |= le32_to_cpu(fe->i_flags) & OCFS2_FL_MASK; */
6348         OCFS2_I(inode)->ip_dyn_features = le16_to_cpu(fe->i_dyn_features);
6349         ocfs2_set_inode_flags(inode);
6350         i_size_write(inode, le64_to_cpu(fe->i_size));
6351         inode->i_nlink = le16_to_cpu(fe->i_links_count);
6352 -       inode->i_uid = le32_to_cpu(fe->i_uid);
6353 -       inode->i_gid = le32_to_cpu(fe->i_gid);
6354 +       uid = le32_to_cpu(fe->i_uid);
6355 +       gid = le32_to_cpu(fe->i_gid);
6356 +       inode->i_uid = INOTAG_UID(DX_TAG(inode), uid, gid);
6357 +       inode->i_gid = INOTAG_GID(DX_TAG(inode), uid, gid);
6358 +       inode->i_tag = INOTAG_TAG(DX_TAG(inode), uid, gid,
6359 +               /* le16_to_cpu(raw_inode->i_raw_tag)i */ 0);
6360         inode->i_mode = le16_to_cpu(fe->i_mode);
6361         if (S_ISLNK(inode->i_mode) && le32_to_cpu(fe->i_clusters) == 0)
6362                 inode->i_blocks = 0;
6363 diff -NurpP --minimal linux-2.6.29.1/fs/ocfs2/inode.h linux-2.6.29.1-vs2.3.0.36.9-pre5/fs/ocfs2/inode.h
6364 --- linux-2.6.29.1/fs/ocfs2/inode.h     2009-03-24 14:22:27.000000000 +0100
6365 +++ linux-2.6.29.1-vs2.3.0.36.9-pre5/fs/ocfs2/inode.h   2009-03-24 14:48:35.000000000 +0100
6366 @@ -147,6 +147,7 @@ struct buffer_head *ocfs2_bread(struct i
6367  
6368  void ocfs2_set_inode_flags(struct inode *inode);
6369  void ocfs2_get_inode_flags(struct ocfs2_inode_info *oi);
6370 +int ocfs2_sync_flags(struct inode *inode);
6371  
6372  static inline blkcnt_t ocfs2_inode_sector_count(struct inode *inode)
6373  {
6374 diff -NurpP --minimal linux-2.6.29.1/fs/ocfs2/ioctl.c linux-2.6.29.1-vs2.3.0.36.9-pre5/fs/ocfs2/ioctl.c
6375 --- linux-2.6.29.1/fs/ocfs2/ioctl.c     2008-12-25 00:26:37.000000000 +0100
6376 +++ linux-2.6.29.1-vs2.3.0.36.9-pre5/fs/ocfs2/ioctl.c   2009-02-22 22:54:25.000000000 +0100
6377 @@ -42,7 +42,7 @@ static int ocfs2_get_inode_attr(struct i
6378         return status;
6379  }
6380  
6381 -static int ocfs2_set_inode_attr(struct inode *inode, unsigned flags,
6382 +int ocfs2_set_inode_attr(struct inode *inode, unsigned flags,
6383                                 unsigned mask)
6384  {
6385         struct ocfs2_inode_info *ocfs2_inode = OCFS2_I(inode);
6386 @@ -67,6 +67,11 @@ static int ocfs2_set_inode_attr(struct i
6387         if (!S_ISDIR(inode->i_mode))
6388                 flags &= ~OCFS2_DIRSYNC_FL;
6389  
6390 +       if (IS_BARRIER(inode)) {
6391 +               vxwprintk_task(1, "messing with the barrier.");
6392 +               goto bail_unlock;
6393 +       }
6394 +
6395         handle = ocfs2_start_trans(osb, OCFS2_INODE_UPDATE_CREDITS);
6396         if (IS_ERR(handle)) {
6397                 status = PTR_ERR(handle);
6398 diff -NurpP --minimal linux-2.6.29.1/fs/ocfs2/ioctl.h linux-2.6.29.1-vs2.3.0.36.9-pre5/fs/ocfs2/ioctl.h
6399 --- linux-2.6.29.1/fs/ocfs2/ioctl.h     2008-12-25 00:26:37.000000000 +0100
6400 +++ linux-2.6.29.1-vs2.3.0.36.9-pre5/fs/ocfs2/ioctl.h   2009-02-22 22:54:25.000000000 +0100
6401 @@ -10,6 +10,9 @@
6402  #ifndef OCFS2_IOCTL_H
6403  #define OCFS2_IOCTL_H
6404  
6405 +int ocfs2_set_inode_attr(struct inode *inode, unsigned flags,
6406 +                               unsigned mask);
6407 +
6408  long ocfs2_ioctl(struct file *filp, unsigned int cmd, unsigned long arg);
6409  long ocfs2_compat_ioctl(struct file *file, unsigned cmd, unsigned long arg);
6410  
6411 diff -NurpP --minimal linux-2.6.29.1/fs/ocfs2/namei.c linux-2.6.29.1-vs2.3.0.36.9-pre5/fs/ocfs2/namei.c
6412 --- linux-2.6.29.1/fs/ocfs2/namei.c     2009-03-24 14:22:27.000000000 +0100
6413 +++ linux-2.6.29.1-vs2.3.0.36.9-pre5/fs/ocfs2/namei.c   2009-03-25 01:04:31.000000000 +0100
6414 @@ -41,6 +41,7 @@
6415  #include <linux/slab.h>
6416  #include <linux/highmem.h>
6417  #include <linux/quotaops.h>
6418 +#include <linux/vs_tag.h>
6419  
6420  #define MLOG_MASK_PREFIX ML_NAMEI
6421  #include <cluster/masklog.h>
6422 @@ -462,6 +463,7 @@ static int ocfs2_mknod_locked(struct ocf
6423         struct ocfs2_extent_list *fel;
6424         u64 fe_blkno = 0;
6425         u16 suballoc_bit;
6426 +       tag_t tag;
6427  
6428         mlog_entry("(0x%p, 0x%p, %d, %lu, '%.*s')\n", dir, dentry,
6429                    inode->i_mode, (unsigned long)dev, dentry->d_name.len,
6430 @@ -508,8 +510,11 @@ static int ocfs2_mknod_locked(struct ocf
6431         fe->i_blkno = cpu_to_le64(fe_blkno);
6432         fe->i_suballoc_bit = cpu_to_le16(suballoc_bit);
6433         fe->i_suballoc_slot = cpu_to_le16(inode_ac->ac_alloc_slot);
6434 -       fe->i_uid = cpu_to_le32(inode->i_uid);
6435 -       fe->i_gid = cpu_to_le32(inode->i_gid);
6436 +
6437 +       tag = dx_current_fstag(osb->sb);
6438 +       fe->i_uid = cpu_to_le32(TAGINO_UID(DX_TAG(inode), inode->i_uid, tag));
6439 +       fe->i_gid = cpu_to_le32(TAGINO_GID(DX_TAG(inode), inode->i_gid, tag));
6440 +       inode->i_tag = tag;
6441         fe->i_mode = cpu_to_le16(inode->i_mode);
6442         if (S_ISCHR(inode->i_mode) || S_ISBLK(inode->i_mode))
6443                 fe->id1.dev1.i_rdev = cpu_to_le64(huge_encode_dev(dev));
6444 @@ -2025,6 +2030,7 @@ const struct inode_operations ocfs2_dir_
6445         .rename         = ocfs2_rename,
6446         .setattr        = ocfs2_setattr,
6447         .getattr        = ocfs2_getattr,
6448 +       .sync_flags     = ocfs2_sync_flags,
6449         .permission     = ocfs2_permission,
6450         .setxattr       = generic_setxattr,
6451         .getxattr       = generic_getxattr,
6452 diff -NurpP --minimal linux-2.6.29.1/fs/ocfs2/ocfs2_fs.h linux-2.6.29.1-vs2.3.0.36.9-pre5/fs/ocfs2/ocfs2_fs.h
6453 --- linux-2.6.29.1/fs/ocfs2/ocfs2_fs.h  2009-03-24 14:22:27.000000000 +0100
6454 +++ linux-2.6.29.1-vs2.3.0.36.9-pre5/fs/ocfs2/ocfs2_fs.h        2009-03-24 14:48:35.000000000 +0100
6455 @@ -219,18 +219,23 @@
6456  #define OCFS2_INDEXED_DIR_FL   (0x0008)
6457  
6458  /* Inode attributes, keep in sync with EXT2 */
6459 -#define OCFS2_SECRM_FL         (0x00000001)    /* Secure deletion */
6460 -#define OCFS2_UNRM_FL          (0x00000002)    /* Undelete */
6461 -#define OCFS2_COMPR_FL         (0x00000004)    /* Compress file */
6462 -#define OCFS2_SYNC_FL          (0x00000008)    /* Synchronous updates */
6463 -#define OCFS2_IMMUTABLE_FL     (0x00000010)    /* Immutable file */
6464 -#define OCFS2_APPEND_FL                (0x00000020)    /* writes to file may only append */
6465 -#define OCFS2_NODUMP_FL                (0x00000040)    /* do not dump file */
6466 -#define OCFS2_NOATIME_FL       (0x00000080)    /* do not update atime */
6467 -#define OCFS2_DIRSYNC_FL       (0x00010000)    /* dirsync behaviour (directories only) */
6468 +#define OCFS2_SECRM_FL         FS_SECRM_FL     /* Secure deletion */
6469 +#define OCFS2_UNRM_FL          FS_UNRM_FL      /* Undelete */
6470 +#define OCFS2_COMPR_FL         FS_COMPR_FL     /* Compress file */
6471 +#define OCFS2_SYNC_FL          FS_SYNC_FL      /* Synchronous updates */
6472 +#define OCFS2_IMMUTABLE_FL     FS_IMMUTABLE_FL /* Immutable file */
6473 +#define OCFS2_APPEND_FL                FS_APPEND_FL    /* writes to file may only append */
6474 +#define OCFS2_NODUMP_FL                FS_NODUMP_FL    /* do not dump file */
6475 +#define OCFS2_NOATIME_FL       FS_NOATIME_FL   /* do not update atime */
6476  
6477 -#define OCFS2_FL_VISIBLE       (0x000100FF)    /* User visible flags */
6478 -#define OCFS2_FL_MODIFIABLE    (0x000100FF)    /* User modifiable flags */
6479 +#define OCFS2_DIRSYNC_FL       FS_DIRSYNC_FL   /* dirsync behaviour (directories only) */
6480 +#define OCFS2_IXUNLINK_FL      FS_IXUNLINK_FL  /* Immutable invert on unlink */
6481 +
6482 +#define OCFS2_BARRIER_FL       FS_BARRIER_FL   /* Barrier for chroot() */
6483 +#define OCFS2_COW_FL           FS_COW_FL       /* Copy on Write marker */
6484 +
6485 +#define OCFS2_FL_VISIBLE       (0x010300FF)    /* User visible flags */
6486 +#define OCFS2_FL_MODIFIABLE    (0x010300FF)    /* User modifiable flags */
6487  
6488  /*
6489   * Extent record flags (e_node.leaf.flags)
6490 diff -NurpP --minimal linux-2.6.29.1/fs/ocfs2/ocfs2.h linux-2.6.29.1-vs2.3.0.36.9-pre5/fs/ocfs2/ocfs2.h
6491 --- linux-2.6.29.1/fs/ocfs2/ocfs2.h     2009-03-24 14:22:27.000000000 +0100
6492 +++ linux-2.6.29.1-vs2.3.0.36.9-pre5/fs/ocfs2/ocfs2.h   2009-03-24 16:18:22.000000000 +0100
6493 @@ -199,6 +199,7 @@ enum ocfs2_mount_options
6494         OCFS2_MOUNT_POSIX_ACL = 1 << 8, /* POSIX access control lists */
6495         OCFS2_MOUNT_USRQUOTA = 1 << 9, /* We support user quotas */
6496         OCFS2_MOUNT_GRPQUOTA = 1 << 10, /* We support group quotas */
6497 +       OCFS2_MOUNT_TAGGED = 1 << 11, /* use tagging */
6498  };
6499  
6500  #define OCFS2_OSB_SOFT_RO      0x0001
6501 diff -NurpP --minimal linux-2.6.29.1/fs/ocfs2/super.c linux-2.6.29.1-vs2.3.0.36.9-pre5/fs/ocfs2/super.c
6502 --- linux-2.6.29.1/fs/ocfs2/super.c     2009-03-24 14:22:27.000000000 +0100
6503 +++ linux-2.6.29.1-vs2.3.0.36.9-pre5/fs/ocfs2/super.c   2009-03-24 16:19:44.000000000 +0100
6504 @@ -172,6 +172,7 @@ enum {
6505         Opt_noacl,
6506         Opt_usrquota,
6507         Opt_grpquota,
6508 +       Opt_tag, Opt_notag, Opt_tagid,
6509         Opt_err,
6510  };
6511  
6512 @@ -198,6 +199,9 @@ static const match_table_t tokens = {
6513         {Opt_noacl, "noacl"},
6514         {Opt_usrquota, "usrquota"},
6515         {Opt_grpquota, "grpquota"},
6516 +       {Opt_tag, "tag"},
6517 +       {Opt_notag, "notag"},
6518 +       {Opt_tagid, "tagid=%u"},
6519         {Opt_err, NULL}
6520  };
6521  
6522 @@ -436,6 +440,13 @@ static int ocfs2_remount(struct super_bl
6523                 goto out;
6524         }
6525  
6526 +       if ((parsed_options.mount_opt & OCFS2_MOUNT_TAGGED) &&
6527 +               !(sb->s_flags & MS_TAGGED)) {
6528 +               ret = -EINVAL;
6529 +               mlog(ML_ERROR, "Cannot change tagging on remount\n");
6530 +               goto out;
6531 +       }
6532 +
6533         if ((osb->s_mount_opt & OCFS2_MOUNT_HB_LOCAL) !=
6534             (parsed_options.mount_opt & OCFS2_MOUNT_HB_LOCAL)) {
6535                 ret = -EINVAL;
6536 @@ -950,6 +961,9 @@ static int ocfs2_fill_super(struct super
6537  
6538         ocfs2_complete_mount_recovery(osb);
6539  
6540 +       if (osb->s_mount_opt & OCFS2_MOUNT_TAGGED)
6541 +               sb->s_flags |= MS_TAGGED;
6542 +
6543         if (ocfs2_mount_local(osb))
6544                 snprintf(nodestr, sizeof(nodestr), "local");
6545         else
6546 @@ -1208,6 +1222,20 @@ static int ocfs2_parse_options(struct su
6547                         printk(KERN_INFO "ocfs2 (no)acl options not supported\n");
6548                         break;
6549  #endif
6550 +#ifndef CONFIG_TAGGING_NONE
6551 +               case Opt_tag:
6552 +                       mopt->mount_opt |= OCFS2_MOUNT_TAGGED;
6553 +                       break;
6554 +               case Opt_notag:
6555 +                       mopt->mount_opt &= ~OCFS2_MOUNT_TAGGED;
6556 +                       break;
6557 +#endif
6558 +#ifdef CONFIG_PROPAGATE
6559 +               case Opt_tagid:
6560 +                       /* use args[0] */
6561 +                       mopt->mount_opt |= OCFS2_MOUNT_TAGGED;
6562 +                       break;
6563 +#endif
6564                 default:
6565                         mlog(ML_ERROR,
6566                              "Unrecognized mount option \"%s\" "
6567 diff -NurpP --minimal linux-2.6.29.1/fs/open.c linux-2.6.29.1-vs2.3.0.36.9-pre5/fs/open.c
6568 --- linux-2.6.29.1/fs/open.c    2009-03-24 14:22:27.000000000 +0100
6569 +++ linux-2.6.29.1-vs2.3.0.36.9-pre5/fs/open.c  2009-03-24 14:48:35.000000000 +0100
6570 @@ -29,22 +29,31 @@
6571  #include <linux/rcupdate.h>
6572  #include <linux/audit.h>
6573  #include <linux/falloc.h>
6574 +#include <linux/vs_base.h>
6575 +#include <linux/vs_limit.h>
6576 +#include <linux/vs_dlimit.h>
6577 +#include <linux/vs_tag.h>
6578 +#include <linux/vs_cowbl.h>
6579  
6580  int vfs_statfs(struct dentry *dentry, struct kstatfs *buf)
6581  {
6582         int retval = -ENODEV;
6583  
6584         if (dentry) {
6585 +               struct super_block *sb = dentry->d_sb;
6586 +
6587                 retval = -ENOSYS;
6588 -               if (dentry->d_sb->s_op->statfs) {
6589 +               if (sb->s_op->statfs) {
6590                         memset(buf, 0, sizeof(*buf));
6591                         retval = security_sb_statfs(dentry);
6592                         if (retval)
6593                                 return retval;
6594 -                       retval = dentry->d_sb->s_op->statfs(dentry, buf);
6595 +                       retval = sb->s_op->statfs(dentry, buf);
6596                         if (retval == 0 && buf->f_frsize == 0)
6597                                 buf->f_frsize = buf->f_bsize;
6598                 }
6599 +               if (!vx_check(0, VS_ADMIN|VS_WATCH))
6600 +                       vx_vsi_statfs(sb, buf);
6601         }
6602         return retval;
6603  }
6604 @@ -638,6 +647,10 @@ SYSCALL_DEFINE3(fchmodat, int, dfd, cons
6605         error = user_path_at(dfd, filename, LOOKUP_FOLLOW, &path);
6606         if (error)
6607                 goto out;
6608 +
6609 +       error = cow_check_and_break(&path);
6610 +       if (error)
6611 +               goto dput_and_out;
6612         inode = path.dentry->d_inode;
6613  
6614         error = mnt_want_write(path.mnt);
6615 @@ -671,11 +684,11 @@ static int chown_common(struct dentry * 
6616         newattrs.ia_valid =  ATTR_CTIME;
6617         if (user != (uid_t) -1) {
6618                 newattrs.ia_valid |= ATTR_UID;
6619 -               newattrs.ia_uid = user;
6620 +               newattrs.ia_uid = dx_map_uid(user);
6621         }
6622         if (group != (gid_t) -1) {
6623                 newattrs.ia_valid |= ATTR_GID;
6624 -               newattrs.ia_gid = group;
6625 +               newattrs.ia_gid = dx_map_gid(group);
6626         }
6627         if (!S_ISDIR(inode->i_mode))
6628                 newattrs.ia_valid |=
6629 @@ -698,7 +711,11 @@ SYSCALL_DEFINE3(chown, const char __user
6630         error = mnt_want_write(path.mnt);
6631         if (error)
6632                 goto out_release;
6633 -       error = chown_common(path.dentry, user, group);
6634 +#ifdef CONFIG_VSERVER_COWBL
6635 +       error = cow_check_and_break(&path);
6636 +       if (!error)
6637 +#endif
6638 +               error = chown_common(path.dentry, user, group);
6639         mnt_drop_write(path.mnt);
6640  out_release:
6641         path_put(&path);
6642 @@ -723,7 +740,11 @@ SYSCALL_DEFINE5(fchownat, int, dfd, cons
6643         error = mnt_want_write(path.mnt);
6644         if (error)
6645                 goto out_release;
6646 -       error = chown_common(path.dentry, user, group);
6647 +#ifdef CONFIG_VSERVER_COWBL
6648 +       error = cow_check_and_break(&path);
6649 +       if (!error)
6650 +#endif
6651 +               error = chown_common(path.dentry, user, group);
6652         mnt_drop_write(path.mnt);
6653  out_release:
6654         path_put(&path);
6655 @@ -742,7 +763,11 @@ SYSCALL_DEFINE3(lchown, const char __use
6656         error = mnt_want_write(path.mnt);
6657         if (error)
6658                 goto out_release;
6659 -       error = chown_common(path.dentry, user, group);
6660 +#ifdef CONFIG_VSERVER_COWBL
6661 +       error = cow_check_and_break(&path);
6662 +       if (!error)
6663 +#endif
6664 +               error = chown_common(path.dentry, user, group);
6665         mnt_drop_write(path.mnt);
6666  out_release:
6667         path_put(&path);
6668 @@ -986,6 +1011,7 @@ static void __put_unused_fd(struct files
6669         __FD_CLR(fd, fdt->open_fds);
6670         if (fd < files->next_fd)
6671                 files->next_fd = fd;
6672 +       vx_openfd_dec(fd);
6673  }
6674  
6675  void put_unused_fd(unsigned int fd)
6676 diff -NurpP --minimal linux-2.6.29.1/fs/proc/array.c linux-2.6.29.1-vs2.3.0.36.9-pre5/fs/proc/array.c
6677 --- linux-2.6.29.1/fs/proc/array.c      2009-03-24 14:22:27.000000000 +0100
6678 +++ linux-2.6.29.1-vs2.3.0.36.9-pre5/fs/proc/array.c    2009-03-25 01:07:51.000000000 +0100
6679 @@ -81,6 +81,8 @@
6680  #include <linux/seq_file.h>
6681  #include <linux/pid_namespace.h>
6682  #include <linux/tracehook.h>
6683 +#include <linux/vs_context.h>
6684 +#include <linux/vs_network.h>
6685  
6686  #include <asm/pgtable.h>
6687  #include <asm/processor.h>
6688 @@ -137,8 +139,9 @@ static const char *task_state_array[] = 
6689         "D (disk sleep)",       /*  2 */
6690         "T (stopped)",          /*  4 */
6691         "T (tracing stop)",     /*  8 */
6692 -       "Z (zombie)",           /* 16 */
6693 -       "X (dead)"              /* 32 */
6694 +       "H (on hold)",          /* 16 */
6695 +       "Z (zombie)",           /* 32 */
6696 +       "X (dead)",             /* 64 */
6697  };
6698  
6699  static inline const char *get_task_state(struct task_struct *tsk)
6700 @@ -165,6 +168,9 @@ static inline void task_state(struct seq
6701         rcu_read_lock();
6702         ppid = pid_alive(p) ?
6703                 task_tgid_nr_ns(rcu_dereference(p->real_parent), ns) : 0;
6704 +       if (unlikely(vx_current_initpid(p->pid)))
6705 +               ppid = 0;
6706 +
6707         tpid = 0;
6708         if (pid_alive(p)) {
6709                 struct task_struct *tracer = tracehook_tracer_task(p);
6710 @@ -280,7 +286,7 @@ static inline void task_sig(struct seq_f
6711  }
6712  
6713  static void render_cap_t(struct seq_file *m, const char *header,
6714 -                       kernel_cap_t *a)
6715 +                       struct vx_info *vxi, kernel_cap_t *a)
6716  {
6717         unsigned __capi;
6718  
6719 @@ -305,10 +311,11 @@ static inline void task_cap(struct seq_f
6720         cap_bset        = cred->cap_bset;
6721         rcu_read_unlock();
6722  
6723 -       render_cap_t(m, "CapInh:\t", &cap_inheritable);
6724 -       render_cap_t(m, "CapPrm:\t", &cap_permitted);
6725 -       render_cap_t(m, "CapEff:\t", &cap_effective);
6726 -       render_cap_t(m, "CapBnd:\t", &cap_bset);
6727 +       /* FIXME: maybe move the p->vx_info masking to __task_cred() ? */
6728 +       render_cap_t(m, "CapInh:\t", p->vx_info, &cap_inheritable);
6729 +       render_cap_t(m, "CapPrm:\t", p->vx_info, &cap_permitted);
6730 +       render_cap_t(m, "CapEff:\t", p->vx_info, &cap_effective);
6731 +       render_cap_t(m, "CapBnd:\t", p->vx_info, &cap_bset);
6732  }
6733  
6734  static inline void task_context_switch_counts(struct seq_file *m,
6735 @@ -320,6 +327,42 @@ static inline void task_context_switch_c
6736                         p->nivcsw);
6737  }
6738  
6739 +int proc_pid_nsproxy(struct seq_file *m, struct pid_namespace *ns,
6740 +                       struct pid *pid, struct task_struct *task)
6741 +{
6742 +       seq_printf(m,   "Proxy:\t%p(%c)\n"
6743 +                       "Count:\t%u\n"
6744 +                       "uts:\t%p(%c)\n"
6745 +                       "ipc:\t%p(%c)\n"
6746 +                       "mnt:\t%p(%c)\n"
6747 +                       "pid:\t%p(%c)\n"
6748 +                       "net:\t%p(%c)\n",
6749 +                       task->nsproxy,
6750 +                       (task->nsproxy == init_task.nsproxy ? 'I' : '-'),
6751 +                       atomic_read(&task->nsproxy->count),
6752 +                       task->nsproxy->uts_ns,
6753 +                       (task->nsproxy->uts_ns == init_task.nsproxy->uts_ns ? 'I' : '-'),
6754 +                       task->nsproxy->ipc_ns,
6755 +                       (task->nsproxy->ipc_ns == init_task.nsproxy->ipc_ns ? 'I' : '-'),
6756 +                       task->nsproxy->mnt_ns,
6757 +                       (task->nsproxy->mnt_ns == init_task.nsproxy->mnt_ns ? 'I' : '-'),
6758 +                       task->nsproxy->pid_ns,
6759 +                       (task->nsproxy->pid_ns == init_task.nsproxy->pid_ns ? 'I' : '-'),
6760 +                       task->nsproxy->net_ns,
6761 +                       (task->nsproxy->net_ns == init_task.nsproxy->net_ns ? 'I' : '-'));
6762 +       return 0;
6763 +}
6764 +
6765 +void task_vs_id(struct seq_file *m, struct task_struct *task)
6766 +{
6767 +       if (task_vx_flags(task, VXF_HIDE_VINFO, 0))
6768 +               return;
6769 +
6770 +       seq_printf(m, "VxID: %d\n", vx_task_xid(task));
6771 +       seq_printf(m, "NxID: %d\n", nx_task_nid(task));
6772 +}
6773 +
6774 +
6775  int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
6776                         struct pid *pid, struct task_struct *task)
6777  {
6778 @@ -335,6 +378,7 @@ int proc_pid_status(struct seq_file *m, 
6779         task_sig(m, task);
6780         task_cap(m, task);
6781         cpuset_task_status_allowed(m, task);
6782 +       task_vs_id(m, task);
6783  #if defined(CONFIG_S390)
6784         task_show_regs(m, task);
6785  #endif
6786 @@ -447,6 +491,17 @@ static int do_task_stat(struct seq_file 
6787         /* convert nsec -> ticks */
6788         start_time = nsec_to_clock_t(start_time);
6789  
6790 +       /* fixup start time for virt uptime */
6791 +       if (vx_flags(VXF_VIRT_UPTIME, 0)) {
6792 +               unsigned long long bias =
6793 +                       current->vx_info->cvirt.bias_clock;
6794 +
6795 +               if (start_time > bias)
6796 +                       start_time -= bias;
6797 +               else
6798 +                       start_time = 0;
6799 +       }
6800 +
6801         seq_printf(m, "%d (%s) %c %d %d %d %d %d %u %lu \
6802  %lu %lu %lu %lu %lu %ld %ld %ld %ld %d 0 %llu %lu %ld %lu %lu %lu %lu %lu \
6803  %lu %lu %lu %lu %lu %lu %lu %lu %d %d %u %u %llu %lu %ld\n",
6804 diff -NurpP --minimal linux-2.6.29.1/fs/proc/base.c linux-2.6.29.1-vs2.3.0.36.9-pre5/fs/proc/base.c
6805 --- linux-2.6.29.1/fs/proc/base.c       2009-03-24 14:22:27.000000000 +0100
6806 +++ linux-2.6.29.1-vs2.3.0.36.9-pre5/fs/proc/base.c     2009-03-24 16:29:35.000000000 +0100
6807 @@ -80,6 +80,8 @@
6808  #include <linux/oom.h>
6809  #include <linux/elf.h>
6810  #include <linux/pid_namespace.h>
6811 +#include <linux/vs_context.h>
6812 +#include <linux/vs_network.h>
6813  #include "internal.h"
6814  
6815  /* NOTE:
6816 @@ -1458,6 +1460,8 @@ static struct inode *proc_pid_make_inode
6817                 inode->i_gid = cred->egid;
6818                 rcu_read_unlock();
6819         }
6820 +       /* procfs is xid tagged */
6821 +       inode->i_tag = (tag_t)vx_task_xid(task);
6822         security_task_to_inode(task, inode);
6823  
6824  out:
6825 @@ -2008,6 +2012,13 @@ static struct dentry *proc_pident_lookup
6826         if (!task)
6827                 goto out_no_task;
6828  
6829 +       /* TODO: maybe we can come up with a generic approach? */
6830 +       if (task_vx_flags(task, VXF_HIDE_VINFO, 0) &&
6831 +               (dentry->d_name.len == 5) &&
6832 +               (!memcmp(dentry->d_name.name, "vinfo", 5) ||
6833 +               !memcmp(dentry->d_name.name, "ninfo", 5)))
6834 +               goto out;
6835 +
6836         /*
6837          * Yes, it does not scale. And it should not. Don't add
6838          * new entries into /proc/<tgid>/ without very good reasons.
6839 @@ -2393,7 +2404,7 @@ out_iput:
6840  static struct dentry *proc_base_lookup(struct inode *dir, struct dentry *dentry)
6841  {
6842         struct dentry *error;
6843 -       struct task_struct *task = get_proc_task(dir);
6844 +       struct task_struct *task = get_proc_task_real(dir);
6845         const struct pid_entry *p, *last;
6846  
6847         error = ERR_PTR(-ENOENT);
6848 @@ -2483,6 +2494,9 @@ static int proc_pid_personality(struct s
6849  static const struct file_operations proc_task_operations;
6850  static const struct inode_operations proc_task_inode_operations;
6851  
6852 +extern int proc_pid_vx_info(struct task_struct *, char *);
6853 +extern int proc_pid_nx_info(struct task_struct *, char *);
6854 +
6855  static const struct pid_entry tgid_base_stuff[] = {
6856         DIR("task",       S_IRUGO|S_IXUGO, proc_task_inode_operations, proc_task_operations),
6857         DIR("fd",         S_IRUSR|S_IXUSR, proc_fd_inode_operations, proc_fd_operations),
6858 @@ -2541,6 +2555,8 @@ static const struct pid_entry tgid_base_
6859  #ifdef CONFIG_CGROUPS
6860         REG("cgroup",  S_IRUGO, proc_cgroup_operations),
6861  #endif
6862 +       INF("vinfo",      S_IRUGO, proc_pid_vx_info),
6863 +       INF("ninfo",      S_IRUGO, proc_pid_nx_info),
6864         INF("oom_score",  S_IRUGO, proc_oom_score),
6865         REG("oom_adj",    S_IRUGO|S_IWUSR, proc_oom_adjust_operations),
6866  #ifdef CONFIG_AUDITSYSCALL
6867 @@ -2556,6 +2572,7 @@ static const struct pid_entry tgid_base_
6868  #ifdef CONFIG_TASK_IO_ACCOUNTING
6869         INF("io",       S_IRUGO, proc_tgid_io_accounting),
6870  #endif
6871 +       ONE("nsproxy",  S_IRUGO, proc_pid_nsproxy),
6872  };
6873  
6874  static int proc_tgid_base_readdir(struct file * filp,
6875 @@ -2752,7 +2769,7 @@ retry:
6876         iter.task = NULL;
6877         pid = find_ge_pid(iter.tgid, ns);
6878         if (pid) {
6879 -               iter.tgid = pid_nr_ns(pid, ns);
6880 +               iter.tgid = pid_unmapped_nr_ns(pid, ns);
6881                 iter.task = pid_task(pid, PIDTYPE_PID);
6882                 /* What we to know is if the pid we have find is the
6883                  * pid of a thread_group_leader.  Testing for task
6884 @@ -2782,7 +2799,7 @@ static int proc_pid_fill_cache(struct fi
6885         struct tgid_iter iter)
6886  {
6887         char name[PROC_NUMBUF];
6888 -       int len = snprintf(name, sizeof(name), "%d", iter.tgid);
6889 +       int len = snprintf(name, sizeof(name), "%d", vx_map_tgid(iter.tgid));
6890         return proc_fill_cache(filp, dirent, filldir, name, len,
6891                                 proc_pid_instantiate, iter.task, NULL);
6892  }
6893 @@ -2791,7 +2808,7 @@ static int proc_pid_fill_cache(struct fi
6894  int proc_pid_readdir(struct file * filp, void * dirent, filldir_t filldir)
6895  {
6896         unsigned int nr = filp->f_pos - FIRST_PROCESS_ENTRY;
6897 -       struct task_struct *reaper = get_proc_task(filp->f_path.dentry->d_inode);
6898 +       struct task_struct *reaper = get_proc_task_real(filp->f_path.dentry->d_inode);
6899         struct tgid_iter iter;
6900         struct pid_namespace *ns;
6901  
6902 @@ -2811,6 +2828,8 @@ int proc_pid_readdir(struct file * filp,
6903              iter.task;
6904              iter.tgid += 1, iter = next_tgid(ns, iter)) {
6905                 filp->f_pos = iter.tgid + TGID_OFFSET;
6906 +               if (!vx_proc_task_visible(iter.task))
6907 +                       continue;
6908                 if (proc_pid_fill_cache(filp, dirent, filldir, iter) < 0) {
6909                         put_task_struct(iter.task);
6910                         goto out;
6911 @@ -2957,6 +2976,8 @@ static struct dentry *proc_task_lookup(s
6912         tid = name_to_int(dentry);
6913         if (tid == ~0U)
6914                 goto out;
6915 +       if (vx_current_initpid(tid))
6916 +               goto out;
6917  
6918         ns = dentry->d_sb->s_fs_info;
6919         rcu_read_lock();
6920 diff -NurpP --minimal linux-2.6.29.1/fs/proc/generic.c linux-2.6.29.1-vs2.3.0.36.9-pre5/fs/proc/generic.c
6921 --- linux-2.6.29.1/fs/proc/generic.c    2009-03-24 14:22:27.000000000 +0100
6922 +++ linux-2.6.29.1-vs2.3.0.36.9-pre5/fs/proc/generic.c  2009-03-24 14:48:35.000000000 +0100
6923 @@ -20,6 +20,7 @@
6924  #include <linux/bitops.h>
6925  #include <linux/spinlock.h>
6926  #include <linux/completion.h>
6927 +#include <linux/vserver/inode.h>
6928  #include <asm/uaccess.h>
6929  
6930  #include "internal.h"
6931 @@ -382,6 +383,8 @@ struct dentry *proc_lookup_de(struct pro
6932         for (de = de->subdir; de ; de = de->next) {
6933                 if (de->namelen != dentry->d_name.len)
6934                         continue;
6935 +                       if (!vx_hide_check(0, de->vx_flags))
6936 +                               continue;
6937                 if (!memcmp(dentry->d_name.name, de->name, de->namelen)) {
6938                         unsigned int ino;
6939  
6940 @@ -390,6 +393,8 @@ struct dentry *proc_lookup_de(struct pro
6941                         spin_unlock(&proc_subdir_lock);
6942                         error = -EINVAL;
6943                         inode = proc_get_inode(dir->i_sb, ino, de);
6944 +                               /* generic proc entries belong to the host */
6945 +                               inode->i_tag = 0;
6946                         goto out_unlock;
6947                 }
6948         }
6949 @@ -467,6 +472,8 @@ int proc_readdir_de(struct proc_dir_entr
6950  
6951                                 /* filldir passes info to user space */
6952                                 de_get(de);
6953 +                               if (!vx_hide_check(0, de->vx_flags))
6954 +                                       goto skip;
6955                                 spin_unlock(&proc_subdir_lock);
6956                                 if (filldir(dirent, de->name, de->namelen, filp->f_pos,
6957                                             de->low_ino, de->mode >> 12) < 0) {
6958 @@ -474,6 +481,7 @@ int proc_readdir_de(struct proc_dir_entr
6959                                         goto out;
6960                                 }
6961                                 spin_lock(&proc_subdir_lock);
6962 +                       skip:
6963                                 filp->f_pos++;
6964                                 next = de->next;
6965                                 de_put(de);
6966 @@ -588,6 +596,7 @@ static struct proc_dir_entry *__proc_cre
6967         ent->nlink = nlink;
6968         atomic_set(&ent->count, 1);
6969         ent->pde_users = 0;
6970 +       ent->vx_flags = IATTR_PROC_DEFAULT;
6971         spin_lock_init(&ent->pde_unload_lock);
6972         ent->pde_unload_completion = NULL;
6973         INIT_LIST_HEAD(&ent->pde_openers);
6974 @@ -611,7 +620,8 @@ struct proc_dir_entry *proc_symlink(cons
6975                                 kfree(ent->data);
6976                                 kfree(ent);
6977                                 ent = NULL;
6978 -                       }
6979 +                       } else
6980 +                               ent->vx_flags = IATTR_PROC_SYMLINK;
6981                 } else {
6982                         kfree(ent);
6983                         ent = NULL;
6984 diff -NurpP --minimal linux-2.6.29.1/fs/proc/inode.c linux-2.6.29.1-vs2.3.0.36.9-pre5/fs/proc/inode.c
6985 --- linux-2.6.29.1/fs/proc/inode.c      2009-03-24 14:22:27.000000000 +0100
6986 +++ linux-2.6.29.1-vs2.3.0.36.9-pre5/fs/proc/inode.c    2009-03-24 14:48:35.000000000 +0100
6987 @@ -465,6 +465,8 @@ struct inode *proc_get_inode(struct supe
6988                         inode->i_uid = de->uid;
6989                         inode->i_gid = de->gid;
6990                 }
6991 +               if (de->vx_flags)
6992 +                       PROC_I(inode)->vx_flags = de->vx_flags;
6993                 if (de->size)
6994                         inode->i_size = de->size;
6995                 if (de->nlink)
6996 diff -NurpP --minimal linux-2.6.29.1/fs/proc/internal.h linux-2.6.29.1-vs2.3.0.36.9-pre5/fs/proc/internal.h
6997 --- linux-2.6.29.1/fs/proc/internal.h   2009-03-24 14:22:27.000000000 +0100
6998 +++ linux-2.6.29.1-vs2.3.0.36.9-pre5/fs/proc/internal.h 2009-03-24 14:48:35.000000000 +0100
6999 @@ -10,6 +10,7 @@
7000   */
7001  
7002  #include <linux/proc_fs.h>
7003 +#include <linux/vs_pid.h>
7004  
7005  extern struct proc_dir_entry proc_root;
7006  #ifdef CONFIG_PROC_SYSCTL
7007 @@ -51,6 +52,9 @@ extern int proc_pid_status(struct seq_fi
7008                                 struct pid *pid, struct task_struct *task);
7009  extern int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns,
7010                                 struct pid *pid, struct task_struct *task);
7011 +extern int proc_pid_nsproxy(struct seq_file *m, struct pid_namespace *ns,
7012 +                               struct pid *pid, struct task_struct *task);
7013 +
7014  extern loff_t mem_lseek(struct file *file, loff_t offset, int orig);
7015  
7016  extern const struct file_operations proc_maps_operations;
7017 @@ -70,11 +74,16 @@ static inline struct pid *proc_pid(struc
7018         return PROC_I(inode)->pid;
7019  }
7020  
7021 -static inline struct task_struct *get_proc_task(struct inode *inode)
7022 +static inline struct task_struct *get_proc_task_real(struct inode *inode)
7023  {
7024         return get_pid_task(proc_pid(inode), PIDTYPE_PID);
7025  }
7026  
7027 +static inline struct task_struct *get_proc_task(struct inode *inode)
7028 +{
7029 +       return vx_get_proc_task(inode, proc_pid(inode));
7030 +}
7031 +
7032  static inline int proc_fd(struct inode *inode)
7033  {
7034         return PROC_I(inode)->fd;
7035 diff -NurpP --minimal linux-2.6.29.1/fs/proc/meminfo.c linux-2.6.29.1-vs2.3.0.36.9-pre5/fs/proc/meminfo.c
7036 --- linux-2.6.29.1/fs/proc/meminfo.c    2009-03-24 14:22:27.000000000 +0100
7037 +++ linux-2.6.29.1-vs2.3.0.36.9-pre5/fs/proc/meminfo.c  2009-03-24 14:48:35.000000000 +0100
7038 @@ -41,7 +41,7 @@ static int meminfo_proc_show(struct seq_
7039  
7040         cached = global_page_state(NR_FILE_PAGES) -
7041                         total_swapcache_pages - i.bufferram;
7042 -       if (cached < 0)
7043 +       if (cached < 0 || vx_flags(VXF_VIRT_MEM, 0))
7044                 cached = 0;
7045  
7046         get_vmalloc_info(&vmi);
7047 diff -NurpP --minimal linux-2.6.29.1/fs/proc/root.c linux-2.6.29.1-vs2.3.0.36.9-pre5/fs/proc/root.c
7048 --- linux-2.6.29.1/fs/proc/root.c       2009-03-24 14:22:27.000000000 +0100
7049 +++ linux-2.6.29.1-vs2.3.0.36.9-pre5/fs/proc/root.c     2009-03-24 14:48:35.000000000 +0100
7050 @@ -18,9 +18,14 @@
7051  #include <linux/bitops.h>
7052  #include <linux/mount.h>
7053  #include <linux/pid_namespace.h>
7054 +#include <linux/vserver/inode.h>
7055  
7056  #include "internal.h"
7057  
7058 +struct proc_dir_entry *proc_virtual;
7059 +
7060 +extern void proc_vx_init(void);
7061 +
7062  static int proc_test_super(struct super_block *sb, void *data)
7063  {
7064         return sb->s_fs_info == data;
7065 @@ -136,6 +141,7 @@ void __init proc_root_init(void)
7066  #endif
7067         proc_mkdir("bus", NULL);
7068         proc_sys_init();
7069 +       proc_vx_init();
7070  }
7071  
7072  static int proc_root_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat
7073 @@ -203,6 +209,7 @@ struct proc_dir_entry proc_root = {
7074         .proc_iops      = &proc_root_inode_operations, 
7075         .proc_fops      = &proc_root_operations,
7076         .parent         = &proc_root,
7077 +       .vx_flags       = IATTR_ADMIN | IATTR_WATCH,
7078  };
7079  
7080  int pid_ns_prepare_proc(struct pid_namespace *ns)
7081 diff -NurpP --minimal linux-2.6.29.1/fs/proc/uptime.c linux-2.6.29.1-vs2.3.0.36.9-pre5/fs/proc/uptime.c
7082 --- linux-2.6.29.1/fs/proc/uptime.c     2008-12-25 00:26:37.000000000 +0100
7083 +++ linux-2.6.29.1-vs2.3.0.36.9-pre5/fs/proc/uptime.c   2009-02-22 22:54:25.000000000 +0100
7084 @@ -2,6 +2,7 @@
7085  #include <linux/proc_fs.h>
7086  #include <linux/sched.h>
7087  #include <linux/time.h>
7088 +#include <linux/vserver/cvirt.h>
7089  #include <asm/cputime.h>
7090  
7091  static int proc_calc_metrics(char *page, char **start, off_t off,
7092 @@ -29,6 +30,10 @@ static int uptime_read_proc(char *page, 
7093         do_posix_clock_monotonic_gettime(&uptime);
7094         monotonic_to_bootbased(&uptime);
7095         cputime_to_timespec(idletime, &idle);
7096 +
7097 +       if (vx_flags(VXF_VIRT_UPTIME, 0))
7098 +               vx_vsi_uptime(&uptime, &idle);
7099 +
7100         len = sprintf(page, "%lu.%02lu %lu.%02lu\n",
7101                         (unsigned long) uptime.tv_sec,
7102                         (uptime.tv_nsec / (NSEC_PER_SEC / 100)),
7103 diff -NurpP --minimal linux-2.6.29.1/fs/quota.c linux-2.6.29.1-vs2.3.0.36.9-pre5/fs/quota.c
7104 --- linux-2.6.29.1/fs/quota.c   2009-03-24 14:22:27.000000000 +0100
7105 +++ linux-2.6.29.1-vs2.3.0.36.9-pre5/fs/quota.c 2009-03-24 14:48:35.000000000 +0100
7106 @@ -18,6 +18,7 @@
7107  #include <linux/capability.h>
7108  #include <linux/quotaops.h>
7109  #include <linux/types.h>
7110 +#include <linux/vs_context.h>
7111  
7112  /* Check validity of generic quotactl commands */
7113  static int generic_quotactl_valid(struct super_block *sb, int type, int cmd, qid_t id)
7114 @@ -81,11 +82,11 @@ static int generic_quotactl_valid(struct
7115         if (cmd == Q_GETQUOTA) {
7116                 if (((type == USRQUOTA && current_euid() != id) ||
7117                      (type == GRPQUOTA && !in_egroup_p(id))) &&
7118 -                   !capable(CAP_SYS_ADMIN))
7119 +                   !vx_capable(CAP_SYS_ADMIN, VXC_QUOTA_CTL))
7120                         return -EPERM;
7121         }
7122         else if (cmd != Q_GETFMT && cmd != Q_SYNC && cmd != Q_GETINFO)
7123 -               if (!capable(CAP_SYS_ADMIN))
7124 +               if (!vx_capable(CAP_SYS_ADMIN, VXC_QUOTA_CTL))
7125                         return -EPERM;
7126  
7127         return 0;
7128 @@ -132,10 +133,10 @@ static int xqm_quotactl_valid(struct sup
7129         if (cmd == Q_XGETQUOTA) {
7130                 if (((type == XQM_USRQUOTA && current_euid() != id) ||
7131                      (type == XQM_GRPQUOTA && !in_egroup_p(id))) &&
7132 -                    !capable(CAP_SYS_ADMIN))
7133 +                    !vx_capable(CAP_SYS_ADMIN, VXC_QUOTA_CTL))
7134                         return -EPERM;
7135         } else if (cmd != Q_XGETQSTAT && cmd != Q_XQUOTASYNC) {
7136 -               if (!capable(CAP_SYS_ADMIN))
7137 +               if (!vx_capable(CAP_SYS_ADMIN, VXC_QUOTA_CTL))
7138                         return -EPERM;
7139         }
7140  
7141 @@ -337,6 +338,46 @@ static int do_quotactl(struct super_bloc
7142         return 0;
7143  }
7144  
7145 +#if defined(CONFIG_BLK_DEV_VROOT) || defined(CONFIG_BLK_DEV_VROOT_MODULE)
7146 +
7147 +#include <linux/vroot.h>
7148 +#include <linux/major.h>
7149 +#include <linux/module.h>
7150 +#include <linux/kallsyms.h>
7151 +#include <linux/vserver/debug.h>
7152 +
7153 +static vroot_grb_func *vroot_get_real_bdev = NULL;
7154 +
7155 +static spinlock_t vroot_grb_lock = SPIN_LOCK_UNLOCKED;
7156 +
7157 +int register_vroot_grb(vroot_grb_func *func) {
7158 +       int ret = -EBUSY;
7159 +
7160 +       spin_lock(&vroot_grb_lock);
7161 +       if (!vroot_get_real_bdev) {
7162 +               vroot_get_real_bdev = func;
7163 +               ret = 0;
7164 +       }
7165 +       spin_unlock(&vroot_grb_lock);
7166 +       return ret;
7167 +}
7168 +EXPORT_SYMBOL(register_vroot_grb);
7169 +
7170 +int unregister_vroot_grb(vroot_grb_func *func) {
7171 +       int ret = -EINVAL;
7172 +
7173 +       spin_lock(&vroot_grb_lock);
7174 +       if (vroot_get_real_bdev) {
7175 +               vroot_get_real_bdev = NULL;
7176 +               ret = 0;
7177 +       }
7178 +       spin_unlock(&vroot_grb_lock);
7179 +       return ret;
7180 +}
7181 +EXPORT_SYMBOL(unregister_vroot_grb);
7182 +
7183 +#endif
7184 +
7185  /*
7186   * look up a superblock on which quota ops will be performed
7187   * - use the name of a block device to find the superblock thereon
7188 @@ -354,6 +395,22 @@ static inline struct super_block *quotac
7189         putname(tmp);
7190         if (IS_ERR(bdev))
7191                 return ERR_CAST(bdev);
7192 +#if defined(CONFIG_BLK_DEV_VROOT) || defined(CONFIG_BLK_DEV_VROOT_MODULE)
7193 +       if (bdev && bdev->bd_inode &&
7194 +                       imajor(bdev->bd_inode) == VROOT_MAJOR) {
7195 +               struct block_device *bdnew = (void *)-EINVAL;
7196 +
7197 +               if (vroot_get_real_bdev)
7198 +                       bdnew = vroot_get_real_bdev(bdev);
7199 +               else
7200 +                       vxdprintk(VXD_CBIT(misc, 0),
7201 +                                       "vroot_get_real_bdev not set");
7202 +               bdput(bdev);
7203 +               if (IS_ERR(bdnew))
7204 +                       return ERR_PTR(PTR_ERR(bdnew));
7205 +               bdev = bdnew;
7206 +       }
7207 +#endif
7208         sb = get_super(bdev);
7209         bdput(bdev);
7210         if (!sb)
7211 diff -NurpP --minimal linux-2.6.29.1/fs/reiserfs/bitmap.c linux-2.6.29.1-vs2.3.0.36.9-pre5/fs/reiserfs/bitmap.c
7212 --- linux-2.6.29.1/fs/reiserfs/bitmap.c 2008-12-25 00:26:37.000000000 +0100
7213 +++ linux-2.6.29.1-vs2.3.0.36.9-pre5/fs/reiserfs/bitmap.c       2009-02-22 22:54:25.000000000 +0100
7214 @@ -13,6 +13,7 @@
7215  #include <linux/reiserfs_fs_sb.h>
7216  #include <linux/reiserfs_fs_i.h>
7217  #include <linux/quotaops.h>
7218 +#include <linux/vs_dlimit.h>
7219  
7220  #define PREALLOCATION_SIZE 9
7221  
7222 @@ -429,8 +430,10 @@ static void _reiserfs_free_block(struct 
7223         set_sb_free_blocks(rs, sb_free_blocks(rs) + 1);
7224  
7225         journal_mark_dirty(th, s, sbh);
7226 -       if (for_unformatted)
7227 +       if (for_unformatted) {
7228 +               DLIMIT_FREE_BLOCK(inode, 1);
7229                 DQUOT_FREE_BLOCK_NODIRTY(inode, 1);
7230 +       }
7231  }
7232  
7233  void reiserfs_free_block(struct reiserfs_transaction_handle *th,
7234 @@ -1045,6 +1048,7 @@ static inline int blocknrs_and_prealloc_
7235         b_blocknr_t finish = SB_BLOCK_COUNT(s) - 1;
7236         int passno = 0;
7237         int nr_allocated = 0;
7238 +       int blocks;
7239  
7240         determine_prealloc_size(hint);
7241         if (!hint->formatted_node) {
7242 @@ -1054,19 +1058,30 @@ static inline int blocknrs_and_prealloc_
7243                                "reiserquota: allocating %d blocks id=%u",
7244                                amount_needed, hint->inode->i_uid);
7245  #endif
7246 -               quota_ret =
7247 -                   DQUOT_ALLOC_BLOCK_NODIRTY(hint->inode, amount_needed);
7248 -               if (quota_ret)  /* Quota exceeded? */
7249 +               quota_ret = DQUOT_ALLOC_BLOCK_NODIRTY(hint->inode,
7250 +                       amount_needed);
7251 +               if (quota_ret)
7252                         return QUOTA_EXCEEDED;
7253 +               if (DLIMIT_ALLOC_BLOCK(hint->inode, amount_needed)) {
7254 +                       DQUOT_FREE_BLOCK_NODIRTY(hint->inode,
7255 +                               amount_needed);
7256 +                       return NO_DISK_SPACE;
7257 +               }
7258 +
7259                 if (hint->preallocate && hint->prealloc_size) {
7260  #ifdef REISERQUOTA_DEBUG
7261                         reiserfs_debug(s, REISERFS_DEBUG_CODE,
7262                                        "reiserquota: allocating (prealloc) %d blocks id=%u",
7263                                        hint->prealloc_size, hint->inode->i_uid);
7264  #endif
7265 -                       quota_ret =
7266 -                           DQUOT_PREALLOC_BLOCK_NODIRTY(hint->inode,
7267 -                                                        hint->prealloc_size);
7268 +                       quota_ret = DQUOT_PREALLOC_BLOCK_NODIRTY(hint->inode,
7269 +                               hint->prealloc_size);
7270 +                       if (!quota_ret &&
7271 +                               DLIMIT_ALLOC_BLOCK(hint->inode, hint->prealloc_size)) {
7272 +                               DQUOT_FREE_BLOCK_NODIRTY(hint->inode,
7273 +                                       hint->prealloc_size);
7274 +                               quota_ret = 1;
7275 +                       }
7276                         if (quota_ret)
7277                                 hint->preallocate = hint->prealloc_size = 0;
7278                 }
7279 @@ -1098,7 +1113,10 @@ static inline int blocknrs_and_prealloc_
7280                                                nr_allocated,
7281                                                hint->inode->i_uid);
7282  #endif
7283 -                               DQUOT_FREE_BLOCK_NODIRTY(hint->inode, amount_needed + hint->prealloc_size - nr_allocated);      /* Free not allocated blocks */
7284 +                               /* Free not allocated blocks */
7285 +                               blocks = amount_needed + hint->prealloc_size - nr_allocated;
7286 +                               DLIMIT_FREE_BLOCK(hint->inode, blocks);
7287 +                               DQUOT_FREE_BLOCK_NODIRTY(hint->inode, blocks);
7288                         }
7289                         while (nr_allocated--)
7290                                 reiserfs_free_block(hint->th, hint->inode,
7291 @@ -1129,10 +1147,10 @@ static inline int blocknrs_and_prealloc_
7292                                REISERFS_I(hint->inode)->i_prealloc_count,
7293                                hint->inode->i_uid);
7294  #endif
7295 -               DQUOT_FREE_BLOCK_NODIRTY(hint->inode, amount_needed +
7296 -                                        hint->prealloc_size - nr_allocated -
7297 -                                        REISERFS_I(hint->inode)->
7298 -                                        i_prealloc_count);
7299 +               blocks = amount_needed + hint->prealloc_size - nr_allocated -
7300 +                       REISERFS_I(hint->inode)->i_prealloc_count;
7301 +               DLIMIT_FREE_BLOCK(hint->inode, blocks);
7302 +               DQUOT_FREE_BLOCK_NODIRTY(hint->inode, blocks);
7303         }
7304  
7305         return CARRY_ON;
7306 diff -NurpP --minimal linux-2.6.29.1/fs/reiserfs/file.c linux-2.6.29.1-vs2.3.0.36.9-pre5/fs/reiserfs/file.c
7307 --- linux-2.6.29.1/fs/reiserfs/file.c   2008-12-25 00:26:37.000000000 +0100
7308 +++ linux-2.6.29.1-vs2.3.0.36.9-pre5/fs/reiserfs/file.c 2009-02-22 22:54:25.000000000 +0100
7309 @@ -307,4 +307,5 @@ const struct inode_operations reiserfs_f
7310         .listxattr = reiserfs_listxattr,
7311         .removexattr = reiserfs_removexattr,
7312         .permission = reiserfs_permission,
7313 +       .sync_flags = reiserfs_sync_flags,
7314  };
7315 diff -NurpP --minimal linux-2.6.29.1/fs/reiserfs/inode.c linux-2.6.29.1-vs2.3.0.36.9-pre5/fs/reiserfs/inode.c
7316 --- linux-2.6.29.1/fs/reiserfs/inode.c  2009-03-24 14:22:27.000000000 +0100
7317 +++ linux-2.6.29.1-vs2.3.0.36.9-pre5/fs/reiserfs/inode.c        2009-03-24 14:48:35.000000000 +0100
7318 @@ -18,6 +18,8 @@
7319  #include <linux/writeback.h>
7320  #include <linux/quotaops.h>
7321  #include <linux/swap.h>
7322 +#include <linux/vs_dlimit.h>
7323 +#include <linux/vs_tag.h>
7324  
7325  int reiserfs_commit_write(struct file *f, struct page *page,
7326                           unsigned from, unsigned to);
7327 @@ -54,6 +56,7 @@ void reiserfs_delete_inode(struct inode 
7328                  * stat data deletion */
7329                 if (!err) 
7330                         DQUOT_FREE_INODE(inode);
7331 +               DLIMIT_FREE_INODE(inode);
7332  
7333                 if (journal_end(&th, inode->i_sb, jbegin_count))
7334                         goto out;
7335 @@ -1116,6 +1119,8 @@ static void init_inode(struct inode *ino
7336         struct buffer_head *bh;
7337         struct item_head *ih;
7338         __u32 rdev;
7339 +       uid_t uid;
7340 +       gid_t gid;
7341         //int version = ITEM_VERSION_1;
7342  
7343         bh = PATH_PLAST_BUFFER(path);
7344 @@ -1139,12 +1144,13 @@ static void init_inode(struct inode *ino
7345                     (struct stat_data_v1 *)B_I_PITEM(bh, ih);
7346                 unsigned long blocks;
7347  
7348 +               uid = sd_v1_uid(sd);
7349 +               gid = sd_v1_gid(sd);
7350 +
7351                 set_inode_item_key_version(inode, KEY_FORMAT_3_5);
7352                 set_inode_sd_version(inode, STAT_DATA_V1);
7353                 inode->i_mode = sd_v1_mode(sd);
7354                 inode->i_nlink = sd_v1_nlink(sd);
7355 -               inode->i_uid = sd_v1_uid(sd);
7356 -               inode->i_gid = sd_v1_gid(sd);
7357                 inode->i_size = sd_v1_size(sd);
7358                 inode->i_atime.tv_sec = sd_v1_atime(sd);
7359                 inode->i_mtime.tv_sec = sd_v1_mtime(sd);
7360 @@ -1186,11 +1192,12 @@ static void init_inode(struct inode *ino
7361                 // (directories and symlinks)
7362                 struct stat_data *sd = (struct stat_data *)B_I_PITEM(bh, ih);
7363  
7364 +               uid    = sd_v2_uid(sd);
7365 +               gid    = sd_v2_gid(sd);
7366 +
7367                 inode->i_mode = sd_v2_mode(sd);
7368                 inode->i_nlink = sd_v2_nlink(sd);
7369 -               inode->i_uid = sd_v2_uid(sd);
7370                 inode->i_size = sd_v2_size(sd);
7371 -               inode->i_gid = sd_v2_gid(sd);
7372                 inode->i_mtime.tv_sec = sd_v2_mtime(sd);
7373                 inode->i_atime.tv_sec = sd_v2_atime(sd);
7374                 inode->i_ctime.tv_sec = sd_v2_ctime(sd);
7375 @@ -1220,6 +1227,10 @@ static void init_inode(struct inode *ino
7376                 sd_attrs_to_i_attrs(sd_v2_attrs(sd), inode);
7377         }
7378  
7379 +       inode->i_uid = INOTAG_UID(DX_TAG(inode), uid, gid);
7380 +       inode->i_gid = INOTAG_GID(DX_TAG(inode), uid, gid);
7381 +       inode->i_tag = INOTAG_TAG(DX_TAG(inode), uid, gid, 0);
7382 +
7383         pathrelse(path);
7384         if (S_ISREG(inode->i_mode)) {
7385                 inode->i_op = &reiserfs_file_inode_operations;
7386 @@ -1242,13 +1253,15 @@ static void init_inode(struct inode *ino
7387  static void inode2sd(void *sd, struct inode *inode, loff_t size)
7388  {
7389         struct stat_data *sd_v2 = (struct stat_data *)sd;
7390 +       uid_t uid = TAGINO_UID(DX_TAG(inode), inode->i_uid, inode->i_tag);
7391 +       gid_t gid = TAGINO_GID(DX_TAG(inode), inode->i_gid, inode->i_tag);
7392         __u16 flags;
7393  
7394 +       set_sd_v2_uid(sd_v2, uid);
7395 +       set_sd_v2_gid(sd_v2, gid);
7396         set_sd_v2_mode(sd_v2, inode->i_mode);
7397         set_sd_v2_nlink(sd_v2, inode->i_nlink);
7398 -       set_sd_v2_uid(sd_v2, inode->i_uid);
7399         set_sd_v2_size(sd_v2, size);
7400 -       set_sd_v2_gid(sd_v2, inode->i_gid);
7401         set_sd_v2_mtime(sd_v2, inode->i_mtime.tv_sec);
7402         set_sd_v2_atime(sd_v2, inode->i_atime.tv_sec);
7403         set_sd_v2_ctime(sd_v2, inode->i_ctime.tv_sec);
7404 @@ -1763,6 +1776,10 @@ int reiserfs_new_inode(struct reiserfs_t
7405  
7406         BUG_ON(!th->t_trans_id);
7407  
7408 +       if (DLIMIT_ALLOC_INODE(inode)) {
7409 +               err = -ENOSPC;
7410 +               goto out_bad_dlimit;
7411 +       }
7412         if (DQUOT_ALLOC_INODE(inode)) {
7413                 err = -EDQUOT;
7414                 goto out_end_trans;
7415 @@ -1950,6 +1967,9 @@ int reiserfs_new_inode(struct reiserfs_t
7416         DQUOT_FREE_INODE(inode);
7417  
7418        out_end_trans:
7419 +       DLIMIT_FREE_INODE(inode);
7420 +
7421 +      out_bad_dlimit:
7422         journal_end(th, th->t_super, th->t_blocks_allocated);
7423         /* Drop can be outside and it needs more credits so it's better to have it outside */
7424         DQUOT_DROP(inode);
7425 @@ -2837,14 +2857,19 @@ int reiserfs_commit_write(struct file *f
7426  void sd_attrs_to_i_attrs(__u16 sd_attrs, struct inode *inode)
7427  {
7428         if (reiserfs_attrs(inode->i_sb)) {
7429 -               if (sd_attrs & REISERFS_SYNC_FL)
7430 -                       inode->i_flags |= S_SYNC;
7431 -               else
7432 -                       inode->i_flags &= ~S_SYNC;
7433                 if (sd_attrs & REISERFS_IMMUTABLE_FL)
7434                         inode->i_flags |= S_IMMUTABLE;
7435                 else
7436                         inode->i_flags &= ~S_IMMUTABLE;
7437 +               if (sd_attrs & REISERFS_IXUNLINK_FL)
7438 +                       inode->i_flags |= S_IXUNLINK;
7439 +               else
7440 +                       inode->i_flags &= ~S_IXUNLINK;
7441 +
7442 +               if (sd_attrs & REISERFS_SYNC_FL)
7443 +                       inode->i_flags |= S_SYNC;
7444 +               else
7445 +                       inode->i_flags &= ~S_SYNC;
7446                 if (sd_attrs & REISERFS_APPEND_FL)
7447                         inode->i_flags |= S_APPEND;
7448                 else
7449 @@ -2857,6 +2882,15 @@ void sd_attrs_to_i_attrs(__u16 sd_attrs,
7450                         REISERFS_I(inode)->i_flags |= i_nopack_mask;
7451                 else
7452                         REISERFS_I(inode)->i_flags &= ~i_nopack_mask;
7453 +
7454 +               if (sd_attrs & REISERFS_BARRIER_FL)
7455 +                       inode->i_vflags |= V_BARRIER;
7456 +               else
7457 +                       inode->i_vflags &= ~V_BARRIER;
7458 +               if (sd_attrs & REISERFS_COW_FL)
7459 +                       inode->i_vflags |= V_COW;
7460 +               else
7461 +                       inode->i_vflags &= ~V_COW;
7462         }
7463  }
7464  
7465 @@ -2867,6 +2901,11 @@ void i_attrs_to_sd_attrs(struct inode *i
7466                         *sd_attrs |= REISERFS_IMMUTABLE_FL;
7467                 else
7468                         *sd_attrs &= ~REISERFS_IMMUTABLE_FL;
7469 +               if (inode->i_flags & S_IXUNLINK)
7470 +                       *sd_attrs |= REISERFS_IXUNLINK_FL;
7471 +               else
7472 +                       *sd_attrs &= ~REISERFS_IXUNLINK_FL;
7473 +
7474                 if (inode->i_flags & S_SYNC)
7475                         *sd_attrs |= REISERFS_SYNC_FL;
7476                 else
7477 @@ -2879,6 +2918,15 @@ void i_attrs_to_sd_attrs(struct inode *i
7478                         *sd_attrs |= REISERFS_NOTAIL_FL;
7479                 else
7480                         *sd_attrs &= ~REISERFS_NOTAIL_FL;
7481 +
7482 +               if (inode->i_vflags & V_BARRIER)
7483 +                       *sd_attrs |= REISERFS_BARRIER_FL;
7484 +               else
7485 +                       *sd_attrs &= ~REISERFS_BARRIER_FL;
7486 +               if (inode->i_vflags & V_COW)
7487 +                       *sd_attrs |= REISERFS_COW_FL;
7488 +               else
7489 +                       *sd_attrs &= ~REISERFS_COW_FL;
7490         }
7491  }
7492  
7493 @@ -3046,6 +3094,22 @@ static ssize_t reiserfs_direct_IO(int rw
7494                                   reiserfs_get_blocks_direct_io, NULL);
7495  }
7496  
7497 +int reiserfs_sync_flags(struct inode *inode)
7498 +{
7499 +       u16 oldflags, newflags;
7500 +
7501 +       oldflags = REISERFS_I(inode)->i_attrs;
7502 +       newflags = oldflags;
7503 +       i_attrs_to_sd_attrs(inode, &newflags);
7504 +
7505 +       if (oldflags ^ newflags) {
7506 +               REISERFS_I(inode)->i_attrs = newflags;
7507 +               inode->i_ctime = CURRENT_TIME_SEC;
7508 +               mark_inode_dirty(inode);
7509 +       }
7510 +       return 0;
7511 +}
7512 +
7513  int reiserfs_setattr(struct dentry *dentry, struct iattr *attr)
7514  {
7515         struct inode *inode = dentry->d_inode;
7516 @@ -3099,9 +3163,11 @@ int reiserfs_setattr(struct dentry *dent
7517         }
7518  
7519         error = inode_change_ok(inode, attr);
7520 +
7521         if (!error) {
7522                 if ((ia_valid & ATTR_UID && attr->ia_uid != inode->i_uid) ||
7523 -                   (ia_valid & ATTR_GID && attr->ia_gid != inode->i_gid)) {
7524 +                   (ia_valid & ATTR_GID && attr->ia_gid != inode->i_gid) ||
7525 +                   (ia_valid & ATTR_TAG && attr->ia_tag != inode->i_tag)) {
7526                         error = reiserfs_chown_xattrs(inode, attr);
7527  
7528                         if (!error) {
7529 @@ -3131,6 +3197,9 @@ int reiserfs_setattr(struct dentry *dent
7530                                         inode->i_uid = attr->ia_uid;
7531                                 if (attr->ia_valid & ATTR_GID)
7532                                         inode->i_gid = attr->ia_gid;
7533 +                               if ((attr->ia_valid & ATTR_TAG) &&
7534 +                                       IS_TAGGED(inode))
7535 +                                       inode->i_tag = attr->ia_tag;
7536                                 mark_inode_dirty(inode);
7537                                 error =
7538                                     journal_end(&th, inode->i_sb, jbegin_count);
7539 diff -NurpP --minimal linux-2.6.29.1/fs/reiserfs/ioctl.c linux-2.6.29.1-vs2.3.0.36.9-pre5/fs/reiserfs/ioctl.c
7540 --- linux-2.6.29.1/fs/reiserfs/ioctl.c  2008-12-25 00:26:37.000000000 +0100
7541 +++ linux-2.6.29.1-vs2.3.0.36.9-pre5/fs/reiserfs/ioctl.c        2009-02-22 22:54:25.000000000 +0100
7542 @@ -7,6 +7,7 @@
7543  #include <linux/mount.h>
7544  #include <linux/reiserfs_fs.h>
7545  #include <linux/time.h>
7546 +#include <linux/mount.h>
7547  #include <asm/uaccess.h>
7548  #include <linux/pagemap.h>
7549  #include <linux/smp_lock.h>
7550 @@ -23,7 +24,7 @@
7551  int reiserfs_ioctl(struct inode *inode, struct file *filp, unsigned int cmd,
7552                    unsigned long arg)
7553  {
7554 -       unsigned int flags;
7555 +       unsigned int flags, oldflags;
7556         int err = 0;
7557  
7558         switch (cmd) {
7559 @@ -43,6 +44,7 @@ int reiserfs_ioctl(struct inode *inode, 
7560  
7561                 flags = REISERFS_I(inode)->i_attrs;
7562                 i_attrs_to_sd_attrs(inode, (__u16 *) & flags);
7563 +               flags &= REISERFS_FL_USER_VISIBLE;
7564                 return put_user(flags, (int __user *)arg);
7565         case REISERFS_IOC_SETFLAGS:{
7566                         if (!reiserfs_attrs(inode->i_sb))
7567 @@ -60,6 +62,10 @@ int reiserfs_ioctl(struct inode *inode, 
7568                                 err = -EFAULT;
7569                                 goto setflags_out;
7570                         }
7571 +                       if (IS_BARRIER(inode)) {
7572 +                               vxwprintk_task(1, "messing with the barrier.");
7573 +                               return -EACCES;
7574 +                       }
7575                         /*
7576                          * Is it quota file? Do not allow user to mess with it
7577                          */
7578 @@ -84,6 +90,10 @@ int reiserfs_ioctl(struct inode *inode, 
7579                                         goto setflags_out;
7580                                 }
7581                         }
7582 +
7583 +                       oldflags = REISERFS_I(inode)->i_attrs;
7584 +                       flags = flags & REISERFS_FL_USER_MODIFIABLE;
7585 +                       flags |= oldflags & ~REISERFS_FL_USER_MODIFIABLE;
7586                         sd_attrs_to_i_attrs(flags, inode);
7587                         REISERFS_I(inode)->i_attrs = flags;
7588                         inode->i_ctime = CURRENT_TIME_SEC;
7589 diff -NurpP --minimal linux-2.6.29.1/fs/reiserfs/namei.c linux-2.6.29.1-vs2.3.0.36.9-pre5/fs/reiserfs/namei.c
7590 --- linux-2.6.29.1/fs/reiserfs/namei.c  2009-03-24 14:22:27.000000000 +0100
7591 +++ linux-2.6.29.1-vs2.3.0.36.9-pre5/fs/reiserfs/namei.c        2009-03-24 14:48:35.000000000 +0100
7592 @@ -17,6 +17,7 @@
7593  #include <linux/reiserfs_acl.h>
7594  #include <linux/reiserfs_xattr.h>
7595  #include <linux/quotaops.h>
7596 +#include <linux/vs_tag.h>
7597  
7598  #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; }
7599  #define DEC_DIR_INODE_NLINK(i) if (i->i_nlink != 1) drop_nlink(i);
7600 @@ -360,6 +361,7 @@ static struct dentry *reiserfs_lookup(st
7601                         reiserfs_write_unlock(dir->i_sb);
7602                         return ERR_PTR(-EACCES);
7603                 }
7604 +               dx_propagate_tag(nd, inode);
7605  
7606                 /* Propogate the priv_object flag so we know we're in the priv tree */
7607                 if (is_reiserfs_priv_object(dir))
7608 @@ -586,6 +588,7 @@ static int new_inode_init(struct inode *
7609         } else {
7610                 inode->i_gid = current_fsgid();
7611         }
7612 +       inode->i_tag = dx_current_fstag(inode->i_sb);
7613         DQUOT_INIT(inode);
7614         return 0;
7615  }
7616 @@ -1540,6 +1543,7 @@ const struct inode_operations reiserfs_d
7617         .listxattr = reiserfs_listxattr,
7618         .removexattr = reiserfs_removexattr,
7619         .permission = reiserfs_permission,
7620 +       .sync_flags = reiserfs_sync_flags,
7621  };
7622  
7623  /*
7624 @@ -1556,6 +1560,7 @@ const struct inode_operations reiserfs_s
7625         .listxattr = reiserfs_listxattr,
7626         .removexattr = reiserfs_removexattr,
7627         .permission = reiserfs_permission,
7628 +       .sync_flags = reiserfs_sync_flags,
7629  
7630  };
7631  
7632 @@ -1569,5 +1574,6 @@ const struct inode_operations reiserfs_s
7633         .listxattr = reiserfs_listxattr,
7634         .removexattr = reiserfs_removexattr,
7635         .permission = reiserfs_permission,
7636 +       .sync_flags = reiserfs_sync_flags,
7637  
7638  };
7639 diff -NurpP --minimal linux-2.6.29.1/fs/reiserfs/stree.c linux-2.6.29.1-vs2.3.0.36.9-pre5/fs/reiserfs/stree.c
7640 --- linux-2.6.29.1/fs/reiserfs/stree.c  2008-12-25 00:26:37.000000000 +0100
7641 +++ linux-2.6.29.1-vs2.3.0.36.9-pre5/fs/reiserfs/stree.c        2009-02-22 22:54:25.000000000 +0100
7642 @@ -55,6 +55,7 @@
7643  #include <linux/reiserfs_fs.h>
7644  #include <linux/buffer_head.h>
7645  #include <linux/quotaops.h>
7646 +#include <linux/vs_dlimit.h>
7647  
7648  /* Does the buffer contain a disk block which is in the tree. */
7649  inline int B_IS_IN_TREE(const struct buffer_head *p_s_bh)
7650 @@ -1297,6 +1298,7 @@ int reiserfs_delete_item(struct reiserfs
7651                        "reiserquota delete_item(): freeing %u, id=%u type=%c",
7652                        quota_cut_bytes, p_s_inode->i_uid, head2type(&s_ih));
7653  #endif
7654 +       DLIMIT_FREE_SPACE(p_s_inode, quota_cut_bytes);
7655         DQUOT_FREE_SPACE_NODIRTY(p_s_inode, quota_cut_bytes);
7656  
7657         /* Return deleted body length */
7658 @@ -1385,6 +1387,7 @@ void reiserfs_delete_solid_item(struct r
7659  #endif
7660                                 DQUOT_FREE_SPACE_NODIRTY(inode,
7661                                                          quota_cut_bytes);
7662 +                               DLIMIT_FREE_SPACE(inode, quota_cut_bytes);
7663                         }
7664                         break;
7665                 }
7666 @@ -1734,6 +1737,7 @@ int reiserfs_cut_from_item(struct reiser
7667                        "reiserquota cut_from_item(): freeing %u id=%u type=%c",
7668                        quota_cut_bytes, p_s_inode->i_uid, '?');
7669  #endif
7670 +       DLIMIT_FREE_SPACE(p_s_inode, quota_cut_bytes);
7671         DQUOT_FREE_SPACE_NODIRTY(p_s_inode, quota_cut_bytes);
7672         return n_ret_value;
7673  }
7674 @@ -1975,6 +1979,11 @@ int reiserfs_paste_into_item(struct reis
7675                 pathrelse(p_s_search_path);
7676                 return -EDQUOT;
7677         }
7678 +       if (DLIMIT_ALLOC_SPACE(inode, n_pasted_size)) {
7679 +               DQUOT_FREE_SPACE_NODIRTY(inode, n_pasted_size);
7680 +               pathrelse(p_s_search_path);
7681 +               return -ENOSPC;
7682 +       }
7683         init_tb_struct(th, &s_paste_balance, th->t_super, p_s_search_path,
7684                        n_pasted_size);
7685  #ifdef DISPLACE_NEW_PACKING_LOCALITIES
7686 @@ -2027,6 +2036,7 @@ int reiserfs_paste_into_item(struct reis
7687                        n_pasted_size, inode->i_uid,
7688                        key2type(&(p_s_key->on_disk_key)));
7689  #endif
7690 +       DLIMIT_FREE_SPACE(inode, n_pasted_size);
7691         DQUOT_FREE_SPACE_NODIRTY(inode, n_pasted_size);
7692         return retval;
7693  }
7694 @@ -2064,6 +2074,11 @@ int reiserfs_insert_item(struct reiserfs
7695                         pathrelse(p_s_path);
7696                         return -EDQUOT;
7697                 }
7698 +               if (DLIMIT_ALLOC_SPACE(inode, quota_bytes)) {
7699 +                       DQUOT_FREE_SPACE_NODIRTY(inode, quota_bytes);
7700 +                       pathrelse(p_s_path);
7701 +                       return -ENOSPC;
7702 +               }
7703         }
7704         init_tb_struct(th, &s_ins_balance, th->t_super, p_s_path,
7705                        IH_SIZE + ih_item_len(p_s_ih));
7706 @@ -2111,7 +2126,9 @@ int reiserfs_insert_item(struct reiserfs
7707                        "reiserquota insert_item(): freeing %u id=%u type=%c",
7708                        quota_bytes, inode->i_uid, head2type(p_s_ih));
7709  #endif
7710 -       if (inode)
7711 +       if (inode) {
7712 +               DLIMIT_FREE_SPACE(inode, quota_bytes);
7713                 DQUOT_FREE_SPACE_NODIRTY(inode, quota_bytes);
7714 +       }
7715         return retval;
7716  }
7717 diff -NurpP --minimal linux-2.6.29.1/fs/reiserfs/super.c linux-2.6.29.1-vs2.3.0.36.9-pre5/fs/reiserfs/super.c
7718 --- linux-2.6.29.1/fs/reiserfs/super.c  2009-03-24 14:22:27.000000000 +0100
7719 +++ linux-2.6.29.1-vs2.3.0.36.9-pre5/fs/reiserfs/super.c        2009-03-24 14:48:35.000000000 +0100
7720 @@ -902,6 +902,14 @@ static int reiserfs_parse_options(struct
7721                 {"user_xattr",.setmask = 1 << REISERFS_UNSUPPORTED_OPT},
7722                 {"nouser_xattr",.clrmask = 1 << REISERFS_UNSUPPORTED_OPT},
7723  #endif
7724 +#ifndef CONFIG_TAGGING_NONE
7725 +               {"tagxid",.setmask = 1 << REISERFS_TAGGED},
7726 +               {"tag",.setmask = 1 << REISERFS_TAGGED},
7727 +               {"notag",.clrmask = 1 << REISERFS_TAGGED},
7728 +#endif
7729 +#ifdef CONFIG_PROPAGATE
7730 +               {"tag",.arg_required = 'T',.values = NULL},
7731 +#endif
7732  #ifdef CONFIG_REISERFS_FS_POSIX_ACL
7733                 {"acl",.setmask = 1 << REISERFS_POSIXACL},
7734                 {"noacl",.clrmask = 1 << REISERFS_POSIXACL},
7735 @@ -1195,6 +1203,12 @@ static int reiserfs_remount(struct super
7736         handle_quota_files(s, qf_names, &qfmt);
7737  #endif
7738  
7739 +       if ((mount_options & (1 << REISERFS_TAGGED)) &&
7740 +               !(s->s_flags & MS_TAGGED)) {
7741 +               reiserfs_warning(s, "reiserfs: tagging not permitted on remount.");
7742 +               return -EINVAL;
7743 +       }
7744 +
7745         handle_attrs(s);
7746  
7747         /* Add options that are safe here */
7748 @@ -1659,6 +1673,10 @@ static int reiserfs_fill_super(struct su
7749                 goto error;
7750         }
7751  
7752 +       /* map mount option tagxid */
7753 +       if (REISERFS_SB(s)->s_mount_opt & (1 << REISERFS_TAGGED))
7754 +               s->s_flags |= MS_TAGGED;
7755 +
7756         rs = SB_DISK_SUPER_BLOCK(s);
7757         /* Let's do basic sanity check to verify that underlying device is not
7758            smaller than the filesystem. If the check fails then abort and scream,
7759 diff -NurpP --minimal linux-2.6.29.1/fs/reiserfs/xattr.c linux-2.6.29.1-vs2.3.0.36.9-pre5/fs/reiserfs/xattr.c
7760 --- linux-2.6.29.1/fs/reiserfs/xattr.c  2008-12-25 00:26:37.000000000 +0100
7761 +++ linux-2.6.29.1-vs2.3.0.36.9-pre5/fs/reiserfs/xattr.c        2009-02-22 22:54:25.000000000 +0100
7762 @@ -35,6 +35,7 @@
7763  #include <linux/namei.h>
7764  #include <linux/errno.h>
7765  #include <linux/fs.h>
7766 +#include <linux/mount.h>
7767  #include <linux/file.h>
7768  #include <linux/pagemap.h>
7769  #include <linux/xattr.h>
7770 diff -NurpP --minimal linux-2.6.29.1/fs/stat.c linux-2.6.29.1-vs2.3.0.36.9-pre5/fs/stat.c
7771 --- linux-2.6.29.1/fs/stat.c    2009-03-24 14:22:36.000000000 +0100
7772 +++ linux-2.6.29.1-vs2.3.0.36.9-pre5/fs/stat.c  2009-03-24 14:48:35.000000000 +0100
7773 @@ -26,6 +26,7 @@ void generic_fillattr(struct inode *inod
7774         stat->nlink = inode->i_nlink;
7775         stat->uid = inode->i_uid;
7776         stat->gid = inode->i_gid;
7777 +       stat->tag = inode->i_tag;
7778         stat->rdev = inode->i_rdev;
7779         stat->atime = inode->i_atime;
7780         stat->mtime = inode->i_mtime;
7781 diff -NurpP --minimal linux-2.6.29.1/fs/super.c linux-2.6.29.1-vs2.3.0.36.9-pre5/fs/super.c
7782 --- linux-2.6.29.1/fs/super.c   2009-03-24 14:22:36.000000000 +0100
7783 +++ linux-2.6.29.1-vs2.3.0.36.9-pre5/fs/super.c 2009-03-24 16:32:06.000000000 +0100
7784 @@ -39,6 +39,9 @@
7785  #include <linux/mutex.h>
7786  #include <linux/file.h>
7787  #include <linux/async.h>
7788 +#include <linux/devpts_fs.h>
7789 +#include <linux/proc_fs.h>
7790 +#include <linux/vs_context.h>
7791  #include <asm/uaccess.h>
7792  #include "internal.h"
7793  
7794 @@ -918,12 +921,18 @@ struct vfsmount *
7795  vfs_kern_mount(struct file_system_type *type, int flags, const char *name, void *data)
7796  {
7797         struct vfsmount *mnt;
7798 +       struct super_block *sb;
7799         char *secdata = NULL;
7800         int error;
7801  
7802         if (!type)
7803                 return ERR_PTR(-ENODEV);
7804  
7805 +       error = -EPERM;
7806 +       if ((type->fs_flags & FS_BINARY_MOUNTDATA) &&
7807 +               !vx_capable(CAP_SYS_ADMIN, VXC_BINARY_MOUNT))
7808 +               goto out;
7809 +
7810         error = -ENOMEM;
7811         mnt = alloc_vfsmnt(name);
7812         if (!mnt)
7813 @@ -942,9 +951,17 @@ vfs_kern_mount(struct file_system_type *
7814         error = type->get_sb(type, flags, name, data, mnt);
7815         if (error < 0)
7816                 goto out_free_secdata;
7817 -       BUG_ON(!mnt->mnt_sb);
7818  
7819 -       error = security_sb_kern_mount(mnt->mnt_sb, flags, secdata);
7820 +       sb = mnt->mnt_sb;
7821 +       BUG_ON(!sb);
7822 +
7823 +       error = -EPERM;
7824 +       if (!vx_capable(CAP_SYS_ADMIN, VXC_BINARY_MOUNT) && !sb->s_bdev &&
7825 +               (sb->s_magic != PROC_SUPER_MAGIC) &&
7826 +               (sb->s_magic != DEVPTS_SUPER_MAGIC))
7827 +               goto out_sb;
7828 +
7829 +       error = security_sb_kern_mount(sb, flags, secdata);
7830         if (error)
7831                 goto out_sb;
7832  
7833 diff -NurpP --minimal linux-2.6.29.1/fs/sysfs/mount.c linux-2.6.29.1-vs2.3.0.36.9-pre5/fs/sysfs/mount.c
7834 --- linux-2.6.29.1/fs/sysfs/mount.c     2008-12-25 00:26:37.000000000 +0100
7835 +++ linux-2.6.29.1-vs2.3.0.36.9-pre5/fs/sysfs/mount.c   2009-02-22 22:54:25.000000000 +0100
7836 @@ -20,8 +20,6 @@
7837  
7838  #include "sysfs.h"
7839  
7840 -/* Random magic number */
7841 -#define SYSFS_MAGIC 0x62656572
7842  
7843  static struct vfsmount *sysfs_mount;
7844  struct super_block * sysfs_sb = NULL;
7845 @@ -47,7 +45,7 @@ static int sysfs_fill_super(struct super
7846  
7847         sb->s_blocksize = PAGE_CACHE_SIZE;
7848         sb->s_blocksize_bits = PAGE_CACHE_SHIFT;
7849 -       sb->s_magic = SYSFS_MAGIC;
7850 +       sb->s_magic = SYSFS_SUPER_MAGIC;
7851         sb->s_op = &sysfs_ops;
7852         sb->s_time_gran = 1;
7853         sysfs_sb = sb;
7854 diff -NurpP --minimal linux-2.6.29.1/fs/utimes.c linux-2.6.29.1-vs2.3.0.36.9-pre5/fs/utimes.c
7855 --- linux-2.6.29.1/fs/utimes.c  2009-03-24 14:22:37.000000000 +0100
7856 +++ linux-2.6.29.1-vs2.3.0.36.9-pre5/fs/utimes.c        2009-02-22 22:54:25.000000000 +0100
7857 @@ -8,6 +8,8 @@
7858  #include <linux/stat.h>
7859  #include <linux/utime.h>
7860  #include <linux/syscalls.h>
7861 +#include <linux/mount.h>
7862 +#include <linux/vs_cowbl.h>
7863  #include <asm/uaccess.h>
7864  #include <asm/unistd.h>
7865  
7866 diff -NurpP --minimal linux-2.6.29.1/fs/xattr.c linux-2.6.29.1-vs2.3.0.36.9-pre5/fs/xattr.c
7867 --- linux-2.6.29.1/fs/xattr.c   2009-03-24 14:22:37.000000000 +0100
7868 +++ linux-2.6.29.1-vs2.3.0.36.9-pre5/fs/xattr.c 2009-03-24 14:48:35.000000000 +0100
7869 @@ -18,6 +18,7 @@
7870  #include <linux/module.h>
7871  #include <linux/fsnotify.h>
7872  #include <linux/audit.h>
7873 +#include <linux/mount.h>
7874  #include <asm/uaccess.h>
7875  
7876  
7877 diff -NurpP --minimal linux-2.6.29.1/fs/xfs/linux-2.6/xfs_ioctl.c linux-2.6.29.1-vs2.3.0.36.9-pre5/fs/xfs/linux-2.6/xfs_ioctl.c
7878 --- linux-2.6.29.1/fs/xfs/linux-2.6/xfs_ioctl.c 2009-03-24 14:22:37.000000000 +0100
7879 +++ linux-2.6.29.1-vs2.3.0.36.9-pre5/fs/xfs/linux-2.6/xfs_ioctl.c       2009-03-24 14:48:35.000000000 +0100
7880 @@ -769,6 +769,10 @@ xfs_merge_ioc_xflags(
7881                 xflags |= XFS_XFLAG_IMMUTABLE;
7882         else
7883                 xflags &= ~XFS_XFLAG_IMMUTABLE;
7884 +       if (flags & FS_IXUNLINK_FL)
7885 +               xflags |= XFS_XFLAG_IXUNLINK;
7886 +       else
7887 +               xflags &= ~XFS_XFLAG_IXUNLINK;
7888         if (flags & FS_APPEND_FL)
7889                 xflags |= XFS_XFLAG_APPEND;
7890         else
7891 @@ -797,6 +801,8 @@ xfs_di2lxflags(
7892  
7893         if (di_flags & XFS_DIFLAG_IMMUTABLE)
7894                 flags |= FS_IMMUTABLE_FL;
7895 +       if (di_flags & XFS_DIFLAG_IXUNLINK)
7896 +               flags |= FS_IXUNLINK_FL;
7897         if (di_flags & XFS_DIFLAG_APPEND)
7898                 flags |= FS_APPEND_FL;
7899         if (di_flags & XFS_DIFLAG_SYNC)
7900 @@ -855,6 +861,8 @@ xfs_set_diflags(
7901         di_flags = (ip->i_d.di_flags & XFS_DIFLAG_PREALLOC);
7902         if (xflags & XFS_XFLAG_IMMUTABLE)
7903                 di_flags |= XFS_DIFLAG_IMMUTABLE;
7904 +       if (xflags & XFS_XFLAG_IXUNLINK)
7905 +               di_flags |= XFS_DIFLAG_IXUNLINK;
7906         if (xflags & XFS_XFLAG_APPEND)
7907                 di_flags |= XFS_DIFLAG_APPEND;
7908         if (xflags & XFS_XFLAG_SYNC)
7909 @@ -897,6 +905,10 @@ xfs_diflags_to_linux(
7910                 inode->i_flags |= S_IMMUTABLE;
7911         else
7912                 inode->i_flags &= ~S_IMMUTABLE;
7913 +       if (xflags & XFS_XFLAG_IXUNLINK)
7914 +               inode->i_flags |= S_IXUNLINK;
7915 +       else
7916 +               inode->i_flags &= ~S_IXUNLINK;
7917         if (xflags & XFS_XFLAG_APPEND)
7918                 inode->i_flags |= S_APPEND;
7919         else
7920 @@ -1371,10 +1383,18 @@ xfs_file_ioctl(
7921         case XFS_IOC_FSGETXATTRA:
7922                 return xfs_ioc_fsgetxattr(ip, 1, arg);
7923         case XFS_IOC_FSSETXATTR:
7924 +               if (IS_BARRIER(inode)) {
7925 +                       vxwprintk_task(1, "messing with the barrier.");
7926 +                       return -XFS_ERROR(EACCES);
7927 +               }
7928                 return xfs_ioc_fssetxattr(ip, filp, arg);
7929         case XFS_IOC_GETXFLAGS:
7930                 return xfs_ioc_getxflags(ip, arg);
7931         case XFS_IOC_SETXFLAGS:
7932 +               if (IS_BARRIER(inode)) {
7933 +                       vxwprintk_task(1, "messing with the barrier.");
7934 +                       return -XFS_ERROR(EACCES);
7935 +               }
7936                 return xfs_ioc_setxflags(ip, filp, arg);
7937  
7938         case XFS_IOC_FSSETDM: {
7939 diff -NurpP --minimal linux-2.6.29.1/fs/xfs/linux-2.6/xfs_iops.c linux-2.6.29.1-vs2.3.0.36.9-pre5/fs/xfs/linux-2.6/xfs_iops.c
7940 --- linux-2.6.29.1/fs/xfs/linux-2.6/xfs_iops.c  2009-03-24 14:22:37.000000000 +0100
7941 +++ linux-2.6.29.1-vs2.3.0.36.9-pre5/fs/xfs/linux-2.6/xfs_iops.c        2009-03-24 16:33:10.000000000 +0100
7942 @@ -54,6 +54,7 @@
7943  #include <linux/security.h>
7944  #include <linux/falloc.h>
7945  #include <linux/fiemap.h>
7946 +#include <linux/vs_tag.h>
7947  
7948  /*
7949   * Bring the atime in the XFS inode uptodate.
7950 @@ -552,6 +553,7 @@ xfs_vn_getattr(
7951         stat->nlink = ip->i_d.di_nlink;
7952         stat->uid = ip->i_d.di_uid;
7953         stat->gid = ip->i_d.di_gid;
7954 +       stat->tag = ip->i_d.di_tag;
7955         stat->ino = ip->i_ino;
7956  #if XFS_BIG_INUMS
7957         stat->ino += mp->m_inoadd;
7958 @@ -591,6 +593,12 @@ xfs_vn_getattr(
7959  }
7960  
7961  STATIC int
7962 +xfs_vn_sync_xflags(struct inode *inode)
7963 +{
7964 +       return -xfs_sync_xflags(XFS_I(inode));
7965 +}
7966 +
7967 +STATIC int
7968  xfs_vn_setattr(
7969         struct dentry   *dentry,
7970         struct iattr    *iattr)
7971 @@ -748,6 +756,7 @@ static const struct inode_operations xfs
7972         .listxattr              = xfs_vn_listxattr,
7973         .fallocate              = xfs_vn_fallocate,
7974         .fiemap                 = xfs_vn_fiemap,
7975 +       .sync_flags             = xfs_vn_sync_xflags,
7976  };
7977  
7978  static const struct inode_operations xfs_dir_inode_operations = {
7979 @@ -773,6 +782,7 @@ static const struct inode_operations xfs
7980         .getxattr               = generic_getxattr,
7981         .removexattr            = generic_removexattr,
7982         .listxattr              = xfs_vn_listxattr,
7983 +       .sync_flags             = xfs_vn_sync_xflags,
7984  };
7985  
7986  static const struct inode_operations xfs_dir_ci_inode_operations = {
7987 @@ -822,6 +832,10 @@ xfs_diflags_to_iflags(
7988                 inode->i_flags |= S_IMMUTABLE;
7989         else
7990                 inode->i_flags &= ~S_IMMUTABLE;
7991 +       if (ip->i_d.di_flags & XFS_DIFLAG_IXUNLINK)
7992 +               inode->i_flags |= S_IXUNLINK;
7993 +       else
7994 +               inode->i_flags &= ~S_IXUNLINK;
7995         if (ip->i_d.di_flags & XFS_DIFLAG_APPEND)
7996                 inode->i_flags |= S_APPEND;
7997         else
7998 @@ -834,6 +848,15 @@ xfs_diflags_to_iflags(
7999                 inode->i_flags |= S_NOATIME;
8000         else
8001                 inode->i_flags &= ~S_NOATIME;
8002 +
8003 +       if (ip->i_d.di_vflags & XFS_DIVFLAG_BARRIER)
8004 +               inode->i_vflags |= V_BARRIER;
8005 +       else
8006 +               inode->i_vflags &= ~V_BARRIER;
8007 +       if (ip->i_d.di_vflags & XFS_DIVFLAG_COW)
8008 +               inode->i_vflags |= V_COW;
8009 +       else
8010 +               inode->i_vflags &= ~V_COW;
8011  }
8012  
8013  /*
8014 @@ -862,6 +885,7 @@ xfs_setup_inode(
8015         inode->i_nlink  = ip->i_d.di_nlink;
8016         inode->i_uid    = ip->i_d.di_uid;
8017         inode->i_gid    = ip->i_d.di_gid;
8018 +       inode->i_tag    = ip->i_d.di_tag;
8019  
8020         switch (inode->i_mode & S_IFMT) {
8021         case S_IFBLK:
8022 diff -NurpP --minimal linux-2.6.29.1/fs/xfs/linux-2.6/xfs_linux.h linux-2.6.29.1-vs2.3.0.36.9-pre5/fs/xfs/linux-2.6/xfs_linux.h
8023 --- linux-2.6.29.1/fs/xfs/linux-2.6/xfs_linux.h 2009-03-24 14:22:37.000000000 +0100
8024 +++ linux-2.6.29.1-vs2.3.0.36.9-pre5/fs/xfs/linux-2.6/xfs_linux.h       2009-03-25 01:26:04.000000000 +0100
8025 @@ -119,6 +119,7 @@
8026  
8027  #define current_cpu()          (raw_smp_processor_id())
8028  #define current_pid()          (current->pid)
8029 +#define current_fstag(cred,vp) (dx_current_fstag((vp)->i_sb))
8030  #define current_test_flags(f)  (current->flags & (f))
8031  #define current_set_flags_nested(sp, f)                \
8032                 (*(sp) = current->flags, current->flags |= (f))
8033 diff -NurpP --minimal linux-2.6.29.1/fs/xfs/linux-2.6/xfs_super.c linux-2.6.29.1-vs2.3.0.36.9-pre5/fs/xfs/linux-2.6/xfs_super.c
8034 --- linux-2.6.29.1/fs/xfs/linux-2.6/xfs_super.c 2009-03-24 14:22:37.000000000 +0100
8035 +++ linux-2.6.29.1-vs2.3.0.36.9-pre5/fs/xfs/linux-2.6/xfs_super.c       2009-03-25 01:48:51.000000000 +0100
8036 @@ -120,6 +120,9 @@ mempool_t *xfs_ioend_pool;
8037  #define MNTOPT_DMAPI   "dmapi"         /* DMI enabled (DMAPI / XDSM) */
8038  #define MNTOPT_XDSM    "xdsm"          /* DMI enabled (DMAPI / XDSM) */
8039  #define MNTOPT_DMI     "dmi"           /* DMI enabled (DMAPI / XDSM) */
8040 +#define MNTOPT_TAGXID  "tagxid"        /* context tagging for inodes */
8041 +#define MNTOPT_TAGGED  "tag"           /* context tagging for inodes */
8042 +#define MNTOPT_NOTAGTAG        "notag"         /* do not use context tagging */
8043  
8044  /*
8045   * Table driven mount option parser.
8046 @@ -128,10 +131,14 @@ mempool_t *xfs_ioend_pool;
8047   * in the future, too.
8048   */
8049  enum {
8050 +       Opt_tag, Opt_notag,
8051         Opt_barrier, Opt_nobarrier, Opt_err
8052  };
8053  
8054  static const match_table_t tokens = {
8055 +       {Opt_tag, "tagxid"},
8056 +       {Opt_tag, "tag"},
8057 +       {Opt_notag, "notag"},
8058         {Opt_barrier, "barrier"},
8059         {Opt_nobarrier, "nobarrier"},
8060         {Opt_err, NULL}
8061 @@ -395,6 +402,19 @@ xfs_parseargs(
8062                 } else if (!strcmp(this_char, "irixsgid")) {
8063                         cmn_err(CE_WARN,
8064         "XFS: irixsgid is now a sysctl(2) variable, option is deprecated.");
8065 +#ifndef CONFIG_TAGGING_NONE
8066 +               } else if (!strcmp(this_char, MNTOPT_TAGGED)) {
8067 +                       mp->m_flags |= XFS_MOUNT_TAGGED;
8068 +               } else if (!strcmp(this_char, MNTOPT_NOTAGTAG)) {
8069 +                       mp->m_flags &= ~XFS_MOUNT_TAGGED;
8070 +               } else if (!strcmp(this_char, MNTOPT_TAGXID)) {
8071 +                       mp->m_flags |= XFS_MOUNT_TAGGED;
8072 +#endif
8073 +#ifdef CONFIG_PROPAGATE
8074 +               } else if (!strcmp(this_char, MNTOPT_TAGGED)) {
8075 +                       /* use value */
8076 +                       mp->m_flags |= XFS_MOUNT_TAGGED;
8077 +#endif
8078                 } else {
8079                         cmn_err(CE_WARN,
8080                                 "XFS: unknown mount option [%s].", this_char);
8081 @@ -1221,6 +1241,16 @@ xfs_fs_remount(
8082                 case Opt_nobarrier:
8083                         mp->m_flags &= ~XFS_MOUNT_BARRIER;
8084                         break;
8085 +               case Opt_tag:
8086 +                       if (!(sb->s_flags & MS_TAGGED)) {
8087 +                               printk(KERN_INFO
8088 +                                       "XFS: %s: tagging not permitted on remount.\n",
8089 +                                       sb->s_id);
8090 +                               return -EINVAL;
8091 +                       }
8092 +                       break;
8093 +               case Opt_notag:
8094 +                       break;
8095                 default:
8096                         /*
8097                          * Logically we would return an error here to prevent
8098 @@ -1480,6 +1510,9 @@ xfs_fs_fill_super(
8099  
8100         XFS_SEND_MOUNT(mp, DM_RIGHT_NULL, mtpt, mp->m_fsname);
8101  
8102 +       if (mp->m_flags & XFS_MOUNT_TAGGED)
8103 +               sb->s_flags |= MS_TAGGED;
8104 +
8105         sb->s_dirt = 1;
8106         sb->s_magic = XFS_SB_MAGIC;
8107         sb->s_blocksize = mp->m_sb.sb_blocksize;
8108 diff -NurpP --minimal linux-2.6.29.1/fs/xfs/quota/xfs_qm_syscalls.c linux-2.6.29.1-vs2.3.0.36.9-pre5/fs/xfs/quota/xfs_qm_syscalls.c
8109 --- linux-2.6.29.1/fs/xfs/quota/xfs_qm_syscalls.c       2009-03-24 14:22:37.000000000 +0100
8110 +++ linux-2.6.29.1-vs2.3.0.36.9-pre5/fs/xfs/quota/xfs_qm_syscalls.c     2009-03-24 14:48:35.000000000 +0100
8111 @@ -426,7 +426,7 @@ xfs_qm_scall_quotaon(
8112         uint            accflags;
8113         __int64_t       sbflags;
8114  
8115 -       if (!capable(CAP_SYS_ADMIN))
8116 +       if (!vx_capable(CAP_SYS_ADMIN, VXC_QUOTA_CTL))
8117                 return XFS_ERROR(EPERM);
8118  
8119         flags &= (XFS_ALL_QUOTA_ACCT | XFS_ALL_QUOTA_ENFD);
8120 diff -NurpP --minimal linux-2.6.29.1/fs/xfs/xfs_dinode.h linux-2.6.29.1-vs2.3.0.36.9-pre5/fs/xfs/xfs_dinode.h
8121 --- linux-2.6.29.1/fs/xfs/xfs_dinode.h  2009-03-24 14:22:37.000000000 +0100
8122 +++ linux-2.6.29.1-vs2.3.0.36.9-pre5/fs/xfs/xfs_dinode.h        2009-03-24 16:38:27.000000000 +0100
8123 @@ -50,7 +50,9 @@ typedef struct xfs_dinode {
8124         __be32          di_gid;         /* owner's group id */
8125         __be32          di_nlink;       /* number of links to file */
8126         __be16          di_projid;      /* owner's project id */
8127 -       __u8            di_pad[8];      /* unused, zeroed space */
8128 +       __be16          di_tag;         /* context tagging */
8129 +       __be16          di_vflags;      /* vserver specific flags */
8130 +       __u8            di_pad[4];      /* unused, zeroed space */
8131         __be16          di_flushiter;   /* incremented on flush */
8132         xfs_timestamp_t di_atime;       /* time last accessed */
8133         xfs_timestamp_t di_mtime;       /* time last modified */
8134 @@ -181,6 +183,8 @@ static inline void xfs_dinode_put_rdev(s
8135  #define XFS_DIFLAG_EXTSZINHERIT_BIT 12 /* inherit inode extent size */
8136  #define XFS_DIFLAG_NODEFRAG_BIT     13 /* do not reorganize/defragment */
8137  #define XFS_DIFLAG_FILESTREAM_BIT   14  /* use filestream allocator */
8138 +#define XFS_DIFLAG_IXUNLINK_BIT     15 /* Immutable inver on unlink */
8139 +
8140  #define XFS_DIFLAG_REALTIME      (1 << XFS_DIFLAG_REALTIME_BIT)
8141  #define XFS_DIFLAG_PREALLOC      (1 << XFS_DIFLAG_PREALLOC_BIT)
8142  #define XFS_DIFLAG_NEWRTBM       (1 << XFS_DIFLAG_NEWRTBM_BIT)
8143 @@ -196,6 +200,7 @@ static inline void xfs_dinode_put_rdev(s
8144  #define XFS_DIFLAG_EXTSZINHERIT  (1 << XFS_DIFLAG_EXTSZINHERIT_BIT)
8145  #define XFS_DIFLAG_NODEFRAG      (1 << XFS_DIFLAG_NODEFRAG_BIT)
8146  #define XFS_DIFLAG_FILESTREAM    (1 << XFS_DIFLAG_FILESTREAM_BIT)
8147 +#define XFS_DIFLAG_IXUNLINK      (1 << XFS_DIFLAG_IXUNLINK_BIT)
8148  
8149  #ifdef CONFIG_XFS_RT
8150  #define XFS_IS_REALTIME_INODE(ip) ((ip)->i_d.di_flags & XFS_DIFLAG_REALTIME)
8151 @@ -208,6 +213,10 @@ static inline void xfs_dinode_put_rdev(s
8152          XFS_DIFLAG_IMMUTABLE | XFS_DIFLAG_APPEND | XFS_DIFLAG_SYNC | \
8153          XFS_DIFLAG_NOATIME | XFS_DIFLAG_NODUMP | XFS_DIFLAG_RTINHERIT | \
8154          XFS_DIFLAG_PROJINHERIT | XFS_DIFLAG_NOSYMLINKS | XFS_DIFLAG_EXTSIZE | \
8155 -        XFS_DIFLAG_EXTSZINHERIT | XFS_DIFLAG_NODEFRAG | XFS_DIFLAG_FILESTREAM)
8156 +        XFS_DIFLAG_EXTSZINHERIT | XFS_DIFLAG_NODEFRAG | XFS_DIFLAG_FILESTREAM | \
8157 +        XFS_DIFLAG_IXUNLINK)
8158 +
8159 +#define XFS_DIVFLAG_BARRIER    0x01
8160 +#define XFS_DIVFLAG_COW                0x02
8161  
8162  #endif /* __XFS_DINODE_H__ */
8163 diff -NurpP --minimal linux-2.6.29.1/fs/xfs/xfs_fs.h linux-2.6.29.1-vs2.3.0.36.9-pre5/fs/xfs/xfs_fs.h
8164 --- linux-2.6.29.1/fs/xfs/xfs_fs.h      2009-03-24 14:22:37.000000000 +0100
8165 +++ linux-2.6.29.1-vs2.3.0.36.9-pre5/fs/xfs/xfs_fs.h    2009-03-24 14:48:35.000000000 +0100
8166 @@ -67,6 +67,9 @@ struct fsxattr {
8167  #define XFS_XFLAG_EXTSZINHERIT 0x00001000      /* inherit inode extent size */
8168  #define XFS_XFLAG_NODEFRAG     0x00002000      /* do not defragment */
8169  #define XFS_XFLAG_FILESTREAM   0x00004000      /* use filestream allocator */
8170 +#define XFS_XFLAG_IXUNLINK     0x00008000      /* immutable invert on unlink */
8171 +#define XFS_XFLAG_BARRIER      0x10000000      /* chroot() barrier */
8172 +#define XFS_XFLAG_COW          0x20000000      /* copy on write mark */
8173  #define XFS_XFLAG_HASATTR      0x80000000      /* no DIFLAG for this   */
8174  
8175  /*
8176 @@ -289,7 +292,8 @@ typedef struct xfs_bstat {
8177         __s32           bs_extents;     /* number of extents            */
8178         __u32           bs_gen;         /* generation count             */
8179         __u16           bs_projid;      /* project id                   */
8180 -       unsigned char   bs_pad[14];     /* pad space, unused            */
8181 +       __u16           bs_tag;         /* context tagging              */
8182 +       unsigned char   bs_pad[12];     /* pad space, unused            */
8183         __u32           bs_dmevmask;    /* DMIG event mask              */
8184         __u16           bs_dmstate;     /* DMIG state info              */
8185         __u16           bs_aextents;    /* attribute number of extents  */
8186 diff -NurpP --minimal linux-2.6.29.1/fs/xfs/xfs_ialloc.c linux-2.6.29.1-vs2.3.0.36.9-pre5/fs/xfs/xfs_ialloc.c
8187 --- linux-2.6.29.1/fs/xfs/xfs_ialloc.c  2009-03-24 14:22:37.000000000 +0100
8188 +++ linux-2.6.29.1-vs2.3.0.36.9-pre5/fs/xfs/xfs_ialloc.c        2009-03-24 17:03:17.000000000 +0100
8189 @@ -41,7 +41,6 @@
8190  #include "xfs_error.h"
8191  #include "xfs_bmap.h"
8192  
8193 -
8194  /*
8195   * Allocation group level functions.
8196   */
8197 diff -NurpP --minimal linux-2.6.29.1/fs/xfs/xfs_inode.c linux-2.6.29.1-vs2.3.0.36.9-pre5/fs/xfs/xfs_inode.c
8198 --- linux-2.6.29.1/fs/xfs/xfs_inode.c   2009-03-24 14:22:37.000000000 +0100
8199 +++ linux-2.6.29.1-vs2.3.0.36.9-pre5/fs/xfs/xfs_inode.c 2009-03-25 01:42:50.000000000 +0100
8200 @@ -250,6 +250,7 @@ xfs_inotobp(
8201         return 0;
8202  }
8203  
8204 +#include <linux/vs_tag.h>
8205  
8206  /*
8207   * This routine is called to map an inode to the buffer containing
8208 @@ -645,15 +646,25 @@ xfs_iformat_btree(
8209  void
8210  xfs_dinode_from_disk(
8211         xfs_icdinode_t          *to,
8212 -       xfs_dinode_t            *from)
8213 +       xfs_dinode_t            *from,
8214 +       int tagged)
8215  {
8216 +       uint32_t uid, gid, tag;
8217 +
8218         to->di_magic = be16_to_cpu(from->di_magic);
8219         to->di_mode = be16_to_cpu(from->di_mode);
8220         to->di_version = from ->di_version;
8221         to->di_format = from->di_format;
8222         to->di_onlink = be16_to_cpu(from->di_onlink);
8223 -       to->di_uid = be32_to_cpu(from->di_uid);
8224 -       to->di_gid = be32_to_cpu(from->di_gid);
8225 +
8226 +       uid = be32_to_cpu(from->di_uid);
8227 +       gid = be32_to_cpu(from->di_gid);
8228 +       tag = be16_to_cpu(from->di_tag);
8229 +
8230 +       to->di_uid = INOTAG_UID(tagged, uid, gid);
8231 +       to->di_gid = INOTAG_GID(tagged, uid, gid);
8232 +       to->di_tag = INOTAG_TAG(tagged, uid, gid, tag);
8233 +
8234         to->di_nlink = be32_to_cpu(from->di_nlink);
8235         to->di_projid = be16_to_cpu(from->di_projid);
8236         memcpy(to->di_pad, from->di_pad, sizeof(to->di_pad));
8237 @@ -674,21 +685,26 @@ xfs_dinode_from_disk(
8238         to->di_dmevmask = be32_to_cpu(from->di_dmevmask);
8239         to->di_dmstate  = be16_to_cpu(from->di_dmstate);
8240         to->di_flags    = be16_to_cpu(from->di_flags);
8241 +       to->di_vflags   = be16_to_cpu(from->di_vflags);
8242         to->di_gen      = be32_to_cpu(from->di_gen);
8243  }
8244  
8245  void
8246  xfs_dinode_to_disk(
8247         xfs_dinode_t            *to,
8248 -       xfs_icdinode_t          *from)
8249 +       xfs_icdinode_t          *from,
8250 +       int tagged)
8251  {
8252         to->di_magic = cpu_to_be16(from->di_magic);
8253         to->di_mode = cpu_to_be16(from->di_mode);
8254         to->di_version = from ->di_version;
8255         to->di_format = from->di_format;
8256         to->di_onlink = cpu_to_be16(from->di_onlink);
8257 -       to->di_uid = cpu_to_be32(from->di_uid);
8258 -       to->di_gid = cpu_to_be32(from->di_gid);
8259 +
8260 +       to->di_uid = cpu_to_be32(TAGINO_UID(tagged, from->di_uid, from->di_tag));
8261 +       to->di_gid = cpu_to_be32(TAGINO_GID(tagged, from->di_gid, from->di_tag));
8262 +       to->di_tag = cpu_to_be16(TAGINO_TAG(tagged, from->di_tag));
8263 +
8264         to->di_nlink = cpu_to_be32(from->di_nlink);
8265         to->di_projid = cpu_to_be16(from->di_projid);
8266         memcpy(to->di_pad, from->di_pad, sizeof(to->di_pad));
8267 @@ -709,12 +725,14 @@ xfs_dinode_to_disk(
8268         to->di_dmevmask = cpu_to_be32(from->di_dmevmask);
8269         to->di_dmstate = cpu_to_be16(from->di_dmstate);
8270         to->di_flags = cpu_to_be16(from->di_flags);
8271 +       to->di_vflags = cpu_to_be16(from->di_vflags);
8272         to->di_gen = cpu_to_be32(from->di_gen);
8273  }
8274  
8275  STATIC uint
8276  _xfs_dic2xflags(
8277 -       __uint16_t              di_flags)
8278 +       __uint16_t              di_flags,
8279 +       __uint16_t              di_vflags)
8280  {
8281         uint                    flags = 0;
8282  
8283 @@ -725,6 +743,8 @@ _xfs_dic2xflags(
8284                         flags |= XFS_XFLAG_PREALLOC;
8285                 if (di_flags & XFS_DIFLAG_IMMUTABLE)
8286                         flags |= XFS_XFLAG_IMMUTABLE;
8287 +               if (di_flags & XFS_DIFLAG_IXUNLINK)
8288 +                       flags |= XFS_XFLAG_IXUNLINK;
8289                 if (di_flags & XFS_DIFLAG_APPEND)
8290                         flags |= XFS_XFLAG_APPEND;
8291                 if (di_flags & XFS_DIFLAG_SYNC)
8292 @@ -749,6 +769,10 @@ _xfs_dic2xflags(
8293                         flags |= XFS_XFLAG_FILESTREAM;
8294         }
8295  
8296 +       if (di_vflags & XFS_DIVFLAG_BARRIER)
8297 +               flags |= FS_BARRIER_FL;
8298 +       if (di_vflags & XFS_DIVFLAG_COW)
8299 +               flags |= FS_COW_FL;
8300         return flags;
8301  }
8302  
8303 @@ -758,7 +782,7 @@ xfs_ip2xflags(
8304  {
8305         xfs_icdinode_t          *dic = &ip->i_d;
8306  
8307 -       return _xfs_dic2xflags(dic->di_flags) |
8308 +       return _xfs_dic2xflags(dic->di_flags, dic->di_vflags) |
8309                                 (XFS_IFORK_Q(ip) ? XFS_XFLAG_HASATTR : 0);
8310  }
8311  
8312 @@ -766,7 +790,8 @@ uint
8313  xfs_dic2xflags(
8314         xfs_dinode_t            *dip)
8315  {
8316 -       return _xfs_dic2xflags(be16_to_cpu(dip->di_flags)) |
8317 +       return _xfs_dic2xflags(be16_to_cpu(dip->di_flags),
8318 +                               be16_to_cpu(dip->di_vflags)) |
8319                                 (XFS_DFORK_Q(dip) ? XFS_XFLAG_HASATTR : 0);
8320  }
8321  
8322 @@ -802,7 +827,6 @@ xfs_iread(
8323         if (error)
8324                 return error;
8325         dip = (xfs_dinode_t *)xfs_buf_offset(bp, ip->i_imap.im_boffset);
8326 -
8327         /*
8328          * If we got something that isn't an inode it means someone
8329          * (nfs or dmi) has a stale handle.
8330 @@ -827,7 +851,8 @@ xfs_iread(
8331          * Otherwise, just get the truly permanent information.
8332          */
8333         if (dip->di_mode) {
8334 -               xfs_dinode_from_disk(&ip->i_d, dip);
8335 +               xfs_dinode_from_disk(&ip->i_d, dip,
8336 +                       mp->m_flags & XFS_MOUNT_TAGGED);
8337                 error = xfs_iformat(ip, dip);
8338                 if (error)  {
8339  #ifdef DEBUG
8340 @@ -1027,6 +1052,7 @@ xfs_ialloc(
8341         ASSERT(ip->i_d.di_nlink == nlink);
8342         ip->i_d.di_uid = current_fsuid();
8343         ip->i_d.di_gid = current_fsgid();
8344 +       ip->i_d.di_tag = current_fstag(cr, &ip->i_vnode);
8345         ip->i_d.di_projid = prid;
8346         memset(&(ip->i_d.di_pad[0]), 0, sizeof(ip->i_d.di_pad));
8347  
8348 @@ -1087,6 +1113,7 @@ xfs_ialloc(
8349         ip->i_d.di_dmevmask = 0;
8350         ip->i_d.di_dmstate = 0;
8351         ip->i_d.di_flags = 0;
8352 +       ip->i_d.di_vflags = 0;
8353         flags = XFS_ILOG_CORE;
8354         switch (mode & S_IFMT) {
8355         case S_IFIFO:
8356 @@ -2161,6 +2188,7 @@ xfs_ifree(
8357         }
8358         ip->i_d.di_mode = 0;            /* mark incore inode as free */
8359         ip->i_d.di_flags = 0;
8360 +       ip->i_d.di_vflags = 0;
8361         ip->i_d.di_dmevmask = 0;
8362         ip->i_d.di_forkoff = 0;         /* mark the attr fork not in use */
8363         ip->i_df.if_ext_max =
8364 @@ -3128,7 +3156,8 @@ xfs_iflush_int(
8365          * because if the inode is dirty at all the core must
8366          * be.
8367          */
8368 -       xfs_dinode_to_disk(dip, &ip->i_d);
8369 +       xfs_dinode_to_disk(dip, &ip->i_d,
8370 +               mp->m_flags & XFS_MOUNT_TAGGED);
8371  
8372         /* Wrap, we never let the log put out DI_MAX_FLUSH */
8373         if (ip->i_d.di_flushiter == DI_MAX_FLUSH)
8374 diff -NurpP --minimal linux-2.6.29.1/fs/xfs/xfs_inode.h linux-2.6.29.1-vs2.3.0.36.9-pre5/fs/xfs/xfs_inode.h
8375 --- linux-2.6.29.1/fs/xfs/xfs_inode.h   2009-03-24 14:22:37.000000000 +0100
8376 +++ linux-2.6.29.1-vs2.3.0.36.9-pre5/fs/xfs/xfs_inode.h 2009-03-25 01:10:35.000000000 +0100
8377 @@ -134,7 +134,9 @@ typedef struct xfs_icdinode {
8378         __uint32_t      di_gid;         /* owner's group id */
8379         __uint32_t      di_nlink;       /* number of links to file */
8380         __uint16_t      di_projid;      /* owner's project id */
8381 -       __uint8_t       di_pad[8];      /* unused, zeroed space */
8382 +       __uint16_t      di_tag;         /* context tagging */
8383 +       __uint16_t      di_vflags;      /* vserver specific flags */
8384 +       __uint8_t       di_pad[4];      /* unused, zeroed space */
8385         __uint16_t      di_flushiter;   /* incremented on flush */
8386         xfs_ictimestamp_t di_atime;     /* time last accessed */
8387         xfs_ictimestamp_t di_mtime;     /* time last modified */
8388 @@ -589,9 +591,9 @@ int         xfs_itobp(struct xfs_mount *, struc
8389  int            xfs_iread(struct xfs_mount *, struct xfs_trans *,
8390                           struct xfs_inode *, xfs_daddr_t, uint);
8391  void           xfs_dinode_from_disk(struct xfs_icdinode *,
8392 -                                    struct xfs_dinode *);
8393 +                                    struct xfs_dinode *, int);
8394  void           xfs_dinode_to_disk(struct xfs_dinode *,
8395 -                                  struct xfs_icdinode *);
8396 +                                  struct xfs_icdinode *, int);
8397  void           xfs_idestroy_fork(struct xfs_inode *, int);
8398  void           xfs_idata_realloc(struct xfs_inode *, int, int);
8399  void           xfs_iroot_realloc(struct xfs_inode *, int, int);
8400 diff -NurpP --minimal linux-2.6.29.1/fs/xfs/xfs_itable.c linux-2.6.29.1-vs2.3.0.36.9-pre5/fs/xfs/xfs_itable.c
8401 --- linux-2.6.29.1/fs/xfs/xfs_itable.c  2009-03-24 14:22:37.000000000 +0100
8402 +++ linux-2.6.29.1-vs2.3.0.36.9-pre5/fs/xfs/xfs_itable.c        2009-03-24 14:48:35.000000000 +0100
8403 @@ -82,6 +82,7 @@ xfs_bulkstat_one_iget(
8404         buf->bs_mode = dic->di_mode;
8405         buf->bs_uid = dic->di_uid;
8406         buf->bs_gid = dic->di_gid;
8407 +       buf->bs_tag = dic->di_tag;
8408         buf->bs_size = dic->di_size;
8409         vn_atime_to_bstime(VFS_I(ip), &buf->bs_atime);
8410         buf->bs_mtime.tv_sec = dic->di_mtime.t_sec;
8411 diff -NurpP --minimal linux-2.6.29.1/fs/xfs/xfs_log_recover.c linux-2.6.29.1-vs2.3.0.36.9-pre5/fs/xfs/xfs_log_recover.c
8412 --- linux-2.6.29.1/fs/xfs/xfs_log_recover.c     2009-03-24 14:22:37.000000000 +0100
8413 +++ linux-2.6.29.1-vs2.3.0.36.9-pre5/fs/xfs/xfs_log_recover.c   2009-03-24 17:17:15.000000000 +0100
8414 @@ -2421,7 +2421,8 @@ xlog_recover_do_inode_trans(
8415         }
8416  
8417         /* The core is in in-core format */
8418 -       xfs_dinode_to_disk(dip, (xfs_icdinode_t *)item->ri_buf[1].i_addr);
8419 +       xfs_dinode_to_disk(dip, (xfs_icdinode_t *)item->ri_buf[1].i_addr,
8420 +               mp->m_flags & XFS_MOUNT_TAGGED);
8421  
8422         /* the rest is in on-disk format */
8423         if (item->ri_buf[1].i_len > sizeof(struct xfs_icdinode)) {
8424 diff -NurpP --minimal linux-2.6.29.1/fs/xfs/xfs_mount.h linux-2.6.29.1-vs2.3.0.36.9-pre5/fs/xfs/xfs_mount.h
8425 --- linux-2.6.29.1/fs/xfs/xfs_mount.h   2009-03-24 14:22:37.000000000 +0100
8426 +++ linux-2.6.29.1-vs2.3.0.36.9-pre5/fs/xfs/xfs_mount.h 2009-03-24 14:48:35.000000000 +0100
8427 @@ -371,6 +371,7 @@ typedef struct xfs_mount {
8428                                                    allocator */
8429  #define XFS_MOUNT_NOATTR2      (1ULL << 25)    /* disable use of attr2 format */
8430  
8431 +#define XFS_MOUNT_TAGGED       (1ULL << 31)    /* context tagging */
8432  
8433  /*
8434   * Default minimum read and write sizes.
8435 diff -NurpP --minimal linux-2.6.29.1/fs/xfs/xfs_vnodeops.c linux-2.6.29.1-vs2.3.0.36.9-pre5/fs/xfs/xfs_vnodeops.c
8436 --- linux-2.6.29.1/fs/xfs/xfs_vnodeops.c        2009-03-24 14:22:37.000000000 +0100
8437 +++ linux-2.6.29.1-vs2.3.0.36.9-pre5/fs/xfs/xfs_vnodeops.c      2009-03-24 17:18:40.000000000 +0100
8438 @@ -53,6 +53,90 @@
8439  #include "xfs_filestream.h"
8440  #include "xfs_vnodeops.h"
8441  
8442 +
8443 +STATIC void
8444 +xfs_get_inode_flags(
8445 +       xfs_inode_t     *ip)
8446 +{
8447 +       struct inode    *inode = VFS_I(ip);
8448 +       unsigned int    flags = inode->i_flags;
8449 +       unsigned int    vflags = inode->i_vflags;
8450 +
8451 +       if (flags & S_IMMUTABLE)
8452 +               ip->i_d.di_flags |= XFS_DIFLAG_IMMUTABLE;
8453 +       else
8454 +               ip->i_d.di_flags &= ~XFS_DIFLAG_IMMUTABLE;
8455 +       if (flags & S_IXUNLINK)
8456 +               ip->i_d.di_flags |= XFS_DIFLAG_IXUNLINK;
8457 +       else
8458 +               ip->i_d.di_flags &= ~XFS_DIFLAG_IXUNLINK;
8459 +
8460 +       if (vflags & V_BARRIER)
8461 +               ip->i_d.di_vflags |= XFS_DIVFLAG_BARRIER;
8462 +       else
8463 +               ip->i_d.di_vflags &= ~XFS_DIVFLAG_BARRIER;
8464 +       if (vflags & V_COW)
8465 +               ip->i_d.di_vflags |= XFS_DIVFLAG_COW;
8466 +       else
8467 +               ip->i_d.di_vflags &= ~XFS_DIVFLAG_COW;
8468 +}
8469 +
8470 +int
8471 +xfs_sync_xflags(
8472 +       xfs_inode_t             *ip)
8473 +{
8474 +       struct xfs_mount        *mp = ip->i_mount;
8475 +       struct xfs_trans        *tp;
8476 +       unsigned int            lock_flags = 0;
8477 +       int                     code;
8478 +
8479 +       xfs_itrace_entry(ip);
8480 +
8481 +       if (mp->m_flags & XFS_MOUNT_RDONLY)
8482 +               return XFS_ERROR(EROFS);
8483 +
8484 +       /*
8485 +        * we acquire the inode lock and do an error checking pass.
8486 +        */
8487 +       tp = xfs_trans_alloc(mp, XFS_TRANS_SETATTR_NOT_SIZE);
8488 +       code = xfs_trans_reserve(tp, 0, XFS_ICHANGE_LOG_RES(mp), 0, 0, 0);
8489 +       if (code)
8490 +               goto error_return;
8491 +
8492 +       lock_flags = XFS_ILOCK_EXCL;
8493 +       xfs_ilock(ip, lock_flags);
8494 +
8495 +       xfs_trans_ijoin(tp, ip, lock_flags);
8496 +       xfs_trans_ihold(tp, ip);
8497 +
8498 +       xfs_get_inode_flags(ip);
8499 +       // xfs_diflags_to_linux(ip);
8500 +
8501 +       xfs_trans_log_inode(tp, ip, XFS_ILOG_CORE);
8502 +       xfs_ichgtime(ip, XFS_ICHGTIME_CHG);
8503 +
8504 +       XFS_STATS_INC(xs_ig_attrchg);
8505 +
8506 +       /*
8507 +        * If this is a synchronous mount, make sure that the
8508 +        * transaction goes to disk before returning to the user.
8509 +        */
8510 +       if (mp->m_flags & XFS_MOUNT_WSYNC)
8511 +               xfs_trans_set_sync(tp);
8512 +       code = xfs_trans_commit(tp, 0);
8513 +       xfs_iunlock(ip, lock_flags);
8514 +
8515 +       if (code)
8516 +               return code;
8517 +       return 0;
8518 +
8519 + error_return:
8520 +       xfs_trans_cancel(tp, 0);
8521 +       if (lock_flags)
8522 +               xfs_iunlock(ip, lock_flags);
8523 +       return code;
8524 +}
8525 +
8526  int
8527  xfs_setattr(
8528         struct xfs_inode        *ip,
8529 @@ -68,6 +152,7 @@ xfs_setattr(
8530         uint                    commit_flags=0;
8531         uid_t                   uid=0, iuid=0;
8532         gid_t                   gid=0, igid=0;
8533 +       tag_t                   tag=0, itag=0;
8534         int                     timeflags = 0;
8535         struct xfs_dquot        *udqp, *gdqp, *olddquot1, *olddquot2;
8536         int                     need_iolock = 1;
8537 @@ -164,7 +249,7 @@ xfs_setattr(
8538         /*
8539          * Change file ownership.  Must be the owner or privileged.
8540          */
8541 -       if (mask & (ATTR_UID|ATTR_GID)) {
8542 +       if (mask & (ATTR_UID|ATTR_GID|ATTR_TAG)) {
8543                 /*
8544                  * These IDs could have changed since we last looked at them.
8545                  * But, we're assured that if the ownership did change
8546 @@ -173,15 +258,19 @@ xfs_setattr(
8547                  */
8548                 iuid = ip->i_d.di_uid;
8549                 igid = ip->i_d.di_gid;
8550 +               itag = ip->i_d.di_tag;
8551                 gid = (mask & ATTR_GID) ? iattr->ia_gid : igid;
8552                 uid = (mask & ATTR_UID) ? iattr->ia_uid : iuid;
8553 +               tag = (mask & ATTR_TAG) ? iattr->ia_tag : itag;
8554  
8555                 /*
8556                  * Do a quota reservation only if uid/gid is actually
8557                  * going to change.
8558                  */
8559                 if ((XFS_IS_UQUOTA_ON(mp) && iuid != uid) ||
8560 -                   (XFS_IS_GQUOTA_ON(mp) && igid != gid)) {
8561 +                   (XFS_IS_GQUOTA_ON(mp) && igid != gid) ||
8562 +                   (XFS_IS_GQUOTA_ON(mp) && itag != tag)) {
8563 +                       /* TODO: handle tagging? */
8564                         ASSERT(tp);
8565                         code = XFS_QM_DQVOPCHOWNRESV(mp, tp, ip, udqp, gdqp,
8566                                                 capable(CAP_FOWNER) ?
8567 @@ -334,7 +423,7 @@ xfs_setattr(
8568         /*
8569          * Change file ownership.  Must be the owner or privileged.
8570          */
8571 -       if (mask & (ATTR_UID|ATTR_GID)) {
8572 +       if (mask & (ATTR_UID|ATTR_GID|ATTR_TAG)) {
8573                 /*
8574                  * CAP_FSETID overrides the following restrictions:
8575                  *
8576 @@ -350,6 +439,10 @@ xfs_setattr(
8577                  * Change the ownerships and register quota modifications
8578                  * in the transaction.
8579                  */
8580 +               if (itag != tag) {
8581 +                       ip->i_d.di_tag = tag;
8582 +                       inode->i_tag = tag;
8583 +               }
8584                 if (iuid != uid) {
8585                         if (XFS_IS_UQUOTA_ON(mp)) {
8586                                 ASSERT(mask & ATTR_UID);
8587 diff -NurpP --minimal linux-2.6.29.1/fs/xfs/xfs_vnodeops.h linux-2.6.29.1-vs2.3.0.36.9-pre5/fs/xfs/xfs_vnodeops.h
8588 --- linux-2.6.29.1/fs/xfs/xfs_vnodeops.h        2009-03-24 14:22:37.000000000 +0100
8589 +++ linux-2.6.29.1-vs2.3.0.36.9-pre5/fs/xfs/xfs_vnodeops.h      2009-03-24 17:19:30.000000000 +0100
8590 @@ -14,6 +14,7 @@ struct xfs_inode;
8591  struct xfs_iomap;
8592  
8593  
8594 +int xfs_sync_xflags(struct xfs_inode *ip);
8595  int xfs_setattr(struct xfs_inode *ip, struct iattr *vap, int flags);
8596  #define        XFS_ATTR_DMI            0x01    /* invocation from a DMI function */
8597  #define        XFS_ATTR_NONBLOCK       0x02    /* return EAGAIN if operation would block */
8598 diff -NurpP --minimal linux-2.6.29.1/include/asm-generic/tlb.h linux-2.6.29.1-vs2.3.0.36.9-pre5/include/asm-generic/tlb.h
8599 --- linux-2.6.29.1/include/asm-generic/tlb.h    2008-12-25 00:26:37.000000000 +0100
8600 +++ linux-2.6.29.1-vs2.3.0.36.9-pre5/include/asm-generic/tlb.h  2009-04-08 15:50:06.000000000 +0200
8601 @@ -14,6 +14,7 @@
8602  #define _ASM_GENERIC__TLB_H
8603  
8604  #include <linux/swap.h>
8605 +#include <linux/vs_memory.h>
8606  #include <asm/pgalloc.h>
8607  #include <asm/tlbflush.h>
8608  
8609 diff -NurpP --minimal linux-2.6.29.1/include/linux/capability.h linux-2.6.29.1-vs2.3.0.36.9-pre5/include/linux/capability.h
8610 --- linux-2.6.29.1/include/linux/capability.h   2009-03-24 14:22:41.000000000 +0100
8611 +++ linux-2.6.29.1-vs2.3.0.36.9-pre5/include/linux/capability.h 2009-03-24 14:48:35.000000000 +0100
8612 @@ -285,6 +285,7 @@ struct cpu_vfs_cap_data {
8613     arbitrary SCSI commands */
8614  /* Allow setting encryption key on loopback filesystem */
8615  /* Allow setting zone reclaim policy */
8616 +/* Allow the selection of a security context */
8617  
8618  #define CAP_SYS_ADMIN        21
8619  
8620 @@ -357,7 +358,13 @@ struct cpu_vfs_cap_data {
8621  
8622  #define CAP_MAC_ADMIN        33
8623  
8624 -#define CAP_LAST_CAP         CAP_MAC_ADMIN
8625 +/* Allow context manipulations */
8626 +/* Allow changing context info on files */
8627 +
8628 +#define CAP_CONTEXT         34
8629 +
8630 +
8631 +#define CAP_LAST_CAP         CAP_CONTEXT
8632  
8633  #define cap_valid(x) ((x) >= 0 && (x) <= CAP_LAST_CAP)
8634  
8635 diff -NurpP --minimal linux-2.6.29.1/include/linux/devpts_fs.h linux-2.6.29.1-vs2.3.0.36.9-pre5/include/linux/devpts_fs.h
8636 --- linux-2.6.29.1/include/linux/devpts_fs.h    2008-12-25 00:26:37.000000000 +0100
8637 +++ linux-2.6.29.1-vs2.3.0.36.9-pre5/include/linux/devpts_fs.h  2009-02-22 22:54:26.000000000 +0100
8638 @@ -45,5 +45,4 @@ static inline void devpts_pty_kill(struc
8639  
8640  #endif
8641  
8642 -
8643  #endif /* _LINUX_DEVPTS_FS_H */
8644 diff -NurpP --minimal linux-2.6.29.1/include/linux/ext2_fs.h linux-2.6.29.1-vs2.3.0.36.9-pre5/include/linux/ext2_fs.h
8645 --- linux-2.6.29.1/include/linux/ext2_fs.h      2009-03-24 14:22:41.000000000 +0100
8646 +++ linux-2.6.29.1-vs2.3.0.36.9-pre5/include/linux/ext2_fs.h    2009-03-24 15:39:54.000000000 +0100
8647 @@ -189,8 +189,12 @@ struct ext2_group_desc
8648  #define EXT2_NOTAIL_FL                 FS_NOTAIL_FL    /* file tail should not be merged */
8649  #define EXT2_DIRSYNC_FL                        FS_DIRSYNC_FL   /* dirsync behaviour (directories only) */
8650  #define EXT2_TOPDIR_FL                 FS_TOPDIR_FL    /* Top of directory hierarchies*/
8651 +#define EXT2_IXUNLINK_FL               FS_IXUNLINK_FL  /* Immutable invert on unlink */
8652  #define EXT2_RESERVED_FL               FS_RESERVED_FL  /* reserved for ext2 lib */
8653  
8654 +#define EXT2_BARRIER_FL                        FS_BARRIER_FL   /* Barrier for chroot() */
8655 +#define EXT2_COW_FL                    FS_COW_FL       /* Copy on Write marker */
8656 +
8657  #define EXT2_FL_USER_VISIBLE           FS_FL_USER_VISIBLE      /* User visible flags */
8658  #define EXT2_FL_USER_MODIFIABLE                FS_FL_USER_MODIFIABLE   /* User modifiable flags */
8659  
8660 @@ -271,7 +275,7 @@ struct ext2_inode {
8661                 struct {
8662                         __u8    l_i_frag;       /* Fragment number */
8663                         __u8    l_i_fsize;      /* Fragment size */
8664 -                       __u16   i_pad1;
8665 +                       __u16   l_i_tag;        /* Context Tag */
8666                         __le16  l_i_uid_high;   /* these 2 fields    */
8667                         __le16  l_i_gid_high;   /* were reserved2[0] */
8668                         __u32   l_i_reserved2;
8669 @@ -303,6 +307,7 @@ struct ext2_inode {
8670  #define i_gid_low      i_gid
8671  #define i_uid_high     osd2.linux2.l_i_uid_high
8672  #define i_gid_high     osd2.linux2.l_i_gid_high
8673 +#define i_raw_tag      osd2.linux2.l_i_tag
8674  #define i_reserved2    osd2.linux2.l_i_reserved2
8675  #endif
8676  
8677 @@ -347,6 +352,7 @@ struct ext2_inode {
8678  #define EXT2_MOUNT_USRQUOTA            0x020000  /* user quota */
8679  #define EXT2_MOUNT_GRPQUOTA            0x040000  /* group quota */
8680  #define EXT2_MOUNT_RESERVATION         0x080000  /* Preallocation */
8681 +#define EXT2_MOUNT_TAGGED              (1<<24)   /* Enable Context Tags */
8682  
8683  
8684  #define clear_opt(o, opt)              o &= ~EXT2_MOUNT_##opt
8685 diff -NurpP --minimal linux-2.6.29.1/include/linux/ext3_fs.h linux-2.6.29.1-vs2.3.0.36.9-pre5/include/linux/ext3_fs.h
8686 --- linux-2.6.29.1/include/linux/ext3_fs.h      2009-03-24 14:22:41.000000000 +0100
8687 +++ linux-2.6.29.1-vs2.3.0.36.9-pre5/include/linux/ext3_fs.h    2009-03-24 14:48:36.000000000 +0100
8688 @@ -173,10 +173,14 @@ struct ext3_group_desc
8689  #define EXT3_NOTAIL_FL                 0x00008000 /* file tail should not be merged */
8690  #define EXT3_DIRSYNC_FL                        0x00010000 /* dirsync behaviour (directories only) */
8691  #define EXT3_TOPDIR_FL                 0x00020000 /* Top of directory hierarchies*/
8692 +#define EXT3_IXUNLINK_FL               0x08000000 /* Immutable invert on unlink */
8693  #define EXT3_RESERVED_FL               0x80000000 /* reserved for ext3 lib */
8694  
8695 -#define EXT3_FL_USER_VISIBLE           0x0003DFFF /* User visible flags */
8696 -#define EXT3_FL_USER_MODIFIABLE                0x000380FF /* User modifiable flags */
8697 +#define EXT3_BARRIER_FL                        0x04000000 /* Barrier for chroot() */
8698 +#define EXT3_COW_FL                    0x20000000 /* Copy on Write marker */
8699 +
8700 +#define EXT3_FL_USER_VISIBLE           0x0103DFFF /* User visible flags */
8701 +#define EXT3_FL_USER_MODIFIABLE                0x010380FF /* User modifiable flags */
8702  
8703  /* Flags that should be inherited by new inodes from their parent. */
8704  #define EXT3_FL_INHERITED (EXT3_SECRM_FL | EXT3_UNRM_FL | EXT3_COMPR_FL |\
8705 @@ -316,7 +320,7 @@ struct ext3_inode {
8706                 struct {
8707                         __u8    l_i_frag;       /* Fragment number */
8708                         __u8    l_i_fsize;      /* Fragment size */
8709 -                       __u16   i_pad1;
8710 +                       __u16   l_i_tag;        /* Context Tag */
8711                         __le16  l_i_uid_high;   /* these 2 fields    */
8712                         __le16  l_i_gid_high;   /* were reserved2[0] */
8713                         __u32   l_i_reserved2;
8714 @@ -350,6 +354,7 @@ struct ext3_inode {
8715  #define i_gid_low      i_gid
8716  #define i_uid_high     osd2.linux2.l_i_uid_high
8717  #define i_gid_high     osd2.linux2.l_i_gid_high
8718 +#define i_raw_tag      osd2.linux2.l_i_tag
8719  #define i_reserved2    osd2.linux2.l_i_reserved2
8720  
8721  #elif defined(__GNU__)
8722 @@ -413,6 +418,7 @@ struct ext3_inode {
8723  #define EXT3_MOUNT_GRPQUOTA            0x200000 /* "old" group quota */
8724  #define EXT3_MOUNT_DATA_ERR_ABORT      0x400000 /* Abort on file data write
8725                                                   * error in ordered mode */
8726 +#define EXT3_MOUNT_TAGGED              (1<<24) /* Enable Context Tags */
8727  
8728  /* Compatibility, for having both ext2_fs.h and ext3_fs.h included at once */
8729  #ifndef _LINUX_EXT2_FS_H
8730 @@ -874,6 +880,7 @@ struct buffer_head * ext3_bread (handle_
8731  int ext3_get_blocks_handle(handle_t *handle, struct inode *inode,
8732         sector_t iblock, unsigned long maxblocks, struct buffer_head *bh_result,
8733         int create, int extend_disksize);
8734 +extern int ext3_sync_flags(struct inode *inode);
8735  
8736  extern struct inode *ext3_iget(struct super_block *, unsigned long);
8737  extern int  ext3_write_inode (struct inode *, int);
8738 diff -NurpP --minimal linux-2.6.29.1/include/linux/fs.h linux-2.6.29.1-vs2.3.0.36.9-pre5/include/linux/fs.h
8739 --- linux-2.6.29.1/include/linux/fs.h   2009-03-24 14:22:41.000000000 +0100
8740 +++ linux-2.6.29.1-vs2.3.0.36.9-pre5/include/linux/fs.h 2009-03-24 17:21:20.000000000 +0100
8741 @@ -141,6 +141,9 @@ struct inodes_stat_t {
8742  #define MS_RELATIME    (1<<21) /* Update atime relative to mtime/ctime. */
8743  #define MS_KERNMOUNT   (1<<22) /* this is a kern_mount call */
8744  #define MS_I_VERSION   (1<<23) /* Update inode I_version field */
8745 +#define MS_TAGGED      (1<<24) /* use generic inode tagging */
8746 +#define MS_TAGID       (1<<25) /* use specific tag for this mount */
8747 +#define MS_NOTAGCHECK  (1<<26) /* don't check tags */
8748  #define MS_ACTIVE      (1<<30)
8749  #define MS_NOUSER      (1<<31)
8750  
8751 @@ -167,6 +170,14 @@ struct inodes_stat_t {
8752  #define S_PRIVATE      512     /* Inode is fs-internal */
8753  #define S_ATOMIC_COPY  1024    /* Pages mapped with this inode need to be
8754                                    atomically copied (gem) */
8755 +#define S_IXUNLINK     2048    /* Immutable Invert on unlink */
8756 +
8757 +/* Linux-VServer related Inode flags */
8758 +
8759 +#define V_VALID                1
8760 +#define V_XATTR                2
8761 +#define V_BARRIER      4       /* Barrier for chroot() */
8762 +#define V_COW          8       /* Copy on Write */
8763  
8764  /*
8765   * Note that nosuid etc flags are inode-specific: setting some file-system
8766 @@ -189,12 +200,15 @@ struct inodes_stat_t {
8767  #define IS_DIRSYNC(inode)      (__IS_FLG(inode, MS_SYNCHRONOUS|MS_DIRSYNC) || \
8768                                         ((inode)->i_flags & (S_SYNC|S_DIRSYNC)))
8769  #define IS_MANDLOCK(inode)     __IS_FLG(inode, MS_MANDLOCK)
8770 -#define IS_NOATIME(inode)   __IS_FLG(inode, MS_RDONLY|MS_NOATIME)
8771 -#define IS_I_VERSION(inode)   __IS_FLG(inode, MS_I_VERSION)
8772 +#define IS_NOATIME(inode)      __IS_FLG(inode, MS_RDONLY|MS_NOATIME)
8773 +#define IS_I_VERSION(inode)    __IS_FLG(inode, MS_I_VERSION)
8774 +#define IS_TAGGED(inode)       __IS_FLG(inode, MS_TAGGED)
8775  
8776  #define IS_NOQUOTA(inode)      ((inode)->i_flags & S_NOQUOTA)
8777  #define IS_APPEND(inode)       ((inode)->i_flags & S_APPEND)
8778  #define IS_IMMUTABLE(inode)    ((inode)->i_flags & S_IMMUTABLE)
8779 +#define IS_IXUNLINK(inode)     ((inode)->i_flags & S_IXUNLINK)
8780 +#define IS_IXORUNLINK(inode)   ((IS_IXUNLINK(inode) ? S_IMMUTABLE : 0) ^ IS_IMMUTABLE(inode))
8781  #define IS_POSIXACL(inode)     __IS_FLG(inode, MS_POSIXACL)
8782  
8783  #define IS_DEADDIR(inode)      ((inode)->i_flags & S_DEAD)
8784 @@ -202,6 +216,16 @@ struct inodes_stat_t {
8785  #define IS_SWAPFILE(inode)     ((inode)->i_flags & S_SWAPFILE)
8786  #define IS_PRIVATE(inode)      ((inode)->i_flags & S_PRIVATE)
8787  
8788 +#define IS_BARRIER(inode)      (S_ISDIR((inode)->i_mode) && ((inode)->i_vflags & V_BARRIER))
8789 +
8790 +#ifdef CONFIG_VSERVER_COWBL
8791 +#  define IS_COW(inode)                (IS_IXUNLINK(inode) && IS_IMMUTABLE(inode))
8792 +#  define IS_COW_LINK(inode)   (S_ISREG((inode)->i_mode) && ((inode)->i_nlink > 1))
8793 +#else
8794 +#  define IS_COW(inode)                (0)
8795 +#  define IS_COW_LINK(inode)   (0)
8796 +#endif
8797 +
8798  /* the read-only stuff doesn't really belong here, but any other place is
8799     probably as bad and I don't want to create yet another include file. */
8800  
8801 @@ -279,11 +303,14 @@ struct inodes_stat_t {
8802  #define FS_TOPDIR_FL                   0x00020000 /* Top of directory hierarchies*/
8803  #define FS_EXTENT_FL                   0x00080000 /* Extents */
8804  #define FS_DIRECTIO_FL                 0x00100000 /* Use direct i/o */
8805 +#define FS_IXUNLINK_FL                 0x08000000 /* Immutable invert on unlink */
8806  #define FS_RESERVED_FL                 0x80000000 /* reserved for ext2 lib */
8807  
8808 -#define FS_FL_USER_VISIBLE             0x0003DFFF /* User visible flags */
8809 -#define FS_FL_USER_MODIFIABLE          0x000380FF /* User modifiable flags */
8810 +#define FS_BARRIER_FL                  0x04000000 /* Barrier for chroot() */
8811 +#define FS_COW_FL                      0x20000000 /* Copy on Write marker */
8812  
8813 +#define FS_FL_USER_VISIBLE             0x0103DFFF /* User visible flags */
8814 +#define FS_FL_USER_MODIFIABLE          0x010380FF /* User modifiable flags */
8815  
8816  #define SYNC_FILE_RANGE_WAIT_BEFORE    1
8817  #define SYNC_FILE_RANGE_WRITE          2
8818 @@ -365,6 +392,7 @@ typedef void (dio_iodone_t)(struct kiocb
8819  #define ATTR_KILL_PRIV (1 << 14)
8820  #define ATTR_OPEN      (1 << 15) /* Truncating from open(O_TRUNC) */
8821  #define ATTR_TIMES_SET (1 << 16)
8822 +#define ATTR_TAG       (1 << 17)
8823  
8824  /*
8825   * This is the Inode Attributes structure, used for notify_change().  It
8826 @@ -380,6 +408,7 @@ struct iattr {
8827         umode_t         ia_mode;
8828         uid_t           ia_uid;
8829         gid_t           ia_gid;
8830 +       tag_t           ia_tag;
8831         loff_t          ia_size;
8832         struct timespec ia_atime;
8833         struct timespec ia_mtime;
8834 @@ -393,6 +422,9 @@ struct iattr {
8835         struct file     *ia_file;
8836  };
8837  
8838 +#define ATTR_FLAG_BARRIER      512     /* Barrier for chroot() */
8839 +#define ATTR_FLAG_IXUNLINK     1024    /* Immutable invert on unlink */
8840 +
8841  /*
8842   * Includes for diskquotas.
8843   */
8844 @@ -656,7 +688,9 @@ struct inode {
8845         unsigned int            i_nlink;
8846         uid_t                   i_uid;
8847         gid_t                   i_gid;
8848 +       tag_t                   i_tag;
8849         dev_t                   i_rdev;
8850 +       dev_t                   i_mdev;
8851         u64                     i_version;
8852         loff_t                  i_size;
8853  #ifdef __NEED_I_SIZE_ORDERED
8854 @@ -704,7 +738,8 @@ struct inode {
8855         unsigned long           i_state;
8856         unsigned long           dirtied_when;   /* jiffies of first dirtying */
8857  
8858 -       unsigned int            i_flags;
8859 +       unsigned short          i_flags;
8860 +       unsigned short          i_vflags;
8861  
8862         atomic_t                i_writecount;
8863  #ifdef CONFIG_SECURITY
8864 @@ -791,12 +826,12 @@ static inline void i_size_write(struct i
8865  
8866  static inline unsigned iminor(const struct inode *inode)
8867  {
8868 -       return MINOR(inode->i_rdev);
8869 +       return MINOR(inode->i_mdev);
8870  }
8871  
8872  static inline unsigned imajor(const struct inode *inode)
8873  {
8874 -       return MAJOR(inode->i_rdev);
8875 +       return MAJOR(inode->i_mdev);
8876  }
8877  
8878  extern struct block_device *I_BDEV(struct inode *inode);
8879 @@ -854,6 +889,7 @@ struct file {
8880         loff_t                  f_pos;
8881         struct fown_struct      f_owner;
8882         const struct cred       *f_cred;
8883 +       xid_t                   f_xid;
8884         struct file_ra_state    f_ra;
8885  
8886         u64                     f_version;
8887 @@ -996,6 +1032,7 @@ struct file_lock {
8888         struct file *fl_file;
8889         loff_t fl_start;
8890         loff_t fl_end;
8891 +       xid_t fl_xid;
8892  
8893         struct fasync_struct *  fl_fasync; /* for lease break notifications */
8894         unsigned long fl_break_time;    /* for nonblocking lease breaks */
8895 @@ -1363,6 +1400,7 @@ struct inode_operations {
8896                           loff_t len);
8897         int (*fiemap)(struct inode *, struct fiemap_extent_info *, u64 start,
8898                       u64 len);
8899 +       int (*sync_flags) (struct inode *);
8900  };
8901  
8902  struct seq_file;
8903 @@ -1378,6 +1416,7 @@ extern ssize_t vfs_readv(struct file *, 
8904                 unsigned long, loff_t *);
8905  extern ssize_t vfs_writev(struct file *, const struct iovec __user *,
8906                 unsigned long, loff_t *);
8907 +ssize_t vfs_sendfile(struct file *, struct file *, loff_t *, size_t, loff_t);
8908  
8909  struct super_operations {
8910         struct inode *(*alloc_inode)(struct super_block *sb);
8911 @@ -2096,6 +2135,7 @@ extern int dcache_dir_open(struct inode 
8912  extern int dcache_dir_close(struct inode *, struct file *);
8913  extern loff_t dcache_dir_lseek(struct file *, loff_t, int);
8914  extern int dcache_readdir(struct file *, void *, filldir_t);
8915 +extern int dcache_readdir_filter(struct file *, void *, filldir_t, int (*)(struct dentry *));
8916  extern int simple_getattr(struct vfsmount *, struct dentry *, struct kstat *);
8917  extern int simple_statfs(struct dentry *, struct kstatfs *);
8918  extern int simple_link(struct dentry *, struct inode *, struct dentry *);
8919 diff -NurpP --minimal linux-2.6.29.1/include/linux/if_tun.h linux-2.6.29.1-vs2.3.0.36.9-pre5/include/linux/if_tun.h
8920 --- linux-2.6.29.1/include/linux/if_tun.h       2008-12-25 00:26:37.000000000 +0100
8921 +++ linux-2.6.29.1-vs2.3.0.36.9-pre5/include/linux/if_tun.h     2009-02-22 22:54:26.000000000 +0100
8922 @@ -46,6 +46,7 @@
8923  #define TUNSETOFFLOAD  _IOW('T', 208, unsigned int)
8924  #define TUNSETTXFILTER _IOW('T', 209, unsigned int)
8925  #define TUNGETIFF      _IOR('T', 210, unsigned int)
8926 +#define TUNSETNID     _IOW('T', 215, int)
8927  
8928  /* TUNSETIFF ifr flags */
8929  #define IFF_TUN                0x0001
8930 diff -NurpP --minimal linux-2.6.29.1/include/linux/init_task.h linux-2.6.29.1-vs2.3.0.36.9-pre5/include/linux/init_task.h
8931 --- linux-2.6.29.1/include/linux/init_task.h    2009-03-24 14:22:41.000000000 +0100
8932 +++ linux-2.6.29.1-vs2.3.0.36.9-pre5/include/linux/init_task.h  2009-03-24 14:48:36.000000000 +0100
8933 @@ -184,6 +184,10 @@ extern struct cred init_cred;
8934         INIT_IDS                                                        \
8935         INIT_TRACE_IRQFLAGS                                             \
8936         INIT_LOCKDEP                                                    \
8937 +       .xid            = 0,                                            \
8938 +       .vx_info        = NULL,                                         \
8939 +       .nid            = 0,                                            \
8940 +       .nx_info        = NULL,                                         \
8941  }
8942  
8943  
8944 diff -NurpP --minimal linux-2.6.29.1/include/linux/interrupt.h linux-2.6.29.1-vs2.3.0.36.9-pre5/include/linux/interrupt.h
8945 --- linux-2.6.29.1/include/linux/interrupt.h    2009-03-24 14:22:41.000000000 +0100
8946 +++ linux-2.6.29.1-vs2.3.0.36.9-pre5/include/linux/interrupt.h  2009-03-24 14:48:36.000000000 +0100
8947 @@ -9,8 +9,8 @@
8948  #include <linux/cpumask.h>
8949  #include <linux/irqreturn.h>
8950  #include <linux/irqnr.h>
8951 -#include <linux/hardirq.h>
8952  #include <linux/sched.h>
8953 +#include <linux/hardirq.h>
8954  #include <linux/irqflags.h>
8955  #include <linux/smp.h>
8956  #include <linux/percpu.h>
8957 diff -NurpP --minimal linux-2.6.29.1/include/linux/ipc.h linux-2.6.29.1-vs2.3.0.36.9-pre5/include/linux/ipc.h
8958 --- linux-2.6.29.1/include/linux/ipc.h  2008-12-25 00:26:37.000000000 +0100
8959 +++ linux-2.6.29.1-vs2.3.0.36.9-pre5/include/linux/ipc.h        2009-02-22 22:54:26.000000000 +0100
8960 @@ -93,6 +93,7 @@ struct kern_ipc_perm
8961         key_t           key;
8962         uid_t           uid;
8963         gid_t           gid;
8964 +       xid_t           xid;
8965         uid_t           cuid;
8966         gid_t           cgid;
8967         mode_t          mode; 
8968 diff -NurpP --minimal linux-2.6.29.1/include/linux/Kbuild linux-2.6.29.1-vs2.3.0.36.9-pre5/include/linux/Kbuild
8969 --- linux-2.6.29.1/include/linux/Kbuild 2009-03-24 14:22:40.000000000 +0100
8970 +++ linux-2.6.29.1-vs2.3.0.36.9-pre5/include/linux/Kbuild       2009-03-24 17:22:07.000000000 +0100
8971 @@ -373,5 +373,8 @@ unifdef-y += xattr.h
8972  unifdef-y += xfrm.h
8973  
8974  objhdr-y += version.h
8975 +
8976 +header-y += vserver/
8977  header-y += wimax.h
8978  header-y += wimax/
8979 +
8980 diff -NurpP --minimal linux-2.6.29.1/include/linux/loop.h linux-2.6.29.1-vs2.3.0.36.9-pre5/include/linux/loop.h
8981 --- linux-2.6.29.1/include/linux/loop.h 2009-03-24 14:22:42.000000000 +0100
8982 +++ linux-2.6.29.1-vs2.3.0.36.9-pre5/include/linux/loop.h       2009-03-24 14:48:36.000000000 +0100
8983 @@ -45,6 +45,7 @@ struct loop_device {
8984         struct loop_func_table *lo_encryption;
8985         __u32           lo_init[2];
8986         uid_t           lo_key_owner;   /* Who set the key */
8987 +       xid_t           lo_xid;
8988         int             (*ioctl)(struct loop_device *, int cmd, 
8989                                  unsigned long arg); 
8990  
8991 diff -NurpP --minimal linux-2.6.29.1/include/linux/magic.h linux-2.6.29.1-vs2.3.0.36.9-pre5/include/linux/magic.h
8992 --- linux-2.6.29.1/include/linux/magic.h        2009-03-24 14:22:42.000000000 +0100
8993 +++ linux-2.6.29.1-vs2.3.0.36.9-pre5/include/linux/magic.h      2009-03-24 14:48:36.000000000 +0100
8994 @@ -3,7 +3,7 @@
8995  
8996  #define ADFS_SUPER_MAGIC       0xadf5
8997  #define AFFS_SUPER_MAGIC       0xadff
8998 -#define AFS_SUPER_MAGIC                0x5346414F
8999 +#define AFS_SUPER_MAGIC                0x5346414F
9000  #define AUTOFS_SUPER_MAGIC     0x0187
9001  #define CODA_SUPER_MAGIC       0x73757245
9002  #define DEBUGFS_MAGIC          0x64626720
9003 @@ -33,6 +33,7 @@
9004  #define NFS_SUPER_MAGIC                0x6969
9005  #define OPENPROM_SUPER_MAGIC   0x9fa1
9006  #define PROC_SUPER_MAGIC       0x9fa0
9007 +#define DEVPTS_SUPER_MAGIC     0x1cd1
9008  #define QNX4_SUPER_MAGIC       0x002f          /* qnx4 fs detection */
9009  
9010  #define REISERFS_SUPER_MAGIC   0x52654973      /* used by gcc */
9011 diff -NurpP --minimal linux-2.6.29.1/include/linux/major.h linux-2.6.29.1-vs2.3.0.36.9-pre5/include/linux/major.h
9012 --- linux-2.6.29.1/include/linux/major.h        2008-12-25 00:26:37.000000000 +0100
9013 +++ linux-2.6.29.1-vs2.3.0.36.9-pre5/include/linux/major.h      2009-02-22 22:54:26.000000000 +0100
9014 @@ -15,6 +15,7 @@
9015  #define HD_MAJOR               IDE0_MAJOR
9016  #define PTY_SLAVE_MAJOR                3
9017  #define TTY_MAJOR              4
9018 +#define VROOT_MAJOR            4
9019  #define TTYAUX_MAJOR           5
9020  #define LP_MAJOR               6
9021  #define VCS_MAJOR              7
9022 diff -NurpP --minimal linux-2.6.29.1/include/linux/mm_types.h linux-2.6.29.1-vs2.3.0.36.9-pre5/include/linux/mm_types.h
9023 --- linux-2.6.29.1/include/linux/mm_types.h     2009-03-24 14:22:42.000000000 +0100
9024 +++ linux-2.6.29.1-vs2.3.0.36.9-pre5/include/linux/mm_types.h   2009-03-24 14:48:36.000000000 +0100
9025 @@ -232,6 +232,7 @@ struct mm_struct {
9026  
9027         /* Architecture-specific MM context */
9028         mm_context_t context;
9029 +       struct vx_info *mm_vx_info;
9030  
9031         /* Swap token stuff */
9032         /*
9033 diff -NurpP --minimal linux-2.6.29.1/include/linux/mount.h linux-2.6.29.1-vs2.3.0.36.9-pre5/include/linux/mount.h
9034 --- linux-2.6.29.1/include/linux/mount.h        2008-12-25 00:26:37.000000000 +0100
9035 +++ linux-2.6.29.1-vs2.3.0.36.9-pre5/include/linux/mount.h      2009-02-22 22:54:26.000000000 +0100
9036 @@ -35,6 +35,9 @@ struct mnt_namespace;
9037  #define MNT_UNBINDABLE 0x2000  /* if the vfsmount is a unbindable mount */
9038  #define MNT_PNODE_MASK 0x3000  /* propagation flag mask */
9039  
9040 +#define MNT_TAGID      0x10000
9041 +#define MNT_NOTAG      0x20000
9042 +
9043  struct vfsmount {
9044         struct list_head mnt_hash;
9045         struct vfsmount *mnt_parent;    /* fs we are mounted on */
9046 @@ -69,6 +72,7 @@ struct vfsmount {
9047          * are held, and all mnt_writer[]s on this mount have 0 as their ->count
9048          */
9049         atomic_t __mnt_writers;
9050 +       tag_t mnt_tag;                  /* tagging used for vfsmount */
9051  };
9052  
9053  static inline struct vfsmount *mntget(struct vfsmount *mnt)
9054 diff -NurpP --minimal linux-2.6.29.1/include/linux/net.h linux-2.6.29.1-vs2.3.0.36.9-pre5/include/linux/net.h
9055 --- linux-2.6.29.1/include/linux/net.h  2008-12-25 00:26:37.000000000 +0100
9056 +++ linux-2.6.29.1-vs2.3.0.36.9-pre5/include/linux/net.h        2009-02-22 22:54:26.000000000 +0100
9057 @@ -68,6 +68,7 @@ struct net;
9058  #define SOCK_NOSPACE           2
9059  #define SOCK_PASSCRED          3
9060  #define SOCK_PASSSEC           4
9061 +#define SOCK_USER_SOCKET       5
9062  
9063  #ifndef ARCH_HAS_SOCKET_TYPES
9064  /**
9065 diff -NurpP --minimal linux-2.6.29.1/include/linux/nfs_mount.h linux-2.6.29.1-vs2.3.0.36.9-pre5/include/linux/nfs_mount.h
9066 --- linux-2.6.29.1/include/linux/nfs_mount.h    2009-03-24 14:22:43.000000000 +0100
9067 +++ linux-2.6.29.1-vs2.3.0.36.9-pre5/include/linux/nfs_mount.h  2009-03-24 14:48:36.000000000 +0100
9068 @@ -63,7 +63,8 @@ struct nfs_mount_data {
9069  #define NFS_MOUNT_SECFLAVOUR   0x2000  /* 5 */
9070  #define NFS_MOUNT_NORDIRPLUS   0x4000  /* 5 */
9071  #define NFS_MOUNT_UNSHARED     0x8000  /* 5 */
9072 -#define NFS_MOUNT_FLAGMASK     0xFFFF
9073 +#define NFS_MOUNT_TAGGED       0x10000 /* context tagging */
9074 +#define NFS_MOUNT_FLAGMASK     0x1FFFF
9075  
9076  /* The following are for internal use only */
9077  #define NFS_MOUNT_LOOKUP_CACHE_NONEG   0x10000
9078 diff -NurpP --minimal linux-2.6.29.1/include/linux/nsproxy.h linux-2.6.29.1-vs2.3.0.36.9-pre5/include/linux/nsproxy.h
9079 --- linux-2.6.29.1/include/linux/nsproxy.h      2009-03-24 14:22:43.000000000 +0100
9080 +++ linux-2.6.29.1-vs2.3.0.36.9-pre5/include/linux/nsproxy.h    2009-03-24 14:48:36.000000000 +0100
9081 @@ -3,6 +3,7 @@
9082  
9083  #include <linux/spinlock.h>
9084  #include <linux/sched.h>
9085 +#include <linux/vserver/debug.h>
9086  
9087  struct mnt_namespace;
9088  struct uts_namespace;
9089 @@ -62,22 +63,33 @@ static inline struct nsproxy *task_nspro
9090  }
9091  
9092  int copy_namespaces(unsigned long flags, struct task_struct *tsk);
9093 +struct nsproxy *copy_nsproxy(struct nsproxy *orig);
9094  void exit_task_namespaces(struct task_struct *tsk);
9095  void switch_task_namespaces(struct task_struct *tsk, struct nsproxy *new);
9096  void free_nsproxy(struct nsproxy *ns);
9097  int unshare_nsproxy_namespaces(unsigned long, struct nsproxy **,
9098         struct fs_struct *);
9099  
9100 -static inline void put_nsproxy(struct nsproxy *ns)
9101 +#define        get_nsproxy(n)  __get_nsproxy(n, __FILE__, __LINE__)
9102 +
9103 +static inline void __get_nsproxy(struct nsproxy *ns,
9104 +       const char *_file, int _line)
9105  {
9106 -       if (atomic_dec_and_test(&ns->count)) {
9107 -               free_nsproxy(ns);
9108 -       }
9109 +       vxlprintk(VXD_CBIT(space, 0), "get_nsproxy(%p[%u])",
9110 +               ns, atomic_read(&ns->count), _file, _line);
9111 +       atomic_inc(&ns->count);
9112  }
9113  
9114 -static inline void get_nsproxy(struct nsproxy *ns)
9115 +#define        put_nsproxy(n)  __put_nsproxy(n, __FILE__, __LINE__)
9116 +
9117 +static inline void __put_nsproxy(struct nsproxy *ns,
9118 +       const char *_file, int _line)
9119  {
9120 -       atomic_inc(&ns->count);
9121 +       vxlprintk(VXD_CBIT(space, 0), "put_nsproxy(%p[%u])",
9122 +               ns, atomic_read(&ns->count), _file, _line);
9123 +       if (atomic_dec_and_test(&ns->count)) {
9124 +               free_nsproxy(ns);
9125 +       }
9126  }
9127  
9128  #ifdef CONFIG_CGROUP_NS
9129 diff -NurpP --minimal linux-2.6.29.1/include/linux/pid.h linux-2.6.29.1-vs2.3.0.36.9-pre5/include/linux/pid.h
9130 --- linux-2.6.29.1/include/linux/pid.h  2009-03-24 14:22:43.000000000 +0100
9131 +++ linux-2.6.29.1-vs2.3.0.36.9-pre5/include/linux/pid.h        2009-03-24 14:48:36.000000000 +0100
9132 @@ -8,7 +8,8 @@ enum pid_type
9133         PIDTYPE_PID,
9134         PIDTYPE_PGID,
9135         PIDTYPE_SID,
9136 -       PIDTYPE_MAX
9137 +       PIDTYPE_MAX,
9138 +       PIDTYPE_REALPID
9139  };
9140  
9141  /*
9142 @@ -160,6 +161,7 @@ static inline pid_t pid_nr(struct pid *p
9143  }
9144  
9145  pid_t pid_nr_ns(struct pid *pid, struct pid_namespace *ns);
9146 +pid_t pid_unmapped_nr_ns(struct pid *pid, struct pid_namespace *ns);
9147  pid_t pid_vnr(struct pid *pid);
9148  
9149  #define do_each_pid_task(pid, type, task)                              \
9150 diff -NurpP --minimal linux-2.6.29.1/include/linux/proc_fs.h linux-2.6.29.1-vs2.3.0.36.9-pre5/include/linux/proc_fs.h
9151 --- linux-2.6.29.1/include/linux/proc_fs.h      2008-12-25 00:26:37.000000000 +0100
9152 +++ linux-2.6.29.1-vs2.3.0.36.9-pre5/include/linux/proc_fs.h    2009-02-22 22:54:26.000000000 +0100
9153 @@ -59,6 +59,7 @@ struct proc_dir_entry {
9154         nlink_t nlink;
9155         uid_t uid;
9156         gid_t gid;
9157 +       int vx_flags;
9158         loff_t size;
9159         const struct inode_operations *proc_iops;
9160         /*
9161 @@ -268,12 +269,18 @@ static inline void kclist_add(struct kco
9162  extern void kclist_add(struct kcore_list *, void *, size_t);
9163  #endif
9164  
9165 +struct vx_info;
9166 +struct nx_info;
9167 +
9168  union proc_op {
9169         int (*proc_get_link)(struct inode *, struct path *);
9170         int (*proc_read)(struct task_struct *task, char *page);
9171         int (*proc_show)(struct seq_file *m,
9172                 struct pid_namespace *ns, struct pid *pid,
9173                 struct task_struct *task);
9174 +       int (*proc_vs_read)(char *page);
9175 +       int (*proc_vxi_read)(struct vx_info *vxi, char *page);
9176 +       int (*proc_nxi_read)(struct nx_info *nxi, char *page);
9177  };
9178  
9179  struct ctl_table_header;
9180 @@ -281,6 +288,7 @@ struct ctl_table;
9181  
9182  struct proc_inode {
9183         struct pid *pid;
9184 +       int vx_flags;
9185         int fd;
9186         union proc_op op;
9187         struct proc_dir_entry *pde;
9188 diff -NurpP --minimal linux-2.6.29.1/include/linux/reiserfs_fs.h linux-2.6.29.1-vs2.3.0.36.9-pre5/include/linux/reiserfs_fs.h
9189 --- linux-2.6.29.1/include/linux/reiserfs_fs.h  2008-12-25 00:26:37.000000000 +0100
9190 +++ linux-2.6.29.1-vs2.3.0.36.9-pre5/include/linux/reiserfs_fs.h        2009-02-22 22:54:26.000000000 +0100
9191 @@ -837,6 +837,11 @@ struct stat_data_v1 {
9192  #define REISERFS_COMPR_FL     FS_COMPR_FL
9193  #define REISERFS_NOTAIL_FL    FS_NOTAIL_FL
9194  
9195 +/* unfortunately reiserfs sdattr is only 16 bit */
9196 +#define REISERFS_IXUNLINK_FL  (FS_IXUNLINK_FL >> 16)
9197 +#define REISERFS_BARRIER_FL   (FS_BARRIER_FL >> 16)
9198 +#define REISERFS_COW_FL       (FS_COW_FL >> 16)
9199 +
9200  /* persistent flags that file inherits from the parent directory */
9201  #define REISERFS_INHERIT_MASK ( REISERFS_IMMUTABLE_FL |        \
9202                                 REISERFS_SYNC_FL |      \
9203 @@ -846,6 +851,9 @@ struct stat_data_v1 {
9204                                 REISERFS_COMPR_FL |     \
9205                                 REISERFS_NOTAIL_FL )
9206  
9207 +#define REISERFS_FL_USER_VISIBLE       0x80FF
9208 +#define REISERFS_FL_USER_MODIFIABLE    0x80FF
9209 +
9210  /* Stat Data on disk (reiserfs version of UFS disk inode minus the
9211     address blocks) */
9212  struct stat_data {
9213 @@ -1911,6 +1919,7 @@ static inline void reiserfs_update_sd(st
9214  void sd_attrs_to_i_attrs(__u16 sd_attrs, struct inode *inode);
9215  void i_attrs_to_sd_attrs(struct inode *inode, __u16 * sd_attrs);
9216  int reiserfs_setattr(struct dentry *dentry, struct iattr *attr);
9217 +int reiserfs_sync_flags(struct inode *inode);
9218  
9219  /* namei.c */
9220  void set_de_name_and_namelen(struct reiserfs_dir_entry *de);
9221 diff -NurpP --minimal linux-2.6.29.1/include/linux/reiserfs_fs_sb.h linux-2.6.29.1-vs2.3.0.36.9-pre5/include/linux/reiserfs_fs_sb.h
9222 --- linux-2.6.29.1/include/linux/reiserfs_fs_sb.h       2008-12-25 00:26:37.000000000 +0100
9223 +++ linux-2.6.29.1-vs2.3.0.36.9-pre5/include/linux/reiserfs_fs_sb.h     2009-02-22 22:54:26.000000000 +0100
9224 @@ -456,6 +456,7 @@ enum reiserfs_mount_options {
9225         REISERFS_POSIXACL,
9226         REISERFS_BARRIER_NONE,
9227         REISERFS_BARRIER_FLUSH,
9228 +       REISERFS_TAGGED,
9229  
9230         /* Actions on error */
9231         REISERFS_ERROR_PANIC,
9232 diff -NurpP --minimal linux-2.6.29.1/include/linux/sched.h linux-2.6.29.1-vs2.3.0.36.9-pre5/include/linux/sched.h
9233 --- linux-2.6.29.1/include/linux/sched.h        2009-03-24 14:22:43.000000000 +0100
9234 +++ linux-2.6.29.1-vs2.3.0.36.9-pre5/include/linux/sched.h      2009-04-08 15:47:01.000000000 +0200
9235 @@ -71,7 +71,6 @@ struct sched_param {
9236  #include <linux/fs_struct.h>
9237  #include <linux/compiler.h>
9238  #include <linux/completion.h>
9239 -#include <linux/pid.h>
9240  #include <linux/percpu.h>
9241  #include <linux/topology.h>
9242  #include <linux/proportions.h>
9243 @@ -88,6 +87,7 @@ struct sched_param {
9244  #include <linux/kobject.h>
9245  #include <linux/latencytop.h>
9246  #include <linux/cred.h>
9247 +#include <linux/pid.h>
9248  
9249  #include <asm/processor.h>
9250  
9251 @@ -176,12 +176,13 @@ extern unsigned long long time_sync_thre
9252  #define TASK_UNINTERRUPTIBLE   2
9253  #define __TASK_STOPPED         4
9254  #define __TASK_TRACED          8
9255 +#define TASK_ONHOLD            16
9256  /* in tsk->exit_state */
9257 -#define EXIT_ZOMBIE            16
9258 -#define EXIT_DEAD              32
9259 +#define EXIT_ZOMBIE            32
9260 +#define EXIT_DEAD              64
9261  /* in tsk->state again */
9262 -#define TASK_DEAD              64
9263 -#define TASK_WAKEKILL          128
9264 +#define TASK_DEAD              128
9265 +#define TASK_WAKEKILL          256
9266  
9267  /* Convenience macros for the sake of set_task_state */
9268  #define TASK_KILLABLE          (TASK_WAKEKILL | TASK_UNINTERRUPTIBLE)
9269 @@ -358,25 +359,28 @@ extern void arch_unmap_area_topdown(stru
9270   * The mm counters are not protected by its page_table_lock,
9271   * so must be incremented atomically.
9272   */
9273 -#define set_mm_counter(mm, member, value) atomic_long_set(&(mm)->_##member, value)
9274 -#define get_mm_counter(mm, member) ((unsigned long)atomic_long_read(&(mm)->_##member))
9275 -#define add_mm_counter(mm, member, value) atomic_long_add(value, &(mm)->_##member)
9276 -#define inc_mm_counter(mm, member) atomic_long_inc(&(mm)->_##member)
9277 -#define dec_mm_counter(mm, member) atomic_long_dec(&(mm)->_##member)
9278 +#define __set_mm_counter(mm, member, value) \
9279 +       atomic_long_set(&(mm)->_##member, value)
9280 +#define get_mm_counter(mm, member) \
9281 +       ((unsigned long)atomic_long_read(&(mm)->_##member))
9282  
9283  #else  /* !USE_SPLIT_PTLOCKS */
9284  /*
9285   * The mm counters are protected by its page_table_lock,
9286   * so can be incremented directly.
9287   */
9288 -#define set_mm_counter(mm, member, value) (mm)->_##member = (value)
9289 +#define __set_mm_counter(mm, member, value) (mm)->_##member = (value)
9290  #define get_mm_counter(mm, member) ((mm)->_##member)
9291 -#define add_mm_counter(mm, member, value) (mm)->_##member += (value)
9292 -#define inc_mm_counter(mm, member) (mm)->_##member++
9293 -#define dec_mm_counter(mm, member) (mm)->_##member--
9294  
9295  #endif /* !USE_SPLIT_PTLOCKS */
9296  
9297 +#define set_mm_counter(mm, member, value) \
9298 +       vx_ ## member ## pages_sub((mm), (get_mm_counter(mm, member) - value))
9299 +#define add_mm_counter(mm, member, value) \
9300 +       vx_ ## member ## pages_add((mm), (value))
9301 +#define inc_mm_counter(mm, member) vx_ ## member ## pages_inc((mm))
9302 +#define dec_mm_counter(mm, member) vx_ ## member ## pages_dec((mm))
9303 +
9304  #define get_mm_rss(mm)                                 \
9305         (get_mm_counter(mm, file_rss) + get_mm_counter(mm, anon_rss))
9306  #define update_hiwater_rss(mm) do {                    \
9307 @@ -1131,7 +1135,9 @@ struct task_struct {
9308         const struct sched_class *sched_class;
9309         struct sched_entity se;
9310         struct sched_rt_entity rt;
9311 -
9312 +#ifdef CONFIG_VSERVER_HARDCPU
9313 +       struct list_head hq;
9314 +#endif
9315  #ifdef CONFIG_PREEMPT_NOTIFIERS
9316         /* list of struct preempt_notifier: */
9317         struct hlist_head preempt_notifiers;
9318 @@ -1287,6 +1293,14 @@ struct task_struct {
9319  #endif
9320         seccomp_t seccomp;
9321  
9322 +/* vserver context data */
9323 +       struct vx_info *vx_info;
9324 +       struct nx_info *nx_info;
9325 +
9326 +       xid_t xid;
9327 +       nid_t nid;
9328 +       tag_t tag;
9329 +
9330  /* Thread group tracking */
9331         u32 parent_exec_id;
9332         u32 self_exec_id;
9333 @@ -1499,6 +1513,11 @@ struct pid_namespace;
9334   * see also pid_nr() etc in include/linux/pid.h
9335   */
9336  
9337 +#include <linux/vserver/base.h>
9338 +#include <linux/vserver/context.h>
9339 +#include <linux/vserver/debug.h>
9340 +#include <linux/vserver/pid.h>
9341 +
9342  static inline pid_t task_pid_nr(struct task_struct *tsk)
9343  {
9344         return tsk->pid;
9345 @@ -1508,7 +1527,7 @@ pid_t task_pid_nr_ns(struct task_struct 
9346  
9347  static inline pid_t task_pid_vnr(struct task_struct *tsk)
9348  {
9349 -       return pid_vnr(task_pid(tsk));
9350 +       return vx_map_pid(pid_vnr(task_pid(tsk)));
9351  }
9352  
9353  
9354 @@ -1521,7 +1540,7 @@ pid_t task_tgid_nr_ns(struct task_struct
9355  
9356  static inline pid_t task_tgid_vnr(struct task_struct *tsk)
9357  {
9358 -       return pid_vnr(task_tgid(tsk));
9359 +       return vx_map_tgid(pid_vnr(task_tgid(tsk)));
9360  }
9361  
9362  
9363 diff -NurpP --minimal linux-2.6.29.1/include/linux/shmem_fs.h linux-2.6.29.1-vs2.3.0.36.9-pre5/include/linux/shmem_fs.h
9364 --- linux-2.6.29.1/include/linux/shmem_fs.h     2008-12-25 00:26:37.000000000 +0100
9365 +++ linux-2.6.29.1-vs2.3.0.36.9-pre5/include/linux/shmem_fs.h   2009-02-22 22:54:26.000000000 +0100
9366 @@ -8,6 +8,9 @@
9367  
9368  #define SHMEM_NR_DIRECT 16
9369  
9370 +#define TMPFS_SUPER_MAGIC      0x01021994
9371 +
9372 +
9373  struct shmem_inode_info {
9374         spinlock_t              lock;
9375         unsigned long           flags;
9376 diff -NurpP --minimal linux-2.6.29.1/include/linux/stat.h linux-2.6.29.1-vs2.3.0.36.9-pre5/include/linux/stat.h
9377 --- linux-2.6.29.1/include/linux/stat.h 2008-12-25 00:26:37.000000000 +0100
9378 +++ linux-2.6.29.1-vs2.3.0.36.9-pre5/include/linux/stat.h       2009-02-22 22:54:26.000000000 +0100
9379 @@ -66,6 +66,7 @@ struct kstat {
9380         unsigned int    nlink;
9381         uid_t           uid;
9382         gid_t           gid;
9383 +       tag_t           tag;
9384         dev_t           rdev;
9385         loff_t          size;
9386         struct timespec  atime;
9387 diff -NurpP --minimal linux-2.6.29.1/include/linux/sunrpc/auth.h linux-2.6.29.1-vs2.3.0.36.9-pre5/include/linux/sunrpc/auth.h
9388 --- linux-2.6.29.1/include/linux/sunrpc/auth.h  2008-12-25 00:26:37.000000000 +0100
9389 +++ linux-2.6.29.1-vs2.3.0.36.9-pre5/include/linux/sunrpc/auth.h        2009-02-22 22:54:26.000000000 +0100
9390 @@ -25,6 +25,7 @@
9391  struct auth_cred {
9392         uid_t   uid;
9393         gid_t   gid;
9394 +       tag_t   tag;
9395         struct group_info *group_info;
9396         unsigned char machine_cred : 1;
9397  };
9398 diff -NurpP --minimal linux-2.6.29.1/include/linux/sunrpc/clnt.h linux-2.6.29.1-vs2.3.0.36.9-pre5/include/linux/sunrpc/clnt.h
9399 --- linux-2.6.29.1/include/linux/sunrpc/clnt.h  2009-03-24 14:22:43.000000000 +0100
9400 +++ linux-2.6.29.1-vs2.3.0.36.9-pre5/include/linux/sunrpc/clnt.h        2009-03-24 14:48:36.000000000 +0100
9401 @@ -43,7 +43,8 @@ struct rpc_clnt {
9402         unsigned int            cl_softrtry : 1,/* soft timeouts */
9403                                 cl_discrtry : 1,/* disconnect before retry */
9404                                 cl_autobind : 1,/* use getport() */
9405 -                               cl_chatty   : 1;/* be verbose */
9406 +                               cl_chatty   : 1,/* be verbose */
9407 +                               cl_tag      : 1;/* context tagging */
9408  
9409         struct rpc_rtt *        cl_rtt;         /* RTO estimator data */
9410         const struct rpc_timeout *cl_timeout;   /* Timeout strategy */
9411 diff -NurpP --minimal linux-2.6.29.1/include/linux/syscalls.h linux-2.6.29.1-vs2.3.0.36.9-pre5/include/linux/syscalls.h
9412 --- linux-2.6.29.1/include/linux/syscalls.h     2009-03-24 14:22:43.000000000 +0100
9413 +++ linux-2.6.29.1-vs2.3.0.36.9-pre5/include/linux/syscalls.h   2009-03-24 14:48:36.000000000 +0100
9414 @@ -369,6 +369,8 @@ asmlinkage long sys_symlink(const char _
9415  asmlinkage long sys_unlink(const char __user *pathname);
9416  asmlinkage long sys_rename(const char __user *oldname,
9417                                 const char __user *newname);
9418 +asmlinkage long sys_copyfile(const char __user *from, const char __user *to,
9419 +                               umode_t mode);
9420  asmlinkage long sys_chmod(const char __user *filename, mode_t mode);
9421  asmlinkage long sys_fchmod(unsigned int fd, mode_t mode);
9422  
9423 diff -NurpP --minimal linux-2.6.29.1/include/linux/sysctl.h linux-2.6.29.1-vs2.3.0.36.9-pre5/include/linux/sysctl.h
9424 --- linux-2.6.29.1/include/linux/sysctl.h       2008-12-25 00:26:37.000000000 +0100
9425 +++ linux-2.6.29.1-vs2.3.0.36.9-pre5/include/linux/sysctl.h     2009-02-22 22:54:26.000000000 +0100
9426 @@ -70,6 +70,7 @@ enum
9427         CTL_ABI=9,              /* Binary emulation */
9428         CTL_CPU=10,             /* CPU stuff (speed scaling, etc) */
9429         CTL_ARLAN=254,          /* arlan wireless driver */
9430 +       CTL_VSERVER=4242,       /* Linux-VServer debug */
9431         CTL_S390DBF=5677,       /* s390 debug */
9432         CTL_SUNRPC=7249,        /* sunrpc debug */
9433         CTL_PM=9899,            /* frv power management */
9434 @@ -104,6 +105,7 @@ enum
9435  
9436         KERN_PANIC=15,          /* int: panic timeout */
9437         KERN_REALROOTDEV=16,    /* real root device to mount after initrd */
9438 +       KERN_VSHELPER=17,       /* string: path to vshelper policy agent */
9439  
9440         KERN_SPARC_REBOOT=21,   /* reboot command on Sparc */
9441         KERN_CTLALTDEL=22,      /* int: allow ctl-alt-del to reboot */
9442 diff -NurpP --minimal linux-2.6.29.1/include/linux/sysfs.h linux-2.6.29.1-vs2.3.0.36.9-pre5/include/linux/sysfs.h
9443 --- linux-2.6.29.1/include/linux/sysfs.h        2008-12-25 00:26:37.000000000 +0100
9444 +++ linux-2.6.29.1-vs2.3.0.36.9-pre5/include/linux/sysfs.h      2009-02-22 22:54:26.000000000 +0100
9445 @@ -17,6 +17,8 @@
9446  #include <linux/list.h>
9447  #include <asm/atomic.h>
9448  
9449 +#define SYSFS_SUPER_MAGIC      0x62656572
9450 +
9451  struct kobject;
9452  struct module;
9453  
9454 diff -NurpP --minimal linux-2.6.29.1/include/linux/time.h linux-2.6.29.1-vs2.3.0.36.9-pre5/include/linux/time.h
9455 --- linux-2.6.29.1/include/linux/time.h 2009-03-24 14:22:43.000000000 +0100
9456 +++ linux-2.6.29.1-vs2.3.0.36.9-pre5/include/linux/time.h       2009-02-22 22:54:26.000000000 +0100
9457 @@ -190,6 +190,9 @@ static __always_inline void timespec_add
9458         a->tv_sec += __iter_div_u64_rem(a->tv_nsec + ns, NSEC_PER_SEC, &ns);
9459         a->tv_nsec = ns;
9460  }
9461 +
9462 +#include <linux/vs_time.h>
9463 +
9464  #endif /* __KERNEL__ */
9465  
9466  #define NFDBITS                        __NFDBITS
9467 diff -NurpP --minimal linux-2.6.29.1/include/linux/types.h linux-2.6.29.1-vs2.3.0.36.9-pre5/include/linux/types.h
9468 --- linux-2.6.29.1/include/linux/types.h        2009-03-24 14:22:43.000000000 +0100
9469 +++ linux-2.6.29.1-vs2.3.0.36.9-pre5/include/linux/types.h      2009-03-24 14:48:36.000000000 +0100
9470 @@ -36,6 +36,9 @@ typedef __kernel_uid32_t      uid_t;
9471  typedef __kernel_gid32_t       gid_t;
9472  typedef __kernel_uid16_t        uid16_t;
9473  typedef __kernel_gid16_t        gid16_t;
9474 +typedef unsigned int           xid_t;
9475 +typedef unsigned int           nid_t;
9476 +typedef unsigned int           tag_t;
9477  
9478  typedef unsigned long          uintptr_t;
9479  
9480 diff -NurpP --minimal linux-2.6.29.1/include/linux/vroot.h linux-2.6.29.1-vs2.3.0.36.9-pre5/include/linux/vroot.h
9481 --- linux-2.6.29.1/include/linux/vroot.h        1970-01-01 01:00:00.000000000 +0100
9482 +++ linux-2.6.29.1-vs2.3.0.36.9-pre5/include/linux/vroot.h      2009-02-22 22:54:26.000000000 +0100
9483 @@ -0,0 +1,51 @@
9484 +
9485 +/*
9486 + * include/linux/vroot.h
9487 + *
9488 + * written by Herbert Pötzl, 9/11/2002
9489 + * ported to 2.6 by Herbert Pötzl, 30/12/2004
9490 + *
9491 + * Copyright (C) 2002-2007 by Herbert Pötzl.
9492 + * Redistribution of this file is permitted under the
9493 + * GNU General Public License.
9494 + */
9495 +
9496 +#ifndef _LINUX_VROOT_H
9497 +#define _LINUX_VROOT_H
9498 +
9499 +
9500 +#ifdef __KERNEL__
9501 +
9502 +/* Possible states of device */
9503 +enum {
9504 +       Vr_unbound,
9505 +       Vr_bound,
9506 +};
9507 +
9508 +struct vroot_device {
9509 +       int             vr_number;
9510 +       int             vr_refcnt;
9511 +
9512 +       struct semaphore        vr_ctl_mutex;
9513 +       struct block_device    *vr_device;
9514 +       int                     vr_state;
9515 +};
9516 +
9517 +
9518 +typedef struct block_device *(vroot_grb_func)(struct block_device *);
9519 +
9520 +extern int register_vroot_grb(vroot_grb_func *);
9521 +extern int unregister_vroot_grb(vroot_grb_func *);
9522 +
9523 +#endif /* __KERNEL__ */
9524 +
9525 +#define MAX_VROOT_DEFAULT      8
9526 +
9527 +/*
9528 + * IOCTL commands --- we will commandeer 0x56 ('V')
9529 + */
9530 +
9531 +#define VROOT_SET_DEV          0x5600
9532 +#define VROOT_CLR_DEV          0x5601
9533 +
9534 +#endif /* _LINUX_VROOT_H */
9535 diff -NurpP --minimal linux-2.6.29.1/include/linux/vs_base.h linux-2.6.29.1-vs2.3.0.36.9-pre5/include/linux/vs_base.h
9536 --- linux-2.6.29.1/include/linux/vs_base.h      1970-01-01 01:00:00.000000000 +0100
9537 +++ linux-2.6.29.1-vs2.3.0.36.9-pre5/include/linux/vs_base.h    2009-02-22 22:54:26.000000000 +0100
9538 @@ -0,0 +1,10 @@
9539 +#ifndef _VS_BASE_H
9540 +#define _VS_BASE_H
9541 +
9542 +#include "vserver/base.h"
9543 +#include "vserver/check.h"
9544 +#include "vserver/debug.h"
9545 +
9546 +#else
9547 +#warning duplicate inclusion
9548 +#endif
9549 diff -NurpP --minimal linux-2.6.29.1/include/linux/vs_context.h linux-2.6.29.1-vs2.3.0.36.9-pre5/include/linux/vs_context.h
9550 --- linux-2.6.29.1/include/linux/vs_context.h   1970-01-01 01:00:00.000000000 +0100
9551 +++ linux-2.6.29.1-vs2.3.0.36.9-pre5/include/linux/vs_context.h 2009-02-22 22:54:26.000000000 +0100
9552 @@ -0,0 +1,227 @@
9553 +#ifndef _VS_CONTEXT_H
9554 +#define _VS_CONTEXT_H
9555 +
9556 +#include "vserver/base.h"
9557 +#include "vserver/check.h"
9558 +#include "vserver/context.h"
9559 +#include "vserver/history.h"
9560 +#include "vserver/debug.h"
9561 +
9562 +#include <linux/sched.h>
9563 +
9564 +
9565 +#define get_vx_info(i) __get_vx_info(i, __FILE__, __LINE__, __HERE__)
9566 +
9567 +static inline struct vx_info *__get_vx_info(struct vx_info *vxi,
9568 +       const char *_file, int _line, void *_here)
9569 +{
9570 +       if (!vxi)
9571 +               return NULL;
9572 +
9573 +       vxlprintk(VXD_CBIT(xid, 2), "get_vx_info(%p[#%d.%d])",
9574 +               vxi, vxi ? vxi->vx_id : 0,
9575 +               vxi ? atomic_read(&vxi->vx_usecnt) : 0,
9576 +               _file, _line);
9577 +       __vxh_get_vx_info(vxi, _here);
9578 +
9579 +       atomic_inc(&vxi->vx_usecnt);
9580 +       return vxi;
9581 +}
9582 +
9583 +
9584 +extern void free_vx_info(struct vx_info *);
9585 +
9586 +#define put_vx_info(i) __put_vx_info(i, __FILE__, __LINE__, __HERE__)
9587 +
9588 +static inline void __put_vx_info(struct vx_info *vxi,
9589 +       const char *_file, int _line, void *_here)
9590 +{
9591 +       if (!vxi)
9592 +               return;
9593 +
9594 +       vxlprintk(VXD_CBIT(xid, 2), "put_vx_info(%p[#%d.%d])",
9595 +               vxi, vxi ? vxi->vx_id : 0,
9596 +               vxi ? atomic_read(&vxi->vx_usecnt) : 0,
9597 +               _file, _line);
9598 +       __vxh_put_vx_info(vxi, _here);
9599 +
9600 +       if (atomic_dec_and_test(&vxi->vx_usecnt))
9601 +               free_vx_info(vxi);
9602 +}
9603 +
9604 +
9605 +#define init_vx_info(p, i) \
9606 +       __init_vx_info(p, i, __FILE__, __LINE__, __HERE__)
9607 +
9608 +static inline void __init_vx_info(struct vx_info **vxp, struct vx_info *vxi,
9609 +       const char *_file, int _line, void *_here)
9610 +{
9611 +       if (vxi) {
9612 +               vxlprintk(VXD_CBIT(xid, 3),
9613 +                       "init_vx_info(%p[#%d.%d])",
9614 +                       vxi, vxi ? vxi->vx_id : 0,
9615 +                       vxi ? atomic_read(&vxi->vx_usecnt) : 0,
9616 +                       _file, _line);
9617 +               __vxh_init_vx_info(vxi, vxp, _here);
9618 +
9619 +               atomic_inc(&vxi->vx_usecnt);
9620 +       }
9621 +       *vxp = vxi;
9622 +}
9623 +
9624 +
9625 +#define set_vx_info(p, i) \
9626 +       __set_vx_info(p, i, __FILE__, __LINE__, __HERE__)
9627 +
9628 +static inline void __set_vx_info(struct vx_info **vxp, struct vx_info *vxi,
9629 +       const char *_file, int _line, void *_here)
9630 +{
9631 +       struct vx_info *vxo;
9632 +
9633 +       if (!vxi)
9634 +               return;
9635 +
9636 +       vxlprintk(VXD_CBIT(xid, 3), "set_vx_info(%p[#%d.%d])",
9637 +               vxi, vxi ? vxi->vx_id : 0,
9638 +               vxi ? atomic_read(&vxi->vx_usecnt) : 0,
9639 +               _file, _line);
9640 +       __vxh_set_vx_info(vxi, vxp, _here);
9641 +
9642 +       atomic_inc(&vxi->vx_usecnt);
9643 +       vxo = xchg(vxp, vxi);
9644 +       BUG_ON(vxo);
9645 +}
9646 +
9647 +
9648 +#define clr_vx_info(p) __clr_vx_info(p, __FILE__, __LINE__, __HERE__)
9649 +
9650 +static inline void __clr_vx_info(struct vx_info **vxp,
9651 +       const char *_file, int _line, void *_here)
9652 +{
9653 +       struct vx_info *vxo;
9654 +
9655 +       vxo = xchg(vxp, NULL);
9656 +       if (!vxo)
9657 +               return;
9658 +
9659 +       vxlprintk(VXD_CBIT(xid, 3), "clr_vx_info(%p[#%d.%d])",
9660 +               vxo, vxo ? vxo->vx_id : 0,
9661 +               vxo ? atomic_read(&vxo->vx_usecnt) : 0,
9662 +               _file, _line);
9663 +       __vxh_clr_vx_info(vxo, vxp, _here);
9664 +
9665 +       if (atomic_dec_and_test(&vxo->vx_usecnt))
9666 +               free_vx_info(vxo);
9667 +}
9668 +
9669 +
9670 +#define claim_vx_info(v, p) \
9671 +       __claim_vx_info(v, p, __FILE__, __LINE__, __HERE__)
9672 +
9673 +static inline void __claim_vx_info(struct vx_info *vxi,
9674 +       struct task_struct *task,
9675 +       const char *_file, int _line, void *_here)
9676 +{
9677 +       vxlprintk(VXD_CBIT(xid, 3), "claim_vx_info(%p[#%d.%d.%d]) %p",
9678 +               vxi, vxi ? vxi->vx_id : 0,
9679 +               vxi ? atomic_read(&vxi->vx_usecnt) : 0,
9680 +               vxi ? atomic_read(&vxi->vx_tasks) : 0,
9681 +               task, _file, _line);
9682 +       __vxh_claim_vx_info(vxi, task, _here);
9683 +
9684 +       atomic_inc(&vxi->vx_tasks);
9685 +}
9686 +
9687 +
9688 +extern void unhash_vx_info(struct vx_info *);
9689 +
9690 +#define release_vx_info(v, p) \
9691 +       __release_vx_info(v, p, __FILE__, __LINE__, __HERE__)
9692 +
9693 +static inline void __release_vx_info(struct vx_info *vxi,
9694 +       struct task_struct *task,
9695 +       const char *_file, int _line, void *_here)
9696 +{
9697 +       vxlprintk(VXD_CBIT(xid, 3), "release_vx_info(%p[#%d.%d.%d]) %p",
9698 +               vxi, vxi ? vxi->vx_id : 0,
9699 +               vxi ? atomic_read(&vxi->vx_usecnt) : 0,
9700 +               vxi ? atomic_read(&vxi->vx_tasks) : 0,
9701 +               task, _file, _line);
9702 +       __vxh_release_vx_info(vxi, task, _here);
9703 +
9704 +       might_sleep();
9705 +
9706 +       if (atomic_dec_and_test(&vxi->vx_tasks))
9707 +               unhash_vx_info(vxi);
9708 +}
9709 +
9710 +
9711 +#define task_get_vx_info(p) \
9712 +       __task_get_vx_info(p, __FILE__, __LINE__, __HERE__)
9713 +
9714 +static inline struct vx_info *__task_get_vx_info(struct task_struct *p,
9715 +       const char *_file, int _line, void *_here)
9716 +{
9717 +       struct vx_info *vxi;
9718 +
9719 +       task_lock(p);
9720 +       vxlprintk(VXD_CBIT(xid, 5), "task_get_vx_info(%p)",
9721 +               p, _file, _line);
9722 +       vxi = __get_vx_info(p->vx_info, _file, _line, _here);
9723 +       task_unlock(p);
9724 +       return vxi;
9725 +}
9726 +
9727 +
9728 +static inline void __wakeup_vx_info(struct vx_info *vxi)
9729 +{
9730 +       if (waitqueue_active(&vxi->vx_wait))
9731 +               wake_up_interruptible(&vxi->vx_wait);
9732 +}
9733 +
9734 +
9735 +#define enter_vx_info(v, s) __enter_vx_info(v, s, __FILE__, __LINE__)
9736 +
9737 +static inline void __enter_vx_info(struct vx_info *vxi,
9738 +       struct vx_info_save *vxis, const char *_file, int _line)
9739 +{
9740 +       vxlprintk(VXD_CBIT(xid, 5), "enter_vx_info(%p[#%d],%p) %p[#%d,%p]",
9741 +               vxi, vxi ? vxi->vx_id : 0, vxis, current,
9742 +               current->xid, current->vx_info, _file, _line);
9743 +       vxis->vxi = xchg(&current->vx_info, vxi);
9744 +       vxis->xid = current->xid;
9745 +       current->xid = vxi ? vxi->vx_id : 0;
9746 +}
9747 +
9748 +#define leave_vx_info(s) __leave_vx_info(s, __FILE__, __LINE__)
9749 +
9750 +static inline void __leave_vx_info(struct vx_info_save *vxis,
9751 +       const char *_file, int _line)
9752 +{
9753 +       vxlprintk(VXD_CBIT(xid, 5), "leave_vx_info(%p[#%d,%p]) %p[#%d,%p]",
9754 +               vxis, vxis->xid, vxis->vxi, current,
9755 +               current->xid, current->vx_info, _file, _line);
9756 +       (void)xchg(&current->vx_info, vxis->vxi);
9757 +       current->xid = vxis->xid;
9758 +}
9759 +
9760 +
9761 +static inline void __enter_vx_admin(struct vx_info_save *vxis)
9762 +{
9763 +       vxis->vxi = xchg(&current->vx_info, NULL);
9764 +       vxis->xid = xchg(&current->xid, (xid_t)0);
9765 +}
9766 +
9767 +static inline void __leave_vx_admin(struct vx_info_save *vxis)
9768 +{
9769 +       (void)xchg(&current->xid, vxis->xid);
9770 +       (void)xchg(&current->vx_info, vxis->vxi);
9771 +}
9772 +
9773 +extern void exit_vx_info(struct task_struct *, int);
9774 +extern void exit_vx_info_early(struct task_struct *, int);
9775 +
9776 +
9777 +#else
9778 +#warning duplicate inclusion
9779 +#endif
9780 diff -NurpP --minimal linux-2.6.29.1/include/linux/vs_cowbl.h linux-2.6.29.1-vs2.3.0.36.9-pre5/include/linux/vs_cowbl.h
9781 --- linux-2.6.29.1/include/linux/vs_cowbl.h     1970-01-01 01:00:00.000000000 +0100
9782 +++ linux-2.6.29.1-vs2.3.0.36.9-pre5/include/linux/vs_cowbl.h   2009-02-22 22:54:26.000000000 +0100
9783 @@ -0,0 +1,47 @@
9784 +#ifndef _VS_COWBL_H
9785 +#define _VS_COWBL_H
9786 +
9787 +#include <linux/fs.h>
9788 +#include <linux/dcache.h>
9789 +#include <linux/namei.h>
9790 +
9791 +extern struct dentry *cow_break_link(const char *pathname);
9792 +
9793 +static inline int cow_check_and_break(struct path *path)
9794 +{
9795 +       struct inode *inode = path->dentry->d_inode;
9796 +       int error = 0;
9797 +
9798 +       /* do we need this check? */
9799 +       if (IS_RDONLY(inode))
9800 +               return -EROFS;
9801 +
9802 +       if (IS_COW(inode)) {
9803 +               if (IS_COW_LINK(inode)) {
9804 +                       struct dentry *new_dentry, *old_dentry = path->dentry;
9805 +                       char *pp, *buf;
9806 +
9807 +                       buf = kmalloc(PATH_MAX, GFP_KERNEL);
9808 +                       if (!buf) {
9809 +                               return -ENOMEM;
9810 +                       }
9811 +                       pp = d_path(path, buf, PATH_MAX);
9812 +                       new_dentry = cow_break_link(pp);
9813 +                       kfree(buf);
9814 +                       if (!IS_ERR(new_dentry)) {
9815 +                               path->dentry = new_dentry;
9816 +                               dput(old_dentry);
9817 +                       } else
9818 +                               error = PTR_ERR(new_dentry);
9819 +               } else {
9820 +                       inode->i_flags &= ~(S_IXUNLINK | S_IMMUTABLE);
9821 +                       inode->i_ctime = CURRENT_TIME;
9822 +                       mark_inode_dirty(inode);
9823 +               }
9824 +       }
9825 +       return error;
9826 +}
9827 +
9828 +#else
9829 +#warning duplicate inclusion
9830 +#endif
9831 diff -NurpP --minimal linux-2.6.29.1/include/linux/vs_cvirt.h linux-2.6.29.1-vs2.3.0.36.9-pre5/include/linux/vs_cvirt.h
9832 --- linux-2.6.29.1/include/linux/vs_cvirt.h     1970-01-01 01:00:00.000000000 +0100
9833 +++ linux-2.6.29.1-vs2.3.0.36.9-pre5/include/linux/vs_cvirt.h   2009-02-22 22:54:26.000000000 +0100
9834 @@ -0,0 +1,50 @@
9835 +#ifndef _VS_CVIRT_H
9836 +#define _VS_CVIRT_H
9837 +
9838 +#include "vserver/cvirt.h"
9839 +#include "vserver/context.h"
9840 +#include "vserver/base.h"
9841 +#include "vserver/check.h"
9842 +#include "vserver/debug.h"
9843 +
9844 +
9845 +static inline void vx_activate_task(struct task_struct *p)
9846 +{
9847 +       struct vx_info *vxi;
9848 +
9849 +       if ((vxi = p->vx_info)) {
9850 +               vx_update_load(vxi);
9851 +               atomic_inc(&vxi->cvirt.nr_running);
9852 +       }
9853 +}
9854 +
9855 +static inline void vx_deactivate_task(struct task_struct *p)
9856 +{
9857 +       struct vx_info *vxi;
9858 +
9859 +       if ((vxi = p->vx_info)) {
9860 +               vx_update_load(vxi);
9861 +               atomic_dec(&vxi->cvirt.nr_running);
9862 +       }
9863 +}
9864 +
9865 +static inline void vx_uninterruptible_inc(struct task_struct *p)
9866 +{
9867 +       struct vx_info *vxi;
9868 +
9869 +       if ((vxi = p->vx_info))
9870 +               atomic_inc(&vxi->cvirt.nr_uninterruptible);
9871 +}
9872 +
9873 +static inline void vx_uninterruptible_dec(struct task_struct *p)
9874 +{
9875 +       struct vx_info *vxi;
9876 +
9877 +       if ((vxi = p->vx_info))
9878 +               atomic_dec(&vxi->cvirt.nr_uninterruptible);
9879 +}
9880 +
9881 +
9882 +#else
9883 +#warning duplicate inclusion
9884 +#endif
9885 diff -NurpP --minimal linux-2.6.29.1/include/linux/vs_device.h linux-2.6.29.1-vs2.3.0.36.9-pre5/include/linux/vs_device.h
9886 --- linux-2.6.29.1/include/linux/vs_device.h    1970-01-01 01:00:00.000000000 +0100
9887 +++ linux-2.6.29.1-vs2.3.0.36.9-pre5/include/linux/vs_device.h  2009-02-22 22:54:26.000000000 +0100
9888 @@ -0,0 +1,45 @@
9889 +#ifndef _VS_DEVICE_H
9890 +#define _VS_DEVICE_H
9891 +
9892 +#include "vserver/base.h"
9893 +#include "vserver/device.h"
9894 +#include "vserver/debug.h"
9895 +
9896 +
9897 +#ifdef CONFIG_VSERVER_DEVICE
9898 +
9899 +int vs_map_device(struct vx_info *, dev_t, dev_t *, umode_t);
9900 +
9901 +#define vs_device_perm(v, d, m, p) \
9902 +       ((vs_map_device(current_vx_info(), d, NULL, m) & (p)) == (p))
9903 +
9904 +#else
9905 +
9906 +static inline
9907 +int vs_map_device(struct vx_info *vxi,
9908 +       dev_t device, dev_t *target, umode_t mode)
9909 +{
9910 +       if (target)
9911 +               *target = device;
9912 +       return ~0;
9913 +}
9914 +
9915 +#define vs_device_perm(v, d, m, p) ((p) == (p))
9916 +
9917 +#endif
9918 +
9919 +
9920 +#define vs_map_chrdev(d, t, p) \
9921 +       ((vs_map_device(current_vx_info(), d, t, S_IFCHR) & (p)) == (p))
9922 +#define vs_map_blkdev(d, t, p) \
9923 +       ((vs_map_device(current_vx_info(), d, t, S_IFBLK) & (p)) == (p))
9924 +
9925 +#define vs_chrdev_perm(d, p) \
9926 +       vs_device_perm(current_vx_info(), d, S_IFCHR, p)
9927 +#define vs_blkdev_perm(d, p) \
9928 +       vs_device_perm(current_vx_info(), d, S_IFBLK, p)
9929 +
9930 +
9931 +#else
9932 +#warning duplicate inclusion
9933 +#endif
9934 diff -NurpP --minimal linux-2.6.29.1/include/linux/vs_dlimit.h linux-2.6.29.1-vs2.3.0.36.9-pre5/include/linux/vs_dlimit.h
9935 --- linux-2.6.29.1/include/linux/vs_dlimit.h    1970-01-01 01:00:00.000000000 +0100
9936 +++ linux-2.6.29.1-vs2.3.0.36.9-pre5/include/linux/vs_dlimit.h  2009-02-22 22:54:26.000000000 +0100
9937 @@ -0,0 +1,211 @@
9938 +#ifndef _VS_DLIMIT_H
9939 +#define _VS_DLIMIT_H
9940 +
9941 +#include <linux/fs.h>
9942 +
9943 +#include "vserver/dlimit.h"
9944 +#include "vserver/base.h"
9945 +#include "vserver/debug.h"
9946 +
9947 +
9948 +#define get_dl_info(i) __get_dl_info(i, __FILE__, __LINE__)
9949 +
9950 +static inline struct dl_info *__get_dl_info(struct dl_info *dli,
9951 +       const char *_file, int _line)
9952 +{
9953 +       if (!dli)
9954 +               return NULL;
9955 +       vxlprintk(VXD_CBIT(dlim, 4), "get_dl_info(%p[#%d.%d])",
9956 +               dli, dli ? dli->dl_tag : 0,
9957 +               dli ? atomic_read(&dli->dl_usecnt) : 0,
9958 +               _file, _line);
9959 +       atomic_inc(&dli->dl_usecnt);
9960 +       return dli;
9961 +}
9962 +
9963 +
9964 +#define free_dl_info(i) \
9965 +       call_rcu(&(i)->dl_rcu, rcu_free_dl_info)
9966 +
9967 +#define put_dl_info(i) __put_dl_info(i, __FILE__, __LINE__)
9968 +
9969 +static inline void __put_dl_info(struct dl_info *dli,
9970 +       const char *_file, int _line)
9971 +{
9972 +       if (!dli)
9973 +               return;
9974 +       vxlprintk(VXD_CBIT(dlim, 4), "put_dl_info(%p[#%d.%d])",
9975 +               dli, dli ? dli->dl_tag : 0,
9976 +               dli ? atomic_read(&dli->dl_usecnt) : 0,
9977 +               _file, _line);
9978 +       if (atomic_dec_and_test(&dli->dl_usecnt))
9979 +               free_dl_info(dli);
9980 +}
9981 +
9982 +
9983 +#define __dlimit_char(d)       ((d) ? '*' : ' ')
9984 +
9985 +static inline int __dl_alloc_space(struct super_block *sb,
9986 +       tag_t tag, dlsize_t nr, const char *file, int line)
9987 +{
9988 +       struct dl_info *dli = NULL;
9989 +       int ret = 0;
9990 +
9991 +       if (nr == 0)
9992 +               goto out;
9993 +       dli = locate_dl_info(sb, tag);
9994 +       if (!dli)
9995 +               goto out;
9996 +
9997 +       spin_lock(&dli->dl_lock);
9998 +       ret = (dli->dl_space_used + nr > dli->dl_space_total);
9999 +       if (!ret)
10000 +               dli->dl_space_used += nr;
10001 +       spin_unlock(&dli->dl_lock);
10002 +       put_dl_info(dli);
10003 +out:
10004 +       vxlprintk(VXD_CBIT(dlim, 1),
10005 +               "ALLOC (%p,#%d)%c %lld bytes (%d)",
10006 +               sb, tag, __dlimit_char(dli), (long long)nr,
10007 +               ret, file, line);
10008 +       return ret;
10009 +}
10010 +
10011 +static inline void __dl_free_space(struct super_block *sb,
10012 +       tag_t tag, dlsize_t nr, const char *_file, int _line)
10013 +{
10014 +       struct dl_info *dli = NULL;
10015 +
10016 +       if (nr == 0)
10017 +               goto out;
10018 +       dli = locate_dl_info(sb, tag);
10019 +       if (!dli)
10020 +               goto out;
10021 +
10022 +       spin_lock(&dli->dl_lock);
10023 +       if (dli->dl_space_used > nr)
10024 +               dli->dl_space_used -= nr;
10025 +       else
10026 +               dli->dl_space_used = 0;
10027 +       spin_unlock(&dli->dl_lock);
10028 +       put_dl_info(dli);
10029 +out:
10030 +       vxlprintk(VXD_CBIT(dlim, 1),
10031 +               "FREE  (%p,#%d)%c %lld bytes",
10032 +               sb, tag, __dlimit_char(dli), (long long)nr,
10033 +               _file, _line);
10034 +}
10035 +
10036 +static inline int __dl_alloc_inode(struct super_block *sb,
10037 +       tag_t tag, const char *_file, int _line)
10038 +{
10039 +       struct dl_info *dli;
10040 +       int ret = 0;
10041 +
10042 +       dli = locate_dl_info(sb, tag);
10043 +       if (!dli)
10044 +               goto out;
10045 +
10046 +       spin_lock(&dli->dl_lock);
10047 +       ret = (dli->dl_inodes_used >= dli->dl_inodes_total);
10048 +       if (!ret)
10049 +               dli->dl_inodes_used++;
10050 +       spin_unlock(&dli->dl_lock);
10051 +       put_dl_info(dli);
10052 +out:
10053 +       vxlprintk(VXD_CBIT(dlim, 0),
10054 +               "ALLOC (%p,#%d)%c inode (%d)",
10055 +               sb, tag, __dlimit_char(dli), ret, _file, _line);
10056 +       return ret;
10057 +}
10058 +
10059 +static inline void __dl_free_inode(struct super_block *sb,
10060 +       tag_t tag, const char *_file, int _line)
10061 +{
10062 +       struct dl_info *dli;
10063 +
10064 +       dli = locate_dl_info(sb, tag);
10065 +       if (!dli)
10066 +               goto out;
10067 +
10068 +       spin_lock(&dli->dl_lock);
10069 +       if (dli->dl_inodes_used > 1)
10070 +               dli->dl_inodes_used--;
10071 +       else
10072 +               dli->dl_inodes_used = 0;
10073 +       spin_unlock(&dli->dl_lock);
10074 +       put_dl_info(dli);
10075 +out:
10076 +       vxlprintk(VXD_CBIT(dlim, 0),
10077 +               "FREE  (%p,#%d)%c inode",
10078 +               sb, tag, __dlimit_char(dli), _file, _line);
10079 +}
10080 +
10081 +static inline void __dl_adjust_block(struct super_block *sb, tag_t tag,
10082 +       unsigned long long *free_blocks, unsigned long long *root_blocks,
10083 +       const char *_file, int _line)
10084 +{
10085 +       struct dl_info *dli;
10086 +       uint64_t broot, bfree;
10087 +
10088 +       dli = locate_dl_info(sb, tag);
10089 +       if (!dli)
10090 +               return;
10091 +
10092 +       spin_lock(&dli->dl_lock);
10093 +       broot = (dli->dl_space_total -
10094 +               (dli->dl_space_total >> 10) * dli->dl_nrlmult)
10095 +               >> sb->s_blocksize_bits;
10096 +       bfree = (dli->dl_space_total - dli->dl_space_used)
10097 +                       >> sb->s_blocksize_bits;
10098 +       spin_unlock(&dli->dl_lock);
10099 +
10100 +       vxlprintk(VXD_CBIT(dlim, 2),
10101 +               "ADJUST: %lld,%lld on %lld,%lld [mult=%d]",
10102 +               (long long)bfree, (long long)broot,
10103 +               *free_blocks, *root_blocks, dli->dl_nrlmult,
10104 +               _file, _line);
10105 +       if (free_blocks) {
10106 +               if (*free_blocks > bfree)
10107 +                       *free_blocks = bfree;
10108 +       }
10109 +       if (root_blocks) {
10110 +               if (*root_blocks > broot)
10111 +                       *root_blocks = broot;
10112 +       }
10113 +       put_dl_info(dli);
10114 +}
10115 +
10116 +#define DLIMIT_ALLOC_SPACE(in, bytes) \
10117 +       __dl_alloc_space((in)->i_sb, (in)->i_tag, (dlsize_t)(bytes), \
10118 +               __FILE__, __LINE__ )
10119 +
10120 +#define DLIMIT_FREE_SPACE(in, bytes) \
10121 +       __dl_free_space((in)->i_sb, (in)->i_tag, (dlsize_t)(bytes), \
10122 +               __FILE__, __LINE__ )
10123 +
10124 +#define DLIMIT_ALLOC_BLOCK(in, nr) \
10125 +       __dl_alloc_space((in)->i_sb, (in)->i_tag, \
10126 +               ((dlsize_t)(nr)) << (in)->i_sb->s_blocksize_bits, \
10127 +               __FILE__, __LINE__ )
10128 +
10129 +#define DLIMIT_FREE_BLOCK(in, nr) \
10130 +       __dl_free_space((in)->i_sb, (in)->i_tag, \
10131 +               ((dlsize_t)(nr)) << (in)->i_sb->s_blocksize_bits, \
10132 +               __FILE__, __LINE__ )
10133 +
10134 +
10135 +#define DLIMIT_ALLOC_INODE(in) \
10136 +       __dl_alloc_inode((in)->i_sb, (in)->i_tag, __FILE__, __LINE__ )
10137 +
10138 +#define DLIMIT_FREE_INODE(in) \
10139 +       __dl_free_inode((in)->i_sb, (in)->i_tag, __FILE__, __LINE__ )
10140 +
10141 +
10142 +#define DLIMIT_ADJUST_BLOCK(sb, tag, fb, rb) \
10143 +       __dl_adjust_block(sb, tag, fb, rb, __FILE__, __LINE__ )
10144 +
10145 +
10146 +#else
10147 +#warning duplicate inclusion
10148 +#endif
10149 diff -NurpP --minimal linux-2.6.29.1/include/linux/vserver/base.h linux-2.6.29.1-vs2.3.0.36.9-pre5/include/linux/vserver/base.h
10150 --- linux-2.6.29.1/include/linux/vserver/base.h 1970-01-01 01:00:00.000000000 +0100
10151 +++ linux-2.6.29.1-vs2.3.0.36.9-pre5/include/linux/vserver/base.h       2009-03-25 00:36:15.000000000 +0100
10152 @@ -0,0 +1,157 @@
10153 +#ifndef _VX_BASE_H
10154 +#define _VX_BASE_H
10155 +
10156 +
10157 +/* context state changes */
10158 +
10159 +enum {
10160 +       VSC_STARTUP = 1,
10161 +       VSC_SHUTDOWN,
10162 +
10163 +       VSC_NETUP,
10164 +       VSC_NETDOWN,
10165 +};
10166 +
10167 +
10168 +
10169 +#define vx_task_xid(t) ((t)->xid)
10170 +
10171 +#define vx_current_xid() vx_task_xid(current)
10172 +
10173 +#define current_vx_info() (current->vx_info)
10174 +
10175 +
10176 +#define nx_task_nid(t) ((t)->nid)
10177 +
10178 +#define nx_current_nid() nx_task_nid(current)
10179 +
10180 +#define current_nx_info() (current->nx_info)
10181 +
10182 +
10183 +/* generic flag merging */
10184 +
10185 +#define vs_check_flags(v, m, f)        (((v) & (m)) ^ (f))
10186 +
10187 +#define vs_mask_flags(v, f, m) (((v) & ~(m)) | ((f) & (m)))
10188 +
10189 +#define vs_mask_mask(v, f, m)  (((v) & ~(m)) | ((v) & (f) & (m)))
10190 +
10191 +#define vs_check_bit(v, n)     ((v) & (1LL << (n)))
10192 +
10193 +
10194 +/* context flags */
10195 +
10196 +#define __vx_flags(v)  ((v) ? (v)->vx_flags : 0)
10197 +
10198 +#define vx_current_flags()     __vx_flags(current->vx_info)
10199 +
10200 +#define vx_info_flags(v, m, f) \
10201 +       vs_check_flags(__vx_flags(v), m, f)
10202 +
10203 +#define task_vx_flags(t, m, f) \
10204 +       ((t) && vx_info_flags((t)->vx_info, m, f))
10205 +
10206 +#define vx_flags(m, f) vx_info_flags(current->vx_info, m, f)
10207 +
10208 +
10209 +/* context caps */
10210 +
10211 +#define __vx_ccaps(v)  ((v) ? (v)->vx_ccaps : 0)
10212 +
10213 +#define vx_current_ccaps()     __vx_ccaps(current->vx_info)
10214 +
10215 +#define vx_info_ccaps(v, c)    (__vx_ccaps(v) & (c))
10216 +
10217 +#define vx_ccaps(c)    vx_info_ccaps(current->vx_info, (c))
10218 +
10219 +
10220 +
10221 +/* network flags */
10222 +
10223 +#define __nx_flags(n)  ((n) ? (n)->nx_flags : 0)
10224 +
10225 +#define nx_current_flags()     __nx_flags(current->nx_info)
10226 +
10227 +#define nx_info_flags(n, m, f) \
10228 +       vs_check_flags(__nx_flags(n), m, f)
10229 +
10230 +#define task_nx_flags(t, m, f) \
10231 +       ((t) && nx_info_flags((t)->nx_info, m, f))
10232 +
10233 +#define nx_flags(m, f) nx_info_flags(current->nx_info, m, f)
10234 +
10235 +
10236 +/* network caps */
10237 +
10238 +#define __nx_ncaps(n)  ((n) ? (n)->nx_ncaps : 0)
10239 +
10240 +#define nx_current_ncaps()     __nx_ncaps(current->nx_info)
10241 +
10242 +#define nx_info_ncaps(n, c)    (__nx_ncaps(n) & (c))
10243 +
10244 +#define nx_ncaps(c)    nx_info_ncaps(current->nx_info, c)
10245 +
10246 +
10247 +/* context mask capabilities */
10248 +
10249 +#define __vx_mcaps(v)  ((v) ? (v)->vx_ccaps >> 32UL : ~0 )
10250 +
10251 +#define vx_info_mcaps(v, c)    (__vx_mcaps(v) & (c))
10252 +
10253 +#define vx_mcaps(c)    vx_info_mcaps(current->vx_info, c)
10254 +
10255 +
10256 +/* context bcap mask */
10257 +
10258 +#define __vx_bcaps(v)          ((v)->vx_bcaps)
10259 +
10260 +#define vx_current_bcaps()     __vx_bcaps(current->vx_info)
10261 +
10262 +
10263 +/* mask given bcaps */
10264 +
10265 +#define vx_info_mbcaps(v, c)   ((v) ? cap_intersect(__vx_bcaps(v), c) : c)
10266 +
10267 +#define vx_mbcaps(c)           vx_info_mbcaps(current->vx_info, c)
10268 +
10269 +
10270 +/* masked cap_bset */
10271 +
10272 +#define vx_info_cap_bset(v)    vx_info_mbcaps(v, current->cap_bset)
10273 +
10274 +#define vx_current_cap_bset()  vx_info_cap_bset(current->vx_info)
10275 +
10276 +#if 0
10277 +#define vx_info_mbcap(v, b) \
10278 +       (!vx_info_flags(v, VXF_STATE_SETUP, 0) ? \
10279 +       vx_info_bcaps(v, b) : (b))
10280 +
10281 +#define task_vx_mbcap(t, b) \
10282 +       vx_info_mbcap((t)->vx_info, (t)->b)
10283 +
10284 +#define vx_mbcap(b)    task_vx_mbcap(current, b)
10285 +#endif
10286 +
10287 +#define vx_cap_raised(v, c, f) cap_raised(vx_info_mbcaps(v, c), f)
10288 +
10289 +#define vx_capable(b, c) (capable(b) || \
10290 +       (cap_raised(current_cap(), b) && vx_ccaps(c)))
10291 +
10292 +#define nx_capable(b, c) (capable(b) || \
10293 +       (cap_raised(current_cap(), b) && nx_ncaps(c)))
10294 +
10295 +#define vx_current_initpid(n) \
10296 +       (current->vx_info && \
10297 +       (current->vx_info->vx_initpid == (n)))
10298 +
10299 +
10300 +#define __vx_state(v)  ((v) ? ((v)->vx_state) : 0)
10301 +
10302 +#define vx_info_state(v, m)    (__vx_state(v) & (m))
10303 +
10304 +
10305 +#define __nx_state(n)  ((n) ? ((n)->nx_state) : 0)
10306 +
10307 +#define nx_info_state(n, m)    (__nx_state(n) & (m))
10308 +
10309 +#endif
10310 diff -NurpP --minimal linux-2.6.29.1/include/linux/vserver/cacct_cmd.h linux-2.6.29.1-vs2.3.0.36.9-pre5/include/linux/vserver/cacct_cmd.h
10311 --- linux-2.6.29.1/include/linux/vserver/cacct_cmd.h    1970-01-01 01:00:00.000000000 +0100
10312 +++ linux-2.6.29.1-vs2.3.0.36.9-pre5/include/linux/vserver/cacct_cmd.h  2009-02-22 22:54:26.000000000 +0100
10313 @@ -0,0 +1,23 @@
10314 +#ifndef _VX_CACCT_CMD_H
10315 +#define _VX_CACCT_CMD_H
10316 +
10317 +
10318 +/* virtual host info name commands */
10319 +
10320 +#define VCMD_sock_stat         VC_CMD(VSTAT, 5, 0)
10321 +
10322 +struct vcmd_sock_stat_v0 {
10323 +       uint32_t field;
10324 +       uint32_t count[3];
10325 +       uint64_t total[3];
10326 +};
10327 +
10328 +
10329 +#ifdef __KERNEL__
10330 +
10331 +#include <linux/compiler.h>
10332 +
10333 +extern int vc_sock_stat(struct vx_info *, void __user *);
10334 +
10335 +#endif /* __KERNEL__ */
10336 +#endif /* _VX_CACCT_CMD_H */
10337 diff -NurpP --minimal linux-2.6.29.1/include/linux/vserver/cacct_def.h linux-2.6.29.1-vs2.3.0.36.9-pre5/include/linux/vserver/cacct_def.h
10338 --- linux-2.6.29.1/include/linux/vserver/cacct_def.h    1970-01-01 01:00:00.000000000 +0100
10339 +++ linux-2.6.29.1-vs2.3.0.36.9-pre5/include/linux/vserver/cacct_def.h  2009-02-22 22:54:26.000000000 +0100
10340 @@ -0,0 +1,43 @@
10341 +#ifndef _VX_CACCT_DEF_H
10342 +#define _VX_CACCT_DEF_H
10343 +
10344 +#include <asm/atomic.h>
10345 +#include <linux/vserver/cacct.h>
10346 +
10347 +
10348 +struct _vx_sock_acc {
10349 +       atomic_long_t count;
10350 +       atomic_long_t total;
10351 +};
10352 +
10353 +/* context sub struct */
10354 +
10355 +struct _vx_cacct {
10356 +       struct _vx_sock_acc sock[VXA_SOCK_SIZE][3];
10357 +       atomic_t slab[8];
10358 +       atomic_t page[6][8];
10359 +};
10360 +
10361 +#ifdef CONFIG_VSERVER_DEBUG
10362 +
10363 +static inline void __dump_vx_cacct(struct _vx_cacct *cacct)
10364 +{
10365 +       int i, j;
10366 +
10367 +       printk("\t_vx_cacct:");
10368 +       for (i = 0; i < 6; i++) {
10369 +               struct _vx_sock_acc *ptr = cacct->sock[i];
10370 +
10371 +               printk("\t [%d] =", i);
10372 +               for (j = 0; j < 3; j++) {
10373 +                       printk(" [%d] = %8lu, %8lu", j,
10374 +                               atomic_long_read(&ptr[j].count),
10375 +                               atomic_long_read(&ptr[j].total));
10376 +               }
10377 +               printk("\n");
10378 +       }
10379 +}
10380 +
10381 +#endif
10382 +
10383 +#endif /* _VX_CACCT_DEF_H */
10384 diff -NurpP --minimal linux-2.6.29.1/include/linux/vserver/cacct.h linux-2.6.29.1-vs2.3.0.36.9-pre5/include/linux/vserver/cacct.h
10385 --- linux-2.6.29.1/include/linux/vserver/cacct.h        1970-01-01 01:00:00.000000000 +0100
10386 +++ linux-2.6.29.1-vs2.3.0.36.9-pre5/include/linux/vserver/cacct.h      2009-02-22 22:54:26.000000000 +0100
10387 @@ -0,0 +1,15 @@
10388 +#ifndef _VX_CACCT_H
10389 +#define _VX_CACCT_H
10390 +
10391 +
10392 +enum sock_acc_field {
10393 +       VXA_SOCK_UNSPEC = 0,
10394 +       VXA_SOCK_UNIX,
10395 +       VXA_SOCK_INET,
10396 +       VXA_SOCK_INET6,
10397 +       VXA_SOCK_PACKET,
10398 +       VXA_SOCK_OTHER,
10399 +       VXA_SOCK_SIZE   /* array size */
10400 +};
10401 +
10402 +#endif /* _VX_CACCT_H */
10403 diff -NurpP --minimal linux-2.6.29.1/include/linux/vserver/cacct_int.h linux-2.6.29.1-vs2.3.0.36.9-pre5/include/linux/vserver/cacct_int.h
10404 --- linux-2.6.29.1/include/linux/vserver/cacct_int.h    1970-01-01 01:00:00.000000000 +0100
10405 +++ linux-2.6.29.1-vs2.3.0.36.9-pre5/include/linux/vserver/cacct_int.h  2009-02-22 22:54:26.000000000 +0100
10406 @@ -0,0 +1,21 @@
10407 +#ifndef _VX_CACCT_INT_H
10408 +#define _VX_CACCT_INT_H
10409 +
10410 +
10411 +#ifdef __KERNEL__
10412 +
10413 +static inline
10414 +unsigned long vx_sock_count(struct _vx_cacct *cacct, int type, int pos)
10415 +{
10416 +       return atomic_long_read(&cacct->sock[type][pos].count);
10417 +}
10418 +
10419 +
10420 +static inline
10421 +unsigned long vx_sock_total(struct _vx_cacct *cacct, int type, int pos)
10422 +{
10423 +       return atomic_long_read(&cacct->sock[type][pos].total);
10424 +}
10425 +
10426 +#endif /* __KERNEL__ */
10427 +#endif /* _VX_CACCT_INT_H */
10428 diff -NurpP --minimal linux-2.6.29.1/include/linux/vserver/check.h linux-2.6.29.1-vs2.3.0.36.9-pre5/include/linux/vserver/check.h
10429 --- linux-2.6.29.1/include/linux/vserver/check.h        1970-01-01 01:00:00.000000000 +0100
10430 +++ linux-2.6.29.1-vs2.3.0.36.9-pre5/include/linux/vserver/check.h      2009-02-22 22:54:26.000000000 +0100
10431 @@ -0,0 +1,89 @@
10432 +#ifndef _VS_CHECK_H
10433 +#define _VS_CHECK_H
10434 +
10435 +
10436 +#define MAX_S_CONTEXT  65535   /* Arbitrary limit */
10437 +
10438 +#ifdef CONFIG_VSERVER_DYNAMIC_IDS
10439 +#define MIN_D_CONTEXT  49152   /* dynamic contexts start here */
10440 +#else
10441 +#define MIN_D_CONTEXT  65536
10442 +#endif
10443 +
10444 +/* check conditions */
10445 +
10446 +#define VS_ADMIN       0x0001
10447 +#define VS_WATCH       0x0002
10448 +#define VS_HIDE                0x0004
10449 +#define VS_HOSTID      0x0008
10450 +
10451 +#define VS_IDENT       0x0010
10452 +#define VS_EQUIV       0x0020
10453 +#define VS_PARENT      0x0040
10454 +#define VS_CHILD       0x0080
10455 +
10456 +#define VS_ARG_MASK    0x00F0
10457 +
10458 +#define VS_DYNAMIC     0x0100
10459 +#define VS_STATIC      0x0200
10460 +
10461 +#define VS_ATR_MASK    0x0F00
10462 +
10463 +#ifdef CONFIG_VSERVER_PRIVACY
10464 +#define VS_ADMIN_P     (0)
10465 +#define VS_WATCH_P     (0)
10466 +#else
10467 +#define VS_ADMIN_P     VS_ADMIN
10468 +#define VS_WATCH_P     VS_WATCH
10469 +#endif
10470 +
10471 +#define VS_HARDIRQ     0x1000
10472 +#define VS_SOFTIRQ     0x2000
10473 +#define VS_IRQ         0x4000
10474 +
10475 +#define VS_IRQ_MASK    0xF000
10476 +
10477 +#include <linux/hardirq.h>
10478 +
10479 +/*
10480 + * check current context for ADMIN/WATCH and
10481 + * optionally against supplied argument
10482 + */
10483 +static inline int __vs_check(int cid, int id, unsigned int mode)
10484 +{
10485 +       if (mode & VS_ARG_MASK) {
10486 +               if ((mode & VS_IDENT) && (id == cid))
10487 +                       return 1;
10488 +       }
10489 +       if (mode & VS_ATR_MASK) {
10490 +               if ((mode & VS_DYNAMIC) &&
10491 +                       (id >= MIN_D_CONTEXT) &&
10492 +                       (id <= MAX_S_CONTEXT))
10493 +                       return 1;
10494 +               if ((mode & VS_STATIC) &&
10495 +                       (id > 1) && (id < MIN_D_CONTEXT))
10496 +                       return 1;
10497 +       }
10498 +       if (mode & VS_IRQ_MASK) {
10499 +               if ((mode & VS_IRQ) && unlikely(in_interrupt()))
10500 +                       return 1;
10501 +               if ((mode & VS_HARDIRQ) && unlikely(in_irq()))
10502 +                       return 1;
10503 +               if ((mode & VS_SOFTIRQ) && unlikely(in_softirq()))
10504 +                       return 1;
10505 +       }
10506 +       return (((mode & VS_ADMIN) && (cid == 0)) ||
10507 +               ((mode & VS_WATCH) && (cid == 1)) ||
10508 +               ((mode & VS_HOSTID) && (id == 0)));
10509 +}
10510 +
10511 +#define vx_check(c, m) __vs_check(vx_current_xid(), c, (m) | VS_IRQ)
10512 +
10513 +#define vx_weak_check(c, m)    ((m) ? vx_check(c, m) : 1)
10514 +
10515 +
10516 +#define nx_check(c, m) __vs_check(nx_current_nid(), c, m)
10517 +
10518 +#define nx_weak_check(c, m)    ((m) ? nx_check(c, m) : 1)
10519 +
10520 +#endif
10521 diff -NurpP --minimal linux-2.6.29.1/include/linux/vserver/context_cmd.h linux-2.6.29.1-vs2.3.0.36.9-pre5/include/linux/vserver/context_cmd.h
10522 --- linux-2.6.29.1/include/linux/vserver/context_cmd.h  1970-01-01 01:00:00.000000000 +0100
10523 +++ linux-2.6.29.1-vs2.3.0.36.9-pre5/include/linux/vserver/context_cmd.h        2009-02-22 22:54:26.000000000 +0100
10524 @@ -0,0 +1,128 @@
10525 +#ifndef _VX_CONTEXT_CMD_H
10526 +#define _VX_CONTEXT_CMD_H
10527 +
10528 +
10529 +/* vinfo commands */
10530 +
10531 +#define VCMD_task_xid          VC_CMD(VINFO, 1, 0)
10532 +
10533 +#ifdef __KERNEL__
10534 +extern int vc_task_xid(uint32_t);
10535 +
10536 +#endif /* __KERNEL__ */
10537 +
10538 +#define VCMD_vx_info           VC_CMD(VINFO, 5, 0)
10539 +
10540 +struct vcmd_vx_info_v0 {
10541 +       uint32_t xid;
10542 +       uint32_t initpid;
10543 +       /* more to come */
10544 +};
10545 +
10546 +#ifdef __KERNEL__
10547 +extern int vc_vx_info(struct vx_info *, void __user *);
10548 +
10549 +#endif /* __KERNEL__ */
10550 +
10551 +#define VCMD_ctx_stat          VC_CMD(VSTAT, 0, 0)
10552 +
10553 +struct vcmd_ctx_stat_v0 {
10554 +       uint32_t usecnt;
10555 +       uint32_t tasks;
10556 +       /* more to come */
10557 +};
10558 +
10559 +#ifdef __KERNEL__
10560 +extern int vc_ctx_stat(struct vx_info *, void __user *);
10561 +
10562 +#endif /* __KERNEL__ */
10563 +
10564 +/* context commands */
10565 +
10566 +#define VCMD_ctx_create_v0     VC_CMD(VPROC, 1, 0)
10567 +#define VCMD_ctx_create                VC_CMD(VPROC, 1, 1)
10568 +
10569 +struct vcmd_ctx_create {
10570 +       uint64_t flagword;
10571 +};
10572 +
10573 +#define VCMD_ctx_migrate_v0    VC_CMD(PROCMIG, 1, 0)
10574 +#define VCMD_ctx_migrate       VC_CMD(PROCMIG, 1, 1)
10575 +
10576 +struct vcmd_ctx_migrate {
10577 +       uint64_t flagword;
10578 +};
10579 +
10580 +#ifdef __KERNEL__
10581 +extern int vc_ctx_create(uint32_t, void __user *);
10582 +extern int vc_ctx_migrate(struct vx_info *, void __user *);
10583 +
10584 +#endif /* __KERNEL__ */
10585 +
10586 +
10587 +/* flag commands */
10588 +
10589 +#define VCMD_get_cflags                VC_CMD(FLAGS, 1, 0)
10590 +#define VCMD_set_cflags                VC_CMD(FLAGS, 2, 0)
10591 +
10592 +struct vcmd_ctx_flags_v0 {
10593 +       uint64_t flagword;
10594 +       uint64_t mask;
10595 +};
10596 +
10597 +#ifdef __KERNEL__
10598 +extern int vc_get_cflags(struct vx_info *, void __user *);
10599 +extern int vc_set_cflags(struct vx_info *, void __user *);
10600 +
10601 +#endif /* __KERNEL__ */
10602 +
10603 +
10604 +/* context caps commands */
10605 +
10606 +#define VCMD_get_ccaps         VC_CMD(FLAGS, 3, 1)
10607 +#define VCMD_set_ccaps         VC_CMD(FLAGS, 4, 1)
10608 +
10609 +struct vcmd_ctx_caps_v1 {
10610 +       uint64_t ccaps;
10611 +       uint64_t cmask;
10612 +};
10613 +
10614 +#ifdef __KERNEL__
10615 +extern int vc_get_ccaps(struct vx_info *, void __user *);
10616 +extern int vc_set_ccaps(struct vx_info *, void __user *);
10617 +
10618 +#endif /* __KERNEL__ */
10619 +
10620 +
10621 +/* bcaps commands */
10622 +
10623 +#define VCMD_get_bcaps         VC_CMD(FLAGS, 9, 0)
10624 +#define VCMD_set_bcaps         VC_CMD(FLAGS, 10, 0)
10625 +
10626 +struct vcmd_bcaps {
10627 +       uint64_t bcaps;
10628 +       uint64_t bmask;
10629 +};
10630 +
10631 +#ifdef __KERNEL__
10632 +extern int vc_get_bcaps(struct vx_info *, void __user *);
10633 +extern int vc_set_bcaps(struct vx_info *, void __user *);
10634 +
10635 +#endif /* __KERNEL__ */
10636 +
10637 +
10638 +/* OOM badness */
10639 +
10640 +#define VCMD_get_badness       VC_CMD(MEMCTRL, 5, 0)
10641 +#define VCMD_set_badness       VC_CMD(MEMCTRL, 6, 0)
10642 +
10643 +struct vcmd_badness_v0 {
10644 +       int64_t bias;
10645 +};
10646 +
10647 +#ifdef __KERNEL__
10648 +extern int vc_get_badness(struct vx_info *, void __user *);
10649 +extern int vc_set_badness(struct vx_info *, void __user *);
10650 +
10651 +#endif /* __KERNEL__ */
10652 +#endif /* _VX_CONTEXT_CMD_H */
10653 diff -NurpP --minimal linux-2.6.29.1/include/linux/vserver/context.h linux-2.6.29.1-vs2.3.0.36.9-pre5/include/linux/vserver/context.h
10654 --- linux-2.6.29.1/include/linux/vserver/context.h      1970-01-01 01:00:00.000000000 +0100
10655 +++ linux-2.6.29.1-vs2.3.0.36.9-pre5/include/linux/vserver/context.h    2009-02-22 22:54:26.000000000 +0100
10656 @@ -0,0 +1,179 @@
10657 +#ifndef _VX_CONTEXT_H
10658 +#define _VX_CONTEXT_H
10659 +
10660 +#include <linux/types.h>
10661 +#include <linux/capability.h>
10662 +
10663 +
10664 +/* context flags */
10665 +
10666 +#define VXF_INFO_SCHED         0x00000002
10667 +#define VXF_INFO_NPROC         0x00000004
10668 +#define VXF_INFO_PRIVATE       0x00000008
10669 +
10670 +#define VXF_INFO_INIT          0x00000010
10671 +#define VXF_INFO_HIDE          0x00000020
10672 +#define VXF_INFO_ULIMIT                0x00000040
10673 +#define VXF_INFO_NSPACE                0x00000080
10674 +
10675 +#define VXF_SCHED_HARD         0x00000100
10676 +#define VXF_SCHED_PRIO         0x00000200
10677 +#define VXF_SCHED_PAUSE                0x00000400
10678 +
10679 +#define VXF_VIRT_MEM           0x00010000
10680 +#define VXF_VIRT_UPTIME                0x00020000
10681 +#define VXF_VIRT_CPU           0x00040000
10682 +#define VXF_VIRT_LOAD          0x00080000
10683 +#define VXF_VIRT_TIME          0x00100000
10684 +
10685 +#define VXF_HIDE_MOUNT         0x01000000
10686 +/* was VXF_HIDE_NETIF          0x02000000 */
10687 +#define VXF_HIDE_VINFO         0x04000000
10688 +
10689 +#define VXF_STATE_SETUP                (1ULL << 32)
10690 +#define VXF_STATE_INIT         (1ULL << 33)
10691 +#define VXF_STATE_ADMIN                (1ULL << 34)
10692 +
10693 +#define VXF_SC_HELPER          (1ULL << 36)
10694 +#define VXF_REBOOT_KILL                (1ULL << 37)
10695 +#define VXF_PERSISTENT         (1ULL << 38)
10696 +
10697 +#define VXF_FORK_RSS           (1ULL << 48)
10698 +#define VXF_PROLIFIC           (1ULL << 49)
10699 +
10700 +#define VXF_IGNEG_NICE         (1ULL << 52)
10701 +
10702 +#define VXF_ONE_TIME           (0x0007ULL << 32)
10703 +
10704 +#define VXF_INIT_SET           (VXF_STATE_SETUP | VXF_STATE_INIT | VXF_STATE_ADMIN)
10705 +
10706 +
10707 +/* context migration */
10708 +
10709 +#define VXM_SET_INIT           0x00000001
10710 +#define VXM_SET_REAPER         0x00000002
10711 +
10712 +/* context caps */
10713 +
10714 +#define VXC_CAP_MASK           0x00000000
10715 +
10716 +#define VXC_SET_UTSNAME                0x00000001
10717 +#define VXC_SET_RLIMIT         0x00000002
10718 +#define VXC_FS_SECURITY                0x00000004
10719 +
10720 +/* was VXC_RAW_ICMP            0x00000100 */
10721 +#define VXC_SYSLOG             0x00001000
10722 +
10723 +#define VXC_SECURE_MOUNT       0x00010000
10724 +#define VXC_SECURE_REMOUNT     0x00020000
10725 +#define VXC_BINARY_MOUNT       0x00040000
10726 +
10727 +#define VXC_QUOTA_CTL          0x00100000
10728 +#define VXC_ADMIN_MAPPER       0x00200000
10729 +#define VXC_ADMIN_CLOOP                0x00400000
10730 +
10731 +#define VXC_KTHREAD            0x01000000
10732 +
10733 +
10734 +#ifdef __KERNEL__
10735 +
10736 +#include <linux/list.h>
10737 +#include <linux/spinlock.h>
10738 +#include <linux/rcupdate.h>
10739 +
10740 +#include "limit_def.h"
10741 +#include "sched_def.h"
10742 +#include "cvirt_def.h"
10743 +#include "cacct_def.h"
10744 +#include "device_def.h"
10745 +
10746 +#define VX_SPACES      2
10747 +
10748 +struct _vx_info_pc {
10749 +       struct _vx_sched_pc sched_pc;
10750 +       struct _vx_cvirt_pc cvirt_pc;
10751 +};
10752 +
10753 +struct vx_info {
10754 +       struct hlist_node vx_hlist;             /* linked list of contexts */
10755 +       xid_t vx_id;                            /* context id */
10756 +       atomic_t vx_usecnt;                     /* usage count */
10757 +       atomic_t vx_tasks;                      /* tasks count */
10758 +       struct vx_info *vx_parent;              /* parent context */
10759 +       int vx_state;                           /* context state */
10760 +
10761 +       unsigned long vx_nsmask[VX_SPACES];     /* assignment mask */
10762 +       struct nsproxy *vx_nsproxy[VX_SPACES];  /* private namespaces */
10763 +       struct fs_struct *vx_fs[VX_SPACES];     /* private namespace fs */
10764 +
10765 +       uint64_t vx_flags;                      /* context flags */
10766 +       uint64_t vx_ccaps;                      /* context caps (vserver) */
10767 +       kernel_cap_t vx_bcaps;                  /* bounding caps (system) */
10768 +       // kernel_cap_t vx_cap_bset;            /* the guest's bset */
10769 +
10770 +       struct task_struct *vx_reaper;          /* guest reaper process */
10771 +       pid_t vx_initpid;                       /* PID of guest init */
10772 +       int64_t vx_badness_bias;                /* OOM points bias */
10773 +
10774 +       struct _vx_limit limit;                 /* vserver limits */
10775 +       struct _vx_sched sched;                 /* vserver scheduler */
10776 +       struct _vx_cvirt cvirt;                 /* virtual/bias stuff */
10777 +       struct _vx_cacct cacct;                 /* context accounting */
10778 +
10779 +       struct _vx_device dmap;                 /* default device map targets */
10780 +
10781 +#ifndef CONFIG_SMP
10782 +       struct _vx_info_pc info_pc;             /* per cpu data */
10783 +#else
10784 +       struct _vx_info_pc *ptr_pc;             /* per cpu array */
10785 +#endif
10786 +
10787 +       wait_queue_head_t vx_wait;              /* context exit waitqueue */
10788 +       int reboot_cmd;                         /* last sys_reboot() cmd */
10789 +       int exit_code;                          /* last process exit code */
10790 +
10791 +       char vx_name[65];                       /* vserver name */
10792 +};
10793 +
10794 +#ifndef CONFIG_SMP
10795 +#define        vx_ptr_pc(vxi)          (&(vxi)->info_pc)
10796 +#define        vx_per_cpu(vxi, v, id)  vx_ptr_pc(vxi)->v
10797 +#else
10798 +#define        vx_ptr_pc(vxi)          ((vxi)->ptr_pc)
10799 +#define        vx_per_cpu(vxi, v, id)  per_cpu_ptr(vx_ptr_pc(vxi), id)->v
10800 +#endif
10801 +
10802 +#define        vx_cpu(vxi, v)          vx_per_cpu(vxi, v, smp_processor_id())
10803 +
10804 +
10805 +struct vx_info_save {
10806 +       struct vx_info *vxi;
10807 +       xid_t xid;
10808 +};
10809 +
10810 +
10811 +/* status flags */
10812 +
10813 +#define VXS_HASHED     0x0001
10814 +#define VXS_PAUSED     0x0010
10815 +#define VXS_SHUTDOWN   0x0100
10816 +#define VXS_HELPER     0x1000
10817 +#define VXS_RELEASED   0x8000
10818 +
10819 +
10820 +extern void claim_vx_info(struct vx_info *, struct task_struct *);
10821 +extern void release_vx_info(struct vx_info *, struct task_struct *);
10822 +
10823 +extern struct vx_info *lookup_vx_info(int);
10824 +extern struct vx_info *lookup_or_create_vx_info(int);
10825 +
10826 +extern int get_xid_list(int, unsigned int *, int);
10827 +extern int xid_is_hashed(xid_t);
10828 +
10829 +extern int vx_migrate_task(struct task_struct *, struct vx_info *, int);
10830 +
10831 +extern long vs_state_change(struct vx_info *, unsigned int);
10832 +
10833 +
10834 +#endif /* __KERNEL__ */
10835 +#endif /* _VX_CONTEXT_H */
10836 diff -NurpP --minimal linux-2.6.29.1/include/linux/vserver/cvirt_cmd.h linux-2.6.29.1-vs2.3.0.36.9-pre5/include/linux/vserver/cvirt_cmd.h
10837 --- linux-2.6.29.1/include/linux/vserver/cvirt_cmd.h    1970-01-01 01:00:00.000000000 +0100
10838 +++ linux-2.6.29.1-vs2.3.0.36.9-pre5/include/linux/vserver/cvirt_cmd.h  2009-02-22 22:54:26.000000000 +0100
10839 @@ -0,0 +1,53 @@
10840 +#ifndef _VX_CVIRT_CMD_H
10841 +#define _VX_CVIRT_CMD_H
10842 +
10843 +
10844 +/* virtual host info name commands */
10845 +
10846 +#define VCMD_set_vhi_name      VC_CMD(VHOST, 1, 0)
10847 +#define VCMD_get_vhi_name      VC_CMD(VHOST, 2, 0)
10848 +
10849 +struct vcmd_vhi_name_v0 {
10850 +       uint32_t field;
10851 +       char name[65];
10852 +};
10853 +
10854 +
10855 +enum vhi_name_field {
10856 +       VHIN_CONTEXT = 0,
10857 +       VHIN_SYSNAME,
10858 +       VHIN_NODENAME,
10859 +       VHIN_RELEASE,
10860 +       VHIN_VERSION,
10861 +       VHIN_MACHINE,
10862 +       VHIN_DOMAINNAME,
10863 +};
10864 +
10865 +
10866 +#ifdef __KERNEL__
10867 +
10868 +#include <linux/compiler.h>
10869 +
10870 +extern int vc_set_vhi_name(struct vx_info *, void __user *);
10871 +extern int vc_get_vhi_name(struct vx_info *, void __user *);
10872 +
10873 +#endif /* __KERNEL__ */
10874 +
10875 +#define VCMD_virt_stat         VC_CMD(VSTAT, 3, 0)
10876 +
10877 +struct vcmd_virt_stat_v0 {
10878 +       uint64_t offset;
10879 +       uint64_t uptime;
10880 +       uint32_t nr_threads;
10881 +       uint32_t nr_running;
10882 +       uint32_t nr_uninterruptible;
10883 +       uint32_t nr_onhold;
10884 +       uint32_t nr_forks;
10885 +       uint32_t load[3];
10886 +};
10887 +
10888 +#ifdef __KERNEL__
10889 +extern int vc_virt_stat(struct vx_info *, void __user *);
10890 +
10891 +#endif /* __KERNEL__ */
10892 +#endif /* _VX_CVIRT_CMD_H */
10893 diff -NurpP --minimal linux-2.6.29.1/include/linux/vserver/cvirt_def.h linux-2.6.29.1-vs2.3.0.36.9-pre5/include/linux/vserver/cvirt_def.h
10894 --- linux-2.6.29.1/include/linux/vserver/cvirt_def.h    1970-01-01 01:00:00.000000000 +0100
10895 +++ linux-2.6.29.1-vs2.3.0.36.9-pre5/include/linux/vserver/cvirt_def.h  2009-02-22 22:54:26.000000000 +0100
10896 @@ -0,0 +1,80 @@
10897 +#ifndef _VX_CVIRT_DEF_H
10898 +#define _VX_CVIRT_DEF_H
10899 +
10900 +#include <linux/jiffies.h>
10901 +#include <linux/spinlock.h>
10902 +#include <linux/wait.h>
10903 +#include <linux/time.h>
10904 +#include <asm/atomic.h>
10905 +
10906 +
10907 +struct _vx_usage_stat {
10908 +       uint64_t user;
10909 +       uint64_t nice;
10910 +       uint64_t system;
10911 +       uint64_t softirq;
10912 +       uint64_t irq;
10913 +       uint64_t idle;
10914 +       uint64_t iowait;
10915 +};
10916 +
10917 +struct _vx_syslog {
10918 +       wait_queue_head_t log_wait;
10919 +       spinlock_t logbuf_lock;         /* lock for the log buffer */
10920 +
10921 +       unsigned long log_start;        /* next char to be read by syslog() */
10922 +       unsigned long con_start;        /* next char to be sent to consoles */
10923 +       unsigned long log_end;  /* most-recently-written-char + 1 */
10924 +       unsigned long logged_chars;     /* #chars since last read+clear operation */
10925 +
10926 +       char log_buf[1024];
10927 +};
10928 +
10929 +
10930 +/* context sub struct */
10931 +
10932 +struct _vx_cvirt {
10933 +       atomic_t nr_threads;            /* number of current threads */
10934 +       atomic_t nr_running;            /* number of running threads */
10935 +       atomic_t nr_uninterruptible;    /* number of uninterruptible threads */
10936 +
10937 +       atomic_t nr_onhold;             /* processes on hold */
10938 +       uint32_t onhold_last;           /* jiffies when put on hold */
10939 +
10940 +       struct timeval bias_tv;         /* time offset to the host */
10941 +       struct timespec bias_idle;
10942 +       struct timespec bias_uptime;    /* context creation point */
10943 +       uint64_t bias_clock;            /* offset in clock_t */
10944 +
10945 +       spinlock_t load_lock;           /* lock for the load averages */
10946 +       atomic_t load_updates;          /* nr of load updates done so far */
10947 +       uint32_t load_last;             /* last time load was calculated */
10948 +       uint32_t load[3];               /* load averages 1,5,15 */
10949 +
10950 +       atomic_t total_forks;           /* number of forks so far */
10951 +
10952 +       struct _vx_syslog syslog;
10953 +};
10954 +
10955 +struct _vx_cvirt_pc {
10956 +       struct _vx_usage_stat cpustat;
10957 +};
10958 +
10959 +
10960 +#ifdef CONFIG_VSERVER_DEBUG
10961 +
10962 +static inline void __dump_vx_cvirt(struct _vx_cvirt *cvirt)
10963 +{
10964 +       printk("\t_vx_cvirt:\n");
10965 +       printk("\t threads: %4d, %4d, %4d, %4d\n",
10966 +               atomic_read(&cvirt->nr_threads),
10967 +               atomic_read(&cvirt->nr_running),
10968 +               atomic_read(&cvirt->nr_uninterruptible),
10969 +               atomic_read(&cvirt->nr_onhold));
10970 +       /* add rest here */
10971 +       printk("\t total_forks = %d\n", atomic_read(&cvirt->total_forks));
10972 +}
10973 +
10974 +#endif
10975 +
10976 +#endif /* _VX_CVIRT_DEF_H */
10977 diff -NurpP --minimal linux-2.6.29.1/include/linux/vserver/cvirt.h linux-2.6.29.1-vs2.3.0.36.9-pre5/include/linux/vserver/cvirt.h
10978 --- linux-2.6.29.1/include/linux/vserver/cvirt.h        1970-01-01 01:00:00.000000000 +0100
10979 +++ linux-2.6.29.1-vs2.3.0.36.9-pre5/include/linux/vserver/cvirt.h      2009-02-22 22:54:26.000000000 +0100
10980 @@ -0,0 +1,20 @@
10981 +#ifndef _VX_CVIRT_H
10982 +#define _VX_CVIRT_H
10983 +
10984 +
10985 +#ifdef __KERNEL__
10986 +
10987 +struct timespec;
10988 +
10989 +void vx_vsi_uptime(struct timespec *, struct timespec *);
10990 +
10991 +
10992 +struct vx_info;
10993 +
10994 +void vx_update_load(struct vx_info *);
10995 +
10996 +
10997 +int vx_do_syslog(int, char __user *, int);
10998 +
10999 +#endif /* __KERNEL__ */
11000 +#endif /* _VX_CVIRT_H */
11001 diff -NurpP --minimal linux-2.6.29.1/include/linux/vserver/debug_cmd.h linux-2.6.29.1-vs2.3.0.36.9-pre5/include/linux/vserver/debug_cmd.h
11002 --- linux-2.6.29.1/include/linux/vserver/debug_cmd.h    1970-01-01 01:00:00.000000000 +0100
11003 +++ linux-2.6.29.1-vs2.3.0.36.9-pre5/include/linux/vserver/debug_cmd.h  2009-02-22 22:54:26.000000000 +0100
11004 @@ -0,0 +1,58 @@
11005 +#ifndef _VX_DEBUG_CMD_H
11006 +#define _VX_DEBUG_CMD_H
11007 +
11008 +
11009 +/* debug commands */
11010 +
11011 +#define VCMD_dump_history      VC_CMD(DEBUG, 1, 0)
11012 +
11013 +#define VCMD_read_history      VC_CMD(DEBUG, 5, 0)
11014 +#define VCMD_read_monitor      VC_CMD(DEBUG, 6, 0)
11015 +
11016 +struct  vcmd_read_history_v0 {
11017 +       uint32_t index;
11018 +       uint32_t count;
11019 +       char __user *data;
11020 +};
11021 +
11022 +struct  vcmd_read_monitor_v0 {
11023 +       uint32_t index;
11024 +       uint32_t count;
11025 +       char __user *data;
11026 +};
11027 +
11028 +
11029 +#ifdef __KERNEL__
11030 +
11031 +#ifdef CONFIG_COMPAT
11032 +
11033 +#include <asm/compat.h>
11034 +
11035 +struct vcmd_read_history_v0_x32 {
11036 +       uint32_t index;
11037 +       uint32_t count;
11038 +       compat_uptr_t data_ptr;
11039 +};
11040 +
11041 +struct vcmd_read_monitor_v0_x32 {
11042 +       uint32_t index;
11043 +       uint32_t count;
11044 +       compat_uptr_t data_ptr;
11045 +};
11046 +
11047 +#endif  /* CONFIG_COMPAT */
11048 +
11049 +extern int vc_dump_history(uint32_t);
11050 +
11051 +extern int vc_read_history(uint32_t, void __user *);
11052 +extern int vc_read_monitor(uint32_t, void __user *);
11053 +
11054 +#ifdef CONFIG_COMPAT
11055 +
11056 +extern int vc_read_history_x32(uint32_t, void __user *);
11057 +extern int vc_read_monitor_x32(uint32_t, void __user *);
11058 +
11059 +#endif  /* CONFIG_COMPAT */
11060 +
11061 +#endif /* __KERNEL__ */
11062 +#endif /* _VX_DEBUG_CMD_H */
11063 diff -NurpP --minimal linux-2.6.29.1/include/linux/vserver/debug.h linux-2.6.29.1-vs2.3.0.36.9-pre5/include/linux/vserver/debug.h
11064 --- linux-2.6.29.1/include/linux/vserver/debug.h        1970-01-01 01:00:00.000000000 +0100
11065 +++ linux-2.6.29.1-vs2.3.0.36.9-pre5/include/linux/vserver/debug.h      2009-02-22 22:54:26.000000000 +0100
11066 @@ -0,0 +1,127 @@
11067 +#ifndef _VX_DEBUG_H
11068 +#define _VX_DEBUG_H
11069 +
11070 +
11071 +#define VXD_CBIT(n, m) (vx_debug_ ## n & (1 << (m)))
11072 +#define VXD_CMIN(n, m) (vx_debug_ ## n > (m))
11073 +#define VXD_MASK(n, m) (vx_debug_ ## n & (m))
11074 +
11075 +#define VXD_DEV(d)     (d), (d)->bd_inode->i_ino,              \
11076 +                       imajor((d)->bd_inode), iminor((d)->bd_inode)
11077 +#define VXF_DEV                "%p[%lu,%d:%d]"
11078 +
11079 +
11080 +#define vxd_path(p)                                            \
11081 +       ({ static char _buffer[PATH_MAX];                       \
11082 +          d_path(p, _buffer, sizeof(_buffer)); })
11083 +
11084 +#define vxd_cond_path(n)                                       \
11085 +       ((n) ? vxd_path(&(n)->path) : "<null>" )
11086 +
11087 +
11088 +#ifdef CONFIG_VSERVER_DEBUG
11089 +
11090 +extern unsigned int vx_debug_switch;
11091 +extern unsigned int vx_debug_xid;
11092 +extern unsigned int vx_debug_nid;
11093 +extern unsigned int vx_debug_tag;
11094 +extern unsigned int vx_debug_net;
11095 +extern unsigned int vx_debug_limit;
11096 +extern unsigned int vx_debug_cres;
11097 +extern unsigned int vx_debug_dlim;
11098 +extern unsigned int vx_debug_quota;
11099 +extern unsigned int vx_debug_cvirt;
11100 +extern unsigned int vx_debug_space;
11101 +extern unsigned int vx_debug_misc;
11102 +
11103 +
11104 +#define VX_LOGLEVEL    "vxD: "
11105 +#define VX_PROC_FMT    "%p: "
11106 +#define VX_PROCESS     current
11107 +
11108 +#define vxdprintk(c, f, x...)                                  \
11109 +       do {                                                    \
11110 +               if (c)                                          \
11111 +                       printk(VX_LOGLEVEL VX_PROC_FMT f "\n",  \
11112 +                               VX_PROCESS , ##x);              \
11113 +       } while (0)
11114 +
11115 +#define vxlprintk(c, f, x...)                                  \
11116 +       do {                                                    \
11117 +               if (c)                                          \
11118 +                       printk(VX_LOGLEVEL f " @%s:%d\n", x);   \
11119 +       } while (0)
11120 +
11121 +#define vxfprintk(c, f, x...)                                  \
11122 +       do {                                                    \
11123 +               if (c)                                          \
11124 +                       printk(VX_LOGLEVEL f " %s@%s:%d\n", x); \
11125 +       } while (0)
11126 +
11127 +
11128 +struct vx_info;
11129 +
11130 +void dump_vx_info(struct vx_info *, int);
11131 +void dump_vx_info_inactive(int);
11132 +
11133 +#else  /* CONFIG_VSERVER_DEBUG */
11134 +
11135 +#define vx_debug_switch 0
11136 +#define vx_debug_xid   0
11137 +#define vx_debug_nid   0
11138 +#define vx_debug_tag   0
11139 +#define vx_debug_net   0
11140 +#define vx_debug_limit 0
11141 +#define vx_debug_cres  0
11142 +#define vx_debug_dlim  0
11143 +#define vx_debug_cvirt 0
11144 +
11145 +#define vxdprintk(x...) do { } while (0)
11146 +#define vxlprintk(x...) do { } while (0)
11147 +#define vxfprintk(x...) do { } while (0)
11148 +
11149 +#endif /* CONFIG_VSERVER_DEBUG */
11150 +
11151 +
11152 +#ifdef CONFIG_VSERVER_WARN
11153 +
11154 +#define VX_WARNLEVEL   KERN_WARNING "vxW: "
11155 +#define VX_WARN_TASK   "[»%s«,%u:#%u|%u|%u] "
11156 +#define VX_WARN_XID    "[xid #%u] "
11157 +#define VX_WARN_NID    "[nid #%u] "
11158 +#define VX_WARN_TAG    "[tag #%u] "
11159 +
11160 +#define vxwprintk(c, f, x...)                                  \
11161 +       do {                                                    \
11162 +               if (c)                                          \
11163 +                       printk(VX_WARNLEVEL f "\n", ##x);       \
11164 +       } while (0)
11165 +
11166 +#else  /* CONFIG_VSERVER_WARN */
11167 +
11168 +#define vxwprintk(x...) do { } while (0)
11169 +
11170 +#endif /* CONFIG_VSERVER_WARN */
11171 +
11172 +#define vxwprintk_task(c, f, x...)                             \
11173 +       vxwprintk(c, VX_WARN_TASK f,                            \
11174 +               current->comm, current->pid,                    \
11175 +               current->xid, current->nid, current->tag, ##x)
11176 +#define vxwprintk_xid(c, f, x...)                              \
11177 +       vxwprintk(c, VX_WARN_XID f, current->xid, x)
11178 +#define vxwprintk_nid(c, f, x...)                              \
11179 +       vxwprintk(c, VX_WARN_NID f, current->nid, x)
11180 +#define vxwprintk_tag(c, f, x...)                              \
11181 +       vxwprintk(c, VX_WARN_TAG f, current->tag, x)
11182 +
11183 +#ifdef CONFIG_VSERVER_DEBUG
11184 +#define vxd_assert_lock(l)     assert_spin_locked(l)
11185 +#define vxd_assert(c, f, x...) vxlprintk(!(c), \
11186 +       "assertion [" f "] failed.", ##x, __FILE__, __LINE__)
11187 +#else
11188 +#define vxd_assert_lock(l)     do { } while (0)
11189 +#define vxd_assert(c, f, x...) do { } while (0)
11190 +#endif
11191 +
11192 +
11193 +#endif /* _VX_DEBUG_H */
11194 diff -NurpP --minimal linux-2.6.29.1/include/linux/vserver/device_cmd.h linux-2.6.29.1-vs2.3.0.36.9-pre5/include/linux/vserver/device_cmd.h
11195 --- linux-2.6.29.1/include/linux/vserver/device_cmd.h   1970-01-01 01:00:00.000000000 +0100
11196 +++ linux-2.6.29.1-vs2.3.0.36.9-pre5/include/linux/vserver/device_cmd.h 2009-02-22 22:54:26.000000000 +0100
11197 @@ -0,0 +1,44 @@
11198 +#ifndef _VX_DEVICE_CMD_H
11199 +#define _VX_DEVICE_CMD_H
11200 +
11201 +
11202 +/*  device vserver commands */
11203 +
11204 +#define VCMD_set_mapping       VC_CMD(DEVICE, 1, 0)
11205 +#define VCMD_unset_mapping     VC_CMD(DEVICE, 2, 0)
11206 +
11207 +struct vcmd_set_mapping_v0 {
11208 +       const char __user *device;
11209 +       const char __user *target;
11210 +       uint32_t flags;
11211 +};
11212 +
11213 +
11214 +#ifdef __KERNEL__
11215 +
11216 +#ifdef CONFIG_COMPAT
11217 +
11218 +#include <asm/compat.h>
11219 +
11220 +struct vcmd_set_mapping_v0_x32 {
11221 +       compat_uptr_t device_ptr;
11222 +       compat_uptr_t target_ptr;
11223 +       uint32_t flags;
11224 +};
11225 +
11226 +#endif /* CONFIG_COMPAT */
11227 +
11228 +#include <linux/compiler.h>
11229 +
11230 +extern int vc_set_mapping(struct vx_info *, void __user *);
11231 +extern int vc_unset_mapping(struct vx_info *, void __user *);
11232 +
11233 +#ifdef CONFIG_COMPAT
11234 +
11235 +extern int vc_set_mapping_x32(struct vx_info *, void __user *);
11236 +extern int vc_unset_mapping_x32(struct vx_info *, void __user *);
11237 +
11238 +#endif /* CONFIG_COMPAT */
11239 +
11240 +#endif /* __KERNEL__ */
11241 +#endif /* _VX_DEVICE_CMD_H */
11242 diff -NurpP --minimal linux-2.6.29.1/include/linux/vserver/device_def.h linux-2.6.29.1-vs2.3.0.36.9-pre5/include/linux/vserver/device_def.h
11243 --- linux-2.6.29.1/include/linux/vserver/device_def.h   1970-01-01 01:00:00.000000000 +0100
11244 +++ linux-2.6.29.1-vs2.3.0.36.9-pre5/include/linux/vserver/device_def.h 2009-02-22 22:54:26.000000000 +0100
11245 @@ -0,0 +1,17 @@
11246 +#ifndef _VX_DEVICE_DEF_H
11247 +#define _VX_DEVICE_DEF_H
11248 +
11249 +#include <linux/types.h>
11250 +
11251 +struct vx_dmap_target {
11252 +       dev_t target;
11253 +       uint32_t flags;
11254 +};
11255 +
11256 +struct _vx_device {
11257 +#ifdef CONFIG_VSERVER_DEVICE
11258 +       struct vx_dmap_target targets[2];
11259 +#endif
11260 +};
11261 +
11262 +#endif /* _VX_DEVICE_DEF_H */
11263 diff -NurpP --minimal linux-2.6.29.1/include/linux/vserver/device.h linux-2.6.29.1-vs2.3.0.36.9-pre5/include/linux/vserver/device.h
11264 --- linux-2.6.29.1/include/linux/vserver/device.h       1970-01-01 01:00:00.000000000 +0100
11265 +++ linux-2.6.29.1-vs2.3.0.36.9-pre5/include/linux/vserver/device.h     2009-02-22 22:54:26.000000000 +0100
11266 @@ -0,0 +1,15 @@
11267 +#ifndef _VX_DEVICE_H
11268 +#define _VX_DEVICE_H
11269 +
11270 +
11271 +#define DATTR_CREATE   0x00000001
11272 +#define DATTR_OPEN     0x00000002
11273 +
11274 +#define DATTR_REMAP    0x00000010
11275 +
11276 +#define DATTR_MASK     0x00000013
11277 +
11278 +
11279 +#else  /* _VX_DEVICE_H */
11280 +#warning duplicate inclusion
11281 +#endif /* _VX_DEVICE_H */
11282 diff -NurpP --minimal linux-2.6.29.1/include/linux/vserver/dlimit_cmd.h linux-2.6.29.1-vs2.3.0.36.9-pre5/include/linux/vserver/dlimit_cmd.h
11283 --- linux-2.6.29.1/include/linux/vserver/dlimit_cmd.h   1970-01-01 01:00:00.000000000 +0100
11284 +++ linux-2.6.29.1-vs2.3.0.36.9-pre5/include/linux/vserver/dlimit_cmd.h 2009-02-22 22:54:26.000000000 +0100
11285 @@ -0,0 +1,74 @@
11286 +#ifndef _VX_DLIMIT_CMD_H
11287 +#define _VX_DLIMIT_CMD_H
11288 +
11289 +
11290 +/*  dlimit vserver commands */
11291 +
11292 +#define VCMD_add_dlimit                VC_CMD(DLIMIT, 1, 0)
11293 +#define VCMD_rem_dlimit                VC_CMD(DLIMIT, 2, 0)
11294 +
11295 +#define VCMD_set_dlimit                VC_CMD(DLIMIT, 5, 0)
11296 +#define VCMD_get_dlimit                VC_CMD(DLIMIT, 6, 0)
11297 +
11298 +struct vcmd_ctx_dlimit_base_v0 {
11299 +       const char __user *name;
11300 +       uint32_t flags;
11301 +};
11302 +
11303 +struct vcmd_ctx_dlimit_v0 {
11304 +       const char __user *name;
11305 +       uint32_t space_used;                    /* used space in kbytes */
11306 +       uint32_t space_total;                   /* maximum space in kbytes */
11307 +       uint32_t inodes_used;                   /* used inodes */
11308 +       uint32_t inodes_total;                  /* maximum inodes */
11309 +       uint32_t reserved;                      /* reserved for root in % */
11310 +       uint32_t flags;
11311 +};
11312 +
11313 +#define CDLIM_UNSET            ((uint32_t)0UL)
11314 +#define CDLIM_INFINITY         ((uint32_t)~0UL)
11315 +#define CDLIM_KEEP             ((uint32_t)~1UL)
11316 +
11317 +#ifdef __KERNEL__
11318 +
11319 +#ifdef CONFIG_COMPAT
11320 +
11321 +#include <asm/compat.h>
11322 +
11323 +struct vcmd_ctx_dlimit_base_v0_x32 {
11324 +       compat_uptr_t name_ptr;
11325 +       uint32_t flags;
11326 +};
11327 +
11328 +struct vcmd_ctx_dlimit_v0_x32 {
11329 +       compat_uptr_t name_ptr;
11330 +       uint32_t space_used;                    /* used space in kbytes */
11331 +       uint32_t space_total;                   /* maximum space in kbytes */
11332 +       uint32_t inodes_used;                   /* used inodes */
11333 +       uint32_t inodes_total;                  /* maximum inodes */
11334 +       uint32_t reserved;                      /* reserved for root in % */
11335 +       uint32_t flags;
11336 +};
11337 +
11338 +#endif /* CONFIG_COMPAT */
11339 +
11340 +#include <linux/compiler.h>
11341 +
11342 +extern int vc_add_dlimit(uint32_t, void __user *);
11343 +extern int vc_rem_dlimit(uint32_t, void __user *);
11344 +
11345 +extern int vc_set_dlimit(uint32_t, void __user *);
11346 +extern int vc_get_dlimit(uint32_t, void __user *);
11347 +
11348 +#ifdef CONFIG_COMPAT
11349 +
11350 +extern int vc_add_dlimit_x32(uint32_t, void __user *);
11351 +extern int vc_rem_dlimit_x32(uint32_t, void __user *);
11352 +
11353 +extern int vc_set_dlimit_x32(uint32_t, void __user *);
11354 +extern int vc_get_dlimit_x32(uint32_t, void __user *);
11355 +
11356 +#endif /* CONFIG_COMPAT */
11357 +
11358 +#endif /* __KERNEL__ */
11359 +#endif /* _VX_DLIMIT_CMD_H */
11360 diff -NurpP --minimal linux-2.6.29.1/include/linux/vserver/dlimit.h linux-2.6.29.1-vs2.3.0.36.9-pre5/include/linux/vserver/dlimit.h
11361 --- linux-2.6.29.1/include/linux/vserver/dlimit.h       1970-01-01 01:00:00.000000000 +0100
11362 +++ linux-2.6.29.1-vs2.3.0.36.9-pre5/include/linux/vserver/dlimit.h     2009-02-22 22:54:26.000000000 +0100
11363 @@ -0,0 +1,54 @@
11364 +#ifndef _VX_DLIMIT_H
11365 +#define _VX_DLIMIT_H
11366 +
11367 +#include "switch.h"
11368 +
11369 +
11370 +#ifdef __KERNEL__
11371 +
11372 +/*      keep in sync with CDLIM_INFINITY       */
11373 +
11374 +#define DLIM_INFINITY          (~0ULL)
11375 +
11376 +#include <linux/spinlock.h>
11377 +#include <linux/rcupdate.h>
11378 +
11379 +struct super_block;
11380 +
11381 +struct dl_info {
11382 +       struct hlist_node dl_hlist;             /* linked list of contexts */
11383 +       struct rcu_head dl_rcu;                 /* the rcu head */
11384 +       tag_t dl_tag;                           /* context tag */
11385 +       atomic_t dl_usecnt;                     /* usage count */
11386 +       atomic_t dl_refcnt;                     /* reference count */
11387 +
11388 +       struct super_block *dl_sb;              /* associated superblock */
11389 +
11390 +       spinlock_t dl_lock;                     /* protect the values */
11391 +
11392 +       unsigned long long dl_space_used;       /* used space in bytes */
11393 +       unsigned long long dl_space_total;      /* maximum space in bytes */
11394 +       unsigned long dl_inodes_used;           /* used inodes */
11395 +       unsigned long dl_inodes_total;          /* maximum inodes */
11396 +
11397 +       unsigned int dl_nrlmult;                /* non root limit mult */
11398 +};
11399 +
11400 +struct rcu_head;
11401 +
11402 +extern void rcu_free_dl_info(struct rcu_head *);
11403 +extern void unhash_dl_info(struct dl_info *);
11404 +
11405 +extern struct dl_info *locate_dl_info(struct super_block *, tag_t);
11406 +
11407 +
11408 +struct kstatfs;
11409 +
11410 +extern void vx_vsi_statfs(struct super_block *, struct kstatfs *);
11411 +
11412 +typedef uint64_t dlsize_t;
11413 +
11414 +#endif /* __KERNEL__ */
11415 +#else  /* _VX_DLIMIT_H */
11416 +#warning duplicate inclusion
11417 +#endif /* _VX_DLIMIT_H */
11418 diff -NurpP --minimal linux-2.6.29.1/include/linux/vserver/global.h linux-2.6.29.1-vs2.3.0.36.9-pre5/include/linux/vserver/global.h
11419 --- linux-2.6.29.1/include/linux/vserver/global.h       1970-01-01 01:00:00.000000000 +0100
11420 +++ linux-2.6.29.1-vs2.3.0.36.9-pre5/include/linux/vserver/global.h     2009-02-22 22:54:26.000000000 +0100
11421 @@ -0,0 +1,20 @@
11422 +#ifndef _VX_GLOBAL_H
11423 +#define _VX_GLOBAL_H
11424 +
11425 +
11426 +extern atomic_t vx_global_ctotal;
11427 +extern atomic_t vx_global_cactive;
11428 +
11429 +extern atomic_t nx_global_ctotal;
11430 +extern atomic_t nx_global_cactive;
11431 +
11432 +extern atomic_t vs_global_nsproxy;
11433 +extern atomic_t vs_global_fs;
11434 +extern atomic_t vs_global_mnt_ns;
11435 +extern atomic_t vs_global_uts_ns;
11436 +extern atomic_t vs_global_ipc_ns;
11437 +extern atomic_t vs_global_user_ns;
11438 +extern atomic_t vs_global_pid_ns;
11439 +
11440 +
11441 +#endif /* _VX_GLOBAL_H */
11442 diff -NurpP --minimal linux-2.6.29.1/include/linux/vserver/history.h linux-2.6.29.1-vs2.3.0.36.9-pre5/include/linux/vserver/history.h
11443 --- linux-2.6.29.1/include/linux/vserver/history.h      1970-01-01 01:00:00.000000000 +0100
11444 +++ linux-2.6.29.1-vs2.3.0.36.9-pre5/include/linux/vserver/history.h    2009-02-22 22:54:26.000000000 +0100
11445 @@ -0,0 +1,197 @@
11446 +#ifndef _VX_HISTORY_H
11447 +#define _VX_HISTORY_H
11448 +
11449 +
11450 +enum {
11451 +       VXH_UNUSED = 0,
11452 +       VXH_THROW_OOPS = 1,
11453 +
11454 +       VXH_GET_VX_INFO,
11455 +       VXH_PUT_VX_INFO,
11456 +       VXH_INIT_VX_INFO,
11457 +       VXH_SET_VX_INFO,
11458 +       VXH_CLR_VX_INFO,
11459 +       VXH_CLAIM_VX_INFO,
11460 +       VXH_RELEASE_VX_INFO,
11461 +       VXH_ALLOC_VX_INFO,
11462 +       VXH_DEALLOC_VX_INFO,
11463 +       VXH_HASH_VX_INFO,
11464 +       VXH_UNHASH_VX_INFO,
11465 +       VXH_LOC_VX_INFO,
11466 +       VXH_LOOKUP_VX_INFO,
11467 +       VXH_CREATE_VX_INFO,
11468 +};
11469 +
11470 +struct _vxhe_vxi {
11471 +       struct vx_info *ptr;
11472 +       unsigned xid;
11473 +       unsigned usecnt;
11474 +       unsigned tasks;
11475 +};
11476 +
11477 +struct _vxhe_set_clr {
11478 +       void *data;
11479 +};
11480 +
11481 +struct _vxhe_loc_lookup {
11482 +       unsigned arg;
11483 +};
11484 +
11485 +struct _vx_hist_entry {
11486 +       void *loc;
11487 +       unsigned short seq;
11488 +       unsigned short type;
11489 +       struct _vxhe_vxi vxi;
11490 +       union {
11491 +               struct _vxhe_set_clr sc;
11492 +               struct _vxhe_loc_lookup ll;
11493 +       };
11494 +};
11495 +
11496 +#ifdef CONFIG_VSERVER_HISTORY
11497 +
11498 +extern unsigned volatile int vxh_active;
11499 +
11500 +struct _vx_hist_entry *vxh_advance(void *loc);
11501 +
11502 +
11503 +static inline
11504 +void   __vxh_copy_vxi(struct _vx_hist_entry *entry, struct vx_info *vxi)
11505 +{
11506 +       entry->vxi.ptr = vxi;
11507 +       if (vxi) {
11508 +               entry->vxi.usecnt = atomic_read(&vxi->vx_usecnt);
11509 +               entry->vxi.tasks = atomic_read(&vxi->vx_tasks);
11510 +               entry->vxi.xid = vxi->vx_id;
11511 +       }
11512 +}
11513 +
11514 +
11515 +#define        __HERE__ current_text_addr()
11516 +
11517 +#define __VXH_BODY(__type, __data, __here)     \
11518 +       struct _vx_hist_entry *entry;           \
11519 +                                               \
11520 +       preempt_disable();                      \
11521 +       entry = vxh_advance(__here);            \
11522 +       __data;                                 \
11523 +       entry->type = __type;                   \
11524 +       preempt_enable();
11525 +
11526 +
11527 +       /* pass vxi only */
11528 +
11529 +#define __VXH_SMPL                             \
11530 +       __vxh_copy_vxi(entry, vxi)
11531 +
11532 +static inline
11533 +void   __vxh_smpl(struct vx_info *vxi, int __type, void *__here)
11534 +{
11535 +       __VXH_BODY(__type, __VXH_SMPL, __here)
11536 +}
11537 +
11538 +       /* pass vxi and data (void *) */
11539 +
11540 +#define __VXH_DATA                             \
11541 +       __vxh_copy_vxi(entry, vxi);             \
11542 +       entry->sc.data = data
11543 +
11544 +static inline
11545 +void   __vxh_data(struct vx_info *vxi, void *data,
11546 +                       int __type, void *__here)
11547 +{
11548 +       __VXH_BODY(__type, __VXH_DATA, __here)
11549 +}
11550 +
11551 +       /* pass vxi and arg (long) */
11552 +
11553 +#define __VXH_LONG                             \
11554 +       __vxh_copy_vxi(entry, vxi);             \
11555 +       entry->ll.arg = arg
11556 +
11557 +static inline
11558 +void   __vxh_long(struct vx_info *vxi, long arg,
11559 +                       int __type, void *__here)
11560 +{
11561 +       __VXH_BODY(__type, __VXH_LONG, __here)
11562 +}
11563 +
11564 +
11565 +static inline
11566 +void   __vxh_throw_oops(void *__here)
11567 +{
11568 +       __VXH_BODY(VXH_THROW_OOPS, {}, __here);
11569 +       /* prevent further acquisition */
11570 +       vxh_active = 0;
11571 +}
11572 +
11573 +
11574 +#define vxh_throw_oops()       __vxh_throw_oops(__HERE__);
11575 +
11576 +#define __vxh_get_vx_info(v, h)        __vxh_smpl(v, VXH_GET_VX_INFO, h);
11577 +#define __vxh_put_vx_info(v, h)        __vxh_smpl(v, VXH_PUT_VX_INFO, h);
11578 +
11579 +#define __vxh_init_vx_info(v, d, h) \
11580 +       __vxh_data(v, d, VXH_INIT_VX_INFO, h);
11581 +#define __vxh_set_vx_info(v, d, h) \
11582 +       __vxh_data(v, d, VXH_SET_VX_INFO, h);
11583 +#define __vxh_clr_vx_info(v, d, h) \
11584 +       __vxh_data(v, d, VXH_CLR_VX_INFO, h);
11585 +
11586 +#define __vxh_claim_vx_info(v, d, h) \
11587 +       __vxh_data(v, d, VXH_CLAIM_VX_INFO, h);
11588 +#define __vxh_release_vx_info(v, d, h) \
11589 +       __vxh_data(v, d, VXH_RELEASE_VX_INFO, h);
11590 +
11591 +#define vxh_alloc_vx_info(v) \
11592 +       __vxh_smpl(v, VXH_ALLOC_VX_INFO, __HERE__);
11593 +#define vxh_dealloc_vx_info(v) \
11594 +       __vxh_smpl(v, VXH_DEALLOC_VX_INFO, __HERE__);
11595 +
11596 +#define vxh_hash_vx_info(v) \
11597 +       __vxh_smpl(v, VXH_HASH_VX_INFO, __HERE__);
11598 +#define vxh_unhash_vx_info(v) \
11599 +       __vxh_smpl(v, VXH_UNHASH_VX_INFO, __HERE__);
11600 +
11601 +#define vxh_loc_vx_info(v, l) \
11602 +       __vxh_long(v, l, VXH_LOC_VX_INFO, __HERE__);
11603 +#define vxh_lookup_vx_info(v, l) \
11604 +       __vxh_long(v, l, VXH_LOOKUP_VX_INFO, __HERE__);
11605 +#define vxh_create_vx_info(v, l) \
11606 +       __vxh_long(v, l, VXH_CREATE_VX_INFO, __HERE__);
11607 +
11608 +extern void vxh_dump_history(void);
11609 +
11610 +
11611 +#else  /* CONFIG_VSERVER_HISTORY */
11612 +
11613 +#define        __HERE__        0
11614 +
11615 +#define vxh_throw_oops()               do { } while (0)
11616 +
11617 +#define __vxh_get_vx_info(v, h)                do { } while (0)
11618 +#define __vxh_put_vx_info(v, h)                do { } while (0)
11619 +
11620 +#define __vxh_init_vx_info(v, d, h)    do { } while (0)
11621 +#define __vxh_set_vx_info(v, d, h)     do { } while (0)
11622 +#define __vxh_clr_vx_info(v, d, h)     do { } while (0)
11623 +
11624 +#define __vxh_claim_vx_info(v, d, h)   do { } while (0)
11625 +#define __vxh_release_vx_info(v, d, h) do { } while (0)
11626 +
11627 +#define vxh_alloc_vx_info(v)           do { } while (0)
11628 +#define vxh_dealloc_vx_info(v)         do { } while (0)
11629 +
11630 +#define vxh_hash_vx_info(v)            do { } while (0)
11631 +#define vxh_unhash_vx_info(v)          do { } while (0)
11632 +
11633 +#define vxh_loc_vx_info(v, l)          do { } while (0)
11634 +#define vxh_lookup_vx_info(v, l)       do { } while (0)
11635 +#define vxh_create_vx_info(v, l)       do { } while (0)
11636 +
11637 +#define vxh_dump_history()             do { } while (0)
11638 +
11639 +
11640 +#endif /* CONFIG_VSERVER_HISTORY */
11641 +
11642 +#endif /* _VX_HISTORY_H */
11643 diff -NurpP --minimal linux-2.6.29.1/include/linux/vserver/inode_cmd.h linux-2.6.29.1-vs2.3.0.36.9-pre5/include/linux/vserver/inode_cmd.h
11644 --- linux-2.6.29.1/include/linux/vserver/inode_cmd.h    1970-01-01 01:00:00.000000000 +0100
11645 +++ linux-2.6.29.1-vs2.3.0.36.9-pre5/include/linux/vserver/inode_cmd.h  2009-02-22 22:54:26.000000000 +0100
11646 @@ -0,0 +1,59 @@
11647 +#ifndef _VX_INODE_CMD_H
11648 +#define _VX_INODE_CMD_H
11649 +
11650 +
11651 +/*  inode vserver commands */
11652 +
11653 +#define VCMD_get_iattr         VC_CMD(INODE, 1, 1)
11654 +#define VCMD_set_iattr         VC_CMD(INODE, 2, 1)
11655 +
11656 +#define VCMD_fget_iattr                VC_CMD(INODE, 3, 0)
11657 +#define VCMD_fset_iattr                VC_CMD(INODE, 4, 0)
11658 +
11659 +struct vcmd_ctx_iattr_v1 {
11660 +       const char __user *name;
11661 +       uint32_t tag;
11662 +       uint32_t flags;
11663 +       uint32_t mask;
11664 +};
11665 +
11666 +struct vcmd_ctx_fiattr_v0 {
11667 +       uint32_t tag;
11668 +       uint32_t flags;
11669 +       uint32_t mask;
11670 +};
11671 +
11672 +
11673 +#ifdef __KERNEL__
11674 +
11675 +
11676 +#ifdef CONFIG_COMPAT
11677 +
11678 +#include <asm/compat.h>
11679 +
11680 +struct vcmd_ctx_iattr_v1_x32 {
11681 +       compat_uptr_t name_ptr;
11682 +       uint32_t tag;
11683 +       uint32_t flags;
11684 +       uint32_t mask;
11685 +};
11686 +
11687 +#endif /* CONFIG_COMPAT */
11688 +
11689 +#include <linux/compiler.h>
11690 +
11691 +extern int vc_get_iattr(void __user *);
11692 +extern int vc_set_iattr(void __user *);
11693 +
11694 +extern int vc_fget_iattr(uint32_t, void __user *);
11695 +extern int vc_fset_iattr(uint32_t, void __user *);
11696 +
11697 +#ifdef CONFIG_COMPAT
11698 +
11699 +extern int vc_get_iattr_x32(void __user *);
11700 +extern int vc_set_iattr_x32(void __user *);
11701 +
11702 +#endif /* CONFIG_COMPAT */
11703 +
11704 +#endif /* __KERNEL__ */
11705 +#endif /* _VX_INODE_CMD_H */
11706 diff -NurpP --minimal linux-2.6.29.1/include/linux/vserver/inode.h linux-2.6.29.1-vs2.3.0.36.9-pre5/include/linux/vserver/inode.h
11707 --- linux-2.6.29.1/include/linux/vserver/inode.h        1970-01-01 01:00:00.000000000 +0100
11708 +++ linux-2.6.29.1-vs2.3.0.36.9-pre5/include/linux/vserver/inode.h      2009-02-22 22:54:26.000000000 +0100
11709 @@ -0,0 +1,38 @@
11710 +#ifndef _VX_INODE_H
11711 +#define _VX_INODE_H
11712 +
11713 +
11714 +#define IATTR_TAG      0x01000000
11715 +
11716 +#define IATTR_ADMIN    0x00000001
11717 +#define IATTR_WATCH    0x00000002
11718 +#define IATTR_HIDE     0x00000004
11719 +#define IATTR_FLAGS    0x00000007
11720 +
11721 +#define IATTR_BARRIER  0x00010000
11722 +#define IATTR_IXUNLINK 0x00020000
11723 +#define IATTR_IMMUTABLE 0x00040000
11724 +
11725 +#ifdef __KERNEL__
11726 +
11727 +
11728 +#ifdef CONFIG_VSERVER_PROC_SECURE
11729 +#define IATTR_PROC_DEFAULT     ( IATTR_ADMIN | IATTR_HIDE )
11730 +#define IATTR_PROC_SYMLINK     ( IATTR_ADMIN )
11731 +#else
11732 +#define IATTR_PROC_DEFAULT     ( IATTR_ADMIN )
11733 +#define IATTR_PROC_SYMLINK     ( IATTR_ADMIN )
11734 +#endif
11735 +
11736 +#define vx_hide_check(c, m)    (((m) & IATTR_HIDE) ? vx_check(c, m) : 1)
11737 +
11738 +#endif /* __KERNEL__ */
11739 +
11740 +/* inode ioctls */
11741 +
11742 +#define FIOC_GETXFLG   _IOR('x', 5, long)
11743 +#define FIOC_SETXFLG   _IOW('x', 6, long)
11744 +
11745 +#else  /* _VX_INODE_H */
11746 +#warning duplicate inclusion
11747 +#endif /* _VX_INODE_H */
11748 diff -NurpP --minimal linux-2.6.29.1/include/linux/vserver/Kbuild linux-2.6.29.1-vs2.3.0.36.9-pre5/include/linux/vserver/Kbuild
11749 --- linux-2.6.29.1/include/linux/vserver/Kbuild 1970-01-01 01:00:00.000000000 +0100
11750 +++ linux-2.6.29.1-vs2.3.0.36.9-pre5/include/linux/vserver/Kbuild       2009-02-22 22:54:26.000000000 +0100
11751 @@ -0,0 +1,8 @@
11752 +
11753 +unifdef-y += context_cmd.h network_cmd.h space_cmd.h \
11754 +       cacct_cmd.h cvirt_cmd.h limit_cmd.h dlimit_cmd.h \
11755 +       inode_cmd.h tag_cmd.h sched_cmd.h signal_cmd.h \
11756 +       debug_cmd.h device_cmd.h
11757 +
11758 +unifdef-y += switch.h network.h monitor.h inode.h device.h
11759 +
11760 diff -NurpP --minimal linux-2.6.29.1/include/linux/vserver/limit_cmd.h linux-2.6.29.1-vs2.3.0.36.9-pre5/include/linux/vserver/limit_cmd.h
11761 --- linux-2.6.29.1/include/linux/vserver/limit_cmd.h    1970-01-01 01:00:00.000000000 +0100
11762 +++ linux-2.6.29.1-vs2.3.0.36.9-pre5/include/linux/vserver/limit_cmd.h  2009-02-22 22:54:26.000000000 +0100
11763 @@ -0,0 +1,69 @@
11764 +#ifndef _VX_LIMIT_CMD_H
11765 +#define _VX_LIMIT_CMD_H
11766 +
11767 +
11768 +/*  rlimit vserver commands */
11769 +
11770 +#define VCMD_get_rlimit                VC_CMD(RLIMIT, 1, 0)
11771 +#define VCMD_set_rlimit                VC_CMD(RLIMIT, 2, 0)
11772 +#define VCMD_get_rlimit_mask   VC_CMD(RLIMIT, 3, 0)
11773 +#define VCMD_reset_minmax      VC_CMD(RLIMIT, 9, 0)
11774 +
11775 +struct vcmd_ctx_rlimit_v0 {
11776 +       uint32_t id;
11777 +       uint64_t minimum;
11778 +       uint64_t softlimit;
11779 +       uint64_t maximum;
11780 +};
11781 +
11782 +struct vcmd_ctx_rlimit_mask_v0 {
11783 +       uint32_t minimum;
11784 +       uint32_t softlimit;
11785 +       uint32_t maximum;
11786 +};
11787 +
11788 +#define VCMD_rlimit_stat       VC_CMD(VSTAT, 1, 0)
11789 +
11790 +struct vcmd_rlimit_stat_v0 {
11791 +       uint32_t id;
11792 +       uint32_t hits;
11793 +       uint64_t value;
11794 +       uint64_t minimum;
11795 +       uint64_t maximum;
11796 +};
11797 +
11798 +#define CRLIM_UNSET            (0ULL)
11799 +#define CRLIM_INFINITY         (~0ULL)
11800 +#define CRLIM_KEEP             (~1ULL)
11801 +
11802 +#ifdef __KERNEL__
11803 +
11804 +#ifdef CONFIG_IA32_EMULATION
11805 +
11806 +struct vcmd_ctx_rlimit_v0_x32 {
11807 +       uint32_t id;
11808 +       uint64_t minimum;
11809 +       uint64_t softlimit;
11810 +       uint64_t maximum;
11811 +} __attribute__ ((packed));
11812 +
11813 +#endif /* CONFIG_IA32_EMULATION */
11814 +
11815 +#include <linux/compiler.h>
11816 +
11817 +extern int vc_get_rlimit_mask(uint32_t, void __user *);
11818 +extern int vc_get_rlimit(struct vx_info *, void __user *);
11819 +extern int vc_set_rlimit(struct vx_info *, void __user *);
11820 +extern int vc_reset_minmax(struct vx_info *, void __user *);
11821 +
11822 +extern int vc_rlimit_stat(struct vx_info *, void __user *);
11823 +
11824 +#ifdef CONFIG_IA32_EMULATION
11825 +
11826 +extern int vc_get_rlimit_x32(struct vx_info *, void __user *);
11827 +extern int vc_set_rlimit_x32(struct vx_info *, void __user *);
11828 +
11829 +#endif /* CONFIG_IA32_EMULATION */
11830 +
11831 +#endif /* __KERNEL__ */
11832 +#endif /* _VX_LIMIT_CMD_H */
11833 diff -NurpP --minimal linux-2.6.29.1/include/linux/vserver/limit_def.h linux-2.6.29.1-vs2.3.0.36.9-pre5/include/linux/vserver/limit_def.h
11834 --- linux-2.6.29.1/include/linux/vserver/limit_def.h    1970-01-01 01:00:00.000000000 +0100
11835 +++ linux-2.6.29.1-vs2.3.0.36.9-pre5/include/linux/vserver/limit_def.h  2009-02-22 22:54:26.000000000 +0100
11836 @@ -0,0 +1,47 @@
11837 +#ifndef _VX_LIMIT_DEF_H
11838 +#define _VX_LIMIT_DEF_H
11839 +
11840 +#include <asm/atomic.h>
11841 +#include <asm/resource.h>
11842 +
11843 +#include "limit.h"
11844 +
11845 +
11846 +struct _vx_res_limit {
11847 +       rlim_t soft;            /* Context soft limit */
11848 +       rlim_t hard;            /* Context hard limit */
11849 +
11850 +       rlim_atomic_t rcur;     /* Current value */
11851 +       rlim_t rmin;            /* Context minimum */
11852 +       rlim_t rmax;            /* Context maximum */
11853 +
11854 +       atomic_t lhit;          /* Limit hits */
11855 +};
11856 +
11857 +/* context sub struct */
11858 +
11859 +struct _vx_limit {
11860 +       struct _vx_res_limit res[NUM_LIMITS];
11861 +};
11862 +
11863 +#ifdef CONFIG_VSERVER_DEBUG
11864 +
11865 +static inline void __dump_vx_limit(struct _vx_limit *limit)
11866 +{
11867 +       int i;
11868 +
11869 +       printk("\t_vx_limit:");
11870 +       for (i = 0; i < NUM_LIMITS; i++) {
11871 +               printk("\t [%2d] = %8lu %8lu/%8lu, %8ld/%8ld, %8d\n",
11872 +                       i, (unsigned long)__rlim_get(limit, i),
11873 +                       (unsigned long)__rlim_rmin(limit, i),
11874 +                       (unsigned long)__rlim_rmax(limit, i),
11875 +                       (long)__rlim_soft(limit, i),
11876 +                       (long)__rlim_hard(limit, i),
11877 +                       atomic_read(&__rlim_lhit(limit, i)));
11878 +       }
11879 +}
11880 +
11881 +#endif
11882 +
11883 +#endif /* _VX_LIMIT_DEF_H */
11884 diff -NurpP --minimal linux-2.6.29.1/include/linux/vserver/limit.h linux-2.6.29.1-vs2.3.0.36.9-pre5/include/linux/vserver/limit.h
11885 --- linux-2.6.29.1/include/linux/vserver/limit.h        1970-01-01 01:00:00.000000000 +0100
11886 +++ linux-2.6.29.1-vs2.3.0.36.9-pre5/include/linux/vserver/limit.h      2009-02-22 22:54:26.000000000 +0100
11887 @@ -0,0 +1,70 @@
11888 +#ifndef _VX_LIMIT_H
11889 +#define _VX_LIMIT_H
11890 +
11891 +#define VLIMIT_NSOCK   16
11892 +#define VLIMIT_OPENFD  17
11893 +#define VLIMIT_ANON    18
11894 +#define VLIMIT_SHMEM   19
11895 +#define VLIMIT_SEMARY  20
11896 +#define VLIMIT_NSEMS   21
11897 +#define VLIMIT_DENTRY  22
11898 +#define VLIMIT_MAPPED  23
11899 +
11900 +
11901 +#ifdef __KERNEL__
11902 +
11903 +#define        VLIM_NOCHECK    ((1L << VLIMIT_DENTRY) | (1L << RLIMIT_RSS))
11904 +
11905 +/*     keep in sync with CRLIM_INFINITY */
11906 +
11907 +#define        VLIM_INFINITY   (~0ULL)
11908 +
11909 +#include <asm/atomic.h>
11910 +#include <asm/resource.h>
11911 +
11912 +#ifndef RLIM_INFINITY
11913 +#warning RLIM_INFINITY is undefined
11914 +#endif
11915 +
11916 +#define __rlim_val(l, r, v)    ((l)->res[r].v)
11917 +
11918 +#define __rlim_soft(l, r)      __rlim_val(l, r, soft)
11919 +#define __rlim_hard(l, r)      __rlim_val(l, r, hard)
11920 +
11921 +#define __rlim_rcur(l, r)      __rlim_val(l, r, rcur)
11922 +#define __rlim_rmin(l, r)      __rlim_val(l, r, rmin)
11923 +#define __rlim_rmax(l, r)      __rlim_val(l, r, rmax)
11924 +
11925 +#define __rlim_lhit(l, r)      __rlim_val(l, r, lhit)
11926 +#define __rlim_hit(l, r)       atomic_inc(&__rlim_lhit(l, r))
11927 +
11928 +typedef atomic_long_t rlim_atomic_t;
11929 +typedef unsigned long rlim_t;
11930 +
11931 +#define __rlim_get(l, r)       atomic_long_read(&__rlim_rcur(l, r))
11932 +#define __rlim_set(l, r, v)    atomic_long_set(&__rlim_rcur(l, r), v)
11933 +#define __rlim_inc(l, r)       atomic_long_inc(&__rlim_rcur(l, r))
11934 +#define __rlim_dec(l, r)       atomic_long_dec(&__rlim_rcur(l, r))
11935 +#define __rlim_add(l, r, v)    atomic_long_add(v, &__rlim_rcur(l, r))
11936 +#define __rlim_sub(l, r, v)    atomic_long_sub(v, &__rlim_rcur(l, r))
11937 +
11938 +
11939 +#if    (RLIM_INFINITY == VLIM_INFINITY)
11940 +#define        VX_VLIM(r) ((long long)(long)(r))
11941 +#define        VX_RLIM(v) ((rlim_t)(v))
11942 +#else
11943 +#define        VX_VLIM(r) (((r) == RLIM_INFINITY) \
11944 +               ? VLIM_INFINITY : (long long)(r))
11945 +#define        VX_RLIM(v) (((v) == VLIM_INFINITY) \
11946 +               ? RLIM_INFINITY : (rlim_t)(v))
11947 +#endif
11948 +
11949 +struct sysinfo;
11950 +
11951 +void vx_vsi_meminfo(struct sysinfo *);
11952 +void vx_vsi_swapinfo(struct sysinfo *);
11953 +
11954 +#define NUM_LIMITS     24
11955 +
11956 +#endif /* __KERNEL__ */
11957 +#endif /* _VX_LIMIT_H */
11958 diff -NurpP --minimal linux-2.6.29.1/include/linux/vserver/limit_int.h linux-2.6.29.1-vs2.3.0.36.9-pre5/include/linux/vserver/limit_int.h
11959 --- linux-2.6.29.1/include/linux/vserver/limit_int.h    1970-01-01 01:00:00.000000000 +0100
11960 +++ linux-2.6.29.1-vs2.3.0.36.9-pre5/include/linux/vserver/limit_int.h  2009-02-22 22:54:26.000000000 +0100
11961 @@ -0,0 +1,198 @@
11962 +#ifndef _VX_LIMIT_INT_H
11963 +#define _VX_LIMIT_INT_H
11964 +
11965 +#include "context.h"
11966 +
11967 +#ifdef __KERNEL__
11968 +
11969 +#define VXD_RCRES_COND(r)      VXD_CBIT(cres, r)
11970 +#define VXD_RLIMIT_COND(r)     VXD_CBIT(limit, r)
11971 +
11972 +extern const char *vlimit_name[NUM_LIMITS];
11973 +
11974 +static inline void __vx_acc_cres(struct vx_info *vxi,
11975 +       int res, int dir, void *_data, char *_file, int _line)
11976 +{
11977 +       if (VXD_RCRES_COND(res))
11978 +               vxlprintk(1, "vx_acc_cres[%5d,%s,%2d]: %5ld%s (%p)",
11979 +                       (vxi ? vxi->vx_id : -1), vlimit_name[res], res,
11980 +                       (vxi ? (long)__rlim_get(&vxi->limit, res) : 0),
11981 +                       (dir > 0) ? "++" : "--", _data, _file, _line);
11982 +       if (!vxi)
11983 +               return;
11984 +
11985 +       if (dir > 0)
11986 +               __rlim_inc(&vxi->limit, res);
11987 +       else
11988 +               __rlim_dec(&vxi->limit, res);
11989 +}
11990 +
11991 +static inline void __vx_add_cres(struct vx_info *vxi,
11992 +       int res, int amount, void *_data, char *_file, int _line)
11993 +{
11994 +       if (VXD_RCRES_COND(res))
11995 +               vxlprintk(1, "vx_add_cres[%5d,%s,%2d]: %5ld += %5d (%p)",
11996 +                       (vxi ? vxi->vx_id : -1), vlimit_name[res], res,
11997 +                       (vxi ? (long)__rlim_get(&vxi->limit, res) : 0),
11998 +                       amount, _data, _file, _line);
11999 +       if (amount == 0)
12000 +               return;
12001 +       if (!vxi)
12002 +               return;
12003 +       __rlim_add(&vxi->limit, res, amount);
12004 +}
12005 +
12006 +static inline
12007 +int __vx_cres_adjust_max(struct _vx_limit *limit, int res, rlim_t value)
12008 +{
12009 +       int cond = (value > __rlim_rmax(limit, res));
12010 +
12011 +       if (cond)
12012 +               __rlim_rmax(limit, res) = value;
12013 +       return cond;
12014 +}
12015 +
12016 +static inline
12017 +int __vx_cres_adjust_min(struct _vx_limit *limit, int res, rlim_t value)
12018 +{
12019 +       int cond = (value < __rlim_rmin(limit, res));
12020 +
12021 +       if (cond)
12022 +               __rlim_rmin(limit, res) = value;
12023 +       return cond;
12024 +}
12025 +
12026 +static inline
12027 +void __vx_cres_fixup(struct _vx_limit *limit, int res, rlim_t value)
12028 +{
12029 +       if (!__vx_cres_adjust_max(limit, res, value))
12030 +               __vx_cres_adjust_min(limit, res, value);
12031 +}
12032 +
12033 +
12034 +/*     return values:
12035 +        +1 ... no limit hit
12036 +        -1 ... over soft limit
12037 +         0 ... over hard limit         */
12038 +
12039 +static inline int __vx_cres_avail(struct vx_info *vxi,
12040 +       int res, int num, char *_file, int _line)
12041 +{
12042 +       struct _vx_limit *limit;
12043 +       rlim_t value;
12044 +
12045 +       if (VXD_RLIMIT_COND(res))
12046 +               vxlprintk(1, "vx_cres_avail[%5d,%s,%2d]: %5ld/%5ld > %5ld + %5d",
12047 +                       (vxi ? vxi->vx_id : -1), vlimit_name[res], res,
12048 +                       (vxi ? (long)__rlim_soft(&vxi->limit, res) : -1),
12049 +                       (vxi ? (long)__rlim_hard(&vxi->limit, res) : -1),
12050 +                       (vxi ? (long)__rlim_get(&vxi->limit, res) : 0),
12051 +                       num, _file, _line);
12052 +       if (!vxi)
12053 +               return 1;
12054 +
12055 +       limit = &vxi->limit;
12056 +       value = __rlim_get(limit, res);
12057 +
12058 +       if (!__vx_cres_adjust_max(limit, res, value))
12059 +               __vx_cres_adjust_min(limit, res, value);
12060 +
12061 +       if (num == 0)
12062 +               return 1;
12063 +
12064 +       if (__rlim_soft(limit, res) == RLIM_INFINITY)
12065 +               return -1;
12066 +       if (value + num <= __rlim_soft(limit, res))
12067 +               return -1;
12068 +
12069 +       if (__rlim_hard(limit, res) == RLIM_INFINITY)
12070 +               return 1;
12071 +       if (value + num <= __rlim_hard(limit, res))
12072 +               return 1;
12073 +
12074 +       __rlim_hit(limit, res);
12075 +       return 0;
12076 +}
12077 +
12078 +
12079 +static const int VLA_RSS[] = { RLIMIT_RSS, VLIMIT_ANON, VLIMIT_MAPPED, 0 };
12080 +
12081 +static inline
12082 +rlim_t __vx_cres_array_sum(struct _vx_limit *limit, const int *array)
12083 +{
12084 +       rlim_t value, sum = 0;
12085 +       int res;
12086 +
12087 +       while ((res = *array++)) {
12088 +               value = __rlim_get(limit, res);
12089 +               __vx_cres_fixup(limit, res, value);
12090 +               sum += value;
12091 +       }
12092 +       return sum;
12093 +}
12094 +
12095 +static inline
12096 +rlim_t __vx_cres_array_fixup(struct _vx_limit *limit, const int *array)
12097 +{
12098 +       rlim_t value = __vx_cres_array_sum(limit, array + 1);
12099 +       int res = *array;
12100 +
12101 +       if (value == __rlim_get(limit, res))
12102 +               return value;
12103 +
12104 +       __rlim_set(limit, res, value);
12105 +       /* now adjust min/max */
12106 +       if (!__vx_cres_adjust_max(limit, res, value))
12107 +               __vx_cres_adjust_min(limit, res, value);
12108 +
12109 +       return value;
12110 +}
12111 +
12112 +static inline int __vx_cres_array_avail(struct vx_info *vxi,
12113 +       const int *array, int num, char *_file, int _line)
12114 +{
12115 +       struct _vx_limit *limit;
12116 +       rlim_t value = 0;
12117 +       int res;
12118 +
12119 +       if (num == 0)
12120 +               return 1;
12121 +       if (!vxi)
12122 +               return 1;
12123 +
12124 +       limit = &vxi->limit;
12125 +       res = *array;
12126 +       value = __vx_cres_array_sum(limit, array + 1);
12127 +
12128 +       __rlim_set(limit, res, value);
12129 +       __vx_cres_fixup(limit, res, value);
12130 +
12131 +       return __vx_cres_avail(vxi, res, num, _file, _line);
12132 +}
12133 +
12134 +
12135 +static inline void vx_limit_fixup(struct _vx_limit *limit, int id)
12136 +{
12137 +       rlim_t value;
12138 +       int res;
12139 +
12140 +       /* complex resources first */
12141 +       if ((id < 0) || (id == RLIMIT_RSS))
12142 +               __vx_cres_array_fixup(limit, VLA_RSS);
12143 +
12144 +       for (res = 0; res < NUM_LIMITS; res++) {
12145 +               if ((id > 0) && (res != id))
12146 +                       continue;
12147 +
12148 +               value = __rlim_get(limit, res);
12149 +               __vx_cres_fixup(limit, res, value);
12150 +
12151 +               /* not supposed to happen, maybe warn? */
12152 +               if (__rlim_rmax(limit, res) > __rlim_hard(limit, res))
12153 +                       __rlim_rmax(limit, res) = __rlim_hard(limit, res);
12154 +       }
12155 +}
12156 +
12157 +
12158 +#endif /* __KERNEL__ */
12159 +#endif /* _VX_LIMIT_INT_H */
12160 diff -NurpP --minimal linux-2.6.29.1/include/linux/vserver/monitor.h linux-2.6.29.1-vs2.3.0.36.9-pre5/include/linux/vserver/monitor.h
12161 --- linux-2.6.29.1/include/linux/vserver/monitor.h      1970-01-01 01:00:00.000000000 +0100
12162 +++ linux-2.6.29.1-vs2.3.0.36.9-pre5/include/linux/vserver/monitor.h    2009-02-22 22:54:26.000000000 +0100
12163 @@ -0,0 +1,96 @@
12164 +#ifndef _VX_MONITOR_H
12165 +#define _VX_MONITOR_H
12166 +
12167 +#include <linux/types.h>
12168 +
12169 +enum {
12170 +       VXM_UNUSED = 0,
12171 +
12172 +       VXM_SYNC = 0x10,
12173 +
12174 +       VXM_UPDATE = 0x20,
12175 +       VXM_UPDATE_1,
12176 +       VXM_UPDATE_2,
12177 +
12178 +       VXM_RQINFO_1 = 0x24,
12179 +       VXM_RQINFO_2,
12180 +
12181 +       VXM_ACTIVATE = 0x40,
12182 +       VXM_DEACTIVATE,
12183 +       VXM_IDLE,
12184 +
12185 +       VXM_HOLD = 0x44,
12186 +       VXM_UNHOLD,
12187 +
12188 +       VXM_MIGRATE = 0x48,
12189 +       VXM_RESCHED,
12190 +
12191 +       /* all other bits are flags */
12192 +       VXM_SCHED = 0x80,
12193 +};
12194 +
12195 +struct _vxm_update_1 {
12196 +       uint32_t tokens_max;
12197 +       uint32_t fill_rate;
12198 +       uint32_t interval;
12199 +};
12200 +
12201 +struct _vxm_update_2 {
12202 +       uint32_t tokens_min;
12203 +       uint32_t fill_rate;
12204 +       uint32_t interval;
12205 +};
12206 +
12207 +struct _vxm_rqinfo_1 {
12208 +       uint16_t running;
12209 +       uint16_t onhold;
12210 +       uint16_t iowait;
12211 +       uint16_t uintr;
12212 +       uint32_t idle_tokens;
12213 +};
12214 +
12215 +struct _vxm_rqinfo_2 {
12216 +       uint32_t norm_time;
12217 +       uint32_t idle_time;
12218 +       uint32_t idle_skip;
12219 +};
12220 +
12221 +struct _vxm_sched {
12222 +       uint32_t tokens;
12223 +       uint32_t norm_time;
12224 +       uint32_t idle_time;
12225 +};
12226 +
12227 +struct _vxm_task {
12228 +       uint16_t pid;
12229 +       uint16_t state;
12230 +};
12231 +
12232 +struct _vxm_event {
12233 +       uint32_t jif;
12234 +       union {
12235 +               uint32_t seq;
12236 +               uint32_t sec;
12237 +       };
12238 +       union {
12239 +               uint32_t tokens;
12240 +               uint32_t nsec;
12241 +               struct _vxm_task tsk;
12242 +       };
12243 +};
12244 +
12245 +struct _vx_mon_entry {
12246 +       uint16_t type;
12247 +       uint16_t xid;
12248 +       union {
12249 +               struct _vxm_event ev;
12250 +               struct _vxm_sched sd;
12251 +               struct _vxm_update_1 u1;
12252 +               struct _vxm_update_2 u2;
12253 +               struct _vxm_rqinfo_1 q1;
12254 +               struct _vxm_rqinfo_2 q2;
12255 +       };
12256 +};
12257 +
12258 +
12259 +#endif /* _VX_MONITOR_H */
12260 diff -NurpP --minimal linux-2.6.29.1/include/linux/vserver/network_cmd.h linux-2.6.29.1-vs2.3.0.36.9-pre5/include/linux/vserver/network_cmd.h
12261 --- linux-2.6.29.1/include/linux/vserver/network_cmd.h  1970-01-01 01:00:00.000000000 +0100
12262 +++ linux-2.6.29.1-vs2.3.0.36.9-pre5/include/linux/vserver/network_cmd.h        2009-02-22 22:54:26.000000000 +0100
12263 @@ -0,0 +1,150 @@
12264 +#ifndef _VX_NETWORK_CMD_H
12265 +#define _VX_NETWORK_CMD_H
12266 +
12267 +
12268 +/* vinfo commands */
12269 +
12270 +#define VCMD_task_nid          VC_CMD(VINFO, 2, 0)
12271 +
12272 +#ifdef __KERNEL__
12273 +extern int vc_task_nid(uint32_t);
12274 +
12275 +#endif /* __KERNEL__ */
12276 +
12277 +#define VCMD_nx_info           VC_CMD(VINFO, 6, 0)
12278 +
12279 +struct vcmd_nx_info_v0 {
12280 +       uint32_t nid;
12281 +       /* more to come */
12282 +};
12283 +
12284 +#ifdef __KERNEL__
12285 +extern int vc_nx_info(struct nx_info *, void __user *);
12286 +
12287 +#endif /* __KERNEL__ */
12288 +
12289 +#include <linux/in.h>
12290 +#include <linux/in6.h>
12291 +
12292 +#define VCMD_net_create_v0     VC_CMD(VNET, 1, 0)
12293 +#define VCMD_net_create                VC_CMD(VNET, 1, 1)
12294 +
12295 +struct  vcmd_net_create {
12296 +       uint64_t flagword;
12297 +};
12298 +
12299 +#define VCMD_net_migrate       VC_CMD(NETMIG, 1, 0)
12300 +
12301 +#define VCMD_net_add           VC_CMD(NETALT, 1, 0)
12302 +#define VCMD_net_remove                VC_CMD(NETALT, 2, 0)
12303 +
12304 +struct vcmd_net_addr_v0 {
12305 +       uint16_t type;
12306 +       uint16_t count;
12307 +       struct in_addr ip[4];
12308 +       struct in_addr mask[4];
12309 +};
12310 +
12311 +#define VCMD_net_add_ipv4      VC_CMD(NETALT, 1, 1)
12312 +#define VCMD_net_remove_ipv4   VC_CMD(NETALT, 2, 1)
12313 +
12314 +struct vcmd_net_addr_ipv4_v1 {
12315 +       uint16_t type;
12316 +       uint16_t flags;
12317 +       struct in_addr ip;
12318 +       struct in_addr mask;
12319 +};
12320 +
12321 +#define VCMD_net_add_ipv6      VC_CMD(NETALT, 3, 1)
12322 +#define VCMD_net_remove_ipv6   VC_CMD(NETALT, 4, 1)
12323 +
12324 +struct vcmd_net_addr_ipv6_v1 {
12325 +       uint16_t type;
12326 +       uint16_t flags;
12327 +       uint32_t prefix;
12328 +       struct in6_addr ip;
12329 +       struct in6_addr mask;
12330 +};
12331 +
12332 +#define VCMD_add_match_ipv4    VC_CMD(NETALT, 5, 0)
12333 +#define VCMD_get_match_ipv4    VC_CMD(NETALT, 6, 0)
12334 +
12335 +struct vcmd_match_ipv4_v0 {
12336 +       uint16_t type;
12337 +       uint16_t flags;
12338 +       uint16_t parent;
12339 +       uint16_t prefix;
12340 +       struct in_addr ip;
12341 +       struct in_addr ip2;
12342 +       struct in_addr mask;
12343 +};
12344 +
12345 +#define VCMD_add_match_ipv6    VC_CMD(NETALT, 7, 0)
12346 +#define VCMD_get_match_ipv6    VC_CMD(NETALT, 8, 0)
12347 +
12348 +struct vcmd_match_ipv6_v0 {
12349 +       uint16_t type;
12350 +       uint16_t flags;
12351 +       uint16_t parent;
12352 +       uint16_t prefix;
12353 +       struct in6_addr ip;
12354 +       struct in6_addr ip2;
12355 +       struct in6_addr mask;
12356 +};
12357 +
12358 +
12359 +#ifdef __KERNEL__
12360 +extern int vc_net_create(uint32_t, void __user *);
12361 +extern int vc_net_migrate(struct nx_info *, void __user *);
12362 +
12363 +extern int vc_net_add(struct nx_info *, void __user *);
12364 +extern int vc_net_remove(struct nx_info *, void __user *);
12365 +
12366 +extern int vc_net_add_ipv4(struct nx_info *, void __user *);
12367 +extern int vc_net_remove_ipv4(struct nx_info *, void __user *);
12368 +
12369 +extern int vc_net_add_ipv6(struct nx_info *, void __user *);
12370 +extern int vc_net_remove_ipv6(struct nx_info *, void __user *);
12371 +
12372 +extern int vc_add_match_ipv4(struct nx_info *, void __user *);
12373 +extern int vc_get_match_ipv4(struct nx_info *, void __user *);
12374 +
12375 +extern int vc_add_match_ipv6(struct nx_info *, void __user *);
12376 +extern int vc_get_match_ipv6(struct nx_info *, void __user *);
12377 +
12378 +#endif /* __KERNEL__ */
12379 +
12380 +
12381 +/* flag commands */
12382 +
12383 +#define VCMD_get_nflags                VC_CMD(FLAGS, 5, 0)
12384 +#define VCMD_set_nflags                VC_CMD(FLAGS, 6, 0)
12385 +
12386 +struct vcmd_net_flags_v0 {
12387 +       uint64_t flagword;
12388 +       uint64_t mask;
12389 +};
12390 +
12391 +#ifdef __KERNEL__
12392 +extern int vc_get_nflags(struct nx_info *, void __user *);
12393 +extern int vc_set_nflags(struct nx_info *, void __user *);
12394 +
12395 +#endif /* __KERNEL__ */
12396 +
12397 +
12398 +/* network caps commands */
12399 +
12400 +#define VCMD_get_ncaps         VC_CMD(FLAGS, 7, 0)
12401 +#define VCMD_set_ncaps         VC_CMD(FLAGS, 8, 0)
12402 +
12403 +struct vcmd_net_caps_v0 {
12404 +       uint64_t ncaps;
12405 +       uint64_t cmask;
12406 +};
12407 +
12408 +#ifdef __KERNEL__
12409 +extern int vc_get_ncaps(struct nx_info *, void __user *);
12410 +extern int vc_set_ncaps(struct nx_info *, void __user *);
12411 +
12412 +#endif /* __KERNEL__ */
12413 +#endif /* _VX_CONTEXT_CMD_H */
12414 diff -NurpP --minimal linux-2.6.29.1/include/linux/vserver/network.h linux-2.6.29.1-vs2.3.0.36.9-pre5/include/linux/vserver/network.h
12415 --- linux-2.6.29.1/include/linux/vserver/network.h      1970-01-01 01:00:00.000000000 +0100
12416 +++ linux-2.6.29.1-vs2.3.0.36.9-pre5/include/linux/vserver/network.h    2009-02-22 22:54:26.000000000 +0100
12417 @@ -0,0 +1,146 @@
12418 +#ifndef _VX_NETWORK_H
12419 +#define _VX_NETWORK_H
12420 +
12421 +#include <linux/types.h>
12422 +
12423 +
12424 +#define MAX_N_CONTEXT  65535   /* Arbitrary limit */
12425 +
12426 +
12427 +/* network flags */
12428 +
12429 +#define NXF_INFO_PRIVATE       0x00000008
12430 +
12431 +#define NXF_SINGLE_IP          0x00000100
12432 +#define NXF_LBACK_REMAP                0x00000200
12433 +#define NXF_LBACK_ALLOW                0x00000400
12434 +
12435 +#define NXF_HIDE_NETIF         0x02000000
12436 +#define NXF_HIDE_LBACK         0x04000000
12437 +
12438 +#define NXF_STATE_SETUP                (1ULL << 32)
12439 +#define NXF_STATE_ADMIN                (1ULL << 34)
12440 +
12441 +#define NXF_SC_HELPER          (1ULL << 36)
12442 +#define NXF_PERSISTENT         (1ULL << 38)
12443 +
12444 +#define NXF_ONE_TIME           (0x0005ULL << 32)
12445 +
12446 +
12447 +#define        NXF_INIT_SET            (__nxf_init_set())
12448 +
12449 +static inline uint64_t __nxf_init_set(void) {
12450 +       return    NXF_STATE_ADMIN
12451 +#ifdef CONFIG_VSERVER_AUTO_LBACK
12452 +               | NXF_LBACK_REMAP
12453 +               | NXF_HIDE_LBACK
12454 +#endif
12455 +#ifdef CONFIG_VSERVER_AUTO_SINGLE
12456 +               | NXF_SINGLE_IP
12457 +#endif
12458 +               | NXF_HIDE_NETIF;
12459 +}
12460 +
12461 +
12462 +/* network caps */
12463 +
12464 +#define NXC_TUN_CREATE         0x00000001
12465 +
12466 +#define NXC_RAW_ICMP           0x00000100
12467 +
12468 +
12469 +/* address types */
12470 +
12471 +#define NXA_TYPE_IPV4          0x0001
12472 +#define NXA_TYPE_IPV6          0x0002
12473 +
12474 +#define NXA_TYPE_NONE          0x0000
12475 +#define NXA_TYPE_ANY           0x00FF
12476 +
12477 +#define NXA_TYPE_ADDR          0x0010
12478 +#define NXA_TYPE_MASK          0x0020
12479 +#define NXA_TYPE_RANGE         0x0040
12480 +
12481 +#define NXA_MASK_ALL           (NXA_TYPE_ADDR | NXA_TYPE_MASK | NXA_TYPE_RANGE)
12482 +
12483 +#define NXA_MOD_BCAST          0x0100
12484 +#define NXA_MOD_LBACK          0x0200
12485 +
12486 +#define NXA_LOOPBACK           0x1000
12487 +
12488 +#define NXA_MASK_BIND          (NXA_MASK_ALL | NXA_MOD_BCAST | NXA_MOD_LBACK)
12489 +#define NXA_MASK_SHOW          (NXA_MASK_ALL | NXA_LOOPBACK)
12490 +
12491 +#ifdef __KERNEL__
12492 +
12493 +#include <linux/list.h>
12494 +#include <linux/spinlock.h>
12495 +#include <linux/rcupdate.h>
12496 +#include <linux/in.h>
12497 +#include <linux/in6.h>
12498 +#include <asm/atomic.h>
12499 +
12500 +struct nx_addr_v4 {
12501 +       struct nx_addr_v4 *next;
12502 +       struct in_addr ip[2];
12503 +       struct in_addr mask;
12504 +       uint16_t type;
12505 +       uint16_t flags;
12506 +};
12507 +
12508 +struct nx_addr_v6 {
12509 +       struct nx_addr_v6 *next;
12510 +       struct in6_addr ip;
12511 +       struct in6_addr mask;
12512 +       uint32_t prefix;
12513 +       uint16_t type;
12514 +       uint16_t flags;
12515 +};
12516 +
12517 +struct nx_info {
12518 +       struct hlist_node nx_hlist;     /* linked list of nxinfos */
12519 +       nid_t nx_id;                    /* vnet id */
12520 +       atomic_t nx_usecnt;             /* usage count */
12521 +       atomic_t nx_tasks;              /* tasks count */
12522 +       int nx_state;                   /* context state */
12523 +
12524 +       uint64_t nx_flags;              /* network flag word */
12525 +       uint64_t nx_ncaps;              /* network capabilities */
12526 +
12527 +       struct in_addr v4_lback;        /* Loopback address */
12528 +       struct in_addr v4_bcast;        /* Broadcast address */
12529 +       struct nx_addr_v4 v4;           /* First/Single ipv4 address */
12530 +#ifdef CONFIG_IPV6
12531 +       struct nx_addr_v6 v6;           /* First/Single ipv6 address */
12532 +#endif
12533 +       char nx_name[65];               /* network context name */
12534 +};
12535 +
12536 +
12537 +/* status flags */
12538 +
12539 +#define NXS_HASHED      0x0001
12540 +#define NXS_SHUTDOWN    0x0100
12541 +#define NXS_RELEASED    0x8000
12542 +
12543 +extern struct nx_info *lookup_nx_info(int);
12544 +
12545 +extern int get_nid_list(int, unsigned int *, int);
12546 +extern int nid_is_hashed(nid_t);
12547 +
12548 +extern int nx_migrate_task(struct task_struct *, struct nx_info *);
12549 +
12550 +extern long vs_net_change(struct nx_info *, unsigned int);
12551 +
12552 +struct sock;
12553 +
12554 +
12555 +#define NX_IPV4(n)     ((n)->v4.type != NXA_TYPE_NONE)
12556 +#ifdef  CONFIG_IPV6
12557 +#define NX_IPV6(n)     ((n)->v6.type != NXA_TYPE_NONE)
12558 +#else
12559 +#define NX_IPV6(n)     (0)
12560 +#endif
12561 +
12562 +#endif /* __KERNEL__ */
12563 +#endif /* _VX_NETWORK_H */
12564 diff -NurpP --minimal linux-2.6.29.1/include/linux/vserver/percpu.h linux-2.6.29.1-vs2.3.0.36.9-pre5/include/linux/vserver/percpu.h
12565 --- linux-2.6.29.1/include/linux/vserver/percpu.h       1970-01-01 01:00:00.000000000 +0100
12566 +++ linux-2.6.29.1-vs2.3.0.36.9-pre5/include/linux/vserver/percpu.h     2009-02-22 22:54:26.000000000 +0100
12567 @@ -0,0 +1,14 @@
12568 +#ifndef _VX_PERCPU_H
12569 +#define _VX_PERCPU_H
12570 +
12571 +#include "cvirt_def.h"
12572 +#include "sched_def.h"
12573 +
12574 +struct _vx_percpu {
12575 +       struct _vx_cvirt_pc cvirt;
12576 +       struct _vx_sched_pc sched;
12577 +};
12578 +
12579 +#define        PERCPU_PERCTX   (sizeof(struct _vx_percpu))
12580 +
12581 +#endif /* _VX_PERCPU_H */
12582 diff -NurpP --minimal linux-2.6.29.1/include/linux/vserver/pid.h linux-2.6.29.1-vs2.3.0.36.9-pre5/include/linux/vserver/pid.h
12583 --- linux-2.6.29.1/include/linux/vserver/pid.h  1970-01-01 01:00:00.000000000 +0100
12584 +++ linux-2.6.29.1-vs2.3.0.36.9-pre5/include/linux/vserver/pid.h        2009-02-22 22:54:26.000000000 +0100
12585 @@ -0,0 +1,51 @@
12586 +#ifndef _VSERVER_PID_H
12587 +#define _VSERVER_PID_H
12588 +
12589 +/* pid faking stuff */
12590 +
12591 +#define vx_info_map_pid(v, p) \
12592 +       __vx_info_map_pid((v), (p), __func__, __FILE__, __LINE__)
12593 +#define vx_info_map_tgid(v,p)  vx_info_map_pid(v,p)
12594 +#define vx_map_pid(p) vx_info_map_pid(current->vx_info, p)
12595 +#define vx_map_tgid(p) vx_map_pid(p)
12596 +
12597 +static inline int __vx_info_map_pid(struct vx_info *vxi, int pid,
12598 +       const char *func, const char *file, int line)
12599 +{
12600 +       if (vx_info_flags(vxi, VXF_INFO_INIT, 0)) {
12601 +               vxfprintk(VXD_CBIT(cvirt, 2),
12602 +                       "vx_map_tgid: %p/%llx: %d -> %d",
12603 +                       vxi, (long long)vxi->vx_flags, pid,
12604 +                       (pid && pid == vxi->vx_initpid) ? 1 : pid,
12605 +                       func, file, line);
12606 +               if (pid == 0)
12607 +                       return 0;
12608 +               if (pid == vxi->vx_initpid)
12609 +                       return 1;
12610 +       }
12611 +       return pid;
12612 +}
12613 +
12614 +#define vx_info_rmap_pid(v, p) \
12615 +       __vx_info_rmap_pid((v), (p), __func__, __FILE__, __LINE__)
12616 +#define vx_rmap_pid(p) vx_info_rmap_pid(current->vx_info, p)
12617 +#define vx_rmap_tgid(p) vx_rmap_pid(p)
12618 +
12619 +static inline int __vx_info_rmap_pid(struct vx_info *vxi, int pid,
12620 +       const char *func, const char *file, int line)
12621 +{
12622 +       if (vx_info_flags(vxi, VXF_INFO_INIT, 0)) {
12623 +               vxfprintk(VXD_CBIT(cvirt, 2),
12624 +                       "vx_rmap_tgid: %p/%llx: %d -> %d",
12625 +                       vxi, (long long)vxi->vx_flags, pid,
12626 +                       (pid == 1) ? vxi->vx_initpid : pid,
12627 +                       func, file, line);
12628 +               if ((pid == 1) && vxi->vx_initpid)
12629 +                       return vxi->vx_initpid;
12630 +               if (pid == vxi->vx_initpid)
12631 +                       return ~0U;
12632 +       }
12633 +       return pid;
12634 +}
12635 +
12636 +#endif
12637 diff -NurpP --minimal linux-2.6.29.1/include/linux/vserver/sched_cmd.h linux-2.6.29.1-vs2.3.0.36.9-pre5/include/linux/vserver/sched_cmd.h
12638 --- linux-2.6.29.1/include/linux/vserver/sched_cmd.h    1970-01-01 01:00:00.000000000 +0100
12639 +++ linux-2.6.29.1-vs2.3.0.36.9-pre5/include/linux/vserver/sched_cmd.h  2009-02-22 22:54:26.000000000 +0100
12640 @@ -0,0 +1,108 @@
12641 +#ifndef _VX_SCHED_CMD_H
12642 +#define _VX_SCHED_CMD_H
12643 +
12644 +
12645 +/*  sched vserver commands */
12646 +
12647 +#define VCMD_set_sched_v2      VC_CMD(SCHED, 1, 2)
12648 +#define VCMD_set_sched_v3      VC_CMD(SCHED, 1, 3)
12649 +#define VCMD_set_sched_v4      VC_CMD(SCHED, 1, 4)
12650 +
12651 +struct vcmd_set_sched_v2 {
12652 +       int32_t fill_rate;
12653 +       int32_t interval;
12654 +       int32_t tokens;
12655 +       int32_t tokens_min;
12656 +       int32_t tokens_max;
12657 +       uint64_t cpu_mask;
12658 +};
12659 +
12660 +struct vcmd_set_sched_v3 {
12661 +       uint32_t set_mask;
12662 +       int32_t fill_rate;
12663 +       int32_t interval;
12664 +       int32_t tokens;
12665 +       int32_t tokens_min;
12666 +       int32_t tokens_max;
12667 +       int32_t priority_bias;
12668 +};
12669 +
12670 +struct vcmd_set_sched_v4 {
12671 +       uint32_t set_mask;
12672 +       int32_t fill_rate;
12673 +       int32_t interval;
12674 +       int32_t tokens;
12675 +       int32_t tokens_min;
12676 +       int32_t tokens_max;
12677 +       int32_t prio_bias;
12678 +       int32_t cpu_id;
12679 +       int32_t bucket_id;
12680 +};
12681 +
12682 +#define VCMD_set_sched         VC_CMD(SCHED, 1, 5)
12683 +#define VCMD_get_sched         VC_CMD(SCHED, 2, 5)
12684 +
12685 +struct vcmd_sched_v5 {
12686 +       uint32_t mask;
12687 +       int32_t cpu_id;
12688 +       int32_t bucket_id;
12689 +       int32_t fill_rate[2];
12690 +       int32_t interval[2];
12691 +       int32_t tokens;
12692 +       int32_t tokens_min;
12693 +       int32_t tokens_max;
12694 +       int32_t prio_bias;
12695 +};
12696 +
12697 +#define VXSM_FILL_RATE         0x0001
12698 +#define VXSM_INTERVAL          0x0002
12699 +#define VXSM_FILL_RATE2                0x0004
12700 +#define VXSM_INTERVAL2         0x0008
12701 +#define VXSM_TOKENS            0x0010
12702 +#define VXSM_TOKENS_MIN                0x0020
12703 +#define VXSM_TOKENS_MAX                0x0040
12704 +#define VXSM_PRIO_BIAS         0x0100
12705 +
12706 +#define VXSM_IDLE_TIME         0x0200
12707 +#define VXSM_FORCE             0x0400
12708 +
12709 +#define        VXSM_V3_MASK            0x0173
12710 +#define        VXSM_SET_MASK           0x01FF
12711 +
12712 +#define VXSM_CPU_ID            0x1000
12713 +#define VXSM_BUCKET_ID         0x2000
12714 +
12715 +#define VXSM_MSEC              0x4000
12716 +
12717 +#define SCHED_KEEP             (-2)    /* only for v2 */
12718 +
12719 +#ifdef __KERNEL__
12720 +
12721 +#include <linux/compiler.h>
12722 +
12723 +extern int vc_set_sched_v2(struct vx_info *, void __user *);
12724 +extern int vc_set_sched_v3(struct vx_info *, void __user *);
12725 +extern int vc_set_sched_v4(struct vx_info *, void __user *);
12726 +extern int vc_set_sched(struct vx_info *, void __user *);
12727 +extern int vc_get_sched(struct vx_info *, void __user *);
12728 +
12729 +#endif /* __KERNEL__ */
12730 +
12731 +#define VCMD_sched_info                VC_CMD(SCHED, 3, 0)
12732 +
12733 +struct vcmd_sched_info {
12734 +       int32_t cpu_id;
12735 +       int32_t bucket_id;
12736 +       uint64_t user_msec;
12737 +       uint64_t sys_msec;
12738 +       uint64_t hold_msec;
12739 +       uint32_t token_usec;
12740 +       int32_t vavavoom;
12741 +};
12742 +
12743 +#ifdef __KERNEL__
12744 +
12745 +extern int vc_sched_info(struct vx_info *, void __user *);
12746 +
12747 +#endif /* __KERNEL__ */
12748 +#endif /* _VX_SCHED_CMD_H */
12749 diff -NurpP --minimal linux-2.6.29.1/include/linux/vserver/sched_def.h linux-2.6.29.1-vs2.3.0.36.9-pre5/include/linux/vserver/sched_def.h
12750 --- linux-2.6.29.1/include/linux/vserver/sched_def.h    1970-01-01 01:00:00.000000000 +0100
12751 +++ linux-2.6.29.1-vs2.3.0.36.9-pre5/include/linux/vserver/sched_def.h  2009-02-22 22:54:26.000000000 +0100
12752 @@ -0,0 +1,68 @@
12753 +#ifndef _VX_SCHED_DEF_H
12754 +#define _VX_SCHED_DEF_H
12755 +
12756 +#include <linux/spinlock.h>
12757 +#include <linux/jiffies.h>
12758 +#include <linux/cpumask.h>
12759 +#include <asm/atomic.h>
12760 +#include <asm/param.h>
12761 +
12762 +
12763 +/* context sub struct */
12764 +
12765 +struct _vx_sched {
12766 +       spinlock_t tokens_lock;         /* lock for token bucket */
12767 +
12768 +       int tokens;                     /* number of CPU tokens */
12769 +       int fill_rate[2];               /* Fill rate: add X tokens... */
12770 +       int interval[2];                /* Divisor:   per Y jiffies   */
12771 +       int tokens_min;                 /* Limit:     minimum for unhold */
12772 +       int tokens_max;                 /* Limit:     no more than N tokens */
12773 +
12774 +       int prio_bias;                  /* bias offset for priority */
12775 +
12776 +       unsigned update_mask;           /* which features should be updated */
12777 +       cpumask_t update;               /* CPUs which should update */
12778 +};
12779 +
12780 +struct _vx_sched_pc {
12781 +       int tokens;                     /* number of CPU tokens */
12782 +       int flags;                      /* bucket flags */
12783 +
12784 +       int fill_rate[2];               /* Fill rate: add X tokens... */
12785 +       int interval[2];                /* Divisor:   per Y jiffies   */
12786 +       int tokens_min;                 /* Limit:     minimum for unhold */
12787 +       int tokens_max;                 /* Limit:     no more than N tokens */
12788 +
12789 +       int prio_bias;                  /* bias offset for priority */
12790 +       int vavavoom;                   /* last calculated vavavoom */
12791 +
12792 +       unsigned long norm_time;        /* last time accounted */
12793 +       unsigned long idle_time;        /* non linear time for fair sched */
12794 +       unsigned long token_time;       /* token time for accounting */
12795 +       unsigned long onhold;           /* jiffies when put on hold */
12796 +
12797 +       uint64_t user_ticks;            /* token tick events */
12798 +       uint64_t sys_ticks;             /* token tick events */
12799 +       uint64_t hold_ticks;            /* token ticks paused */
12800 +};
12801 +
12802 +
12803 +#define VXSF_ONHOLD    0x0001
12804 +#define VXSF_IDLE_TIME 0x0100
12805 +
12806 +#ifdef CONFIG_VSERVER_DEBUG
12807 +
12808 +static inline void __dump_vx_sched(struct _vx_sched *sched)
12809 +{
12810 +       printk("\t_vx_sched:\n");
12811 +       printk("\t tokens: %4d/%4d, %4d/%4d, %4d, %4d\n",
12812 +               sched->fill_rate[0], sched->interval[0],
12813 +               sched->fill_rate[1], sched->interval[1],
12814 +               sched->tokens_min, sched->tokens_max);
12815 +       printk("\t priority = %4d\n", sched->prio_bias);
12816 +}
12817 +
12818 +#endif
12819 +
12820 +#endif /* _VX_SCHED_DEF_H */
12821 diff -NurpP --minimal linux-2.6.29.1/include/linux/vserver/sched.h linux-2.6.29.1-vs2.3.0.36.9-pre5/include/linux/vserver/sched.h
12822 --- linux-2.6.29.1/include/linux/vserver/sched.h        1970-01-01 01:00:00.000000000 +0100
12823 +++ linux-2.6.29.1-vs2.3.0.36.9-pre5/include/linux/vserver/sched.h      2009-02-22 22:54:26.000000000 +0100
12824 @@ -0,0 +1,26 @@
12825 +#ifndef _VX_SCHED_H
12826 +#define _VX_SCHED_H
12827 +
12828 +
12829 +#ifdef __KERNEL__
12830 +
12831 +struct timespec;
12832 +
12833 +void vx_vsi_uptime(struct timespec *, struct timespec *);
12834 +
12835 +
12836 +struct vx_info;
12837 +
12838 +void vx_update_load(struct vx_info *);
12839 +
12840 +
12841 +int vx_tokens_recalc(struct _vx_sched_pc *,
12842 +       unsigned long *, unsigned long *, int [2]);
12843 +
12844 +void vx_update_sched_param(struct _vx_sched *sched,
12845 +       struct _vx_sched_pc *sched_pc);
12846 +
12847 +#endif /* __KERNEL__ */
12848 +#else  /* _VX_SCHED_H */
12849 +#warning duplicate inclusion
12850 +#endif /* _VX_SCHED_H */
12851 diff -NurpP --minimal linux-2.6.29.1/include/linux/vserver/signal_cmd.h linux-2.6.29.1-vs2.3.0.36.9-pre5/include/linux/vserver/signal_cmd.h
12852 --- linux-2.6.29.1/include/linux/vserver/signal_cmd.h   1970-01-01 01:00:00.000000000 +0100
12853 +++ linux-2.6.29.1-vs2.3.0.36.9-pre5/include/linux/vserver/signal_cmd.h 2009-02-22 22:54:26.000000000 +0100
12854 @@ -0,0 +1,43 @@
12855 +#ifndef _VX_SIGNAL_CMD_H
12856 +#define _VX_SIGNAL_CMD_H
12857 +
12858 +
12859 +/*  signalling vserver commands */
12860 +
12861 +#define VCMD_ctx_kill          VC_CMD(PROCTRL, 1, 0)
12862 +#define VCMD_wait_exit         VC_CMD(EVENT, 99, 0)
12863 +
12864 +struct vcmd_ctx_kill_v0 {
12865 +       int32_t pid;
12866 +       int32_t sig;
12867 +};
12868 +
12869 +struct vcmd_wait_exit_v0 {
12870 +       int32_t reboot_cmd;
12871 +       int32_t exit_code;
12872 +};
12873 +
12874 +#ifdef __KERNEL__
12875 +
12876 +extern int vc_ctx_kill(struct vx_info *, void __user *);
12877 +extern int vc_wait_exit(struct vx_info *, void __user *);
12878 +
12879 +#endif /* __KERNEL__ */
12880 +
12881 +/*  process alteration commands */
12882 +
12883 +#define VCMD_get_pflags                VC_CMD(PROCALT, 5, 0)
12884 +#define VCMD_set_pflags                VC_CMD(PROCALT, 6, 0)
12885 +
12886 +struct vcmd_pflags_v0 {
12887 +       uint32_t flagword;
12888 +       uint32_t mask;
12889 +};
12890 +
12891 +#ifdef __KERNEL__
12892 +
12893 +extern int vc_get_pflags(uint32_t pid, void __user *);
12894 +extern int vc_set_pflags(uint32_t pid, void __user *);
12895 +
12896 +#endif /* __KERNEL__ */
12897 +#endif /* _VX_SIGNAL_CMD_H */
12898 diff -NurpP --minimal linux-2.6.29.1/include/linux/vserver/signal.h linux-2.6.29.1-vs2.3.0.36.9-pre5/include/linux/vserver/signal.h
12899 --- linux-2.6.29.1/include/linux/vserver/signal.h       1970-01-01 01:00:00.000000000 +0100
12900 +++ linux-2.6.29.1-vs2.3.0.36.9-pre5/include/linux/vserver/signal.h     2009-02-22 22:54:26.000000000 +0100
12901 @@ -0,0 +1,14 @@
12902 +#ifndef _VX_SIGNAL_H
12903 +#define _VX_SIGNAL_H
12904 +
12905 +
12906 +#ifdef __KERNEL__
12907 +
12908 +struct vx_info;
12909 +
12910 +int vx_info_kill(struct vx_info *, int, int);
12911 +
12912 +#endif /* __KERNEL__ */
12913 +#else  /* _VX_SIGNAL_H */
12914 +#warning duplicate inclusion
12915 +#endif /* _VX_SIGNAL_H */
12916 diff -NurpP --minimal linux-2.6.29.1/include/linux/vserver/space_cmd.h linux-2.6.29.1-vs2.3.0.36.9-pre5/include/linux/vserver/space_cmd.h
12917 --- linux-2.6.29.1/include/linux/vserver/space_cmd.h    1970-01-01 01:00:00.000000000 +0100
12918 +++ linux-2.6.29.1-vs2.3.0.36.9-pre5/include/linux/vserver/space_cmd.h  2009-02-22 22:54:26.000000000 +0100
12919 @@ -0,0 +1,38 @@
12920 +#ifndef _VX_SPACE_CMD_H
12921 +#define _VX_SPACE_CMD_H
12922 +
12923 +
12924 +#define VCMD_enter_space_v0    VC_CMD(PROCALT, 1, 0)
12925 +#define VCMD_enter_space_v1    VC_CMD(PROCALT, 1, 1)
12926 +#define VCMD_enter_space       VC_CMD(PROCALT, 1, 2)
12927 +
12928 +#define VCMD_set_space_v0      VC_CMD(PROCALT, 3, 0)
12929 +#define VCMD_set_space_v1      VC_CMD(PROCALT, 3, 1)
12930 +#define VCMD_set_space         VC_CMD(PROCALT, 3, 2)
12931 +
12932 +#define VCMD_get_space_mask_v0 VC_CMD(PROCALT, 4, 0)
12933 +
12934 +#define VCMD_get_space_mask    VC_CMD(VSPACE, 0, 1)
12935 +#define VCMD_get_space_default VC_CMD(VSPACE, 1, 0)
12936 +
12937 +
12938 +struct vcmd_space_mask_v1 {
12939 +       uint64_t mask;
12940 +};
12941 +
12942 +struct vcmd_space_mask_v2 {
12943 +       uint64_t mask;
12944 +       uint32_t index;
12945 +};
12946 +
12947 +
12948 +#ifdef __KERNEL__
12949 +
12950 +extern int vc_enter_space_v1(struct vx_info *, void __user *);
12951 +extern int vc_set_space_v1(struct vx_info *, void __user *);
12952 +extern int vc_enter_space(struct vx_info *, void __user *);
12953 +extern int vc_set_space(struct vx_info *, void __user *);
12954 +extern int vc_get_space_mask(void __user *, int);
12955 +
12956 +#endif /* __KERNEL__ */
12957 +#endif /* _VX_SPACE_CMD_H */
12958 diff -NurpP --minimal linux-2.6.29.1/include/linux/vserver/space.h linux-2.6.29.1-vs2.3.0.36.9-pre5/include/linux/vserver/space.h
12959 --- linux-2.6.29.1/include/linux/vserver/space.h        1970-01-01 01:00:00.000000000 +0100
12960 +++ linux-2.6.29.1-vs2.3.0.36.9-pre5/include/linux/vserver/space.h      2009-02-22 22:54:26.000000000 +0100
12961 @@ -0,0 +1,12 @@
12962 +#ifndef _VX_SPACE_H
12963 +#define _VX_SPACE_H
12964 +
12965 +#include <linux/types.h>
12966 +
12967 +struct vx_info;
12968 +
12969 +int vx_set_space(struct vx_info *vxi, unsigned long mask, unsigned index);
12970 +
12971 +#else  /* _VX_SPACE_H */
12972 +#warning duplicate inclusion
12973 +#endif /* _VX_SPACE_H */
12974 diff -NurpP --minimal linux-2.6.29.1/include/linux/vserver/switch.h linux-2.6.29.1-vs2.3.0.36.9-pre5/include/linux/vserver/switch.h
12975 --- linux-2.6.29.1/include/linux/vserver/switch.h       1970-01-01 01:00:00.000000000 +0100
12976 +++ linux-2.6.29.1-vs2.3.0.36.9-pre5/include/linux/vserver/switch.h     2009-02-22 22:54:26.000000000 +0100
12977 @@ -0,0 +1,98 @@
12978 +#ifndef _VX_SWITCH_H
12979 +#define _VX_SWITCH_H
12980 +
12981 +#include <linux/types.h>
12982 +
12983 +
12984 +#define VC_CATEGORY(c)         (((c) >> 24) & 0x3F)
12985 +#define VC_COMMAND(c)          (((c) >> 16) & 0xFF)
12986 +#define VC_VERSION(c)          ((c) & 0xFFF)
12987 +
12988 +#define VC_CMD(c, i, v)                ((((VC_CAT_ ## c) & 0x3F) << 24) \
12989 +                               | (((i) & 0xFF) << 16) | ((v) & 0xFFF))
12990 +
12991 +/*
12992 +
12993 +  Syscall Matrix V2.8
12994 +
12995 +        |VERSION|CREATE |MODIFY |MIGRATE|CONTROL|EXPERIM| |SPECIAL|SPECIAL|
12996 +        |STATS  |DESTROY|ALTER  |CHANGE |LIMIT  |TEST   | |       |       |
12997 +        |INFO   |SETUP  |       |MOVE   |       |       | |       |       |
12998 +  -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
12999 +  SYSTEM |VERSION|VSETUP |VHOST  |       |       |       | |DEVICE |       |
13000 +  HOST   |     00|     01|     02|     03|     04|     05| |     06|     07|
13001 +  -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
13002 +  CPU    |       |VPROC  |PROCALT|PROCMIG|PROCTRL|       | |SCHED. |       |
13003 +  PROCESS|     08|     09|     10|     11|     12|     13| |     14|     15|
13004 +  -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
13005 +  MEMORY |       |       |       |       |MEMCTRL|       | |SWAP   |       |
13006 +        |     16|     17|     18|     19|     20|     21| |     22|     23|
13007 +  -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
13008 +  NETWORK|       |VNET   |NETALT |NETMIG |NETCTL |       | |SERIAL |       |
13009 +        |     24|     25|     26|     27|     28|     29| |     30|     31|
13010 +  -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
13011 +  DISK   |       |       |       |TAGMIG |DLIMIT |       | |INODE  |       |
13012 +  VFS    |     32|     33|     34|     35|     36|     37| |     38|     39|
13013 +  -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
13014 +  OTHER  |VSTAT  |       |       |       |       |       | |VINFO  |       |
13015 +        |     40|     41|     42|     43|     44|     45| |     46|     47|
13016 +  =======+=======+=======+=======+=======+=======+=======+ +=======+=======+
13017 +  SPECIAL|EVENT  |       |       |       |FLAGS  |       | |VSPACE |       |
13018 +        |     48|     49|     50|     51|     52|     53| |     54|     55|
13019 +  -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
13020 +  SPECIAL|DEBUG  |       |       |       |RLIMIT |SYSCALL| |       |COMPAT |
13021 +        |     56|     57|     58|     59|     60|TEST 61| |     62|     63|
13022 +  -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
13023 +
13024 +*/
13025 +
13026 +#define VC_CAT_VERSION         0
13027 +
13028 +#define VC_CAT_VSETUP          1
13029 +#define VC_CAT_VHOST           2
13030 +
13031 +#define VC_CAT_DEVICE          6
13032 +
13033 +#define VC_CAT_VPROC           9
13034 +#define VC_CAT_PROCALT         10
13035 +#define VC_CAT_PROCMIG         11
13036 +#define VC_CAT_PROCTRL         12
13037 +
13038 +#define VC_CAT_SCHED           14
13039 +#define VC_CAT_MEMCTRL         20
13040 +
13041 +#define VC_CAT_VNET            25
13042 +#define VC_CAT_NETALT          26
13043 +#define VC_CAT_NETMIG          27
13044 +#define VC_CAT_NETCTRL         28
13045 +
13046 +#define VC_CAT_TAGMIG          35
13047 +#define VC_CAT_DLIMIT          36
13048 +#define VC_CAT_INODE           38
13049 +
13050 +#define VC_CAT_VSTAT           40
13051 +#define VC_CAT_VINFO           46
13052 +#define VC_CAT_EVENT           48
13053 +
13054 +#define VC_CAT_FLAGS           52
13055 +#define VC_CAT_VSPACE          54
13056 +#define VC_CAT_DEBUG           56
13057 +#define VC_CAT_RLIMIT          60
13058 +
13059 +#define VC_CAT_SYSTEST         61
13060 +#define VC_CAT_COMPAT          63
13061 +
13062 +/*  query version */
13063 +
13064 +#define VCMD_get_version       VC_CMD(VERSION, 0, 0)
13065 +#define VCMD_get_vci           VC_CMD(VERSION, 1, 0)
13066 +
13067 +
13068 +#ifdef __KERNEL__
13069 +
13070 +#include <linux/errno.h>
13071 +
13072 +#endif /* __KERNEL__ */
13073 +
13074 +#endif /* _VX_SWITCH_H */
13075 +
13076 diff -NurpP --minimal linux-2.6.29.1/include/linux/vserver/tag_cmd.h linux-2.6.29.1-vs2.3.0.36.9-pre5/include/linux/vserver/tag_cmd.h
13077 --- linux-2.6.29.1/include/linux/vserver/tag_cmd.h      1970-01-01 01:00:00.000000000 +0100
13078 +++ linux-2.6.29.1-vs2.3.0.36.9-pre5/include/linux/vserver/tag_cmd.h    2009-02-22 22:54:26.000000000 +0100
13079 @@ -0,0 +1,22 @@
13080 +#ifndef _VX_TAG_CMD_H
13081 +#define _VX_TAG_CMD_H
13082 +
13083 +
13084 +/* vinfo commands */
13085 +
13086 +#define VCMD_task_tag          VC_CMD(VINFO, 3, 0)
13087 +
13088 +#ifdef __KERNEL__
13089 +extern int vc_task_tag(uint32_t);
13090 +
13091 +#endif /* __KERNEL__ */
13092 +
13093 +/* context commands */
13094 +
13095 +#define VCMD_tag_migrate       VC_CMD(TAGMIG, 1, 0)
13096 +
13097 +#ifdef __KERNEL__
13098 +extern int vc_tag_migrate(uint32_t);
13099 +
13100 +#endif /* __KERNEL__ */
13101 +#endif /* _VX_TAG_CMD_H */
13102 diff -NurpP --minimal linux-2.6.29.1/include/linux/vserver/tag.h linux-2.6.29.1-vs2.3.0.36.9-pre5/include/linux/vserver/tag.h
13103 --- linux-2.6.29.1/include/linux/vserver/tag.h  1970-01-01 01:00:00.000000000 +0100
13104 +++ linux-2.6.29.1-vs2.3.0.36.9-pre5/include/linux/vserver/tag.h        2009-02-22 22:54:26.000000000 +0100
13105 @@ -0,0 +1,143 @@
13106 +#ifndef _DX_TAG_H
13107 +#define _DX_TAG_H
13108 +
13109 +#include <linux/types.h>
13110 +
13111 +
13112 +#define DX_TAG(in)     (IS_TAGGED(in))
13113 +
13114 +
13115 +#ifdef CONFIG_TAG_NFSD
13116 +#define DX_TAG_NFSD    1
13117 +#else
13118 +#define DX_TAG_NFSD    0
13119 +#endif
13120 +
13121 +
13122 +#ifdef CONFIG_TAGGING_NONE
13123 +
13124 +#define MAX_UID                0xFFFFFFFF
13125 +#define MAX_GID                0xFFFFFFFF
13126 +
13127 +#define INOTAG_TAG(cond, uid, gid, tag)        (0)
13128 +
13129 +#define TAGINO_UID(cond, uid, tag)     (uid)
13130 +#define TAGINO_GID(cond, gid, tag)     (gid)
13131 +
13132 +#endif
13133 +
13134 +
13135 +#ifdef CONFIG_TAGGING_GID16
13136 +
13137 +#define MAX_UID                0xFFFFFFFF
13138 +#define MAX_GID                0x0000FFFF
13139 +
13140 +#define INOTAG_TAG(cond, uid, gid, tag)        \
13141 +       ((cond) ? (((gid) >> 16) & 0xFFFF) : 0)
13142 +
13143 +#define TAGINO_UID(cond, uid, tag)     (uid)
13144 +#define TAGINO_GID(cond, gid, tag)     \
13145 +       ((cond) ? (((gid) & 0xFFFF) | ((tag) << 16)) : (gid))
13146 +
13147 +#endif
13148 +
13149 +
13150 +#ifdef CONFIG_TAGGING_ID24
13151 +
13152 +#define MAX_UID                0x00FFFFFF
13153 +#define MAX_GID                0x00FFFFFF
13154 +
13155 +#define INOTAG_TAG(cond, uid, gid, tag)        \
13156 +       ((cond) ? ((((uid) >> 16) & 0xFF00) | (((gid) >> 24) & 0xFF)) : 0)
13157 +
13158 +#define TAGINO_UID(cond, uid, tag)     \
13159 +       ((cond) ? (((uid) & 0xFFFFFF) | (((tag) & 0xFF00) << 16)) : (uid))
13160 +#define TAGINO_GID(cond, gid, tag)     \
13161 +       ((cond) ? (((gid) & 0xFFFFFF) | (((tag) & 0x00FF) << 24)) : (gid))
13162 +
13163 +#endif
13164 +
13165 +
13166 +#ifdef CONFIG_TAGGING_UID16
13167 +
13168 +#define MAX_UID                0x0000FFFF
13169 +#define MAX_GID                0xFFFFFFFF
13170 +
13171 +#define INOTAG_TAG(cond, uid, gid, tag)        \
13172 +       ((cond) ? (((uid) >> 16) & 0xFFFF) : 0)
13173 +
13174 +#define TAGINO_UID(cond, uid, tag)     \
13175 +       ((cond) ? (((uid) & 0xFFFF) | ((tag) << 16)) : (uid))
13176 +#define TAGINO_GID(cond, gid, tag)     (gid)
13177 +
13178 +#endif
13179 +
13180 +
13181 +#ifdef CONFIG_TAGGING_INTERN
13182 +
13183 +#define MAX_UID                0xFFFFFFFF
13184 +#define MAX_GID                0xFFFFFFFF
13185 +
13186 +#define INOTAG_TAG(cond, uid, gid, tag)        \
13187 +       ((cond) ? (tag) : 0)
13188 +
13189 +#define TAGINO_UID(cond, uid, tag)     (uid)
13190 +#define TAGINO_GID(cond, gid, tag)     (gid)
13191 +
13192 +#endif
13193 +
13194 +
13195 +#ifndef CONFIG_TAGGING_NONE
13196 +#define dx_current_fstag(sb)   \
13197 +       ((sb)->s_flags & MS_TAGGED ? dx_current_tag() : 0)
13198 +#else
13199 +#define dx_current_fstag(sb)   (0)
13200 +#endif
13201 +
13202 +#ifndef CONFIG_TAGGING_INTERN
13203 +#define TAGINO_TAG(cond, tag)  (0)
13204 +#else
13205 +#define TAGINO_TAG(cond, tag)  ((cond) ? (tag) : 0)
13206 +#endif
13207 +
13208 +#define INOTAG_UID(cond, uid, gid)     \
13209 +       ((cond) ? ((uid) & MAX_UID) : (uid))
13210 +#define INOTAG_GID(cond, uid, gid)     \
13211 +       ((cond) ? ((gid) & MAX_GID) : (gid))
13212 +
13213 +
13214 +static inline uid_t dx_map_uid(uid_t uid)
13215 +{
13216 +       if ((uid > MAX_UID) && (uid != -1))
13217 +               uid = -2;
13218 +       return (uid & MAX_UID);
13219 +}
13220 +
13221 +static inline gid_t dx_map_gid(gid_t gid)
13222 +{
13223 +       if ((gid > MAX_GID) && (gid != -1))
13224 +               gid = -2;
13225 +       return (gid & MAX_GID);
13226 +}
13227 +
13228 +struct peer_tag {
13229 +       int32_t xid;
13230 +       int32_t nid;
13231 +};
13232 +
13233 +#define dx_notagcheck(sb) ((sb) && ((sb)->s_flags & MS_NOTAGCHECK))
13234 +
13235 +int dx_parse_tag(char *string, tag_t *tag, int remove, int *mnt_flags,
13236 +                unsigned long *flags);
13237 +
13238 +#ifdef CONFIG_PROPAGATE
13239 +
13240 +void __dx_propagate_tag(struct nameidata *nd, struct inode *inode);
13241 +
13242 +#define dx_propagate_tag(n, i) __dx_propagate_tag(n, i)
13243 +
13244 +#else
13245 +#define dx_propagate_tag(n, i) do { } while (0)
13246 +#endif
13247 +
13248 +#endif /* _DX_TAG_H */
13249 diff -NurpP --minimal linux-2.6.29.1/include/linux/vs_inet6.h linux-2.6.29.1-vs2.3.0.36.9-pre5/include/linux/vs_inet6.h
13250 --- linux-2.6.29.1/include/linux/vs_inet6.h     1970-01-01 01:00:00.000000000 +0100
13251 +++ linux-2.6.29.1-vs2.3.0.36.9-pre5/include/linux/vs_inet6.h   2009-03-25 00:46:50.000000000 +0100
13252 @@ -0,0 +1,246 @@
13253 +#ifndef _VS_INET6_H
13254 +#define _VS_INET6_H
13255 +
13256 +#include "vserver/base.h"
13257 +#include "vserver/network.h"
13258 +#include "vserver/debug.h"
13259 +
13260 +#include <net/ipv6.h>
13261 +
13262 +#define NXAV6(a)       &(a)->ip, &(a)->mask, (a)->prefix, (a)->type
13263 +#define NXAV6_FMT      "[%pI6/%pI6/%d:%04x]"
13264 +
13265 +
13266 +#ifdef CONFIG_IPV6
13267 +
13268 +static inline
13269 +int v6_addr_match(struct nx_addr_v6 *nxa,
13270 +       const struct in6_addr *addr, uint16_t mask)
13271 +{
13272 +       int ret = 0;
13273 +
13274 +       switch (nxa->type & mask) {
13275 +       case NXA_TYPE_MASK:
13276 +               ret = ipv6_masked_addr_cmp(&nxa->ip, &nxa->mask, addr);
13277 +               break;
13278 +       case NXA_TYPE_ADDR:
13279 +               ret = ipv6_addr_equal(&nxa->ip, addr);
13280 +               break;
13281 +       case NXA_TYPE_ANY:
13282 +               ret = 1;
13283 +               break;
13284 +       }
13285 +       vxdprintk(VXD_CBIT(net, 0),
13286 +               "v6_addr_match(%p" NXAV6_FMT ",%pI6,%04x) = %d",
13287 +               nxa, NXAV6(nxa), addr, mask, ret);
13288 +       return ret;
13289 +}
13290 +
13291 +static inline
13292 +int v6_addr_in_nx_info(struct nx_info *nxi,
13293 +       const struct in6_addr *addr, uint16_t mask)
13294 +{
13295 +       struct nx_addr_v6 *nxa;
13296 +       int ret = 1;
13297 +
13298 +       if (!nxi)
13299 +               goto out;
13300 +       for (nxa = &nxi->v6; nxa; nxa = nxa->next)
13301 +               if (v6_addr_match(nxa, addr, mask))
13302 +                       goto out;
13303 +       ret = 0;
13304 +out:
13305 +       vxdprintk(VXD_CBIT(net, 0),
13306 +               "v6_addr_in_nx_info(%p[#%u],%pI6,%04x) = %d",
13307 +               nxi, nxi ? nxi->nx_id : 0, addr, mask, ret);
13308 +       return ret;
13309 +}
13310 +
13311 +static inline
13312 +int v6_nx_addr_match(struct nx_addr_v6 *nxa, struct nx_addr_v6 *addr, uint16_t mask)
13313 +{
13314 +       /* FIXME: needs full range checks */
13315 +       return v6_addr_match(nxa, &addr->ip, mask);
13316 +}
13317 +
13318 +static inline
13319 +int v6_nx_addr_in_nx_info(struct nx_info *nxi, struct nx_addr_v6 *nxa, uint16_t mask)
13320 +{
13321 +       struct nx_addr_v6 *ptr;
13322 +
13323 +       for (ptr = &nxi->v6; ptr; ptr = ptr->next)
13324 +               if (v6_nx_addr_match(ptr, nxa, mask))
13325 +                       return 1;
13326 +       return 0;
13327 +}
13328 +
13329 +
13330 +/*
13331 + *     Check if a given address matches for a socket
13332 + *
13333 + *     nxi:            the socket's nx_info if any
13334 + *     addr:           to be verified address
13335 + */
13336 +static inline
13337 +int v6_sock_addr_match (
13338 +       struct nx_info *nxi,
13339 +       struct inet_sock *inet,
13340 +       struct in6_addr *addr)
13341 +{
13342 +       struct sock *sk = &inet->sk;
13343 +       struct in6_addr *saddr = inet6_rcv_saddr(sk);
13344 +
13345 +       if (!ipv6_addr_any(addr) &&
13346 +               ipv6_addr_equal(saddr, addr))
13347 +               return 1;
13348 +       if (ipv6_addr_any(saddr))
13349 +               return v6_addr_in_nx_info(nxi, addr, -1);
13350 +       return 0;
13351 +}
13352 +
13353 +/*
13354 + *     check if address is covered by socket
13355 + *
13356 + *     sk:     the socket to check against
13357 + *     addr:   the address in question (must be != 0)
13358 + */
13359 +
13360 +static inline
13361 +int __v6_addr_match_socket(const struct sock *sk, struct nx_addr_v6 *nxa)
13362 +{
13363 +       struct nx_info *nxi = sk->sk_nx_info;
13364 +       struct in6_addr *saddr = inet6_rcv_saddr(sk);
13365 +
13366 +       vxdprintk(VXD_CBIT(net, 5),
13367 +               "__v6_addr_in_socket(%p," NXAV6_FMT ") %p:%pI6 %p;%lx",
13368 +               sk, NXAV6(nxa), nxi, saddr, sk->sk_socket,
13369 +               (sk->sk_socket?sk->sk_socket->flags:0));
13370 +
13371 +       if (!ipv6_addr_any(saddr)) {    /* direct address match */
13372 +               return v6_addr_match(nxa, saddr, -1);
13373 +       } else if (nxi) {               /* match against nx_info */
13374 +               return v6_nx_addr_in_nx_info(nxi, nxa, -1);
13375 +       } else {                        /* unrestricted any socket */
13376 +               return 1;
13377 +       }
13378 +}
13379 +
13380 +
13381 +/* inet related checks and helpers */
13382 +
13383 +
13384 +struct in_ifaddr;
13385 +struct net_device;
13386 +struct sock;
13387 +
13388 +
13389 +#include <linux/netdevice.h>
13390 +#include <linux/inetdevice.h>
13391 +#include <net/inet_timewait_sock.h>
13392 +
13393 +
13394 +int dev_in_nx_info(struct net_device *, struct nx_info *);
13395 +int v6_dev_in_nx_info(struct net_device *, struct nx_info *);
13396 +int nx_v6_addr_conflict(struct nx_info *, struct nx_info *);
13397 +
13398 +
13399 +
13400 +static inline
13401 +int v6_ifa_in_nx_info(struct inet6_ifaddr *ifa, struct nx_info *nxi)
13402 +{
13403 +       if (!nxi)
13404 +               return 1;
13405 +       if (!ifa)
13406 +               return 0;
13407 +       return v6_addr_in_nx_info(nxi, &ifa->addr, -1);
13408 +}
13409 +
13410 +static inline
13411 +int nx_v6_ifa_visible(struct nx_info *nxi, struct inet6_ifaddr *ifa)
13412 +{
13413 +       vxdprintk(VXD_CBIT(net, 1), "nx_v6_ifa_visible(%p[#%u],%p) %d",
13414 +               nxi, nxi ? nxi->nx_id : 0, ifa,
13415 +               nxi ? v6_ifa_in_nx_info(ifa, nxi) : 0);
13416 +
13417 +       if (!nx_info_flags(nxi, NXF_HIDE_NETIF, 0))
13418 +               return 1;
13419 +       if (v6_ifa_in_nx_info(ifa, nxi))
13420 +               return 1;
13421 +       return 0;
13422 +}
13423 +
13424 +
13425 +struct nx_v6_sock_addr {
13426 +       struct in6_addr saddr;  /* Address used for validation */
13427 +       struct in6_addr baddr;  /* Address used for socket bind */
13428 +};
13429 +
13430 +static inline
13431 +int v6_map_sock_addr(struct inet_sock *inet, struct sockaddr_in6 *addr,
13432 +       struct nx_v6_sock_addr *nsa)
13433 +{
13434 +       // struct sock *sk = &inet->sk;
13435 +       // struct nx_info *nxi = sk->sk_nx_info;
13436 +       struct in6_addr saddr = addr->sin6_addr;
13437 +       struct in6_addr baddr = saddr;
13438 +
13439 +       nsa->saddr = saddr;
13440 +       nsa->baddr = baddr;
13441 +       return 0;
13442 +}
13443 +
13444 +static inline
13445 +void v6_set_sock_addr(struct inet_sock *inet, struct nx_v6_sock_addr *nsa)
13446 +{
13447 +       // struct sock *sk = &inet->sk;
13448 +       // struct in6_addr *saddr = inet6_rcv_saddr(sk);
13449 +
13450 +       // *saddr = nsa->baddr;
13451 +       // inet->saddr = nsa->baddr;
13452 +}
13453 +
13454 +static inline
13455 +int nx_info_has_v6(struct nx_info *nxi)
13456 +{
13457 +       if (!nxi)
13458 +               return 1;
13459 +       if (NX_IPV6(nxi))
13460 +               return 1;
13461 +       return 0;
13462 +}
13463 +
13464 +#else /* CONFIG_IPV6 */
13465 +
13466 +static inline
13467 +int nx_v6_dev_visible(struct nx_info *n, struct net_device *d)
13468 +{
13469 +       return 1;
13470 +}
13471 +
13472 +
13473 +static inline
13474 +int nx_v6_addr_conflict(struct nx_info *n, uint32_t a, const struct sock *s)
13475 +{
13476 +       return 1;
13477 +}
13478 +
13479 +static inline
13480 +int v6_ifa_in_nx_info(struct in_ifaddr *a, struct nx_info *n)
13481 +{
13482 +       return 1;
13483 +}
13484 +
13485 +static inline
13486 +int nx_info_has_v6(struct nx_info *nxi)
13487 +{
13488 +       return 0;
13489 +}
13490 +
13491 +#endif /* CONFIG_IPV6 */
13492 +
13493 +#define current_nx_info_has_v6() \
13494 +       nx_info_has_v6(current_nx_info())
13495 +
13496 +#else
13497 +#warning duplicate inclusion
13498 +#endif
13499 diff -NurpP --minimal linux-2.6.29.1/include/linux/vs_inet.h linux-2.6.29.1-vs2.3.0.36.9-pre5/include/linux/vs_inet.h
13500 --- linux-2.6.29.1/include/linux/vs_inet.h      1970-01-01 01:00:00.000000000 +0100
13501 +++ linux-2.6.29.1-vs2.3.0.36.9-pre5/include/linux/vs_inet.h    2009-02-22 22:54:26.000000000 +0100
13502 @@ -0,0 +1,342 @@
13503 +#ifndef _VS_INET_H
13504 +#define _VS_INET_H
13505 +
13506 +#include "vserver/base.h"
13507 +#include "vserver/network.h"
13508 +#include "vserver/debug.h"
13509 +
13510 +#define IPI_LOOPBACK   htonl(INADDR_LOOPBACK)
13511 +
13512 +#define NXAV4(a)       NIPQUAD((a)->ip[0]), NIPQUAD((a)->ip[1]), \
13513 +                       NIPQUAD((a)->mask), (a)->type
13514 +#define NXAV4_FMT      "[" NIPQUAD_FMT "-" NIPQUAD_FMT "/" NIPQUAD_FMT ":%04x]"
13515 +
13516 +
13517 +static inline
13518 +int v4_addr_match(struct nx_addr_v4 *nxa, __be32 addr, uint16_t tmask)
13519 +{
13520 +       __be32 ip = nxa->ip[0].s_addr;
13521 +       __be32 mask = nxa->mask.s_addr;
13522 +       __be32 bcast = ip | ~mask;
13523 +       int ret = 0;
13524 +
13525 +       switch (nxa->type & tmask) {
13526 +       case NXA_TYPE_MASK:
13527 +               ret = (ip == (addr & mask));
13528 +               break;
13529 +       case NXA_TYPE_ADDR:
13530 +               ret = 3;
13531 +               if (addr == ip)
13532 +                       break;
13533 +               /* fall through to broadcast */
13534 +       case NXA_MOD_BCAST:
13535 +               ret = ((tmask & NXA_MOD_BCAST) && (addr == bcast));
13536 +               break;
13537 +       case NXA_TYPE_RANGE:
13538 +               ret = ((nxa->ip[0].s_addr <= addr) &&
13539 +                       (nxa->ip[1].s_addr > addr));
13540 +               break;
13541 +       case NXA_TYPE_ANY:
13542 +               ret = 2;
13543 +               break;
13544 +       }
13545 +
13546 +       vxdprintk(VXD_CBIT(net, 0),
13547 +               "v4_addr_match(%p" NXAV4_FMT "," NIPQUAD_FMT ",%04x) = %d",
13548 +               nxa, NXAV4(nxa), NIPQUAD(addr), tmask, ret);
13549 +       return ret;
13550 +}
13551 +
13552 +static inline
13553 +int v4_addr_in_nx_info(struct nx_info *nxi, __be32 addr, uint16_t tmask)
13554 +{
13555 +       struct nx_addr_v4 *nxa;
13556 +       int ret = 1;
13557 +
13558 +       if (!nxi)
13559 +               goto out;
13560 +
13561 +       ret = 2;
13562 +       /* allow 127.0.0.1 when remapping lback */
13563 +       if ((tmask & NXA_LOOPBACK) &&
13564 +               (addr == IPI_LOOPBACK) &&
13565 +               nx_info_flags(nxi, NXF_LBACK_REMAP, 0))
13566 +               goto out;
13567 +       ret = 3;
13568 +       /* check for lback address */
13569 +       if ((tmask & NXA_MOD_LBACK) &&
13570 +               (nxi->v4_lback.s_addr == addr))
13571 +               goto out;
13572 +       ret = 4;
13573 +       /* check for broadcast address */
13574 +       if ((tmask & NXA_MOD_BCAST) &&
13575 +               (nxi->v4_bcast.s_addr == addr))
13576 +               goto out;
13577 +       ret = 5;
13578 +       /* check for v4 addresses */
13579 +       for (nxa = &nxi->v4; nxa; nxa = nxa->next)
13580 +               if (v4_addr_match(nxa, addr, tmask))
13581 +                       goto out;
13582 +       ret = 0;
13583 +out:
13584 +       vxdprintk(VXD_CBIT(net, 0),
13585 +               "v4_addr_in_nx_info(%p[#%u]," NIPQUAD_FMT ",%04x) = %d",
13586 +               nxi, nxi ? nxi->nx_id : 0, NIPQUAD(addr), tmask, ret);
13587 +       return ret;
13588 +}
13589 +
13590 +static inline
13591 +int v4_nx_addr_match(struct nx_addr_v4 *nxa, struct nx_addr_v4 *addr, uint16_t mask)
13592 +{
13593 +       /* FIXME: needs full range checks */
13594 +       return v4_addr_match(nxa, addr->ip[0].s_addr, mask);
13595 +}
13596 +
13597 +static inline
13598 +int v4_nx_addr_in_nx_info(struct nx_info *nxi, struct nx_addr_v4 *nxa, uint16_t mask)
13599 +{
13600 +       struct nx_addr_v4 *ptr;
13601 +
13602 +       for (ptr = &nxi->v4; ptr; ptr = ptr->next)
13603 +               if (v4_nx_addr_match(ptr, nxa, mask))
13604 +                       return 1;
13605 +       return 0;
13606 +}
13607 +
13608 +#include <net/inet_sock.h>
13609 +
13610 +/*
13611 + *     Check if a given address matches for a socket
13612 + *
13613 + *     nxi:            the socket's nx_info if any
13614 + *     addr:           to be verified address
13615 + */
13616 +static inline
13617 +int v4_sock_addr_match (
13618 +       struct nx_info *nxi,
13619 +       struct inet_sock *inet,
13620 +       __be32 addr)
13621 +{
13622 +       __be32 saddr = inet->rcv_saddr;
13623 +       __be32 bcast = nxi ? nxi->v4_bcast.s_addr : INADDR_BROADCAST;
13624 +
13625 +       if (addr && (saddr == addr || bcast == addr))
13626 +               return 1;
13627 +       if (!saddr)
13628 +               return v4_addr_in_nx_info(nxi, addr, NXA_MASK_BIND);
13629 +       return 0;
13630 +}
13631 +
13632 +
13633 +/* inet related checks and helpers */
13634 +
13635 +
13636 +struct in_ifaddr;
13637 +struct net_device;
13638 +struct sock;
13639 +
13640 +#ifdef CONFIG_INET
13641 +
13642 +#include <linux/netdevice.h>
13643 +#include <linux/inetdevice.h>
13644 +#include <net/inet_sock.h>
13645 +#include <net/inet_timewait_sock.h>
13646 +
13647 +
13648 +int dev_in_nx_info(struct net_device *, struct nx_info *);
13649 +int v4_dev_in_nx_info(struct net_device *, struct nx_info *);
13650 +int nx_v4_addr_conflict(struct nx_info *, struct nx_info *);
13651 +
13652 +
13653 +/*
13654 + *     check if address is covered by socket
13655 + *
13656 + *     sk:     the socket to check against
13657 + *     addr:   the address in question (must be != 0)
13658 + */
13659 +
13660 +static inline
13661 +int __v4_addr_match_socket(const struct sock *sk, struct nx_addr_v4 *nxa)
13662 +{
13663 +       struct nx_info *nxi = sk->sk_nx_info;
13664 +       __be32 saddr = inet_rcv_saddr(sk);
13665 +
13666 +       vxdprintk(VXD_CBIT(net, 5),
13667 +               "__v4_addr_in_socket(%p," NXAV4_FMT ") %p:" NIPQUAD_FMT " %p;%lx",
13668 +               sk, NXAV4(nxa), nxi, NIPQUAD(saddr), sk->sk_socket,
13669 +               (sk->sk_socket?sk->sk_socket->flags:0));
13670 +
13671 +       if (saddr) {            /* direct address match */
13672 +               return v4_addr_match(nxa, saddr, -1);
13673 +       } else if (nxi) {       /* match against nx_info */
13674 +               return v4_nx_addr_in_nx_info(nxi, nxa, -1);
13675 +       } else {                /* unrestricted any socket */
13676 +               return 1;
13677 +       }
13678 +}
13679 +
13680 +
13681 +
13682 +static inline
13683 +int nx_dev_visible(struct nx_info *nxi, struct net_device *dev)
13684 +{
13685 +       vxdprintk(VXD_CBIT(net, 1), "nx_dev_visible(%p[#%u],%p Â»%s«) %d",
13686 +               nxi, nxi ? nxi->nx_id : 0, dev, dev->name,
13687 +               nxi ? dev_in_nx_info(dev, nxi) : 0);
13688 +
13689 +       if (!nx_info_flags(nxi, NXF_HIDE_NETIF, 0))
13690 +               return 1;
13691 +       if (dev_in_nx_info(dev, nxi))
13692 +               return 1;
13693 +       return 0;
13694 +}
13695 +
13696 +
13697 +static inline
13698 +int v4_ifa_in_nx_info(struct in_ifaddr *ifa, struct nx_info *nxi)
13699 +{
13700 +       if (!nxi)
13701 +               return 1;
13702 +       if (!ifa)
13703 +               return 0;
13704 +       return v4_addr_in_nx_info(nxi, ifa->ifa_local, NXA_MASK_SHOW);
13705 +}
13706 +
13707 +static inline
13708 +int nx_v4_ifa_visible(struct nx_info *nxi, struct in_ifaddr *ifa)
13709 +{
13710 +       vxdprintk(VXD_CBIT(net, 1), "nx_v4_ifa_visible(%p[#%u],%p) %d",
13711 +               nxi, nxi ? nxi->nx_id : 0, ifa,
13712 +               nxi ? v4_ifa_in_nx_info(ifa, nxi) : 0);
13713 +
13714 +       if (!nx_info_flags(nxi, NXF_HIDE_NETIF, 0))
13715 +               return 1;
13716 +       if (v4_ifa_in_nx_info(ifa, nxi))
13717 +               return 1;
13718 +       return 0;
13719 +}
13720 +
13721 +
13722 +struct nx_v4_sock_addr {
13723 +       __be32 saddr;   /* Address used for validation */
13724 +       __be32 baddr;   /* Address used for socket bind */
13725 +};
13726 +
13727 +static inline
13728 +int v4_map_sock_addr(struct inet_sock *inet, struct sockaddr_in *addr,
13729 +       struct nx_v4_sock_addr *nsa)
13730 +{
13731 +       struct sock *sk = &inet->sk;
13732 +       struct nx_info *nxi = sk->sk_nx_info;
13733 +       __be32 saddr = addr->sin_addr.s_addr;
13734 +       __be32 baddr = saddr;
13735 +
13736 +       vxdprintk(VXD_CBIT(net, 3),
13737 +               "inet_bind(%p)* %p,%p;%lx " NIPQUAD_FMT,
13738 +               sk, sk->sk_nx_info, sk->sk_socket,
13739 +               (sk->sk_socket ? sk->sk_socket->flags : 0),
13740 +               NIPQUAD(saddr));
13741 +
13742 +       if (nxi) {
13743 +               if (saddr == INADDR_ANY) {
13744 +                       if (nx_info_flags(nxi, NXF_SINGLE_IP, 0))
13745 +                               baddr = nxi->v4.ip[0].s_addr;
13746 +               } else if (saddr == IPI_LOOPBACK) {
13747 +                       if (nx_info_flags(nxi, NXF_LBACK_REMAP, 0))
13748 +                               baddr = nxi->v4_lback.s_addr;
13749 +               } else {        /* normal address bind */
13750 +                       if (!v4_addr_in_nx_info(nxi, saddr, NXA_MASK_BIND))
13751 +                               return -EADDRNOTAVAIL;
13752 +               }
13753 +       }
13754 +
13755 +       vxdprintk(VXD_CBIT(net, 3),
13756 +               "inet_bind(%p) " NIPQUAD_FMT ", " NIPQUAD_FMT,
13757 +               sk, NIPQUAD(saddr), NIPQUAD(baddr));
13758 +
13759 +       nsa->saddr = saddr;
13760 +       nsa->baddr = baddr;
13761 +       return 0;
13762 +}
13763 +
13764 +static inline
13765 +void v4_set_sock_addr(struct inet_sock *inet, struct nx_v4_sock_addr *nsa)
13766 +{
13767 +       inet->saddr = nsa->baddr;
13768 +       inet->rcv_saddr = nsa->baddr;
13769 +}
13770 +
13771 +
13772 +/*
13773 + *      helper to simplify inet_lookup_listener
13774 + *
13775 + *      nxi:   the socket's nx_info if any
13776 + *      addr:  to be verified address
13777 + *      saddr: socket address
13778 + */
13779 +static inline int v4_inet_addr_match (
13780 +       struct nx_info *nxi,
13781 +       __be32 addr,
13782 +       __be32 saddr)
13783 +{
13784 +       if (addr && (saddr == addr))
13785 +               return 1;
13786 +       if (!saddr)
13787 +               return nxi ? v4_addr_in_nx_info(nxi, addr, NXA_MASK_BIND) : 1;
13788 +       return 0;
13789 +}
13790 +
13791 +static inline __be32 nx_map_sock_lback(struct nx_info *nxi, __be32 addr)
13792 +{
13793 +       if (nx_info_flags(nxi, NXF_HIDE_LBACK, 0) &&
13794 +               (addr == nxi->v4_lback.s_addr))
13795 +               return IPI_LOOPBACK;
13796 +       return addr;
13797 +}
13798 +
13799 +static inline
13800 +int nx_info_has_v4(struct nx_info *nxi)
13801 +{
13802 +       if (!nxi)
13803 +               return 1;
13804 +       if (NX_IPV4(nxi))
13805 +               return 1;
13806 +       if (nx_info_flags(nxi, NXF_LBACK_REMAP, 0))
13807 +               return 1;
13808 +       return 0;
13809 +}
13810 +
13811 +#else /* CONFIG_INET */
13812 +
13813 +static inline
13814 +int nx_dev_visible(struct nx_info *n, struct net_device *d)
13815 +{
13816 +       return 1;
13817 +}
13818 +
13819 +static inline
13820 +int nx_v4_addr_conflict(struct nx_info *n, uint32_t a, const struct sock *s)
13821 +{
13822 +       return 1;
13823 +}
13824 +
13825 +static inline
13826 +int v4_ifa_in_nx_info(struct in_ifaddr *a, struct nx_info *n)
13827 +{
13828 +       return 1;
13829 +}
13830 +
13831 +static inline
13832 +int nx_info_has_v4(struct nx_info *nxi)
13833 +{
13834 +       return 0;
13835 +}
13836 +
13837 +#endif /* CONFIG_INET */
13838 +
13839 +#define current_nx_info_has_v4() \
13840 +       nx_info_has_v4(current_nx_info())
13841 +
13842 +#else
13843 +// #warning duplicate inclusion
13844 +#endif
13845 diff -NurpP --minimal linux-2.6.29.1/include/linux/vs_limit.h linux-2.6.29.1-vs2.3.0.36.9-pre5/include/linux/vs_limit.h
13846 --- linux-2.6.29.1/include/linux/vs_limit.h     1970-01-01 01:00:00.000000000 +0100
13847 +++ linux-2.6.29.1-vs2.3.0.36.9-pre5/include/linux/vs_limit.h   2009-02-22 22:54:26.000000000 +0100
13848 @@ -0,0 +1,140 @@
13849 +#ifndef _VS_LIMIT_H
13850 +#define _VS_LIMIT_H
13851 +
13852 +#include "vserver/limit.h"
13853 +#include "vserver/base.h"
13854 +#include "vserver/context.h"
13855 +#include "vserver/debug.h"
13856 +#include "vserver/context.h"
13857 +#include "vserver/limit_int.h"
13858 +
13859 +
13860 +#define vx_acc_cres(v, d, p, r) \
13861 +       __vx_acc_cres(v, r, d, p, __FILE__, __LINE__)
13862 +
13863 +#define vx_acc_cres_cond(x, d, p, r) \
13864 +       __vx_acc_cres(((x) == vx_current_xid()) ? current->vx_info : 0, \
13865 +       r, d, p, __FILE__, __LINE__)
13866 +
13867 +
13868 +#define vx_add_cres(v, a, p, r) \
13869 +       __vx_add_cres(v, r, a, p, __FILE__, __LINE__)
13870 +#define vx_sub_cres(v, a, p, r)                vx_add_cres(v, -(a), p, r)
13871 +
13872 +#define vx_add_cres_cond(x, a, p, r) \
13873 +       __vx_add_cres(((x) == vx_current_xid()) ? current->vx_info : 0, \
13874 +       r, a, p, __FILE__, __LINE__)
13875 +#define vx_sub_cres_cond(x, a, p, r)   vx_add_cres_cond(x, -(a), p, r)
13876 +
13877 +
13878 +/* process and file limits */
13879 +
13880 +#define vx_nproc_inc(p) \
13881 +       vx_acc_cres((p)->vx_info, 1, p, RLIMIT_NPROC)
13882 +
13883 +#define vx_nproc_dec(p) \
13884 +       vx_acc_cres((p)->vx_info,-1, p, RLIMIT_NPROC)
13885 +
13886 +#define vx_files_inc(f) \
13887 +       vx_acc_cres_cond((f)->f_xid, 1, f, RLIMIT_NOFILE)
13888 +
13889 +#define vx_files_dec(f) \
13890 +       vx_acc_cres_cond((f)->f_xid,-1, f, RLIMIT_NOFILE)
13891 +
13892 +#define vx_locks_inc(l) \
13893 +       vx_acc_cres_cond((l)->fl_xid, 1, l, RLIMIT_LOCKS)
13894 +
13895 +#define vx_locks_dec(l) \
13896 +       vx_acc_cres_cond((l)->fl_xid,-1, l, RLIMIT_LOCKS)
13897 +
13898 +#define vx_openfd_inc(f) \
13899 +       vx_acc_cres(current->vx_info, 1, (void *)(long)(f), VLIMIT_OPENFD)
13900 +
13901 +#define vx_openfd_dec(f) \
13902 +       vx_acc_cres(current->vx_info,-1, (void *)(long)(f), VLIMIT_OPENFD)
13903 +
13904 +
13905 +#define vx_cres_avail(v, n, r) \
13906 +       __vx_cres_avail(v, r, n, __FILE__, __LINE__)
13907 +
13908 +
13909 +#define vx_nproc_avail(n) \
13910 +       vx_cres_avail(current->vx_info, n, RLIMIT_NPROC)
13911 +
13912 +#define vx_files_avail(n) \
13913 +       vx_cres_avail(current->vx_info, n, RLIMIT_NOFILE)
13914 +
13915 +#define vx_locks_avail(n) \
13916 +       vx_cres_avail(current->vx_info, n, RLIMIT_LOCKS)
13917 +
13918 +#define vx_openfd_avail(n) \
13919 +       vx_cres_avail(current->vx_info, n, VLIMIT_OPENFD)
13920 +
13921 +
13922 +/* dentry limits */
13923 +
13924 +#define vx_dentry_inc(d) do {                                          \
13925 +       if (atomic_read(&d->d_count) == 1)                              \
13926 +               vx_acc_cres(current->vx_info, 1, d, VLIMIT_DENTRY);     \
13927 +       } while (0)
13928 +
13929 +#define vx_dentry_dec(d) do {                                          \
13930 +       if (atomic_read(&d->d_count) == 0)                              \
13931 +               vx_acc_cres(current->vx_info,-1, d, VLIMIT_DENTRY);     \
13932 +       } while (0)
13933 +
13934 +#define vx_dentry_avail(n) \
13935 +       vx_cres_avail(current->vx_info, n, VLIMIT_DENTRY)
13936 +
13937 +
13938 +/* socket limits */
13939 +
13940 +#define vx_sock_inc(s) \
13941 +       vx_acc_cres((s)->sk_vx_info, 1, s, VLIMIT_NSOCK)
13942 +
13943 +#define vx_sock_dec(s) \
13944 +       vx_acc_cres((s)->sk_vx_info,-1, s, VLIMIT_NSOCK)
13945 +
13946 +#define vx_sock_avail(n) \
13947 +       vx_cres_avail(current->vx_info, n, VLIMIT_NSOCK)
13948 +
13949 +
13950 +/* ipc resource limits */
13951 +
13952 +#define vx_ipcmsg_add(v, u, a) \
13953 +       vx_add_cres(v, a, u, RLIMIT_MSGQUEUE)
13954 +
13955 +#define vx_ipcmsg_sub(v, u, a) \
13956 +       vx_sub_cres(v, a, u, RLIMIT_MSGQUEUE)
13957 +
13958 +#define vx_ipcmsg_avail(v, a) \
13959 +       vx_cres_avail(v, a, RLIMIT_MSGQUEUE)
13960 +
13961 +
13962 +#define vx_ipcshm_add(v, k, a) \
13963 +       vx_add_cres(v, a, (void *)(long)(k), VLIMIT_SHMEM)
13964 +
13965 +#define vx_ipcshm_sub(v, k, a) \
13966 +       vx_sub_cres(v, a, (void *)(long)(k), VLIMIT_SHMEM)
13967 +
13968 +#define vx_ipcshm_avail(v, a) \
13969 +       vx_cres_avail(v, a, VLIMIT_SHMEM)
13970 +
13971 +
13972 +#define vx_semary_inc(a) \
13973 +       vx_acc_cres(current->vx_info, 1, a, VLIMIT_SEMARY)
13974 +
13975 +#define vx_semary_dec(a) \
13976 +       vx_acc_cres(current->vx_info, -1, a, VLIMIT_SEMARY)
13977 +
13978 +
13979 +#define vx_nsems_add(a,n) \
13980 +       vx_add_cres(current->vx_info, n, a, VLIMIT_NSEMS)
13981 +
13982 +#define vx_nsems_sub(a,n) \
13983 +       vx_sub_cres(current->vx_info, n, a, VLIMIT_NSEMS)
13984 +
13985 +
13986 +#else
13987 +#warning duplicate inclusion
13988 +#endif
13989 diff -NurpP --minimal linux-2.6.29.1/include/linux/vs_memory.h linux-2.6.29.1-vs2.3.0.36.9-pre5/include/linux/vs_memory.h
13990 --- linux-2.6.29.1/include/linux/vs_memory.h    1970-01-01 01:00:00.000000000 +0100
13991 +++ linux-2.6.29.1-vs2.3.0.36.9-pre5/include/linux/vs_memory.h  2009-02-22 22:54:26.000000000 +0100
13992 @@ -0,0 +1,159 @@
13993 +#ifndef _VS_MEMORY_H
13994 +#define _VS_MEMORY_H
13995 +
13996 +#include "vserver/limit.h"
13997 +#include "vserver/base.h"
13998 +#include "vserver/context.h"
13999 +#include "vserver/debug.h"
14000 +#include "vserver/context.h"
14001 +#include "vserver/limit_int.h"
14002 +
14003 +
14004 +#define __acc_add_long(a, v)   (*(v) += (a))
14005 +#define __acc_inc_long(v)      (++*(v))
14006 +#define __acc_dec_long(v)      (--*(v))
14007 +
14008 +#if    NR_CPUS >= CONFIG_SPLIT_PTLOCK_CPUS
14009 +#define __acc_add_atomic(a, v) atomic_long_add(a, v)
14010 +#define __acc_inc_atomic(v)    atomic_long_inc(v)
14011 +#define __acc_dec_atomic(v)    atomic_long_dec(v)
14012 +#else  /* NR_CPUS < CONFIG_SPLIT_PTLOCK_CPUS */
14013 +#define __acc_add_atomic(a, v) __acc_add_long(a, v)
14014 +#define __acc_inc_atomic(v)    __acc_inc_long(v)
14015 +#define __acc_dec_atomic(v)    __acc_dec_long(v)
14016 +#endif /* NR_CPUS < CONFIG_SPLIT_PTLOCK_CPUS */
14017 +
14018 +
14019 +#define vx_acc_page(m, d, v, r) do {                                   \
14020 +       if ((d) > 0)                                                    \
14021 +               __acc_inc_long(&(m)->v);                                \
14022 +       else                                                            \
14023 +               __acc_dec_long(&(m)->v);                                \
14024 +       __vx_acc_cres(m->mm_vx_info, r, d, m, __FILE__, __LINE__);      \
14025 +} while (0)
14026 +
14027 +#define vx_acc_page_atomic(m, d, v, r) do {                            \
14028 +       if ((d) > 0)                                                    \
14029 +               __acc_inc_atomic(&(m)->v);                              \
14030 +       else                                                            \
14031 +               __acc_dec_atomic(&(m)->v);                              \
14032 +       __vx_acc_cres(m->mm_vx_info, r, d, m, __FILE__, __LINE__);      \
14033 +} while (0)
14034 +
14035 +
14036 +#define vx_acc_pages(m, p, v, r) do {                                  \
14037 +       unsigned long __p = (p);                                        \
14038 +       __acc_add_long(__p, &(m)->v);                                   \
14039 +       __vx_add_cres(m->mm_vx_info, r, __p, m, __FILE__, __LINE__);    \
14040 +} while (0)
14041 +
14042 +#define vx_acc_pages_atomic(m, p, v, r) do {                           \
14043 +       unsigned long __p = (p);                                        \
14044 +       __acc_add_atomic(__p, &(m)->v);                                 \
14045 +       __vx_add_cres(m->mm_vx_info, r, __p, m, __FILE__, __LINE__);    \
14046 +} while (0)
14047 +
14048 +
14049 +
14050 +#define vx_acc_vmpage(m, d) \
14051 +       vx_acc_page(m, d, total_vm,  RLIMIT_AS)
14052 +#define vx_acc_vmlpage(m, d) \
14053 +       vx_acc_page(m, d, locked_vm, RLIMIT_MEMLOCK)
14054 +#define vx_acc_file_rsspage(m, d) \
14055 +       vx_acc_page_atomic(m, d, _file_rss, VLIMIT_MAPPED)
14056 +#define vx_acc_anon_rsspage(m, d) \
14057 +       vx_acc_page_atomic(m, d, _anon_rss, VLIMIT_ANON)
14058 +
14059 +#define vx_acc_vmpages(m, p) \
14060 +       vx_acc_pages(m, p, total_vm,  RLIMIT_AS)
14061 +#define vx_acc_vmlpages(m, p) \
14062 +       vx_acc_pages(m, p, locked_vm, RLIMIT_MEMLOCK)
14063 +#define vx_acc_file_rsspages(m, p) \
14064 +       vx_acc_pages_atomic(m, p, _file_rss, VLIMIT_MAPPED)
14065 +#define vx_acc_anon_rsspages(m, p) \
14066 +       vx_acc_pages_atomic(m, p, _anon_rss, VLIMIT_ANON)
14067 +
14068 +#define vx_pages_add(s, r, p)  __vx_add_cres(s, r, p, 0, __FILE__, __LINE__)
14069 +#define vx_pages_sub(s, r, p)  vx_pages_add(s, r, -(p))
14070 +
14071 +#define vx_vmpages_inc(m)              vx_acc_vmpage(m, 1)
14072 +#define vx_vmpages_dec(m)              vx_acc_vmpage(m, -1)
14073 +#define vx_vmpages_add(m, p)           vx_acc_vmpages(m, p)
14074 +#define vx_vmpages_sub(m, p)           vx_acc_vmpages(m, -(p))
14075 +
14076 +#define vx_vmlocked_inc(m)             vx_acc_vmlpage(m, 1)
14077 +#define vx_vmlocked_dec(m)             vx_acc_vmlpage(m, -1)
14078 +#define vx_vmlocked_add(m, p)          vx_acc_vmlpages(m, p)
14079 +#define vx_vmlocked_sub(m, p)          vx_acc_vmlpages(m, -(p))
14080 +
14081 +#define vx_file_rsspages_inc(m)                vx_acc_file_rsspage(m, 1)
14082 +#define vx_file_rsspages_dec(m)                vx_acc_file_rsspage(m, -1)
14083 +#define vx_file_rsspages_add(m, p)     vx_acc_file_rsspages(m, p)
14084 +#define vx_file_rsspages_sub(m, p)     vx_acc_file_rsspages(m, -(p))
14085 +
14086 +#define vx_anon_rsspages_inc(m)                vx_acc_anon_rsspage(m, 1)
14087 +#define vx_anon_rsspages_dec(m)                vx_acc_anon_rsspage(m, -1)
14088 +#define vx_anon_rsspages_add(m, p)     vx_acc_anon_rsspages(m, p)
14089 +#define vx_anon_rsspages_sub(m, p)     vx_acc_anon_rsspages(m, -(p))
14090 +
14091 +
14092 +#define vx_pages_avail(m, p, r) \
14093 +       __vx_cres_avail((m)->mm_vx_info, r, p, __FILE__, __LINE__)
14094 +
14095 +#define vx_vmpages_avail(m, p) vx_pages_avail(m, p, RLIMIT_AS)
14096 +#define vx_vmlocked_avail(m, p)        vx_pages_avail(m, p, RLIMIT_MEMLOCK)
14097 +#define vx_anon_avail(m, p)    vx_pages_avail(m, p, VLIMIT_ANON)
14098 +#define vx_mapped_avail(m, p)  vx_pages_avail(m, p, VLIMIT_MAPPED)
14099 +
14100 +#define vx_rss_avail(m, p) \
14101 +       __vx_cres_array_avail((m)->mm_vx_info, VLA_RSS, p, __FILE__, __LINE__)
14102 +
14103 +
14104 +enum {
14105 +       VXPT_UNKNOWN = 0,
14106 +       VXPT_ANON,
14107 +       VXPT_NONE,
14108 +       VXPT_FILE,
14109 +       VXPT_SWAP,
14110 +       VXPT_WRITE
14111 +};
14112 +
14113 +#if 0
14114 +#define        vx_page_fault(mm, vma, type, ret)
14115 +#else
14116 +
14117 +static inline
14118 +void __vx_page_fault(struct mm_struct *mm,
14119 +       struct vm_area_struct *vma, int type, int ret)
14120 +{
14121 +       struct vx_info *vxi = mm->mm_vx_info;
14122 +       int what;
14123 +/*
14124 +       static char *page_type[6] =
14125 +               { "UNKNOWN", "ANON", "NONE", "FILE", "SWAP", "WRITE" };
14126 +       static char *page_what[4] =
14127 +               { "FAULT_OOM", "FAULT_SIGBUS", "FAULT_MINOR", "FAULT_MAJOR" };
14128 +*/
14129 +
14130 +       if (!vxi)
14131 +               return;
14132 +
14133 +       what = (ret & 0x3);
14134 +
14135 +/*     printk("[%d] page[%d][%d] %2x %s %s\n", vxi->vx_id,
14136 +               type, what, ret, page_type[type], page_what[what]);
14137 +*/
14138 +       if (ret & VM_FAULT_WRITE)
14139 +               what |= 0x4;
14140 +       atomic_inc(&vxi->cacct.page[type][what]);
14141 +}
14142 +
14143 +#define        vx_page_fault(mm, vma, type, ret)       __vx_page_fault(mm, vma, type, ret)
14144 +#endif
14145 +
14146 +
14147 +extern unsigned long vx_badness(struct task_struct *task, struct mm_struct *mm);
14148 +
14149 +#else
14150 +#warning duplicate inclusion
14151 +#endif
14152 diff -NurpP --minimal linux-2.6.29.1/include/linux/vs_network.h linux-2.6.29.1-vs2.3.0.36.9-pre5/include/linux/vs_network.h
14153 --- linux-2.6.29.1/include/linux/vs_network.h   1970-01-01 01:00:00.000000000 +0100
14154 +++ linux-2.6.29.1-vs2.3.0.36.9-pre5/include/linux/vs_network.h 2009-02-22 22:54:26.000000000 +0100
14155 @@ -0,0 +1,169 @@
14156 +#ifndef _NX_VS_NETWORK_H
14157 +#define _NX_VS_NETWORK_H
14158 +
14159 +#include "vserver/context.h"
14160 +#include "vserver/network.h"
14161 +#include "vserver/base.h"
14162 +#include "vserver/check.h"
14163 +#include "vserver/debug.h"
14164 +
14165 +#include <linux/sched.h>
14166 +
14167 +
14168 +#define get_nx_info(i) __get_nx_info(i, __FILE__, __LINE__)
14169 +
14170 +static inline struct nx_info *__get_nx_info(struct nx_info *nxi,
14171 +       const char *_file, int _line)
14172 +{
14173 +       if (!nxi)
14174 +               return NULL;
14175 +
14176 +       vxlprintk(VXD_CBIT(nid, 2), "get_nx_info(%p[#%d.%d])",
14177 +               nxi, nxi ? nxi->nx_id : 0,
14178 +               nxi ? atomic_read(&nxi->nx_usecnt) : 0,
14179 +               _file, _line);
14180 +
14181 +       atomic_inc(&nxi->nx_usecnt);
14182 +       return nxi;
14183 +}
14184 +
14185 +
14186 +extern void free_nx_info(struct nx_info *);
14187 +
14188 +#define put_nx_info(i) __put_nx_info(i, __FILE__, __LINE__)
14189 +
14190 +static inline void __put_nx_info(struct nx_info *nxi, const char *_file, int _line)
14191 +{
14192 +       if (!nxi)
14193 +               return;
14194 +
14195 +       vxlprintk(VXD_CBIT(nid, 2), "put_nx_info(%p[#%d.%d])",
14196 +               nxi, nxi ? nxi->nx_id : 0,
14197 +               nxi ? atomic_read(&nxi->nx_usecnt) : 0,
14198 +               _file, _line);
14199 +
14200 +       if (atomic_dec_and_test(&nxi->nx_usecnt))
14201 +               free_nx_info(nxi);
14202 +}
14203 +
14204 +
14205 +#define init_nx_info(p, i) __init_nx_info(p, i, __FILE__, __LINE__)
14206 +
14207 +static inline void __init_nx_info(struct nx_info **nxp, struct nx_info *nxi,
14208 +               const char *_file, int _line)
14209 +{
14210 +       if (nxi) {
14211 +               vxlprintk(VXD_CBIT(nid, 3),
14212 +                       "init_nx_info(%p[#%d.%d])",
14213 +                       nxi, nxi ? nxi->nx_id : 0,
14214 +                       nxi ? atomic_read(&nxi->nx_usecnt) : 0,
14215 +                       _file, _line);
14216 +
14217 +               atomic_inc(&nxi->nx_usecnt);
14218 +       }
14219 +       *nxp = nxi;
14220 +}
14221 +
14222 +
14223 +#define set_nx_info(p, i) __set_nx_info(p, i, __FILE__, __LINE__)
14224 +
14225 +static inline void __set_nx_info(struct nx_info **nxp, struct nx_info *nxi,
14226 +       const char *_file, int _line)
14227 +{
14228 +       struct nx_info *nxo;
14229 +
14230 +       if (!nxi)
14231 +               return;
14232 +
14233 +       vxlprintk(VXD_CBIT(nid, 3), "set_nx_info(%p[#%d.%d])",
14234 +               nxi, nxi ? nxi->nx_id : 0,
14235 +               nxi ? atomic_read(&nxi->nx_usecnt) : 0,
14236 +               _file, _line);
14237 +
14238 +       atomic_inc(&nxi->nx_usecnt);
14239 +       nxo = xchg(nxp, nxi);
14240 +       BUG_ON(nxo);
14241 +}
14242 +
14243 +#define clr_nx_info(p) __clr_nx_info(p, __FILE__, __LINE__)
14244 +
14245 +static inline void __clr_nx_info(struct nx_info **nxp,
14246 +       const char *_file, int _line)
14247 +{
14248 +       struct nx_info *nxo;
14249 +
14250 +       nxo = xchg(nxp, NULL);
14251 +       if (!nxo)
14252 +               return;
14253 +
14254 +       vxlprintk(VXD_CBIT(nid, 3), "clr_nx_info(%p[#%d.%d])",
14255 +               nxo, nxo ? nxo->nx_id : 0,
14256 +               nxo ? atomic_read(&nxo->nx_usecnt) : 0,
14257 +               _file, _line);
14258 +
14259 +       if (atomic_dec_and_test(&nxo->nx_usecnt))
14260 +               free_nx_info(nxo);
14261 +}
14262 +
14263 +
14264 +#define claim_nx_info(v, p) __claim_nx_info(v, p, __FILE__, __LINE__)
14265 +
14266 +static inline void __claim_nx_info(struct nx_info *nxi,
14267 +       struct task_struct *task, const char *_file, int _line)
14268 +{
14269 +       vxlprintk(VXD_CBIT(nid, 3), "claim_nx_info(%p[#%d.%d.%d]) %p",
14270 +               nxi, nxi ? nxi->nx_id : 0,
14271 +               nxi?atomic_read(&nxi->nx_usecnt):0,
14272 +               nxi?atomic_read(&nxi->nx_tasks):0,
14273 +               task, _file, _line);
14274 +
14275 +       atomic_inc(&nxi->nx_tasks);
14276 +}
14277 +
14278 +
14279 +extern void unhash_nx_info(struct nx_info *);
14280 +
14281 +#define release_nx_info(v, p) __release_nx_info(v, p, __FILE__, __LINE__)
14282 +
14283 +static inline void __release_nx_info(struct nx_info *nxi,
14284 +       struct task_struct *task, const char *_file, int _line)
14285 +{
14286 +       vxlprintk(VXD_CBIT(nid, 3), "release_nx_info(%p[#%d.%d.%d]) %p",
14287 +               nxi, nxi ? nxi->nx_id : 0,
14288 +               nxi ? atomic_read(&nxi->nx_usecnt) : 0,
14289 +               nxi ? atomic_read(&nxi->nx_tasks) : 0,
14290 +               task, _file, _line);
14291 +
14292 +       might_sleep();
14293 +
14294 +       if (atomic_dec_and_test(&nxi->nx_tasks))
14295 +               unhash_nx_info(nxi);
14296 +}
14297 +
14298 +
14299 +#define task_get_nx_info(i)    __task_get_nx_info(i, __FILE__, __LINE__)
14300 +
14301 +static __inline__ struct nx_info *__task_get_nx_info(struct task_struct *p,
14302 +       const char *_file, int _line)
14303 +{
14304 +       struct nx_info *nxi;
14305 +
14306 +       task_lock(p);
14307 +       vxlprintk(VXD_CBIT(nid, 5), "task_get_nx_info(%p)",
14308 +               p, _file, _line);
14309 +       nxi = __get_nx_info(p->nx_info, _file, _line);
14310 +       task_unlock(p);
14311 +       return nxi;
14312 +}
14313 +
14314 +
14315 +static inline void exit_nx_info(struct task_struct *p)
14316 +{
14317 +       if (p->nx_info)
14318 +               release_nx_info(p->nx_info, p);
14319 +}
14320 +
14321 +
14322 +#else
14323 +#warning duplicate inclusion
14324 +#endif
14325 diff -NurpP --minimal linux-2.6.29.1/include/linux/vs_pid.h linux-2.6.29.1-vs2.3.0.36.9-pre5/include/linux/vs_pid.h
14326 --- linux-2.6.29.1/include/linux/vs_pid.h       1970-01-01 01:00:00.000000000 +0100
14327 +++ linux-2.6.29.1-vs2.3.0.36.9-pre5/include/linux/vs_pid.h     2009-02-22 22:54:26.000000000 +0100
14328 @@ -0,0 +1,95 @@
14329 +#ifndef _VS_PID_H
14330 +#define _VS_PID_H
14331 +
14332 +#include "vserver/base.h"
14333 +#include "vserver/check.h"
14334 +#include "vserver/context.h"
14335 +#include "vserver/debug.h"
14336 +#include "vserver/pid.h"
14337 +#include <linux/pid_namespace.h>
14338 +
14339 +
14340 +#define VXF_FAKE_INIT  (VXF_INFO_INIT | VXF_STATE_INIT)
14341 +
14342 +static inline
14343 +int vx_proc_task_visible(struct task_struct *task)
14344 +{
14345 +       if ((task->pid == 1) &&
14346 +               !vx_flags(VXF_FAKE_INIT, VXF_FAKE_INIT))
14347 +               /* show a blend through init */
14348 +               goto visible;
14349 +       if (vx_check(vx_task_xid(task), VS_WATCH | VS_IDENT))
14350 +               goto visible;
14351 +       return 0;
14352 +visible:
14353 +       return 1;
14354 +}
14355 +
14356 +#define find_task_by_real_pid(pid) find_task_by_pid_ns(pid, &init_pid_ns)
14357 +
14358 +#if 0
14359 +
14360 +static inline
14361 +struct task_struct *vx_find_proc_task_by_pid(int pid)
14362 +{
14363 +       struct task_struct *task = find_task_by_real_pid(pid);
14364 +
14365 +       if (task && !vx_proc_task_visible(task)) {
14366 +               vxdprintk(VXD_CBIT(misc, 6),
14367 +                       "dropping task (find) %p[#%u,%u] for %p[#%u,%u]",
14368 +                       task, task->xid, task->pid,
14369 +                       current, current->xid, current->pid);
14370 +               task = NULL;
14371 +       }
14372 +       return task;
14373 +}
14374 +
14375 +#endif
14376 +
14377 +static inline
14378 +struct task_struct *vx_get_proc_task(struct inode *inode, struct pid *pid)
14379 +{
14380 +       struct task_struct *task = get_pid_task(pid, PIDTYPE_PID);
14381 +
14382 +       if (task && !vx_proc_task_visible(task)) {
14383 +               vxdprintk(VXD_CBIT(misc, 6),
14384 +                       "dropping task (get) %p[#%u,%u] for %p[#%u,%u]",
14385 +                       task, task->xid, task->pid,
14386 +                       current, current->xid, current->pid);
14387 +               put_task_struct(task);
14388 +               task = NULL;
14389 +       }
14390 +       return task;
14391 +}
14392 +
14393 +#if 0
14394 +
14395 +static inline
14396 +struct task_struct *vx_child_reaper(struct task_struct *p)
14397 +{
14398 +       struct vx_info *vxi = p->vx_info;
14399 +       struct task_struct *reaper = child_reaper(p);
14400 +
14401 +       if (!vxi)
14402 +               goto out;
14403 +
14404 +       BUG_ON(!p->vx_info->vx_reaper);
14405 +
14406 +       /* child reaper for the guest reaper */
14407 +       if (vxi->vx_reaper == p)
14408 +               goto out;
14409 +
14410 +       reaper = vxi->vx_reaper;
14411 +out:
14412 +       vxdprintk(VXD_CBIT(xid, 7),
14413 +               "vx_child_reaper(%p[#%u,%u]) = %p[#%u,%u]",
14414 +               p, p->xid, p->pid, reaper, reaper->xid, reaper->pid);
14415 +       return reaper;
14416 +}
14417 +
14418 +#endif
14419 +
14420 +
14421 +#else
14422 +#warning duplicate inclusion
14423 +#endif
14424 diff -NurpP --minimal linux-2.6.29.1/include/linux/vs_sched.h linux-2.6.29.1-vs2.3.0.36.9-pre5/include/linux/vs_sched.h
14425 --- linux-2.6.29.1/include/linux/vs_sched.h     1970-01-01 01:00:00.000000000 +0100
14426 +++ linux-2.6.29.1-vs2.3.0.36.9-pre5/include/linux/vs_sched.h   2009-02-22 22:54:26.000000000 +0100
14427 @@ -0,0 +1,110 @@
14428 +#ifndef _VS_SCHED_H
14429 +#define _VS_SCHED_H
14430 +
14431 +#include "vserver/base.h"
14432 +#include "vserver/context.h"
14433 +#include "vserver/sched.h"
14434 +
14435 +
14436 +#define VAVAVOOM_RATIO          50
14437 +
14438 +#define MAX_PRIO_BIAS           20
14439 +#define MIN_PRIO_BIAS          -20
14440 +
14441 +
14442 +#ifdef CONFIG_VSERVER_HARDCPU
14443 +
14444 +/*
14445 + * effective_prio - return the priority that is based on the static
14446 + * priority but is modified by bonuses/penalties.
14447 + *
14448 + * We scale the actual sleep average [0 .... MAX_SLEEP_AVG]
14449 + * into a -4 ... 0 ... +4 bonus/penalty range.
14450 + *
14451 + * Additionally, we scale another amount based on the number of
14452 + * CPU tokens currently held by the context, if the process is
14453 + * part of a context (and the appropriate SCHED flag is set).
14454 + * This ranges from -5 ... 0 ... +15, quadratically.
14455 + *
14456 + * So, the total bonus is -9 .. 0 .. +19
14457 + * We use ~50% of the full 0...39 priority range so that:
14458 + *
14459 + * 1) nice +19 interactive tasks do not preempt nice 0 CPU hogs.
14460 + * 2) nice -20 CPU hogs do not get preempted by nice 0 tasks.
14461 + *    unless that context is far exceeding its CPU allocation.
14462 + *
14463 + * Both properties are important to certain workloads.
14464 + */
14465 +static inline
14466 +int vx_effective_vavavoom(struct _vx_sched_pc *sched_pc, int max_prio)
14467 +{
14468 +       int vavavoom, max;
14469 +
14470 +       /* lots of tokens = lots of vavavoom
14471 +        *      no tokens = no vavavoom      */
14472 +       if ((vavavoom = sched_pc->tokens) >= 0) {
14473 +               max = sched_pc->tokens_max;
14474 +               vavavoom = max - vavavoom;
14475 +               max = max * max;
14476 +               vavavoom = max_prio * VAVAVOOM_RATIO / 100
14477 +                       * (vavavoom*vavavoom - (max >> 2)) / max;
14478 +               return vavavoom;
14479 +       }
14480 +       return 0;
14481 +}
14482 +
14483 +
14484 +static inline
14485 +int vx_adjust_prio(struct task_struct *p, int prio, int max_user)
14486 +{
14487 +       struct vx_info *vxi = p->vx_info;
14488 +       struct _vx_sched_pc *sched_pc;
14489 +
14490 +       if (!vxi)
14491 +               return prio;
14492 +
14493 +       sched_pc = &vx_cpu(vxi, sched_pc);
14494 +       if (vx_info_flags(vxi, VXF_SCHED_PRIO, 0)) {
14495 +               int vavavoom = vx_effective_vavavoom(sched_pc, max_user);
14496 +
14497 +               sched_pc->vavavoom = vavavoom;
14498 +               prio += vavavoom;
14499 +       }
14500 +       prio += sched_pc->prio_bias;
14501 +       return prio;
14502 +}
14503 +
14504 +#else /* !CONFIG_VSERVER_HARDCPU */
14505 +
14506 +static inline
14507 +int vx_adjust_prio(struct task_struct *p, int prio, int max_user)
14508 +{
14509 +       struct vx_info *vxi = p->vx_info;
14510 +
14511 +       if (vxi)
14512 +               prio += vx_cpu(vxi, sched_pc).prio_bias;
14513 +       return prio;
14514 +}
14515 +
14516 +#endif /* CONFIG_VSERVER_HARDCPU */
14517 +
14518 +
14519 +static inline void vx_account_user(struct vx_info *vxi,
14520 +       cputime_t cputime, int nice)
14521 +{
14522 +       if (!vxi)
14523 +               return;
14524 +       vx_cpu(vxi, sched_pc).user_ticks += cputime;
14525 +}
14526 +
14527 +static inline void vx_account_system(struct vx_info *vxi,
14528 +       cputime_t cputime, int idle)
14529 +{
14530 +       if (!vxi)
14531 +               return;
14532 +       vx_cpu(vxi, sched_pc).sys_ticks += cputime;
14533 +}
14534 +
14535 +#else
14536 +#warning duplicate inclusion
14537 +#endif
14538 diff -NurpP --minimal linux-2.6.29.1/include/linux/vs_socket.h linux-2.6.29.1-vs2.3.0.36.9-pre5/include/linux/vs_socket.h
14539 --- linux-2.6.29.1/include/linux/vs_socket.h    1970-01-01 01:00:00.000000000 +0100
14540 +++ linux-2.6.29.1-vs2.3.0.36.9-pre5/include/linux/vs_socket.h  2009-02-22 22:54:26.000000000 +0100
14541 @@ -0,0 +1,67 @@
14542 +#ifndef _VS_SOCKET_H
14543 +#define _VS_SOCKET_H
14544 +
14545 +#include "vserver/debug.h"
14546 +#include "vserver/base.h"
14547 +#include "vserver/cacct.h"
14548 +#include "vserver/context.h"
14549 +#include "vserver/tag.h"
14550 +
14551 +
14552 +/* socket accounting */
14553 +
14554 +#include <linux/socket.h>
14555 +
14556 +static inline int vx_sock_type(int family)
14557 +{
14558 +       switch (family) {
14559 +       case PF_UNSPEC:
14560 +               return VXA_SOCK_UNSPEC;
14561 +       case PF_UNIX:
14562 +               return VXA_SOCK_UNIX;
14563 +       case PF_INET:
14564 +               return VXA_SOCK_INET;
14565 +       case PF_INET6:
14566 +               return VXA_SOCK_INET6;
14567 +       case PF_PACKET:
14568 +               return VXA_SOCK_PACKET;
14569 +       default:
14570 +               return VXA_SOCK_OTHER;
14571 +       }
14572 +}
14573 +
14574 +#define vx_acc_sock(v, f, p, s) \
14575 +       __vx_acc_sock(v, f, p, s, __FILE__, __LINE__)
14576 +
14577 +static inline void __vx_acc_sock(struct vx_info *vxi,
14578 +       int family, int pos, int size, char *file, int line)
14579 +{
14580 +       if (vxi) {
14581 +               int type = vx_sock_type(family);
14582 +
14583 +               atomic_long_inc(&vxi->cacct.sock[type][pos].count);
14584 +               atomic_long_add(size, &vxi->cacct.sock[type][pos].total);
14585 +       }
14586 +}
14587 +
14588 +#define vx_sock_recv(sk, s) \
14589 +       vx_acc_sock((sk)->sk_vx_info, (sk)->sk_family, 0, s)
14590 +#define vx_sock_send(sk, s) \
14591 +       vx_acc_sock((sk)->sk_vx_info, (sk)->sk_family, 1, s)
14592 +#define vx_sock_fail(sk, s) \
14593 +       vx_acc_sock((sk)->sk_vx_info, (sk)->sk_family, 2, s)
14594 +
14595 +
14596 +#define sock_vx_init(s) do {           \
14597 +       (s)->sk_xid = 0;                \
14598 +       (s)->sk_vx_info = NULL;         \
14599 +       } while (0)
14600 +
14601 +#define sock_nx_init(s) do {           \
14602 +       (s)->sk_nid = 0;                \
14603 +       (s)->sk_nx_info = NULL;         \
14604 +       } while (0)
14605 +
14606 +#else
14607 +#warning duplicate inclusion
14608 +#endif
14609 diff -NurpP --minimal linux-2.6.29.1/include/linux/vs_tag.h linux-2.6.29.1-vs2.3.0.36.9-pre5/include/linux/vs_tag.h
14610 --- linux-2.6.29.1/include/linux/vs_tag.h       1970-01-01 01:00:00.000000000 +0100
14611 +++ linux-2.6.29.1-vs2.3.0.36.9-pre5/include/linux/vs_tag.h     2009-02-22 22:54:26.000000000 +0100
14612 @@ -0,0 +1,47 @@
14613 +#ifndef _VS_TAG_H
14614 +#define _VS_TAG_H
14615 +
14616 +#include <linux/vserver/tag.h>
14617 +
14618 +/* check conditions */
14619 +
14620 +#define DX_ADMIN       0x0001
14621 +#define DX_WATCH       0x0002
14622 +#define DX_HOSTID      0x0008
14623 +
14624 +#define DX_IDENT       0x0010
14625 +
14626 +#define DX_ARG_MASK    0x0010
14627 +
14628 +
14629 +#define dx_task_tag(t) ((t)->tag)
14630 +
14631 +#define dx_current_tag() dx_task_tag(current)
14632 +
14633 +#define dx_check(c, m) __dx_check(dx_current_tag(), c, m)
14634 +
14635 +#define dx_weak_check(c, m)    ((m) ? dx_check(c, m) : 1)
14636 +
14637 +
14638 +/*
14639 + * check current context for ADMIN/WATCH and
14640 + * optionally against supplied argument
14641 + */
14642 +static inline int __dx_check(tag_t cid, tag_t id, unsigned int mode)
14643 +{
14644 +       if (mode & DX_ARG_MASK) {
14645 +               if ((mode & DX_IDENT) && (id == cid))
14646 +                       return 1;
14647 +       }
14648 +       return (((mode & DX_ADMIN) && (cid == 0)) ||
14649 +               ((mode & DX_WATCH) && (cid == 1)) ||
14650 +               ((mode & DX_HOSTID) && (id == 0)));
14651 +}
14652 +
14653 +struct inode;
14654 +int dx_permission(struct inode *inode, int mask);
14655 +
14656 +
14657 +#else
14658 +#warning duplicate inclusion
14659 +#endif
14660 diff -NurpP --minimal linux-2.6.29.1/include/linux/vs_time.h linux-2.6.29.1-vs2.3.0.36.9-pre5/include/linux/vs_time.h
14661 --- linux-2.6.29.1/include/linux/vs_time.h      1970-01-01 01:00:00.000000000 +0100
14662 +++ linux-2.6.29.1-vs2.3.0.36.9-pre5/include/linux/vs_time.h    2009-02-22 22:54:26.000000000 +0100
14663 @@ -0,0 +1,19 @@
14664 +#ifndef _VS_TIME_H
14665 +#define _VS_TIME_H
14666 +
14667 +
14668 +/* time faking stuff */
14669 +
14670 +#ifdef CONFIG_VSERVER_VTIME
14671 +
14672 +extern void vx_gettimeofday(struct timeval *tv);
14673 +extern int vx_settimeofday(struct timespec *ts);
14674 +
14675 +#else
14676 +#define        vx_gettimeofday(t)      do_gettimeofday(t)
14677 +#define        vx_settimeofday(t)      do_settimeofday(t)
14678 +#endif
14679 +
14680 +#else
14681 +#warning duplicate inclusion
14682 +#endif
14683 diff -NurpP --minimal linux-2.6.29.1/include/net/addrconf.h linux-2.6.29.1-vs2.3.0.36.9-pre5/include/net/addrconf.h
14684 --- linux-2.6.29.1/include/net/addrconf.h       2008-12-25 00:26:37.000000000 +0100
14685 +++ linux-2.6.29.1-vs2.3.0.36.9-pre5/include/net/addrconf.h     2009-02-22 22:54:26.000000000 +0100
14686 @@ -84,7 +84,8 @@ extern int                    ipv6_dev_get_saddr(struct n
14687                                                struct net_device *dev,
14688                                                const struct in6_addr *daddr,
14689                                                unsigned int srcprefs,
14690 -                                              struct in6_addr *saddr);
14691 +                                              struct in6_addr *saddr,
14692 +                                              struct nx_info *nxi);
14693  extern int                     ipv6_get_lladdr(struct net_device *dev,
14694                                                 struct in6_addr *addr,
14695                                                 unsigned char banned_flags);
14696 diff -NurpP --minimal linux-2.6.29.1/include/net/af_unix.h linux-2.6.29.1-vs2.3.0.36.9-pre5/include/net/af_unix.h
14697 --- linux-2.6.29.1/include/net/af_unix.h        2008-12-25 00:26:37.000000000 +0100
14698 +++ linux-2.6.29.1-vs2.3.0.36.9-pre5/include/net/af_unix.h      2009-02-22 22:54:26.000000000 +0100
14699 @@ -4,6 +4,7 @@
14700  #include <linux/socket.h>
14701  #include <linux/un.h>
14702  #include <linux/mutex.h>
14703 +#include <linux/vs_base.h>
14704  #include <net/sock.h>
14705  
14706  extern void unix_inflight(struct file *fp);
14707 diff -NurpP --minimal linux-2.6.29.1/include/net/inet_timewait_sock.h linux-2.6.29.1-vs2.3.0.36.9-pre5/include/net/inet_timewait_sock.h
14708 --- linux-2.6.29.1/include/net/inet_timewait_sock.h     2009-03-24 14:22:44.000000000 +0100
14709 +++ linux-2.6.29.1-vs2.3.0.36.9-pre5/include/net/inet_timewait_sock.h   2009-03-24 14:48:36.000000000 +0100
14710 @@ -15,15 +15,14 @@
14711  #ifndef _INET_TIMEWAIT_SOCK_
14712  #define _INET_TIMEWAIT_SOCK_
14713  
14714 +// #include <net/inet_sock.h>
14715 +#include <net/sock.h>
14716  
14717  #include <linux/list.h>
14718  #include <linux/module.h>
14719  #include <linux/timer.h>
14720  #include <linux/types.h>
14721  #include <linux/workqueue.h>
14722 -
14723 -#include <net/inet_sock.h>
14724 -#include <net/sock.h>
14725  #include <net/tcp_states.h>
14726  #include <net/timewait_sock.h>
14727  
14728 @@ -116,6 +115,10 @@ struct inet_timewait_sock {
14729  #define tw_hash                        __tw_common.skc_hash
14730  #define tw_prot                        __tw_common.skc_prot
14731  #define tw_net                 __tw_common.skc_net
14732 +#define tw_xid                 __tw_common.skc_xid
14733 +#define tw_vx_info             __tw_common.skc_vx_info
14734 +#define tw_nid                 __tw_common.skc_nid
14735 +#define tw_nx_info             __tw_common.skc_nx_info
14736         int                     tw_timeout;
14737         volatile unsigned char  tw_substate;
14738         /* 3 bits hole, try to pack */
14739 diff -NurpP --minimal linux-2.6.29.1/include/net/route.h linux-2.6.29.1-vs2.3.0.36.9-pre5/include/net/route.h
14740 --- linux-2.6.29.1/include/net/route.h  2008-12-25 00:26:37.000000000 +0100
14741 +++ linux-2.6.29.1-vs2.3.0.36.9-pre5/include/net/route.h        2009-02-22 22:54:26.000000000 +0100
14742 @@ -135,6 +135,9 @@ static inline void ip_rt_put(struct rtab
14743                 dst_release(&rt->u.dst);
14744  }
14745  
14746 +#include <linux/vs_base.h>
14747 +#include <linux/vs_inet.h>
14748 +
14749  #define IPTOS_RT_MASK  (IPTOS_TOS_MASK & ~3)
14750  
14751  extern const __u8 ip_tos2prio[16];
14752 @@ -144,6 +147,9 @@ static inline char rt_tos2priority(u8 to
14753         return ip_tos2prio[IPTOS_TOS(tos)>>1];
14754  }
14755  
14756 +extern int ip_v4_find_src(struct net *net, struct nx_info *,
14757 +       struct rtable **, struct flowi *);
14758 +
14759  static inline int ip_route_connect(struct rtable **rp, __be32 dst,
14760                                    __be32 src, u32 tos, int oif, u8 protocol,
14761                                    __be16 sport, __be16 dport, struct sock *sk,
14762 @@ -161,11 +167,24 @@ static inline int ip_route_connect(struc
14763  
14764         int err;
14765         struct net *net = sock_net(sk);
14766 +       struct nx_info *nx_info = current->nx_info;
14767  
14768         if (inet_sk(sk)->transparent)
14769                 fl.flags |= FLOWI_FLAG_ANYSRC;
14770  
14771 -       if (!dst || !src) {
14772 +       if (sk)
14773 +               nx_info = sk->sk_nx_info;
14774 +
14775 +       vxdprintk(VXD_CBIT(net, 4),
14776 +               "ip_route_connect(%p) %p,%p;%lx",
14777 +               sk, nx_info, sk->sk_socket,
14778 +               (sk->sk_socket?sk->sk_socket->flags:0));
14779 +
14780 +       err = ip_v4_find_src(net, nx_info, rp, &fl);
14781 +       if (err)
14782 +               return err;
14783 +
14784 +       if (!fl.fl4_dst || !fl.fl4_src) {
14785                 err = __ip_route_output_key(net, rp, &fl);
14786                 if (err)
14787                         return err;
14788 diff -NurpP --minimal linux-2.6.29.1/include/net/sock.h linux-2.6.29.1-vs2.3.0.36.9-pre5/include/net/sock.h
14789 --- linux-2.6.29.1/include/net/sock.h   2009-03-24 14:22:44.000000000 +0100
14790 +++ linux-2.6.29.1-vs2.3.0.36.9-pre5/include/net/sock.h 2009-03-24 14:48:36.000000000 +0100
14791 @@ -134,6 +134,10 @@ struct sock_common {
14792  #ifdef CONFIG_NET_NS
14793         struct net              *skc_net;
14794  #endif
14795 +       xid_t                   skc_xid;
14796 +       struct vx_info          *skc_vx_info;
14797 +       nid_t                   skc_nid;
14798 +       struct nx_info          *skc_nx_info;
14799  };
14800  
14801  /**
14802 @@ -218,6 +222,10 @@ struct sock {
14803  #define sk_hash                        __sk_common.skc_hash
14804  #define sk_prot                        __sk_common.skc_prot
14805  #define sk_net                 __sk_common.skc_net
14806 +#define sk_xid                 __sk_common.skc_xid
14807 +#define sk_vx_info             __sk_common.skc_vx_info
14808 +#define sk_nid                 __sk_common.skc_nid
14809 +#define sk_nx_info             __sk_common.skc_nx_info
14810         unsigned char           sk_shutdown : 2,
14811                                 sk_no_check : 2,
14812                                 sk_userlocks : 4;
14813 diff -NurpP --minimal linux-2.6.29.1/init/main.c linux-2.6.29.1-vs2.3.0.36.9-pre5/init/main.c
14814 --- linux-2.6.29.1/init/main.c  2009-03-24 14:22:44.000000000 +0100
14815 +++ linux-2.6.29.1-vs2.3.0.36.9-pre5/init/main.c        2009-03-24 17:22:37.000000000 +0100
14816 @@ -64,6 +64,7 @@
14817  #include <linux/ftrace.h>
14818  #include <linux/async.h>
14819  #include <trace/boot.h>
14820 +#include <linux/vserver/percpu.h>
14821  
14822  #include <asm/io.h>
14823  #include <asm/bugs.h>
14824 @@ -381,12 +382,14 @@ EXPORT_SYMBOL(__per_cpu_offset);
14825  
14826  static void __init setup_per_cpu_areas(void)
14827  {
14828 -       unsigned long size, i;
14829 +       unsigned long size, vspc, i;
14830         char *ptr;
14831         unsigned long nr_possible_cpus = num_possible_cpus();
14832  
14833 +       vspc = PERCPU_PERCTX * CONFIG_VSERVER_CONTEXTS;
14834 +
14835         /* Copy section for each CPU (we discard the original) */
14836 -       size = ALIGN(PERCPU_ENOUGH_ROOM, PAGE_SIZE);
14837 +       size = ALIGN(PERCPU_ENOUGH_ROOM + vspc, PAGE_SIZE);
14838         ptr = alloc_bootmem_pages(size * nr_possible_cpus);
14839  
14840         for_each_possible_cpu(i) {
14841 diff -NurpP --minimal linux-2.6.29.1/ipc/mqueue.c linux-2.6.29.1-vs2.3.0.36.9-pre5/ipc/mqueue.c
14842 --- linux-2.6.29.1/ipc/mqueue.c 2009-03-24 14:22:44.000000000 +0100
14843 +++ linux-2.6.29.1-vs2.3.0.36.9-pre5/ipc/mqueue.c       2009-03-24 17:24:19.000000000 +0100
14844 @@ -31,6 +31,8 @@
14845  #include <linux/mutex.h>
14846  #include <linux/nsproxy.h>
14847  #include <linux/pid.h>
14848 +#include <linux/vs_context.h>
14849 +#include <linux/vs_limit.h>
14850  
14851  #include <net/sock.h>
14852  #include "util.h"
14853 @@ -79,6 +81,7 @@ struct mqueue_inode_info {
14854         struct sigevent notify;
14855         struct pid* notify_owner;
14856         struct user_struct *user;       /* user who created, for accounting */
14857 +       struct vx_info *vxi;
14858         struct sock *notify_sock;
14859         struct sk_buff *notify_cookie;
14860  
14861 @@ -126,6 +129,7 @@ static struct inode *mqueue_get_inode(st
14862                 if (S_ISREG(mode)) {
14863                         struct mqueue_inode_info *info;
14864                         struct task_struct *p = current;
14865 +                       struct vx_info *vxi = p->vx_info;
14866                         unsigned long mq_bytes, mq_msg_tblsz;
14867  
14868                         inode->i_fop = &mqueue_file_operations;
14869 @@ -140,6 +144,7 @@ static struct inode *mqueue_get_inode(st
14870                         info->notify_owner = NULL;
14871                         info->qsize = 0;
14872                         info->user = NULL;      /* set when all is ok */
14873 +                       info->vxi = NULL;
14874                         memset(&info->attr, 0, sizeof(info->attr));
14875                         info->attr.mq_maxmsg = msg_max;
14876                         info->attr.mq_msgsize = msgsize_max;
14877 @@ -154,22 +159,26 @@ static struct inode *mqueue_get_inode(st
14878                         spin_lock(&mq_lock);
14879                         if (u->mq_bytes + mq_bytes < u->mq_bytes ||
14880                             u->mq_bytes + mq_bytes >
14881 -                           p->signal->rlim[RLIMIT_MSGQUEUE].rlim_cur) {
14882 +                           p->signal->rlim[RLIMIT_MSGQUEUE].rlim_cur ||
14883 +                           !vx_ipcmsg_avail(vxi, mq_bytes)) {
14884                                 spin_unlock(&mq_lock);
14885                                 goto out_inode;
14886                         }
14887                         u->mq_bytes += mq_bytes;
14888 +                       vx_ipcmsg_add(vxi, u, mq_bytes);
14889                         spin_unlock(&mq_lock);
14890  
14891                         info->messages = kmalloc(mq_msg_tblsz, GFP_KERNEL);
14892                         if (!info->messages) {
14893                                 spin_lock(&mq_lock);
14894                                 u->mq_bytes -= mq_bytes;
14895 +                               vx_ipcmsg_sub(vxi, u, mq_bytes);
14896                                 spin_unlock(&mq_lock);
14897                                 goto out_inode;
14898                         }
14899                         /* all is ok */
14900                         info->user = get_uid(u);
14901 +                       info->vxi = get_vx_info(vxi);
14902                 } else if (S_ISDIR(mode)) {
14903                         inc_nlink(inode);
14904                         /* Some things misbehave if size == 0 on a directory */
14905 @@ -260,10 +269,14 @@ static void mqueue_delete_inode(struct i
14906                    (info->attr.mq_maxmsg * info->attr.mq_msgsize));
14907         user = info->user;
14908         if (user) {
14909 +               struct vx_info *vxi = info->vxi;
14910 +
14911                 spin_lock(&mq_lock);
14912                 user->mq_bytes -= mq_bytes;
14913 +               vx_ipcmsg_sub(vxi, user, mq_bytes);
14914                 queues_count--;
14915                 spin_unlock(&mq_lock);
14916 +               put_vx_info(vxi);
14917                 free_uid(user);
14918         }
14919  }
14920 diff -NurpP --minimal linux-2.6.29.1/ipc/msg.c linux-2.6.29.1-vs2.3.0.36.9-pre5/ipc/msg.c
14921 --- linux-2.6.29.1/ipc/msg.c    2009-03-24 14:22:44.000000000 +0100
14922 +++ linux-2.6.29.1-vs2.3.0.36.9-pre5/ipc/msg.c  2009-02-22 22:54:26.000000000 +0100
14923 @@ -38,6 +38,7 @@
14924  #include <linux/rwsem.h>
14925  #include <linux/nsproxy.h>
14926  #include <linux/ipc_namespace.h>
14927 +#include <linux/vs_base.h>
14928  
14929  #include <asm/current.h>
14930  #include <asm/uaccess.h>
14931 @@ -190,6 +191,7 @@ static int newque(struct ipc_namespace *
14932  
14933         msq->q_perm.mode = msgflg & S_IRWXUGO;
14934         msq->q_perm.key = key;
14935 +       msq->q_perm.xid = vx_current_xid();
14936  
14937         msq->q_perm.security = NULL;
14938         retval = security_msg_queue_alloc(msq);
14939 diff -NurpP --minimal linux-2.6.29.1/ipc/namespace.c linux-2.6.29.1-vs2.3.0.36.9-pre5/ipc/namespace.c
14940 --- linux-2.6.29.1/ipc/namespace.c      2008-12-25 00:26:37.000000000 +0100
14941 +++ linux-2.6.29.1-vs2.3.0.36.9-pre5/ipc/namespace.c    2009-02-22 22:54:26.000000000 +0100
14942 @@ -9,6 +9,8 @@
14943  #include <linux/rcupdate.h>
14944  #include <linux/nsproxy.h>
14945  #include <linux/slab.h>
14946 +#include <linux/vs_base.h>
14947 +#include <linux/vserver/global.h>
14948  
14949  #include "util.h"
14950  
14951 @@ -35,6 +37,7 @@ static struct ipc_namespace *clone_ipc_n
14952         register_ipcns_notifier(ns);
14953  
14954         kref_init(&ns->kref);
14955 +       atomic_inc(&vs_global_ipc_ns);
14956         return ns;
14957  }
14958  
14959 @@ -101,6 +104,7 @@ void free_ipc_ns(struct kref *kref)
14960         sem_exit_ns(ns);
14961         msg_exit_ns(ns);
14962         shm_exit_ns(ns);
14963 +       atomic_dec(&vs_global_ipc_ns);
14964         kfree(ns);
14965         atomic_dec(&nr_ipc_ns);
14966  
14967 diff -NurpP --minimal linux-2.6.29.1/ipc/sem.c linux-2.6.29.1-vs2.3.0.36.9-pre5/ipc/sem.c
14968 --- linux-2.6.29.1/ipc/sem.c    2009-03-24 14:22:44.000000000 +0100
14969 +++ linux-2.6.29.1-vs2.3.0.36.9-pre5/ipc/sem.c  2009-03-31 23:31:33.000000000 +0200
14970 @@ -83,6 +83,8 @@
14971  #include <linux/rwsem.h>
14972  #include <linux/nsproxy.h>
14973  #include <linux/ipc_namespace.h>
14974 +#include <linux/vs_base.h>
14975 +#include <linux/vs_limit.h>
14976  
14977  #include <asm/uaccess.h>
14978  #include "util.h"
14979 @@ -255,6 +257,7 @@ static int newary(struct ipc_namespace *
14980  
14981         sma->sem_perm.mode = (semflg & S_IRWXUGO);
14982         sma->sem_perm.key = key;
14983 +       sma->sem_perm.xid = vx_current_xid();
14984  
14985         sma->sem_perm.security = NULL;
14986         retval = security_sem_alloc(sma);
14987 @@ -270,6 +273,9 @@ static int newary(struct ipc_namespace *
14988                 return id;
14989         }
14990         ns->used_sems += nsems;
14991 +       /* FIXME: obsoleted? */
14992 +       vx_semary_inc(sma);
14993 +       vx_nsems_add(sma, nsems);
14994  
14995         sma->sem_base = (struct sem *) &sma[1];
14996         INIT_LIST_HEAD(&sma->sem_pending);
14997 @@ -546,6 +552,9 @@ static void freeary(struct ipc_namespace
14998         sem_unlock(sma);
14999  
15000         ns->used_sems -= sma->sem_nsems;
15001 +       /* FIXME: obsoleted? */
15002 +       vx_nsems_sub(sma, sma->sem_nsems);
15003 +       vx_semary_dec(sma);
15004         security_sem_free(sma);
15005         ipc_rcu_putref(sma);
15006  }
15007 diff -NurpP --minimal linux-2.6.29.1/ipc/shm.c linux-2.6.29.1-vs2.3.0.36.9-pre5/ipc/shm.c
15008 --- linux-2.6.29.1/ipc/shm.c    2009-03-24 14:22:44.000000000 +0100
15009 +++ linux-2.6.29.1-vs2.3.0.36.9-pre5/ipc/shm.c  2009-03-24 14:48:36.000000000 +0100
15010 @@ -39,6 +39,8 @@
15011  #include <linux/nsproxy.h>
15012  #include <linux/mount.h>
15013  #include <linux/ipc_namespace.h>
15014 +#include <linux/vs_context.h>
15015 +#include <linux/vs_limit.h>
15016  
15017  #include <asm/uaccess.h>
15018  
15019 @@ -168,7 +170,12 @@ static void shm_open(struct vm_area_stru
15020   */
15021  static void shm_destroy(struct ipc_namespace *ns, struct shmid_kernel *shp)
15022  {
15023 -       ns->shm_tot -= (shp->shm_segsz + PAGE_SIZE - 1) >> PAGE_SHIFT;
15024 +       struct vx_info *vxi = lookup_vx_info(shp->shm_perm.xid);
15025 +       int numpages = (shp->shm_segsz + PAGE_SIZE - 1) >> PAGE_SHIFT;
15026 +
15027 +       vx_ipcshm_sub(vxi, shp, numpages);
15028 +       ns->shm_tot -= numpages;
15029 +
15030         shm_rmid(ns, shp);
15031         shm_unlock(shp);
15032         if (!is_file_hugepages(shp->shm_file))
15033 @@ -178,6 +185,7 @@ static void shm_destroy(struct ipc_names
15034                                                 shp->mlock_user);
15035         fput (shp->shm_file);
15036         security_shm_free(shp);
15037 +       put_vx_info(vxi);
15038         ipc_rcu_putref(shp);
15039  }
15040  
15041 @@ -348,11 +356,15 @@ static int newseg(struct ipc_namespace *
15042         if (ns->shm_tot + numpages > ns->shm_ctlall)
15043                 return -ENOSPC;
15044  
15045 +       if (!vx_ipcshm_avail(current->vx_info, numpages))
15046 +               return -ENOSPC;
15047 +
15048         shp = ipc_rcu_alloc(sizeof(*shp));
15049         if (!shp)
15050                 return -ENOMEM;
15051  
15052         shp->shm_perm.key = key;
15053 +       shp->shm_perm.xid = vx_current_xid();
15054         shp->shm_perm.mode = (shmflg & S_IRWXUGO);
15055         shp->mlock_user = NULL;
15056  
15057 @@ -406,6 +418,7 @@ static int newseg(struct ipc_namespace *
15058         ns->shm_tot += numpages;
15059         error = shp->shm_perm.id;
15060         shm_unlock(shp);
15061 +       vx_ipcshm_add(current->vx_info, key, numpages);
15062         return error;
15063  
15064  no_id:
15065 diff -NurpP --minimal linux-2.6.29.1/kernel/capability.c linux-2.6.29.1-vs2.3.0.36.9-pre5/kernel/capability.c
15066 --- linux-2.6.29.1/kernel/capability.c  2009-03-24 14:22:44.000000000 +0100
15067 +++ linux-2.6.29.1-vs2.3.0.36.9-pre5/kernel/capability.c        2009-03-24 17:27:28.000000000 +0100
15068 @@ -14,6 +14,7 @@
15069  #include <linux/security.h>
15070  #include <linux/syscalls.h>
15071  #include <linux/pid_namespace.h>
15072 +#include <linux/vs_context.h>
15073  #include <asm/uaccess.h>
15074  #include "cred-internals.h"
15075  
15076 @@ -122,6 +123,7 @@ static int cap_validate_magic(cap_user_h
15077         return 0;
15078  }
15079  
15080 +
15081  /*
15082   * The only thing that can change the capabilities of the current
15083   * process is the current process. As such, we can't be in this code
15084 @@ -289,6 +291,8 @@ error:
15085         return ret;
15086  }
15087  
15088 +#include <linux/vserver/base.h>
15089 +
15090  /**
15091   * capable - Determine if the current task has a superior capability in effect
15092   * @cap: The capability to be tested for
15093 @@ -301,6 +305,9 @@ error:
15094   */
15095  int capable(int cap)
15096  {
15097 +       /* here for now so we don't require task locking */
15098 +       if (vs_check_bit(VXC_CAP_MASK, cap) && !vx_mcaps(1L << cap))
15099 +               return 0;
15100         if (unlikely(!cap_valid(cap))) {
15101                 printk(KERN_CRIT "capable() called with invalid cap=%u\n", cap);
15102                 BUG();
15103 diff -NurpP --minimal linux-2.6.29.1/kernel/compat.c linux-2.6.29.1-vs2.3.0.36.9-pre5/kernel/compat.c
15104 --- linux-2.6.29.1/kernel/compat.c      2009-03-24 14:22:44.000000000 +0100
15105 +++ linux-2.6.29.1-vs2.3.0.36.9-pre5/kernel/compat.c    2009-03-24 14:48:36.000000000 +0100
15106 @@ -891,7 +891,7 @@ asmlinkage long compat_sys_time(compat_t
15107         compat_time_t i;
15108         struct timeval tv;
15109  
15110 -       do_gettimeofday(&tv);
15111 +       vx_gettimeofday(&tv);
15112         i = tv.tv_sec;
15113  
15114         if (tloc) {
15115 @@ -916,7 +916,7 @@ asmlinkage long compat_sys_stime(compat_
15116         if (err)
15117                 return err;
15118  
15119 -       do_settimeofday(&tv);
15120 +       vx_settimeofday(&tv);
15121         return 0;
15122  }
15123  
15124 diff -NurpP --minimal linux-2.6.29.1/kernel/exit.c linux-2.6.29.1-vs2.3.0.36.9-pre5/kernel/exit.c
15125 --- linux-2.6.29.1/kernel/exit.c        2009-03-24 14:22:44.000000000 +0100
15126 +++ linux-2.6.29.1-vs2.3.0.36.9-pre5/kernel/exit.c      2009-03-24 17:28:40.000000000 +0100
15127 @@ -47,6 +47,11 @@
15128  #include <linux/task_io_accounting_ops.h>
15129  #include <linux/tracehook.h>
15130  #include <linux/init_task.h>
15131 +#include <linux/vs_limit.h>
15132 +#include <linux/vs_context.h>
15133 +#include <linux/vs_network.h>
15134 +#include <linux/vs_pid.h>
15135 +#include <linux/vserver/global.h>
15136  #include <trace/sched.h>
15137  
15138  #include <asm/uaccess.h>
15139 @@ -502,9 +507,11 @@ static void close_files(struct files_str
15140                                         filp_close(file, files);
15141                                         cond_resched();
15142                                 }
15143 +                               vx_openfd_dec(i);
15144                         }
15145                         i++;
15146                         set >>= 1;
15147 +                       cond_resched();
15148                 }
15149         }
15150  }
15151 @@ -571,6 +578,7 @@ void put_fs_struct(struct fs_struct *fs)
15152         if (atomic_dec_and_test(&fs->count)) {
15153                 path_put(&fs->root);
15154                 path_put(&fs->pwd);
15155 +               atomic_dec(&vs_global_fs);
15156                 kmem_cache_free(fs_cachep, fs);
15157         }
15158  }
15159 @@ -1122,10 +1130,15 @@ NORET_TYPE void do_exit(long code)
15160         if (tsk->splice_pipe)
15161                 __free_pipe_info(tsk->splice_pipe);
15162  
15163 +       /* needs to stay after exit_notify() */
15164 +       exit_vx_info(tsk, code);
15165 +       exit_nx_info(tsk);
15166 +
15167         preempt_disable();
15168         /* causes final put_task_struct in finish_task_switch(). */
15169         tsk->state = TASK_DEAD;
15170         schedule();
15171 +       printk("bad task: %p [%lx]\n", current, current->state);
15172         BUG();
15173         /* Avoid "noreturn function does return".  */
15174         for (;;)
15175 diff -NurpP --minimal linux-2.6.29.1/kernel/fork.c linux-2.6.29.1-vs2.3.0.36.9-pre5/kernel/fork.c
15176 --- linux-2.6.29.1/kernel/fork.c        2009-03-24 14:22:44.000000000 +0100
15177 +++ linux-2.6.29.1-vs2.3.0.36.9-pre5/kernel/fork.c      2009-03-24 17:31:42.000000000 +0100
15178 @@ -60,6 +60,11 @@
15179  #include <linux/tty.h>
15180  #include <linux/proc_fs.h>
15181  #include <linux/blkdev.h>
15182 +#include <linux/vs_context.h>
15183 +#include <linux/vs_network.h>
15184 +#include <linux/vs_limit.h>
15185 +#include <linux/vs_memory.h>
15186 +#include <linux/vserver/global.h>
15187  #include <trace/sched.h>
15188  
15189  #include <asm/pgtable.h>
15190 @@ -140,6 +145,8 @@ void free_task(struct task_struct *tsk)
15191         prop_local_destroy_single(&tsk->dirties);
15192         free_thread_info(tsk->stack);
15193         rt_mutex_debug_task_free(tsk);
15194 +       clr_vx_info(&tsk->vx_info);
15195 +       clr_nx_info(&tsk->nx_info);
15196         ftrace_graph_exit_task(tsk);
15197         free_task_struct(tsk);
15198  }
15199 @@ -279,6 +286,8 @@ static int dup_mmap(struct mm_struct *mm
15200         mm->free_area_cache = oldmm->mmap_base;
15201         mm->cached_hole_size = ~0UL;
15202         mm->map_count = 0;
15203 +       __set_mm_counter(mm, file_rss, 0);
15204 +       __set_mm_counter(mm, anon_rss, 0);
15205         cpus_clear(mm->cpu_vm_mask);
15206         mm->mm_rb = RB_ROOT;
15207         rb_link = &mm->mm_rb.rb_node;
15208 @@ -290,7 +299,7 @@ static int dup_mmap(struct mm_struct *mm
15209  
15210                 if (mpnt->vm_flags & VM_DONTCOPY) {
15211                         long pages = vma_pages(mpnt);
15212 -                       mm->total_vm -= pages;
15213 +                       vx_vmpages_sub(mm, pages);
15214                         vm_stat_account(mm, mpnt->vm_flags, mpnt->vm_file,
15215                                                                 -pages);
15216                         continue;
15217 @@ -423,8 +432,8 @@ static struct mm_struct * mm_init(struct
15218         mm->flags = (current->mm) ? current->mm->flags : default_dump_filter;
15219         mm->core_state = NULL;
15220         mm->nr_ptes = 0;
15221 -       set_mm_counter(mm, file_rss, 0);
15222 -       set_mm_counter(mm, anon_rss, 0);
15223 +       __set_mm_counter(mm, file_rss, 0);
15224 +       __set_mm_counter(mm, anon_rss, 0);
15225         spin_lock_init(&mm->page_table_lock);
15226         spin_lock_init(&mm->ioctx_lock);
15227         INIT_HLIST_HEAD(&mm->ioctx_list);
15228 @@ -435,6 +444,7 @@ static struct mm_struct * mm_init(struct
15229         if (likely(!mm_alloc_pgd(mm))) {
15230                 mm->def_flags = 0;
15231                 mmu_notifier_mm_init(mm);
15232 +               set_vx_info(&mm->mm_vx_info, p->vx_info);
15233                 return mm;
15234         }
15235  
15236 @@ -468,6 +478,7 @@ void __mmdrop(struct mm_struct *mm)
15237         mm_free_pgd(mm);
15238         destroy_context(mm);
15239         mmu_notifier_mm_destroy(mm);
15240 +       clr_vx_info(&mm->mm_vx_info);
15241         free_mm(mm);
15242  }
15243  EXPORT_SYMBOL_GPL(__mmdrop);
15244 @@ -594,6 +605,7 @@ struct mm_struct *dup_mm(struct task_str
15245                 goto fail_nomem;
15246  
15247         memcpy(mm, oldmm, sizeof(*mm));
15248 +       mm->mm_vx_info = NULL;
15249  
15250         /* Initializing for Swap token stuff */
15251         mm->token_priority = 0;
15252 @@ -627,6 +639,7 @@ fail_nocontext:
15253          * If init_new_context() failed, we cannot use mmput() to free the mm
15254          * because it calls destroy_context()
15255          */
15256 +       clr_vx_info(&mm->mm_vx_info);
15257         mm_free_pgd(mm);
15258         free_mm(mm);
15259         return NULL;
15260 @@ -690,6 +703,7 @@ static struct fs_struct *__copy_fs_struc
15261                 fs->pwd = old->pwd;
15262                 path_get(&old->pwd);
15263                 read_unlock(&old->lock);
15264 +               atomic_inc(&vs_global_fs);
15265         }
15266         return fs;
15267  }
15268 @@ -955,6 +969,8 @@ static struct task_struct *copy_process(
15269         int retval;
15270         struct task_struct *p;
15271         int cgroup_callbacks_done = 0;
15272 +       struct vx_info *vxi;
15273 +       struct nx_info *nxi;
15274  
15275         if ((clone_flags & (CLONE_NEWNS|CLONE_FS)) == (CLONE_NEWNS|CLONE_FS))
15276                 return ERR_PTR(-EINVAL);
15277 @@ -989,12 +1005,28 @@ static struct task_struct *copy_process(
15278         DEBUG_LOCKS_WARN_ON(!p->hardirqs_enabled);
15279         DEBUG_LOCKS_WARN_ON(!p->softirqs_enabled);
15280  #endif
15281 +       init_vx_info(&p->vx_info, current->vx_info);
15282 +       init_nx_info(&p->nx_info, current->nx_info);
15283 +
15284 +       /* check vserver memory */
15285 +       if (p->mm && !(clone_flags & CLONE_VM)) {
15286 +               if (vx_vmpages_avail(p->mm, p->mm->total_vm))
15287 +                       vx_pages_add(p->vx_info, RLIMIT_AS, p->mm->total_vm);
15288 +               else
15289 +                       goto bad_fork_free;
15290 +       }
15291 +       if (p->mm && vx_flags(VXF_FORK_RSS, 0)) {
15292 +               if (!vx_rss_avail(p->mm, get_mm_counter(p->mm, file_rss)))
15293 +                       goto bad_fork_cleanup_vm;
15294 +       }
15295         retval = -EAGAIN;
15296 +       if (!vx_nproc_avail(1))
15297 +               goto bad_fork_cleanup_vm;
15298         if (atomic_read(&p->real_cred->user->processes) >=
15299                         p->signal->rlim[RLIMIT_NPROC].rlim_cur) {
15300                 if (!capable(CAP_SYS_ADMIN) && !capable(CAP_SYS_RESOURCE) &&
15301                     p->real_cred->user != INIT_USER)
15302 -                       goto bad_fork_free;
15303 +                       goto bad_fork_cleanup_vm;
15304         }
15305  
15306         retval = copy_creds(p, clone_flags);
15307 @@ -1271,6 +1303,18 @@ static struct task_struct *copy_process(
15308  
15309         total_forks++;
15310         spin_unlock(&current->sighand->siglock);
15311 +
15312 +       /* p is copy of current */
15313 +       vxi = p->vx_info;
15314 +       if (vxi) {
15315 +               claim_vx_info(vxi, p);
15316 +               atomic_inc(&vxi->cvirt.nr_threads);
15317 +               atomic_inc(&vxi->cvirt.total_forks);
15318 +               vx_nproc_inc(p);
15319 +       }
15320 +       nxi = p->nx_info;
15321 +       if (nxi)
15322 +               claim_nx_info(nxi, p);
15323         write_unlock_irq(&tasklist_lock);
15324         proc_fork_connector(p);
15325         cgroup_post_fork(p);
15326 @@ -1315,6 +1359,9 @@ bad_fork_cleanup_count:
15327         atomic_dec(&p->cred->user->processes);
15328         put_cred(p->real_cred);
15329         put_cred(p->cred);
15330 +bad_fork_cleanup_vm:
15331 +       if (p->mm && !(clone_flags & CLONE_VM))
15332 +               vx_pages_sub(p->vx_info, RLIMIT_AS, p->mm->total_vm);
15333  bad_fork_free:
15334         free_task(p);
15335  fork_out:
15336 diff -NurpP --minimal linux-2.6.29.1/kernel/kthread.c linux-2.6.29.1-vs2.3.0.36.9-pre5/kernel/kthread.c
15337 --- linux-2.6.29.1/kernel/kthread.c     2009-03-24 14:22:44.000000000 +0100
15338 +++ linux-2.6.29.1-vs2.3.0.36.9-pre5/kernel/kthread.c   2009-03-24 14:48:36.000000000 +0100
15339 @@ -13,6 +13,7 @@
15340  #include <linux/file.h>
15341  #include <linux/module.h>
15342  #include <linux/mutex.h>
15343 +#include <linux/vs_pid.h>
15344  #include <trace/sched.h>
15345  
15346  #define KTHREAD_NICE_LEVEL (-5)
15347 @@ -102,7 +103,7 @@ static void create_kthread(struct kthrea
15348                 struct sched_param param = { .sched_priority = 0 };
15349                 wait_for_completion(&create->started);
15350                 read_lock(&tasklist_lock);
15351 -               create->result = find_task_by_pid_ns(pid, &init_pid_ns);
15352 +               create->result = find_task_by_real_pid(pid);
15353                 read_unlock(&tasklist_lock);
15354                 /*
15355                  * root may have changed our (kthreadd's) priority or CPU mask.
15356 diff -NurpP --minimal linux-2.6.29.1/kernel/Makefile linux-2.6.29.1-vs2.3.0.36.9-pre5/kernel/Makefile
15357 --- linux-2.6.29.1/kernel/Makefile      2009-03-24 14:22:44.000000000 +0100
15358 +++ linux-2.6.29.1-vs2.3.0.36.9-pre5/kernel/Makefile    2009-03-24 14:48:36.000000000 +0100
15359 @@ -22,6 +22,7 @@ CFLAGS_REMOVE_cgroup-debug.o = -pg
15360  CFLAGS_REMOVE_sched_clock.o = -pg
15361  endif
15362  
15363 +obj-y += vserver/
15364  obj-$(CONFIG_FREEZER) += freezer.o
15365  obj-$(CONFIG_PROFILING) += profile.o
15366  obj-$(CONFIG_SYSCTL_SYSCALL_CHECK) += sysctl_check.o
15367 diff -NurpP --minimal linux-2.6.29.1/kernel/nsproxy.c linux-2.6.29.1-vs2.3.0.36.9-pre5/kernel/nsproxy.c
15368 --- linux-2.6.29.1/kernel/nsproxy.c     2009-03-24 14:22:44.000000000 +0100
15369 +++ linux-2.6.29.1-vs2.3.0.36.9-pre5/kernel/nsproxy.c   2009-03-25 00:39:02.000000000 +0100
15370 @@ -19,6 +19,8 @@
15371  #include <linux/mnt_namespace.h>
15372  #include <linux/utsname.h>
15373  #include <linux/pid_namespace.h>
15374 +#include <linux/vserver/global.h>
15375 +#include <linux/vserver/debug.h>
15376  #include <net/net_namespace.h>
15377  #include <linux/ipc_namespace.h>
15378  
15379 @@ -37,6 +39,9 @@ static inline struct nsproxy *clone_nspr
15380         if (ns) {
15381                 memcpy(ns, orig, sizeof(struct nsproxy));
15382                 atomic_set(&ns->count, 1);
15383 +               vxdprintk(VXD_CBIT(space, 2), "clone_nsproxy(%p[%u] = %p[1]",
15384 +                       orig, atomic_read(&orig->count), ns);
15385 +               atomic_inc(&vs_global_nsproxy);
15386         }
15387         return ns;
15388  }
15389 @@ -46,41 +51,52 @@ static inline struct nsproxy *clone_nspr
15390   * Return the newly created nsproxy.  Do not attach this to the task,
15391   * leave it to the caller to do proper locking and attach it to task.
15392   */
15393 -static struct nsproxy *create_new_namespaces(unsigned long flags,
15394 -                       struct task_struct *tsk, struct fs_struct *new_fs)
15395 +static struct nsproxy *unshare_namespaces(unsigned long flags,
15396 +                       struct nsproxy *orig, struct fs_struct *new_fs)
15397  {
15398         struct nsproxy *new_nsp;
15399         int err;
15400  
15401 -       new_nsp = clone_nsproxy(tsk->nsproxy);
15402 +       vxdprintk(VXD_CBIT(space, 4),
15403 +               "unshare_namespaces(0x%08lx,%p,%p)",
15404 +               flags, orig, new_fs);
15405 +
15406 +       new_nsp = clone_nsproxy(orig);
15407         if (!new_nsp)
15408                 return ERR_PTR(-ENOMEM);
15409  
15410 -       new_nsp->mnt_ns = copy_mnt_ns(flags, tsk->nsproxy->mnt_ns, new_fs);
15411 +       new_nsp->mnt_ns = copy_mnt_ns(flags, orig->mnt_ns, new_fs);
15412         if (IS_ERR(new_nsp->mnt_ns)) {
15413                 err = PTR_ERR(new_nsp->mnt_ns);
15414                 goto out_ns;
15415         }
15416  
15417 -       new_nsp->uts_ns = copy_utsname(flags, tsk->nsproxy->uts_ns);
15418 +       new_nsp->uts_ns = copy_utsname(flags, orig->uts_ns);
15419         if (IS_ERR(new_nsp->uts_ns)) {
15420                 err = PTR_ERR(new_nsp->uts_ns);
15421                 goto out_uts;
15422         }
15423  
15424 -       new_nsp->ipc_ns = copy_ipcs(flags, tsk->nsproxy->ipc_ns);
15425 +       new_nsp->ipc_ns = copy_ipcs(flags, orig->ipc_ns);
15426         if (IS_ERR(new_nsp->ipc_ns)) {
15427                 err = PTR_ERR(new_nsp->ipc_ns);
15428                 goto out_ipc;
15429         }
15430  
15431 -       new_nsp->pid_ns = copy_pid_ns(flags, task_active_pid_ns(tsk));
15432 +       new_nsp->pid_ns = copy_pid_ns(flags, orig->pid_ns);
15433         if (IS_ERR(new_nsp->pid_ns)) {
15434                 err = PTR_ERR(new_nsp->pid_ns);
15435                 goto out_pid;
15436         }
15437  
15438 -       new_nsp->net_ns = copy_net_ns(flags, tsk->nsproxy->net_ns);
15439 +       /* disabled now?
15440 +       new_nsp->user_ns = copy_user_ns(flags, orig->user_ns);
15441 +       if (IS_ERR(new_nsp->user_ns)) {
15442 +               err = PTR_ERR(new_nsp->user_ns);
15443 +               goto out_user;
15444 +       } */
15445 +
15446 +       new_nsp->net_ns = copy_net_ns(flags, orig->net_ns);
15447         if (IS_ERR(new_nsp->net_ns)) {
15448                 err = PTR_ERR(new_nsp->net_ns);
15449                 goto out_net;
15450 @@ -105,6 +121,35 @@ out_ns:
15451         return ERR_PTR(err);
15452  }
15453  
15454 +static struct nsproxy *create_new_namespaces(int flags, struct task_struct *tsk,
15455 +                       struct fs_struct *new_fs)
15456 +{
15457 +       return unshare_namespaces(flags, tsk->nsproxy, new_fs);
15458 +}
15459 +
15460 +/*
15461 + * copies the nsproxy, setting refcount to 1, and grabbing a
15462 + * reference to all contained namespaces.
15463 + */
15464 +struct nsproxy *copy_nsproxy(struct nsproxy *orig)
15465 +{
15466 +       struct nsproxy *ns = clone_nsproxy(orig);
15467 +
15468 +       if (ns) {
15469 +               if (ns->mnt_ns)
15470 +                       get_mnt_ns(ns->mnt_ns);
15471 +               if (ns->uts_ns)
15472 +                       get_uts_ns(ns->uts_ns);
15473 +               if (ns->ipc_ns)
15474 +                       get_ipc_ns(ns->ipc_ns);
15475 +               if (ns->pid_ns)
15476 +                       get_pid_ns(ns->pid_ns);
15477 +               if (ns->net_ns)
15478 +                       get_net(ns->net_ns);
15479 +       }
15480 +       return ns;
15481 +}
15482 +
15483  /*
15484   * called from clone.  This now handles copy for nsproxy and all
15485   * namespaces therein.
15486 @@ -112,9 +157,12 @@ out_ns:
15487  int copy_namespaces(unsigned long flags, struct task_struct *tsk)
15488  {
15489         struct nsproxy *old_ns = tsk->nsproxy;
15490 -       struct nsproxy *new_ns;
15491 +       struct nsproxy *new_ns = NULL;
15492         int err = 0;
15493  
15494 +       vxdprintk(VXD_CBIT(space, 7), "copy_namespaces(0x%08lx,%p[%p])",
15495 +               flags, tsk, old_ns);
15496 +
15497         if (!old_ns)
15498                 return 0;
15499  
15500 @@ -151,6 +199,9 @@ int copy_namespaces(unsigned long flags,
15501  
15502  out:
15503         put_nsproxy(old_ns);
15504 +       vxdprintk(VXD_CBIT(space, 3),
15505 +               "copy_namespaces(0x%08lx,%p[%p]) = %d [%p]",
15506 +               flags, tsk, old_ns, err, new_ns);
15507         return err;
15508  }
15509  
15510 @@ -164,7 +215,9 @@ void free_nsproxy(struct nsproxy *ns)
15511                 put_ipc_ns(ns->ipc_ns);
15512         if (ns->pid_ns)
15513                 put_pid_ns(ns->pid_ns);
15514 -       put_net(ns->net_ns);
15515 +       if (ns->net_ns)
15516 +               put_net(ns->net_ns);
15517 +       atomic_dec(&vs_global_nsproxy);
15518         kmem_cache_free(nsproxy_cachep, ns);
15519  }
15520  
15521 @@ -177,6 +230,10 @@ int unshare_nsproxy_namespaces(unsigned 
15522  {
15523         int err = 0;
15524  
15525 +       vxdprintk(VXD_CBIT(space, 4),
15526 +               "unshare_nsproxy_namespaces(0x%08lx,[%p])",
15527 +               unshare_flags, current->nsproxy);
15528 +
15529         if (!(unshare_flags & (CLONE_NEWNS | CLONE_NEWUTS | CLONE_NEWIPC |
15530                                CLONE_NEWNET)))
15531                 return 0;
15532 diff -NurpP --minimal linux-2.6.29.1/kernel/pid.c linux-2.6.29.1-vs2.3.0.36.9-pre5/kernel/pid.c
15533 --- linux-2.6.29.1/kernel/pid.c 2009-03-24 14:22:44.000000000 +0100
15534 +++ linux-2.6.29.1-vs2.3.0.36.9-pre5/kernel/pid.c       2009-03-24 14:48:36.000000000 +0100
15535 @@ -36,6 +36,8 @@
15536  #include <linux/pid_namespace.h>
15537  #include <linux/init_task.h>
15538  #include <linux/syscalls.h>
15539 +#include <linux/vs_pid.h>
15540 +#include <linux/vserver/global.h>
15541  
15542  #define pid_hashfn(nr, ns)     \
15543         hash_long((unsigned long)nr + (unsigned long)ns, pidhash_shift)
15544 @@ -305,7 +307,7 @@ EXPORT_SYMBOL_GPL(find_pid_ns);
15545  
15546  struct pid *find_vpid(int nr)
15547  {
15548 -       return find_pid_ns(nr, current->nsproxy->pid_ns);
15549 +       return find_pid_ns(vx_rmap_pid(nr), current->nsproxy->pid_ns);
15550  }
15551  EXPORT_SYMBOL_GPL(find_vpid);
15552  
15553 @@ -365,6 +367,9 @@ void transfer_pid(struct task_struct *ol
15554  struct task_struct *pid_task(struct pid *pid, enum pid_type type)
15555  {
15556         struct task_struct *result = NULL;
15557 +
15558 +       if (type == PIDTYPE_REALPID)
15559 +               type = PIDTYPE_PID;
15560         if (pid) {
15561                 struct hlist_node *first;
15562                 first = rcu_dereference(pid->tasks[type].first);
15563 @@ -388,14 +393,14 @@ EXPORT_SYMBOL(find_task_by_pid_type_ns);
15564  
15565  struct task_struct *find_task_by_vpid(pid_t vnr)
15566  {
15567 -       return find_task_by_pid_type_ns(PIDTYPE_PID, vnr,
15568 +       return find_task_by_pid_type_ns(PIDTYPE_PID, vx_rmap_pid(vnr),
15569                         current->nsproxy->pid_ns);
15570  }
15571  EXPORT_SYMBOL(find_task_by_vpid);
15572  
15573  struct task_struct *find_task_by_pid_ns(pid_t nr, struct pid_namespace *ns)
15574  {
15575 -       return find_task_by_pid_type_ns(PIDTYPE_PID, nr, ns);
15576 +       return find_task_by_pid_type_ns(PIDTYPE_PID, vx_rmap_pid(nr), ns);
15577  }
15578  EXPORT_SYMBOL(find_task_by_pid_ns);
15579  
15580 @@ -431,7 +436,7 @@ struct pid *find_get_pid(pid_t nr)
15581  }
15582  EXPORT_SYMBOL_GPL(find_get_pid);
15583  
15584 -pid_t pid_nr_ns(struct pid *pid, struct pid_namespace *ns)
15585 +pid_t pid_unmapped_nr_ns(struct pid *pid, struct pid_namespace *ns)
15586  {
15587         struct upid *upid;
15588         pid_t nr = 0;
15589 @@ -444,6 +449,11 @@ pid_t pid_nr_ns(struct pid *pid, struct 
15590         return nr;
15591  }
15592  
15593 +pid_t pid_nr_ns(struct pid *pid, struct pid_namespace *ns)
15594 +{
15595 +       return vx_map_pid(pid_unmapped_nr_ns(pid, ns));
15596 +}
15597 +
15598  pid_t pid_vnr(struct pid *pid)
15599  {
15600         return pid_nr_ns(pid, current->nsproxy->pid_ns);
15601 diff -NurpP --minimal linux-2.6.29.1/kernel/pid_namespace.c linux-2.6.29.1-vs2.3.0.36.9-pre5/kernel/pid_namespace.c
15602 --- linux-2.6.29.1/kernel/pid_namespace.c       2008-12-25 00:26:37.000000000 +0100
15603 +++ linux-2.6.29.1-vs2.3.0.36.9-pre5/kernel/pid_namespace.c     2009-02-22 22:54:26.000000000 +0100
15604 @@ -13,6 +13,7 @@
15605  #include <linux/syscalls.h>
15606  #include <linux/err.h>
15607  #include <linux/acct.h>
15608 +#include <linux/vserver/global.h>
15609  
15610  #define BITS_PER_PAGE          (PAGE_SIZE*8)
15611  
15612 @@ -85,6 +86,7 @@ static struct pid_namespace *create_pid_
15613                 goto out_free_map;
15614  
15615         kref_init(&ns->kref);
15616 +       atomic_inc(&vs_global_pid_ns);
15617         ns->level = level;
15618  
15619         set_bit(0, ns->pidmap[0].page);
15620 @@ -109,6 +111,7 @@ static void destroy_pid_namespace(struct
15621  
15622         for (i = 0; i < PIDMAP_ENTRIES; i++)
15623                 kfree(ns->pidmap[i].page);
15624 +       atomic_dec(&vs_global_pid_ns);
15625         kmem_cache_free(pid_ns_cachep, ns);
15626  }
15627  
15628 diff -NurpP --minimal linux-2.6.29.1/kernel/posix-timers.c linux-2.6.29.1-vs2.3.0.36.9-pre5/kernel/posix-timers.c
15629 --- linux-2.6.29.1/kernel/posix-timers.c        2009-03-24 14:22:44.000000000 +0100
15630 +++ linux-2.6.29.1-vs2.3.0.36.9-pre5/kernel/posix-timers.c      2009-03-24 17:36:18.000000000 +0100
15631 @@ -46,6 +46,7 @@
15632  #include <linux/wait.h>
15633  #include <linux/workqueue.h>
15634  #include <linux/module.h>
15635 +#include <linux/vs_context.h>
15636  
15637  /*
15638   * Management arrays for POSIX timers.  Timers are kept in slab memory
15639 @@ -321,6 +322,12 @@ int posix_timer_event(struct k_itimer *t
15640  {
15641         struct task_struct *task;
15642         int shared, ret = -1;
15643 +       struct vx_info_save vxis;
15644 +       struct vx_info *vxi;
15645 +
15646 +       /* FIXME: move that down where we have the task */
15647 +       vxi = task_get_vx_info(timr->it_process);
15648 +       enter_vx_info(vxi, &vxis);
15649         /*
15650          * FIXME: if ->sigq is queued we can race with
15651          * dequeue_signal()->do_schedule_next_timer().
15652 @@ -341,6 +348,9 @@ int posix_timer_event(struct k_itimer *t
15653                 ret = send_sigqueue(timr->sigq, task, shared);
15654         }
15655         rcu_read_unlock();
15656 +
15657 +       leave_vx_info(&vxis);
15658 +       put_vx_info(vxi);
15659         /* If we failed to send the signal the timer stops. */
15660         return ret > 0;
15661  }
15662 diff -NurpP --minimal linux-2.6.29.1/kernel/printk.c linux-2.6.29.1-vs2.3.0.36.9-pre5/kernel/printk.c
15663 --- linux-2.6.29.1/kernel/printk.c      2009-03-24 14:22:44.000000000 +0100
15664 +++ linux-2.6.29.1-vs2.3.0.36.9-pre5/kernel/printk.c    2009-03-24 14:48:36.000000000 +0100
15665 @@ -32,6 +32,7 @@
15666  #include <linux/security.h>
15667  #include <linux/bootmem.h>
15668  #include <linux/syscalls.h>
15669 +#include <linux/vs_cvirt.h>
15670  
15671  #include <asm/uaccess.h>
15672  
15673 @@ -251,18 +252,13 @@ int do_syslog(int type, char __user *buf
15674         unsigned i, j, limit, count;
15675         int do_clear = 0;
15676         char c;
15677 -       int error = 0;
15678 +       int error;
15679  
15680         error = security_syslog(type);
15681         if (error)
15682                 return error;
15683  
15684 -       switch (type) {
15685 -       case 0:         /* Close log */
15686 -               break;
15687 -       case 1:         /* Open log */
15688 -               break;
15689 -       case 2:         /* Read from log */
15690 +       if ((type >= 2) && (type <= 4)) {
15691                 error = -EINVAL;
15692                 if (!buf || len < 0)
15693                         goto out;
15694 @@ -273,6 +269,16 @@ int do_syslog(int type, char __user *buf
15695                         error = -EFAULT;
15696                         goto out;
15697                 }
15698 +       }
15699 +       if (!vx_check(0, VS_ADMIN|VS_WATCH))
15700 +               return vx_do_syslog(type, buf, len);
15701 +
15702 +       switch (type) {
15703 +       case 0:         /* Close log */
15704 +               break;
15705 +       case 1:         /* Open log */
15706 +               break;
15707 +       case 2:         /* Read from log */
15708                 error = wait_event_interruptible(log_wait,
15709                                                         (log_start - log_end));
15710                 if (error)
15711 @@ -297,16 +303,6 @@ int do_syslog(int type, char __user *buf
15712                 do_clear = 1;
15713                 /* FALL THRU */
15714         case 3:         /* Read last kernel messages */
15715 -               error = -EINVAL;
15716 -               if (!buf || len < 0)
15717 -                       goto out;
15718 -               error = 0;
15719 -               if (!len)
15720 -                       goto out;
15721 -               if (!access_ok(VERIFY_WRITE, buf, len)) {
15722 -                       error = -EFAULT;
15723 -                       goto out;
15724 -               }
15725                 count = len;
15726                 if (count > log_buf_len)
15727                         count = log_buf_len;
15728 diff -NurpP --minimal linux-2.6.29.1/kernel/ptrace.c linux-2.6.29.1-vs2.3.0.36.9-pre5/kernel/ptrace.c
15729 --- linux-2.6.29.1/kernel/ptrace.c      2009-03-24 14:22:44.000000000 +0100
15730 +++ linux-2.6.29.1-vs2.3.0.36.9-pre5/kernel/ptrace.c    2009-03-24 14:48:36.000000000 +0100
15731 @@ -21,6 +21,7 @@
15732  #include <linux/audit.h>
15733  #include <linux/pid_namespace.h>
15734  #include <linux/syscalls.h>
15735 +#include <linux/vs_context.h>
15736  
15737  #include <asm/pgtable.h>
15738  #include <asm/uaccess.h>
15739 @@ -159,6 +160,11 @@ int __ptrace_may_access(struct task_stru
15740                 dumpable = get_dumpable(task->mm);
15741         if (!dumpable && !capable(CAP_SYS_PTRACE))
15742                 return -EPERM;
15743 +       if (!vx_check(task->xid, VS_ADMIN_P|VS_IDENT))
15744 +               return -EPERM;
15745 +       if (!vx_check(task->xid, VS_IDENT) &&
15746 +               !task_vx_flags(task, VXF_STATE_ADMIN, 0))
15747 +               return -EACCES;
15748  
15749         return security_ptrace_may_access(task, mode);
15750  }
15751 @@ -596,6 +602,10 @@ SYSCALL_DEFINE4(ptrace, long, request, l
15752                 goto out;
15753         }
15754  
15755 +       ret = -EPERM;
15756 +       if (!vx_check(vx_task_xid(child), VS_WATCH_P | VS_IDENT))
15757 +               goto out_put_task_struct;
15758 +
15759         if (request == PTRACE_ATTACH) {
15760                 ret = ptrace_attach(child);
15761                 /*
15762 diff -NurpP --minimal linux-2.6.29.1/kernel/sched.c linux-2.6.29.1-vs2.3.0.36.9-pre5/kernel/sched.c
15763 --- linux-2.6.29.1/kernel/sched.c       2009-03-24 14:22:44.000000000 +0100
15764 +++ linux-2.6.29.1-vs2.3.0.36.9-pre5/kernel/sched.c     2009-03-24 21:52:21.000000000 +0100
15765 @@ -72,6 +72,8 @@
15766  #include <linux/debugfs.h>
15767  #include <linux/ctype.h>
15768  #include <linux/ftrace.h>
15769 +#include <linux/vs_sched.h>
15770 +#include <linux/vs_cvirt.h>
15771  #include <trace/sched.h>
15772  
15773  #include <asm/tlb.h>
15774 @@ -610,6 +612,16 @@ struct rq {
15775  #endif
15776         struct hrtimer hrtick_timer;
15777  #endif
15778 +       unsigned long norm_time;
15779 +       unsigned long idle_time;
15780 +#ifdef CONFIG_VSERVER_IDLETIME
15781 +       int idle_skip;
15782 +#endif
15783 +#ifdef CONFIG_VSERVER_HARDCPU
15784 +       struct list_head hold_queue;
15785 +       unsigned long nr_onhold;
15786 +       int idle_tokens;
15787 +#endif
15788  
15789  #ifdef CONFIG_SCHEDSTATS
15790         /* latency stats */
15791 @@ -1705,6 +1717,7 @@ static void update_avg(u64 *avg, u64 sam
15792  
15793  static void enqueue_task(struct rq *rq, struct task_struct *p, int wakeup)
15794  {
15795 +       // BUG_ON(p->state & TASK_ONHOLD);
15796         sched_info_queued(p);
15797         p->sched_class->enqueue_task(rq, p, wakeup);
15798         p->se.on_rq = 1;
15799 @@ -1828,6 +1841,8 @@ static inline void check_class_changed(s
15800                 p->sched_class->prio_changed(rq, p, oldprio, running);
15801  }
15802  
15803 +#include "sched_mon.h"
15804 +
15805  #ifdef CONFIG_SMP
15806  
15807  /* Used instead of source_load when we know the type == 0 */
15808 @@ -1915,6 +1930,7 @@ migrate_task(struct task_struct *p, int 
15809  {
15810         struct rq *rq = task_rq(p);
15811  
15812 +       vxm_migrate_task(p, rq, dest_cpu);
15813         /*
15814          * If the task is not on a runqueue (and not running), then
15815          * it is sufficient to simply update the task's cpu field.
15816 @@ -2242,6 +2258,8 @@ static int sched_balance_self(int cpu, i
15817  
15818  #endif /* CONFIG_SMP */
15819  
15820 +#include "sched_hard.h"
15821 +
15822  /***
15823   * try_to_wake_up - wake up a thread
15824   * @p: the to-be-woken-up thread
15825 @@ -2286,6 +2304,13 @@ static int try_to_wake_up(struct task_st
15826         rq = task_rq_lock(p, &flags);
15827         update_rq_clock(rq);
15828         old_state = p->state;
15829 +
15830 +       /* we need to unhold suspended tasks */
15831 +       if (old_state & TASK_ONHOLD) {
15832 +               vx_unhold_task(p, rq);
15833 +               old_state = p->state;
15834 +       }
15835 +
15836         if (!(old_state & state))
15837                 goto out;
15838  
15839 @@ -2307,6 +2332,12 @@ static int try_to_wake_up(struct task_st
15840                 /* might preempt at this point */
15841                 rq = task_rq_lock(p, &flags);
15842                 old_state = p->state;
15843 +
15844 +       /* we need to unhold suspended tasks
15845 +       if (old_state & TASK_ONHOLD) {
15846 +               vx_unhold_task(p, rq);
15847 +               old_state = p->state;
15848 +       } */
15849                 if (!(old_state & state))
15850                         goto out;
15851                 if (p->se.on_rq)
15852 @@ -4169,16 +4200,19 @@ void account_user_time(struct task_struc
15853                        cputime_t cputime_scaled)
15854  {
15855         struct cpu_usage_stat *cpustat = &kstat_this_cpu.cpustat;
15856 +       struct vx_info *vxi = p->vx_info;  /* p is _always_ current */
15857         cputime64_t tmp;
15858 +       int nice = (TASK_NICE(p) > 0);
15859  
15860         /* Add user time to process. */
15861         p->utime = cputime_add(p->utime, cputime);
15862         p->utimescaled = cputime_add(p->utimescaled, cputime_scaled);
15863 +       vx_account_user(vxi, cputime, nice);
15864         account_group_user_time(p, cputime);
15865  
15866         /* Add user time to cpustat. */
15867         tmp = cputime_to_cputime64(cputime);
15868 -       if (TASK_NICE(p) > 0)
15869 +       if (nice)
15870                 cpustat->nice = cputime64_add(cpustat->nice, tmp);
15871         else
15872                 cpustat->user = cputime64_add(cpustat->user, tmp);
15873 @@ -4222,6 +4256,7 @@ void account_system_time(struct task_str
15874                          cputime_t cputime, cputime_t cputime_scaled)
15875  {
15876         struct cpu_usage_stat *cpustat = &kstat_this_cpu.cpustat;
15877 +       struct vx_info *vxi = p->vx_info;  /* p is _always_ current */
15878         cputime64_t tmp;
15879  
15880         if ((p->flags & PF_VCPU) && (irq_count() - hardirq_offset == 0)) {
15881 @@ -4232,6 +4267,7 @@ void account_system_time(struct task_str
15882         /* Add system time to process. */
15883         p->stime = cputime_add(p->stime, cputime);
15884         p->stimescaled = cputime_add(p->stimescaled, cputime_scaled);
15885 +       vx_account_system(vxi, cputime, 0 /* do we have idle time? */);
15886         account_group_system_time(p, cputime);
15887  
15888         /* Add system time to cpustat. */
15889 @@ -4587,6 +4623,11 @@ need_resched_nonpreemptible:
15890                 idle_balance(cpu, rq);
15891  
15892         prev->sched_class->put_prev_task(rq, prev);
15893 +
15894 +       vx_set_rq_time(rq, jiffies);    /* update time */
15895 +       vx_schedule(prev, rq, cpu);     /* hold if over limit */
15896 +       vx_try_unhold(rq, cpu);         /* unhold if refilled */
15897 +
15898         next = pick_next_task(rq, prev);
15899  
15900         if (likely(prev != next)) {
15901 @@ -5152,7 +5193,7 @@ SYSCALL_DEFINE1(nice, int, increment)
15902                 nice = 19;
15903  
15904         if (increment < 0 && !can_nice(current, nice))
15905 -               return -EPERM;
15906 +               return vx_flags(VXF_IGNEG_NICE, 0) ? 0 : -EPERM;
15907  
15908         retval = security_task_setnice(current, nice);
15909         if (retval)
15910 @@ -8428,7 +8469,10 @@ void __init sched_init(void)
15911  
15912  #endif
15913  #endif /* CONFIG_FAIR_GROUP_SCHED */
15914 -
15915 +#ifdef CONFIG_VSERVER_HARDCPU
15916 +               INIT_LIST_HEAD(&rq->hold_queue);
15917 +               rq->nr_onhold = 0;
15918 +#endif
15919                 rq->rt.rt_runtime = def_rt_bandwidth.rt_runtime;
15920  #ifdef CONFIG_RT_GROUP_SCHED
15921                 INIT_LIST_HEAD(&rq->leaf_rt_rq_list);
15922 diff -NurpP --minimal linux-2.6.29.1/kernel/sched_fair.c linux-2.6.29.1-vs2.3.0.36.9-pre5/kernel/sched_fair.c
15923 --- linux-2.6.29.1/kernel/sched_fair.c  2009-03-24 14:22:45.000000000 +0100
15924 +++ linux-2.6.29.1-vs2.3.0.36.9-pre5/kernel/sched_fair.c        2009-03-24 14:48:36.000000000 +0100
15925 @@ -717,6 +717,9 @@ enqueue_entity(struct cfs_rq *cfs_rq, st
15926         check_spread(cfs_rq, se);
15927         if (se != cfs_rq->curr)
15928                 __enqueue_entity(cfs_rq, se);
15929 +
15930 +       if (entity_is_task(se))
15931 +               vx_activate_task(task_of(se));
15932  }
15933  
15934  static void __clear_buddies(struct cfs_rq *cfs_rq, struct sched_entity *se)
15935 @@ -760,6 +763,8 @@ dequeue_entity(struct cfs_rq *cfs_rq, st
15936  
15937         if (se != cfs_rq->curr)
15938                 __dequeue_entity(cfs_rq, se);
15939 +       if (entity_is_task(se))
15940 +               vx_deactivate_task(task_of(se));
15941         account_entity_dequeue(cfs_rq, se);
15942         update_min_vruntime(cfs_rq);
15943  }
15944 diff -NurpP --minimal linux-2.6.29.1/kernel/sched_hard.h linux-2.6.29.1-vs2.3.0.36.9-pre5/kernel/sched_hard.h
15945 --- linux-2.6.29.1/kernel/sched_hard.h  1970-01-01 01:00:00.000000000 +0100
15946 +++ linux-2.6.29.1-vs2.3.0.36.9-pre5/kernel/sched_hard.h        2009-02-22 22:54:26.000000000 +0100
15947 @@ -0,0 +1,353 @@
15948 +
15949 +#ifdef CONFIG_VSERVER_IDLELIMIT
15950 +
15951 +/*
15952 + * vx_idle_resched - reschedule after maxidle
15953 + */
15954 +static inline
15955 +void vx_idle_resched(struct rq *rq)
15956 +{
15957 +       /* maybe have a better criterion for paused */
15958 +       if (!--rq->idle_tokens && !list_empty(&rq->hold_queue))
15959 +               set_need_resched();
15960 +}
15961 +
15962 +#else /* !CONFIG_VSERVER_IDLELIMIT */
15963 +
15964 +#define vx_idle_resched(rq)
15965 +
15966 +#endif /* CONFIG_VSERVER_IDLELIMIT */
15967 +
15968 +
15969 +
15970 +#ifdef CONFIG_VSERVER_IDLETIME
15971 +
15972 +#define vx_set_rq_min_skip(rq, min)            \
15973 +       (rq)->idle_skip = (min)
15974 +
15975 +#define vx_save_min_skip(ret, min, val)                \
15976 +       __vx_save_min_skip(ret, min, val)
15977 +
15978 +static inline
15979 +void __vx_save_min_skip(int ret, int *min, int val)
15980 +{
15981 +       if (ret > -2)
15982 +               return;
15983 +       if ((*min > val) || !*min)
15984 +               *min = val;
15985 +}
15986 +
15987 +static inline
15988 +int vx_try_skip(struct rq *rq, int cpu)
15989 +{
15990 +       /* artificially advance time */
15991 +       if (rq->idle_skip > 0) {
15992 +               vxdprintk(list_empty(&rq->hold_queue),
15993 +                       "hold queue empty on cpu %d", cpu);
15994 +               rq->idle_time += rq->idle_skip;
15995 +               vxm_idle_skip(rq, cpu);
15996 +               return 1;
15997 +       }
15998 +       return 0;
15999 +}
16000 +
16001 +#else /* !CONFIG_VSERVER_IDLETIME */
16002 +
16003 +#define vx_set_rq_min_skip(rq, min)            \
16004 +       ({ int dummy = (min); dummy; })
16005 +
16006 +#define vx_save_min_skip(ret, min, val)
16007 +
16008 +static inline
16009 +int vx_try_skip(struct rq *rq, int cpu)
16010 +{
16011 +       return 0;
16012 +}
16013 +
16014 +#endif /* CONFIG_VSERVER_IDLETIME */
16015 +
16016 +
16017 +
16018 +#ifdef CONFIG_VSERVER_HARDCPU
16019 +
16020 +#define vx_set_rq_max_idle(rq, max)            \
16021 +       (rq)->idle_tokens = (max)
16022 +
16023 +#define vx_save_max_idle(ret, min, val)                \
16024 +       __vx_save_max_idle(ret, min, val)
16025 +
16026 +static inline
16027 +void __vx_save_max_idle(int ret, int *min, int val)
16028 +{
16029 +       if (*min > val)
16030 +               *min = val;
16031 +}
16032 +
16033 +
16034 +/*
16035 + * vx_hold_task - put a task on the hold queue
16036 + */
16037 +static inline
16038 +void vx_hold_task(struct task_struct *p, struct rq *rq)
16039 +{
16040 +       // printk("@ hold_task(%p[%lx])\n", p, p->state);
16041 +
16042 +       /* ignore dead/killed tasks */
16043 +       if (unlikely(p->state & (TASK_DEAD | TASK_WAKEKILL)))
16044 +               return;
16045 +
16046 +       /* ignore sleeping tasks */
16047 +       if (unlikely(p->state & TASK_NORMAL))
16048 +               return;
16049 +
16050 +       /* remove task from runqueue */
16051 +       if (likely(p->se.on_rq))
16052 +               dequeue_task(rq, p, 0);
16053 +       else
16054 +               printk("@ woops, task %p not on runqueue?\n", p);
16055 +
16056 +       p->state |= TASK_ONHOLD;
16057 +       /* a new one on hold */
16058 +       rq->nr_onhold++;
16059 +       vxm_hold_task(p, rq);
16060 +       list_add_tail(&p->hq, &rq->hold_queue);
16061 +       // list_add_tail(&p->run_list, &rq->hold_queue);
16062 +}
16063 +
16064 +/*
16065 + * vx_unhold_task - put a task back to the runqueue
16066 + */
16067 +static inline
16068 +void vx_unhold_task(struct task_struct *p, struct rq *rq)
16069 +{
16070 +       // printk("@ unhold_task(%p[%lx])\n", p, p->state);
16071 +       list_del_init(&p->hq);
16072 +       // list_del(&p->run_list);
16073 +       /* one less waiting */
16074 +       rq->nr_onhold--;
16075 +       p->state &= ~TASK_ONHOLD;
16076 +       enqueue_task(rq, p, 0);
16077 +       // ? inc_nr_running(p, rq);
16078 +       vxm_unhold_task(p, rq);
16079 +}
16080 +
16081 +/*
16082 + * vx_remove_hold - remove a task from the hold queue
16083 + */
16084 +static inline
16085 +void vx_remove_hold(struct task_struct *p, struct rq *rq)
16086 +{
16087 +       printk("@ remove_hold(%p[%lx])\n", p, p->state);
16088 +       list_del_init(&p->hq);
16089 +       // list_del(&p->run_list);
16090 +       /* one less waiting */
16091 +       rq->nr_onhold--;
16092 +       p->state &= ~TASK_ONHOLD;
16093 +}
16094 +
16095 +unsigned long nr_onhold(void)
16096 +{
16097 +       unsigned long i, sum = 0;
16098 +
16099 +       for_each_online_cpu(i)
16100 +               sum += cpu_rq(i)->nr_onhold;
16101 +
16102 +       return sum;
16103 +}
16104 +
16105 +
16106 +
16107 +static inline
16108 +int __vx_tokens_avail(struct _vx_sched_pc *sched_pc)
16109 +{
16110 +       return sched_pc->tokens;
16111 +}
16112 +
16113 +static inline
16114 +void __vx_consume_token(struct _vx_sched_pc *sched_pc)
16115 +{
16116 +       sched_pc->tokens--;
16117 +}
16118 +
16119 +static inline
16120 +int vx_need_resched(struct task_struct *p, int slice, int cpu)
16121 +{
16122 +       struct vx_info *vxi = p->vx_info;
16123 +
16124 +       if (vx_info_flags(vxi, VXF_SCHED_HARD|VXF_SCHED_PRIO, 0)) {
16125 +               struct _vx_sched_pc *sched_pc =
16126 +                       &vx_per_cpu(vxi, sched_pc, cpu);
16127 +               int tokens;
16128 +
16129 +               /* maybe we can simplify that to decrement
16130 +                  the token counter unconditional? */
16131 +
16132 +               if ((tokens = __vx_tokens_avail(sched_pc)) > 0)
16133 +                       __vx_consume_token(sched_pc);
16134 +
16135 +               /* for tokens > 0, one token was consumed */
16136 +               if (tokens < 2)
16137 +                       slice = 0;
16138 +       }
16139 +       vxm_need_resched(p, slice, cpu);
16140 +       return (slice == 0);
16141 +}
16142 +
16143 +
16144 +#define vx_set_rq_time(rq, time) do {  \
16145 +       rq->norm_time = time;           \
16146 +} while (0)
16147 +
16148 +
16149 +static inline
16150 +void vx_try_unhold(struct rq *rq, int cpu)
16151 +{
16152 +       struct vx_info *vxi = NULL;
16153 +       struct list_head *l, *n;
16154 +       int maxidle = HZ;
16155 +       int minskip = 0;
16156 +
16157 +       /* nothing to do? what about pause? */
16158 +       if (list_empty(&rq->hold_queue))
16159 +               return;
16160 +
16161 +       list_for_each_safe(l, n, &rq->hold_queue) {
16162 +               int ret, delta_min[2];
16163 +               struct _vx_sched_pc *sched_pc;
16164 +               struct task_struct *p;
16165 +
16166 +               p = list_entry(l, struct task_struct, hq);
16167 +               /* don't bother with same context */
16168 +               if (vxi == p->vx_info)
16169 +                       continue;
16170 +
16171 +               vxi = p->vx_info;
16172 +               /* ignore paused contexts */
16173 +               if (vx_info_flags(vxi, VXF_SCHED_PAUSE, 0))
16174 +                       continue;
16175 +
16176 +               sched_pc = &vx_per_cpu(vxi, sched_pc, cpu);
16177 +
16178 +               /* recalc tokens */
16179 +               vxm_sched_info(sched_pc, vxi, cpu);
16180 +               ret = vx_tokens_recalc(sched_pc,
16181 +                       &rq->norm_time, &rq->idle_time, delta_min);
16182 +               vxm_tokens_recalc(sched_pc, rq, vxi, cpu);
16183 +
16184 +               if (ret > 0) {
16185 +                       /* we found a runable context */
16186 +                       vx_unhold_task(p, rq);
16187 +                       break;
16188 +               }
16189 +               vx_save_max_idle(ret, &maxidle, delta_min[0]);
16190 +               vx_save_min_skip(ret, &minskip, delta_min[1]);
16191 +       }
16192 +       vx_set_rq_max_idle(rq, maxidle);
16193 +       vx_set_rq_min_skip(rq, minskip);
16194 +       vxm_rq_max_min(rq, cpu);
16195 +}
16196 +
16197 +
16198 +static inline
16199 +int vx_schedule(struct task_struct *next, struct rq *rq, int cpu)
16200 +{
16201 +       struct vx_info *vxi = next->vx_info;
16202 +       struct _vx_sched_pc *sched_pc;
16203 +       int delta_min[2];
16204 +       int flags, ret;
16205 +
16206 +       if (!vxi)
16207 +               return 1;
16208 +
16209 +       flags = vxi->vx_flags;
16210 +
16211 +       if (unlikely(vs_check_flags(flags, VXF_SCHED_PAUSE, 0)))
16212 +               goto put_on_hold;
16213 +       if (!vs_check_flags(flags, VXF_SCHED_HARD | VXF_SCHED_PRIO, 0))
16214 +               return 1;
16215 +
16216 +       sched_pc = &vx_per_cpu(vxi, sched_pc, cpu);
16217 +#ifdef CONFIG_SMP
16218 +       /* update scheduler params */
16219 +       if (cpu_isset(cpu, vxi->sched.update)) {
16220 +               vx_update_sched_param(&vxi->sched, sched_pc);
16221 +               vxm_update_sched(sched_pc, vxi, cpu);
16222 +               cpu_clear(cpu, vxi->sched.update);
16223 +       }
16224 +#endif
16225 +       vxm_sched_info(sched_pc, vxi, cpu);
16226 +       ret  = vx_tokens_recalc(sched_pc,
16227 +               &rq->norm_time, &rq->idle_time, delta_min);
16228 +       vxm_tokens_recalc(sched_pc, rq, vxi, cpu);
16229 +
16230 +       if (!vs_check_flags(flags, VXF_SCHED_HARD, 0))
16231 +               return 1;
16232 +
16233 +       if (unlikely(ret < 0)) {
16234 +               vx_save_max_idle(ret, &rq->idle_tokens, delta_min[0]);
16235 +               vx_save_min_skip(ret, &rq->idle_skip, delta_min[1]);
16236 +               vxm_rq_max_min(rq, cpu);
16237 +       put_on_hold:
16238 +               vx_hold_task(next, rq);
16239 +               return 0;
16240 +       }
16241 +       return 1;
16242 +}
16243 +
16244 +
16245 +#else /* CONFIG_VSERVER_HARDCPU */
16246 +
16247 +static inline
16248 +void vx_hold_task(struct task_struct *p, struct rq *rq)
16249 +{
16250 +       return;
16251 +}
16252 +
16253 +static inline
16254 +void vx_unhold_task(struct task_struct *p, struct rq *rq)
16255 +{
16256 +       return;
16257 +}
16258 +
16259 +unsigned long nr_onhold(void)
16260 +{
16261 +       return 0;
16262 +}
16263 +
16264 +
16265 +static inline
16266 +int vx_need_resched(struct task_struct *p, int slice, int cpu)
16267 +{
16268 +       return (slice == 0);
16269 +}
16270 +
16271 +
16272 +#define vx_set_rq_time(rq, time)
16273 +
16274 +static inline
16275 +void vx_try_unhold(struct rq *rq, int cpu)
16276 +{
16277 +       return;
16278 +}
16279 +
16280 +static inline
16281 +int vx_schedule(struct task_struct *next, struct rq *rq, int cpu)
16282 +{
16283 +       struct vx_info *vxi = next->vx_info;
16284 +       struct _vx_sched_pc *sched_pc;
16285 +       int delta_min[2];
16286 +       int ret;
16287 +
16288 +       if (!vx_info_flags(vxi, VXF_SCHED_PRIO, 0))
16289 +               return 1;
16290 +
16291 +       sched_pc = &vx_per_cpu(vxi, sched_pc, cpu);
16292 +       vxm_sched_info(sched_pc, vxi, cpu);
16293 +       ret  = vx_tokens_recalc(sched_pc,
16294 +               &rq->norm_time, &rq->idle_time, delta_min);
16295 +       vxm_tokens_recalc(sched_pc, rq, vxi, cpu);
16296 +       return 1;
16297 +}
16298 +
16299 +#endif /* CONFIG_VSERVER_HARDCPU */
16300 +
16301 diff -NurpP --minimal linux-2.6.29.1/kernel/sched_mon.h linux-2.6.29.1-vs2.3.0.36.9-pre5/kernel/sched_mon.h
16302 --- linux-2.6.29.1/kernel/sched_mon.h   1970-01-01 01:00:00.000000000 +0100
16303 +++ linux-2.6.29.1-vs2.3.0.36.9-pre5/kernel/sched_mon.h 2009-02-22 22:54:26.000000000 +0100
16304 @@ -0,0 +1,200 @@
16305 +
16306 +#include <linux/vserver/monitor.h>
16307 +
16308 +#ifdef  CONFIG_VSERVER_MONITOR
16309 +
16310 +#ifdef CONFIG_VSERVER_HARDCPU
16311 +#define HARDCPU(x) (x)
16312 +#else
16313 +#define HARDCPU(x) (0)
16314 +#endif
16315 +
16316 +#ifdef CONFIG_VSERVER_IDLETIME
16317 +#define IDLETIME(x) (x)
16318 +#else
16319 +#define IDLETIME(x) (0)
16320 +#endif
16321 +
16322 +struct _vx_mon_entry *vxm_advance(int cpu);
16323 +
16324 +
16325 +static inline
16326 +void   __vxm_basic(struct _vx_mon_entry *entry, xid_t xid, int type)
16327 +{
16328 +       entry->type = type;
16329 +       entry->xid = xid;
16330 +}
16331 +
16332 +static inline
16333 +void   __vxm_sync(int cpu)
16334 +{
16335 +       struct _vx_mon_entry *entry = vxm_advance(cpu);
16336 +
16337 +       __vxm_basic(entry, 0, VXM_SYNC);
16338 +       entry->ev.sec = xtime.tv_sec;
16339 +       entry->ev.nsec = xtime.tv_nsec;
16340 +}
16341 +
16342 +static inline
16343 +void   __vxm_task(struct task_struct *p, int type)
16344 +{
16345 +       struct _vx_mon_entry *entry = vxm_advance(task_cpu(p));
16346 +
16347 +       __vxm_basic(entry, p->xid, type);
16348 +       entry->ev.tsk.pid = p->pid;
16349 +       entry->ev.tsk.state = p->state;
16350 +}
16351 +
16352 +static inline
16353 +void   __vxm_sched(struct _vx_sched_pc *s, struct vx_info *vxi, int cpu)
16354 +{
16355 +       struct _vx_mon_entry *entry = vxm_advance(cpu);
16356 +
16357 +       __vxm_basic(entry, vxi->vx_id, (VXM_SCHED | s->flags));
16358 +       entry->sd.tokens = s->tokens;
16359 +       entry->sd.norm_time = s->norm_time;
16360 +       entry->sd.idle_time = s->idle_time;
16361 +}
16362 +
16363 +static inline
16364 +void   __vxm_rqinfo1(struct rq *q, int cpu)
16365 +{
16366 +       struct _vx_mon_entry *entry = vxm_advance(cpu);
16367 +
16368 +       entry->type = VXM_RQINFO_1;
16369 +       entry->xid = ((unsigned long)q >> 16) & 0xffff;
16370 +       entry->q1.running = q->nr_running;
16371 +       entry->q1.onhold = HARDCPU(q->nr_onhold);
16372 +       entry->q1.iowait = atomic_read(&q->nr_iowait);
16373 +       entry->q1.uintr = q->nr_uninterruptible;
16374 +       entry->q1.idle_tokens = IDLETIME(q->idle_tokens);
16375 +}
16376 +
16377 +static inline
16378 +void   __vxm_rqinfo2(struct rq *q, int cpu)
16379 +{
16380 +       struct _vx_mon_entry *entry = vxm_advance(cpu);
16381 +
16382 +       entry->type = VXM_RQINFO_2;
16383 +       entry->xid = (unsigned long)q & 0xffff;
16384 +       entry->q2.norm_time = q->norm_time;
16385 +       entry->q2.idle_time = q->idle_time;
16386 +       entry->q2.idle_skip = IDLETIME(q->idle_skip);
16387 +}
16388 +
16389 +static inline
16390 +void   __vxm_update(struct _vx_sched_pc *s, struct vx_info *vxi, int cpu)
16391 +{
16392 +       struct _vx_mon_entry *entry = vxm_advance(cpu);
16393 +
16394 +       __vxm_basic(entry, vxi->vx_id, VXM_UPDATE);
16395 +       entry->ev.tokens = s->tokens;
16396 +}
16397 +
16398 +static inline
16399 +void   __vxm_update1(struct _vx_sched_pc *s, struct vx_info *vxi, int cpu)
16400 +{
16401 +       struct _vx_mon_entry *entry = vxm_advance(cpu);
16402 +
16403 +       __vxm_basic(entry, vxi->vx_id, VXM_UPDATE_1);
16404 +       entry->u1.tokens_max = s->tokens_max;
16405 +       entry->u1.fill_rate = s->fill_rate[0];
16406 +       entry->u1.interval = s->interval[0];
16407 +}
16408 +
16409 +static inline
16410 +void   __vxm_update2(struct _vx_sched_pc *s, struct vx_info *vxi, int cpu)
16411 +{
16412 +       struct _vx_mon_entry *entry = vxm_advance(cpu);
16413 +
16414 +       __vxm_basic(entry, vxi->vx_id, VXM_UPDATE_2);
16415 +       entry->u2.tokens_min = s->tokens_min;
16416 +       entry->u2.fill_rate = s->fill_rate[1];
16417 +       entry->u2.interval = s->interval[1];
16418 +}
16419 +
16420 +
16421 +#define        vxm_activate_task(p,q)          __vxm_task(p, VXM_ACTIVATE)
16422 +#define        vxm_activate_idle(p,q)          __vxm_task(p, VXM_IDLE)
16423 +#define        vxm_deactivate_task(p,q)        __vxm_task(p, VXM_DEACTIVATE)
16424 +#define        vxm_hold_task(p,q)              __vxm_task(p, VXM_HOLD)
16425 +#define        vxm_unhold_task(p,q)            __vxm_task(p, VXM_UNHOLD)
16426 +
16427 +static inline
16428 +void   vxm_migrate_task(struct task_struct *p, struct rq *rq, int dest)
16429 +{
16430 +       __vxm_task(p, VXM_MIGRATE);
16431 +       __vxm_rqinfo1(rq, task_cpu(p));
16432 +       __vxm_rqinfo2(rq, task_cpu(p));
16433 +}
16434 +
16435 +static inline
16436 +void   vxm_idle_skip(struct rq *rq, int cpu)
16437 +{
16438 +       __vxm_rqinfo1(rq, cpu);
16439 +       __vxm_rqinfo2(rq, cpu);
16440 +}
16441 +
16442 +static inline
16443 +void   vxm_need_resched(struct task_struct *p, int slice, int cpu)
16444 +{
16445 +       if (slice)
16446 +               return;
16447 +
16448 +       __vxm_task(p, VXM_RESCHED);
16449 +}
16450 +
16451 +static inline
16452 +void   vxm_sync(unsigned long now, int cpu)
16453 +{
16454 +       if (!CONFIG_VSERVER_MONITOR_SYNC ||
16455 +               (now % CONFIG_VSERVER_MONITOR_SYNC))
16456 +               return;
16457 +
16458 +       __vxm_sync(cpu);
16459 +}
16460 +
16461 +#define        vxm_sched_info(s,v,c)           __vxm_sched(s,v,c)
16462 +
16463 +static inline
16464 +void   vxm_tokens_recalc(struct _vx_sched_pc *s, struct rq *rq,
16465 +       struct vx_info *vxi, int cpu)
16466 +{
16467 +       __vxm_sched(s, vxi, cpu);
16468 +       __vxm_rqinfo2(rq, cpu);
16469 +}
16470 +
16471 +static inline
16472 +void   vxm_update_sched(struct _vx_sched_pc *s, struct vx_info *vxi, int cpu)
16473 +{
16474 +       __vxm_sched(s, vxi, cpu);
16475 +       __vxm_update(s, vxi, cpu);
16476 +       __vxm_update1(s, vxi, cpu);
16477 +       __vxm_update2(s, vxi, cpu);
16478 +}
16479 +
16480 +static inline
16481 +void   vxm_rq_max_min(struct rq *rq, int cpu)
16482 +{
16483 +       __vxm_rqinfo1(rq, cpu);
16484 +       __vxm_rqinfo2(rq, cpu);
16485 +}
16486 +
16487 +#else  /* CONFIG_VSERVER_MONITOR */
16488 +
16489 +#define        vxm_activate_task(t,q)          do { } while (0)
16490 +#define        vxm_activate_idle(t,q)          do { } while (0)
16491 +#define        vxm_deactivate_task(t,q)        do { } while (0)
16492 +#define        vxm_hold_task(t,q)              do { } while (0)
16493 +#define        vxm_unhold_task(t,q)            do { } while (0)
16494 +#define        vxm_migrate_task(t,q,d)         do { } while (0)
16495 +#define        vxm_idle_skip(q,c)              do { } while (0)
16496 +#define        vxm_need_resched(t,s,c)         do { } while (0)
16497 +#define        vxm_sync(s,c)                   do { } while (0)
16498 +#define        vxm_sched_info(s,v,c)           do { } while (0)
16499 +#define        vxm_tokens_recalc(s,q,v,c)      do { } while (0)
16500 +#define        vxm_update_sched(s,v,c)         do { } while (0)
16501 +#define        vxm_rq_max_min(q,c)             do { } while (0)
16502 +
16503 +#endif /* CONFIG_VSERVER_MONITOR */
16504 +
16505 diff -NurpP --minimal linux-2.6.29.1/kernel/signal.c linux-2.6.29.1-vs2.3.0.36.9-pre5/kernel/signal.c
16506 --- linux-2.6.29.1/kernel/signal.c      2009-03-24 14:22:45.000000000 +0100
16507 +++ linux-2.6.29.1-vs2.3.0.36.9-pre5/kernel/signal.c    2009-03-24 14:48:36.000000000 +0100
16508 @@ -27,6 +27,8 @@
16509  #include <linux/freezer.h>
16510  #include <linux/pid_namespace.h>
16511  #include <linux/nsproxy.h>
16512 +#include <linux/vs_context.h>
16513 +#include <linux/vs_pid.h>
16514  #include <trace/sched.h>
16515  
16516  #include <asm/param.h>
16517 @@ -584,6 +586,14 @@ static int check_kill_permission(int sig
16518         if (!valid_signal(sig))
16519                 return -EINVAL;
16520  
16521 +       if ((info != SEND_SIG_NOINFO) &&
16522 +               (is_si_special(info) || !SI_FROMUSER(info)))
16523 +               goto skip;
16524 +
16525 +       vxdprintk(VXD_CBIT(misc, 7),
16526 +               "check_kill_permission(%d,%p,%p[#%u,%u])",
16527 +               sig, info, t, vx_task_xid(t), t->pid);
16528 +
16529         if (info != SEND_SIG_NOINFO && (is_si_special(info) || SI_FROMKERNEL(info)))
16530                 return 0;
16531  
16532 @@ -611,6 +621,18 @@ static int check_kill_permission(int sig
16533                 }
16534         }
16535  
16536 +       error = -EPERM;
16537 +       if (t->pid == 1 && current->xid)
16538 +               return error;
16539 +
16540 +       error = -ESRCH;
16541 +       if (!vx_check(vx_task_xid(t), VS_WATCH_P | VS_IDENT)) {
16542 +               vxdprintk(current->xid || VXD_CBIT(misc, 7),
16543 +                       "signal %d[%p] xid mismatch %p[#%u,%u] xid=#%u",
16544 +                       sig, info, t, vx_task_xid(t), t->pid, current->xid);
16545 +               return error;
16546 +       }
16547 +skip:
16548         return security_task_kill(t, info, sig, 0);
16549  }
16550  
16551 @@ -1076,7 +1098,7 @@ int kill_pid_info(int sig, struct siginf
16552         rcu_read_lock();
16553  retry:
16554         p = pid_task(pid, PIDTYPE_PID);
16555 -       if (p) {
16556 +       if (p && vx_check(vx_task_xid(p), VS_ADMIN | VS_IDENT)) {
16557                 error = group_send_sig_info(sig, info, p);
16558                 if (unlikely(error == -ESRCH))
16559                         /*
16560 @@ -1115,7 +1137,7 @@ int kill_pid_info_as_uid(int sig, struct
16561  
16562         read_lock(&tasklist_lock);
16563         p = pid_task(pid, PIDTYPE_PID);
16564 -       if (!p) {
16565 +       if (!p || !vx_check(vx_task_xid(p), VS_IDENT)) {
16566                 ret = -ESRCH;
16567                 goto out_unlock;
16568         }
16569 @@ -1169,8 +1191,10 @@ static int kill_something_info(int sig, 
16570                 struct task_struct * p;
16571  
16572                 for_each_process(p) {
16573 -                       if (task_pid_vnr(p) > 1 &&
16574 -                                       !same_thread_group(p, current)) {
16575 +                       if (vx_check(vx_task_xid(p), VS_ADMIN|VS_IDENT) &&
16576 +                               task_pid_vnr(p) > 1 &&
16577 +                               !same_thread_group(p, current) &&
16578 +                               !vx_current_initpid(p->pid)) {
16579                                 int err = group_send_sig_info(sig, info, p);
16580                                 ++count;
16581                                 if (err != -EPERM)
16582 @@ -1849,6 +1873,11 @@ relock:
16583                     !signal_group_exit(signal))
16584                         continue;
16585  
16586 +               /* virtual init is protected against user signals */
16587 +               if ((info->si_code == SI_USER) &&
16588 +                       vx_current_initpid(current->pid))
16589 +                       continue;
16590 +
16591                 if (sig_kernel_stop(signr)) {
16592                         /*
16593                          * The default action is to stop all threads in
16594 diff -NurpP --minimal linux-2.6.29.1/kernel/softirq.c linux-2.6.29.1-vs2.3.0.36.9-pre5/kernel/softirq.c
16595 --- linux-2.6.29.1/kernel/softirq.c     2009-03-24 14:22:45.000000000 +0100
16596 +++ linux-2.6.29.1-vs2.3.0.36.9-pre5/kernel/softirq.c   2009-03-24 14:48:36.000000000 +0100
16597 @@ -23,6 +23,7 @@
16598  #include <linux/rcupdate.h>
16599  #include <linux/smp.h>
16600  #include <linux/tick.h>
16601 +#include <linux/vs_context.h>
16602  
16603  #include <asm/irq.h>
16604  /*
16605 diff -NurpP --minimal linux-2.6.29.1/kernel/sys.c linux-2.6.29.1-vs2.3.0.36.9-pre5/kernel/sys.c
16606 --- linux-2.6.29.1/kernel/sys.c 2009-03-24 14:22:45.000000000 +0100
16607 +++ linux-2.6.29.1-vs2.3.0.36.9-pre5/kernel/sys.c       2009-03-24 14:48:36.000000000 +0100
16608 @@ -39,6 +39,7 @@
16609  #include <linux/syscalls.h>
16610  #include <linux/kprobes.h>
16611  #include <linux/user_namespace.h>
16612 +#include <linux/vs_pid.h>
16613  
16614  #include <asm/uaccess.h>
16615  #include <asm/io.h>
16616 @@ -128,7 +129,10 @@ static int set_one_prio(struct task_stru
16617                 goto out;
16618         }
16619         if (niceval < task_nice(p) && !can_nice(p, niceval)) {
16620 -               error = -EACCES;
16621 +               if (vx_flags(VXF_IGNEG_NICE, 0))
16622 +                       error = 0;
16623 +               else
16624 +                       error = -EACCES;
16625                 goto out;
16626         }
16627         no_nice = security_task_setnice(p, niceval);
16628 @@ -177,6 +181,8 @@ SYSCALL_DEFINE3(setpriority, int, which,
16629                         else
16630                                 pgrp = task_pgrp(current);
16631                         do_each_pid_thread(pgrp, PIDTYPE_PGID, p) {
16632 +                               if (!vx_check(p->xid, VS_ADMIN_P | VS_IDENT))
16633 +                                       continue;
16634                                 error = set_one_prio(p, niceval, error);
16635                         } while_each_pid_thread(pgrp, PIDTYPE_PGID, p);
16636                         break;
16637 @@ -238,6 +244,8 @@ SYSCALL_DEFINE2(getpriority, int, which,
16638                         else
16639                                 pgrp = task_pgrp(current);
16640                         do_each_pid_thread(pgrp, PIDTYPE_PGID, p) {
16641 +                               if (!vx_check(p->xid, VS_ADMIN_P | VS_IDENT))
16642 +                                       continue;
16643                                 niceval = 20 - task_nice(p);
16644                                 if (niceval > retval)
16645                                         retval = niceval;
16646 @@ -347,6 +355,9 @@ void kernel_power_off(void)
16647         machine_power_off();
16648  }
16649  EXPORT_SYMBOL_GPL(kernel_power_off);
16650 +
16651 +long vs_reboot(unsigned int, void __user *);
16652 +
16653  /*
16654   * Reboot system call: for obvious reasons only root may call it,
16655   * and even root needs to set up some magic numbers in the registers
16656 @@ -378,6 +389,9 @@ SYSCALL_DEFINE4(reboot, int, magic1, int
16657         if ((cmd == LINUX_REBOOT_CMD_POWER_OFF) && !pm_power_off)
16658                 cmd = LINUX_REBOOT_CMD_HALT;
16659  
16660 +       if (!vx_check(0, VS_ADMIN|VS_WATCH))
16661 +               return vs_reboot(cmd, arg);
16662 +
16663         lock_kernel();
16664         switch (cmd) {
16665         case LINUX_REBOOT_CMD_RESTART:
16666 @@ -1420,7 +1434,7 @@ SYSCALL_DEFINE2(sethostname, char __user
16667         int errno;
16668         char tmp[__NEW_UTS_LEN];
16669  
16670 -       if (!capable(CAP_SYS_ADMIN))
16671 +       if (!vx_capable(CAP_SYS_ADMIN, VXC_SET_UTSNAME))
16672                 return -EPERM;
16673         if (len < 0 || len > __NEW_UTS_LEN)
16674                 return -EINVAL;
16675 @@ -1469,7 +1483,7 @@ SYSCALL_DEFINE2(setdomainname, char __us
16676         int errno;
16677         char tmp[__NEW_UTS_LEN];
16678  
16679 -       if (!capable(CAP_SYS_ADMIN))
16680 +       if (!vx_capable(CAP_SYS_ADMIN, VXC_SET_UTSNAME))
16681                 return -EPERM;
16682         if (len < 0 || len > __NEW_UTS_LEN)
16683                 return -EINVAL;
16684 @@ -1538,7 +1552,7 @@ SYSCALL_DEFINE2(setrlimit, unsigned int,
16685                 return -EINVAL;
16686         old_rlim = current->signal->rlim + resource;
16687         if ((new_rlim.rlim_max > old_rlim->rlim_max) &&
16688 -           !capable(CAP_SYS_RESOURCE))
16689 +           !vx_capable(CAP_SYS_RESOURCE, VXC_SET_RLIMIT))
16690                 return -EPERM;
16691         if (resource == RLIMIT_NOFILE && new_rlim.rlim_max > sysctl_nr_open)
16692                 return -EPERM;
16693 diff -NurpP --minimal linux-2.6.29.1/kernel/sysctl.c linux-2.6.29.1-vs2.3.0.36.9-pre5/kernel/sysctl.c
16694 --- linux-2.6.29.1/kernel/sysctl.c      2009-03-24 14:22:45.000000000 +0100
16695 +++ linux-2.6.29.1-vs2.3.0.36.9-pre5/kernel/sysctl.c    2009-03-24 14:48:36.000000000 +0100
16696 @@ -114,6 +114,7 @@ static int ngroups_max = NGROUPS_MAX;
16697  #ifdef CONFIG_MODULES
16698  extern char modprobe_path[];
16699  #endif
16700 +extern char vshelper_path[];
16701  #ifdef CONFIG_CHR_DEV_SG
16702  extern int sg_big_buff;
16703  #endif
16704 @@ -545,6 +546,15 @@ static struct ctl_table kern_table[] = {
16705                 .strategy       = &sysctl_string,
16706         },
16707  #endif
16708 +       {
16709 +               .ctl_name       = KERN_VSHELPER,
16710 +               .procname       = "vshelper",
16711 +               .data           = &vshelper_path,
16712 +               .maxlen         = 256,
16713 +               .mode           = 0644,
16714 +               .proc_handler   = &proc_dostring,
16715 +               .strategy       = &sysctl_string,
16716 +       },
16717  #ifdef CONFIG_CHR_DEV_SG
16718         {
16719                 .ctl_name       = KERN_SG_BIG_BUFF,
16720 diff -NurpP --minimal linux-2.6.29.1/kernel/sysctl_check.c linux-2.6.29.1-vs2.3.0.36.9-pre5/kernel/sysctl_check.c
16721 --- linux-2.6.29.1/kernel/sysctl_check.c        2009-03-24 14:22:45.000000000 +0100
16722 +++ linux-2.6.29.1-vs2.3.0.36.9-pre5/kernel/sysctl_check.c      2009-03-24 14:48:36.000000000 +0100
16723 @@ -39,6 +39,7 @@ static const struct trans_ctl_table tran
16724  
16725         { KERN_PANIC,                   "panic" },
16726         { KERN_REALROOTDEV,             "real-root-dev" },
16727 +       { KERN_VSHELPER,                "vshelper", },
16728  
16729         { KERN_SPARC_REBOOT,            "reboot-cmd" },
16730         { KERN_CTLALTDEL,               "ctrl-alt-del" },
16731 @@ -1216,6 +1217,22 @@ static const struct trans_ctl_table tran
16732         {}
16733  };
16734  
16735 +static struct trans_ctl_table trans_vserver_table[] = {
16736 +       { 1,    "debug_switch" },
16737 +       { 2,    "debug_xid" },
16738 +       { 3,    "debug_nid" },
16739 +       { 4,    "debug_tag" },
16740 +       { 5,    "debug_net" },
16741 +       { 6,    "debug_limit" },
16742 +       { 7,    "debug_cres" },
16743 +       { 8,    "debug_dlim" },
16744 +       { 9,    "debug_quota" },
16745 +       { 10,   "debug_cvirt" },
16746 +       { 11,   "debug_space" },
16747 +       { 12,   "debug_misc" },
16748 +       {}
16749 +};
16750 +
16751  static const struct trans_ctl_table trans_root_table[] = {
16752         { CTL_KERN,     "kernel",       trans_kern_table },
16753         { CTL_VM,       "vm",           trans_vm_table },
16754 @@ -1232,6 +1249,7 @@ static const struct trans_ctl_table tran
16755         { CTL_SUNRPC,   "sunrpc",       trans_sunrpc_table },
16756         { CTL_PM,       "pm",           trans_pm_table },
16757         { CTL_FRV,      "frv",          trans_frv_table },
16758 +       { CTL_VSERVER,  "vserver",      trans_vserver_table },
16759         {}
16760  };
16761  
16762 diff -NurpP --minimal linux-2.6.29.1/kernel/time.c linux-2.6.29.1-vs2.3.0.36.9-pre5/kernel/time.c
16763 --- linux-2.6.29.1/kernel/time.c        2009-03-24 14:22:45.000000000 +0100
16764 +++ linux-2.6.29.1-vs2.3.0.36.9-pre5/kernel/time.c      2009-03-24 14:48:36.000000000 +0100
16765 @@ -63,6 +63,7 @@ EXPORT_SYMBOL(sys_tz);
16766  SYSCALL_DEFINE1(time, time_t __user *, tloc)
16767  {
16768         time_t i = get_seconds();
16769 +/*     FIXME: do_gettimeofday(&tv) -> vx_gettimeofday(&tv) */
16770  
16771         if (tloc) {
16772                 if (put_user(i,tloc))
16773 @@ -93,7 +94,7 @@ SYSCALL_DEFINE1(stime, time_t __user *, 
16774         if (err)
16775                 return err;
16776  
16777 -       do_settimeofday(&tv);
16778 +       vx_settimeofday(&tv);
16779         return 0;
16780  }
16781  
16782 @@ -104,7 +105,7 @@ SYSCALL_DEFINE2(gettimeofday, struct tim
16783  {
16784         if (likely(tv != NULL)) {
16785                 struct timeval ktv;
16786 -               do_gettimeofday(&ktv);
16787 +               vx_gettimeofday(&ktv);
16788                 if (copy_to_user(tv, &ktv, sizeof(ktv)))
16789                         return -EFAULT;
16790         }
16791 @@ -179,7 +180,7 @@ int do_sys_settimeofday(struct timespec 
16792                 /* SMP safe, again the code in arch/foo/time.c should
16793                  * globally block out interrupts when it runs.
16794                  */
16795 -               return do_settimeofday(tv);
16796 +               return vx_settimeofday(tv);
16797         }
16798         return 0;
16799  }
16800 @@ -311,7 +312,7 @@ void getnstimeofday(struct timespec *tv)
16801  {
16802         struct timeval x;
16803  
16804 -       do_gettimeofday(&x);
16805 +       vx_gettimeofday(&x);
16806         tv->tv_sec = x.tv_sec;
16807         tv->tv_nsec = x.tv_usec * NSEC_PER_USEC;
16808  }
16809 diff -NurpP --minimal linux-2.6.29.1/kernel/timer.c linux-2.6.29.1-vs2.3.0.36.9-pre5/kernel/timer.c
16810 --- linux-2.6.29.1/kernel/timer.c       2009-03-24 14:22:45.000000000 +0100
16811 +++ linux-2.6.29.1-vs2.3.0.36.9-pre5/kernel/timer.c     2009-03-24 17:41:02.000000000 +0100
16812 @@ -37,6 +37,10 @@
16813  #include <linux/delay.h>
16814  #include <linux/tick.h>
16815  #include <linux/kallsyms.h>
16816 +#include <linux/vs_base.h>
16817 +#include <linux/vs_cvirt.h>
16818 +#include <linux/vs_pid.h>
16819 +#include <linux/vserver/sched.h>
16820  
16821  #include <asm/uaccess.h>
16822  #include <asm/unistd.h>
16823 @@ -1018,6 +1022,25 @@ unsigned long get_next_timer_interrupt(u
16824  }
16825  #endif
16826  
16827 +static inline
16828 +void __vx_consume_token(struct _vx_sched_pc *sched_pc)
16829 +{
16830 +       sched_pc->tokens--;
16831 +}
16832 +
16833 +static inline
16834 +void vx_hard_tick(struct task_struct *p, int cpu)
16835 +{
16836 +       struct vx_info *vxi = p->vx_info;
16837 +
16838 +       if (vx_info_flags(vxi, VXF_SCHED_HARD|VXF_SCHED_PRIO, 0)) {
16839 +               struct _vx_sched_pc *sched_pc =
16840 +                       &vx_per_cpu(vxi, sched_pc, cpu);
16841 +
16842 +               __vx_consume_token(sched_pc);
16843 +       }
16844 +}
16845 +
16846  /*
16847   * Called from the timer interrupt handler to charge one tick to the current
16848   * process.  user_tick is 1 if the tick is user time, 0 for system.
16849 @@ -1034,6 +1057,7 @@ void update_process_times(int user_tick)
16850                 rcu_check_callbacks(cpu, user_tick);
16851         printk_tick();
16852         scheduler_tick();
16853 +       vx_hard_tick(p, cpu);
16854         run_posix_cpu_timers(p);
16855  }
16856  
16857 @@ -1136,12 +1160,6 @@ SYSCALL_DEFINE1(alarm, unsigned int, sec
16858  
16859  #endif
16860  
16861 -#ifndef __alpha__
16862 -
16863 -/*
16864 - * The Alpha uses getxpid, getxuid, and getxgid instead.  Maybe this
16865 - * should be moved into arch/i386 instead?
16866 - */
16867  
16868  /**
16869   * sys_getpid - return the thread group id of the current process
16870 @@ -1170,10 +1188,23 @@ SYSCALL_DEFINE0(getppid)
16871         rcu_read_lock();
16872         pid = task_tgid_vnr(current->real_parent);
16873         rcu_read_unlock();
16874 +       return vx_map_pid(pid);
16875 +}
16876  
16877 -       return pid;
16878 +#ifdef __alpha__
16879 +
16880 +/*
16881 + * The Alpha uses getxpid, getxuid, and getxgid instead.
16882 + */
16883 +
16884 +asmlinkage long do_getxpid(long *ppid)
16885 +{
16886 +       *ppid = sys_getppid();
16887 +       return sys_getpid();
16888  }
16889  
16890 +#else /* _alpha_ */
16891 +
16892  SYSCALL_DEFINE0(getuid)
16893  {
16894         /* Only we change this so SMP safe */
16895 @@ -1344,6 +1375,8 @@ int do_sysinfo(struct sysinfo *info)
16896                         tp.tv_nsec = tp.tv_nsec - NSEC_PER_SEC;
16897                         tp.tv_sec++;
16898                 }
16899 +               if (vx_flags(VXF_VIRT_UPTIME, 0))
16900 +                       vx_vsi_uptime(&tp, NULL);
16901                 info->uptime = tp.tv_sec + (tp.tv_nsec ? 1 : 0);
16902  
16903                 info->loads[0] = avenrun[0] << (SI_LOAD_SHIFT - FSHIFT);
16904 diff -NurpP --minimal linux-2.6.29.1/kernel/user.c linux-2.6.29.1-vs2.3.0.36.9-pre5/kernel/user.c
16905 --- linux-2.6.29.1/kernel/user.c        2009-03-24 14:22:45.000000000 +0100
16906 +++ linux-2.6.29.1-vs2.3.0.36.9-pre5/kernel/user.c      2009-03-24 17:47:32.000000000 +0100
16907 @@ -249,10 +249,10 @@ static struct kobj_type uids_ktype = {
16908   *
16909   * See Documentation/scheduler/sched-design-CFS.txt for ramifications.
16910   */
16911 -static int uids_user_create(struct user_struct *up)
16912 +static int uids_user_create(struct user_namespace *ns, struct user_struct *up)
16913  {
16914         struct kobject *kobj = &up->kobj;
16915 -       int error;
16916 +       int error = 0;
16917  
16918         memset(kobj, 0, sizeof(struct kobject));
16919         if (up->user_ns != &init_user_ns)
16920 @@ -280,7 +280,7 @@ int __init uids_sysfs_init(void)
16921         if (!uids_kset)
16922                 return -ENOMEM;
16923  
16924 -       return uids_user_create(&root_user);
16925 +       return uids_user_create(NULL, &root_user);
16926  }
16927  
16928  /* work function to remove sysfs directory for a user and free up
16929 @@ -342,7 +342,8 @@ static void free_user(struct user_struct
16930  #else  /* CONFIG_USER_SCHED && CONFIG_SYSFS */
16931  
16932  int uids_sysfs_init(void) { return 0; }
16933 -static inline int uids_user_create(struct user_struct *up) { return 0; }
16934 +static inline int uids_user_create(struct user_namespace *ns,
16935 +       struct user_struct *up) { return 0; }
16936  static inline void uids_mutex_lock(void) { }
16937  static inline void uids_mutex_unlock(void) { }
16938  
16939 @@ -439,7 +440,7 @@ struct user_struct *alloc_uid(struct use
16940  
16941                 new->user_ns = get_user_ns(ns);
16942  
16943 -               if (uids_user_create(new))
16944 +               if (uids_user_create(ns, new))
16945                         goto out_destoy_sched;
16946  
16947                 /*
16948 diff -NurpP --minimal linux-2.6.29.1/kernel/user_namespace.c linux-2.6.29.1-vs2.3.0.36.9-pre5/kernel/user_namespace.c
16949 --- linux-2.6.29.1/kernel/user_namespace.c      2009-03-24 14:22:45.000000000 +0100
16950 +++ linux-2.6.29.1-vs2.3.0.36.9-pre5/kernel/user_namespace.c    2009-03-24 18:05:19.000000000 +0100
16951 @@ -10,6 +10,7 @@
16952  #include <linux/slab.h>
16953  #include <linux/user_namespace.h>
16954  #include <linux/cred.h>
16955 +#include <linux/vserver/global.h>
16956  
16957  /*
16958   * Create a new user namespace, deriving the creator from the user in the
16959 @@ -30,6 +31,7 @@ int create_user_ns(struct cred *new)
16960                 return -ENOMEM;
16961  
16962         kref_init(&ns->kref);
16963 +       atomic_inc(&vs_global_user_ns);
16964  
16965         for (n = 0; n < UIDHASH_SZ; ++n)
16966                 INIT_HLIST_HEAD(ns->uidhash_table + n);
16967 @@ -78,6 +80,8 @@ void free_user_ns(struct kref *kref)
16968         struct user_namespace *ns =
16969                 container_of(kref, struct user_namespace, kref);
16970  
16971 +       /* FIXME: maybe move into destroyer? */
16972 +       atomic_dec(&vs_global_user_ns);
16973         INIT_WORK(&ns->destroyer, free_user_ns_work);
16974         schedule_work(&ns->destroyer);
16975  }
16976 diff -NurpP --minimal linux-2.6.29.1/kernel/utsname.c linux-2.6.29.1-vs2.3.0.36.9-pre5/kernel/utsname.c
16977 --- linux-2.6.29.1/kernel/utsname.c     2008-12-25 00:26:37.000000000 +0100
16978 +++ linux-2.6.29.1-vs2.3.0.36.9-pre5/kernel/utsname.c   2009-02-22 22:54:26.000000000 +0100
16979 @@ -14,6 +14,7 @@
16980  #include <linux/utsname.h>
16981  #include <linux/err.h>
16982  #include <linux/slab.h>
16983 +#include <linux/vserver/global.h>
16984  
16985  /*
16986   * Clone a new ns copying an original utsname, setting refcount to 1
16987 @@ -32,6 +33,7 @@ static struct uts_namespace *clone_uts_n
16988         memcpy(&ns->name, &old_ns->name, sizeof(ns->name));
16989         up_read(&uts_sem);
16990         kref_init(&ns->kref);
16991 +       atomic_inc(&vs_global_uts_ns);
16992         return ns;
16993  }
16994  
16995 @@ -62,5 +64,6 @@ void free_uts_ns(struct kref *kref)
16996         struct uts_namespace *ns;
16997  
16998         ns = container_of(kref, struct uts_namespace, kref);
16999 +       atomic_dec(&vs_global_uts_ns);
17000         kfree(ns);
17001  }
17002 diff -NurpP --minimal linux-2.6.29.1/kernel/vserver/cacct.c linux-2.6.29.1-vs2.3.0.36.9-pre5/kernel/vserver/cacct.c
17003 --- linux-2.6.29.1/kernel/vserver/cacct.c       1970-01-01 01:00:00.000000000 +0100
17004 +++ linux-2.6.29.1-vs2.3.0.36.9-pre5/kernel/vserver/cacct.c     2009-02-22 22:54:26.000000000 +0100
17005 @@ -0,0 +1,42 @@
17006 +/*
17007 + *  linux/kernel/vserver/cacct.c
17008 + *
17009 + *  Virtual Server: Context Accounting
17010 + *
17011 + *  Copyright (C) 2006-2007 Herbert Pötzl
17012 + *
17013 + *  V0.01  added accounting stats
17014 + *
17015 + */
17016 +
17017 +#include <linux/types.h>
17018 +#include <linux/vs_context.h>
17019 +#include <linux/vserver/cacct_cmd.h>
17020 +#include <linux/vserver/cacct_int.h>
17021 +
17022 +#include <asm/errno.h>
17023 +#include <asm/uaccess.h>
17024 +
17025 +
17026 +int vc_sock_stat(struct vx_info *vxi, void __user *data)
17027 +{
17028 +       struct vcmd_sock_stat_v0 vc_data;
17029 +       int j, field;
17030 +
17031 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
17032 +               return -EFAULT;
17033 +
17034 +       field = vc_data.field;
17035 +       if ((field < 0) || (field >= VXA_SOCK_SIZE))
17036 +               return -EINVAL;
17037 +
17038 +       for (j = 0; j < 3; j++) {
17039 +               vc_data.count[j] = vx_sock_count(&vxi->cacct, field, j);
17040 +               vc_data.total[j] = vx_sock_total(&vxi->cacct, field, j);
17041 +       }
17042 +
17043 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
17044 +               return -EFAULT;
17045 +       return 0;
17046 +}
17047 +
17048 diff -NurpP --minimal linux-2.6.29.1/kernel/vserver/cacct_init.h linux-2.6.29.1-vs2.3.0.36.9-pre5/kernel/vserver/cacct_init.h
17049 --- linux-2.6.29.1/kernel/vserver/cacct_init.h  1970-01-01 01:00:00.000000000 +0100
17050 +++ linux-2.6.29.1-vs2.3.0.36.9-pre5/kernel/vserver/cacct_init.h        2009-02-22 22:54:26.000000000 +0100
17051 @@ -0,0 +1,25 @@
17052 +
17053 +
17054 +static inline void vx_info_init_cacct(struct _vx_cacct *cacct)
17055 +{
17056 +       int i, j;
17057 +
17058 +
17059 +       for (i = 0; i < VXA_SOCK_SIZE; i++) {
17060 +               for (j = 0; j < 3; j++) {
17061 +                       atomic_set(&cacct->sock[i][j].count, 0);
17062 +                       atomic_set(&cacct->sock[i][j].total, 0);
17063 +               }
17064 +       }
17065 +       for (i = 0; i < 8; i++)
17066 +               atomic_set(&cacct->slab[i], 0);
17067 +       for (i = 0; i < 5; i++)
17068 +               for (j = 0; j < 4; j++)
17069 +                       atomic_set(&cacct->page[i][j], 0);
17070 +}
17071 +
17072 +static inline void vx_info_exit_cacct(struct _vx_cacct *cacct)
17073 +{
17074 +       return;
17075 +}
17076 +
17077 diff -NurpP --minimal linux-2.6.29.1/kernel/vserver/cacct_proc.h linux-2.6.29.1-vs2.3.0.36.9-pre5/kernel/vserver/cacct_proc.h
17078 --- linux-2.6.29.1/kernel/vserver/cacct_proc.h  1970-01-01 01:00:00.000000000 +0100
17079 +++ linux-2.6.29.1-vs2.3.0.36.9-pre5/kernel/vserver/cacct_proc.h        2009-02-22 22:54:26.000000000 +0100
17080 @@ -0,0 +1,53 @@
17081 +#ifndef _VX_CACCT_PROC_H
17082 +#define _VX_CACCT_PROC_H
17083 +
17084 +#include <linux/vserver/cacct_int.h>
17085 +
17086 +
17087 +#define VX_SOCKA_TOP   \
17088 +       "Type\t    recv #/bytes\t\t   send #/bytes\t\t    fail #/bytes\n"
17089 +
17090 +static inline int vx_info_proc_cacct(struct _vx_cacct *cacct, char *buffer)
17091 +{
17092 +       int i, j, length = 0;
17093 +       static char *type[VXA_SOCK_SIZE] = {
17094 +               "UNSPEC", "UNIX", "INET", "INET6", "PACKET", "OTHER"
17095 +       };
17096 +
17097 +       length += sprintf(buffer + length, VX_SOCKA_TOP);
17098 +       for (i = 0; i < VXA_SOCK_SIZE; i++) {
17099 +               length += sprintf(buffer + length, "%s:", type[i]);
17100 +               for (j = 0; j < 3; j++) {
17101 +                       length += sprintf(buffer + length,
17102 +                               "\t%10lu/%-10lu",
17103 +                               vx_sock_count(cacct, i, j),
17104 +                               vx_sock_total(cacct, i, j));
17105 +               }
17106 +               buffer[length++] = '\n';
17107 +       }
17108 +
17109 +       length += sprintf(buffer + length, "\n");
17110 +       length += sprintf(buffer + length,
17111 +               "slab:\t %8u %8u %8u %8u\n",
17112 +               atomic_read(&cacct->slab[1]),
17113 +               atomic_read(&cacct->slab[4]),
17114 +               atomic_read(&cacct->slab[0]),
17115 +               atomic_read(&cacct->slab[2]));
17116 +
17117 +       length += sprintf(buffer + length, "\n");
17118 +       for (i = 0; i < 5; i++) {
17119 +               length += sprintf(buffer + length,
17120 +                       "page[%d]: %8u %8u %8u %8u\t %8u %8u %8u %8u\n", i,
17121 +                       atomic_read(&cacct->page[i][0]),
17122 +                       atomic_read(&cacct->page[i][1]),
17123 +                       atomic_read(&cacct->page[i][2]),
17124 +                       atomic_read(&cacct->page[i][3]),
17125 +                       atomic_read(&cacct->page[i][4]),
17126 +                       atomic_read(&cacct->page[i][5]),
17127 +                       atomic_read(&cacct->page[i][6]),
17128 +                       atomic_read(&cacct->page[i][7]));
17129 +       }
17130 +       return length;
17131 +}
17132 +
17133 +#endif /* _VX_CACCT_PROC_H */
17134 diff -NurpP --minimal linux-2.6.29.1/kernel/vserver/context.c linux-2.6.29.1-vs2.3.0.36.9-pre5/kernel/vserver/context.c
17135 --- linux-2.6.29.1/kernel/vserver/context.c     1970-01-01 01:00:00.000000000 +0100
17136 +++ linux-2.6.29.1-vs2.3.0.36.9-pre5/kernel/vserver/context.c   2009-04-03 21:25:31.000000000 +0200
17137 @@ -0,0 +1,1018 @@
17138 +/*
17139 + *  linux/kernel/vserver/context.c
17140 + *
17141 + *  Virtual Server: Context Support
17142 + *
17143 + *  Copyright (C) 2003-2007  Herbert Pötzl
17144 + *
17145 + *  V0.01  context helper
17146 + *  V0.02  vx_ctx_kill syscall command
17147 + *  V0.03  replaced context_info calls
17148 + *  V0.04  redesign of struct (de)alloc
17149 + *  V0.05  rlimit basic implementation
17150 + *  V0.06  task_xid and info commands
17151 + *  V0.07  context flags and caps
17152 + *  V0.08  switch to RCU based hash
17153 + *  V0.09  revert to non RCU for now
17154 + *  V0.10  and back to working RCU hash
17155 + *  V0.11  and back to locking again
17156 + *  V0.12  referenced context store
17157 + *  V0.13  separate per cpu data
17158 + *  V0.14  changed vcmds to vxi arg
17159 + *  V0.15  added context stat
17160 + *  V0.16  have __create claim() the vxi
17161 + *  V0.17  removed older and legacy stuff
17162 + *
17163 + */
17164 +
17165 +#include <linux/slab.h>
17166 +#include <linux/types.h>
17167 +#include <linux/security.h>
17168 +#include <linux/pid_namespace.h>
17169 +
17170 +#include <linux/vserver/context.h>
17171 +#include <linux/vserver/network.h>
17172 +#include <linux/vserver/debug.h>
17173 +#include <linux/vserver/limit.h>
17174 +#include <linux/vserver/limit_int.h>
17175 +#include <linux/vserver/space.h>
17176 +
17177 +#include <linux/vs_context.h>
17178 +#include <linux/vs_limit.h>
17179 +#include <linux/vs_pid.h>
17180 +#include <linux/vserver/context_cmd.h>
17181 +
17182 +#include "cvirt_init.h"
17183 +#include "cacct_init.h"
17184 +#include "limit_init.h"
17185 +#include "sched_init.h"
17186 +
17187 +
17188 +atomic_t vx_global_ctotal      = ATOMIC_INIT(0);
17189 +atomic_t vx_global_cactive     = ATOMIC_INIT(0);
17190 +
17191 +
17192 +/*     now inactive context structures */
17193 +
17194 +static struct hlist_head vx_info_inactive = HLIST_HEAD_INIT;
17195 +
17196 +static spinlock_t vx_info_inactive_lock = SPIN_LOCK_UNLOCKED;
17197 +
17198 +
17199 +/*     __alloc_vx_info()
17200 +
17201 +       * allocate an initialized vx_info struct
17202 +       * doesn't make it visible (hash)                        */
17203 +
17204 +static struct vx_info *__alloc_vx_info(xid_t xid)
17205 +{
17206 +       struct vx_info *new = NULL;
17207 +       int cpu;
17208 +
17209 +       vxdprintk(VXD_CBIT(xid, 0), "alloc_vx_info(%d)*", xid);
17210 +
17211 +       /* would this benefit from a slab cache? */
17212 +       new = kmalloc(sizeof(struct vx_info), GFP_KERNEL);
17213 +       if (!new)
17214 +               return 0;
17215 +
17216 +       memset(new, 0, sizeof(struct vx_info));
17217 +#ifdef CONFIG_SMP
17218 +       new->ptr_pc = alloc_percpu(struct _vx_info_pc);
17219 +       if (!new->ptr_pc)
17220 +               goto error;
17221 +#endif
17222 +       new->vx_id = xid;
17223 +       INIT_HLIST_NODE(&new->vx_hlist);
17224 +       atomic_set(&new->vx_usecnt, 0);
17225 +       atomic_set(&new->vx_tasks, 0);
17226 +       new->vx_parent = NULL;
17227 +       new->vx_state = 0;
17228 +       init_waitqueue_head(&new->vx_wait);
17229 +
17230 +       /* prepare reaper */
17231 +       get_task_struct(init_pid_ns.child_reaper);
17232 +       new->vx_reaper = init_pid_ns.child_reaper;
17233 +       new->vx_badness_bias = 0;
17234 +
17235 +       /* rest of init goes here */
17236 +       vx_info_init_limit(&new->limit);
17237 +       vx_info_init_sched(&new->sched);
17238 +       vx_info_init_cvirt(&new->cvirt);
17239 +       vx_info_init_cacct(&new->cacct);
17240 +
17241 +       /* per cpu data structures */
17242 +       for_each_possible_cpu(cpu) {
17243 +               vx_info_init_sched_pc(
17244 +                       &vx_per_cpu(new, sched_pc, cpu), cpu);
17245 +               vx_info_init_cvirt_pc(
17246 +                       &vx_per_cpu(new, cvirt_pc, cpu), cpu);
17247 +       }
17248 +
17249 +       new->vx_flags = VXF_INIT_SET;
17250 +       cap_set_init_eff(new->vx_bcaps);
17251 +       new->vx_ccaps = 0;
17252 +       // new->vx_cap_bset = current->cap_bset;
17253 +
17254 +       new->reboot_cmd = 0;
17255 +       new->exit_code = 0;
17256 +
17257 +       vxdprintk(VXD_CBIT(xid, 0),
17258 +               "alloc_vx_info(%d) = %p", xid, new);
17259 +       vxh_alloc_vx_info(new);
17260 +       atomic_inc(&vx_global_ctotal);
17261 +       return new;
17262 +#ifdef CONFIG_SMP
17263 +error:
17264 +       kfree(new);
17265 +       return 0;
17266 +#endif
17267 +}
17268 +
17269 +/*     __dealloc_vx_info()
17270 +
17271 +       * final disposal of vx_info                             */
17272 +
17273 +static void __dealloc_vx_info(struct vx_info *vxi)
17274 +{
17275 +       struct vx_info_save vxis;
17276 +       int cpu;
17277 +
17278 +       vxdprintk(VXD_CBIT(xid, 0),
17279 +               "dealloc_vx_info(%p)", vxi);
17280 +       vxh_dealloc_vx_info(vxi);
17281 +
17282 +#ifdef CONFIG_VSERVER_WARN
17283 +       enter_vx_info(vxi, &vxis);
17284 +       vx_info_exit_limit(&vxi->limit);
17285 +       vx_info_exit_sched(&vxi->sched);
17286 +       vx_info_exit_cvirt(&vxi->cvirt);
17287 +       vx_info_exit_cacct(&vxi->cacct);
17288 +
17289 +       for_each_possible_cpu(cpu) {
17290 +               vx_info_exit_sched_pc(
17291 +                       &vx_per_cpu(vxi, sched_pc, cpu), cpu);
17292 +               vx_info_exit_cvirt_pc(
17293 +                       &vx_per_cpu(vxi, cvirt_pc, cpu), cpu);
17294 +       }
17295 +       leave_vx_info(&vxis);
17296 +#endif
17297 +
17298 +       vxi->vx_id = -1;
17299 +       vxi->vx_state |= VXS_RELEASED;
17300 +
17301 +#ifdef CONFIG_SMP
17302 +       free_percpu(vxi->ptr_pc);
17303 +#endif
17304 +       kfree(vxi);
17305 +       atomic_dec(&vx_global_ctotal);
17306 +}
17307 +
17308 +static void __shutdown_vx_info(struct vx_info *vxi)
17309 +{
17310 +       struct nsproxy *nsproxy;
17311 +       struct fs_struct *fs;
17312 +       int index;
17313 +
17314 +       might_sleep();
17315 +
17316 +       vxi->vx_state |= VXS_SHUTDOWN;
17317 +       vs_state_change(vxi, VSC_SHUTDOWN);
17318 +
17319 +       for (index = 0; index < VX_SPACES; index++) {
17320 +               nsproxy = xchg(&vxi->vx_nsproxy[index], NULL);
17321 +               if (nsproxy)
17322 +                       put_nsproxy(nsproxy);
17323 +
17324 +               fs = xchg(&vxi->vx_fs[index], NULL);
17325 +               if (fs)
17326 +                       put_fs_struct(fs);
17327 +       }
17328 +}
17329 +
17330 +/* exported stuff */
17331 +
17332 +void free_vx_info(struct vx_info *vxi)
17333 +{
17334 +       unsigned long flags;
17335 +       unsigned index;
17336 +
17337 +       /* check for reference counts first */
17338 +       BUG_ON(atomic_read(&vxi->vx_usecnt));
17339 +       BUG_ON(atomic_read(&vxi->vx_tasks));
17340 +
17341 +       /* context must not be hashed */
17342 +       BUG_ON(vx_info_state(vxi, VXS_HASHED));
17343 +
17344 +       /* context shutdown is mandatory */
17345 +       BUG_ON(!vx_info_state(vxi, VXS_SHUTDOWN));
17346 +
17347 +       /* nsproxy and fs check */
17348 +       for (index = 0; index < VX_SPACES; index++) {
17349 +               BUG_ON(vxi->vx_nsproxy[index]);
17350 +               BUG_ON(vxi->vx_fs[index]);
17351 +       }
17352 +
17353 +       spin_lock_irqsave(&vx_info_inactive_lock, flags);
17354 +       hlist_del(&vxi->vx_hlist);
17355 +       spin_unlock_irqrestore(&vx_info_inactive_lock, flags);
17356 +
17357 +       __dealloc_vx_info(vxi);
17358 +}
17359 +
17360 +
17361 +/*     hash table for vx_info hash */
17362 +
17363 +#define VX_HASH_SIZE   13
17364 +
17365 +static struct hlist_head vx_info_hash[VX_HASH_SIZE] =
17366 +       { [0 ... VX_HASH_SIZE-1] = HLIST_HEAD_INIT };
17367 +
17368 +static spinlock_t vx_info_hash_lock = SPIN_LOCK_UNLOCKED;
17369 +
17370 +
17371 +static inline unsigned int __hashval(xid_t xid)
17372 +{
17373 +       return (xid % VX_HASH_SIZE);
17374 +}
17375 +
17376 +
17377 +
17378 +/*     __hash_vx_info()
17379 +
17380 +       * add the vxi to the global hash table
17381 +       * requires the hash_lock to be held                     */
17382 +
17383 +static inline void __hash_vx_info(struct vx_info *vxi)
17384 +{
17385 +       struct hlist_head *head;
17386 +
17387 +       vxd_assert_lock(&vx_info_hash_lock);
17388 +       vxdprintk(VXD_CBIT(xid, 4),
17389 +               "__hash_vx_info: %p[#%d]", vxi, vxi->vx_id);
17390 +       vxh_hash_vx_info(vxi);
17391 +
17392 +       /* context must not be hashed */
17393 +       BUG_ON(vx_info_state(vxi, VXS_HASHED));
17394 +
17395 +       vxi->vx_state |= VXS_HASHED;
17396 +       head = &vx_info_hash[__hashval(vxi->vx_id)];
17397 +       hlist_add_head(&vxi->vx_hlist, head);
17398 +       atomic_inc(&vx_global_cactive);
17399 +}
17400 +
17401 +/*     __unhash_vx_info()
17402 +
17403 +       * remove the vxi from the global hash table
17404 +       * requires the hash_lock to be held                     */
17405 +
17406 +static inline void __unhash_vx_info(struct vx_info *vxi)
17407 +{
17408 +       unsigned long flags;
17409 +
17410 +       vxd_assert_lock(&vx_info_hash_lock);
17411 +       vxdprintk(VXD_CBIT(xid, 4),
17412 +               "__unhash_vx_info: %p[#%d.%d.%d]", vxi, vxi->vx_id,
17413 +               atomic_read(&vxi->vx_usecnt), atomic_read(&vxi->vx_tasks));
17414 +       vxh_unhash_vx_info(vxi);
17415 +
17416 +       /* context must be hashed */
17417 +       BUG_ON(!vx_info_state(vxi, VXS_HASHED));
17418 +       /* but without tasks */
17419 +       BUG_ON(atomic_read(&vxi->vx_tasks));
17420 +
17421 +       vxi->vx_state &= ~VXS_HASHED;
17422 +       hlist_del_init(&vxi->vx_hlist);
17423 +       spin_lock_irqsave(&vx_info_inactive_lock, flags);
17424 +       hlist_add_head(&vxi->vx_hlist, &vx_info_inactive);
17425 +       spin_unlock_irqrestore(&vx_info_inactive_lock, flags);
17426 +       atomic_dec(&vx_global_cactive);
17427 +}
17428 +
17429 +
17430 +/*     __lookup_vx_info()
17431 +
17432 +       * requires the hash_lock to be held
17433 +       * doesn't increment the vx_refcnt                       */
17434 +
17435 +static inline struct vx_info *__lookup_vx_info(xid_t xid)
17436 +{
17437 +       struct hlist_head *head = &vx_info_hash[__hashval(xid)];
17438 +       struct hlist_node *pos;
17439 +       struct vx_info *vxi;
17440 +
17441 +       vxd_assert_lock(&vx_info_hash_lock);
17442 +       hlist_for_each(pos, head) {
17443 +               vxi = hlist_entry(pos, struct vx_info, vx_hlist);
17444 +
17445 +               if (vxi->vx_id == xid)
17446 +                       goto found;
17447 +       }
17448 +       vxi = NULL;
17449 +found:
17450 +       vxdprintk(VXD_CBIT(xid, 0),
17451 +               "__lookup_vx_info(#%u): %p[#%u]",
17452 +               xid, vxi, vxi ? vxi->vx_id : 0);
17453 +       vxh_lookup_vx_info(vxi, xid);
17454 +       return vxi;
17455 +}
17456 +
17457 +
17458 +/*     __create_vx_info()
17459 +
17460 +       * create the requested context
17461 +       * get(), claim() and hash it                            */
17462 +
17463 +static struct vx_info *__create_vx_info(int id)
17464 +{
17465 +       struct vx_info *new, *vxi = NULL;
17466 +
17467 +       vxdprintk(VXD_CBIT(xid, 1), "create_vx_info(%d)*", id);
17468 +
17469 +       if (!(new = __alloc_vx_info(id)))
17470 +               return ERR_PTR(-ENOMEM);
17471 +
17472 +       /* required to make dynamic xids unique */
17473 +       spin_lock(&vx_info_hash_lock);
17474 +
17475 +       /* static context requested */
17476 +       if ((vxi = __lookup_vx_info(id))) {
17477 +               vxdprintk(VXD_CBIT(xid, 0),
17478 +                       "create_vx_info(%d) = %p (already there)", id, vxi);
17479 +               if (vx_info_flags(vxi, VXF_STATE_SETUP, 0))
17480 +                       vxi = ERR_PTR(-EBUSY);
17481 +               else
17482 +                       vxi = ERR_PTR(-EEXIST);
17483 +               goto out_unlock;
17484 +       }
17485 +       /* new context */
17486 +       vxdprintk(VXD_CBIT(xid, 0),
17487 +               "create_vx_info(%d) = %p (new)", id, new);
17488 +       claim_vx_info(new, NULL);
17489 +       __hash_vx_info(get_vx_info(new));
17490 +       vxi = new, new = NULL;
17491 +
17492 +out_unlock:
17493 +       spin_unlock(&vx_info_hash_lock);
17494 +       vxh_create_vx_info(IS_ERR(vxi) ? NULL : vxi, id);
17495 +       if (new)
17496 +               __dealloc_vx_info(new);
17497 +       return vxi;
17498 +}
17499 +
17500 +
17501 +/*     exported stuff                                          */
17502 +
17503 +
17504 +void unhash_vx_info(struct vx_info *vxi)
17505 +{
17506 +       __shutdown_vx_info(vxi);
17507 +       spin_lock(&vx_info_hash_lock);
17508 +       __unhash_vx_info(vxi);
17509 +       spin_unlock(&vx_info_hash_lock);
17510 +       __wakeup_vx_info(vxi);
17511 +}
17512 +
17513 +
17514 +/*     lookup_vx_info()
17515 +
17516 +       * search for a vx_info and get() it
17517 +       * negative id means current                             */
17518 +
17519 +struct vx_info *lookup_vx_info(int id)
17520 +{
17521 +       struct vx_info *vxi = NULL;
17522 +
17523 +       if (id < 0) {
17524 +               vxi = get_vx_info(current->vx_info);
17525 +       } else if (id > 1) {
17526 +               spin_lock(&vx_info_hash_lock);
17527 +               vxi = get_vx_info(__lookup_vx_info(id));
17528 +               spin_unlock(&vx_info_hash_lock);
17529 +       }
17530 +       return vxi;
17531 +}
17532 +
17533 +/*     xid_is_hashed()
17534 +
17535 +       * verify that xid is still hashed                       */
17536 +
17537 +int xid_is_hashed(xid_t xid)
17538 +{
17539 +       int hashed;
17540 +
17541 +       spin_lock(&vx_info_hash_lock);
17542 +       hashed = (__lookup_vx_info(xid) != NULL);
17543 +       spin_unlock(&vx_info_hash_lock);
17544 +       return hashed;
17545 +}
17546 +
17547 +#ifdef CONFIG_PROC_FS
17548 +
17549 +/*     get_xid_list()
17550 +
17551 +       * get a subset of hashed xids for proc
17552 +       * assumes size is at least one                          */
17553 +
17554 +int get_xid_list(int index, unsigned int *xids, int size)
17555 +{
17556 +       int hindex, nr_xids = 0;
17557 +
17558 +       /* only show current and children */
17559 +       if (!vx_check(0, VS_ADMIN | VS_WATCH)) {
17560 +               if (index > 0)
17561 +                       return 0;
17562 +               xids[nr_xids] = vx_current_xid();
17563 +               return 1;
17564 +       }
17565 +
17566 +       for (hindex = 0; hindex < VX_HASH_SIZE; hindex++) {
17567 +               struct hlist_head *head = &vx_info_hash[hindex];
17568 +               struct hlist_node *pos;
17569 +
17570 +               spin_lock(&vx_info_hash_lock);
17571 +               hlist_for_each(pos, head) {
17572 +                       struct vx_info *vxi;
17573 +
17574 +                       if (--index > 0)
17575 +                               continue;
17576 +
17577 +                       vxi = hlist_entry(pos, struct vx_info, vx_hlist);
17578 +                       xids[nr_xids] = vxi->vx_id;
17579 +                       if (++nr_xids >= size) {
17580 +                               spin_unlock(&vx_info_hash_lock);
17581 +                               goto out;
17582 +                       }
17583 +               }
17584 +               /* keep the lock time short */
17585 +               spin_unlock(&vx_info_hash_lock);
17586 +       }
17587 +out:
17588 +       return nr_xids;
17589 +}
17590 +#endif
17591 +
17592 +#ifdef CONFIG_VSERVER_DEBUG
17593 +
17594 +void   dump_vx_info_inactive(int level)
17595 +{
17596 +       struct hlist_node *entry, *next;
17597 +
17598 +       hlist_for_each_safe(entry, next, &vx_info_inactive) {
17599 +               struct vx_info *vxi =
17600 +                       list_entry(entry, struct vx_info, vx_hlist);
17601 +
17602 +               dump_vx_info(vxi, level);
17603 +       }
17604 +}
17605 +
17606 +#endif
17607 +
17608 +#if 0
17609 +int vx_migrate_user(struct task_struct *p, struct vx_info *vxi)
17610 +{
17611 +       struct user_struct *new_user, *old_user;
17612 +
17613 +       if (!p || !vxi)
17614 +               BUG();
17615 +
17616 +       if (vx_info_flags(vxi, VXF_INFO_PRIVATE, 0))
17617 +               return -EACCES;
17618 +
17619 +       new_user = alloc_uid(vxi->vx_id, p->uid);
17620 +       if (!new_user)
17621 +               return -ENOMEM;
17622 +
17623 +       old_user = p->user;
17624 +       if (new_user != old_user) {
17625 +               atomic_inc(&new_user->processes);
17626 +               atomic_dec(&old_user->processes);
17627 +               p->user = new_user;
17628 +       }
17629 +       free_uid(old_user);
17630 +       return 0;
17631 +}
17632 +#endif
17633 +
17634 +#if 0
17635 +void vx_mask_cap_bset(struct vx_info *vxi, struct task_struct *p)
17636 +{
17637 +       // p->cap_effective &= vxi->vx_cap_bset;
17638 +       p->cap_effective =
17639 +               cap_intersect(p->cap_effective, vxi->cap_bset);
17640 +       // p->cap_inheritable &= vxi->vx_cap_bset;
17641 +       p->cap_inheritable =
17642 +               cap_intersect(p->cap_inheritable, vxi->cap_bset);
17643 +       // p->cap_permitted &= vxi->vx_cap_bset;
17644 +       p->cap_permitted =
17645 +               cap_intersect(p->cap_permitted, vxi->cap_bset);
17646 +}
17647 +#endif
17648 +
17649 +
17650 +#include <linux/file.h>
17651 +#include <linux/fdtable.h>
17652 +
17653 +static int vx_openfd_task(struct task_struct *tsk)
17654 +{
17655 +       struct files_struct *files = tsk->files;
17656 +       struct fdtable *fdt;
17657 +       const unsigned long *bptr;
17658 +       int count, total;
17659 +
17660 +       /* no rcu_read_lock() because of spin_lock() */
17661 +       spin_lock(&files->file_lock);
17662 +       fdt = files_fdtable(files);
17663 +       bptr = fdt->open_fds->fds_bits;
17664 +       count = fdt->max_fds / (sizeof(unsigned long) * 8);
17665 +       for (total = 0; count > 0; count--) {
17666 +               if (*bptr)
17667 +                       total += hweight_long(*bptr);
17668 +               bptr++;
17669 +       }
17670 +       spin_unlock(&files->file_lock);
17671 +       return total;
17672 +}
17673 +
17674 +
17675 +/*     for *space compatibility */
17676 +
17677 +asmlinkage long sys_unshare(unsigned long);
17678 +
17679 +/*
17680 + *     migrate task to new context
17681 + *     gets vxi, puts old_vxi on change
17682 + *     optionally unshares namespaces (hack)
17683 + */
17684 +
17685 +int vx_migrate_task(struct task_struct *p, struct vx_info *vxi, int unshare)
17686 +{
17687 +       struct vx_info *old_vxi;
17688 +       int ret = 0;
17689 +
17690 +       if (!p || !vxi)
17691 +               BUG();
17692 +
17693 +       vxdprintk(VXD_CBIT(xid, 5),
17694 +               "vx_migrate_task(%p,%p[#%d.%d])", p, vxi,
17695 +               vxi->vx_id, atomic_read(&vxi->vx_usecnt));
17696 +
17697 +       if (vx_info_flags(vxi, VXF_INFO_PRIVATE, 0) &&
17698 +               !vx_info_flags(vxi, VXF_STATE_SETUP, 0))
17699 +               return -EACCES;
17700 +
17701 +       if (vx_info_state(vxi, VXS_SHUTDOWN))
17702 +               return -EFAULT;
17703 +
17704 +       old_vxi = task_get_vx_info(p);
17705 +       if (old_vxi == vxi)
17706 +               goto out;
17707 +
17708 +//     if (!(ret = vx_migrate_user(p, vxi))) {
17709 +       {
17710 +               int openfd;
17711 +
17712 +               task_lock(p);
17713 +               openfd = vx_openfd_task(p);
17714 +
17715 +               if (old_vxi) {
17716 +                       atomic_dec(&old_vxi->cvirt.nr_threads);
17717 +                       atomic_dec(&old_vxi->cvirt.nr_running);
17718 +                       __rlim_dec(&old_vxi->limit, RLIMIT_NPROC);
17719 +                       /* FIXME: what about the struct files here? */
17720 +                       __rlim_sub(&old_vxi->limit, VLIMIT_OPENFD, openfd);
17721 +                       /* account for the executable */
17722 +                       __rlim_dec(&old_vxi->limit, VLIMIT_DENTRY);
17723 +               }
17724 +               atomic_inc(&vxi->cvirt.nr_threads);
17725 +               atomic_inc(&vxi->cvirt.nr_running);
17726 +               __rlim_inc(&vxi->limit, RLIMIT_NPROC);
17727 +               /* FIXME: what about the struct files here? */
17728 +               __rlim_add(&vxi->limit, VLIMIT_OPENFD, openfd);
17729 +               /* account for the executable */
17730 +               __rlim_inc(&vxi->limit, VLIMIT_DENTRY);
17731 +
17732 +               if (old_vxi) {
17733 +                       release_vx_info(old_vxi, p);
17734 +                       clr_vx_info(&p->vx_info);
17735 +               }
17736 +               claim_vx_info(vxi, p);
17737 +               set_vx_info(&p->vx_info, vxi);
17738 +               p->xid = vxi->vx_id;
17739 +
17740 +               vxdprintk(VXD_CBIT(xid, 5),
17741 +                       "moved task %p into vxi:%p[#%d]",
17742 +                       p, vxi, vxi->vx_id);
17743 +
17744 +               // vx_mask_cap_bset(vxi, p);
17745 +               task_unlock(p);
17746 +
17747 +               /* hack for *spaces to provide compatibility */
17748 +               if (unshare) {
17749 +                       struct nsproxy *old_nsp, *new_nsp;
17750 +
17751 +                       ret = unshare_nsproxy_namespaces(
17752 +                               CLONE_NEWUTS | CLONE_NEWIPC | CLONE_NEWUSER,
17753 +                               &new_nsp, NULL);
17754 +                       if (ret)
17755 +                               goto out;
17756 +
17757 +                       old_nsp = xchg(&p->nsproxy, new_nsp);
17758 +                       vx_set_space(vxi,
17759 +                               CLONE_NEWUTS | CLONE_NEWIPC | CLONE_NEWUSER, 0);
17760 +                       put_nsproxy(old_nsp);
17761 +               }
17762 +       }
17763 +out:
17764 +       put_vx_info(old_vxi);
17765 +       return ret;
17766 +}
17767 +
17768 +int vx_set_reaper(struct vx_info *vxi, struct task_struct *p)
17769 +{
17770 +       struct task_struct *old_reaper;
17771 +
17772 +       if (!vxi)
17773 +               return -EINVAL;
17774 +
17775 +       vxdprintk(VXD_CBIT(xid, 6),
17776 +               "vx_set_reaper(%p[#%d],%p[#%d,%d])",
17777 +               vxi, vxi->vx_id, p, p->xid, p->pid);
17778 +
17779 +       old_reaper = vxi->vx_reaper;
17780 +       if (old_reaper == p)
17781 +               return 0;
17782 +
17783 +       /* set new child reaper */
17784 +       get_task_struct(p);
17785 +       vxi->vx_reaper = p;
17786 +       put_task_struct(old_reaper);
17787 +       return 0;
17788 +}
17789 +
17790 +int vx_set_init(struct vx_info *vxi, struct task_struct *p)
17791 +{
17792 +       if (!vxi)
17793 +               return -EINVAL;
17794 +
17795 +       vxdprintk(VXD_CBIT(xid, 6),
17796 +               "vx_set_init(%p[#%d],%p[#%d,%d,%d])",
17797 +               vxi, vxi->vx_id, p, p->xid, p->pid, p->tgid);
17798 +
17799 +       vxi->vx_flags &= ~VXF_STATE_INIT;
17800 +       vxi->vx_initpid = p->tgid;
17801 +       return 0;
17802 +}
17803 +
17804 +void vx_exit_init(struct vx_info *vxi, struct task_struct *p, int code)
17805 +{
17806 +       vxdprintk(VXD_CBIT(xid, 6),
17807 +               "vx_exit_init(%p[#%d],%p[#%d,%d,%d])",
17808 +               vxi, vxi->vx_id, p, p->xid, p->pid, p->tgid);
17809 +
17810 +       vxi->exit_code = code;
17811 +       vxi->vx_initpid = 0;
17812 +}
17813 +
17814 +
17815 +void vx_set_persistent(struct vx_info *vxi)
17816 +{
17817 +       vxdprintk(VXD_CBIT(xid, 6),
17818 +               "vx_set_persistent(%p[#%d])", vxi, vxi->vx_id);
17819 +
17820 +       get_vx_info(vxi);
17821 +       claim_vx_info(vxi, NULL);
17822 +}
17823 +
17824 +void vx_clear_persistent(struct vx_info *vxi)
17825 +{
17826 +       vxdprintk(VXD_CBIT(xid, 6),
17827 +               "vx_clear_persistent(%p[#%d])", vxi, vxi->vx_id);
17828 +
17829 +       release_vx_info(vxi, NULL);
17830 +       put_vx_info(vxi);
17831 +}
17832 +
17833 +void vx_update_persistent(struct vx_info *vxi)
17834 +{
17835 +       if (vx_info_flags(vxi, VXF_PERSISTENT, 0))
17836 +               vx_set_persistent(vxi);
17837 +       else
17838 +               vx_clear_persistent(vxi);
17839 +}
17840 +
17841 +
17842 +/*     task must be current or locked          */
17843 +
17844 +void   exit_vx_info(struct task_struct *p, int code)
17845 +{
17846 +       struct vx_info *vxi = p->vx_info;
17847 +
17848 +       if (vxi) {
17849 +               atomic_dec(&vxi->cvirt.nr_threads);
17850 +               vx_nproc_dec(p);
17851 +
17852 +               vxi->exit_code = code;
17853 +               release_vx_info(vxi, p);
17854 +       }
17855 +}
17856 +
17857 +void   exit_vx_info_early(struct task_struct *p, int code)
17858 +{
17859 +       struct vx_info *vxi = p->vx_info;
17860 +
17861 +       if (vxi) {
17862 +               if (vxi->vx_initpid == p->tgid)
17863 +                       vx_exit_init(vxi, p, code);
17864 +               if (vxi->vx_reaper == p)
17865 +                       vx_set_reaper(vxi, init_pid_ns.child_reaper);
17866 +       }
17867 +}
17868 +
17869 +
17870 +/* vserver syscall commands below here */
17871 +
17872 +/* taks xid and vx_info functions */
17873 +
17874 +#include <asm/uaccess.h>
17875 +
17876 +
17877 +int vc_task_xid(uint32_t id)
17878 +{
17879 +       xid_t xid;
17880 +
17881 +       if (id) {
17882 +               struct task_struct *tsk;
17883 +
17884 +               read_lock(&tasklist_lock);
17885 +               tsk = find_task_by_real_pid(id);
17886 +               xid = (tsk) ? tsk->xid : -ESRCH;
17887 +               read_unlock(&tasklist_lock);
17888 +       } else
17889 +               xid = vx_current_xid();
17890 +       return xid;
17891 +}
17892 +
17893 +
17894 +int vc_vx_info(struct vx_info *vxi, void __user *data)
17895 +{
17896 +       struct vcmd_vx_info_v0 vc_data;
17897 +
17898 +       vc_data.xid = vxi->vx_id;
17899 +       vc_data.initpid = vxi->vx_initpid;
17900 +
17901 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
17902 +               return -EFAULT;
17903 +       return 0;
17904 +}
17905 +
17906 +
17907 +int vc_ctx_stat(struct vx_info *vxi, void __user *data)
17908 +{
17909 +       struct vcmd_ctx_stat_v0 vc_data;
17910 +
17911 +       vc_data.usecnt = atomic_read(&vxi->vx_usecnt);
17912 +       vc_data.tasks = atomic_read(&vxi->vx_tasks);
17913 +
17914 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
17915 +               return -EFAULT;
17916 +       return 0;
17917 +}
17918 +
17919 +
17920 +/* context functions */
17921 +
17922 +int vc_ctx_create(uint32_t xid, void __user *data)
17923 +{
17924 +       struct vcmd_ctx_create vc_data = { .flagword = VXF_INIT_SET };
17925 +       struct vx_info *new_vxi;
17926 +       int ret;
17927 +
17928 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
17929 +               return -EFAULT;
17930 +
17931 +       if ((xid > MAX_S_CONTEXT) || (xid < 2))
17932 +               return -EINVAL;
17933 +
17934 +       new_vxi = __create_vx_info(xid);
17935 +       if (IS_ERR(new_vxi))
17936 +               return PTR_ERR(new_vxi);
17937 +
17938 +       /* initial flags */
17939 +       new_vxi->vx_flags = vc_data.flagword;
17940 +
17941 +       ret = -ENOEXEC;
17942 +       if (vs_state_change(new_vxi, VSC_STARTUP))
17943 +               goto out;
17944 +
17945 +       ret = vx_migrate_task(current, new_vxi, (!data));
17946 +       if (ret)
17947 +               goto out;
17948 +
17949 +       /* return context id on success */
17950 +       ret = new_vxi->vx_id;
17951 +
17952 +       /* get a reference for persistent contexts */
17953 +       if ((vc_data.flagword & VXF_PERSISTENT))
17954 +               vx_set_persistent(new_vxi);
17955 +out:
17956 +       release_vx_info(new_vxi, NULL);
17957 +       put_vx_info(new_vxi);
17958 +       return ret;
17959 +}
17960 +
17961 +
17962 +int vc_ctx_migrate(struct vx_info *vxi, void __user *data)
17963 +{
17964 +       struct vcmd_ctx_migrate vc_data = { .flagword = 0 };
17965 +       int ret;
17966 +
17967 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
17968 +               return -EFAULT;
17969 +
17970 +       ret = vx_migrate_task(current, vxi, 0);
17971 +       if (ret)
17972 +               return ret;
17973 +       if (vc_data.flagword & VXM_SET_INIT)
17974 +               ret = vx_set_init(vxi, current);
17975 +       if (ret)
17976 +               return ret;
17977 +       if (vc_data.flagword & VXM_SET_REAPER)
17978 +               ret = vx_set_reaper(vxi, current);
17979 +       return ret;
17980 +}
17981 +
17982 +
17983 +int vc_get_cflags(struct vx_info *vxi, void __user *data)
17984 +{
17985 +       struct vcmd_ctx_flags_v0 vc_data;
17986 +
17987 +       vc_data.flagword = vxi->vx_flags;
17988 +
17989 +       /* special STATE flag handling */
17990 +       vc_data.mask = vs_mask_flags(~0ULL, vxi->vx_flags, VXF_ONE_TIME);
17991 +
17992 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
17993 +               return -EFAULT;
17994 +       return 0;
17995 +}
17996 +
17997 +int vc_set_cflags(struct vx_info *vxi, void __user *data)
17998 +{
17999 +       struct vcmd_ctx_flags_v0 vc_data;
18000 +       uint64_t mask, trigger;
18001 +
18002 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18003 +               return -EFAULT;
18004 +
18005 +       /* special STATE flag handling */
18006 +       mask = vs_mask_mask(vc_data.mask, vxi->vx_flags, VXF_ONE_TIME);
18007 +       trigger = (mask & vxi->vx_flags) ^ (mask & vc_data.flagword);
18008 +
18009 +       if (vxi == current->vx_info) {
18010 +               /* if (trigger & VXF_STATE_SETUP)
18011 +                       vx_mask_cap_bset(vxi, current); */
18012 +               if (trigger & VXF_STATE_INIT) {
18013 +                       int ret;
18014 +
18015 +                       ret = vx_set_init(vxi, current);
18016 +                       if (ret)
18017 +                               return ret;
18018 +                       ret = vx_set_reaper(vxi, current);
18019 +                       if (ret)
18020 +                               return ret;
18021 +               }
18022 +       }
18023 +
18024 +       vxi->vx_flags = vs_mask_flags(vxi->vx_flags,
18025 +               vc_data.flagword, mask);
18026 +       if (trigger & VXF_PERSISTENT)
18027 +               vx_update_persistent(vxi);
18028 +
18029 +       return 0;
18030 +}
18031 +
18032 +
18033 +static inline uint64_t caps_from_cap_t(kernel_cap_t c)
18034 +{
18035 +       uint64_t v = c.cap[0] | ((uint64_t)c.cap[1] << 32);
18036 +
18037 +       // printk("caps_from_cap_t(%08x:%08x) = %016llx\n", c.cap[1], c.cap[0], v);
18038 +       return v;
18039 +}
18040 +
18041 +static inline kernel_cap_t cap_t_from_caps(uint64_t v)
18042 +{
18043 +       kernel_cap_t c = __cap_empty_set;
18044 +
18045 +       c.cap[0] = v & 0xFFFFFFFF;
18046 +       c.cap[1] = (v >> 32) & 0xFFFFFFFF;
18047 +
18048 +       // printk("cap_t_from_caps(%016llx) = %08x:%08x\n", v, c.cap[1], c.cap[0]);
18049 +       return c;
18050 +}
18051 +
18052 +
18053 +static int do_get_caps(struct vx_info *vxi, uint64_t *bcaps, uint64_t *ccaps)
18054 +{
18055 +       if (bcaps)
18056 +               *bcaps = caps_from_cap_t(vxi->vx_bcaps);
18057 +       if (ccaps)
18058 +               *ccaps = vxi->vx_ccaps;
18059 +
18060 +       return 0;
18061 +}
18062 +
18063 +int vc_get_ccaps(struct vx_info *vxi, void __user *data)
18064 +{
18065 +       struct vcmd_ctx_caps_v1 vc_data;
18066 +       int ret;
18067 +
18068 +       ret = do_get_caps(vxi, NULL, &vc_data.ccaps);
18069 +       if (ret)
18070 +               return ret;
18071 +       vc_data.cmask = ~0ULL;
18072 +
18073 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
18074 +               return -EFAULT;
18075 +       return 0;
18076 +}
18077 +
18078 +static int do_set_caps(struct vx_info *vxi,
18079 +       uint64_t bcaps, uint64_t bmask, uint64_t ccaps, uint64_t cmask)
18080 +{
18081 +       uint64_t bcold = caps_from_cap_t(vxi->vx_bcaps);
18082 +
18083 +#if 0
18084 +       printk("do_set_caps(%16llx, %16llx, %16llx, %16llx)\n",
18085 +               bcaps, bmask, ccaps, cmask);
18086 +#endif
18087 +       vxi->vx_bcaps = cap_t_from_caps(
18088 +               vs_mask_flags(bcold, bcaps, bmask));
18089 +       vxi->vx_ccaps = vs_mask_flags(vxi->vx_ccaps, ccaps, cmask);
18090 +
18091 +       return 0;
18092 +}
18093 +
18094 +int vc_set_ccaps(struct vx_info *vxi, void __user *data)
18095 +{
18096 +       struct vcmd_ctx_caps_v1 vc_data;
18097 +
18098 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18099 +               return -EFAULT;
18100 +
18101 +       return do_set_caps(vxi, 0, 0, vc_data.ccaps, vc_data.cmask);
18102 +}
18103 +
18104 +int vc_get_bcaps(struct vx_info *vxi, void __user *data)
18105 +{
18106 +       struct vcmd_bcaps vc_data;
18107 +       int ret;
18108 +
18109 +       ret = do_get_caps(vxi, &vc_data.bcaps, NULL);
18110 +       if (ret)
18111 +               return ret;
18112 +       vc_data.bmask = ~0ULL;
18113 +
18114 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
18115 +               return -EFAULT;
18116 +       return 0;
18117 +}
18118 +
18119 +int vc_set_bcaps(struct vx_info *vxi, void __user *data)
18120 +{
18121 +       struct vcmd_bcaps vc_data;
18122 +
18123 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18124 +               return -EFAULT;
18125 +
18126 +       return do_set_caps(vxi, vc_data.bcaps, vc_data.bmask, 0, 0);
18127 +}
18128 +
18129 +
18130 +int vc_get_badness(struct vx_info *vxi, void __user *data)
18131 +{
18132 +       struct vcmd_badness_v0 vc_data;
18133 +
18134 +       vc_data.bias = vxi->vx_badness_bias;
18135 +
18136 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
18137 +               return -EFAULT;
18138 +       return 0;
18139 +}
18140 +
18141 +int vc_set_badness(struct vx_info *vxi, void __user *data)
18142 +{
18143 +       struct vcmd_badness_v0 vc_data;
18144 +
18145 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18146 +               return -EFAULT;
18147 +
18148 +       vxi->vx_badness_bias = vc_data.bias;
18149 +       return 0;
18150 +}
18151 +
18152 +#include <linux/module.h>
18153 +
18154 +EXPORT_SYMBOL_GPL(free_vx_info);
18155 +
18156 diff -NurpP --minimal linux-2.6.29.1/kernel/vserver/cvirt.c linux-2.6.29.1-vs2.3.0.36.9-pre5/kernel/vserver/cvirt.c
18157 --- linux-2.6.29.1/kernel/vserver/cvirt.c       1970-01-01 01:00:00.000000000 +0100
18158 +++ linux-2.6.29.1-vs2.3.0.36.9-pre5/kernel/vserver/cvirt.c     2009-02-22 22:54:26.000000000 +0100
18159 @@ -0,0 +1,300 @@
18160 +/*
18161 + *  linux/kernel/vserver/cvirt.c
18162 + *
18163 + *  Virtual Server: Context Virtualization
18164 + *
18165 + *  Copyright (C) 2004-2007  Herbert Pötzl
18166 + *
18167 + *  V0.01  broken out from limit.c
18168 + *  V0.02  added utsname stuff
18169 + *  V0.03  changed vcmds to vxi arg
18170 + *
18171 + */
18172 +
18173 +#include <linux/types.h>
18174 +#include <linux/utsname.h>
18175 +#include <linux/vs_cvirt.h>
18176 +#include <linux/vserver/switch.h>
18177 +#include <linux/vserver/cvirt_cmd.h>
18178 +
18179 +#include <asm/uaccess.h>
18180 +
18181 +
18182 +void vx_vsi_uptime(struct timespec *uptime, struct timespec *idle)
18183 +{
18184 +       struct vx_info *vxi = current->vx_info;
18185 +
18186 +       set_normalized_timespec(uptime,
18187 +               uptime->tv_sec - vxi->cvirt.bias_uptime.tv_sec,
18188 +               uptime->tv_nsec - vxi->cvirt.bias_uptime.tv_nsec);
18189 +       if (!idle)
18190 +               return;
18191 +       set_normalized_timespec(idle,
18192 +               idle->tv_sec - vxi->cvirt.bias_idle.tv_sec,
18193 +               idle->tv_nsec - vxi->cvirt.bias_idle.tv_nsec);
18194 +       return;
18195 +}
18196 +
18197 +uint64_t vx_idle_jiffies(void)
18198 +{
18199 +       return init_task.utime + init_task.stime;
18200 +}
18201 +
18202 +
18203 +
18204 +static inline uint32_t __update_loadavg(uint32_t load,
18205 +       int wsize, int delta, int n)
18206 +{
18207 +       unsigned long long calc, prev;
18208 +
18209 +       /* just set it to n */
18210 +       if (unlikely(delta >= wsize))
18211 +               return (n << FSHIFT);
18212 +
18213 +       calc = delta * n;
18214 +       calc <<= FSHIFT;
18215 +       prev = (wsize - delta);
18216 +       prev *= load;
18217 +       calc += prev;
18218 +       do_div(calc, wsize);
18219 +       return calc;
18220 +}
18221 +
18222 +
18223 +void vx_update_load(struct vx_info *vxi)
18224 +{
18225 +       uint32_t now, last, delta;
18226 +       unsigned int nr_running, nr_uninterruptible;
18227 +       unsigned int total;
18228 +       unsigned long flags;
18229 +
18230 +       spin_lock_irqsave(&vxi->cvirt.load_lock, flags);
18231 +
18232 +       now = jiffies;
18233 +       last = vxi->cvirt.load_last;
18234 +       delta = now - last;
18235 +
18236 +       if (delta < 5*HZ)
18237 +               goto out;
18238 +
18239 +       nr_running = atomic_read(&vxi->cvirt.nr_running);
18240 +       nr_uninterruptible = atomic_read(&vxi->cvirt.nr_uninterruptible);
18241 +       total = nr_running + nr_uninterruptible;
18242 +
18243 +       vxi->cvirt.load[0] = __update_loadavg(vxi->cvirt.load[0],
18244 +               60*HZ, delta, total);
18245 +       vxi->cvirt.load[1] = __update_loadavg(vxi->cvirt.load[1],
18246 +               5*60*HZ, delta, total);
18247 +       vxi->cvirt.load[2] = __update_loadavg(vxi->cvirt.load[2],
18248 +               15*60*HZ, delta, total);
18249 +
18250 +       vxi->cvirt.load_last = now;
18251 +out:
18252 +       atomic_inc(&vxi->cvirt.load_updates);
18253 +       spin_unlock_irqrestore(&vxi->cvirt.load_lock, flags);
18254 +}
18255 +
18256 +
18257 +/*
18258 + * Commands to do_syslog:
18259 + *
18260 + *      0 -- Close the log.  Currently a NOP.
18261 + *      1 -- Open the log. Currently a NOP.
18262 + *      2 -- Read from the log.
18263 + *      3 -- Read all messages remaining in the ring buffer.
18264 + *      4 -- Read and clear all messages remaining in the ring buffer
18265 + *      5 -- Clear ring buffer.
18266 + *      6 -- Disable printk's to console
18267 + *      7 -- Enable printk's to console
18268 + *      8 -- Set level of messages printed to console
18269 + *      9 -- Return number of unread characters in the log buffer
18270 + *     10 -- Return size of the log buffer
18271 + */
18272 +int vx_do_syslog(int type, char __user *buf, int len)
18273 +{
18274 +       int error = 0;
18275 +       int do_clear = 0;
18276 +       struct vx_info *vxi = current->vx_info;
18277 +       struct _vx_syslog *log;
18278 +
18279 +       if (!vxi)
18280 +               return -EINVAL;
18281 +       log = &vxi->cvirt.syslog;
18282 +
18283 +       switch (type) {
18284 +       case 0:         /* Close log */
18285 +       case 1:         /* Open log */
18286 +               break;
18287 +       case 2:         /* Read from log */
18288 +               error = wait_event_interruptible(log->log_wait,
18289 +                       (log->log_start - log->log_end));
18290 +               if (error)
18291 +                       break;
18292 +               spin_lock_irq(&log->logbuf_lock);
18293 +               spin_unlock_irq(&log->logbuf_lock);
18294 +               break;
18295 +       case 4:         /* Read/clear last kernel messages */
18296 +               do_clear = 1;
18297 +               /* fall through */
18298 +       case 3:         /* Read last kernel messages */
18299 +               return 0;
18300 +
18301 +       case 5:         /* Clear ring buffer */
18302 +               return 0;
18303 +
18304 +       case 6:         /* Disable logging to console */
18305 +       case 7:         /* Enable logging to console */
18306 +       case 8:         /* Set level of messages printed to console */
18307 +               break;
18308 +
18309 +       case 9:         /* Number of chars in the log buffer */
18310 +               return 0;
18311 +       case 10:        /* Size of the log buffer */
18312 +               return 0;
18313 +       default:
18314 +               error = -EINVAL;
18315 +               break;
18316 +       }
18317 +       return error;
18318 +}
18319 +
18320 +
18321 +/* virtual host info names */
18322 +
18323 +static char *vx_vhi_name(struct vx_info *vxi, int id)
18324 +{
18325 +       struct nsproxy *nsproxy;
18326 +       struct uts_namespace *uts;
18327 +
18328 +       if (id == VHIN_CONTEXT)
18329 +               return vxi->vx_name;
18330 +
18331 +       nsproxy = vxi->vx_nsproxy[0];
18332 +       if (!nsproxy)
18333 +               return NULL;
18334 +
18335 +       uts = nsproxy->uts_ns;
18336 +       if (!uts)
18337 +               return NULL;
18338 +
18339 +       switch (id) {
18340 +       case VHIN_SYSNAME:
18341 +               return uts->name.sysname;
18342 +       case VHIN_NODENAME:
18343 +               return uts->name.nodename;
18344 +       case VHIN_RELEASE:
18345 +               return uts->name.release;
18346 +       case VHIN_VERSION:
18347 +               return uts->name.version;
18348 +       case VHIN_MACHINE:
18349 +               return uts->name.machine;
18350 +       case VHIN_DOMAINNAME:
18351 +               return uts->name.domainname;
18352 +       default:
18353 +               return NULL;
18354 +       }
18355 +       return NULL;
18356 +}
18357 +
18358 +int vc_set_vhi_name(struct vx_info *vxi, void __user *data)
18359 +{
18360 +       struct vcmd_vhi_name_v0 vc_data;
18361 +       char *name;
18362 +
18363 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18364 +               return -EFAULT;
18365 +
18366 +       name = vx_vhi_name(vxi, vc_data.field);
18367 +       if (!name)
18368 +               return -EINVAL;
18369 +
18370 +       memcpy(name, vc_data.name, 65);
18371 +       return 0;
18372 +}
18373 +
18374 +int vc_get_vhi_name(struct vx_info *vxi, void __user *data)
18375 +{
18376 +       struct vcmd_vhi_name_v0 vc_data;
18377 +       char *name;
18378 +
18379 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18380 +               return -EFAULT;
18381 +
18382 +       name = vx_vhi_name(vxi, vc_data.field);
18383 +       if (!name)
18384 +               return -EINVAL;
18385 +
18386 +       memcpy(vc_data.name, name, 65);
18387 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
18388 +               return -EFAULT;
18389 +       return 0;
18390 +}
18391 +
18392 +
18393 +int vc_virt_stat(struct vx_info *vxi, void __user *data)
18394 +{
18395 +       struct vcmd_virt_stat_v0 vc_data;
18396 +       struct _vx_cvirt *cvirt = &vxi->cvirt;
18397 +       struct timespec uptime;
18398 +
18399 +       do_posix_clock_monotonic_gettime(&uptime);
18400 +       set_normalized_timespec(&uptime,
18401 +               uptime.tv_sec - cvirt->bias_uptime.tv_sec,
18402 +               uptime.tv_nsec - cvirt->bias_uptime.tv_nsec);
18403 +
18404 +       vc_data.offset = timeval_to_ns(&cvirt->bias_tv);
18405 +       vc_data.uptime = timespec_to_ns(&uptime);
18406 +       vc_data.nr_threads = atomic_read(&cvirt->nr_threads);
18407 +       vc_data.nr_running = atomic_read(&cvirt->nr_running);
18408 +       vc_data.nr_uninterruptible = atomic_read(&cvirt->nr_uninterruptible);
18409 +       vc_data.nr_onhold = atomic_read(&cvirt->nr_onhold);
18410 +       vc_data.nr_forks = atomic_read(&cvirt->total_forks);
18411 +       vc_data.load[0] = cvirt->load[0];
18412 +       vc_data.load[1] = cvirt->load[1];
18413 +       vc_data.load[2] = cvirt->load[2];
18414 +
18415 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
18416 +               return -EFAULT;
18417 +       return 0;
18418 +}
18419 +
18420 +
18421 +#ifdef CONFIG_VSERVER_VTIME
18422 +
18423 +/* virtualized time base */
18424 +
18425 +void vx_gettimeofday(struct timeval *tv)
18426 +{
18427 +       do_gettimeofday(tv);
18428 +       if (!vx_flags(VXF_VIRT_TIME, 0))
18429 +               return;
18430 +
18431 +       tv->tv_sec += current->vx_info->cvirt.bias_tv.tv_sec;
18432 +       tv->tv_usec += current->vx_info->cvirt.bias_tv.tv_usec;
18433 +
18434 +       if (tv->tv_usec >= USEC_PER_SEC) {
18435 +               tv->tv_sec++;
18436 +               tv->tv_usec -= USEC_PER_SEC;
18437 +       } else if (tv->tv_usec < 0) {
18438 +               tv->tv_sec--;
18439 +               tv->tv_usec += USEC_PER_SEC;
18440 +       }
18441 +}
18442 +
18443 +int vx_settimeofday(struct timespec *ts)
18444 +{
18445 +       struct timeval tv;
18446 +
18447 +       if (!vx_flags(VXF_VIRT_TIME, 0))
18448 +               return do_settimeofday(ts);
18449 +
18450 +       do_gettimeofday(&tv);
18451 +       current->vx_info->cvirt.bias_tv.tv_sec =
18452 +               ts->tv_sec - tv.tv_sec;
18453 +       current->vx_info->cvirt.bias_tv.tv_usec =
18454 +               (ts->tv_nsec/NSEC_PER_USEC) - tv.tv_usec;
18455 +       return 0;
18456 +}
18457 +
18458 +#endif
18459 +
18460 diff -NurpP --minimal linux-2.6.29.1/kernel/vserver/cvirt_init.h linux-2.6.29.1-vs2.3.0.36.9-pre5/kernel/vserver/cvirt_init.h
18461 --- linux-2.6.29.1/kernel/vserver/cvirt_init.h  1970-01-01 01:00:00.000000000 +0100
18462 +++ linux-2.6.29.1-vs2.3.0.36.9-pre5/kernel/vserver/cvirt_init.h        2009-02-22 22:54:26.000000000 +0100
18463 @@ -0,0 +1,69 @@
18464 +
18465 +
18466 +extern uint64_t vx_idle_jiffies(void);
18467 +
18468 +static inline void vx_info_init_cvirt(struct _vx_cvirt *cvirt)
18469 +{
18470 +       uint64_t idle_jiffies = vx_idle_jiffies();
18471 +       uint64_t nsuptime;
18472 +
18473 +       do_posix_clock_monotonic_gettime(&cvirt->bias_uptime);
18474 +       nsuptime = (unsigned long long)cvirt->bias_uptime.tv_sec
18475 +               * NSEC_PER_SEC + cvirt->bias_uptime.tv_nsec;
18476 +       cvirt->bias_clock = nsec_to_clock_t(nsuptime);
18477 +       cvirt->bias_tv.tv_sec = 0;
18478 +       cvirt->bias_tv.tv_usec = 0;
18479 +
18480 +       jiffies_to_timespec(idle_jiffies, &cvirt->bias_idle);
18481 +       atomic_set(&cvirt->nr_threads, 0);
18482 +       atomic_set(&cvirt->nr_running, 0);
18483 +       atomic_set(&cvirt->nr_uninterruptible, 0);
18484 +       atomic_set(&cvirt->nr_onhold, 0);
18485 +
18486 +       spin_lock_init(&cvirt->load_lock);
18487 +       cvirt->load_last = jiffies;
18488 +       atomic_set(&cvirt->load_updates, 0);
18489 +       cvirt->load[0] = 0;
18490 +       cvirt->load[1] = 0;
18491 +       cvirt->load[2] = 0;
18492 +       atomic_set(&cvirt->total_forks, 0);
18493 +
18494 +       spin_lock_init(&cvirt->syslog.logbuf_lock);
18495 +       init_waitqueue_head(&cvirt->syslog.log_wait);
18496 +       cvirt->syslog.log_start = 0;
18497 +       cvirt->syslog.log_end = 0;
18498 +       cvirt->syslog.con_start = 0;
18499 +       cvirt->syslog.logged_chars = 0;
18500 +}
18501 +
18502 +static inline
18503 +void vx_info_init_cvirt_pc(struct _vx_cvirt_pc *cvirt_pc, int cpu)
18504 +{
18505 +       // cvirt_pc->cpustat = { 0 };
18506 +}
18507 +
18508 +static inline void vx_info_exit_cvirt(struct _vx_cvirt *cvirt)
18509 +{
18510 +       int value;
18511 +
18512 +       vxwprintk_xid((value = atomic_read(&cvirt->nr_threads)),
18513 +               "!!! cvirt: %p[nr_threads] = %d on exit.",
18514 +               cvirt, value);
18515 +       vxwprintk_xid((value = atomic_read(&cvirt->nr_running)),
18516 +               "!!! cvirt: %p[nr_running] = %d on exit.",
18517 +               cvirt, value);
18518 +       vxwprintk_xid((value = atomic_read(&cvirt->nr_uninterruptible)),
18519 +               "!!! cvirt: %p[nr_uninterruptible] = %d on exit.",
18520 +               cvirt, value);
18521 +       vxwprintk_xid((value = atomic_read(&cvirt->nr_onhold)),
18522 +               "!!! cvirt: %p[nr_onhold] = %d on exit.",
18523 +               cvirt, value);
18524 +       return;
18525 +}
18526 +
18527 +static inline
18528 +void vx_info_exit_cvirt_pc(struct _vx_cvirt_pc *cvirt_pc, int cpu)
18529 +{
18530 +       return;
18531 +}
18532 +
18533 diff -NurpP --minimal linux-2.6.29.1/kernel/vserver/cvirt_proc.h linux-2.6.29.1-vs2.3.0.36.9-pre5/kernel/vserver/cvirt_proc.h
18534 --- linux-2.6.29.1/kernel/vserver/cvirt_proc.h  1970-01-01 01:00:00.000000000 +0100
18535 +++ linux-2.6.29.1-vs2.3.0.36.9-pre5/kernel/vserver/cvirt_proc.h        2009-02-22 22:54:26.000000000 +0100
18536 @@ -0,0 +1,135 @@
18537 +#ifndef _VX_CVIRT_PROC_H
18538 +#define _VX_CVIRT_PROC_H
18539 +
18540 +#include <linux/nsproxy.h>
18541 +#include <linux/mnt_namespace.h>
18542 +#include <linux/ipc_namespace.h>
18543 +#include <linux/utsname.h>
18544 +#include <linux/ipc.h>
18545 +
18546 +
18547 +static inline
18548 +int vx_info_proc_nsproxy(struct nsproxy *nsproxy, char *buffer)
18549 +{
18550 +       struct mnt_namespace *ns;
18551 +       struct uts_namespace *uts;
18552 +       struct ipc_namespace *ipc;
18553 +       struct path path;
18554 +       char *pstr, *root;
18555 +       int length = 0;
18556 +
18557 +       if (!nsproxy)
18558 +               goto out;
18559 +
18560 +       length += sprintf(buffer + length,
18561 +               "NSProxy:\t%p [%p,%p,%p]\n",
18562 +               nsproxy, nsproxy->mnt_ns,
18563 +               nsproxy->uts_ns, nsproxy->ipc_ns);
18564 +
18565 +       ns = nsproxy->mnt_ns;
18566 +       if (!ns)
18567 +               goto skip_ns;
18568 +
18569 +       pstr = kmalloc(PATH_MAX, GFP_KERNEL);
18570 +       if (!pstr)
18571 +               goto skip_ns;
18572 +
18573 +       path.mnt = ns->root;
18574 +       path.dentry = ns->root->mnt_root;
18575 +       root = d_path(&path, pstr, PATH_MAX - 2);
18576 +       length += sprintf(buffer + length,
18577 +               "Namespace:\t%p [#%u]\n"
18578 +               "RootPath:\t%s\n",
18579 +               ns, atomic_read(&ns->count),
18580 +               root);
18581 +       kfree(pstr);
18582 +skip_ns:
18583 +
18584 +       uts = nsproxy->uts_ns;
18585 +       if (!uts)
18586 +               goto skip_uts;
18587 +
18588 +       length += sprintf(buffer + length,
18589 +               "SysName:\t%.*s\n"
18590 +               "NodeName:\t%.*s\n"
18591 +               "Release:\t%.*s\n"
18592 +               "Version:\t%.*s\n"
18593 +               "Machine:\t%.*s\n"
18594 +               "DomainName:\t%.*s\n",
18595 +               __NEW_UTS_LEN, uts->name.sysname,
18596 +               __NEW_UTS_LEN, uts->name.nodename,
18597 +               __NEW_UTS_LEN, uts->name.release,
18598 +               __NEW_UTS_LEN, uts->name.version,
18599 +               __NEW_UTS_LEN, uts->name.machine,
18600 +               __NEW_UTS_LEN, uts->name.domainname);
18601 +skip_uts:
18602 +
18603 +       ipc = nsproxy->ipc_ns;
18604 +       if (!ipc)
18605 +               goto skip_ipc;
18606 +
18607 +       length += sprintf(buffer + length,
18608 +               "SEMS:\t\t%d %d %d %d  %d\n"
18609 +               "MSG:\t\t%d %d %d\n"
18610 +               "SHM:\t\t%lu %lu  %d %d\n",
18611 +               ipc->sem_ctls[0], ipc->sem_ctls[1],
18612 +               ipc->sem_ctls[2], ipc->sem_ctls[3],
18613 +               ipc->used_sems,
18614 +               ipc->msg_ctlmax, ipc->msg_ctlmnb, ipc->msg_ctlmni,
18615 +               (unsigned long)ipc->shm_ctlmax,
18616 +               (unsigned long)ipc->shm_ctlall,
18617 +               ipc->shm_ctlmni, ipc->shm_tot);
18618 +skip_ipc:
18619 +out:
18620 +       return length;
18621 +}
18622 +
18623 +
18624 +#include <linux/sched.h>
18625 +
18626 +#define LOAD_INT(x) ((x) >> FSHIFT)
18627 +#define LOAD_FRAC(x) LOAD_INT(((x) & (FIXED_1 - 1)) * 100)
18628 +
18629 +static inline
18630 +int vx_info_proc_cvirt(struct _vx_cvirt *cvirt, char *buffer)
18631 +{
18632 +       int length = 0;
18633 +       int a, b, c;
18634 +
18635 +       length += sprintf(buffer + length,
18636 +               "BiasUptime:\t%lu.%02lu\n",
18637 +               (unsigned long)cvirt->bias_uptime.tv_sec,
18638 +               (cvirt->bias_uptime.tv_nsec / (NSEC_PER_SEC / 100)));
18639 +
18640 +       a = cvirt->load[0] + (FIXED_1 / 200);
18641 +       b = cvirt->load[1] + (FIXED_1 / 200);
18642 +       c = cvirt->load[2] + (FIXED_1 / 200);
18643 +       length += sprintf(buffer + length,
18644 +               "nr_threads:\t%d\n"
18645 +               "nr_running:\t%d\n"
18646 +               "nr_unintr:\t%d\n"
18647 +               "nr_onhold:\t%d\n"
18648 +               "load_updates:\t%d\n"
18649 +               "loadavg:\t%d.%02d %d.%02d %d.%02d\n"
18650 +               "total_forks:\t%d\n",
18651 +               atomic_read(&cvirt->nr_threads),
18652 +               atomic_read(&cvirt->nr_running),
18653 +               atomic_read(&cvirt->nr_uninterruptible),
18654 +               atomic_read(&cvirt->nr_onhold),
18655 +               atomic_read(&cvirt->load_updates),
18656 +               LOAD_INT(a), LOAD_FRAC(a),
18657 +               LOAD_INT(b), LOAD_FRAC(b),
18658 +               LOAD_INT(c), LOAD_FRAC(c),
18659 +               atomic_read(&cvirt->total_forks));
18660 +       return length;
18661 +}
18662 +
18663 +static inline
18664 +int vx_info_proc_cvirt_pc(struct _vx_cvirt_pc *cvirt_pc,
18665 +       char *buffer, int cpu)
18666 +{
18667 +       int length = 0;
18668 +       return length;
18669 +}
18670 +
18671 +#endif /* _VX_CVIRT_PROC_H */
18672 diff -NurpP --minimal linux-2.6.29.1/kernel/vserver/debug.c linux-2.6.29.1-vs2.3.0.36.9-pre5/kernel/vserver/debug.c
18673 --- linux-2.6.29.1/kernel/vserver/debug.c       1970-01-01 01:00:00.000000000 +0100
18674 +++ linux-2.6.29.1-vs2.3.0.36.9-pre5/kernel/vserver/debug.c     2009-02-22 22:54:26.000000000 +0100
18675 @@ -0,0 +1,32 @@
18676 +/*
18677 + *  kernel/vserver/debug.c
18678 + *
18679 + *  Copyright (C) 2005-2007 Herbert Pötzl
18680 + *
18681 + *  V0.01  vx_info dump support
18682 + *
18683 + */
18684 +
18685 +#include <linux/module.h>
18686 +
18687 +#include <linux/vserver/context.h>
18688 +
18689 +
18690 +void   dump_vx_info(struct vx_info *vxi, int level)
18691 +{
18692 +       printk("vx_info %p[#%d, %d.%d, %4x]\n", vxi, vxi->vx_id,
18693 +               atomic_read(&vxi->vx_usecnt),
18694 +               atomic_read(&vxi->vx_tasks),
18695 +               vxi->vx_state);
18696 +       if (level > 0) {
18697 +               __dump_vx_limit(&vxi->limit);
18698 +               __dump_vx_sched(&vxi->sched);
18699 +               __dump_vx_cvirt(&vxi->cvirt);
18700 +               __dump_vx_cacct(&vxi->cacct);
18701 +       }
18702 +       printk("---\n");
18703 +}
18704 +
18705 +
18706 +EXPORT_SYMBOL_GPL(dump_vx_info);
18707 +
18708 diff -NurpP --minimal linux-2.6.29.1/kernel/vserver/device.c linux-2.6.29.1-vs2.3.0.36.9-pre5/kernel/vserver/device.c
18709 --- linux-2.6.29.1/kernel/vserver/device.c      1970-01-01 01:00:00.000000000 +0100
18710 +++ linux-2.6.29.1-vs2.3.0.36.9-pre5/kernel/vserver/device.c    2009-02-22 22:54:26.000000000 +0100
18711 @@ -0,0 +1,443 @@
18712 +/*
18713 + *  linux/kernel/vserver/device.c
18714 + *
18715 + *  Linux-VServer: Device Support
18716 + *
18717 + *  Copyright (C) 2006  Herbert Pötzl
18718 + *  Copyright (C) 2007  Daniel Hokka Zakrisson
18719 + *
18720 + *  V0.01  device mapping basics
18721 + *  V0.02  added defaults
18722 + *
18723 + */
18724 +
18725 +#include <linux/slab.h>
18726 +#include <linux/rcupdate.h>
18727 +#include <linux/fs.h>
18728 +#include <linux/namei.h>
18729 +#include <linux/hash.h>
18730 +
18731 +#include <asm/errno.h>
18732 +#include <asm/uaccess.h>
18733 +#include <linux/vserver/base.h>
18734 +#include <linux/vserver/debug.h>
18735 +#include <linux/vserver/context.h>
18736 +#include <linux/vserver/device.h>
18737 +#include <linux/vserver/device_cmd.h>
18738 +
18739 +
18740 +#define DMAP_HASH_BITS 4
18741 +
18742 +
18743 +struct vs_mapping {
18744 +       union {
18745 +               struct hlist_node hlist;
18746 +               struct list_head list;
18747 +       } u;
18748 +#define dm_hlist       u.hlist
18749 +#define dm_list                u.list
18750 +       xid_t xid;
18751 +       dev_t device;
18752 +       struct vx_dmap_target target;
18753 +};
18754 +
18755 +
18756 +static struct hlist_head dmap_main_hash[1 << DMAP_HASH_BITS];
18757 +
18758 +static spinlock_t dmap_main_hash_lock = SPIN_LOCK_UNLOCKED;
18759 +
18760 +static struct vx_dmap_target dmap_defaults[2] = {
18761 +       { .flags = DATTR_OPEN },
18762 +       { .flags = DATTR_OPEN },
18763 +};
18764 +
18765 +
18766 +struct kmem_cache *dmap_cachep __read_mostly;
18767 +
18768 +int __init dmap_cache_init(void)
18769 +{
18770 +       dmap_cachep = kmem_cache_create("dmap_cache",
18771 +               sizeof(struct vs_mapping), 0,
18772 +               SLAB_HWCACHE_ALIGN|SLAB_PANIC, NULL);
18773 +       return 0;
18774 +}
18775 +
18776 +__initcall(dmap_cache_init);
18777 +
18778 +
18779 +static inline unsigned int __hashval(dev_t dev, int bits)
18780 +{
18781 +       return hash_long((unsigned long)dev, bits);
18782 +}
18783 +
18784 +
18785 +/*     __hash_mapping()
18786 + *     add the mapping to the hash table
18787 + */
18788 +static inline void __hash_mapping(struct vx_info *vxi, struct vs_mapping *vdm)
18789 +{
18790 +       spinlock_t *hash_lock = &dmap_main_hash_lock;
18791 +       struct hlist_head *head, *hash = dmap_main_hash;
18792 +       int device = vdm->device;
18793 +
18794 +       spin_lock(hash_lock);
18795 +       vxdprintk(VXD_CBIT(misc, 8), "__hash_mapping: %p[#%d] %08x:%08x",
18796 +               vxi, vxi ? vxi->vx_id : 0, device, vdm->target.target);
18797 +
18798 +       head = &hash[__hashval(device, DMAP_HASH_BITS)];
18799 +       hlist_add_head(&vdm->dm_hlist, head);
18800 +       spin_unlock(hash_lock);
18801 +}
18802 +
18803 +
18804 +static inline int __mode_to_default(umode_t mode)
18805 +{
18806 +       switch (mode) {
18807 +       case S_IFBLK:
18808 +               return 0;
18809 +       case S_IFCHR:
18810 +               return 1;
18811 +       default:
18812 +               BUG();
18813 +       }
18814 +}
18815 +
18816 +
18817 +/*     __set_default()
18818 + *     set a default
18819 + */
18820 +static inline void __set_default(struct vx_info *vxi, umode_t mode,
18821 +       struct vx_dmap_target *vdmt)
18822 +{
18823 +       spinlock_t *hash_lock = &dmap_main_hash_lock;
18824 +       spin_lock(hash_lock);
18825 +
18826 +       if (vxi)
18827 +               vxi->dmap.targets[__mode_to_default(mode)] = *vdmt;
18828 +       else
18829 +               dmap_defaults[__mode_to_default(mode)] = *vdmt;
18830 +
18831 +
18832 +       spin_unlock(hash_lock);
18833 +
18834 +       vxdprintk(VXD_CBIT(misc, 8), "__set_default: %p[#%u] %08x %04x",
18835 +                 vxi, vxi ? vxi->vx_id : 0, vdmt->target, vdmt->flags);
18836 +}
18837 +
18838 +
18839 +/*     __remove_default()
18840 + *     remove a default
18841 + */
18842 +static inline int __remove_default(struct vx_info *vxi, umode_t mode)
18843 +{
18844 +       spinlock_t *hash_lock = &dmap_main_hash_lock;
18845 +       spin_lock(hash_lock);
18846 +
18847 +       if (vxi)
18848 +               vxi->dmap.targets[__mode_to_default(mode)].flags = 0;
18849 +       else    /* remove == reset */
18850 +               dmap_defaults[__mode_to_default(mode)].flags = DATTR_OPEN | mode;
18851 +
18852 +       spin_unlock(hash_lock);
18853 +       return 0;
18854 +}
18855 +
18856 +
18857 +/*     __find_mapping()
18858 + *     find a mapping in the hash table
18859 + *
18860 + *     caller must hold hash_lock
18861 + */
18862 +static inline int __find_mapping(xid_t xid, dev_t device, umode_t mode,
18863 +       struct vs_mapping **local, struct vs_mapping **global)
18864 +{
18865 +       struct hlist_head *hash = dmap_main_hash;
18866 +       struct hlist_head *head = &hash[__hashval(device, DMAP_HASH_BITS)];
18867 +       struct hlist_node *pos;
18868 +       struct vs_mapping *vdm;
18869 +
18870 +       *local = NULL;
18871 +       if (global)
18872 +               *global = NULL;
18873 +
18874 +       hlist_for_each(pos, head) {
18875 +               vdm = hlist_entry(pos, struct vs_mapping, dm_hlist);
18876 +
18877 +               if ((vdm->device == device) &&
18878 +                       !((vdm->target.flags ^ mode) & S_IFMT)) {
18879 +                       if (vdm->xid == xid) {
18880 +                               *local = vdm;
18881 +                               return 1;
18882 +                       } else if (global && vdm->xid == 0)
18883 +                               *global = vdm;
18884 +               }
18885 +       }
18886 +
18887 +       if (global && *global)
18888 +               return 0;
18889 +       else
18890 +               return -ENOENT;
18891 +}
18892 +
18893 +
18894 +/*     __lookup_mapping()
18895 + *     find a mapping and store the result in target and flags
18896 + */
18897 +static inline int __lookup_mapping(struct vx_info *vxi,
18898 +       dev_t device, dev_t *target, int *flags, umode_t mode)
18899 +{
18900 +       spinlock_t *hash_lock = &dmap_main_hash_lock;
18901 +       struct vs_mapping *vdm, *global;
18902 +       struct vx_dmap_target *vdmt;
18903 +       int ret = 0;
18904 +       xid_t xid = vxi->vx_id;
18905 +       int index;
18906 +
18907 +       spin_lock(hash_lock);
18908 +       if (__find_mapping(xid, device, mode, &vdm, &global) > 0) {
18909 +               ret = 1;
18910 +               vdmt = &vdm->target;
18911 +               goto found;
18912 +       }
18913 +
18914 +       index = __mode_to_default(mode);
18915 +       if (vxi && vxi->dmap.targets[index].flags) {
18916 +               ret = 2;
18917 +               vdmt = &vxi->dmap.targets[index];
18918 +       } else if (global) {
18919 +               ret = 3;
18920 +               vdmt = &global->target;
18921 +               goto found;
18922 +       } else {
18923 +               ret = 4;
18924 +               vdmt = &dmap_defaults[index];
18925 +       }
18926 +
18927 +found:
18928 +       if (target && (vdmt->flags & DATTR_REMAP))
18929 +               *target = vdmt->target;
18930 +       else if (target)
18931 +               *target = device;
18932 +       if (flags)
18933 +               *flags = vdmt->flags;
18934 +
18935 +       spin_unlock(hash_lock);
18936 +
18937 +       return ret;
18938 +}
18939 +
18940 +
18941 +/*     __remove_mapping()
18942 + *     remove a mapping from the hash table
18943 + */
18944 +static inline int __remove_mapping(struct vx_info *vxi, dev_t device,
18945 +       umode_t mode)
18946 +{
18947 +       spinlock_t *hash_lock = &dmap_main_hash_lock;
18948 +       struct vs_mapping *vdm = NULL;
18949 +       int ret = 0;
18950 +
18951 +       spin_lock(hash_lock);
18952 +
18953 +       ret = __find_mapping((vxi ? vxi->vx_id : 0), device, mode, &vdm,
18954 +               NULL);
18955 +       vxdprintk(VXD_CBIT(misc, 8), "__remove_mapping: %p[#%d] %08x %04x",
18956 +               vxi, vxi ? vxi->vx_id : 0, device, mode);
18957 +       if (ret < 0)
18958 +               goto out;
18959 +       hlist_del(&vdm->dm_hlist);
18960 +
18961 +out:
18962 +       spin_unlock(hash_lock);
18963 +       if (vdm)
18964 +               kmem_cache_free(dmap_cachep, vdm);
18965 +       return ret;
18966 +}
18967 +
18968 +
18969 +
18970 +int vs_map_device(struct vx_info *vxi,
18971 +       dev_t device, dev_t *target, umode_t mode)
18972 +{
18973 +       int ret, flags = DATTR_MASK;
18974 +
18975 +       if (!vxi) {
18976 +               if (target)
18977 +                       *target = device;
18978 +               goto out;
18979 +       }
18980 +       ret = __lookup_mapping(vxi, device, target, &flags, mode);
18981 +       vxdprintk(VXD_CBIT(misc, 8), "vs_map_device: %08x target: %08x flags: %04x mode: %04x mapped=%d",
18982 +               device, target ? *target : 0, flags, mode, ret);
18983 +out:
18984 +       return (flags & DATTR_MASK);
18985 +}
18986 +
18987 +
18988 +
18989 +static int do_set_mapping(struct vx_info *vxi,
18990 +       dev_t device, dev_t target, int flags, umode_t mode)
18991 +{
18992 +       if (device) {
18993 +               struct vs_mapping *new;
18994 +
18995 +               new = kmem_cache_alloc(dmap_cachep, GFP_KERNEL);
18996 +               if (!new)
18997 +                       return -ENOMEM;
18998 +
18999 +               INIT_HLIST_NODE(&new->dm_hlist);
19000 +               new->device = device;
19001 +               new->target.target = target;
19002 +               new->target.flags = flags | mode;
19003 +               new->xid = (vxi ? vxi->vx_id : 0);
19004 +
19005 +               vxdprintk(VXD_CBIT(misc, 8), "do_set_mapping: %08x target: %08x flags: %04x", device, target, flags);
19006 +               __hash_mapping(vxi, new);
19007 +       } else {
19008 +               struct vx_dmap_target new = {
19009 +                       .target = target,
19010 +                       .flags = flags | mode,
19011 +               };
19012 +               __set_default(vxi, mode, &new);
19013 +       }
19014 +       return 0;
19015 +}
19016 +
19017 +
19018 +static int do_unset_mapping(struct vx_info *vxi,
19019 +       dev_t device, dev_t target, int flags, umode_t mode)
19020 +{
19021 +       int ret = -EINVAL;
19022 +
19023 +       if (device) {
19024 +               ret = __remove_mapping(vxi, device, mode);
19025 +               if (ret < 0)
19026 +                       goto out;
19027 +       } else {
19028 +               ret = __remove_default(vxi, mode);
19029 +               if (ret < 0)
19030 +                       goto out;
19031 +       }
19032 +
19033 +out:
19034 +       return ret;
19035 +}
19036 +
19037 +
19038 +static inline int __user_device(const char __user *name, dev_t *dev,
19039 +       umode_t *mode)
19040 +{
19041 +       struct nameidata nd;
19042 +       int ret;
19043 +
19044 +       if (!name) {
19045 +               *dev = 0;
19046 +               return 0;
19047 +       }
19048 +       ret = user_lpath(name, &nd.path);
19049 +       if (ret)
19050 +               return ret;
19051 +       if (nd.path.dentry->d_inode) {
19052 +               *dev = nd.path.dentry->d_inode->i_rdev;
19053 +               *mode = nd.path.dentry->d_inode->i_mode;
19054 +       }
19055 +       path_put(&nd.path);
19056 +       return 0;
19057 +}
19058 +
19059 +static inline int __mapping_mode(dev_t device, dev_t target,
19060 +       umode_t device_mode, umode_t target_mode, umode_t *mode)
19061 +{
19062 +       if (device)
19063 +               *mode = device_mode & S_IFMT;
19064 +       else if (target)
19065 +               *mode = target_mode & S_IFMT;
19066 +       else
19067 +               return -EINVAL;
19068 +
19069 +       /* if both given, device and target mode have to match */
19070 +       if (device && target &&
19071 +               ((device_mode ^ target_mode) & S_IFMT))
19072 +               return -EINVAL;
19073 +       return 0;
19074 +}
19075 +
19076 +
19077 +static inline int do_mapping(struct vx_info *vxi, const char __user *device_path,
19078 +       const char __user *target_path, int flags, int set)
19079 +{
19080 +       dev_t device = ~0, target = ~0;
19081 +       umode_t device_mode = 0, target_mode = 0, mode;
19082 +       int ret;
19083 +
19084 +       ret = __user_device(device_path, &device, &device_mode);
19085 +       if (ret)
19086 +               return ret;
19087 +       ret = __user_device(target_path, &target, &target_mode);
19088 +       if (ret)
19089 +               return ret;
19090 +
19091 +       ret = __mapping_mode(device, target,
19092 +               device_mode, target_mode, &mode);
19093 +       if (ret)
19094 +               return ret;
19095 +
19096 +       if (set)
19097 +               return do_set_mapping(vxi, device, target,
19098 +                       flags, mode);
19099 +       else
19100 +               return do_unset_mapping(vxi, device, target,
19101 +                       flags, mode);
19102 +}
19103 +
19104 +
19105 +int vc_set_mapping(struct vx_info *vxi, void __user *data)
19106 +{
19107 +       struct vcmd_set_mapping_v0 vc_data;
19108 +
19109 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19110 +               return -EFAULT;
19111 +
19112 +       return do_mapping(vxi, vc_data.device, vc_data.target,
19113 +               vc_data.flags, 1);
19114 +}
19115 +
19116 +int vc_unset_mapping(struct vx_info *vxi, void __user *data)
19117 +{
19118 +       struct vcmd_set_mapping_v0 vc_data;
19119 +
19120 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19121 +               return -EFAULT;
19122 +
19123 +       return do_mapping(vxi, vc_data.device, vc_data.target,
19124 +               vc_data.flags, 0);
19125 +}
19126 +
19127 +
19128 +#ifdef CONFIG_COMPAT
19129 +
19130 +int vc_set_mapping_x32(struct vx_info *vxi, void __user *data)
19131 +{
19132 +       struct vcmd_set_mapping_v0_x32 vc_data;
19133 +
19134 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19135 +               return -EFAULT;
19136 +
19137 +       return do_mapping(vxi, compat_ptr(vc_data.device_ptr),
19138 +               compat_ptr(vc_data.target_ptr), vc_data.flags, 1);
19139 +}
19140 +
19141 +int vc_unset_mapping_x32(struct vx_info *vxi, void __user *data)
19142 +{
19143 +       struct vcmd_set_mapping_v0_x32 vc_data;
19144 +
19145 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19146 +               return -EFAULT;
19147 +
19148 +       return do_mapping(vxi, compat_ptr(vc_data.device_ptr),
19149 +               compat_ptr(vc_data.target_ptr), vc_data.flags, 0);
19150 +}
19151 +
19152 +#endif /* CONFIG_COMPAT */
19153 +
19154 +
19155 diff -NurpP --minimal linux-2.6.29.1/kernel/vserver/dlimit.c linux-2.6.29.1-vs2.3.0.36.9-pre5/kernel/vserver/dlimit.c
19156 --- linux-2.6.29.1/kernel/vserver/dlimit.c      1970-01-01 01:00:00.000000000 +0100
19157 +++ linux-2.6.29.1-vs2.3.0.36.9-pre5/kernel/vserver/dlimit.c    2009-02-22 22:54:26.000000000 +0100
19158 @@ -0,0 +1,522 @@
19159 +/*
19160 + *  linux/kernel/vserver/dlimit.c
19161 + *
19162 + *  Virtual Server: Context Disk Limits
19163 + *
19164 + *  Copyright (C) 2004-2007  Herbert Pötzl
19165 + *
19166 + *  V0.01  initial version
19167 + *  V0.02  compat32 splitup
19168 + *
19169 + */
19170 +
19171 +#include <linux/statfs.h>
19172 +#include <linux/sched.h>
19173 +#include <linux/namei.h>
19174 +#include <linux/vs_tag.h>
19175 +#include <linux/vs_dlimit.h>
19176 +#include <linux/vserver/dlimit_cmd.h>
19177 +
19178 +#include <asm/uaccess.h>
19179 +
19180 +/*     __alloc_dl_info()
19181 +
19182 +       * allocate an initialized dl_info struct
19183 +       * doesn't make it visible (hash)                        */
19184 +
19185 +static struct dl_info *__alloc_dl_info(struct super_block *sb, tag_t tag)
19186 +{
19187 +       struct dl_info *new = NULL;
19188 +
19189 +       vxdprintk(VXD_CBIT(dlim, 5),
19190 +               "alloc_dl_info(%p,%d)*", sb, tag);
19191 +
19192 +       /* would this benefit from a slab cache? */
19193 +       new = kmalloc(sizeof(struct dl_info), GFP_KERNEL);
19194 +       if (!new)
19195 +               return 0;
19196 +
19197 +       memset(new, 0, sizeof(struct dl_info));
19198 +       new->dl_tag = tag;
19199 +       new->dl_sb = sb;
19200 +       INIT_RCU_HEAD(&new->dl_rcu);
19201 +       INIT_HLIST_NODE(&new->dl_hlist);
19202 +       spin_lock_init(&new->dl_lock);
19203 +       atomic_set(&new->dl_refcnt, 0);
19204 +       atomic_set(&new->dl_usecnt, 0);
19205 +
19206 +       /* rest of init goes here */
19207 +
19208 +       vxdprintk(VXD_CBIT(dlim, 4),
19209 +               "alloc_dl_info(%p,%d) = %p", sb, tag, new);
19210 +       return new;
19211 +}
19212 +
19213 +/*     __dealloc_dl_info()
19214 +
19215 +       * final disposal of dl_info                             */
19216 +
19217 +static void __dealloc_dl_info(struct dl_info *dli)
19218 +{
19219 +       vxdprintk(VXD_CBIT(dlim, 4),
19220 +               "dealloc_dl_info(%p)", dli);
19221 +
19222 +       dli->dl_hlist.next = LIST_POISON1;
19223 +       dli->dl_tag = -1;
19224 +       dli->dl_sb = 0;
19225 +
19226 +       BUG_ON(atomic_read(&dli->dl_usecnt));
19227 +       BUG_ON(atomic_read(&dli->dl_refcnt));
19228 +
19229 +       kfree(dli);
19230 +}
19231 +
19232 +
19233 +/*     hash table for dl_info hash */
19234 +
19235 +#define DL_HASH_SIZE   13
19236 +
19237 +struct hlist_head dl_info_hash[DL_HASH_SIZE];
19238 +
19239 +static spinlock_t dl_info_hash_lock = SPIN_LOCK_UNLOCKED;
19240 +
19241 +
19242 +static inline unsigned int __hashval(struct super_block *sb, tag_t tag)
19243 +{
19244 +       return ((tag ^ (unsigned long)sb) % DL_HASH_SIZE);
19245 +}
19246 +
19247 +
19248 +
19249 +/*     __hash_dl_info()
19250 +
19251 +       * add the dli to the global hash table
19252 +       * requires the hash_lock to be held                     */
19253 +
19254 +static inline void __hash_dl_info(struct dl_info *dli)
19255 +{
19256 +       struct hlist_head *head;
19257 +
19258 +       vxdprintk(VXD_CBIT(dlim, 6),
19259 +               "__hash_dl_info: %p[#%d]", dli, dli->dl_tag);
19260 +       get_dl_info(dli);
19261 +       head = &dl_info_hash[__hashval(dli->dl_sb, dli->dl_tag)];
19262 +       hlist_add_head_rcu(&dli->dl_hlist, head);
19263 +}
19264 +
19265 +/*     __unhash_dl_info()
19266 +
19267 +       * remove the dli from the global hash table
19268 +       * requires the hash_lock to be held                     */
19269 +
19270 +static inline void __unhash_dl_info(struct dl_info *dli)
19271 +{
19272 +       vxdprintk(VXD_CBIT(dlim, 6),
19273 +               "__unhash_dl_info: %p[#%d]", dli, dli->dl_tag);
19274 +       hlist_del_rcu(&dli->dl_hlist);
19275 +       put_dl_info(dli);
19276 +}
19277 +
19278 +
19279 +/*     __lookup_dl_info()
19280 +
19281 +       * requires the rcu_read_lock()
19282 +       * doesn't increment the dl_refcnt                       */
19283 +
19284 +static inline struct dl_info *__lookup_dl_info(struct super_block *sb, tag_t tag)
19285 +{
19286 +       struct hlist_head *head = &dl_info_hash[__hashval(sb, tag)];
19287 +       struct hlist_node *pos;
19288 +       struct dl_info *dli;
19289 +
19290 +       hlist_for_each_entry_rcu(dli, pos, head, dl_hlist) {
19291 +
19292 +               if (dli->dl_tag == tag && dli->dl_sb == sb) {
19293 +                       return dli;
19294 +               }
19295 +       }
19296 +       return NULL;
19297 +}
19298 +
19299 +
19300 +struct dl_info *locate_dl_info(struct super_block *sb, tag_t tag)
19301 +{
19302 +       struct dl_info *dli;
19303 +
19304 +       rcu_read_lock();
19305 +       dli = get_dl_info(__lookup_dl_info(sb, tag));
19306 +       vxdprintk(VXD_CBIT(dlim, 7),
19307 +               "locate_dl_info(%p,#%d) = %p", sb, tag, dli);
19308 +       rcu_read_unlock();
19309 +       return dli;
19310 +}
19311 +
19312 +void rcu_free_dl_info(struct rcu_head *head)
19313 +{
19314 +       struct dl_info *dli = container_of(head, struct dl_info, dl_rcu);
19315 +       int usecnt, refcnt;
19316 +
19317 +       BUG_ON(!dli || !head);
19318 +
19319 +       usecnt = atomic_read(&dli->dl_usecnt);
19320 +       BUG_ON(usecnt < 0);
19321 +
19322 +       refcnt = atomic_read(&dli->dl_refcnt);
19323 +       BUG_ON(refcnt < 0);
19324 +
19325 +       vxdprintk(VXD_CBIT(dlim, 3),
19326 +               "rcu_free_dl_info(%p)", dli);
19327 +       if (!usecnt)
19328 +               __dealloc_dl_info(dli);
19329 +       else
19330 +               printk("!!! rcu didn't free\n");
19331 +}
19332 +
19333 +
19334 +
19335 +
19336 +static int do_addrem_dlimit(uint32_t id, const char __user *name,
19337 +       uint32_t flags, int add)
19338 +{
19339 +       struct path path;
19340 +       int ret;
19341 +
19342 +       ret = user_lpath(name, &path);
19343 +       if (!ret) {
19344 +               struct super_block *sb;
19345 +               struct dl_info *dli;
19346 +
19347 +               ret = -EINVAL;
19348 +               if (!path.dentry->d_inode)
19349 +                       goto out_release;
19350 +               if (!(sb = path.dentry->d_inode->i_sb))
19351 +                       goto out_release;
19352 +
19353 +               if (add) {
19354 +                       dli = __alloc_dl_info(sb, id);
19355 +                       spin_lock(&dl_info_hash_lock);
19356 +
19357 +                       ret = -EEXIST;
19358 +                       if (__lookup_dl_info(sb, id))
19359 +                               goto out_unlock;
19360 +                       __hash_dl_info(dli);
19361 +                       dli = NULL;
19362 +               } else {
19363 +                       spin_lock(&dl_info_hash_lock);
19364 +                       dli = __lookup_dl_info(sb, id);
19365 +
19366 +                       ret = -ESRCH;
19367 +                       if (!dli)
19368 +                               goto out_unlock;
19369 +                       __unhash_dl_info(dli);
19370 +               }
19371 +               ret = 0;
19372 +       out_unlock:
19373 +               spin_unlock(&dl_info_hash_lock);
19374 +               if (add && dli)
19375 +                       __dealloc_dl_info(dli);
19376 +       out_release:
19377 +               path_put(&path);
19378 +       }
19379 +       return ret;
19380 +}
19381 +
19382 +int vc_add_dlimit(uint32_t id, void __user *data)
19383 +{
19384 +       struct vcmd_ctx_dlimit_base_v0 vc_data;
19385 +
19386 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19387 +               return -EFAULT;
19388 +
19389 +       return do_addrem_dlimit(id, vc_data.name, vc_data.flags, 1);
19390 +}
19391 +
19392 +int vc_rem_dlimit(uint32_t id, void __user *data)
19393 +{
19394 +       struct vcmd_ctx_dlimit_base_v0 vc_data;
19395 +
19396 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19397 +               return -EFAULT;
19398 +
19399 +       return do_addrem_dlimit(id, vc_data.name, vc_data.flags, 0);
19400 +}
19401 +
19402 +#ifdef CONFIG_COMPAT
19403 +
19404 +int vc_add_dlimit_x32(uint32_t id, void __user *data)
19405 +{
19406 +       struct vcmd_ctx_dlimit_base_v0_x32 vc_data;
19407 +
19408 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19409 +               return -EFAULT;
19410 +
19411 +       return do_addrem_dlimit(id,
19412 +               compat_ptr(vc_data.name_ptr), vc_data.flags, 1);
19413 +}
19414 +
19415 +int vc_rem_dlimit_x32(uint32_t id, void __user *data)
19416 +{
19417 +       struct vcmd_ctx_dlimit_base_v0_x32 vc_data;
19418 +
19419 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19420 +               return -EFAULT;
19421 +
19422 +       return do_addrem_dlimit(id,
19423 +               compat_ptr(vc_data.name_ptr), vc_data.flags, 0);
19424 +}
19425 +
19426 +#endif /* CONFIG_COMPAT */
19427 +
19428 +
19429 +static inline
19430 +int do_set_dlimit(uint32_t id, const char __user *name,
19431 +       uint32_t space_used, uint32_t space_total,
19432 +       uint32_t inodes_used, uint32_t inodes_total,
19433 +       uint32_t reserved, uint32_t flags)
19434 +{
19435 +       struct path path;
19436 +       int ret;
19437 +
19438 +       ret = user_lpath(name, &path);
19439 +       if (!ret) {
19440 +               struct super_block *sb;
19441 +               struct dl_info *dli;
19442 +
19443 +               ret = -EINVAL;
19444 +               if (!path.dentry->d_inode)
19445 +                       goto out_release;
19446 +               if (!(sb = path.dentry->d_inode->i_sb))
19447 +                       goto out_release;
19448 +               if ((reserved != CDLIM_KEEP &&
19449 +                       reserved > 100) ||
19450 +                       (inodes_used != CDLIM_KEEP &&
19451 +                       inodes_used > inodes_total) ||
19452 +                       (space_used != CDLIM_KEEP &&
19453 +                       space_used > space_total))
19454 +                       goto out_release;
19455 +
19456 +               ret = -ESRCH;
19457 +               dli = locate_dl_info(sb, id);
19458 +               if (!dli)
19459 +                       goto out_release;
19460 +
19461 +               spin_lock(&dli->dl_lock);
19462 +
19463 +               if (inodes_used != CDLIM_KEEP)
19464 +                       dli->dl_inodes_used = inodes_used;
19465 +               if (inodes_total != CDLIM_KEEP)
19466 +                       dli->dl_inodes_total = inodes_total;
19467 +               if (space_used != CDLIM_KEEP) {
19468 +                       dli->dl_space_used = space_used;
19469 +                       dli->dl_space_used <<= 10;
19470 +               }
19471 +               if (space_total == CDLIM_INFINITY)
19472 +                       dli->dl_space_total = DLIM_INFINITY;
19473 +               else if (space_total != CDLIM_KEEP) {
19474 +                       dli->dl_space_total = space_total;
19475 +                       dli->dl_space_total <<= 10;
19476 +               }
19477 +               if (reserved != CDLIM_KEEP)
19478 +                       dli->dl_nrlmult = (1 << 10) * (100 - reserved) / 100;
19479 +
19480 +               spin_unlock(&dli->dl_lock);
19481 +
19482 +               put_dl_info(dli);
19483 +               ret = 0;
19484 +
19485 +       out_release:
19486 +               path_put(&path);
19487 +       }
19488 +       return ret;
19489 +}
19490 +
19491 +int vc_set_dlimit(uint32_t id, void __user *data)
19492 +{
19493 +       struct vcmd_ctx_dlimit_v0 vc_data;
19494 +
19495 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19496 +               return -EFAULT;
19497 +
19498 +       return do_set_dlimit(id, vc_data.name,
19499 +               vc_data.space_used, vc_data.space_total,
19500 +               vc_data.inodes_used, vc_data.inodes_total,
19501 +               vc_data.reserved, vc_data.flags);
19502 +}
19503 +
19504 +#ifdef CONFIG_COMPAT
19505 +
19506 +int vc_set_dlimit_x32(uint32_t id, void __user *data)
19507 +{
19508 +       struct vcmd_ctx_dlimit_v0_x32 vc_data;
19509 +
19510 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19511 +               return -EFAULT;
19512 +
19513 +       return do_set_dlimit(id, compat_ptr(vc_data.name_ptr),
19514 +               vc_data.space_used, vc_data.space_total,
19515 +               vc_data.inodes_used, vc_data.inodes_total,
19516 +               vc_data.reserved, vc_data.flags);
19517 +}
19518 +
19519 +#endif /* CONFIG_COMPAT */
19520 +
19521 +
19522 +static inline
19523 +int do_get_dlimit(uint32_t id, const char __user *name,
19524 +       uint32_t *space_used, uint32_t *space_total,
19525 +       uint32_t *inodes_used, uint32_t *inodes_total,
19526 +       uint32_t *reserved, uint32_t *flags)
19527 +{
19528 +       struct path path;
19529 +       int ret;
19530 +
19531 +       ret = user_lpath(name, &path);
19532 +       if (!ret) {
19533 +               struct super_block *sb;
19534 +               struct dl_info *dli;
19535 +
19536 +               ret = -EINVAL;
19537 +               if (!path.dentry->d_inode)
19538 +                       goto out_release;
19539 +               if (!(sb = path.dentry->d_inode->i_sb))
19540 +                       goto out_release;
19541 +
19542 +               ret = -ESRCH;
19543 +               dli = locate_dl_info(sb, id);
19544 +               if (!dli)
19545 +                       goto out_release;
19546 +
19547 +               spin_lock(&dli->dl_lock);
19548 +               *inodes_used = dli->dl_inodes_used;
19549 +               *inodes_total = dli->dl_inodes_total;
19550 +               *space_used = dli->dl_space_used >> 10;
19551 +               if (dli->dl_space_total == DLIM_INFINITY)
19552 +                       *space_total = CDLIM_INFINITY;
19553 +               else
19554 +                       *space_total = dli->dl_space_total >> 10;
19555 +
19556 +               *reserved = 100 - ((dli->dl_nrlmult * 100 + 512) >> 10);
19557 +               spin_unlock(&dli->dl_lock);
19558 +
19559 +               put_dl_info(dli);
19560 +               ret = -EFAULT;
19561 +
19562 +               ret = 0;
19563 +       out_release:
19564 +               path_put(&path);
19565 +       }
19566 +       return ret;
19567 +}
19568 +
19569 +
19570 +int vc_get_dlimit(uint32_t id, void __user *data)
19571 +{
19572 +       struct vcmd_ctx_dlimit_v0 vc_data;
19573 +       int ret;
19574 +
19575 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19576 +               return -EFAULT;
19577 +
19578 +       ret = do_get_dlimit(id, vc_data.name,
19579 +               &vc_data.space_used, &vc_data.space_total,
19580 +               &vc_data.inodes_used, &vc_data.inodes_total,
19581 +               &vc_data.reserved, &vc_data.flags);
19582 +       if (ret)
19583 +               return ret;
19584 +
19585 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
19586 +               return -EFAULT;
19587 +       return 0;
19588 +}
19589 +
19590 +#ifdef CONFIG_COMPAT
19591 +
19592 +int vc_get_dlimit_x32(uint32_t id, void __user *data)
19593 +{
19594 +       struct vcmd_ctx_dlimit_v0_x32 vc_data;
19595 +       int ret;
19596 +
19597 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19598 +               return -EFAULT;
19599 +
19600 +       ret = do_get_dlimit(id, compat_ptr(vc_data.name_ptr),
19601 +               &vc_data.space_used, &vc_data.space_total,
19602 +               &vc_data.inodes_used, &vc_data.inodes_total,
19603 +               &vc_data.reserved, &vc_data.flags);
19604 +       if (ret)
19605 +               return ret;
19606 +
19607 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
19608 +               return -EFAULT;
19609 +       return 0;
19610 +}
19611 +
19612 +#endif /* CONFIG_COMPAT */
19613 +
19614 +
19615 +void vx_vsi_statfs(struct super_block *sb, struct kstatfs *buf)
19616 +{
19617 +       struct dl_info *dli;
19618 +       __u64 blimit, bfree, bavail;
19619 +       __u32 ifree;
19620 +
19621 +       dli = locate_dl_info(sb, dx_current_tag());
19622 +       if (!dli)
19623 +               return;
19624 +
19625 +       spin_lock(&dli->dl_lock);
19626 +       if (dli->dl_inodes_total == (unsigned long)DLIM_INFINITY)
19627 +               goto no_ilim;
19628 +
19629 +       /* reduce max inodes available to limit */
19630 +       if (buf->f_files > dli->dl_inodes_total)
19631 +               buf->f_files = dli->dl_inodes_total;
19632 +
19633 +       ifree = dli->dl_inodes_total - dli->dl_inodes_used;
19634 +       /* reduce free inodes to min */
19635 +       if (ifree < buf->f_ffree)
19636 +               buf->f_ffree = ifree;
19637 +
19638 +no_ilim:
19639 +       if (dli->dl_space_total == DLIM_INFINITY)
19640 +               goto no_blim;
19641 +
19642 +       blimit = dli->dl_space_total >> sb->s_blocksize_bits;
19643 +
19644 +       if (dli->dl_space_total < dli->dl_space_used)
19645 +               bfree = 0;
19646 +       else
19647 +               bfree = (dli->dl_space_total - dli->dl_space_used)
19648 +                       >> sb->s_blocksize_bits;
19649 +
19650 +       bavail = ((dli->dl_space_total >> 10) * dli->dl_nrlmult);
19651 +       if (bavail < dli->dl_space_used)
19652 +               bavail = 0;
19653 +       else
19654 +               bavail = (bavail - dli->dl_space_used)
19655 +                       >> sb->s_blocksize_bits;
19656 +
19657 +       /* reduce max space available to limit */
19658 +       if (buf->f_blocks > blimit)
19659 +               buf->f_blocks = blimit;
19660 +
19661 +       /* reduce free space to min */
19662 +       if (bfree < buf->f_bfree)
19663 +               buf->f_bfree = bfree;
19664 +
19665 +       /* reduce avail space to min */
19666 +       if (bavail < buf->f_bavail)
19667 +               buf->f_bavail = bavail;
19668 +
19669 +no_blim:
19670 +       spin_unlock(&dli->dl_lock);
19671 +       put_dl_info(dli);
19672 +
19673 +       return;
19674 +}
19675 +
19676 +#include <linux/module.h>
19677 +
19678 +EXPORT_SYMBOL_GPL(locate_dl_info);
19679 +EXPORT_SYMBOL_GPL(rcu_free_dl_info);
19680 +
19681 diff -NurpP --minimal linux-2.6.29.1/kernel/vserver/helper.c linux-2.6.29.1-vs2.3.0.36.9-pre5/kernel/vserver/helper.c
19682 --- linux-2.6.29.1/kernel/vserver/helper.c      1970-01-01 01:00:00.000000000 +0100
19683 +++ linux-2.6.29.1-vs2.3.0.36.9-pre5/kernel/vserver/helper.c    2009-03-25 00:40:43.000000000 +0100
19684 @@ -0,0 +1,199 @@
19685 +/*
19686 + *  linux/kernel/vserver/helper.c
19687 + *
19688 + *  Virtual Context Support
19689 + *
19690 + *  Copyright (C) 2004-2007  Herbert Pötzl
19691 + *
19692 + *  V0.01  basic helper
19693 + *
19694 + */
19695 +
19696 +#include <linux/kmod.h>
19697 +#include <linux/reboot.h>
19698 +#include <linux/vs_context.h>
19699 +#include <linux/vs_network.h>
19700 +#include <linux/vserver/signal.h>
19701 +
19702 +
19703 +char vshelper_path[255] = "/sbin/vshelper";
19704 +
19705 +
19706 +static int do_vshelper(char *name, char *argv[], char *envp[], int sync)
19707 +{
19708 +       int ret;
19709 +
19710 +       if ((ret = call_usermodehelper(name, argv, envp, sync))) {
19711 +               printk( KERN_WARNING
19712 +                       "%s: (%s %s) returned %s with %d\n",
19713 +                       name, argv[1], argv[2],
19714 +                       sync ? "sync" : "async", ret);
19715 +       }
19716 +       vxdprintk(VXD_CBIT(switch, 4),
19717 +               "%s: (%s %s) returned %s with %d",
19718 +               name, argv[1], argv[2], sync ? "sync" : "async", ret);
19719 +       return ret;
19720 +}
19721 +
19722 +/*
19723 + *      vshelper path is set via /proc/sys
19724 + *      invoked by vserver sys_reboot(), with
19725 + *      the following arguments
19726 + *
19727 + *      argv [0] = vshelper_path;
19728 + *      argv [1] = action: "restart", "halt", "poweroff", ...
19729 + *      argv [2] = context identifier
19730 + *
19731 + *      envp [*] = type-specific parameters
19732 + */
19733 +
19734 +long vs_reboot_helper(struct vx_info *vxi, int cmd, void __user *arg)
19735 +{
19736 +       char id_buf[8], cmd_buf[16];
19737 +       char uid_buf[16], pid_buf[16];
19738 +       int ret;
19739 +
19740 +       char *argv[] = {vshelper_path, NULL, id_buf, 0};
19741 +       char *envp[] = {"HOME=/", "TERM=linux",
19742 +                       "PATH=/sbin:/usr/sbin:/bin:/usr/bin",
19743 +                       uid_buf, pid_buf, cmd_buf, 0};
19744 +
19745 +       if (vx_info_state(vxi, VXS_HELPER))
19746 +               return -EAGAIN;
19747 +       vxi->vx_state |= VXS_HELPER;
19748 +
19749 +       snprintf(id_buf, sizeof(id_buf)-1, "%d", vxi->vx_id);
19750 +
19751 +       snprintf(cmd_buf, sizeof(cmd_buf)-1, "VS_CMD=%08x", cmd);
19752 +       snprintf(uid_buf, sizeof(uid_buf)-1, "VS_UID=%d", current_uid());
19753 +       snprintf(pid_buf, sizeof(pid_buf)-1, "VS_PID=%d", current->pid);
19754 +
19755 +       switch (cmd) {
19756 +       case LINUX_REBOOT_CMD_RESTART:
19757 +               argv[1] = "restart";
19758 +               break;
19759 +
19760 +       case LINUX_REBOOT_CMD_HALT:
19761 +               argv[1] = "halt";
19762 +               break;
19763 +
19764 +       case LINUX_REBOOT_CMD_POWER_OFF:
19765 +               argv[1] = "poweroff";
19766 +               break;
19767 +
19768 +       case LINUX_REBOOT_CMD_SW_SUSPEND:
19769 +               argv[1] = "swsusp";
19770 +               break;
19771 +
19772 +       default:
19773 +               vxi->vx_state &= ~VXS_HELPER;
19774 +               return 0;
19775 +       }
19776 +
19777 +       ret = do_vshelper(vshelper_path, argv, envp, 0);
19778 +       vxi->vx_state &= ~VXS_HELPER;
19779 +       __wakeup_vx_info(vxi);
19780 +       return (ret) ? -EPERM : 0;
19781 +}
19782 +
19783 +
19784 +long vs_reboot(unsigned int cmd, void __user *arg)
19785 +{
19786 +       struct vx_info *vxi = current->vx_info;
19787 +       long ret = 0;
19788 +
19789 +       vxdprintk(VXD_CBIT(misc, 5),
19790 +               "vs_reboot(%p[#%d],%d)",
19791 +               vxi, vxi ? vxi->vx_id : 0, cmd);
19792 +
19793 +       ret = vs_reboot_helper(vxi, cmd, arg);
19794 +       if (ret)
19795 +               return ret;
19796 +
19797 +       vxi->reboot_cmd = cmd;
19798 +       if (vx_info_flags(vxi, VXF_REBOOT_KILL, 0)) {
19799 +               switch (cmd) {
19800 +               case LINUX_REBOOT_CMD_RESTART:
19801 +               case LINUX_REBOOT_CMD_HALT:
19802 +               case LINUX_REBOOT_CMD_POWER_OFF:
19803 +                       vx_info_kill(vxi, 0, SIGKILL);
19804 +                       vx_info_kill(vxi, 1, SIGKILL);
19805 +               default:
19806 +                       break;
19807 +               }
19808 +       }
19809 +       return 0;
19810 +}
19811 +
19812 +
19813 +/*
19814 + *      argv [0] = vshelper_path;
19815 + *      argv [1] = action: "startup", "shutdown"
19816 + *      argv [2] = context identifier
19817 + *
19818 + *      envp [*] = type-specific parameters
19819 + */
19820 +
19821 +long vs_state_change(struct vx_info *vxi, unsigned int cmd)
19822 +{
19823 +       char id_buf[8], cmd_buf[16];
19824 +       char *argv[] = {vshelper_path, NULL, id_buf, 0};
19825 +       char *envp[] = {"HOME=/", "TERM=linux",
19826 +                       "PATH=/sbin:/usr/sbin:/bin:/usr/bin", cmd_buf, 0};
19827 +
19828 +       if (!vx_info_flags(vxi, VXF_SC_HELPER, 0))
19829 +               return 0;
19830 +
19831 +       snprintf(id_buf, sizeof(id_buf)-1, "%d", vxi->vx_id);
19832 +       snprintf(cmd_buf, sizeof(cmd_buf)-1, "VS_CMD=%08x", cmd);
19833 +
19834 +       switch (cmd) {
19835 +       case VSC_STARTUP:
19836 +               argv[1] = "startup";
19837 +               break;
19838 +       case VSC_SHUTDOWN:
19839 +               argv[1] = "shutdown";
19840 +               break;
19841 +       default:
19842 +               return 0;
19843 +       }
19844 +
19845 +       return do_vshelper(vshelper_path, argv, envp, 1);
19846 +}
19847 +
19848 +
19849 +/*
19850 + *      argv [0] = vshelper_path;
19851 + *      argv [1] = action: "netup", "netdown"
19852 + *      argv [2] = context identifier
19853 + *
19854 + *      envp [*] = type-specific parameters
19855 + */
19856 +
19857 +long vs_net_change(struct nx_info *nxi, unsigned int cmd)
19858 +{
19859 +       char id_buf[8], cmd_buf[16];
19860 +       char *argv[] = {vshelper_path, NULL, id_buf, 0};
19861 +       char *envp[] = {"HOME=/", "TERM=linux",
19862 +                       "PATH=/sbin:/usr/sbin:/bin:/usr/bin", cmd_buf, 0};
19863 +
19864 +       if (!nx_info_flags(nxi, NXF_SC_HELPER, 0))
19865 +               return 0;
19866 +
19867 +       snprintf(id_buf, sizeof(id_buf)-1, "%d", nxi->nx_id);
19868 +       snprintf(cmd_buf, sizeof(cmd_buf)-1, "VS_CMD=%08x", cmd);
19869 +
19870 +       switch (cmd) {
19871 +       case VSC_NETUP:
19872 +               argv[1] = "netup";
19873 +               break;
19874 +       case VSC_NETDOWN:
19875 +               argv[1] = "netdown";
19876 +               break;
19877 +       default:
19878 +               return 0;
19879 +       }
19880 +
19881 +       return do_vshelper(vshelper_path, argv, envp, 1);
19882 +}
19883 +
19884 diff -NurpP --minimal linux-2.6.29.1/kernel/vserver/history.c linux-2.6.29.1-vs2.3.0.36.9-pre5/kernel/vserver/history.c
19885 --- linux-2.6.29.1/kernel/vserver/history.c     1970-01-01 01:00:00.000000000 +0100
19886 +++ linux-2.6.29.1-vs2.3.0.36.9-pre5/kernel/vserver/history.c   2009-02-22 22:54:26.000000000 +0100
19887 @@ -0,0 +1,258 @@
19888 +/*
19889 + *  kernel/vserver/history.c
19890 + *
19891 + *  Virtual Context History Backtrace
19892 + *
19893 + *  Copyright (C) 2004-2007  Herbert Pötzl
19894 + *
19895 + *  V0.01  basic structure
19896 + *  V0.02  hash/unhash and trace
19897 + *  V0.03  preemption fixes
19898 + *
19899 + */
19900 +
19901 +#include <linux/module.h>
19902 +#include <asm/uaccess.h>
19903 +
19904 +#include <linux/vserver/context.h>
19905 +#include <linux/vserver/debug.h>
19906 +#include <linux/vserver/debug_cmd.h>
19907 +#include <linux/vserver/history.h>
19908 +
19909 +
19910 +#ifdef CONFIG_VSERVER_HISTORY
19911 +#define VXH_SIZE       CONFIG_VSERVER_HISTORY_SIZE
19912 +#else
19913 +#define VXH_SIZE       64
19914 +#endif
19915 +
19916 +struct _vx_history {
19917 +       unsigned int counter;
19918 +
19919 +       struct _vx_hist_entry entry[VXH_SIZE + 1];
19920 +};
19921 +
19922 +
19923 +DEFINE_PER_CPU(struct _vx_history, vx_history_buffer);
19924 +
19925 +unsigned volatile int vxh_active = 1;
19926 +
19927 +static atomic_t sequence = ATOMIC_INIT(0);
19928 +
19929 +
19930 +/*     vxh_advance()
19931 +
19932 +       * requires disabled preemption                          */
19933 +
19934 +struct _vx_hist_entry *vxh_advance(void *loc)
19935 +{
19936 +       unsigned int cpu = smp_processor_id();
19937 +       struct _vx_history *hist = &per_cpu(vx_history_buffer, cpu);
19938 +       struct _vx_hist_entry *entry;
19939 +       unsigned int index;
19940 +
19941 +       index = vxh_active ? (hist->counter++ % VXH_SIZE) : VXH_SIZE;
19942 +       entry = &hist->entry[index];
19943 +
19944 +       entry->seq = atomic_inc_return(&sequence);
19945 +       entry->loc = loc;
19946 +       return entry;
19947 +}
19948 +
19949 +EXPORT_SYMBOL_GPL(vxh_advance);
19950 +
19951 +
19952 +#define VXH_LOC_FMTS   "(#%04x,*%d):%p"
19953 +
19954 +#define VXH_LOC_ARGS(e)        (e)->seq, cpu, (e)->loc
19955 +
19956 +
19957 +#define VXH_VXI_FMTS   "%p[#%d,%d.%d]"
19958 +
19959 +#define VXH_VXI_ARGS(e)        (e)->vxi.ptr,                           \
19960 +                       (e)->vxi.ptr ? (e)->vxi.xid : 0,        \
19961 +                       (e)->vxi.ptr ? (e)->vxi.usecnt : 0,     \
19962 +                       (e)->vxi.ptr ? (e)->vxi.tasks : 0
19963 +
19964 +void   vxh_dump_entry(struct _vx_hist_entry *e, unsigned cpu)
19965 +{
19966 +       switch (e->type) {
19967 +       case VXH_THROW_OOPS:
19968 +               printk( VXH_LOC_FMTS " oops \n", VXH_LOC_ARGS(e));
19969 +               break;
19970 +
19971 +       case VXH_GET_VX_INFO:
19972 +       case VXH_PUT_VX_INFO:
19973 +               printk( VXH_LOC_FMTS " %s_vx_info " VXH_VXI_FMTS "\n",
19974 +                       VXH_LOC_ARGS(e),
19975 +                       (e->type == VXH_GET_VX_INFO) ? "get" : "put",
19976 +                       VXH_VXI_ARGS(e));
19977 +               break;
19978 +
19979 +       case VXH_INIT_VX_INFO:
19980 +       case VXH_SET_VX_INFO:
19981 +       case VXH_CLR_VX_INFO:
19982 +               printk( VXH_LOC_FMTS " %s_vx_info " VXH_VXI_FMTS " @%p\n",
19983 +                       VXH_LOC_ARGS(e),
19984 +                       (e->type == VXH_INIT_VX_INFO) ? "init" :
19985 +                       ((e->type == VXH_SET_VX_INFO) ? "set" : "clr"),
19986 +                       VXH_VXI_ARGS(e), e->sc.data);
19987 +               break;
19988 +
19989 +       case VXH_CLAIM_VX_INFO:
19990 +       case VXH_RELEASE_VX_INFO:
19991 +               printk( VXH_LOC_FMTS " %s_vx_info " VXH_VXI_FMTS " @%p\n",
19992 +                       VXH_LOC_ARGS(e),
19993 +                       (e->type == VXH_CLAIM_VX_INFO) ? "claim" : "release",
19994 +                       VXH_VXI_ARGS(e), e->sc.data);
19995 +               break;
19996 +
19997 +       case VXH_ALLOC_VX_INFO:
19998 +       case VXH_DEALLOC_VX_INFO:
19999 +               printk( VXH_LOC_FMTS " %s_vx_info " VXH_VXI_FMTS "\n",
20000 +                       VXH_LOC_ARGS(e),
20001 +                       (e->type == VXH_ALLOC_VX_INFO) ? "alloc" : "dealloc",
20002 +                       VXH_VXI_ARGS(e));
20003 +               break;
20004 +
20005 +       case VXH_HASH_VX_INFO:
20006 +       case VXH_UNHASH_VX_INFO:
20007 +               printk( VXH_LOC_FMTS " __%s_vx_info " VXH_VXI_FMTS "\n",
20008 +                       VXH_LOC_ARGS(e),
20009 +                       (e->type == VXH_HASH_VX_INFO) ? "hash" : "unhash",
20010 +                       VXH_VXI_ARGS(e));
20011 +               break;
20012 +
20013 +       case VXH_LOC_VX_INFO:
20014 +       case VXH_LOOKUP_VX_INFO:
20015 +       case VXH_CREATE_VX_INFO:
20016 +               printk( VXH_LOC_FMTS " __%s_vx_info [#%d] -> " VXH_VXI_FMTS "\n",
20017 +                       VXH_LOC_ARGS(e),
20018 +                       (e->type == VXH_CREATE_VX_INFO) ? "create" :
20019 +                       ((e->type == VXH_LOC_VX_INFO) ? "loc" : "lookup"),
20020 +                       e->ll.arg, VXH_VXI_ARGS(e));
20021 +               break;
20022 +       }
20023 +}
20024 +
20025 +static void __vxh_dump_history(void)
20026 +{
20027 +       unsigned int i, cpu;
20028 +
20029 +       printk("History:\tSEQ: %8x\tNR_CPUS: %d\n",
20030 +               atomic_read(&sequence), NR_CPUS);
20031 +
20032 +       for (i = 0; i < VXH_SIZE; i++) {
20033 +               for_each_online_cpu(cpu) {
20034 +                       struct _vx_history *hist =
20035 +                               &per_cpu(vx_history_buffer, cpu);
20036 +                       unsigned int index = (hist->counter - i) % VXH_SIZE;
20037 +                       struct _vx_hist_entry *entry = &hist->entry[index];
20038 +
20039 +                       vxh_dump_entry(entry, cpu);
20040 +               }
20041 +       }
20042 +}
20043 +
20044 +void   vxh_dump_history(void)
20045 +{
20046 +       vxh_active = 0;
20047 +#ifdef CONFIG_SMP
20048 +       local_irq_enable();
20049 +       smp_send_stop();
20050 +       local_irq_disable();
20051 +#endif
20052 +       __vxh_dump_history();
20053 +}
20054 +
20055 +
20056 +/* vserver syscall commands below here */
20057 +
20058 +
20059 +int vc_dump_history(uint32_t id)
20060 +{
20061 +       vxh_active = 0;
20062 +       __vxh_dump_history();
20063 +       vxh_active = 1;
20064 +
20065 +       return 0;
20066 +}
20067 +
20068 +
20069 +int do_read_history(struct __user _vx_hist_entry *data,
20070 +       int cpu, uint32_t *index, uint32_t *count)
20071 +{
20072 +       int pos, ret = 0;
20073 +       struct _vx_history *hist = &per_cpu(vx_history_buffer, cpu);
20074 +       int end = hist->counter;
20075 +       int start = end - VXH_SIZE + 2;
20076 +       int idx = *index;
20077 +
20078 +       /* special case: get current pos */
20079 +       if (!*count) {
20080 +               *index = end;
20081 +               return 0;
20082 +       }
20083 +
20084 +       /* have we lost some data? */
20085 +       if (idx < start)
20086 +               idx = start;
20087 +
20088 +       for (pos = 0; (pos < *count) && (idx < end); pos++, idx++) {
20089 +               struct _vx_hist_entry *entry =
20090 +                       &hist->entry[idx % VXH_SIZE];
20091 +
20092 +               /* send entry to userspace */
20093 +               ret = copy_to_user(&data[pos], entry, sizeof(*entry));
20094 +               if (ret)
20095 +                       break;
20096 +       }
20097 +       /* save new index and count */
20098 +       *index = idx;
20099 +       *count = pos;
20100 +       return ret ? ret : (*index < end);
20101 +}
20102 +
20103 +int vc_read_history(uint32_t id, void __user *data)
20104 +{
20105 +       struct vcmd_read_history_v0 vc_data;
20106 +       int ret;
20107 +
20108 +       if (id >= NR_CPUS)
20109 +               return -EINVAL;
20110 +
20111 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
20112 +               return -EFAULT;
20113 +
20114 +       ret = do_read_history((struct __user _vx_hist_entry *)vc_data.data,
20115 +               id, &vc_data.index, &vc_data.count);
20116 +
20117 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
20118 +               return -EFAULT;
20119 +       return ret;
20120 +}
20121 +
20122 +#ifdef CONFIG_COMPAT
20123 +
20124 +int vc_read_history_x32(uint32_t id, void __user *data)
20125 +{
20126 +       struct vcmd_read_history_v0_x32 vc_data;
20127 +       int ret;
20128 +
20129 +       if (id >= NR_CPUS)
20130 +               return -EINVAL;
20131 +
20132 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
20133 +               return -EFAULT;
20134 +
20135 +       ret = do_read_history((struct __user _vx_hist_entry *)
20136 +               compat_ptr(vc_data.data_ptr),
20137 +               id, &vc_data.index, &vc_data.count);
20138 +
20139 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
20140 +               return -EFAULT;
20141 +       return ret;
20142 +}
20143 +
20144 +#endif /* CONFIG_COMPAT */
20145 +
20146 diff -NurpP --minimal linux-2.6.29.1/kernel/vserver/inet.c linux-2.6.29.1-vs2.3.0.36.9-pre5/kernel/vserver/inet.c
20147 --- linux-2.6.29.1/kernel/vserver/inet.c        1970-01-01 01:00:00.000000000 +0100
20148 +++ linux-2.6.29.1-vs2.3.0.36.9-pre5/kernel/vserver/inet.c      2009-02-22 22:54:26.000000000 +0100
20149 @@ -0,0 +1,225 @@
20150 +
20151 +#include <linux/in.h>
20152 +#include <linux/inetdevice.h>
20153 +#include <linux/vs_inet.h>
20154 +#include <linux/vs_inet6.h>
20155 +#include <linux/vserver/debug.h>
20156 +#include <net/route.h>
20157 +#include <net/addrconf.h>
20158 +
20159 +
20160 +int nx_v4_addr_conflict(struct nx_info *nxi1, struct nx_info *nxi2)
20161 +{
20162 +       int ret = 0;
20163 +
20164 +       if (!nxi1 || !nxi2 || nxi1 == nxi2)
20165 +               ret = 1;
20166 +       else {
20167 +               struct nx_addr_v4 *ptr;
20168 +
20169 +               for (ptr = &nxi1->v4; ptr; ptr = ptr->next) {
20170 +                       if (v4_nx_addr_in_nx_info(nxi2, ptr, -1)) {
20171 +                               ret = 1;
20172 +                               break;
20173 +                       }
20174 +               }
20175 +       }
20176 +
20177 +       vxdprintk(VXD_CBIT(net, 2),
20178 +               "nx_v4_addr_conflict(%p,%p): %d",
20179 +               nxi1, nxi2, ret);
20180 +
20181 +       return ret;
20182 +}
20183 +
20184 +
20185 +#ifdef CONFIG_IPV6
20186 +
20187 +int nx_v6_addr_conflict(struct nx_info *nxi1, struct nx_info *nxi2)
20188 +{
20189 +       int ret = 0;
20190 +
20191 +       if (!nxi1 || !nxi2 || nxi1 == nxi2)
20192 +               ret = 1;
20193 +       else {
20194 +               struct nx_addr_v6 *ptr;
20195 +
20196 +               for (ptr = &nxi1->v6; ptr; ptr = ptr->next) {
20197 +                       if (v6_nx_addr_in_nx_info(nxi2, ptr, -1)) {
20198 +                               ret = 1;
20199 +                               break;
20200 +                       }
20201 +               }
20202 +       }
20203 +
20204 +       vxdprintk(VXD_CBIT(net, 2),
20205 +               "nx_v6_addr_conflict(%p,%p): %d",
20206 +               nxi1, nxi2, ret);
20207 +
20208 +       return ret;
20209 +}
20210 +
20211 +#endif
20212 +
20213 +int v4_dev_in_nx_info(struct net_device *dev, struct nx_info *nxi)
20214 +{
20215 +       struct in_device *in_dev;
20216 +       struct in_ifaddr **ifap;
20217 +       struct in_ifaddr *ifa;
20218 +       int ret = 0;
20219 +
20220 +       if (!dev)
20221 +               goto out;
20222 +       in_dev = in_dev_get(dev);
20223 +       if (!in_dev)
20224 +               goto out;
20225 +
20226 +       for (ifap = &in_dev->ifa_list; (ifa = *ifap) != NULL;
20227 +               ifap = &ifa->ifa_next) {
20228 +               if (v4_addr_in_nx_info(nxi, ifa->ifa_local, NXA_MASK_SHOW)) {
20229 +                       ret = 1;
20230 +                       break;
20231 +               }
20232 +       }
20233 +       in_dev_put(in_dev);
20234 +out:
20235 +       return ret;
20236 +}
20237 +
20238 +
20239 +#ifdef CONFIG_IPV6
20240 +
20241 +int v6_dev_in_nx_info(struct net_device *dev, struct nx_info *nxi)
20242 +{
20243 +       struct inet6_dev *in_dev;
20244 +       struct inet6_ifaddr **ifap;
20245 +       struct inet6_ifaddr *ifa;
20246 +       int ret = 0;
20247 +
20248 +       if (!dev)
20249 +               goto out;
20250 +       in_dev = in6_dev_get(dev);
20251 +       if (!in_dev)
20252 +               goto out;
20253 +
20254 +       for (ifap = &in_dev->addr_list; (ifa = *ifap) != NULL;
20255 +               ifap = &ifa->if_next) {
20256 +               if (v6_addr_in_nx_info(nxi, &ifa->addr, -1)) {
20257 +                       ret = 1;
20258 +                       break;
20259 +               }
20260 +       }
20261 +       in6_dev_put(in_dev);
20262 +out:
20263 +       return ret;
20264 +}
20265 +
20266 +#endif
20267 +
20268 +int dev_in_nx_info(struct net_device *dev, struct nx_info *nxi)
20269 +{
20270 +       int ret = 1;
20271 +
20272 +       if (!nxi)
20273 +               goto out;
20274 +       if (nxi->v4.type && v4_dev_in_nx_info(dev, nxi))
20275 +               goto out;
20276 +#ifdef CONFIG_IPV6
20277 +       ret = 2;
20278 +       if (nxi->v6.type && v6_dev_in_nx_info(dev, nxi))
20279 +               goto out;
20280 +#endif
20281 +       ret = 0;
20282 +out:
20283 +       vxdprintk(VXD_CBIT(net, 3),
20284 +               "dev_in_nx_info(%p,%p[#%d]) = %d",
20285 +               dev, nxi, nxi ? nxi->nx_id : 0, ret);
20286 +       return ret;
20287 +}
20288 +
20289 +int ip_v4_find_src(struct net *net, struct nx_info *nxi,
20290 +       struct rtable **rp, struct flowi *fl)
20291 +{
20292 +       if (!nxi)
20293 +               return 0;
20294 +
20295 +       /* FIXME: handle lback only case */
20296 +       if (!NX_IPV4(nxi))
20297 +               return -EPERM;
20298 +
20299 +       vxdprintk(VXD_CBIT(net, 4),
20300 +               "ip_v4_find_src(%p[#%u]) " NIPQUAD_FMT " -> " NIPQUAD_FMT,
20301 +               nxi, nxi ? nxi->nx_id : 0,
20302 +               NIPQUAD(fl->fl4_src), NIPQUAD(fl->fl4_dst));
20303 +
20304 +       /* single IP is unconditional */
20305 +       if (nx_info_flags(nxi, NXF_SINGLE_IP, 0) &&
20306 +               (fl->fl4_src == INADDR_ANY))
20307 +               fl->fl4_src = nxi->v4.ip[0].s_addr;
20308 +
20309 +       if (fl->fl4_src == INADDR_ANY) {
20310 +               struct nx_addr_v4 *ptr;
20311 +               __be32 found = 0;
20312 +               int err;
20313 +
20314 +               err = __ip_route_output_key(net, rp, fl);
20315 +               if (!err) {
20316 +                       found = (*rp)->rt_src;
20317 +                       ip_rt_put(*rp);
20318 +                       vxdprintk(VXD_CBIT(net, 4),
20319 +                               "ip_v4_find_src(%p[#%u]) rok[%u]: " NIPQUAD_FMT,
20320 +                               nxi, nxi ? nxi->nx_id : 0, fl->oif, NIPQUAD(found));
20321 +                       if (v4_addr_in_nx_info(nxi, found, NXA_MASK_BIND))
20322 +                               goto found;
20323 +               }
20324 +
20325 +               for (ptr = &nxi->v4; ptr; ptr = ptr->next) {
20326 +                       __be32 primary = ptr->ip[0].s_addr;
20327 +                       __be32 mask = ptr->mask.s_addr;
20328 +                       __be32 neta = primary & mask;
20329 +
20330 +                       vxdprintk(VXD_CBIT(net, 4), "ip_v4_find_src(%p[#%u]) chk: "
20331 +                               NIPQUAD_FMT "/" NIPQUAD_FMT "/" NIPQUAD_FMT,
20332 +                               nxi, nxi ? nxi->nx_id : 0, NIPQUAD(primary),
20333 +                               NIPQUAD(mask), NIPQUAD(neta));
20334 +                       if ((found & mask) != neta)
20335 +                               continue;
20336 +
20337 +                       fl->fl4_src = primary;
20338 +                       err = __ip_route_output_key(net, rp, fl);
20339 +                       vxdprintk(VXD_CBIT(net, 4),
20340 +                               "ip_v4_find_src(%p[#%u]) rok[%u]: " NIPQUAD_FMT,
20341 +                               nxi, nxi ? nxi->nx_id : 0, fl->oif, NIPQUAD(primary));
20342 +                       if (!err) {
20343 +                               found = (*rp)->rt_src;
20344 +                               ip_rt_put(*rp);
20345 +                               if (found == primary)
20346 +                                       goto found;
20347 +                       }
20348 +               }
20349 +               /* still no source ip? */
20350 +               found = ipv4_is_loopback(fl->fl4_dst)
20351 +                       ? IPI_LOOPBACK : nxi->v4.ip[0].s_addr;
20352 +       found:
20353 +               /* assign src ip to flow */
20354 +               fl->fl4_src = found;
20355 +
20356 +       } else {
20357 +               if (!v4_addr_in_nx_info(nxi, fl->fl4_src, NXA_MASK_BIND))
20358 +                       return -EPERM;
20359 +       }
20360 +
20361 +       if (nx_info_flags(nxi, NXF_LBACK_REMAP, 0)) {
20362 +               if (ipv4_is_loopback(fl->fl4_dst))
20363 +                       fl->fl4_dst = nxi->v4_lback.s_addr;
20364 +               if (ipv4_is_loopback(fl->fl4_src))
20365 +                       fl->fl4_src = nxi->v4_lback.s_addr;
20366 +       } else if (ipv4_is_loopback(fl->fl4_dst) &&
20367 +               !nx_info_flags(nxi, NXF_LBACK_ALLOW, 0))
20368 +               return -EPERM;
20369 +
20370 +       return 0;
20371 +}
20372 +
20373 +EXPORT_SYMBOL_GPL(ip_v4_find_src);
20374 +
20375 diff -NurpP --minimal linux-2.6.29.1/kernel/vserver/init.c linux-2.6.29.1-vs2.3.0.36.9-pre5/kernel/vserver/init.c
20376 --- linux-2.6.29.1/kernel/vserver/init.c        1970-01-01 01:00:00.000000000 +0100
20377 +++ linux-2.6.29.1-vs2.3.0.36.9-pre5/kernel/vserver/init.c      2009-02-22 22:54:26.000000000 +0100
20378 @@ -0,0 +1,45 @@
20379 +/*
20380 + *  linux/kernel/init.c
20381 + *
20382 + *  Virtual Server Init
20383 + *
20384 + *  Copyright (C) 2004-2007  Herbert Pötzl
20385 + *
20386 + *  V0.01  basic structure
20387 + *
20388 + */
20389 +
20390 +#include <linux/init.h>
20391 +
20392 +int    vserver_register_sysctl(void);
20393 +void   vserver_unregister_sysctl(void);
20394 +
20395 +
20396 +static int __init init_vserver(void)
20397 +{
20398 +       int ret = 0;
20399 +
20400 +#ifdef CONFIG_VSERVER_DEBUG
20401 +       vserver_register_sysctl();
20402 +#endif
20403 +       return ret;
20404 +}
20405 +
20406 +
20407 +static void __exit exit_vserver(void)
20408 +{
20409 +
20410 +#ifdef CONFIG_VSERVER_DEBUG
20411 +       vserver_unregister_sysctl();
20412 +#endif
20413 +       return;
20414 +}
20415 +
20416 +/* FIXME: GFP_ZONETYPES gone
20417 +long vx_slab[GFP_ZONETYPES]; */
20418 +long vx_area;
20419 +
20420 +
20421 +module_init(init_vserver);
20422 +module_exit(exit_vserver);
20423 +
20424 diff -NurpP --minimal linux-2.6.29.1/kernel/vserver/inode.c linux-2.6.29.1-vs2.3.0.36.9-pre5/kernel/vserver/inode.c
20425 --- linux-2.6.29.1/kernel/vserver/inode.c       1970-01-01 01:00:00.000000000 +0100
20426 +++ linux-2.6.29.1-vs2.3.0.36.9-pre5/kernel/vserver/inode.c     2009-02-22 22:54:26.000000000 +0100
20427 @@ -0,0 +1,422 @@
20428 +/*
20429 + *  linux/kernel/vserver/inode.c
20430 + *
20431 + *  Virtual Server: File System Support
20432 + *
20433 + *  Copyright (C) 2004-2007  Herbert Pötzl
20434 + *
20435 + *  V0.01  separated from vcontext V0.05
20436 + *  V0.02  moved to tag (instead of xid)
20437 + *
20438 + */
20439 +
20440 +#include <linux/tty.h>
20441 +#include <linux/proc_fs.h>
20442 +#include <linux/devpts_fs.h>
20443 +#include <linux/fs.h>
20444 +#include <linux/file.h>
20445 +#include <linux/mount.h>
20446 +#include <linux/parser.h>
20447 +#include <linux/namei.h>
20448 +#include <linux/vserver/inode.h>
20449 +#include <linux/vserver/inode_cmd.h>
20450 +#include <linux/vs_base.h>
20451 +#include <linux/vs_tag.h>
20452 +
20453 +#include <asm/uaccess.h>
20454 +
20455 +
20456 +static int __vc_get_iattr(struct inode *in, uint32_t *tag, uint32_t *flags, uint32_t *mask)
20457 +{
20458 +       struct proc_dir_entry *entry;
20459 +
20460 +       if (!in || !in->i_sb)
20461 +               return -ESRCH;
20462 +
20463 +       *flags = IATTR_TAG
20464 +               | (IS_BARRIER(in) ? IATTR_BARRIER : 0)
20465 +               | (IS_IXUNLINK(in) ? IATTR_IXUNLINK : 0)
20466 +               | (IS_IMMUTABLE(in) ? IATTR_IMMUTABLE : 0);
20467 +       *mask = IATTR_IXUNLINK | IATTR_IMMUTABLE;
20468 +
20469 +       if (S_ISDIR(in->i_mode))
20470 +               *mask |= IATTR_BARRIER;
20471 +
20472 +       if (IS_TAGGED(in)) {
20473 +               *tag = in->i_tag;
20474 +               *mask |= IATTR_TAG;
20475 +       }
20476 +
20477 +       switch (in->i_sb->s_magic) {
20478 +       case PROC_SUPER_MAGIC:
20479 +               entry = PROC_I(in)->pde;
20480 +
20481 +               /* check for specific inodes? */
20482 +               if (entry)
20483 +                       *mask |= IATTR_FLAGS;
20484 +               if (entry)
20485 +                       *flags |= (entry->vx_flags & IATTR_FLAGS);
20486 +               else
20487 +                       *flags |= (PROC_I(in)->vx_flags & IATTR_FLAGS);
20488 +               break;
20489 +
20490 +       case DEVPTS_SUPER_MAGIC:
20491 +               *tag = in->i_tag;
20492 +               *mask |= IATTR_TAG;
20493 +               break;
20494 +
20495 +       default:
20496 +               break;
20497 +       }
20498 +       return 0;
20499 +}
20500 +
20501 +int vc_get_iattr(void __user *data)
20502 +{
20503 +       struct path path;
20504 +       struct vcmd_ctx_iattr_v1 vc_data = { .tag = -1 };
20505 +       int ret;
20506 +
20507 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
20508 +               return -EFAULT;
20509 +
20510 +       ret = user_lpath(vc_data.name, &path);
20511 +       if (!ret) {
20512 +               ret = __vc_get_iattr(path.dentry->d_inode,
20513 +                       &vc_data.tag, &vc_data.flags, &vc_data.mask);
20514 +               path_put(&path);
20515 +       }
20516 +       if (ret)
20517 +               return ret;
20518 +
20519 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
20520 +               ret = -EFAULT;
20521 +       return ret;
20522 +}
20523 +
20524 +#ifdef CONFIG_COMPAT
20525 +
20526 +int vc_get_iattr_x32(void __user *data)
20527 +{
20528 +       struct path path;
20529 +       struct vcmd_ctx_iattr_v1_x32 vc_data = { .tag = -1 };
20530 +       int ret;
20531 +
20532 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
20533 +               return -EFAULT;
20534 +
20535 +       ret = user_lpath(compat_ptr(vc_data.name_ptr), &path);
20536 +       if (!ret) {
20537 +               ret = __vc_get_iattr(path.dentry->d_inode,
20538 +                       &vc_data.tag, &vc_data.flags, &vc_data.mask);
20539 +               path_put(&path);
20540 +       }
20541 +       if (ret)
20542 +               return ret;
20543 +
20544 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
20545 +               ret = -EFAULT;
20546 +       return ret;
20547 +}
20548 +
20549 +#endif /* CONFIG_COMPAT */
20550 +
20551 +
20552 +int vc_fget_iattr(uint32_t fd, void __user *data)
20553 +{
20554 +       struct file *filp;
20555 +       struct vcmd_ctx_fiattr_v0 vc_data = { .tag = -1 };
20556 +       int ret;
20557 +
20558 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
20559 +               return -EFAULT;
20560 +
20561 +       filp = fget(fd);
20562 +       if (!filp || !filp->f_dentry || !filp->f_dentry->d_inode)
20563 +               return -EBADF;
20564 +
20565 +       ret = __vc_get_iattr(filp->f_dentry->d_inode,
20566 +               &vc_data.tag, &vc_data.flags, &vc_data.mask);
20567 +
20568 +       fput(filp);
20569 +
20570 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
20571 +               ret = -EFAULT;
20572 +       return ret;
20573 +}
20574 +
20575 +
20576 +static int __vc_set_iattr(struct dentry *de, uint32_t *tag, uint32_t *flags, uint32_t *mask)
20577 +{
20578 +       struct inode *in = de->d_inode;
20579 +       int error = 0, is_proc = 0, has_tag = 0;
20580 +       struct iattr attr = { 0 };
20581 +
20582 +       if (!in || !in->i_sb)
20583 +               return -ESRCH;
20584 +
20585 +       is_proc = (in->i_sb->s_magic == PROC_SUPER_MAGIC);
20586 +       if ((*mask & IATTR_FLAGS) && !is_proc)
20587 +               return -EINVAL;
20588 +
20589 +       has_tag = IS_TAGGED(in) ||
20590 +               (in->i_sb->s_magic == DEVPTS_SUPER_MAGIC);
20591 +       if ((*mask & IATTR_TAG) && !has_tag)
20592 +               return -EINVAL;
20593 +
20594 +       mutex_lock(&in->i_mutex);
20595 +       if (*mask & IATTR_TAG) {
20596 +               attr.ia_tag = *tag;
20597 +               attr.ia_valid |= ATTR_TAG;
20598 +       }
20599 +
20600 +       if (*mask & IATTR_FLAGS) {
20601 +               struct proc_dir_entry *entry = PROC_I(in)->pde;
20602 +               unsigned int iflags = PROC_I(in)->vx_flags;
20603 +
20604 +               iflags = (iflags & ~(*mask & IATTR_FLAGS))
20605 +                       | (*flags & IATTR_FLAGS);
20606 +               PROC_I(in)->vx_flags = iflags;
20607 +               if (entry)
20608 +                       entry->vx_flags = iflags;
20609 +       }
20610 +
20611 +       if (*mask & (IATTR_BARRIER | IATTR_IXUNLINK | IATTR_IMMUTABLE)) {
20612 +               if (*mask & IATTR_IMMUTABLE) {
20613 +                       if (*flags & IATTR_IMMUTABLE)
20614 +                               in->i_flags |= S_IMMUTABLE;
20615 +                       else
20616 +                               in->i_flags &= ~S_IMMUTABLE;
20617 +               }
20618 +               if (*mask & IATTR_IXUNLINK) {
20619 +                       if (*flags & IATTR_IXUNLINK)
20620 +                               in->i_flags |= S_IXUNLINK;
20621 +                       else
20622 +                               in->i_flags &= ~S_IXUNLINK;
20623 +               }
20624 +               if (S_ISDIR(in->i_mode) && (*mask & IATTR_BARRIER)) {
20625 +                       if (*flags & IATTR_BARRIER)
20626 +                               in->i_vflags |= V_BARRIER;
20627 +                       else
20628 +                               in->i_vflags &= ~V_BARRIER;
20629 +               }
20630 +               if (in->i_op && in->i_op->sync_flags) {
20631 +                       error = in->i_op->sync_flags(in);
20632 +                       if (error)
20633 +                               goto out;
20634 +               }
20635 +       }
20636 +
20637 +       if (attr.ia_valid) {
20638 +               if (in->i_op && in->i_op->setattr)
20639 +                       error = in->i_op->setattr(de, &attr);
20640 +               else {
20641 +                       error = inode_change_ok(in, &attr);
20642 +                       if (!error)
20643 +                               error = inode_setattr(in, &attr);
20644 +               }
20645 +       }
20646 +
20647 +out:
20648 +       mutex_unlock(&in->i_mutex);
20649 +       return error;
20650 +}
20651 +
20652 +int vc_set_iattr(void __user *data)
20653 +{
20654 +       struct path path;
20655 +       struct vcmd_ctx_iattr_v1 vc_data;
20656 +       int ret;
20657 +
20658 +       if (!capable(CAP_LINUX_IMMUTABLE))
20659 +               return -EPERM;
20660 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
20661 +               return -EFAULT;
20662 +
20663 +       ret = user_lpath(vc_data.name, &path);
20664 +       if (!ret) {
20665 +               ret = __vc_set_iattr(path.dentry,
20666 +                       &vc_data.tag, &vc_data.flags, &vc_data.mask);
20667 +               path_put(&path);
20668 +       }
20669 +
20670 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
20671 +               ret = -EFAULT;
20672 +       return ret;
20673 +}
20674 +
20675 +#ifdef CONFIG_COMPAT
20676 +
20677 +int vc_set_iattr_x32(void __user *data)
20678 +{
20679 +       struct path path;
20680 +       struct vcmd_ctx_iattr_v1_x32 vc_data;
20681 +       int ret;
20682 +
20683 +       if (!capable(CAP_LINUX_IMMUTABLE))
20684 +               return -EPERM;
20685 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
20686 +               return -EFAULT;
20687 +
20688 +       ret = user_lpath(compat_ptr(vc_data.name_ptr), &path);
20689 +       if (!ret) {
20690 +               ret = __vc_set_iattr(path.dentry,
20691 +                       &vc_data.tag, &vc_data.flags, &vc_data.mask);
20692 +               path_put(&path);
20693 +       }
20694 +
20695 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
20696 +               ret = -EFAULT;
20697 +       return ret;
20698 +}
20699 +
20700 +#endif /* CONFIG_COMPAT */
20701 +
20702 +int vc_fset_iattr(uint32_t fd, void __user *data)
20703 +{
20704 +       struct file *filp;
20705 +       struct vcmd_ctx_fiattr_v0 vc_data;
20706 +       int ret;
20707 +
20708 +       if (!capable(CAP_LINUX_IMMUTABLE))
20709 +               return -EPERM;
20710 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
20711 +               return -EFAULT;
20712 +
20713 +       filp = fget(fd);
20714 +       if (!filp || !filp->f_dentry || !filp->f_dentry->d_inode)
20715 +               return -EBADF;
20716 +
20717 +       ret = __vc_set_iattr(filp->f_dentry, &vc_data.tag,
20718 +               &vc_data.flags, &vc_data.mask);
20719 +
20720 +       fput(filp);
20721 +
20722 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
20723 +               return -EFAULT;
20724 +       return ret;
20725 +}
20726 +
20727 +
20728 +enum { Opt_notagcheck, Opt_tag, Opt_notag, Opt_tagid, Opt_err };
20729 +
20730 +static match_table_t tokens = {
20731 +       {Opt_notagcheck, "notagcheck"},
20732 +#ifdef CONFIG_PROPAGATE
20733 +       {Opt_notag, "notag"},
20734 +       {Opt_tag, "tag"},
20735 +       {Opt_tagid, "tagid=%u"},
20736 +#endif
20737 +       {Opt_err, NULL}
20738 +};
20739 +
20740 +
20741 +static void __dx_parse_remove(char *string, char *opt)
20742 +{
20743 +       char *p = strstr(string, opt);
20744 +       char *q = p;
20745 +
20746 +       if (p) {
20747 +               while (*q != '\0' && *q != ',')
20748 +                       q++;
20749 +               while (*q)
20750 +                       *p++ = *q++;
20751 +               while (*p)
20752 +                       *p++ = '\0';
20753 +       }
20754 +}
20755 +
20756 +int dx_parse_tag(char *string, tag_t *tag, int remove, int *mnt_flags,
20757 +                unsigned long *flags)
20758 +{
20759 +       int set = 0;
20760 +       substring_t args[MAX_OPT_ARGS];
20761 +       int token, option = 0;
20762 +       char *s, *p, *opts;
20763 +
20764 +       if (!string)
20765 +               return 0;
20766 +       s = kstrdup(string, GFP_KERNEL | GFP_ATOMIC);
20767 +       if (!s)
20768 +               return 0;
20769 +
20770 +       opts = s;
20771 +       while ((p = strsep(&opts, ",")) != NULL) {
20772 +               token = match_token(p, tokens, args);
20773 +
20774 +               vxdprintk(VXD_CBIT(tag, 7),
20775 +                       "dx_parse_tag(»%s«): %d:#%d",
20776 +                       p, token, option);
20777 +
20778 +               switch (token) {
20779 +#ifdef CONFIG_PROPAGATE
20780 +               case Opt_tag:
20781 +                       if (tag)
20782 +                               *tag = 0;
20783 +                       if (remove)
20784 +                               __dx_parse_remove(s, "tag");
20785 +                       *mnt_flags |= MNT_TAGID;
20786 +                       set |= MNT_TAGID;
20787 +                       break;
20788 +               case Opt_notag:
20789 +                       if (remove)
20790 +                               __dx_parse_remove(s, "notag");
20791 +                       *mnt_flags |= MNT_NOTAG;
20792 +                       set |= MNT_NOTAG;
20793 +                       break;
20794 +               case Opt_tagid:
20795 +                       if (tag && !match_int(args, &option))
20796 +                               *tag = option;
20797 +                       if (remove)
20798 +                               __dx_parse_remove(s, "tagid");
20799 +                       *mnt_flags |= MNT_TAGID;
20800 +                       set |= MNT_TAGID;
20801 +                       break;
20802 +#endif
20803 +               case Opt_notagcheck:
20804 +                       if (remove)
20805 +                               __dx_parse_remove(s, "notagcheck");
20806 +                       *flags |= MS_NOTAGCHECK;
20807 +                       set |= MS_NOTAGCHECK;
20808 +                       break;
20809 +               }
20810 +       }
20811 +       if (set)
20812 +               strcpy(string, s);
20813 +       kfree(s);
20814 +       return set;
20815 +}
20816 +
20817 +#ifdef CONFIG_PROPAGATE
20818 +
20819 +void __dx_propagate_tag(struct nameidata *nd, struct inode *inode)
20820 +{
20821 +       tag_t new_tag = 0;
20822 +       struct vfsmount *mnt;
20823 +       int propagate;
20824 +
20825 +       if (!nd)
20826 +               return;
20827 +       mnt = nd->path.mnt;
20828 +       if (!mnt)
20829 +               return;
20830 +
20831 +       propagate = (mnt->mnt_flags & MNT_TAGID);
20832 +       if (propagate)
20833 +               new_tag = mnt->mnt_tag;
20834 +
20835 +       vxdprintk(VXD_CBIT(tag, 7),
20836 +               "dx_propagate_tag(%p[#%lu.%d]): %d,%d",
20837 +               inode, inode->i_ino, inode->i_tag,
20838 +               new_tag, (propagate) ? 1 : 0);
20839 +
20840 +       if (propagate)
20841 +               inode->i_tag = new_tag;
20842 +}
20843 +
20844 +#include <linux/module.h>
20845 +
20846 +EXPORT_SYMBOL_GPL(__dx_propagate_tag);
20847 +
20848 +#endif /* CONFIG_PROPAGATE */
20849 +
20850 diff -NurpP --minimal linux-2.6.29.1/kernel/vserver/Kconfig linux-2.6.29.1-vs2.3.0.36.9-pre5/kernel/vserver/Kconfig
20851 --- linux-2.6.29.1/kernel/vserver/Kconfig       1970-01-01 01:00:00.000000000 +0100
20852 +++ linux-2.6.29.1-vs2.3.0.36.9-pre5/kernel/vserver/Kconfig     2009-02-22 22:54:26.000000000 +0100
20853 @@ -0,0 +1,251 @@
20854 +#
20855 +# Linux VServer configuration
20856 +#
20857 +
20858 +menu "Linux VServer"
20859 +
20860 +config VSERVER_AUTO_LBACK
20861 +       bool    "Automatically Assign Loopback IP"
20862 +       default y
20863 +       help
20864 +         Automatically assign a guest specific loopback
20865 +         IP and add it to the kernel network stack on
20866 +         startup.
20867 +
20868 +config VSERVER_AUTO_SINGLE
20869 +       bool    "Automatic Single IP Special Casing"
20870 +       depends on EXPERIMENTAL
20871 +       default y
20872 +       help
20873 +         This allows network contexts with a single IP to
20874 +         automatically remap 0.0.0.0 bindings to that IP,
20875 +         avoiding further network checks and improving
20876 +         performance.
20877 +
20878 +         (note: such guests do not allow to change the ip
20879 +          on the fly and do not show loopback addresses)
20880 +
20881 +config VSERVER_COWBL
20882 +       bool    "Enable COW Immutable Link Breaking"
20883 +       default y
20884 +       help
20885 +         This enables the COW (Copy-On-Write) link break code.
20886 +         It allows you to treat unified files like normal files
20887 +         when writing to them (which will implicitely break the
20888 +         link and create a copy of the unified file)
20889 +
20890 +config VSERVER_VTIME
20891 +       bool    "Enable Virtualized Guest Time"
20892 +       depends on EXPERIMENTAL
20893 +       default n
20894 +       help
20895 +         This enables per guest time offsets to allow for
20896 +         adjusting the system clock individually per guest.
20897 +         this adds some overhead to the time functions and
20898 +         therefore should not be enabled without good reason.
20899 +
20900 +config VSERVER_DEVICE
20901 +       bool    "Enable Guest Device Mapping"
20902 +       depends on EXPERIMENTAL
20903 +       default n
20904 +       help
20905 +         This enables generic device remapping.
20906 +
20907 +config VSERVER_PROC_SECURE
20908 +       bool    "Enable Proc Security"
20909 +       depends on PROC_FS
20910 +       default y
20911 +       help
20912 +         This configures ProcFS security to initially hide
20913 +         non-process entries for all contexts except the main and
20914 +         spectator context (i.e. for all guests), which is a secure
20915 +         default.
20916 +
20917 +         (note: on 1.2x the entries were visible by default)
20918 +
20919 +config VSERVER_HARDCPU
20920 +       bool    "Enable Hard CPU Limits"
20921 +       default y
20922 +       help
20923 +         Activate the Hard CPU Limits
20924 +
20925 +         This will compile in code that allows the Token Bucket
20926 +         Scheduler to put processes on hold when a context's
20927 +         tokens are depleted (provided that its per-context
20928 +         sched_hard flag is set).
20929 +
20930 +         Processes belonging to that context will not be able
20931 +         to consume CPU resources again until a per-context
20932 +         configured minimum of tokens has been reached.
20933 +
20934 +config VSERVER_IDLETIME
20935 +       bool    "Avoid idle CPUs by skipping Time"
20936 +       depends on VSERVER_HARDCPU
20937 +       default y
20938 +       help
20939 +         This option allows the scheduler to artificially
20940 +         advance time (per cpu) when otherwise the idle
20941 +         task would be scheduled, thus keeping the cpu
20942 +         busy and sharing the available resources among
20943 +         certain contexts.
20944 +
20945 +config VSERVER_IDLELIMIT
20946 +       bool    "Limit the IDLE task"
20947 +       depends on VSERVER_HARDCPU
20948 +       default n
20949 +       help
20950 +         Limit the idle slices, so the the next context
20951 +         will be scheduled as soon as possible.
20952 +
20953 +         This might improve interactivity and latency, but
20954 +         will also marginally increase scheduling overhead.
20955 +
20956 +choice
20957 +       prompt  "Persistent Inode Tagging"
20958 +       default TAGGING_ID24
20959 +       help
20960 +         This adds persistent context information to filesystems
20961 +         mounted with the tagxid option. Tagging is a requirement
20962 +         for per-context disk limits and per-context quota.
20963 +
20964 +
20965 +config TAGGING_NONE
20966 +       bool    "Disabled"
20967 +       help
20968 +         do not store per-context information in inodes.
20969 +
20970 +config TAGGING_UID16
20971 +       bool    "UID16/GID32"
20972 +       help
20973 +         reduces UID to 16 bit, but leaves GID at 32 bit.
20974 +
20975 +config TAGGING_GID16
20976 +       bool    "UID32/GID16"
20977 +       help
20978 +         reduces GID to 16 bit, but leaves UID at 32 bit.
20979 +
20980 +config TAGGING_ID24
20981 +       bool    "UID24/GID24"
20982 +       help
20983 +         uses the upper 8bit from UID and GID for XID tagging
20984 +         which leaves 24bit for UID/GID each, which should be
20985 +         more than sufficient for normal use.
20986 +
20987 +config TAGGING_INTERN
20988 +       bool    "UID32/GID32"
20989 +       help
20990 +         this uses otherwise reserved inode fields in the on
20991 +         disk representation, which limits the use to a few
20992 +         filesystems (currently ext2 and ext3)
20993 +
20994 +endchoice
20995 +
20996 +config TAG_NFSD
20997 +       bool    "Tag NFSD User Auth and Files"
20998 +       default n
20999 +       help
21000 +         Enable this if you do want the in-kernel NFS
21001 +         Server to use the tagging specified above.
21002 +         (will require patched clients too)
21003 +
21004 +config VSERVER_PRIVACY
21005 +       bool    "Honor Privacy Aspects of Guests"
21006 +       default n
21007 +       help
21008 +         When enabled, most context checks will disallow
21009 +         access to structures assigned to a specific context,
21010 +         like ptys or loop devices.
21011 +
21012 +config VSERVER_CONTEXTS
21013 +       int     "Maximum number of Contexts (1-65533)"  if EMBEDDED
21014 +       range 1 65533
21015 +       default "768"   if 64BIT
21016 +       default "256"
21017 +       help
21018 +         This setting will optimize certain data structures
21019 +         and memory allocations according to the expected
21020 +         maximum.
21021 +
21022 +         note: this is not a strict upper limit.
21023 +
21024 +config VSERVER_WARN
21025 +       bool    "VServer Warnings"
21026 +       default y
21027 +       help
21028 +         This enables various runtime warnings, which will
21029 +         notify about potential manipulation attempts or
21030 +         resource shortage. It is generally considered to
21031 +         be a good idea to have that enabled.
21032 +
21033 +config VSERVER_DEBUG
21034 +       bool    "VServer Debugging Code"
21035 +       default n
21036 +       help
21037 +         Set this to yes if you want to be able to activate
21038 +         debugging output at runtime. It adds a very small
21039 +         overhead to all vserver related functions and
21040 +         increases the kernel size by about 20k.
21041 +
21042 +config VSERVER_HISTORY
21043 +       bool    "VServer History Tracing"
21044 +       depends on VSERVER_DEBUG
21045 +       default n
21046 +       help
21047 +         Set this to yes if you want to record the history of
21048 +         linux-vserver activities, so they can be replayed in
21049 +         the event of a kernel panic or oops.
21050 +
21051 +config VSERVER_HISTORY_SIZE
21052 +       int     "Per-CPU History Size (32-65536)"
21053 +       depends on VSERVER_HISTORY
21054 +       range 32 65536
21055 +       default 64
21056 +       help
21057 +         This allows you to specify the number of entries in
21058 +         the per-CPU history buffer.
21059 +
21060 +config VSERVER_MONITOR
21061 +       bool    "VServer Scheduling Monitor"
21062 +       depends on VSERVER_DISABLED
21063 +       default n
21064 +       help
21065 +         Set this to yes if you want to record the scheduling
21066 +         decisions, so that they can be relayed to userspace
21067 +         for detailed analysis.
21068 +
21069 +config VSERVER_MONITOR_SIZE
21070 +       int     "Per-CPU Monitor Queue Size (32-65536)"
21071 +       depends on VSERVER_MONITOR
21072 +       range 32 65536
21073 +       default 1024
21074 +       help
21075 +         This allows you to specify the number of entries in
21076 +         the per-CPU scheduling monitor buffer.
21077 +
21078 +config VSERVER_MONITOR_SYNC
21079 +       int     "Per-CPU Monitor Sync Interval (0-65536)"
21080 +       depends on VSERVER_MONITOR
21081 +       range 0 65536
21082 +       default 256
21083 +       help
21084 +         This allows you to specify the interval in ticks
21085 +         when a time sync entry is inserted.
21086 +
21087 +endmenu
21088 +
21089 +
21090 +config VSERVER
21091 +       bool
21092 +       default y
21093 +       select NAMESPACES
21094 +       select UTS_NS
21095 +       select IPC_NS
21096 +       select USER_NS
21097 +       select SYSVIPC
21098 +
21099 +config VSERVER_SECURITY
21100 +       bool
21101 +       depends on SECURITY
21102 +       default y
21103 +       select SECURITY_CAPABILITIES
21104 +
21105 diff -NurpP --minimal linux-2.6.29.1/kernel/vserver/limit.c linux-2.6.29.1-vs2.3.0.36.9-pre5/kernel/vserver/limit.c
21106 --- linux-2.6.29.1/kernel/vserver/limit.c       1970-01-01 01:00:00.000000000 +0100
21107 +++ linux-2.6.29.1-vs2.3.0.36.9-pre5/kernel/vserver/limit.c     2009-02-22 22:54:26.000000000 +0100
21108 @@ -0,0 +1,319 @@
21109 +/*
21110 + *  linux/kernel/vserver/limit.c
21111 + *
21112 + *  Virtual Server: Context Limits
21113 + *
21114 + *  Copyright (C) 2004-2007  Herbert Pötzl
21115 + *
21116 + *  V0.01  broken out from vcontext V0.05
21117 + *  V0.02  changed vcmds to vxi arg
21118 + *
21119 + */
21120 +
21121 +#include <linux/sched.h>
21122 +#include <linux/module.h>
21123 +#include <linux/vs_limit.h>
21124 +#include <linux/vserver/limit.h>
21125 +#include <linux/vserver/limit_cmd.h>
21126 +
21127 +#include <asm/uaccess.h>
21128 +
21129 +
21130 +const char *vlimit_name[NUM_LIMITS] = {
21131 +       [RLIMIT_CPU]            = "CPU",
21132 +       [RLIMIT_RSS]            = "RSS",
21133 +       [RLIMIT_NPROC]          = "NPROC",
21134 +       [RLIMIT_NOFILE]         = "NOFILE",
21135 +       [RLIMIT_MEMLOCK]        = "VML",
21136 +       [RLIMIT_AS]             = "VM",
21137 +       [RLIMIT_LOCKS]          = "LOCKS",
21138 +       [RLIMIT_SIGPENDING]     = "SIGP",
21139 +       [RLIMIT_MSGQUEUE]       = "MSGQ",
21140 +
21141 +       [VLIMIT_NSOCK]          = "NSOCK",
21142 +       [VLIMIT_OPENFD]         = "OPENFD",
21143 +       [VLIMIT_ANON]           = "ANON",
21144 +       [VLIMIT_SHMEM]          = "SHMEM",
21145 +       [VLIMIT_DENTRY]         = "DENTRY",
21146 +};
21147 +
21148 +EXPORT_SYMBOL_GPL(vlimit_name);
21149 +
21150 +#define MASK_ENTRY(x)  (1 << (x))
21151 +
21152 +const struct vcmd_ctx_rlimit_mask_v0 vlimit_mask = {
21153 +               /* minimum */
21154 +       0
21155 +       ,       /* softlimit */
21156 +       MASK_ENTRY( RLIMIT_RSS          ) |
21157 +       MASK_ENTRY( VLIMIT_ANON         ) |
21158 +       0
21159 +       ,       /* maximum */
21160 +       MASK_ENTRY( RLIMIT_RSS          ) |
21161 +       MASK_ENTRY( RLIMIT_NPROC        ) |
21162 +       MASK_ENTRY( RLIMIT_NOFILE       ) |
21163 +       MASK_ENTRY( RLIMIT_MEMLOCK      ) |
21164 +       MASK_ENTRY( RLIMIT_AS           ) |
21165 +       MASK_ENTRY( RLIMIT_LOCKS        ) |
21166 +       MASK_ENTRY( RLIMIT_MSGQUEUE     ) |
21167 +
21168 +       MASK_ENTRY( VLIMIT_NSOCK        ) |
21169 +       MASK_ENTRY( VLIMIT_OPENFD       ) |
21170 +       MASK_ENTRY( VLIMIT_ANON         ) |
21171 +       MASK_ENTRY( VLIMIT_SHMEM        ) |
21172 +       MASK_ENTRY( VLIMIT_DENTRY       ) |
21173 +       0
21174 +};
21175 +               /* accounting only */
21176 +uint32_t account_mask =
21177 +       MASK_ENTRY( VLIMIT_SEMARY       ) |
21178 +       MASK_ENTRY( VLIMIT_NSEMS        ) |
21179 +       MASK_ENTRY( VLIMIT_MAPPED       ) |
21180 +       0;
21181 +
21182 +
21183 +static int is_valid_vlimit(int id)
21184 +{
21185 +       uint32_t mask = vlimit_mask.minimum |
21186 +               vlimit_mask.softlimit | vlimit_mask.maximum;
21187 +       return mask & (1 << id);
21188 +}
21189 +
21190 +static int is_accounted_vlimit(int id)
21191 +{
21192 +       if (is_valid_vlimit(id))
21193 +               return 1;
21194 +       return account_mask & (1 << id);
21195 +}
21196 +
21197 +
21198 +static inline uint64_t vc_get_soft(struct vx_info *vxi, int id)
21199 +{
21200 +       rlim_t limit = __rlim_soft(&vxi->limit, id);
21201 +       return VX_VLIM(limit);
21202 +}
21203 +
21204 +static inline uint64_t vc_get_hard(struct vx_info *vxi, int id)
21205 +{
21206 +       rlim_t limit = __rlim_hard(&vxi->limit, id);
21207 +       return VX_VLIM(limit);
21208 +}
21209 +
21210 +static int do_get_rlimit(struct vx_info *vxi, uint32_t id,
21211 +       uint64_t *minimum, uint64_t *softlimit, uint64_t *maximum)
21212 +{
21213 +       if (!is_valid_vlimit(id))
21214 +               return -EINVAL;
21215 +
21216 +       if (minimum)
21217 +               *minimum = CRLIM_UNSET;
21218 +       if (softlimit)
21219 +               *softlimit = vc_get_soft(vxi, id);
21220 +       if (maximum)
21221 +               *maximum = vc_get_hard(vxi, id);
21222 +       return 0;
21223 +}
21224 +
21225 +int vc_get_rlimit(struct vx_info *vxi, void __user *data)
21226 +{
21227 +       struct vcmd_ctx_rlimit_v0 vc_data;
21228 +       int ret;
21229 +
21230 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
21231 +               return -EFAULT;
21232 +
21233 +       ret = do_get_rlimit(vxi, vc_data.id,
21234 +               &vc_data.minimum, &vc_data.softlimit, &vc_data.maximum);
21235 +       if (ret)
21236 +               return ret;
21237 +
21238 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
21239 +               return -EFAULT;
21240 +       return 0;
21241 +}
21242 +
21243 +static int do_set_rlimit(struct vx_info *vxi, uint32_t id,
21244 +       uint64_t minimum, uint64_t softlimit, uint64_t maximum)
21245 +{
21246 +       if (!is_valid_vlimit(id))
21247 +               return -EINVAL;
21248 +
21249 +       if (maximum != CRLIM_KEEP)
21250 +               __rlim_hard(&vxi->limit, id) = VX_RLIM(maximum);
21251 +       if (softlimit != CRLIM_KEEP)
21252 +               __rlim_soft(&vxi->limit, id) = VX_RLIM(softlimit);
21253 +
21254 +       /* clamp soft limit */
21255 +       if (__rlim_soft(&vxi->limit, id) > __rlim_hard(&vxi->limit, id))
21256 +               __rlim_soft(&vxi->limit, id) = __rlim_hard(&vxi->limit, id);
21257 +
21258 +       return 0;
21259 +}
21260 +
21261 +int vc_set_rlimit(struct vx_info *vxi, void __user *data)
21262 +{
21263 +       struct vcmd_ctx_rlimit_v0 vc_data;
21264 +
21265 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
21266 +               return -EFAULT;
21267 +
21268 +       return do_set_rlimit(vxi, vc_data.id,
21269 +               vc_data.minimum, vc_data.softlimit, vc_data.maximum);
21270 +}
21271 +
21272 +#ifdef CONFIG_IA32_EMULATION
21273 +
21274 +int vc_set_rlimit_x32(struct vx_info *vxi, void __user *data)
21275 +{
21276 +       struct vcmd_ctx_rlimit_v0_x32 vc_data;
21277 +
21278 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
21279 +               return -EFAULT;
21280 +
21281 +       return do_set_rlimit(vxi, vc_data.id,
21282 +               vc_data.minimum, vc_data.softlimit, vc_data.maximum);
21283 +}
21284 +
21285 +int vc_get_rlimit_x32(struct vx_info *vxi, void __user *data)
21286 +{
21287 +       struct vcmd_ctx_rlimit_v0_x32 vc_data;
21288 +       int ret;
21289 +
21290 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
21291 +               return -EFAULT;
21292 +
21293 +       ret = do_get_rlimit(vxi, vc_data.id,
21294 +               &vc_data.minimum, &vc_data.softlimit, &vc_data.maximum);
21295 +       if (ret)
21296 +               return ret;
21297 +
21298 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
21299 +               return -EFAULT;
21300 +       return 0;
21301 +}
21302 +
21303 +#endif /* CONFIG_IA32_EMULATION */
21304 +
21305 +
21306 +int vc_get_rlimit_mask(uint32_t id, void __user *data)
21307 +{
21308 +       if (copy_to_user(data, &vlimit_mask, sizeof(vlimit_mask)))
21309 +               return -EFAULT;
21310 +       return 0;
21311 +}
21312 +
21313 +
21314 +static inline void vx_reset_minmax(struct _vx_limit *limit)
21315 +{
21316 +       rlim_t value;
21317 +       int lim;
21318 +
21319 +       for (lim = 0; lim < NUM_LIMITS; lim++) {
21320 +               value = __rlim_get(limit, lim);
21321 +               __rlim_rmax(limit, lim) = value;
21322 +               __rlim_rmin(limit, lim) = value;
21323 +       }
21324 +}
21325 +
21326 +
21327 +int vc_reset_minmax(struct vx_info *vxi, void __user *data)
21328 +{
21329 +       vx_reset_minmax(&vxi->limit);
21330 +       return 0;
21331 +}
21332 +
21333 +
21334 +int vc_rlimit_stat(struct vx_info *vxi, void __user *data)
21335 +{
21336 +       struct vcmd_rlimit_stat_v0 vc_data;
21337 +       struct _vx_limit *limit = &vxi->limit;
21338 +       int id;
21339 +
21340 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
21341 +               return -EFAULT;
21342 +
21343 +       id = vc_data.id;
21344 +       if (!is_accounted_vlimit(id))
21345 +               return -EINVAL;
21346 +
21347 +       vx_limit_fixup(limit, id);
21348 +       vc_data.hits = atomic_read(&__rlim_lhit(limit, id));
21349 +       vc_data.value = __rlim_get(limit, id);
21350 +       vc_data.minimum = __rlim_rmin(limit, id);
21351 +       vc_data.maximum = __rlim_rmax(limit, id);
21352 +
21353 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
21354 +               return -EFAULT;
21355 +       return 0;
21356 +}
21357 +
21358 +
21359 +void vx_vsi_meminfo(struct sysinfo *val)
21360 +{
21361 +       struct vx_info *vxi = current->vx_info;
21362 +       unsigned long totalram, freeram;
21363 +       rlim_t v;
21364 +
21365 +       /* we blindly accept the max */
21366 +       v = __rlim_soft(&vxi->limit, RLIMIT_RSS);
21367 +       totalram = (v != RLIM_INFINITY) ? v : val->totalram;
21368 +
21369 +       /* total minus used equals free */
21370 +       v = __vx_cres_array_fixup(&vxi->limit, VLA_RSS);
21371 +       freeram = (v < totalram) ? totalram - v : 0;
21372 +
21373 +       val->totalram = totalram;
21374 +       val->freeram = freeram;
21375 +       val->bufferram = 0;
21376 +       val->totalhigh = 0;
21377 +       val->freehigh = 0;
21378 +       return;
21379 +}
21380 +
21381 +void vx_vsi_swapinfo(struct sysinfo *val)
21382 +{
21383 +       struct vx_info *vxi = current->vx_info;
21384 +       unsigned long totalswap, freeswap;
21385 +       rlim_t v, w;
21386 +
21387 +       v = __rlim_soft(&vxi->limit, RLIMIT_RSS);
21388 +       if (v == RLIM_INFINITY) {
21389 +               val->freeswap = val->totalswap;
21390 +               return;
21391 +       }
21392 +
21393 +       /* we blindly accept the max */
21394 +       w = __rlim_hard(&vxi->limit, RLIMIT_RSS);
21395 +       totalswap = (w != RLIM_INFINITY) ? (w - v) : val->totalswap;
21396 +
21397 +       /* currently 'used' swap */
21398 +       w = __vx_cres_array_fixup(&vxi->limit, VLA_RSS);
21399 +       w -= (w > v) ? v : w;
21400 +
21401 +       /* total minus used equals free */
21402 +       freeswap = (w < totalswap) ? totalswap - w : 0;
21403 +
21404 +       val->totalswap = totalswap;
21405 +       val->freeswap = freeswap;
21406 +       return;
21407 +}
21408 +
21409 +
21410 +unsigned long vx_badness(struct task_struct *task, struct mm_struct *mm)
21411 +{
21412 +       struct vx_info *vxi = mm->mm_vx_info;
21413 +       unsigned long points;
21414 +       rlim_t v, w;
21415 +
21416 +       if (!vxi)
21417 +               return 0;
21418 +
21419 +       points = vxi->vx_badness_bias;
21420 +
21421 +       v = __vx_cres_array_fixup(&vxi->limit, VLA_RSS);
21422 +       w = __rlim_soft(&vxi->limit, RLIMIT_RSS);
21423 +       points += (v > w) ? (v - w) : 0;
21424 +
21425 +       return points;
21426 +}
21427 +
21428 diff -NurpP --minimal linux-2.6.29.1/kernel/vserver/limit_init.h linux-2.6.29.1-vs2.3.0.36.9-pre5/kernel/vserver/limit_init.h
21429 --- linux-2.6.29.1/kernel/vserver/limit_init.h  1970-01-01 01:00:00.000000000 +0100
21430 +++ linux-2.6.29.1-vs2.3.0.36.9-pre5/kernel/vserver/limit_init.h        2009-02-22 22:54:26.000000000 +0100
21431 @@ -0,0 +1,31 @@
21432 +
21433 +
21434 +static inline void vx_info_init_limit(struct _vx_limit *limit)
21435 +{
21436 +       int lim;
21437 +
21438 +       for (lim = 0; lim < NUM_LIMITS; lim++) {
21439 +               __rlim_soft(limit, lim) = RLIM_INFINITY;
21440 +               __rlim_hard(limit, lim) = RLIM_INFINITY;
21441 +               __rlim_set(limit, lim, 0);
21442 +               atomic_set(&__rlim_lhit(limit, lim), 0);
21443 +               __rlim_rmin(limit, lim) = 0;
21444 +               __rlim_rmax(limit, lim) = 0;
21445 +       }
21446 +}
21447 +
21448 +static inline void vx_info_exit_limit(struct _vx_limit *limit)
21449 +{
21450 +       rlim_t value;
21451 +       int lim;
21452 +
21453 +       for (lim = 0; lim < NUM_LIMITS; lim++) {
21454 +               if ((1 << lim) & VLIM_NOCHECK)
21455 +                       continue;
21456 +               value = __rlim_get(limit, lim);
21457 +               vxwprintk_xid(value,
21458 +                       "!!! limit: %p[%s,%d] = %ld on exit.",
21459 +                       limit, vlimit_name[lim], lim, (long)value);
21460 +       }
21461 +}
21462 +
21463 diff -NurpP --minimal linux-2.6.29.1/kernel/vserver/limit_proc.h linux-2.6.29.1-vs2.3.0.36.9-pre5/kernel/vserver/limit_proc.h
21464 --- linux-2.6.29.1/kernel/vserver/limit_proc.h  1970-01-01 01:00:00.000000000 +0100
21465 +++ linux-2.6.29.1-vs2.3.0.36.9-pre5/kernel/vserver/limit_proc.h        2009-02-22 22:54:26.000000000 +0100
21466 @@ -0,0 +1,57 @@
21467 +#ifndef _VX_LIMIT_PROC_H
21468 +#define _VX_LIMIT_PROC_H
21469 +
21470 +#include <linux/vserver/limit_int.h>
21471 +
21472 +
21473 +#define VX_LIMIT_FMT   ":\t%8ld\t%8ld/%8ld\t%8lld/%8lld\t%6d\n"
21474 +#define VX_LIMIT_TOP   \
21475 +       "Limit\t current\t     min/max\t\t    soft/hard\t\thits\n"
21476 +
21477 +#define VX_LIMIT_ARG(r)                                \
21478 +       (unsigned long)__rlim_get(limit, r),    \
21479 +       (unsigned long)__rlim_rmin(limit, r),   \
21480 +       (unsigned long)__rlim_rmax(limit, r),   \
21481 +       VX_VLIM(__rlim_soft(limit, r)),         \
21482 +       VX_VLIM(__rlim_hard(limit, r)),         \
21483 +       atomic_read(&__rlim_lhit(limit, r))
21484 +
21485 +static inline int vx_info_proc_limit(struct _vx_limit *limit, char *buffer)
21486 +{
21487 +       vx_limit_fixup(limit, -1);
21488 +       return sprintf(buffer, VX_LIMIT_TOP
21489 +               "PROC"  VX_LIMIT_FMT
21490 +               "VM"    VX_LIMIT_FMT
21491 +               "VML"   VX_LIMIT_FMT
21492 +               "RSS"   VX_LIMIT_FMT
21493 +               "ANON"  VX_LIMIT_FMT
21494 +               "RMAP"  VX_LIMIT_FMT
21495 +               "FILES" VX_LIMIT_FMT
21496 +               "OFD"   VX_LIMIT_FMT
21497 +               "LOCKS" VX_LIMIT_FMT
21498 +               "SOCK"  VX_LIMIT_FMT
21499 +               "MSGQ"  VX_LIMIT_FMT
21500 +               "SHM"   VX_LIMIT_FMT
21501 +               "SEMA"  VX_LIMIT_FMT
21502 +               "SEMS"  VX_LIMIT_FMT
21503 +               "DENT"  VX_LIMIT_FMT,
21504 +               VX_LIMIT_ARG(RLIMIT_NPROC),
21505 +               VX_LIMIT_ARG(RLIMIT_AS),
21506 +               VX_LIMIT_ARG(RLIMIT_MEMLOCK),
21507 +               VX_LIMIT_ARG(RLIMIT_RSS),
21508 +               VX_LIMIT_ARG(VLIMIT_ANON),
21509 +               VX_LIMIT_ARG(VLIMIT_MAPPED),
21510 +               VX_LIMIT_ARG(RLIMIT_NOFILE),
21511 +               VX_LIMIT_ARG(VLIMIT_OPENFD),
21512 +               VX_LIMIT_ARG(RLIMIT_LOCKS),
21513 +               VX_LIMIT_ARG(VLIMIT_NSOCK),
21514 +               VX_LIMIT_ARG(RLIMIT_MSGQUEUE),
21515 +               VX_LIMIT_ARG(VLIMIT_SHMEM),
21516 +               VX_LIMIT_ARG(VLIMIT_SEMARY),
21517 +               VX_LIMIT_ARG(VLIMIT_NSEMS),
21518 +               VX_LIMIT_ARG(VLIMIT_DENTRY));
21519 +}
21520 +
21521 +#endif /* _VX_LIMIT_PROC_H */
21522 +
21523 +
21524 diff -NurpP --minimal linux-2.6.29.1/kernel/vserver/Makefile linux-2.6.29.1-vs2.3.0.36.9-pre5/kernel/vserver/Makefile
21525 --- linux-2.6.29.1/kernel/vserver/Makefile      1970-01-01 01:00:00.000000000 +0100
21526 +++ linux-2.6.29.1-vs2.3.0.36.9-pre5/kernel/vserver/Makefile    2009-02-22 22:54:26.000000000 +0100
21527 @@ -0,0 +1,18 @@
21528 +#
21529 +# Makefile for the Linux vserver routines.
21530 +#
21531 +
21532 +
21533 +obj-y          += vserver.o
21534 +
21535 +vserver-y      := switch.o context.o space.o sched.o network.o inode.o \
21536 +                  limit.o cvirt.o cacct.o signal.o helper.o init.o \
21537 +                  dlimit.o tag.o
21538 +
21539 +vserver-$(CONFIG_INET) += inet.o
21540 +vserver-$(CONFIG_PROC_FS) += proc.o
21541 +vserver-$(CONFIG_VSERVER_DEBUG) += sysctl.o debug.o
21542 +vserver-$(CONFIG_VSERVER_HISTORY) += history.o
21543 +vserver-$(CONFIG_VSERVER_MONITOR) += monitor.o
21544 +vserver-$(CONFIG_VSERVER_DEVICE) += device.o
21545 +
21546 diff -NurpP --minimal linux-2.6.29.1/kernel/vserver/monitor.c linux-2.6.29.1-vs2.3.0.36.9-pre5/kernel/vserver/monitor.c
21547 --- linux-2.6.29.1/kernel/vserver/monitor.c     1970-01-01 01:00:00.000000000 +0100
21548 +++ linux-2.6.29.1-vs2.3.0.36.9-pre5/kernel/vserver/monitor.c   2009-02-22 22:54:26.000000000 +0100
21549 @@ -0,0 +1,138 @@
21550 +/*
21551 + *  kernel/vserver/monitor.c
21552 + *
21553 + *  Virtual Context Scheduler Monitor
21554 + *
21555 + *  Copyright (C) 2006-2007 Herbert Pötzl
21556 + *
21557 + *  V0.01  basic design
21558 + *
21559 + */
21560 +
21561 +#include <linux/module.h>
21562 +#include <linux/jiffies.h>
21563 +#include <asm/uaccess.h>
21564 +#include <asm/atomic.h>
21565 +
21566 +#include <linux/vserver/monitor.h>
21567 +#include <linux/vserver/debug_cmd.h>
21568 +
21569 +
21570 +#ifdef CONFIG_VSERVER_MONITOR
21571 +#define VXM_SIZE       CONFIG_VSERVER_MONITOR_SIZE
21572 +#else
21573 +#define VXM_SIZE       64
21574 +#endif
21575 +
21576 +struct _vx_monitor {
21577 +       unsigned int counter;
21578 +
21579 +       struct _vx_mon_entry entry[VXM_SIZE+1];
21580 +};
21581 +
21582 +
21583 +DEFINE_PER_CPU(struct _vx_monitor, vx_monitor_buffer);
21584 +
21585 +unsigned volatile int vxm_active = 1;
21586 +
21587 +static atomic_t sequence = ATOMIC_INIT(0);
21588 +
21589 +
21590 +/*     vxm_advance()
21591 +
21592 +       * requires disabled preemption                          */
21593 +
21594 +struct _vx_mon_entry *vxm_advance(int cpu)
21595 +{
21596 +       struct _vx_monitor *mon = &per_cpu(vx_monitor_buffer, cpu);
21597 +       struct _vx_mon_entry *entry;
21598 +       unsigned int index;
21599 +
21600 +       index = vxm_active ? (mon->counter++ % VXM_SIZE) : VXM_SIZE;
21601 +       entry = &mon->entry[index];
21602 +
21603 +       entry->ev.seq = atomic_inc_return(&sequence);
21604 +       entry->ev.jif = jiffies;
21605 +       return entry;
21606 +}
21607 +
21608 +EXPORT_SYMBOL_GPL(vxm_advance);
21609 +
21610 +
21611 +int do_read_monitor(struct __user _vx_mon_entry *data,
21612 +       int cpu, uint32_t *index, uint32_t *count)
21613 +{
21614 +       int pos, ret = 0;
21615 +       struct _vx_monitor *mon = &per_cpu(vx_monitor_buffer, cpu);
21616 +       int end = mon->counter;
21617 +       int start = end - VXM_SIZE + 2;
21618 +       int idx = *index;
21619 +
21620 +       /* special case: get current pos */
21621 +       if (!*count) {
21622 +               *index = end;
21623 +               return 0;
21624 +       }
21625 +
21626 +       /* have we lost some data? */
21627 +       if (idx < start)
21628 +               idx = start;
21629 +
21630 +       for (pos = 0; (pos < *count) && (idx < end); pos++, idx++) {
21631 +               struct _vx_mon_entry *entry =
21632 +                       &mon->entry[idx % VXM_SIZE];
21633 +
21634 +               /* send entry to userspace */
21635 +               ret = copy_to_user(&data[pos], entry, sizeof(*entry));
21636 +               if (ret)
21637 +                       break;
21638 +       }
21639 +       /* save new index and count */
21640 +       *index = idx;
21641 +       *count = pos;
21642 +       return ret ? ret : (*index < end);
21643 +}
21644 +
21645 +int vc_read_monitor(uint32_t id, void __user *data)
21646 +{
21647 +       struct vcmd_read_monitor_v0 vc_data;
21648 +       int ret;
21649 +
21650 +       if (id >= NR_CPUS)
21651 +               return -EINVAL;
21652 +
21653 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
21654 +               return -EFAULT;
21655 +
21656 +       ret = do_read_monitor((struct __user _vx_mon_entry *)vc_data.data,
21657 +               id, &vc_data.index, &vc_data.count);
21658 +
21659 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
21660 +               return -EFAULT;
21661 +       return ret;
21662 +}
21663 +
21664 +#ifdef CONFIG_COMPAT
21665 +
21666 +int vc_read_monitor_x32(uint32_t id, void __user *data)
21667 +{
21668 +       struct vcmd_read_monitor_v0_x32 vc_data;
21669 +       int ret;
21670 +
21671 +       if (id >= NR_CPUS)
21672 +               return -EINVAL;
21673 +
21674 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
21675 +               return -EFAULT;
21676 +
21677 +       ret = do_read_monitor((struct __user _vx_mon_entry *)
21678 +               compat_ptr(vc_data.data_ptr),
21679 +               id, &vc_data.index, &vc_data.count);
21680 +
21681 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
21682 +               return -EFAULT;
21683 +       return ret;
21684 +}
21685 +
21686 +#endif /* CONFIG_COMPAT */
21687 +
21688 diff -NurpP --minimal linux-2.6.29.1/kernel/vserver/network.c linux-2.6.29.1-vs2.3.0.36.9-pre5/kernel/vserver/network.c
21689 --- linux-2.6.29.1/kernel/vserver/network.c     1970-01-01 01:00:00.000000000 +0100
21690 +++ linux-2.6.29.1-vs2.3.0.36.9-pre5/kernel/vserver/network.c   2009-02-22 22:54:26.000000000 +0100
21691 @@ -0,0 +1,864 @@
21692 +/*
21693 + *  linux/kernel/vserver/network.c
21694 + *
21695 + *  Virtual Server: Network Support
21696 + *
21697 + *  Copyright (C) 2003-2007  Herbert Pötzl
21698 + *
21699 + *  V0.01  broken out from vcontext V0.05
21700 + *  V0.02  cleaned up implementation
21701 + *  V0.03  added equiv nx commands
21702 + *  V0.04  switch to RCU based hash
21703 + *  V0.05  and back to locking again
21704 + *  V0.06  changed vcmds to nxi arg
21705 + *  V0.07  have __create claim() the nxi
21706 + *
21707 + */
21708 +
21709 +#include <linux/err.h>
21710 +#include <linux/slab.h>
21711 +#include <linux/rcupdate.h>
21712 +
21713 +#include <linux/vs_network.h>
21714 +#include <linux/vs_pid.h>
21715 +#include <linux/vserver/network_cmd.h>
21716 +
21717 +
21718 +atomic_t nx_global_ctotal      = ATOMIC_INIT(0);
21719 +atomic_t nx_global_cactive     = ATOMIC_INIT(0);
21720 +
21721 +static struct kmem_cache *nx_addr_v4_cachep = NULL;
21722 +static struct kmem_cache *nx_addr_v6_cachep = NULL;
21723 +
21724 +
21725 +static int __init init_network(void)
21726 +{
21727 +       nx_addr_v4_cachep = kmem_cache_create("nx_v4_addr_cache",
21728 +               sizeof(struct nx_addr_v4), 0,
21729 +               SLAB_HWCACHE_ALIGN|SLAB_PANIC, NULL);
21730 +       nx_addr_v6_cachep = kmem_cache_create("nx_v6_addr_cache",
21731 +               sizeof(struct nx_addr_v6), 0,
21732 +               SLAB_HWCACHE_ALIGN|SLAB_PANIC, NULL);
21733 +       return 0;
21734 +}
21735 +
21736 +
21737 +/*     __alloc_nx_addr_v4()                                    */
21738 +
21739 +static inline struct nx_addr_v4 *__alloc_nx_addr_v4(void)
21740 +{
21741 +       struct nx_addr_v4 *nxa = kmem_cache_alloc(
21742 +               nx_addr_v4_cachep, GFP_KERNEL);
21743 +
21744 +       if (!IS_ERR(nxa))
21745 +               memset(nxa, 0, sizeof(*nxa));
21746 +       return nxa;
21747 +}
21748 +
21749 +/*     __dealloc_nx_addr_v4()                                  */
21750 +
21751 +static inline void __dealloc_nx_addr_v4(struct nx_addr_v4 *nxa)
21752 +{
21753 +       kmem_cache_free(nx_addr_v4_cachep, nxa);
21754 +}
21755 +
21756 +/*     __dealloc_nx_addr_v4_all()                              */
21757 +
21758 +static inline void __dealloc_nx_addr_v4_all(struct nx_addr_v4 *nxa)
21759 +{
21760 +       while (nxa) {
21761 +               struct nx_addr_v4 *next = nxa->next;
21762 +
21763 +               __dealloc_nx_addr_v4(nxa);
21764 +               nxa = next;
21765 +       }
21766 +}
21767 +
21768 +
21769 +#ifdef CONFIG_IPV6
21770 +
21771 +/*     __alloc_nx_addr_v6()                                    */
21772 +
21773 +static inline struct nx_addr_v6 *__alloc_nx_addr_v6(void)
21774 +{
21775 +       struct nx_addr_v6 *nxa = kmem_cache_alloc(
21776 +               nx_addr_v6_cachep, GFP_KERNEL);
21777 +
21778 +       if (!IS_ERR(nxa))
21779 +               memset(nxa, 0, sizeof(*nxa));
21780 +       return nxa;
21781 +}
21782 +
21783 +/*     __dealloc_nx_addr_v6()                                  */
21784 +
21785 +static inline void __dealloc_nx_addr_v6(struct nx_addr_v6 *nxa)
21786 +{
21787 +       kmem_cache_free(nx_addr_v6_cachep, nxa);
21788 +}
21789 +
21790 +/*     __dealloc_nx_addr_v6_all()                              */
21791 +
21792 +static inline void __dealloc_nx_addr_v6_all(struct nx_addr_v6 *nxa)
21793 +{
21794 +       while (nxa) {
21795 +               struct nx_addr_v6 *next = nxa->next;
21796 +
21797 +               __dealloc_nx_addr_v6(nxa);
21798 +               nxa = next;
21799 +       }
21800 +}
21801 +
21802 +#endif /* CONFIG_IPV6 */
21803 +
21804 +/*     __alloc_nx_info()
21805 +
21806 +       * allocate an initialized nx_info struct
21807 +       * doesn't make it visible (hash)                        */
21808 +
21809 +static struct nx_info *__alloc_nx_info(nid_t nid)
21810 +{
21811 +       struct nx_info *new = NULL;
21812 +
21813 +       vxdprintk(VXD_CBIT(nid, 1), "alloc_nx_info(%d)*", nid);
21814 +
21815 +       /* would this benefit from a slab cache? */
21816 +       new = kmalloc(sizeof(struct nx_info), GFP_KERNEL);
21817 +       if (!new)
21818 +               return 0;
21819 +
21820 +       memset(new, 0, sizeof(struct nx_info));
21821 +       new->nx_id = nid;
21822 +       INIT_HLIST_NODE(&new->nx_hlist);
21823 +       atomic_set(&new->nx_usecnt, 0);
21824 +       atomic_set(&new->nx_tasks, 0);
21825 +       new->nx_state = 0;
21826 +
21827 +       new->nx_flags = NXF_INIT_SET;
21828 +
21829 +       /* rest of init goes here */
21830 +
21831 +       new->v4_lback.s_addr = htonl(INADDR_LOOPBACK);
21832 +       new->v4_bcast.s_addr = htonl(INADDR_BROADCAST);
21833 +
21834 +       vxdprintk(VXD_CBIT(nid, 0),
21835 +               "alloc_nx_info(%d) = %p", nid, new);
21836 +       atomic_inc(&nx_global_ctotal);
21837 +       return new;
21838 +}
21839 +
21840 +/*     __dealloc_nx_info()
21841 +
21842 +       * final disposal of nx_info                             */
21843 +
21844 +static void __dealloc_nx_info(struct nx_info *nxi)
21845 +{
21846 +       vxdprintk(VXD_CBIT(nid, 0),
21847 +               "dealloc_nx_info(%p)", nxi);
21848 +
21849 +       nxi->nx_hlist.next = LIST_POISON1;
21850 +       nxi->nx_id = -1;
21851 +
21852 +       BUG_ON(atomic_read(&nxi->nx_usecnt));
21853 +       BUG_ON(atomic_read(&nxi->nx_tasks));
21854 +
21855 +       __dealloc_nx_addr_v4_all(nxi->v4.next);
21856 +
21857 +       nxi->nx_state |= NXS_RELEASED;
21858 +       kfree(nxi);
21859 +       atomic_dec(&nx_global_ctotal);
21860 +}
21861 +
21862 +static void __shutdown_nx_info(struct nx_info *nxi)
21863 +{
21864 +       nxi->nx_state |= NXS_SHUTDOWN;
21865 +       vs_net_change(nxi, VSC_NETDOWN);
21866 +}
21867 +
21868 +/*     exported stuff                                          */
21869 +
21870 +void free_nx_info(struct nx_info *nxi)
21871 +{
21872 +       /* context shutdown is mandatory */
21873 +       BUG_ON(nxi->nx_state != NXS_SHUTDOWN);
21874 +
21875 +       /* context must not be hashed */
21876 +       BUG_ON(nxi->nx_state & NXS_HASHED);
21877 +
21878 +       BUG_ON(atomic_read(&nxi->nx_usecnt));
21879 +       BUG_ON(atomic_read(&nxi->nx_tasks));
21880 +
21881 +       __dealloc_nx_info(nxi);
21882 +}
21883 +
21884 +
21885 +void __nx_set_lback(struct nx_info *nxi)
21886 +{
21887 +       int nid = nxi->nx_id;
21888 +       __be32 lback = htonl(INADDR_LOOPBACK ^ ((nid & 0xFFFF) << 8));
21889 +
21890 +       nxi->v4_lback.s_addr = lback;
21891 +}
21892 +
21893 +extern int __nx_inet_add_lback(__be32 addr);
21894 +extern int __nx_inet_del_lback(__be32 addr);
21895 +
21896 +
21897 +/*     hash table for nx_info hash */
21898 +
21899 +#define NX_HASH_SIZE   13
21900 +
21901 +struct hlist_head nx_info_hash[NX_HASH_SIZE];
21902 +
21903 +static spinlock_t nx_info_hash_lock = SPIN_LOCK_UNLOCKED;
21904 +
21905 +
21906 +static inline unsigned int __hashval(nid_t nid)
21907 +{
21908 +       return (nid % NX_HASH_SIZE);
21909 +}
21910 +
21911 +
21912 +
21913 +/*     __hash_nx_info()
21914 +
21915 +       * add the nxi to the global hash table
21916 +       * requires the hash_lock to be held                     */
21917 +
21918 +static inline void __hash_nx_info(struct nx_info *nxi)
21919 +{
21920 +       struct hlist_head *head;
21921 +
21922 +       vxd_assert_lock(&nx_info_hash_lock);
21923 +       vxdprintk(VXD_CBIT(nid, 4),
21924 +               "__hash_nx_info: %p[#%d]", nxi, nxi->nx_id);
21925 +
21926 +       /* context must not be hashed */
21927 +       BUG_ON(nx_info_state(nxi, NXS_HASHED));
21928 +
21929 +       nxi->nx_state |= NXS_HASHED;
21930 +       head = &nx_info_hash[__hashval(nxi->nx_id)];
21931 +       hlist_add_head(&nxi->nx_hlist, head);
21932 +       atomic_inc(&nx_global_cactive);
21933 +}
21934 +
21935 +/*     __unhash_nx_info()
21936 +
21937 +       * remove the nxi from the global hash table
21938 +       * requires the hash_lock to be held                     */
21939 +
21940 +static inline void __unhash_nx_info(struct nx_info *nxi)
21941 +{
21942 +       vxd_assert_lock(&nx_info_hash_lock);
21943 +       vxdprintk(VXD_CBIT(nid, 4),
21944 +               "__unhash_nx_info: %p[#%d.%d.%d]", nxi, nxi->nx_id,
21945 +               atomic_read(&nxi->nx_usecnt), atomic_read(&nxi->nx_tasks));
21946 +
21947 +       /* context must be hashed */
21948 +       BUG_ON(!nx_info_state(nxi, NXS_HASHED));
21949 +       /* but without tasks */
21950 +       BUG_ON(atomic_read(&nxi->nx_tasks));
21951 +
21952 +       nxi->nx_state &= ~NXS_HASHED;
21953 +       hlist_del(&nxi->nx_hlist);
21954 +       atomic_dec(&nx_global_cactive);
21955 +}
21956 +
21957 +
21958 +/*     __lookup_nx_info()
21959 +
21960 +       * requires the hash_lock to be held
21961 +       * doesn't increment the nx_refcnt                       */
21962 +
21963 +static inline struct nx_info *__lookup_nx_info(nid_t nid)
21964 +{
21965 +       struct hlist_head *head = &nx_info_hash[__hashval(nid)];
21966 +       struct hlist_node *pos;
21967 +       struct nx_info *nxi;
21968 +
21969 +       vxd_assert_lock(&nx_info_hash_lock);
21970 +       hlist_for_each(pos, head) {
21971 +               nxi = hlist_entry(pos, struct nx_info, nx_hlist);
21972 +
21973 +               if (nxi->nx_id == nid)
21974 +                       goto found;
21975 +       }
21976 +       nxi = NULL;
21977 +found:
21978 +       vxdprintk(VXD_CBIT(nid, 0),
21979 +               "__lookup_nx_info(#%u): %p[#%u]",
21980 +               nid, nxi, nxi ? nxi->nx_id : 0);
21981 +       return nxi;
21982 +}
21983 +
21984 +
21985 +/*     __create_nx_info()
21986 +
21987 +       * create the requested context
21988 +       * get(), claim() and hash it                            */
21989 +
21990 +static struct nx_info *__create_nx_info(int id)
21991 +{
21992 +       struct nx_info *new, *nxi = NULL;
21993 +
21994 +       vxdprintk(VXD_CBIT(nid, 1), "create_nx_info(%d)*", id);
21995 +
21996 +       if (!(new = __alloc_nx_info(id)))
21997 +               return ERR_PTR(-ENOMEM);
21998 +
21999 +       /* required to make dynamic xids unique */
22000 +       spin_lock(&nx_info_hash_lock);
22001 +
22002 +       /* static context requested */
22003 +       if ((nxi = __lookup_nx_info(id))) {
22004 +               vxdprintk(VXD_CBIT(nid, 0),
22005 +                       "create_nx_info(%d) = %p (already there)", id, nxi);
22006 +               if (nx_info_flags(nxi, NXF_STATE_SETUP, 0))
22007 +                       nxi = ERR_PTR(-EBUSY);
22008 +               else
22009 +                       nxi = ERR_PTR(-EEXIST);
22010 +               goto out_unlock;
22011 +       }
22012 +       /* new context */
22013 +       vxdprintk(VXD_CBIT(nid, 0),
22014 +               "create_nx_info(%d) = %p (new)", id, new);
22015 +       claim_nx_info(new, NULL);
22016 +       __nx_set_lback(new);
22017 +       __hash_nx_info(get_nx_info(new));
22018 +       nxi = new, new = NULL;
22019 +
22020 +out_unlock:
22021 +       spin_unlock(&nx_info_hash_lock);
22022 +       if (new)
22023 +               __dealloc_nx_info(new);
22024 +       return nxi;
22025 +}
22026 +
22027 +
22028 +
22029 +/*     exported stuff                                          */
22030 +
22031 +
22032 +void unhash_nx_info(struct nx_info *nxi)
22033 +{
22034 +       __shutdown_nx_info(nxi);
22035 +       spin_lock(&nx_info_hash_lock);
22036 +       __unhash_nx_info(nxi);
22037 +       spin_unlock(&nx_info_hash_lock);
22038 +}
22039 +
22040 +/*     lookup_nx_info()
22041 +
22042 +       * search for a nx_info and get() it
22043 +       * negative id means current                             */
22044 +
22045 +struct nx_info *lookup_nx_info(int id)
22046 +{
22047 +       struct nx_info *nxi = NULL;
22048 +
22049 +       if (id < 0) {
22050 +               nxi = get_nx_info(current->nx_info);
22051 +       } else if (id > 1) {
22052 +               spin_lock(&nx_info_hash_lock);
22053 +               nxi = get_nx_info(__lookup_nx_info(id));
22054 +               spin_unlock(&nx_info_hash_lock);
22055 +       }
22056 +       return nxi;
22057 +}
22058 +
22059 +/*     nid_is_hashed()
22060 +
22061 +       * verify that nid is still hashed                       */
22062 +
22063 +int nid_is_hashed(nid_t nid)
22064 +{
22065 +       int hashed;
22066 +
22067 +       spin_lock(&nx_info_hash_lock);
22068 +       hashed = (__lookup_nx_info(nid) != NULL);
22069 +       spin_unlock(&nx_info_hash_lock);
22070 +       return hashed;
22071 +}
22072 +
22073 +
22074 +#ifdef CONFIG_PROC_FS
22075 +
22076 +/*     get_nid_list()
22077 +
22078 +       * get a subset of hashed nids for proc
22079 +       * assumes size is at least one                          */
22080 +
22081 +int get_nid_list(int index, unsigned int *nids, int size)
22082 +{
22083 +       int hindex, nr_nids = 0;
22084 +
22085 +       /* only show current and children */
22086 +       if (!nx_check(0, VS_ADMIN | VS_WATCH)) {
22087 +               if (index > 0)
22088 +                       return 0;
22089 +               nids[nr_nids] = nx_current_nid();
22090 +               return 1;
22091 +       }
22092 +
22093 +       for (hindex = 0; hindex < NX_HASH_SIZE; hindex++) {
22094 +               struct hlist_head *head = &nx_info_hash[hindex];
22095 +               struct hlist_node *pos;
22096 +
22097 +               spin_lock(&nx_info_hash_lock);
22098 +               hlist_for_each(pos, head) {
22099 +                       struct nx_info *nxi;
22100 +
22101 +                       if (--index > 0)
22102 +                               continue;
22103 +
22104 +                       nxi = hlist_entry(pos, struct nx_info, nx_hlist);
22105 +                       nids[nr_nids] = nxi->nx_id;
22106 +                       if (++nr_nids >= size) {
22107 +                               spin_unlock(&nx_info_hash_lock);
22108 +                               goto out;
22109 +                       }
22110 +               }
22111 +               /* keep the lock time short */
22112 +               spin_unlock(&nx_info_hash_lock);
22113 +       }
22114 +out:
22115 +       return nr_nids;
22116 +}
22117 +#endif
22118 +
22119 +
22120 +/*
22121 + *     migrate task to new network
22122 + *     gets nxi, puts old_nxi on change
22123 + */
22124 +
22125 +int nx_migrate_task(struct task_struct *p, struct nx_info *nxi)
22126 +{
22127 +       struct nx_info *old_nxi;
22128 +       int ret = 0;
22129 +
22130 +       if (!p || !nxi)
22131 +               BUG();
22132 +
22133 +       vxdprintk(VXD_CBIT(nid, 5),
22134 +               "nx_migrate_task(%p,%p[#%d.%d.%d])",
22135 +               p, nxi, nxi->nx_id,
22136 +               atomic_read(&nxi->nx_usecnt),
22137 +               atomic_read(&nxi->nx_tasks));
22138 +
22139 +       if (nx_info_flags(nxi, NXF_INFO_PRIVATE, 0) &&
22140 +               !nx_info_flags(nxi, NXF_STATE_SETUP, 0))
22141 +               return -EACCES;
22142 +
22143 +       if (nx_info_state(nxi, NXS_SHUTDOWN))
22144 +               return -EFAULT;
22145 +
22146 +       /* maybe disallow this completely? */
22147 +       old_nxi = task_get_nx_info(p);
22148 +       if (old_nxi == nxi)
22149 +               goto out;
22150 +
22151 +       task_lock(p);
22152 +       if (old_nxi)
22153 +               clr_nx_info(&p->nx_info);
22154 +       claim_nx_info(nxi, p);
22155 +       set_nx_info(&p->nx_info, nxi);
22156 +       p->nid = nxi->nx_id;
22157 +       task_unlock(p);
22158 +
22159 +       vxdprintk(VXD_CBIT(nid, 5),
22160 +               "moved task %p into nxi:%p[#%d]",
22161 +               p, nxi, nxi->nx_id);
22162 +
22163 +       if (old_nxi)
22164 +               release_nx_info(old_nxi, p);
22165 +       ret = 0;
22166 +out:
22167 +       put_nx_info(old_nxi);
22168 +       return ret;
22169 +}
22170 +
22171 +
22172 +void nx_set_persistent(struct nx_info *nxi)
22173 +{
22174 +       vxdprintk(VXD_CBIT(nid, 6),
22175 +               "nx_set_persistent(%p[#%d])", nxi, nxi->nx_id);
22176 +
22177 +       get_nx_info(nxi);
22178 +       claim_nx_info(nxi, NULL);
22179 +}
22180 +
22181 +void nx_clear_persistent(struct nx_info *nxi)
22182 +{
22183 +       vxdprintk(VXD_CBIT(nid, 6),
22184 +               "nx_clear_persistent(%p[#%d])", nxi, nxi->nx_id);
22185 +
22186 +       release_nx_info(nxi, NULL);
22187 +       put_nx_info(nxi);
22188 +}
22189 +
22190 +void nx_update_persistent(struct nx_info *nxi)
22191 +{
22192 +       if (nx_info_flags(nxi, NXF_PERSISTENT, 0))
22193 +               nx_set_persistent(nxi);
22194 +       else
22195 +               nx_clear_persistent(nxi);
22196 +}
22197 +
22198 +/* vserver syscall commands below here */
22199 +
22200 +/* taks nid and nx_info functions */
22201 +
22202 +#include <asm/uaccess.h>
22203 +
22204 +
22205 +int vc_task_nid(uint32_t id)
22206 +{
22207 +       nid_t nid;
22208 +
22209 +       if (id) {
22210 +               struct task_struct *tsk;
22211 +
22212 +               read_lock(&tasklist_lock);
22213 +               tsk = find_task_by_real_pid(id);
22214 +               nid = (tsk) ? tsk->nid : -ESRCH;
22215 +               read_unlock(&tasklist_lock);
22216 +       } else
22217 +               nid = nx_current_nid();
22218 +       return nid;
22219 +}
22220 +
22221 +
22222 +int vc_nx_info(struct nx_info *nxi, void __user *data)
22223 +{
22224 +       struct vcmd_nx_info_v0 vc_data;
22225 +
22226 +       vc_data.nid = nxi->nx_id;
22227 +
22228 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
22229 +               return -EFAULT;
22230 +       return 0;
22231 +}
22232 +
22233 +
22234 +/* network functions */
22235 +
22236 +int vc_net_create(uint32_t nid, void __user *data)
22237 +{
22238 +       struct vcmd_net_create vc_data = { .flagword = NXF_INIT_SET };
22239 +       struct nx_info *new_nxi;
22240 +       int ret;
22241 +
22242 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
22243 +               return -EFAULT;
22244 +
22245 +       if ((nid > MAX_S_CONTEXT) || (nid < 2))
22246 +               return -EINVAL;
22247 +
22248 +       new_nxi = __create_nx_info(nid);
22249 +       if (IS_ERR(new_nxi))
22250 +               return PTR_ERR(new_nxi);
22251 +
22252 +       /* initial flags */
22253 +       new_nxi->nx_flags = vc_data.flagword;
22254 +
22255 +       ret = -ENOEXEC;
22256 +       if (vs_net_change(new_nxi, VSC_NETUP))
22257 +               goto out;
22258 +
22259 +       ret = nx_migrate_task(current, new_nxi);
22260 +       if (ret)
22261 +               goto out;
22262 +
22263 +       /* return context id on success */
22264 +       ret = new_nxi->nx_id;
22265 +
22266 +       /* get a reference for persistent contexts */
22267 +       if ((vc_data.flagword & NXF_PERSISTENT))
22268 +               nx_set_persistent(new_nxi);
22269 +out:
22270 +       release_nx_info(new_nxi, NULL);
22271 +       put_nx_info(new_nxi);
22272 +       return ret;
22273 +}
22274 +
22275 +
22276 +int vc_net_migrate(struct nx_info *nxi, void __user *data)
22277 +{
22278 +       return nx_migrate_task(current, nxi);
22279 +}
22280 +
22281 +
22282 +
22283 +int do_add_v4_addr(struct nx_info *nxi, __be32 ip, __be32 ip2, __be32 mask,
22284 +       uint16_t type, uint16_t flags)
22285 +{
22286 +       struct nx_addr_v4 *nxa = &nxi->v4;
22287 +
22288 +       if (NX_IPV4(nxi)) {
22289 +               /* locate last entry */
22290 +               for (; nxa->next; nxa = nxa->next);
22291 +               nxa->next = __alloc_nx_addr_v4();
22292 +               nxa = nxa->next;
22293 +
22294 +               if (IS_ERR(nxa))
22295 +                       return PTR_ERR(nxa);
22296 +       }
22297 +
22298 +       if (nxi->v4.next)
22299 +               /* remove single ip for ip list */
22300 +               nxi->nx_flags &= ~NXF_SINGLE_IP;
22301 +
22302 +       nxa->ip[0].s_addr = ip;
22303 +       nxa->ip[1].s_addr = ip2;
22304 +       nxa->mask.s_addr = mask;
22305 +       nxa->type = type;
22306 +       nxa->flags = flags;
22307 +       return 0;
22308 +}
22309 +
22310 +
22311 +int vc_net_add(struct nx_info *nxi, void __user *data)
22312 +{
22313 +       struct vcmd_net_addr_v0 vc_data;
22314 +       int index, ret = 0;
22315 +
22316 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
22317 +               return -EFAULT;
22318 +
22319 +       switch (vc_data.type) {
22320 +       case NXA_TYPE_IPV4:
22321 +               if ((vc_data.count < 1) || (vc_data.count > 4))
22322 +                       return -EINVAL;
22323 +
22324 +               index = 0;
22325 +               while (index < vc_data.count) {
22326 +                       ret = do_add_v4_addr(nxi, vc_data.ip[index].s_addr, 0,
22327 +                               vc_data.mask[index].s_addr, NXA_TYPE_ADDR, 0);
22328 +                       if (ret)
22329 +                               return ret;
22330 +                       index++;
22331 +               }
22332 +               ret = index;
22333 +               break;
22334 +
22335 +       case NXA_TYPE_IPV4|NXA_MOD_BCAST:
22336 +               nxi->v4_bcast = vc_data.ip[0];
22337 +               ret = 1;
22338 +               break;
22339 +
22340 +       case NXA_TYPE_IPV4|NXA_MOD_LBACK:
22341 +               nxi->v4_lback = vc_data.ip[0];
22342 +               ret = 1;
22343 +               break;
22344 +
22345 +       default:
22346 +               ret = -EINVAL;
22347 +               break;
22348 +       }
22349 +       return ret;
22350 +}
22351 +
22352 +int vc_net_remove(struct nx_info *nxi, void __user *data)
22353 +{
22354 +       struct vcmd_net_addr_v0 vc_data;
22355 +
22356 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
22357 +               return -EFAULT;
22358 +
22359 +       switch (vc_data.type) {
22360 +       case NXA_TYPE_ANY:
22361 +               __dealloc_nx_addr_v4_all(xchg(&nxi->v4.next, NULL));
22362 +               memset(&nxi->v4, 0, sizeof(nxi->v4));
22363 +               break;
22364 +
22365 +       default:
22366 +               return -EINVAL;
22367 +       }
22368 +       return 0;
22369 +}
22370 +
22371 +
22372 +int vc_net_add_ipv4(struct nx_info *nxi, void __user *data)
22373 +{
22374 +       struct vcmd_net_addr_ipv4_v1 vc_data;
22375 +
22376 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
22377 +               return -EFAULT;
22378 +
22379 +       switch (vc_data.type) {
22380 +       case NXA_TYPE_ADDR:
22381 +       case NXA_TYPE_RANGE:
22382 +       case NXA_TYPE_MASK:
22383 +               return do_add_v4_addr(nxi, vc_data.ip.s_addr, 0,
22384 +                       vc_data.mask.s_addr, vc_data.type, vc_data.flags);
22385 +
22386 +       case NXA_TYPE_ADDR | NXA_MOD_BCAST:
22387 +               nxi->v4_bcast = vc_data.ip;
22388 +               break;
22389 +
22390 +       case NXA_TYPE_ADDR | NXA_MOD_LBACK:
22391 +               nxi->v4_lback = vc_data.ip;
22392 +               break;
22393 +
22394 +       default:
22395 +               return -EINVAL;
22396 +       }
22397 +       return 0;
22398 +}
22399 +
22400 +int vc_net_remove_ipv4(struct nx_info *nxi, void __user *data)
22401 +{
22402 +       struct vcmd_net_addr_ipv4_v1 vc_data;
22403 +
22404 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
22405 +               return -EFAULT;
22406 +
22407 +       switch (vc_data.type) {
22408 +/*     case NXA_TYPE_ADDR:
22409 +               break;          */
22410 +
22411 +       case NXA_TYPE_ANY:
22412 +               __dealloc_nx_addr_v4_all(xchg(&nxi->v4.next, NULL));
22413 +               memset(&nxi->v4, 0, sizeof(nxi->v4));
22414 +               break;
22415 +
22416 +       default:
22417 +               return -EINVAL;
22418 +       }
22419 +       return 0;
22420 +}
22421 +
22422 +
22423 +#ifdef CONFIG_IPV6
22424 +
22425 +int do_add_v6_addr(struct nx_info *nxi,
22426 +       struct in6_addr *ip, struct in6_addr *mask,
22427 +       uint32_t prefix, uint16_t type, uint16_t flags)
22428 +{
22429 +       struct nx_addr_v6 *nxa = &nxi->v6;
22430 +
22431 +       if (NX_IPV6(nxi)) {
22432 +               /* locate last entry */
22433 +               for (; nxa->next; nxa = nxa->next);
22434 +               nxa->next = __alloc_nx_addr_v6();
22435 +               nxa = nxa->next;
22436 +
22437 +               if (IS_ERR(nxa))
22438 +                       return PTR_ERR(nxa);
22439 +       }
22440 +
22441 +       nxa->ip = *ip;
22442 +       nxa->mask = *mask;
22443 +       nxa->prefix = prefix;
22444 +       nxa->type = type;
22445 +       nxa->flags = flags;
22446 +       return 0;
22447 +}
22448 +
22449 +
22450 +int vc_net_add_ipv6(struct nx_info *nxi, void __user *data)
22451 +{
22452 +       struct vcmd_net_addr_ipv6_v1 vc_data;
22453 +
22454 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
22455 +               return -EFAULT;
22456 +
22457 +       switch (vc_data.type) {
22458 +       case NXA_TYPE_ADDR:
22459 +       case NXA_TYPE_MASK:
22460 +               return do_add_v6_addr(nxi, &vc_data.ip, &vc_data.mask,
22461 +                       vc_data.prefix, vc_data.type, vc_data.flags);
22462 +       default:
22463 +               return -EINVAL;
22464 +       }
22465 +       return 0;
22466 +}
22467 +
22468 +int vc_net_remove_ipv6(struct nx_info *nxi, void __user *data)
22469 +{
22470 +       struct vcmd_net_addr_ipv6_v1 vc_data;
22471 +
22472 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
22473 +               return -EFAULT;
22474 +
22475 +       switch (vc_data.type) {
22476 +       case NXA_TYPE_ANY:
22477 +               __dealloc_nx_addr_v6_all(xchg(&nxi->v6.next, NULL));
22478 +               memset(&nxi->v6, 0, sizeof(nxi->v6));
22479 +               break;
22480 +
22481 +       default:
22482 +               return -EINVAL;
22483 +       }
22484 +       return 0;
22485 +}
22486 +
22487 +#endif /* CONFIG_IPV6 */
22488 +
22489 +
22490 +int vc_get_nflags(struct nx_info *nxi, void __user *data)
22491 +{
22492 +       struct vcmd_net_flags_v0 vc_data;
22493 +
22494 +       vc_data.flagword = nxi->nx_flags;
22495 +
22496 +       /* special STATE flag handling */
22497 +       vc_data.mask = vs_mask_flags(~0ULL, nxi->nx_flags, NXF_ONE_TIME);
22498 +
22499 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
22500 +               return -EFAULT;
22501 +       return 0;
22502 +}
22503 +
22504 +int vc_set_nflags(struct nx_info *nxi, void __user *data)
22505 +{
22506 +       struct vcmd_net_flags_v0 vc_data;
22507 +       uint64_t mask, trigger;
22508 +
22509 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
22510 +               return -EFAULT;
22511 +
22512 +       /* special STATE flag handling */
22513 +       mask = vs_mask_mask(vc_data.mask, nxi->nx_flags, NXF_ONE_TIME);
22514 +       trigger = (mask & nxi->nx_flags) ^ (mask & vc_data.flagword);
22515 +
22516 +       nxi->nx_flags = vs_mask_flags(nxi->nx_flags,
22517 +               vc_data.flagword, mask);
22518 +       if (trigger & NXF_PERSISTENT)
22519 +               nx_update_persistent(nxi);
22520 +
22521 +       return 0;
22522 +}
22523 +
22524 +int vc_get_ncaps(struct nx_info *nxi, void __user *data)
22525 +{
22526 +       struct vcmd_net_caps_v0 vc_data;
22527 +
22528 +       vc_data.ncaps = nxi->nx_ncaps;
22529 +       vc_data.cmask = ~0ULL;
22530 +
22531 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
22532 +               return -EFAULT;
22533 +       return 0;
22534 +}
22535 +
22536 +int vc_set_ncaps(struct nx_info *nxi, void __user *data)
22537 +{
22538 +       struct vcmd_net_caps_v0 vc_data;
22539 +
22540 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
22541 +               return -EFAULT;
22542 +
22543 +       nxi->nx_ncaps = vs_mask_flags(nxi->nx_ncaps,
22544 +               vc_data.ncaps, vc_data.cmask);
22545 +       return 0;
22546 +}
22547 +
22548 +
22549 +#include <linux/module.h>
22550 +
22551 +module_init(init_network);
22552 +
22553 +EXPORT_SYMBOL_GPL(free_nx_info);
22554 +EXPORT_SYMBOL_GPL(unhash_nx_info);
22555 +
22556 diff -NurpP --minimal linux-2.6.29.1/kernel/vserver/proc.c linux-2.6.29.1-vs2.3.0.36.9-pre5/kernel/vserver/proc.c
22557 --- linux-2.6.29.1/kernel/vserver/proc.c        1970-01-01 01:00:00.000000000 +0100
22558 +++ linux-2.6.29.1-vs2.3.0.36.9-pre5/kernel/vserver/proc.c      2009-02-22 22:54:26.000000000 +0100
22559 @@ -0,0 +1,1092 @@
22560 +/*
22561 + *  linux/kernel/vserver/proc.c
22562 + *
22563 + *  Virtual Context Support
22564 + *
22565 + *  Copyright (C) 2003-2007  Herbert Pötzl
22566 + *
22567 + *  V0.01  basic structure
22568 + *  V0.02  adaptation vs1.3.0
22569 + *  V0.03  proc permissions
22570 + *  V0.04  locking/generic
22571 + *  V0.05  next generation procfs
22572 + *  V0.06  inode validation
22573 + *  V0.07  generic rewrite vid
22574 + *  V0.08  remove inode type
22575 + *
22576 + */
22577 +
22578 +#include <linux/proc_fs.h>
22579 +#include <asm/unistd.h>
22580 +
22581 +#include <linux/vs_context.h>
22582 +#include <linux/vs_network.h>
22583 +#include <linux/vs_cvirt.h>
22584 +
22585 +#include <linux/in.h>
22586 +#include <linux/inetdevice.h>
22587 +#include <linux/vs_inet.h>
22588 +#include <linux/vs_inet6.h>
22589 +
22590 +#include <linux/vserver/global.h>
22591 +
22592 +#include "cvirt_proc.h"
22593 +#include "cacct_proc.h"
22594 +#include "limit_proc.h"
22595 +#include "sched_proc.h"
22596 +#include "vci_config.h"
22597 +
22598 +
22599 +static inline char *print_cap_t(char *buffer, kernel_cap_t *c)
22600 +{
22601 +       unsigned __capi;
22602 +
22603 +       CAP_FOR_EACH_U32(__capi) {
22604 +               buffer += sprintf(buffer, "%08x",
22605 +                       c->cap[(_KERNEL_CAPABILITY_U32S-1) - __capi]);
22606 +       }
22607 +       return buffer;
22608 +}
22609 +
22610 +
22611 +static struct proc_dir_entry *proc_virtual;
22612 +
22613 +static struct proc_dir_entry *proc_virtnet;
22614 +
22615 +
22616 +/* first the actual feeds */
22617 +
22618 +
22619 +static int proc_vci(char *buffer)
22620 +{
22621 +       return sprintf(buffer,
22622 +               "VCIVersion:\t%04x:%04x\n"
22623 +               "VCISyscall:\t%d\n"
22624 +               "VCIKernel:\t%08x\n",
22625 +               VCI_VERSION >> 16,
22626 +               VCI_VERSION & 0xFFFF,
22627 +               __NR_vserver,
22628 +               vci_kernel_config());
22629 +}
22630 +
22631 +static int proc_virtual_info(char *buffer)
22632 +{
22633 +       return proc_vci(buffer);
22634 +}
22635 +
22636 +static int proc_virtual_status(char *buffer)
22637 +{
22638 +       return sprintf(buffer,
22639 +               "#CTotal:\t%d\n"
22640 +               "#CActive:\t%d\n"
22641 +               "#NSProxy:\t%d\t%d %d %d %d %d %d\n",
22642 +               atomic_read(&vx_global_ctotal),
22643 +               atomic_read(&vx_global_cactive),
22644 +               atomic_read(&vs_global_nsproxy),
22645 +               atomic_read(&vs_global_fs),
22646 +               atomic_read(&vs_global_mnt_ns),
22647 +               atomic_read(&vs_global_uts_ns),
22648 +               atomic_read(&vs_global_ipc_ns),
22649 +               atomic_read(&vs_global_user_ns),
22650 +               atomic_read(&vs_global_pid_ns));
22651 +}
22652 +
22653 +
22654 +int proc_vxi_info(struct vx_info *vxi, char *buffer)
22655 +{
22656 +       int length;
22657 +
22658 +       length = sprintf(buffer,
22659 +               "ID:\t%d\n"
22660 +               "Info:\t%p\n"
22661 +               "Init:\t%d\n"
22662 +               "OOM:\t%lld\n",
22663 +               vxi->vx_id,
22664 +               vxi,
22665 +               vxi->vx_initpid,
22666 +               vxi->vx_badness_bias);
22667 +       return length;
22668 +}
22669 +
22670 +int proc_vxi_status(struct vx_info *vxi, char *buffer)
22671 +{
22672 +       char *orig = buffer;
22673 +
22674 +       buffer += sprintf(buffer,
22675 +               "UseCnt:\t%d\n"
22676 +               "Tasks:\t%d\n"
22677 +               "Flags:\t%016llx\n",
22678 +               atomic_read(&vxi->vx_usecnt),
22679 +               atomic_read(&vxi->vx_tasks),
22680 +               (unsigned long long)vxi->vx_flags);
22681 +
22682 +       buffer += sprintf(buffer, "BCaps:\t");
22683 +       buffer = print_cap_t(buffer, &vxi->vx_bcaps);
22684 +       buffer += sprintf(buffer, "\n");
22685 +
22686 +       buffer += sprintf(buffer,
22687 +               "CCaps:\t%016llx\n"
22688 +               "Spaces:\t%08lx %08lx\n",
22689 +               (unsigned long long)vxi->vx_ccaps,
22690 +               vxi->vx_nsmask[0], vxi->vx_nsmask[1]);
22691 +       return buffer - orig;
22692 +}
22693 +
22694 +int proc_vxi_limit(struct vx_info *vxi, char *buffer)
22695 +{
22696 +       return vx_info_proc_limit(&vxi->limit, buffer);
22697 +}
22698 +
22699 +int proc_vxi_sched(struct vx_info *vxi, char *buffer)
22700 +{
22701 +       int cpu, length;
22702 +
22703 +       length = vx_info_proc_sched(&vxi->sched, buffer);
22704 +       for_each_online_cpu(cpu) {
22705 +               length += vx_info_proc_sched_pc(
22706 +                       &vx_per_cpu(vxi, sched_pc, cpu),
22707 +                       buffer + length, cpu);
22708 +       }
22709 +       return length;
22710 +}
22711 +
22712 +int proc_vxi_nsproxy0(struct vx_info *vxi, char *buffer)
22713 +{
22714 +       return vx_info_proc_nsproxy(vxi->vx_nsproxy[0], buffer);
22715 +}
22716 +
22717 +int proc_vxi_nsproxy1(struct vx_info *vxi, char *buffer)
22718 +{
22719 +       return vx_info_proc_nsproxy(vxi->vx_nsproxy[1], buffer);
22720 +}
22721 +
22722 +int proc_vxi_cvirt(struct vx_info *vxi, char *buffer)
22723 +{
22724 +       int cpu, length;
22725 +
22726 +       vx_update_load(vxi);
22727 +       length = vx_info_proc_cvirt(&vxi->cvirt, buffer);
22728 +       for_each_online_cpu(cpu) {
22729 +               length += vx_info_proc_cvirt_pc(
22730 +                       &vx_per_cpu(vxi, cvirt_pc, cpu),
22731 +                       buffer + length, cpu);
22732 +       }
22733 +       return length;
22734 +}
22735 +
22736 +int proc_vxi_cacct(struct vx_info *vxi, char *buffer)
22737 +{
22738 +       return vx_info_proc_cacct(&vxi->cacct, buffer);
22739 +}
22740 +
22741 +
22742 +static int proc_virtnet_info(char *buffer)
22743 +{
22744 +       return proc_vci(buffer);
22745 +}
22746 +
22747 +static int proc_virtnet_status(char *buffer)
22748 +{
22749 +       return sprintf(buffer,
22750 +               "#CTotal:\t%d\n"
22751 +               "#CActive:\t%d\n",
22752 +               atomic_read(&nx_global_ctotal),
22753 +               atomic_read(&nx_global_cactive));
22754 +}
22755 +
22756 +int proc_nxi_info(struct nx_info *nxi, char *buffer)
22757 +{
22758 +       struct nx_addr_v4 *v4a;
22759 +#ifdef CONFIG_IPV6
22760 +       struct nx_addr_v6 *v6a;
22761 +#endif
22762 +       int length, i;
22763 +
22764 +       length = sprintf(buffer,
22765 +               "ID:\t%d\n"
22766 +               "Info:\t%p\n"
22767 +               "Bcast:\t" NIPQUAD_FMT "\n"
22768 +               "Lback:\t" NIPQUAD_FMT "\n",
22769 +               nxi->nx_id,
22770 +               nxi,
22771 +               NIPQUAD(nxi->v4_bcast.s_addr),
22772 +               NIPQUAD(nxi->v4_lback.s_addr));
22773 +
22774 +       if (!NX_IPV4(nxi))
22775 +               goto skip_v4;
22776 +       for (i = 0, v4a = &nxi->v4; v4a; i++, v4a = v4a->next)
22777 +               length += sprintf(buffer + length, "%d:\t" NXAV4_FMT "\n",
22778 +                       i, NXAV4(v4a));
22779 +skip_v4:
22780 +#ifdef CONFIG_IPV6
22781 +       if (!NX_IPV6(nxi))
22782 +               goto skip_v6;
22783 +       for (i = 0, v6a = &nxi->v6; v6a; i++, v6a = v6a->next)
22784 +               length += sprintf(buffer + length, "%d:\t" NXAV6_FMT "\n",
22785 +                       i, NXAV6(v6a));
22786 +skip_v6:
22787 +#endif
22788 +       return length;
22789 +}
22790 +
22791 +int proc_nxi_status(struct nx_info *nxi, char *buffer)
22792 +{
22793 +       int length;
22794 +
22795 +       length = sprintf(buffer,
22796 +               "UseCnt:\t%d\n"
22797 +               "Tasks:\t%d\n"
22798 +               "Flags:\t%016llx\n"
22799 +               "NCaps:\t%016llx\n",
22800 +               atomic_read(&nxi->nx_usecnt),
22801 +               atomic_read(&nxi->nx_tasks),
22802 +               (unsigned long long)nxi->nx_flags,
22803 +               (unsigned long long)nxi->nx_ncaps);
22804 +       return length;
22805 +}
22806 +
22807 +
22808 +
22809 +/* here the inode helpers */
22810 +
22811 +struct vs_entry {
22812 +       int len;
22813 +       char *name;
22814 +       mode_t mode;
22815 +       struct inode_operations *iop;
22816 +       struct file_operations *fop;
22817 +       union proc_op op;
22818 +};
22819 +
22820 +static struct inode *vs_proc_make_inode(struct super_block *sb, struct vs_entry *p)
22821 +{
22822 +       struct inode *inode = new_inode(sb);
22823 +
22824 +       if (!inode)
22825 +               goto out;
22826 +
22827 +       inode->i_mode = p->mode;
22828 +       if (p->iop)
22829 +               inode->i_op = p->iop;
22830 +       if (p->fop)
22831 +               inode->i_fop = p->fop;
22832 +
22833 +       inode->i_nlink = (p->mode & S_IFDIR) ? 2 : 1;
22834 +       inode->i_flags |= S_IMMUTABLE;
22835 +
22836 +       inode->i_mtime = inode->i_atime = inode->i_ctime = CURRENT_TIME;
22837 +
22838 +       inode->i_uid = 0;
22839 +       inode->i_gid = 0;
22840 +       inode->i_tag = 0;
22841 +out:
22842 +       return inode;
22843 +}
22844 +
22845 +static struct dentry *vs_proc_instantiate(struct inode *dir,
22846 +       struct dentry *dentry, int id, void *ptr)
22847 +{
22848 +       struct vs_entry *p = ptr;
22849 +       struct inode *inode = vs_proc_make_inode(dir->i_sb, p);
22850 +       struct dentry *error = ERR_PTR(-EINVAL);
22851 +
22852 +       if (!inode)
22853 +               goto out;
22854 +
22855 +       PROC_I(inode)->op = p->op;
22856 +       PROC_I(inode)->fd = id;
22857 +       d_add(dentry, inode);
22858 +       error = NULL;
22859 +out:
22860 +       return error;
22861 +}
22862 +
22863 +/* Lookups */
22864 +
22865 +typedef struct dentry *instantiate_t(struct inode *, struct dentry *, int, void *);
22866 +
22867 +/*
22868 + * Fill a directory entry.
22869 + *
22870 + * If possible create the dcache entry and derive our inode number and
22871 + * file type from dcache entry.
22872 + *
22873 + * Since all of the proc inode numbers are dynamically generated, the inode
22874 + * numbers do not exist until the inode is cache.  This means creating the
22875 + * the dcache entry in readdir is necessary to keep the inode numbers
22876 + * reported by readdir in sync with the inode numbers reported
22877 + * by stat.
22878 + */
22879 +static int proc_fill_cache(struct file *filp, void *dirent, filldir_t filldir,
22880 +       char *name, int len, instantiate_t instantiate, int id, void *ptr)
22881 +{
22882 +       struct dentry *child, *dir = filp->f_dentry;
22883 +       struct inode *inode;
22884 +       struct qstr qname;
22885 +       ino_t ino = 0;
22886 +       unsigned type = DT_UNKNOWN;
22887 +
22888 +       qname.name = name;
22889 +       qname.len  = len;
22890 +       qname.hash = full_name_hash(name, len);
22891 +
22892 +       child = d_lookup(dir, &qname);
22893 +       if (!child) {
22894 +               struct dentry *new;
22895 +               new = d_alloc(dir, &qname);
22896 +               if (new) {
22897 +                       child = instantiate(dir->d_inode, new, id, ptr);
22898 +                       if (child)
22899 +                               dput(new);
22900 +                       else
22901 +                               child = new;
22902 +               }
22903 +       }
22904 +       if (!child || IS_ERR(child) || !child->d_inode)
22905 +               goto end_instantiate;
22906 +       inode = child->d_inode;
22907 +       if (inode) {
22908 +               ino = inode->i_ino;
22909 +               type = inode->i_mode >> 12;
22910 +       }
22911 +       dput(child);
22912 +end_instantiate:
22913 +       if (!ino)
22914 +               ino = find_inode_number(dir, &qname);
22915 +       if (!ino)
22916 +               ino = 1;
22917 +       return filldir(dirent, name, len, filp->f_pos, ino, type);
22918 +}
22919 +
22920 +
22921 +
22922 +/* get and revalidate vx_info/xid */
22923 +
22924 +static inline
22925 +struct vx_info *get_proc_vx_info(struct inode *inode)
22926 +{
22927 +       return lookup_vx_info(PROC_I(inode)->fd);
22928 +}
22929 +
22930 +static int proc_xid_revalidate(struct dentry *dentry, struct nameidata *nd)
22931 +{
22932 +       struct inode *inode = dentry->d_inode;
22933 +       xid_t xid = PROC_I(inode)->fd;
22934 +
22935 +       if (!xid || xid_is_hashed(xid))
22936 +               return 1;
22937 +       d_drop(dentry);
22938 +       return 0;
22939 +}
22940 +
22941 +
22942 +/* get and revalidate nx_info/nid */
22943 +
22944 +static int proc_nid_revalidate(struct dentry *dentry, struct nameidata *nd)
22945 +{
22946 +       struct inode *inode = dentry->d_inode;
22947 +       nid_t nid = PROC_I(inode)->fd;
22948 +
22949 +       if (!nid || nid_is_hashed(nid))
22950 +               return 1;
22951 +       d_drop(dentry);
22952 +       return 0;
22953 +}
22954 +
22955 +
22956 +
22957 +#define PROC_BLOCK_SIZE (PAGE_SIZE - 1024)
22958 +
22959 +static ssize_t proc_vs_info_read(struct file *file, char __user *buf,
22960 +                         size_t count, loff_t *ppos)
22961 +{
22962 +       struct inode *inode = file->f_dentry->d_inode;
22963 +       unsigned long page;
22964 +       ssize_t length = 0;
22965 +
22966 +       if (count > PROC_BLOCK_SIZE)
22967 +               count = PROC_BLOCK_SIZE;
22968 +
22969 +       /* fade that out as soon as stable */
22970 +       WARN_ON(PROC_I(inode)->fd);
22971 +
22972 +       if (!(page = __get_free_page(GFP_KERNEL)))
22973 +               return -ENOMEM;
22974 +
22975 +       BUG_ON(!PROC_I(inode)->op.proc_vs_read);
22976 +       length = PROC_I(inode)->op.proc_vs_read((char *)page);
22977 +
22978 +       if (length >= 0)
22979 +               length = simple_read_from_buffer(buf, count, ppos,
22980 +                       (char *)page, length);
22981 +
22982 +       free_page(page);
22983 +       return length;
22984 +}
22985 +
22986 +static ssize_t proc_vx_info_read(struct file *file, char __user *buf,
22987 +                         size_t count, loff_t *ppos)
22988 +{
22989 +       struct inode *inode = file->f_dentry->d_inode;
22990 +       struct vx_info *vxi = NULL;
22991 +       xid_t xid = PROC_I(inode)->fd;
22992 +       unsigned long page;
22993 +       ssize_t length = 0;
22994 +
22995 +       if (count > PROC_BLOCK_SIZE)
22996 +               count = PROC_BLOCK_SIZE;
22997 +
22998 +       /* fade that out as soon as stable */
22999 +       WARN_ON(!xid);
23000 +       vxi = lookup_vx_info(xid);
23001 +       if (!vxi)
23002 +               goto out;
23003 +
23004 +       length = -ENOMEM;
23005 +       if (!(page = __get_free_page(GFP_KERNEL)))
23006 +               goto out_put;
23007 +
23008 +       BUG_ON(!PROC_I(inode)->op.proc_vxi_read);
23009 +       length = PROC_I(inode)->op.proc_vxi_read(vxi, (char *)page);
23010 +
23011 +       if (length >= 0)
23012 +               length = simple_read_from_buffer(buf, count, ppos,
23013 +                       (char *)page, length);
23014 +
23015 +       free_page(page);
23016 +out_put:
23017 +       put_vx_info(vxi);
23018 +out:
23019 +       return length;
23020 +}
23021 +
23022 +static ssize_t proc_nx_info_read(struct file *file, char __user *buf,
23023 +                         size_t count, loff_t *ppos)
23024 +{
23025 +       struct inode *inode = file->f_dentry->d_inode;
23026 +       struct nx_info *nxi = NULL;
23027 +       nid_t nid = PROC_I(inode)->fd;
23028 +       unsigned long page;
23029 +       ssize_t length = 0;
23030 +
23031 +       if (count > PROC_BLOCK_SIZE)
23032 +               count = PROC_BLOCK_SIZE;
23033 +
23034 +       /* fade that out as soon as stable */
23035 +       WARN_ON(!nid);
23036 +       nxi = lookup_nx_info(nid);
23037 +       if (!nxi)
23038 +               goto out;
23039 +
23040 +       length = -ENOMEM;
23041 +       if (!(page = __get_free_page(GFP_KERNEL)))
23042 +               goto out_put;
23043 +
23044 +       BUG_ON(!PROC_I(inode)->op.proc_nxi_read);
23045 +       length = PROC_I(inode)->op.proc_nxi_read(nxi, (char *)page);
23046 +
23047 +       if (length >= 0)
23048 +               length = simple_read_from_buffer(buf, count, ppos,
23049 +                       (char *)page, length);
23050 +
23051 +       free_page(page);
23052 +out_put:
23053 +       put_nx_info(nxi);
23054 +out:
23055 +       return length;
23056 +}
23057 +
23058 +
23059 +
23060 +/* here comes the lower level */
23061 +
23062 +
23063 +#define NOD(NAME, MODE, IOP, FOP, OP) {        \
23064 +       .len  = sizeof(NAME) - 1,       \
23065 +       .name = (NAME),                 \
23066 +       .mode = MODE,                   \
23067 +       .iop  = IOP,                    \
23068 +       .fop  = FOP,                    \
23069 +       .op   = OP,                     \
23070 +}
23071 +
23072 +
23073 +#define DIR(NAME, MODE, OTYPE)                         \
23074 +       NOD(NAME, (S_IFDIR | (MODE)),                   \
23075 +               &proc_ ## OTYPE ## _inode_operations,   \
23076 +               &proc_ ## OTYPE ## _file_operations, { } )
23077 +
23078 +#define INF(NAME, MODE, OTYPE)                         \
23079 +       NOD(NAME, (S_IFREG | (MODE)), NULL,             \
23080 +               &proc_vs_info_file_operations,          \
23081 +               { .proc_vs_read = &proc_##OTYPE } )
23082 +
23083 +#define VINF(NAME, MODE, OTYPE)                                \
23084 +       NOD(NAME, (S_IFREG | (MODE)), NULL,             \
23085 +               &proc_vx_info_file_operations,          \
23086 +               { .proc_vxi_read = &proc_##OTYPE } )
23087 +
23088 +#define NINF(NAME, MODE, OTYPE)                                \
23089 +       NOD(NAME, (S_IFREG | (MODE)), NULL,             \
23090 +               &proc_nx_info_file_operations,          \
23091 +               { .proc_nxi_read = &proc_##OTYPE } )
23092 +
23093 +
23094 +static struct file_operations proc_vs_info_file_operations = {
23095 +       .read =         proc_vs_info_read,
23096 +};
23097 +
23098 +static struct file_operations proc_vx_info_file_operations = {
23099 +       .read =         proc_vx_info_read,
23100 +};
23101 +
23102 +static struct dentry_operations proc_xid_dentry_operations = {
23103 +       .d_revalidate = proc_xid_revalidate,
23104 +};
23105 +
23106 +static struct vs_entry vx_base_stuff[] = {
23107 +       VINF("info",    S_IRUGO, vxi_info),
23108 +       VINF("status",  S_IRUGO, vxi_status),
23109 +       VINF("limit",   S_IRUGO, vxi_limit),
23110 +       VINF("sched",   S_IRUGO, vxi_sched),
23111 +       VINF("nsproxy", S_IRUGO, vxi_nsproxy0),
23112 +       VINF("nsproxy1",S_IRUGO, vxi_nsproxy1),
23113 +       VINF("cvirt",   S_IRUGO, vxi_cvirt),
23114 +       VINF("cacct",   S_IRUGO, vxi_cacct),
23115 +       {}
23116 +};
23117 +
23118 +
23119 +
23120 +
23121 +static struct dentry *proc_xid_instantiate(struct inode *dir,
23122 +       struct dentry *dentry, int id, void *ptr)
23123 +{
23124 +       dentry->d_op = &proc_xid_dentry_operations;
23125 +       return vs_proc_instantiate(dir, dentry, id, ptr);
23126 +}
23127 +
23128 +static struct dentry *proc_xid_lookup(struct inode *dir,
23129 +       struct dentry *dentry, struct nameidata *nd)
23130 +{
23131 +       struct vs_entry *p = vx_base_stuff;
23132 +       struct dentry *error = ERR_PTR(-ENOENT);
23133 +
23134 +       for (; p->name; p++) {
23135 +               if (p->len != dentry->d_name.len)
23136 +                       continue;
23137 +               if (!memcmp(dentry->d_name.name, p->name, p->len))
23138 +                       break;
23139 +       }
23140 +       if (!p->name)
23141 +               goto out;
23142 +
23143 +       error = proc_xid_instantiate(dir, dentry, PROC_I(dir)->fd, p);
23144 +out:
23145 +       return error;
23146 +}
23147 +
23148 +static int proc_xid_readdir(struct file *filp,
23149 +       void *dirent, filldir_t filldir)
23150 +{
23151 +       struct dentry *dentry = filp->f_dentry;
23152 +       struct inode *inode = dentry->d_inode;
23153 +       struct vs_entry *p = vx_base_stuff;
23154 +       int size = sizeof(vx_base_stuff) / sizeof(struct vs_entry);
23155 +       int pos, index;
23156 +       u64 ino;
23157 +
23158 +       pos = filp->f_pos;
23159 +       switch (pos) {
23160 +       case 0:
23161 +               ino = inode->i_ino;
23162 +               if (filldir(dirent, ".", 1, pos, ino, DT_DIR) < 0)
23163 +                       goto out;
23164 +               pos++;
23165 +               /* fall through */
23166 +       case 1:
23167 +               ino = parent_ino(dentry);
23168 +               if (filldir(dirent, "..", 2, pos, ino, DT_DIR) < 0)
23169 +                       goto out;
23170 +               pos++;
23171 +               /* fall through */
23172 +       default:
23173 +               index = pos - 2;
23174 +               if (index >= size)
23175 +                       goto out;
23176 +               for (p += index; p->name; p++) {
23177 +                       if (proc_fill_cache(filp, dirent, filldir, p->name, p->len,
23178 +                               vs_proc_instantiate, PROC_I(inode)->fd, p))
23179 +                               goto out;
23180 +                       pos++;
23181 +               }
23182 +       }
23183 +out:
23184 +       filp->f_pos = pos;
23185 +       return 1;
23186 +}
23187 +
23188 +
23189 +
23190 +static struct file_operations proc_nx_info_file_operations = {
23191 +       .read =         proc_nx_info_read,
23192 +};
23193 +
23194 +static struct dentry_operations proc_nid_dentry_operations = {
23195 +       .d_revalidate = proc_nid_revalidate,
23196 +};
23197 +
23198 +static struct vs_entry nx_base_stuff[] = {
23199 +       NINF("info",    S_IRUGO, nxi_info),
23200 +       NINF("status",  S_IRUGO, nxi_status),
23201 +       {}
23202 +};
23203 +
23204 +
23205 +static struct dentry *proc_nid_instantiate(struct inode *dir,
23206 +       struct dentry *dentry, int id, void *ptr)
23207 +{
23208 +       dentry->d_op = &proc_nid_dentry_operations;
23209 +       return vs_proc_instantiate(dir, dentry, id, ptr);
23210 +}
23211 +
23212 +static struct dentry *proc_nid_lookup(struct inode *dir,
23213 +       struct dentry *dentry, struct nameidata *nd)
23214 +{
23215 +       struct vs_entry *p = nx_base_stuff;
23216 +       struct dentry *error = ERR_PTR(-ENOENT);
23217 +
23218 +       for (; p->name; p++) {
23219 +               if (p->len != dentry->d_name.len)
23220 +                       continue;
23221 +               if (!memcmp(dentry->d_name.name, p->name, p->len))
23222 +                       break;
23223 +       }
23224 +       if (!p->name)
23225 +               goto out;
23226 +
23227 +       error = proc_nid_instantiate(dir, dentry, PROC_I(dir)->fd, p);
23228 +out:
23229 +       return error;
23230 +}
23231 +
23232 +static int proc_nid_readdir(struct file *filp,
23233 +       void *dirent, filldir_t filldir)
23234 +{
23235 +       struct dentry *dentry = filp->f_dentry;
23236 +       struct inode *inode = dentry->d_inode;
23237 +       struct vs_entry *p = nx_base_stuff;
23238 +       int size = sizeof(nx_base_stuff) / sizeof(struct vs_entry);
23239 +       int pos, index;
23240 +       u64 ino;
23241 +
23242 +       pos = filp->f_pos;
23243 +       switch (pos) {
23244 +       case 0:
23245 +               ino = inode->i_ino;
23246 +               if (filldir(dirent, ".", 1, pos, ino, DT_DIR) < 0)
23247 +                       goto out;
23248 +               pos++;
23249 +               /* fall through */
23250 +       case 1:
23251 +               ino = parent_ino(dentry);
23252 +               if (filldir(dirent, "..", 2, pos, ino, DT_DIR) < 0)
23253 +                       goto out;
23254 +               pos++;
23255 +               /* fall through */
23256 +       default:
23257 +               index = pos - 2;
23258 +               if (index >= size)
23259 +                       goto out;
23260 +               for (p += index; p->name; p++) {
23261 +                       if (proc_fill_cache(filp, dirent, filldir, p->name, p->len,
23262 +                               vs_proc_instantiate, PROC_I(inode)->fd, p))
23263 +                               goto out;
23264 +                       pos++;
23265 +               }
23266 +       }
23267 +out:
23268 +       filp->f_pos = pos;
23269 +       return 1;
23270 +}
23271 +
23272 +
23273 +#define MAX_MULBY10    ((~0U - 9) / 10)
23274 +
23275 +static inline int atovid(const char *str, int len)
23276 +{
23277 +       int vid, c;
23278 +
23279 +       vid = 0;
23280 +       while (len-- > 0) {
23281 +               c = *str - '0';
23282 +               str++;
23283 +               if (c > 9)
23284 +                       return -1;
23285 +               if (vid >= MAX_MULBY10)
23286 +                       return -1;
23287 +               vid *= 10;
23288 +               vid += c;
23289 +               if (!vid)
23290 +                       return -1;
23291 +       }
23292 +       return vid;
23293 +}
23294 +
23295 +/* now the upper level (virtual) */
23296 +
23297 +
23298 +static struct file_operations proc_xid_file_operations = {
23299 +       .read =         generic_read_dir,
23300 +       .readdir =      proc_xid_readdir,
23301 +};
23302 +
23303 +static struct inode_operations proc_xid_inode_operations = {
23304 +       .lookup =       proc_xid_lookup,
23305 +};
23306 +
23307 +static struct vs_entry vx_virtual_stuff[] = {
23308 +       INF("info",     S_IRUGO, virtual_info),
23309 +       INF("status",   S_IRUGO, virtual_status),
23310 +       DIR(NULL,       S_IRUGO | S_IXUGO, xid),
23311 +};
23312 +
23313 +
23314 +static struct dentry *proc_virtual_lookup(struct inode *dir,
23315 +       struct dentry *dentry, struct nameidata *nd)
23316 +{
23317 +       struct vs_entry *p = vx_virtual_stuff;
23318 +       struct dentry *error = ERR_PTR(-ENOENT);
23319 +       int id = 0;
23320 +
23321 +       for (; p->name; p++) {
23322 +               if (p->len != dentry->d_name.len)
23323 +                       continue;
23324 +               if (!memcmp(dentry->d_name.name, p->name, p->len))
23325 +                       break;
23326 +       }
23327 +       if (p->name)
23328 +               goto instantiate;
23329 +
23330 +       id = atovid(dentry->d_name.name, dentry->d_name.len);
23331 +       if ((id < 0) || !xid_is_hashed(id))
23332 +               goto out;
23333 +
23334 +instantiate:
23335 +       error = proc_xid_instantiate(dir, dentry, id, p);
23336 +out:
23337 +       return error;
23338 +}
23339 +
23340 +static struct file_operations proc_nid_file_operations = {
23341 +       .read =         generic_read_dir,
23342 +       .readdir =      proc_nid_readdir,
23343 +};
23344 +
23345 +static struct inode_operations proc_nid_inode_operations = {
23346 +       .lookup =       proc_nid_lookup,
23347 +};
23348 +
23349 +static struct vs_entry nx_virtnet_stuff[] = {
23350 +       INF("info",     S_IRUGO, virtnet_info),
23351 +       INF("status",   S_IRUGO, virtnet_status),
23352 +       DIR(NULL,       S_IRUGO | S_IXUGO, nid),
23353 +};
23354 +
23355 +
23356 +static struct dentry *proc_virtnet_lookup(struct inode *dir,
23357 +       struct dentry *dentry, struct nameidata *nd)
23358 +{
23359 +       struct vs_entry *p = nx_virtnet_stuff;
23360 +       struct dentry *error = ERR_PTR(-ENOENT);
23361 +       int id = 0;
23362 +
23363 +       for (; p->name; p++) {
23364 +               if (p->len != dentry->d_name.len)
23365 +                       continue;
23366 +               if (!memcmp(dentry->d_name.name, p->name, p->len))
23367 +                       break;
23368 +       }
23369 +       if (p->name)
23370 +               goto instantiate;
23371 +
23372 +       id = atovid(dentry->d_name.name, dentry->d_name.len);
23373 +       if ((id < 0) || !nid_is_hashed(id))
23374 +               goto out;
23375 +
23376 +instantiate:
23377 +       error = proc_nid_instantiate(dir, dentry, id, p);
23378 +out:
23379 +       return error;
23380 +}
23381 +
23382 +
23383 +#define PROC_MAXVIDS 32
23384 +
23385 +int proc_virtual_readdir(struct file *filp,
23386 +       void *dirent, filldir_t filldir)
23387 +{
23388 +       struct dentry *dentry = filp->f_dentry;
23389 +       struct inode *inode = dentry->d_inode;
23390 +       struct vs_entry *p = vx_virtual_stuff;
23391 +       int size = sizeof(vx_virtual_stuff) / sizeof(struct vs_entry);
23392 +       int pos, index;
23393 +       unsigned int xid_array[PROC_MAXVIDS];
23394 +       char buf[PROC_NUMBUF];
23395 +       unsigned int nr_xids, i;
23396 +       u64 ino;
23397 +
23398 +       pos = filp->f_pos;
23399 +       switch (pos) {
23400 +       case 0:
23401 +               ino = inode->i_ino;
23402 +               if (filldir(dirent, ".", 1, pos, ino, DT_DIR) < 0)
23403 +                       goto out;
23404 +               pos++;
23405 +               /* fall through */
23406 +       case 1:
23407 +               ino = parent_ino(dentry);
23408 +               if (filldir(dirent, "..", 2, pos, ino, DT_DIR) < 0)
23409 +                       goto out;
23410 +               pos++;
23411 +               /* fall through */
23412 +       default:
23413 +               index = pos - 2;
23414 +               if (index >= size)
23415 +                       goto entries;
23416 +               for (p += index; p->name; p++) {
23417 +                       if (proc_fill_cache(filp, dirent, filldir, p->name, p->len,
23418 +                               vs_proc_instantiate, 0, p))
23419 +                               goto out;
23420 +                       pos++;
23421 +               }
23422 +       entries:
23423 +               index = pos - size;
23424 +               p = &vx_virtual_stuff[size - 1];
23425 +               nr_xids = get_xid_list(index, xid_array, PROC_MAXVIDS);
23426 +               for (i = 0; i < nr_xids; i++) {
23427 +                       int n, xid = xid_array[i];
23428 +                       unsigned int j = PROC_NUMBUF;
23429 +
23430 +                       n = xid;
23431 +                       do
23432 +                               buf[--j] = '0' + (n % 10);
23433 +                       while (n /= 10);
23434 +
23435 +                       if (proc_fill_cache(filp, dirent, filldir,
23436 +                               buf + j, PROC_NUMBUF - j,
23437 +                               vs_proc_instantiate, xid, p))
23438 +                               goto out;
23439 +                       pos++;
23440 +               }
23441 +       }
23442 +out:
23443 +       filp->f_pos = pos;
23444 +       return 0;
23445 +}
23446 +
23447 +static int proc_virtual_getattr(struct vfsmount *mnt,
23448 +       struct dentry *dentry, struct kstat *stat)
23449 +{
23450 +       struct inode *inode = dentry->d_inode;
23451 +
23452 +       generic_fillattr(inode, stat);
23453 +       stat->nlink = 2 + atomic_read(&vx_global_cactive);
23454 +       return 0;
23455 +}
23456 +
23457 +static struct file_operations proc_virtual_dir_operations = {
23458 +       .read =         generic_read_dir,
23459 +       .readdir =      proc_virtual_readdir,
23460 +};
23461 +
23462 +static struct inode_operations proc_virtual_dir_inode_operations = {
23463 +       .getattr =      proc_virtual_getattr,
23464 +       .lookup =       proc_virtual_lookup,
23465 +};
23466 +
23467 +
23468 +
23469 +
23470 +
23471 +int proc_virtnet_readdir(struct file *filp,
23472 +       void *dirent, filldir_t filldir)
23473 +{
23474 +       struct dentry *dentry = filp->f_dentry;
23475 +       struct inode *inode = dentry->d_inode;
23476 +       struct vs_entry *p = nx_virtnet_stuff;
23477 +       int size = sizeof(nx_virtnet_stuff) / sizeof(struct vs_entry);
23478 +       int pos, index;
23479 +       unsigned int nid_array[PROC_MAXVIDS];
23480 +       char buf[PROC_NUMBUF];
23481 +       unsigned int nr_nids, i;
23482 +       u64 ino;
23483 +
23484 +       pos = filp->f_pos;
23485 +       switch (pos) {
23486 +       case 0:
23487 +               ino = inode->i_ino;
23488 +               if (filldir(dirent, ".", 1, pos, ino, DT_DIR) < 0)
23489 +                       goto out;
23490 +               pos++;
23491 +               /* fall through */
23492 +       case 1:
23493 +               ino = parent_ino(dentry);
23494 +               if (filldir(dirent, "..", 2, pos, ino, DT_DIR) < 0)
23495 +                       goto out;
23496 +               pos++;
23497 +               /* fall through */
23498 +       default:
23499 +               index = pos - 2;
23500 +               if (index >= size)
23501 +                       goto entries;
23502 +               for (p += index; p->name; p++) {
23503 +                       if (proc_fill_cache(filp, dirent, filldir, p->name, p->len,
23504 +                               vs_proc_instantiate, 0, p))
23505 +                               goto out;
23506 +                       pos++;
23507 +               }
23508 +       entries:
23509 +               index = pos - size;
23510 +               p = &nx_virtnet_stuff[size - 1];
23511 +               nr_nids = get_nid_list(index, nid_array, PROC_MAXVIDS);
23512 +               for (i = 0; i < nr_nids; i++) {
23513 +                       int n, nid = nid_array[i];
23514 +                       unsigned int j = PROC_NUMBUF;
23515 +
23516 +                       n = nid;
23517 +                       do
23518 +                               buf[--j] = '0' + (n % 10);
23519 +                       while (n /= 10);
23520 +
23521 +                       if (proc_fill_cache(filp, dirent, filldir,
23522 +                               buf + j, PROC_NUMBUF - j,
23523 +                               vs_proc_instantiate, nid, p))
23524 +                               goto out;
23525 +                       pos++;
23526 +               }
23527 +       }
23528 +out:
23529 +       filp->f_pos = pos;
23530 +       return 0;
23531 +}
23532 +
23533 +static int proc_virtnet_getattr(struct vfsmount *mnt,
23534 +       struct dentry *dentry, struct kstat *stat)
23535 +{
23536 +       struct inode *inode = dentry->d_inode;
23537 +
23538 +       generic_fillattr(inode, stat);
23539 +       stat->nlink = 2 + atomic_read(&nx_global_cactive);
23540 +       return 0;
23541 +}
23542 +
23543 +static struct file_operations proc_virtnet_dir_operations = {
23544 +       .read =         generic_read_dir,
23545 +       .readdir =      proc_virtnet_readdir,
23546 +};
23547 +
23548 +static struct inode_operations proc_virtnet_dir_inode_operations = {
23549 +       .getattr =      proc_virtnet_getattr,
23550 +       .lookup =       proc_virtnet_lookup,
23551 +};
23552 +
23553 +
23554 +
23555 +void proc_vx_init(void)
23556 +{
23557 +       struct proc_dir_entry *ent;
23558 +
23559 +       ent = proc_mkdir("virtual", 0);
23560 +       if (ent) {
23561 +               ent->proc_fops = &proc_virtual_dir_operations;
23562 +               ent->proc_iops = &proc_virtual_dir_inode_operations;
23563 +       }
23564 +       proc_virtual = ent;
23565 +
23566 +       ent = proc_mkdir("virtnet", 0);
23567 +       if (ent) {
23568 +               ent->proc_fops = &proc_virtnet_dir_operations;
23569 +               ent->proc_iops = &proc_virtnet_dir_inode_operations;
23570 +       }
23571 +       proc_virtnet = ent;
23572 +}
23573 +
23574 +
23575 +
23576 +
23577 +/* per pid info */
23578 +
23579 +
23580 +int proc_pid_vx_info(struct task_struct *p, char *buffer)
23581 +{
23582 +       struct vx_info *vxi;
23583 +       char *orig = buffer;
23584 +
23585 +       buffer += sprintf(buffer, "XID:\t%d\n", vx_task_xid(p));
23586 +
23587 +       vxi = task_get_vx_info(p);
23588 +       if (!vxi)
23589 +               goto out;
23590 +
23591 +       buffer += sprintf(buffer, "BCaps:\t");
23592 +       buffer = print_cap_t(buffer, &vxi->vx_bcaps);
23593 +       buffer += sprintf(buffer, "\n");
23594 +       buffer += sprintf(buffer, "CCaps:\t%016llx\n",
23595 +               (unsigned long long)vxi->vx_ccaps);
23596 +       buffer += sprintf(buffer, "CFlags:\t%016llx\n",
23597 +               (unsigned long long)vxi->vx_flags);
23598 +       buffer += sprintf(buffer, "CIPid:\t%d\n", vxi->vx_initpid);
23599 +
23600 +       put_vx_info(vxi);
23601 +out:
23602 +       return buffer - orig;
23603 +}
23604 +
23605 +
23606 +int proc_pid_nx_info(struct task_struct *p, char *buffer)
23607 +{
23608 +       struct nx_info *nxi;
23609 +       struct nx_addr_v4 *v4a;
23610 +#ifdef CONFIG_IPV6
23611 +       struct nx_addr_v6 *v6a;
23612 +#endif
23613 +       char *orig = buffer;
23614 +       int i;
23615 +
23616 +       buffer += sprintf(buffer, "NID:\t%d\n", nx_task_nid(p));
23617 +
23618 +       nxi = task_get_nx_info(p);
23619 +       if (!nxi)
23620 +               goto out;
23621 +
23622 +       buffer += sprintf(buffer, "NCaps:\t%016llx\n",
23623 +               (unsigned long long)nxi->nx_ncaps);
23624 +       buffer += sprintf(buffer, "NFlags:\t%016llx\n",
23625 +               (unsigned long long)nxi->nx_flags);
23626 +
23627 +       buffer += sprintf(buffer,
23628 +               "V4Root[bcast]:\t" NIPQUAD_FMT "\n",
23629 +               NIPQUAD(nxi->v4_bcast.s_addr));
23630 +       buffer += sprintf (buffer,
23631 +               "V4Root[lback]:\t" NIPQUAD_FMT "\n",
23632 +               NIPQUAD(nxi->v4_lback.s_addr));
23633 +       if (!NX_IPV4(nxi))
23634 +               goto skip_v4;
23635 +       for (i = 0, v4a = &nxi->v4; v4a; i++, v4a = v4a->next)
23636 +               buffer += sprintf(buffer, "V4Root[%d]:\t" NXAV4_FMT "\n",
23637 +                       i, NXAV4(v4a));
23638 +skip_v4:
23639 +#ifdef CONFIG_IPV6
23640 +       if (!NX_IPV6(nxi))
23641 +               goto skip_v6;
23642 +       for (i = 0, v6a = &nxi->v6; v6a; i++, v6a = v6a->next)
23643 +               buffer += sprintf(buffer, "V6Root[%d]:\t" NXAV6_FMT "\n",
23644 +                       i, NXAV6(v6a));
23645 +skip_v6:
23646 +#endif
23647 +       put_nx_info(nxi);
23648 +out:
23649 +       return buffer - orig;
23650 +}
23651 +
23652 diff -NurpP --minimal linux-2.6.29.1/kernel/vserver/sched.c linux-2.6.29.1-vs2.3.0.36.9-pre5/kernel/vserver/sched.c
23653 --- linux-2.6.29.1/kernel/vserver/sched.c       1970-01-01 01:00:00.000000000 +0100
23654 +++ linux-2.6.29.1-vs2.3.0.36.9-pre5/kernel/vserver/sched.c     2009-02-22 22:54:26.000000000 +0100
23655 @@ -0,0 +1,414 @@
23656 +/*
23657 + *  linux/kernel/vserver/sched.c
23658 + *
23659 + *  Virtual Server: Scheduler Support
23660 + *
23661 + *  Copyright (C) 2004-2007  Herbert Pötzl
23662 + *
23663 + *  V0.01  adapted Sam Vilains version to 2.6.3
23664 + *  V0.02  removed legacy interface
23665 + *  V0.03  changed vcmds to vxi arg
23666 + *  V0.04  removed older and legacy interfaces
23667 + *
23668 + */
23669 +
23670 +#include <linux/vs_context.h>
23671 +#include <linux/vs_sched.h>
23672 +#include <linux/vserver/sched_cmd.h>
23673 +
23674 +#include <asm/uaccess.h>
23675 +
23676 +
23677 +#define vxd_check_range(val, min, max) do {            \
23678 +       vxlprintk((val < min) || (val > max),           \
23679 +               "check_range(%ld,%ld,%ld)",             \
23680 +               (long)val, (long)min, (long)max,        \
23681 +               __FILE__, __LINE__);                    \
23682 +       } while (0)
23683 +
23684 +
23685 +void vx_update_sched_param(struct _vx_sched *sched,
23686 +       struct _vx_sched_pc *sched_pc)
23687 +{
23688 +       unsigned int set_mask = sched->update_mask;
23689 +
23690 +       if (set_mask & VXSM_FILL_RATE)
23691 +               sched_pc->fill_rate[0] = sched->fill_rate[0];
23692 +       if (set_mask & VXSM_INTERVAL)
23693 +               sched_pc->interval[0] = sched->interval[0];
23694 +       if (set_mask & VXSM_FILL_RATE2)
23695 +               sched_pc->fill_rate[1] = sched->fill_rate[1];
23696 +       if (set_mask & VXSM_INTERVAL2)
23697 +               sched_pc->interval[1] = sched->interval[1];
23698 +       if (set_mask & VXSM_TOKENS)
23699 +               sched_pc->tokens = sched->tokens;
23700 +       if (set_mask & VXSM_TOKENS_MIN)
23701 +               sched_pc->tokens_min = sched->tokens_min;
23702 +       if (set_mask & VXSM_TOKENS_MAX)
23703 +               sched_pc->tokens_max = sched->tokens_max;
23704 +       if (set_mask & VXSM_PRIO_BIAS)
23705 +               sched_pc->prio_bias = sched->prio_bias;
23706 +
23707 +       if (set_mask & VXSM_IDLE_TIME)
23708 +               sched_pc->flags |= VXSF_IDLE_TIME;
23709 +       else
23710 +               sched_pc->flags &= ~VXSF_IDLE_TIME;
23711 +
23712 +       /* reset time */
23713 +       sched_pc->norm_time = jiffies;
23714 +}
23715 +
23716 +
23717 +/*
23718 + * recalculate the context's scheduling tokens
23719 + *
23720 + * ret > 0 : number of tokens available
23721 + * ret < 0 : on hold, check delta_min[]
23722 + *          -1 only jiffies
23723 + *          -2 also idle time
23724 + *
23725 + */
23726 +int vx_tokens_recalc(struct _vx_sched_pc *sched_pc,
23727 +       unsigned long *norm_time, unsigned long *idle_time, int delta_min[2])
23728 +{
23729 +       long delta;
23730 +       long tokens = 0;
23731 +       int flags = sched_pc->flags;
23732 +
23733 +       /* how much time did pass? */
23734 +       delta = *norm_time - sched_pc->norm_time;
23735 +       // printk("@ %ld, %ld, %ld\n", *norm_time, sched_pc->norm_time, jiffies);
23736 +       vxd_check_range(delta, 0, INT_MAX);
23737 +
23738 +       if (delta >= sched_pc->interval[0]) {
23739 +               long tokens, integral;
23740 +
23741 +               /* calc integral token part */
23742 +               tokens = delta / sched_pc->interval[0];
23743 +               integral = tokens * sched_pc->interval[0];
23744 +               tokens *= sched_pc->fill_rate[0];
23745 +#ifdef CONFIG_VSERVER_HARDCPU
23746 +               delta_min[0] = delta - integral;
23747 +               vxd_check_range(delta_min[0], 0, sched_pc->interval[0]);
23748 +#endif
23749 +               /* advance time */
23750 +               sched_pc->norm_time += delta;
23751 +
23752 +               /* add tokens */
23753 +               sched_pc->tokens += tokens;
23754 +               sched_pc->token_time += tokens;
23755 +       } else
23756 +               delta_min[0] = delta;
23757 +
23758 +#ifdef CONFIG_VSERVER_IDLETIME
23759 +       if (!(flags & VXSF_IDLE_TIME))
23760 +               goto skip_idle;
23761 +
23762 +       /* how much was the idle skip? */
23763 +       delta = *idle_time - sched_pc->idle_time;
23764 +       vxd_check_range(delta, 0, INT_MAX);
23765 +
23766 +       if (delta >= sched_pc->interval[1]) {
23767 +               long tokens, integral;
23768 +
23769 +               /* calc fair share token part */
23770 +               tokens = delta / sched_pc->interval[1];
23771 +               integral = tokens * sched_pc->interval[1];
23772 +               tokens *= sched_pc->fill_rate[1];
23773 +               delta_min[1] = delta - integral;
23774 +               vxd_check_range(delta_min[1], 0, sched_pc->interval[1]);
23775 +
23776 +               /* advance idle time */
23777 +               sched_pc->idle_time += integral;
23778 +
23779 +               /* add tokens */
23780 +               sched_pc->tokens += tokens;
23781 +               sched_pc->token_time += tokens;
23782 +       } else
23783 +               delta_min[1] = delta;
23784 +skip_idle:
23785 +#endif
23786 +
23787 +       /* clip at maximum */
23788 +       if (sched_pc->tokens > sched_pc->tokens_max)
23789 +               sched_pc->tokens = sched_pc->tokens_max;
23790 +       tokens = sched_pc->tokens;
23791 +
23792 +       if ((flags & VXSF_ONHOLD)) {
23793 +               /* can we unhold? */
23794 +               if (tokens >= sched_pc->tokens_min) {
23795 +                       flags &= ~VXSF_ONHOLD;
23796 +                       sched_pc->hold_ticks +=
23797 +                               *norm_time - sched_pc->onhold;
23798 +               } else
23799 +                       goto on_hold;
23800 +       } else {
23801 +               /* put on hold? */
23802 +               if (tokens <= 0) {
23803 +                       flags |= VXSF_ONHOLD;
23804 +                       sched_pc->onhold = *norm_time;
23805 +                       goto on_hold;
23806 +               }
23807 +       }
23808 +       sched_pc->flags = flags;
23809 +       return tokens;
23810 +
23811 +on_hold:
23812 +       tokens = sched_pc->tokens_min - tokens;
23813 +       sched_pc->flags = flags;
23814 +       // BUG_ON(tokens < 0); probably doesn't hold anymore
23815 +
23816 +#ifdef CONFIG_VSERVER_HARDCPU
23817 +       /* next interval? */
23818 +       if (!sched_pc->fill_rate[0])
23819 +               delta_min[0] = HZ;
23820 +       else if (tokens > sched_pc->fill_rate[0])
23821 +               delta_min[0] += sched_pc->interval[0] *
23822 +                       tokens / sched_pc->fill_rate[0];
23823 +       else
23824 +               delta_min[0] = sched_pc->interval[0] - delta_min[0];
23825 +       vxd_check_range(delta_min[0], 0, INT_MAX);
23826 +
23827 +#ifdef CONFIG_VSERVER_IDLETIME
23828 +       if (!(flags & VXSF_IDLE_TIME))
23829 +               return -1;
23830 +
23831 +       /* next interval? */
23832 +       if (!sched_pc->fill_rate[1])
23833 +               delta_min[1] = HZ;
23834 +       else if (tokens > sched_pc->fill_rate[1])
23835 +               delta_min[1] += sched_pc->interval[1] *
23836 +                       tokens / sched_pc->fill_rate[1];
23837 +       else
23838 +               delta_min[1] = sched_pc->interval[1] - delta_min[1];
23839 +       vxd_check_range(delta_min[1], 0, INT_MAX);
23840 +
23841 +       return -2;
23842 +#else
23843 +       return -1;
23844 +#endif /* CONFIG_VSERVER_IDLETIME */
23845 +#else
23846 +       return 0;
23847 +#endif /* CONFIG_VSERVER_HARDCPU */
23848 +}
23849 +
23850 +static inline unsigned long msec_to_ticks(unsigned long msec)
23851 +{
23852 +       return msecs_to_jiffies(msec);
23853 +}
23854 +
23855 +static inline unsigned long ticks_to_msec(unsigned long ticks)
23856 +{
23857 +       return jiffies_to_msecs(ticks);
23858 +}
23859 +
23860 +static inline unsigned long ticks_to_usec(unsigned long ticks)
23861 +{
23862 +       return jiffies_to_usecs(ticks);
23863 +}
23864 +
23865 +
23866 +static int do_set_sched(struct vx_info *vxi, struct vcmd_sched_v5 *data)
23867 +{
23868 +       unsigned int set_mask = data->mask;
23869 +       unsigned int update_mask;
23870 +       int i, cpu;
23871 +
23872 +       /* Sanity check data values */
23873 +       if (data->tokens_max <= 0)
23874 +               data->tokens_max = HZ;
23875 +       if (data->tokens_min < 0)
23876 +               data->tokens_min = HZ / 3;
23877 +       if (data->tokens_min >= data->tokens_max)
23878 +               data->tokens_min = data->tokens_max;
23879 +
23880 +       if (data->prio_bias > MAX_PRIO_BIAS)
23881 +               data->prio_bias = MAX_PRIO_BIAS;
23882 +       if (data->prio_bias < MIN_PRIO_BIAS)
23883 +               data->prio_bias = MIN_PRIO_BIAS;
23884 +
23885 +       spin_lock(&vxi->sched.tokens_lock);
23886 +
23887 +       /* sync up on delayed updates */
23888 +       for_each_cpu_mask(cpu, vxi->sched.update)
23889 +               vx_update_sched_param(&vxi->sched,
23890 +                       &vx_per_cpu(vxi, sched_pc, cpu));
23891 +
23892 +       if (set_mask & VXSM_FILL_RATE)
23893 +               vxi->sched.fill_rate[0] = data->fill_rate[0];
23894 +       if (set_mask & VXSM_FILL_RATE2)
23895 +               vxi->sched.fill_rate[1] = data->fill_rate[1];
23896 +       if (set_mask & VXSM_INTERVAL)
23897 +               vxi->sched.interval[0] = (set_mask & VXSM_MSEC) ?
23898 +                       msec_to_ticks(data->interval[0]) : data->interval[0];
23899 +       if (set_mask & VXSM_INTERVAL2)
23900 +               vxi->sched.interval[1] = (set_mask & VXSM_MSEC) ?
23901 +                       msec_to_ticks(data->interval[1]) : data->interval[1];
23902 +       if (set_mask & VXSM_TOKENS)
23903 +               vxi->sched.tokens = data->tokens;
23904 +       if (set_mask & VXSM_TOKENS_MIN)
23905 +               vxi->sched.tokens_min = data->tokens_min;
23906 +       if (set_mask & VXSM_TOKENS_MAX)
23907 +               vxi->sched.tokens_max = data->tokens_max;
23908 +       if (set_mask & VXSM_PRIO_BIAS)
23909 +               vxi->sched.prio_bias = data->prio_bias;
23910 +
23911 +       /* Sanity check rate/interval */
23912 +       for (i = 0; i < 2; i++) {
23913 +               if (data->fill_rate[i] < 0)
23914 +                       data->fill_rate[i] = 0;
23915 +               if (data->interval[i] <= 0)
23916 +                       data->interval[i] = HZ;
23917 +       }
23918 +
23919 +       update_mask = vxi->sched.update_mask & VXSM_SET_MASK;
23920 +       update_mask |= (set_mask & (VXSM_SET_MASK | VXSM_IDLE_TIME));
23921 +       vxi->sched.update_mask = update_mask;
23922 +
23923 +#ifdef CONFIG_SMP
23924 +       rmb();
23925 +       if (set_mask & VXSM_CPU_ID) {
23926 +               vxi->sched.update = cpumask_of_cpu(data->cpu_id);
23927 +               cpus_and(vxi->sched.update, cpu_online_map,
23928 +                       vxi->sched.update);
23929 +       } else
23930 +               vxi->sched.update = cpu_online_map;
23931 +
23932 +       /* forced reload? */
23933 +       if (set_mask & VXSM_FORCE) {
23934 +               for_each_cpu_mask(cpu, vxi->sched.update)
23935 +                       vx_update_sched_param(&vxi->sched,
23936 +                               &vx_per_cpu(vxi, sched_pc, cpu));
23937 +               vxi->sched.update = CPU_MASK_NONE;
23938 +       }
23939 +#else
23940 +       /* on UP we update immediately */
23941 +       vx_update_sched_param(&vxi->sched,
23942 +               &vx_per_cpu(vxi, sched_pc, 0));
23943 +#endif
23944 +
23945 +       spin_unlock(&vxi->sched.tokens_lock);
23946 +       return 0;
23947 +}
23948 +
23949 +
23950 +#define COPY_IDS(C) C(cpu_id); C(bucket_id)
23951 +#define COPY_PRI(C) C(prio_bias)
23952 +#define COPY_TOK(C) C(tokens); C(tokens_min); C(tokens_max)
23953 +#define COPY_FRI(C) C(fill_rate[0]); C(interval[0]);   \
23954 +                   C(fill_rate[1]); C(interval[1]);
23955 +
23956 +#define COPY_VALUE(name) vc_data.name = data->name
23957 +
23958 +static int do_set_sched_v4(struct vx_info *vxi, struct vcmd_set_sched_v4 *data)
23959 +{
23960 +       struct vcmd_sched_v5 vc_data;
23961 +
23962 +       vc_data.mask = data->set_mask;
23963 +       COPY_IDS(COPY_VALUE);
23964 +       COPY_PRI(COPY_VALUE);
23965 +       COPY_TOK(COPY_VALUE);
23966 +       vc_data.fill_rate[0] = vc_data.fill_rate[1] = data->fill_rate;
23967 +       vc_data.interval[0] = vc_data.interval[1] = data->interval;
23968 +       return do_set_sched(vxi, &vc_data);
23969 +}
23970 +
23971 +int vc_set_sched_v4(struct vx_info *vxi, void __user *data)
23972 +{
23973 +       struct vcmd_set_sched_v4 vc_data;
23974 +
23975 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
23976 +               return -EFAULT;
23977 +
23978 +       return do_set_sched_v4(vxi, &vc_data);
23979 +}
23980 +
23981 +       /* latest interface is v5 */
23982 +
23983 +int vc_set_sched(struct vx_info *vxi, void __user *data)
23984 +{
23985 +       struct vcmd_sched_v5 vc_data;
23986 +
23987 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
23988 +               return -EFAULT;
23989 +
23990 +       return do_set_sched(vxi, &vc_data);
23991 +}
23992 +
23993 +
23994 +#define COPY_PRI(C) C(prio_bias)
23995 +#define COPY_TOK(C) C(tokens); C(tokens_min); C(tokens_max)
23996 +#define COPY_FRI(C) C(fill_rate[0]); C(interval[0]);    \
23997 +                   C(fill_rate[1]); C(interval[1]);
23998 +
23999 +#define COPY_VALUE(name) vc_data.name = data->name
24000 +
24001 +
24002 +int vc_get_sched(struct vx_info *vxi, void __user *data)
24003 +{
24004 +       struct vcmd_sched_v5 vc_data;
24005 +
24006 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
24007 +               return -EFAULT;
24008 +
24009 +       if (vc_data.mask & VXSM_CPU_ID) {
24010 +               int cpu = vc_data.cpu_id;
24011 +               struct _vx_sched_pc *data;
24012 +
24013 +               if (!cpu_possible(cpu))
24014 +                       return -EINVAL;
24015 +
24016 +               data = &vx_per_cpu(vxi, sched_pc, cpu);
24017 +               COPY_TOK(COPY_VALUE);
24018 +               COPY_PRI(COPY_VALUE);
24019 +               COPY_FRI(COPY_VALUE);
24020 +
24021 +               if (data->flags & VXSF_IDLE_TIME)
24022 +                       vc_data.mask |= VXSM_IDLE_TIME;
24023 +       } else {
24024 +               struct _vx_sched *data = &vxi->sched;
24025 +
24026 +               COPY_TOK(COPY_VALUE);
24027 +               COPY_PRI(COPY_VALUE);
24028 +               COPY_FRI(COPY_VALUE);
24029 +       }
24030 +
24031 +       if (vc_data.mask & VXSM_MSEC) {
24032 +               vc_data.interval[0] = ticks_to_msec(vc_data.interval[0]);
24033 +               vc_data.interval[1] = ticks_to_msec(vc_data.interval[1]);
24034 +       }
24035 +
24036 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
24037 +               return -EFAULT;
24038 +       return 0;
24039 +}
24040 +
24041 +
24042 +int vc_sched_info(struct vx_info *vxi, void __user *data)
24043 +{
24044 +       struct vcmd_sched_info vc_data;
24045 +       int cpu;
24046 +
24047 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
24048 +               return -EFAULT;
24049 +
24050 +       cpu = vc_data.cpu_id;
24051 +       if (!cpu_possible(cpu))
24052 +               return -EINVAL;
24053 +
24054 +       if (vxi) {
24055 +               struct _vx_sched_pc *sched_pc =
24056 +                       &vx_per_cpu(vxi, sched_pc, cpu);
24057 +
24058 +               vc_data.user_msec = ticks_to_msec(sched_pc->user_ticks);
24059 +               vc_data.sys_msec = ticks_to_msec(sched_pc->sys_ticks);
24060 +               vc_data.hold_msec = ticks_to_msec(sched_pc->hold_ticks);
24061 +               vc_data.vavavoom = sched_pc->vavavoom;
24062 +       }
24063 +       vc_data.token_usec = ticks_to_usec(1);
24064 +
24065 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
24066 +               return -EFAULT;
24067 +       return 0;
24068 +}
24069 +
24070 diff -NurpP --minimal linux-2.6.29.1/kernel/vserver/sched_init.h linux-2.6.29.1-vs2.3.0.36.9-pre5/kernel/vserver/sched_init.h
24071 --- linux-2.6.29.1/kernel/vserver/sched_init.h  1970-01-01 01:00:00.000000000 +0100
24072 +++ linux-2.6.29.1-vs2.3.0.36.9-pre5/kernel/vserver/sched_init.h        2009-02-22 22:54:26.000000000 +0100
24073 @@ -0,0 +1,50 @@
24074 +
24075 +static inline void vx_info_init_sched(struct _vx_sched *sched)
24076 +{
24077 +       static struct lock_class_key tokens_lock_key;
24078 +
24079 +       /* scheduling; hard code starting values as constants */
24080 +       sched->fill_rate[0]     = 1;
24081 +       sched->interval[0]      = 4;
24082 +       sched->fill_rate[1]     = 1;
24083 +       sched->interval[1]      = 8;
24084 +       sched->tokens           = HZ >> 2;
24085 +       sched->tokens_min       = HZ >> 4;
24086 +       sched->tokens_max       = HZ >> 1;
24087 +       sched->tokens_lock      = SPIN_LOCK_UNLOCKED;
24088 +       sched->prio_bias        = 0;
24089 +
24090 +       lockdep_set_class(&sched->tokens_lock, &tokens_lock_key);
24091 +}
24092 +
24093 +static inline
24094 +void vx_info_init_sched_pc(struct _vx_sched_pc *sched_pc, int cpu)
24095 +{
24096 +       sched_pc->fill_rate[0]  = 1;
24097 +       sched_pc->interval[0]   = 4;
24098 +       sched_pc->fill_rate[1]  = 1;
24099 +       sched_pc->interval[1]   = 8;
24100 +       sched_pc->tokens        = HZ >> 2;
24101 +       sched_pc->tokens_min    = HZ >> 4;
24102 +       sched_pc->tokens_max    = HZ >> 1;
24103 +       sched_pc->prio_bias     = 0;
24104 +       sched_pc->vavavoom      = 0;
24105 +       sched_pc->token_time    = 0;
24106 +       sched_pc->idle_time     = 0;
24107 +       sched_pc->norm_time     = jiffies;
24108 +
24109 +       sched_pc->user_ticks = 0;
24110 +       sched_pc->sys_ticks = 0;
24111 +       sched_pc->hold_ticks = 0;
24112 +}
24113 +
24114 +static inline void vx_info_exit_sched(struct _vx_sched *sched)
24115 +{
24116 +       return;
24117 +}
24118 +
24119 +static inline
24120 +void vx_info_exit_sched_pc(struct _vx_sched_pc *sched_pc, int cpu)
24121 +{
24122 +       return;
24123 +}
24124 diff -NurpP --minimal linux-2.6.29.1/kernel/vserver/sched_proc.h linux-2.6.29.1-vs2.3.0.36.9-pre5/kernel/vserver/sched_proc.h
24125 --- linux-2.6.29.1/kernel/vserver/sched_proc.h  1970-01-01 01:00:00.000000000 +0100
24126 +++ linux-2.6.29.1-vs2.3.0.36.9-pre5/kernel/vserver/sched_proc.h        2009-02-22 22:54:26.000000000 +0100
24127 @@ -0,0 +1,57 @@
24128 +#ifndef _VX_SCHED_PROC_H
24129 +#define _VX_SCHED_PROC_H
24130 +
24131 +
24132 +static inline
24133 +int vx_info_proc_sched(struct _vx_sched *sched, char *buffer)
24134 +{
24135 +       int length = 0;
24136 +
24137 +       length += sprintf(buffer,
24138 +               "FillRate:\t%8d,%d\n"
24139 +               "Interval:\t%8d,%d\n"
24140 +               "TokensMin:\t%8d\n"
24141 +               "TokensMax:\t%8d\n"
24142 +               "PrioBias:\t%8d\n",
24143 +               sched->fill_rate[0],
24144 +               sched->fill_rate[1],
24145 +               sched->interval[0],
24146 +               sched->interval[1],
24147 +               sched->tokens_min,
24148 +               sched->tokens_max,
24149 +               sched->prio_bias);
24150 +       return length;
24151 +}
24152 +
24153 +static inline
24154 +int vx_info_proc_sched_pc(struct _vx_sched_pc *sched_pc,
24155 +       char *buffer, int cpu)
24156 +{
24157 +       int length = 0;
24158 +
24159 +       length += sprintf(buffer + length,
24160 +               "cpu %d: %lld %lld %lld %ld %ld", cpu,
24161 +               (unsigned long long)sched_pc->user_ticks,
24162 +               (unsigned long long)sched_pc->sys_ticks,
24163 +               (unsigned long long)sched_pc->hold_ticks,
24164 +               sched_pc->token_time,
24165 +               sched_pc->idle_time);
24166 +       length += sprintf(buffer + length,
24167 +               " %c%c %d %d %d %d/%d %d/%d",
24168 +               (sched_pc->flags & VXSF_ONHOLD) ? 'H' : 'R',
24169 +               (sched_pc->flags & VXSF_IDLE_TIME) ? 'I' : '-',
24170 +               sched_pc->tokens,
24171 +               sched_pc->tokens_min,
24172 +               sched_pc->tokens_max,
24173 +               sched_pc->fill_rate[0],
24174 +               sched_pc->interval[0],
24175 +               sched_pc->fill_rate[1],
24176 +               sched_pc->interval[1]);
24177 +       length += sprintf(buffer + length,
24178 +               " %d %d\n",
24179 +               sched_pc->prio_bias,
24180 +               sched_pc->vavavoom);
24181 +       return length;
24182 +}
24183 +
24184 +#endif /* _VX_SCHED_PROC_H */
24185 diff -NurpP --minimal linux-2.6.29.1/kernel/vserver/signal.c linux-2.6.29.1-vs2.3.0.36.9-pre5/kernel/vserver/signal.c
24186 --- linux-2.6.29.1/kernel/vserver/signal.c      1970-01-01 01:00:00.000000000 +0100
24187 +++ linux-2.6.29.1-vs2.3.0.36.9-pre5/kernel/vserver/signal.c    2009-02-22 22:54:26.000000000 +0100
24188 @@ -0,0 +1,132 @@
24189 +/*
24190 + *  linux/kernel/vserver/signal.c
24191 + *
24192 + *  Virtual Server: Signal Support
24193 + *
24194 + *  Copyright (C) 2003-2007  Herbert Pötzl
24195 + *
24196 + *  V0.01  broken out from vcontext V0.05
24197 + *  V0.02  changed vcmds to vxi arg
24198 + *  V0.03  adjusted siginfo for kill
24199 + *
24200 + */
24201 +
24202 +#include <asm/uaccess.h>
24203 +
24204 +#include <linux/vs_context.h>
24205 +#include <linux/vs_pid.h>
24206 +#include <linux/vserver/signal_cmd.h>
24207 +
24208 +
24209 +int vx_info_kill(struct vx_info *vxi, int pid, int sig)
24210 +{
24211 +       int retval, count = 0;
24212 +       struct task_struct *p;
24213 +       struct siginfo *sip = SEND_SIG_PRIV;
24214 +
24215 +       retval = -ESRCH;
24216 +       vxdprintk(VXD_CBIT(misc, 4),
24217 +               "vx_info_kill(%p[#%d],%d,%d)*",
24218 +               vxi, vxi->vx_id, pid, sig);
24219 +       read_lock(&tasklist_lock);
24220 +       switch (pid) {
24221 +       case  0:
24222 +       case -1:
24223 +               for_each_process(p) {
24224 +                       int err = 0;
24225 +
24226 +                       if (vx_task_xid(p) != vxi->vx_id || p->pid <= 1 ||
24227 +                               (pid && vxi->vx_initpid == p->pid))
24228 +                               continue;
24229 +
24230 +                       err = group_send_sig_info(sig, sip, p);
24231 +                       ++count;
24232 +                       if (err != -EPERM)
24233 +                               retval = err;
24234 +               }
24235 +               break;
24236 +
24237 +       case 1:
24238 +               if (vxi->vx_initpid) {
24239 +                       pid = vxi->vx_initpid;
24240 +                       /* for now, only SIGINT to private init ... */
24241 +                       if (!vx_info_flags(vxi, VXF_STATE_ADMIN, 0) &&
24242 +                               /* ... as long as there are tasks left */
24243 +                               (atomic_read(&vxi->vx_tasks) > 1))
24244 +                               sig = SIGINT;
24245 +               }
24246 +               /* fallthrough */
24247 +       default:
24248 +               p = find_task_by_real_pid(pid);
24249 +               if (p) {
24250 +                       if (vx_task_xid(p) == vxi->vx_id)
24251 +                               retval = group_send_sig_info(sig, sip, p);
24252 +               }
24253 +               break;
24254 +       }
24255 +       read_unlock(&tasklist_lock);
24256 +       vxdprintk(VXD_CBIT(misc, 4),
24257 +               "vx_info_kill(%p[#%d],%d,%d,%ld) = %d",
24258 +               vxi, vxi->vx_id, pid, sig, (long)sip, retval);
24259 +       return retval;
24260 +}
24261 +
24262 +int vc_ctx_kill(struct vx_info *vxi, void __user *data)
24263 +{
24264 +       struct vcmd_ctx_kill_v0 vc_data;
24265 +
24266 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
24267 +               return -EFAULT;
24268 +
24269 +       /* special check to allow guest shutdown */
24270 +       if (!vx_info_flags(vxi, VXF_STATE_ADMIN, 0) &&
24271 +               /* forbid killall pid=0 when init is present */
24272 +               (((vc_data.pid < 1) && vxi->vx_initpid) ||
24273 +               (vc_data.pid > 1)))
24274 +               return -EACCES;
24275 +
24276 +       return vx_info_kill(vxi, vc_data.pid, vc_data.sig);
24277 +}
24278 +
24279 +
24280 +static int __wait_exit(struct vx_info *vxi)
24281 +{
24282 +       DECLARE_WAITQUEUE(wait, current);
24283 +       int ret = 0;
24284 +
24285 +       add_wait_queue(&vxi->vx_wait, &wait);
24286 +       set_current_state(TASK_INTERRUPTIBLE);
24287 +
24288 +wait:
24289 +       if (vx_info_state(vxi,
24290 +               VXS_SHUTDOWN | VXS_HASHED | VXS_HELPER) == VXS_SHUTDOWN)
24291 +               goto out;
24292 +       if (signal_pending(current)) {
24293 +               ret = -ERESTARTSYS;
24294 +               goto out;
24295 +       }
24296 +       schedule();
24297 +       goto wait;
24298 +
24299 +out:
24300 +       set_current_state(TASK_RUNNING);
24301 +       remove_wait_queue(&vxi->vx_wait, &wait);
24302 +       return ret;
24303 +}
24304 +
24305 +
24306 +
24307 +int vc_wait_exit(struct vx_info *vxi, void __user *data)
24308 +{
24309 +       struct vcmd_wait_exit_v0 vc_data;
24310 +       int ret;
24311 +
24312 +       ret = __wait_exit(vxi);
24313 +       vc_data.reboot_cmd = vxi->reboot_cmd;
24314 +       vc_data.exit_code = vxi->exit_code;
24315 +
24316 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
24317 +               ret = -EFAULT;
24318 +       return ret;
24319 +}
24320 +
24321 diff -NurpP --minimal linux-2.6.29.1/kernel/vserver/space.c linux-2.6.29.1-vs2.3.0.36.9-pre5/kernel/vserver/space.c
24322 --- linux-2.6.29.1/kernel/vserver/space.c       1970-01-01 01:00:00.000000000 +0100
24323 +++ linux-2.6.29.1-vs2.3.0.36.9-pre5/kernel/vserver/space.c     2009-04-03 21:25:31.000000000 +0200
24324 @@ -0,0 +1,387 @@
24325 +/*
24326 + *  linux/kernel/vserver/space.c
24327 + *
24328 + *  Virtual Server: Context Space Support
24329 + *
24330 + *  Copyright (C) 2003-2007  Herbert Pötzl
24331 + *
24332 + *  V0.01  broken out from context.c 0.07
24333 + *  V0.02  added task locking for namespace
24334 + *  V0.03  broken out vx_enter_namespace
24335 + *  V0.04  added *space support and commands
24336 + *
24337 + */
24338 +
24339 +#include <linux/utsname.h>
24340 +#include <linux/nsproxy.h>
24341 +#include <linux/err.h>
24342 +#include <asm/uaccess.h>
24343 +
24344 +#include <linux/vs_context.h>
24345 +#include <linux/vserver/space.h>
24346 +#include <linux/vserver/space_cmd.h>
24347 +
24348 +atomic_t vs_global_nsproxy     = ATOMIC_INIT(0);
24349 +atomic_t vs_global_fs          = ATOMIC_INIT(0);
24350 +atomic_t vs_global_mnt_ns      = ATOMIC_INIT(0);
24351 +atomic_t vs_global_uts_ns      = ATOMIC_INIT(0);
24352 +atomic_t vs_global_ipc_ns      = ATOMIC_INIT(0);
24353 +atomic_t vs_global_user_ns     = ATOMIC_INIT(0);
24354 +atomic_t vs_global_pid_ns      = ATOMIC_INIT(0);
24355 +
24356 +
24357 +/* namespace functions */
24358 +
24359 +#include <linux/mnt_namespace.h>
24360 +#include <linux/user_namespace.h>
24361 +#include <linux/pid_namespace.h>
24362 +#include <linux/ipc_namespace.h>
24363 +#include <net/net_namespace.h>
24364 +
24365 +
24366 +static const struct vcmd_space_mask_v1 space_mask_v0 = {
24367 +       .mask = CLONE_FS |
24368 +               CLONE_NEWNS |
24369 +               CLONE_NEWUTS |
24370 +               CLONE_NEWIPC |
24371 +               CLONE_NEWUSER |
24372 +               0
24373 +};
24374 +
24375 +static const struct vcmd_space_mask_v1 space_mask = {
24376 +       .mask = CLONE_FS |
24377 +               CLONE_NEWNS |
24378 +               CLONE_NEWUTS |
24379 +               CLONE_NEWIPC |
24380 +               CLONE_NEWUSER |
24381 +#ifdef CONFIG_PID_NS
24382 +               CLONE_NEWPID |
24383 +#endif
24384 +#ifdef CONFIG_NET_NS
24385 +               CLONE_NEWNET |
24386 +#endif
24387 +               0
24388 +};
24389 +
24390 +static const struct vcmd_space_mask_v1 default_space_mask = {
24391 +       .mask = CLONE_FS |
24392 +               CLONE_NEWNS |
24393 +               CLONE_NEWUTS |
24394 +               CLONE_NEWIPC |
24395 +               CLONE_NEWUSER |
24396 +#ifdef CONFIG_PID_NS
24397 +//             CLONE_NEWPID |
24398 +#endif
24399 +               0
24400 +};
24401 +
24402 +/*
24403 + *     build a new nsproxy mix
24404 + *      assumes that both proxies are 'const'
24405 + *     does not touch nsproxy refcounts
24406 + *     will hold a reference on the result.
24407 + */
24408 +
24409 +struct nsproxy *vs_mix_nsproxy(struct nsproxy *old_nsproxy,
24410 +       struct nsproxy *new_nsproxy, unsigned long mask)
24411 +{
24412 +       struct mnt_namespace *old_ns;
24413 +       struct uts_namespace *old_uts;
24414 +       struct ipc_namespace *old_ipc;
24415 +#ifdef CONFIG_PID_NS
24416 +       struct pid_namespace *old_pid;
24417 +#endif
24418 +#ifdef CONFIG_NET_NS
24419 +       struct net *old_net;
24420 +#endif
24421 +       struct nsproxy *nsproxy;
24422 +
24423 +       nsproxy = copy_nsproxy(old_nsproxy);
24424 +       if (!nsproxy)
24425 +               goto out;
24426 +
24427 +       if (mask & CLONE_NEWNS) {
24428 +               old_ns = nsproxy->mnt_ns;
24429 +               nsproxy->mnt_ns = new_nsproxy->mnt_ns;
24430 +               if (nsproxy->mnt_ns)
24431 +                       get_mnt_ns(nsproxy->mnt_ns);
24432 +       } else
24433 +               old_ns = NULL;
24434 +
24435 +       if (mask & CLONE_NEWUTS) {
24436 +               old_uts = nsproxy->uts_ns;
24437 +               nsproxy->uts_ns = new_nsproxy->uts_ns;
24438 +               if (nsproxy->uts_ns)
24439 +                       get_uts_ns(nsproxy->uts_ns);
24440 +       } else
24441 +               old_uts = NULL;
24442 +
24443 +       if (mask & CLONE_NEWIPC) {
24444 +               old_ipc = nsproxy->ipc_ns;
24445 +               nsproxy->ipc_ns = new_nsproxy->ipc_ns;
24446 +               if (nsproxy->ipc_ns)
24447 +                       get_ipc_ns(nsproxy->ipc_ns);
24448 +       } else
24449 +               old_ipc = NULL;
24450 +
24451 +#ifdef CONFIG_PID_NS
24452 +       if (mask & CLONE_NEWPID) {
24453 +               old_pid = nsproxy->pid_ns;
24454 +               nsproxy->pid_ns = new_nsproxy->pid_ns;
24455 +               if (nsproxy->pid_ns)
24456 +                       get_pid_ns(nsproxy->pid_ns);
24457 +       } else
24458 +               old_pid = NULL;
24459 +#endif
24460 +#ifdef CONFIG_NET_NS
24461 +       if (mask & CLONE_NEWNET) {
24462 +               old_net = nsproxy->net_ns;
24463 +               nsproxy->net_ns = new_nsproxy->net_ns;
24464 +               if (nsproxy->net_ns)
24465 +                       get_net(nsproxy->net_ns);
24466 +       } else
24467 +               old_net = NULL;
24468 +#endif
24469 +       if (old_ns)
24470 +               put_mnt_ns(old_ns);
24471 +       if (old_uts)
24472 +               put_uts_ns(old_uts);
24473 +       if (old_ipc)
24474 +               put_ipc_ns(old_ipc);
24475 +#ifdef CONFIG_PID_NS
24476 +       if (old_pid)
24477 +               put_pid_ns(old_pid);
24478 +#endif
24479 +#ifdef CONFIG_NET_NS
24480 +       if (old_net)
24481 +               put_net(old_net);
24482 +#endif
24483 +out:
24484 +       return nsproxy;
24485 +}
24486 +
24487 +
24488 +/*
24489 + *     merge two nsproxy structs into a new one.
24490 + *     will hold a reference on the result.
24491 + */
24492 +
24493 +static inline
24494 +struct nsproxy *__vs_merge_nsproxy(struct nsproxy *old,
24495 +       struct nsproxy *proxy, unsigned long mask)
24496 +{
24497 +       struct nsproxy null_proxy = { .mnt_ns = NULL };
24498 +
24499 +       if (!proxy)
24500 +               return NULL;
24501 +
24502 +       if (mask) {
24503 +               /* vs_mix_nsproxy returns with reference */
24504 +               return vs_mix_nsproxy(old ? old : &null_proxy,
24505 +                       proxy, mask);
24506 +       }
24507 +       get_nsproxy(proxy);
24508 +       return proxy;
24509 +}
24510 +
24511 +/*
24512 + *     merge two fs structs into a new one.
24513 + *     will take a reference on the result.
24514 + */
24515 +
24516 +static inline
24517 +struct fs_struct *__vs_merge_fs(struct fs_struct *old,
24518 +       struct fs_struct *fs, unsigned long mask)
24519 +{
24520 +       if (!(mask & CLONE_FS)) {
24521 +               if (old)
24522 +                       atomic_inc(&old->count);
24523 +               return old;
24524 +       }
24525 +
24526 +       if (!fs)
24527 +               return NULL;
24528 +
24529 +       return copy_fs_struct(fs);
24530 +}
24531 +
24532 +
24533 +int vx_enter_space(struct vx_info *vxi, unsigned long mask, unsigned index)
24534 +{
24535 +       struct nsproxy *proxy, *proxy_cur, *proxy_new;
24536 +       struct fs_struct *fs, *fs_cur, *fs_new;
24537 +       int ret;
24538 +
24539 +       vxdprintk(VXD_CBIT(space, 8), "vx_enter_space(%p[#%u],0x%08lx,%d)",
24540 +               vxi, vxi->vx_id, mask, index);
24541 +
24542 +       if (vx_info_flags(vxi, VXF_INFO_PRIVATE, 0))
24543 +               return -EACCES;
24544 +
24545 +       if (!mask)
24546 +               mask = vxi->vx_nsmask[index];
24547 +
24548 +       if ((mask & vxi->vx_nsmask[index]) != mask)
24549 +               return -EINVAL;
24550 +
24551 +       proxy = vxi->vx_nsproxy[index];
24552 +       fs = vxi->vx_fs[index];
24553 +
24554 +       task_lock(current);
24555 +       fs_cur = current->fs;
24556 +       atomic_inc(&fs_cur->count);
24557 +       proxy_cur = current->nsproxy;
24558 +       get_nsproxy(proxy_cur);
24559 +       task_unlock(current);
24560 +
24561 +       fs_new = __vs_merge_fs(fs_cur, fs, mask);
24562 +       if (IS_ERR(fs_new)) {
24563 +               ret = PTR_ERR(fs_new);
24564 +               goto out_put;
24565 +       }
24566 +
24567 +       proxy_new = __vs_merge_nsproxy(proxy_cur, proxy, mask);
24568 +       if (IS_ERR(proxy_new)) {
24569 +               ret = PTR_ERR(proxy_new);
24570 +               goto out_put_fs;
24571 +       }
24572 +
24573 +       fs_new = xchg(&current->fs, fs_new);
24574 +       proxy_new = xchg(&current->nsproxy, proxy_new);
24575 +       ret = 0;
24576 +
24577 +       if (proxy_new)
24578 +               put_nsproxy(proxy_new);
24579 +out_put_fs:
24580 +       if (fs_new)
24581 +               put_fs_struct(fs_new);
24582 +out_put:
24583 +       if (proxy_cur)
24584 +               put_nsproxy(proxy_cur);
24585 +       if (fs_cur)
24586 +               put_fs_struct(fs_cur);
24587 +       return ret;
24588 +}
24589 +
24590 +
24591 +int vx_set_space(struct vx_info *vxi, unsigned long mask, unsigned index)
24592 +{
24593 +       struct nsproxy *proxy_vxi, *proxy_cur, *proxy_new;
24594 +       struct fs_struct *fs_vxi, *fs_cur, *fs_new;
24595 +       int ret;
24596 +
24597 +       vxdprintk(VXD_CBIT(space, 8), "vx_set_space(%p[#%u],0x%08lx,%d)",
24598 +               vxi, vxi->vx_id, mask, index);
24599 +#if 0
24600 +       if (!mask)
24601 +               mask = default_space_mask.mask;
24602 +#endif
24603 +       if ((mask & space_mask.mask) != mask)
24604 +               return -EINVAL;
24605 +
24606 +       proxy_vxi = vxi->vx_nsproxy[index];
24607 +       fs_vxi = vxi->vx_fs[index];
24608 +
24609 +       task_lock(current);
24610 +       fs_cur = current->fs;
24611 +       atomic_inc(&fs_cur->count);
24612 +       proxy_cur = current->nsproxy;
24613 +       get_nsproxy(proxy_cur);
24614 +       task_unlock(current);
24615 +
24616 +       fs_new = __vs_merge_fs(fs_vxi, fs_cur, mask);
24617 +       if (IS_ERR(fs_new)) {
24618 +               ret = PTR_ERR(fs_new);
24619 +               goto out_put;
24620 +       }
24621 +
24622 +       proxy_new = __vs_merge_nsproxy(proxy_vxi, proxy_cur, mask);
24623 +       if (IS_ERR(proxy_new)) {
24624 +               ret = PTR_ERR(proxy_new);
24625 +               goto out_put_fs;
24626 +       }
24627 +
24628 +       fs_new = xchg(&vxi->vx_fs[index], fs_new);
24629 +       proxy_new = xchg(&vxi->vx_nsproxy[index], proxy_new);
24630 +       vxi->vx_nsmask[index] |= mask;
24631 +       ret = 0;
24632 +
24633 +       if (proxy_new)
24634 +               put_nsproxy(proxy_new);
24635 +out_put_fs:
24636 +       if (fs_new)
24637 +               put_fs_struct(fs_new);
24638 +out_put:
24639 +       if (proxy_cur)
24640 +               put_nsproxy(proxy_cur);
24641 +       if (fs_cur)
24642 +               put_fs_struct(fs_cur);
24643 +       return ret;
24644 +}
24645 +
24646 +
24647 +int vc_enter_space_v1(struct vx_info *vxi, void __user *data)
24648 +{
24649 +       struct vcmd_space_mask_v1 vc_data = { .mask = 0 };
24650 +
24651 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
24652 +               return -EFAULT;
24653 +
24654 +       return vx_enter_space(vxi, vc_data.mask, 0);
24655 +}
24656 +
24657 +int vc_enter_space(struct vx_info *vxi, void __user *data)
24658 +{
24659 +       struct vcmd_space_mask_v2 vc_data = { .mask = 0 };
24660 +
24661 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
24662 +               return -EFAULT;
24663 +
24664 +       if (vc_data.index >= VX_SPACES)
24665 +               return -EINVAL;
24666 +
24667 +       return vx_enter_space(vxi, vc_data.mask, vc_data.index);
24668 +}
24669 +
24670 +int vc_set_space_v1(struct vx_info *vxi, void __user *data)
24671 +{
24672 +       struct vcmd_space_mask_v1 vc_data = { .mask = 0 };
24673 +
24674 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
24675 +               return -EFAULT;
24676 +
24677 +       return vx_set_space(vxi, vc_data.mask, 0);
24678 +}
24679 +
24680 +int vc_set_space(struct vx_info *vxi, void __user *data)
24681 +{
24682 +       struct vcmd_space_mask_v2 vc_data = { .mask = 0 };
24683 +
24684 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
24685 +               return -EFAULT;
24686 +
24687 +       if (vc_data.index >= VX_SPACES)
24688 +               return -EINVAL;
24689 +
24690 +       return vx_set_space(vxi, vc_data.mask, vc_data.index);
24691 +}
24692 +
24693 +int vc_get_space_mask(void __user *data, int type)
24694 +{
24695 +       const struct vcmd_space_mask_v1 *mask;
24696 +
24697 +       if (type == 0)
24698 +               mask = &space_mask_v0;
24699 +       else if (type == 1)
24700 +               mask = &space_mask;
24701 +       else
24702 +               mask = &default_space_mask;
24703 +
24704 +       vxdprintk(VXD_CBIT(space, 10),
24705 +               "vc_get_space_mask(%d) = %08llx", type, mask->mask);
24706 +
24707 +       if (copy_to_user(data, mask, sizeof(*mask)))
24708 +               return -EFAULT;
24709 +       return 0;
24710 +}
24711 +
24712 diff -NurpP --minimal linux-2.6.29.1/kernel/vserver/switch.c linux-2.6.29.1-vs2.3.0.36.9-pre5/kernel/vserver/switch.c
24713 --- linux-2.6.29.1/kernel/vserver/switch.c      1970-01-01 01:00:00.000000000 +0100
24714 +++ linux-2.6.29.1-vs2.3.0.36.9-pre5/kernel/vserver/switch.c    2009-03-24 14:59:18.000000000 +0100
24715 @@ -0,0 +1,543 @@
24716 +/*
24717 + *  linux/kernel/vserver/switch.c
24718 + *
24719 + *  Virtual Server: Syscall Switch
24720 + *
24721 + *  Copyright (C) 2003-2007  Herbert Pötzl
24722 + *
24723 + *  V0.01  syscall switch
24724 + *  V0.02  added signal to context
24725 + *  V0.03  added rlimit functions
24726 + *  V0.04  added iattr, task/xid functions
24727 + *  V0.05  added debug/history stuff
24728 + *  V0.06  added compat32 layer
24729 + *  V0.07  vcmd args and perms
24730 + *  V0.08  added status commands
24731 + *  V0.09  added tag commands
24732 + *  V0.10  added oom bias
24733 + *  V0.11  added device commands
24734 + *
24735 + */
24736 +
24737 +#include <linux/vs_context.h>
24738 +#include <linux/vs_network.h>
24739 +#include <linux/vserver/switch.h>
24740 +
24741 +#include "vci_config.h"
24742 +
24743 +
24744 +static inline
24745 +int vc_get_version(uint32_t id)
24746 +{
24747 +       return VCI_VERSION;
24748 +}
24749 +
24750 +static inline
24751 +int vc_get_vci(uint32_t id)
24752 +{
24753 +       return vci_kernel_config();
24754 +}
24755 +
24756 +#include <linux/vserver/context_cmd.h>
24757 +#include <linux/vserver/cvirt_cmd.h>
24758 +#include <linux/vserver/cacct_cmd.h>
24759 +#include <linux/vserver/limit_cmd.h>
24760 +#include <linux/vserver/network_cmd.h>
24761 +#include <linux/vserver/sched_cmd.h>
24762 +#include <linux/vserver/debug_cmd.h>
24763 +#include <linux/vserver/inode_cmd.h>
24764 +#include <linux/vserver/dlimit_cmd.h>
24765 +#include <linux/vserver/signal_cmd.h>
24766 +#include <linux/vserver/space_cmd.h>
24767 +#include <linux/vserver/tag_cmd.h>
24768 +#include <linux/vserver/device_cmd.h>
24769 +
24770 +#include <linux/vserver/inode.h>
24771 +#include <linux/vserver/dlimit.h>
24772 +
24773 +
24774 +#ifdef CONFIG_COMPAT
24775 +#define __COMPAT(name, id, data, compat)       \
24776 +       (compat) ? name ## _x32(id, data) : name(id, data)
24777 +#define __COMPAT_NO_ID(name, data, compat)     \
24778 +       (compat) ? name ## _x32(data) : name(data)
24779 +#else
24780 +#define __COMPAT(name, id, data, compat)       \
24781 +       name(id, data)
24782 +#define __COMPAT_NO_ID(name, data, compat)     \
24783 +       name(data)
24784 +#endif
24785 +
24786 +
24787 +static inline
24788 +long do_vcmd(uint32_t cmd, uint32_t id,
24789 +       struct vx_info *vxi, struct nx_info *nxi,
24790 +       void __user *data, int compat)
24791 +{
24792 +       switch (cmd) {
24793 +
24794 +       case VCMD_get_version:
24795 +               return vc_get_version(id);
24796 +       case VCMD_get_vci:
24797 +               return vc_get_vci(id);
24798 +
24799 +       case VCMD_task_xid:
24800 +               return vc_task_xid(id);
24801 +       case VCMD_vx_info:
24802 +               return vc_vx_info(vxi, data);
24803 +
24804 +       case VCMD_task_nid:
24805 +               return vc_task_nid(id);
24806 +       case VCMD_nx_info:
24807 +               return vc_nx_info(nxi, data);
24808 +
24809 +       case VCMD_task_tag:
24810 +               return vc_task_tag(id);
24811 +
24812 +       case VCMD_set_space_v1:
24813 +               return vc_set_space_v1(vxi, data);
24814 +       /* this is version 2 */
24815 +       case VCMD_set_space:
24816 +               return vc_set_space(vxi, data);
24817 +
24818 +       case VCMD_get_space_mask_v0:
24819 +               return vc_get_space_mask(data, 0);
24820 +       /* this is version 1 */
24821 +       case VCMD_get_space_mask:
24822 +               return vc_get_space_mask(data, 1);
24823 +
24824 +       case VCMD_get_space_default:
24825 +               return vc_get_space_mask(data, -1);
24826 +
24827 +#ifdef CONFIG_IA32_EMULATION
24828 +       case VCMD_get_rlimit:
24829 +               return __COMPAT(vc_get_rlimit, vxi, data, compat);
24830 +       case VCMD_set_rlimit:
24831 +               return __COMPAT(vc_set_rlimit, vxi, data, compat);
24832 +#else
24833 +       case VCMD_get_rlimit:
24834 +               return vc_get_rlimit(vxi, data);
24835 +       case VCMD_set_rlimit:
24836 +               return vc_set_rlimit(vxi, data);
24837 +#endif
24838 +       case VCMD_get_rlimit_mask:
24839 +               return vc_get_rlimit_mask(id, data);
24840 +       case VCMD_reset_minmax:
24841 +               return vc_reset_minmax(vxi, data);
24842 +
24843 +       case VCMD_get_vhi_name:
24844 +               return vc_get_vhi_name(vxi, data);
24845 +       case VCMD_set_vhi_name:
24846 +               return vc_set_vhi_name(vxi, data);
24847 +
24848 +       case VCMD_ctx_stat:
24849 +               return vc_ctx_stat(vxi, data);
24850 +       case VCMD_virt_stat:
24851 +               return vc_virt_stat(vxi, data);
24852 +       case VCMD_sock_stat:
24853 +               return vc_sock_stat(vxi, data);
24854 +       case VCMD_rlimit_stat:
24855 +               return vc_rlimit_stat(vxi, data);
24856 +
24857 +       case VCMD_set_cflags:
24858 +               return vc_set_cflags(vxi, data);
24859 +       case VCMD_get_cflags:
24860 +               return vc_get_cflags(vxi, data);
24861 +
24862 +       /* this is version 1 */
24863 +       case VCMD_set_ccaps:
24864 +               return vc_set_ccaps(vxi, data);
24865 +       /* this is version 1 */
24866 +       case VCMD_get_ccaps:
24867 +               return vc_get_ccaps(vxi, data);
24868 +       case VCMD_set_bcaps:
24869 +               return vc_set_bcaps(vxi, data);
24870 +       case VCMD_get_bcaps:
24871 +               return vc_get_bcaps(vxi, data);
24872 +
24873 +       case VCMD_set_badness:
24874 +               return vc_set_badness(vxi, data);
24875 +       case VCMD_get_badness:
24876 +               return vc_get_badness(vxi, data);
24877 +
24878 +       case VCMD_set_nflags:
24879 +               return vc_set_nflags(nxi, data);
24880 +       case VCMD_get_nflags:
24881 +               return vc_get_nflags(nxi, data);
24882 +
24883 +       case VCMD_set_ncaps:
24884 +               return vc_set_ncaps(nxi, data);
24885 +       case VCMD_get_ncaps:
24886 +               return vc_get_ncaps(nxi, data);
24887 +
24888 +       case VCMD_set_sched_v4:
24889 +               return vc_set_sched_v4(vxi, data);
24890 +       /* this is version 5 */
24891 +       case VCMD_set_sched:
24892 +               return vc_set_sched(vxi, data);
24893 +       case VCMD_get_sched:
24894 +               return vc_get_sched(vxi, data);
24895 +       case VCMD_sched_info:
24896 +               return vc_sched_info(vxi, data);
24897 +
24898 +       case VCMD_add_dlimit:
24899 +               return __COMPAT(vc_add_dlimit, id, data, compat);
24900 +       case VCMD_rem_dlimit:
24901 +               return __COMPAT(vc_rem_dlimit, id, data, compat);
24902 +       case VCMD_set_dlimit:
24903 +               return __COMPAT(vc_set_dlimit, id, data, compat);
24904 +       case VCMD_get_dlimit:
24905 +               return __COMPAT(vc_get_dlimit, id, data, compat);
24906 +
24907 +       case VCMD_ctx_kill:
24908 +               return vc_ctx_kill(vxi, data);
24909 +
24910 +       case VCMD_wait_exit:
24911 +               return vc_wait_exit(vxi, data);
24912 +
24913 +       case VCMD_get_iattr:
24914 +               return __COMPAT_NO_ID(vc_get_iattr, data, compat);
24915 +       case VCMD_set_iattr:
24916 +               return __COMPAT_NO_ID(vc_set_iattr, data, compat);
24917 +
24918 +       case VCMD_fget_iattr:
24919 +               return vc_fget_iattr(id, data);
24920 +       case VCMD_fset_iattr:
24921 +               return vc_fset_iattr(id, data);
24922 +
24923 +       case VCMD_enter_space_v0:
24924 +               return vc_enter_space_v1(vxi, NULL);
24925 +       case VCMD_enter_space_v1:
24926 +               return vc_enter_space_v1(vxi, data);
24927 +       /* this is version 2 */
24928 +       case VCMD_enter_space:
24929 +               return vc_enter_space(vxi, data);
24930 +
24931 +       case VCMD_ctx_create_v0:
24932 +               return vc_ctx_create(id, NULL);
24933 +       case VCMD_ctx_create:
24934 +               return vc_ctx_create(id, data);
24935 +       case VCMD_ctx_migrate_v0:
24936 +               return vc_ctx_migrate(vxi, NULL);
24937 +       case VCMD_ctx_migrate:
24938 +               return vc_ctx_migrate(vxi, data);
24939 +
24940 +       case VCMD_net_create_v0:
24941 +               return vc_net_create(id, NULL);
24942 +       case VCMD_net_create:
24943 +               return vc_net_create(id, data);
24944 +       case VCMD_net_migrate:
24945 +               return vc_net_migrate(nxi, data);
24946 +
24947 +       case VCMD_tag_migrate:
24948 +               return vc_tag_migrate(id);
24949 +
24950 +       case VCMD_net_add:
24951 +               return vc_net_add(nxi, data);
24952 +       case VCMD_net_remove:
24953 +               return vc_net_remove(nxi, data);
24954 +
24955 +       case VCMD_net_add_ipv4:
24956 +               return vc_net_add_ipv4(nxi, data);
24957 +       case VCMD_net_remove_ipv4:
24958 +               return vc_net_remove_ipv4(nxi, data);
24959 +#ifdef CONFIG_IPV6
24960 +       case VCMD_net_add_ipv6:
24961 +               return vc_net_add_ipv6(nxi, data);
24962 +       case VCMD_net_remove_ipv6:
24963 +               return vc_net_remove_ipv6(nxi, data);
24964 +#endif
24965 +/*     case VCMD_add_match_ipv4:
24966 +               return vc_add_match_ipv4(nxi, data);
24967 +       case VCMD_get_match_ipv4:
24968 +               return vc_get_match_ipv4(nxi, data);
24969 +#ifdef CONFIG_IPV6
24970 +       case VCMD_add_match_ipv6:
24971 +               return vc_add_match_ipv6(nxi, data);
24972 +       case VCMD_get_match_ipv6:
24973 +               return vc_get_match_ipv6(nxi, data);
24974 +#endif */
24975 +
24976 +#ifdef CONFIG_VSERVER_DEVICE
24977 +       case VCMD_set_mapping:
24978 +               return __COMPAT(vc_set_mapping, vxi, data, compat);
24979 +       case VCMD_unset_mapping:
24980 +               return __COMPAT(vc_unset_mapping, vxi, data, compat);
24981 +#endif
24982 +#ifdef CONFIG_VSERVER_HISTORY
24983 +       case VCMD_dump_history:
24984 +               return vc_dump_history(id);
24985 +       case VCMD_read_history:
24986 +               return __COMPAT(vc_read_history, id, data, compat);
24987 +#endif
24988 +#ifdef CONFIG_VSERVER_MONITOR
24989 +       case VCMD_read_monitor:
24990 +               return __COMPAT(vc_read_monitor, id, data, compat);
24991 +#endif
24992 +       default:
24993 +               vxwprintk_task(1, "unimplemented VCMD_%02d_%d[%d]",
24994 +                       VC_CATEGORY(cmd), VC_COMMAND(cmd), VC_VERSION(cmd));
24995 +       }
24996 +       return -ENOSYS;
24997 +}
24998 +
24999 +
25000 +#define        __VCMD(vcmd, _perm, _args, _flags)              \
25001 +       case VCMD_ ## vcmd: perm = _perm;               \
25002 +               args = _args; flags = _flags; break
25003 +
25004 +
25005 +#define VCA_NONE       0x00
25006 +#define VCA_VXI                0x01
25007 +#define VCA_NXI                0x02
25008 +
25009 +#define VCF_NONE       0x00
25010 +#define VCF_INFO       0x01
25011 +#define VCF_ADMIN      0x02
25012 +#define VCF_ARES       0x06    /* includes admin */
25013 +#define VCF_SETUP      0x08
25014 +
25015 +#define VCF_ZIDOK      0x10    /* zero id okay */
25016 +
25017 +
25018 +static inline
25019 +long do_vserver(uint32_t cmd, uint32_t id, void __user *data, int compat)
25020 +{
25021 +       long ret;
25022 +       int permit = -1, state = 0;
25023 +       int perm = -1, args = 0, flags = 0;
25024 +       struct vx_info *vxi = NULL;
25025 +       struct nx_info *nxi = NULL;
25026 +
25027 +       switch (cmd) {
25028 +       /* unpriviledged commands */
25029 +       __VCMD(get_version,      0, VCA_NONE,   0);
25030 +       __VCMD(get_vci,          0, VCA_NONE,   0);
25031 +       __VCMD(get_rlimit_mask,  0, VCA_NONE,   0);
25032 +       __VCMD(get_space_mask_v0,0, VCA_NONE,   0);
25033 +       __VCMD(get_space_mask,   0, VCA_NONE,   0);
25034 +       __VCMD(get_space_default,0, VCA_NONE,   0);
25035 +
25036 +       /* info commands */
25037 +       __VCMD(task_xid,         2, VCA_NONE,   0);
25038 +       __VCMD(reset_minmax,     2, VCA_VXI,    0);
25039 +       __VCMD(vx_info,          3, VCA_VXI,    VCF_INFO);
25040 +       __VCMD(get_bcaps,        3, VCA_VXI,    VCF_INFO);
25041 +       __VCMD(get_ccaps,        3, VCA_VXI,    VCF_INFO);
25042 +       __VCMD(get_cflags,       3, VCA_VXI,    VCF_INFO);
25043 +       __VCMD(get_badness,      3, VCA_VXI,    VCF_INFO);
25044 +       __VCMD(get_vhi_name,     3, VCA_VXI,    VCF_INFO);
25045 +       __VCMD(get_rlimit,       3, VCA_VXI,    VCF_INFO);
25046 +
25047 +       __VCMD(ctx_stat,         3, VCA_VXI,    VCF_INFO);
25048 +       __VCMD(virt_stat,        3, VCA_VXI,    VCF_INFO);
25049 +       __VCMD(sock_stat,        3, VCA_VXI,    VCF_INFO);
25050 +       __VCMD(rlimit_stat,      3, VCA_VXI,    VCF_INFO);
25051 +
25052 +       __VCMD(task_nid,         2, VCA_NONE,   0);
25053 +       __VCMD(nx_info,          3, VCA_NXI,    VCF_INFO);
25054 +       __VCMD(get_ncaps,        3, VCA_NXI,    VCF_INFO);
25055 +       __VCMD(get_nflags,       3, VCA_NXI,    VCF_INFO);
25056 +
25057 +       __VCMD(task_tag,         2, VCA_NONE,   0);
25058 +
25059 +       __VCMD(get_iattr,        2, VCA_NONE,   0);
25060 +       __VCMD(fget_iattr,       2, VCA_NONE,   0);
25061 +       __VCMD(get_dlimit,       3, VCA_NONE,   VCF_INFO);
25062 +       __VCMD(get_sched,        3, VCA_VXI,    VCF_INFO);
25063 +       __VCMD(sched_info,       3, VCA_VXI,    VCF_INFO | VCF_ZIDOK);
25064 +
25065 +       /* lower admin commands */
25066 +       __VCMD(wait_exit,        4, VCA_VXI,    VCF_INFO);
25067 +       __VCMD(ctx_create_v0,    5, VCA_NONE,   0);
25068 +       __VCMD(ctx_create,       5, VCA_NONE,   0);
25069 +       __VCMD(ctx_migrate_v0,   5, VCA_VXI,    VCF_ADMIN);
25070 +       __VCMD(ctx_migrate,      5, VCA_VXI,    VCF_ADMIN);
25071 +       __VCMD(enter_space_v0,   5, VCA_VXI,    VCF_ADMIN);
25072 +       __VCMD(enter_space_v1,   5, VCA_VXI,    VCF_ADMIN);
25073 +       __VCMD(enter_space,      5, VCA_VXI,    VCF_ADMIN);
25074 +
25075 +       __VCMD(net_create_v0,    5, VCA_NONE,   0);
25076 +       __VCMD(net_create,       5, VCA_NONE,   0);
25077 +       __VCMD(net_migrate,      5, VCA_NXI,    VCF_ADMIN);
25078 +
25079 +       __VCMD(tag_migrate,      5, VCA_NONE,   VCF_ADMIN);
25080 +
25081 +       /* higher admin commands */
25082 +       __VCMD(ctx_kill,         6, VCA_VXI,    VCF_ARES);
25083 +       __VCMD(set_space_v1,     7, VCA_VXI,    VCF_ARES | VCF_SETUP);
25084 +       __VCMD(set_space,        7, VCA_VXI,    VCF_ARES | VCF_SETUP);
25085 +
25086 +       __VCMD(set_ccaps,        7, VCA_VXI,    VCF_ARES | VCF_SETUP);
25087 +       __VCMD(set_bcaps,        7, VCA_VXI,    VCF_ARES | VCF_SETUP);
25088 +       __VCMD(set_cflags,       7, VCA_VXI,    VCF_ARES | VCF_SETUP);
25089 +       __VCMD(set_badness,      7, VCA_VXI,    VCF_ARES | VCF_SETUP);
25090 +
25091 +       __VCMD(set_vhi_name,     7, VCA_VXI,    VCF_ARES | VCF_SETUP);
25092 +       __VCMD(set_rlimit,       7, VCA_VXI,    VCF_ARES | VCF_SETUP);
25093 +       __VCMD(set_sched,        7, VCA_VXI,    VCF_ARES | VCF_SETUP);
25094 +       __VCMD(set_sched_v4,     7, VCA_VXI,    VCF_ARES | VCF_SETUP);
25095 +
25096 +       __VCMD(set_ncaps,        7, VCA_NXI,    VCF_ARES | VCF_SETUP);
25097 +       __VCMD(set_nflags,       7, VCA_NXI,    VCF_ARES | VCF_SETUP);
25098 +       __VCMD(net_add,          8, VCA_NXI,    VCF_ARES | VCF_SETUP);
25099 +       __VCMD(net_remove,       8, VCA_NXI,    VCF_ARES | VCF_SETUP);
25100 +       __VCMD(net_add_ipv4,     8, VCA_NXI,    VCF_ARES | VCF_SETUP);
25101 +       __VCMD(net_remove_ipv4,  8, VCA_NXI,    VCF_ARES | VCF_SETUP);
25102 +#ifdef CONFIG_IPV6
25103 +       __VCMD(net_add_ipv6,     8, VCA_NXI,    VCF_ARES | VCF_SETUP);
25104 +       __VCMD(net_remove_ipv6,  8, VCA_NXI,    VCF_ARES | VCF_SETUP);
25105 +#endif
25106 +       __VCMD(set_iattr,        7, VCA_NONE,   0);
25107 +       __VCMD(fset_iattr,       7, VCA_NONE,   0);
25108 +       __VCMD(set_dlimit,       7, VCA_NONE,   VCF_ARES);
25109 +       __VCMD(add_dlimit,       8, VCA_NONE,   VCF_ARES);
25110 +       __VCMD(rem_dlimit,       8, VCA_NONE,   VCF_ARES);
25111 +
25112 +#ifdef CONFIG_VSERVER_DEVICE
25113 +       __VCMD(set_mapping,      8, VCA_VXI,    VCF_ARES|VCF_ZIDOK);
25114 +       __VCMD(unset_mapping,    8, VCA_VXI,    VCF_ARES|VCF_ZIDOK);
25115 +#endif
25116 +       /* debug level admin commands */
25117 +#ifdef CONFIG_VSERVER_HISTORY
25118 +       __VCMD(dump_history,     9, VCA_NONE,   0);
25119 +       __VCMD(read_history,     9, VCA_NONE,   0);
25120 +#endif
25121 +#ifdef CONFIG_VSERVER_MONITOR
25122 +       __VCMD(read_monitor,     9, VCA_NONE,   0);
25123 +#endif
25124 +
25125 +       default:
25126 +               perm = -1;
25127 +       }
25128 +
25129 +       vxdprintk(VXD_CBIT(switch, 0),
25130 +               "vc: VCMD_%02d_%d[%d], %d,%p [%d,%d,%x,%x]",
25131 +               VC_CATEGORY(cmd), VC_COMMAND(cmd),
25132 +               VC_VERSION(cmd), id, data, compat,
25133 +               perm, args, flags);
25134 +
25135 +       ret = -ENOSYS;
25136 +       if (perm < 0)
25137 +               goto out;
25138 +
25139 +       state = 1;
25140 +       if (!capable(CAP_CONTEXT))
25141 +               goto out;
25142 +
25143 +       state = 2;
25144 +       /* moved here from the individual commands */
25145 +       ret = -EPERM;
25146 +       if ((perm > 1) && !capable(CAP_SYS_ADMIN))
25147 +               goto out;
25148 +
25149 +       state = 3;
25150 +       /* vcmd involves resource management  */
25151 +       ret = -EPERM;
25152 +       if ((flags & VCF_ARES) && !capable(CAP_SYS_RESOURCE))
25153 +               goto out;
25154 +
25155 +       state = 4;
25156 +       /* various legacy exceptions */
25157 +       switch (cmd) {
25158 +       /* will go away when spectator is a cap */
25159 +       case VCMD_ctx_migrate_v0:
25160 +       case VCMD_ctx_migrate:
25161 +               if (id == 1) {
25162 +                       current->xid = 1;
25163 +                       ret = 1;
25164 +                       goto out;
25165 +               }
25166 +               break;
25167 +
25168 +       /* will go away when spectator is a cap */
25169 +       case VCMD_net_migrate:
25170 +               if (id == 1) {
25171 +                       current->nid = 1;
25172 +                       ret = 1;
25173 +                       goto out;
25174 +               }
25175 +               break;
25176 +       }
25177 +
25178 +       /* vcmds are fine by default */
25179 +       permit = 1;
25180 +
25181 +       /* admin type vcmds require admin ... */
25182 +       if (flags & VCF_ADMIN)
25183 +               permit = vx_check(0, VS_ADMIN) ? 1 : 0;
25184 +
25185 +       /* ... but setup type vcmds override that */
25186 +       if (!permit && (flags & VCF_SETUP))
25187 +               permit = vx_flags(VXF_STATE_SETUP, 0) ? 2 : 0;
25188 +
25189 +       state = 5;
25190 +       ret = -EPERM;
25191 +       if (!permit)
25192 +               goto out;
25193 +
25194 +       state = 6;
25195 +       if (!id && (flags & VCF_ZIDOK))
25196 +               goto skip_id;
25197 +
25198 +       ret = -ESRCH;
25199 +       if (args & VCA_VXI) {
25200 +               vxi = lookup_vx_info(id);
25201 +               if (!vxi)
25202 +                       goto out;
25203 +
25204 +               if ((flags & VCF_ADMIN) &&
25205 +                       /* special case kill for shutdown */
25206 +                       (cmd != VCMD_ctx_kill) &&
25207 +                       /* can context be administrated? */
25208 +                       !vx_info_flags(vxi, VXF_STATE_ADMIN, 0)) {
25209 +                       ret = -EACCES;
25210 +                       goto out_vxi;
25211 +               }
25212 +       }
25213 +       state = 7;
25214 +       if (args & VCA_NXI) {
25215 +               nxi = lookup_nx_info(id);
25216 +               if (!nxi)
25217 +                       goto out_vxi;
25218 +
25219 +               if ((flags & VCF_ADMIN) &&
25220 +                       /* can context be administrated? */
25221 +                       !nx_info_flags(nxi, NXF_STATE_ADMIN, 0)) {
25222 +                       ret = -EACCES;
25223 +                       goto out_nxi;
25224 +               }
25225 +       }
25226 +skip_id:
25227 +       state = 8;
25228 +       ret = do_vcmd(cmd, id, vxi, nxi, data, compat);
25229 +
25230 +out_nxi:
25231 +       if ((args & VCA_NXI) && nxi)
25232 +               put_nx_info(nxi);
25233 +out_vxi:
25234 +       if ((args & VCA_VXI) && vxi)
25235 +               put_vx_info(vxi);
25236 +out:
25237 +       vxdprintk(VXD_CBIT(switch, 1),
25238 +               "vc: VCMD_%02d_%d[%d] = %08lx(%ld) [%d,%d]",
25239 +               VC_CATEGORY(cmd), VC_COMMAND(cmd),
25240 +               VC_VERSION(cmd), ret, ret, state, permit);
25241 +       return ret;
25242 +}
25243 +
25244 +asmlinkage long
25245 +sys_vserver(uint32_t cmd, uint32_t id, void __user *data)
25246 +{
25247 +       return do_vserver(cmd, id, data, 0);
25248 +}
25249 +
25250 +#ifdef CONFIG_COMPAT
25251 +
25252 +asmlinkage long
25253 +sys32_vserver(uint32_t cmd, uint32_t id, void __user *data)
25254 +{
25255 +       return do_vserver(cmd, id, data, 1);
25256 +}
25257 +
25258 +#endif /* CONFIG_COMPAT */
25259 diff -NurpP --minimal linux-2.6.29.1/kernel/vserver/sysctl.c linux-2.6.29.1-vs2.3.0.36.9-pre5/kernel/vserver/sysctl.c
25260 --- linux-2.6.29.1/kernel/vserver/sysctl.c      1970-01-01 01:00:00.000000000 +0100
25261 +++ linux-2.6.29.1-vs2.3.0.36.9-pre5/kernel/vserver/sysctl.c    2009-02-22 22:54:26.000000000 +0100
25262 @@ -0,0 +1,244 @@
25263 +/*
25264 + *  kernel/vserver/sysctl.c
25265 + *
25266 + *  Virtual Context Support
25267 + *
25268 + *  Copyright (C) 2004-2007  Herbert Pötzl
25269 + *
25270 + *  V0.01  basic structure
25271 + *
25272 + */
25273 +
25274 +#include <linux/module.h>
25275 +#include <linux/ctype.h>
25276 +#include <linux/sysctl.h>
25277 +#include <linux/parser.h>
25278 +#include <asm/uaccess.h>
25279 +
25280 +
25281 +enum {
25282 +       CTL_DEBUG_ERROR         = 0,
25283 +       CTL_DEBUG_SWITCH        = 1,
25284 +       CTL_DEBUG_XID,
25285 +       CTL_DEBUG_NID,
25286 +       CTL_DEBUG_TAG,
25287 +       CTL_DEBUG_NET,
25288 +       CTL_DEBUG_LIMIT,
25289 +       CTL_DEBUG_CRES,
25290 +       CTL_DEBUG_DLIM,
25291 +       CTL_DEBUG_QUOTA,
25292 +       CTL_DEBUG_CVIRT,
25293 +       CTL_DEBUG_SPACE,
25294 +       CTL_DEBUG_MISC,
25295 +};
25296 +
25297 +
25298 +unsigned int vx_debug_switch   = 0;
25299 +unsigned int vx_debug_xid      = 0;
25300 +unsigned int vx_debug_nid      = 0;
25301 +unsigned int vx_debug_tag      = 0;
25302 +unsigned int vx_debug_net      = 0;
25303 +unsigned int vx_debug_limit    = 0;
25304 +unsigned int vx_debug_cres     = 0;
25305 +unsigned int vx_debug_dlim     = 0;
25306 +unsigned int vx_debug_quota    = 0;
25307 +unsigned int vx_debug_cvirt    = 0;
25308 +unsigned int vx_debug_space    = 0;
25309 +unsigned int vx_debug_misc     = 0;
25310 +
25311 +
25312 +static struct ctl_table_header *vserver_table_header;
25313 +static ctl_table vserver_root_table[];
25314 +
25315 +
25316 +void vserver_register_sysctl(void)
25317 +{
25318 +       if (!vserver_table_header) {
25319 +               vserver_table_header = register_sysctl_table(vserver_root_table);
25320 +       }
25321 +
25322 +}
25323 +
25324 +void vserver_unregister_sysctl(void)
25325 +{
25326 +       if (vserver_table_header) {
25327 +               unregister_sysctl_table(vserver_table_header);
25328 +               vserver_table_header = NULL;
25329 +       }
25330 +}
25331 +
25332 +
25333 +static int proc_dodebug(ctl_table *table, int write,
25334 +       struct file *filp, void __user *buffer, size_t *lenp, loff_t *ppos)
25335 +{
25336 +       char            tmpbuf[20], *p, c;
25337 +       unsigned int    value;
25338 +       size_t          left, len;
25339 +
25340 +       if ((*ppos && !write) || !*lenp) {
25341 +               *lenp = 0;
25342 +               return 0;
25343 +       }
25344 +
25345 +       left = *lenp;
25346 +
25347 +       if (write) {
25348 +               if (!access_ok(VERIFY_READ, buffer, left))
25349 +                       return -EFAULT;
25350 +               p = (char *)buffer;
25351 +               while (left && __get_user(c, p) >= 0 && isspace(c))
25352 +                       left--, p++;
25353 +               if (!left)
25354 +                       goto done;
25355 +
25356 +               if (left > sizeof(tmpbuf) - 1)
25357 +                       return -EINVAL;
25358 +               if (copy_from_user(tmpbuf, p, left))
25359 +                       return -EFAULT;
25360 +               tmpbuf[left] = '\0';
25361 +
25362 +               for (p = tmpbuf, value = 0; '0' <= *p && *p <= '9'; p++, left--)
25363 +                       value = 10 * value + (*p - '0');
25364 +               if (*p && !isspace(*p))
25365 +                       return -EINVAL;
25366 +               while (left && isspace(*p))
25367 +                       left--, p++;
25368 +               *(unsigned int *)table->data = value;
25369 +       } else {
25370 +               if (!access_ok(VERIFY_WRITE, buffer, left))
25371 +                       return -EFAULT;
25372 +               len = sprintf(tmpbuf, "%d", *(unsigned int *)table->data);
25373 +               if (len > left)
25374 +                       len = left;
25375 +               if (__copy_to_user(buffer, tmpbuf, len))
25376 +                       return -EFAULT;
25377 +               if ((left -= len) > 0) {
25378 +                       if (put_user('\n', (char *)buffer + len))
25379 +                               return -EFAULT;
25380 +                       left--;
25381 +               }
25382 +       }
25383 +
25384 +done:
25385 +       *lenp -= left;
25386 +       *ppos += *lenp;
25387 +       return 0;
25388 +}
25389 +
25390 +static int zero;
25391 +
25392 +#define        CTL_ENTRY(ctl, name)                            \
25393 +       {                                               \
25394 +               .ctl_name       = ctl,                  \
25395 +               .procname       = #name,                \
25396 +               .data           = &vx_ ## name,         \
25397 +               .maxlen         = sizeof(int),          \
25398 +               .mode           = 0644,                 \
25399 +               .proc_handler   = &proc_dodebug,        \
25400 +               .strategy       = &sysctl_intvec,       \
25401 +               .extra1         = &zero,                \
25402 +       }
25403 +
25404 +static ctl_table vserver_debug_table[] = {
25405 +       CTL_ENTRY(CTL_DEBUG_SWITCH,     debug_switch),
25406 +       CTL_ENTRY(CTL_DEBUG_XID,        debug_xid),
25407 +       CTL_ENTRY(CTL_DEBUG_NID,        debug_nid),
25408 +       CTL_ENTRY(CTL_DEBUG_TAG,        debug_tag),
25409 +       CTL_ENTRY(CTL_DEBUG_NET,        debug_net),
25410 +       CTL_ENTRY(CTL_DEBUG_LIMIT,      debug_limit),
25411 +       CTL_ENTRY(CTL_DEBUG_CRES,       debug_cres),
25412 +       CTL_ENTRY(CTL_DEBUG_DLIM,       debug_dlim),
25413 +       CTL_ENTRY(CTL_DEBUG_QUOTA,      debug_quota),
25414 +       CTL_ENTRY(CTL_DEBUG_CVIRT,      debug_cvirt),
25415 +       CTL_ENTRY(CTL_DEBUG_SPACE,      debug_space),
25416 +       CTL_ENTRY(CTL_DEBUG_MISC,       debug_misc),
25417 +       { .ctl_name = 0 }
25418 +};
25419 +
25420 +static ctl_table vserver_root_table[] = {
25421 +       {
25422 +               .ctl_name       = CTL_VSERVER,
25423 +               .procname       = "vserver",
25424 +               .mode           = 0555,
25425 +               .child          = vserver_debug_table
25426 +       },
25427 +       { .ctl_name = 0 }
25428 +};
25429 +
25430 +
25431 +static match_table_t tokens = {
25432 +       { CTL_DEBUG_SWITCH,     "switch=%x"     },
25433 +       { CTL_DEBUG_XID,        "xid=%x"        },
25434 +       { CTL_DEBUG_NID,        "nid=%x"        },
25435 +       { CTL_DEBUG_TAG,        "tag=%x"        },
25436 +       { CTL_DEBUG_NET,        "net=%x"        },
25437 +       { CTL_DEBUG_LIMIT,      "limit=%x"      },
25438 +       { CTL_DEBUG_CRES,       "cres=%x"       },
25439 +       { CTL_DEBUG_DLIM,       "dlim=%x"       },
25440 +       { CTL_DEBUG_QUOTA,      "quota=%x"      },
25441 +       { CTL_DEBUG_CVIRT,      "cvirt=%x"      },
25442 +       { CTL_DEBUG_SPACE,      "space=%x"      },
25443 +       { CTL_DEBUG_MISC,       "misc=%x"       },
25444 +       { CTL_DEBUG_ERROR,      NULL            }
25445 +};
25446 +
25447 +#define        HANDLE_CASE(id, name, val)                              \
25448 +       case CTL_DEBUG_ ## id:                                  \
25449 +               vx_debug_ ## name = val;                        \
25450 +               printk("vs_debug_" #name "=0x%x\n", val);       \
25451 +               break
25452 +
25453 +
25454 +static int __init vs_debug_setup(char *str)
25455 +{
25456 +       char *p;
25457 +       int token;
25458 +
25459 +       printk("vs_debug_setup(%s)\n", str);
25460 +       while ((p = strsep(&str, ",")) != NULL) {
25461 +               substring_t args[MAX_OPT_ARGS];
25462 +               unsigned int value;
25463 +
25464 +               if (!*p)
25465 +                       continue;
25466 +
25467 +               token = match_token(p, tokens, args);
25468 +               value = (token > 0) ? simple_strtoul(args[0].from, NULL, 0) : 0;
25469 +
25470 +               switch (token) {
25471 +               HANDLE_CASE(SWITCH, switch, value);
25472 +               HANDLE_CASE(XID,    xid,    value);
25473 +               HANDLE_CASE(NID,    nid,    value);
25474 +               HANDLE_CASE(TAG,    tag,    value);
25475 +               HANDLE_CASE(NET,    net,    value);
25476 +               HANDLE_CASE(LIMIT,  limit,  value);
25477 +               HANDLE_CASE(CRES,   cres,   value);
25478 +               HANDLE_CASE(DLIM,   dlim,   value);
25479 +               HANDLE_CASE(QUOTA,  quota,  value);
25480 +               HANDLE_CASE(CVIRT,  cvirt,  value);
25481 +               HANDLE_CASE(SPACE,  space,  value);
25482 +               HANDLE_CASE(MISC,   misc,   value);
25483 +               default:
25484 +                       return -EINVAL;
25485 +                       break;
25486 +               }
25487 +       }
25488 +       return 1;
25489 +}
25490 +
25491 +__setup("vsdebug=", vs_debug_setup);
25492 +
25493 +
25494 +
25495 +EXPORT_SYMBOL_GPL(vx_debug_switch);
25496 +EXPORT_SYMBOL_GPL(vx_debug_xid);
25497 +EXPORT_SYMBOL_GPL(vx_debug_nid);
25498 +EXPORT_SYMBOL_GPL(vx_debug_net);
25499 +EXPORT_SYMBOL_GPL(vx_debug_limit);
25500 +EXPORT_SYMBOL_GPL(vx_debug_cres);
25501 +EXPORT_SYMBOL_GPL(vx_debug_dlim);
25502 +EXPORT_SYMBOL_GPL(vx_debug_quota);
25503 +EXPORT_SYMBOL_GPL(vx_debug_cvirt);
25504 +EXPORT_SYMBOL_GPL(vx_debug_space);
25505 +EXPORT_SYMBOL_GPL(vx_debug_misc);
25506 +
25507 diff -NurpP --minimal linux-2.6.29.1/kernel/vserver/tag.c linux-2.6.29.1-vs2.3.0.36.9-pre5/kernel/vserver/tag.c
25508 --- linux-2.6.29.1/kernel/vserver/tag.c 1970-01-01 01:00:00.000000000 +0100
25509 +++ linux-2.6.29.1-vs2.3.0.36.9-pre5/kernel/vserver/tag.c       2009-02-22 22:54:26.000000000 +0100
25510 @@ -0,0 +1,63 @@
25511 +/*
25512 + *  linux/kernel/vserver/tag.c
25513 + *
25514 + *  Virtual Server: Shallow Tag Space
25515 + *
25516 + *  Copyright (C) 2007  Herbert Pötzl
25517 + *
25518 + *  V0.01  basic implementation
25519 + *
25520 + */
25521 +
25522 +#include <linux/sched.h>
25523 +#include <linux/vserver/debug.h>
25524 +#include <linux/vs_pid.h>
25525 +#include <linux/vs_tag.h>
25526 +
25527 +#include <linux/vserver/tag_cmd.h>
25528 +
25529 +
25530 +int dx_migrate_task(struct task_struct *p, tag_t tag)
25531 +{
25532 +       if (!p)
25533 +               BUG();
25534 +
25535 +       vxdprintk(VXD_CBIT(tag, 5),
25536 +               "dx_migrate_task(%p[#%d],#%d)", p, p->tag, tag);
25537 +
25538 +       task_lock(p);
25539 +       p->tag = tag;
25540 +       task_unlock(p);
25541 +
25542 +       vxdprintk(VXD_CBIT(tag, 5),
25543 +               "moved task %p into [#%d]", p, tag);
25544 +       return 0;
25545 +}
25546 +
25547 +/* vserver syscall commands below here */
25548 +
25549 +/* taks xid and vx_info functions */
25550 +
25551 +
25552 +int vc_task_tag(uint32_t id)
25553 +{
25554 +       tag_t tag;
25555 +
25556 +       if (id) {
25557 +               struct task_struct *tsk;
25558 +               read_lock(&tasklist_lock);
25559 +               tsk = find_task_by_real_pid(id);
25560 +               tag = (tsk) ? tsk->tag : -ESRCH;
25561 +               read_unlock(&tasklist_lock);
25562 +       } else
25563 +               tag = dx_current_tag();
25564 +       return tag;
25565 +}
25566 +
25567 +
25568 +int vc_tag_migrate(uint32_t tag)
25569 +{
25570 +       return dx_migrate_task(current, tag & 0xFFFF);
25571 +}
25572 +
25573 +
25574 diff -NurpP --minimal linux-2.6.29.1/kernel/vserver/vci_config.h linux-2.6.29.1-vs2.3.0.36.9-pre5/kernel/vserver/vci_config.h
25575 --- linux-2.6.29.1/kernel/vserver/vci_config.h  1970-01-01 01:00:00.000000000 +0100
25576 +++ linux-2.6.29.1-vs2.3.0.36.9-pre5/kernel/vserver/vci_config.h        2009-02-22 22:54:26.000000000 +0100
25577 @@ -0,0 +1,81 @@
25578 +
25579 +/*  interface version */
25580 +
25581 +#define VCI_VERSION            0x00020304
25582 +
25583 +
25584 +enum {
25585 +       VCI_KCBIT_NO_DYNAMIC = 0,
25586 +
25587 +       VCI_KCBIT_PROC_SECURE = 4,
25588 +       VCI_KCBIT_HARDCPU = 5,
25589 +       VCI_KCBIT_IDLELIMIT = 6,
25590 +       VCI_KCBIT_IDLETIME = 7,
25591 +
25592 +       VCI_KCBIT_COWBL = 8,
25593 +       VCI_KCBIT_FULLCOWBL = 9,
25594 +       VCI_KCBIT_SPACES = 10,
25595 +       VCI_KCBIT_NETV2 = 11,
25596 +
25597 +       VCI_KCBIT_DEBUG = 16,
25598 +       VCI_KCBIT_HISTORY = 20,
25599 +       VCI_KCBIT_TAGGED = 24,
25600 +       VCI_KCBIT_PPTAG = 28,
25601 +
25602 +       VCI_KCBIT_MORE = 31,
25603 +};
25604 +
25605 +
25606 +static inline uint32_t vci_kernel_config(void)
25607 +{
25608 +       return
25609 +       (1 << VCI_KCBIT_NO_DYNAMIC) |
25610 +
25611 +       /* configured features */
25612 +#ifdef CONFIG_VSERVER_PROC_SECURE
25613 +       (1 << VCI_KCBIT_PROC_SECURE) |
25614 +#endif
25615 +#ifdef CONFIG_VSERVER_HARDCPU
25616 +       (1 << VCI_KCBIT_HARDCPU) |
25617 +#endif
25618 +#ifdef CONFIG_VSERVER_IDLELIMIT
25619 +       (1 << VCI_KCBIT_IDLELIMIT) |
25620 +#endif
25621 +#ifdef CONFIG_VSERVER_IDLETIME
25622 +       (1 << VCI_KCBIT_IDLETIME) |
25623 +#endif
25624 +#ifdef CONFIG_VSERVER_COWBL
25625 +       (1 << VCI_KCBIT_COWBL) |
25626 +       (1 << VCI_KCBIT_FULLCOWBL) |
25627 +#endif
25628 +       (1 << VCI_KCBIT_SPACES) |
25629 +       (1 << VCI_KCBIT_NETV2) |
25630 +
25631 +       /* debug options */
25632 +#ifdef CONFIG_VSERVER_DEBUG
25633 +       (1 << VCI_KCBIT_DEBUG) |
25634 +#endif
25635 +#ifdef CONFIG_VSERVER_HISTORY
25636 +       (1 << VCI_KCBIT_HISTORY) |
25637 +#endif
25638 +
25639 +       /* inode context tagging */
25640 +#if    defined(CONFIG_TAGGING_NONE)
25641 +       (0 << VCI_KCBIT_TAGGED) |
25642 +#elif  defined(CONFIG_TAGGING_UID16)
25643 +       (1 << VCI_KCBIT_TAGGED) |
25644 +#elif  defined(CONFIG_TAGGING_GID16)
25645 +       (2 << VCI_KCBIT_TAGGED) |
25646 +#elif  defined(CONFIG_TAGGING_ID24)
25647 +       (3 << VCI_KCBIT_TAGGED) |
25648 +#elif  defined(CONFIG_TAGGING_INTERN)
25649 +       (4 << VCI_KCBIT_TAGGED) |
25650 +#elif  defined(CONFIG_TAGGING_RUNTIME)
25651 +       (5 << VCI_KCBIT_TAGGED) |
25652 +#else
25653 +       (7 << VCI_KCBIT_TAGGED) |
25654 +#endif
25655 +       (1 << VCI_KCBIT_PPTAG) |
25656 +       0;
25657 +}
25658 +
25659 diff -NurpP --minimal linux-2.6.29.1/mm/filemap_xip.c linux-2.6.29.1-vs2.3.0.36.9-pre5/mm/filemap_xip.c
25660 --- linux-2.6.29.1/mm/filemap_xip.c     2009-03-24 14:22:45.000000000 +0100
25661 +++ linux-2.6.29.1-vs2.3.0.36.9-pre5/mm/filemap_xip.c   2009-03-24 14:48:36.000000000 +0100
25662 @@ -17,6 +17,7 @@
25663  #include <linux/sched.h>
25664  #include <linux/seqlock.h>
25665  #include <linux/mutex.h>
25666 +#include <linux/vs_memory.h>
25667  #include <asm/tlbflush.h>
25668  #include <asm/io.h>
25669  
25670 diff -NurpP --minimal linux-2.6.29.1/mm/fremap.c linux-2.6.29.1-vs2.3.0.36.9-pre5/mm/fremap.c
25671 --- linux-2.6.29.1/mm/fremap.c  2009-03-24 14:22:45.000000000 +0100
25672 +++ linux-2.6.29.1-vs2.3.0.36.9-pre5/mm/fremap.c        2009-03-24 14:48:36.000000000 +0100
25673 @@ -16,6 +16,7 @@
25674  #include <linux/module.h>
25675  #include <linux/syscalls.h>
25676  #include <linux/mmu_notifier.h>
25677 +#include <linux/vs_memory.h>
25678  
25679  #include <asm/mmu_context.h>
25680  #include <asm/cacheflush.h>
25681 diff -NurpP --minimal linux-2.6.29.1/mm/hugetlb.c linux-2.6.29.1-vs2.3.0.36.9-pre5/mm/hugetlb.c
25682 --- linux-2.6.29.1/mm/hugetlb.c 2009-03-24 14:22:45.000000000 +0100
25683 +++ linux-2.6.29.1-vs2.3.0.36.9-pre5/mm/hugetlb.c       2009-03-24 14:48:36.000000000 +0100
25684 @@ -24,6 +24,7 @@
25685  #include <asm/io.h>
25686  
25687  #include <linux/hugetlb.h>
25688 +#include <linux/vs_memory.h>
25689  #include "internal.h"
25690  
25691  const unsigned long hugetlb_zero = 0, hugetlb_infinity = ~0UL;
25692 diff -NurpP --minimal linux-2.6.29.1/mm/memory.c linux-2.6.29.1-vs2.3.0.36.9-pre5/mm/memory.c
25693 --- linux-2.6.29.1/mm/memory.c  2009-04-15 22:53:12.000000000 +0200
25694 +++ linux-2.6.29.1-vs2.3.0.36.9-pre5/mm/memory.c        2009-04-15 22:58:30.000000000 +0200
25695 @@ -55,6 +55,7 @@
25696  #include <linux/kallsyms.h>
25697  #include <linux/swapops.h>
25698  #include <linux/elf.h>
25699 +// #include <linux/vs_memory.h>
25700  
25701  #include <asm/pgalloc.h>
25702  #include <asm/uaccess.h>
25703 @@ -612,6 +613,9 @@ static int copy_pte_range(struct mm_stru
25704         int progress = 0;
25705         int rss[2];
25706  
25707 +       if (!vx_rss_avail(dst_mm, ((end - addr)/PAGE_SIZE + 1)))
25708 +               return -ENOMEM;
25709 +
25710  again:
25711         rss[1] = rss[0] = 0;
25712         dst_pte = pte_alloc_map_lock(dst_mm, dst_pmd, addr, &dst_ptl);
25713 @@ -2435,6 +2439,11 @@ static int do_swap_page(struct mm_struct
25714                 count_vm_event(PGMAJFAULT);
25715         }
25716  
25717 +       if (!vx_rss_avail(mm, 1)) {
25718 +               ret = VM_FAULT_OOM;
25719 +               goto out;
25720 +       }
25721 +
25722         mark_page_accessed(page);
25723  
25724         lock_page(page);
25725 @@ -2526,6 +2535,8 @@ static int do_anonymous_page(struct mm_s
25726         /* Allocate our own private page. */
25727         pte_unmap(page_table);
25728  
25729 +       if (!vx_rss_avail(mm, 1))
25730 +               goto oom;
25731         if (unlikely(anon_vma_prepare(vma)))
25732                 goto oom;
25733         page = alloc_zeroed_user_highpage_movable(vma, address);
25734 @@ -2793,6 +2804,7 @@ static inline int handle_pte_fault(struc
25735  {
25736         pte_t entry;
25737         spinlock_t *ptl;
25738 +       int ret = 0, type = VXPT_UNKNOWN;
25739  
25740         entry = *pte;
25741         if (!pte_present(entry)) {
25742 @@ -2817,9 +2829,12 @@ static inline int handle_pte_fault(struc
25743         if (unlikely(!pte_same(*pte, entry)))
25744                 goto unlock;
25745         if (write_access) {
25746 -               if (!pte_write(entry))
25747 -                       return do_wp_page(mm, vma, address,
25748 +               if (!pte_write(entry)) {
25749 +                       ret = do_wp_page(mm, vma, address,
25750                                         pte, pmd, ptl, entry);
25751 +                       type = VXPT_WRITE;
25752 +                       goto out;
25753 +               }
25754                 entry = pte_mkdirty(entry);
25755         }
25756         entry = pte_mkyoung(entry);
25757 @@ -2837,7 +2852,10 @@ static inline int handle_pte_fault(struc
25758         }
25759  unlock:
25760         pte_unmap_unlock(pte, ptl);
25761 -       return 0;
25762 +       ret = 0;
25763 +out:
25764 +       vx_page_fault(mm, vma, type, ret);
25765 +       return ret;
25766  }
25767  
25768  /*
25769 diff -NurpP --minimal linux-2.6.29.1/mm/mlock.c linux-2.6.29.1-vs2.3.0.36.9-pre5/mm/mlock.c
25770 --- linux-2.6.29.1/mm/mlock.c   2009-03-24 14:22:45.000000000 +0100
25771 +++ linux-2.6.29.1-vs2.3.0.36.9-pre5/mm/mlock.c 2009-03-28 05:08:26.000000000 +0100
25772 @@ -18,6 +18,7 @@
25773  #include <linux/rmap.h>
25774  #include <linux/mmzone.h>
25775  #include <linux/hugetlb.h>
25776 +#include <linux/vs_memory.h>
25777  
25778  #include "internal.h"
25779  
25780 @@ -415,7 +416,7 @@ success:
25781         nr_pages = (end - start) >> PAGE_SHIFT;
25782         if (!lock)
25783                 nr_pages = -nr_pages;
25784 -       mm->locked_vm += nr_pages;
25785 +       vx_vmlocked_add(mm, nr_pages);
25786  
25787         /*
25788          * vm_flags is protected by the mmap_sem held in write mode.
25789 @@ -492,7 +493,7 @@ static int do_mlock(unsigned long start,
25790  
25791  SYSCALL_DEFINE2(mlock, unsigned long, start, size_t, len)
25792  {
25793 -       unsigned long locked;
25794 +       unsigned long locked, grow;
25795         unsigned long lock_limit;
25796         int error = -ENOMEM;
25797  
25798 @@ -505,8 +506,10 @@ SYSCALL_DEFINE2(mlock, unsigned long, st
25799         len = PAGE_ALIGN(len + (start & ~PAGE_MASK));
25800         start &= PAGE_MASK;
25801  
25802 -       locked = len >> PAGE_SHIFT;
25803 -       locked += current->mm->locked_vm;
25804 +       grow = len >> PAGE_SHIFT;
25805 +       if (!vx_vmlocked_avail(current->mm, grow))
25806 +               goto out;
25807 +       locked = current->mm->locked_vm + grow;
25808  
25809         lock_limit = current->signal->rlim[RLIMIT_MEMLOCK].rlim_cur;
25810         lock_limit >>= PAGE_SHIFT;
25811 @@ -514,6 +517,7 @@ SYSCALL_DEFINE2(mlock, unsigned long, st
25812         /* check against resource limits */
25813         if ((locked <= lock_limit) || capable(CAP_IPC_LOCK))
25814                 error = do_mlock(start, len, 1);
25815 +out:
25816         up_write(&current->mm->mmap_sem);
25817         return error;
25818  }
25819 @@ -575,6 +579,8 @@ SYSCALL_DEFINE1(mlockall, int, flags)
25820         lock_limit >>= PAGE_SHIFT;
25821  
25822         ret = -ENOMEM;
25823 +       if (!vx_vmlocked_avail(current->mm, current->mm->total_vm))
25824 +               goto out;
25825         if (!(flags & MCL_CURRENT) || (current->mm->total_vm <= lock_limit) ||
25826             capable(CAP_IPC_LOCK))
25827                 ret = do_mlockall(flags);
25828 @@ -652,8 +658,10 @@ void *alloc_locked_buffer(size_t size)
25829         if (!buffer)
25830                 goto out;
25831  
25832 -       current->mm->total_vm  += pgsz;
25833 -       current->mm->locked_vm += pgsz;
25834 +       // current->mm->total_vm  += pgsz;
25835 +       vx_vmpages_add(current->mm, pgsz);
25836 +       // current->mm->locked_vm += pgsz;
25837 +       vx_vmlocked_add(current->mm, pgsz);
25838  
25839   out:
25840         up_write(&current->mm->mmap_sem);
25841 @@ -666,8 +674,10 @@ void release_locked_buffer(void *buffer,
25842  
25843         down_write(&current->mm->mmap_sem);
25844  
25845 -       current->mm->total_vm  -= pgsz;
25846 -       current->mm->locked_vm -= pgsz;
25847 +       // current->mm->total_vm  -= pgsz;
25848 +       vx_vmpages_sub(current->mm, pgsz);
25849 +       // current->mm->locked_vm -= pgsz;
25850 +       vx_vmlocked_sub(current->mm, pgsz);
25851  
25852         up_write(&current->mm->mmap_sem);
25853  }
25854 diff -NurpP --minimal linux-2.6.29.1/mm/mmap.c linux-2.6.29.1-vs2.3.0.36.9-pre5/mm/mmap.c
25855 --- linux-2.6.29.1/mm/mmap.c    2009-03-24 14:22:45.000000000 +0100
25856 +++ linux-2.6.29.1-vs2.3.0.36.9-pre5/mm/mmap.c  2009-03-24 14:48:36.000000000 +0100
25857 @@ -1219,7 +1219,8 @@ munmap_back:
25858         if (correct_wcount)
25859                 atomic_inc(&inode->i_writecount);
25860  out:
25861 -       mm->total_vm += len >> PAGE_SHIFT;
25862 +       // mm->total_vm += len >> PAGE_SHIFT;
25863 +       vx_vmpages_add(mm, len >> PAGE_SHIFT);
25864         vm_stat_account(mm, vm_flags, file, len >> PAGE_SHIFT);
25865         if (vm_flags & VM_LOCKED) {
25866                 /*
25867 @@ -1228,7 +1229,8 @@ out:
25868                 long nr_pages = mlock_vma_pages_range(vma, addr, addr + len);
25869                 if (nr_pages < 0)
25870                         return nr_pages;        /* vma gone! */
25871 -               mm->locked_vm += (len >> PAGE_SHIFT) - nr_pages;
25872 +               // mm->locked_vm += (len >> PAGE_SHIFT) - nr_pages;
25873 +               vx_vmlocked_add(mm, (len >> PAGE_SHIFT) - nr_pages);
25874         } else if ((flags & MAP_POPULATE) && !(flags & MAP_NONBLOCK))
25875                 make_pages_present(addr, addr + len);
25876         return addr;
25877 @@ -1575,9 +1577,9 @@ static int acct_stack_growth(struct vm_a
25878                 return -ENOMEM;
25879  
25880         /* Ok, everything looks good - let it rip */
25881 -       mm->total_vm += grow;
25882 +       vx_vmpages_add(mm, grow);
25883         if (vma->vm_flags & VM_LOCKED)
25884 -               mm->locked_vm += grow;
25885 +               vx_vmlocked_add(mm, grow);
25886         vm_stat_account(mm, vma->vm_flags, vma->vm_file, grow);
25887         return 0;
25888  }
25889 @@ -1752,7 +1754,8 @@ static void remove_vma_list(struct mm_st
25890         do {
25891                 long nrpages = vma_pages(vma);
25892  
25893 -               mm->total_vm -= nrpages;
25894 +               // mm->total_vm -= nrpages;
25895 +               vx_vmpages_sub(mm, nrpages);
25896                 vm_stat_account(mm, vma->vm_flags, vma->vm_file, -nrpages);
25897                 vma = remove_vma(vma);
25898         } while (vma);
25899 @@ -1924,7 +1927,8 @@ int do_munmap(struct mm_struct *mm, unsi
25900                 struct vm_area_struct *tmp = vma;
25901                 while (tmp && tmp->vm_start < end) {
25902                         if (tmp->vm_flags & VM_LOCKED) {
25903 -                               mm->locked_vm -= vma_pages(tmp);
25904 +                               // mm->locked_vm -= vma_pages(tmp);
25905 +                               vx_vmlocked_sub(mm, vma_pages(tmp));
25906                                 munlock_vma_pages_all(tmp);
25907                         }
25908                         tmp = tmp->vm_next;
25909 @@ -2013,6 +2017,8 @@ unsigned long do_brk(unsigned long addr,
25910                 lock_limit >>= PAGE_SHIFT;
25911                 if (locked > lock_limit && !capable(CAP_IPC_LOCK))
25912                         return -EAGAIN;
25913 +               if (!vx_vmlocked_avail(mm, len >> PAGE_SHIFT))
25914 +                       return -ENOMEM;
25915         }
25916  
25917         /*
25918 @@ -2039,7 +2045,8 @@ unsigned long do_brk(unsigned long addr,
25919         if (mm->map_count > sysctl_max_map_count)
25920                 return -ENOMEM;
25921  
25922 -       if (security_vm_enough_memory(len >> PAGE_SHIFT))
25923 +       if (security_vm_enough_memory(len >> PAGE_SHIFT) ||
25924 +               !vx_vmpages_avail(mm, len >> PAGE_SHIFT))
25925                 return -ENOMEM;
25926  
25927         /* Can we just expand an old private anonymous mapping? */
25928 @@ -2065,10 +2072,13 @@ unsigned long do_brk(unsigned long addr,
25929         vma->vm_page_prot = vm_get_page_prot(flags);
25930         vma_link(mm, vma, prev, rb_link, rb_parent);
25931  out:
25932 -       mm->total_vm += len >> PAGE_SHIFT;
25933 +       // mm->total_vm += len >> PAGE_SHIFT;
25934 +       vx_vmpages_add(mm, len >> PAGE_SHIFT);
25935 +
25936         if (flags & VM_LOCKED) {
25937                 if (!mlock_vma_pages_range(vma, addr, addr + len))
25938 -                       mm->locked_vm += (len >> PAGE_SHIFT);
25939 +                       // mm->locked_vm += (len >> PAGE_SHIFT);
25940 +                       vx_vmlocked_add(mm, len >> PAGE_SHIFT);
25941         }
25942         return addr;
25943  }
25944 @@ -2111,6 +2121,11 @@ void exit_mmap(struct mm_struct *mm)
25945         free_pgtables(tlb, vma, FIRST_USER_ADDRESS, 0);
25946         tlb_finish_mmu(tlb, 0, end);
25947  
25948 +       set_mm_counter(mm, file_rss, 0);
25949 +       set_mm_counter(mm, anon_rss, 0);
25950 +       vx_vmpages_sub(mm, mm->total_vm);
25951 +       vx_vmlocked_sub(mm, mm->locked_vm);
25952 +
25953         /*
25954          * Walk the list again, actually closing and freeing it,
25955          * with preemption enabled, without holding any MM locks.
25956 @@ -2150,7 +2165,8 @@ int insert_vm_struct(struct mm_struct * 
25957         if (__vma && __vma->vm_start < vma->vm_end)
25958                 return -ENOMEM;
25959         if ((vma->vm_flags & VM_ACCOUNT) &&
25960 -            security_vm_enough_memory_mm(mm, vma_pages(vma)))
25961 +               (security_vm_enough_memory_mm(mm, vma_pages(vma)) ||
25962 +               !vx_vmpages_avail(mm, vma_pages(vma))))
25963                 return -ENOMEM;
25964         vma_link(mm, vma, prev, rb_link, rb_parent);
25965         return 0;
25966 @@ -2226,6 +2242,8 @@ int may_expand_vm(struct mm_struct *mm, 
25967  
25968         if (cur + npages > lim)
25969                 return 0;
25970 +       if (!vx_vmpages_avail(mm, npages))
25971 +               return 0;
25972         return 1;
25973  }
25974  
25975 @@ -2303,8 +2321,7 @@ int install_special_mapping(struct mm_st
25976                 return -ENOMEM;
25977         }
25978  
25979 -       mm->total_vm += len >> PAGE_SHIFT;
25980 -
25981 +       vx_vmpages_add(mm, len >> PAGE_SHIFT);
25982         return 0;
25983  }
25984  
25985 diff -NurpP --minimal linux-2.6.29.1/mm/mremap.c linux-2.6.29.1-vs2.3.0.36.9-pre5/mm/mremap.c
25986 --- linux-2.6.29.1/mm/mremap.c  2009-03-24 14:22:45.000000000 +0100
25987 +++ linux-2.6.29.1-vs2.3.0.36.9-pre5/mm/mremap.c        2009-03-24 14:48:36.000000000 +0100
25988 @@ -19,6 +19,7 @@
25989  #include <linux/security.h>
25990  #include <linux/syscalls.h>
25991  #include <linux/mmu_notifier.h>
25992 +#include <linux/vs_memory.h>
25993  
25994  #include <asm/uaccess.h>
25995  #include <asm/cacheflush.h>
25996 @@ -220,7 +221,7 @@ static unsigned long move_vma(struct vm_
25997          * If this were a serious issue, we'd add a flag to do_munmap().
25998          */
25999         hiwater_vm = mm->hiwater_vm;
26000 -       mm->total_vm += new_len >> PAGE_SHIFT;
26001 +       vx_vmpages_add(mm, new_len >> PAGE_SHIFT);
26002         vm_stat_account(mm, vma->vm_flags, vma->vm_file, new_len>>PAGE_SHIFT);
26003  
26004         if (do_munmap(mm, old_addr, old_len) < 0) {
26005 @@ -238,7 +239,7 @@ static unsigned long move_vma(struct vm_
26006         }
26007  
26008         if (vm_flags & VM_LOCKED) {
26009 -               mm->locked_vm += new_len >> PAGE_SHIFT;
26010 +               vx_vmlocked_add(mm, new_len >> PAGE_SHIFT);
26011                 if (new_len > old_len)
26012                         mlock_vma_pages_range(new_vma, new_addr + old_len,
26013                                                        new_addr + new_len);
26014 @@ -349,6 +350,9 @@ unsigned long do_mremap(unsigned long ad
26015                 ret = -EAGAIN;
26016                 if (locked > lock_limit && !capable(CAP_IPC_LOCK))
26017                         goto out;
26018 +               if (!vx_vmlocked_avail(current->mm,
26019 +                       (new_len - old_len) >> PAGE_SHIFT))
26020 +                       goto out;
26021         }
26022         if (!may_expand_vm(mm, (new_len - old_len) >> PAGE_SHIFT)) {
26023                 ret = -ENOMEM;
26024 @@ -377,10 +381,12 @@ unsigned long do_mremap(unsigned long ad
26025                         vma_adjust(vma, vma->vm_start,
26026                                 addr + new_len, vma->vm_pgoff, NULL);
26027  
26028 -                       mm->total_vm += pages;
26029 +                       // mm->total_vm += pages;
26030 +                       vx_vmpages_add(mm, pages);
26031                         vm_stat_account(mm, vma->vm_flags, vma->vm_file, pages);
26032                         if (vma->vm_flags & VM_LOCKED) {
26033 -                               mm->locked_vm += pages;
26034 +                               // mm->locked_vm += pages;
26035 +                               vx_vmlocked_add(mm, pages);
26036                                 mlock_vma_pages_range(vma, addr + old_len,
26037                                                    addr + new_len);
26038                         }
26039 diff -NurpP --minimal linux-2.6.29.1/mm/nommu.c linux-2.6.29.1-vs2.3.0.36.9-pre5/mm/nommu.c
26040 --- linux-2.6.29.1/mm/nommu.c   2009-03-24 14:22:45.000000000 +0100
26041 +++ linux-2.6.29.1-vs2.3.0.36.9-pre5/mm/nommu.c 2009-03-24 18:25:55.000000000 +0100
26042 @@ -1348,7 +1348,7 @@ unsigned long do_mmap_pgoff(struct file 
26043         /* okay... we have a mapping; now we have to register it */
26044         result = vma->vm_start;
26045  
26046 -       current->mm->total_vm += len >> PAGE_SHIFT;
26047 +       vx_vmpages_add(current->mm, len >> PAGE_SHIFT);
26048  
26049  share:
26050         add_vma_to_mm(current->mm, vma);
26051 @@ -1614,7 +1614,7 @@ void exit_mmap(struct mm_struct *mm)
26052  
26053         kenter("");
26054  
26055 -       mm->total_vm = 0;
26056 +       vx_vmpages_sub(mm, mm->total_vm);
26057  
26058         while ((vma = mm->mmap)) {
26059                 mm->mmap = vma->vm_next;
26060 diff -NurpP --minimal linux-2.6.29.1/mm/oom_kill.c linux-2.6.29.1-vs2.3.0.36.9-pre5/mm/oom_kill.c
26061 --- linux-2.6.29.1/mm/oom_kill.c        2009-03-24 14:22:45.000000000 +0100
26062 +++ linux-2.6.29.1-vs2.3.0.36.9-pre5/mm/oom_kill.c      2009-03-24 14:48:36.000000000 +0100
26063 @@ -27,6 +27,7 @@
26064  #include <linux/notifier.h>
26065  #include <linux/memcontrol.h>
26066  #include <linux/security.h>
26067 +#include <linux/vs_memory.h>
26068  
26069  int sysctl_panic_on_oom;
26070  int sysctl_oom_kill_allocating_task;
26071 @@ -72,6 +73,12 @@ unsigned long badness(struct task_struct
26072         points = mm->total_vm;
26073  
26074         /*
26075 +        * add points for context badness
26076 +        */
26077 +
26078 +       points += vx_badness(p, mm);
26079 +
26080 +       /*
26081          * After this unlock we can no longer dereference local variable `mm'
26082          */
26083         task_unlock(p);
26084 @@ -162,8 +169,8 @@ unsigned long badness(struct task_struct
26085         }
26086  
26087  #ifdef DEBUG
26088 -       printk(KERN_DEBUG "OOMkill: task %d (%s) got %lu points\n",
26089 -       p->pid, p->comm, points);
26090 +       printk(KERN_DEBUG "OOMkill: task %d:#%u (%s) got %d points\n",
26091 +               task_pid_nr(p), p->xid, p->comm, points);
26092  #endif
26093         return points;
26094  }
26095 @@ -326,8 +333,8 @@ static void __oom_kill_task(struct task_
26096         }
26097  
26098         if (verbose)
26099 -               printk(KERN_ERR "Killed process %d (%s)\n",
26100 -                               task_pid_nr(p), p->comm);
26101 +               printk(KERN_ERR "Killed process %d:#%u (%s)\n",
26102 +                               task_pid_nr(p), p->xid, p->comm);
26103  
26104         /*
26105          * We give our sacrificial lamb high priority and access to
26106 @@ -410,8 +417,8 @@ static int oom_kill_process(struct task_
26107                 return 0;
26108         }
26109  
26110 -       printk(KERN_ERR "%s: kill process %d (%s) score %li or a child\n",
26111 -                                       message, task_pid_nr(p), p->comm, points);
26112 +       printk(KERN_ERR "%s: kill process %d:#%u (%s) score %li or a child\n",
26113 +                               message, task_pid_nr(p), p->xid, p->comm, points);
26114  
26115         /* Try to kill a child first */
26116         list_for_each_entry(c, &p->children, sibling) {
26117 diff -NurpP --minimal linux-2.6.29.1/mm/page_alloc.c linux-2.6.29.1-vs2.3.0.36.9-pre5/mm/page_alloc.c
26118 --- linux-2.6.29.1/mm/page_alloc.c      2009-03-24 14:22:45.000000000 +0100
26119 +++ linux-2.6.29.1-vs2.3.0.36.9-pre5/mm/page_alloc.c    2009-03-24 14:48:36.000000000 +0100
26120 @@ -46,6 +46,8 @@
26121  #include <linux/page-isolation.h>
26122  #include <linux/page_cgroup.h>
26123  #include <linux/debugobjects.h>
26124 +#include <linux/vs_base.h>
26125 +#include <linux/vs_limit.h>
26126  
26127  #include <asm/tlbflush.h>
26128  #include <asm/div64.h>
26129 @@ -1839,6 +1841,9 @@ void si_meminfo(struct sysinfo *val)
26130         val->totalhigh = totalhigh_pages;
26131         val->freehigh = nr_free_highpages();
26132         val->mem_unit = PAGE_SIZE;
26133 +
26134 +       if (vx_flags(VXF_VIRT_MEM, 0))
26135 +               vx_vsi_meminfo(val);
26136  }
26137  
26138  EXPORT_SYMBOL(si_meminfo);
26139 @@ -1859,6 +1864,9 @@ void si_meminfo_node(struct sysinfo *val
26140         val->freehigh = 0;
26141  #endif
26142         val->mem_unit = PAGE_SIZE;
26143 +
26144 +       if (vx_flags(VXF_VIRT_MEM, 0))
26145 +               vx_vsi_meminfo(val);
26146  }
26147  #endif
26148  
26149 diff -NurpP --minimal linux-2.6.29.1/mm/rmap.c linux-2.6.29.1-vs2.3.0.36.9-pre5/mm/rmap.c
26150 --- linux-2.6.29.1/mm/rmap.c    2009-03-24 14:22:45.000000000 +0100
26151 +++ linux-2.6.29.1-vs2.3.0.36.9-pre5/mm/rmap.c  2009-03-24 18:26:27.000000000 +0100
26152 @@ -50,6 +50,7 @@
26153  #include <linux/memcontrol.h>
26154  #include <linux/mmu_notifier.h>
26155  #include <linux/migrate.h>
26156 +#include <linux/vs_memory.h>
26157  
26158  #include <asm/tlbflush.h>
26159  
26160 diff -NurpP --minimal linux-2.6.29.1/mm/shmem.c linux-2.6.29.1-vs2.3.0.36.9-pre5/mm/shmem.c
26161 --- linux-2.6.29.1/mm/shmem.c   2009-03-24 14:22:45.000000000 +0100
26162 +++ linux-2.6.29.1-vs2.3.0.36.9-pre5/mm/shmem.c 2009-03-24 14:48:36.000000000 +0100
26163 @@ -1757,7 +1757,7 @@ static int shmem_statfs(struct dentry *d
26164  {
26165         struct shmem_sb_info *sbinfo = SHMEM_SB(dentry->d_sb);
26166  
26167 -       buf->f_type = TMPFS_MAGIC;
26168 +       buf->f_type = TMPFS_SUPER_MAGIC;
26169         buf->f_bsize = PAGE_CACHE_SIZE;
26170         buf->f_namelen = NAME_MAX;
26171         spin_lock(&sbinfo->stat_lock);
26172 @@ -2326,7 +2326,7 @@ static int shmem_fill_super(struct super
26173         sb->s_maxbytes = SHMEM_MAX_BYTES;
26174         sb->s_blocksize = PAGE_CACHE_SIZE;
26175         sb->s_blocksize_bits = PAGE_CACHE_SHIFT;
26176 -       sb->s_magic = TMPFS_MAGIC;
26177 +       sb->s_magic = TMPFS_SUPER_MAGIC;
26178         sb->s_op = &shmem_ops;
26179         sb->s_time_gran = 1;
26180  #ifdef CONFIG_TMPFS_POSIX_ACL
26181 diff -NurpP --minimal linux-2.6.29.1/mm/slab.c linux-2.6.29.1-vs2.3.0.36.9-pre5/mm/slab.c
26182 --- linux-2.6.29.1/mm/slab.c    2009-03-24 14:22:45.000000000 +0100
26183 +++ linux-2.6.29.1-vs2.3.0.36.9-pre5/mm/slab.c  2009-03-24 14:48:36.000000000 +0100
26184 @@ -509,6 +509,8 @@ struct kmem_cache {
26185  #define STATS_INC_FREEMISS(x)  do { } while (0)
26186  #endif
26187  
26188 +#include "slab_vs.h"
26189 +
26190  #if DEBUG
26191  
26192  /*
26193 @@ -3275,6 +3277,7 @@ retry:
26194  
26195         obj = slab_get_obj(cachep, slabp, nodeid);
26196         check_slabp(cachep, slabp);
26197 +       vx_slab_alloc(cachep, flags);
26198         l3->free_objects--;
26199         /* move slabp to correct slabp list: */
26200         list_del(&slabp->list);
26201 @@ -3347,6 +3350,7 @@ __cache_alloc_node(struct kmem_cache *ca
26202         /* ___cache_alloc_node can fall back to other nodes */
26203         ptr = ____cache_alloc_node(cachep, flags, nodeid);
26204    out:
26205 +       vx_slab_alloc(cachep, flags);
26206         local_irq_restore(save_flags);
26207         ptr = cache_alloc_debugcheck_after(cachep, flags, ptr, caller);
26208  
26209 @@ -3518,6 +3522,7 @@ static inline void __cache_free(struct k
26210  
26211         check_irq_off();
26212         objp = cache_free_debugcheck(cachep, objp, __builtin_return_address(0));
26213 +       vx_slab_free(cachep);
26214  
26215         /*
26216          * Skip calling cache_free_alien() when the platform is not numa.
26217 diff -NurpP --minimal linux-2.6.29.1/mm/slab_vs.h linux-2.6.29.1-vs2.3.0.36.9-pre5/mm/slab_vs.h
26218 --- linux-2.6.29.1/mm/slab_vs.h 1970-01-01 01:00:00.000000000 +0100
26219 +++ linux-2.6.29.1-vs2.3.0.36.9-pre5/mm/slab_vs.h       2009-02-22 22:54:26.000000000 +0100
26220 @@ -0,0 +1,27 @@
26221 +
26222 +#include <linux/vserver/context.h>
26223 +
26224 +#include <linux/vs_context.h>
26225 +
26226 +static inline
26227 +void vx_slab_alloc(struct kmem_cache *cachep, gfp_t flags)
26228 +{
26229 +       int what = gfp_zone(cachep->gfpflags);
26230 +
26231 +       if (!current->vx_info)
26232 +               return;
26233 +
26234 +       atomic_add(cachep->buffer_size, &current->vx_info->cacct.slab[what]);
26235 +}
26236 +
26237 +static inline
26238 +void vx_slab_free(struct kmem_cache *cachep)
26239 +{
26240 +       int what = gfp_zone(cachep->gfpflags);
26241 +
26242 +       if (!current->vx_info)
26243 +               return;
26244 +
26245 +       atomic_sub(cachep->buffer_size, &current->vx_info->cacct.slab[what]);
26246 +}
26247 +
26248 diff -NurpP --minimal linux-2.6.29.1/mm/swapfile.c linux-2.6.29.1-vs2.3.0.36.9-pre5/mm/swapfile.c
26249 --- linux-2.6.29.1/mm/swapfile.c        2009-03-24 14:22:45.000000000 +0100
26250 +++ linux-2.6.29.1-vs2.3.0.36.9-pre5/mm/swapfile.c      2009-03-24 18:27:15.000000000 +0100
26251 @@ -34,6 +34,8 @@
26252  #include <asm/tlbflush.h>
26253  #include <linux/swapops.h>
26254  #include <linux/page_cgroup.h>
26255 +#include <linux/vs_base.h>
26256 +#include <linux/vs_memory.h>
26257  
26258  static DEFINE_SPINLOCK(swap_lock);
26259  static unsigned int nr_swapfiles;
26260 @@ -1935,6 +1937,8 @@ void si_swapinfo(struct sysinfo *val)
26261         val->freeswap = nr_swap_pages + nr_to_be_unused;
26262         val->totalswap = total_swap_pages + nr_to_be_unused;
26263         spin_unlock(&swap_lock);
26264 +       if (vx_flags(VXF_VIRT_MEM, 0))
26265 +               vx_vsi_swapinfo(val);
26266  }
26267  
26268  /*
26269 diff -NurpP --minimal linux-2.6.29.1/net/core/dev.c linux-2.6.29.1-vs2.3.0.36.9-pre5/net/core/dev.c
26270 --- linux-2.6.29.1/net/core/dev.c       2009-04-15 22:53:12.000000000 +0200
26271 +++ linux-2.6.29.1-vs2.3.0.36.9-pre5/net/core/dev.c     2009-04-15 22:58:30.000000000 +0200
26272 @@ -126,6 +126,7 @@
26273  #include <linux/in.h>
26274  #include <linux/jhash.h>
26275  #include <linux/random.h>
26276 +#include <linux/vs_inet.h>
26277  
26278  #include "net-sysfs.h"
26279  
26280 @@ -2853,6 +2854,8 @@ static int dev_ifconf(struct net *net, c
26281  
26282         total = 0;
26283         for_each_netdev(net, dev) {
26284 +               if (!nx_dev_visible(current->nx_info, dev))
26285 +                       continue;
26286                 for (i = 0; i < NPROTO; i++) {
26287                         if (gifconf_list[i]) {
26288                                 int done;
26289 @@ -2921,6 +2924,9 @@ static void dev_seq_printf_stats(struct 
26290  {
26291         const struct net_device_stats *stats = dev_get_stats(dev);
26292  
26293 +       if (!nx_dev_visible(current->nx_info, dev))
26294 +               return;
26295 +
26296         seq_printf(seq, "%6s:%8lu %7lu %4lu %4lu %4lu %5lu %10lu %9lu "
26297                    "%8lu %7lu %4lu %4lu %4lu %5lu %7lu %10lu\n",
26298                    dev->name, stats->rx_bytes, stats->rx_packets,
26299 @@ -4862,6 +4868,15 @@ int dev_change_net_namespace(struct net_
26300                 goto out;
26301  #endif
26302  
26303 +#ifdef CONFIG_SYSFS
26304 +       /* Don't allow real devices to be moved when sysfs
26305 +        * is enabled.
26306 +        */
26307 +       err = -EINVAL;
26308 +       if (dev->dev.parent)
26309 +               goto out;
26310 +#endif
26311 +
26312         /* Ensure the device has been registrered */
26313         err = -EINVAL;
26314         if (dev->reg_state != NETREG_REGISTERED)
26315 @@ -4921,6 +4936,8 @@ int dev_change_net_namespace(struct net_
26316  
26317         netdev_unregister_kobject(dev);
26318  
26319 +       netdev_unregister_kobject(dev);
26320 +
26321         /* Actually switch the network namespace */
26322         dev_net_set(dev, net);
26323  
26324 diff -NurpP --minimal linux-2.6.29.1/net/core/net-sysfs.c linux-2.6.29.1-vs2.3.0.36.9-pre5/net/core/net-sysfs.c
26325 --- linux-2.6.29.1/net/core/net-sysfs.c 2009-03-24 14:22:46.000000000 +0100
26326 +++ linux-2.6.29.1-vs2.3.0.36.9-pre5/net/core/net-sysfs.c       2009-03-24 18:30:01.000000000 +0100
26327 @@ -512,6 +512,9 @@ int netdev_register_kobject(struct net_d
26328         if (dev_net(net) != &init_net)
26329                 return 0;
26330  
26331 +       if (dev_net(net) != &init_net)
26332 +               return 0;
26333 +
26334         return device_add(dev);
26335  }
26336  
26337 diff -NurpP --minimal linux-2.6.29.1/net/core/rtnetlink.c linux-2.6.29.1-vs2.3.0.36.9-pre5/net/core/rtnetlink.c
26338 --- linux-2.6.29.1/net/core/rtnetlink.c 2009-03-24 14:22:46.000000000 +0100
26339 +++ linux-2.6.29.1-vs2.3.0.36.9-pre5/net/core/rtnetlink.c       2009-03-24 14:48:36.000000000 +0100
26340 @@ -690,6 +690,8 @@ static int rtnl_dump_ifinfo(struct sk_bu
26341  
26342         idx = 0;
26343         for_each_netdev(net, dev) {
26344 +               if (!nx_dev_visible(skb->sk->sk_nx_info, dev))
26345 +                       continue;
26346                 if (idx < s_idx)
26347                         goto cont;
26348                 if (rtnl_fill_ifinfo(skb, dev, RTM_NEWLINK,
26349 @@ -1235,6 +1237,9 @@ void rtmsg_ifinfo(int type, struct net_d
26350         struct sk_buff *skb;
26351         int err = -ENOBUFS;
26352  
26353 +       if (!nx_dev_visible(current->nx_info, dev))
26354 +               return;
26355 +
26356         skb = nlmsg_new(if_nlmsg_size(dev), GFP_KERNEL);
26357         if (skb == NULL)
26358                 goto errout;
26359 diff -NurpP --minimal linux-2.6.29.1/net/core/sock.c linux-2.6.29.1-vs2.3.0.36.9-pre5/net/core/sock.c
26360 --- linux-2.6.29.1/net/core/sock.c      2009-03-24 14:22:46.000000000 +0100
26361 +++ linux-2.6.29.1-vs2.3.0.36.9-pre5/net/core/sock.c    2009-03-24 14:48:36.000000000 +0100
26362 @@ -124,6 +124,10 @@
26363  #include <linux/ipsec.h>
26364  
26365  #include <linux/filter.h>
26366 +#include <linux/vs_socket.h>
26367 +#include <linux/vs_limit.h>
26368 +#include <linux/vs_context.h>
26369 +#include <linux/vs_network.h>
26370  
26371  #ifdef CONFIG_INET
26372  #include <net/tcp.h>
26373 @@ -900,6 +904,8 @@ static struct sock *sk_prot_alloc(struct
26374                 if (!try_module_get(prot->owner))
26375                         goto out_free_sec;
26376         }
26377 +               sock_vx_init(sk);
26378 +               sock_nx_init(sk);
26379  
26380         return sk;
26381  
26382 @@ -976,6 +982,11 @@ void sk_free(struct sock *sk)
26383                        __func__, atomic_read(&sk->sk_omem_alloc));
26384  
26385         put_net(sock_net(sk));
26386 +       vx_sock_dec(sk);
26387 +       clr_vx_info(&sk->sk_vx_info);
26388 +       sk->sk_xid = -1;
26389 +       clr_nx_info(&sk->sk_nx_info);
26390 +       sk->sk_nid = -1;
26391         sk_prot_free(sk->sk_prot_creator, sk);
26392  }
26393  
26394 @@ -1011,6 +1022,8 @@ struct sock *sk_clone(const struct sock 
26395  
26396                 /* SANITY */
26397                 get_net(sock_net(newsk));
26398 +               sock_vx_init(newsk);
26399 +               sock_nx_init(newsk);
26400                 sk_node_init(&newsk->sk_node);
26401                 sock_lock_init(newsk);
26402                 bh_lock_sock(newsk);
26403 @@ -1057,6 +1070,12 @@ struct sock *sk_clone(const struct sock 
26404                 newsk->sk_priority = 0;
26405                 atomic_set(&newsk->sk_refcnt, 2);
26406  
26407 +               set_vx_info(&newsk->sk_vx_info, sk->sk_vx_info);
26408 +               newsk->sk_xid = sk->sk_xid;
26409 +               vx_sock_inc(newsk);
26410 +               set_nx_info(&newsk->sk_nx_info, sk->sk_nx_info);
26411 +               newsk->sk_nid = sk->sk_nid;
26412 +
26413                 /*
26414                  * Increment the counter in the same struct proto as the master
26415                  * sock (sk_refcnt_debug_inc uses newsk->sk_prot->socks, that
26416 @@ -1744,6 +1763,11 @@ void sock_init_data(struct socket *sock,
26417  
26418         sk->sk_stamp = ktime_set(-1L, 0);
26419  
26420 +       set_vx_info(&sk->sk_vx_info, current->vx_info);
26421 +       sk->sk_xid = vx_current_xid();
26422 +       vx_sock_inc(sk);
26423 +       set_nx_info(&sk->sk_nx_info, current->nx_info);
26424 +       sk->sk_nid = nx_current_nid();
26425         atomic_set(&sk->sk_refcnt, 1);
26426         atomic_set(&sk->sk_drops, 0);
26427  }
26428 diff -NurpP --minimal linux-2.6.29.1/net/ipv4/af_inet.c linux-2.6.29.1-vs2.3.0.36.9-pre5/net/ipv4/af_inet.c
26429 --- linux-2.6.29.1/net/ipv4/af_inet.c   2009-03-24 14:22:46.000000000 +0100
26430 +++ linux-2.6.29.1-vs2.3.0.36.9-pre5/net/ipv4/af_inet.c 2009-03-24 14:48:37.000000000 +0100
26431 @@ -115,6 +115,7 @@
26432  #ifdef CONFIG_IP_MROUTE
26433  #include <linux/mroute.h>
26434  #endif
26435 +#include <linux/vs_limit.h>
26436  
26437  extern void ip_mc_drop_socket(struct sock *sk);
26438  
26439 @@ -325,9 +326,12 @@ lookup_protocol:
26440         }
26441  
26442         err = -EPERM;
26443 +       if ((protocol == IPPROTO_ICMP) &&
26444 +               nx_capable(answer->capability, NXC_RAW_ICMP))
26445 +               goto override;
26446         if (answer->capability > 0 && !capable(answer->capability))
26447                 goto out_rcu_unlock;
26448 -
26449 +override:
26450         err = -EAFNOSUPPORT;
26451         if (!inet_netns_ok(net, protocol))
26452                 goto out_rcu_unlock;
26453 @@ -445,6 +449,7 @@ int inet_bind(struct socket *sock, struc
26454         struct sockaddr_in *addr = (struct sockaddr_in *)uaddr;
26455         struct sock *sk = sock->sk;
26456         struct inet_sock *inet = inet_sk(sk);
26457 +       struct nx_v4_sock_addr nsa;
26458         unsigned short snum;
26459         int chk_addr_ret;
26460         int err;
26461 @@ -458,7 +463,11 @@ int inet_bind(struct socket *sock, struc
26462         if (addr_len < sizeof(struct sockaddr_in))
26463                 goto out;
26464  
26465 -       chk_addr_ret = inet_addr_type(sock_net(sk), addr->sin_addr.s_addr);
26466 +       err = v4_map_sock_addr(inet, addr, &nsa);
26467 +       if (err)
26468 +               goto out;
26469 +
26470 +       chk_addr_ret = inet_addr_type(sock_net(sk), nsa.saddr);
26471  
26472         /* Not specified by any standard per-se, however it breaks too
26473          * many applications when removed.  It is unfortunate since
26474 @@ -470,7 +479,7 @@ int inet_bind(struct socket *sock, struc
26475         err = -EADDRNOTAVAIL;
26476         if (!sysctl_ip_nonlocal_bind &&
26477             !(inet->freebind || inet->transparent) &&
26478 -           addr->sin_addr.s_addr != htonl(INADDR_ANY) &&
26479 +           nsa.saddr != htonl(INADDR_ANY) &&
26480             chk_addr_ret != RTN_LOCAL &&
26481             chk_addr_ret != RTN_MULTICAST &&
26482             chk_addr_ret != RTN_BROADCAST)
26483 @@ -495,7 +504,7 @@ int inet_bind(struct socket *sock, struc
26484         if (sk->sk_state != TCP_CLOSE || inet->num)
26485                 goto out_release_sock;
26486  
26487 -       inet->rcv_saddr = inet->saddr = addr->sin_addr.s_addr;
26488 +       v4_set_sock_addr(inet, &nsa);
26489         if (chk_addr_ret == RTN_MULTICAST || chk_addr_ret == RTN_BROADCAST)
26490                 inet->saddr = 0;  /* Use device */
26491  
26492 @@ -688,11 +697,13 @@ int inet_getname(struct socket *sock, st
26493                      peer == 1))
26494                         return -ENOTCONN;
26495                 sin->sin_port = inet->dport;
26496 -               sin->sin_addr.s_addr = inet->daddr;
26497 +               sin->sin_addr.s_addr =
26498 +                       nx_map_sock_lback(sk->sk_nx_info, inet->daddr);
26499         } else {
26500                 __be32 addr = inet->rcv_saddr;
26501                 if (!addr)
26502                         addr = inet->saddr;
26503 +               addr = nx_map_sock_lback(sk->sk_nx_info, addr);
26504                 sin->sin_port = inet->sport;
26505                 sin->sin_addr.s_addr = addr;
26506         }
26507 diff -NurpP --minimal linux-2.6.29.1/net/ipv4/devinet.c linux-2.6.29.1-vs2.3.0.36.9-pre5/net/ipv4/devinet.c
26508 --- linux-2.6.29.1/net/ipv4/devinet.c   2009-03-24 14:22:46.000000000 +0100
26509 +++ linux-2.6.29.1-vs2.3.0.36.9-pre5/net/ipv4/devinet.c 2009-03-24 14:48:37.000000000 +0100
26510 @@ -413,6 +413,7 @@ struct in_device *inetdev_by_index(struc
26511         return in_dev;
26512  }
26513  
26514 +
26515  /* Called only from RTNL semaphored context. No locks. */
26516  
26517  struct in_ifaddr *inet_ifa_byprefix(struct in_device *in_dev, __be32 prefix,
26518 @@ -653,6 +654,8 @@ int devinet_ioctl(struct net *net, unsig
26519                 *colon = ':';
26520  
26521         if ((in_dev = __in_dev_get_rtnl(dev)) != NULL) {
26522 +               struct nx_info *nxi = current->nx_info;
26523 +
26524                 if (tryaddrmatch) {
26525                         /* Matthias Andree */
26526                         /* compare label and address (4.4BSD style) */
26527 @@ -661,6 +664,8 @@ int devinet_ioctl(struct net *net, unsig
26528                            This is checked above. */
26529                         for (ifap = &in_dev->ifa_list; (ifa = *ifap) != NULL;
26530                              ifap = &ifa->ifa_next) {
26531 +                               if (!nx_v4_ifa_visible(nxi, ifa))
26532 +                                       continue;
26533                                 if (!strcmp(ifr.ifr_name, ifa->ifa_label) &&
26534                                     sin_orig.sin_addr.s_addr ==
26535                                                         ifa->ifa_address) {
26536 @@ -673,9 +678,12 @@ int devinet_ioctl(struct net *net, unsig
26537                    comparing just the label */
26538                 if (!ifa) {
26539                         for (ifap = &in_dev->ifa_list; (ifa = *ifap) != NULL;
26540 -                            ifap = &ifa->ifa_next)
26541 +                            ifap = &ifa->ifa_next) {
26542 +                               if (!nx_v4_ifa_visible(nxi, ifa))
26543 +                                       continue;
26544                                 if (!strcmp(ifr.ifr_name, ifa->ifa_label))
26545                                         break;
26546 +                       }
26547                 }
26548         }
26549  
26550 @@ -826,6 +834,8 @@ static int inet_gifconf(struct net_devic
26551                 goto out;
26552  
26553         for (; ifa; ifa = ifa->ifa_next) {
26554 +               if (!nx_v4_ifa_visible(current->nx_info, ifa))
26555 +                       continue;
26556                 if (!buf) {
26557                         done += sizeof(ifr);
26558                         continue;
26559 @@ -1156,6 +1166,7 @@ static int inet_dump_ifaddr(struct sk_bu
26560         struct net_device *dev;
26561         struct in_device *in_dev;
26562         struct in_ifaddr *ifa;
26563 +       struct sock *sk = skb->sk;
26564         int s_ip_idx, s_idx = cb->args[0];
26565  
26566         s_ip_idx = ip_idx = cb->args[1];
26567 @@ -1170,6 +1181,8 @@ static int inet_dump_ifaddr(struct sk_bu
26568  
26569                 for (ifa = in_dev->ifa_list, ip_idx = 0; ifa;
26570                      ifa = ifa->ifa_next, ip_idx++) {
26571 +                       if (sk && !nx_v4_ifa_visible(sk->sk_nx_info, ifa))
26572 +                               continue;
26573                         if (ip_idx < s_ip_idx)
26574                                 continue;
26575                         if (inet_fill_ifaddr(skb, ifa, NETLINK_CB(cb->skb).pid,
26576 diff -NurpP --minimal linux-2.6.29.1/net/ipv4/fib_hash.c linux-2.6.29.1-vs2.3.0.36.9-pre5/net/ipv4/fib_hash.c
26577 --- linux-2.6.29.1/net/ipv4/fib_hash.c  2009-03-24 14:22:46.000000000 +0100
26578 +++ linux-2.6.29.1-vs2.3.0.36.9-pre5/net/ipv4/fib_hash.c        2009-03-24 14:48:37.000000000 +0100
26579 @@ -1022,7 +1022,7 @@ static int fib_seq_show(struct seq_file 
26580         prefix  = f->fn_key;
26581         mask    = FZ_MASK(iter->zone);
26582         flags   = fib_flag_trans(fa->fa_type, mask, fi);
26583 -       if (fi)
26584 +       if (fi && nx_dev_visible(current->nx_info, fi->fib_dev))
26585                 seq_printf(seq,
26586                          "%s\t%08X\t%08X\t%04X\t%d\t%u\t%d\t%08X\t%d\t%u\t%u%n",
26587                          fi->fib_dev ? fi->fib_dev->name : "*", prefix,
26588 diff -NurpP --minimal linux-2.6.29.1/net/ipv4/inet_connection_sock.c linux-2.6.29.1-vs2.3.0.36.9-pre5/net/ipv4/inet_connection_sock.c
26589 --- linux-2.6.29.1/net/ipv4/inet_connection_sock.c      2009-03-24 14:22:46.000000000 +0100
26590 +++ linux-2.6.29.1-vs2.3.0.36.9-pre5/net/ipv4/inet_connection_sock.c    2009-03-24 14:48:37.000000000 +0100
26591 @@ -49,10 +49,40 @@ void inet_get_local_port_range(int *low,
26592  }
26593  EXPORT_SYMBOL(inet_get_local_port_range);
26594  
26595 +int ipv4_rcv_saddr_equal(const struct sock *sk1, const struct sock *sk2)
26596 +{
26597 +       __be32  sk1_rcv_saddr = inet_rcv_saddr(sk1),
26598 +               sk2_rcv_saddr = inet_rcv_saddr(sk2);
26599 +
26600 +       if (inet_v6_ipv6only(sk2))
26601 +               return 0;
26602 +
26603 +       if (sk1_rcv_saddr &&
26604 +           sk2_rcv_saddr &&
26605 +           sk1_rcv_saddr == sk2_rcv_saddr)
26606 +               return 1;
26607 +
26608 +       if (sk1_rcv_saddr &&
26609 +           !sk2_rcv_saddr &&
26610 +           v4_addr_in_nx_info(sk2->sk_nx_info, sk1_rcv_saddr, NXA_MASK_BIND))
26611 +               return 1;
26612 +
26613 +       if (sk2_rcv_saddr &&
26614 +           !sk1_rcv_saddr &&
26615 +           v4_addr_in_nx_info(sk1->sk_nx_info, sk2_rcv_saddr, NXA_MASK_BIND))
26616 +               return 1;
26617 +
26618 +       if (!sk1_rcv_saddr &&
26619 +           !sk2_rcv_saddr &&
26620 +           nx_v4_addr_conflict(sk1->sk_nx_info, sk2->sk_nx_info))
26621 +               return 1;
26622 +
26623 +       return 0;
26624 +}
26625 +
26626  int inet_csk_bind_conflict(const struct sock *sk,
26627                            const struct inet_bind_bucket *tb)
26628  {
26629 -       const __be32 sk_rcv_saddr = inet_rcv_saddr(sk);
26630         struct sock *sk2;
26631         struct hlist_node *node;
26632         int reuse = sk->sk_reuse;
26633 @@ -72,9 +102,7 @@ int inet_csk_bind_conflict(const struct 
26634                      sk->sk_bound_dev_if == sk2->sk_bound_dev_if)) {
26635                         if (!reuse || !sk2->sk_reuse ||
26636                             sk2->sk_state == TCP_LISTEN) {
26637 -                               const __be32 sk2_rcv_saddr = inet_rcv_saddr(sk2);
26638 -                               if (!sk2_rcv_saddr || !sk_rcv_saddr ||
26639 -                                   sk2_rcv_saddr == sk_rcv_saddr)
26640 +                               if (ipv4_rcv_saddr_equal(sk, sk2))
26641                                         break;
26642                         }
26643                 }
26644 diff -NurpP --minimal linux-2.6.29.1/net/ipv4/inet_diag.c linux-2.6.29.1-vs2.3.0.36.9-pre5/net/ipv4/inet_diag.c
26645 --- linux-2.6.29.1/net/ipv4/inet_diag.c 2009-03-24 14:22:46.000000000 +0100
26646 +++ linux-2.6.29.1-vs2.3.0.36.9-pre5/net/ipv4/inet_diag.c       2009-03-24 14:48:37.000000000 +0100
26647 @@ -32,6 +32,8 @@
26648  #include <linux/stddef.h>
26649  
26650  #include <linux/inet_diag.h>
26651 +#include <linux/vs_network.h>
26652 +#include <linux/vs_inet.h>
26653  
26654  static const struct inet_diag_handler **inet_diag_table;
26655  
26656 @@ -118,8 +120,8 @@ static int inet_csk_diag_fill(struct soc
26657  
26658         r->id.idiag_sport = inet->sport;
26659         r->id.idiag_dport = inet->dport;
26660 -       r->id.idiag_src[0] = inet->rcv_saddr;
26661 -       r->id.idiag_dst[0] = inet->daddr;
26662 +       r->id.idiag_src[0] = nx_map_sock_lback(sk->sk_nx_info, inet->rcv_saddr);
26663 +       r->id.idiag_dst[0] = nx_map_sock_lback(sk->sk_nx_info, inet->daddr);
26664  
26665  #if defined(CONFIG_IPV6) || defined (CONFIG_IPV6_MODULE)
26666         if (r->idiag_family == AF_INET6) {
26667 @@ -206,8 +208,8 @@ static int inet_twsk_diag_fill(struct in
26668         r->id.idiag_cookie[1] = (u32)(((unsigned long)tw >> 31) >> 1);
26669         r->id.idiag_sport     = tw->tw_sport;
26670         r->id.idiag_dport     = tw->tw_dport;
26671 -       r->id.idiag_src[0]    = tw->tw_rcv_saddr;
26672 -       r->id.idiag_dst[0]    = tw->tw_daddr;
26673 +       r->id.idiag_src[0]    = nx_map_sock_lback(tw->tw_nx_info, tw->tw_rcv_saddr);
26674 +       r->id.idiag_dst[0]    = nx_map_sock_lback(tw->tw_nx_info, tw->tw_daddr);
26675         r->idiag_state        = tw->tw_substate;
26676         r->idiag_timer        = 3;
26677         r->idiag_expires      = DIV_ROUND_UP(tmo * 1000, HZ);
26678 @@ -264,6 +266,7 @@ static int inet_diag_get_exact(struct sk
26679         err = -EINVAL;
26680  
26681         if (req->idiag_family == AF_INET) {
26682 +               /* TODO: lback */
26683                 sk = inet_lookup(&init_net, hashinfo, req->id.idiag_dst[0],
26684                                  req->id.idiag_dport, req->id.idiag_src[0],
26685                                  req->id.idiag_sport, req->id.idiag_if);
26686 @@ -506,6 +509,7 @@ static int inet_csk_diag_dump(struct soc
26687                 } else
26688  #endif
26689                 {
26690 +                       /* TODO: lback */
26691                         entry.saddr = &inet->rcv_saddr;
26692                         entry.daddr = &inet->daddr;
26693                 }
26694 @@ -542,6 +546,7 @@ static int inet_twsk_diag_dump(struct in
26695                 } else
26696  #endif
26697                 {
26698 +                       /* TODO: lback */
26699                         entry.saddr = &tw->tw_rcv_saddr;
26700                         entry.daddr = &tw->tw_daddr;
26701                 }
26702 @@ -588,8 +593,8 @@ static int inet_diag_fill_req(struct sk_
26703  
26704         r->id.idiag_sport = inet->sport;
26705         r->id.idiag_dport = ireq->rmt_port;
26706 -       r->id.idiag_src[0] = ireq->loc_addr;
26707 -       r->id.idiag_dst[0] = ireq->rmt_addr;
26708 +       r->id.idiag_src[0] = nx_map_sock_lback(sk->sk_nx_info, ireq->loc_addr);
26709 +       r->id.idiag_dst[0] = nx_map_sock_lback(sk->sk_nx_info, ireq->rmt_addr);
26710         r->idiag_expires = jiffies_to_msecs(tmo);
26711         r->idiag_rqueue = 0;
26712         r->idiag_wqueue = 0;
26713 @@ -659,6 +664,7 @@ static int inet_diag_dump_reqs(struct sk
26714                                 continue;
26715  
26716                         if (bc) {
26717 +                               /* TODO: lback */
26718                                 entry.saddr =
26719  #if defined(CONFIG_IPV6) || defined (CONFIG_IPV6_MODULE)
26720                                         (entry.family == AF_INET6) ?
26721 @@ -729,6 +735,8 @@ static int inet_diag_dump(struct sk_buff
26722                         sk_nulls_for_each(sk, node, &ilb->head) {
26723                                 struct inet_sock *inet = inet_sk(sk);
26724  
26725 +                               if (!nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
26726 +                                       continue;
26727                                 if (num < s_num) {
26728                                         num++;
26729                                         continue;
26730 @@ -795,6 +803,8 @@ skip_listen_ht:
26731                 sk_nulls_for_each(sk, node, &head->chain) {
26732                         struct inet_sock *inet = inet_sk(sk);
26733  
26734 +                       if (!nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
26735 +                               continue;
26736                         if (num < s_num)
26737                                 goto next_normal;
26738                         if (!(r->idiag_states & (1 << sk->sk_state)))
26739 @@ -819,6 +829,8 @@ next_normal:
26740                         inet_twsk_for_each(tw, node,
26741                                     &head->twchain) {
26742  
26743 +                               if (!nx_check(tw->tw_nid, VS_WATCH_P | VS_IDENT))
26744 +                                       continue;
26745                                 if (num < s_num)
26746                                         goto next_dying;
26747                                 if (r->id.idiag_sport != tw->tw_sport &&
26748 diff -NurpP --minimal linux-2.6.29.1/net/ipv4/inet_hashtables.c linux-2.6.29.1-vs2.3.0.36.9-pre5/net/ipv4/inet_hashtables.c
26749 --- linux-2.6.29.1/net/ipv4/inet_hashtables.c   2009-03-24 14:22:46.000000000 +0100
26750 +++ linux-2.6.29.1-vs2.3.0.36.9-pre5/net/ipv4/inet_hashtables.c 2009-03-24 19:35:10.000000000 +0100
26751 @@ -21,6 +21,7 @@
26752  
26753  #include <net/inet_connection_sock.h>
26754  #include <net/inet_hashtables.h>
26755 +#include <net/route.h>
26756  #include <net/ip.h>
26757  
26758  /*
26759 @@ -142,7 +143,6 @@ static inline int compute_score(struct s
26760   * wildcarded during the search since they can never be otherwise.
26761   */
26762  
26763 -
26764  struct sock *__inet_lookup_listener(struct net *net,
26765                                     struct inet_hashinfo *hashinfo,
26766                                     const __be32 daddr, const unsigned short hnum,
26767 @@ -165,6 +165,7 @@ begin:
26768                         hiscore = score;
26769                 }
26770         }
26771 +
26772         /*
26773          * if the nulls value we got at the end of this lookup is
26774          * not the expected one, we must restart lookup.
26775 diff -NurpP --minimal linux-2.6.29.1/net/ipv4/netfilter/nf_nat_helper.c linux-2.6.29.1-vs2.3.0.36.9-pre5/net/ipv4/netfilter/nf_nat_helper.c
26776 --- linux-2.6.29.1/net/ipv4/netfilter/nf_nat_helper.c   2008-12-25 00:26:37.000000000 +0100
26777 +++ linux-2.6.29.1-vs2.3.0.36.9-pre5/net/ipv4/netfilter/nf_nat_helper.c 2009-02-22 22:54:26.000000000 +0100
26778 @@ -19,6 +19,7 @@
26779  #include <net/route.h>
26780  
26781  #include <linux/netfilter_ipv4.h>
26782 +#include <net/route.h>
26783  #include <net/netfilter/nf_conntrack.h>
26784  #include <net/netfilter/nf_conntrack_helper.h>
26785  #include <net/netfilter/nf_conntrack_ecache.h>
26786 diff -NurpP --minimal linux-2.6.29.1/net/ipv4/netfilter.c linux-2.6.29.1-vs2.3.0.36.9-pre5/net/ipv4/netfilter.c
26787 --- linux-2.6.29.1/net/ipv4/netfilter.c 2009-03-24 14:22:46.000000000 +0100
26788 +++ linux-2.6.29.1-vs2.3.0.36.9-pre5/net/ipv4/netfilter.c       2009-03-24 14:48:37.000000000 +0100
26789 @@ -4,7 +4,7 @@
26790  #include <linux/netfilter_ipv4.h>
26791  #include <linux/ip.h>
26792  #include <linux/skbuff.h>
26793 -#include <net/route.h>
26794 +// #include <net/route.h>
26795  #include <net/xfrm.h>
26796  #include <net/ip.h>
26797  #include <net/netfilter/nf_queue.h>
26798 diff -NurpP --minimal linux-2.6.29.1/net/ipv4/raw.c linux-2.6.29.1-vs2.3.0.36.9-pre5/net/ipv4/raw.c
26799 --- linux-2.6.29.1/net/ipv4/raw.c       2009-03-24 14:22:46.000000000 +0100
26800 +++ linux-2.6.29.1-vs2.3.0.36.9-pre5/net/ipv4/raw.c     2009-03-24 14:48:37.000000000 +0100
26801 @@ -117,7 +117,7 @@ static struct sock *__raw_v4_lookup(stru
26802  
26803                 if (net_eq(sock_net(sk), net) && inet->num == num       &&
26804                     !(inet->daddr && inet->daddr != raddr)              &&
26805 -                   !(inet->rcv_saddr && inet->rcv_saddr != laddr)      &&
26806 +                   v4_sock_addr_match(sk->sk_nx_info, inet, laddr)     &&
26807                     !(sk->sk_bound_dev_if && sk->sk_bound_dev_if != dif))
26808                         goto found; /* gotcha */
26809         }
26810 @@ -372,6 +372,12 @@ static int raw_send_hdrinc(struct sock *
26811                 icmp_out_count(net, ((struct icmphdr *)
26812                         skb_transport_header(skb))->type);
26813  
26814 +       err = -EPERM;
26815 +       if (!nx_check(0, VS_ADMIN) && !capable(CAP_NET_RAW) &&
26816 +               sk->sk_nx_info &&
26817 +               !v4_addr_in_nx_info(sk->sk_nx_info, iph->saddr, NXA_MASK_BIND))
26818 +               goto error_free;
26819 +
26820         err = NF_HOOK(PF_INET, NF_INET_LOCAL_OUT, skb, NULL, rt->u.dst.dev,
26821                       dst_output);
26822         if (err > 0)
26823 @@ -383,6 +389,7 @@ out:
26824  
26825  error_fault:
26826         err = -EFAULT;
26827 +error_free:
26828         kfree_skb(skb);
26829  error:
26830         IP_INC_STATS(net, IPSTATS_MIB_OUTDISCARDS);
26831 @@ -550,6 +557,13 @@ static int raw_sendmsg(struct kiocb *ioc
26832                 }
26833  
26834                 security_sk_classify_flow(sk, &fl);
26835 +               if (sk->sk_nx_info) {
26836 +                       err = ip_v4_find_src(sock_net(sk),
26837 +                               sk->sk_nx_info, &rt, &fl);
26838 +
26839 +                       if (err)
26840 +                               goto done;
26841 +               }
26842                 err = ip_route_output_flow(sock_net(sk), &rt, &fl, sk, 1);
26843         }
26844         if (err)
26845 @@ -619,17 +633,19 @@ static int raw_bind(struct sock *sk, str
26846  {
26847         struct inet_sock *inet = inet_sk(sk);
26848         struct sockaddr_in *addr = (struct sockaddr_in *) uaddr;
26849 +       struct nx_v4_sock_addr nsa = { 0 };
26850         int ret = -EINVAL;
26851         int chk_addr_ret;
26852  
26853         if (sk->sk_state != TCP_CLOSE || addr_len < sizeof(struct sockaddr_in))
26854                 goto out;
26855 -       chk_addr_ret = inet_addr_type(sock_net(sk), addr->sin_addr.s_addr);
26856 +       v4_map_sock_addr(inet, addr, &nsa);
26857 +       chk_addr_ret = inet_addr_type(sock_net(sk), nsa.saddr);
26858         ret = -EADDRNOTAVAIL;
26859 -       if (addr->sin_addr.s_addr && chk_addr_ret != RTN_LOCAL &&
26860 +       if (nsa.saddr && chk_addr_ret != RTN_LOCAL &&
26861             chk_addr_ret != RTN_MULTICAST && chk_addr_ret != RTN_BROADCAST)
26862                 goto out;
26863 -       inet->rcv_saddr = inet->saddr = addr->sin_addr.s_addr;
26864 +       v4_set_sock_addr(inet, &nsa);
26865         if (chk_addr_ret == RTN_MULTICAST || chk_addr_ret == RTN_BROADCAST)
26866                 inet->saddr = 0;  /* Use device */
26867         sk_dst_reset(sk);
26868 @@ -681,7 +697,8 @@ static int raw_recvmsg(struct kiocb *ioc
26869         /* Copy the address. */
26870         if (sin) {
26871                 sin->sin_family = AF_INET;
26872 -               sin->sin_addr.s_addr = ip_hdr(skb)->saddr;
26873 +               sin->sin_addr.s_addr =
26874 +                       nx_map_sock_lback(sk->sk_nx_info, ip_hdr(skb)->saddr);
26875                 sin->sin_port = 0;
26876                 memset(&sin->sin_zero, 0, sizeof(sin->sin_zero));
26877         }
26878 @@ -858,7 +875,8 @@ static struct sock *raw_get_first(struct
26879                 struct hlist_node *node;
26880  
26881                 sk_for_each(sk, node, &state->h->ht[state->bucket])
26882 -                       if (sock_net(sk) == seq_file_net(seq))
26883 +                       if ((sock_net(sk) == seq_file_net(seq)) &&
26884 +                               nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
26885                                 goto found;
26886         }
26887         sk = NULL;
26888 @@ -874,7 +892,8 @@ static struct sock *raw_get_next(struct 
26889                 sk = sk_next(sk);
26890  try_again:
26891                 ;
26892 -       } while (sk && sock_net(sk) != seq_file_net(seq));
26893 +       } while (sk && ((sock_net(sk) != seq_file_net(seq)) ||
26894 +               !nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT)));
26895  
26896         if (!sk && ++state->bucket < RAW_HTABLE_SIZE) {
26897                 sk = sk_head(&state->h->ht[state->bucket]);
26898 @@ -933,7 +952,10 @@ static void raw_sock_seq_show(struct seq
26899  
26900         seq_printf(seq, "%4d: %08X:%04X %08X:%04X"
26901                 " %02X %08X:%08X %02X:%08lX %08X %5d %8d %lu %d %p %d\n",
26902 -               i, src, srcp, dest, destp, sp->sk_state,
26903 +               i,
26904 +               nx_map_sock_lback(current_nx_info(), src), srcp,
26905 +               nx_map_sock_lback(current_nx_info(), dest), destp,
26906 +               sp->sk_state,
26907                 atomic_read(&sp->sk_wmem_alloc),
26908                 atomic_read(&sp->sk_rmem_alloc),
26909                 0, 0L, 0, sock_i_uid(sp), 0, sock_i_ino(sp),
26910 diff -NurpP --minimal linux-2.6.29.1/net/ipv4/tcp.c linux-2.6.29.1-vs2.3.0.36.9-pre5/net/ipv4/tcp.c
26911 --- linux-2.6.29.1/net/ipv4/tcp.c       2009-03-24 14:22:46.000000000 +0100
26912 +++ linux-2.6.29.1-vs2.3.0.36.9-pre5/net/ipv4/tcp.c     2009-03-24 14:48:37.000000000 +0100
26913 @@ -264,6 +264,7 @@
26914  #include <linux/cache.h>
26915  #include <linux/err.h>
26916  #include <linux/crypto.h>
26917 +#include <linux/in.h>
26918  
26919  #include <net/icmp.h>
26920  #include <net/tcp.h>
26921 diff -NurpP --minimal linux-2.6.29.1/net/ipv4/tcp_ipv4.c linux-2.6.29.1-vs2.3.0.36.9-pre5/net/ipv4/tcp_ipv4.c
26922 --- linux-2.6.29.1/net/ipv4/tcp_ipv4.c  2009-03-24 14:22:46.000000000 +0100
26923 +++ linux-2.6.29.1-vs2.3.0.36.9-pre5/net/ipv4/tcp_ipv4.c        2009-03-24 19:51:34.000000000 +0100
26924 @@ -1894,6 +1894,12 @@ static void *listening_get_next(struct s
26925                 req = req->dl_next;
26926                 while (1) {
26927                         while (req) {
26928 +                               vxdprintk(VXD_CBIT(net, 6),
26929 +                                       "sk,req: %p [#%d] (from %d)", req->sk,
26930 +                                       (req->sk)?req->sk->sk_nid:0, nx_current_nid());
26931 +                               if (req->sk &&
26932 +                                       !nx_check(req->sk->sk_nid, VS_WATCH_P | VS_IDENT))
26933 +                                       continue;
26934                                 if (req->rsk_ops->family == st->family) {
26935                                         cur = req;
26936                                         goto out;
26937 @@ -1918,6 +1924,10 @@ get_req:
26938         }
26939  get_sk:
26940         sk_nulls_for_each_from(sk, node) {
26941 +               vxdprintk(VXD_CBIT(net, 6), "sk: %p [#%d] (from %d)",
26942 +                       sk, sk->sk_nid, nx_current_nid());
26943 +               if (!nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
26944 +                       continue;
26945                 if (sk->sk_family == st->family && net_eq(sock_net(sk), net)) {
26946                         cur = sk;
26947                         goto out;
26948 @@ -1981,6 +1991,11 @@ static void *established_get_first(struc
26949  
26950                 spin_lock_bh(lock);
26951                 sk_nulls_for_each(sk, node, &tcp_hashinfo.ehash[st->bucket].chain) {
26952 +                       vxdprintk(VXD_CBIT(net, 6),
26953 +                               "sk,egf: %p [#%d] (from %d)",
26954 +                               sk, sk->sk_nid, nx_current_nid());
26955 +                       if (!nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
26956 +                               continue;
26957                         if (sk->sk_family != st->family ||
26958                             !net_eq(sock_net(sk), net)) {
26959                                 continue;
26960 @@ -1991,6 +2006,11 @@ static void *established_get_first(struc
26961                 st->state = TCP_SEQ_STATE_TIME_WAIT;
26962                 inet_twsk_for_each(tw, node,
26963                                    &tcp_hashinfo.ehash[st->bucket].twchain) {
26964 +                       vxdprintk(VXD_CBIT(net, 6),
26965 +                               "tw: %p [#%d] (from %d)",
26966 +                               tw, tw->tw_nid, nx_current_nid());
26967 +                       if (!nx_check(tw->tw_nid, VS_WATCH_P | VS_IDENT))
26968 +                               continue;
26969                         if (tw->tw_family != st->family ||
26970                             !net_eq(twsk_net(tw), net)) {
26971                                 continue;
26972 @@ -2019,7 +2039,9 @@ static void *established_get_next(struct
26973                 tw = cur;
26974                 tw = tw_next(tw);
26975  get_tw:
26976 -               while (tw && (tw->tw_family != st->family || !net_eq(twsk_net(tw), net))) {
26977 +               while (tw && (tw->tw_family != st->family ||
26978 +                       !net_eq(twsk_net(tw), net) ||
26979 +                       !nx_check(tw->tw_nid, VS_WATCH_P | VS_IDENT))) {
26980                         tw = tw_next(tw);
26981                 }
26982                 if (tw) {
26983 @@ -2042,6 +2064,11 @@ get_tw:
26984                 sk = sk_nulls_next(sk);
26985  
26986         sk_nulls_for_each_from(sk, node) {
26987 +               vxdprintk(VXD_CBIT(net, 6),
26988 +                       "sk,egn: %p [#%d] (from %d)",
26989 +                       sk, sk->sk_nid, nx_current_nid());
26990 +               if (!nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
26991 +                       continue;
26992                 if (sk->sk_family == st->family && net_eq(sock_net(sk), net))
26993                         goto found;
26994         }
26995 @@ -2193,9 +2220,9 @@ static void get_openreq4(struct sock *sk
26996         seq_printf(f, "%4d: %08X:%04X %08X:%04X"
26997                 " %02X %08X:%08X %02X:%08lX %08X %5d %8d %u %d %p%n",
26998                 i,
26999 -               ireq->loc_addr,
27000 +               nx_map_sock_lback(current_nx_info(), ireq->loc_addr),
27001                 ntohs(inet_sk(sk)->sport),
27002 -               ireq->rmt_addr,
27003 +               nx_map_sock_lback(current_nx_info(), ireq->rmt_addr),
27004                 ntohs(ireq->rmt_port),
27005                 TCP_SYN_RECV,
27006                 0, 0, /* could print option size, but that is af dependent. */
27007 @@ -2238,7 +2265,10 @@ static void get_tcp4_sock(struct sock *s
27008  
27009         seq_printf(f, "%4d: %08X:%04X %08X:%04X %02X %08X:%08X %02X:%08lX "
27010                         "%08X %5d %8d %lu %d %p %lu %lu %u %u %d%n",
27011 -               i, src, srcp, dest, destp, sk->sk_state,
27012 +               i,
27013 +               nx_map_sock_lback(current_nx_info(), src), srcp,
27014 +               nx_map_sock_lback(current_nx_info(), dest), destp,
27015 +               sk->sk_state,
27016                 tp->write_seq - tp->snd_una,
27017                 sk->sk_state == TCP_LISTEN ? sk->sk_ack_backlog :
27018                                              (tp->rcv_nxt - tp->copied_seq),
27019 @@ -2274,7 +2304,10 @@ static void get_timewait4_sock(struct in
27020  
27021         seq_printf(f, "%4d: %08X:%04X %08X:%04X"
27022                 " %02X %08X:%08X %02X:%08lX %08X %5d %8d %d %d %p%n",
27023 -               i, src, srcp, dest, destp, tw->tw_substate, 0, 0,
27024 +               i,
27025 +               nx_map_sock_lback(current_nx_info(), src), srcp,
27026 +               nx_map_sock_lback(current_nx_info(), dest), destp,
27027 +               tw->tw_substate, 0, 0,
27028                 3, jiffies_to_clock_t(ttd), 0, 0, 0, 0,
27029                 atomic_read(&tw->tw_refcnt), tw, len);
27030  }
27031 diff -NurpP --minimal linux-2.6.29.1/net/ipv4/tcp_minisocks.c linux-2.6.29.1-vs2.3.0.36.9-pre5/net/ipv4/tcp_minisocks.c
27032 --- linux-2.6.29.1/net/ipv4/tcp_minisocks.c     2009-03-24 14:22:46.000000000 +0100
27033 +++ linux-2.6.29.1-vs2.3.0.36.9-pre5/net/ipv4/tcp_minisocks.c   2009-03-24 14:48:37.000000000 +0100
27034 @@ -26,6 +26,10 @@
27035  #include <net/inet_common.h>
27036  #include <net/xfrm.h>
27037  
27038 +#include <linux/vs_limit.h>
27039 +#include <linux/vs_socket.h>
27040 +#include <linux/vs_context.h>
27041 +
27042  #ifdef CONFIG_SYSCTL
27043  #define SYNC_INIT 0 /* let the user enable it */
27044  #else
27045 @@ -293,6 +297,11 @@ void tcp_time_wait(struct sock *sk, int 
27046                 tcptw->tw_ts_recent     = tp->rx_opt.ts_recent;
27047                 tcptw->tw_ts_recent_stamp = tp->rx_opt.ts_recent_stamp;
27048  
27049 +               tw->tw_xid              = sk->sk_xid;
27050 +               tw->tw_vx_info          = NULL;
27051 +               tw->tw_nid              = sk->sk_nid;
27052 +               tw->tw_nx_info          = NULL;
27053 +
27054  #if defined(CONFIG_IPV6) || defined(CONFIG_IPV6_MODULE)
27055                 if (tw->tw_family == PF_INET6) {
27056                         struct ipv6_pinfo *np = inet6_sk(sk);
27057 diff -NurpP --minimal linux-2.6.29.1/net/ipv4/udp.c linux-2.6.29.1-vs2.3.0.36.9-pre5/net/ipv4/udp.c
27058 --- linux-2.6.29.1/net/ipv4/udp.c       2009-04-15 22:53:12.000000000 +0200
27059 +++ linux-2.6.29.1-vs2.3.0.36.9-pre5/net/ipv4/udp.c     2009-04-15 22:58:30.000000000 +0200
27060 @@ -222,14 +222,7 @@ fail:
27061         return error;
27062  }
27063  
27064 -static int ipv4_rcv_saddr_equal(const struct sock *sk1, const struct sock *sk2)
27065 -{
27066 -       struct inet_sock *inet1 = inet_sk(sk1), *inet2 = inet_sk(sk2);
27067 -
27068 -       return  ( !ipv6_only_sock(sk2)  &&
27069 -                 (!inet1->rcv_saddr || !inet2->rcv_saddr ||
27070 -                  inet1->rcv_saddr == inet2->rcv_saddr      ));
27071 -}
27072 +extern int ipv4_rcv_saddr_equal(const struct sock *, const struct sock *);
27073  
27074  int udp_v4_get_port(struct sock *sk, unsigned short snum)
27075  {
27076 @@ -251,6 +244,11 @@ static inline int compute_score(struct s
27077                         if (inet->rcv_saddr != daddr)
27078                                 return -1;
27079                         score += 2;
27080 +               } else {
27081 +                       /* block non nx_info ips */
27082 +                       if (!v4_addr_in_nx_info(sk->sk_nx_info,
27083 +                               daddr, NXA_MASK_BIND))
27084 +                               return -1;
27085                 }
27086                 if (inet->daddr) {
27087                         if (inet->daddr != saddr)
27088 @@ -271,6 +269,7 @@ static inline int compute_score(struct s
27089         return score;
27090  }
27091  
27092 +
27093  /* UDP is nearly always wildcards out the wazoo, it makes no sense to try
27094   * harder than this. -DaveM
27095   */
27096 @@ -292,6 +291,11 @@ begin:
27097         sk_nulls_for_each_rcu(sk, node, &hslot->head) {
27098                 score = compute_score(sk, net, saddr, hnum, sport,
27099                                       daddr, dport, dif);
27100 +               /* FIXME: disabled?
27101 +               if (score == 9) {
27102 +                       result = sk;
27103 +                       break;
27104 +               } else */
27105                 if (score > badness) {
27106                         result = sk;
27107                         badness = score;
27108 @@ -305,6 +309,7 @@ begin:
27109         if (get_nulls_value(node) != hash)
27110                 goto begin;
27111  
27112 +
27113         if (result) {
27114                 if (unlikely(!atomic_inc_not_zero(&result->sk_refcnt)))
27115                         result = NULL;
27116 @@ -314,6 +319,7 @@ begin:
27117                         goto begin;
27118                 }
27119         }
27120 +
27121         rcu_read_unlock();
27122         return result;
27123  }
27124 @@ -356,7 +362,7 @@ static inline struct sock *udp_v4_mcast_
27125                     s->sk_hash != hnum                                  ||
27126                     (inet->daddr && inet->daddr != rmt_addr)            ||
27127                     (inet->dport != rmt_port && inet->dport)            ||
27128 -                   (inet->rcv_saddr && inet->rcv_saddr != loc_addr)    ||
27129 +                   !v4_sock_addr_match(sk->sk_nx_info, inet, loc_addr) ||
27130                     ipv6_only_sock(s)                                   ||
27131                     (s->sk_bound_dev_if && s->sk_bound_dev_if != dif))
27132                         continue;
27133 @@ -694,8 +700,13 @@ int udp_sendmsg(struct kiocb *iocb, stru
27134                                                { .sport = inet->sport,
27135                                                  .dport = dport } } };
27136                 struct net *net = sock_net(sk);
27137 +               struct nx_info *nxi = sk->sk_nx_info;
27138  
27139                 security_sk_classify_flow(sk, &fl);
27140 +               err = ip_v4_find_src(net, nxi, &rt, &fl);
27141 +               if (err)
27142 +                       goto out;
27143 +
27144                 err = ip_route_output_flow(net, &rt, &fl, sk, 1);
27145                 if (err) {
27146                         if (err == -ENETUNREACH)
27147 @@ -940,7 +951,8 @@ try_again:
27148         {
27149                 sin->sin_family = AF_INET;
27150                 sin->sin_port = udp_hdr(skb)->source;
27151 -               sin->sin_addr.s_addr = ip_hdr(skb)->saddr;
27152 +               sin->sin_addr.s_addr = nx_map_sock_lback(
27153 +                       skb->sk->sk_nx_info, ip_hdr(skb)->saddr);
27154                 memset(sin->sin_zero, 0, sizeof(sin->sin_zero));
27155         }
27156         if (inet->cmsg_flags)
27157 @@ -1594,6 +1606,8 @@ static struct sock *udp_get_first(struct
27158                 sk_nulls_for_each(sk, node, &hslot->head) {
27159                         if (!net_eq(sock_net(sk), net))
27160                                 continue;
27161 +                       if (!nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
27162 +                               continue;
27163                         if (sk->sk_family == state->family)
27164                                 goto found;
27165                 }
27166 @@ -1611,7 +1625,9 @@ static struct sock *udp_get_next(struct 
27167  
27168         do {
27169                 sk = sk_nulls_next(sk);
27170 -       } while (sk && (!net_eq(sock_net(sk), net) || sk->sk_family != state->family));
27171 +       } while (sk && (!net_eq(sock_net(sk), net) ||
27172 +               sk->sk_family != state->family ||
27173 +               !nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT)));
27174  
27175         if (!sk) {
27176                 if (state->bucket < UDP_HTABLE_SIZE)
27177 @@ -1716,7 +1732,10 @@ static void udp4_format_sock(struct sock
27178  
27179         seq_printf(f, "%4d: %08X:%04X %08X:%04X"
27180                 " %02X %08X:%08X %02X:%08lX %08X %5d %8d %lu %d %p %d%n",
27181 -               bucket, src, srcp, dest, destp, sp->sk_state,
27182 +               bucket,
27183 +               nx_map_sock_lback(current_nx_info(), src), srcp,
27184 +               nx_map_sock_lback(current_nx_info(), dest), destp,
27185 +               sp->sk_state,
27186                 atomic_read(&sp->sk_wmem_alloc),
27187                 atomic_read(&sp->sk_rmem_alloc),
27188                 0, 0L, 0, sock_i_uid(sp), 0, sock_i_ino(sp),
27189 diff -NurpP --minimal linux-2.6.29.1/net/ipv6/addrconf.c linux-2.6.29.1-vs2.3.0.36.9-pre5/net/ipv6/addrconf.c
27190 --- linux-2.6.29.1/net/ipv6/addrconf.c  2009-03-24 14:22:46.000000000 +0100
27191 +++ linux-2.6.29.1-vs2.3.0.36.9-pre5/net/ipv6/addrconf.c        2009-03-24 20:39:23.000000000 +0100
27192 @@ -85,6 +85,8 @@
27193  
27194  #include <linux/proc_fs.h>
27195  #include <linux/seq_file.h>
27196 +#include <linux/vs_network.h>
27197 +#include <linux/vs_inet6.h>
27198  
27199  /* Set to 3 to get tracing... */
27200  #define ACONF_DEBUG 2
27201 @@ -1111,7 +1113,7 @@ out:
27202  
27203  int ipv6_dev_get_saddr(struct net *net, struct net_device *dst_dev,
27204                        const struct in6_addr *daddr, unsigned int prefs,
27205 -                      struct in6_addr *saddr)
27206 +                      struct in6_addr *saddr, struct nx_info *nxi)
27207  {
27208         struct ipv6_saddr_score scores[2],
27209                                 *score = &scores[0], *hiscore = &scores[1];
27210 @@ -1184,6 +1186,8 @@ int ipv6_dev_get_saddr(struct net *net, 
27211                                                dev->name);
27212                                 continue;
27213                         }
27214 +                       if (!v6_addr_in_nx_info(nxi, &score->ifa->addr, -1))
27215 +                               continue;
27216  
27217                         score->rule = -1;
27218                         bitmap_zero(score->scorebits, IPV6_SADDR_RULE_MAX);
27219 @@ -1367,35 +1371,46 @@ struct inet6_ifaddr *ipv6_get_ifaddr(str
27220         return ifp;
27221  }
27222  
27223 +extern int ipv4_rcv_saddr_equal(const struct sock *sk1, const struct sock *sk2);
27224 +
27225  int ipv6_rcv_saddr_equal(const struct sock *sk, const struct sock *sk2)
27226  {
27227         const struct in6_addr *sk_rcv_saddr6 = &inet6_sk(sk)->rcv_saddr;
27228         const struct in6_addr *sk2_rcv_saddr6 = inet6_rcv_saddr(sk2);
27229 -       __be32 sk_rcv_saddr = inet_sk(sk)->rcv_saddr;
27230         __be32 sk2_rcv_saddr = inet_rcv_saddr(sk2);
27231         int sk_ipv6only = ipv6_only_sock(sk);
27232         int sk2_ipv6only = inet_v6_ipv6only(sk2);
27233         int addr_type = ipv6_addr_type(sk_rcv_saddr6);
27234         int addr_type2 = sk2_rcv_saddr6 ? ipv6_addr_type(sk2_rcv_saddr6) : IPV6_ADDR_MAPPED;
27235  
27236 -       if (!sk2_rcv_saddr && !sk_ipv6only)
27237 +       /* FIXME: needs handling for v4 ANY */
27238 +       if (!sk2_rcv_saddr && !sk_ipv6only && !sk2->sk_nx_info)
27239                 return 1;
27240  
27241         if (addr_type2 == IPV6_ADDR_ANY &&
27242 -           !(sk2_ipv6only && addr_type == IPV6_ADDR_MAPPED))
27243 +           !(sk2_ipv6only && addr_type == IPV6_ADDR_MAPPED) &&
27244 +           v6_addr_in_nx_info(sk2->sk_nx_info, sk_rcv_saddr6, -1))
27245                 return 1;
27246  
27247         if (addr_type == IPV6_ADDR_ANY &&
27248 -           !(sk_ipv6only && addr_type2 == IPV6_ADDR_MAPPED))
27249 +           !(sk_ipv6only && addr_type2 == IPV6_ADDR_MAPPED) &&
27250 +           (sk2_rcv_saddr6 && v6_addr_in_nx_info(sk->sk_nx_info, sk2_rcv_saddr6, -1)))
27251 +               return 1;
27252 +
27253 +       if (addr_type == IPV6_ADDR_ANY &&
27254 +           addr_type2 == IPV6_ADDR_ANY &&
27255 +           nx_v6_addr_conflict(sk->sk_nx_info, sk2->sk_nx_info))
27256                 return 1;
27257  
27258         if (sk2_rcv_saddr6 &&
27259 +           addr_type != IPV6_ADDR_ANY &&
27260 +           addr_type != IPV6_ADDR_ANY &&
27261             ipv6_addr_equal(sk_rcv_saddr6, sk2_rcv_saddr6))
27262                 return 1;
27263  
27264         if (addr_type == IPV6_ADDR_MAPPED &&
27265             !sk2_ipv6only &&
27266 -           (!sk2_rcv_saddr || !sk_rcv_saddr || sk_rcv_saddr == sk2_rcv_saddr))
27267 +           ipv4_rcv_saddr_equal(sk, sk2))
27268                 return 1;
27269  
27270         return 0;
27271 @@ -2993,7 +3008,10 @@ static void if6_seq_stop(struct seq_file
27272  static int if6_seq_show(struct seq_file *seq, void *v)
27273  {
27274         struct inet6_ifaddr *ifp = (struct inet6_ifaddr *)v;
27275 -       seq_printf(seq, "%pi6 %02x %02x %02x %02x %8s\n",
27276 +
27277 +       if (nx_check(0, VS_ADMIN|VS_WATCH) ||
27278 +           v6_addr_in_nx_info(current_nx_info(), &ifp->addr, -1))
27279 +               seq_printf(seq, "%pi6 %02x %02x %02x %02x %8s\n",
27280                    &ifp->addr,
27281                    ifp->idev->dev->ifindex,
27282                    ifp->prefix_len,
27283 @@ -3487,6 +3505,12 @@ static int inet6_dump_addr(struct sk_buf
27284         struct ifmcaddr6 *ifmca;
27285         struct ifacaddr6 *ifaca;
27286         struct net *net = sock_net(skb->sk);
27287 +       struct nx_info *nxi = skb->sk ? skb->sk->sk_nx_info : NULL;
27288 +
27289 +       /* disable ipv6 on non v6 guests */
27290 +       if (nxi && !nx_info_has_v6(nxi))
27291 +               return skb->len;
27292 +
27293  
27294         s_idx = cb->args[0];
27295         s_ip_idx = ip_idx = cb->args[1];
27296 @@ -3508,6 +3532,8 @@ static int inet6_dump_addr(struct sk_buf
27297                              ifa = ifa->if_next, ip_idx++) {
27298                                 if (ip_idx < s_ip_idx)
27299                                         continue;
27300 +                               if (!v6_addr_in_nx_info(nxi, &ifa->addr, -1))
27301 +                                       continue;
27302                                 err = inet6_fill_ifaddr(skb, ifa,
27303                                                         NETLINK_CB(cb->skb).pid,
27304                                                         cb->nlh->nlmsg_seq,
27305 @@ -3521,6 +3547,8 @@ static int inet6_dump_addr(struct sk_buf
27306                              ifmca = ifmca->next, ip_idx++) {
27307                                 if (ip_idx < s_ip_idx)
27308                                         continue;
27309 +                               if (!v6_addr_in_nx_info(nxi, &ifmca->mca_addr, -1))
27310 +                                       continue;
27311                                 err = inet6_fill_ifmcaddr(skb, ifmca,
27312                                                           NETLINK_CB(cb->skb).pid,
27313                                                           cb->nlh->nlmsg_seq,
27314 @@ -3534,6 +3562,8 @@ static int inet6_dump_addr(struct sk_buf
27315                              ifaca = ifaca->aca_next, ip_idx++) {
27316                                 if (ip_idx < s_ip_idx)
27317                                         continue;
27318 +                               if (!v6_addr_in_nx_info(nxi, &ifaca->aca_addr, -1))
27319 +                                       continue;
27320                                 err = inet6_fill_ifacaddr(skb, ifaca,
27321                                                           NETLINK_CB(cb->skb).pid,
27322                                                           cb->nlh->nlmsg_seq,
27323 @@ -3819,12 +3849,19 @@ static int inet6_dump_ifinfo(struct sk_b
27324         int s_idx = cb->args[0];
27325         struct net_device *dev;
27326         struct inet6_dev *idev;
27327 +       struct nx_info *nxi = skb->sk ? skb->sk->sk_nx_info : NULL;
27328 +
27329 +       /* FIXME: maybe disable ipv6 on non v6 guests?
27330 +       if (skb->sk && skb->sk->sk_vx_info)
27331 +               return skb->len; */
27332  
27333         read_lock(&dev_base_lock);
27334         idx = 0;
27335         for_each_netdev(net, dev) {
27336                 if (idx < s_idx)
27337                         goto cont;
27338 +               if (!v6_dev_in_nx_info(dev, nxi))
27339 +                       goto cont;
27340                 if ((idev = in6_dev_get(dev)) == NULL)
27341                         goto cont;
27342                 err = inet6_fill_ifinfo(skb, idev, NETLINK_CB(cb->skb).pid,
27343 diff -NurpP --minimal linux-2.6.29.1/net/ipv6/af_inet6.c linux-2.6.29.1-vs2.3.0.36.9-pre5/net/ipv6/af_inet6.c
27344 --- linux-2.6.29.1/net/ipv6/af_inet6.c  2009-03-24 14:22:46.000000000 +0100
27345 +++ linux-2.6.29.1-vs2.3.0.36.9-pre5/net/ipv6/af_inet6.c        2009-03-24 14:48:37.000000000 +0100
27346 @@ -41,6 +41,8 @@
27347  #include <linux/netdevice.h>
27348  #include <linux/icmpv6.h>
27349  #include <linux/netfilter_ipv6.h>
27350 +#include <linux/vs_inet.h>
27351 +#include <linux/vs_inet6.h>
27352  
27353  #include <net/ip.h>
27354  #include <net/ipv6.h>
27355 @@ -49,6 +51,7 @@
27356  #include <net/tcp.h>
27357  #include <net/ipip.h>
27358  #include <net/protocol.h>
27359 +#include <net/route.h>
27360  #include <net/inet_common.h>
27361  #include <net/route.h>
27362  #include <net/transp_v6.h>
27363 @@ -146,9 +149,12 @@ lookup_protocol:
27364         }
27365  
27366         err = -EPERM;
27367 +       if ((protocol == IPPROTO_ICMPV6) &&
27368 +               nx_capable(answer->capability, NXC_RAW_ICMP))
27369 +               goto override;
27370         if (answer->capability > 0 && !capable(answer->capability))
27371                 goto out_rcu_unlock;
27372 -
27373 +override:
27374         sock->ops = answer->ops;
27375         answer_prot = answer->prot;
27376         answer_no_check = answer->no_check;
27377 @@ -247,6 +253,7 @@ int inet6_bind(struct socket *sock, stru
27378         struct inet_sock *inet = inet_sk(sk);
27379         struct ipv6_pinfo *np = inet6_sk(sk);
27380         struct net *net = sock_net(sk);
27381 +       struct nx_v6_sock_addr nsa;
27382         __be32 v4addr = 0;
27383         unsigned short snum;
27384         int addr_type = 0;
27385 @@ -258,6 +265,11 @@ int inet6_bind(struct socket *sock, stru
27386  
27387         if (addr_len < SIN6_LEN_RFC2133)
27388                 return -EINVAL;
27389 +
27390 +       err = v6_map_sock_addr(inet, addr, &nsa);
27391 +       if (err)
27392 +               return err;
27393 +
27394         addr_type = ipv6_addr_type(&addr->sin6_addr);
27395         if ((addr_type & IPV6_ADDR_MULTICAST) && sock->type == SOCK_STREAM)
27396                 return -EINVAL;
27397 @@ -281,6 +293,10 @@ int inet6_bind(struct socket *sock, stru
27398                         err = -EADDRNOTAVAIL;
27399                         goto out;
27400                 }
27401 +               if (!v4_addr_in_nx_info(sk->sk_nx_info, v4addr, NXA_MASK_BIND)) {
27402 +                       err = -EADDRNOTAVAIL;
27403 +                       goto out;
27404 +               }
27405         } else {
27406                 if (addr_type != IPV6_ADDR_ANY) {
27407                         struct net_device *dev = NULL;
27408 @@ -306,6 +322,11 @@ int inet6_bind(struct socket *sock, stru
27409                                 }
27410                         }
27411  
27412 +                       if (!v6_addr_in_nx_info(sk->sk_nx_info, &addr->sin6_addr, -1)) {
27413 +                               err = -EADDRNOTAVAIL;
27414 +                               goto out;
27415 +                       }
27416 +
27417                         /* ipv4 addr of the socket is invalid.  Only the
27418                          * unspecified and mapped address have a v4 equivalent.
27419                          */
27420 @@ -324,6 +345,8 @@ int inet6_bind(struct socket *sock, stru
27421                 }
27422         }
27423  
27424 +       v6_set_sock_addr(inet, &nsa);
27425 +
27426         inet->rcv_saddr = v4addr;
27427         inet->saddr = v4addr;
27428  
27429 @@ -416,9 +439,11 @@ int inet6_getname(struct socket *sock, s
27430                         return -ENOTCONN;
27431                 sin->sin6_port = inet->dport;
27432                 ipv6_addr_copy(&sin->sin6_addr, &np->daddr);
27433 +               /* FIXME: remap lback? */
27434                 if (np->sndflow)
27435                         sin->sin6_flowinfo = np->flow_label;
27436         } else {
27437 +               /* FIXME: remap lback? */
27438                 if (ipv6_addr_any(&np->rcv_saddr))
27439                         ipv6_addr_copy(&sin->sin6_addr, &np->saddr);
27440                 else
27441 diff -NurpP --minimal linux-2.6.29.1/net/ipv6/fib6_rules.c linux-2.6.29.1-vs2.3.0.36.9-pre5/net/ipv6/fib6_rules.c
27442 --- linux-2.6.29.1/net/ipv6/fib6_rules.c        2008-12-25 00:26:37.000000000 +0100
27443 +++ linux-2.6.29.1-vs2.3.0.36.9-pre5/net/ipv6/fib6_rules.c      2009-02-22 22:54:26.000000000 +0100
27444 @@ -96,7 +96,7 @@ static int fib6_rule_action(struct fib_r
27445                         if (ipv6_dev_get_saddr(net,
27446                                                ip6_dst_idev(&rt->u.dst)->dev,
27447                                                &flp->fl6_dst, srcprefs,
27448 -                                              &saddr))
27449 +                                              &saddr, NULL))
27450                                 goto again;
27451                         if (!ipv6_prefix_equal(&saddr, &r->src.addr,
27452                                                r->src.plen))
27453 diff -NurpP --minimal linux-2.6.29.1/net/ipv6/inet6_hashtables.c linux-2.6.29.1-vs2.3.0.36.9-pre5/net/ipv6/inet6_hashtables.c
27454 --- linux-2.6.29.1/net/ipv6/inet6_hashtables.c  2009-03-24 14:22:46.000000000 +0100
27455 +++ linux-2.6.29.1-vs2.3.0.36.9-pre5/net/ipv6/inet6_hashtables.c        2009-03-24 20:50:24.000000000 +0100
27456 @@ -16,6 +16,7 @@
27457  
27458  #include <linux/module.h>
27459  #include <linux/random.h>
27460 +#include <linux/vs_inet6.h>
27461  
27462  #include <net/inet_connection_sock.h>
27463  #include <net/inet_hashtables.h>
27464 @@ -76,7 +77,6 @@ struct sock *__inet6_lookup_established(
27465         unsigned int slot = hash & (hashinfo->ehash_size - 1);
27466         struct inet_ehash_bucket *head = &hashinfo->ehash[slot];
27467  
27468 -
27469         rcu_read_lock();
27470  begin:
27471         sk_nulls_for_each_rcu(sk, node, &head->chain) {
27472 @@ -88,7 +88,7 @@ begin:
27473                                 sock_put(sk);
27474                                 goto begin;
27475                         }
27476 -               goto out;
27477 +                       goto out;
27478                 }
27479         }
27480         if (get_nulls_value(node) != slot)
27481 @@ -134,6 +134,9 @@ static int inline compute_score(struct s
27482                         if (!ipv6_addr_equal(&np->rcv_saddr, daddr))
27483                                 return -1;
27484                         score++;
27485 +               } else {
27486 +                       if (!v6_addr_in_nx_info(sk->sk_nx_info, daddr, -1))
27487 +                               return -1;
27488                 }
27489                 if (sk->sk_bound_dev_if) {
27490                         if (sk->sk_bound_dev_if != dif)
27491 diff -NurpP --minimal linux-2.6.29.1/net/ipv6/ip6_output.c linux-2.6.29.1-vs2.3.0.36.9-pre5/net/ipv6/ip6_output.c
27492 --- linux-2.6.29.1/net/ipv6/ip6_output.c        2009-03-24 14:22:47.000000000 +0100
27493 +++ linux-2.6.29.1-vs2.3.0.36.9-pre5/net/ipv6/ip6_output.c      2009-03-24 14:48:37.000000000 +0100
27494 @@ -951,7 +951,7 @@ static int ip6_dst_lookup_tail(struct so
27495                 err = ipv6_dev_get_saddr(net, ip6_dst_idev(*dst)->dev,
27496                                          &fl->fl6_dst,
27497                                          sk ? inet6_sk(sk)->srcprefs : 0,
27498 -                                        &fl->fl6_src);
27499 +                                        &fl->fl6_src, sk->sk_nx_info);
27500                 if (err)
27501                         goto out_err_release;
27502         }
27503 diff -NurpP --minimal linux-2.6.29.1/net/ipv6/Kconfig linux-2.6.29.1-vs2.3.0.36.9-pre5/net/ipv6/Kconfig
27504 --- linux-2.6.29.1/net/ipv6/Kconfig     2008-12-25 00:26:37.000000000 +0100
27505 +++ linux-2.6.29.1-vs2.3.0.36.9-pre5/net/ipv6/Kconfig   2009-02-22 22:54:26.000000000 +0100
27506 @@ -4,8 +4,8 @@
27507  
27508  #   IPv6 as module will cause a CRASH if you try to unload it
27509  menuconfig IPV6
27510 -       tristate "The IPv6 protocol"
27511 -       default m
27512 +       bool "The IPv6 protocol"
27513 +       default n
27514         ---help---
27515           This is complemental support for the IP version 6.
27516           You will still be able to do traditional IPv4 networking as well.
27517 diff -NurpP --minimal linux-2.6.29.1/net/ipv6/ndisc.c linux-2.6.29.1-vs2.3.0.36.9-pre5/net/ipv6/ndisc.c
27518 --- linux-2.6.29.1/net/ipv6/ndisc.c     2009-03-24 14:22:47.000000000 +0100
27519 +++ linux-2.6.29.1-vs2.3.0.36.9-pre5/net/ipv6/ndisc.c   2009-03-24 14:48:37.000000000 +0100
27520 @@ -589,7 +589,7 @@ static void ndisc_send_na(struct net_dev
27521         } else {
27522                 if (ipv6_dev_get_saddr(dev_net(dev), dev, daddr,
27523                                        inet6_sk(dev_net(dev)->ipv6.ndisc_sk)->srcprefs,
27524 -                                      &tmpaddr))
27525 +                                      &tmpaddr, NULL /* FIXME: ? */ ))
27526                         return;
27527                 src_addr = &tmpaddr;
27528         }
27529 diff -NurpP --minimal linux-2.6.29.1/net/ipv6/raw.c linux-2.6.29.1-vs2.3.0.36.9-pre5/net/ipv6/raw.c
27530 --- linux-2.6.29.1/net/ipv6/raw.c       2009-03-24 14:22:47.000000000 +0100
27531 +++ linux-2.6.29.1-vs2.3.0.36.9-pre5/net/ipv6/raw.c     2009-03-24 14:48:37.000000000 +0100
27532 @@ -29,6 +29,7 @@
27533  #include <linux/icmpv6.h>
27534  #include <linux/netfilter.h>
27535  #include <linux/netfilter_ipv6.h>
27536 +#include <linux/vs_inet6.h>
27537  #include <linux/skbuff.h>
27538  #include <asm/uaccess.h>
27539  #include <asm/ioctls.h>
27540 @@ -281,6 +282,13 @@ static int rawv6_bind(struct sock *sk, s
27541                         }
27542                 }
27543  
27544 +               if (!v6_addr_in_nx_info(sk->sk_nx_info, &addr->sin6_addr, -1)) {
27545 +                       err = -EADDRNOTAVAIL;
27546 +                       if (dev)
27547 +                               dev_put(dev);
27548 +                       goto out;
27549 +               }
27550 +
27551                 /* ipv4 addr of the socket is invalid.  Only the
27552                  * unspecified and mapped address have a v4 equivalent.
27553                  */
27554 diff -NurpP --minimal linux-2.6.29.1/net/ipv6/route.c linux-2.6.29.1-vs2.3.0.36.9-pre5/net/ipv6/route.c
27555 --- linux-2.6.29.1/net/ipv6/route.c     2009-03-24 14:22:47.000000000 +0100
27556 +++ linux-2.6.29.1-vs2.3.0.36.9-pre5/net/ipv6/route.c   2009-03-24 14:48:37.000000000 +0100
27557 @@ -2254,7 +2254,8 @@ static int rt6_fill_node(struct net *net
27558                 struct inet6_dev *idev = ip6_dst_idev(&rt->u.dst);
27559                 struct in6_addr saddr_buf;
27560                 if (ipv6_dev_get_saddr(net, idev ? idev->dev : NULL,
27561 -                                      dst, 0, &saddr_buf) == 0)
27562 +                       dst, 0, &saddr_buf,
27563 +                       (skb->sk ? skb->sk->sk_nx_info : NULL)) == 0)
27564                         NLA_PUT(skb, RTA_PREFSRC, 16, &saddr_buf);
27565         }
27566  
27567 diff -NurpP --minimal linux-2.6.29.1/net/ipv6/tcp_ipv6.c linux-2.6.29.1-vs2.3.0.36.9-pre5/net/ipv6/tcp_ipv6.c
27568 --- linux-2.6.29.1/net/ipv6/tcp_ipv6.c  2009-03-24 14:22:47.000000000 +0100
27569 +++ linux-2.6.29.1-vs2.3.0.36.9-pre5/net/ipv6/tcp_ipv6.c        2009-03-24 14:48:37.000000000 +0100
27570 @@ -68,6 +68,7 @@
27571  
27572  #include <linux/crypto.h>
27573  #include <linux/scatterlist.h>
27574 +#include <linux/vs_inet6.h>
27575  
27576  static void    tcp_v6_send_reset(struct sock *sk, struct sk_buff *skb);
27577  static void    tcp_v6_reqsk_send_ack(struct sock *sk, struct sk_buff *skb,
27578 @@ -156,8 +157,15 @@ static int tcp_v6_connect(struct sock *s
27579          *      connect() to INADDR_ANY means loopback (BSD'ism).
27580          */
27581  
27582 -       if(ipv6_addr_any(&usin->sin6_addr))
27583 -               usin->sin6_addr.s6_addr[15] = 0x1;
27584 +       if(ipv6_addr_any(&usin->sin6_addr)) {
27585 +               struct nx_info *nxi =  sk->sk_nx_info;
27586 +
27587 +               if (nxi && nx_info_has_v6(nxi))
27588 +                       /* FIXME: remap lback? */
27589 +                       usin->sin6_addr = nxi->v6.ip;
27590 +               else
27591 +                       usin->sin6_addr.s6_addr[15] = 0x1;
27592 +       }
27593  
27594         addr_type = ipv6_addr_type(&usin->sin6_addr);
27595  
27596 diff -NurpP --minimal linux-2.6.29.1/net/ipv6/udp.c linux-2.6.29.1-vs2.3.0.36.9-pre5/net/ipv6/udp.c
27597 --- linux-2.6.29.1/net/ipv6/udp.c       2009-03-24 14:22:47.000000000 +0100
27598 +++ linux-2.6.29.1-vs2.3.0.36.9-pre5/net/ipv6/udp.c     2009-03-24 20:56:49.000000000 +0100
27599 @@ -47,6 +47,7 @@
27600  
27601  #include <linux/proc_fs.h>
27602  #include <linux/seq_file.h>
27603 +#include <linux/vs_inet6.h>
27604  #include "udp_impl.h"
27605  
27606  int udp_v6_get_port(struct sock *sk, unsigned short snum)
27607 @@ -77,6 +78,10 @@ static inline int compute_score(struct s
27608                         if (!ipv6_addr_equal(&np->rcv_saddr, daddr))
27609                                 return -1;
27610                         score++;
27611 +               } else {
27612 +                       /* block non nx_info ips */
27613 +                       if (!v6_addr_in_nx_info(sk->sk_nx_info, daddr, -1))
27614 +                               return -1;
27615                 }
27616                 if (!ipv6_addr_any(&np->daddr)) {
27617                         if (!ipv6_addr_equal(&np->daddr, saddr))
27618 diff -NurpP --minimal linux-2.6.29.1/net/ipv6/xfrm6_policy.c linux-2.6.29.1-vs2.3.0.36.9-pre5/net/ipv6/xfrm6_policy.c
27619 --- linux-2.6.29.1/net/ipv6/xfrm6_policy.c      2009-03-24 14:22:47.000000000 +0100
27620 +++ linux-2.6.29.1-vs2.3.0.36.9-pre5/net/ipv6/xfrm6_policy.c    2009-03-24 14:48:37.000000000 +0100
27621 @@ -63,7 +63,7 @@ static int xfrm6_get_saddr(struct net *n
27622         dev = ip6_dst_idev(dst)->dev;
27623         ipv6_dev_get_saddr(dev_net(dev), dev,
27624                            (struct in6_addr *)&daddr->a6, 0,
27625 -                          (struct in6_addr *)&saddr->a6);
27626 +                          (struct in6_addr *)&saddr->a6, NULL);
27627         dst_release(dst);
27628         return 0;
27629  }
27630 diff -NurpP --minimal linux-2.6.29.1/net/netlink/af_netlink.c linux-2.6.29.1-vs2.3.0.36.9-pre5/net/netlink/af_netlink.c
27631 --- linux-2.6.29.1/net/netlink/af_netlink.c     2009-03-24 14:22:47.000000000 +0100
27632 +++ linux-2.6.29.1-vs2.3.0.36.9-pre5/net/netlink/af_netlink.c   2009-03-24 14:48:37.000000000 +0100
27633 @@ -55,6 +55,9 @@
27634  #include <linux/types.h>
27635  #include <linux/audit.h>
27636  #include <linux/mutex.h>
27637 +#include <linux/vs_context.h>
27638 +#include <linux/vs_network.h>
27639 +#include <linux/vs_limit.h>
27640  
27641  #include <net/net_namespace.h>
27642  #include <net/sock.h>
27643 @@ -1776,6 +1779,8 @@ static struct sock *netlink_seq_socket_i
27644                         sk_for_each(s, node, &hash->table[j]) {
27645                                 if (sock_net(s) != seq_file_net(seq))
27646                                         continue;
27647 +                               if (!nx_check(s->sk_nid, VS_WATCH_P | VS_IDENT))
27648 +                                       continue;
27649                                 if (off == pos) {
27650                                         iter->link = i;
27651                                         iter->hash_idx = j;
27652 @@ -1810,7 +1815,8 @@ static void *netlink_seq_next(struct seq
27653         s = v;
27654         do {
27655                 s = sk_next(s);
27656 -       } while (s && sock_net(s) != seq_file_net(seq));
27657 +       } while (s && (sock_net(s) != seq_file_net(seq) ||
27658 +               !nx_check(s->sk_nid, VS_WATCH_P | VS_IDENT)));
27659         if (s)
27660                 return s;
27661  
27662 @@ -1822,7 +1828,8 @@ static void *netlink_seq_next(struct seq
27663  
27664                 for (; j <= hash->mask; j++) {
27665                         s = sk_head(&hash->table[j]);
27666 -                       while (s && sock_net(s) != seq_file_net(seq))
27667 +                       while (s && (sock_net(s) != seq_file_net(seq) ||
27668 +                               !nx_check(s->sk_nid, VS_WATCH_P | VS_IDENT)))
27669                                 s = sk_next(s);
27670                         if (s) {
27671                                 iter->link = i;
27672 diff -NurpP --minimal linux-2.6.29.1/net/sctp/ipv6.c linux-2.6.29.1-vs2.3.0.36.9-pre5/net/sctp/ipv6.c
27673 --- linux-2.6.29.1/net/sctp/ipv6.c      2009-03-24 14:22:48.000000000 +0100
27674 +++ linux-2.6.29.1-vs2.3.0.36.9-pre5/net/sctp/ipv6.c    2009-03-24 20:58:14.000000000 +0100
27675 @@ -317,7 +317,8 @@ static void sctp_v6_get_saddr(struct sct
27676                                    dst ? ip6_dst_idev(dst)->dev : NULL,
27677                                    &daddr->v6.sin6_addr,
27678                                    inet6_sk(&sk->inet.sk)->srcprefs,
27679 -                                  &saddr->v6.sin6_addr);
27680 +                                  &saddr->v6.sin6_addr,
27681 +                                  asoc->base.sk->sk_nx_info);
27682                 SCTP_DEBUG_PRINTK("saddr from ipv6_get_saddr: %pI6\n",
27683                                   &saddr->v6.sin6_addr);
27684                 return;
27685 diff -NurpP --minimal linux-2.6.29.1/net/socket.c linux-2.6.29.1-vs2.3.0.36.9-pre5/net/socket.c
27686 --- linux-2.6.29.1/net/socket.c 2009-03-24 14:22:48.000000000 +0100
27687 +++ linux-2.6.29.1-vs2.3.0.36.9-pre5/net/socket.c       2009-03-24 14:48:37.000000000 +0100
27688 @@ -95,6 +95,10 @@
27689  
27690  #include <net/sock.h>
27691  #include <linux/netfilter.h>
27692 +#include <linux/vs_base.h>
27693 +#include <linux/vs_socket.h>
27694 +#include <linux/vs_inet.h>
27695 +#include <linux/vs_inet6.h>
27696  
27697  static int sock_no_open(struct inode *irrelevant, struct file *dontcare);
27698  static ssize_t sock_aio_read(struct kiocb *iocb, const struct iovec *iov,
27699 @@ -549,7 +553,7 @@ static inline int __sock_sendmsg(struct 
27700                                  struct msghdr *msg, size_t size)
27701  {
27702         struct sock_iocb *si = kiocb_to_siocb(iocb);
27703 -       int err;
27704 +       int err, len;
27705  
27706         si->sock = sock;
27707         si->scm = NULL;
27708 @@ -560,7 +564,22 @@ static inline int __sock_sendmsg(struct 
27709         if (err)
27710                 return err;
27711  
27712 -       return sock->ops->sendmsg(iocb, sock, msg, size);
27713 +       len = sock->ops->sendmsg(iocb, sock, msg, size);
27714 +       if (sock->sk) {
27715 +               if (len == size)
27716 +                       vx_sock_send(sock->sk, size);
27717 +               else
27718 +                       vx_sock_fail(sock->sk, size);
27719 +       }
27720 +       vxdprintk(VXD_CBIT(net, 7),
27721 +               "__sock_sendmsg: %p[%p,%p,%p;%d/%d]:%d/%d",
27722 +               sock, sock->sk,
27723 +               (sock->sk)?sock->sk->sk_nx_info:0,
27724 +               (sock->sk)?sock->sk->sk_vx_info:0,
27725 +               (sock->sk)?sock->sk->sk_xid:0,
27726 +               (sock->sk)?sock->sk->sk_nid:0,
27727 +               (unsigned int)size, len);
27728 +       return len;
27729  }
27730  
27731  int sock_sendmsg(struct socket *sock, struct msghdr *msg, size_t size)
27732 @@ -629,7 +648,7 @@ EXPORT_SYMBOL_GPL(__sock_recv_timestamp)
27733  static inline int __sock_recvmsg(struct kiocb *iocb, struct socket *sock,
27734                                  struct msghdr *msg, size_t size, int flags)
27735  {
27736 -       int err;
27737 +       int err, len;
27738         struct sock_iocb *si = kiocb_to_siocb(iocb);
27739  
27740         si->sock = sock;
27741 @@ -642,7 +661,18 @@ static inline int __sock_recvmsg(struct 
27742         if (err)
27743                 return err;
27744  
27745 -       return sock->ops->recvmsg(iocb, sock, msg, size, flags);
27746 +       len = sock->ops->recvmsg(iocb, sock, msg, size, flags);
27747 +       if ((len >= 0) && sock->sk)
27748 +               vx_sock_recv(sock->sk, len);
27749 +       vxdprintk(VXD_CBIT(net, 7),
27750 +               "__sock_recvmsg: %p[%p,%p,%p;%d/%d]:%d/%d",
27751 +               sock, sock->sk,
27752 +               (sock->sk)?sock->sk->sk_nx_info:0,
27753 +               (sock->sk)?sock->sk->sk_vx_info:0,
27754 +               (sock->sk)?sock->sk->sk_xid:0,
27755 +               (sock->sk)?sock->sk->sk_nid:0,
27756 +               (unsigned int)size, len);
27757 +       return len;
27758  }
27759  
27760  int sock_recvmsg(struct socket *sock, struct msghdr *msg,
27761 @@ -1106,6 +1136,13 @@ static int __sock_create(struct net *net
27762         if (type < 0 || type >= SOCK_MAX)
27763                 return -EINVAL;
27764  
27765 +       if (!nx_check(0, VS_ADMIN)) {
27766 +               if (family == PF_INET && !current_nx_info_has_v4())
27767 +                       return -EAFNOSUPPORT;
27768 +               if (family == PF_INET6 && !current_nx_info_has_v6())
27769 +                       return -EAFNOSUPPORT;
27770 +       }
27771 +
27772         /* Compatibility.
27773  
27774            This uglymoron is moved from INET layer to here to avoid
27775 @@ -1238,6 +1275,7 @@ SYSCALL_DEFINE3(socket, int, family, int
27776         if (retval < 0)
27777                 goto out;
27778  
27779 +       set_bit(SOCK_USER_SOCKET, &sock->flags);
27780         retval = sock_map_fd(sock, flags & (O_CLOEXEC | O_NONBLOCK));
27781         if (retval < 0)
27782                 goto out_release;
27783 @@ -1279,10 +1317,12 @@ SYSCALL_DEFINE4(socketpair, int, family,
27784         err = sock_create(family, type, protocol, &sock1);
27785         if (err < 0)
27786                 goto out;
27787 +       set_bit(SOCK_USER_SOCKET, &sock1->flags);
27788  
27789         err = sock_create(family, type, protocol, &sock2);
27790         if (err < 0)
27791                 goto out_release_1;
27792 +       set_bit(SOCK_USER_SOCKET, &sock2->flags);
27793  
27794         err = sock1->ops->socketpair(sock1, sock2);
27795         if (err < 0)
27796 diff -NurpP --minimal linux-2.6.29.1/net/sunrpc/auth.c linux-2.6.29.1-vs2.3.0.36.9-pre5/net/sunrpc/auth.c
27797 --- linux-2.6.29.1/net/sunrpc/auth.c    2009-03-24 14:22:48.000000000 +0100
27798 +++ linux-2.6.29.1-vs2.3.0.36.9-pre5/net/sunrpc/auth.c  2009-03-24 21:00:49.000000000 +0100
27799 @@ -14,6 +14,7 @@
27800  #include <linux/hash.h>
27801  #include <linux/sunrpc/clnt.h>
27802  #include <linux/spinlock.h>
27803 +#include <linux/vs_tag.h>
27804  
27805  #ifdef RPC_DEBUG
27806  # define RPCDBG_FACILITY       RPCDBG_AUTH
27807 @@ -360,6 +361,7 @@ rpcauth_lookupcred(struct rpc_auth *auth
27808         memset(&acred, 0, sizeof(acred));
27809         acred.uid = cred->fsuid;
27810         acred.gid = cred->fsgid;
27811 +       acred.tag = dx_current_tag();
27812         acred.group_info = get_group_info(((struct cred *)cred)->group_info);
27813  
27814         ret = auth->au_ops->lookup_cred(auth, &acred, flags);
27815 @@ -400,6 +402,7 @@ rpcauth_bind_root_cred(struct rpc_task *
27816         struct auth_cred acred = {
27817                 .uid = 0,
27818                 .gid = 0,
27819 +               .tag = dx_current_tag(),
27820         };
27821         struct rpc_cred *ret;
27822  
27823 diff -NurpP --minimal linux-2.6.29.1/net/sunrpc/auth_unix.c linux-2.6.29.1-vs2.3.0.36.9-pre5/net/sunrpc/auth_unix.c
27824 --- linux-2.6.29.1/net/sunrpc/auth_unix.c       2008-12-25 00:26:37.000000000 +0100
27825 +++ linux-2.6.29.1-vs2.3.0.36.9-pre5/net/sunrpc/auth_unix.c     2009-02-22 22:54:26.000000000 +0100
27826 @@ -11,12 +11,14 @@
27827  #include <linux/module.h>
27828  #include <linux/sunrpc/clnt.h>
27829  #include <linux/sunrpc/auth.h>
27830 +#include <linux/vs_tag.h>
27831  
27832  #define NFS_NGROUPS    16
27833  
27834  struct unx_cred {
27835         struct rpc_cred         uc_base;
27836         gid_t                   uc_gid;
27837 +       tag_t                   uc_tag;
27838         gid_t                   uc_gids[NFS_NGROUPS];
27839  };
27840  #define uc_uid                 uc_base.cr_uid
27841 @@ -78,6 +80,7 @@ unx_create_cred(struct rpc_auth *auth, s
27842                 groups = NFS_NGROUPS;
27843  
27844         cred->uc_gid = acred->gid;
27845 +       cred->uc_tag = acred->tag;
27846         for (i = 0; i < groups; i++)
27847                 cred->uc_gids[i] = GROUP_AT(acred->group_info, i);
27848         if (i < NFS_NGROUPS)
27849 @@ -119,7 +122,9 @@ unx_match(struct auth_cred *acred, struc
27850         unsigned int i;
27851  
27852  
27853 -       if (cred->uc_uid != acred->uid || cred->uc_gid != acred->gid)
27854 +       if (cred->uc_uid != acred->uid ||
27855 +               cred->uc_gid != acred->gid ||
27856 +               cred->uc_tag != acred->tag)
27857                 return 0;
27858  
27859         if (acred->group_info != NULL)
27860 @@ -142,7 +147,7 @@ unx_marshal(struct rpc_task *task, __be3
27861         struct rpc_clnt *clnt = task->tk_client;
27862         struct unx_cred *cred = container_of(task->tk_msg.rpc_cred, struct unx_cred, uc_base);
27863         __be32          *base, *hold;
27864 -       int             i;
27865 +       int             i, tag;
27866  
27867         *p++ = htonl(RPC_AUTH_UNIX);
27868         base = p++;
27869 @@ -152,9 +157,12 @@ unx_marshal(struct rpc_task *task, __be3
27870          * Copy the UTS nodename captured when the client was created.
27871          */
27872         p = xdr_encode_array(p, clnt->cl_nodename, clnt->cl_nodelen);
27873 +       tag = task->tk_client->cl_tag;
27874  
27875 -       *p++ = htonl((u32) cred->uc_uid);
27876 -       *p++ = htonl((u32) cred->uc_gid);
27877 +       *p++ = htonl((u32) TAGINO_UID(tag,
27878 +               cred->uc_uid, cred->uc_tag));
27879 +       *p++ = htonl((u32) TAGINO_GID(tag,
27880 +               cred->uc_gid, cred->uc_tag));
27881         hold = p++;
27882         for (i = 0; i < 16 && cred->uc_gids[i] != (gid_t) NOGROUP; i++)
27883                 *p++ = htonl((u32) cred->uc_gids[i]);
27884 diff -NurpP --minimal linux-2.6.29.1/net/sunrpc/clnt.c linux-2.6.29.1-vs2.3.0.36.9-pre5/net/sunrpc/clnt.c
27885 --- linux-2.6.29.1/net/sunrpc/clnt.c    2009-03-24 14:22:48.000000000 +0100
27886 +++ linux-2.6.29.1-vs2.3.0.36.9-pre5/net/sunrpc/clnt.c  2009-03-24 14:48:37.000000000 +0100
27887 @@ -32,6 +32,7 @@
27888  #include <linux/utsname.h>
27889  #include <linux/workqueue.h>
27890  #include <linux/in6.h>
27891 +#include <linux/vs_cvirt.h>
27892  
27893  #include <linux/sunrpc/clnt.h>
27894  #include <linux/sunrpc/rpc_pipe_fs.h>
27895 @@ -335,6 +336,9 @@ struct rpc_clnt *rpc_create(struct rpc_c
27896         if (!(args->flags & RPC_CLNT_CREATE_QUIET))
27897                 clnt->cl_chatty = 1;
27898  
27899 +       /* TODO: handle RPC_CLNT_CREATE_TAGGED
27900 +       if (args->flags & RPC_CLNT_CREATE_TAGGED)
27901 +               clnt->cl_tag = 1; */
27902         return clnt;
27903  }
27904  EXPORT_SYMBOL_GPL(rpc_create);
27905 diff -NurpP --minimal linux-2.6.29.1/net/unix/af_unix.c linux-2.6.29.1-vs2.3.0.36.9-pre5/net/unix/af_unix.c
27906 --- linux-2.6.29.1/net/unix/af_unix.c   2009-03-24 14:22:48.000000000 +0100
27907 +++ linux-2.6.29.1-vs2.3.0.36.9-pre5/net/unix/af_unix.c 2009-03-24 14:48:37.000000000 +0100
27908 @@ -114,6 +114,8 @@
27909  #include <linux/mount.h>
27910  #include <net/checksum.h>
27911  #include <linux/security.h>
27912 +#include <linux/vs_context.h>
27913 +#include <linux/vs_limit.h>
27914  
27915  static struct hlist_head unix_socket_table[UNIX_HASH_SIZE + 1];
27916  static DEFINE_SPINLOCK(unix_table_lock);
27917 @@ -258,6 +260,8 @@ static struct sock *__unix_find_socket_b
27918                 if (!net_eq(sock_net(s), net))
27919                         continue;
27920  
27921 +               if (!nx_check(s->sk_nid, VS_WATCH_P | VS_IDENT))
27922 +                       continue;
27923                 if (u->addr->len == len &&
27924                     !memcmp(u->addr->name, sunname, len))
27925                         goto found;
27926 @@ -2110,6 +2114,8 @@ static struct sock *unix_seq_idx(struct 
27927         for (s = first_unix_socket(&iter->i); s; s = next_unix_socket(&iter->i, s)) {
27928                 if (sock_net(s) != seq_file_net(seq))
27929                         continue;
27930 +               if (!nx_check(s->sk_nid, VS_WATCH_P | VS_IDENT))
27931 +                       continue;
27932                 if (off == pos)
27933                         return s;
27934                 ++off;
27935 @@ -2134,7 +2140,8 @@ static void *unix_seq_next(struct seq_fi
27936                 sk = first_unix_socket(&iter->i);
27937         else
27938                 sk = next_unix_socket(&iter->i, sk);
27939 -       while (sk && (sock_net(sk) != seq_file_net(seq)))
27940 +       while (sk && (sock_net(sk) != seq_file_net(seq) ||
27941 +               !nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT)))
27942                 sk = next_unix_socket(&iter->i, sk);
27943         return sk;
27944  }
27945 diff -NurpP --minimal linux-2.6.29.1/net/x25/af_x25.c linux-2.6.29.1-vs2.3.0.36.9-pre5/net/x25/af_x25.c
27946 --- linux-2.6.29.1/net/x25/af_x25.c     2008-12-25 00:26:37.000000000 +0100
27947 +++ linux-2.6.29.1-vs2.3.0.36.9-pre5/net/x25/af_x25.c   2009-02-22 22:54:26.000000000 +0100
27948 @@ -506,7 +506,10 @@ static int x25_create(struct net *net, s
27949  
27950         x25 = x25_sk(sk);
27951  
27952 -       sock_init_data(sock, sk);
27953 +       sk->sk_socket = sock;
27954 +       sk->sk_type = sock->type;
27955 +       sk->sk_sleep = &sock->wait;
27956 +       sock->sk = sk;
27957  
27958         x25_init_timers(sk);
27959  
27960 diff -NurpP --minimal linux-2.6.29.1/scripts/checksyscalls.sh linux-2.6.29.1-vs2.3.0.36.9-pre5/scripts/checksyscalls.sh
27961 --- linux-2.6.29.1/scripts/checksyscalls.sh     2008-12-25 00:26:37.000000000 +0100
27962 +++ linux-2.6.29.1-vs2.3.0.36.9-pre5/scripts/checksyscalls.sh   2009-02-22 22:54:26.000000000 +0100
27963 @@ -108,7 +108,6 @@ cat << EOF
27964  #define __IGNORE_afs_syscall
27965  #define __IGNORE_getpmsg
27966  #define __IGNORE_putpmsg
27967 -#define __IGNORE_vserver
27968  EOF
27969  }
27970  
27971 diff -NurpP --minimal linux-2.6.29.1/security/commoncap.c linux-2.6.29.1-vs2.3.0.36.9-pre5/security/commoncap.c
27972 --- linux-2.6.29.1/security/commoncap.c 2009-03-24 14:23:21.000000000 +0100
27973 +++ linux-2.6.29.1-vs2.3.0.36.9-pre5/security/commoncap.c       2009-03-25 00:34:48.000000000 +0100
27974 @@ -27,10 +27,11 @@
27975  #include <linux/sched.h>
27976  #include <linux/prctl.h>
27977  #include <linux/securebits.h>
27978 +#include <linux/vs_context.h>
27979  
27980  int cap_netlink_send(struct sock *sk, struct sk_buff *skb)
27981  {
27982 -       NETLINK_CB(skb).eff_cap = current_cap();
27983 +       NETLINK_CB(skb).eff_cap = vx_mbcaps(current_cap());
27984         return 0;
27985  }
27986  
27987 @@ -40,6 +41,7 @@ int cap_netlink_recv(struct sk_buff *skb
27988                 return -EPERM;
27989         return 0;
27990  }
27991 +
27992  EXPORT_SYMBOL(cap_netlink_recv);
27993  
27994  /**
27995 @@ -60,7 +62,22 @@ EXPORT_SYMBOL(cap_netlink_recv);
27996  int cap_capable(struct task_struct *tsk, const struct cred *cred, int cap,
27997                 int audit)
27998  {
27999 -       return cap_raised(cred->cap_effective, cap) ? 0 : -EPERM;
28000 +       struct vx_info *vxi = tsk->vx_info;
28001 +
28002 +#if 0
28003 +       printk("cap_capable() VXF_STATE_SETUP = %llx, raised = %x, eff = %08x:%08x\n",
28004 +               vx_info_flags(vxi, VXF_STATE_SETUP, 0),
28005 +               cap_raised(tsk->cap_effective, cap),
28006 +               tsk->cap_effective.cap[1], tsk->cap_effective.cap[0]);
28007 +#endif
28008 +
28009 +       /* special case SETUP */
28010 +       if (vx_info_flags(vxi, VXF_STATE_SETUP, 0) &&
28011 +               /* FIXME: maybe use cred instead? */
28012 +               cap_raised(tsk->cred->cap_effective, cap))
28013 +               return 0;
28014 +
28015 +       return vx_cap_raised(vxi, cred->cap_effective, cap) ? 0 : -EPERM;
28016  }
28017  
28018  /**
28019 @@ -586,7 +603,7 @@ int cap_inode_setxattr(struct dentry *de
28020  
28021         if (!strncmp(name, XATTR_SECURITY_PREFIX,
28022                      sizeof(XATTR_SECURITY_PREFIX) - 1)  &&
28023 -           !capable(CAP_SYS_ADMIN))
28024 +               !vx_capable(CAP_SYS_ADMIN, VXC_FS_SECURITY))
28025                 return -EPERM;
28026         return 0;
28027  }
28028 @@ -931,7 +948,8 @@ error:
28029   */
28030  int cap_syslog(int type)
28031  {
28032 -       if ((type != 3 && type != 10) && !capable(CAP_SYS_ADMIN))
28033 +       if ((type != 3 && type != 10) &&
28034 +               !vx_capable(CAP_SYS_ADMIN, VXC_SYSLOG))
28035                 return -EPERM;
28036         return 0;
28037  }
28038 @@ -953,3 +971,4 @@ int cap_vm_enough_memory(struct mm_struc
28039                 cap_sys_admin = 1;
28040         return __vm_enough_memory(mm, pages, cap_sys_admin);
28041  }
28042 +
28043 diff -NurpP --minimal linux-2.6.29.1/security/selinux/hooks.c linux-2.6.29.1-vs2.3.0.36.9-pre5/security/selinux/hooks.c
28044 --- linux-2.6.29.1/security/selinux/hooks.c     2009-03-24 14:23:21.000000000 +0100
28045 +++ linux-2.6.29.1-vs2.3.0.36.9-pre5/security/selinux/hooks.c   2009-03-24 14:48:37.000000000 +0100
28046 @@ -64,7 +64,6 @@
28047  #include <linux/dccp.h>
28048  #include <linux/quota.h>
28049  #include <linux/un.h>          /* for Unix socket types */
28050 -#include <net/af_unix.h>       /* for Unix socket types */
28051  #include <linux/parser.h>
28052  #include <linux/nfs_mount.h>
28053  #include <net/ipv6.h>
This page took 2.170517 seconds and 4 git commands to generate.