]> git.pld-linux.org Git - packages/kernel.git/blob - kernel-vserver-2.3.patch
- up to 2.6.32.7-1, updated grsec_full and vserver, small changes in
[packages/kernel.git] / kernel-vserver-2.3.patch
1 diff -NurpP --minimal linux-2.6.32.6/arch/alpha/Kconfig linux-2.6.32.6-vs2.3.0.36.28/arch/alpha/Kconfig
2 --- linux-2.6.32.6/arch/alpha/Kconfig   2009-12-03 20:01:49.000000000 +0100
3 +++ linux-2.6.32.6-vs2.3.0.36.28/arch/alpha/Kconfig     2009-12-03 20:04:56.000000000 +0100
4 @@ -674,6 +674,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.32.6/arch/alpha/kernel/entry.S linux-2.6.32.6-vs2.3.0.36.28/arch/alpha/kernel/entry.S
14 --- linux-2.6.32.6/arch/alpha/kernel/entry.S    2009-06-11 17:11:46.000000000 +0200
15 +++ linux-2.6.32.6-vs2.3.0.36.28/arch/alpha/kernel/entry.S      2009-12-03 20:04:56.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.32.6/arch/alpha/kernel/osf_sys.c linux-2.6.32.6-vs2.3.0.36.28/arch/alpha/kernel/osf_sys.c
49 --- linux-2.6.32.6/arch/alpha/kernel/osf_sys.c  2010-01-26 19:31:20.000000000 +0100
50 +++ linux-2.6.32.6-vs2.3.0.36.28/arch/alpha/kernel/osf_sys.c    2010-01-20 04:21:33.000000000 +0100
51 @@ -865,7 +865,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.32.6/arch/alpha/kernel/ptrace.c linux-2.6.32.6-vs2.3.0.36.28/arch/alpha/kernel/ptrace.c
61 --- linux-2.6.32.6/arch/alpha/kernel/ptrace.c   2009-09-10 15:25:14.000000000 +0200
62 +++ linux-2.6.32.6-vs2.3.0.36.28/arch/alpha/kernel/ptrace.c     2009-12-03 20:04:56.000000000 +0100
63 @@ -14,6 +14,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.32.6/arch/alpha/kernel/systbls.S linux-2.6.32.6-vs2.3.0.36.28/arch/alpha/kernel/systbls.S
72 --- linux-2.6.32.6/arch/alpha/kernel/systbls.S  2009-03-24 14:18:08.000000000 +0100
73 +++ linux-2.6.32.6-vs2.3.0.36.28/arch/alpha/kernel/systbls.S    2009-12-03 20:04:56.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.32.6/arch/alpha/kernel/traps.c linux-2.6.32.6-vs2.3.0.36.28/arch/alpha/kernel/traps.c
84 --- linux-2.6.32.6/arch/alpha/kernel/traps.c    2009-06-11 17:11:46.000000000 +0200
85 +++ linux-2.6.32.6-vs2.3.0.36.28/arch/alpha/kernel/traps.c      2009-12-03 20:04:56.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.32.6/arch/alpha/mm/fault.c linux-2.6.32.6-vs2.3.0.36.28/arch/alpha/mm/fault.c
97 --- linux-2.6.32.6/arch/alpha/mm/fault.c        2009-09-10 15:25:14.000000000 +0200
98 +++ linux-2.6.32.6-vs2.3.0.36.28/arch/alpha/mm/fault.c  2009-12-03 20:04:56.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.32.6/arch/arm/Kconfig linux-2.6.32.6-vs2.3.0.36.28/arch/arm/Kconfig
111 --- linux-2.6.32.6/arch/arm/Kconfig     2009-12-03 20:01:49.000000000 +0100
112 +++ linux-2.6.32.6-vs2.3.0.36.28/arch/arm/Kconfig       2009-12-03 20:04:56.000000000 +0100
113 @@ -1512,6 +1512,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.32.6/arch/arm/kernel/calls.S linux-2.6.32.6-vs2.3.0.36.28/arch/arm/kernel/calls.S
123 --- linux-2.6.32.6/arch/arm/kernel/calls.S      2010-01-26 19:31:20.000000000 +0100
124 +++ linux-2.6.32.6-vs2.3.0.36.28/arch/arm/kernel/calls.S        2010-01-20 04:21:33.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.32.6/arch/arm/kernel/process.c linux-2.6.32.6-vs2.3.0.36.28/arch/arm/kernel/process.c
135 --- linux-2.6.32.6/arch/arm/kernel/process.c    2009-12-03 20:01:50.000000000 +0100
136 +++ linux-2.6.32.6-vs2.3.0.36.28/arch/arm/kernel/process.c      2009-12-03 20:04:56.000000000 +0100
137 @@ -269,7 +269,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.32.6/arch/arm/kernel/traps.c linux-2.6.32.6-vs2.3.0.36.28/arch/arm/kernel/traps.c
148 --- linux-2.6.32.6/arch/arm/kernel/traps.c      2009-12-03 20:01:50.000000000 +0100
149 +++ linux-2.6.32.6-vs2.3.0.36.28/arch/arm/kernel/traps.c        2009-12-03 20:04:56.000000000 +0100
150 @@ -234,8 +234,8 @@ static void __die(const char *str, int e
151         sysfs_printk_last_file();
152         print_modules();
153         __show_regs(regs);
154 -       printk(KERN_EMERG "Process %.*s (pid: %d, stack limit = 0x%p)\n",
155 -               TASK_COMM_LEN, tsk->comm, task_pid_nr(tsk), thread + 1);
156 +       printk(KERN_EMERG "Process %.*s (pid: %d:#%u, stack limit = 0x%p)\n",
157 +               TASK_COMM_LEN, tsk->comm, task_pid_nr(tsk), tsk->xid, thread + 1);
158  
159         if (!user_mode(regs) || in_interrupt()) {
160                 dump_mem(KERN_EMERG, "Stack: ", regs->ARM_sp,
161 diff -NurpP --minimal linux-2.6.32.6/arch/avr32/mm/fault.c linux-2.6.32.6-vs2.3.0.36.28/arch/avr32/mm/fault.c
162 --- linux-2.6.32.6/arch/avr32/mm/fault.c        2009-09-10 15:25:20.000000000 +0200
163 +++ linux-2.6.32.6-vs2.3.0.36.28/arch/avr32/mm/fault.c  2009-12-03 20:04:56.000000000 +0100
164 @@ -216,7 +216,8 @@ out_of_memory:
165                 down_read(&mm->mmap_sem);
166                 goto survive;
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         if (user_mode(regs))
172                 do_group_exit(SIGKILL);
173         goto no_context;
174 diff -NurpP --minimal linux-2.6.32.6/arch/cris/Kconfig linux-2.6.32.6-vs2.3.0.36.28/arch/cris/Kconfig
175 --- linux-2.6.32.6/arch/cris/Kconfig    2009-06-11 17:11:56.000000000 +0200
176 +++ linux-2.6.32.6-vs2.3.0.36.28/arch/cris/Kconfig      2009-12-03 20:04:56.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.32.6/arch/cris/mm/fault.c linux-2.6.32.6-vs2.3.0.36.28/arch/cris/mm/fault.c
187 --- linux-2.6.32.6/arch/cris/mm/fault.c 2009-12-03 20:01:56.000000000 +0100
188 +++ linux-2.6.32.6-vs2.3.0.36.28/arch/cris/mm/fault.c   2009-12-03 20:04:56.000000000 +0100
189 @@ -245,7 +245,8 @@ do_page_fault(unsigned long address, str
190  
191   out_of_memory:
192         up_read(&mm->mmap_sem);
193 -       printk("VM: killing process %s\n", tsk->comm);
194 +       printk("VM: killing process %s(%d:#%u)\n",
195 +               tsk->comm, task_pid_nr(tsk), tsk->xid);
196         if (user_mode(regs))
197                 do_exit(SIGKILL);
198         goto no_context;
199 diff -NurpP --minimal linux-2.6.32.6/arch/frv/kernel/kernel_thread.S linux-2.6.32.6-vs2.3.0.36.28/arch/frv/kernel/kernel_thread.S
200 --- linux-2.6.32.6/arch/frv/kernel/kernel_thread.S      2008-12-25 00:26:37.000000000 +0100
201 +++ linux-2.6.32.6-vs2.3.0.36.28/arch/frv/kernel/kernel_thread.S        2009-12-03 20:04:56.000000000 +0100
202 @@ -37,7 +37,7 @@ kernel_thread:
203  
204         # start by forking the current process, but with shared VM
205         setlos.p        #__NR_clone,gr7         ; syscall number
206 -       ori             gr10,#CLONE_VM,gr8      ; first syscall arg     [clone_flags]
207 +       ori             gr10,#CLONE_KT,gr8      ; first syscall arg     [clone_flags]
208         sethi.p         #0xe4e4,gr9             ; second syscall arg    [newsp]
209         setlo           #0xe4e4,gr9
210         setlos.p        #0,gr10                 ; third syscall arg     [parent_tidptr]
211 diff -NurpP --minimal linux-2.6.32.6/arch/frv/mm/fault.c linux-2.6.32.6-vs2.3.0.36.28/arch/frv/mm/fault.c
212 --- linux-2.6.32.6/arch/frv/mm/fault.c  2009-09-10 15:25:22.000000000 +0200
213 +++ linux-2.6.32.6-vs2.3.0.36.28/arch/frv/mm/fault.c    2009-12-03 20:04:56.000000000 +0100
214 @@ -257,7 +257,8 @@ asmlinkage void do_page_fault(int datamm
215   */
216   out_of_memory:
217         up_read(&mm->mmap_sem);
218 -       printk("VM: killing process %s\n", current->comm);
219 +       printk("VM: killing process %s(%d:#%u)\n",
220 +               current->comm, task_pid_nr(current), current->xid);
221         if (user_mode(__frame))
222                 do_group_exit(SIGKILL);
223         goto no_context;
224 diff -NurpP --minimal linux-2.6.32.6/arch/h8300/Kconfig linux-2.6.32.6-vs2.3.0.36.28/arch/h8300/Kconfig
225 --- linux-2.6.32.6/arch/h8300/Kconfig   2009-03-24 14:18:24.000000000 +0100
226 +++ linux-2.6.32.6-vs2.3.0.36.28/arch/h8300/Kconfig     2009-12-03 20:04:56.000000000 +0100
227 @@ -226,6 +226,8 @@ source "fs/Kconfig"
228  
229  source "arch/h8300/Kconfig.debug"
230  
231 +source "kernel/vserver/Kconfig"
232 +
233  source "security/Kconfig"
234  
235  source "crypto/Kconfig"
236 diff -NurpP --minimal linux-2.6.32.6/arch/ia64/ia32/ia32_entry.S linux-2.6.32.6-vs2.3.0.36.28/arch/ia64/ia32/ia32_entry.S
237 --- linux-2.6.32.6/arch/ia64/ia32/ia32_entry.S  2009-06-11 17:11:57.000000000 +0200
238 +++ linux-2.6.32.6-vs2.3.0.36.28/arch/ia64/ia32/ia32_entry.S    2009-12-03 20:04:56.000000000 +0100
239 @@ -451,7 +451,7 @@ ia32_syscall_table:
240         data8 sys_tgkill        /* 270 */
241         data8 compat_sys_utimes
242         data8 sys32_fadvise64_64
243 -       data8 sys_ni_syscall
244 +       data8 sys32_vserver
245         data8 sys_ni_syscall
246         data8 sys_ni_syscall    /* 275 */
247         data8 sys_ni_syscall
248 diff -NurpP --minimal linux-2.6.32.6/arch/ia64/include/asm/tlb.h linux-2.6.32.6-vs2.3.0.36.28/arch/ia64/include/asm/tlb.h
249 --- linux-2.6.32.6/arch/ia64/include/asm/tlb.h  2009-09-10 15:25:22.000000000 +0200
250 +++ linux-2.6.32.6-vs2.3.0.36.28/arch/ia64/include/asm/tlb.h    2009-12-31 14:37:34.000000000 +0100
251 @@ -40,6 +40,7 @@
252  #include <linux/mm.h>
253  #include <linux/pagemap.h>
254  #include <linux/swap.h>
255 +#include <linux/vs_memory.h>
256  
257  #include <asm/pgalloc.h>
258  #include <asm/processor.h>
259 diff -NurpP --minimal linux-2.6.32.6/arch/ia64/Kconfig linux-2.6.32.6-vs2.3.0.36.28/arch/ia64/Kconfig
260 --- linux-2.6.32.6/arch/ia64/Kconfig    2009-12-03 20:01:56.000000000 +0100
261 +++ linux-2.6.32.6-vs2.3.0.36.28/arch/ia64/Kconfig      2009-12-03 20:04:56.000000000 +0100
262 @@ -685,6 +685,8 @@ source "fs/Kconfig"
263  
264  source "arch/ia64/Kconfig.debug"
265  
266 +source "kernel/vserver/Kconfig"
267 +
268  source "security/Kconfig"
269  
270  source "crypto/Kconfig"
271 diff -NurpP --minimal linux-2.6.32.6/arch/ia64/kernel/entry.S linux-2.6.32.6-vs2.3.0.36.28/arch/ia64/kernel/entry.S
272 --- linux-2.6.32.6/arch/ia64/kernel/entry.S     2009-09-10 15:25:22.000000000 +0200
273 +++ linux-2.6.32.6-vs2.3.0.36.28/arch/ia64/kernel/entry.S       2009-12-03 20:04:56.000000000 +0100
274 @@ -1753,7 +1753,7 @@ sys_call_table:
275         data8 sys_mq_notify
276         data8 sys_mq_getsetattr
277         data8 sys_kexec_load
278 -       data8 sys_ni_syscall                    // reserved for vserver
279 +       data8 sys_vserver
280         data8 sys_waitid                        // 1270
281         data8 sys_add_key
282         data8 sys_request_key
283 diff -NurpP --minimal linux-2.6.32.6/arch/ia64/kernel/perfmon.c linux-2.6.32.6-vs2.3.0.36.28/arch/ia64/kernel/perfmon.c
284 --- linux-2.6.32.6/arch/ia64/kernel/perfmon.c   2009-09-10 15:25:22.000000000 +0200
285 +++ linux-2.6.32.6-vs2.3.0.36.28/arch/ia64/kernel/perfmon.c     2009-12-03 20:04:56.000000000 +0100
286 @@ -41,6 +41,7 @@
287  #include <linux/rcupdate.h>
288  #include <linux/completion.h>
289  #include <linux/tracehook.h>
290 +#include <linux/vs_memory.h>
291  
292  #include <asm/errno.h>
293  #include <asm/intrinsics.h>
294 @@ -2372,7 +2373,7 @@ pfm_smpl_buffer_alloc(struct task_struct
295          */
296         insert_vm_struct(mm, vma);
297  
298 -       mm->total_vm  += size >> PAGE_SHIFT;
299 +       vx_vmpages_add(mm, size >> PAGE_SHIFT);
300         vm_stat_account(vma->vm_mm, vma->vm_flags, vma->vm_file,
301                                                         vma_pages(vma));
302         up_write(&task->mm->mmap_sem);
303 diff -NurpP --minimal linux-2.6.32.6/arch/ia64/kernel/process.c linux-2.6.32.6-vs2.3.0.36.28/arch/ia64/kernel/process.c
304 --- linux-2.6.32.6/arch/ia64/kernel/process.c   2009-12-03 20:01:56.000000000 +0100
305 +++ linux-2.6.32.6-vs2.3.0.36.28/arch/ia64/kernel/process.c     2009-12-03 20:04:56.000000000 +0100
306 @@ -110,8 +110,8 @@ show_regs (struct pt_regs *regs)
307         unsigned long ip = regs->cr_iip + ia64_psr(regs)->ri;
308  
309         print_modules();
310 -       printk("\nPid: %d, CPU %d, comm: %20s\n", task_pid_nr(current),
311 -                       smp_processor_id(), current->comm);
312 +       printk("\nPid: %d[#%u], CPU %d, comm: %20s\n", task_pid_nr(current),
313 +                       current->xid, smp_processor_id(), current->comm);
314         printk("psr : %016lx ifs : %016lx ip  : [<%016lx>]    %s (%s)\n",
315                regs->cr_ipsr, regs->cr_ifs, ip, print_tainted(),
316                init_utsname()->release);
317 diff -NurpP --minimal linux-2.6.32.6/arch/ia64/kernel/ptrace.c linux-2.6.32.6-vs2.3.0.36.28/arch/ia64/kernel/ptrace.c
318 --- linux-2.6.32.6/arch/ia64/kernel/ptrace.c    2009-09-10 15:25:22.000000000 +0200
319 +++ linux-2.6.32.6-vs2.3.0.36.28/arch/ia64/kernel/ptrace.c      2009-12-03 20:04:56.000000000 +0100
320 @@ -22,6 +22,7 @@
321  #include <linux/regset.h>
322  #include <linux/elf.h>
323  #include <linux/tracehook.h>
324 +#include <linux/vs_base.h>
325  
326  #include <asm/pgtable.h>
327  #include <asm/processor.h>
328 diff -NurpP --minimal linux-2.6.32.6/arch/ia64/kernel/traps.c linux-2.6.32.6-vs2.3.0.36.28/arch/ia64/kernel/traps.c
329 --- linux-2.6.32.6/arch/ia64/kernel/traps.c     2008-12-25 00:26:37.000000000 +0100
330 +++ linux-2.6.32.6-vs2.3.0.36.28/arch/ia64/kernel/traps.c       2009-12-03 20:04:56.000000000 +0100
331 @@ -60,8 +60,9 @@ die (const char *str, struct pt_regs *re
332         put_cpu();
333  
334         if (++die.lock_owner_depth < 3) {
335 -               printk("%s[%d]: %s %ld [%d]\n",
336 -               current->comm, task_pid_nr(current), str, err, ++die_counter);
337 +               printk("%s[%d[#%u]]: %s %ld [%d]\n",
338 +                       current->comm, task_pid_nr(current), current->xid,
339 +                       str, err, ++die_counter);
340                 if (notify_die(DIE_OOPS, str, regs, err, 255, SIGSEGV)
341                     != NOTIFY_STOP)
342                         show_regs(regs);
343 @@ -324,8 +325,9 @@ handle_fpu_swa (int fp_fault, struct pt_
344                         if ((last.count & 15) < 5 && (ia64_fetchadd(1, &last.count, acq) & 15) < 5) {
345                                 last.time = current_jiffies + 5 * HZ;
346                                 printk(KERN_WARNING
347 -                                       "%s(%d): floating-point assist fault at ip %016lx, isr %016lx\n",
348 -                                       current->comm, task_pid_nr(current), regs->cr_iip + ia64_psr(regs)->ri, isr);
349 +                                       "%s(%d[#%u]): floating-point assist fault at ip %016lx, isr %016lx\n",
350 +                                       current->comm, task_pid_nr(current), current->xid,
351 +                                       regs->cr_iip + ia64_psr(regs)->ri, isr);
352                         }
353                 }
354         }
355 diff -NurpP --minimal linux-2.6.32.6/arch/ia64/mm/fault.c linux-2.6.32.6-vs2.3.0.36.28/arch/ia64/mm/fault.c
356 --- linux-2.6.32.6/arch/ia64/mm/fault.c 2009-09-10 15:25:23.000000000 +0200
357 +++ linux-2.6.32.6-vs2.3.0.36.28/arch/ia64/mm/fault.c   2009-12-03 20:04:56.000000000 +0100
358 @@ -10,6 +10,7 @@
359  #include <linux/interrupt.h>
360  #include <linux/kprobes.h>
361  #include <linux/kdebug.h>
362 +#include <linux/vs_memory.h>
363  
364  #include <asm/pgtable.h>
365  #include <asm/processor.h>
366 @@ -281,7 +282,8 @@ ia64_do_page_fault (unsigned long addres
367                 down_read(&mm->mmap_sem);
368                 goto survive;
369         }
370 -       printk(KERN_CRIT "VM: killing process %s\n", current->comm);
371 +       printk(KERN_CRIT "VM: killing process %s(%d:#%u)\n",
372 +               current->comm, task_pid_nr(current), current->xid);
373         if (user_mode(regs))
374                 do_group_exit(SIGKILL);
375         goto no_context;
376 diff -NurpP --minimal linux-2.6.32.6/arch/m32r/kernel/traps.c linux-2.6.32.6-vs2.3.0.36.28/arch/m32r/kernel/traps.c
377 --- linux-2.6.32.6/arch/m32r/kernel/traps.c     2009-12-03 20:01:57.000000000 +0100
378 +++ linux-2.6.32.6-vs2.3.0.36.28/arch/m32r/kernel/traps.c       2009-12-03 20:04:56.000000000 +0100
379 @@ -196,8 +196,9 @@ static void show_registers(struct pt_reg
380         } else {
381                 printk("SPI: %08lx\n", sp);
382         }
383 -       printk("Process %s (pid: %d, process nr: %d, stackpage=%08lx)",
384 -               current->comm, task_pid_nr(current), 0xffff & i, 4096+(unsigned long)current);
385 +       printk("Process %s (pid: %d[#%u], process nr: %d, stackpage=%08lx)",
386 +               current->comm, task_pid_nr(current), current->xid,
387 +               0xffff & i, 4096+(unsigned long)current);
388  
389         /*
390          * When in-kernel, we also print out the stack and code at the
391 diff -NurpP --minimal linux-2.6.32.6/arch/m32r/mm/fault.c linux-2.6.32.6-vs2.3.0.36.28/arch/m32r/mm/fault.c
392 --- linux-2.6.32.6/arch/m32r/mm/fault.c 2009-09-10 15:25:23.000000000 +0200
393 +++ linux-2.6.32.6-vs2.3.0.36.28/arch/m32r/mm/fault.c   2009-12-03 20:04:56.000000000 +0100
394 @@ -276,7 +276,8 @@ out_of_memory:
395                 down_read(&mm->mmap_sem);
396                 goto survive;
397         }
398 -       printk("VM: killing process %s\n", tsk->comm);
399 +       printk("VM: killing process %s(%d:#%u)\n",
400 +               tsk->comm, task_pid_nr(tsk), tsk->xid);
401         if (error_code & ACE_USERMODE)
402                 do_group_exit(SIGKILL);
403         goto no_context;
404 diff -NurpP --minimal linux-2.6.32.6/arch/m68k/Kconfig linux-2.6.32.6-vs2.3.0.36.28/arch/m68k/Kconfig
405 --- linux-2.6.32.6/arch/m68k/Kconfig    2009-12-03 20:01:57.000000000 +0100
406 +++ linux-2.6.32.6-vs2.3.0.36.28/arch/m68k/Kconfig      2009-12-03 20:04:56.000000000 +0100
407 @@ -622,6 +622,8 @@ source "fs/Kconfig"
408  
409  source "arch/m68k/Kconfig.debug"
410  
411 +source "kernel/vserver/Kconfig"
412 +
413  source "security/Kconfig"
414  
415  source "crypto/Kconfig"
416 diff -NurpP --minimal linux-2.6.32.6/arch/m68k/kernel/ptrace.c linux-2.6.32.6-vs2.3.0.36.28/arch/m68k/kernel/ptrace.c
417 --- linux-2.6.32.6/arch/m68k/kernel/ptrace.c    2008-12-25 00:26:37.000000000 +0100
418 +++ linux-2.6.32.6-vs2.3.0.36.28/arch/m68k/kernel/ptrace.c      2009-12-03 20:04:56.000000000 +0100
419 @@ -18,6 +18,7 @@
420  #include <linux/ptrace.h>
421  #include <linux/user.h>
422  #include <linux/signal.h>
423 +#include <linux/vs_base.h>
424  
425  #include <asm/uaccess.h>
426  #include <asm/page.h>
427 @@ -269,6 +270,8 @@ long arch_ptrace(struct task_struct *chi
428                 ret = ptrace_request(child, request, addr, data);
429                 break;
430         }
431 +       if (!vx_check(vx_task_xid(child), VS_WATCH_P | VS_IDENT))
432 +               goto out_tsk;
433  
434         return ret;
435  out_eio:
436 diff -NurpP --minimal linux-2.6.32.6/arch/m68k/kernel/traps.c linux-2.6.32.6-vs2.3.0.36.28/arch/m68k/kernel/traps.c
437 --- linux-2.6.32.6/arch/m68k/kernel/traps.c     2009-09-10 15:25:23.000000000 +0200
438 +++ linux-2.6.32.6-vs2.3.0.36.28/arch/m68k/kernel/traps.c       2009-12-03 20:04:56.000000000 +0100
439 @@ -906,8 +906,8 @@ void show_registers(struct pt_regs *regs
440         printk("d4: %08lx    d5: %08lx    a0: %08lx    a1: %08lx\n",
441                regs->d4, regs->d5, regs->a0, regs->a1);
442  
443 -       printk("Process %s (pid: %d, task=%p)\n",
444 -               current->comm, task_pid_nr(current), current);
445 +       printk("Process %s (pid: %d[#%u], task=%p)\n",
446 +               current->comm, task_pid_nr(current), current->xid, current);
447         addr = (unsigned long)&fp->un;
448         printk("Frame format=%X ", regs->format);
449         switch (regs->format) {
450 diff -NurpP --minimal linux-2.6.32.6/arch/m68k/mm/fault.c linux-2.6.32.6-vs2.3.0.36.28/arch/m68k/mm/fault.c
451 --- linux-2.6.32.6/arch/m68k/mm/fault.c 2009-09-10 15:25:23.000000000 +0200
452 +++ linux-2.6.32.6-vs2.3.0.36.28/arch/m68k/mm/fault.c   2009-12-03 20:04:56.000000000 +0100
453 @@ -186,7 +186,8 @@ out_of_memory:
454                 goto survive;
455         }
456  
457 -       printk("VM: killing process %s\n", current->comm);
458 +       printk("VM: killing process %s(%d:#%u)\n",
459 +               current->comm, task_pid_nr(current), current->xid);
460         if (user_mode(regs))
461                 do_group_exit(SIGKILL);
462  
463 diff -NurpP --minimal linux-2.6.32.6/arch/m68knommu/Kconfig linux-2.6.32.6-vs2.3.0.36.28/arch/m68knommu/Kconfig
464 --- linux-2.6.32.6/arch/m68knommu/Kconfig       2009-12-03 20:01:57.000000000 +0100
465 +++ linux-2.6.32.6-vs2.3.0.36.28/arch/m68knommu/Kconfig 2009-12-03 20:04:56.000000000 +0100
466 @@ -727,6 +727,8 @@ source "fs/Kconfig"
467  
468  source "arch/m68knommu/Kconfig.debug"
469  
470 +source "kernel/vserver/Kconfig"
471 +
472  source "security/Kconfig"
473  
474  source "crypto/Kconfig"
475 diff -NurpP --minimal linux-2.6.32.6/arch/m68knommu/kernel/traps.c linux-2.6.32.6-vs2.3.0.36.28/arch/m68knommu/kernel/traps.c
476 --- linux-2.6.32.6/arch/m68knommu/kernel/traps.c        2009-09-10 15:25:23.000000000 +0200
477 +++ linux-2.6.32.6-vs2.3.0.36.28/arch/m68knommu/kernel/traps.c  2009-12-03 20:04:56.000000000 +0100
478 @@ -78,8 +78,9 @@ void die_if_kernel(char *str, struct pt_
479         printk(KERN_EMERG "d4: %08lx    d5: %08lx    a0: %08lx    a1: %08lx\n",
480                fp->d4, fp->d5, fp->a0, fp->a1);
481  
482 -       printk(KERN_EMERG "Process %s (pid: %d, stackpage=%08lx)\n",
483 -               current->comm, current->pid, PAGE_SIZE+(unsigned long)current);
484 +       printk(KERN_EMERG "Process %s (pid: %d[#%u], stackpage=%08lx)\n",
485 +               current->comm, task_pid_nr(current), current->xid,
486 +               PAGE_SIZE+(unsigned long)current);
487         show_stack(NULL, (unsigned long *)(fp + 1));
488         add_taint(TAINT_DIE);
489         do_exit(SIGSEGV);
490 diff -NurpP --minimal linux-2.6.32.6/arch/microblaze/mm/fault.c linux-2.6.32.6-vs2.3.0.36.28/arch/microblaze/mm/fault.c
491 --- linux-2.6.32.6/arch/microblaze/mm/fault.c   2009-09-10 15:25:24.000000000 +0200
492 +++ linux-2.6.32.6-vs2.3.0.36.28/arch/microblaze/mm/fault.c     2009-12-03 20:04:56.000000000 +0100
493 @@ -279,7 +279,8 @@ out_of_memory:
494                 goto survive;
495         }
496         up_read(&mm->mmap_sem);
497 -       printk(KERN_WARNING "VM: killing process %s\n", current->comm);
498 +       printk(KERN_WARNING "VM: killing process %s(%d:#%u)\n",
499 +               current->comm, task_pid_nr(current), current->xid);
500         if (user_mode(regs))
501                 do_exit(SIGKILL);
502         bad_page_fault(regs, address, SIGKILL);
503 diff -NurpP --minimal linux-2.6.32.6/arch/mips/Kconfig linux-2.6.32.6-vs2.3.0.36.28/arch/mips/Kconfig
504 --- linux-2.6.32.6/arch/mips/Kconfig    2009-12-03 20:01:58.000000000 +0100
505 +++ linux-2.6.32.6-vs2.3.0.36.28/arch/mips/Kconfig      2009-12-03 20:04:56.000000000 +0100
506 @@ -2188,6 +2188,8 @@ source "fs/Kconfig"
507  
508  source "arch/mips/Kconfig.debug"
509  
510 +source "kernel/vserver/Kconfig"
511 +
512  source "security/Kconfig"
513  
514  source "crypto/Kconfig"
515 diff -NurpP --minimal linux-2.6.32.6/arch/mips/kernel/ptrace.c linux-2.6.32.6-vs2.3.0.36.28/arch/mips/kernel/ptrace.c
516 --- linux-2.6.32.6/arch/mips/kernel/ptrace.c    2008-12-25 00:26:37.000000000 +0100
517 +++ linux-2.6.32.6-vs2.3.0.36.28/arch/mips/kernel/ptrace.c      2009-12-03 20:04:56.000000000 +0100
518 @@ -25,6 +25,7 @@
519  #include <linux/security.h>
520  #include <linux/audit.h>
521  #include <linux/seccomp.h>
522 +#include <linux/vs_base.h>
523  
524  #include <asm/byteorder.h>
525  #include <asm/cpu.h>
526 @@ -259,6 +260,9 @@ long arch_ptrace(struct task_struct *chi
527  {
528         int ret;
529  
530 +       if (!vx_check(vx_task_xid(child), VS_WATCH_P | VS_IDENT))
531 +               goto out;
532 +
533         switch (request) {
534         /* when I and D space are separate, these will need to be fixed. */
535         case PTRACE_PEEKTEXT: /* read word at location addr. */
536 diff -NurpP --minimal linux-2.6.32.6/arch/mips/kernel/scall32-o32.S linux-2.6.32.6-vs2.3.0.36.28/arch/mips/kernel/scall32-o32.S
537 --- linux-2.6.32.6/arch/mips/kernel/scall32-o32.S       2009-12-03 20:01:59.000000000 +0100
538 +++ linux-2.6.32.6-vs2.3.0.36.28/arch/mips/kernel/scall32-o32.S 2009-12-03 20:04:56.000000000 +0100
539 @@ -525,7 +525,7 @@ einval:     li      v0, -ENOSYS
540         sys     sys_mq_timedreceive     5
541         sys     sys_mq_notify           2       /* 4275 */
542         sys     sys_mq_getsetattr       3
543 -       sys     sys_ni_syscall          0       /* sys_vserver */
544 +       sys     sys_vserver             3
545         sys     sys_waitid              5
546         sys     sys_ni_syscall          0       /* available, was setaltroot */
547         sys     sys_add_key             5       /* 4280 */
548 diff -NurpP --minimal linux-2.6.32.6/arch/mips/kernel/scall64-64.S linux-2.6.32.6-vs2.3.0.36.28/arch/mips/kernel/scall64-64.S
549 --- linux-2.6.32.6/arch/mips/kernel/scall64-64.S        2009-12-03 20:01:59.000000000 +0100
550 +++ linux-2.6.32.6-vs2.3.0.36.28/arch/mips/kernel/scall64-64.S  2009-12-03 20:04:56.000000000 +0100
551 @@ -362,7 +362,7 @@ sys_call_table:
552         PTR     sys_mq_timedreceive
553         PTR     sys_mq_notify
554         PTR     sys_mq_getsetattr               /* 5235 */
555 -       PTR     sys_ni_syscall                  /* sys_vserver */
556 +       PTR     sys_vserver
557         PTR     sys_waitid
558         PTR     sys_ni_syscall                  /* available, was setaltroot */
559         PTR     sys_add_key
560 diff -NurpP --minimal linux-2.6.32.6/arch/mips/kernel/scall64-n32.S linux-2.6.32.6-vs2.3.0.36.28/arch/mips/kernel/scall64-n32.S
561 --- linux-2.6.32.6/arch/mips/kernel/scall64-n32.S       2009-12-03 20:01:59.000000000 +0100
562 +++ linux-2.6.32.6-vs2.3.0.36.28/arch/mips/kernel/scall64-n32.S 2009-12-03 20:04:56.000000000 +0100
563 @@ -360,7 +360,7 @@ EXPORT(sysn32_call_table)
564         PTR     compat_sys_mq_timedreceive
565         PTR     compat_sys_mq_notify
566         PTR     compat_sys_mq_getsetattr
567 -       PTR     sys_ni_syscall                  /* 6240, sys_vserver */
568 +       PTR     sys32_vserver                   /* 6240 */
569         PTR     compat_sys_waitid
570         PTR     sys_ni_syscall                  /* available, was setaltroot */
571         PTR     sys_add_key
572 diff -NurpP --minimal linux-2.6.32.6/arch/mips/kernel/scall64-o32.S linux-2.6.32.6-vs2.3.0.36.28/arch/mips/kernel/scall64-o32.S
573 --- linux-2.6.32.6/arch/mips/kernel/scall64-o32.S       2009-12-03 20:01:59.000000000 +0100
574 +++ linux-2.6.32.6-vs2.3.0.36.28/arch/mips/kernel/scall64-o32.S 2009-12-03 20:04:56.000000000 +0100
575 @@ -480,7 +480,7 @@ sys_call_table:
576         PTR     compat_sys_mq_timedreceive
577         PTR     compat_sys_mq_notify            /* 4275 */
578         PTR     compat_sys_mq_getsetattr
579 -       PTR     sys_ni_syscall                  /* sys_vserver */
580 +       PTR     sys32_vserver
581         PTR     sys_32_waitid
582         PTR     sys_ni_syscall                  /* available, was setaltroot */
583         PTR     sys_add_key                     /* 4280 */
584 diff -NurpP --minimal linux-2.6.32.6/arch/mips/kernel/traps.c linux-2.6.32.6-vs2.3.0.36.28/arch/mips/kernel/traps.c
585 --- linux-2.6.32.6/arch/mips/kernel/traps.c     2009-12-03 20:01:59.000000000 +0100
586 +++ linux-2.6.32.6-vs2.3.0.36.28/arch/mips/kernel/traps.c       2009-12-03 20:04:56.000000000 +0100
587 @@ -335,9 +335,10 @@ void show_registers(const struct pt_regs
588  
589         __show_regs(regs);
590         print_modules();
591 -       printk("Process %s (pid: %d, threadinfo=%p, task=%p, tls=%0*lx)\n",
592 -              current->comm, current->pid, current_thread_info(), current,
593 -             field, current_thread_info()->tp_value);
594 +       printk("Process %s (pid: %d:#%u, threadinfo=%p, task=%p, tls=%0*lx)\n",
595 +               current->comm, task_pid_nr(current), current->xid,
596 +               current_thread_info(), current,
597 +               field, current_thread_info()->tp_value);
598         if (cpu_has_userlocal) {
599                 unsigned long tls;
600  
601 diff -NurpP --minimal linux-2.6.32.6/arch/mn10300/mm/fault.c linux-2.6.32.6-vs2.3.0.36.28/arch/mn10300/mm/fault.c
602 --- linux-2.6.32.6/arch/mn10300/mm/fault.c      2009-09-10 15:25:39.000000000 +0200
603 +++ linux-2.6.32.6-vs2.3.0.36.28/arch/mn10300/mm/fault.c        2009-12-03 20:04:56.000000000 +0100
604 @@ -339,7 +339,8 @@ no_context:
605  out_of_memory:
606         up_read(&mm->mmap_sem);
607         monitor_signal(regs);
608 -       printk(KERN_ALERT "VM: killing process %s\n", tsk->comm);
609 +       printk(KERN_ALERT "VM: killing process %s(%d:#%u)\n",
610 +               tsk->comm, task_pid_nr(tsk), tsk->xid);
611         if ((fault_code & MMUFCR_xFC_ACCESS) == MMUFCR_xFC_ACCESS_USR)
612                 do_exit(SIGKILL);
613         goto no_context;
614 diff -NurpP --minimal linux-2.6.32.6/arch/parisc/Kconfig linux-2.6.32.6-vs2.3.0.36.28/arch/parisc/Kconfig
615 --- linux-2.6.32.6/arch/parisc/Kconfig  2009-12-03 20:02:00.000000000 +0100
616 +++ linux-2.6.32.6-vs2.3.0.36.28/arch/parisc/Kconfig    2009-12-03 20:04:56.000000000 +0100
617 @@ -294,6 +294,8 @@ source "fs/Kconfig"
618  
619  source "arch/parisc/Kconfig.debug"
620  
621 +source "kernel/vserver/Kconfig"
622 +
623  source "security/Kconfig"
624  
625  source "crypto/Kconfig"
626 diff -NurpP --minimal linux-2.6.32.6/arch/parisc/kernel/syscall_table.S linux-2.6.32.6-vs2.3.0.36.28/arch/parisc/kernel/syscall_table.S
627 --- linux-2.6.32.6/arch/parisc/kernel/syscall_table.S   2009-12-03 20:02:00.000000000 +0100
628 +++ linux-2.6.32.6-vs2.3.0.36.28/arch/parisc/kernel/syscall_table.S     2009-12-03 20:04:56.000000000 +0100
629 @@ -361,7 +361,7 @@
630         ENTRY_COMP(mbind)               /* 260 */
631         ENTRY_COMP(get_mempolicy)
632         ENTRY_COMP(set_mempolicy)
633 -       ENTRY_SAME(ni_syscall)  /* 263: reserved for vserver */
634 +       ENTRY_DIFF(vserver)
635         ENTRY_SAME(add_key)
636         ENTRY_SAME(request_key)         /* 265 */
637         ENTRY_SAME(keyctl)
638 diff -NurpP --minimal linux-2.6.32.6/arch/parisc/kernel/traps.c linux-2.6.32.6-vs2.3.0.36.28/arch/parisc/kernel/traps.c
639 --- linux-2.6.32.6/arch/parisc/kernel/traps.c   2009-09-10 15:25:40.000000000 +0200
640 +++ linux-2.6.32.6-vs2.3.0.36.28/arch/parisc/kernel/traps.c     2009-12-03 20:04:56.000000000 +0100
641 @@ -236,8 +236,9 @@ void die_if_kernel(char *str, struct pt_
642                 if (err == 0)
643                         return; /* STFU */
644  
645 -               printk(KERN_CRIT "%s (pid %d): %s (code %ld) at " RFMT "\n",
646 -                       current->comm, task_pid_nr(current), str, err, regs->iaoq[0]);
647 +               printk(KERN_CRIT "%s (pid %d:#%u): %s (code %ld) at " RFMT "\n",
648 +                       current->comm, task_pid_nr(current), current->xid,
649 +                       str, err, regs->iaoq[0]);
650  #ifdef PRINT_USER_FAULTS
651                 /* XXX for debugging only */
652                 show_regs(regs);
653 @@ -270,8 +271,8 @@ void die_if_kernel(char *str, struct pt_
654                 pdc_console_restart();
655         
656         if (err)
657 -               printk(KERN_CRIT "%s (pid %d): %s (code %ld)\n",
658 -                       current->comm, task_pid_nr(current), str, err);
659 +               printk(KERN_CRIT "%s (pid %d:#%u): %s (code %ld)\n",
660 +                       current->comm, task_pid_nr(current), current->xid, str, err);
661  
662         /* Wot's wrong wif bein' racy? */
663         if (current->thread.flags & PARISC_KERNEL_DEATH) {
664 diff -NurpP --minimal linux-2.6.32.6/arch/parisc/mm/fault.c linux-2.6.32.6-vs2.3.0.36.28/arch/parisc/mm/fault.c
665 --- linux-2.6.32.6/arch/parisc/mm/fault.c       2009-09-10 15:25:40.000000000 +0200
666 +++ linux-2.6.32.6-vs2.3.0.36.28/arch/parisc/mm/fault.c 2009-12-03 20:04:56.000000000 +0100
667 @@ -237,8 +237,9 @@ bad_area:
668  
669  #ifdef PRINT_USER_FAULTS
670                 printk(KERN_DEBUG "\n");
671 -               printk(KERN_DEBUG "do_page_fault() pid=%d command='%s' type=%lu address=0x%08lx\n",
672 -                   task_pid_nr(tsk), tsk->comm, code, address);
673 +               printk(KERN_DEBUG "do_page_fault() pid=%d:#%u "
674 +                   "command='%s' type=%lu address=0x%08lx\n",
675 +                   task_pid_nr(tsk), tsk->xid, tsk->comm, code, address);
676                 if (vma) {
677                         printk(KERN_DEBUG "vm_start = 0x%08lx, vm_end = 0x%08lx\n",
678                                         vma->vm_start, vma->vm_end);
679 @@ -264,7 +265,8 @@ no_context:
680  
681    out_of_memory:
682         up_read(&mm->mmap_sem);
683 -       printk(KERN_CRIT "VM: killing process %s\n", current->comm);
684 +       printk(KERN_CRIT "VM: killing process %s(%d:#%u)\n",
685 +               current->comm, current->pid, current->xid);
686         if (user_mode(regs))
687                 do_group_exit(SIGKILL);
688         goto no_context;
689 diff -NurpP --minimal linux-2.6.32.6/arch/powerpc/include/asm/unistd.h linux-2.6.32.6-vs2.3.0.36.28/arch/powerpc/include/asm/unistd.h
690 --- linux-2.6.32.6/arch/powerpc/include/asm/unistd.h    2009-12-03 20:02:01.000000000 +0100
691 +++ linux-2.6.32.6-vs2.3.0.36.28/arch/powerpc/include/asm/unistd.h      2009-12-03 20:04:56.000000000 +0100
692 @@ -275,7 +275,7 @@
693  #endif
694  #define __NR_rtas              255
695  #define __NR_sys_debug_setcontext 256
696 -/* Number 257 is reserved for vserver */
697 +#define __NR_vserver           257
698  #define __NR_migrate_pages     258
699  #define __NR_mbind             259
700  #define __NR_get_mempolicy     260
701 diff -NurpP --minimal linux-2.6.32.6/arch/powerpc/Kconfig linux-2.6.32.6-vs2.3.0.36.28/arch/powerpc/Kconfig
702 --- linux-2.6.32.6/arch/powerpc/Kconfig 2009-12-03 20:02:00.000000000 +0100
703 +++ linux-2.6.32.6-vs2.3.0.36.28/arch/powerpc/Kconfig   2009-12-03 20:04:56.000000000 +0100
704 @@ -943,6 +943,8 @@ source "lib/Kconfig"
705  
706  source "arch/powerpc/Kconfig.debug"
707  
708 +source "kernel/vserver/Kconfig"
709 +
710  source "security/Kconfig"
711  
712  config KEYS_COMPAT
713 diff -NurpP --minimal linux-2.6.32.6/arch/powerpc/kernel/irq.c linux-2.6.32.6-vs2.3.0.36.28/arch/powerpc/kernel/irq.c
714 --- linux-2.6.32.6/arch/powerpc/kernel/irq.c    2009-12-03 20:02:01.000000000 +0100
715 +++ linux-2.6.32.6-vs2.3.0.36.28/arch/powerpc/kernel/irq.c      2009-12-03 20:04:56.000000000 +0100
716 @@ -54,6 +54,7 @@
717  #include <linux/pci.h>
718  #include <linux/debugfs.h>
719  #include <linux/perf_event.h>
720 +// #include <linux/vs_context.h>
721  
722  #include <asm/uaccess.h>
723  #include <asm/system.h>
724 diff -NurpP --minimal linux-2.6.32.6/arch/powerpc/kernel/process.c linux-2.6.32.6-vs2.3.0.36.28/arch/powerpc/kernel/process.c
725 --- linux-2.6.32.6/arch/powerpc/kernel/process.c        2009-12-03 20:02:02.000000000 +0100
726 +++ linux-2.6.32.6-vs2.3.0.36.28/arch/powerpc/kernel/process.c  2009-12-03 20:04:56.000000000 +0100
727 @@ -519,8 +519,9 @@ void show_regs(struct pt_regs * regs)
728  #else
729                 printk("DAR: "REG", DSISR: "REG"\n", regs->dar, regs->dsisr);
730  #endif
731 -       printk("TASK = %p[%d] '%s' THREAD: %p",
732 -              current, task_pid_nr(current), current->comm, task_thread_info(current));
733 +       printk("TASK = %p[%d,#%u] '%s' THREAD: %p",
734 +              current, task_pid_nr(current), current->xid,
735 +              current->comm, task_thread_info(current));
736  
737  #ifdef CONFIG_SMP
738         printk(" CPU: %d", raw_smp_processor_id());
739 diff -NurpP --minimal linux-2.6.32.6/arch/powerpc/kernel/traps.c linux-2.6.32.6-vs2.3.0.36.28/arch/powerpc/kernel/traps.c
740 --- linux-2.6.32.6/arch/powerpc/kernel/traps.c  2009-09-10 15:25:41.000000000 +0200
741 +++ linux-2.6.32.6-vs2.3.0.36.28/arch/powerpc/kernel/traps.c    2009-12-03 20:04:56.000000000 +0100
742 @@ -931,8 +931,9 @@ void nonrecoverable_exception(struct pt_
743  
744  void trace_syscall(struct pt_regs *regs)
745  {
746 -       printk("Task: %p(%d), PC: %08lX/%08lX, Syscall: %3ld, Result: %s%ld    %s\n",
747 -              current, task_pid_nr(current), regs->nip, regs->link, regs->gpr[0],
748 +       printk("Task: %p(%d[#%u]), PC: %08lX/%08lX, Syscall: %3ld, Result: %s%ld    %s\n",
749 +              current, task_pid_nr(current), current->xid,
750 +              regs->nip, regs->link, regs->gpr[0],
751                regs->ccr&0x10000000?"Error=":"", regs->gpr[3], print_tainted());
752  }
753  
754 diff -NurpP --minimal linux-2.6.32.6/arch/powerpc/kernel/vdso.c linux-2.6.32.6-vs2.3.0.36.28/arch/powerpc/kernel/vdso.c
755 --- linux-2.6.32.6/arch/powerpc/kernel/vdso.c   2009-12-03 20:02:02.000000000 +0100
756 +++ linux-2.6.32.6-vs2.3.0.36.28/arch/powerpc/kernel/vdso.c     2009-12-03 20:04:56.000000000 +0100
757 @@ -23,6 +23,7 @@
758  #include <linux/security.h>
759  #include <linux/bootmem.h>
760  #include <linux/lmb.h>
761 +#include <linux/vs_memory.h>
762  
763  #include <asm/pgtable.h>
764  #include <asm/system.h>
765 diff -NurpP --minimal linux-2.6.32.6/arch/powerpc/mm/fault.c linux-2.6.32.6-vs2.3.0.36.28/arch/powerpc/mm/fault.c
766 --- linux-2.6.32.6/arch/powerpc/mm/fault.c      2009-12-03 20:02:02.000000000 +0100
767 +++ linux-2.6.32.6-vs2.3.0.36.28/arch/powerpc/mm/fault.c        2009-12-03 20:04:56.000000000 +0100
768 @@ -358,7 +358,8 @@ out_of_memory:
769                 down_read(&mm->mmap_sem);
770                 goto survive;
771         }
772 -       printk("VM: killing process %s\n", current->comm);
773 +       printk("VM: killing process %s(%d:#%u)\n",
774 +               current->comm, current->pid, current->xid);
775         if (user_mode(regs))
776                 do_group_exit(SIGKILL);
777         return SIGKILL;
778 diff -NurpP --minimal linux-2.6.32.6/arch/s390/include/asm/tlb.h linux-2.6.32.6-vs2.3.0.36.28/arch/s390/include/asm/tlb.h
779 --- linux-2.6.32.6/arch/s390/include/asm/tlb.h  2009-09-10 15:25:43.000000000 +0200
780 +++ linux-2.6.32.6-vs2.3.0.36.28/arch/s390/include/asm/tlb.h    2009-12-31 14:37:21.000000000 +0100
781 @@ -23,6 +23,8 @@
782  
783  #include <linux/mm.h>
784  #include <linux/swap.h>
785 +#include <linux/vs_memory.h>
786 +
787  #include <asm/processor.h>
788  #include <asm/pgalloc.h>
789  #include <asm/smp.h>
790 diff -NurpP --minimal linux-2.6.32.6/arch/s390/include/asm/unistd.h linux-2.6.32.6-vs2.3.0.36.28/arch/s390/include/asm/unistd.h
791 --- linux-2.6.32.6/arch/s390/include/asm/unistd.h       2009-12-03 20:02:03.000000000 +0100
792 +++ linux-2.6.32.6-vs2.3.0.36.28/arch/s390/include/asm/unistd.h 2009-12-30 00:58:47.000000000 +0100
793 @@ -202,7 +202,7 @@
794  #define __NR_clock_gettime     (__NR_timer_create+6)
795  #define __NR_clock_getres      (__NR_timer_create+7)
796  #define __NR_clock_nanosleep   (__NR_timer_create+8)
797 -/* Number 263 is reserved for vserver */
798 +#define __NR_vserver           263
799  #define __NR_statfs64          265
800  #define __NR_fstatfs64         266
801  #define __NR_remap_file_pages  267
802 diff -NurpP --minimal linux-2.6.32.6/arch/s390/Kconfig linux-2.6.32.6-vs2.3.0.36.28/arch/s390/Kconfig
803 --- linux-2.6.32.6/arch/s390/Kconfig    2009-12-03 20:02:03.000000000 +0100
804 +++ linux-2.6.32.6-vs2.3.0.36.28/arch/s390/Kconfig      2009-12-03 20:04:56.000000000 +0100
805 @@ -616,6 +616,8 @@ source "fs/Kconfig"
806  
807  source "arch/s390/Kconfig.debug"
808  
809 +source "kernel/vserver/Kconfig"
810 +
811  source "security/Kconfig"
812  
813  source "crypto/Kconfig"
814 diff -NurpP --minimal linux-2.6.32.6/arch/s390/kernel/ptrace.c linux-2.6.32.6-vs2.3.0.36.28/arch/s390/kernel/ptrace.c
815 --- linux-2.6.32.6/arch/s390/kernel/ptrace.c    2009-12-03 20:02:03.000000000 +0100
816 +++ linux-2.6.32.6-vs2.3.0.36.28/arch/s390/kernel/ptrace.c      2009-12-03 20:04:56.000000000 +0100
817 @@ -36,6 +36,7 @@
818  #include <linux/regset.h>
819  #include <linux/tracehook.h>
820  #include <linux/seccomp.h>
821 +#include <linux/vs_base.h>
822  #include <trace/syscall.h>
823  #include <asm/compat.h>
824  #include <asm/segment.h>
825 diff -NurpP --minimal linux-2.6.32.6/arch/s390/kernel/syscalls.S linux-2.6.32.6-vs2.3.0.36.28/arch/s390/kernel/syscalls.S
826 --- linux-2.6.32.6/arch/s390/kernel/syscalls.S  2009-12-03 20:02:03.000000000 +0100
827 +++ linux-2.6.32.6-vs2.3.0.36.28/arch/s390/kernel/syscalls.S    2009-12-03 20:04:56.000000000 +0100
828 @@ -271,7 +271,7 @@ SYSCALL(sys_clock_settime,sys_clock_sett
829  SYSCALL(sys_clock_gettime,sys_clock_gettime,sys32_clock_gettime_wrapper)       /* 260 */
830  SYSCALL(sys_clock_getres,sys_clock_getres,sys32_clock_getres_wrapper)
831  SYSCALL(sys_clock_nanosleep,sys_clock_nanosleep,sys32_clock_nanosleep_wrapper)
832 -NI_SYSCALL                                                     /* reserved for vserver */
833 +SYSCALL(sys_vserver,sys_vserver,sys32_vserver)
834  SYSCALL(sys_s390_fadvise64_64,sys_ni_syscall,sys32_fadvise64_64_wrapper)
835  SYSCALL(sys_statfs64,sys_statfs64,compat_sys_statfs64_wrapper)
836  SYSCALL(sys_fstatfs64,sys_fstatfs64,compat_sys_fstatfs64_wrapper)
837 diff -NurpP --minimal linux-2.6.32.6/arch/s390/lib/uaccess_pt.c linux-2.6.32.6-vs2.3.0.36.28/arch/s390/lib/uaccess_pt.c
838 --- linux-2.6.32.6/arch/s390/lib/uaccess_pt.c   2009-09-10 15:25:43.000000000 +0200
839 +++ linux-2.6.32.6-vs2.3.0.36.28/arch/s390/lib/uaccess_pt.c     2009-12-03 20:04:56.000000000 +0100
840 @@ -90,7 +90,8 @@ out_of_memory:
841                 down_read(&mm->mmap_sem);
842                 goto survive;
843         }
844 -       printk("VM: killing process %s\n", current->comm);
845 +       printk("VM: killing process %s(%d:#%u)\n",
846 +               current->comm, task_pid_nr(current), current->xid);
847         return ret;
848  
849  out_sigbus:
850 diff -NurpP --minimal linux-2.6.32.6/arch/sh/Kconfig linux-2.6.32.6-vs2.3.0.36.28/arch/sh/Kconfig
851 --- linux-2.6.32.6/arch/sh/Kconfig      2009-12-03 20:02:03.000000000 +0100
852 +++ linux-2.6.32.6-vs2.3.0.36.28/arch/sh/Kconfig        2009-12-03 20:04:56.000000000 +0100
853 @@ -853,6 +853,8 @@ source "fs/Kconfig"
854  
855  source "arch/sh/Kconfig.debug"
856  
857 +source "kernel/vserver/Kconfig"
858 +
859  source "security/Kconfig"
860  
861  source "crypto/Kconfig"
862 diff -NurpP --minimal linux-2.6.32.6/arch/sh/kernel/irq.c linux-2.6.32.6-vs2.3.0.36.28/arch/sh/kernel/irq.c
863 --- linux-2.6.32.6/arch/sh/kernel/irq.c 2009-12-03 20:02:10.000000000 +0100
864 +++ linux-2.6.32.6-vs2.3.0.36.28/arch/sh/kernel/irq.c   2009-12-03 20:04:56.000000000 +0100
865 @@ -12,6 +12,7 @@
866  #include <linux/kernel_stat.h>
867  #include <linux/seq_file.h>
868  #include <linux/ftrace.h>
869 +// #include <linux/vs_context.h>
870  #include <asm/processor.h>
871  #include <asm/machvec.h>
872  #include <asm/uaccess.h>
873 diff -NurpP --minimal linux-2.6.32.6/arch/sh/kernel/vsyscall/vsyscall.c linux-2.6.32.6-vs2.3.0.36.28/arch/sh/kernel/vsyscall/vsyscall.c
874 --- linux-2.6.32.6/arch/sh/kernel/vsyscall/vsyscall.c   2009-03-24 14:18:42.000000000 +0100
875 +++ linux-2.6.32.6-vs2.3.0.36.28/arch/sh/kernel/vsyscall/vsyscall.c     2009-12-03 20:04:56.000000000 +0100
876 @@ -19,6 +19,7 @@
877  #include <linux/elf.h>
878  #include <linux/sched.h>
879  #include <linux/err.h>
880 +#include <linux/vs_memory.h>
881  
882  /*
883   * Should the kernel map a VDSO page into processes and pass its
884 diff -NurpP --minimal linux-2.6.32.6/arch/sh/mm/fault_32.c linux-2.6.32.6-vs2.3.0.36.28/arch/sh/mm/fault_32.c
885 --- linux-2.6.32.6/arch/sh/mm/fault_32.c        2009-12-03 20:02:14.000000000 +0100
886 +++ linux-2.6.32.6-vs2.3.0.36.28/arch/sh/mm/fault_32.c  2009-12-03 20:04:56.000000000 +0100
887 @@ -292,7 +292,8 @@ out_of_memory:
888                 down_read(&mm->mmap_sem);
889                 goto survive;
890         }
891 -       printk("VM: killing process %s\n", tsk->comm);
892 +       printk("VM: killing process %s(%d:#%u)\n",
893 +               tsk->comm, task_pid_nr(tsk), tsk->xid);
894         if (user_mode(regs))
895                 do_group_exit(SIGKILL);
896         goto no_context;
897 diff -NurpP --minimal linux-2.6.32.6/arch/sh/mm/tlbflush_64.c linux-2.6.32.6-vs2.3.0.36.28/arch/sh/mm/tlbflush_64.c
898 --- linux-2.6.32.6/arch/sh/mm/tlbflush_64.c     2009-12-03 20:02:14.000000000 +0100
899 +++ linux-2.6.32.6-vs2.3.0.36.28/arch/sh/mm/tlbflush_64.c       2009-12-03 20:04:56.000000000 +0100
900 @@ -306,7 +306,8 @@ out_of_memory:
901                 down_read(&mm->mmap_sem);
902                 goto survive;
903         }
904 -       printk("VM: killing process %s\n", tsk->comm);
905 +       printk("VM: killing process %s(%d:#%u)\n",
906 +               tsk->comm, task_pid_nr(tsk), tsk->xid);
907         if (user_mode(regs))
908                 do_group_exit(SIGKILL);
909         goto no_context;
910 diff -NurpP --minimal linux-2.6.32.6/arch/sparc/include/asm/tlb_64.h linux-2.6.32.6-vs2.3.0.36.28/arch/sparc/include/asm/tlb_64.h
911 --- linux-2.6.32.6/arch/sparc/include/asm/tlb_64.h      2009-09-10 15:25:45.000000000 +0200
912 +++ linux-2.6.32.6-vs2.3.0.36.28/arch/sparc/include/asm/tlb_64.h        2009-12-03 20:04:56.000000000 +0100
913 @@ -3,6 +3,7 @@
914  
915  #include <linux/swap.h>
916  #include <linux/pagemap.h>
917 +#include <linux/vs_memory.h>
918  #include <asm/pgalloc.h>
919  #include <asm/tlbflush.h>
920  #include <asm/mmu_context.h>
921 diff -NurpP --minimal linux-2.6.32.6/arch/sparc/include/asm/unistd.h linux-2.6.32.6-vs2.3.0.36.28/arch/sparc/include/asm/unistd.h
922 --- linux-2.6.32.6/arch/sparc/include/asm/unistd.h      2009-12-03 20:02:15.000000000 +0100
923 +++ linux-2.6.32.6-vs2.3.0.36.28/arch/sparc/include/asm/unistd.h        2009-12-03 20:04:56.000000000 +0100
924 @@ -335,7 +335,7 @@
925  #define __NR_timer_getoverrun  264
926  #define __NR_timer_delete      265
927  #define __NR_timer_create      266
928 -/* #define __NR_vserver                267 Reserved for VSERVER */
929 +#define __NR_vserver           267
930  #define __NR_io_setup          268
931  #define __NR_io_destroy                269
932  #define __NR_io_submit         270
933 diff -NurpP --minimal linux-2.6.32.6/arch/sparc/Kconfig linux-2.6.32.6-vs2.3.0.36.28/arch/sparc/Kconfig
934 --- linux-2.6.32.6/arch/sparc/Kconfig   2009-12-03 20:02:14.000000000 +0100
935 +++ linux-2.6.32.6-vs2.3.0.36.28/arch/sparc/Kconfig     2009-12-03 20:04:56.000000000 +0100
936 @@ -550,6 +550,8 @@ source "fs/Kconfig"
937  
938  source "arch/sparc/Kconfig.debug"
939  
940 +source "kernel/vserver/Kconfig"
941 +
942  source "security/Kconfig"
943  
944  source "crypto/Kconfig"
945 diff -NurpP --minimal linux-2.6.32.6/arch/sparc/kernel/systbls_32.S linux-2.6.32.6-vs2.3.0.36.28/arch/sparc/kernel/systbls_32.S
946 --- linux-2.6.32.6/arch/sparc/kernel/systbls_32.S       2010-01-26 19:31:21.000000000 +0100
947 +++ linux-2.6.32.6-vs2.3.0.36.28/arch/sparc/kernel/systbls_32.S 2010-01-20 04:21:33.000000000 +0100
948 @@ -70,7 +70,7 @@ sys_call_table:
949  /*250*/        .long sys_mremap, sys_sysctl, sys_getsid, sys_fdatasync, sys_nfsservctl
950  /*255*/        .long sys_sync_file_range, sys_clock_settime, sys_clock_gettime, sys_clock_getres, sys_clock_nanosleep
951  /*260*/        .long sys_sched_getaffinity, sys_sched_setaffinity, sys_timer_settime, sys_timer_gettime, sys_timer_getoverrun
952 -/*265*/        .long sys_timer_delete, sys_timer_create, sys_nis_syscall, sys_io_setup, sys_io_destroy
953 +/*265*/        .long sys_timer_delete, sys_timer_create, sys_vserver, sys_io_setup, sys_io_destroy
954  /*270*/        .long sys_io_submit, sys_io_cancel, sys_io_getevents, sys_mq_open, sys_mq_unlink
955  /*275*/        .long sys_mq_timedsend, sys_mq_timedreceive, sys_mq_notify, sys_mq_getsetattr, sys_waitid
956  /*280*/        .long sys_tee, sys_add_key, sys_request_key, sys_keyctl, sys_openat
957 diff -NurpP --minimal linux-2.6.32.6/arch/sparc/kernel/systbls_64.S linux-2.6.32.6-vs2.3.0.36.28/arch/sparc/kernel/systbls_64.S
958 --- linux-2.6.32.6/arch/sparc/kernel/systbls_64.S       2010-01-26 19:31:21.000000000 +0100
959 +++ linux-2.6.32.6-vs2.3.0.36.28/arch/sparc/kernel/systbls_64.S 2010-01-20 04:21:33.000000000 +0100
960 @@ -71,7 +71,7 @@ sys_call_table32:
961  /*250*/        .word sys32_mremap, sys32_sysctl, sys32_getsid, sys_fdatasync, sys32_nfsservctl
962         .word sys32_sync_file_range, compat_sys_clock_settime, compat_sys_clock_gettime, compat_sys_clock_getres, sys32_clock_nanosleep
963  /*260*/        .word compat_sys_sched_getaffinity, compat_sys_sched_setaffinity, sys32_timer_settime, compat_sys_timer_gettime, sys_timer_getoverrun
964 -       .word sys_timer_delete, compat_sys_timer_create, sys_ni_syscall, compat_sys_io_setup, sys_io_destroy
965 +       .word sys_timer_delete, compat_sys_timer_create, sys32_vserver, compat_sys_io_setup, sys_io_destroy
966  /*270*/        .word sys32_io_submit, sys_io_cancel, compat_sys_io_getevents, sys32_mq_open, sys_mq_unlink
967         .word compat_sys_mq_timedsend, compat_sys_mq_timedreceive, compat_sys_mq_notify, compat_sys_mq_getsetattr, compat_sys_waitid
968  /*280*/        .word sys32_tee, sys_add_key, sys_request_key, sys_keyctl, compat_sys_openat
969 @@ -146,7 +146,7 @@ sys_call_table:
970  /*250*/        .word sys_64_mremap, sys_sysctl, sys_getsid, sys_fdatasync, sys_nfsservctl
971         .word sys_sync_file_range, sys_clock_settime, sys_clock_gettime, sys_clock_getres, sys_clock_nanosleep
972  /*260*/        .word sys_sched_getaffinity, sys_sched_setaffinity, sys_timer_settime, sys_timer_gettime, sys_timer_getoverrun
973 -       .word sys_timer_delete, sys_timer_create, sys_ni_syscall, sys_io_setup, sys_io_destroy
974 +       .word sys_timer_delete, sys_timer_create, sys_vserver, sys_io_setup, sys_io_destroy
975  /*270*/        .word sys_io_submit, sys_io_cancel, sys_io_getevents, sys_mq_open, sys_mq_unlink
976         .word sys_mq_timedsend, sys_mq_timedreceive, sys_mq_notify, sys_mq_getsetattr, sys_waitid
977  /*280*/        .word sys_tee, sys_add_key, sys_request_key, sys_keyctl, sys_openat
978 diff -NurpP --minimal linux-2.6.32.6/arch/x86/ia32/ia32entry.S linux-2.6.32.6-vs2.3.0.36.28/arch/x86/ia32/ia32entry.S
979 --- linux-2.6.32.6/arch/x86/ia32/ia32entry.S    2010-01-26 19:31:21.000000000 +0100
980 +++ linux-2.6.32.6-vs2.3.0.36.28/arch/x86/ia32/ia32entry.S      2010-01-20 04:21:33.000000000 +0100
981 @@ -777,7 +777,7 @@ ia32_sys_call_table:
982         .quad sys_tgkill                /* 270 */
983         .quad compat_sys_utimes
984         .quad sys32_fadvise64_64
985 -       .quad quiet_ni_syscall  /* sys_vserver */
986 +       .quad sys32_vserver
987         .quad sys_mbind
988         .quad compat_sys_get_mempolicy  /* 275 */
989         .quad sys_set_mempolicy
990 diff -NurpP --minimal linux-2.6.32.6/arch/x86/include/asm/unistd_64.h linux-2.6.32.6-vs2.3.0.36.28/arch/x86/include/asm/unistd_64.h
991 --- linux-2.6.32.6/arch/x86/include/asm/unistd_64.h     2009-12-03 20:02:16.000000000 +0100
992 +++ linux-2.6.32.6-vs2.3.0.36.28/arch/x86/include/asm/unistd_64.h       2009-12-03 20:04:56.000000000 +0100
993 @@ -535,7 +535,7 @@ __SYSCALL(__NR_tgkill, sys_tgkill)
994  #define __NR_utimes                            235
995  __SYSCALL(__NR_utimes, sys_utimes)
996  #define __NR_vserver                           236
997 -__SYSCALL(__NR_vserver, sys_ni_syscall)
998 +__SYSCALL(__NR_vserver, sys_vserver)
999  #define __NR_mbind                             237
1000  __SYSCALL(__NR_mbind, sys_mbind)
1001  #define __NR_set_mempolicy                     238
1002 diff -NurpP --minimal linux-2.6.32.6/arch/x86/Kconfig linux-2.6.32.6-vs2.3.0.36.28/arch/x86/Kconfig
1003 --- linux-2.6.32.6/arch/x86/Kconfig     2009-12-03 20:02:15.000000000 +0100
1004 +++ linux-2.6.32.6-vs2.3.0.36.28/arch/x86/Kconfig       2009-12-03 20:04:56.000000000 +0100
1005 @@ -2085,6 +2085,8 @@ source "fs/Kconfig"
1006  
1007  source "arch/x86/Kconfig.debug"
1008  
1009 +source "kernel/vserver/Kconfig"
1010 +
1011  source "security/Kconfig"
1012  
1013  source "crypto/Kconfig"
1014 diff -NurpP --minimal linux-2.6.32.6/arch/x86/kernel/syscall_table_32.S linux-2.6.32.6-vs2.3.0.36.28/arch/x86/kernel/syscall_table_32.S
1015 --- linux-2.6.32.6/arch/x86/kernel/syscall_table_32.S   2010-01-26 19:31:21.000000000 +0100
1016 +++ linux-2.6.32.6-vs2.3.0.36.28/arch/x86/kernel/syscall_table_32.S     2010-01-20 04:21:33.000000000 +0100
1017 @@ -272,7 +272,7 @@ ENTRY(sys_call_table)
1018         .long sys_tgkill        /* 270 */
1019         .long sys_utimes
1020         .long sys_fadvise64_64
1021 -       .long sys_ni_syscall    /* sys_vserver */
1022 +       .long sys_vserver
1023         .long sys_mbind
1024         .long sys_get_mempolicy
1025         .long sys_set_mempolicy
1026 diff -NurpP --minimal linux-2.6.32.6/arch/xtensa/mm/fault.c linux-2.6.32.6-vs2.3.0.36.28/arch/xtensa/mm/fault.c
1027 --- linux-2.6.32.6/arch/xtensa/mm/fault.c       2009-09-10 15:25:48.000000000 +0200
1028 +++ linux-2.6.32.6-vs2.3.0.36.28/arch/xtensa/mm/fault.c 2009-12-03 20:04:56.000000000 +0100
1029 @@ -151,7 +151,8 @@ out_of_memory:
1030                 down_read(&mm->mmap_sem);
1031                 goto survive;
1032         }
1033 -       printk("VM: killing process %s\n", current->comm);
1034 +       printk("VM: killing process %s(%d:#%u)\n",
1035 +               current->comm, task_pid_nr(current), current->xid);
1036         if (user_mode(regs))
1037                 do_group_exit(SIGKILL);
1038         bad_page_fault(regs, address, SIGKILL);
1039 diff -NurpP --minimal linux-2.6.32.6/Documentation/scheduler/sched-cfs-hard-limits.txt linux-2.6.32.6-vs2.3.0.36.28/Documentation/scheduler/sched-cfs-hard-limits.txt
1040 --- linux-2.6.32.6/Documentation/scheduler/sched-cfs-hard-limits.txt    1970-01-01 01:00:00.000000000 +0100
1041 +++ linux-2.6.32.6-vs2.3.0.36.28/Documentation/scheduler/sched-cfs-hard-limits.txt      2009-12-03 20:04:56.000000000 +0100
1042 @@ -0,0 +1,48 @@
1043 +CPU HARD LIMITS FOR CFS GROUPS
1044 +==============================
1045 +
1046 +1. Overview
1047 +2. Interface
1048 +3. Examples
1049 +
1050 +1. Overview
1051 +-----------
1052 +
1053 +CFS is a proportional share scheduler which tries to divide the CPU time
1054 +proportionately between tasks or groups of tasks (task group/cgroup) depending
1055 +on the priority/weight of the task or shares assigned to groups of tasks.
1056 +In CFS, a task/task group can get more than its share of CPU if there are
1057 +enough idle CPU cycles available in the system, due to the work conserving
1058 +nature of the scheduler. However in certain scenarios (like pay-per-use),
1059 +it is desirable not to provide extra time to a group even in the presence
1060 +of idle CPU cycles. This is where hard limiting can be of use.
1061 +
1062 +Hard limits for task groups can be set by specifying how much CPU runtime a
1063 +group can consume within a given period. If the group consumes more CPU time
1064 +than the runtime in a given period, it gets throttled. None of the tasks of
1065 +the throttled group gets to run until the runtime of the group gets refreshed
1066 +at the beginning of the next period.
1067 +
1068 +2. Interface
1069 +------------
1070 +
1071 +Hard limit feature adds 2 cgroup files for CFS group scheduler:
1072 +
1073 +cfs_runtime_us: Hard limit for the group in microseconds.
1074 +
1075 +cfs_period_us: Time period in microseconds within which hard limits is
1076 +enforced.
1077 +
1078 +A group gets created with default values for runtime (infinite runtime which
1079 +means hard limits disabled) and period (0.5s). Each group can set its own
1080 +values for runtime and period independent of other groups in the system.
1081 +
1082 +3. Examples
1083 +-----------
1084 +
1085 +# mount -t cgroup -ocpu none /cgroups/
1086 +# cd /cgroups
1087 +# mkdir 1
1088 +# cd 1/
1089 +# echo 250000 > cfs_runtime_us /* set a 250ms runtime or limit */
1090 +# echo 500000 > cfs_period_us /* set a 500ms period */
1091 diff -NurpP --minimal linux-2.6.32.6/Documentation/vserver/debug.txt linux-2.6.32.6-vs2.3.0.36.28/Documentation/vserver/debug.txt
1092 --- linux-2.6.32.6/Documentation/vserver/debug.txt      1970-01-01 01:00:00.000000000 +0100
1093 +++ linux-2.6.32.6-vs2.3.0.36.28/Documentation/vserver/debug.txt        2009-12-03 20:04:56.000000000 +0100
1094 @@ -0,0 +1,154 @@
1095 +
1096 +debug_cvirt:
1097 +
1098 + 2   4 "vx_map_tgid: %p/%llx: %d -> %d"
1099 +       "vx_rmap_tgid: %p/%llx: %d -> %d"
1100 +
1101 +debug_dlim:
1102 +
1103 + 0   1 "ALLOC (%p,#%d)%c inode (%d)"
1104 +       "FREE  (%p,#%d)%c inode"
1105 + 1   2 "ALLOC (%p,#%d)%c %lld bytes (%d)"
1106 +       "FREE  (%p,#%d)%c %lld bytes"
1107 + 2   4 "ADJUST: %lld,%lld on %ld,%ld [mult=%d]"
1108 + 3   8 "ext3_has_free_blocks(%p): %lu<%lu+1, %c, %u!=%u r=%d"
1109 +       "ext3_has_free_blocks(%p): free=%lu, root=%lu"
1110 +       "rcu_free_dl_info(%p)"
1111 + 4  10 "alloc_dl_info(%p,%d) = %p"
1112 +       "dealloc_dl_info(%p)"
1113 +       "get_dl_info(%p[#%d.%d])"
1114 +       "put_dl_info(%p[#%d.%d])"
1115 + 5  20 "alloc_dl_info(%p,%d)*"
1116 + 6  40 "__hash_dl_info: %p[#%d]"
1117 +       "__unhash_dl_info: %p[#%d]"
1118 + 7  80 "locate_dl_info(%p,#%d) = %p"
1119 +
1120 +debug_misc:
1121 +
1122 + 0   1 "destroy_dqhash: %p [#0x%08x] c=%d"
1123 +       "new_dqhash: %p [#0x%08x]"
1124 +       "vroot[%d]_clr_dev: dev=%p[%lu,%d:%d]"
1125 +       "vroot[%d]_get_real_bdev: dev=%p[%lu,%d:%d]"
1126 +       "vroot[%d]_set_dev: dev=%p[%lu,%d:%d]"
1127 +       "vroot_get_real_bdev not set"
1128 + 1   2 "cow_break_link(»%s«)"
1129 +       "temp copy Â»%s«"
1130 + 2   4 "dentry_open(new): %p"
1131 +       "dentry_open(old): %p"
1132 +       "lookup_create(new): %p"
1133 +       "old path Â»%s«"
1134 +       "path_lookup(old): %d"
1135 +       "vfs_create(new): %d"
1136 +       "vfs_rename: %d"
1137 +       "vfs_sendfile: %d"
1138 + 3   8 "fput(new_file=%p[#%d])"
1139 +       "fput(old_file=%p[#%d])"
1140 + 4  10 "vx_info_kill(%p[#%d],%d,%d) = %d"
1141 +       "vx_info_kill(%p[#%d],%d,%d)*"
1142 + 5  20 "vs_reboot(%p[#%d],%d)"
1143 + 6  40 "dropping task %p[#%u,%u] for %p[#%u,%u]"
1144 +
1145 +debug_net:
1146 +
1147 + 2   4 "nx_addr_conflict(%p,%p) %d.%d,%d.%d"
1148 + 3   8 "inet_bind(%p) %d.%d.%d.%d, %d.%d.%d.%d, %d.%d.%d.%d"
1149 +       "inet_bind(%p)* %p,%p;%lx %d.%d.%d.%d"
1150 + 4  10 "ip_route_connect(%p) %p,%p;%lx"
1151 + 5  20 "__addr_in_socket(%p,%d.%d.%d.%d) %p:%d.%d.%d.%d %p;%lx"
1152 + 6  40 "sk,egf: %p [#%d] (from %d)"
1153 +       "sk,egn: %p [#%d] (from %d)"
1154 +       "sk,req: %p [#%d] (from %d)"
1155 +       "sk: %p [#%d] (from %d)"
1156 +       "tw: %p [#%d] (from %d)"
1157 + 7  80 "__sock_recvmsg: %p[%p,%p,%p;%d]:%d/%d"
1158 +       "__sock_sendmsg: %p[%p,%p,%p;%d]:%d/%d"
1159 +
1160 +debug_nid:
1161 +
1162 + 0   1 "__lookup_nx_info(#%u): %p[#%u]"
1163 +       "alloc_nx_info(%d) = %p"
1164 +       "create_nx_info(%d) (dynamic rejected)"
1165 +       "create_nx_info(%d) = %p (already there)"
1166 +       "create_nx_info(%d) = %p (new)"
1167 +       "dealloc_nx_info(%p)"
1168 + 1   2 "alloc_nx_info(%d)*"
1169 +       "create_nx_info(%d)*"
1170 + 2   4 "get_nx_info(%p[#%d.%d])"
1171 +       "put_nx_info(%p[#%d.%d])"
1172 + 3   8 "claim_nx_info(%p[#%d.%d.%d]) %p"
1173 +       "clr_nx_info(%p[#%d.%d])"
1174 +       "init_nx_info(%p[#%d.%d])"
1175 +       "release_nx_info(%p[#%d.%d.%d]) %p"
1176 +       "set_nx_info(%p[#%d.%d])"
1177 + 4  10 "__hash_nx_info: %p[#%d]"
1178 +       "__nx_dynamic_id: [#%d]"
1179 +       "__unhash_nx_info: %p[#%d.%d.%d]"
1180 + 5  20 "moved task %p into nxi:%p[#%d]"
1181 +       "nx_migrate_task(%p,%p[#%d.%d.%d])"
1182 +       "task_get_nx_info(%p)"
1183 + 6  40 "nx_clear_persistent(%p[#%d])"
1184 +
1185 +debug_quota:
1186 +
1187 + 0   1 "quota_sync_dqh(%p,%d) discard inode %p"
1188 + 1   2 "quota_sync_dqh(%p,%d)"
1189 +       "sync_dquots(%p,%d)"
1190 +       "sync_dquots_dqh(%p,%d)"
1191 + 3   8 "do_quotactl(%p,%d,cmd=%d,id=%d,%p)"
1192 +
1193 +debug_switch:
1194 +
1195 + 0   1 "vc: VCMD_%02d_%d[%d], %d,%p [%d,%d,%x,%x]"
1196 + 1   2 "vc: VCMD_%02d_%d[%d] = %08lx(%ld) [%d,%d]"
1197 + 4  10 "%s: (%s %s) returned %s with %d"
1198 +
1199 +debug_tag:
1200 +
1201 + 7  80 "dx_parse_tag(»%s«): %d:#%d"
1202 +       "dx_propagate_tag(%p[#%lu.%d]): %d,%d"
1203 +
1204 +debug_xid:
1205 +
1206 + 0   1 "__lookup_vx_info(#%u): %p[#%u]"
1207 +       "alloc_vx_info(%d) = %p"
1208 +       "alloc_vx_info(%d)*"
1209 +       "create_vx_info(%d) (dynamic rejected)"
1210 +       "create_vx_info(%d) = %p (already there)"
1211 +       "create_vx_info(%d) = %p (new)"
1212 +       "dealloc_vx_info(%p)"
1213 +       "loc_vx_info(%d) = %p (found)"
1214 +       "loc_vx_info(%d) = %p (new)"
1215 +       "loc_vx_info(%d) = %p (not available)"
1216 + 1   2 "create_vx_info(%d)*"
1217 +       "loc_vx_info(%d)*"
1218 + 2   4 "get_vx_info(%p[#%d.%d])"
1219 +       "put_vx_info(%p[#%d.%d])"
1220 + 3   8 "claim_vx_info(%p[#%d.%d.%d]) %p"
1221 +       "clr_vx_info(%p[#%d.%d])"
1222 +       "init_vx_info(%p[#%d.%d])"
1223 +       "release_vx_info(%p[#%d.%d.%d]) %p"
1224 +       "set_vx_info(%p[#%d.%d])"
1225 + 4  10 "__hash_vx_info: %p[#%d]"
1226 +       "__unhash_vx_info: %p[#%d.%d.%d]"
1227 +       "__vx_dynamic_id: [#%d]"
1228 + 5  20 "enter_vx_info(%p[#%d],%p) %p[#%d,%p]"
1229 +       "leave_vx_info(%p[#%d,%p]) %p[#%d,%p]"
1230 +       "moved task %p into vxi:%p[#%d]"
1231 +       "task_get_vx_info(%p)"
1232 +       "vx_migrate_task(%p,%p[#%d.%d])"
1233 + 6  40 "vx_clear_persistent(%p[#%d])"
1234 +       "vx_exit_init(%p[#%d],%p[#%d,%d,%d])"
1235 +       "vx_set_init(%p[#%d],%p[#%d,%d,%d])"
1236 +       "vx_set_persistent(%p[#%d])"
1237 +       "vx_set_reaper(%p[#%d],%p[#%d,%d])"
1238 + 7  80 "vx_child_reaper(%p[#%u,%u]) = %p[#%u,%u]"
1239 +
1240 +
1241 +debug_limit:
1242 +
1243 + n 2^n "vx_acc_cres[%5d,%s,%2d]: %5d%s"
1244 +       "vx_cres_avail[%5d,%s,%2d]: %5ld > %5d + %5d"
1245 +
1246 + m 2^m "vx_acc_page[%5d,%s,%2d]: %5d%s"
1247 +       "vx_acc_pages[%5d,%s,%2d]: %5d += %5d"
1248 +       "vx_pages_avail[%5d,%s,%2d]: %5ld > %5d + %5d"
1249 diff -NurpP --minimal linux-2.6.32.6/drivers/block/Kconfig linux-2.6.32.6-vs2.3.0.36.28/drivers/block/Kconfig
1250 --- linux-2.6.32.6/drivers/block/Kconfig        2009-09-10 15:25:49.000000000 +0200
1251 +++ linux-2.6.32.6-vs2.3.0.36.28/drivers/block/Kconfig  2009-12-03 20:04:56.000000000 +0100
1252 @@ -271,6 +271,13 @@ config BLK_DEV_CRYPTOLOOP
1253           instead, which can be configured to be on-disk compatible with the
1254           cryptoloop device.
1255  
1256 +config BLK_DEV_VROOT
1257 +       tristate "Virtual Root device support"
1258 +       depends on QUOTACTL
1259 +       ---help---
1260 +         Saying Y here will allow you to use quota/fs ioctls on a shared
1261 +         partition within a virtual server without compromising security.
1262 +
1263  config BLK_DEV_NBD
1264         tristate "Network block device support"
1265         depends on NET
1266 diff -NurpP --minimal linux-2.6.32.6/drivers/block/loop.c linux-2.6.32.6-vs2.3.0.36.28/drivers/block/loop.c
1267 --- linux-2.6.32.6/drivers/block/loop.c 2009-12-03 20:02:19.000000000 +0100
1268 +++ linux-2.6.32.6-vs2.3.0.36.28/drivers/block/loop.c   2009-12-03 20:04:56.000000000 +0100
1269 @@ -74,6 +74,7 @@
1270  #include <linux/gfp.h>
1271  #include <linux/kthread.h>
1272  #include <linux/splice.h>
1273 +#include <linux/vs_context.h>
1274  
1275  #include <asm/uaccess.h>
1276  
1277 @@ -812,6 +813,7 @@ static int loop_set_fd(struct loop_devic
1278         lo->lo_blocksize = lo_blocksize;
1279         lo->lo_device = bdev;
1280         lo->lo_flags = lo_flags;
1281 +       lo->lo_xid = vx_current_xid();
1282         lo->lo_backing_file = file;
1283         lo->transfer = transfer_none;
1284         lo->ioctl = NULL;
1285 @@ -937,6 +939,7 @@ static int loop_clr_fd(struct loop_devic
1286         lo->lo_encrypt_key_size = 0;
1287         lo->lo_flags = 0;
1288         lo->lo_thread = NULL;
1289 +       lo->lo_xid = 0;
1290         memset(lo->lo_encrypt_key, 0, LO_KEY_SIZE);
1291         memset(lo->lo_crypt_name, 0, LO_NAME_SIZE);
1292         memset(lo->lo_file_name, 0, LO_NAME_SIZE);
1293 @@ -971,7 +974,7 @@ loop_set_status(struct loop_device *lo, 
1294  
1295         if (lo->lo_encrypt_key_size &&
1296             lo->lo_key_owner != uid &&
1297 -           !capable(CAP_SYS_ADMIN))
1298 +           !vx_capable(CAP_SYS_ADMIN, VXC_ADMIN_CLOOP))
1299                 return -EPERM;
1300         if (lo->lo_state != Lo_bound)
1301                 return -ENXIO;
1302 @@ -1055,7 +1058,8 @@ loop_get_status(struct loop_device *lo, 
1303         memcpy(info->lo_crypt_name, lo->lo_crypt_name, LO_NAME_SIZE);
1304         info->lo_encrypt_type =
1305                 lo->lo_encryption ? lo->lo_encryption->number : 0;
1306 -       if (lo->lo_encrypt_key_size && capable(CAP_SYS_ADMIN)) {
1307 +       if (lo->lo_encrypt_key_size &&
1308 +               vx_capable(CAP_SYS_ADMIN, VXC_ADMIN_CLOOP)) {
1309                 info->lo_encrypt_key_size = lo->lo_encrypt_key_size;
1310                 memcpy(info->lo_encrypt_key, lo->lo_encrypt_key,
1311                        lo->lo_encrypt_key_size);
1312 @@ -1399,6 +1403,9 @@ static int lo_open(struct block_device *
1313  {
1314         struct loop_device *lo = bdev->bd_disk->private_data;
1315  
1316 +       if (!vx_check(lo->lo_xid, VS_IDENT|VS_HOSTID|VS_ADMIN_P))
1317 +               return -EACCES;
1318 +
1319         mutex_lock(&lo->lo_ctl_mutex);
1320         lo->lo_refcnt++;
1321         mutex_unlock(&lo->lo_ctl_mutex);
1322 diff -NurpP --minimal linux-2.6.32.6/drivers/block/Makefile linux-2.6.32.6-vs2.3.0.36.28/drivers/block/Makefile
1323 --- linux-2.6.32.6/drivers/block/Makefile       2009-09-10 15:25:49.000000000 +0200
1324 +++ linux-2.6.32.6-vs2.3.0.36.28/drivers/block/Makefile 2009-12-03 20:04:56.000000000 +0100
1325 @@ -34,6 +34,7 @@ obj-$(CONFIG_VIODASD)         += viodasd.o
1326  obj-$(CONFIG_BLK_DEV_SX8)      += sx8.o
1327  obj-$(CONFIG_BLK_DEV_UB)       += ub.o
1328  obj-$(CONFIG_BLK_DEV_HD)       += hd.o
1329 +obj-$(CONFIG_BLK_DEV_VROOT)    += vroot.o
1330  
1331  obj-$(CONFIG_XEN_BLKDEV_FRONTEND)      += xen-blkfront.o
1332  
1333 diff -NurpP --minimal linux-2.6.32.6/drivers/block/vroot.c linux-2.6.32.6-vs2.3.0.36.28/drivers/block/vroot.c
1334 --- linux-2.6.32.6/drivers/block/vroot.c        1970-01-01 01:00:00.000000000 +0100
1335 +++ linux-2.6.32.6-vs2.3.0.36.28/drivers/block/vroot.c  2009-12-03 20:04:56.000000000 +0100
1336 @@ -0,0 +1,281 @@
1337 +/*
1338 + *  linux/drivers/block/vroot.c
1339 + *
1340 + *  written by Herbert Pötzl, 9/11/2002
1341 + *  ported to 2.6.10 by Herbert Pötzl, 30/12/2004
1342 + *
1343 + *  based on the loop.c code by Theodore Ts'o.
1344 + *
1345 + * Copyright (C) 2002-2007 by Herbert Pötzl.
1346 + * Redistribution of this file is permitted under the
1347 + * GNU General Public License.
1348 + *
1349 + */
1350 +
1351 +#include <linux/module.h>
1352 +#include <linux/moduleparam.h>
1353 +#include <linux/file.h>
1354 +#include <linux/major.h>
1355 +#include <linux/blkdev.h>
1356 +
1357 +#include <linux/vroot.h>
1358 +#include <linux/vs_context.h>
1359 +
1360 +
1361 +static int max_vroot = 8;
1362 +
1363 +static struct vroot_device *vroot_dev;
1364 +static struct gendisk **disks;
1365 +
1366 +
1367 +static int vroot_set_dev(
1368 +       struct vroot_device *vr,
1369 +       struct block_device *bdev,
1370 +       unsigned int arg)
1371 +{
1372 +       struct block_device *real_bdev;
1373 +       struct file *file;
1374 +       struct inode *inode;
1375 +       int error;
1376 +
1377 +       error = -EBUSY;
1378 +       if (vr->vr_state != Vr_unbound)
1379 +               goto out;
1380 +
1381 +       error = -EBADF;
1382 +       file = fget(arg);
1383 +       if (!file)
1384 +               goto out;
1385 +
1386 +       error = -EINVAL;
1387 +       inode = file->f_dentry->d_inode;
1388 +
1389 +
1390 +       if (S_ISBLK(inode->i_mode)) {
1391 +               real_bdev = inode->i_bdev;
1392 +               vr->vr_device = real_bdev;
1393 +               __iget(real_bdev->bd_inode);
1394 +       } else
1395 +               goto out_fput;
1396 +
1397 +       vxdprintk(VXD_CBIT(misc, 0),
1398 +               "vroot[%d]_set_dev: dev=" VXF_DEV,
1399 +               vr->vr_number, VXD_DEV(real_bdev));
1400 +
1401 +       vr->vr_state = Vr_bound;
1402 +       error = 0;
1403 +
1404 + out_fput:
1405 +       fput(file);
1406 + out:
1407 +       return error;
1408 +}
1409 +
1410 +static int vroot_clr_dev(
1411 +       struct vroot_device *vr,
1412 +       struct block_device *bdev)
1413 +{
1414 +       struct block_device *real_bdev;
1415 +
1416 +       if (vr->vr_state != Vr_bound)
1417 +               return -ENXIO;
1418 +       if (vr->vr_refcnt > 1)  /* we needed one fd for the ioctl */
1419 +               return -EBUSY;
1420 +
1421 +       real_bdev = vr->vr_device;
1422 +
1423 +       vxdprintk(VXD_CBIT(misc, 0),
1424 +               "vroot[%d]_clr_dev: dev=" VXF_DEV,
1425 +               vr->vr_number, VXD_DEV(real_bdev));
1426 +
1427 +       bdput(real_bdev);
1428 +       vr->vr_state = Vr_unbound;
1429 +       vr->vr_device = NULL;
1430 +       return 0;
1431 +}
1432 +
1433 +
1434 +static int vr_ioctl(struct block_device *bdev, fmode_t mode,
1435 +       unsigned int cmd, unsigned long arg)
1436 +{
1437 +       struct vroot_device *vr = bdev->bd_disk->private_data;
1438 +       int err;
1439 +
1440 +       down(&vr->vr_ctl_mutex);
1441 +       switch (cmd) {
1442 +       case VROOT_SET_DEV:
1443 +               err = vroot_set_dev(vr, bdev, arg);
1444 +               break;
1445 +       case VROOT_CLR_DEV:
1446 +               err = vroot_clr_dev(vr, bdev);
1447 +               break;
1448 +       default:
1449 +               err = -EINVAL;
1450 +               break;
1451 +       }
1452 +       up(&vr->vr_ctl_mutex);
1453 +       return err;
1454 +}
1455 +
1456 +static int vr_open(struct block_device *bdev, fmode_t mode)
1457 +{
1458 +       struct vroot_device *vr = bdev->bd_disk->private_data;
1459 +
1460 +       down(&vr->vr_ctl_mutex);
1461 +       vr->vr_refcnt++;
1462 +       up(&vr->vr_ctl_mutex);
1463 +       return 0;
1464 +}
1465 +
1466 +static int vr_release(struct gendisk *disk, fmode_t mode)
1467 +{
1468 +       struct vroot_device *vr = disk->private_data;
1469 +
1470 +       down(&vr->vr_ctl_mutex);
1471 +       --vr->vr_refcnt;
1472 +       up(&vr->vr_ctl_mutex);
1473 +       return 0;
1474 +}
1475 +
1476 +static struct block_device_operations vr_fops = {
1477 +       .owner =        THIS_MODULE,
1478 +       .open =         vr_open,
1479 +       .release =      vr_release,
1480 +       .ioctl =        vr_ioctl,
1481 +};
1482 +
1483 +struct block_device *__vroot_get_real_bdev(struct block_device *bdev)
1484 +{
1485 +       struct inode *inode = bdev->bd_inode;
1486 +       struct vroot_device *vr;
1487 +       struct block_device *real_bdev;
1488 +       int minor = iminor(inode);
1489 +
1490 +       vr = &vroot_dev[minor];
1491 +       real_bdev = vr->vr_device;
1492 +
1493 +       vxdprintk(VXD_CBIT(misc, 0),
1494 +               "vroot[%d]_get_real_bdev: dev=" VXF_DEV,
1495 +               vr->vr_number, VXD_DEV(real_bdev));
1496 +
1497 +       if (vr->vr_state != Vr_bound)
1498 +               return ERR_PTR(-ENXIO);
1499 +
1500 +       __iget(real_bdev->bd_inode);
1501 +       return real_bdev;
1502 +}
1503 +
1504 +/*
1505 + * And now the modules code and kernel interface.
1506 + */
1507 +
1508 +module_param(max_vroot, int, 0);
1509 +
1510 +MODULE_PARM_DESC(max_vroot, "Maximum number of vroot devices (1-256)");
1511 +MODULE_LICENSE("GPL");
1512 +MODULE_ALIAS_BLOCKDEV_MAJOR(VROOT_MAJOR);
1513 +
1514 +MODULE_AUTHOR ("Herbert Pötzl");
1515 +MODULE_DESCRIPTION ("Virtual Root Device Mapper");
1516 +
1517 +
1518 +int __init vroot_init(void)
1519 +{
1520 +       int err, i;
1521 +
1522 +       if (max_vroot < 1 || max_vroot > 256) {
1523 +               max_vroot = MAX_VROOT_DEFAULT;
1524 +               printk(KERN_WARNING "vroot: invalid max_vroot "
1525 +                       "(must be between 1 and 256), "
1526 +                       "using default (%d)\n", max_vroot);
1527 +       }
1528 +
1529 +       if (register_blkdev(VROOT_MAJOR, "vroot"))
1530 +               return -EIO;
1531 +
1532 +       err = -ENOMEM;
1533 +       vroot_dev = kmalloc(max_vroot * sizeof(struct vroot_device), GFP_KERNEL);
1534 +       if (!vroot_dev)
1535 +               goto out_mem1;
1536 +       memset(vroot_dev, 0, max_vroot * sizeof(struct vroot_device));
1537 +
1538 +       disks = kmalloc(max_vroot * sizeof(struct gendisk *), GFP_KERNEL);
1539 +       if (!disks)
1540 +               goto out_mem2;
1541 +
1542 +       for (i = 0; i < max_vroot; i++) {
1543 +               disks[i] = alloc_disk(1);
1544 +               if (!disks[i])
1545 +                       goto out_mem3;
1546 +               disks[i]->queue = blk_alloc_queue(GFP_KERNEL);
1547 +               if (!disks[i]->queue)
1548 +                       goto out_mem3;
1549 +       }
1550 +
1551 +       for (i = 0; i < max_vroot; i++) {
1552 +               struct vroot_device *vr = &vroot_dev[i];
1553 +               struct gendisk *disk = disks[i];
1554 +
1555 +               memset(vr, 0, sizeof(*vr));
1556 +               init_MUTEX(&vr->vr_ctl_mutex);
1557 +               vr->vr_number = i;
1558 +               disk->major = VROOT_MAJOR;
1559 +               disk->first_minor = i;
1560 +               disk->fops = &vr_fops;
1561 +               sprintf(disk->disk_name, "vroot%d", i);
1562 +               disk->private_data = vr;
1563 +       }
1564 +
1565 +       err = register_vroot_grb(&__vroot_get_real_bdev);
1566 +       if (err)
1567 +               goto out_mem3;
1568 +
1569 +       for (i = 0; i < max_vroot; i++)
1570 +               add_disk(disks[i]);
1571 +       printk(KERN_INFO "vroot: loaded (max %d devices)\n", max_vroot);
1572 +       return 0;
1573 +
1574 +out_mem3:
1575 +       while (i--)
1576 +               put_disk(disks[i]);
1577 +       kfree(disks);
1578 +out_mem2:
1579 +       kfree(vroot_dev);
1580 +out_mem1:
1581 +       unregister_blkdev(VROOT_MAJOR, "vroot");
1582 +       printk(KERN_ERR "vroot: ran out of memory\n");
1583 +       return err;
1584 +}
1585 +
1586 +void vroot_exit(void)
1587 +{
1588 +       int i;
1589 +
1590 +       if (unregister_vroot_grb(&__vroot_get_real_bdev))
1591 +               printk(KERN_WARNING "vroot: cannot unregister grb\n");
1592 +
1593 +       for (i = 0; i < max_vroot; i++) {
1594 +               del_gendisk(disks[i]);
1595 +               put_disk(disks[i]);
1596 +       }
1597 +       unregister_blkdev(VROOT_MAJOR, "vroot");
1598 +
1599 +       kfree(disks);
1600 +       kfree(vroot_dev);
1601 +}
1602 +
1603 +module_init(vroot_init);
1604 +module_exit(vroot_exit);
1605 +
1606 +#ifndef MODULE
1607 +
1608 +static int __init max_vroot_setup(char *str)
1609 +{
1610 +       max_vroot = simple_strtol(str, NULL, 0);
1611 +       return 1;
1612 +}
1613 +
1614 +__setup("max_vroot=", max_vroot_setup);
1615 +
1616 +#endif
1617 +
1618 diff -NurpP --minimal linux-2.6.32.6/drivers/char/sysrq.c linux-2.6.32.6-vs2.3.0.36.28/drivers/char/sysrq.c
1619 --- linux-2.6.32.6/drivers/char/sysrq.c 2009-12-03 20:02:20.000000000 +0100
1620 +++ linux-2.6.32.6-vs2.3.0.36.28/drivers/char/sysrq.c   2009-12-03 20:04:56.000000000 +0100
1621 @@ -38,6 +38,7 @@
1622  #include <linux/workqueue.h>
1623  #include <linux/hrtimer.h>
1624  #include <linux/oom.h>
1625 +#include <linux/vserver/debug.h>
1626  
1627  #include <asm/ptrace.h>
1628  #include <asm/irq_regs.h>
1629 @@ -391,6 +392,21 @@ static struct sysrq_key_op sysrq_unrt_op
1630         .enable_mask    = SYSRQ_ENABLE_RTNICE,
1631  };
1632  
1633 +
1634 +#ifdef CONFIG_VSERVER_DEBUG
1635 +static void sysrq_handle_vxinfo(int key, struct tty_struct *tty)
1636 +{
1637 +       dump_vx_info_inactive((key == 'x')?0:1);
1638 +}
1639 +
1640 +static struct sysrq_key_op sysrq_showvxinfo_op = {
1641 +       .handler        = sysrq_handle_vxinfo,
1642 +       .help_msg       = "conteXt",
1643 +       .action_msg     = "Show Context Info",
1644 +       .enable_mask    = SYSRQ_ENABLE_DUMP,
1645 +};
1646 +#endif
1647 +
1648  /* Key Operations table and lock */
1649  static DEFINE_SPINLOCK(sysrq_key_table_lock);
1650  
1651 @@ -445,7 +461,11 @@ static struct sysrq_key_op *sysrq_key_ta
1652         NULL,                           /* v */
1653         &sysrq_showstate_blocked_op,    /* w */
1654         /* x: May be registered on ppc/powerpc for xmon */
1655 +#ifdef CONFIG_VSERVER_DEBUG
1656 +       &sysrq_showvxinfo_op,           /* x */
1657 +#else
1658         NULL,                           /* x */
1659 +#endif
1660         /* y: May be registered on sparc64 for global register dump */
1661         NULL,                           /* y */
1662         &sysrq_ftrace_dump_op,          /* z */
1663 @@ -460,6 +480,8 @@ static int sysrq_key_table_key2index(int
1664                 retval = key - '0';
1665         else if ((key >= 'a') && (key <= 'z'))
1666                 retval = key + 10 - 'a';
1667 +       else if ((key >= 'A') && (key <= 'Z'))
1668 +               retval = key + 10 - 'A';
1669         else
1670                 retval = -1;
1671         return retval;
1672 diff -NurpP --minimal linux-2.6.32.6/drivers/char/tty_io.c linux-2.6.32.6-vs2.3.0.36.28/drivers/char/tty_io.c
1673 --- linux-2.6.32.6/drivers/char/tty_io.c        2010-01-26 19:31:22.000000000 +0100
1674 +++ linux-2.6.32.6-vs2.3.0.36.28/drivers/char/tty_io.c  2010-01-26 20:35:35.000000000 +0100
1675 @@ -106,6 +106,7 @@
1676  
1677  #include <linux/kmod.h>
1678  #include <linux/nsproxy.h>
1679 +#include <linux/vs_pid.h>
1680  
1681  #undef TTY_DEBUG_HANGUP
1682  
1683 @@ -1966,7 +1967,8 @@ static int tiocsti(struct tty_struct *tt
1684         char ch, mbz = 0;
1685         struct tty_ldisc *ld;
1686  
1687 -       if ((current->signal->tty != tty) && !capable(CAP_SYS_ADMIN))
1688 +       if (((current->signal->tty != tty) && !capable(CAP_SYS_ADMIN)) ||
1689 +               !vx_ccaps(VXC_TIOCSTI))
1690                 return -EPERM;
1691         if (get_user(ch, p))
1692                 return -EFAULT;
1693 @@ -2254,6 +2256,7 @@ static int tiocspgrp(struct tty_struct *
1694                 return -ENOTTY;
1695         if (get_user(pgrp_nr, p))
1696                 return -EFAULT;
1697 +       pgrp_nr = vx_rmap_pid(pgrp_nr);
1698         if (pgrp_nr < 0)
1699                 return -EINVAL;
1700         rcu_read_lock();
1701 diff -NurpP --minimal linux-2.6.32.6/drivers/infiniband/hw/ipath/ipath_user_pages.c linux-2.6.32.6-vs2.3.0.36.28/drivers/infiniband/hw/ipath/ipath_user_pages.c
1702 --- linux-2.6.32.6/drivers/infiniband/hw/ipath/ipath_user_pages.c       2009-12-03 20:02:23.000000000 +0100
1703 +++ linux-2.6.32.6-vs2.3.0.36.28/drivers/infiniband/hw/ipath/ipath_user_pages.c 2009-12-04 23:31:17.000000000 +0100
1704 @@ -34,6 +34,7 @@
1705  #include <linux/mm.h>
1706  #include <linux/device.h>
1707  #include <linux/sched.h>
1708 +#include <linux/vs_memory.h>
1709  
1710  #include "ipath_kernel.h"
1711  
1712 @@ -62,7 +63,8 @@ static int __get_user_pages(unsigned lon
1713         lock_limit = current->signal->rlim[RLIMIT_MEMLOCK].rlim_cur >>
1714                 PAGE_SHIFT;
1715  
1716 -       if (num_pages > lock_limit) {
1717 +       if (num_pages > lock_limit ||
1718 +               !vx_vmlocked_avail(current->mm, num_pages)) {
1719                 ret = -ENOMEM;
1720                 goto bail;
1721         }
1722 @@ -79,7 +81,7 @@ static int __get_user_pages(unsigned lon
1723                         goto bail_release;
1724         }
1725  
1726 -       current->mm->locked_vm += num_pages;
1727 +       vx_vmlocked_add(current->mm, num_pages);
1728  
1729         ret = 0;
1730         goto bail;
1731 @@ -178,7 +180,7 @@ void ipath_release_user_pages(struct pag
1732  
1733         __ipath_release_user_pages(p, num_pages, 1);
1734  
1735 -       current->mm->locked_vm -= num_pages;
1736 +       vx_vmlocked_sub(current->mm, num_pages);
1737  
1738         up_write(&current->mm->mmap_sem);
1739  }
1740 @@ -195,7 +197,7 @@ static void user_pages_account(struct wo
1741                 container_of(_work, struct ipath_user_pages_work, work);
1742  
1743         down_write(&work->mm->mmap_sem);
1744 -       work->mm->locked_vm -= work->num_pages;
1745 +       vx_vmlocked_sub(work->mm, work->num_pages);
1746         up_write(&work->mm->mmap_sem);
1747         mmput(work->mm);
1748         kfree(work);
1749 diff -NurpP --minimal linux-2.6.32.6/drivers/md/dm.c linux-2.6.32.6-vs2.3.0.36.28/drivers/md/dm.c
1750 --- linux-2.6.32.6/drivers/md/dm.c      2009-12-03 20:02:25.000000000 +0100
1751 +++ linux-2.6.32.6-vs2.3.0.36.28/drivers/md/dm.c        2009-12-03 20:04:56.000000000 +0100
1752 @@ -19,6 +19,7 @@
1753  #include <linux/slab.h>
1754  #include <linux/idr.h>
1755  #include <linux/hdreg.h>
1756 +#include <linux/vs_base.h>
1757  
1758  #include <trace/events/block.h>
1759  
1760 @@ -119,6 +120,7 @@ struct mapped_device {
1761         rwlock_t map_lock;
1762         atomic_t holders;
1763         atomic_t open_count;
1764 +       xid_t xid;
1765  
1766         unsigned long flags;
1767  
1768 @@ -323,6 +325,7 @@ static void __exit dm_exit(void)
1769  static int dm_blk_open(struct block_device *bdev, fmode_t mode)
1770  {
1771         struct mapped_device *md;
1772 +       int ret = -ENXIO;
1773  
1774         spin_lock(&_minor_lock);
1775  
1776 @@ -331,18 +334,19 @@ static int dm_blk_open(struct block_devi
1777                 goto out;
1778  
1779         if (test_bit(DMF_FREEING, &md->flags) ||
1780 -           test_bit(DMF_DELETING, &md->flags)) {
1781 -               md = NULL;
1782 +           test_bit(DMF_DELETING, &md->flags))
1783 +               goto out;
1784 +
1785 +       ret = -EACCES;
1786 +       if (!vx_check(md->xid, VS_IDENT|VS_HOSTID))
1787                 goto out;
1788 -       }
1789  
1790         dm_get(md);
1791         atomic_inc(&md->open_count);
1792 -
1793 +       ret = 0;
1794  out:
1795         spin_unlock(&_minor_lock);
1796 -
1797 -       return md ? 0 : -ENXIO;
1798 +       return ret;
1799  }
1800  
1801  static int dm_blk_close(struct gendisk *disk, fmode_t mode)
1802 @@ -553,6 +557,14 @@ int dm_set_geometry(struct mapped_device
1803         return 0;
1804  }
1805  
1806 +/*
1807 + * Get the xid associated with a dm device
1808 + */
1809 +xid_t dm_get_xid(struct mapped_device *md)
1810 +{
1811 +       return md->xid;
1812 +}
1813 +
1814  /*-----------------------------------------------------------------
1815   * CRUD START:
1816   *   A more elegant soln is in the works that uses the queue
1817 @@ -1762,6 +1774,7 @@ static struct mapped_device *alloc_dev(i
1818         INIT_LIST_HEAD(&md->uevent_list);
1819         spin_lock_init(&md->uevent_lock);
1820  
1821 +       md->xid = vx_current_xid();
1822         md->queue = blk_init_queue(dm_request_fn, NULL);
1823         if (!md->queue)
1824                 goto bad_queue;
1825 diff -NurpP --minimal linux-2.6.32.6/drivers/md/dm.h linux-2.6.32.6-vs2.3.0.36.28/drivers/md/dm.h
1826 --- linux-2.6.32.6/drivers/md/dm.h      2009-09-10 15:25:55.000000000 +0200
1827 +++ linux-2.6.32.6-vs2.3.0.36.28/drivers/md/dm.h        2009-12-03 20:04:56.000000000 +0100
1828 @@ -41,6 +41,8 @@ struct dm_dev_internal {
1829  struct dm_table;
1830  struct dm_md_mempools;
1831  
1832 +xid_t dm_get_xid(struct mapped_device *md);
1833 +
1834  /*-----------------------------------------------------------------
1835   * Internal table functions.
1836   *---------------------------------------------------------------*/
1837 diff -NurpP --minimal linux-2.6.32.6/drivers/md/dm-ioctl.c linux-2.6.32.6-vs2.3.0.36.28/drivers/md/dm-ioctl.c
1838 --- linux-2.6.32.6/drivers/md/dm-ioctl.c        2010-01-26 19:31:23.000000000 +0100
1839 +++ linux-2.6.32.6-vs2.3.0.36.28/drivers/md/dm-ioctl.c  2009-12-29 00:36:25.000000000 +0100
1840 @@ -16,6 +16,7 @@
1841  #include <linux/dm-ioctl.h>
1842  #include <linux/hdreg.h>
1843  #include <linux/compat.h>
1844 +#include <linux/vs_context.h>
1845  
1846  #include <asm/uaccess.h>
1847  
1848 @@ -106,7 +107,8 @@ static struct hash_cell *__get_name_cell
1849         unsigned int h = hash_str(str);
1850  
1851         list_for_each_entry (hc, _name_buckets + h, name_list)
1852 -               if (!strcmp(hc->name, str)) {
1853 +               if (vx_check(dm_get_xid(hc->md), VS_WATCH_P | VS_IDENT) &&
1854 +                       !strcmp(hc->name, str)) {
1855                         dm_get(hc->md);
1856                         return hc;
1857                 }
1858 @@ -120,7 +122,8 @@ static struct hash_cell *__get_uuid_cell
1859         unsigned int h = hash_str(str);
1860  
1861         list_for_each_entry (hc, _uuid_buckets + h, uuid_list)
1862 -               if (!strcmp(hc->uuid, str)) {
1863 +               if (vx_check(dm_get_xid(hc->md), VS_WATCH_P | VS_IDENT) &&
1864 +                       !strcmp(hc->uuid, str)) {
1865                         dm_get(hc->md);
1866                         return hc;
1867                 }
1868 @@ -363,6 +366,9 @@ typedef int (*ioctl_fn)(struct dm_ioctl 
1869  
1870  static int remove_all(struct dm_ioctl *param, size_t param_size)
1871  {
1872 +       if (!vx_check(0, VS_ADMIN))
1873 +               return -EPERM;
1874 +
1875         dm_hash_remove_all(1);
1876         param->data_size = 0;
1877         return 0;
1878 @@ -410,6 +416,8 @@ static int list_devices(struct dm_ioctl 
1879          */
1880         for (i = 0; i < NUM_BUCKETS; i++) {
1881                 list_for_each_entry (hc, _name_buckets + i, name_list) {
1882 +                       if (!vx_check(dm_get_xid(hc->md), VS_WATCH_P | VS_IDENT))
1883 +                               continue;
1884                         needed += sizeof(struct dm_name_list);
1885                         needed += strlen(hc->name) + 1;
1886                         needed += ALIGN_MASK;
1887 @@ -433,6 +441,8 @@ static int list_devices(struct dm_ioctl 
1888          */
1889         for (i = 0; i < NUM_BUCKETS; i++) {
1890                 list_for_each_entry (hc, _name_buckets + i, name_list) {
1891 +                       if (!vx_check(dm_get_xid(hc->md), VS_WATCH_P | VS_IDENT))
1892 +                               continue;
1893                         if (old_nl)
1894                                 old_nl->next = (uint32_t) ((void *) nl -
1895                                                            (void *) old_nl);
1896 @@ -623,10 +633,11 @@ static struct hash_cell *__find_device_h
1897         if (!md)
1898                 goto out;
1899  
1900 -       mdptr = dm_get_mdptr(md);
1901 +       if (vx_check(dm_get_xid(md), VS_WATCH_P | VS_IDENT))
1902 +               mdptr = dm_get_mdptr(md);
1903 +
1904         if (!mdptr)
1905                 dm_put(md);
1906 -
1907  out:
1908         return mdptr;
1909  }
1910 @@ -1456,8 +1467,8 @@ static int ctl_ioctl(uint command, struc
1911         ioctl_fn fn = NULL;
1912         size_t param_size;
1913  
1914 -       /* only root can play with this */
1915 -       if (!capable(CAP_SYS_ADMIN))
1916 +       /* only root and certain contexts can play with this */
1917 +       if (!vx_capable(CAP_SYS_ADMIN, VXC_ADMIN_MAPPER))
1918                 return -EACCES;
1919  
1920         if (_IOC_TYPE(command) != DM_IOCTL)
1921 diff -NurpP --minimal linux-2.6.32.6/drivers/net/tun.c linux-2.6.32.6-vs2.3.0.36.28/drivers/net/tun.c
1922 --- linux-2.6.32.6/drivers/net/tun.c    2009-12-03 20:02:32.000000000 +0100
1923 +++ linux-2.6.32.6-vs2.3.0.36.28/drivers/net/tun.c      2009-12-03 20:04:56.000000000 +0100
1924 @@ -61,6 +61,7 @@
1925  #include <linux/crc32.h>
1926  #include <linux/nsproxy.h>
1927  #include <linux/virtio_net.h>
1928 +#include <linux/vs_network.h>
1929  #include <net/net_namespace.h>
1930  #include <net/netns/generic.h>
1931  #include <net/rtnetlink.h>
1932 @@ -102,6 +103,7 @@ struct tun_struct {
1933         unsigned int            flags;
1934         uid_t                   owner;
1935         gid_t                   group;
1936 +       nid_t                   nid;
1937  
1938         struct net_device       *dev;
1939         struct fasync_struct    *fasync;
1940 @@ -816,6 +818,7 @@ static void tun_setup(struct net_device 
1941  
1942         tun->owner = -1;
1943         tun->group = -1;
1944 +       tun->nid = current->nid;
1945  
1946         dev->ethtool_ops = &tun_ethtool_ops;
1947         dev->destructor = tun_free_netdev;
1948 @@ -932,7 +935,7 @@ static int tun_set_iff(struct net *net, 
1949  
1950                 if (((tun->owner != -1 && cred->euid != tun->owner) ||
1951                      (tun->group != -1 && !in_egroup_p(tun->group))) &&
1952 -                   !capable(CAP_NET_ADMIN))
1953 +               !cap_raised(current_cap(), CAP_NET_ADMIN))
1954                         return -EPERM;
1955                 err = security_tun_dev_attach(tun->socket.sk);
1956                 if (err < 0)
1957 @@ -946,7 +949,7 @@ static int tun_set_iff(struct net *net, 
1958                 char *name;
1959                 unsigned long flags = 0;
1960  
1961 -               if (!capable(CAP_NET_ADMIN))
1962 +               if (!nx_capable(CAP_NET_ADMIN, NXC_TUN_CREATE))
1963                         return -EPERM;
1964                 err = security_tun_dev_create();
1965                 if (err < 0)
1966 @@ -1013,6 +1016,9 @@ static int tun_set_iff(struct net *net, 
1967  
1968                 sk->sk_destruct = tun_sock_destruct;
1969  
1970 +               if (!nx_check(tun->nid, VS_IDENT | VS_HOSTID | VS_ADMIN_P))
1971 +                       return -EPERM;
1972 +
1973                 err = tun_attach(tun, file);
1974                 if (err < 0)
1975                         goto failed;
1976 @@ -1202,6 +1208,16 @@ static long tun_chr_ioctl(struct file *f
1977                 DBG(KERN_INFO "%s: group set to %d\n", tun->dev->name, tun->group);
1978                 break;
1979  
1980 +       case TUNSETNID:
1981 +               if (!capable(CAP_CONTEXT))
1982 +                       return -EPERM;
1983 +
1984 +               /* Set nid owner of the device */
1985 +               tun->nid = (nid_t) arg;
1986 +
1987 +               DBG(KERN_INFO "%s: nid owner set to %u\n", tun->dev->name, tun->nid);
1988 +               break;
1989 +
1990         case TUNSETLINK:
1991                 /* Only allow setting the type when the interface is down */
1992                 if (tun->dev->flags & IFF_UP) {
1993 diff -NurpP --minimal linux-2.6.32.6/fs/attr.c linux-2.6.32.6-vs2.3.0.36.28/fs/attr.c
1994 --- linux-2.6.32.6/fs/attr.c    2009-12-03 20:02:51.000000000 +0100
1995 +++ linux-2.6.32.6-vs2.3.0.36.28/fs/attr.c      2009-12-03 20:04:56.000000000 +0100
1996 @@ -14,6 +14,9 @@
1997  #include <linux/fcntl.h>
1998  #include <linux/quotaops.h>
1999  #include <linux/security.h>
2000 +#include <linux/proc_fs.h>
2001 +#include <linux/devpts_fs.h>
2002 +#include <linux/vs_tag.h>
2003  
2004  /* Taken over from the old code... */
2005  
2006 @@ -55,6 +58,10 @@ int inode_change_ok(const struct inode *
2007                 if (!is_owner_or_cap(inode))
2008                         goto error;
2009         }
2010 +
2011 +       if (dx_permission(inode, MAY_WRITE))
2012 +               goto error;
2013 +
2014  fine:
2015         retval = 0;
2016  error:
2017 @@ -120,6 +127,8 @@ int inode_setattr(struct inode * inode, 
2018                 inode->i_uid = attr->ia_uid;
2019         if (ia_valid & ATTR_GID)
2020                 inode->i_gid = attr->ia_gid;
2021 +       if ((ia_valid & ATTR_TAG) && IS_TAGGED(inode))
2022 +               inode->i_tag = attr->ia_tag;
2023         if (ia_valid & ATTR_ATIME)
2024                 inode->i_atime = timespec_trunc(attr->ia_atime,
2025                                                 inode->i_sb->s_time_gran);
2026 @@ -214,7 +223,8 @@ int notify_change(struct dentry * dentry
2027                 error = inode_change_ok(inode, attr);
2028                 if (!error) {
2029                         if ((ia_valid & ATTR_UID && attr->ia_uid != inode->i_uid) ||
2030 -                           (ia_valid & ATTR_GID && attr->ia_gid != inode->i_gid))
2031 +                           (ia_valid & ATTR_GID && attr->ia_gid != inode->i_gid) ||
2032 +                           (ia_valid & ATTR_TAG && attr->ia_tag != inode->i_tag))
2033                                 error = vfs_dq_transfer(inode, attr) ?
2034                                         -EDQUOT : 0;
2035                         if (!error)
2036 diff -NurpP --minimal linux-2.6.32.6/fs/binfmt_aout.c linux-2.6.32.6-vs2.3.0.36.28/fs/binfmt_aout.c
2037 --- linux-2.6.32.6/fs/binfmt_aout.c     2009-03-24 14:22:24.000000000 +0100
2038 +++ linux-2.6.32.6-vs2.3.0.36.28/fs/binfmt_aout.c       2009-12-03 20:04:56.000000000 +0100
2039 @@ -24,6 +24,7 @@
2040  #include <linux/binfmts.h>
2041  #include <linux/personality.h>
2042  #include <linux/init.h>
2043 +#include <linux/vs_memory.h>
2044  
2045  #include <asm/system.h>
2046  #include <asm/uaccess.h>
2047 diff -NurpP --minimal linux-2.6.32.6/fs/binfmt_elf.c linux-2.6.32.6-vs2.3.0.36.28/fs/binfmt_elf.c
2048 --- linux-2.6.32.6/fs/binfmt_elf.c      2009-12-03 20:02:51.000000000 +0100
2049 +++ linux-2.6.32.6-vs2.3.0.36.28/fs/binfmt_elf.c        2009-12-03 20:04:56.000000000 +0100
2050 @@ -31,6 +31,7 @@
2051  #include <linux/random.h>
2052  #include <linux/elf.h>
2053  #include <linux/utsname.h>
2054 +#include <linux/vs_memory.h>
2055  #include <asm/uaccess.h>
2056  #include <asm/param.h>
2057  #include <asm/page.h>
2058 diff -NurpP --minimal linux-2.6.32.6/fs/binfmt_flat.c linux-2.6.32.6-vs2.3.0.36.28/fs/binfmt_flat.c
2059 --- linux-2.6.32.6/fs/binfmt_flat.c     2009-12-03 20:02:51.000000000 +0100
2060 +++ linux-2.6.32.6-vs2.3.0.36.28/fs/binfmt_flat.c       2009-12-03 20:04:56.000000000 +0100
2061 @@ -35,6 +35,7 @@
2062  #include <linux/init.h>
2063  #include <linux/flat.h>
2064  #include <linux/syscalls.h>
2065 +#include <linux/vs_memory.h>
2066  
2067  #include <asm/byteorder.h>
2068  #include <asm/system.h>
2069 diff -NurpP --minimal linux-2.6.32.6/fs/binfmt_som.c linux-2.6.32.6-vs2.3.0.36.28/fs/binfmt_som.c
2070 --- linux-2.6.32.6/fs/binfmt_som.c      2009-06-11 17:13:02.000000000 +0200
2071 +++ linux-2.6.32.6-vs2.3.0.36.28/fs/binfmt_som.c        2009-12-03 20:04:56.000000000 +0100
2072 @@ -28,6 +28,7 @@
2073  #include <linux/shm.h>
2074  #include <linux/personality.h>
2075  #include <linux/init.h>
2076 +#include <linux/vs_memory.h>
2077  
2078  #include <asm/uaccess.h>
2079  #include <asm/pgtable.h>
2080 diff -NurpP --minimal linux-2.6.32.6/fs/block_dev.c linux-2.6.32.6-vs2.3.0.36.28/fs/block_dev.c
2081 --- linux-2.6.32.6/fs/block_dev.c       2009-12-03 20:02:51.000000000 +0100
2082 +++ linux-2.6.32.6-vs2.3.0.36.28/fs/block_dev.c 2009-12-03 20:04:56.000000000 +0100
2083 @@ -26,6 +26,7 @@
2084  #include <linux/namei.h>
2085  #include <linux/log2.h>
2086  #include <linux/kmemleak.h>
2087 +#include <linux/vs_device.h>
2088  #include <asm/uaccess.h>
2089  #include "internal.h"
2090  
2091 @@ -555,6 +556,7 @@ struct block_device *bdget(dev_t dev)
2092                 bdev->bd_invalidated = 0;
2093                 inode->i_mode = S_IFBLK;
2094                 inode->i_rdev = dev;
2095 +               inode->i_mdev = dev;
2096                 inode->i_bdev = bdev;
2097                 inode->i_data.a_ops = &def_blk_aops;
2098                 mapping_set_gfp_mask(&inode->i_data, GFP_USER);
2099 @@ -601,6 +603,11 @@ EXPORT_SYMBOL(bdput);
2100  static struct block_device *bd_acquire(struct inode *inode)
2101  {
2102         struct block_device *bdev;
2103 +       dev_t mdev;
2104 +
2105 +       if (!vs_map_blkdev(inode->i_rdev, &mdev, DATTR_OPEN))
2106 +               return NULL;
2107 +       inode->i_mdev = mdev;
2108  
2109         spin_lock(&bdev_lock);
2110         bdev = inode->i_bdev;
2111 @@ -611,7 +618,7 @@ static struct block_device *bd_acquire(s
2112         }
2113         spin_unlock(&bdev_lock);
2114  
2115 -       bdev = bdget(inode->i_rdev);
2116 +       bdev = bdget(mdev);
2117         if (bdev) {
2118                 spin_lock(&bdev_lock);
2119                 if (!inode->i_bdev) {
2120 diff -NurpP --minimal linux-2.6.32.6/fs/btrfs/ctree.h linux-2.6.32.6-vs2.3.0.36.28/fs/btrfs/ctree.h
2121 --- linux-2.6.32.6/fs/btrfs/ctree.h     2009-12-03 20:02:51.000000000 +0100
2122 +++ linux-2.6.32.6-vs2.3.0.36.28/fs/btrfs/ctree.h       2009-12-03 20:04:56.000000000 +0100
2123 @@ -544,11 +544,14 @@ struct btrfs_inode_item {
2124         /* modification sequence number for NFS */
2125         __le64 sequence;
2126  
2127 +       __le16 tag;
2128         /*
2129          * a little future expansion, for more than this we can
2130          * just grow the inode item and version it
2131          */
2132 -       __le64 reserved[4];
2133 +       __le16 reserved16;
2134 +       __le32 reserved32;
2135 +       __le64 reserved[3];
2136         struct btrfs_timespec atime;
2137         struct btrfs_timespec ctime;
2138         struct btrfs_timespec mtime;
2139 @@ -1155,6 +1158,8 @@ struct btrfs_root {
2140  #define BTRFS_MOUNT_NOSSD              (1 << 9)
2141  #define BTRFS_MOUNT_DISCARD            (1 << 10)
2142  
2143 +#define BTRFS_MOUNT_TAGGED             (1 << 24)
2144 +
2145  #define btrfs_clear_opt(o, opt)                ((o) &= ~BTRFS_MOUNT_##opt)
2146  #define btrfs_set_opt(o, opt)          ((o) |= BTRFS_MOUNT_##opt)
2147  #define btrfs_test_opt(root, opt)      ((root)->fs_info->mount_opt & \
2148 @@ -1174,6 +1179,10 @@ struct btrfs_root {
2149  #define BTRFS_INODE_NOATIME            (1 << 9)
2150  #define BTRFS_INODE_DIRSYNC            (1 << 10)
2151  
2152 +#define BTRFS_INODE_IXUNLINK           (1 << 24)
2153 +#define BTRFS_INODE_BARRIER            (1 << 25)
2154 +#define BTRFS_INODE_COW                        (1 << 26)
2155 +
2156  
2157  /* some macros to generate set/get funcs for the struct fields.  This
2158   * assumes there is a lefoo_to_cpu for every type, so lets make a simple
2159 @@ -1376,6 +1385,7 @@ BTRFS_SETGET_FUNCS(inode_block_group, st
2160  BTRFS_SETGET_FUNCS(inode_nlink, struct btrfs_inode_item, nlink, 32);
2161  BTRFS_SETGET_FUNCS(inode_uid, struct btrfs_inode_item, uid, 32);
2162  BTRFS_SETGET_FUNCS(inode_gid, struct btrfs_inode_item, gid, 32);
2163 +BTRFS_SETGET_FUNCS(inode_tag, struct btrfs_inode_item, tag, 16);
2164  BTRFS_SETGET_FUNCS(inode_mode, struct btrfs_inode_item, mode, 32);
2165  BTRFS_SETGET_FUNCS(inode_rdev, struct btrfs_inode_item, rdev, 64);
2166  BTRFS_SETGET_FUNCS(inode_flags, struct btrfs_inode_item, flags, 64);
2167 @@ -2338,6 +2348,7 @@ extern const struct dentry_operations bt
2168  long btrfs_ioctl(struct file *file, unsigned int cmd, unsigned long arg);
2169  void btrfs_update_iflags(struct inode *inode);
2170  void btrfs_inherit_iflags(struct inode *inode, struct inode *dir);
2171 +int btrfs_sync_flags(struct inode *inode, int, int);
2172  
2173  /* file.c */
2174  int btrfs_sync_file(struct file *file, struct dentry *dentry, int datasync);
2175 diff -NurpP --minimal linux-2.6.32.6/fs/btrfs/disk-io.c linux-2.6.32.6-vs2.3.0.36.28/fs/btrfs/disk-io.c
2176 --- linux-2.6.32.6/fs/btrfs/disk-io.c   2009-12-03 20:02:51.000000000 +0100
2177 +++ linux-2.6.32.6-vs2.3.0.36.28/fs/btrfs/disk-io.c     2009-12-03 20:04:56.000000000 +0100
2178 @@ -1723,6 +1723,9 @@ struct btrfs_root *open_ctree(struct sup
2179                 goto fail_iput;
2180         }
2181  
2182 +       if (btrfs_test_opt(tree_root, TAGGED))
2183 +               sb->s_flags |= MS_TAGGED;
2184 +
2185         features = btrfs_super_incompat_flags(disk_super) &
2186                 ~BTRFS_FEATURE_INCOMPAT_SUPP;
2187         if (features) {
2188 diff -NurpP --minimal linux-2.6.32.6/fs/btrfs/inode.c linux-2.6.32.6-vs2.3.0.36.28/fs/btrfs/inode.c
2189 --- linux-2.6.32.6/fs/btrfs/inode.c     2009-12-03 20:02:51.000000000 +0100
2190 +++ linux-2.6.32.6-vs2.3.0.36.28/fs/btrfs/inode.c       2009-12-03 20:04:56.000000000 +0100
2191 @@ -36,6 +36,8 @@
2192  #include <linux/xattr.h>
2193  #include <linux/posix_acl.h>
2194  #include <linux/falloc.h>
2195 +#include <linux/vs_tag.h>
2196 +
2197  #include "compat.h"
2198  #include "ctree.h"
2199  #include "disk-io.h"
2200 @@ -2242,6 +2244,8 @@ static void btrfs_read_locked_inode(stru
2201         int maybe_acls;
2202         u64 alloc_group_block;
2203         u32 rdev;
2204 +       uid_t uid;
2205 +       gid_t gid;
2206         int ret;
2207  
2208         path = btrfs_alloc_path();
2209 @@ -2258,8 +2262,13 @@ static void btrfs_read_locked_inode(stru
2210  
2211         inode->i_mode = btrfs_inode_mode(leaf, inode_item);
2212         inode->i_nlink = btrfs_inode_nlink(leaf, inode_item);
2213 -       inode->i_uid = btrfs_inode_uid(leaf, inode_item);
2214 -       inode->i_gid = btrfs_inode_gid(leaf, inode_item);
2215 +
2216 +       uid = btrfs_inode_uid(leaf, inode_item);
2217 +       gid = btrfs_inode_gid(leaf, inode_item);
2218 +       inode->i_uid = INOTAG_UID(DX_TAG(inode), uid, gid);
2219 +       inode->i_gid = INOTAG_GID(DX_TAG(inode), uid, gid);
2220 +       inode->i_tag = INOTAG_TAG(DX_TAG(inode), uid, gid,
2221 +               btrfs_inode_tag(leaf, inode_item));
2222         btrfs_i_size_write(inode, btrfs_inode_size(leaf, inode_item));
2223  
2224         tspec = btrfs_inode_atime(inode_item);
2225 @@ -2341,8 +2350,15 @@ static void fill_inode_item(struct btrfs
2226                             struct btrfs_inode_item *item,
2227                             struct inode *inode)
2228  {
2229 -       btrfs_set_inode_uid(leaf, item, inode->i_uid);
2230 -       btrfs_set_inode_gid(leaf, item, inode->i_gid);
2231 +       uid_t uid = TAGINO_UID(DX_TAG(inode), inode->i_uid, inode->i_tag);
2232 +       gid_t gid = TAGINO_GID(DX_TAG(inode), inode->i_gid, inode->i_tag);
2233 +
2234 +       btrfs_set_inode_uid(leaf, item, uid);
2235 +       btrfs_set_inode_gid(leaf, item, gid);
2236 +#ifdef CONFIG_TAGGING_INTERN
2237 +       btrfs_set_inode_tag(leaf, item, inode->i_tag);
2238 +#endif
2239 +
2240         btrfs_set_inode_size(leaf, item, BTRFS_I(inode)->disk_i_size);
2241         btrfs_set_inode_mode(leaf, item, inode->i_mode);
2242         btrfs_set_inode_nlink(leaf, item, inode->i_nlink);
2243 @@ -4065,6 +4081,7 @@ static struct inode *btrfs_new_inode(str
2244         } else
2245                 inode->i_gid = current_fsgid();
2246  
2247 +       inode->i_tag = dx_current_fstag(root->fs_info->sb);
2248         inode->i_mode = mode;
2249         inode->i_ino = objectid;
2250         inode_set_bytes(inode, 0);
2251 @@ -5836,6 +5853,7 @@ static const struct inode_operations btr
2252         .listxattr      = btrfs_listxattr,
2253         .removexattr    = btrfs_removexattr,
2254         .permission     = btrfs_permission,
2255 +       .sync_flags     = btrfs_sync_flags,
2256  };
2257  static const struct inode_operations btrfs_dir_ro_inode_operations = {
2258         .lookup         = btrfs_lookup,
2259 @@ -5911,6 +5929,7 @@ static const struct inode_operations btr
2260         .permission     = btrfs_permission,
2261         .fallocate      = btrfs_fallocate,
2262         .fiemap         = btrfs_fiemap,
2263 +       .sync_flags     = btrfs_sync_flags,
2264  };
2265  static const struct inode_operations btrfs_special_inode_operations = {
2266         .getattr        = btrfs_getattr,
2267 diff -NurpP --minimal linux-2.6.32.6/fs/btrfs/ioctl.c linux-2.6.32.6-vs2.3.0.36.28/fs/btrfs/ioctl.c
2268 --- linux-2.6.32.6/fs/btrfs/ioctl.c     2009-12-03 20:02:51.000000000 +0100
2269 +++ linux-2.6.32.6-vs2.3.0.36.28/fs/btrfs/ioctl.c       2009-12-03 20:04:56.000000000 +0100
2270 @@ -67,10 +67,13 @@ static unsigned int btrfs_flags_to_ioctl
2271  {
2272         unsigned int iflags = 0;
2273  
2274 -       if (flags & BTRFS_INODE_SYNC)
2275 -               iflags |= FS_SYNC_FL;
2276         if (flags & BTRFS_INODE_IMMUTABLE)
2277                 iflags |= FS_IMMUTABLE_FL;
2278 +       if (flags & BTRFS_INODE_IXUNLINK)
2279 +               iflags |= FS_IXUNLINK_FL;
2280 +
2281 +       if (flags & BTRFS_INODE_SYNC)
2282 +               iflags |= FS_SYNC_FL;
2283         if (flags & BTRFS_INODE_APPEND)
2284                 iflags |= FS_APPEND_FL;
2285         if (flags & BTRFS_INODE_NODUMP)
2286 @@ -80,28 +83,78 @@ static unsigned int btrfs_flags_to_ioctl
2287         if (flags & BTRFS_INODE_DIRSYNC)
2288                 iflags |= FS_DIRSYNC_FL;
2289  
2290 +       if (flags & BTRFS_INODE_BARRIER)
2291 +               iflags |= FS_BARRIER_FL;
2292 +       if (flags & BTRFS_INODE_COW)
2293 +               iflags |= FS_COW_FL;
2294         return iflags;
2295  }
2296  
2297  /*
2298 - * Update inode->i_flags based on the btrfs internal flags.
2299 + * Update inode->i_(v)flags based on the btrfs internal flags.
2300   */
2301  void btrfs_update_iflags(struct inode *inode)
2302  {
2303         struct btrfs_inode *ip = BTRFS_I(inode);
2304  
2305 -       inode->i_flags &= ~(S_SYNC|S_APPEND|S_IMMUTABLE|S_NOATIME|S_DIRSYNC);
2306 +       inode->i_flags &= ~(S_IMMUTABLE | S_IXUNLINK |
2307 +               S_SYNC | S_APPEND | S_NOATIME | S_DIRSYNC);
2308  
2309 -       if (ip->flags & BTRFS_INODE_SYNC)
2310 -               inode->i_flags |= S_SYNC;
2311         if (ip->flags & BTRFS_INODE_IMMUTABLE)
2312                 inode->i_flags |= S_IMMUTABLE;
2313 +       if (ip->flags & BTRFS_INODE_IXUNLINK)
2314 +               inode->i_flags |= S_IXUNLINK;
2315 +
2316 +       if (ip->flags & BTRFS_INODE_SYNC)
2317 +               inode->i_flags |= S_SYNC;
2318         if (ip->flags & BTRFS_INODE_APPEND)
2319                 inode->i_flags |= S_APPEND;
2320         if (ip->flags & BTRFS_INODE_NOATIME)
2321                 inode->i_flags |= S_NOATIME;
2322         if (ip->flags & BTRFS_INODE_DIRSYNC)
2323                 inode->i_flags |= S_DIRSYNC;
2324 +
2325 +       inode->i_vflags &= ~(V_BARRIER | V_COW);
2326 +
2327 +       if (ip->flags & BTRFS_INODE_BARRIER)
2328 +               inode->i_vflags |= V_BARRIER;
2329 +       if (ip->flags & BTRFS_INODE_COW)
2330 +               inode->i_vflags |= V_COW;
2331 +}
2332 +
2333 +/*
2334 + * Update btrfs internal flags from inode->i_(v)flags.
2335 + */
2336 +void btrfs_update_flags(struct inode *inode)
2337 +{
2338 +       struct btrfs_inode *ip = BTRFS_I(inode);
2339 +
2340 +       unsigned int flags = inode->i_flags;
2341 +       unsigned int vflags = inode->i_vflags;
2342 +
2343 +       ip->flags &= ~(BTRFS_INODE_SYNC | BTRFS_INODE_APPEND |
2344 +                       BTRFS_INODE_IMMUTABLE | BTRFS_INODE_IXUNLINK |
2345 +                       BTRFS_INODE_NOATIME | BTRFS_INODE_DIRSYNC |
2346 +                       BTRFS_INODE_BARRIER | BTRFS_INODE_COW);
2347 +
2348 +       if (flags & S_IMMUTABLE)
2349 +               ip->flags |= BTRFS_INODE_IMMUTABLE;
2350 +       if (flags & S_IXUNLINK)
2351 +               ip->flags |= BTRFS_INODE_IXUNLINK;
2352 +
2353 +       if (flags & S_SYNC)
2354 +               ip->flags |= BTRFS_INODE_SYNC;
2355 +       if (flags & S_APPEND)
2356 +               ip->flags |= BTRFS_INODE_APPEND;
2357 +       if (flags & S_NOATIME)
2358 +               ip->flags |= BTRFS_INODE_NOATIME;
2359 +       if (flags & S_DIRSYNC)
2360 +               ip->flags |= BTRFS_INODE_DIRSYNC;
2361 +
2362 +       if (vflags & V_BARRIER)
2363 +               ip->flags |= BTRFS_INODE_BARRIER;
2364 +       if (vflags & V_COW)
2365 +               ip->flags |= BTRFS_INODE_COW;
2366  }
2367  
2368  /*
2369 @@ -119,7 +172,7 @@ void btrfs_inherit_iflags(struct inode *
2370         flags = BTRFS_I(dir)->flags;
2371  
2372         if (S_ISREG(inode->i_mode))
2373 -               flags &= ~BTRFS_INODE_DIRSYNC;
2374 +               flags &= ~(BTRFS_INODE_DIRSYNC | BTRFS_INODE_BARRIER);
2375         else if (!S_ISDIR(inode->i_mode))
2376                 flags &= (BTRFS_INODE_NODUMP | BTRFS_INODE_NOATIME);
2377  
2378 @@ -127,6 +180,30 @@ void btrfs_inherit_iflags(struct inode *
2379         btrfs_update_iflags(inode);
2380  }
2381  
2382 +int btrfs_sync_flags(struct inode *inode, int flags, int vflags)
2383 +{
2384 +       struct btrfs_inode *ip = BTRFS_I(inode);
2385 +       struct btrfs_root *root = ip->root;
2386 +       struct btrfs_trans_handle *trans;
2387 +       int ret;
2388 +
2389 +       trans = btrfs_join_transaction(root, 1);
2390 +       BUG_ON(!trans);
2391 +
2392 +       inode->i_flags = flags;
2393 +       inode->i_vflags = vflags;
2394 +       btrfs_update_flags(inode);
2395 +
2396 +       ret = btrfs_update_inode(trans, root, inode);
2397 +       BUG_ON(ret);
2398 +
2399 +       btrfs_update_iflags(inode);
2400 +       inode->i_ctime = CURRENT_TIME;
2401 +       btrfs_end_transaction(trans, root);
2402 +
2403 +       return 0;
2404 +}
2405 +
2406  static int btrfs_ioctl_getflags(struct file *file, void __user *arg)
2407  {
2408         struct btrfs_inode *ip = BTRFS_I(file->f_path.dentry->d_inode);
2409 @@ -149,6 +226,7 @@ static int btrfs_ioctl_setflags(struct f
2410         if (copy_from_user(&flags, arg, sizeof(flags)))
2411                 return -EFAULT;
2412  
2413 +       /* maybe add FS_IXUNLINK_FL ? */
2414         if (flags & ~(FS_IMMUTABLE_FL | FS_APPEND_FL | \
2415                       FS_NOATIME_FL | FS_NODUMP_FL | \
2416                       FS_SYNC_FL | FS_DIRSYNC_FL))
2417 @@ -161,7 +239,8 @@ static int btrfs_ioctl_setflags(struct f
2418  
2419         flags = btrfs_mask_flags(inode->i_mode, flags);
2420         oldflags = btrfs_flags_to_ioctl(ip->flags);
2421 -       if ((flags ^ oldflags) & (FS_APPEND_FL | FS_IMMUTABLE_FL)) {
2422 +       if ((flags ^ oldflags) & (FS_APPEND_FL |
2423 +               FS_IMMUTABLE_FL | FS_IXUNLINK_FL)) {
2424                 if (!capable(CAP_LINUX_IMMUTABLE)) {
2425                         ret = -EPERM;
2426                         goto out_unlock;
2427 @@ -172,14 +251,19 @@ static int btrfs_ioctl_setflags(struct f
2428         if (ret)
2429                 goto out_unlock;
2430  
2431 -       if (flags & FS_SYNC_FL)
2432 -               ip->flags |= BTRFS_INODE_SYNC;
2433 -       else
2434 -               ip->flags &= ~BTRFS_INODE_SYNC;
2435         if (flags & FS_IMMUTABLE_FL)
2436                 ip->flags |= BTRFS_INODE_IMMUTABLE;
2437         else
2438                 ip->flags &= ~BTRFS_INODE_IMMUTABLE;
2439 +       if (flags & FS_IXUNLINK_FL)
2440 +               ip->flags |= BTRFS_INODE_IXUNLINK;
2441 +       else
2442 +               ip->flags &= ~BTRFS_INODE_IXUNLINK;
2443 +
2444 +       if (flags & FS_SYNC_FL)
2445 +               ip->flags |= BTRFS_INODE_SYNC;
2446 +       else
2447 +               ip->flags &= ~BTRFS_INODE_SYNC;
2448         if (flags & FS_APPEND_FL)
2449                 ip->flags |= BTRFS_INODE_APPEND;
2450         else
2451 diff -NurpP --minimal linux-2.6.32.6/fs/btrfs/super.c linux-2.6.32.6-vs2.3.0.36.28/fs/btrfs/super.c
2452 --- linux-2.6.32.6/fs/btrfs/super.c     2009-12-03 20:02:51.000000000 +0100
2453 +++ linux-2.6.32.6-vs2.3.0.36.28/fs/btrfs/super.c       2009-12-03 20:04:56.000000000 +0100
2454 @@ -67,7 +67,7 @@ enum {
2455         Opt_max_extent, Opt_max_inline, Opt_alloc_start, Opt_nobarrier,
2456         Opt_ssd, Opt_nossd, Opt_ssd_spread, Opt_thread_pool, Opt_noacl,
2457         Opt_compress, Opt_notreelog, Opt_ratio, Opt_flushoncommit,
2458 -       Opt_discard, Opt_err,
2459 +       Opt_tag, Opt_notag, Opt_tagid, Opt_discard, Opt_err,
2460  };
2461  
2462  static match_table_t tokens = {
2463 @@ -90,6 +90,9 @@ static match_table_t tokens = {
2464         {Opt_flushoncommit, "flushoncommit"},
2465         {Opt_ratio, "metadata_ratio=%d"},
2466         {Opt_discard, "discard"},
2467 +       {Opt_tag, "tag"},
2468 +       {Opt_notag, "notag"},
2469 +       {Opt_tagid, "tagid=%u"},
2470         {Opt_err, NULL},
2471  };
2472  
2473 @@ -262,6 +265,22 @@ int btrfs_parse_options(struct btrfs_roo
2474                 case Opt_discard:
2475                         btrfs_set_opt(info->mount_opt, DISCARD);
2476                         break;
2477 +#ifndef CONFIG_TAGGING_NONE
2478 +               case Opt_tag:
2479 +                       printk(KERN_INFO "btrfs: use tagging\n");
2480 +                       btrfs_set_opt(info->mount_opt, TAGGED);
2481 +                       break;
2482 +               case Opt_notag:
2483 +                       printk(KERN_INFO "btrfs: disabled tagging\n");
2484 +                       btrfs_clear_opt(info->mount_opt, TAGGED);
2485 +                       break;
2486 +#endif
2487 +#ifdef CONFIG_PROPAGATE
2488 +               case Opt_tagid:
2489 +                       /* use args[0] */
2490 +                       btrfs_set_opt(info->mount_opt, TAGGED);
2491 +                       break;
2492 +#endif
2493                 default:
2494                         break;
2495                 }
2496 @@ -575,6 +594,12 @@ static int btrfs_remount(struct super_bl
2497         if (ret)
2498                 return -EINVAL;
2499  
2500 +       if (btrfs_test_opt(root, TAGGED) && !(sb->s_flags & MS_TAGGED)) {
2501 +               printk("btrfs: %s: tagging not permitted on remount.\n",
2502 +                       sb->s_id);
2503 +               return -EINVAL;
2504 +       }
2505 +
2506         if ((*flags & MS_RDONLY) == (sb->s_flags & MS_RDONLY))
2507                 return 0;
2508  
2509 diff -NurpP --minimal linux-2.6.32.6/fs/char_dev.c linux-2.6.32.6-vs2.3.0.36.28/fs/char_dev.c
2510 --- linux-2.6.32.6/fs/char_dev.c        2009-12-03 20:02:51.000000000 +0100
2511 +++ linux-2.6.32.6-vs2.3.0.36.28/fs/char_dev.c  2009-12-03 20:04:56.000000000 +0100
2512 @@ -20,6 +20,8 @@
2513  #include <linux/cdev.h>
2514  #include <linux/mutex.h>
2515  #include <linux/backing-dev.h>
2516 +#include <linux/vs_context.h>
2517 +#include <linux/vs_device.h>
2518  
2519  #include "internal.h"
2520  
2521 @@ -368,14 +370,21 @@ static int chrdev_open(struct inode *ino
2522         struct cdev *p;
2523         struct cdev *new = NULL;
2524         int ret = 0;
2525 +       dev_t mdev;
2526 +
2527 +       if (!vs_map_chrdev(inode->i_rdev, &mdev, DATTR_OPEN))
2528 +               return -EPERM;
2529 +       inode->i_mdev = mdev;
2530  
2531         spin_lock(&cdev_lock);
2532         p = inode->i_cdev;
2533         if (!p) {
2534                 struct kobject *kobj;
2535                 int idx;
2536 +
2537                 spin_unlock(&cdev_lock);
2538 -               kobj = kobj_lookup(cdev_map, inode->i_rdev, &idx);
2539 +
2540 +               kobj = kobj_lookup(cdev_map, mdev, &idx);
2541                 if (!kobj)
2542                         return -ENXIO;
2543                 new = container_of(kobj, struct cdev, kobj);
2544 diff -NurpP --minimal linux-2.6.32.6/fs/dcache.c linux-2.6.32.6-vs2.3.0.36.28/fs/dcache.c
2545 --- linux-2.6.32.6/fs/dcache.c  2009-12-03 20:02:51.000000000 +0100
2546 +++ linux-2.6.32.6-vs2.3.0.36.28/fs/dcache.c    2009-12-03 20:04:56.000000000 +0100
2547 @@ -33,6 +33,7 @@
2548  #include <linux/bootmem.h>
2549  #include <linux/fs_struct.h>
2550  #include <linux/hardirq.h>
2551 +#include <linux/vs_limit.h>
2552  #include "internal.h"
2553  
2554  int sysctl_vfs_cache_pressure __read_mostly = 100;
2555 @@ -230,6 +231,8 @@ repeat:
2556                 return;
2557         }
2558  
2559 +       vx_dentry_dec(dentry);
2560 +
2561         /*
2562          * AV: ->d_delete() is _NOT_ allowed to block now.
2563          */
2564 @@ -321,6 +324,7 @@ static inline struct dentry * __dget_loc
2565  {
2566         atomic_inc(&dentry->d_count);
2567         dentry_lru_del_init(dentry);
2568 +       vx_dentry_inc(dentry);
2569         return dentry;
2570  }
2571  
2572 @@ -919,6 +923,9 @@ struct dentry *d_alloc(struct dentry * p
2573         struct dentry *dentry;
2574         char *dname;
2575  
2576 +       if (!vx_dentry_avail(1))
2577 +               return NULL;
2578 +
2579         dentry = kmem_cache_alloc(dentry_cache, GFP_KERNEL);
2580         if (!dentry)
2581                 return NULL;
2582 @@ -964,6 +971,7 @@ struct dentry *d_alloc(struct dentry * p
2583         if (parent)
2584                 list_add(&dentry->d_u.d_child, &parent->d_subdirs);
2585         dentry_stat.nr_dentry++;
2586 +       vx_dentry_inc(dentry);
2587         spin_unlock(&dcache_lock);
2588  
2589         return dentry;
2590 @@ -1407,6 +1415,7 @@ struct dentry * __d_lookup(struct dentry
2591                 }
2592  
2593                 atomic_inc(&dentry->d_count);
2594 +               vx_dentry_inc(dentry);
2595                 found = dentry;
2596                 spin_unlock(&dentry->d_lock);
2597                 break;
2598 diff -NurpP --minimal linux-2.6.32.6/fs/devpts/inode.c linux-2.6.32.6-vs2.3.0.36.28/fs/devpts/inode.c
2599 --- linux-2.6.32.6/fs/devpts/inode.c    2010-01-26 19:31:26.000000000 +0100
2600 +++ linux-2.6.32.6-vs2.3.0.36.28/fs/devpts/inode.c      2009-12-29 00:36:26.000000000 +0100
2601 @@ -24,6 +24,7 @@
2602  #include <linux/parser.h>
2603  #include <linux/fsnotify.h>
2604  #include <linux/seq_file.h>
2605 +#include <linux/vs_base.h>
2606  
2607  #define DEVPTS_DEFAULT_MODE 0600
2608  /*
2609 @@ -35,6 +36,20 @@
2610  #define DEVPTS_DEFAULT_PTMX_MODE 0000
2611  #define PTMX_MINOR     2
2612  
2613 +static int devpts_permission(struct inode *inode, int mask)
2614 +{
2615 +       int ret = -EACCES;
2616 +
2617 +       /* devpts is xid tagged */
2618 +       if (vx_check((xid_t)inode->i_tag, VS_WATCH_P | VS_IDENT))
2619 +               ret = generic_permission(inode, mask, NULL);
2620 +       return ret;
2621 +}
2622 +
2623 +static struct inode_operations devpts_file_inode_operations = {
2624 +       .permission     = devpts_permission,
2625 +};
2626 +
2627  extern int pty_limit;                  /* Config limit on Unix98 ptys */
2628  static DEFINE_MUTEX(allocated_ptys_lock);
2629  
2630 @@ -262,6 +277,25 @@ static int devpts_show_options(struct se
2631         return 0;
2632  }
2633  
2634 +static int devpts_filter(struct dentry *de)
2635 +{
2636 +       /* devpts is xid tagged */
2637 +       return vx_check((xid_t)de->d_inode->i_tag, VS_WATCH_P | VS_IDENT);
2638 +}
2639 +
2640 +static int devpts_readdir(struct file * filp, void * dirent, filldir_t filldir)
2641 +{
2642 +       return dcache_readdir_filter(filp, dirent, filldir, devpts_filter);
2643 +}
2644 +
2645 +static struct file_operations devpts_dir_operations = {
2646 +       .open           = dcache_dir_open,
2647 +       .release        = dcache_dir_close,
2648 +       .llseek         = dcache_dir_lseek,
2649 +       .read           = generic_read_dir,
2650 +       .readdir        = devpts_readdir,
2651 +};
2652 +
2653  static const struct super_operations devpts_sops = {
2654         .statfs         = simple_statfs,
2655         .remount_fs     = devpts_remount,
2656 @@ -301,12 +335,15 @@ devpts_fill_super(struct super_block *s,
2657         inode = new_inode(s);
2658         if (!inode)
2659                 goto free_fsi;
2660 +
2661         inode->i_ino = 1;
2662         inode->i_mtime = inode->i_atime = inode->i_ctime = CURRENT_TIME;
2663         inode->i_mode = S_IFDIR | S_IRUGO | S_IXUGO | S_IWUSR;
2664         inode->i_op = &simple_dir_inode_operations;
2665 -       inode->i_fop = &simple_dir_operations;
2666 +       inode->i_fop = &devpts_dir_operations;
2667         inode->i_nlink = 2;
2668 +       /* devpts is xid tagged */
2669 +       inode->i_tag = (tag_t)vx_current_xid();
2670  
2671         s->s_root = d_alloc_root(inode);
2672         if (s->s_root)
2673 @@ -497,6 +534,9 @@ int devpts_pty_new(struct inode *ptmx_in
2674         inode->i_gid = opts->setgid ? opts->gid : current_fsgid();
2675         inode->i_mtime = inode->i_atime = inode->i_ctime = CURRENT_TIME;
2676         init_special_inode(inode, S_IFCHR|opts->mode, device);
2677 +       /* devpts is xid tagged */
2678 +       inode->i_tag = (tag_t)vx_current_xid();
2679 +       inode->i_op = &devpts_file_inode_operations;
2680         inode->i_private = tty;
2681         tty->driver_data = inode;
2682  
2683 diff -NurpP --minimal linux-2.6.32.6/fs/exec.c linux-2.6.32.6-vs2.3.0.36.28/fs/exec.c
2684 --- linux-2.6.32.6/fs/exec.c    2009-12-03 20:02:51.000000000 +0100
2685 +++ linux-2.6.32.6-vs2.3.0.36.28/fs/exec.c      2009-12-30 00:58:19.000000000 +0100
2686 @@ -251,7 +251,9 @@ static int __bprm_mm_init(struct linux_b
2687         if (err)
2688                 goto err;
2689  
2690 -       mm->stack_vm = mm->total_vm = 1;
2691 +       mm->total_vm = 0;
2692 +       vx_vmpages_inc(mm);
2693 +       mm->stack_vm = 1;
2694         up_write(&mm->mmap_sem);
2695         bprm->p = vma->vm_end - sizeof(void *);
2696         return 0;
2697 @@ -1474,7 +1476,7 @@ static int format_corename(char *corenam
2698                         /* UNIX time of coredump */
2699                         case 't': {
2700                                 struct timeval tv;
2701 -                               do_gettimeofday(&tv);
2702 +                               vx_gettimeofday(&tv);
2703                                 rc = snprintf(out_ptr, out_end - out_ptr,
2704                                               "%lu", tv.tv_sec);
2705                                 if (rc > out_end - out_ptr)
2706 diff -NurpP --minimal linux-2.6.32.6/fs/ext2/balloc.c linux-2.6.32.6-vs2.3.0.36.28/fs/ext2/balloc.c
2707 --- linux-2.6.32.6/fs/ext2/balloc.c     2009-06-11 17:13:03.000000000 +0200
2708 +++ linux-2.6.32.6-vs2.3.0.36.28/fs/ext2/balloc.c       2009-12-03 20:04:56.000000000 +0100
2709 @@ -701,7 +701,6 @@ ext2_try_to_allocate(struct super_block 
2710                         start = 0;
2711                 end = EXT2_BLOCKS_PER_GROUP(sb);
2712         }
2713 -
2714         BUG_ON(start > EXT2_BLOCKS_PER_GROUP(sb));
2715  
2716  repeat:
2717 diff -NurpP --minimal linux-2.6.32.6/fs/ext2/ext2.h linux-2.6.32.6-vs2.3.0.36.28/fs/ext2/ext2.h
2718 --- linux-2.6.32.6/fs/ext2/ext2.h       2009-09-10 15:26:21.000000000 +0200
2719 +++ linux-2.6.32.6-vs2.3.0.36.28/fs/ext2/ext2.h 2009-12-03 20:04:56.000000000 +0100
2720 @@ -131,6 +131,7 @@ extern int ext2_fiemap(struct inode *ino
2721  int __ext2_write_begin(struct file *file, struct address_space *mapping,
2722                 loff_t pos, unsigned len, unsigned flags,
2723                 struct page **pagep, void **fsdata);
2724 +extern int ext2_sync_flags(struct inode *, int, int);
2725  
2726  /* ioctl.c */
2727  extern long ext2_ioctl(struct file *, unsigned int, unsigned long);
2728 diff -NurpP --minimal linux-2.6.32.6/fs/ext2/file.c linux-2.6.32.6-vs2.3.0.36.28/fs/ext2/file.c
2729 --- linux-2.6.32.6/fs/ext2/file.c       2009-12-03 20:02:51.000000000 +0100
2730 +++ linux-2.6.32.6-vs2.3.0.36.28/fs/ext2/file.c 2009-12-03 20:04:56.000000000 +0100
2731 @@ -87,4 +87,5 @@ const struct inode_operations ext2_file_
2732         .setattr        = ext2_setattr,
2733         .check_acl      = ext2_check_acl,
2734         .fiemap         = ext2_fiemap,
2735 +       .sync_flags     = ext2_sync_flags,
2736  };
2737 diff -NurpP --minimal linux-2.6.32.6/fs/ext2/ialloc.c linux-2.6.32.6-vs2.3.0.36.28/fs/ext2/ialloc.c
2738 --- linux-2.6.32.6/fs/ext2/ialloc.c     2009-06-11 17:13:03.000000000 +0200
2739 +++ linux-2.6.32.6-vs2.3.0.36.28/fs/ext2/ialloc.c       2009-12-03 20:04:56.000000000 +0100
2740 @@ -17,6 +17,7 @@
2741  #include <linux/backing-dev.h>
2742  #include <linux/buffer_head.h>
2743  #include <linux/random.h>
2744 +#include <linux/vs_tag.h>
2745  #include "ext2.h"
2746  #include "xattr.h"
2747  #include "acl.h"
2748 @@ -560,6 +561,7 @@ got:
2749         } else
2750                 inode->i_gid = current_fsgid();
2751         inode->i_mode = mode;
2752 +       inode->i_tag = dx_current_fstag(sb);
2753  
2754         inode->i_ino = ino;
2755         inode->i_blocks = 0;
2756 diff -NurpP --minimal linux-2.6.32.6/fs/ext2/inode.c linux-2.6.32.6-vs2.3.0.36.28/fs/ext2/inode.c
2757 --- linux-2.6.32.6/fs/ext2/inode.c      2009-12-03 20:02:51.000000000 +0100
2758 +++ linux-2.6.32.6-vs2.3.0.36.28/fs/ext2/inode.c        2009-12-03 20:04:56.000000000 +0100
2759 @@ -33,6 +33,7 @@
2760  #include <linux/mpage.h>
2761  #include <linux/fiemap.h>
2762  #include <linux/namei.h>
2763 +#include <linux/vs_tag.h>
2764  #include "ext2.h"
2765  #include "acl.h"
2766  #include "xip.h"
2767 @@ -1040,7 +1041,7 @@ void ext2_truncate(struct inode *inode)
2768                 return;
2769         if (ext2_inode_is_fast_symlink(inode))
2770                 return;
2771 -       if (IS_APPEND(inode) || IS_IMMUTABLE(inode))
2772 +       if (IS_APPEND(inode) || IS_IXORUNLINK(inode))
2773                 return;
2774  
2775         blocksize = inode->i_sb->s_blocksize;
2776 @@ -1178,36 +1179,61 @@ void ext2_set_inode_flags(struct inode *
2777  {
2778         unsigned int flags = EXT2_I(inode)->i_flags;
2779  
2780 -       inode->i_flags &= ~(S_SYNC|S_APPEND|S_IMMUTABLE|S_NOATIME|S_DIRSYNC);
2781 +       inode->i_flags &= ~(S_IMMUTABLE | S_IXUNLINK |
2782 +               S_SYNC | S_APPEND | S_NOATIME | S_DIRSYNC);
2783 +
2784 +
2785 +       if (flags & EXT2_IMMUTABLE_FL)
2786 +               inode->i_flags |= S_IMMUTABLE;
2787 +       if (flags & EXT2_IXUNLINK_FL)
2788 +               inode->i_flags |= S_IXUNLINK;
2789 +
2790         if (flags & EXT2_SYNC_FL)
2791                 inode->i_flags |= S_SYNC;
2792         if (flags & EXT2_APPEND_FL)
2793                 inode->i_flags |= S_APPEND;
2794 -       if (flags & EXT2_IMMUTABLE_FL)
2795 -               inode->i_flags |= S_IMMUTABLE;
2796         if (flags & EXT2_NOATIME_FL)
2797                 inode->i_flags |= S_NOATIME;
2798         if (flags & EXT2_DIRSYNC_FL)
2799                 inode->i_flags |= S_DIRSYNC;
2800 +
2801 +       inode->i_vflags &= ~(V_BARRIER | V_COW);
2802 +
2803 +       if (flags & EXT2_BARRIER_FL)
2804 +               inode->i_vflags |= V_BARRIER;
2805 +       if (flags & EXT2_COW_FL)
2806 +               inode->i_vflags |= V_COW;
2807  }
2808  
2809  /* Propagate flags from i_flags to EXT2_I(inode)->i_flags */
2810  void ext2_get_inode_flags(struct ext2_inode_info *ei)
2811  {
2812         unsigned int flags = ei->vfs_inode.i_flags;
2813 +       unsigned int vflags = ei->vfs_inode.i_vflags;
2814 +
2815 +       ei->i_flags &= ~(EXT2_SYNC_FL | EXT2_APPEND_FL |
2816 +                       EXT2_IMMUTABLE_FL | EXT2_IXUNLINK_FL |
2817 +                       EXT2_NOATIME_FL | EXT2_DIRSYNC_FL |
2818 +                       EXT2_BARRIER_FL | EXT2_COW_FL);
2819 +
2820 +       if (flags & S_IMMUTABLE)
2821 +               ei->i_flags |= EXT2_IMMUTABLE_FL;
2822 +       if (flags & S_IXUNLINK)
2823 +               ei->i_flags |= EXT2_IXUNLINK_FL;
2824  
2825 -       ei->i_flags &= ~(EXT2_SYNC_FL|EXT2_APPEND_FL|
2826 -                       EXT2_IMMUTABLE_FL|EXT2_NOATIME_FL|EXT2_DIRSYNC_FL);
2827         if (flags & S_SYNC)
2828                 ei->i_flags |= EXT2_SYNC_FL;
2829         if (flags & S_APPEND)
2830                 ei->i_flags |= EXT2_APPEND_FL;
2831 -       if (flags & S_IMMUTABLE)
2832 -               ei->i_flags |= EXT2_IMMUTABLE_FL;
2833         if (flags & S_NOATIME)
2834                 ei->i_flags |= EXT2_NOATIME_FL;
2835         if (flags & S_DIRSYNC)
2836                 ei->i_flags |= EXT2_DIRSYNC_FL;
2837 +
2838 +       if (vflags & V_BARRIER)
2839 +               ei->i_flags |= EXT2_BARRIER_FL;
2840 +       if (vflags & V_COW)
2841 +               ei->i_flags |= EXT2_COW_FL;
2842  }
2843  
2844  struct inode *ext2_iget (struct super_block *sb, unsigned long ino)
2845 @@ -1217,6 +1243,8 @@ struct inode *ext2_iget (struct super_bl
2846         struct ext2_inode *raw_inode;
2847         struct inode *inode;
2848         long ret = -EIO;
2849 +       uid_t uid;
2850 +       gid_t gid;
2851         int n;
2852  
2853         inode = iget_locked(sb, ino);
2854 @@ -1235,12 +1263,17 @@ struct inode *ext2_iget (struct super_bl
2855         }
2856  
2857         inode->i_mode = le16_to_cpu(raw_inode->i_mode);
2858 -       inode->i_uid = (uid_t)le16_to_cpu(raw_inode->i_uid_low);
2859 -       inode->i_gid = (gid_t)le16_to_cpu(raw_inode->i_gid_low);
2860 +       uid = (uid_t)le16_to_cpu(raw_inode->i_uid_low);
2861 +       gid = (gid_t)le16_to_cpu(raw_inode->i_gid_low);
2862         if (!(test_opt (inode->i_sb, NO_UID32))) {
2863 -               inode->i_uid |= le16_to_cpu(raw_inode->i_uid_high) << 16;
2864 -               inode->i_gid |= le16_to_cpu(raw_inode->i_gid_high) << 16;
2865 +               uid |= le16_to_cpu(raw_inode->i_uid_high) << 16;
2866 +               gid |= le16_to_cpu(raw_inode->i_gid_high) << 16;
2867         }
2868 +       inode->i_uid = INOTAG_UID(DX_TAG(inode), uid, gid);
2869 +       inode->i_gid = INOTAG_GID(DX_TAG(inode), uid, gid);
2870 +       inode->i_tag = INOTAG_TAG(DX_TAG(inode), uid, gid,
2871 +               le16_to_cpu(raw_inode->i_raw_tag));
2872 +
2873         inode->i_nlink = le16_to_cpu(raw_inode->i_links_count);
2874         inode->i_size = le32_to_cpu(raw_inode->i_size);
2875         inode->i_atime.tv_sec = (signed)le32_to_cpu(raw_inode->i_atime);
2876 @@ -1338,8 +1371,8 @@ int ext2_write_inode(struct inode *inode
2877         struct ext2_inode_info *ei = EXT2_I(inode);
2878         struct super_block *sb = inode->i_sb;
2879         ino_t ino = inode->i_ino;
2880 -       uid_t uid = inode->i_uid;
2881 -       gid_t gid = inode->i_gid;
2882 +       uid_t uid = TAGINO_UID(DX_TAG(inode), inode->i_uid, inode->i_tag);
2883 +       gid_t gid = TAGINO_GID(DX_TAG(inode), inode->i_gid, inode->i_tag);
2884         struct buffer_head * bh;
2885         struct ext2_inode * raw_inode = ext2_get_inode(sb, ino, &bh);
2886         int n;
2887 @@ -1375,6 +1408,9 @@ int ext2_write_inode(struct inode *inode
2888                 raw_inode->i_uid_high = 0;
2889                 raw_inode->i_gid_high = 0;
2890         }
2891 +#ifdef CONFIG_TAGGING_INTERN
2892 +       raw_inode->i_raw_tag = cpu_to_le16(inode->i_tag);
2893 +#endif
2894         raw_inode->i_links_count = cpu_to_le16(inode->i_nlink);
2895         raw_inode->i_size = cpu_to_le32(inode->i_size);
2896         raw_inode->i_atime = cpu_to_le32(inode->i_atime.tv_sec);
2897 @@ -1456,7 +1492,8 @@ int ext2_setattr(struct dentry *dentry, 
2898         if (error)
2899                 return error;
2900         if ((iattr->ia_valid & ATTR_UID && iattr->ia_uid != inode->i_uid) ||
2901 -           (iattr->ia_valid & ATTR_GID && iattr->ia_gid != inode->i_gid)) {
2902 +           (iattr->ia_valid & ATTR_GID && iattr->ia_gid != inode->i_gid) ||
2903 +           (iattr->ia_valid & ATTR_TAG && iattr->ia_tag != inode->i_tag)) {
2904                 error = vfs_dq_transfer(inode, iattr) ? -EDQUOT : 0;
2905                 if (error)
2906                         return error;
2907 diff -NurpP --minimal linux-2.6.32.6/fs/ext2/ioctl.c linux-2.6.32.6-vs2.3.0.36.28/fs/ext2/ioctl.c
2908 --- linux-2.6.32.6/fs/ext2/ioctl.c      2009-09-10 15:26:21.000000000 +0200
2909 +++ linux-2.6.32.6-vs2.3.0.36.28/fs/ext2/ioctl.c        2009-12-03 20:04:56.000000000 +0100
2910 @@ -17,6 +17,16 @@
2911  #include <asm/uaccess.h>
2912  
2913  
2914 +int ext2_sync_flags(struct inode *inode, int flags, int vflags)
2915 +{
2916 +       inode->i_flags = flags;
2917 +       inode->i_vflags = vflags;
2918 +       ext2_get_inode_flags(EXT2_I(inode));
2919 +       inode->i_ctime = CURRENT_TIME_SEC;
2920 +       mark_inode_dirty(inode);
2921 +       return 0;
2922 +}
2923 +
2924  long ext2_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
2925  {
2926         struct inode *inode = filp->f_dentry->d_inode;
2927 @@ -51,6 +61,11 @@ long ext2_ioctl(struct file *filp, unsig
2928  
2929                 flags = ext2_mask_flags(inode->i_mode, flags);
2930  
2931 +               if (IS_BARRIER(inode)) {
2932 +                       vxwprintk_task(1, "messing with the barrier.");
2933 +                       return -EACCES;
2934 +               }
2935 +
2936                 mutex_lock(&inode->i_mutex);
2937                 /* Is it quota file? Do not allow user to mess with it */
2938                 if (IS_NOQUOTA(inode)) {
2939 @@ -66,7 +81,9 @@ long ext2_ioctl(struct file *filp, unsig
2940                  *
2941                  * This test looks nicer. Thanks to Pauline Middelink
2942                  */
2943 -               if ((flags ^ oldflags) & (EXT2_APPEND_FL | EXT2_IMMUTABLE_FL)) {
2944 +               if ((oldflags & EXT2_IMMUTABLE_FL) ||
2945 +                       ((flags ^ oldflags) & (EXT2_APPEND_FL |
2946 +                       EXT2_IMMUTABLE_FL | EXT2_IXUNLINK_FL))) {
2947                         if (!capable(CAP_LINUX_IMMUTABLE)) {
2948                                 mutex_unlock(&inode->i_mutex);
2949                                 ret = -EPERM;
2950 @@ -74,7 +91,7 @@ long ext2_ioctl(struct file *filp, unsig
2951                         }
2952                 }
2953  
2954 -               flags = flags & EXT2_FL_USER_MODIFIABLE;
2955 +               flags &= EXT2_FL_USER_MODIFIABLE;
2956                 flags |= oldflags & ~EXT2_FL_USER_MODIFIABLE;
2957                 ei->i_flags = flags;
2958                 mutex_unlock(&inode->i_mutex);
2959 diff -NurpP --minimal linux-2.6.32.6/fs/ext2/namei.c linux-2.6.32.6-vs2.3.0.36.28/fs/ext2/namei.c
2960 --- linux-2.6.32.6/fs/ext2/namei.c      2009-12-03 20:02:51.000000000 +0100
2961 +++ linux-2.6.32.6-vs2.3.0.36.28/fs/ext2/namei.c        2009-12-03 20:04:56.000000000 +0100
2962 @@ -31,6 +31,7 @@
2963   */
2964  
2965  #include <linux/pagemap.h>
2966 +#include <linux/vs_tag.h>
2967  #include "ext2.h"
2968  #include "xattr.h"
2969  #include "acl.h"
2970 @@ -74,6 +75,7 @@ static struct dentry *ext2_lookup(struct
2971                                 return ERR_PTR(-EIO);
2972                         } else {
2973                                 return ERR_CAST(inode);
2974 +               dx_propagate_tag(nd, inode);
2975                         }
2976                 }
2977         }
2978 @@ -401,6 +403,7 @@ const struct inode_operations ext2_dir_i
2979  #endif
2980         .setattr        = ext2_setattr,
2981         .check_acl      = ext2_check_acl,
2982 +       .sync_flags     = ext2_sync_flags,
2983  };
2984  
2985  const struct inode_operations ext2_special_inode_operations = {
2986 diff -NurpP --minimal linux-2.6.32.6/fs/ext2/super.c linux-2.6.32.6-vs2.3.0.36.28/fs/ext2/super.c
2987 --- linux-2.6.32.6/fs/ext2/super.c      2009-09-10 15:26:21.000000000 +0200
2988 +++ linux-2.6.32.6-vs2.3.0.36.28/fs/ext2/super.c        2009-12-03 20:04:56.000000000 +0100
2989 @@ -382,7 +382,8 @@ enum {
2990         Opt_err_ro, Opt_nouid32, Opt_nocheck, Opt_debug,
2991         Opt_oldalloc, Opt_orlov, Opt_nobh, Opt_user_xattr, Opt_nouser_xattr,
2992         Opt_acl, Opt_noacl, Opt_xip, Opt_ignore, Opt_err, Opt_quota,
2993 -       Opt_usrquota, Opt_grpquota, Opt_reservation, Opt_noreservation
2994 +       Opt_usrquota, Opt_grpquota, Opt_reservation, Opt_noreservation,
2995 +       Opt_tag, Opt_notag, Opt_tagid
2996  };
2997  
2998  static const match_table_t tokens = {
2999 @@ -410,6 +411,9 @@ static const match_table_t tokens = {
3000         {Opt_acl, "acl"},
3001         {Opt_noacl, "noacl"},
3002         {Opt_xip, "xip"},
3003 +       {Opt_tag, "tag"},
3004 +       {Opt_notag, "notag"},
3005 +       {Opt_tagid, "tagid=%u"},
3006         {Opt_grpquota, "grpquota"},
3007         {Opt_ignore, "noquota"},
3008         {Opt_quota, "quota"},
3009 @@ -480,6 +484,20 @@ static int parse_options (char * options
3010                 case Opt_nouid32:
3011                         set_opt (sbi->s_mount_opt, NO_UID32);
3012                         break;
3013 +#ifndef CONFIG_TAGGING_NONE
3014 +               case Opt_tag:
3015 +                       set_opt (sbi->s_mount_opt, TAGGED);
3016 +                       break;
3017 +               case Opt_notag:
3018 +                       clear_opt (sbi->s_mount_opt, TAGGED);
3019 +                       break;
3020 +#endif
3021 +#ifdef CONFIG_PROPAGATE
3022 +               case Opt_tagid:
3023 +                       /* use args[0] */
3024 +                       set_opt (sbi->s_mount_opt, TAGGED);
3025 +                       break;
3026 +#endif
3027                 case Opt_nocheck:
3028                         clear_opt (sbi->s_mount_opt, CHECK);
3029                         break;
3030 @@ -829,6 +847,8 @@ static int ext2_fill_super(struct super_
3031         if (!parse_options ((char *) data, sbi))
3032                 goto failed_mount;
3033  
3034 +       if (EXT2_SB(sb)->s_mount_opt & EXT2_MOUNT_TAGGED)
3035 +               sb->s_flags |= MS_TAGGED;
3036         sb->s_flags = (sb->s_flags & ~MS_POSIXACL) |
3037                 ((EXT2_SB(sb)->s_mount_opt & EXT2_MOUNT_POSIX_ACL) ?
3038                  MS_POSIXACL : 0);
3039 @@ -1175,6 +1195,14 @@ static int ext2_remount (struct super_bl
3040                 goto restore_opts;
3041         }
3042  
3043 +       if ((sbi->s_mount_opt & EXT2_MOUNT_TAGGED) &&
3044 +               !(sb->s_flags & MS_TAGGED)) {
3045 +               printk("EXT2-fs: %s: tagging not permitted on remount.\n",
3046 +                      sb->s_id);
3047 +               err = -EINVAL;
3048 +               goto restore_opts;
3049 +       }
3050 +
3051         sb->s_flags = (sb->s_flags & ~MS_POSIXACL) |
3052                 ((sbi->s_mount_opt & EXT2_MOUNT_POSIX_ACL) ? MS_POSIXACL : 0);
3053  
3054 diff -NurpP --minimal linux-2.6.32.6/fs/ext3/file.c linux-2.6.32.6-vs2.3.0.36.28/fs/ext3/file.c
3055 --- linux-2.6.32.6/fs/ext3/file.c       2009-12-03 20:02:51.000000000 +0100
3056 +++ linux-2.6.32.6-vs2.3.0.36.28/fs/ext3/file.c 2009-12-03 20:04:56.000000000 +0100
3057 @@ -80,5 +80,6 @@ const struct inode_operations ext3_file_
3058  #endif
3059         .check_acl      = ext3_check_acl,
3060         .fiemap         = ext3_fiemap,
3061 +       .sync_flags     = ext3_sync_flags,
3062  };
3063  
3064 diff -NurpP --minimal linux-2.6.32.6/fs/ext3/ialloc.c linux-2.6.32.6-vs2.3.0.36.28/fs/ext3/ialloc.c
3065 --- linux-2.6.32.6/fs/ext3/ialloc.c     2009-09-10 15:26:21.000000000 +0200
3066 +++ linux-2.6.32.6-vs2.3.0.36.28/fs/ext3/ialloc.c       2009-12-03 20:04:56.000000000 +0100
3067 @@ -23,6 +23,7 @@
3068  #include <linux/buffer_head.h>
3069  #include <linux/random.h>
3070  #include <linux/bitops.h>
3071 +#include <linux/vs_tag.h>
3072  
3073  #include <asm/byteorder.h>
3074  
3075 @@ -548,6 +549,7 @@ got:
3076         } else
3077                 inode->i_gid = current_fsgid();
3078         inode->i_mode = mode;
3079 +       inode->i_tag = dx_current_fstag(sb);
3080  
3081         inode->i_ino = ino;
3082         /* This is the optimal IO size (for stat), not the fs block size */
3083 diff -NurpP --minimal linux-2.6.32.6/fs/ext3/inode.c linux-2.6.32.6-vs2.3.0.36.28/fs/ext3/inode.c
3084 --- linux-2.6.32.6/fs/ext3/inode.c      2010-01-26 19:31:26.000000000 +0100
3085 +++ linux-2.6.32.6-vs2.3.0.36.28/fs/ext3/inode.c        2009-12-29 00:36:26.000000000 +0100
3086 @@ -38,6 +38,7 @@
3087  #include <linux/bio.h>
3088  #include <linux/fiemap.h>
3089  #include <linux/namei.h>
3090 +#include <linux/vs_tag.h>
3091  #include "xattr.h"
3092  #include "acl.h"
3093  
3094 @@ -2343,7 +2344,7 @@ static void ext3_free_branches(handle_t 
3095  
3096  int ext3_can_truncate(struct inode *inode)
3097  {
3098 -       if (IS_APPEND(inode) || IS_IMMUTABLE(inode))
3099 +       if (IS_APPEND(inode) || IS_IXORUNLINK(inode))
3100                 return 0;
3101         if (S_ISREG(inode->i_mode))
3102                 return 1;
3103 @@ -2728,36 +2729,60 @@ void ext3_set_inode_flags(struct inode *
3104  {
3105         unsigned int flags = EXT3_I(inode)->i_flags;
3106  
3107 -       inode->i_flags &= ~(S_SYNC|S_APPEND|S_IMMUTABLE|S_NOATIME|S_DIRSYNC);
3108 +       inode->i_flags &= ~(S_IMMUTABLE | S_IXUNLINK |
3109 +               S_SYNC | S_APPEND | S_NOATIME | S_DIRSYNC);
3110 +
3111 +       if (flags & EXT3_IMMUTABLE_FL)
3112 +               inode->i_flags |= S_IMMUTABLE;
3113 +       if (flags & EXT3_IXUNLINK_FL)
3114 +               inode->i_flags |= S_IXUNLINK;
3115 +
3116         if (flags & EXT3_SYNC_FL)
3117                 inode->i_flags |= S_SYNC;
3118         if (flags & EXT3_APPEND_FL)
3119                 inode->i_flags |= S_APPEND;
3120 -       if (flags & EXT3_IMMUTABLE_FL)
3121 -               inode->i_flags |= S_IMMUTABLE;
3122         if (flags & EXT3_NOATIME_FL)
3123                 inode->i_flags |= S_NOATIME;
3124         if (flags & EXT3_DIRSYNC_FL)
3125                 inode->i_flags |= S_DIRSYNC;
3126 +
3127 +       inode->i_vflags &= ~(V_BARRIER | V_COW);
3128 +
3129 +       if (flags & EXT3_BARRIER_FL)
3130 +               inode->i_vflags |= V_BARRIER;
3131 +       if (flags & EXT3_COW_FL)
3132 +               inode->i_vflags |= V_COW;
3133  }
3134  
3135  /* Propagate flags from i_flags to EXT3_I(inode)->i_flags */
3136  void ext3_get_inode_flags(struct ext3_inode_info *ei)
3137  {
3138         unsigned int flags = ei->vfs_inode.i_flags;
3139 +       unsigned int vflags = ei->vfs_inode.i_vflags;
3140 +
3141 +       ei->i_flags &= ~(EXT3_SYNC_FL | EXT3_APPEND_FL |
3142 +                       EXT3_IMMUTABLE_FL | EXT3_IXUNLINK_FL |
3143 +                       EXT3_NOATIME_FL | EXT3_DIRSYNC_FL |
3144 +                       EXT3_BARRIER_FL | EXT3_COW_FL);
3145 +
3146 +       if (flags & S_IMMUTABLE)
3147 +               ei->i_flags |= EXT3_IMMUTABLE_FL;
3148 +       if (flags & S_IXUNLINK)
3149 +               ei->i_flags |= EXT3_IXUNLINK_FL;
3150  
3151 -       ei->i_flags &= ~(EXT3_SYNC_FL|EXT3_APPEND_FL|
3152 -                       EXT3_IMMUTABLE_FL|EXT3_NOATIME_FL|EXT3_DIRSYNC_FL);
3153         if (flags & S_SYNC)
3154                 ei->i_flags |= EXT3_SYNC_FL;
3155         if (flags & S_APPEND)
3156                 ei->i_flags |= EXT3_APPEND_FL;
3157 -       if (flags & S_IMMUTABLE)
3158 -               ei->i_flags |= EXT3_IMMUTABLE_FL;
3159         if (flags & S_NOATIME)
3160                 ei->i_flags |= EXT3_NOATIME_FL;
3161         if (flags & S_DIRSYNC)
3162                 ei->i_flags |= EXT3_DIRSYNC_FL;
3163 +
3164 +       if (vflags & V_BARRIER)
3165 +               ei->i_flags |= EXT3_BARRIER_FL;
3166 +       if (vflags & V_COW)
3167 +               ei->i_flags |= EXT3_COW_FL;
3168  }
3169  
3170  struct inode *ext3_iget(struct super_block *sb, unsigned long ino)
3171 @@ -2771,6 +2796,8 @@ struct inode *ext3_iget(struct super_blo
3172         transaction_t *transaction;
3173         long ret;
3174         int block;
3175 +       uid_t uid;
3176 +       gid_t gid;
3177  
3178         inode = iget_locked(sb, ino);
3179         if (!inode)
3180 @@ -2787,12 +2814,17 @@ struct inode *ext3_iget(struct super_blo
3181         bh = iloc.bh;
3182         raw_inode = ext3_raw_inode(&iloc);
3183         inode->i_mode = le16_to_cpu(raw_inode->i_mode);
3184 -       inode->i_uid = (uid_t)le16_to_cpu(raw_inode->i_uid_low);
3185 -       inode->i_gid = (gid_t)le16_to_cpu(raw_inode->i_gid_low);
3186 +       uid = (uid_t)le16_to_cpu(raw_inode->i_uid_low);
3187 +       gid = (gid_t)le16_to_cpu(raw_inode->i_gid_low);
3188         if(!(test_opt (inode->i_sb, NO_UID32))) {
3189 -               inode->i_uid |= le16_to_cpu(raw_inode->i_uid_high) << 16;
3190 -               inode->i_gid |= le16_to_cpu(raw_inode->i_gid_high) << 16;
3191 +               uid |= le16_to_cpu(raw_inode->i_uid_high) << 16;
3192 +               gid |= le16_to_cpu(raw_inode->i_gid_high) << 16;
3193         }
3194 +       inode->i_uid = INOTAG_UID(DX_TAG(inode), uid, gid);
3195 +       inode->i_gid = INOTAG_GID(DX_TAG(inode), uid, gid);
3196 +       inode->i_tag = INOTAG_TAG(DX_TAG(inode), uid, gid,
3197 +               le16_to_cpu(raw_inode->i_raw_tag));
3198 +
3199         inode->i_nlink = le16_to_cpu(raw_inode->i_links_count);
3200         inode->i_size = le32_to_cpu(raw_inode->i_size);
3201         inode->i_atime.tv_sec = (signed)le32_to_cpu(raw_inode->i_atime);
3202 @@ -2947,6 +2979,8 @@ static int ext3_do_update_inode(handle_t
3203         struct ext3_inode *raw_inode = ext3_raw_inode(iloc);
3204         struct ext3_inode_info *ei = EXT3_I(inode);
3205         struct buffer_head *bh = iloc->bh;
3206 +       uid_t uid = TAGINO_UID(DX_TAG(inode), inode->i_uid, inode->i_tag);
3207 +       gid_t gid = TAGINO_GID(DX_TAG(inode), inode->i_gid, inode->i_tag);
3208         int err = 0, rc, block;
3209  
3210  again:
3211 @@ -2961,29 +2995,32 @@ again:
3212         ext3_get_inode_flags(ei);
3213         raw_inode->i_mode = cpu_to_le16(inode->i_mode);
3214         if(!(test_opt(inode->i_sb, NO_UID32))) {
3215 -               raw_inode->i_uid_low = cpu_to_le16(low_16_bits(inode->i_uid));
3216 -               raw_inode->i_gid_low = cpu_to_le16(low_16_bits(inode->i_gid));
3217 +               raw_inode->i_uid_low = cpu_to_le16(low_16_bits(uid));
3218 +               raw_inode->i_gid_low = cpu_to_le16(low_16_bits(gid));
3219  /*
3220   * Fix up interoperability with old kernels. Otherwise, old inodes get
3221   * re-used with the upper 16 bits of the uid/gid intact
3222   */
3223                 if(!ei->i_dtime) {
3224                         raw_inode->i_uid_high =
3225 -                               cpu_to_le16(high_16_bits(inode->i_uid));
3226 +                               cpu_to_le16(high_16_bits(uid));
3227                         raw_inode->i_gid_high =
3228 -                               cpu_to_le16(high_16_bits(inode->i_gid));
3229 +                               cpu_to_le16(high_16_bits(gid));
3230                 } else {
3231                         raw_inode->i_uid_high = 0;
3232                         raw_inode->i_gid_high = 0;
3233                 }
3234         } else {
3235                 raw_inode->i_uid_low =
3236 -                       cpu_to_le16(fs_high2lowuid(inode->i_uid));
3237 +                       cpu_to_le16(fs_high2lowuid(uid));
3238                 raw_inode->i_gid_low =
3239 -                       cpu_to_le16(fs_high2lowgid(inode->i_gid));
3240 +                       cpu_to_le16(fs_high2lowgid(gid));
3241                 raw_inode->i_uid_high = 0;
3242                 raw_inode->i_gid_high = 0;
3243         }
3244 +#ifdef CONFIG_TAGGING_INTERN
3245 +       raw_inode->i_raw_tag = cpu_to_le16(inode->i_tag);
3246 +#endif
3247         raw_inode->i_links_count = cpu_to_le16(inode->i_nlink);
3248         raw_inode->i_size = cpu_to_le32(ei->i_disksize);
3249         raw_inode->i_atime = cpu_to_le32(inode->i_atime.tv_sec);
3250 @@ -3141,7 +3178,8 @@ int ext3_setattr(struct dentry *dentry, 
3251                 return error;
3252  
3253         if ((ia_valid & ATTR_UID && attr->ia_uid != inode->i_uid) ||
3254 -               (ia_valid & ATTR_GID && attr->ia_gid != inode->i_gid)) {
3255 +               (ia_valid & ATTR_GID && attr->ia_gid != inode->i_gid) ||
3256 +               (ia_valid & ATTR_TAG && attr->ia_tag != inode->i_tag)) {
3257                 handle_t *handle;
3258  
3259                 /* (user+group)*(old+new) structure, inode write (sb,
3260 @@ -3163,6 +3201,8 @@ int ext3_setattr(struct dentry *dentry, 
3261                         inode->i_uid = attr->ia_uid;
3262                 if (attr->ia_valid & ATTR_GID)
3263                         inode->i_gid = attr->ia_gid;
3264 +               if ((attr->ia_valid & ATTR_TAG) && IS_TAGGED(inode))
3265 +                       inode->i_tag = attr->ia_tag;
3266                 error = ext3_mark_inode_dirty(handle, inode);
3267                 ext3_journal_stop(handle);
3268         }
3269 diff -NurpP --minimal linux-2.6.32.6/fs/ext3/ioctl.c linux-2.6.32.6-vs2.3.0.36.28/fs/ext3/ioctl.c
3270 --- linux-2.6.32.6/fs/ext3/ioctl.c      2009-06-11 17:13:03.000000000 +0200
3271 +++ linux-2.6.32.6-vs2.3.0.36.28/fs/ext3/ioctl.c        2009-12-03 20:04:56.000000000 +0100
3272 @@ -8,6 +8,7 @@
3273   */
3274  
3275  #include <linux/fs.h>
3276 +#include <linux/mount.h>
3277  #include <linux/jbd.h>
3278  #include <linux/capability.h>
3279  #include <linux/ext3_fs.h>
3280 @@ -17,6 +18,34 @@
3281  #include <linux/compat.h>
3282  #include <asm/uaccess.h>
3283  
3284 +
3285 +int ext3_sync_flags(struct inode *inode, int flags, int vflags)
3286 +{
3287 +       handle_t *handle = NULL;
3288 +       struct ext3_iloc iloc;
3289 +       int err;
3290 +
3291 +       handle = ext3_journal_start(inode, 1);
3292 +       if (IS_ERR(handle))
3293 +               return PTR_ERR(handle);
3294 +
3295 +       if (IS_SYNC(inode))
3296 +               handle->h_sync = 1;
3297 +       err = ext3_reserve_inode_write(handle, inode, &iloc);
3298 +       if (err)
3299 +               goto flags_err;
3300 +
3301 +       inode->i_flags = flags;
3302 +       inode->i_vflags = vflags;
3303 +       ext3_get_inode_flags(EXT3_I(inode));
3304 +       inode->i_ctime = CURRENT_TIME_SEC;
3305 +
3306 +       err = ext3_mark_iloc_dirty(handle, inode, &iloc);
3307 +flags_err:
3308 +       ext3_journal_stop(handle);
3309 +       return err;
3310 +}
3311 +
3312  long ext3_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
3313  {
3314         struct inode *inode = filp->f_dentry->d_inode;
3315 @@ -50,6 +79,11 @@ long ext3_ioctl(struct file *filp, unsig
3316  
3317                 flags = ext3_mask_flags(inode->i_mode, flags);
3318  
3319 +               if (IS_BARRIER(inode)) {
3320 +                       vxwprintk_task(1, "messing with the barrier.");
3321 +                       return -EACCES;
3322 +               }
3323 +
3324                 mutex_lock(&inode->i_mutex);
3325  
3326                 /* Is it quota file? Do not allow user to mess with it */
3327 @@ -68,7 +102,9 @@ long ext3_ioctl(struct file *filp, unsig
3328                  *
3329                  * This test looks nicer. Thanks to Pauline Middelink
3330                  */
3331 -               if ((flags ^ oldflags) & (EXT3_APPEND_FL | EXT3_IMMUTABLE_FL)) {
3332 +               if ((oldflags & EXT3_IMMUTABLE_FL) ||
3333 +                       ((flags ^ oldflags) & (EXT3_APPEND_FL |
3334 +                       EXT3_IMMUTABLE_FL | EXT3_IXUNLINK_FL))) {
3335                         if (!capable(CAP_LINUX_IMMUTABLE))
3336                                 goto flags_out;
3337                 }
3338 @@ -93,7 +129,7 @@ long ext3_ioctl(struct file *filp, unsig
3339                 if (err)
3340                         goto flags_err;
3341  
3342 -               flags = flags & EXT3_FL_USER_MODIFIABLE;
3343 +               flags &= EXT3_FL_USER_MODIFIABLE;
3344                 flags |= oldflags & ~EXT3_FL_USER_MODIFIABLE;
3345                 ei->i_flags = flags;
3346  
3347 diff -NurpP --minimal linux-2.6.32.6/fs/ext3/namei.c linux-2.6.32.6-vs2.3.0.36.28/fs/ext3/namei.c
3348 --- linux-2.6.32.6/fs/ext3/namei.c      2009-12-03 20:02:51.000000000 +0100
3349 +++ linux-2.6.32.6-vs2.3.0.36.28/fs/ext3/namei.c        2009-12-03 20:04:56.000000000 +0100
3350 @@ -36,6 +36,7 @@
3351  #include <linux/quotaops.h>
3352  #include <linux/buffer_head.h>
3353  #include <linux/bio.h>
3354 +#include <linux/vs_tag.h>
3355  
3356  #include "namei.h"
3357  #include "xattr.h"
3358 @@ -912,6 +913,7 @@ restart:
3359                                 if (bh)
3360                                         ll_rw_block(READ_META, 1, &bh);
3361                         }
3362 +               dx_propagate_tag(nd, inode);
3363                 }
3364                 if ((bh = bh_use[ra_ptr++]) == NULL)
3365                         goto next;
3366 @@ -2446,6 +2448,7 @@ const struct inode_operations ext3_dir_i
3367         .removexattr    = generic_removexattr,
3368  #endif
3369         .check_acl      = ext3_check_acl,
3370 +       .sync_flags     = ext3_sync_flags,
3371  };
3372  
3373  const struct inode_operations ext3_special_inode_operations = {
3374 diff -NurpP --minimal linux-2.6.32.6/fs/ext3/super.c linux-2.6.32.6-vs2.3.0.36.28/fs/ext3/super.c
3375 --- linux-2.6.32.6/fs/ext3/super.c      2009-12-03 20:02:51.000000000 +0100
3376 +++ linux-2.6.32.6-vs2.3.0.36.28/fs/ext3/super.c        2009-12-03 20:04:56.000000000 +0100
3377 @@ -789,7 +789,7 @@ enum {
3378         Opt_usrjquota, Opt_grpjquota, Opt_offusrjquota, Opt_offgrpjquota,
3379         Opt_jqfmt_vfsold, Opt_jqfmt_vfsv0, Opt_quota, Opt_noquota,
3380         Opt_ignore, Opt_barrier, Opt_err, Opt_resize, Opt_usrquota,
3381 -       Opt_grpquota
3382 +       Opt_grpquota, Opt_tag, Opt_notag, Opt_tagid
3383  };
3384  
3385  static const match_table_t tokens = {
3386 @@ -842,6 +842,9 @@ static const match_table_t tokens = {
3387         {Opt_usrquota, "usrquota"},
3388         {Opt_barrier, "barrier=%u"},
3389         {Opt_resize, "resize"},
3390 +       {Opt_tag, "tag"},
3391 +       {Opt_notag, "notag"},
3392 +       {Opt_tagid, "tagid=%u"},
3393         {Opt_err, NULL},
3394  };
3395  
3396 @@ -934,6 +937,20 @@ static int parse_options (char *options,
3397                 case Opt_nouid32:
3398                         set_opt (sbi->s_mount_opt, NO_UID32);
3399                         break;
3400 +#ifndef CONFIG_TAGGING_NONE
3401 +               case Opt_tag:
3402 +                       set_opt (sbi->s_mount_opt, TAGGED);
3403 +                       break;
3404 +               case Opt_notag:
3405 +                       clear_opt (sbi->s_mount_opt, TAGGED);
3406 +                       break;
3407 +#endif
3408 +#ifdef CONFIG_PROPAGATE
3409 +               case Opt_tagid:
3410 +                       /* use args[0] */
3411 +                       set_opt (sbi->s_mount_opt, TAGGED);
3412 +                       break;
3413 +#endif
3414                 case Opt_nocheck:
3415                         clear_opt (sbi->s_mount_opt, CHECK);
3416                         break;
3417 @@ -1658,6 +1675,9 @@ static int ext3_fill_super (struct super
3418                             NULL, 0))
3419                 goto failed_mount;
3420  
3421 +       if (EXT3_SB(sb)->s_mount_opt & EXT3_MOUNT_TAGGED)
3422 +               sb->s_flags |= MS_TAGGED;
3423 +
3424         sb->s_flags = (sb->s_flags & ~MS_POSIXACL) |
3425                 ((sbi->s_mount_opt & EXT3_MOUNT_POSIX_ACL) ? MS_POSIXACL : 0);
3426  
3427 @@ -2527,6 +2547,14 @@ static int ext3_remount (struct super_bl
3428         if (sbi->s_mount_opt & EXT3_MOUNT_ABORT)
3429                 ext3_abort(sb, __func__, "Abort forced by user");
3430  
3431 +       if ((sbi->s_mount_opt & EXT3_MOUNT_TAGGED) &&
3432 +               !(sb->s_flags & MS_TAGGED)) {
3433 +               printk("EXT3-fs: %s: tagging not permitted on remount.\n",
3434 +                       sb->s_id);
3435 +               err = -EINVAL;
3436 +               goto restore_opts;
3437 +       }
3438 +
3439         sb->s_flags = (sb->s_flags & ~MS_POSIXACL) |
3440                 ((sbi->s_mount_opt & EXT3_MOUNT_POSIX_ACL) ? MS_POSIXACL : 0);
3441  
3442 diff -NurpP --minimal linux-2.6.32.6/fs/ext4/ext4.h linux-2.6.32.6-vs2.3.0.36.28/fs/ext4/ext4.h
3443 --- linux-2.6.32.6/fs/ext4/ext4.h       2010-01-26 19:31:26.000000000 +0100
3444 +++ linux-2.6.32.6-vs2.3.0.36.28/fs/ext4/ext4.h 2010-01-13 14:33:47.000000000 +0100
3445 @@ -284,8 +284,12 @@ struct flex_groups {
3446  #define EXT4_TOPDIR_FL                 0x00020000 /* Top of directory hierarchies*/
3447  #define EXT4_HUGE_FILE_FL               0x00040000 /* Set to each huge file */
3448  #define EXT4_EXTENTS_FL                        0x00080000 /* Inode uses extents */
3449 +#define EXT4_IXUNLINK_FL               0x08000000 /* Immutable invert on unlink */
3450  #define EXT4_RESERVED_FL               0x80000000 /* reserved for ext4 lib */
3451  
3452 +#define EXT4_BARRIER_FL                        0x04000000 /* Barrier for chroot() */
3453 +#define EXT4_COW_FL                    0x20000000 /* Copy on Write marker */
3454 +
3455  #define EXT4_FL_USER_VISIBLE           0x000BDFFF /* User visible flags */
3456  #define EXT4_FL_USER_MODIFIABLE                0x000B80FF /* User modifiable flags */
3457  
3458 @@ -469,7 +473,8 @@ struct ext4_inode {
3459                         __le16  l_i_file_acl_high;
3460                         __le16  l_i_uid_high;   /* these 2 fields */
3461                         __le16  l_i_gid_high;   /* were reserved2[0] */
3462 -                       __u32   l_i_reserved2;
3463 +                       __le16  l_i_tag;        /* Context Tag */
3464 +                       __u16   l_i_reserved2;
3465                 } linux2;
3466                 struct {
3467                         __le16  h_i_reserved1;  /* Obsoleted fragment number/size which are removed in ext4 */
3468 @@ -583,6 +588,7 @@ do {                                                                               \
3469  #define i_gid_low      i_gid
3470  #define i_uid_high     osd2.linux2.l_i_uid_high
3471  #define i_gid_high     osd2.linux2.l_i_gid_high
3472 +#define i_raw_tag      osd2.linux2.l_i_tag
3473  #define i_reserved2    osd2.linux2.l_i_reserved2
3474  
3475  #elif defined(__GNU__)
3476 @@ -755,6 +761,7 @@ struct ext4_inode_info {
3477  #define EXT4_MOUNT_QUOTA               0x80000 /* Some quota option set */
3478  #define EXT4_MOUNT_USRQUOTA            0x100000 /* "old" user quota */
3479  #define EXT4_MOUNT_GRPQUOTA            0x200000 /* "old" group quota */
3480 +#define EXT4_MOUNT_TAGGED              0x400000 /* Enable Context Tags */
3481  #define EXT4_MOUNT_JOURNAL_CHECKSUM    0x800000 /* Journal checksums */
3482  #define EXT4_MOUNT_JOURNAL_ASYNC_COMMIT        0x1000000 /* Journal Async Commit */
3483  #define EXT4_MOUNT_I_VERSION            0x2000000 /* i_version support */
3484 @@ -1746,6 +1753,7 @@ extern int ext4_get_blocks(handle_t *han
3485                            struct buffer_head *bh, int flags);
3486  extern int ext4_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo,
3487                         __u64 start, __u64 len);
3488 +extern int ext4_sync_flags(struct inode *, int, int);
3489  /* move_extent.c */
3490  extern int ext4_move_extents(struct file *o_filp, struct file *d_filp,
3491                              __u64 start_orig, __u64 start_donor,
3492 diff -NurpP --minimal linux-2.6.32.6/fs/ext4/file.c linux-2.6.32.6-vs2.3.0.36.28/fs/ext4/file.c
3493 --- linux-2.6.32.6/fs/ext4/file.c       2009-12-03 20:02:51.000000000 +0100
3494 +++ linux-2.6.32.6-vs2.3.0.36.28/fs/ext4/file.c 2009-12-03 20:04:56.000000000 +0100
3495 @@ -161,5 +161,6 @@ const struct inode_operations ext4_file_
3496         .check_acl      = ext4_check_acl,
3497         .fallocate      = ext4_fallocate,
3498         .fiemap         = ext4_fiemap,
3499 +       .sync_flags     = ext4_sync_flags,
3500  };
3501  
3502 diff -NurpP --minimal linux-2.6.32.6/fs/ext4/ialloc.c linux-2.6.32.6-vs2.3.0.36.28/fs/ext4/ialloc.c
3503 --- linux-2.6.32.6/fs/ext4/ialloc.c     2009-12-03 20:02:51.000000000 +0100
3504 +++ linux-2.6.32.6-vs2.3.0.36.28/fs/ext4/ialloc.c       2009-12-03 20:04:56.000000000 +0100
3505 @@ -22,6 +22,7 @@
3506  #include <linux/random.h>
3507  #include <linux/bitops.h>
3508  #include <linux/blkdev.h>
3509 +#include <linux/vs_tag.h>
3510  #include <asm/byteorder.h>
3511  
3512  #include "ext4.h"
3513 @@ -995,6 +996,7 @@ got:
3514         } else
3515                 inode->i_gid = current_fsgid();
3516         inode->i_mode = mode;
3517 +       inode->i_tag = dx_current_fstag(sb);
3518  
3519         inode->i_ino = ino + group * EXT4_INODES_PER_GROUP(sb);
3520         /* This is the optimal IO size (for stat), not the fs block size */
3521 diff -NurpP --minimal linux-2.6.32.6/fs/ext4/inode.c linux-2.6.32.6-vs2.3.0.36.28/fs/ext4/inode.c
3522 --- linux-2.6.32.6/fs/ext4/inode.c      2010-01-26 19:31:26.000000000 +0100
3523 +++ linux-2.6.32.6-vs2.3.0.36.28/fs/ext4/inode.c        2010-01-13 14:33:47.000000000 +0100
3524 @@ -38,6 +38,7 @@
3525  #include <linux/uio.h>
3526  #include <linux/bio.h>
3527  #include <linux/workqueue.h>
3528 +#include <linux/vs_tag.h>
3529  
3530  #include "ext4_jbd2.h"
3531  #include "xattr.h"
3532 @@ -4378,7 +4379,7 @@ static void ext4_free_branches(handle_t 
3533  
3534  int ext4_can_truncate(struct inode *inode)
3535  {
3536 -       if (IS_APPEND(inode) || IS_IMMUTABLE(inode))
3537 +       if (IS_APPEND(inode) || IS_IXORUNLINK(inode))
3538                 return 0;
3539         if (S_ISREG(inode->i_mode))
3540                 return 1;
3541 @@ -4729,36 +4730,60 @@ void ext4_set_inode_flags(struct inode *
3542  {
3543         unsigned int flags = EXT4_I(inode)->i_flags;
3544  
3545 -       inode->i_flags &= ~(S_SYNC|S_APPEND|S_IMMUTABLE|S_NOATIME|S_DIRSYNC);
3546 +       inode->i_flags &= ~(S_IMMUTABLE | S_IXUNLINK |
3547 +               S_SYNC | S_APPEND | S_NOATIME | S_DIRSYNC);
3548 +
3549 +       if (flags & EXT4_IMMUTABLE_FL)
3550 +               inode->i_flags |= S_IMMUTABLE;
3551 +       if (flags & EXT4_IXUNLINK_FL)
3552 +               inode->i_flags |= S_IXUNLINK;
3553 +
3554         if (flags & EXT4_SYNC_FL)
3555                 inode->i_flags |= S_SYNC;
3556         if (flags & EXT4_APPEND_FL)
3557                 inode->i_flags |= S_APPEND;
3558 -       if (flags & EXT4_IMMUTABLE_FL)
3559 -               inode->i_flags |= S_IMMUTABLE;
3560         if (flags & EXT4_NOATIME_FL)
3561                 inode->i_flags |= S_NOATIME;
3562         if (flags & EXT4_DIRSYNC_FL)
3563                 inode->i_flags |= S_DIRSYNC;
3564 +
3565 +       inode->i_vflags &= ~(V_BARRIER | V_COW);
3566 +
3567 +       if (flags & EXT4_BARRIER_FL)
3568 +               inode->i_vflags |= V_BARRIER;
3569 +       if (flags & EXT4_COW_FL)
3570 +               inode->i_vflags |= V_COW;
3571  }
3572  
3573  /* Propagate flags from i_flags to EXT4_I(inode)->i_flags */
3574  void ext4_get_inode_flags(struct ext4_inode_info *ei)
3575  {
3576         unsigned int flags = ei->vfs_inode.i_flags;
3577 +       unsigned int vflags = ei->vfs_inode.i_vflags;
3578 +
3579 +       ei->i_flags &= ~(EXT4_SYNC_FL | EXT4_APPEND_FL |
3580 +                       EXT4_IMMUTABLE_FL | EXT4_IXUNLINK_FL |
3581 +                       EXT4_NOATIME_FL | EXT4_DIRSYNC_FL |
3582 +                       EXT4_BARRIER_FL | EXT4_COW_FL);
3583 +
3584 +       if (flags & S_IMMUTABLE)
3585 +               ei->i_flags |= EXT4_IMMUTABLE_FL;
3586 +       if (flags & S_IXUNLINK)
3587 +               ei->i_flags |= EXT4_IXUNLINK_FL;
3588  
3589 -       ei->i_flags &= ~(EXT4_SYNC_FL|EXT4_APPEND_FL|
3590 -                       EXT4_IMMUTABLE_FL|EXT4_NOATIME_FL|EXT4_DIRSYNC_FL);
3591         if (flags & S_SYNC)
3592                 ei->i_flags |= EXT4_SYNC_FL;
3593         if (flags & S_APPEND)
3594                 ei->i_flags |= EXT4_APPEND_FL;
3595 -       if (flags & S_IMMUTABLE)
3596 -               ei->i_flags |= EXT4_IMMUTABLE_FL;
3597         if (flags & S_NOATIME)
3598                 ei->i_flags |= EXT4_NOATIME_FL;
3599         if (flags & S_DIRSYNC)
3600                 ei->i_flags |= EXT4_DIRSYNC_FL;
3601 +
3602 +       if (vflags & V_BARRIER)
3603 +               ei->i_flags |= EXT4_BARRIER_FL;
3604 +       if (vflags & V_COW)
3605 +               ei->i_flags |= EXT4_COW_FL;
3606  }
3607  
3608  static blkcnt_t ext4_inode_blocks(struct ext4_inode *raw_inode,
3609 @@ -4793,6 +4818,8 @@ struct inode *ext4_iget(struct super_blo
3610         journal_t *journal = EXT4_SB(sb)->s_journal;
3611         long ret;
3612         int block;
3613 +       uid_t uid;
3614 +       gid_t gid;
3615  
3616         inode = iget_locked(sb, ino);
3617         if (!inode)
3618 @@ -4808,12 +4835,16 @@ struct inode *ext4_iget(struct super_blo
3619                 goto bad_inode;
3620         raw_inode = ext4_raw_inode(&iloc);
3621         inode->i_mode = le16_to_cpu(raw_inode->i_mode);
3622 -       inode->i_uid = (uid_t)le16_to_cpu(raw_inode->i_uid_low);
3623 -       inode->i_gid = (gid_t)le16_to_cpu(raw_inode->i_gid_low);
3624 +       uid = (uid_t)le16_to_cpu(raw_inode->i_uid_low);
3625 +       gid = (gid_t)le16_to_cpu(raw_inode->i_gid_low);
3626         if (!(test_opt(inode->i_sb, NO_UID32))) {
3627 -               inode->i_uid |= le16_to_cpu(raw_inode->i_uid_high) << 16;
3628 -               inode->i_gid |= le16_to_cpu(raw_inode->i_gid_high) << 16;
3629 +               uid |= le16_to_cpu(raw_inode->i_uid_high) << 16;
3630 +               gid |= le16_to_cpu(raw_inode->i_gid_high) << 16;
3631         }
3632 +       inode->i_uid = INOTAG_UID(DX_TAG(inode), uid, gid);
3633 +       inode->i_gid = INOTAG_GID(DX_TAG(inode), uid, gid);
3634 +       inode->i_tag = INOTAG_TAG(DX_TAG(inode), uid, gid,
3635 +               le16_to_cpu(raw_inode->i_raw_tag));
3636         inode->i_nlink = le16_to_cpu(raw_inode->i_links_count);
3637  
3638         ei->i_state = 0;
3639 @@ -5035,6 +5066,8 @@ static int ext4_do_update_inode(handle_t
3640         struct ext4_inode *raw_inode = ext4_raw_inode(iloc);
3641         struct ext4_inode_info *ei = EXT4_I(inode);
3642         struct buffer_head *bh = iloc->bh;
3643 +       uid_t uid = TAGINO_UID(DX_TAG(inode), inode->i_uid, inode->i_tag);
3644 +       gid_t gid = TAGINO_GID(DX_TAG(inode), inode->i_gid, inode->i_tag);
3645         int err = 0, rc, block;
3646  
3647         /* For fields not not tracking in the in-memory inode,
3648 @@ -5045,29 +5078,32 @@ static int ext4_do_update_inode(handle_t
3649         ext4_get_inode_flags(ei);
3650         raw_inode->i_mode = cpu_to_le16(inode->i_mode);
3651         if (!(test_opt(inode->i_sb, NO_UID32))) {
3652 -               raw_inode->i_uid_low = cpu_to_le16(low_16_bits(inode->i_uid));
3653 -               raw_inode->i_gid_low = cpu_to_le16(low_16_bits(inode->i_gid));
3654 +               raw_inode->i_uid_low = cpu_to_le16(low_16_bits(uid));
3655 +               raw_inode->i_gid_low = cpu_to_le16(low_16_bits(gid));
3656  /*
3657   * Fix up interoperability with old kernels. Otherwise, old inodes get
3658   * re-used with the upper 16 bits of the uid/gid intact
3659   */
3660                 if (!ei->i_dtime) {
3661                         raw_inode->i_uid_high =
3662 -                               cpu_to_le16(high_16_bits(inode->i_uid));
3663 +                               cpu_to_le16(high_16_bits(uid));
3664                         raw_inode->i_gid_high =
3665 -                               cpu_to_le16(high_16_bits(inode->i_gid));
3666 +                               cpu_to_le16(high_16_bits(gid));
3667                 } else {
3668                         raw_inode->i_uid_high = 0;
3669                         raw_inode->i_gid_high = 0;
3670                 }
3671         } else {
3672                 raw_inode->i_uid_low =
3673 -                       cpu_to_le16(fs_high2lowuid(inode->i_uid));
3674 +                       cpu_to_le16(fs_high2lowuid(uid));
3675                 raw_inode->i_gid_low =
3676 -                       cpu_to_le16(fs_high2lowgid(inode->i_gid));
3677 +                       cpu_to_le16(fs_high2lowgid(gid));
3678                 raw_inode->i_uid_high = 0;
3679                 raw_inode->i_gid_high = 0;
3680         }
3681 +#ifdef CONFIG_TAGGING_INTERN
3682 +       raw_inode->i_raw_tag = cpu_to_le16(inode->i_tag);
3683 +#endif
3684         raw_inode->i_links_count = cpu_to_le16(inode->i_nlink);
3685  
3686         EXT4_INODE_SET_XTIME(i_ctime, inode, raw_inode);
3687 @@ -5252,7 +5288,8 @@ int ext4_setattr(struct dentry *dentry, 
3688                 return error;
3689  
3690         if ((ia_valid & ATTR_UID && attr->ia_uid != inode->i_uid) ||
3691 -               (ia_valid & ATTR_GID && attr->ia_gid != inode->i_gid)) {
3692 +               (ia_valid & ATTR_GID && attr->ia_gid != inode->i_gid) ||
3693 +               (ia_valid & ATTR_TAG && attr->ia_tag != inode->i_tag)) {
3694                 handle_t *handle;
3695  
3696                 /* (user+group)*(old+new) structure, inode write (sb,
3697 @@ -5274,6 +5311,8 @@ int ext4_setattr(struct dentry *dentry, 
3698                         inode->i_uid = attr->ia_uid;
3699                 if (attr->ia_valid & ATTR_GID)
3700                         inode->i_gid = attr->ia_gid;
3701 +               if ((attr->ia_valid & ATTR_TAG) && IS_TAGGED(inode))
3702 +                       inode->i_tag = attr->ia_tag;
3703                 error = ext4_mark_inode_dirty(handle, inode);
3704                 ext4_journal_stop(handle);
3705         }
3706 diff -NurpP --minimal linux-2.6.32.6/fs/ext4/ioctl.c linux-2.6.32.6-vs2.3.0.36.28/fs/ext4/ioctl.c
3707 --- linux-2.6.32.6/fs/ext4/ioctl.c      2010-01-26 19:31:26.000000000 +0100
3708 +++ linux-2.6.32.6-vs2.3.0.36.28/fs/ext4/ioctl.c        2009-12-14 22:20:55.000000000 +0100
3709 @@ -14,10 +14,39 @@
3710  #include <linux/compat.h>
3711  #include <linux/mount.h>
3712  #include <linux/file.h>
3713 +#include <linux/vs_tag.h>
3714  #include <asm/uaccess.h>
3715  #include "ext4_jbd2.h"
3716  #include "ext4.h"
3717  
3718 +
3719 +int ext4_sync_flags(struct inode *inode, int flags, int vflags)
3720 +{
3721 +       handle_t *handle = NULL;
3722 +       struct ext4_iloc iloc;
3723 +       int err;
3724 +
3725 +       handle = ext4_journal_start(inode, 1);
3726 +       if (IS_ERR(handle))
3727 +               return PTR_ERR(handle);
3728 +
3729 +       if (IS_SYNC(inode))
3730 +               ext4_handle_sync(handle);
3731 +       err = ext4_reserve_inode_write(handle, inode, &iloc);
3732 +       if (err)
3733 +               goto flags_err;
3734 +
3735 +       inode->i_flags = flags;
3736 +       inode->i_vflags = vflags;
3737 +       ext4_get_inode_flags(EXT4_I(inode));
3738 +       inode->i_ctime = ext4_current_time(inode);
3739 +
3740 +       err = ext4_mark_iloc_dirty(handle, inode, &iloc);
3741 +flags_err:
3742 +       ext4_journal_stop(handle);
3743 +       return err;
3744 +}
3745 +
3746  long ext4_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
3747  {
3748         struct inode *inode = filp->f_dentry->d_inode;
3749 @@ -50,6 +79,11 @@ long ext4_ioctl(struct file *filp, unsig
3750  
3751                 flags = ext4_mask_flags(inode->i_mode, flags);
3752  
3753 +               if (IS_BARRIER(inode)) {
3754 +                       vxwprintk_task(1, "messing with the barrier.");
3755 +                       return -EACCES;
3756 +               }
3757 +
3758                 err = -EPERM;
3759                 mutex_lock(&inode->i_mutex);
3760                 /* Is it quota file? Do not allow user to mess with it */
3761 @@ -67,7 +101,9 @@ long ext4_ioctl(struct file *filp, unsig
3762                  *
3763                  * This test looks nicer. Thanks to Pauline Middelink
3764                  */
3765 -               if ((flags ^ oldflags) & (EXT4_APPEND_FL | EXT4_IMMUTABLE_FL)) {
3766 +               if ((oldflags & EXT4_IMMUTABLE_FL) ||
3767 +                       ((flags ^ oldflags) & (EXT4_APPEND_FL |
3768 +                       EXT4_IMMUTABLE_FL | EXT4_IXUNLINK_FL))) {
3769                         if (!capable(CAP_LINUX_IMMUTABLE))
3770                                 goto flags_out;
3771                 }
3772 diff -NurpP --minimal linux-2.6.32.6/fs/ext4/namei.c linux-2.6.32.6-vs2.3.0.36.28/fs/ext4/namei.c
3773 --- linux-2.6.32.6/fs/ext4/namei.c      2010-01-26 19:31:26.000000000 +0100
3774 +++ linux-2.6.32.6-vs2.3.0.36.28/fs/ext4/namei.c        2009-12-14 22:20:55.000000000 +0100
3775 @@ -34,6 +34,7 @@
3776  #include <linux/quotaops.h>
3777  #include <linux/buffer_head.h>
3778  #include <linux/bio.h>
3779 +#include <linux/vs_tag.h>
3780  #include "ext4.h"
3781  #include "ext4_jbd2.h"
3782  
3783 @@ -941,6 +942,7 @@ restart:
3784                                 if (bh)
3785                                         ll_rw_block(READ_META, 1, &bh);
3786                         }
3787 +               dx_propagate_tag(nd, inode);
3788                 }
3789                 if ((bh = bh_use[ra_ptr++]) == NULL)
3790                         goto next;
3791 @@ -2533,6 +2535,7 @@ const struct inode_operations ext4_dir_i
3792  #endif
3793         .check_acl      = ext4_check_acl,
3794         .fiemap         = ext4_fiemap,
3795 +       .sync_flags     = ext4_sync_flags,
3796  };
3797  
3798  const struct inode_operations ext4_special_inode_operations = {
3799 diff -NurpP --minimal linux-2.6.32.6/fs/ext4/super.c linux-2.6.32.6-vs2.3.0.36.28/fs/ext4/super.c
3800 --- linux-2.6.32.6/fs/ext4/super.c      2010-01-26 19:31:26.000000000 +0100
3801 +++ linux-2.6.32.6-vs2.3.0.36.28/fs/ext4/super.c        2010-01-13 14:33:47.000000000 +0100
3802 @@ -1096,6 +1096,7 @@ enum {
3803         Opt_block_validity, Opt_noblock_validity,
3804         Opt_inode_readahead_blks, Opt_journal_ioprio,
3805         Opt_discard, Opt_nodiscard,
3806 +       Opt_tag, Opt_notag, Opt_tagid
3807  };
3808  
3809  static const match_table_t tokens = {
3810 @@ -1163,6 +1164,9 @@ static const match_table_t tokens = {
3811         {Opt_noauto_da_alloc, "noauto_da_alloc"},
3812         {Opt_discard, "discard"},
3813         {Opt_nodiscard, "nodiscard"},
3814 +       {Opt_tag, "tag"},
3815 +       {Opt_notag, "notag"},
3816 +       {Opt_tagid, "tagid=%u"},
3817         {Opt_err, NULL},
3818  };
3819  
3820 @@ -1260,6 +1264,20 @@ static int parse_options(char *options, 
3821                 case Opt_nouid32:
3822                         set_opt(sbi->s_mount_opt, NO_UID32);
3823                         break;
3824 +#ifndef CONFIG_TAGGING_NONE
3825 +               case Opt_tag:
3826 +                       set_opt (sbi->s_mount_opt, TAGGED);
3827 +                       break;
3828 +               case Opt_notag:
3829 +                       clear_opt (sbi->s_mount_opt, TAGGED);
3830 +                       break;
3831 +#endif
3832 +#ifdef CONFIG_PROPAGATE
3833 +               case Opt_tagid:
3834 +                       /* use args[0] */
3835 +                       set_opt (sbi->s_mount_opt, TAGGED);
3836 +                       break;
3837 +#endif
3838                 case Opt_debug:
3839                         set_opt(sbi->s_mount_opt, DEBUG);
3840                         break;
3841 @@ -2460,6 +2478,9 @@ static int ext4_fill_super(struct super_
3842                            &journal_ioprio, NULL, 0))
3843                 goto failed_mount;
3844  
3845 +       if (EXT4_SB(sb)->s_mount_opt & EXT4_MOUNT_TAGGED)
3846 +               sb->s_flags |= MS_TAGGED;
3847 +
3848         sb->s_flags = (sb->s_flags & ~MS_POSIXACL) |
3849                 ((sbi->s_mount_opt & EXT4_MOUNT_POSIX_ACL) ? MS_POSIXACL : 0);
3850  
3851 @@ -3517,6 +3538,14 @@ static int ext4_remount(struct super_blo
3852         if (sbi->s_mount_flags & EXT4_MF_FS_ABORTED)
3853                 ext4_abort(sb, __func__, "Abort forced by user");
3854  
3855 +       if ((sbi->s_mount_opt & EXT4_MOUNT_TAGGED) &&
3856 +               !(sb->s_flags & MS_TAGGED)) {
3857 +               printk("EXT4-fs: %s: tagging not permitted on remount.\n",
3858 +                       sb->s_id);
3859 +               err = -EINVAL;
3860 +               goto restore_opts;
3861 +       }
3862 +
3863         sb->s_flags = (sb->s_flags & ~MS_POSIXACL) |
3864                 ((sbi->s_mount_opt & EXT4_MOUNT_POSIX_ACL) ? MS_POSIXACL : 0);
3865  
3866 diff -NurpP --minimal linux-2.6.32.6/fs/fcntl.c linux-2.6.32.6-vs2.3.0.36.28/fs/fcntl.c
3867 --- linux-2.6.32.6/fs/fcntl.c   2010-01-26 19:31:26.000000000 +0100
3868 +++ linux-2.6.32.6-vs2.3.0.36.28/fs/fcntl.c     2010-01-20 04:21:33.000000000 +0100
3869 @@ -19,6 +19,7 @@
3870  #include <linux/signal.h>
3871  #include <linux/rcupdate.h>
3872  #include <linux/pid_namespace.h>
3873 +#include <linux/vs_limit.h>
3874  
3875  #include <asm/poll.h>
3876  #include <asm/siginfo.h>
3877 @@ -102,6 +103,8 @@ SYSCALL_DEFINE3(dup3, unsigned int, oldf
3878  
3879         if (tofree)
3880                 filp_close(tofree, files);
3881 +       else
3882 +               vx_openfd_inc(newfd);   /* fd was unused */
3883  
3884         return newfd;
3885  
3886 @@ -426,6 +429,8 @@ SYSCALL_DEFINE3(fcntl, unsigned int, fd,
3887         filp = fget(fd);
3888         if (!filp)
3889                 goto out;
3890 +       if (!vx_files_avail(1))
3891 +               goto out;
3892  
3893         err = security_file_fcntl(filp, cmd, arg);
3894         if (err) {
3895 diff -NurpP --minimal linux-2.6.32.6/fs/file.c linux-2.6.32.6-vs2.3.0.36.28/fs/file.c
3896 --- linux-2.6.32.6/fs/file.c    2009-12-03 20:02:51.000000000 +0100
3897 +++ linux-2.6.32.6-vs2.3.0.36.28/fs/file.c      2009-12-03 20:04:56.000000000 +0100
3898 @@ -20,6 +20,7 @@
3899  #include <linux/spinlock.h>
3900  #include <linux/rcupdate.h>
3901  #include <linux/workqueue.h>
3902 +#include <linux/vs_limit.h>
3903  
3904  struct fdtable_defer {
3905         spinlock_t lock;
3906 @@ -368,6 +369,8 @@ struct files_struct *dup_fd(struct files
3907                 struct file *f = *old_fds++;
3908                 if (f) {
3909                         get_file(f);
3910 +                       /* TODO: sum it first for check and performance */
3911 +                       vx_openfd_inc(open_files - i);
3912                 } else {
3913                         /*
3914                          * The fd may be claimed in the fd bitmap but not yet
3915 @@ -476,6 +479,7 @@ repeat:
3916         else
3917                 FD_CLR(fd, fdt->close_on_exec);
3918         error = fd;
3919 +       vx_openfd_inc(fd);
3920  #if 1
3921         /* Sanity check */
3922         if (rcu_dereference(fdt->fd[fd]) != NULL) {
3923 diff -NurpP --minimal linux-2.6.32.6/fs/file_table.c linux-2.6.32.6-vs2.3.0.36.28/fs/file_table.c
3924 --- linux-2.6.32.6/fs/file_table.c      2009-12-03 20:02:51.000000000 +0100
3925 +++ linux-2.6.32.6-vs2.3.0.36.28/fs/file_table.c        2009-12-03 20:04:56.000000000 +0100
3926 @@ -22,6 +22,8 @@
3927  #include <linux/fsnotify.h>
3928  #include <linux/sysctl.h>
3929  #include <linux/percpu_counter.h>
3930 +#include <linux/vs_limit.h>
3931 +#include <linux/vs_context.h>
3932  
3933  #include <asm/atomic.h>
3934  
3935 @@ -131,6 +133,8 @@ struct file *get_empty_filp(void)
3936         spin_lock_init(&f->f_lock);
3937         eventpoll_init_file(f);
3938         /* f->f_version: 0 */
3939 +       f->f_xid = vx_current_xid();
3940 +       vx_files_inc(f);
3941         return f;
3942  
3943  over:
3944 @@ -285,6 +289,8 @@ void __fput(struct file *file)
3945                 cdev_put(inode->i_cdev);
3946         fops_put(file->f_op);
3947         put_pid(file->f_owner.pid);
3948 +       vx_files_dec(file);
3949 +       file->f_xid = 0;
3950         file_kill(file);
3951         if (file->f_mode & FMODE_WRITE)
3952                 drop_file_write_access(file);
3953 @@ -352,6 +358,8 @@ void put_filp(struct file *file)
3954  {
3955         if (atomic_long_dec_and_test(&file->f_count)) {
3956                 security_file_free(file);
3957 +               vx_files_dec(file);
3958 +               file->f_xid = 0;
3959                 file_kill(file);
3960                 file_free(file);
3961         }
3962 diff -NurpP --minimal linux-2.6.32.6/fs/fs_struct.c linux-2.6.32.6-vs2.3.0.36.28/fs/fs_struct.c
3963 --- linux-2.6.32.6/fs/fs_struct.c       2009-06-11 17:13:04.000000000 +0200
3964 +++ linux-2.6.32.6-vs2.3.0.36.28/fs/fs_struct.c 2009-12-03 20:04:56.000000000 +0100
3965 @@ -4,6 +4,7 @@
3966  #include <linux/path.h>
3967  #include <linux/slab.h>
3968  #include <linux/fs_struct.h>
3969 +#include <linux/vserver/global.h>
3970  
3971  /*
3972   * Replace the fs->{rootmnt,root} with {mnt,dentry}. Put the old values.
3973 @@ -77,6 +78,7 @@ void free_fs_struct(struct fs_struct *fs
3974  {
3975         path_put(&fs->root);
3976         path_put(&fs->pwd);
3977 +       atomic_dec(&vs_global_fs);
3978         kmem_cache_free(fs_cachep, fs);
3979  }
3980  
3981 @@ -112,6 +114,7 @@ struct fs_struct *copy_fs_struct(struct 
3982                 fs->pwd = old->pwd;
3983                 path_get(&old->pwd);
3984                 read_unlock(&old->lock);
3985 +               atomic_inc(&vs_global_fs);
3986         }
3987         return fs;
3988  }
3989 diff -NurpP --minimal linux-2.6.32.6/fs/gfs2/file.c linux-2.6.32.6-vs2.3.0.36.28/fs/gfs2/file.c
3990 --- linux-2.6.32.6/fs/gfs2/file.c       2009-12-03 20:02:52.000000000 +0100
3991 +++ linux-2.6.32.6-vs2.3.0.36.28/fs/gfs2/file.c 2009-12-03 20:04:56.000000000 +0100
3992 @@ -132,6 +132,9 @@ static const u32 fsflags_to_gfs2[32] = {
3993         [7] = GFS2_DIF_NOATIME,
3994         [12] = GFS2_DIF_EXHASH,
3995         [14] = GFS2_DIF_INHERIT_JDATA,
3996 +       [27] = GFS2_DIF_IXUNLINK,
3997 +       [26] = GFS2_DIF_BARRIER,
3998 +       [29] = GFS2_DIF_COW,
3999  };
4000  
4001  static const u32 gfs2_to_fsflags[32] = {
4002 @@ -141,6 +144,9 @@ static const u32 gfs2_to_fsflags[32] = {
4003         [gfs2fl_NoAtime] = FS_NOATIME_FL,
4004         [gfs2fl_ExHash] = FS_INDEX_FL,
4005         [gfs2fl_InheritJdata] = FS_JOURNAL_DATA_FL,
4006 +       [gfs2fl_IXUnlink] = FS_IXUNLINK_FL,
4007 +       [gfs2fl_Barrier] = FS_BARRIER_FL,
4008 +       [gfs2fl_Cow] = FS_COW_FL,
4009  };
4010  
4011  static int gfs2_get_flags(struct file *filp, u32 __user *ptr)
4012 @@ -171,10 +177,16 @@ void gfs2_set_inode_flags(struct inode *
4013  {
4014         struct gfs2_inode *ip = GFS2_I(inode);
4015         unsigned int flags = inode->i_flags;
4016 +       unsigned int vflags = inode->i_vflags;
4017 +
4018 +       flags &= ~(S_IMMUTABLE | S_IXUNLINK |
4019 +               S_SYNC | S_APPEND | S_NOATIME | S_DIRSYNC);
4020  
4021 -       flags &= ~(S_SYNC|S_APPEND|S_IMMUTABLE|S_NOATIME|S_DIRSYNC);
4022         if (ip->i_diskflags & GFS2_DIF_IMMUTABLE)
4023                 flags |= S_IMMUTABLE;
4024 +       if (ip->i_diskflags & GFS2_DIF_IXUNLINK)
4025 +               flags |= S_IXUNLINK;
4026 +
4027         if (ip->i_diskflags & GFS2_DIF_APPENDONLY)
4028                 flags |= S_APPEND;
4029         if (ip->i_diskflags & GFS2_DIF_NOATIME)
4030 @@ -182,6 +194,43 @@ void gfs2_set_inode_flags(struct inode *
4031         if (ip->i_diskflags & GFS2_DIF_SYNC)
4032                 flags |= S_SYNC;
4033         inode->i_flags = flags;
4034 +
4035 +       vflags &= ~(V_BARRIER | V_COW);
4036 +
4037 +       if (ip->i_diskflags & GFS2_DIF_BARRIER)
4038 +               vflags |= V_BARRIER;
4039 +       if (ip->i_diskflags & GFS2_DIF_COW)
4040 +               vflags |= V_COW;
4041 +       inode->i_vflags = vflags;
4042 +}
4043 +
4044 +void gfs2_get_inode_flags(struct inode *inode)
4045 +{
4046 +       struct gfs2_inode *ip = GFS2_I(inode);
4047 +       unsigned int flags = inode->i_flags;
4048 +       unsigned int vflags = inode->i_vflags;
4049 +
4050 +       ip->i_diskflags &= ~(GFS2_DIF_APPENDONLY |
4051 +                       GFS2_DIF_NOATIME | GFS2_DIF_SYNC |
4052 +                       GFS2_DIF_IMMUTABLE | GFS2_DIF_IXUNLINK |
4053 +                       GFS2_DIF_BARRIER | GFS2_DIF_COW);
4054 +
4055 +       if (flags & S_IMMUTABLE)
4056 +               ip->i_diskflags |= GFS2_DIF_IMMUTABLE;
4057 +       if (flags & S_IXUNLINK)
4058 +               ip->i_diskflags |= GFS2_DIF_IXUNLINK;
4059 +
4060 +       if (flags & S_APPEND)
4061 +               ip->i_diskflags |= GFS2_DIF_APPENDONLY;
4062 +       if (flags & S_NOATIME)
4063 +               ip->i_diskflags |= GFS2_DIF_NOATIME;
4064 +       if (flags & S_SYNC)
4065 +               ip->i_diskflags |= GFS2_DIF_SYNC;
4066 +
4067 +       if (vflags & V_BARRIER)
4068 +               ip->i_diskflags |= GFS2_DIF_BARRIER;
4069 +       if (vflags & V_COW)
4070 +               ip->i_diskflags |= GFS2_DIF_COW;
4071  }
4072  
4073  /* Flags that can be set by user space */
4074 @@ -286,6 +335,37 @@ static int gfs2_set_flags(struct file *f
4075         return do_gfs2_set_flags(filp, gfsflags, ~GFS2_DIF_JDATA);
4076  }
4077  
4078 +int gfs2_sync_flags(struct inode *inode, int flags, int vflags)
4079 +{
4080 +       struct gfs2_inode *ip = GFS2_I(inode);
4081 +       struct gfs2_sbd *sdp = GFS2_SB(inode);
4082 +       struct buffer_head *bh;
4083 +       struct gfs2_holder gh;
4084 +       int error;
4085 +
4086 +       error = gfs2_glock_nq_init(ip->i_gl, LM_ST_EXCLUSIVE, 0, &gh);
4087 +       if (error)
4088 +               return error;
4089 +       error = gfs2_trans_begin(sdp, RES_DINODE, 0);
4090 +       if (error)
4091 +               goto out;
4092 +       error = gfs2_meta_inode_buffer(ip, &bh);
4093 +       if (error)
4094 +               goto out_trans_end;
4095 +       gfs2_trans_add_bh(ip->i_gl, bh, 1);
4096 +       inode->i_flags = flags;
4097 +       inode->i_vflags = vflags;
4098 +       gfs2_get_inode_flags(inode);
4099 +       gfs2_dinode_out(ip, bh->b_data);
4100 +       brelse(bh);
4101 +       gfs2_set_aops(inode);
4102 +out_trans_end:
4103 +       gfs2_trans_end(sdp);
4104 +out:
4105 +       gfs2_glock_dq_uninit(&gh);
4106 +       return error;
4107 +}
4108 +
4109  static long gfs2_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
4110  {
4111         switch(cmd) {
4112 diff -NurpP --minimal linux-2.6.32.6/fs/gfs2/inode.h linux-2.6.32.6-vs2.3.0.36.28/fs/gfs2/inode.h
4113 --- linux-2.6.32.6/fs/gfs2/inode.h      2009-09-10 15:26:22.000000000 +0200
4114 +++ linux-2.6.32.6-vs2.3.0.36.28/fs/gfs2/inode.h        2009-12-03 20:04:56.000000000 +0100
4115 @@ -109,6 +109,7 @@ extern const struct file_operations gfs2
4116  extern const struct file_operations gfs2_dir_fops_nolock;
4117  
4118  extern void gfs2_set_inode_flags(struct inode *inode);
4119 +extern int gfs2_sync_flags(struct inode *inode, int flags, int vflags);
4120   
4121  #ifdef CONFIG_GFS2_FS_LOCKING_DLM
4122  extern const struct file_operations gfs2_file_fops;
4123 diff -NurpP --minimal linux-2.6.32.6/fs/gfs2/ops_inode.c linux-2.6.32.6-vs2.3.0.36.28/fs/gfs2/ops_inode.c
4124 --- linux-2.6.32.6/fs/gfs2/ops_inode.c  2009-12-03 20:02:52.000000000 +0100
4125 +++ linux-2.6.32.6-vs2.3.0.36.28/fs/gfs2/ops_inode.c    2009-12-03 20:04:56.000000000 +0100
4126 @@ -1400,6 +1400,7 @@ const struct inode_operations gfs2_file_
4127         .listxattr = gfs2_listxattr,
4128         .removexattr = gfs2_removexattr,
4129         .fiemap = gfs2_fiemap,
4130 +       .sync_flags = gfs2_sync_flags,
4131  };
4132  
4133  const struct inode_operations gfs2_dir_iops = {
4134 @@ -1420,6 +1421,7 @@ const struct inode_operations gfs2_dir_i
4135         .listxattr = gfs2_listxattr,
4136         .removexattr = gfs2_removexattr,
4137         .fiemap = gfs2_fiemap,
4138 +       .sync_flags = gfs2_sync_flags,
4139  };
4140  
4141  const struct inode_operations gfs2_symlink_iops = {
4142 diff -NurpP --minimal linux-2.6.32.6/fs/hfsplus/ioctl.c linux-2.6.32.6-vs2.3.0.36.28/fs/hfsplus/ioctl.c
4143 --- linux-2.6.32.6/fs/hfsplus/ioctl.c   2008-12-25 00:26:37.000000000 +0100
4144 +++ linux-2.6.32.6-vs2.3.0.36.28/fs/hfsplus/ioctl.c     2009-12-03 20:04:56.000000000 +0100
4145 @@ -17,6 +17,7 @@
4146  #include <linux/mount.h>
4147  #include <linux/sched.h>
4148  #include <linux/xattr.h>
4149 +#include <linux/mount.h>
4150  #include <asm/uaccess.h>
4151  #include "hfsplus_fs.h"
4152  
4153 diff -NurpP --minimal linux-2.6.32.6/fs/inode.c linux-2.6.32.6-vs2.3.0.36.28/fs/inode.c
4154 --- linux-2.6.32.6/fs/inode.c   2009-12-03 20:02:52.000000000 +0100
4155 +++ linux-2.6.32.6-vs2.3.0.36.28/fs/inode.c     2009-12-03 20:04:56.000000000 +0100
4156 @@ -133,6 +133,9 @@ int inode_init_always(struct super_block
4157         struct address_space *const mapping = &inode->i_data;
4158  
4159         inode->i_sb = sb;
4160 +
4161 +       /* essential because of inode slab reuse */
4162 +       inode->i_tag = 0;
4163         inode->i_blkbits = sb->s_blocksize_bits;
4164         inode->i_flags = 0;
4165         atomic_set(&inode->i_count, 1);
4166 @@ -153,6 +156,7 @@ int inode_init_always(struct super_block
4167         inode->i_bdev = NULL;
4168         inode->i_cdev = NULL;
4169         inode->i_rdev = 0;
4170 +       inode->i_mdev = 0;
4171         inode->dirtied_when = 0;
4172  
4173         if (security_inode_alloc(inode))
4174 @@ -307,6 +311,8 @@ void __iget(struct inode *inode)
4175         inodes_stat.nr_unused--;
4176  }
4177  
4178 +EXPORT_SYMBOL_GPL(__iget);
4179 +
4180  /**
4181   * clear_inode - clear an inode
4182   * @inode: inode to clear
4183 @@ -1611,9 +1617,11 @@ void init_special_inode(struct inode *in
4184         if (S_ISCHR(mode)) {
4185                 inode->i_fop = &def_chr_fops;
4186                 inode->i_rdev = rdev;
4187 +               inode->i_mdev = rdev;
4188         } else if (S_ISBLK(mode)) {
4189                 inode->i_fop = &def_blk_fops;
4190                 inode->i_rdev = rdev;
4191 +               inode->i_mdev = rdev;
4192         } else if (S_ISFIFO(mode))
4193                 inode->i_fop = &def_fifo_fops;
4194         else if (S_ISSOCK(mode))
4195 diff -NurpP --minimal linux-2.6.32.6/fs/ioctl.c linux-2.6.32.6-vs2.3.0.36.28/fs/ioctl.c
4196 --- linux-2.6.32.6/fs/ioctl.c   2009-12-03 20:02:52.000000000 +0100
4197 +++ linux-2.6.32.6-vs2.3.0.36.28/fs/ioctl.c     2009-12-03 20:04:56.000000000 +0100
4198 @@ -16,6 +16,9 @@
4199  #include <linux/writeback.h>
4200  #include <linux/buffer_head.h>
4201  #include <linux/falloc.h>
4202 +#include <linux/proc_fs.h>
4203 +#include <linux/vserver/inode.h>
4204 +#include <linux/vs_tag.h>
4205  
4206  #include <asm/ioctls.h>
4207  
4208 diff -NurpP --minimal linux-2.6.32.6/fs/ioprio.c linux-2.6.32.6-vs2.3.0.36.28/fs/ioprio.c
4209 --- linux-2.6.32.6/fs/ioprio.c  2009-03-24 14:22:26.000000000 +0100
4210 +++ linux-2.6.32.6-vs2.3.0.36.28/fs/ioprio.c    2009-12-03 20:04:56.000000000 +0100
4211 @@ -26,6 +26,7 @@
4212  #include <linux/syscalls.h>
4213  #include <linux/security.h>
4214  #include <linux/pid_namespace.h>
4215 +#include <linux/vs_base.h>
4216  
4217  int set_task_ioprio(struct task_struct *task, int ioprio)
4218  {
4219 @@ -123,6 +124,8 @@ SYSCALL_DEFINE3(ioprio_set, int, which, 
4220                         else
4221                                 pgrp = find_vpid(who);
4222                         do_each_pid_thread(pgrp, PIDTYPE_PGID, p) {
4223 +                               if (!vx_check(p->xid, VS_ADMIN_P | VS_IDENT))
4224 +                                       continue;
4225                                 ret = set_task_ioprio(p, ioprio);
4226                                 if (ret)
4227                                         break;
4228 @@ -212,6 +215,8 @@ SYSCALL_DEFINE2(ioprio_get, int, which, 
4229                         else
4230                                 pgrp = find_vpid(who);
4231                         do_each_pid_thread(pgrp, PIDTYPE_PGID, p) {
4232 +                               if (!vx_check(p->xid, VS_ADMIN_P | VS_IDENT))
4233 +                                       continue;
4234                                 tmpio = get_task_ioprio(p);
4235                                 if (tmpio < 0)
4236                                         continue;
4237 diff -NurpP --minimal linux-2.6.32.6/fs/jfs/acl.c linux-2.6.32.6-vs2.3.0.36.28/fs/jfs/acl.c
4238 --- linux-2.6.32.6/fs/jfs/acl.c 2009-12-03 20:02:52.000000000 +0100
4239 +++ linux-2.6.32.6-vs2.3.0.36.28/fs/jfs/acl.c   2009-12-03 20:04:56.000000000 +0100
4240 @@ -216,7 +216,8 @@ int jfs_setattr(struct dentry *dentry, s
4241                 return rc;
4242  
4243         if ((iattr->ia_valid & ATTR_UID && iattr->ia_uid != inode->i_uid) ||
4244 -           (iattr->ia_valid & ATTR_GID && iattr->ia_gid != inode->i_gid)) {
4245 +           (iattr->ia_valid & ATTR_GID && iattr->ia_gid != inode->i_gid) ||
4246 +           (iattr->ia_valid & ATTR_TAG && iattr->ia_tag != inode->i_tag)) {
4247                 if (vfs_dq_transfer(inode, iattr))
4248                         return -EDQUOT;
4249         }
4250 diff -NurpP --minimal linux-2.6.32.6/fs/jfs/file.c linux-2.6.32.6-vs2.3.0.36.28/fs/jfs/file.c
4251 --- linux-2.6.32.6/fs/jfs/file.c        2009-12-03 20:02:52.000000000 +0100
4252 +++ linux-2.6.32.6-vs2.3.0.36.28/fs/jfs/file.c  2009-12-03 20:04:56.000000000 +0100
4253 @@ -98,6 +98,7 @@ const struct inode_operations jfs_file_i
4254         .setattr        = jfs_setattr,
4255         .check_acl      = jfs_check_acl,
4256  #endif
4257 +       .sync_flags     = jfs_sync_flags,
4258  };
4259  
4260  const struct file_operations jfs_file_operations = {
4261 diff -NurpP --minimal linux-2.6.32.6/fs/jfs/ioctl.c linux-2.6.32.6-vs2.3.0.36.28/fs/jfs/ioctl.c
4262 --- linux-2.6.32.6/fs/jfs/ioctl.c       2008-12-25 00:26:37.000000000 +0100
4263 +++ linux-2.6.32.6-vs2.3.0.36.28/fs/jfs/ioctl.c 2009-12-03 20:04:56.000000000 +0100
4264 @@ -11,6 +11,7 @@
4265  #include <linux/mount.h>
4266  #include <linux/time.h>
4267  #include <linux/sched.h>
4268 +#include <linux/mount.h>
4269  #include <asm/current.h>
4270  #include <asm/uaccess.h>
4271  
4272 @@ -52,6 +53,16 @@ static long jfs_map_ext2(unsigned long f
4273  }
4274  
4275  
4276 +int jfs_sync_flags(struct inode *inode, int flags, int vflags)
4277 +{
4278 +       inode->i_flags = flags;
4279 +       inode->i_vflags = vflags;
4280 +       jfs_get_inode_flags(JFS_IP(inode));
4281 +       inode->i_ctime = CURRENT_TIME_SEC;
4282 +       mark_inode_dirty(inode);
4283 +       return 0;
4284 +}
4285 +
4286  long jfs_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
4287  {
4288         struct inode *inode = filp->f_dentry->d_inode;
4289 @@ -85,6 +96,11 @@ long jfs_ioctl(struct file *filp, unsign
4290                 if (!S_ISDIR(inode->i_mode))
4291                         flags &= ~JFS_DIRSYNC_FL;
4292  
4293 +               if (IS_BARRIER(inode)) {
4294 +                       vxwprintk_task(1, "messing with the barrier.");
4295 +                       return -EACCES;
4296 +               }
4297 +
4298                 /* Is it quota file? Do not allow user to mess with it */
4299                 if (IS_NOQUOTA(inode)) {
4300                         err = -EPERM;
4301 @@ -102,8 +118,8 @@ long jfs_ioctl(struct file *filp, unsign
4302                  * the relevant capability.
4303                  */
4304                 if ((oldflags & JFS_IMMUTABLE_FL) ||
4305 -                       ((flags ^ oldflags) &
4306 -                       (JFS_APPEND_FL | JFS_IMMUTABLE_FL))) {
4307 +                       ((flags ^ oldflags) & (JFS_APPEND_FL |
4308 +                       JFS_IMMUTABLE_FL | JFS_IXUNLINK_FL))) {
4309                         if (!capable(CAP_LINUX_IMMUTABLE)) {
4310                                 mutex_unlock(&inode->i_mutex);
4311                                 err = -EPERM;
4312 @@ -111,7 +127,7 @@ long jfs_ioctl(struct file *filp, unsign
4313                         }
4314                 }
4315  
4316 -               flags = flags & JFS_FL_USER_MODIFIABLE;
4317 +               flags &= JFS_FL_USER_MODIFIABLE;
4318                 flags |= oldflags & ~JFS_FL_USER_MODIFIABLE;
4319                 jfs_inode->mode2 = flags;
4320  
4321 diff -NurpP --minimal linux-2.6.32.6/fs/jfs/jfs_dinode.h linux-2.6.32.6-vs2.3.0.36.28/fs/jfs/jfs_dinode.h
4322 --- linux-2.6.32.6/fs/jfs/jfs_dinode.h  2008-12-25 00:26:37.000000000 +0100
4323 +++ linux-2.6.32.6-vs2.3.0.36.28/fs/jfs/jfs_dinode.h    2009-12-03 20:04:56.000000000 +0100
4324 @@ -161,9 +161,13 @@ struct dinode {
4325  
4326  #define JFS_APPEND_FL          0x01000000 /* writes to file may only append */
4327  #define JFS_IMMUTABLE_FL       0x02000000 /* Immutable file */
4328 +#define JFS_IXUNLINK_FL                0x08000000 /* Immutable invert on unlink */
4329  
4330 -#define JFS_FL_USER_VISIBLE    0x03F80000
4331 -#define JFS_FL_USER_MODIFIABLE 0x03F80000
4332 +#define JFS_BARRIER_FL         0x04000000 /* Barrier for chroot() */
4333 +#define JFS_COW_FL             0x20000000 /* Copy on Write marker */
4334 +
4335 +#define JFS_FL_USER_VISIBLE    0x07F80000
4336 +#define JFS_FL_USER_MODIFIABLE 0x07F80000
4337  #define JFS_FL_INHERIT         0x03C80000
4338  
4339  /* These are identical to EXT[23]_IOC_GETFLAGS/SETFLAGS */
4340 diff -NurpP --minimal linux-2.6.32.6/fs/jfs/jfs_filsys.h linux-2.6.32.6-vs2.3.0.36.28/fs/jfs/jfs_filsys.h
4341 --- linux-2.6.32.6/fs/jfs/jfs_filsys.h  2008-12-25 00:26:37.000000000 +0100
4342 +++ linux-2.6.32.6-vs2.3.0.36.28/fs/jfs/jfs_filsys.h    2009-12-03 20:04:56.000000000 +0100
4343 @@ -263,6 +263,7 @@
4344  #define JFS_NAME_MAX   255
4345  #define JFS_PATH_MAX   BPSIZE
4346  
4347 +#define JFS_TAGGED             0x00800000      /* Context Tagging */
4348  
4349  /*
4350   *     file system state (superblock state)
4351 diff -NurpP --minimal linux-2.6.32.6/fs/jfs/jfs_imap.c linux-2.6.32.6-vs2.3.0.36.28/fs/jfs/jfs_imap.c
4352 --- linux-2.6.32.6/fs/jfs/jfs_imap.c    2009-09-10 15:26:22.000000000 +0200
4353 +++ linux-2.6.32.6-vs2.3.0.36.28/fs/jfs/jfs_imap.c      2009-12-03 20:04:56.000000000 +0100
4354 @@ -45,6 +45,7 @@
4355  #include <linux/buffer_head.h>
4356  #include <linux/pagemap.h>
4357  #include <linux/quotaops.h>
4358 +#include <linux/vs_tag.h>
4359  
4360  #include "jfs_incore.h"
4361  #include "jfs_inode.h"
4362 @@ -3059,6 +3060,8 @@ static int copy_from_dinode(struct dinod
4363  {
4364         struct jfs_inode_info *jfs_ip = JFS_IP(ip);
4365         struct jfs_sb_info *sbi = JFS_SBI(ip->i_sb);
4366 +       uid_t uid;
4367 +       gid_t gid;
4368  
4369         jfs_ip->fileset = le32_to_cpu(dip->di_fileset);
4370         jfs_ip->mode2 = le32_to_cpu(dip->di_mode);
4371 @@ -3079,14 +3082,18 @@ static int copy_from_dinode(struct dinod
4372         }
4373         ip->i_nlink = le32_to_cpu(dip->di_nlink);
4374  
4375 -       jfs_ip->saved_uid = le32_to_cpu(dip->di_uid);
4376 +       uid = le32_to_cpu(dip->di_uid);
4377 +       gid = le32_to_cpu(dip->di_gid);
4378 +       ip->i_tag = INOTAG_TAG(DX_TAG(ip), uid, gid, 0);
4379 +
4380 +       jfs_ip->saved_uid = INOTAG_UID(DX_TAG(ip), uid, gid);
4381         if (sbi->uid == -1)
4382                 ip->i_uid = jfs_ip->saved_uid;
4383         else {
4384                 ip->i_uid = sbi->uid;
4385         }
4386  
4387 -       jfs_ip->saved_gid = le32_to_cpu(dip->di_gid);
4388 +       jfs_ip->saved_gid = INOTAG_GID(DX_TAG(ip), uid, gid);
4389         if (sbi->gid == -1)
4390                 ip->i_gid = jfs_ip->saved_gid;
4391         else {
4392 @@ -3151,14 +3158,12 @@ static void copy_to_dinode(struct dinode
4393         dip->di_size = cpu_to_le64(ip->i_size);
4394         dip->di_nblocks = cpu_to_le64(PBLK2LBLK(ip->i_sb, ip->i_blocks));
4395         dip->di_nlink = cpu_to_le32(ip->i_nlink);
4396 -       if (sbi->uid == -1)
4397 -               dip->di_uid = cpu_to_le32(ip->i_uid);
4398 -       else
4399 -               dip->di_uid = cpu_to_le32(jfs_ip->saved_uid);
4400 -       if (sbi->gid == -1)
4401 -               dip->di_gid = cpu_to_le32(ip->i_gid);
4402 -       else
4403 -               dip->di_gid = cpu_to_le32(jfs_ip->saved_gid);
4404 +
4405 +       dip->di_uid = cpu_to_le32(TAGINO_UID(DX_TAG(ip),
4406 +               (sbi->uid == -1) ? ip->i_uid : jfs_ip->saved_uid, ip->i_tag));
4407 +       dip->di_gid = cpu_to_le32(TAGINO_GID(DX_TAG(ip),
4408 +               (sbi->gid == -1) ? ip->i_gid : jfs_ip->saved_gid, ip->i_tag));
4409 +
4410         jfs_get_inode_flags(jfs_ip);
4411         /*
4412          * mode2 is only needed for storing the higher order bits.
4413 diff -NurpP --minimal linux-2.6.32.6/fs/jfs/jfs_inode.c linux-2.6.32.6-vs2.3.0.36.28/fs/jfs/jfs_inode.c
4414 --- linux-2.6.32.6/fs/jfs/jfs_inode.c   2009-06-11 17:13:05.000000000 +0200
4415 +++ linux-2.6.32.6-vs2.3.0.36.28/fs/jfs/jfs_inode.c     2009-12-03 20:04:56.000000000 +0100
4416 @@ -18,6 +18,7 @@
4417  
4418  #include <linux/fs.h>
4419  #include <linux/quotaops.h>
4420 +#include <linux/vs_tag.h>
4421  #include "jfs_incore.h"
4422  #include "jfs_inode.h"
4423  #include "jfs_filsys.h"
4424 @@ -30,29 +31,46 @@ void jfs_set_inode_flags(struct inode *i
4425  {
4426         unsigned int flags = JFS_IP(inode)->mode2;
4427  
4428 -       inode->i_flags &= ~(S_IMMUTABLE | S_APPEND |
4429 -               S_NOATIME | S_DIRSYNC | S_SYNC);
4430 +       inode->i_flags &= ~(S_IMMUTABLE | S_IXUNLINK |
4431 +               S_SYNC | S_APPEND | S_NOATIME | S_DIRSYNC);
4432  
4433         if (flags & JFS_IMMUTABLE_FL)
4434                 inode->i_flags |= S_IMMUTABLE;
4435 +       if (flags & JFS_IXUNLINK_FL)
4436 +               inode->i_flags |= S_IXUNLINK;
4437 +
4438 +       if (flags & JFS_SYNC_FL)
4439 +               inode->i_flags |= S_SYNC;
4440         if (flags & JFS_APPEND_FL)
4441                 inode->i_flags |= S_APPEND;
4442         if (flags & JFS_NOATIME_FL)
4443                 inode->i_flags |= S_NOATIME;
4444         if (flags & JFS_DIRSYNC_FL)
4445                 inode->i_flags |= S_DIRSYNC;
4446 -       if (flags & JFS_SYNC_FL)
4447 -               inode->i_flags |= S_SYNC;
4448 +
4449 +       inode->i_vflags &= ~(V_BARRIER | V_COW);
4450 +
4451 +       if (flags & JFS_BARRIER_FL)
4452 +               inode->i_vflags |= V_BARRIER;
4453 +       if (flags & JFS_COW_FL)
4454 +               inode->i_vflags |= V_COW;
4455  }
4456  
4457  void jfs_get_inode_flags(struct jfs_inode_info *jfs_ip)
4458  {
4459         unsigned int flags = jfs_ip->vfs_inode.i_flags;
4460 +       unsigned int vflags = jfs_ip->vfs_inode.i_vflags;
4461 +
4462 +       jfs_ip->mode2 &= ~(JFS_IMMUTABLE_FL | JFS_IXUNLINK_FL |
4463 +                          JFS_APPEND_FL | JFS_NOATIME_FL |
4464 +                          JFS_DIRSYNC_FL | JFS_SYNC_FL |
4465 +                          JFS_BARRIER_FL | JFS_COW_FL);
4466  
4467 -       jfs_ip->mode2 &= ~(JFS_IMMUTABLE_FL | JFS_APPEND_FL | JFS_NOATIME_FL |
4468 -                          JFS_DIRSYNC_FL | JFS_SYNC_FL);
4469         if (flags & S_IMMUTABLE)
4470                 jfs_ip->mode2 |= JFS_IMMUTABLE_FL;
4471 +       if (flags & S_IXUNLINK)
4472 +               jfs_ip->mode2 |= JFS_IXUNLINK_FL;
4473 +
4474         if (flags & S_APPEND)
4475                 jfs_ip->mode2 |= JFS_APPEND_FL;
4476         if (flags & S_NOATIME)
4477 @@ -61,6 +79,11 @@ void jfs_get_inode_flags(struct jfs_inod
4478                 jfs_ip->mode2 |= JFS_DIRSYNC_FL;
4479         if (flags & S_SYNC)
4480                 jfs_ip->mode2 |= JFS_SYNC_FL;
4481 +
4482 +       if (vflags & V_BARRIER)
4483 +               jfs_ip->mode2 |= JFS_BARRIER_FL;
4484 +       if (vflags & V_COW)
4485 +               jfs_ip->mode2 |= JFS_COW_FL;
4486  }
4487  
4488  /*
4489 @@ -105,6 +128,7 @@ struct inode *ialloc(struct inode *paren
4490                         mode |= S_ISGID;
4491         } else
4492                 inode->i_gid = current_fsgid();
4493 +       inode->i_tag = dx_current_fstag(sb);
4494  
4495         /*
4496          * New inodes need to save sane values on disk when
4497 diff -NurpP --minimal linux-2.6.32.6/fs/jfs/jfs_inode.h linux-2.6.32.6-vs2.3.0.36.28/fs/jfs/jfs_inode.h
4498 --- linux-2.6.32.6/fs/jfs/jfs_inode.h   2009-06-11 17:13:05.000000000 +0200
4499 +++ linux-2.6.32.6-vs2.3.0.36.28/fs/jfs/jfs_inode.h     2009-12-03 20:04:56.000000000 +0100
4500 @@ -39,6 +39,7 @@ extern struct dentry *jfs_fh_to_dentry(s
4501  extern struct dentry *jfs_fh_to_parent(struct super_block *sb, struct fid *fid,
4502         int fh_len, int fh_type);
4503  extern void jfs_set_inode_flags(struct inode *);
4504 +extern int jfs_sync_flags(struct inode *, int, int);
4505  extern int jfs_get_block(struct inode *, sector_t, struct buffer_head *, int);
4506  
4507  extern const struct address_space_operations jfs_aops;
4508 diff -NurpP --minimal linux-2.6.32.6/fs/jfs/namei.c linux-2.6.32.6-vs2.3.0.36.28/fs/jfs/namei.c
4509 --- linux-2.6.32.6/fs/jfs/namei.c       2009-12-03 20:02:52.000000000 +0100
4510 +++ linux-2.6.32.6-vs2.3.0.36.28/fs/jfs/namei.c 2009-12-03 20:04:56.000000000 +0100
4511 @@ -21,6 +21,7 @@
4512  #include <linux/ctype.h>
4513  #include <linux/quotaops.h>
4514  #include <linux/exportfs.h>
4515 +#include <linux/vs_tag.h>
4516  #include "jfs_incore.h"
4517  #include "jfs_superblock.h"
4518  #include "jfs_inode.h"
4519 @@ -1476,6 +1477,7 @@ static struct dentry *jfs_lookup(struct 
4520                 return ERR_CAST(ip);
4521         }
4522  
4523 +       dx_propagate_tag(nd, ip);
4524         dentry = d_splice_alias(ip, dentry);
4525  
4526         if (dentry && (JFS_SBI(dip->i_sb)->mntflag & JFS_OS2))
4527 @@ -1545,6 +1547,7 @@ const struct inode_operations jfs_dir_in
4528         .setattr        = jfs_setattr,
4529         .check_acl      = jfs_check_acl,
4530  #endif
4531 +       .sync_flags     = jfs_sync_flags,
4532  };
4533  
4534  const struct file_operations jfs_dir_operations = {
4535 diff -NurpP --minimal linux-2.6.32.6/fs/jfs/super.c linux-2.6.32.6-vs2.3.0.36.28/fs/jfs/super.c
4536 --- linux-2.6.32.6/fs/jfs/super.c       2009-12-03 20:02:52.000000000 +0100
4537 +++ linux-2.6.32.6-vs2.3.0.36.28/fs/jfs/super.c 2009-12-03 20:04:56.000000000 +0100
4538 @@ -192,7 +192,8 @@ static void jfs_put_super(struct super_b
4539  enum {
4540         Opt_integrity, Opt_nointegrity, Opt_iocharset, Opt_resize,
4541         Opt_resize_nosize, Opt_errors, Opt_ignore, Opt_err, Opt_quota,
4542 -       Opt_usrquota, Opt_grpquota, Opt_uid, Opt_gid, Opt_umask
4543 +       Opt_usrquota, Opt_grpquota, Opt_uid, Opt_gid, Opt_umask,
4544 +       Opt_tag, Opt_notag, Opt_tagid
4545  };
4546  
4547  static const match_table_t tokens = {
4548 @@ -202,6 +203,10 @@ static const match_table_t tokens = {
4549         {Opt_resize, "resize=%u"},
4550         {Opt_resize_nosize, "resize"},
4551         {Opt_errors, "errors=%s"},
4552 +       {Opt_tag, "tag"},
4553 +       {Opt_notag, "notag"},
4554 +       {Opt_tagid, "tagid=%u"},
4555 +       {Opt_tag, "tagxid"},
4556         {Opt_ignore, "noquota"},
4557         {Opt_ignore, "quota"},
4558         {Opt_usrquota, "usrquota"},
4559 @@ -336,6 +341,20 @@ static int parse_options(char *options, 
4560                         }
4561                         break;
4562                 }
4563 +#ifndef CONFIG_TAGGING_NONE
4564 +               case Opt_tag:
4565 +                       *flag |= JFS_TAGGED;
4566 +                       break;
4567 +               case Opt_notag:
4568 +                       *flag &= JFS_TAGGED;
4569 +                       break;
4570 +#endif
4571 +#ifdef CONFIG_PROPAGATE
4572 +               case Opt_tagid:
4573 +                       /* use args[0] */
4574 +                       *flag |= JFS_TAGGED;
4575 +                       break;
4576 +#endif
4577                 default:
4578                         printk("jfs: Unrecognized mount option \"%s\" "
4579                                         " or missing value\n", p);
4580 @@ -366,6 +385,12 @@ static int jfs_remount(struct super_bloc
4581         if (!parse_options(data, sb, &newLVSize, &flag)) {
4582                 return -EINVAL;
4583         }
4584 +       if ((flag & JFS_TAGGED) && !(sb->s_flags & MS_TAGGED)) {
4585 +               printk(KERN_ERR "JFS: %s: tagging not permitted on remount.\n",
4586 +                       sb->s_id);
4587 +               return -EINVAL;
4588 +       }
4589 +
4590         lock_kernel();
4591         if (newLVSize) {
4592                 if (sb->s_flags & MS_RDONLY) {
4593 @@ -449,6 +474,9 @@ static int jfs_fill_super(struct super_b
4594  #ifdef CONFIG_JFS_POSIX_ACL
4595         sb->s_flags |= MS_POSIXACL;
4596  #endif
4597 +       /* map mount option tagxid */
4598 +       if (sbi->flag & JFS_TAGGED)
4599 +               sb->s_flags |= MS_TAGGED;
4600  
4601         if (newLVSize) {
4602                 printk(KERN_ERR "resize option for remount only\n");
4603 diff -NurpP --minimal linux-2.6.32.6/fs/libfs.c linux-2.6.32.6-vs2.3.0.36.28/fs/libfs.c
4604 --- linux-2.6.32.6/fs/libfs.c   2009-12-03 20:02:52.000000000 +0100
4605 +++ linux-2.6.32.6-vs2.3.0.36.28/fs/libfs.c     2009-12-03 20:04:56.000000000 +0100
4606 @@ -127,7 +127,8 @@ static inline unsigned char dt_type(stru
4607   * both impossible due to the lock on directory.
4608   */
4609  
4610 -int dcache_readdir(struct file * filp, void * dirent, filldir_t filldir)
4611 +static inline int do_dcache_readdir_filter(struct file *filp,
4612 +       void *dirent, filldir_t filldir, int (*filter)(struct dentry *dentry))
4613  {
4614         struct dentry *dentry = filp->f_path.dentry;
4615         struct dentry *cursor = filp->private_data;
4616 @@ -160,6 +161,8 @@ int dcache_readdir(struct file * filp, v
4617                                 next = list_entry(p, struct dentry, d_u.d_child);
4618                                 if (d_unhashed(next) || !next->d_inode)
4619                                         continue;
4620 +                               if (filter && !filter(next))
4621 +                                       continue;
4622  
4623                                 spin_unlock(&dcache_lock);
4624                                 if (filldir(dirent, next->d_name.name, 
4625 @@ -178,6 +181,18 @@ int dcache_readdir(struct file * filp, v
4626         return 0;
4627  }
4628  
4629 +int dcache_readdir(struct file *filp, void *dirent, filldir_t filldir)
4630 +{
4631 +       return do_dcache_readdir_filter(filp, dirent, filldir, NULL);
4632 +}
4633 +
4634 +int dcache_readdir_filter(struct file *filp, void *dirent, filldir_t filldir,
4635 +       int (*filter)(struct dentry *))
4636 +{
4637 +       return do_dcache_readdir_filter(filp, dirent, filldir, filter);
4638 +}
4639 +
4640 +
4641  ssize_t generic_read_dir(struct file *filp, char __user *buf, size_t siz, loff_t *ppos)
4642  {
4643         return -EISDIR;
4644 @@ -841,6 +856,7 @@ EXPORT_SYMBOL(dcache_dir_close);
4645  EXPORT_SYMBOL(dcache_dir_lseek);
4646  EXPORT_SYMBOL(dcache_dir_open);
4647  EXPORT_SYMBOL(dcache_readdir);
4648 +EXPORT_SYMBOL(dcache_readdir_filter);
4649  EXPORT_SYMBOL(generic_read_dir);
4650  EXPORT_SYMBOL(get_sb_pseudo);
4651  EXPORT_SYMBOL(simple_write_begin);
4652 diff -NurpP --minimal linux-2.6.32.6/fs/locks.c linux-2.6.32.6-vs2.3.0.36.28/fs/locks.c
4653 --- linux-2.6.32.6/fs/locks.c   2009-12-03 20:02:52.000000000 +0100
4654 +++ linux-2.6.32.6-vs2.3.0.36.28/fs/locks.c     2009-12-03 20:04:56.000000000 +0100
4655 @@ -127,6 +127,8 @@
4656  #include <linux/time.h>
4657  #include <linux/rcupdate.h>
4658  #include <linux/pid_namespace.h>
4659 +#include <linux/vs_base.h>
4660 +#include <linux/vs_limit.h>
4661  
4662  #include <asm/uaccess.h>
4663  
4664 @@ -148,6 +150,8 @@ static struct kmem_cache *filelock_cache
4665  /* Allocate an empty lock structure. */
4666  static struct file_lock *locks_alloc_lock(void)
4667  {
4668 +       if (!vx_locks_avail(1))
4669 +               return NULL;
4670         return kmem_cache_alloc(filelock_cache, GFP_KERNEL);
4671  }
4672  
4673 @@ -174,6 +178,7 @@ static void locks_free_lock(struct file_
4674         BUG_ON(!list_empty(&fl->fl_block));
4675         BUG_ON(!list_empty(&fl->fl_link));
4676  
4677 +       vx_locks_dec(fl);
4678         locks_release_private(fl);
4679         kmem_cache_free(filelock_cache, fl);
4680  }
4681 @@ -194,6 +199,7 @@ void locks_init_lock(struct file_lock *f
4682         fl->fl_start = fl->fl_end = 0;
4683         fl->fl_ops = NULL;
4684         fl->fl_lmops = NULL;
4685 +       fl->fl_xid = -1;
4686  }
4687  
4688  EXPORT_SYMBOL(locks_init_lock);
4689 @@ -248,6 +254,7 @@ void locks_copy_lock(struct file_lock *n
4690         new->fl_file = fl->fl_file;
4691         new->fl_ops = fl->fl_ops;
4692         new->fl_lmops = fl->fl_lmops;
4693 +       new->fl_xid = fl->fl_xid;
4694  
4695         locks_copy_private(new, fl);
4696  }
4697 @@ -286,6 +293,11 @@ static int flock_make_lock(struct file *
4698         fl->fl_flags = FL_FLOCK;
4699         fl->fl_type = type;
4700         fl->fl_end = OFFSET_MAX;
4701 +
4702 +       vxd_assert(filp->f_xid == vx_current_xid(),
4703 +               "f_xid(%d) == current(%d)", filp->f_xid, vx_current_xid());
4704 +       fl->fl_xid = filp->f_xid;
4705 +       vx_locks_inc(fl);
4706         
4707         *lock = fl;
4708         return 0;
4709 @@ -451,6 +463,7 @@ static int lease_init(struct file *filp,
4710  
4711         fl->fl_owner = current->files;
4712         fl->fl_pid = current->tgid;
4713 +       fl->fl_xid = vx_current_xid();
4714  
4715         fl->fl_file = filp;
4716         fl->fl_flags = FL_LEASE;
4717 @@ -470,6 +483,11 @@ static struct file_lock *lease_alloc(str
4718         if (fl == NULL)
4719                 return ERR_PTR(error);
4720  
4721 +       fl->fl_xid = vx_current_xid();
4722 +       if (filp)
4723 +               vxd_assert(filp->f_xid == fl->fl_xid,
4724 +                       "f_xid(%d) == fl_xid(%d)", filp->f_xid, fl->fl_xid);
4725 +       vx_locks_inc(fl);
4726         error = lease_init(filp, type, fl);
4727         if (error) {
4728                 locks_free_lock(fl);
4729 @@ -770,6 +788,7 @@ static int flock_lock_file(struct file *
4730         if (found)
4731                 cond_resched();
4732  
4733 +       new_fl->fl_xid = -1;
4734  find_conflict:
4735         for_each_lock(inode, before) {
4736                 struct file_lock *fl = *before;
4737 @@ -790,6 +809,7 @@ find_conflict:
4738                 goto out;
4739         locks_copy_lock(new_fl, request);
4740         locks_insert_lock(before, new_fl);
4741 +       vx_locks_inc(new_fl);
4742         new_fl = NULL;
4743         error = 0;
4744  
4745 @@ -800,7 +820,8 @@ out:
4746         return error;
4747  }
4748  
4749 -static int __posix_lock_file(struct inode *inode, struct file_lock *request, struct file_lock *conflock)
4750 +static int __posix_lock_file(struct inode *inode, struct file_lock *request,
4751 +       struct file_lock *conflock, xid_t xid)
4752  {
4753         struct file_lock *fl;
4754         struct file_lock *new_fl = NULL;
4755 @@ -810,6 +831,8 @@ static int __posix_lock_file(struct inod
4756         struct file_lock **before;
4757         int error, added = 0;
4758  
4759 +       vxd_assert(xid == vx_current_xid(),
4760 +               "xid(%d) == current(%d)", xid, vx_current_xid());
4761         /*
4762          * We may need two file_lock structures for this operation,
4763          * so we get them in advance to avoid races.
4764 @@ -820,7 +843,11 @@ static int __posix_lock_file(struct inod
4765             (request->fl_type != F_UNLCK ||
4766              request->fl_start != 0 || request->fl_end != OFFSET_MAX)) {
4767                 new_fl = locks_alloc_lock();
4768 +               new_fl->fl_xid = xid;
4769 +               vx_locks_inc(new_fl);
4770                 new_fl2 = locks_alloc_lock();
4771 +               new_fl2->fl_xid = xid;
4772 +               vx_locks_inc(new_fl2);
4773         }
4774  
4775         lock_kernel();
4776 @@ -1019,7 +1046,8 @@ static int __posix_lock_file(struct inod
4777  int posix_lock_file(struct file *filp, struct file_lock *fl,
4778                         struct file_lock *conflock)
4779  {
4780 -       return __posix_lock_file(filp->f_path.dentry->d_inode, fl, conflock);
4781 +       return __posix_lock_file(filp->f_path.dentry->d_inode,
4782 +               fl, conflock, filp->f_xid);
4783  }
4784  EXPORT_SYMBOL(posix_lock_file);
4785  
4786 @@ -1109,7 +1137,7 @@ int locks_mandatory_area(int read_write,
4787         fl.fl_end = offset + count - 1;
4788  
4789         for (;;) {
4790 -               error = __posix_lock_file(inode, &fl, NULL);
4791 +               error = __posix_lock_file(inode, &fl, NULL, filp->f_xid);
4792                 if (error != FILE_LOCK_DEFERRED)
4793                         break;
4794                 error = wait_event_interruptible(fl.fl_wait, !fl.fl_next);
4795 @@ -1424,6 +1452,7 @@ int generic_setlease(struct file *filp, 
4796  
4797         locks_copy_lock(new_fl, lease);
4798         locks_insert_lock(before, new_fl);
4799 +       vx_locks_inc(new_fl);
4800  
4801         *flp = new_fl;
4802         return 0;
4803 @@ -1779,6 +1808,11 @@ int fcntl_setlk(unsigned int fd, struct 
4804         if (file_lock == NULL)
4805                 return -ENOLCK;
4806  
4807 +       vxd_assert(filp->f_xid == vx_current_xid(),
4808 +               "f_xid(%d) == current(%d)", filp->f_xid, vx_current_xid());
4809 +       file_lock->fl_xid = filp->f_xid;
4810 +       vx_locks_inc(file_lock);
4811 +
4812         /*
4813          * This might block, so we do it before checking the inode.
4814          */
4815 @@ -1897,6 +1931,11 @@ int fcntl_setlk64(unsigned int fd, struc
4816         if (file_lock == NULL)
4817                 return -ENOLCK;
4818  
4819 +       vxd_assert(filp->f_xid == vx_current_xid(),
4820 +               "f_xid(%d) == current(%d)", filp->f_xid, vx_current_xid());
4821 +       file_lock->fl_xid = filp->f_xid;
4822 +       vx_locks_inc(file_lock);
4823 +
4824         /*
4825          * This might block, so we do it before checking the inode.
4826          */
4827 @@ -2162,8 +2201,11 @@ static int locks_show(struct seq_file *f
4828  
4829         lock_get_status(f, fl, (long)f->private, "");
4830  
4831 -       list_for_each_entry(bfl, &fl->fl_block, fl_block)
4832 +       list_for_each_entry(bfl, &fl->fl_block, fl_block) {
4833 +               if (!vx_check(fl->fl_xid, VS_WATCH_P | VS_IDENT))
4834 +                       continue;
4835                 lock_get_status(f, bfl, (long)f->private, " ->");
4836 +       }
4837  
4838         f->private++;
4839         return 0;
4840 diff -NurpP --minimal linux-2.6.32.6/fs/namei.c linux-2.6.32.6-vs2.3.0.36.28/fs/namei.c
4841 --- linux-2.6.32.6/fs/namei.c   2010-01-26 19:31:26.000000000 +0100
4842 +++ linux-2.6.32.6-vs2.3.0.36.28/fs/namei.c     2010-01-13 14:33:47.000000000 +0100
4843 @@ -33,6 +33,14 @@
4844  #include <linux/fcntl.h>
4845  #include <linux/device_cgroup.h>
4846  #include <linux/fs_struct.h>
4847 +#include <linux/proc_fs.h>
4848 +#include <linux/vserver/inode.h>
4849 +#include <linux/vs_base.h>
4850 +#include <linux/vs_tag.h>
4851 +#include <linux/vs_cowbl.h>
4852 +#include <linux/vs_device.h>
4853 +#include <linux/vs_context.h>
4854 +#include <linux/pid_namespace.h>
4855  #include <asm/uaccess.h>
4856  
4857  #define ACC_MODE(x) ("\000\004\002\006"[(x)&O_ACCMODE])
4858 @@ -169,6 +177,77 @@ void putname(const char *name)
4859  EXPORT_SYMBOL(putname);
4860  #endif
4861  
4862 +static inline int dx_barrier(const struct inode *inode)
4863 +{
4864 +       if (IS_BARRIER(inode) && !vx_check(0, VS_ADMIN | VS_WATCH)) {
4865 +               vxwprintk_task(1, "did hit the barrier.");
4866 +               return 1;
4867 +       }
4868 +       return 0;
4869 +}
4870 +
4871 +static int __dx_permission(const struct inode *inode, int mask)
4872 +{
4873 +       if (dx_barrier(inode))
4874 +               return -EACCES;
4875 +
4876 +       if (inode->i_sb->s_magic == DEVPTS_SUPER_MAGIC) {
4877 +               /* devpts is xid tagged */
4878 +               if (S_ISDIR(inode->i_mode) ||
4879 +                   vx_check((xid_t)inode->i_tag, VS_IDENT | VS_WATCH_P))
4880 +                       return 0;
4881 +       }
4882 +       else if (inode->i_sb->s_magic == PROC_SUPER_MAGIC) {
4883 +               struct proc_dir_entry *de = PDE(inode);
4884 +
4885 +               if (de && !vx_hide_check(0, de->vx_flags))
4886 +                       goto out;
4887 +
4888 +               if ((mask & (MAY_WRITE | MAY_APPEND))) {
4889 +                       struct pid *pid;
4890 +                       struct task_struct *tsk;
4891 +
4892 +                       if (vx_check(0, VS_ADMIN | VS_WATCH_P) ||
4893 +                           vx_flags(VXF_STATE_SETUP, 0))
4894 +                               return 0;
4895 +
4896 +                       pid = PROC_I(inode)->pid;
4897 +                       if (!pid)
4898 +                               goto out;
4899 +
4900 +                       tsk = pid_task(pid, PIDTYPE_PID);
4901 +                       vxdprintk(VXD_CBIT(tag, 0), "accessing %p[#%u]",
4902 +                                 tsk, (tsk ? vx_task_xid(tsk) : 0));
4903 +                       if (tsk && vx_check(vx_task_xid(tsk), VS_IDENT | VS_WATCH_P))
4904 +                               return 0;
4905 +               }
4906 +               else {
4907 +                       /* FIXME: Should we block some entries here? */
4908 +                       return 0;
4909 +               }
4910 +       }
4911 +       else {
4912 +               if (dx_notagcheck(inode->i_sb) ||
4913 +                   dx_check(inode->i_tag, DX_HOSTID | DX_ADMIN | DX_WATCH |
4914 +                            DX_IDENT))
4915 +                       return 0;
4916 +       }
4917 +
4918 +out:
4919 +       return -EACCES;
4920 +}
4921 +
4922 +int dx_permission(const struct inode *inode, int mask)
4923 +{
4924 +       int ret = __dx_permission(inode, mask);
4925 +       if (unlikely(ret)) {
4926 +               vxwprintk_task(1, "denied %x access to %s:%p[#%d,%lu]",
4927 +                       mask, inode->i_sb->s_id, inode, inode->i_tag,
4928 +                       inode->i_ino);
4929 +       }
4930 +       return ret;
4931 +}
4932 +
4933  /*
4934   * This does basic POSIX ACL permission checking
4935   */
4936 @@ -269,10 +348,14 @@ int inode_permission(struct inode *inode
4937                 /*
4938                  * Nobody gets write access to an immutable file.
4939                  */
4940 -               if (IS_IMMUTABLE(inode))
4941 +               if (IS_IMMUTABLE(inode) && !IS_COW(inode))
4942                         return -EACCES;
4943         }
4944  
4945 +       retval = dx_permission(inode, mask);
4946 +       if (retval)
4947 +               return retval;
4948 +
4949         if (inode->i_op->permission)
4950                 retval = inode->i_op->permission(inode, mask);
4951         else
4952 @@ -448,6 +531,9 @@ static int exec_permission_lite(struct i
4953  {
4954         int ret;
4955  
4956 +       if (dx_barrier(inode))
4957 +               return -EACCES;
4958 +
4959         if (inode->i_op->permission) {
4960                 ret = inode->i_op->permission(inode, MAY_EXEC);
4961                 if (!ret)
4962 @@ -763,7 +849,8 @@ static __always_inline void follow_dotdo
4963  
4964                 if (nd->path.dentry == nd->root.dentry &&
4965                     nd->path.mnt == nd->root.mnt) {
4966 -                       break;
4967 +                       /* for sane '/' avoid follow_mount() */
4968 +                       return;
4969                 }
4970                 spin_lock(&dcache_lock);
4971                 if (nd->path.dentry != nd->path.mnt->mnt_root) {
4972 @@ -799,16 +886,30 @@ static int do_lookup(struct nameidata *n
4973  {
4974         struct vfsmount *mnt = nd->path.mnt;
4975         struct dentry *dentry = __d_lookup(nd->path.dentry, name);
4976 +       struct inode *inode;
4977  
4978         if (!dentry)
4979                 goto need_lookup;
4980         if (dentry->d_op && dentry->d_op->d_revalidate)
4981                 goto need_revalidate;
4982 +       inode = dentry->d_inode;
4983 +       if (!inode)
4984 +               goto done;
4985 +
4986 +       if (__dx_permission(inode, MAY_ACCESS))
4987 +               goto hidden;
4988 +
4989  done:
4990         path->mnt = mnt;
4991         path->dentry = dentry;
4992         __follow_mount(path);
4993         return 0;
4994 +hidden:
4995 +       vxwprintk_task(1, "did lookup hidden %s:%p[#%d,%lu] Â»%s/%.*s«.",
4996 +               inode->i_sb->s_id, inode, inode->i_tag, inode->i_ino,
4997 +               vxd_path(&nd->path), name->len, name->name);
4998 +       dput(dentry);
4999 +       return -ENOENT;
5000  
5001  need_lookup:
5002         dentry = real_lookup(nd->path.dentry, name, nd);
5003 @@ -1390,7 +1491,7 @@ static int may_delete(struct inode *dir,
5004         if (IS_APPEND(dir))
5005                 return -EPERM;
5006         if (check_sticky(dir, victim->d_inode)||IS_APPEND(victim->d_inode)||
5007 -           IS_IMMUTABLE(victim->d_inode) || IS_SWAPFILE(victim->d_inode))
5008 +               IS_IXORUNLINK(victim->d_inode) || IS_SWAPFILE(victim->d_inode))
5009                 return -EPERM;
5010         if (isdir) {
5011                 if (!S_ISDIR(victim->d_inode->i_mode))
5012 @@ -1530,6 +1631,14 @@ int may_open(struct path *path, int acc_
5013                 break;
5014         }
5015  
5016 +#ifdef CONFIG_VSERVER_COWBL
5017 +       if (IS_COW(inode) && (flag & FMODE_WRITE)) {
5018 +               if (IS_COW_LINK(inode))
5019 +                       return -EMLINK;
5020 +               inode->i_flags &= ~(S_IXUNLINK|S_IMMUTABLE);
5021 +               mark_inode_dirty(inode);
5022 +       }
5023 +#endif
5024         error = inode_permission(inode, acc_mode);
5025         if (error)
5026                 return error;
5027 @@ -1678,7 +1787,11 @@ struct file *do_filp_open(int dfd, const
5028         int count = 0;
5029         int will_write;
5030         int flag = open_to_namei_flags(open_flag);
5031 -
5032 +#ifdef CONFIG_VSERVER_COWBL
5033 +       int rflag = flag;
5034 +       int rmode = mode;
5035 +restart:
5036 +#endif
5037         if (!acc_mode)
5038                 acc_mode = MAY_OPEN | ACC_MODE(flag);
5039  
5040 @@ -1826,6 +1939,25 @@ ok:
5041                         goto exit;
5042         }
5043         error = may_open(&nd.path, acc_mode, flag);
5044 +#ifdef CONFIG_VSERVER_COWBL
5045 +       if (error == -EMLINK) {
5046 +               struct dentry *dentry;
5047 +               dentry = cow_break_link(pathname);
5048 +               if (IS_ERR(dentry)) {
5049 +                       error = PTR_ERR(dentry);
5050 +                       goto exit_cow;
5051 +               }
5052 +               dput(dentry);
5053 +               if (will_write)
5054 +                       mnt_drop_write(nd.path.mnt);
5055 +               release_open_intent(&nd);
5056 +               path_put(&nd.path);
5057 +               flag = rflag;
5058 +               mode = rmode;
5059 +               goto restart;
5060 +       }
5061 +exit_cow:
5062 +#endif
5063         if (error) {
5064                 if (will_write)
5065                         mnt_drop_write(nd.path.mnt);
5066 @@ -1988,9 +2120,17 @@ int vfs_mknod(struct inode *dir, struct 
5067         if (error)
5068                 return error;
5069  
5070 -       if ((S_ISCHR(mode) || S_ISBLK(mode)) && !capable(CAP_MKNOD))
5071 +       if (!(S_ISCHR(mode) || S_ISBLK(mode)))
5072 +               goto okay;
5073 +
5074 +       if (!capable(CAP_MKNOD))
5075                 return -EPERM;
5076  
5077 +       if (S_ISCHR(mode) && !vs_chrdev_perm(dev, DATTR_CREATE))
5078 +               return -EPERM;
5079 +       if (S_ISBLK(mode) && !vs_blkdev_perm(dev, DATTR_CREATE))
5080 +               return -EPERM;
5081 +okay:
5082         if (!dir->i_op->mknod)
5083                 return -EPERM;
5084  
5085 @@ -2457,7 +2597,7 @@ int vfs_link(struct dentry *old_dentry, 
5086         /*
5087          * A link to an append-only or immutable file cannot be created.
5088          */
5089 -       if (IS_APPEND(inode) || IS_IMMUTABLE(inode))
5090 +       if (IS_APPEND(inode) || IS_IXORUNLINK(inode))
5091                 return -EPERM;
5092         if (!dir->i_op->link)
5093                 return -EPERM;
5094 @@ -2830,6 +2970,219 @@ int vfs_follow_link(struct nameidata *nd
5095         return __vfs_follow_link(nd, link);
5096  }
5097  
5098 +
5099 +#ifdef CONFIG_VSERVER_COWBL
5100 +
5101 +#include <linux/file.h>
5102 +
5103 +static inline
5104 +long do_cow_splice(struct file *in, struct file *out, size_t len)
5105 +{
5106 +       loff_t ppos = 0;
5107 +
5108 +       return do_splice_direct(in, &ppos, out, len, 0);
5109 +}
5110 +
5111 +struct dentry *cow_break_link(const char *pathname)
5112 +{
5113 +       int ret, mode, pathlen, redo = 0;
5114 +       struct nameidata old_nd, dir_nd;
5115 +       struct path old_path, new_path;
5116 +       struct dentry *dir, *res = NULL;
5117 +       struct file *old_file;
5118 +       struct file *new_file;
5119 +       char *to, *path, pad='\251';
5120 +       loff_t size;
5121 +
5122 +       vxdprintk(VXD_CBIT(misc, 1), "cow_break_link(»%s«)", pathname);
5123 +       path = kmalloc(PATH_MAX, GFP_KERNEL);
5124 +       ret = -ENOMEM;
5125 +       if (!path)
5126 +               goto out;
5127 +
5128 +       /* old_nd will have refs to dentry and mnt */
5129 +       ret = path_lookup(pathname, LOOKUP_FOLLOW, &old_nd);
5130 +       vxdprintk(VXD_CBIT(misc, 2), "path_lookup(old): %d", ret);
5131 +       if (ret < 0)
5132 +               goto out_free_path;
5133 +
5134 +       old_path = old_nd.path;
5135 +       mode = old_path.dentry->d_inode->i_mode;
5136 +
5137 +       to = d_path(&old_path, path, PATH_MAX-2);
5138 +       pathlen = strlen(to);
5139 +       vxdprintk(VXD_CBIT(misc, 2), "old path Â»%s« [»%.*s«:%d]", to,
5140 +               old_path.dentry->d_name.len, old_path.dentry->d_name.name,
5141 +               old_path.dentry->d_name.len);
5142 +
5143 +       to[pathlen + 1] = 0;
5144 +retry:
5145 +       to[pathlen] = pad--;
5146 +       ret = -EMLINK;
5147 +       if (pad <= '\240')
5148 +               goto out_rel_old;
5149 +
5150 +       vxdprintk(VXD_CBIT(misc, 1), "temp copy Â»%s«", to);
5151 +       /* dir_nd will have refs to dentry and mnt */
5152 +       ret = path_lookup(to,
5153 +               LOOKUP_PARENT | LOOKUP_OPEN | LOOKUP_CREATE, &dir_nd);
5154 +       vxdprintk(VXD_CBIT(misc, 2),
5155 +               "path_lookup(new): %d", ret);
5156 +       if (ret < 0)
5157 +               goto retry;
5158 +
5159 +       /* this puppy downs the inode mutex */
5160 +       new_path.dentry = lookup_create(&dir_nd, 0);
5161 +       if (!new_path.dentry || IS_ERR(new_path.dentry)) {
5162 +               vxdprintk(VXD_CBIT(misc, 2),
5163 +                       "lookup_create(new): %p", new_path.dentry);
5164 +               mutex_unlock(&dir_nd.path.dentry->d_inode->i_mutex);
5165 +               path_put(&dir_nd.path);
5166 +               goto retry;
5167 +       }
5168 +       vxdprintk(VXD_CBIT(misc, 2),
5169 +               "lookup_create(new): %p [»%.*s«:%d]", new_path.dentry,
5170 +               new_path.dentry->d_name.len, new_path.dentry->d_name.name,
5171 +               new_path.dentry->d_name.len);
5172 +       dir = dir_nd.path.dentry;
5173 +
5174 +       ret = vfs_create(dir_nd.path.dentry->d_inode, new_path.dentry, mode, &dir_nd);
5175 +       vxdprintk(VXD_CBIT(misc, 2),
5176 +               "vfs_create(new): %d", ret);
5177 +       if (ret == -EEXIST) {
5178 +               mutex_unlock(&dir->d_inode->i_mutex);
5179 +               dput(new_path.dentry);
5180 +               path_put(&dir_nd.path);
5181 +               goto retry;
5182 +       }
5183 +       else if (ret < 0)
5184 +               goto out_unlock_new;
5185 +
5186 +       /* drop out early, ret passes ENOENT */
5187 +       ret = -ENOENT;
5188 +       if ((redo = d_unhashed(old_path.dentry)))
5189 +               goto out_unlock_new;
5190 +
5191 +       new_path.mnt = dir_nd.path.mnt;
5192 +       dget(old_path.dentry);
5193 +       mntget(old_path.mnt);
5194 +       /* this one cleans up the dentry/mnt in case of failure */
5195 +       old_file = dentry_open(old_path.dentry, old_path.mnt,
5196 +               O_RDONLY, current_cred());
5197 +       vxdprintk(VXD_CBIT(misc, 2),
5198 +               "dentry_open(old): %p", old_file);
5199 +       if (!old_file || IS_ERR(old_file)) {
5200 +               res = IS_ERR(old_file) ? (void *) old_file : res;
5201 +               goto out_unlock_new;
5202 +       }
5203 +
5204 +       dget(new_path.dentry);
5205 +       mntget(new_path.mnt);
5206 +       /* this one cleans up the dentry/mnt in case of failure */
5207 +       new_file = dentry_open(new_path.dentry, new_path.mnt,
5208 +               O_WRONLY, current_cred());
5209 +       vxdprintk(VXD_CBIT(misc, 2),
5210 +               "dentry_open(new): %p", new_file);
5211 +
5212 +       ret = IS_ERR(new_file) ? PTR_ERR(new_file) : -ENOENT;
5213 +       if (!new_file || IS_ERR(new_file))
5214 +               goto out_fput_old;
5215 +
5216 +       size = i_size_read(old_file->f_dentry->d_inode);
5217 +       ret = do_cow_splice(old_file, new_file, size);
5218 +       vxdprintk(VXD_CBIT(misc, 2), "do_splice_direct: %d", ret);
5219 +       if (ret < 0) {
5220 +               goto out_fput_both;
5221 +       } else if (ret < size) {
5222 +               ret = -ENOSPC;
5223 +               goto out_fput_both;
5224 +       } else {
5225 +               struct inode *old_inode = old_path.dentry->d_inode;
5226 +               struct inode *new_inode = new_path.dentry->d_inode;
5227 +               struct iattr attr = {
5228 +                       .ia_uid = old_inode->i_uid,
5229 +                       .ia_gid = old_inode->i_gid,
5230 +                       .ia_valid = ATTR_UID | ATTR_GID
5231 +                       };
5232 +
5233 +               ret = inode_setattr(new_inode, &attr);
5234 +               if (ret)
5235 +                       goto out_fput_both;
5236 +       }
5237 +
5238 +       mutex_lock(&old_path.dentry->d_inode->i_sb->s_vfs_rename_mutex);
5239 +
5240 +       /* drop out late */
5241 +       ret = -ENOENT;
5242 +       if ((redo = d_unhashed(old_path.dentry)))
5243 +               goto out_unlock;
5244 +
5245 +       vxdprintk(VXD_CBIT(misc, 2),
5246 +               "vfs_rename: [»%*s«:%d] -> [»%*s«:%d]",
5247 +               new_path.dentry->d_name.len, new_path.dentry->d_name.name,
5248 +               new_path.dentry->d_name.len,
5249 +               old_path.dentry->d_name.len, old_path.dentry->d_name.name,
5250 +               old_path.dentry->d_name.len);
5251 +       ret = vfs_rename(dir_nd.path.dentry->d_inode, new_path.dentry,
5252 +               old_nd.path.dentry->d_parent->d_inode, old_path.dentry);
5253 +       vxdprintk(VXD_CBIT(misc, 2), "vfs_rename: %d", ret);
5254 +       res = new_path.dentry;
5255 +
5256 +out_unlock:
5257 +       mutex_unlock(&old_path.dentry->d_inode->i_sb->s_vfs_rename_mutex);
5258 +
5259 +out_fput_both:
5260 +       vxdprintk(VXD_CBIT(misc, 3),
5261 +               "fput(new_file=%p[#%ld])", new_file,
5262 +               atomic_long_read(&new_file->f_count));
5263 +       fput(new_file);
5264 +
5265 +out_fput_old:
5266 +       vxdprintk(VXD_CBIT(misc, 3),
5267 +               "fput(old_file=%p[#%ld])", old_file,
5268 +               atomic_long_read(&old_file->f_count));
5269 +       fput(old_file);
5270 +
5271 +out_unlock_new:
5272 +       mutex_unlock(&dir->d_inode->i_mutex);
5273 +       if (!ret)
5274 +               goto out_redo;
5275 +
5276 +       /* error path cleanup */
5277 +       vfs_unlink(dir->d_inode, new_path.dentry);
5278 +       dput(new_path.dentry);
5279 +
5280 +out_redo:
5281 +       if (!redo)
5282 +               goto out_rel_both;
5283 +       /* lookup dentry once again */
5284 +       path_put(&old_nd.path);
5285 +       ret = path_lookup(pathname, LOOKUP_FOLLOW, &old_nd);
5286 +       if (ret)
5287 +               goto out_rel_both;
5288 +
5289 +       new_path.dentry = old_nd.path.dentry;
5290 +       vxdprintk(VXD_CBIT(misc, 2),
5291 +               "path_lookup(redo): %p [»%.*s«:%d]", new_path.dentry,
5292 +               new_path.dentry->d_name.len, new_path.dentry->d_name.name,
5293 +               new_path.dentry->d_name.len);
5294 +       dget(new_path.dentry);
5295 +       res = new_path.dentry;
5296 +
5297 +out_rel_both:
5298 +       path_put(&dir_nd.path);
5299 +out_rel_old:
5300 +       path_put(&old_nd.path);
5301 +out_free_path:
5302 +       kfree(path);
5303 +out:
5304 +       if (ret)
5305 +               res = ERR_PTR(ret);
5306 +       return res;
5307 +}
5308 +
5309 +#endif
5310 +
5311  /* get the link contents into pagecache */
5312  static char *page_getlink(struct dentry * dentry, struct page **ppage)
5313  {
5314 diff -NurpP --minimal linux-2.6.32.6/fs/namespace.c linux-2.6.32.6-vs2.3.0.36.28/fs/namespace.c
5315 --- linux-2.6.32.6/fs/namespace.c       2009-12-03 20:02:52.000000000 +0100
5316 +++ linux-2.6.32.6-vs2.3.0.36.28/fs/namespace.c 2009-12-03 20:04:56.000000000 +0100
5317 @@ -29,6 +29,11 @@
5318  #include <linux/log2.h>
5319  #include <linux/idr.h>
5320  #include <linux/fs_struct.h>
5321 +#include <linux/vs_base.h>
5322 +#include <linux/vs_context.h>
5323 +#include <linux/vs_tag.h>
5324 +#include <linux/vserver/space.h>
5325 +#include <linux/vserver/global.h>
5326  #include <asm/uaccess.h>
5327  #include <asm/unistd.h>
5328  #include "pnode.h"
5329 @@ -567,6 +572,7 @@ static struct vfsmount *clone_mnt(struct
5330                 mnt->mnt_root = dget(root);
5331                 mnt->mnt_mountpoint = mnt->mnt_root;
5332                 mnt->mnt_parent = mnt;
5333 +               mnt->mnt_tag = old->mnt_tag;
5334  
5335                 if (flag & CL_SLAVE) {
5336                         list_add(&mnt->mnt_slave, &old->mnt_slave_list);
5337 @@ -661,6 +667,31 @@ static inline void mangle(struct seq_fil
5338         seq_escape(m, s, " \t\n\\");
5339  }
5340  
5341 +static int mnt_is_reachable(struct vfsmount *mnt)
5342 +{
5343 +       struct path root;
5344 +       struct dentry *point;
5345 +       int ret;
5346 +
5347 +       if (mnt == mnt->mnt_ns->root)
5348 +               return 1;
5349 +
5350 +       spin_lock(&vfsmount_lock);
5351 +       root = current->fs->root;
5352 +       point = root.dentry;
5353 +
5354 +       while ((mnt != mnt->mnt_parent) && (mnt != root.mnt)) {
5355 +               point = mnt->mnt_mountpoint;
5356 +               mnt = mnt->mnt_parent;
5357 +       }
5358 +
5359 +       ret = (mnt == root.mnt) && is_subdir(point, root.dentry);
5360 +
5361 +       spin_unlock(&vfsmount_lock);
5362 +
5363 +       return ret;
5364 +}
5365 +
5366  /*
5367   * Simple .show_options callback for filesystems which don't want to
5368   * implement more complex mount option showing.
5369 @@ -748,6 +779,8 @@ static int show_sb_opts(struct seq_file 
5370                 { MS_SYNCHRONOUS, ",sync" },
5371                 { MS_DIRSYNC, ",dirsync" },
5372                 { MS_MANDLOCK, ",mand" },
5373 +               { MS_TAGGED, ",tag" },
5374 +               { MS_NOTAGCHECK, ",notagcheck" },
5375                 { 0, NULL }
5376         };
5377         const struct proc_fs_info *fs_infop;
5378 @@ -795,10 +828,20 @@ static int show_vfsmnt(struct seq_file *
5379         int err = 0;
5380         struct path mnt_path = { .dentry = mnt->mnt_root, .mnt = mnt };
5381  
5382 -       mangle(m, mnt->mnt_devname ? mnt->mnt_devname : "none");
5383 -       seq_putc(m, ' ');
5384 -       seq_path(m, &mnt_path, " \t\n\\");
5385 -       seq_putc(m, ' ');
5386 +       if (vx_flags(VXF_HIDE_MOUNT, 0))
5387 +               return SEQ_SKIP;
5388 +       if (!mnt_is_reachable(mnt) && !vx_check(0, VS_WATCH_P))
5389 +               return SEQ_SKIP;
5390 +
5391 +       if (!vx_check(0, VS_ADMIN|VS_WATCH) &&
5392 +               mnt == current->fs->root.mnt) {
5393 +               seq_puts(m, "/dev/root / ");
5394 +       } else {
5395 +               mangle(m, mnt->mnt_devname ? mnt->mnt_devname : "none");
5396 +               seq_putc(m, ' ');
5397 +               seq_path(m, &mnt_path, " \t\n\\");
5398 +               seq_putc(m, ' ');
5399 +       }
5400         show_type(m, mnt->mnt_sb);
5401         seq_puts(m, __mnt_is_readonly(mnt) ? " ro" : " rw");
5402         err = show_sb_opts(m, mnt->mnt_sb);
5403 @@ -828,6 +871,11 @@ static int show_mountinfo(struct seq_fil
5404         struct path root = p->root;
5405         int err = 0;
5406  
5407 +       if (vx_flags(VXF_HIDE_MOUNT, 0))
5408 +               return SEQ_SKIP;
5409 +       if (!mnt_is_reachable(mnt) && !vx_check(0, VS_WATCH_P))
5410 +               return SEQ_SKIP;
5411 +
5412         seq_printf(m, "%i %i %u:%u ", mnt->mnt_id, mnt->mnt_parent->mnt_id,
5413                    MAJOR(sb->s_dev), MINOR(sb->s_dev));
5414         seq_dentry(m, mnt->mnt_root, " \t\n\\");
5415 @@ -886,17 +934,27 @@ static int show_vfsstat(struct seq_file 
5416         struct path mnt_path = { .dentry = mnt->mnt_root, .mnt = mnt };
5417         int err = 0;
5418  
5419 -       /* device */
5420 -       if (mnt->mnt_devname) {
5421 -               seq_puts(m, "device ");
5422 -               mangle(m, mnt->mnt_devname);
5423 -       } else
5424 -               seq_puts(m, "no device");
5425 +       if (vx_flags(VXF_HIDE_MOUNT, 0))
5426 +               return SEQ_SKIP;
5427 +       if (!mnt_is_reachable(mnt) && !vx_check(0, VS_WATCH_P))
5428 +               return SEQ_SKIP;
5429  
5430 -       /* mount point */
5431 -       seq_puts(m, " mounted on ");
5432 -       seq_path(m, &mnt_path, " \t\n\\");
5433 -       seq_putc(m, ' ');
5434 +       if (!vx_check(0, VS_ADMIN|VS_WATCH) &&
5435 +               mnt == current->fs->root.mnt) {
5436 +               seq_puts(m, "device /dev/root mounted on / ");
5437 +       } else {
5438 +               /* device */
5439 +               if (mnt->mnt_devname) {
5440 +                       seq_puts(m, "device ");
5441 +                       mangle(m, mnt->mnt_devname);
5442 +               } else
5443 +                       seq_puts(m, "no device");
5444 +
5445 +               /* mount point */
5446 +               seq_puts(m, " mounted on ");
5447 +               seq_path(m, &mnt_path, " \t\n\\");
5448 +               seq_putc(m, ' ');
5449 +       }
5450  
5451         /* file system type */
5452         seq_puts(m, "with fstype ");
5453 @@ -1130,7 +1188,7 @@ SYSCALL_DEFINE2(umount, char __user *, n
5454                 goto dput_and_out;
5455  
5456         retval = -EPERM;
5457 -       if (!capable(CAP_SYS_ADMIN))
5458 +       if (!vx_capable(CAP_SYS_ADMIN, VXC_SECURE_MOUNT))
5459                 goto dput_and_out;
5460  
5461         retval = do_umount(path.mnt, flags);
5462 @@ -1156,7 +1214,7 @@ SYSCALL_DEFINE1(oldumount, char __user *
5463  
5464  static int mount_is_safe(struct path *path)
5465  {
5466 -       if (capable(CAP_SYS_ADMIN))
5467 +       if (vx_capable(CAP_SYS_ADMIN, VXC_SECURE_MOUNT))
5468                 return 0;
5469         return -EPERM;
5470  #ifdef notyet
5471 @@ -1420,7 +1478,7 @@ static int do_change_type(struct path *p
5472         int type = flag & ~MS_REC;
5473         int err = 0;
5474  
5475 -       if (!capable(CAP_SYS_ADMIN))
5476 +       if (!vx_capable(CAP_SYS_ADMIN, VXC_NAMESPACE))
5477                 return -EPERM;
5478  
5479         if (path->dentry != path->mnt->mnt_root)
5480 @@ -1447,11 +1505,13 @@ static int do_change_type(struct path *p
5481   * do loopback mount.
5482   */
5483  static int do_loopback(struct path *path, char *old_name,
5484 -                               int recurse)
5485 +       tag_t tag, unsigned long flags, int mnt_flags)
5486  {
5487         struct path old_path;
5488         struct vfsmount *mnt = NULL;
5489         int err = mount_is_safe(path);
5490 +       int recurse = flags & MS_REC;
5491 +
5492         if (err)
5493                 return err;
5494         if (!old_name || !*old_name)
5495 @@ -1485,6 +1545,7 @@ static int do_loopback(struct path *path
5496                 spin_unlock(&vfsmount_lock);
5497                 release_mounts(&umount_list);
5498         }
5499 +       mnt->mnt_flags = mnt_flags;
5500  
5501  out:
5502         up_write(&namespace_sem);
5503 @@ -1515,12 +1576,12 @@ static int change_mount_flags(struct vfs
5504   * on it - tough luck.
5505   */
5506  static int do_remount(struct path *path, int flags, int mnt_flags,
5507 -                     void *data)
5508 +       void *data, xid_t xid)
5509  {
5510         int err;
5511         struct super_block *sb = path->mnt->mnt_sb;
5512  
5513 -       if (!capable(CAP_SYS_ADMIN))
5514 +       if (!vx_capable(CAP_SYS_ADMIN, VXC_SECURE_REMOUNT))
5515                 return -EPERM;
5516  
5517         if (!check_mnt(path->mnt))
5518 @@ -1562,7 +1623,7 @@ static int do_move_mount(struct path *pa
5519         struct path old_path, parent_path;
5520         struct vfsmount *p;
5521         int err = 0;
5522 -       if (!capable(CAP_SYS_ADMIN))
5523 +       if (!vx_capable(CAP_SYS_ADMIN, VXC_SECURE_MOUNT))
5524                 return -EPERM;
5525         if (!old_name || !*old_name)
5526                 return -EINVAL;
5527 @@ -1644,7 +1705,7 @@ static int do_new_mount(struct path *pat
5528                 return -EINVAL;
5529  
5530         /* we need capabilities... */
5531 -       if (!capable(CAP_SYS_ADMIN))
5532 +       if (!vx_capable(CAP_SYS_ADMIN, VXC_SECURE_MOUNT))
5533                 return -EPERM;
5534  
5535         lock_kernel();
5536 @@ -1908,6 +1969,7 @@ long do_mount(char *dev_name, char *dir_
5537         struct path path;
5538         int retval = 0;
5539         int mnt_flags = 0;
5540 +       tag_t tag = 0;
5541  
5542         /* Discard magic */
5543         if ((flags & MS_MGC_MSK) == MS_MGC_VAL)
5544 @@ -1925,6 +1987,12 @@ long do_mount(char *dev_name, char *dir_
5545         if (!(flags & MS_NOATIME))
5546                 mnt_flags |= MNT_RELATIME;
5547  
5548 +       if (dx_parse_tag(data_page, &tag, 1, &mnt_flags, &flags)) {
5549 +               /* FIXME: bind and re-mounts get the tag flag? */
5550 +               if (flags & (MS_BIND|MS_REMOUNT))
5551 +                       flags |= MS_TAGID;
5552 +       }
5553 +
5554         /* Separate the per-mountpoint flags */
5555         if (flags & MS_NOSUID)
5556                 mnt_flags |= MNT_NOSUID;
5557 @@ -1941,6 +2009,8 @@ long do_mount(char *dev_name, char *dir_
5558         if (flags & MS_RDONLY)
5559                 mnt_flags |= MNT_READONLY;
5560  
5561 +       if (!capable(CAP_SYS_ADMIN))
5562 +               mnt_flags |= MNT_NODEV;
5563         flags &= ~(MS_NOSUID | MS_NOEXEC | MS_NODEV | MS_ACTIVE |
5564                    MS_NOATIME | MS_NODIRATIME | MS_RELATIME| MS_KERNMOUNT |
5565                    MS_STRICTATIME);
5566 @@ -1957,9 +2027,9 @@ long do_mount(char *dev_name, char *dir_
5567  
5568         if (flags & MS_REMOUNT)
5569                 retval = do_remount(&path, flags & ~MS_REMOUNT, mnt_flags,
5570 -                                   data_page);
5571 +                                   data_page, tag);
5572         else if (flags & MS_BIND)
5573 -               retval = do_loopback(&path, dev_name, flags & MS_REC);
5574 +               retval = do_loopback(&path, dev_name, tag, flags, mnt_flags);
5575         else if (flags & (MS_SHARED | MS_PRIVATE | MS_SLAVE | MS_UNBINDABLE))
5576                 retval = do_change_type(&path, flags);
5577         else if (flags & MS_MOVE)
5578 @@ -2038,6 +2108,7 @@ static struct mnt_namespace *dup_mnt_ns(
5579                 q = next_mnt(q, new_ns->root);
5580         }
5581         up_write(&namespace_sem);
5582 +       atomic_inc(&vs_global_mnt_ns);
5583  
5584         if (rootmnt)
5585                 mntput(rootmnt);
5586 @@ -2182,9 +2253,10 @@ SYSCALL_DEFINE2(pivot_root, const char _
5587         down_write(&namespace_sem);
5588         mutex_lock(&old.dentry->d_inode->i_mutex);
5589         error = -EINVAL;
5590 -       if (IS_MNT_SHARED(old.mnt) ||
5591 +       if ((IS_MNT_SHARED(old.mnt) ||
5592                 IS_MNT_SHARED(new.mnt->mnt_parent) ||
5593 -               IS_MNT_SHARED(root.mnt->mnt_parent))
5594 +               IS_MNT_SHARED(root.mnt->mnt_parent)) &&
5595 +               !vx_flags(VXF_STATE_SETUP, 0))
5596                 goto out2;
5597         if (!check_mnt(root.mnt))
5598                 goto out2;
5599 @@ -2320,6 +2392,7 @@ void put_mnt_ns(struct mnt_namespace *ns
5600         spin_unlock(&vfsmount_lock);
5601         up_write(&namespace_sem);
5602         release_mounts(&umount_list);
5603 +       atomic_dec(&vs_global_mnt_ns);
5604         kfree(ns);
5605  }
5606  EXPORT_SYMBOL(put_mnt_ns);
5607 diff -NurpP --minimal linux-2.6.32.6/fs/nfs/client.c linux-2.6.32.6-vs2.3.0.36.28/fs/nfs/client.c
5608 --- linux-2.6.32.6/fs/nfs/client.c      2009-12-03 20:02:52.000000000 +0100
5609 +++ linux-2.6.32.6-vs2.3.0.36.28/fs/nfs/client.c        2009-12-03 20:04:56.000000000 +0100
5610 @@ -738,6 +738,9 @@ static int nfs_init_server_rpcclient(str
5611         if (server->flags & NFS_MOUNT_SOFT)
5612                 server->client->cl_softrtry = 1;
5613  
5614 +       server->client->cl_tag = 0;
5615 +       if (server->flags & NFS_MOUNT_TAGGED)
5616 +               server->client->cl_tag = 1;
5617         return 0;
5618  }
5619  
5620 @@ -909,6 +912,10 @@ static void nfs_server_set_fsinfo(struct
5621                 server->acdirmin = server->acdirmax = 0;
5622         }
5623  
5624 +       /* FIXME: needs fsinfo
5625 +       if (server->flags & NFS_MOUNT_TAGGED)
5626 +               sb->s_flags |= MS_TAGGED;       */
5627 +
5628         server->maxfilesize = fsinfo->maxfilesize;
5629  
5630         /* We're airborne Set socket buffersize */
5631 diff -NurpP --minimal linux-2.6.32.6/fs/nfs/dir.c linux-2.6.32.6-vs2.3.0.36.28/fs/nfs/dir.c
5632 --- linux-2.6.32.6/fs/nfs/dir.c 2009-12-03 20:02:52.000000000 +0100
5633 +++ linux-2.6.32.6-vs2.3.0.36.28/fs/nfs/dir.c   2009-12-03 20:04:56.000000000 +0100
5634 @@ -33,6 +33,7 @@
5635  #include <linux/namei.h>
5636  #include <linux/mount.h>
5637  #include <linux/sched.h>
5638 +#include <linux/vs_tag.h>
5639  
5640  #include "nfs4_fs.h"
5641  #include "delegation.h"
5642 @@ -949,6 +950,7 @@ static struct dentry *nfs_lookup(struct 
5643         if (IS_ERR(res))
5644                 goto out_unblock_sillyrename;
5645  
5646 +       dx_propagate_tag(nd, inode);
5647  no_entry:
5648         res = d_materialise_unique(dentry, inode);
5649         if (res != NULL) {
5650 diff -NurpP --minimal linux-2.6.32.6/fs/nfs/inode.c linux-2.6.32.6-vs2.3.0.36.28/fs/nfs/inode.c
5651 --- linux-2.6.32.6/fs/nfs/inode.c       2009-12-03 20:02:52.000000000 +0100
5652 +++ linux-2.6.32.6-vs2.3.0.36.28/fs/nfs/inode.c 2009-12-03 20:04:56.000000000 +0100
5653 @@ -36,6 +36,7 @@
5654  #include <linux/vfs.h>
5655  #include <linux/inet.h>
5656  #include <linux/nfs_xdr.h>
5657 +#include <linux/vs_tag.h>
5658  
5659  #include <asm/system.h>
5660  #include <asm/uaccess.h>
5661 @@ -279,6 +280,8 @@ nfs_fhget(struct super_block *sb, struct
5662         if (inode->i_state & I_NEW) {
5663                 struct nfs_inode *nfsi = NFS_I(inode);
5664                 unsigned long now = jiffies;
5665 +               uid_t uid;
5666 +               gid_t gid;
5667  
5668                 /* We set i_ino for the few things that still rely on it,
5669                  * such as stat(2) */
5670 @@ -327,8 +330,8 @@ nfs_fhget(struct super_block *sb, struct
5671                 nfsi->change_attr = 0;
5672                 inode->i_size = 0;
5673                 inode->i_nlink = 0;
5674 -               inode->i_uid = -2;
5675 -               inode->i_gid = -2;
5676 +               uid = -2;
5677 +               gid = -2;
5678                 inode->i_blocks = 0;
5679                 memset(nfsi->cookieverf, 0, sizeof(nfsi->cookieverf));
5680  
5681 @@ -365,13 +368,13 @@ nfs_fhget(struct super_block *sb, struct
5682                 else if (nfs_server_capable(inode, NFS_CAP_NLINK))
5683                         nfsi->cache_validity |= NFS_INO_INVALID_ATTR;
5684                 if (fattr->valid & NFS_ATTR_FATTR_OWNER)
5685 -                       inode->i_uid = fattr->uid;
5686 +                       uid = fattr->uid;
5687                 else if (nfs_server_capable(inode, NFS_CAP_OWNER))
5688                         nfsi->cache_validity |= NFS_INO_INVALID_ATTR
5689                                 | NFS_INO_INVALID_ACCESS
5690                                 | NFS_INO_INVALID_ACL;
5691                 if (fattr->valid & NFS_ATTR_FATTR_GROUP)
5692 -                       inode->i_gid = fattr->gid;
5693 +                       gid = fattr->gid;
5694                 else if (nfs_server_capable(inode, NFS_CAP_OWNER_GROUP))
5695                         nfsi->cache_validity |= NFS_INO_INVALID_ATTR
5696                                 | NFS_INO_INVALID_ACCESS
5697 @@ -384,6 +387,11 @@ nfs_fhget(struct super_block *sb, struct
5698                          */
5699                         inode->i_blocks = nfs_calc_block_size(fattr->du.nfs3.used);
5700                 }
5701 +               inode->i_uid = INOTAG_UID(DX_TAG(inode), uid, gid);
5702 +               inode->i_gid = INOTAG_GID(DX_TAG(inode), uid, gid);
5703 +               inode->i_tag = INOTAG_TAG(DX_TAG(inode), uid, gid, 0);
5704 +                               /* maybe fattr->xid someday */
5705 +
5706                 nfsi->attrtimeo = NFS_MINATTRTIMEO(inode);
5707                 nfsi->attrtimeo_timestamp = now;
5708                 nfsi->access_cache = RB_ROOT;
5709 @@ -496,6 +504,8 @@ void nfs_setattr_update_inode(struct ino
5710                         inode->i_uid = attr->ia_uid;
5711                 if ((attr->ia_valid & ATTR_GID) != 0)
5712                         inode->i_gid = attr->ia_gid;
5713 +               if ((attr->ia_valid & ATTR_TAG) && IS_TAGGED(inode))
5714 +                       inode->i_tag = attr->ia_tag;
5715                 NFS_I(inode)->cache_validity |= NFS_INO_INVALID_ACCESS|NFS_INO_INVALID_ACL;
5716                 spin_unlock(&inode->i_lock);
5717         }
5718 @@ -906,6 +916,9 @@ static int nfs_check_inode_attributes(st
5719         struct nfs_inode *nfsi = NFS_I(inode);
5720         loff_t cur_size, new_isize;
5721         unsigned long invalid = 0;
5722 +       uid_t uid;
5723 +       gid_t gid;
5724 +       tag_t tag;
5725  
5726  
5727         /* Has the inode gone and changed behind our back? */
5728 @@ -929,13 +942,18 @@ static int nfs_check_inode_attributes(st
5729                         invalid |= NFS_INO_INVALID_ATTR|NFS_INO_REVAL_PAGECACHE;
5730         }
5731  
5732 +       uid = INOTAG_UID(DX_TAG(inode), fattr->uid, fattr->gid);
5733 +       gid = INOTAG_GID(DX_TAG(inode), fattr->uid, fattr->gid);
5734 +       tag = INOTAG_TAG(DX_TAG(inode), fattr->uid, fattr->gid, 0);
5735 +
5736         /* Have any file permissions changed? */
5737         if ((fattr->valid & NFS_ATTR_FATTR_MODE) && (inode->i_mode & S_IALLUGO) != (fattr->mode & S_IALLUGO))
5738                 invalid |= NFS_INO_INVALID_ATTR | NFS_INO_INVALID_ACCESS | NFS_INO_INVALID_ACL;
5739 -       if ((fattr->valid & NFS_ATTR_FATTR_OWNER) && inode->i_uid != fattr->uid)
5740 +       if ((fattr->valid & NFS_ATTR_FATTR_OWNER) && uid != fattr->uid)
5741                 invalid |= NFS_INO_INVALID_ATTR | NFS_INO_INVALID_ACCESS | NFS_INO_INVALID_ACL;
5742 -       if ((fattr->valid & NFS_ATTR_FATTR_GROUP) && inode->i_gid != fattr->gid)
5743 +       if ((fattr->valid & NFS_ATTR_FATTR_GROUP) && gid != fattr->gid)
5744                 invalid |= NFS_INO_INVALID_ATTR | NFS_INO_INVALID_ACCESS | NFS_INO_INVALID_ACL;
5745 +               /* maybe check for tag too? */
5746  
5747         /* Has the link count changed? */
5748         if ((fattr->valid & NFS_ATTR_FATTR_NLINK) && inode->i_nlink != fattr->nlink)
5749 @@ -1150,6 +1168,9 @@ static int nfs_update_inode(struct inode
5750         unsigned long invalid = 0;
5751         unsigned long now = jiffies;
5752         unsigned long save_cache_validity;
5753 +       uid_t uid;
5754 +       gid_t gid;
5755 +       tag_t tag;
5756  
5757         dfprintk(VFS, "NFS: %s(%s/%ld ct=%d info=0x%x)\n",
5758                         __func__, inode->i_sb->s_id, inode->i_ino,
5759 @@ -1252,6 +1273,9 @@ static int nfs_update_inode(struct inode
5760                                 | NFS_INO_REVAL_PAGECACHE
5761                                 | NFS_INO_REVAL_FORCED);
5762  
5763 +       uid = INOTAG_UID(DX_TAG(inode), fattr->uid, fattr->gid);
5764 +       gid = INOTAG_GID(DX_TAG(inode), fattr->uid, fattr->gid);
5765 +       tag = INOTAG_TAG(DX_TAG(inode), fattr->uid, fattr->gid, 0);
5766  
5767         if (fattr->valid & NFS_ATTR_FATTR_ATIME)
5768                 memcpy(&inode->i_atime, &fattr->atime, sizeof(inode->i_atime));
5769 @@ -1271,9 +1295,9 @@ static int nfs_update_inode(struct inode
5770                                 | NFS_INO_REVAL_FORCED);
5771  
5772         if (fattr->valid & NFS_ATTR_FATTR_OWNER) {
5773 -               if (inode->i_uid != fattr->uid) {
5774 +               if (uid != fattr->uid) {
5775                         invalid |= NFS_INO_INVALID_ATTR|NFS_INO_INVALID_ACCESS|NFS_INO_INVALID_ACL;
5776 -                       inode->i_uid = fattr->uid;
5777 +                       uid = fattr->uid;
5778                 }
5779         } else if (server->caps & NFS_CAP_OWNER)
5780                 invalid |= save_cache_validity & (NFS_INO_INVALID_ATTR
5781 @@ -1282,9 +1306,9 @@ static int nfs_update_inode(struct inode
5782                                 | NFS_INO_REVAL_FORCED);
5783  
5784         if (fattr->valid & NFS_ATTR_FATTR_GROUP) {
5785 -               if (inode->i_gid != fattr->gid) {
5786 +               if (gid != fattr->gid) {
5787                         invalid |= NFS_INO_INVALID_ATTR|NFS_INO_INVALID_ACCESS|NFS_INO_INVALID_ACL;
5788 -                       inode->i_gid = fattr->gid;
5789 +                       gid = fattr->gid;
5790                 }
5791         } else if (server->caps & NFS_CAP_OWNER_GROUP)
5792                 invalid |= save_cache_validity & (NFS_INO_INVALID_ATTR
5793 @@ -1292,6 +1316,10 @@ static int nfs_update_inode(struct inode
5794                                 | NFS_INO_INVALID_ACL
5795                                 | NFS_INO_REVAL_FORCED);
5796  
5797 +       inode->i_uid = uid;
5798 +       inode->i_gid = gid;
5799 +       inode->i_tag = tag;
5800 +
5801         if (fattr->valid & NFS_ATTR_FATTR_NLINK) {
5802                 if (inode->i_nlink != fattr->nlink) {
5803                         invalid |= NFS_INO_INVALID_ATTR;
5804 diff -NurpP --minimal linux-2.6.32.6/fs/nfs/nfs3xdr.c linux-2.6.32.6-vs2.3.0.36.28/fs/nfs/nfs3xdr.c
5805 --- linux-2.6.32.6/fs/nfs/nfs3xdr.c     2009-12-03 20:02:52.000000000 +0100
5806 +++ linux-2.6.32.6-vs2.3.0.36.28/fs/nfs/nfs3xdr.c       2009-12-03 20:04:56.000000000 +0100
5807 @@ -21,6 +21,7 @@
5808  #include <linux/nfs3.h>
5809  #include <linux/nfs_fs.h>
5810  #include <linux/nfsacl.h>
5811 +#include <linux/vs_tag.h>
5812  #include "internal.h"
5813  
5814  #define NFSDBG_FACILITY                NFSDBG_XDR
5815 @@ -176,7 +177,7 @@ xdr_decode_fattr(__be32 *p, struct nfs_f
5816  }
5817  
5818  static inline __be32 *
5819 -xdr_encode_sattr(__be32 *p, struct iattr *attr)
5820 +xdr_encode_sattr(__be32 *p, struct iattr *attr, int tag)
5821  {
5822         if (attr->ia_valid & ATTR_MODE) {
5823                 *p++ = xdr_one;
5824 @@ -184,15 +185,17 @@ xdr_encode_sattr(__be32 *p, struct iattr
5825         } else {
5826                 *p++ = xdr_zero;
5827         }
5828 -       if (attr->ia_valid & ATTR_UID) {
5829 +       if (attr->ia_valid & ATTR_UID ||
5830 +               (tag && (attr->ia_valid & ATTR_TAG))) {
5831                 *p++ = xdr_one;
5832 -               *p++ = htonl(attr->ia_uid);
5833 +               *p++ = htonl(TAGINO_UID(tag, attr->ia_uid, attr->ia_tag));
5834         } else {
5835                 *p++ = xdr_zero;
5836         }
5837 -       if (attr->ia_valid & ATTR_GID) {
5838 +       if (attr->ia_valid & ATTR_GID ||
5839 +               (tag && (attr->ia_valid & ATTR_TAG))) {
5840                 *p++ = xdr_one;
5841 -               *p++ = htonl(attr->ia_gid);
5842 +               *p++ = htonl(TAGINO_GID(tag, attr->ia_gid, attr->ia_tag));
5843         } else {
5844                 *p++ = xdr_zero;
5845         }
5846 @@ -279,7 +282,8 @@ static int
5847  nfs3_xdr_sattrargs(struct rpc_rqst *req, __be32 *p, struct nfs3_sattrargs *args)
5848  {
5849         p = xdr_encode_fhandle(p, args->fh);
5850 -       p = xdr_encode_sattr(p, args->sattr);
5851 +       p = xdr_encode_sattr(p, args->sattr,
5852 +               req->rq_task->tk_client->cl_tag);
5853         *p++ = htonl(args->guard);
5854         if (args->guard)
5855                 p = xdr_encode_time3(p, &args->guardtime);
5856 @@ -384,7 +388,8 @@ nfs3_xdr_createargs(struct rpc_rqst *req
5857                 *p++ = args->verifier[0];
5858                 *p++ = args->verifier[1];
5859         } else
5860 -               p = xdr_encode_sattr(p, args->sattr);
5861 +               p = xdr_encode_sattr(p, args->sattr,
5862 +                       req->rq_task->tk_client->cl_tag);
5863  
5864         req->rq_slen = xdr_adjust_iovec(req->rq_svec, p);
5865         return 0;
5866 @@ -398,7 +403,8 @@ nfs3_xdr_mkdirargs(struct rpc_rqst *req,
5867  {
5868         p = xdr_encode_fhandle(p, args->fh);
5869         p = xdr_encode_array(p, args->name, args->len);
5870 -       p = xdr_encode_sattr(p, args->sattr);
5871 +       p = xdr_encode_sattr(p, args->sattr,
5872 +               req->rq_task->tk_client->cl_tag);
5873         req->rq_slen = xdr_adjust_iovec(req->rq_svec, p);
5874         return 0;
5875  }
5876 @@ -411,7 +417,8 @@ nfs3_xdr_symlinkargs(struct rpc_rqst *re
5877  {
5878         p = xdr_encode_fhandle(p, args->fromfh);
5879         p = xdr_encode_array(p, args->fromname, args->fromlen);
5880 -       p = xdr_encode_sattr(p, args->sattr);
5881 +       p = xdr_encode_sattr(p, args->sattr,
5882 +               req->rq_task->tk_client->cl_tag);
5883         *p++ = htonl(args->pathlen);
5884         req->rq_slen = xdr_adjust_iovec(req->rq_svec, p);
5885  
5886 @@ -429,7 +436,8 @@ nfs3_xdr_mknodargs(struct rpc_rqst *req,
5887         p = xdr_encode_fhandle(p, args->fh);
5888         p = xdr_encode_array(p, args->name, args->len);
5889         *p++ = htonl(args->type);
5890 -       p = xdr_encode_sattr(p, args->sattr);
5891 +       p = xdr_encode_sattr(p, args->sattr,
5892 +               req->rq_task->tk_client->cl_tag);
5893         if (args->type == NF3CHR || args->type == NF3BLK) {
5894                 *p++ = htonl(MAJOR(args->rdev));
5895                 *p++ = htonl(MINOR(args->rdev));
5896 diff -NurpP --minimal linux-2.6.32.6/fs/nfs/nfsroot.c linux-2.6.32.6-vs2.3.0.36.28/fs/nfs/nfsroot.c
5897 --- linux-2.6.32.6/fs/nfs/nfsroot.c     2009-09-10 15:26:23.000000000 +0200
5898 +++ linux-2.6.32.6-vs2.3.0.36.28/fs/nfs/nfsroot.c       2009-12-03 20:04:56.000000000 +0100
5899 @@ -122,12 +122,12 @@ static int mount_port __initdata = 0;             /
5900  enum {
5901         /* Options that take integer arguments */
5902         Opt_port, Opt_rsize, Opt_wsize, Opt_timeo, Opt_retrans, Opt_acregmin,
5903 -       Opt_acregmax, Opt_acdirmin, Opt_acdirmax,
5904 +       Opt_acregmax, Opt_acdirmin, Opt_acdirmax, Opt_tagid,
5905         /* Options that take no arguments */
5906         Opt_soft, Opt_hard, Opt_intr,
5907         Opt_nointr, Opt_posix, Opt_noposix, Opt_cto, Opt_nocto, Opt_ac, 
5908         Opt_noac, Opt_lock, Opt_nolock, Opt_v2, Opt_v3, Opt_udp, Opt_tcp,
5909 -       Opt_acl, Opt_noacl,
5910 +       Opt_acl, Opt_noacl, Opt_tag, Opt_notag,
5911         /* Error token */
5912         Opt_err
5913  };
5914 @@ -164,6 +164,9 @@ static const match_table_t tokens __init
5915         {Opt_tcp, "tcp"},
5916         {Opt_acl, "acl"},
5917         {Opt_noacl, "noacl"},
5918 +       {Opt_tag, "tag"},
5919 +       {Opt_notag, "notag"},
5920 +       {Opt_tagid, "tagid=%u"},
5921         {Opt_err, NULL}
5922         
5923  };
5924 @@ -275,6 +278,20 @@ static int __init root_nfs_parse(char *n
5925                         case Opt_noacl:
5926                                 nfs_data.flags |= NFS_MOUNT_NOACL;
5927                                 break;
5928 +#ifndef CONFIG_TAGGING_NONE
5929 +                       case Opt_tag:
5930 +                               nfs_data.flags |= NFS_MOUNT_TAGGED;
5931 +                               break;
5932 +                       case Opt_notag:
5933 +                               nfs_data.flags &= ~NFS_MOUNT_TAGGED;
5934 +                               break;
5935 +#endif
5936 +#ifdef CONFIG_PROPAGATE
5937 +                       case Opt_tagid:
5938 +                               /* use args[0] */
5939 +                               nfs_data.flags |= NFS_MOUNT_TAGGED;
5940 +                               break;
5941 +#endif
5942                         default:
5943                                 printk(KERN_WARNING "Root-NFS: unknown "
5944                                         "option: %s\n", p);
5945 diff -NurpP --minimal linux-2.6.32.6/fs/nfs/super.c linux-2.6.32.6-vs2.3.0.36.28/fs/nfs/super.c
5946 --- linux-2.6.32.6/fs/nfs/super.c       2009-12-03 20:02:52.000000000 +0100
5947 +++ linux-2.6.32.6-vs2.3.0.36.28/fs/nfs/super.c 2009-12-03 20:04:56.000000000 +0100
5948 @@ -53,6 +53,7 @@
5949  #include <linux/nfs_xdr.h>
5950  #include <linux/magic.h>
5951  #include <linux/parser.h>
5952 +#include <linux/vs_tag.h>
5953  
5954  #include <asm/system.h>
5955  #include <asm/uaccess.h>
5956 @@ -551,6 +552,7 @@ static void nfs_show_mount_options(struc
5957                 { NFS_MOUNT_NORDIRPLUS, ",nordirplus", "" },
5958                 { NFS_MOUNT_UNSHARED, ",nosharecache", "" },
5959                 { NFS_MOUNT_NORESVPORT, ",noresvport", "" },
5960 +               { NFS_MOUNT_TAGGED, ",tag", "" },
5961                 { 0, NULL, NULL }
5962         };
5963         const struct proc_nfs_info *nfs_infop;
5964 diff -NurpP --minimal linux-2.6.32.6/fs/nfsd/auth.c linux-2.6.32.6-vs2.3.0.36.28/fs/nfsd/auth.c
5965 --- linux-2.6.32.6/fs/nfsd/auth.c       2009-12-03 20:02:52.000000000 +0100
5966 +++ linux-2.6.32.6-vs2.3.0.36.28/fs/nfsd/auth.c 2009-12-03 20:04:56.000000000 +0100
5967 @@ -10,6 +10,7 @@
5968  #include <linux/sunrpc/svcauth.h>
5969  #include <linux/nfsd/nfsd.h>
5970  #include <linux/nfsd/export.h>
5971 +#include <linux/vs_tag.h>
5972  #include "auth.h"
5973  
5974  int nfsexp_flags(struct svc_rqst *rqstp, struct svc_export *exp)
5975 @@ -44,6 +45,9 @@ int nfsd_setuser(struct svc_rqst *rqstp,
5976  
5977         new->fsuid = rqstp->rq_cred.cr_uid;
5978         new->fsgid = rqstp->rq_cred.cr_gid;
5979 +       /* FIXME: this desperately needs a tag :)
5980 +       new->xid = (xid_t)INOTAG_TAG(DX_TAG_NFSD, cred.cr_uid, cred.cr_gid, 0);
5981 +                       */
5982  
5983         rqgi = rqstp->rq_cred.cr_group_info;
5984  
5985 diff -NurpP --minimal linux-2.6.32.6/fs/nfsd/nfs3xdr.c linux-2.6.32.6-vs2.3.0.36.28/fs/nfsd/nfs3xdr.c
5986 --- linux-2.6.32.6/fs/nfsd/nfs3xdr.c    2009-12-03 20:02:52.000000000 +0100
5987 +++ linux-2.6.32.6-vs2.3.0.36.28/fs/nfsd/nfs3xdr.c      2009-12-03 20:04:56.000000000 +0100
5988 @@ -21,6 +21,7 @@
5989  #include <linux/sunrpc/svc.h>
5990  #include <linux/nfsd/nfsd.h>
5991  #include <linux/nfsd/xdr3.h>
5992 +#include <linux/vs_tag.h>
5993  #include "auth.h"
5994  
5995  #define NFSDDBG_FACILITY               NFSDDBG_XDR
5996 @@ -108,6 +109,8 @@ static __be32 *
5997  decode_sattr3(__be32 *p, struct iattr *iap)
5998  {
5999         u32     tmp;
6000 +       uid_t   uid = 0;
6001 +       gid_t   gid = 0;
6002  
6003         iap->ia_valid = 0;
6004  
6005 @@ -117,12 +120,15 @@ decode_sattr3(__be32 *p, struct iattr *i
6006         }
6007         if (*p++) {
6008                 iap->ia_valid |= ATTR_UID;
6009 -               iap->ia_uid = ntohl(*p++);
6010 +               uid = ntohl(*p++);
6011         }
6012         if (*p++) {
6013                 iap->ia_valid |= ATTR_GID;
6014 -               iap->ia_gid = ntohl(*p++);
6015 +               gid = ntohl(*p++);
6016         }
6017 +       iap->ia_uid = INOTAG_UID(DX_TAG_NFSD, uid, gid);
6018 +       iap->ia_gid = INOTAG_GID(DX_TAG_NFSD, uid, gid);
6019 +       iap->ia_tag = INOTAG_TAG(DX_TAG_NFSD, uid, gid, 0);
6020         if (*p++) {
6021                 u64     newsize;
6022  
6023 @@ -178,8 +184,12 @@ encode_fattr3(struct svc_rqst *rqstp, __
6024         *p++ = htonl(nfs3_ftypes[(stat->mode & S_IFMT) >> 12]);
6025         *p++ = htonl((u32) stat->mode);
6026         *p++ = htonl((u32) stat->nlink);
6027 -       *p++ = htonl((u32) nfsd_ruid(rqstp, stat->uid));
6028 -       *p++ = htonl((u32) nfsd_rgid(rqstp, stat->gid));
6029 +       *p++ = htonl((u32) nfsd_ruid(rqstp,
6030 +               TAGINO_UID(0 /* FIXME: DX_TAG(dentry->d_inode) */,
6031 +               stat->uid, stat->tag)));
6032 +       *p++ = htonl((u32) nfsd_rgid(rqstp,
6033 +               TAGINO_GID(0 /* FIXME: DX_TAG(dentry->d_inode) */,
6034 +               stat->gid, stat->tag)));
6035         if (S_ISLNK(stat->mode) && stat->size > NFS3_MAXPATHLEN) {
6036                 p = xdr_encode_hyper(p, (u64) NFS3_MAXPATHLEN);
6037         } else {
6038 diff -NurpP --minimal linux-2.6.32.6/fs/nfsd/nfs4xdr.c linux-2.6.32.6-vs2.3.0.36.28/fs/nfsd/nfs4xdr.c
6039 --- linux-2.6.32.6/fs/nfsd/nfs4xdr.c    2009-12-03 20:02:52.000000000 +0100
6040 +++ linux-2.6.32.6-vs2.3.0.36.28/fs/nfsd/nfs4xdr.c      2009-12-03 20:04:56.000000000 +0100
6041 @@ -57,6 +57,7 @@
6042  #include <linux/nfs4_acl.h>
6043  #include <linux/sunrpc/gss_api.h>
6044  #include <linux/sunrpc/svcauth_gss.h>
6045 +#include <linux/vs_tag.h>
6046  
6047  #define NFSDDBG_FACILITY               NFSDDBG_XDR
6048  
6049 @@ -2050,14 +2051,18 @@ out_acl:
6050                 WRITE32(stat.nlink);
6051         }
6052         if (bmval1 & FATTR4_WORD1_OWNER) {
6053 -               status = nfsd4_encode_user(rqstp, stat.uid, &p, &buflen);
6054 +               status = nfsd4_encode_user(rqstp,
6055 +                       TAGINO_UID(DX_TAG(dentry->d_inode),
6056 +                       stat.uid, stat.tag), &p, &buflen);
6057                 if (status == nfserr_resource)
6058                         goto out_resource;
6059                 if (status)
6060                         goto out;
6061         }
6062         if (bmval1 & FATTR4_WORD1_OWNER_GROUP) {
6063 -               status = nfsd4_encode_group(rqstp, stat.gid, &p, &buflen);
6064 +               status = nfsd4_encode_group(rqstp,
6065 +                       TAGINO_GID(DX_TAG(dentry->d_inode),
6066 +                       stat.gid, stat.tag), &p, &buflen);
6067                 if (status == nfserr_resource)
6068                         goto out_resource;
6069                 if (status)
6070 diff -NurpP --minimal linux-2.6.32.6/fs/nfsd/nfsxdr.c linux-2.6.32.6-vs2.3.0.36.28/fs/nfsd/nfsxdr.c
6071 --- linux-2.6.32.6/fs/nfsd/nfsxdr.c     2008-12-25 00:26:37.000000000 +0100
6072 +++ linux-2.6.32.6-vs2.3.0.36.28/fs/nfsd/nfsxdr.c       2009-12-03 20:04:56.000000000 +0100
6073 @@ -15,6 +15,7 @@
6074  #include <linux/nfsd/nfsd.h>
6075  #include <linux/nfsd/xdr.h>
6076  #include <linux/mm.h>
6077 +#include <linux/vs_tag.h>
6078  #include "auth.h"
6079  
6080  #define NFSDDBG_FACILITY               NFSDDBG_XDR
6081 @@ -98,6 +99,8 @@ static __be32 *
6082  decode_sattr(__be32 *p, struct iattr *iap)
6083  {
6084         u32     tmp, tmp1;
6085 +       uid_t   uid = 0;
6086 +       gid_t   gid = 0;
6087  
6088         iap->ia_valid = 0;
6089  
6090 @@ -111,12 +114,15 @@ decode_sattr(__be32 *p, struct iattr *ia
6091         }
6092         if ((tmp = ntohl(*p++)) != (u32)-1) {
6093                 iap->ia_valid |= ATTR_UID;
6094 -               iap->ia_uid = tmp;
6095 +               uid = tmp;
6096         }
6097         if ((tmp = ntohl(*p++)) != (u32)-1) {
6098                 iap->ia_valid |= ATTR_GID;
6099 -               iap->ia_gid = tmp;
6100 +               gid = tmp;
6101         }
6102 +       iap->ia_uid = INOTAG_UID(DX_TAG_NFSD, uid, gid);
6103 +       iap->ia_gid = INOTAG_GID(DX_TAG_NFSD, uid, gid);
6104 +       iap->ia_tag = INOTAG_TAG(DX_TAG_NFSD, uid, gid, 0);
6105         if ((tmp = ntohl(*p++)) != (u32)-1) {
6106                 iap->ia_valid |= ATTR_SIZE;
6107                 iap->ia_size = tmp;
6108 @@ -161,8 +167,10 @@ encode_fattr(struct svc_rqst *rqstp, __b
6109         *p++ = htonl(nfs_ftypes[type >> 12]);
6110         *p++ = htonl((u32) stat->mode);
6111         *p++ = htonl((u32) stat->nlink);
6112 -       *p++ = htonl((u32) nfsd_ruid(rqstp, stat->uid));
6113 -       *p++ = htonl((u32) nfsd_rgid(rqstp, stat->gid));
6114 +       *p++ = htonl((u32) nfsd_ruid(rqstp,
6115 +               TAGINO_UID(DX_TAG(dentry->d_inode), stat->uid, stat->tag)));
6116 +       *p++ = htonl((u32) nfsd_rgid(rqstp,
6117 +               TAGINO_GID(DX_TAG(dentry->d_inode), stat->gid, stat->tag)));
6118  
6119         if (S_ISLNK(type) && stat->size > NFS_MAXPATHLEN) {
6120                 *p++ = htonl(NFS_MAXPATHLEN);
6121 diff -NurpP --minimal linux-2.6.32.6/fs/ocfs2/dlm/dlmfs.c linux-2.6.32.6-vs2.3.0.36.28/fs/ocfs2/dlm/dlmfs.c
6122 --- linux-2.6.32.6/fs/ocfs2/dlm/dlmfs.c 2009-12-03 20:02:53.000000000 +0100
6123 +++ linux-2.6.32.6-vs2.3.0.36.28/fs/ocfs2/dlm/dlmfs.c   2009-12-03 20:04:56.000000000 +0100
6124 @@ -43,6 +43,7 @@
6125  #include <linux/init.h>
6126  #include <linux/string.h>
6127  #include <linux/backing-dev.h>
6128 +#include <linux/vs_tag.h>
6129  
6130  #include <asm/uaccess.h>
6131  
6132 @@ -342,6 +343,7 @@ static struct inode *dlmfs_get_root_inod
6133                 inode->i_mode = mode;
6134                 inode->i_uid = current_fsuid();
6135                 inode->i_gid = current_fsgid();
6136 +               inode->i_tag = dx_current_fstag(sb);
6137                 inode->i_mapping->backing_dev_info = &dlmfs_backing_dev_info;
6138                 inode->i_atime = inode->i_mtime = inode->i_ctime = CURRENT_TIME;
6139                 inc_nlink(inode);
6140 @@ -367,6 +369,7 @@ static struct inode *dlmfs_get_inode(str
6141         inode->i_mode = mode;
6142         inode->i_uid = current_fsuid();
6143         inode->i_gid = current_fsgid();
6144 +       inode->i_tag = dx_current_fstag(sb);
6145         inode->i_mapping->backing_dev_info = &dlmfs_backing_dev_info;
6146         inode->i_atime = inode->i_mtime = inode->i_ctime = CURRENT_TIME;
6147  
6148 diff -NurpP --minimal linux-2.6.32.6/fs/ocfs2/dlmglue.c linux-2.6.32.6-vs2.3.0.36.28/fs/ocfs2/dlmglue.c
6149 --- linux-2.6.32.6/fs/ocfs2/dlmglue.c   2009-12-03 20:02:53.000000000 +0100
6150 +++ linux-2.6.32.6-vs2.3.0.36.28/fs/ocfs2/dlmglue.c     2009-12-03 20:04:56.000000000 +0100
6151 @@ -1991,6 +1991,7 @@ static void __ocfs2_stuff_meta_lvb(struc
6152         lvb->lvb_iclusters = cpu_to_be32(oi->ip_clusters);
6153         lvb->lvb_iuid      = cpu_to_be32(inode->i_uid);
6154         lvb->lvb_igid      = cpu_to_be32(inode->i_gid);
6155 +       lvb->lvb_itag      = cpu_to_be16(inode->i_tag);
6156         lvb->lvb_imode     = cpu_to_be16(inode->i_mode);
6157         lvb->lvb_inlink    = cpu_to_be16(inode->i_nlink);
6158         lvb->lvb_iatime_packed  =
6159 @@ -2045,6 +2046,7 @@ static void ocfs2_refresh_inode_from_lvb
6160  
6161         inode->i_uid     = be32_to_cpu(lvb->lvb_iuid);
6162         inode->i_gid     = be32_to_cpu(lvb->lvb_igid);
6163 +       inode->i_tag     = be16_to_cpu(lvb->lvb_itag);
6164         inode->i_mode    = be16_to_cpu(lvb->lvb_imode);
6165         inode->i_nlink   = be16_to_cpu(lvb->lvb_inlink);
6166         ocfs2_unpack_timespec(&inode->i_atime,
6167 diff -NurpP --minimal linux-2.6.32.6/fs/ocfs2/dlmglue.h linux-2.6.32.6-vs2.3.0.36.28/fs/ocfs2/dlmglue.h
6168 --- linux-2.6.32.6/fs/ocfs2/dlmglue.h   2009-12-03 20:02:53.000000000 +0100
6169 +++ linux-2.6.32.6-vs2.3.0.36.28/fs/ocfs2/dlmglue.h     2009-12-03 20:04:56.000000000 +0100
6170 @@ -46,7 +46,8 @@ struct ocfs2_meta_lvb {
6171         __be16       lvb_inlink;
6172         __be32       lvb_iattr;
6173         __be32       lvb_igeneration;
6174 -       __be32       lvb_reserved2;
6175 +       __be16       lvb_itag;
6176 +       __be16       lvb_reserved2;
6177  };
6178  
6179  #define OCFS2_QINFO_LVB_VERSION 1
6180 diff -NurpP --minimal linux-2.6.32.6/fs/ocfs2/file.c linux-2.6.32.6-vs2.3.0.36.28/fs/ocfs2/file.c
6181 --- linux-2.6.32.6/fs/ocfs2/file.c      2009-12-03 20:02:53.000000000 +0100
6182 +++ linux-2.6.32.6-vs2.3.0.36.28/fs/ocfs2/file.c        2009-12-03 20:04:56.000000000 +0100
6183 @@ -960,13 +960,15 @@ int ocfs2_setattr(struct dentry *dentry,
6184                 mlog(0, "uid change: %d\n", attr->ia_uid);
6185         if (attr->ia_valid & ATTR_GID)
6186                 mlog(0, "gid change: %d\n", attr->ia_gid);
6187 +       if (attr->ia_valid & ATTR_TAG)
6188 +               mlog(0, "tag change: %d\n", attr->ia_tag);
6189         if (attr->ia_valid & ATTR_SIZE)
6190                 mlog(0, "size change...\n");
6191         if (attr->ia_valid & (ATTR_ATIME | ATTR_MTIME | ATTR_CTIME))
6192                 mlog(0, "time change...\n");
6193  
6194  #define OCFS2_VALID_ATTRS (ATTR_ATIME | ATTR_MTIME | ATTR_CTIME | ATTR_SIZE \
6195 -                          | ATTR_GID | ATTR_UID | ATTR_MODE)
6196 +                          | ATTR_GID | ATTR_UID | ATTR_TAG | ATTR_MODE)
6197         if (!(attr->ia_valid & OCFS2_VALID_ATTRS)) {
6198                 mlog(0, "can't handle attrs: 0x%x\n", attr->ia_valid);
6199                 return 0;
6200 diff -NurpP --minimal linux-2.6.32.6/fs/ocfs2/inode.c linux-2.6.32.6-vs2.3.0.36.28/fs/ocfs2/inode.c
6201 --- linux-2.6.32.6/fs/ocfs2/inode.c     2009-12-03 20:02:53.000000000 +0100
6202 +++ linux-2.6.32.6-vs2.3.0.36.28/fs/ocfs2/inode.c       2009-12-03 20:04:56.000000000 +0100
6203 @@ -29,6 +29,7 @@
6204  #include <linux/highmem.h>
6205  #include <linux/pagemap.h>
6206  #include <linux/quotaops.h>
6207 +#include <linux/vs_tag.h>
6208  
6209  #include <asm/byteorder.h>
6210  
6211 @@ -79,11 +80,13 @@ void ocfs2_set_inode_flags(struct inode 
6212  {
6213         unsigned int flags = OCFS2_I(inode)->ip_attr;
6214  
6215 -       inode->i_flags &= ~(S_IMMUTABLE |
6216 +       inode->i_flags &= ~(S_IMMUTABLE | S_IXUNLINK |
6217                 S_SYNC | S_APPEND | S_NOATIME | S_DIRSYNC);
6218  
6219         if (flags & OCFS2_IMMUTABLE_FL)
6220                 inode->i_flags |= S_IMMUTABLE;
6221 +       if (flags & OCFS2_IXUNLINK_FL)
6222 +               inode->i_flags |= S_IXUNLINK;
6223  
6224         if (flags & OCFS2_SYNC_FL)
6225                 inode->i_flags |= S_SYNC;
6226 @@ -93,25 +96,44 @@ void ocfs2_set_inode_flags(struct inode 
6227                 inode->i_flags |= S_NOATIME;
6228         if (flags & OCFS2_DIRSYNC_FL)
6229                 inode->i_flags |= S_DIRSYNC;
6230 +
6231 +       inode->i_vflags &= ~(V_BARRIER | V_COW);
6232 +
6233 +       if (flags & OCFS2_BARRIER_FL)
6234 +               inode->i_vflags |= V_BARRIER;
6235 +       if (flags & OCFS2_COW_FL)
6236 +               inode->i_vflags |= V_COW;
6237  }
6238  
6239  /* Propagate flags from i_flags to OCFS2_I(inode)->ip_attr */
6240  void ocfs2_get_inode_flags(struct ocfs2_inode_info *oi)
6241  {
6242         unsigned int flags = oi->vfs_inode.i_flags;
6243 +       unsigned int vflags = oi->vfs_inode.i_vflags;
6244 +
6245 +       oi->ip_attr &= ~(OCFS2_SYNC_FL | OCFS2_APPEND_FL |
6246 +                       OCFS2_IMMUTABLE_FL | OCFS2_IXUNLINK_FL |
6247 +                       OCFS2_NOATIME_FL | OCFS2_DIRSYNC_FL |
6248 +                       OCFS2_BARRIER_FL | OCFS2_COW_FL);
6249 +
6250 +       if (flags & S_IMMUTABLE)
6251 +               oi->ip_attr |= OCFS2_IMMUTABLE_FL;
6252 +       if (flags & S_IXUNLINK)
6253 +               oi->ip_attr |= OCFS2_IXUNLINK_FL;
6254  
6255 -       oi->ip_attr &= ~(OCFS2_SYNC_FL|OCFS2_APPEND_FL|
6256 -                       OCFS2_IMMUTABLE_FL|OCFS2_NOATIME_FL|OCFS2_DIRSYNC_FL);
6257         if (flags & S_SYNC)
6258                 oi->ip_attr |= OCFS2_SYNC_FL;
6259         if (flags & S_APPEND)
6260                 oi->ip_attr |= OCFS2_APPEND_FL;
6261 -       if (flags & S_IMMUTABLE)
6262 -               oi->ip_attr |= OCFS2_IMMUTABLE_FL;
6263         if (flags & S_NOATIME)
6264                 oi->ip_attr |= OCFS2_NOATIME_FL;
6265         if (flags & S_DIRSYNC)
6266                 oi->ip_attr |= OCFS2_DIRSYNC_FL;
6267 +
6268 +       if (vflags & V_BARRIER)
6269 +               oi->ip_attr |= OCFS2_BARRIER_FL;
6270 +       if (vflags & V_COW)
6271 +               oi->ip_attr |= OCFS2_COW_FL;
6272  }
6273  
6274  struct inode *ocfs2_ilookup(struct super_block *sb, u64 blkno)
6275 @@ -246,6 +268,8 @@ void ocfs2_populate_inode(struct inode *
6276         struct super_block *sb;
6277         struct ocfs2_super *osb;
6278         int use_plocks = 1;
6279 +       uid_t uid;
6280 +       gid_t gid;
6281  
6282         mlog_entry("(0x%p, size:%llu)\n", inode,
6283                    (unsigned long long)le64_to_cpu(fe->i_size));
6284 @@ -277,8 +301,12 @@ void ocfs2_populate_inode(struct inode *
6285         inode->i_generation = le32_to_cpu(fe->i_generation);
6286         inode->i_rdev = huge_decode_dev(le64_to_cpu(fe->id1.dev1.i_rdev));
6287         inode->i_mode = le16_to_cpu(fe->i_mode);
6288 -       inode->i_uid = le32_to_cpu(fe->i_uid);
6289 -       inode->i_gid = le32_to_cpu(fe->i_gid);
6290 +       uid = le32_to_cpu(fe->i_uid);
6291 +       gid = le32_to_cpu(fe->i_gid);
6292 +       inode->i_uid = INOTAG_UID(DX_TAG(inode), uid, gid);
6293 +       inode->i_gid = INOTAG_GID(DX_TAG(inode), uid, gid);
6294 +       inode->i_tag = INOTAG_TAG(DX_TAG(inode), uid, gid,
6295 +               /* le16_to_cpu(raw_inode->i_raw_tag)i */ 0);
6296  
6297         /* Fast symlinks will have i_size but no allocated clusters. */
6298         if (S_ISLNK(inode->i_mode) && !fe->i_clusters)
6299 diff -NurpP --minimal linux-2.6.32.6/fs/ocfs2/inode.h linux-2.6.32.6-vs2.3.0.36.28/fs/ocfs2/inode.h
6300 --- linux-2.6.32.6/fs/ocfs2/inode.h     2009-12-03 20:02:53.000000000 +0100
6301 +++ linux-2.6.32.6-vs2.3.0.36.28/fs/ocfs2/inode.h       2009-12-03 20:04:56.000000000 +0100
6302 @@ -150,6 +150,7 @@ struct buffer_head *ocfs2_bread(struct i
6303  
6304  void ocfs2_set_inode_flags(struct inode *inode);
6305  void ocfs2_get_inode_flags(struct ocfs2_inode_info *oi);
6306 +int ocfs2_sync_flags(struct inode *inode, int, int);
6307  
6308  static inline blkcnt_t ocfs2_inode_sector_count(struct inode *inode)
6309  {
6310 diff -NurpP --minimal linux-2.6.32.6/fs/ocfs2/ioctl.c linux-2.6.32.6-vs2.3.0.36.28/fs/ocfs2/ioctl.c
6311 --- linux-2.6.32.6/fs/ocfs2/ioctl.c     2009-12-03 20:02:53.000000000 +0100
6312 +++ linux-2.6.32.6-vs2.3.0.36.28/fs/ocfs2/ioctl.c       2009-12-03 20:04:56.000000000 +0100
6313 @@ -42,7 +42,41 @@ static int ocfs2_get_inode_attr(struct i
6314         return status;
6315  }
6316  
6317 -static int ocfs2_set_inode_attr(struct inode *inode, unsigned flags,
6318 +int ocfs2_sync_flags(struct inode *inode, int flags, int vflags)
6319 +{
6320 +       struct ocfs2_super *osb = OCFS2_SB(inode->i_sb);
6321 +       struct buffer_head *bh = NULL;
6322 +       handle_t *handle = NULL;
6323 +       int status;
6324 +
6325 +       status = ocfs2_inode_lock(inode, &bh, 1);
6326 +       if (status < 0) {
6327 +               mlog_errno(status);
6328 +               return status;
6329 +       }
6330 +       handle = ocfs2_start_trans(osb, OCFS2_INODE_UPDATE_CREDITS);
6331 +       if (IS_ERR(handle)) {
6332 +               status = PTR_ERR(handle);
6333 +               mlog_errno(status);
6334 +               goto bail_unlock;
6335 +       }
6336 +
6337 +       inode->i_flags = flags;
6338 +       inode->i_vflags = vflags;
6339 +       ocfs2_get_inode_flags(OCFS2_I(inode));
6340 +
6341 +       status = ocfs2_mark_inode_dirty(handle, inode, bh);
6342 +       if (status < 0)
6343 +               mlog_errno(status);
6344 +
6345 +       ocfs2_commit_trans(osb, handle);
6346 +bail_unlock:
6347 +       ocfs2_inode_unlock(inode, 1);
6348 +       brelse(bh);
6349 +       return status;
6350 +}
6351 +
6352 +int ocfs2_set_inode_attr(struct inode *inode, unsigned flags,
6353                                 unsigned mask)
6354  {
6355         struct ocfs2_inode_info *ocfs2_inode = OCFS2_I(inode);
6356 @@ -67,6 +101,11 @@ static int ocfs2_set_inode_attr(struct i
6357         if (!S_ISDIR(inode->i_mode))
6358                 flags &= ~OCFS2_DIRSYNC_FL;
6359  
6360 +       if (IS_BARRIER(inode)) {
6361 +               vxwprintk_task(1, "messing with the barrier.");
6362 +               goto bail_unlock;
6363 +       }
6364 +
6365         handle = ocfs2_start_trans(osb, OCFS2_INODE_UPDATE_CREDITS);
6366         if (IS_ERR(handle)) {
6367                 status = PTR_ERR(handle);
6368 @@ -108,6 +147,7 @@ bail:
6369         return status;
6370  }
6371  
6372 +
6373  long ocfs2_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
6374  {
6375         struct inode *inode = filp->f_path.dentry->d_inode;
6376 diff -NurpP --minimal linux-2.6.32.6/fs/ocfs2/namei.c linux-2.6.32.6-vs2.3.0.36.28/fs/ocfs2/namei.c
6377 --- linux-2.6.32.6/fs/ocfs2/namei.c     2009-12-03 20:02:53.000000000 +0100
6378 +++ linux-2.6.32.6-vs2.3.0.36.28/fs/ocfs2/namei.c       2009-12-03 20:04:56.000000000 +0100
6379 @@ -41,6 +41,7 @@
6380  #include <linux/slab.h>
6381  #include <linux/highmem.h>
6382  #include <linux/quotaops.h>
6383 +#include <linux/vs_tag.h>
6384  
6385  #define MLOG_MASK_PREFIX ML_NAMEI
6386  #include <cluster/masklog.h>
6387 @@ -481,6 +482,7 @@ static int ocfs2_mknod_locked(struct ocf
6388         u64 fe_blkno = 0;
6389         u16 suballoc_bit;
6390         u16 feat;
6391 +       tag_t tag;
6392  
6393         *new_fe_bh = NULL;
6394  
6395 @@ -524,8 +526,11 @@ static int ocfs2_mknod_locked(struct ocf
6396         fe->i_blkno = cpu_to_le64(fe_blkno);
6397         fe->i_suballoc_bit = cpu_to_le16(suballoc_bit);
6398         fe->i_suballoc_slot = cpu_to_le16(inode_ac->ac_alloc_slot);
6399 -       fe->i_uid = cpu_to_le32(inode->i_uid);
6400 -       fe->i_gid = cpu_to_le32(inode->i_gid);
6401 +
6402 +       tag = dx_current_fstag(osb->sb);
6403 +       fe->i_uid = cpu_to_le32(TAGINO_UID(DX_TAG(inode), inode->i_uid, tag));
6404 +       fe->i_gid = cpu_to_le32(TAGINO_GID(DX_TAG(inode), inode->i_gid, tag));
6405 +       inode->i_tag = tag;
6406         fe->i_mode = cpu_to_le16(inode->i_mode);
6407         if (S_ISCHR(inode->i_mode) || S_ISBLK(inode->i_mode))
6408                 fe->id1.dev1.i_rdev = cpu_to_le64(huge_encode_dev(dev));
6409 diff -NurpP --minimal linux-2.6.32.6/fs/ocfs2/ocfs2_fs.h linux-2.6.32.6-vs2.3.0.36.28/fs/ocfs2/ocfs2_fs.h
6410 --- linux-2.6.32.6/fs/ocfs2/ocfs2_fs.h  2009-12-03 20:02:53.000000000 +0100
6411 +++ linux-2.6.32.6-vs2.3.0.36.28/fs/ocfs2/ocfs2_fs.h    2009-12-03 20:04:56.000000000 +0100
6412 @@ -231,18 +231,23 @@
6413  #define OCFS2_HAS_REFCOUNT_FL   (0x0010)
6414  
6415  /* Inode attributes, keep in sync with EXT2 */
6416 -#define OCFS2_SECRM_FL         (0x00000001)    /* Secure deletion */
6417 -#define OCFS2_UNRM_FL          (0x00000002)    /* Undelete */
6418 -#define OCFS2_COMPR_FL         (0x00000004)    /* Compress file */
6419 -#define OCFS2_SYNC_FL          (0x00000008)    /* Synchronous updates */
6420 -#define OCFS2_IMMUTABLE_FL     (0x00000010)    /* Immutable file */
6421 -#define OCFS2_APPEND_FL                (0x00000020)    /* writes to file may only append */
6422 -#define OCFS2_NODUMP_FL                (0x00000040)    /* do not dump file */
6423 -#define OCFS2_NOATIME_FL       (0x00000080)    /* do not update atime */
6424 -#define OCFS2_DIRSYNC_FL       (0x00010000)    /* dirsync behaviour (directories only) */
6425 +#define OCFS2_SECRM_FL         FS_SECRM_FL     /* Secure deletion */
6426 +#define OCFS2_UNRM_FL          FS_UNRM_FL      /* Undelete */
6427 +#define OCFS2_COMPR_FL         FS_COMPR_FL     /* Compress file */
6428 +#define OCFS2_SYNC_FL          FS_SYNC_FL      /* Synchronous updates */
6429 +#define OCFS2_IMMUTABLE_FL     FS_IMMUTABLE_FL /* Immutable file */
6430 +#define OCFS2_APPEND_FL                FS_APPEND_FL    /* writes to file may only append */
6431 +#define OCFS2_NODUMP_FL                FS_NODUMP_FL    /* do not dump file */
6432 +#define OCFS2_NOATIME_FL       FS_NOATIME_FL   /* do not update atime */
6433  
6434 -#define OCFS2_FL_VISIBLE       (0x000100FF)    /* User visible flags */
6435 -#define OCFS2_FL_MODIFIABLE    (0x000100FF)    /* User modifiable flags */
6436 +#define OCFS2_DIRSYNC_FL       FS_DIRSYNC_FL   /* dirsync behaviour (directories only) */
6437 +#define OCFS2_IXUNLINK_FL      FS_IXUNLINK_FL  /* Immutable invert on unlink */
6438 +
6439 +#define OCFS2_BARRIER_FL       FS_BARRIER_FL   /* Barrier for chroot() */
6440 +#define OCFS2_COW_FL           FS_COW_FL       /* Copy on Write marker */
6441 +
6442 +#define OCFS2_FL_VISIBLE       (0x010300FF)    /* User visible flags */
6443 +#define OCFS2_FL_MODIFIABLE    (0x010300FF)    /* User modifiable flags */
6444  
6445  /*
6446   * Extent record flags (e_node.leaf.flags)
6447 diff -NurpP --minimal linux-2.6.32.6/fs/ocfs2/ocfs2.h linux-2.6.32.6-vs2.3.0.36.28/fs/ocfs2/ocfs2.h
6448 --- linux-2.6.32.6/fs/ocfs2/ocfs2.h     2009-12-03 20:02:53.000000000 +0100
6449 +++ linux-2.6.32.6-vs2.3.0.36.28/fs/ocfs2/ocfs2.h       2009-12-03 20:04:56.000000000 +0100
6450 @@ -248,6 +248,7 @@ enum ocfs2_mount_options
6451         OCFS2_MOUNT_POSIX_ACL = 1 << 8, /* POSIX access control lists */
6452         OCFS2_MOUNT_USRQUOTA = 1 << 9, /* We support user quotas */
6453         OCFS2_MOUNT_GRPQUOTA = 1 << 10, /* We support group quotas */
6454 +       OCFS2_MOUNT_TAGGED = 1 << 11, /* use tagging */
6455  };
6456  
6457  #define OCFS2_OSB_SOFT_RO                      0x0001
6458 diff -NurpP --minimal linux-2.6.32.6/fs/ocfs2/super.c linux-2.6.32.6-vs2.3.0.36.28/fs/ocfs2/super.c
6459 --- linux-2.6.32.6/fs/ocfs2/super.c     2009-12-03 20:02:53.000000000 +0100
6460 +++ linux-2.6.32.6-vs2.3.0.36.28/fs/ocfs2/super.c       2009-12-03 20:04:56.000000000 +0100
6461 @@ -173,6 +173,7 @@ enum {
6462         Opt_noacl,
6463         Opt_usrquota,
6464         Opt_grpquota,
6465 +       Opt_tag, Opt_notag, Opt_tagid,
6466         Opt_err,
6467  };
6468  
6469 @@ -199,6 +200,9 @@ static const match_table_t tokens = {
6470         {Opt_noacl, "noacl"},
6471         {Opt_usrquota, "usrquota"},
6472         {Opt_grpquota, "grpquota"},
6473 +       {Opt_tag, "tag"},
6474 +       {Opt_notag, "notag"},
6475 +       {Opt_tagid, "tagid=%u"},
6476         {Opt_err, NULL}
6477  };
6478  
6479 @@ -605,6 +609,13 @@ static int ocfs2_remount(struct super_bl
6480                 goto out;
6481         }
6482  
6483 +       if ((osb->s_mount_opt & OCFS2_MOUNT_TAGGED) !=
6484 +           (parsed_options.mount_opt & OCFS2_MOUNT_TAGGED)) {
6485 +               ret = -EINVAL;
6486 +               mlog(ML_ERROR, "Cannot change tagging on remount\n");
6487 +               goto out;
6488 +       }
6489 +
6490         if ((osb->s_mount_opt & OCFS2_MOUNT_HB_LOCAL) !=
6491             (parsed_options.mount_opt & OCFS2_MOUNT_HB_LOCAL)) {
6492                 ret = -EINVAL;
6493 @@ -1148,6 +1159,9 @@ static int ocfs2_fill_super(struct super
6494  
6495         ocfs2_complete_mount_recovery(osb);
6496  
6497 +       if (osb->s_mount_opt & OCFS2_MOUNT_TAGGED)
6498 +               sb->s_flags |= MS_TAGGED;
6499 +
6500         if (ocfs2_mount_local(osb))
6501                 snprintf(nodestr, sizeof(nodestr), "local");
6502         else
6503 @@ -1426,6 +1440,20 @@ static int ocfs2_parse_options(struct su
6504                         printk(KERN_INFO "ocfs2 (no)acl options not supported\n");
6505                         break;
6506  #endif
6507 +#ifndef CONFIG_TAGGING_NONE
6508 +               case Opt_tag:
6509 +                       mopt->mount_opt |= OCFS2_MOUNT_TAGGED;
6510 +                       break;
6511 +               case Opt_notag:
6512 +                       mopt->mount_opt &= ~OCFS2_MOUNT_TAGGED;
6513 +                       break;
6514 +#endif
6515 +#ifdef CONFIG_PROPAGATE
6516 +               case Opt_tagid:
6517 +                       /* use args[0] */
6518 +                       mopt->mount_opt |= OCFS2_MOUNT_TAGGED;
6519 +                       break;
6520 +#endif
6521                 default:
6522                         mlog(ML_ERROR,
6523                              "Unrecognized mount option \"%s\" "
6524 diff -NurpP --minimal linux-2.6.32.6/fs/open.c linux-2.6.32.6-vs2.3.0.36.28/fs/open.c
6525 --- linux-2.6.32.6/fs/open.c    2009-12-03 20:02:53.000000000 +0100
6526 +++ linux-2.6.32.6-vs2.3.0.36.28/fs/open.c      2009-12-03 20:04:56.000000000 +0100
6527 @@ -30,22 +30,30 @@
6528  #include <linux/audit.h>
6529  #include <linux/falloc.h>
6530  #include <linux/fs_struct.h>
6531 +#include <linux/vs_base.h>
6532 +#include <linux/vs_limit.h>
6533 +#include <linux/vs_tag.h>
6534 +#include <linux/vs_cowbl.h>
6535  
6536  int vfs_statfs(struct dentry *dentry, struct kstatfs *buf)
6537  {
6538         int retval = -ENODEV;
6539  
6540         if (dentry) {
6541 +               struct super_block *sb = dentry->d_sb;
6542 +
6543                 retval = -ENOSYS;
6544 -               if (dentry->d_sb->s_op->statfs) {
6545 +               if (sb->s_op->statfs) {
6546                         memset(buf, 0, sizeof(*buf));
6547                         retval = security_sb_statfs(dentry);
6548                         if (retval)
6549                                 return retval;
6550 -                       retval = dentry->d_sb->s_op->statfs(dentry, buf);
6551 +                       retval = sb->s_op->statfs(dentry, buf);
6552                         if (retval == 0 && buf->f_frsize == 0)
6553                                 buf->f_frsize = buf->f_bsize;
6554                 }
6555 +               if (!vx_check(0, VS_ADMIN|VS_WATCH))
6556 +                       vx_vsi_statfs(sb, buf);
6557         }
6558         return retval;
6559  }
6560 @@ -640,6 +648,10 @@ SYSCALL_DEFINE3(fchmodat, int, dfd, cons
6561         error = user_path_at(dfd, filename, LOOKUP_FOLLOW, &path);
6562         if (error)
6563                 goto out;
6564 +
6565 +       error = cow_check_and_break(&path);
6566 +       if (error)
6567 +               goto dput_and_out;
6568         inode = path.dentry->d_inode;
6569  
6570         error = mnt_want_write(path.mnt);
6571 @@ -673,11 +685,11 @@ static int chown_common(struct dentry * 
6572         newattrs.ia_valid =  ATTR_CTIME;
6573         if (user != (uid_t) -1) {
6574                 newattrs.ia_valid |= ATTR_UID;
6575 -               newattrs.ia_uid = user;
6576 +               newattrs.ia_uid = dx_map_uid(user);
6577         }
6578         if (group != (gid_t) -1) {
6579                 newattrs.ia_valid |= ATTR_GID;
6580 -               newattrs.ia_gid = group;
6581 +               newattrs.ia_gid = dx_map_gid(group);
6582         }
6583         if (!S_ISDIR(inode->i_mode))
6584                 newattrs.ia_valid |=
6585 @@ -700,7 +712,11 @@ SYSCALL_DEFINE3(chown, const char __user
6586         error = mnt_want_write(path.mnt);
6587         if (error)
6588                 goto out_release;
6589 -       error = chown_common(path.dentry, user, group);
6590 +#ifdef CONFIG_VSERVER_COWBL
6591 +       error = cow_check_and_break(&path);
6592 +       if (!error)
6593 +#endif
6594 +               error = chown_common(path.dentry, user, group);
6595         mnt_drop_write(path.mnt);
6596  out_release:
6597         path_put(&path);
6598 @@ -725,7 +741,11 @@ SYSCALL_DEFINE5(fchownat, int, dfd, cons
6599         error = mnt_want_write(path.mnt);
6600         if (error)
6601                 goto out_release;
6602 -       error = chown_common(path.dentry, user, group);
6603 +#ifdef CONFIG_VSERVER_COWBL
6604 +       error = cow_check_and_break(&path);
6605 +       if (!error)
6606 +#endif
6607 +               error = chown_common(path.dentry, user, group);
6608         mnt_drop_write(path.mnt);
6609  out_release:
6610         path_put(&path);
6611 @@ -744,7 +764,11 @@ SYSCALL_DEFINE3(lchown, const char __use
6612         error = mnt_want_write(path.mnt);
6613         if (error)
6614                 goto out_release;
6615 -       error = chown_common(path.dentry, user, group);
6616 +#ifdef CONFIG_VSERVER_COWBL
6617 +       error = cow_check_and_break(&path);
6618 +       if (!error)
6619 +#endif
6620 +               error = chown_common(path.dentry, user, group);
6621         mnt_drop_write(path.mnt);
6622  out_release:
6623         path_put(&path);
6624 @@ -990,6 +1014,7 @@ static void __put_unused_fd(struct files
6625         __FD_CLR(fd, fdt->open_fds);
6626         if (fd < files->next_fd)
6627                 files->next_fd = fd;
6628 +       vx_openfd_dec(fd);
6629  }
6630  
6631  void put_unused_fd(unsigned int fd)
6632 diff -NurpP --minimal linux-2.6.32.6/fs/proc/array.c linux-2.6.32.6-vs2.3.0.36.28/fs/proc/array.c
6633 --- linux-2.6.32.6/fs/proc/array.c      2009-12-03 20:02:53.000000000 +0100
6634 +++ linux-2.6.32.6-vs2.3.0.36.28/fs/proc/array.c        2009-12-03 20:04:56.000000000 +0100
6635 @@ -83,6 +83,8 @@
6636  #include <linux/ptrace.h>
6637  #include <linux/tracehook.h>
6638  #include <linux/swapops.h>
6639 +#include <linux/vs_context.h>
6640 +#include <linux/vs_network.h>
6641  
6642  #include <asm/pgtable.h>
6643  #include <asm/processor.h>
6644 @@ -139,8 +141,9 @@ static const char *task_state_array[] = 
6645         "D (disk sleep)",       /*  2 */
6646         "T (stopped)",          /*  4 */
6647         "T (tracing stop)",     /*  8 */
6648 -       "Z (zombie)",           /* 16 */
6649 -       "X (dead)"              /* 32 */
6650 +       "H (on hold)",          /* 16 */
6651 +       "Z (zombie)",           /* 32 */
6652 +       "X (dead)",             /* 64 */
6653  };
6654  
6655  static inline const char *get_task_state(struct task_struct *tsk)
6656 @@ -167,6 +170,9 @@ static inline void task_state(struct seq
6657         rcu_read_lock();
6658         ppid = pid_alive(p) ?
6659                 task_tgid_nr_ns(rcu_dereference(p->real_parent), ns) : 0;
6660 +       if (unlikely(vx_current_initpid(p->pid)))
6661 +               ppid = 0;
6662 +
6663         tpid = 0;
6664         if (pid_alive(p)) {
6665                 struct task_struct *tracer = tracehook_tracer_task(p);
6666 @@ -282,7 +288,7 @@ static inline void task_sig(struct seq_f
6667  }
6668  
6669  static void render_cap_t(struct seq_file *m, const char *header,
6670 -                       kernel_cap_t *a)
6671 +                       struct vx_info *vxi, kernel_cap_t *a)
6672  {
6673         unsigned __capi;
6674  
6675 @@ -307,10 +313,11 @@ static inline void task_cap(struct seq_f
6676         cap_bset        = cred->cap_bset;
6677         rcu_read_unlock();
6678  
6679 -       render_cap_t(m, "CapInh:\t", &cap_inheritable);
6680 -       render_cap_t(m, "CapPrm:\t", &cap_permitted);
6681 -       render_cap_t(m, "CapEff:\t", &cap_effective);
6682 -       render_cap_t(m, "CapBnd:\t", &cap_bset);
6683 +       /* FIXME: maybe move the p->vx_info masking to __task_cred() ? */
6684 +       render_cap_t(m, "CapInh:\t", p->vx_info, &cap_inheritable);
6685 +       render_cap_t(m, "CapPrm:\t", p->vx_info, &cap_permitted);
6686 +       render_cap_t(m, "CapEff:\t", p->vx_info, &cap_effective);
6687 +       render_cap_t(m, "CapBnd:\t", p->vx_info, &cap_bset);
6688  }
6689  
6690  static inline void task_context_switch_counts(struct seq_file *m,
6691 @@ -410,6 +417,42 @@ static void task_show_stack_usage(struct
6692  }
6693  #endif         /* CONFIG_MMU */
6694  
6695 +int proc_pid_nsproxy(struct seq_file *m, struct pid_namespace *ns,
6696 +                       struct pid *pid, struct task_struct *task)
6697 +{
6698 +       seq_printf(m,   "Proxy:\t%p(%c)\n"
6699 +                       "Count:\t%u\n"
6700 +                       "uts:\t%p(%c)\n"
6701 +                       "ipc:\t%p(%c)\n"
6702 +                       "mnt:\t%p(%c)\n"
6703 +                       "pid:\t%p(%c)\n"
6704 +                       "net:\t%p(%c)\n",
6705 +                       task->nsproxy,
6706 +                       (task->nsproxy == init_task.nsproxy ? 'I' : '-'),
6707 +                       atomic_read(&task->nsproxy->count),
6708 +                       task->nsproxy->uts_ns,
6709 +                       (task->nsproxy->uts_ns == init_task.nsproxy->uts_ns ? 'I' : '-'),
6710 +                       task->nsproxy->ipc_ns,
6711 +                       (task->nsproxy->ipc_ns == init_task.nsproxy->ipc_ns ? 'I' : '-'),
6712 +                       task->nsproxy->mnt_ns,
6713 +                       (task->nsproxy->mnt_ns == init_task.nsproxy->mnt_ns ? 'I' : '-'),
6714 +                       task->nsproxy->pid_ns,
6715 +                       (task->nsproxy->pid_ns == init_task.nsproxy->pid_ns ? 'I' : '-'),
6716 +                       task->nsproxy->net_ns,
6717 +                       (task->nsproxy->net_ns == init_task.nsproxy->net_ns ? 'I' : '-'));
6718 +       return 0;
6719 +}
6720 +
6721 +void task_vs_id(struct seq_file *m, struct task_struct *task)
6722 +{
6723 +       if (task_vx_flags(task, VXF_HIDE_VINFO, 0))
6724 +               return;
6725 +
6726 +       seq_printf(m, "VxID: %d\n", vx_task_xid(task));
6727 +       seq_printf(m, "NxID: %d\n", nx_task_nid(task));
6728 +}
6729 +
6730 +
6731  int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
6732                         struct pid *pid, struct task_struct *task)
6733  {
6734 @@ -425,6 +468,7 @@ int proc_pid_status(struct seq_file *m, 
6735         task_sig(m, task);
6736         task_cap(m, task);
6737         cpuset_task_status_allowed(m, task);
6738 +       task_vs_id(m, task);
6739  #if defined(CONFIG_S390)
6740         task_show_regs(m, task);
6741  #endif
6742 @@ -542,6 +586,17 @@ static int do_task_stat(struct seq_file 
6743         /* convert nsec -> ticks */
6744         start_time = nsec_to_clock_t(start_time);
6745  
6746 +       /* fixup start time for virt uptime */
6747 +       if (vx_flags(VXF_VIRT_UPTIME, 0)) {
6748 +               unsigned long long bias =
6749 +                       current->vx_info->cvirt.bias_clock;
6750 +
6751 +               if (start_time > bias)
6752 +                       start_time -= bias;
6753 +               else
6754 +                       start_time = 0;
6755 +       }
6756 +
6757         seq_printf(m, "%d (%s) %c %d %d %d %d %d %u %lu \
6758  %lu %lu %lu %lu %lu %ld %ld %ld %ld %d 0 %llu %lu %ld %lu %lu %lu %lu %lu \
6759  %lu %lu %lu %lu %lu %lu %lu %lu %d %d %u %u %llu %lu %ld\n",
6760 diff -NurpP --minimal linux-2.6.32.6/fs/proc/base.c linux-2.6.32.6-vs2.3.0.36.28/fs/proc/base.c
6761 --- linux-2.6.32.6/fs/proc/base.c       2009-12-03 20:02:53.000000000 +0100
6762 +++ linux-2.6.32.6-vs2.3.0.36.28/fs/proc/base.c 2009-12-03 20:04:56.000000000 +0100
6763 @@ -81,6 +81,8 @@
6764  #include <linux/elf.h>
6765  #include <linux/pid_namespace.h>
6766  #include <linux/fs_struct.h>
6767 +#include <linux/vs_context.h>
6768 +#include <linux/vs_network.h>
6769  #include "internal.h"
6770  
6771  /* NOTE:
6772 @@ -1047,12 +1049,17 @@ static ssize_t oom_adjust_write(struct f
6773                 return -ESRCH;
6774         }
6775  
6776 -       if (oom_adjust < task->signal->oom_adj && !capable(CAP_SYS_RESOURCE)) {
6777 +       if (oom_adjust < task->signal->oom_adj &&
6778 +               !vx_capable(CAP_SYS_RESOURCE, VXC_OOM_ADJUST)) {
6779                 unlock_task_sighand(task, &flags);
6780                 put_task_struct(task);
6781                 return -EACCES;
6782         }
6783  
6784 +       /* prevent guest processes from circumventing the oom killer */
6785 +       if (vx_current_xid() && (oom_adjust == OOM_DISABLE))
6786 +               oom_adjust = OOM_ADJUST_MIN;
6787 +
6788         task->signal->oom_adj = oom_adjust;
6789  
6790         unlock_task_sighand(task, &flags);
6791 @@ -1092,7 +1099,7 @@ static ssize_t proc_loginuid_write(struc
6792         ssize_t length;
6793         uid_t loginuid;
6794  
6795 -       if (!capable(CAP_AUDIT_CONTROL))
6796 +       if (!vx_capable(CAP_AUDIT_CONTROL, VXC_AUDIT_CONTROL))
6797                 return -EPERM;
6798  
6799         if (current != pid_task(proc_pid(inode), PIDTYPE_PID))
6800 @@ -1458,6 +1465,8 @@ static struct inode *proc_pid_make_inode
6801                 inode->i_gid = cred->egid;
6802                 rcu_read_unlock();
6803         }
6804 +       /* procfs is xid tagged */
6805 +       inode->i_tag = (tag_t)vx_task_xid(task);
6806         security_task_to_inode(task, inode);
6807  
6808  out:
6809 @@ -2008,6 +2017,13 @@ static struct dentry *proc_pident_lookup
6810         if (!task)
6811                 goto out_no_task;
6812  
6813 +       /* TODO: maybe we can come up with a generic approach? */
6814 +       if (task_vx_flags(task, VXF_HIDE_VINFO, 0) &&
6815 +               (dentry->d_name.len == 5) &&
6816 +               (!memcmp(dentry->d_name.name, "vinfo", 5) ||
6817 +               !memcmp(dentry->d_name.name, "ninfo", 5)))
6818 +               goto out;
6819 +
6820         /*
6821          * Yes, it does not scale. And it should not. Don't add
6822          * new entries into /proc/<tgid>/ without very good reasons.
6823 @@ -2399,7 +2415,7 @@ out_iput:
6824  static struct dentry *proc_base_lookup(struct inode *dir, struct dentry *dentry)
6825  {
6826         struct dentry *error;
6827 -       struct task_struct *task = get_proc_task(dir);
6828 +       struct task_struct *task = get_proc_task_real(dir);
6829         const struct pid_entry *p, *last;
6830  
6831         error = ERR_PTR(-ENOENT);
6832 @@ -2489,6 +2505,9 @@ static int proc_pid_personality(struct s
6833  static const struct file_operations proc_task_operations;
6834  static const struct inode_operations proc_task_inode_operations;
6835  
6836 +extern int proc_pid_vx_info(struct task_struct *, char *);
6837 +extern int proc_pid_nx_info(struct task_struct *, char *);
6838 +
6839  static const struct pid_entry tgid_base_stuff[] = {
6840         DIR("task",       S_IRUGO|S_IXUGO, proc_task_inode_operations, proc_task_operations),
6841         DIR("fd",         S_IRUSR|S_IXUSR, proc_fd_inode_operations, proc_fd_operations),
6842 @@ -2547,6 +2566,8 @@ static const struct pid_entry tgid_base_
6843  #ifdef CONFIG_CGROUPS
6844         REG("cgroup",  S_IRUGO, proc_cgroup_operations),
6845  #endif
6846 +       INF("vinfo",      S_IRUGO, proc_pid_vx_info),
6847 +       INF("ninfo",      S_IRUGO, proc_pid_nx_info),
6848         INF("oom_score",  S_IRUGO, proc_oom_score),
6849         REG("oom_adj",    S_IRUGO|S_IWUSR, proc_oom_adjust_operations),
6850  #ifdef CONFIG_AUDITSYSCALL
6851 @@ -2562,6 +2583,7 @@ static const struct pid_entry tgid_base_
6852  #ifdef CONFIG_TASK_IO_ACCOUNTING
6853         INF("io",       S_IRUGO, proc_tgid_io_accounting),
6854  #endif
6855 +       ONE("nsproxy",  S_IRUGO, proc_pid_nsproxy),
6856  };
6857  
6858  static int proc_tgid_base_readdir(struct file * filp,
6859 @@ -2753,7 +2775,7 @@ retry:
6860         iter.task = NULL;
6861         pid = find_ge_pid(iter.tgid, ns);
6862         if (pid) {
6863 -               iter.tgid = pid_nr_ns(pid, ns);
6864 +               iter.tgid = pid_unmapped_nr_ns(pid, ns);
6865                 iter.task = pid_task(pid, PIDTYPE_PID);
6866                 /* What we to know is if the pid we have find is the
6867                  * pid of a thread_group_leader.  Testing for task
6868 @@ -2783,7 +2805,7 @@ static int proc_pid_fill_cache(struct fi
6869         struct tgid_iter iter)
6870  {
6871         char name[PROC_NUMBUF];
6872 -       int len = snprintf(name, sizeof(name), "%d", iter.tgid);
6873 +       int len = snprintf(name, sizeof(name), "%d", vx_map_tgid(iter.tgid));
6874         return proc_fill_cache(filp, dirent, filldir, name, len,
6875                                 proc_pid_instantiate, iter.task, NULL);
6876  }
6877 @@ -2792,7 +2814,7 @@ static int proc_pid_fill_cache(struct fi
6878  int proc_pid_readdir(struct file * filp, void * dirent, filldir_t filldir)
6879  {
6880         unsigned int nr = filp->f_pos - FIRST_PROCESS_ENTRY;
6881 -       struct task_struct *reaper = get_proc_task(filp->f_path.dentry->d_inode);
6882 +       struct task_struct *reaper = get_proc_task_real(filp->f_path.dentry->d_inode);
6883         struct tgid_iter iter;
6884         struct pid_namespace *ns;
6885  
6886 @@ -2812,6 +2834,8 @@ int proc_pid_readdir(struct file * filp,
6887              iter.task;
6888              iter.tgid += 1, iter = next_tgid(ns, iter)) {
6889                 filp->f_pos = iter.tgid + TGID_OFFSET;
6890 +               if (!vx_proc_task_visible(iter.task))
6891 +                       continue;
6892                 if (proc_pid_fill_cache(filp, dirent, filldir, iter) < 0) {
6893                         put_task_struct(iter.task);
6894                         goto out;
6895 @@ -2958,6 +2982,8 @@ static struct dentry *proc_task_lookup(s
6896         tid = name_to_int(dentry);
6897         if (tid == ~0U)
6898                 goto out;
6899 +       if (vx_current_initpid(tid))
6900 +               goto out;
6901  
6902         ns = dentry->d_sb->s_fs_info;
6903         rcu_read_lock();
6904 diff -NurpP --minimal linux-2.6.32.6/fs/proc/generic.c linux-2.6.32.6-vs2.3.0.36.28/fs/proc/generic.c
6905 --- linux-2.6.32.6/fs/proc/generic.c    2009-06-11 17:13:07.000000000 +0200
6906 +++ linux-2.6.32.6-vs2.3.0.36.28/fs/proc/generic.c      2009-12-03 20:04:56.000000000 +0100
6907 @@ -20,6 +20,7 @@
6908  #include <linux/bitops.h>
6909  #include <linux/spinlock.h>
6910  #include <linux/completion.h>
6911 +#include <linux/vserver/inode.h>
6912  #include <asm/uaccess.h>
6913  
6914  #include "internal.h"
6915 @@ -425,6 +426,8 @@ struct dentry *proc_lookup_de(struct pro
6916         for (de = de->subdir; de ; de = de->next) {
6917                 if (de->namelen != dentry->d_name.len)
6918                         continue;
6919 +                       if (!vx_hide_check(0, de->vx_flags))
6920 +                               continue;
6921                 if (!memcmp(dentry->d_name.name, de->name, de->namelen)) {
6922                         unsigned int ino;
6923  
6924 @@ -433,6 +436,8 @@ struct dentry *proc_lookup_de(struct pro
6925                         spin_unlock(&proc_subdir_lock);
6926                         error = -EINVAL;
6927                         inode = proc_get_inode(dir->i_sb, ino, de);
6928 +                               /* generic proc entries belong to the host */
6929 +                               inode->i_tag = 0;
6930                         goto out_unlock;
6931                 }
6932         }
6933 @@ -510,6 +515,8 @@ int proc_readdir_de(struct proc_dir_entr
6934  
6935                                 /* filldir passes info to user space */
6936                                 de_get(de);
6937 +                               if (!vx_hide_check(0, de->vx_flags))
6938 +                                       goto skip;
6939                                 spin_unlock(&proc_subdir_lock);
6940                                 if (filldir(dirent, de->name, de->namelen, filp->f_pos,
6941                                             de->low_ino, de->mode >> 12) < 0) {
6942 @@ -517,6 +524,7 @@ int proc_readdir_de(struct proc_dir_entr
6943                                         goto out;
6944                                 }
6945                                 spin_lock(&proc_subdir_lock);
6946 +                       skip:
6947                                 filp->f_pos++;
6948                                 next = de->next;
6949                                 de_put(de);
6950 @@ -631,6 +639,7 @@ static struct proc_dir_entry *__proc_cre
6951         ent->nlink = nlink;
6952         atomic_set(&ent->count, 1);
6953         ent->pde_users = 0;
6954 +       ent->vx_flags = IATTR_PROC_DEFAULT;
6955         spin_lock_init(&ent->pde_unload_lock);
6956         ent->pde_unload_completion = NULL;
6957         INIT_LIST_HEAD(&ent->pde_openers);
6958 @@ -654,7 +663,8 @@ struct proc_dir_entry *proc_symlink(cons
6959                                 kfree(ent->data);
6960                                 kfree(ent);
6961                                 ent = NULL;
6962 -                       }
6963 +                       } else
6964 +                               ent->vx_flags = IATTR_PROC_SYMLINK;
6965                 } else {
6966                         kfree(ent);
6967                         ent = NULL;
6968 diff -NurpP --minimal linux-2.6.32.6/fs/proc/inode.c linux-2.6.32.6-vs2.3.0.36.28/fs/proc/inode.c
6969 --- linux-2.6.32.6/fs/proc/inode.c      2009-06-11 17:13:07.000000000 +0200
6970 +++ linux-2.6.32.6-vs2.3.0.36.28/fs/proc/inode.c        2009-12-03 20:04:56.000000000 +0100
6971 @@ -459,6 +459,8 @@ struct inode *proc_get_inode(struct supe
6972                         inode->i_uid = de->uid;
6973                         inode->i_gid = de->gid;
6974                 }
6975 +               if (de->vx_flags)
6976 +                       PROC_I(inode)->vx_flags = de->vx_flags;
6977                 if (de->size)
6978                         inode->i_size = de->size;
6979                 if (de->nlink)
6980 diff -NurpP --minimal linux-2.6.32.6/fs/proc/internal.h linux-2.6.32.6-vs2.3.0.36.28/fs/proc/internal.h
6981 --- linux-2.6.32.6/fs/proc/internal.h   2009-09-10 15:26:23.000000000 +0200
6982 +++ linux-2.6.32.6-vs2.3.0.36.28/fs/proc/internal.h     2009-12-03 20:04:56.000000000 +0100
6983 @@ -10,6 +10,7 @@
6984   */
6985  
6986  #include <linux/proc_fs.h>
6987 +#include <linux/vs_pid.h>
6988  
6989  extern struct proc_dir_entry proc_root;
6990  #ifdef CONFIG_PROC_SYSCTL
6991 @@ -51,6 +52,9 @@ extern int proc_pid_status(struct seq_fi
6992                                 struct pid *pid, struct task_struct *task);
6993  extern int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns,
6994                                 struct pid *pid, struct task_struct *task);
6995 +extern int proc_pid_nsproxy(struct seq_file *m, struct pid_namespace *ns,
6996 +                               struct pid *pid, struct task_struct *task);
6997 +
6998  extern loff_t mem_lseek(struct file *file, loff_t offset, int orig);
6999  
7000  extern const struct file_operations proc_maps_operations;
7001 @@ -70,11 +74,16 @@ static inline struct pid *proc_pid(struc
7002         return PROC_I(inode)->pid;
7003  }
7004  
7005 -static inline struct task_struct *get_proc_task(struct inode *inode)
7006 +static inline struct task_struct *get_proc_task_real(struct inode *inode)
7007  {
7008         return get_pid_task(proc_pid(inode), PIDTYPE_PID);
7009  }
7010  
7011 +static inline struct task_struct *get_proc_task(struct inode *inode)
7012 +{
7013 +       return vx_get_proc_task(inode, proc_pid(inode));
7014 +}
7015 +
7016  static inline int proc_fd(struct inode *inode)
7017  {
7018         return PROC_I(inode)->fd;
7019 diff -NurpP --minimal linux-2.6.32.6/fs/proc/loadavg.c linux-2.6.32.6-vs2.3.0.36.28/fs/proc/loadavg.c
7020 --- linux-2.6.32.6/fs/proc/loadavg.c    2009-09-10 15:26:23.000000000 +0200
7021 +++ linux-2.6.32.6-vs2.3.0.36.28/fs/proc/loadavg.c      2009-12-03 20:04:56.000000000 +0100
7022 @@ -12,15 +12,27 @@
7023  
7024  static int loadavg_proc_show(struct seq_file *m, void *v)
7025  {
7026 +       unsigned long running;
7027 +       unsigned int threads;
7028         unsigned long avnrun[3];
7029  
7030         get_avenrun(avnrun, FIXED_1/200, 0);
7031  
7032 +       if (vx_flags(VXF_VIRT_LOAD, 0)) {
7033 +               struct vx_info *vxi = current_vx_info();
7034 +
7035 +               running = atomic_read(&vxi->cvirt.nr_running);
7036 +               threads = atomic_read(&vxi->cvirt.nr_threads);
7037 +       } else {
7038 +               running = nr_running();
7039 +               threads = nr_threads;
7040 +       }
7041 +
7042         seq_printf(m, "%lu.%02lu %lu.%02lu %lu.%02lu %ld/%d %d\n",
7043                 LOAD_INT(avnrun[0]), LOAD_FRAC(avnrun[0]),
7044                 LOAD_INT(avnrun[1]), LOAD_FRAC(avnrun[1]),
7045                 LOAD_INT(avnrun[2]), LOAD_FRAC(avnrun[2]),
7046 -               nr_running(), nr_threads,
7047 +               running, threads,
7048                 task_active_pid_ns(current)->last_pid);
7049         return 0;
7050  }
7051 diff -NurpP --minimal linux-2.6.32.6/fs/proc/meminfo.c linux-2.6.32.6-vs2.3.0.36.28/fs/proc/meminfo.c
7052 --- linux-2.6.32.6/fs/proc/meminfo.c    2009-12-03 20:02:53.000000000 +0100
7053 +++ linux-2.6.32.6-vs2.3.0.36.28/fs/proc/meminfo.c      2009-12-03 20:04:56.000000000 +0100
7054 @@ -41,7 +41,7 @@ static int meminfo_proc_show(struct seq_
7055  
7056         cached = global_page_state(NR_FILE_PAGES) -
7057                         total_swapcache_pages - i.bufferram;
7058 -       if (cached < 0)
7059 +       if (cached < 0 || vx_flags(VXF_VIRT_MEM, 0))
7060                 cached = 0;
7061  
7062         get_vmalloc_info(&vmi);
7063 diff -NurpP --minimal linux-2.6.32.6/fs/proc/root.c linux-2.6.32.6-vs2.3.0.36.28/fs/proc/root.c
7064 --- linux-2.6.32.6/fs/proc/root.c       2009-06-11 17:13:07.000000000 +0200
7065 +++ linux-2.6.32.6-vs2.3.0.36.28/fs/proc/root.c 2009-12-03 20:04:56.000000000 +0100
7066 @@ -18,9 +18,14 @@
7067  #include <linux/bitops.h>
7068  #include <linux/mount.h>
7069  #include <linux/pid_namespace.h>
7070 +#include <linux/vserver/inode.h>
7071  
7072  #include "internal.h"
7073  
7074 +struct proc_dir_entry *proc_virtual;
7075 +
7076 +extern void proc_vx_init(void);
7077 +
7078  static int proc_test_super(struct super_block *sb, void *data)
7079  {
7080         return sb->s_fs_info == data;
7081 @@ -136,6 +141,7 @@ void __init proc_root_init(void)
7082  #endif
7083         proc_mkdir("bus", NULL);
7084         proc_sys_init();
7085 +       proc_vx_init();
7086  }
7087  
7088  static int proc_root_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat
7089 @@ -203,6 +209,7 @@ struct proc_dir_entry proc_root = {
7090         .proc_iops      = &proc_root_inode_operations, 
7091         .proc_fops      = &proc_root_operations,
7092         .parent         = &proc_root,
7093 +       .vx_flags       = IATTR_ADMIN | IATTR_WATCH,
7094  };
7095  
7096  int pid_ns_prepare_proc(struct pid_namespace *ns)
7097 diff -NurpP --minimal linux-2.6.32.6/fs/proc/uptime.c linux-2.6.32.6-vs2.3.0.36.28/fs/proc/uptime.c
7098 --- linux-2.6.32.6/fs/proc/uptime.c     2009-12-03 20:02:53.000000000 +0100
7099 +++ linux-2.6.32.6-vs2.3.0.36.28/fs/proc/uptime.c       2009-12-03 20:04:56.000000000 +0100
7100 @@ -4,22 +4,22 @@
7101  #include <linux/sched.h>
7102  #include <linux/seq_file.h>
7103  #include <linux/time.h>
7104 -#include <linux/kernel_stat.h>
7105 +#include <linux/vserver/cvirt.h>
7106  #include <asm/cputime.h>
7107  
7108  static int uptime_proc_show(struct seq_file *m, void *v)
7109  {
7110         struct timespec uptime;
7111         struct timespec idle;
7112 -       int i;
7113 -       cputime_t idletime = cputime_zero;
7114 -
7115 -       for_each_possible_cpu(i)
7116 -               idletime = cputime64_add(idletime, kstat_cpu(i).cpustat.idle);
7117 +       cputime_t idletime = cputime_add(init_task.utime, init_task.stime);
7118  
7119         do_posix_clock_monotonic_gettime(&uptime);
7120         monotonic_to_bootbased(&uptime);
7121         cputime_to_timespec(idletime, &idle);
7122 +
7123 +       if (vx_flags(VXF_VIRT_UPTIME, 0))
7124 +               vx_vsi_uptime(&uptime, &idle);
7125 +
7126         seq_printf(m, "%lu.%02lu %lu.%02lu\n",
7127                         (unsigned long) uptime.tv_sec,
7128                         (uptime.tv_nsec / (NSEC_PER_SEC / 100)),
7129 diff -NurpP --minimal linux-2.6.32.6/fs/quota/quota.c linux-2.6.32.6-vs2.3.0.36.28/fs/quota/quota.c
7130 --- linux-2.6.32.6/fs/quota/quota.c     2009-09-10 15:26:24.000000000 +0200
7131 +++ linux-2.6.32.6-vs2.3.0.36.28/fs/quota/quota.c       2009-12-03 20:04:56.000000000 +0100
7132 @@ -18,6 +18,7 @@
7133  #include <linux/capability.h>
7134  #include <linux/quotaops.h>
7135  #include <linux/types.h>
7136 +#include <linux/vs_context.h>
7137  
7138  /* Check validity of generic quotactl commands */
7139  static int generic_quotactl_valid(struct super_block *sb, int type, int cmd,
7140 @@ -83,11 +84,11 @@ static int generic_quotactl_valid(struct
7141         if (cmd == Q_GETQUOTA) {
7142                 if (((type == USRQUOTA && current_euid() != id) ||
7143                      (type == GRPQUOTA && !in_egroup_p(id))) &&
7144 -                   !capable(CAP_SYS_ADMIN))
7145 +                   !vx_capable(CAP_SYS_ADMIN, VXC_QUOTA_CTL))
7146                         return -EPERM;
7147         }
7148         else if (cmd != Q_GETFMT && cmd != Q_SYNC && cmd != Q_GETINFO)
7149 -               if (!capable(CAP_SYS_ADMIN))
7150 +               if (!vx_capable(CAP_SYS_ADMIN, VXC_QUOTA_CTL))
7151                         return -EPERM;
7152  
7153         return 0;
7154 @@ -135,10 +136,10 @@ static int xqm_quotactl_valid(struct sup
7155         if (cmd == Q_XGETQUOTA) {
7156                 if (((type == XQM_USRQUOTA && current_euid() != id) ||
7157                      (type == XQM_GRPQUOTA && !in_egroup_p(id))) &&
7158 -                    !capable(CAP_SYS_ADMIN))
7159 +                    !vx_capable(CAP_SYS_ADMIN, VXC_QUOTA_CTL))
7160                         return -EPERM;
7161         } else if (cmd != Q_XGETQSTAT && cmd != Q_XQUOTASYNC) {
7162 -               if (!capable(CAP_SYS_ADMIN))
7163 +               if (!vx_capable(CAP_SYS_ADMIN, VXC_QUOTA_CTL))
7164                         return -EPERM;
7165         }
7166  
7167 @@ -351,6 +352,46 @@ static int do_quotactl(struct super_bloc
7168         return 0;
7169  }
7170  
7171 +#if defined(CONFIG_BLK_DEV_VROOT) || defined(CONFIG_BLK_DEV_VROOT_MODULE)
7172 +
7173 +#include <linux/vroot.h>
7174 +#include <linux/major.h>
7175 +#include <linux/module.h>
7176 +#include <linux/kallsyms.h>
7177 +#include <linux/vserver/debug.h>
7178 +
7179 +static vroot_grb_func *vroot_get_real_bdev = NULL;
7180 +
7181 +static spinlock_t vroot_grb_lock = SPIN_LOCK_UNLOCKED;
7182 +
7183 +int register_vroot_grb(vroot_grb_func *func) {
7184 +       int ret = -EBUSY;
7185 +
7186 +       spin_lock(&vroot_grb_lock);
7187 +       if (!vroot_get_real_bdev) {
7188 +               vroot_get_real_bdev = func;
7189 +               ret = 0;
7190 +       }
7191 +       spin_unlock(&vroot_grb_lock);
7192 +       return ret;
7193 +}
7194 +EXPORT_SYMBOL(register_vroot_grb);
7195 +
7196 +int unregister_vroot_grb(vroot_grb_func *func) {
7197 +       int ret = -EINVAL;
7198 +
7199 +       spin_lock(&vroot_grb_lock);
7200 +       if (vroot_get_real_bdev) {
7201 +               vroot_get_real_bdev = NULL;
7202 +               ret = 0;
7203 +       }
7204 +       spin_unlock(&vroot_grb_lock);
7205 +       return ret;
7206 +}
7207 +EXPORT_SYMBOL(unregister_vroot_grb);
7208 +
7209 +#endif
7210 +
7211  /*
7212   * look up a superblock on which quota ops will be performed
7213   * - use the name of a block device to find the superblock thereon
7214 @@ -368,6 +409,22 @@ static struct super_block *quotactl_bloc
7215         putname(tmp);
7216         if (IS_ERR(bdev))
7217                 return ERR_CAST(bdev);
7218 +#if defined(CONFIG_BLK_DEV_VROOT) || defined(CONFIG_BLK_DEV_VROOT_MODULE)
7219 +       if (bdev && bdev->bd_inode &&
7220 +                       imajor(bdev->bd_inode) == VROOT_MAJOR) {
7221 +               struct block_device *bdnew = (void *)-EINVAL;
7222 +
7223 +               if (vroot_get_real_bdev)
7224 +                       bdnew = vroot_get_real_bdev(bdev);
7225 +               else
7226 +                       vxdprintk(VXD_CBIT(misc, 0),
7227 +                                       "vroot_get_real_bdev not set");
7228 +               bdput(bdev);
7229 +               if (IS_ERR(bdnew))
7230 +                       return ERR_PTR(PTR_ERR(bdnew));
7231 +               bdev = bdnew;
7232 +       }
7233 +#endif
7234         sb = get_super(bdev);
7235         bdput(bdev);
7236         if (!sb)
7237 diff -NurpP --minimal linux-2.6.32.6/fs/reiserfs/file.c linux-2.6.32.6-vs2.3.0.36.28/fs/reiserfs/file.c
7238 --- linux-2.6.32.6/fs/reiserfs/file.c   2009-06-11 17:13:08.000000000 +0200
7239 +++ linux-2.6.32.6-vs2.3.0.36.28/fs/reiserfs/file.c     2009-12-03 20:04:56.000000000 +0100
7240 @@ -307,4 +307,5 @@ const struct inode_operations reiserfs_f
7241         .listxattr = reiserfs_listxattr,
7242         .removexattr = reiserfs_removexattr,
7243         .permission = reiserfs_permission,
7244 +       .sync_flags = reiserfs_sync_flags,
7245  };
7246 diff -NurpP --minimal linux-2.6.32.6/fs/reiserfs/inode.c linux-2.6.32.6-vs2.3.0.36.28/fs/reiserfs/inode.c
7247 --- linux-2.6.32.6/fs/reiserfs/inode.c  2010-01-26 19:31:27.000000000 +0100
7248 +++ linux-2.6.32.6-vs2.3.0.36.28/fs/reiserfs/inode.c    2010-01-26 20:35:35.000000000 +0100
7249 @@ -18,6 +18,7 @@
7250  #include <linux/writeback.h>
7251  #include <linux/quotaops.h>
7252  #include <linux/swap.h>
7253 +#include <linux/vs_tag.h>
7254  
7255  int reiserfs_commit_write(struct file *f, struct page *page,
7256                           unsigned from, unsigned to);
7257 @@ -1117,6 +1118,8 @@ static void init_inode(struct inode *ino
7258         struct buffer_head *bh;
7259         struct item_head *ih;
7260         __u32 rdev;
7261 +       uid_t uid;
7262 +       gid_t gid;
7263         //int version = ITEM_VERSION_1;
7264  
7265         bh = PATH_PLAST_BUFFER(path);
7266 @@ -1138,12 +1141,13 @@ static void init_inode(struct inode *ino
7267                     (struct stat_data_v1 *)B_I_PITEM(bh, ih);
7268                 unsigned long blocks;
7269  
7270 +               uid = sd_v1_uid(sd);
7271 +               gid = sd_v1_gid(sd);
7272 +
7273                 set_inode_item_key_version(inode, KEY_FORMAT_3_5);
7274                 set_inode_sd_version(inode, STAT_DATA_V1);
7275                 inode->i_mode = sd_v1_mode(sd);
7276                 inode->i_nlink = sd_v1_nlink(sd);
7277 -               inode->i_uid = sd_v1_uid(sd);
7278 -               inode->i_gid = sd_v1_gid(sd);
7279                 inode->i_size = sd_v1_size(sd);
7280                 inode->i_atime.tv_sec = sd_v1_atime(sd);
7281                 inode->i_mtime.tv_sec = sd_v1_mtime(sd);
7282 @@ -1185,11 +1189,12 @@ static void init_inode(struct inode *ino
7283                 // (directories and symlinks)
7284                 struct stat_data *sd = (struct stat_data *)B_I_PITEM(bh, ih);
7285  
7286 +               uid    = sd_v2_uid(sd);
7287 +               gid    = sd_v2_gid(sd);
7288 +
7289                 inode->i_mode = sd_v2_mode(sd);
7290                 inode->i_nlink = sd_v2_nlink(sd);
7291 -               inode->i_uid = sd_v2_uid(sd);
7292                 inode->i_size = sd_v2_size(sd);
7293 -               inode->i_gid = sd_v2_gid(sd);
7294                 inode->i_mtime.tv_sec = sd_v2_mtime(sd);
7295                 inode->i_atime.tv_sec = sd_v2_atime(sd);
7296                 inode->i_ctime.tv_sec = sd_v2_ctime(sd);
7297 @@ -1219,6 +1224,10 @@ static void init_inode(struct inode *ino
7298                 sd_attrs_to_i_attrs(sd_v2_attrs(sd), inode);
7299         }
7300  
7301 +       inode->i_uid = INOTAG_UID(DX_TAG(inode), uid, gid);
7302 +       inode->i_gid = INOTAG_GID(DX_TAG(inode), uid, gid);
7303 +       inode->i_tag = INOTAG_TAG(DX_TAG(inode), uid, gid, 0);
7304 +
7305         pathrelse(path);
7306         if (S_ISREG(inode->i_mode)) {
7307                 inode->i_op = &reiserfs_file_inode_operations;
7308 @@ -1241,13 +1250,15 @@ static void init_inode(struct inode *ino
7309  static void inode2sd(void *sd, struct inode *inode, loff_t size)
7310  {
7311         struct stat_data *sd_v2 = (struct stat_data *)sd;
7312 +       uid_t uid = TAGINO_UID(DX_TAG(inode), inode->i_uid, inode->i_tag);
7313 +       gid_t gid = TAGINO_GID(DX_TAG(inode), inode->i_gid, inode->i_tag);
7314         __u16 flags;
7315  
7316 +       set_sd_v2_uid(sd_v2, uid);
7317 +       set_sd_v2_gid(sd_v2, gid);
7318         set_sd_v2_mode(sd_v2, inode->i_mode);
7319         set_sd_v2_nlink(sd_v2, inode->i_nlink);
7320 -       set_sd_v2_uid(sd_v2, inode->i_uid);
7321         set_sd_v2_size(sd_v2, size);
7322 -       set_sd_v2_gid(sd_v2, inode->i_gid);
7323         set_sd_v2_mtime(sd_v2, inode->i_mtime.tv_sec);
7324         set_sd_v2_atime(sd_v2, inode->i_atime.tv_sec);
7325         set_sd_v2_ctime(sd_v2, inode->i_ctime.tv_sec);
7326 @@ -2839,14 +2850,19 @@ int reiserfs_commit_write(struct file *f
7327  void sd_attrs_to_i_attrs(__u16 sd_attrs, struct inode *inode)
7328  {
7329         if (reiserfs_attrs(inode->i_sb)) {
7330 -               if (sd_attrs & REISERFS_SYNC_FL)
7331 -                       inode->i_flags |= S_SYNC;
7332 -               else
7333 -                       inode->i_flags &= ~S_SYNC;
7334                 if (sd_attrs & REISERFS_IMMUTABLE_FL)
7335                         inode->i_flags |= S_IMMUTABLE;
7336                 else
7337                         inode->i_flags &= ~S_IMMUTABLE;
7338 +               if (sd_attrs & REISERFS_IXUNLINK_FL)
7339 +                       inode->i_flags |= S_IXUNLINK;
7340 +               else
7341 +                       inode->i_flags &= ~S_IXUNLINK;
7342 +
7343 +               if (sd_attrs & REISERFS_SYNC_FL)
7344 +                       inode->i_flags |= S_SYNC;
7345 +               else
7346 +                       inode->i_flags &= ~S_SYNC;
7347                 if (sd_attrs & REISERFS_APPEND_FL)
7348                         inode->i_flags |= S_APPEND;
7349                 else
7350 @@ -2859,6 +2875,15 @@ void sd_attrs_to_i_attrs(__u16 sd_attrs,
7351                         REISERFS_I(inode)->i_flags |= i_nopack_mask;
7352                 else
7353                         REISERFS_I(inode)->i_flags &= ~i_nopack_mask;
7354 +
7355 +               if (sd_attrs & REISERFS_BARRIER_FL)
7356 +                       inode->i_vflags |= V_BARRIER;
7357 +               else
7358 +                       inode->i_vflags &= ~V_BARRIER;
7359 +               if (sd_attrs & REISERFS_COW_FL)
7360 +                       inode->i_vflags |= V_COW;
7361 +               else
7362 +                       inode->i_vflags &= ~V_COW;
7363         }
7364  }
7365  
7366 @@ -2869,6 +2894,11 @@ void i_attrs_to_sd_attrs(struct inode *i
7367                         *sd_attrs |= REISERFS_IMMUTABLE_FL;
7368                 else
7369                         *sd_attrs &= ~REISERFS_IMMUTABLE_FL;
7370 +               if (inode->i_flags & S_IXUNLINK)
7371 +                       *sd_attrs |= REISERFS_IXUNLINK_FL;
7372 +               else
7373 +                       *sd_attrs &= ~REISERFS_IXUNLINK_FL;
7374 +
7375                 if (inode->i_flags & S_SYNC)
7376                         *sd_attrs |= REISERFS_SYNC_FL;
7377                 else
7378 @@ -2881,6 +2911,15 @@ void i_attrs_to_sd_attrs(struct inode *i
7379                         *sd_attrs |= REISERFS_NOTAIL_FL;
7380                 else
7381                         *sd_attrs &= ~REISERFS_NOTAIL_FL;
7382 +
7383 +               if (inode->i_vflags & V_BARRIER)
7384 +                       *sd_attrs |= REISERFS_BARRIER_FL;
7385 +               else
7386 +                       *sd_attrs &= ~REISERFS_BARRIER_FL;
7387 +               if (inode->i_vflags & V_COW)
7388 +                       *sd_attrs |= REISERFS_COW_FL;
7389 +               else
7390 +                       *sd_attrs &= ~REISERFS_COW_FL;
7391         }
7392  }
7393  
7394 @@ -3101,9 +3140,11 @@ int reiserfs_setattr(struct dentry *dent
7395         }
7396  
7397         error = inode_change_ok(inode, attr);
7398 +
7399         if (!error) {
7400                 if ((ia_valid & ATTR_UID && attr->ia_uid != inode->i_uid) ||
7401 -                   (ia_valid & ATTR_GID && attr->ia_gid != inode->i_gid)) {
7402 +                   (ia_valid & ATTR_GID && attr->ia_gid != inode->i_gid) ||
7403 +                   (ia_valid & ATTR_TAG && attr->ia_tag != inode->i_tag)) {
7404                         error = reiserfs_chown_xattrs(inode, attr);
7405  
7406                         if (!error) {
7407 @@ -3133,6 +3174,9 @@ int reiserfs_setattr(struct dentry *dent
7408                                         inode->i_uid = attr->ia_uid;
7409                                 if (attr->ia_valid & ATTR_GID)
7410                                         inode->i_gid = attr->ia_gid;
7411 +                               if ((attr->ia_valid & ATTR_TAG) &&
7412 +                                       IS_TAGGED(inode))
7413 +                                       inode->i_tag = attr->ia_tag;
7414                                 mark_inode_dirty(inode);
7415                                 error =
7416                                     journal_end(&th, inode->i_sb, jbegin_count);
7417 diff -NurpP --minimal linux-2.6.32.6/fs/reiserfs/ioctl.c linux-2.6.32.6-vs2.3.0.36.28/fs/reiserfs/ioctl.c
7418 --- linux-2.6.32.6/fs/reiserfs/ioctl.c  2009-06-11 17:13:08.000000000 +0200
7419 +++ linux-2.6.32.6-vs2.3.0.36.28/fs/reiserfs/ioctl.c    2009-12-03 20:04:56.000000000 +0100
7420 @@ -7,11 +7,27 @@
7421  #include <linux/mount.h>
7422  #include <linux/reiserfs_fs.h>
7423  #include <linux/time.h>
7424 +#include <linux/mount.h>
7425  #include <asm/uaccess.h>
7426  #include <linux/pagemap.h>
7427  #include <linux/smp_lock.h>
7428  #include <linux/compat.h>
7429  
7430 +
7431 +int reiserfs_sync_flags(struct inode *inode, int flags, int vflags)
7432 +{
7433 +       __u16 sd_attrs = 0;
7434 +
7435 +       inode->i_flags = flags;
7436 +       inode->i_vflags = vflags;
7437 +
7438 +       i_attrs_to_sd_attrs(inode, &sd_attrs);
7439 +       REISERFS_I(inode)->i_attrs = sd_attrs;
7440 +       inode->i_ctime = CURRENT_TIME_SEC;
7441 +       mark_inode_dirty(inode);
7442 +       return 0;
7443 +}
7444 +
7445  /*
7446  ** reiserfs_ioctl - handler for ioctl for inode
7447  ** supported commands:
7448 @@ -23,7 +39,7 @@
7449  int reiserfs_ioctl(struct inode *inode, struct file *filp, unsigned int cmd,
7450                    unsigned long arg)
7451  {
7452 -       unsigned int flags;
7453 +       unsigned int flags, oldflags;
7454         int err = 0;
7455  
7456         switch (cmd) {
7457 @@ -43,6 +59,7 @@ int reiserfs_ioctl(struct inode *inode, 
7458  
7459                 flags = REISERFS_I(inode)->i_attrs;
7460                 i_attrs_to_sd_attrs(inode, (__u16 *) & flags);
7461 +               flags &= REISERFS_FL_USER_VISIBLE;
7462                 return put_user(flags, (int __user *)arg);
7463         case REISERFS_IOC_SETFLAGS:{
7464                         if (!reiserfs_attrs(inode->i_sb))
7465 @@ -60,6 +77,10 @@ int reiserfs_ioctl(struct inode *inode, 
7466                                 err = -EFAULT;
7467                                 goto setflags_out;
7468                         }
7469 +                       if (IS_BARRIER(inode)) {
7470 +                               vxwprintk_task(1, "messing with the barrier.");
7471 +                               return -EACCES;
7472 +                       }
7473                         /*
7474                          * Is it quota file? Do not allow user to mess with it
7475                          */
7476 @@ -84,6 +105,10 @@ int reiserfs_ioctl(struct inode *inode, 
7477                                         goto setflags_out;
7478                                 }
7479                         }
7480 +
7481 +                       oldflags = REISERFS_I(inode)->i_attrs;
7482 +                       flags &= REISERFS_FL_USER_MODIFIABLE;
7483 +                       flags |= oldflags & ~REISERFS_FL_USER_MODIFIABLE;
7484                         sd_attrs_to_i_attrs(flags, inode);
7485                         REISERFS_I(inode)->i_attrs = flags;
7486                         inode->i_ctime = CURRENT_TIME_SEC;
7487 diff -NurpP --minimal linux-2.6.32.6/fs/reiserfs/namei.c linux-2.6.32.6-vs2.3.0.36.28/fs/reiserfs/namei.c
7488 --- linux-2.6.32.6/fs/reiserfs/namei.c  2009-06-11 17:13:08.000000000 +0200
7489 +++ linux-2.6.32.6-vs2.3.0.36.28/fs/reiserfs/namei.c    2009-12-03 20:04:56.000000000 +0100
7490 @@ -17,6 +17,7 @@
7491  #include <linux/reiserfs_acl.h>
7492  #include <linux/reiserfs_xattr.h>
7493  #include <linux/quotaops.h>
7494 +#include <linux/vs_tag.h>
7495  
7496  #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; }
7497  #define DEC_DIR_INODE_NLINK(i) if (i->i_nlink != 1) drop_nlink(i);
7498 @@ -354,6 +355,7 @@ static struct dentry *reiserfs_lookup(st
7499         if (retval == IO_ERROR) {
7500                 return ERR_PTR(-EIO);
7501         }
7502 +               dx_propagate_tag(nd, inode);
7503  
7504         return d_splice_alias(inode, dentry);
7505  }
7506 @@ -570,6 +572,7 @@ static int new_inode_init(struct inode *
7507         } else {
7508                 inode->i_gid = current_fsgid();
7509         }
7510 +       inode->i_tag = dx_current_fstag(inode->i_sb);
7511         vfs_dq_init(inode);
7512         return 0;
7513  }
7514 @@ -1515,6 +1518,7 @@ const struct inode_operations reiserfs_d
7515         .listxattr = reiserfs_listxattr,
7516         .removexattr = reiserfs_removexattr,
7517         .permission = reiserfs_permission,
7518 +       .sync_flags = reiserfs_sync_flags,
7519  };
7520  
7521  /*
7522 diff -NurpP --minimal linux-2.6.32.6/fs/reiserfs/super.c linux-2.6.32.6-vs2.3.0.36.28/fs/reiserfs/super.c
7523 --- linux-2.6.32.6/fs/reiserfs/super.c  2009-12-03 20:02:53.000000000 +0100
7524 +++ linux-2.6.32.6-vs2.3.0.36.28/fs/reiserfs/super.c    2009-12-03 20:04:56.000000000 +0100
7525 @@ -884,6 +884,14 @@ static int reiserfs_parse_options(struct
7526                 {"user_xattr",.setmask = 1 << REISERFS_UNSUPPORTED_OPT},
7527                 {"nouser_xattr",.clrmask = 1 << REISERFS_UNSUPPORTED_OPT},
7528  #endif
7529 +#ifndef CONFIG_TAGGING_NONE
7530 +               {"tagxid",.setmask = 1 << REISERFS_TAGGED},
7531 +               {"tag",.setmask = 1 << REISERFS_TAGGED},
7532 +               {"notag",.clrmask = 1 << REISERFS_TAGGED},
7533 +#endif
7534 +#ifdef CONFIG_PROPAGATE
7535 +               {"tag",.arg_required = 'T',.values = NULL},
7536 +#endif
7537  #ifdef CONFIG_REISERFS_FS_POSIX_ACL
7538                 {"acl",.setmask = 1 << REISERFS_POSIXACL},
7539                 {"noacl",.clrmask = 1 << REISERFS_POSIXACL},
7540 @@ -1190,6 +1198,14 @@ static int reiserfs_remount(struct super
7541         handle_quota_files(s, qf_names, &qfmt);
7542  #endif
7543  
7544 +       if ((mount_options & (1 << REISERFS_TAGGED)) &&
7545 +               !(s->s_flags & MS_TAGGED)) {
7546 +               reiserfs_warning(s, "super-vs01",
7547 +                       "reiserfs: tagging not permitted on remount.");
7548 +               err = -EINVAL;
7549 +               goto out_err;
7550 +       }
7551 +
7552         handle_attrs(s);
7553  
7554         /* Add options that are safe here */
7555 @@ -1652,6 +1668,10 @@ static int reiserfs_fill_super(struct su
7556                 goto error;
7557         }
7558  
7559 +       /* map mount option tagxid */
7560 +       if (REISERFS_SB(s)->s_mount_opt & (1 << REISERFS_TAGGED))
7561 +               s->s_flags |= MS_TAGGED;
7562 +
7563         rs = SB_DISK_SUPER_BLOCK(s);
7564         /* Let's do basic sanity check to verify that underlying device is not
7565            smaller than the filesystem. If the check fails then abort and scream,
7566 diff -NurpP --minimal linux-2.6.32.6/fs/reiserfs/xattr.c linux-2.6.32.6-vs2.3.0.36.28/fs/reiserfs/xattr.c
7567 --- linux-2.6.32.6/fs/reiserfs/xattr.c  2009-09-10 15:26:24.000000000 +0200
7568 +++ linux-2.6.32.6-vs2.3.0.36.28/fs/reiserfs/xattr.c    2009-12-03 20:04:56.000000000 +0100
7569 @@ -39,6 +39,7 @@
7570  #include <linux/namei.h>
7571  #include <linux/errno.h>
7572  #include <linux/fs.h>
7573 +#include <linux/mount.h>
7574  #include <linux/file.h>
7575  #include <linux/pagemap.h>
7576  #include <linux/xattr.h>
7577 diff -NurpP --minimal linux-2.6.32.6/fs/stat.c linux-2.6.32.6-vs2.3.0.36.28/fs/stat.c
7578 --- linux-2.6.32.6/fs/stat.c    2010-01-26 19:31:27.000000000 +0100
7579 +++ linux-2.6.32.6-vs2.3.0.36.28/fs/stat.c      2010-01-13 14:33:47.000000000 +0100
7580 @@ -26,6 +26,7 @@ void generic_fillattr(struct inode *inod
7581         stat->nlink = inode->i_nlink;
7582         stat->uid = inode->i_uid;
7583         stat->gid = inode->i_gid;
7584 +       stat->tag = inode->i_tag;
7585         stat->rdev = inode->i_rdev;
7586         stat->atime = inode->i_atime;
7587         stat->mtime = inode->i_mtime;
7588 diff -NurpP --minimal linux-2.6.32.6/fs/super.c linux-2.6.32.6-vs2.3.0.36.28/fs/super.c
7589 --- linux-2.6.32.6/fs/super.c   2009-12-03 20:02:53.000000000 +0100
7590 +++ linux-2.6.32.6-vs2.3.0.36.28/fs/super.c     2009-12-03 20:04:56.000000000 +0100
7591 @@ -37,6 +37,9 @@
7592  #include <linux/kobject.h>
7593  #include <linux/mutex.h>
7594  #include <linux/file.h>
7595 +#include <linux/devpts_fs.h>
7596 +#include <linux/proc_fs.h>
7597 +#include <linux/vs_context.h>
7598  #include <asm/uaccess.h>
7599  #include "internal.h"
7600  
7601 @@ -913,12 +916,18 @@ struct vfsmount *
7602  vfs_kern_mount(struct file_system_type *type, int flags, const char *name, void *data)
7603  {
7604         struct vfsmount *mnt;
7605 +       struct super_block *sb;
7606         char *secdata = NULL;
7607         int error;
7608  
7609         if (!type)
7610                 return ERR_PTR(-ENODEV);
7611  
7612 +       error = -EPERM;
7613 +       if ((type->fs_flags & FS_BINARY_MOUNTDATA) &&
7614 +               !vx_capable(CAP_SYS_ADMIN, VXC_BINARY_MOUNT))
7615 +               goto out;
7616 +
7617         error = -ENOMEM;
7618         mnt = alloc_vfsmnt(name);
7619         if (!mnt)
7620 @@ -937,9 +946,17 @@ vfs_kern_mount(struct file_system_type *
7621         error = type->get_sb(type, flags, name, data, mnt);
7622         if (error < 0)
7623                 goto out_free_secdata;
7624 -       BUG_ON(!mnt->mnt_sb);
7625  
7626 -       error = security_sb_kern_mount(mnt->mnt_sb, flags, secdata);
7627 +       sb = mnt->mnt_sb;
7628 +       BUG_ON(!sb);
7629 +
7630 +       error = -EPERM;
7631 +       if (!vx_capable(CAP_SYS_ADMIN, VXC_BINARY_MOUNT) && !sb->s_bdev &&
7632 +               (sb->s_magic != PROC_SUPER_MAGIC) &&
7633 +               (sb->s_magic != DEVPTS_SUPER_MAGIC))
7634 +               goto out_sb;
7635 +
7636 +       error = security_sb_kern_mount(sb, flags, secdata);
7637         if (error)
7638                 goto out_sb;
7639  
7640 diff -NurpP --minimal linux-2.6.32.6/fs/sysfs/mount.c linux-2.6.32.6-vs2.3.0.36.28/fs/sysfs/mount.c
7641 --- linux-2.6.32.6/fs/sysfs/mount.c     2009-06-11 17:13:08.000000000 +0200
7642 +++ linux-2.6.32.6-vs2.3.0.36.28/fs/sysfs/mount.c       2009-12-03 20:04:56.000000000 +0100
7643 @@ -47,7 +47,7 @@ static int sysfs_fill_super(struct super
7644  
7645         sb->s_blocksize = PAGE_CACHE_SIZE;
7646         sb->s_blocksize_bits = PAGE_CACHE_SHIFT;
7647 -       sb->s_magic = SYSFS_MAGIC;
7648 +       sb->s_magic = SYSFS_SUPER_MAGIC;
7649         sb->s_op = &sysfs_ops;
7650         sb->s_time_gran = 1;
7651         sysfs_sb = sb;
7652 diff -NurpP --minimal linux-2.6.32.6/fs/utimes.c linux-2.6.32.6-vs2.3.0.36.28/fs/utimes.c
7653 --- linux-2.6.32.6/fs/utimes.c  2009-03-24 14:22:37.000000000 +0100
7654 +++ linux-2.6.32.6-vs2.3.0.36.28/fs/utimes.c    2009-12-03 20:04:56.000000000 +0100
7655 @@ -8,6 +8,8 @@
7656  #include <linux/stat.h>
7657  #include <linux/utime.h>
7658  #include <linux/syscalls.h>
7659 +#include <linux/mount.h>
7660 +#include <linux/vs_cowbl.h>
7661  #include <asm/uaccess.h>
7662  #include <asm/unistd.h>
7663  
7664 diff -NurpP --minimal linux-2.6.32.6/fs/xattr.c linux-2.6.32.6-vs2.3.0.36.28/fs/xattr.c
7665 --- linux-2.6.32.6/fs/xattr.c   2009-12-03 20:02:53.000000000 +0100
7666 +++ linux-2.6.32.6-vs2.3.0.36.28/fs/xattr.c     2009-12-03 20:04:56.000000000 +0100
7667 @@ -18,6 +18,7 @@
7668  #include <linux/module.h>
7669  #include <linux/fsnotify.h>
7670  #include <linux/audit.h>
7671 +#include <linux/mount.h>
7672  #include <asm/uaccess.h>
7673  
7674  
7675 diff -NurpP --minimal linux-2.6.32.6/fs/xfs/linux-2.6/xfs_ioctl.c linux-2.6.32.6-vs2.3.0.36.28/fs/xfs/linux-2.6/xfs_ioctl.c
7676 --- linux-2.6.32.6/fs/xfs/linux-2.6/xfs_ioctl.c 2009-09-10 15:26:24.000000000 +0200
7677 +++ linux-2.6.32.6-vs2.3.0.36.28/fs/xfs/linux-2.6/xfs_ioctl.c   2009-12-03 20:04:56.000000000 +0100
7678 @@ -34,7 +34,6 @@
7679  #include "xfs_dir2_sf.h"
7680  #include "xfs_dinode.h"
7681  #include "xfs_inode.h"
7682 -#include "xfs_ioctl.h"
7683  #include "xfs_btree.h"
7684  #include "xfs_ialloc.h"
7685  #include "xfs_rtalloc.h"
7686 @@ -742,6 +741,10 @@ xfs_merge_ioc_xflags(
7687                 xflags |= XFS_XFLAG_IMMUTABLE;
7688         else
7689                 xflags &= ~XFS_XFLAG_IMMUTABLE;
7690 +       if (flags & FS_IXUNLINK_FL)
7691 +               xflags |= XFS_XFLAG_IXUNLINK;
7692 +       else
7693 +               xflags &= ~XFS_XFLAG_IXUNLINK;
7694         if (flags & FS_APPEND_FL)
7695                 xflags |= XFS_XFLAG_APPEND;
7696         else
7697 @@ -770,6 +773,8 @@ xfs_di2lxflags(
7698  
7699         if (di_flags & XFS_DIFLAG_IMMUTABLE)
7700                 flags |= FS_IMMUTABLE_FL;
7701 +       if (di_flags & XFS_DIFLAG_IXUNLINK)
7702 +               flags |= FS_IXUNLINK_FL;
7703         if (di_flags & XFS_DIFLAG_APPEND)
7704                 flags |= FS_APPEND_FL;
7705         if (di_flags & XFS_DIFLAG_SYNC)
7706 @@ -828,6 +833,8 @@ xfs_set_diflags(
7707         di_flags = (ip->i_d.di_flags & XFS_DIFLAG_PREALLOC);
7708         if (xflags & XFS_XFLAG_IMMUTABLE)
7709                 di_flags |= XFS_DIFLAG_IMMUTABLE;
7710 +       if (xflags & XFS_XFLAG_IXUNLINK)
7711 +               di_flags |= XFS_DIFLAG_IXUNLINK;
7712         if (xflags & XFS_XFLAG_APPEND)
7713                 di_flags |= XFS_DIFLAG_APPEND;
7714         if (xflags & XFS_XFLAG_SYNC)
7715 @@ -870,6 +877,10 @@ xfs_diflags_to_linux(
7716                 inode->i_flags |= S_IMMUTABLE;
7717         else
7718                 inode->i_flags &= ~S_IMMUTABLE;
7719 +       if (xflags & XFS_XFLAG_IXUNLINK)
7720 +               inode->i_flags |= S_IXUNLINK;
7721 +       else
7722 +               inode->i_flags &= ~S_IXUNLINK;
7723         if (xflags & XFS_XFLAG_APPEND)
7724                 inode->i_flags |= S_APPEND;
7725         else
7726 @@ -1346,10 +1357,18 @@ xfs_file_ioctl(
7727         case XFS_IOC_FSGETXATTRA:
7728                 return xfs_ioc_fsgetxattr(ip, 1, arg);
7729         case XFS_IOC_FSSETXATTR:
7730 +               if (IS_BARRIER(inode)) {
7731 +                       vxwprintk_task(1, "messing with the barrier.");
7732 +                       return -XFS_ERROR(EACCES);
7733 +               }
7734                 return xfs_ioc_fssetxattr(ip, filp, arg);
7735         case XFS_IOC_GETXFLAGS:
7736                 return xfs_ioc_getxflags(ip, arg);
7737         case XFS_IOC_SETXFLAGS:
7738 +               if (IS_BARRIER(inode)) {
7739 +                       vxwprintk_task(1, "messing with the barrier.");
7740 +                       return -XFS_ERROR(EACCES);
7741 +               }
7742                 return xfs_ioc_setxflags(ip, filp, arg);
7743  
7744         case XFS_IOC_FSSETDM: {
7745 diff -NurpP --minimal linux-2.6.32.6/fs/xfs/linux-2.6/xfs_ioctl.h linux-2.6.32.6-vs2.3.0.36.28/fs/xfs/linux-2.6/xfs_ioctl.h
7746 --- linux-2.6.32.6/fs/xfs/linux-2.6/xfs_ioctl.h 2009-03-24 14:22:37.000000000 +0100
7747 +++ linux-2.6.32.6-vs2.3.0.36.28/fs/xfs/linux-2.6/xfs_ioctl.h   2009-12-03 20:04:56.000000000 +0100
7748 @@ -70,6 +70,12 @@ xfs_handle_to_dentry(
7749         void __user             *uhandle,
7750         u32                     hlen);
7751  
7752 +extern int
7753 +xfs_sync_flags(
7754 +       struct inode            *inode,
7755 +       int                     flags,
7756 +       int                     vflags);
7757 +
7758  extern long
7759  xfs_file_ioctl(
7760         struct file             *filp,
7761 diff -NurpP --minimal linux-2.6.32.6/fs/xfs/linux-2.6/xfs_iops.c linux-2.6.32.6-vs2.3.0.36.28/fs/xfs/linux-2.6/xfs_iops.c
7762 --- linux-2.6.32.6/fs/xfs/linux-2.6/xfs_iops.c  2009-12-03 20:02:53.000000000 +0100
7763 +++ linux-2.6.32.6-vs2.3.0.36.28/fs/xfs/linux-2.6/xfs_iops.c    2009-12-03 20:04:56.000000000 +0100
7764 @@ -36,6 +36,7 @@
7765  #include "xfs_attr_sf.h"
7766  #include "xfs_dinode.h"
7767  #include "xfs_inode.h"
7768 +#include "xfs_ioctl.h"
7769  #include "xfs_bmap.h"
7770  #include "xfs_btree.h"
7771  #include "xfs_ialloc.h"
7772 @@ -55,6 +56,7 @@
7773  #include <linux/security.h>
7774  #include <linux/falloc.h>
7775  #include <linux/fiemap.h>
7776 +#include <linux/vs_tag.h>
7777  
7778  /*
7779   * Bring the timestamps in the XFS inode uptodate.
7780 @@ -495,6 +497,7 @@ xfs_vn_getattr(
7781         stat->nlink = ip->i_d.di_nlink;
7782         stat->uid = ip->i_d.di_uid;
7783         stat->gid = ip->i_d.di_gid;
7784 +       stat->tag = ip->i_d.di_tag;
7785         stat->ino = ip->i_ino;
7786         stat->atime = inode->i_atime;
7787         stat->mtime = inode->i_mtime;
7788 @@ -686,6 +689,7 @@ static const struct inode_operations xfs
7789         .listxattr              = xfs_vn_listxattr,
7790         .fallocate              = xfs_vn_fallocate,
7791         .fiemap                 = xfs_vn_fiemap,
7792 +       .sync_flags             = xfs_sync_flags,
7793  };
7794  
7795  static const struct inode_operations xfs_dir_inode_operations = {
7796 @@ -711,6 +715,7 @@ static const struct inode_operations xfs
7797         .getxattr               = generic_getxattr,
7798         .removexattr            = generic_removexattr,
7799         .listxattr              = xfs_vn_listxattr,
7800 +       .sync_flags             = xfs_sync_flags,
7801  };
7802  
7803  static const struct inode_operations xfs_dir_ci_inode_operations = {
7804 @@ -760,6 +765,10 @@ xfs_diflags_to_iflags(
7805                 inode->i_flags |= S_IMMUTABLE;
7806         else
7807                 inode->i_flags &= ~S_IMMUTABLE;
7808 +       if (ip->i_d.di_flags & XFS_DIFLAG_IXUNLINK)
7809 +               inode->i_flags |= S_IXUNLINK;
7810 +       else
7811 +               inode->i_flags &= ~S_IXUNLINK;
7812         if (ip->i_d.di_flags & XFS_DIFLAG_APPEND)
7813                 inode->i_flags |= S_APPEND;
7814         else
7815 @@ -772,6 +781,15 @@ xfs_diflags_to_iflags(
7816                 inode->i_flags |= S_NOATIME;
7817         else
7818                 inode->i_flags &= ~S_NOATIME;
7819 +
7820 +       if (ip->i_d.di_vflags & XFS_DIVFLAG_BARRIER)
7821 +               inode->i_vflags |= V_BARRIER;
7822 +       else
7823 +               inode->i_vflags &= ~V_BARRIER;
7824 +       if (ip->i_d.di_vflags & XFS_DIVFLAG_COW)
7825 +               inode->i_vflags |= V_COW;
7826 +       else
7827 +               inode->i_vflags &= ~V_COW;
7828  }
7829  
7830  /*
7831 @@ -800,6 +818,7 @@ xfs_setup_inode(
7832         inode->i_nlink  = ip->i_d.di_nlink;
7833         inode->i_uid    = ip->i_d.di_uid;
7834         inode->i_gid    = ip->i_d.di_gid;
7835 +       inode->i_tag    = ip->i_d.di_tag;
7836  
7837         switch (inode->i_mode & S_IFMT) {
7838         case S_IFBLK:
7839 diff -NurpP --minimal linux-2.6.32.6/fs/xfs/linux-2.6/xfs_linux.h linux-2.6.32.6-vs2.3.0.36.28/fs/xfs/linux-2.6/xfs_linux.h
7840 --- linux-2.6.32.6/fs/xfs/linux-2.6/xfs_linux.h 2009-09-10 15:26:24.000000000 +0200
7841 +++ linux-2.6.32.6-vs2.3.0.36.28/fs/xfs/linux-2.6/xfs_linux.h   2009-12-03 20:04:56.000000000 +0100
7842 @@ -119,6 +119,7 @@
7843  
7844  #define current_cpu()          (raw_smp_processor_id())
7845  #define current_pid()          (current->pid)
7846 +#define current_fstag(cred,vp) (dx_current_fstag((vp)->i_sb))
7847  #define current_test_flags(f)  (current->flags & (f))
7848  #define current_set_flags_nested(sp, f)                \
7849                 (*(sp) = current->flags, current->flags |= (f))
7850 diff -NurpP --minimal linux-2.6.32.6/fs/xfs/linux-2.6/xfs_super.c linux-2.6.32.6-vs2.3.0.36.28/fs/xfs/linux-2.6/xfs_super.c
7851 --- linux-2.6.32.6/fs/xfs/linux-2.6/xfs_super.c 2009-12-03 20:02:53.000000000 +0100
7852 +++ linux-2.6.32.6-vs2.3.0.36.28/fs/xfs/linux-2.6/xfs_super.c   2009-12-03 20:04:56.000000000 +0100
7853 @@ -117,6 +117,9 @@ mempool_t *xfs_ioend_pool;
7854  #define MNTOPT_DMAPI   "dmapi"         /* DMI enabled (DMAPI / XDSM) */
7855  #define MNTOPT_XDSM    "xdsm"          /* DMI enabled (DMAPI / XDSM) */
7856  #define MNTOPT_DMI     "dmi"           /* DMI enabled (DMAPI / XDSM) */
7857 +#define MNTOPT_TAGXID  "tagxid"        /* context tagging for inodes */
7858 +#define MNTOPT_TAGGED  "tag"           /* context tagging for inodes */
7859 +#define MNTOPT_NOTAGTAG        "notag"         /* do not use context tagging */
7860  
7861  /*
7862   * Table driven mount option parser.
7863 @@ -125,10 +128,14 @@ mempool_t *xfs_ioend_pool;
7864   * in the future, too.
7865   */
7866  enum {
7867 +       Opt_tag, Opt_notag,
7868         Opt_barrier, Opt_nobarrier, Opt_err
7869  };
7870  
7871  static const match_table_t tokens = {
7872 +       {Opt_tag, "tagxid"},
7873 +       {Opt_tag, "tag"},
7874 +       {Opt_notag, "notag"},
7875         {Opt_barrier, "barrier"},
7876         {Opt_nobarrier, "nobarrier"},
7877         {Opt_err, NULL}
7878 @@ -382,6 +389,19 @@ xfs_parseargs(
7879                 } else if (!strcmp(this_char, "irixsgid")) {
7880                         cmn_err(CE_WARN,
7881         "XFS: irixsgid is now a sysctl(2) variable, option is deprecated.");
7882 +#ifndef CONFIG_TAGGING_NONE
7883 +               } else if (!strcmp(this_char, MNTOPT_TAGGED)) {
7884 +                       mp->m_flags |= XFS_MOUNT_TAGGED;
7885 +               } else if (!strcmp(this_char, MNTOPT_NOTAGTAG)) {
7886 +                       mp->m_flags &= ~XFS_MOUNT_TAGGED;
7887 +               } else if (!strcmp(this_char, MNTOPT_TAGXID)) {
7888 +                       mp->m_flags |= XFS_MOUNT_TAGGED;
7889 +#endif
7890 +#ifdef CONFIG_PROPAGATE
7891 +               } else if (!strcmp(this_char, MNTOPT_TAGGED)) {
7892 +                       /* use value */
7893 +                       mp->m_flags |= XFS_MOUNT_TAGGED;
7894 +#endif
7895                 } else {
7896                         cmn_err(CE_WARN,
7897                                 "XFS: unknown mount option [%s].", this_char);
7898 @@ -1270,6 +1290,16 @@ xfs_fs_remount(
7899                 case Opt_nobarrier:
7900                         mp->m_flags &= ~XFS_MOUNT_BARRIER;
7901                         break;
7902 +               case Opt_tag:
7903 +                       if (!(sb->s_flags & MS_TAGGED)) {
7904 +                               printk(KERN_INFO
7905 +                                       "XFS: %s: tagging not permitted on remount.\n",
7906 +                                       sb->s_id);
7907 +                               return -EINVAL;
7908 +                       }
7909 +                       break;
7910 +               case Opt_notag:
7911 +                       break;
7912                 default:
7913                         /*
7914                          * Logically we would return an error here to prevent
7915 @@ -1477,6 +1507,9 @@ xfs_fs_fill_super(
7916  
7917         XFS_SEND_MOUNT(mp, DM_RIGHT_NULL, mtpt, mp->m_fsname);
7918  
7919 +       if (mp->m_flags & XFS_MOUNT_TAGGED)
7920 +               sb->s_flags |= MS_TAGGED;
7921 +
7922         sb->s_magic = XFS_SB_MAGIC;
7923         sb->s_blocksize = mp->m_sb.sb_blocksize;
7924         sb->s_blocksize_bits = ffs(sb->s_blocksize) - 1;
7925 diff -NurpP --minimal linux-2.6.32.6/fs/xfs/xfs_dinode.h linux-2.6.32.6-vs2.3.0.36.28/fs/xfs/xfs_dinode.h
7926 --- linux-2.6.32.6/fs/xfs/xfs_dinode.h  2009-06-11 17:13:09.000000000 +0200
7927 +++ linux-2.6.32.6-vs2.3.0.36.28/fs/xfs/xfs_dinode.h    2009-12-03 20:04:56.000000000 +0100
7928 @@ -50,7 +50,9 @@ typedef struct xfs_dinode {
7929         __be32          di_gid;         /* owner's group id */
7930         __be32          di_nlink;       /* number of links to file */
7931         __be16          di_projid;      /* owner's project id */
7932 -       __u8            di_pad[8];      /* unused, zeroed space */
7933 +       __be16          di_tag;         /* context tagging */
7934 +       __be16          di_vflags;      /* vserver specific flags */
7935 +       __u8            di_pad[4];      /* unused, zeroed space */
7936         __be16          di_flushiter;   /* incremented on flush */
7937         xfs_timestamp_t di_atime;       /* time last accessed */
7938         xfs_timestamp_t di_mtime;       /* time last modified */
7939 @@ -183,6 +185,8 @@ static inline void xfs_dinode_put_rdev(s
7940  #define XFS_DIFLAG_EXTSZINHERIT_BIT 12 /* inherit inode extent size */
7941  #define XFS_DIFLAG_NODEFRAG_BIT     13 /* do not reorganize/defragment */
7942  #define XFS_DIFLAG_FILESTREAM_BIT   14  /* use filestream allocator */
7943 +#define XFS_DIFLAG_IXUNLINK_BIT     15 /* Immutable inver on unlink */
7944 +
7945  #define XFS_DIFLAG_REALTIME      (1 << XFS_DIFLAG_REALTIME_BIT)
7946  #define XFS_DIFLAG_PREALLOC      (1 << XFS_DIFLAG_PREALLOC_BIT)
7947  #define XFS_DIFLAG_NEWRTBM       (1 << XFS_DIFLAG_NEWRTBM_BIT)
7948 @@ -198,6 +202,7 @@ static inline void xfs_dinode_put_rdev(s
7949  #define XFS_DIFLAG_EXTSZINHERIT  (1 << XFS_DIFLAG_EXTSZINHERIT_BIT)
7950  #define XFS_DIFLAG_NODEFRAG      (1 << XFS_DIFLAG_NODEFRAG_BIT)
7951  #define XFS_DIFLAG_FILESTREAM    (1 << XFS_DIFLAG_FILESTREAM_BIT)
7952 +#define XFS_DIFLAG_IXUNLINK      (1 << XFS_DIFLAG_IXUNLINK_BIT)
7953  
7954  #ifdef CONFIG_XFS_RT
7955  #define XFS_IS_REALTIME_INODE(ip) ((ip)->i_d.di_flags & XFS_DIFLAG_REALTIME)
7956 @@ -210,6 +215,10 @@ static inline void xfs_dinode_put_rdev(s
7957          XFS_DIFLAG_IMMUTABLE | XFS_DIFLAG_APPEND | XFS_DIFLAG_SYNC | \
7958          XFS_DIFLAG_NOATIME | XFS_DIFLAG_NODUMP | XFS_DIFLAG_RTINHERIT | \
7959          XFS_DIFLAG_PROJINHERIT | XFS_DIFLAG_NOSYMLINKS | XFS_DIFLAG_EXTSIZE | \
7960 -        XFS_DIFLAG_EXTSZINHERIT | XFS_DIFLAG_NODEFRAG | XFS_DIFLAG_FILESTREAM)
7961 +        XFS_DIFLAG_EXTSZINHERIT | XFS_DIFLAG_NODEFRAG | XFS_DIFLAG_FILESTREAM | \
7962 +        XFS_DIFLAG_IXUNLINK)
7963 +
7964 +#define XFS_DIVFLAG_BARRIER    0x01
7965 +#define XFS_DIVFLAG_COW                0x02
7966  
7967  #endif /* __XFS_DINODE_H__ */
7968 diff -NurpP --minimal linux-2.6.32.6/fs/xfs/xfs_fs.h linux-2.6.32.6-vs2.3.0.36.28/fs/xfs/xfs_fs.h
7969 --- linux-2.6.32.6/fs/xfs/xfs_fs.h      2009-12-03 20:02:53.000000000 +0100
7970 +++ linux-2.6.32.6-vs2.3.0.36.28/fs/xfs/xfs_fs.h        2009-12-03 20:04:56.000000000 +0100
7971 @@ -67,6 +67,9 @@ struct fsxattr {
7972  #define XFS_XFLAG_EXTSZINHERIT 0x00001000      /* inherit inode extent size */
7973  #define XFS_XFLAG_NODEFRAG     0x00002000      /* do not defragment */
7974  #define XFS_XFLAG_FILESTREAM   0x00004000      /* use filestream allocator */
7975 +#define XFS_XFLAG_IXUNLINK     0x00008000      /* immutable invert on unlink */
7976 +#define XFS_XFLAG_BARRIER      0x10000000      /* chroot() barrier */
7977 +#define XFS_XFLAG_COW          0x20000000      /* copy on write mark */
7978  #define XFS_XFLAG_HASATTR      0x80000000      /* no DIFLAG for this   */
7979  
7980  /*
7981 @@ -292,7 +295,8 @@ typedef struct xfs_bstat {
7982         __s32           bs_extents;     /* number of extents            */
7983         __u32           bs_gen;         /* generation count             */
7984         __u16           bs_projid;      /* project id                   */
7985 -       unsigned char   bs_pad[14];     /* pad space, unused            */
7986 +       __u16           bs_tag;         /* context tagging              */
7987 +       unsigned char   bs_pad[12];     /* pad space, unused            */
7988         __u32           bs_dmevmask;    /* DMIG event mask              */
7989         __u16           bs_dmstate;     /* DMIG state info              */
7990         __u16           bs_aextents;    /* attribute number of extents  */
7991 diff -NurpP --minimal linux-2.6.32.6/fs/xfs/xfs_ialloc.c linux-2.6.32.6-vs2.3.0.36.28/fs/xfs/xfs_ialloc.c
7992 --- linux-2.6.32.6/fs/xfs/xfs_ialloc.c  2009-12-03 20:02:53.000000000 +0100
7993 +++ linux-2.6.32.6-vs2.3.0.36.28/fs/xfs/xfs_ialloc.c    2009-12-03 20:04:56.000000000 +0100
7994 @@ -41,7 +41,6 @@
7995  #include "xfs_error.h"
7996  #include "xfs_bmap.h"
7997  
7998 -
7999  /*
8000   * Allocation group level functions.
8001   */
8002 diff -NurpP --minimal linux-2.6.32.6/fs/xfs/xfs_inode.c linux-2.6.32.6-vs2.3.0.36.28/fs/xfs/xfs_inode.c
8003 --- linux-2.6.32.6/fs/xfs/xfs_inode.c   2009-12-03 20:02:54.000000000 +0100
8004 +++ linux-2.6.32.6-vs2.3.0.36.28/fs/xfs/xfs_inode.c     2009-12-03 20:04:56.000000000 +0100
8005 @@ -249,6 +249,7 @@ xfs_inotobp(
8006         return 0;
8007  }
8008  
8009 +#include <linux/vs_tag.h>
8010  
8011  /*
8012   * This routine is called to map an inode to the buffer containing
8013 @@ -654,15 +655,25 @@ xfs_iformat_btree(
8014  STATIC void
8015  xfs_dinode_from_disk(
8016         xfs_icdinode_t          *to,
8017 -       xfs_dinode_t            *from)
8018 +       xfs_dinode_t            *from,
8019 +       int tagged)
8020  {
8021 +       uint32_t uid, gid, tag;
8022 +
8023         to->di_magic = be16_to_cpu(from->di_magic);
8024         to->di_mode = be16_to_cpu(from->di_mode);
8025         to->di_version = from ->di_version;
8026         to->di_format = from->di_format;
8027         to->di_onlink = be16_to_cpu(from->di_onlink);
8028 -       to->di_uid = be32_to_cpu(from->di_uid);
8029 -       to->di_gid = be32_to_cpu(from->di_gid);
8030 +
8031 +       uid = be32_to_cpu(from->di_uid);
8032 +       gid = be32_to_cpu(from->di_gid);
8033 +       tag = be16_to_cpu(from->di_tag);
8034 +
8035 +       to->di_uid = INOTAG_UID(tagged, uid, gid);
8036 +       to->di_gid = INOTAG_GID(tagged, uid, gid);
8037 +       to->di_tag = INOTAG_TAG(tagged, uid, gid, tag);
8038 +
8039         to->di_nlink = be32_to_cpu(from->di_nlink);
8040         to->di_projid = be16_to_cpu(from->di_projid);
8041         memcpy(to->di_pad, from->di_pad, sizeof(to->di_pad));
8042 @@ -683,21 +694,26 @@ xfs_dinode_from_disk(
8043         to->di_dmevmask = be32_to_cpu(from->di_dmevmask);
8044         to->di_dmstate  = be16_to_cpu(from->di_dmstate);
8045         to->di_flags    = be16_to_cpu(from->di_flags);
8046 +       to->di_vflags   = be16_to_cpu(from->di_vflags);
8047         to->di_gen      = be32_to_cpu(from->di_gen);
8048  }
8049  
8050  void
8051  xfs_dinode_to_disk(
8052         xfs_dinode_t            *to,
8053 -       xfs_icdinode_t          *from)
8054 +       xfs_icdinode_t          *from,
8055 +       int tagged)
8056  {
8057         to->di_magic = cpu_to_be16(from->di_magic);
8058         to->di_mode = cpu_to_be16(from->di_mode);
8059         to->di_version = from ->di_version;
8060         to->di_format = from->di_format;
8061         to->di_onlink = cpu_to_be16(from->di_onlink);
8062 -       to->di_uid = cpu_to_be32(from->di_uid);
8063 -       to->di_gid = cpu_to_be32(from->di_gid);
8064 +
8065 +       to->di_uid = cpu_to_be32(TAGINO_UID(tagged, from->di_uid, from->di_tag));
8066 +       to->di_gid = cpu_to_be32(TAGINO_GID(tagged, from->di_gid, from->di_tag));
8067 +       to->di_tag = cpu_to_be16(TAGINO_TAG(tagged, from->di_tag));
8068 +
8069         to->di_nlink = cpu_to_be32(from->di_nlink);
8070         to->di_projid = cpu_to_be16(from->di_projid);
8071         memcpy(to->di_pad, from->di_pad, sizeof(to->di_pad));
8072 @@ -718,12 +734,14 @@ xfs_dinode_to_disk(
8073         to->di_dmevmask = cpu_to_be32(from->di_dmevmask);
8074         to->di_dmstate = cpu_to_be16(from->di_dmstate);
8075         to->di_flags = cpu_to_be16(from->di_flags);
8076 +       to->di_vflags = cpu_to_be16(from->di_vflags);
8077         to->di_gen = cpu_to_be32(from->di_gen);
8078  }
8079  
8080  STATIC uint
8081  _xfs_dic2xflags(
8082 -       __uint16_t              di_flags)
8083 +       __uint16_t              di_flags,
8084 +       __uint16_t              di_vflags)
8085  {
8086         uint                    flags = 0;
8087  
8088 @@ -734,6 +752,8 @@ _xfs_dic2xflags(
8089                         flags |= XFS_XFLAG_PREALLOC;
8090                 if (di_flags & XFS_DIFLAG_IMMUTABLE)
8091                         flags |= XFS_XFLAG_IMMUTABLE;
8092 +               if (di_flags & XFS_DIFLAG_IXUNLINK)
8093 +                       flags |= XFS_XFLAG_IXUNLINK;
8094                 if (di_flags & XFS_DIFLAG_APPEND)
8095                         flags |= XFS_XFLAG_APPEND;
8096                 if (di_flags & XFS_DIFLAG_SYNC)
8097 @@ -758,6 +778,10 @@ _xfs_dic2xflags(
8098                         flags |= XFS_XFLAG_FILESTREAM;
8099         }
8100  
8101 +       if (di_vflags & XFS_DIVFLAG_BARRIER)
8102 +               flags |= FS_BARRIER_FL;
8103 +       if (di_vflags & XFS_DIVFLAG_COW)
8104 +               flags |= FS_COW_FL;
8105         return flags;
8106  }
8107  
8108 @@ -767,7 +791,7 @@ xfs_ip2xflags(
8109  {
8110         xfs_icdinode_t          *dic = &ip->i_d;
8111  
8112 -       return _xfs_dic2xflags(dic->di_flags) |
8113 +       return _xfs_dic2xflags(dic->di_flags, dic->di_vflags) |
8114                                 (XFS_IFORK_Q(ip) ? XFS_XFLAG_HASATTR : 0);
8115  }
8116  
8117 @@ -775,7 +799,8 @@ uint
8118  xfs_dic2xflags(
8119         xfs_dinode_t            *dip)
8120  {
8121 -       return _xfs_dic2xflags(be16_to_cpu(dip->di_flags)) |
8122 +       return _xfs_dic2xflags(be16_to_cpu(dip->di_flags),
8123 +                               be16_to_cpu(dip->di_vflags)) |
8124                                 (XFS_DFORK_Q(dip) ? XFS_XFLAG_HASATTR : 0);
8125  }
8126  
8127 @@ -811,7 +836,6 @@ xfs_iread(
8128         if (error)
8129                 return error;
8130         dip = (xfs_dinode_t *)xfs_buf_offset(bp, ip->i_imap.im_boffset);
8131 -
8132         /*
8133          * If we got something that isn't an inode it means someone
8134          * (nfs or dmi) has a stale handle.
8135 @@ -836,7 +860,8 @@ xfs_iread(
8136          * Otherwise, just get the truly permanent information.
8137          */
8138         if (dip->di_mode) {
8139 -               xfs_dinode_from_disk(&ip->i_d, dip);
8140 +               xfs_dinode_from_disk(&ip->i_d, dip,
8141 +                       mp->m_flags & XFS_MOUNT_TAGGED);
8142                 error = xfs_iformat(ip, dip);
8143                 if (error)  {
8144  #ifdef DEBUG
8145 @@ -1036,6 +1061,7 @@ xfs_ialloc(
8146         ASSERT(ip->i_d.di_nlink == nlink);
8147         ip->i_d.di_uid = current_fsuid();
8148         ip->i_d.di_gid = current_fsgid();
8149 +       ip->i_d.di_tag = current_fstag(cr, &ip->i_vnode);
8150         ip->i_d.di_projid = prid;
8151         memset(&(ip->i_d.di_pad[0]), 0, sizeof(ip->i_d.di_pad));
8152  
8153 @@ -1096,6 +1122,7 @@ xfs_ialloc(
8154         ip->i_d.di_dmevmask = 0;
8155         ip->i_d.di_dmstate = 0;
8156         ip->i_d.di_flags = 0;
8157 +       ip->i_d.di_vflags = 0;
8158         flags = XFS_ILOG_CORE;
8159         switch (mode & S_IFMT) {
8160         case S_IFIFO:
8161 @@ -2172,6 +2199,7 @@ xfs_ifree(
8162         }
8163         ip->i_d.di_mode = 0;            /* mark incore inode as free */
8164         ip->i_d.di_flags = 0;
8165 +       ip->i_d.di_vflags = 0;
8166         ip->i_d.di_dmevmask = 0;
8167         ip->i_d.di_forkoff = 0;         /* mark the attr fork not in use */
8168         ip->i_df.if_ext_max =
8169 @@ -3139,7 +3167,8 @@ xfs_iflush_int(
8170          * because if the inode is dirty at all the core must
8171          * be.
8172          */
8173 -       xfs_dinode_to_disk(dip, &ip->i_d);
8174 +       xfs_dinode_to_disk(dip, &ip->i_d,
8175 +               mp->m_flags & XFS_MOUNT_TAGGED);
8176  
8177         /* Wrap, we never let the log put out DI_MAX_FLUSH */
8178         if (ip->i_d.di_flushiter == DI_MAX_FLUSH)
8179 diff -NurpP --minimal linux-2.6.32.6/fs/xfs/xfs_inode.h linux-2.6.32.6-vs2.3.0.36.28/fs/xfs/xfs_inode.h
8180 --- linux-2.6.32.6/fs/xfs/xfs_inode.h   2009-12-03 20:02:54.000000000 +0100
8181 +++ linux-2.6.32.6-vs2.3.0.36.28/fs/xfs/xfs_inode.h     2009-12-03 20:04:56.000000000 +0100
8182 @@ -135,7 +135,9 @@ typedef struct xfs_icdinode {
8183         __uint32_t      di_gid;         /* owner's group id */
8184         __uint32_t      di_nlink;       /* number of links to file */
8185         __uint16_t      di_projid;      /* owner's project id */
8186 -       __uint8_t       di_pad[8];      /* unused, zeroed space */
8187 +       __uint16_t      di_tag;         /* context tagging */
8188 +       __uint16_t      di_vflags;      /* vserver specific flags */
8189 +       __uint8_t       di_pad[4];      /* unused, zeroed space */
8190         __uint16_t      di_flushiter;   /* incremented on flush */
8191         xfs_ictimestamp_t di_atime;     /* time last accessed */
8192         xfs_ictimestamp_t di_mtime;     /* time last modified */
8193 @@ -569,7 +571,7 @@ int         xfs_itobp(struct xfs_mount *, struc
8194  int            xfs_iread(struct xfs_mount *, struct xfs_trans *,
8195                           struct xfs_inode *, xfs_daddr_t, uint);
8196  void           xfs_dinode_to_disk(struct xfs_dinode *,
8197 -                                  struct xfs_icdinode *);
8198 +                                  struct xfs_icdinode *, int);
8199  void           xfs_idestroy_fork(struct xfs_inode *, int);
8200  void           xfs_idata_realloc(struct xfs_inode *, int, int);
8201  void           xfs_iroot_realloc(struct xfs_inode *, int, int);
8202 diff -NurpP --minimal linux-2.6.32.6/fs/xfs/xfs_itable.c linux-2.6.32.6-vs2.3.0.36.28/fs/xfs/xfs_itable.c
8203 --- linux-2.6.32.6/fs/xfs/xfs_itable.c  2009-12-03 20:02:54.000000000 +0100
8204 +++ linux-2.6.32.6-vs2.3.0.36.28/fs/xfs/xfs_itable.c    2009-12-03 20:04:56.000000000 +0100
8205 @@ -84,6 +84,7 @@ xfs_bulkstat_one_iget(
8206         buf->bs_mode = dic->di_mode;
8207         buf->bs_uid = dic->di_uid;
8208         buf->bs_gid = dic->di_gid;
8209 +       buf->bs_tag = dic->di_tag;
8210         buf->bs_size = dic->di_size;
8211  
8212         /*
8213 diff -NurpP --minimal linux-2.6.32.6/fs/xfs/xfs_log_recover.c linux-2.6.32.6-vs2.3.0.36.28/fs/xfs/xfs_log_recover.c
8214 --- linux-2.6.32.6/fs/xfs/xfs_log_recover.c     2009-12-03 20:02:54.000000000 +0100
8215 +++ linux-2.6.32.6-vs2.3.0.36.28/fs/xfs/xfs_log_recover.c       2009-12-03 20:04:56.000000000 +0100
8216 @@ -2467,7 +2467,8 @@ xlog_recover_do_inode_trans(
8217         }
8218  
8219         /* The core is in in-core format */
8220 -       xfs_dinode_to_disk(dip, (xfs_icdinode_t *)item->ri_buf[1].i_addr);
8221 +       xfs_dinode_to_disk(dip, (xfs_icdinode_t *)item->ri_buf[1].i_addr,
8222 +               mp->m_flags & XFS_MOUNT_TAGGED);
8223  
8224         /* the rest is in on-disk format */
8225         if (item->ri_buf[1].i_len > sizeof(struct xfs_icdinode)) {
8226 diff -NurpP --minimal linux-2.6.32.6/fs/xfs/xfs_mount.h linux-2.6.32.6-vs2.3.0.36.28/fs/xfs/xfs_mount.h
8227 --- linux-2.6.32.6/fs/xfs/xfs_mount.h   2009-12-03 20:02:54.000000000 +0100
8228 +++ linux-2.6.32.6-vs2.3.0.36.28/fs/xfs/xfs_mount.h     2009-12-03 20:04:56.000000000 +0100
8229 @@ -283,6 +283,7 @@ typedef struct xfs_mount {
8230                                                    allocator */
8231  #define XFS_MOUNT_NOATTR2      (1ULL << 25)    /* disable use of attr2 format */
8232  
8233 +#define XFS_MOUNT_TAGGED       (1ULL << 31)    /* context tagging */
8234  
8235  /*
8236   * Default minimum read and write sizes.
8237 diff -NurpP --minimal linux-2.6.32.6/fs/xfs/xfs_vnodeops.c linux-2.6.32.6-vs2.3.0.36.28/fs/xfs/xfs_vnodeops.c
8238 --- linux-2.6.32.6/fs/xfs/xfs_vnodeops.c        2009-12-03 20:02:54.000000000 +0100
8239 +++ linux-2.6.32.6-vs2.3.0.36.28/fs/xfs/xfs_vnodeops.c  2009-12-03 20:04:56.000000000 +0100
8240 @@ -54,6 +54,80 @@
8241  #include "xfs_filestream.h"
8242  #include "xfs_vnodeops.h"
8243  
8244 +
8245 +STATIC void
8246 +xfs_get_inode_flags(
8247 +       xfs_inode_t     *ip)
8248 +{
8249 +       struct inode    *inode = VFS_I(ip);
8250 +       unsigned int    flags = inode->i_flags;
8251 +       unsigned int    vflags = inode->i_vflags;
8252 +
8253 +       if (flags & S_IMMUTABLE)
8254 +               ip->i_d.di_flags |= XFS_DIFLAG_IMMUTABLE;
8255 +       else
8256 +               ip->i_d.di_flags &= ~XFS_DIFLAG_IMMUTABLE;
8257 +       if (flags & S_IXUNLINK)
8258 +               ip->i_d.di_flags |= XFS_DIFLAG_IXUNLINK;
8259 +       else
8260 +               ip->i_d.di_flags &= ~XFS_DIFLAG_IXUNLINK;
8261 +
8262 +       if (vflags & V_BARRIER)
8263 +               ip->i_d.di_vflags |= XFS_DIVFLAG_BARRIER;
8264 +       else
8265 +               ip->i_d.di_vflags &= ~XFS_DIVFLAG_BARRIER;
8266 +       if (vflags & V_COW)
8267 +               ip->i_d.di_vflags |= XFS_DIVFLAG_COW;
8268 +       else
8269 +               ip->i_d.di_vflags &= ~XFS_DIVFLAG_COW;
8270 +}
8271 +
8272 +int
8273 +xfs_sync_flags(
8274 +       struct inode            *inode,
8275 +       int                     flags,
8276 +       int                     vflags)
8277 +{
8278 +       struct xfs_inode        *ip = XFS_I(inode);
8279 +       struct xfs_mount        *mp = ip->i_mount;
8280 +       struct xfs_trans        *tp;
8281 +       unsigned int            lock_flags = 0;
8282 +       int                     code;
8283 +
8284 +       tp = xfs_trans_alloc(mp, XFS_TRANS_SETATTR_NOT_SIZE);
8285 +       code = xfs_trans_reserve(tp, 0, XFS_ICHANGE_LOG_RES(mp), 0, 0, 0);
8286 +       if (code)
8287 +               goto error_out;
8288 +
8289 +       lock_flags = XFS_ILOCK_EXCL;
8290 +       xfs_ilock(ip, lock_flags);
8291 +
8292 +       xfs_trans_ijoin(tp, ip, lock_flags);
8293 +       xfs_trans_ihold(tp, ip);
8294 +
8295 +       inode->i_flags = flags;
8296 +       inode->i_vflags = vflags;
8297 +       xfs_get_inode_flags(ip);
8298 +
8299 +       xfs_trans_log_inode(tp, ip, XFS_ILOG_CORE);
8300 +       xfs_ichgtime(ip, XFS_ICHGTIME_CHG);
8301 +
8302 +       XFS_STATS_INC(xs_ig_attrchg);
8303 +
8304 +       if (mp->m_flags & XFS_MOUNT_WSYNC)
8305 +               xfs_trans_set_sync(tp);
8306 +       code = xfs_trans_commit(tp, 0);
8307 +       xfs_iunlock(ip, lock_flags);
8308 +       return code;
8309 +
8310 +error_out:
8311 +       xfs_trans_cancel(tp, 0);
8312 +       if (lock_flags)
8313 +               xfs_iunlock(ip, lock_flags);
8314 +       return code;
8315 +}
8316 +
8317 +
8318  int
8319  xfs_setattr(
8320         struct xfs_inode        *ip,
8321 @@ -69,6 +143,7 @@ xfs_setattr(
8322         uint                    commit_flags=0;
8323         uid_t                   uid=0, iuid=0;
8324         gid_t                   gid=0, igid=0;
8325 +       tag_t                   tag=0, itag=0;
8326         int                     timeflags = 0;
8327         struct xfs_dquot        *udqp, *gdqp, *olddquot1, *olddquot2;
8328         int                     need_iolock = 1;
8329 @@ -165,7 +240,7 @@ xfs_setattr(
8330         /*
8331          * Change file ownership.  Must be the owner or privileged.
8332          */
8333 -       if (mask & (ATTR_UID|ATTR_GID)) {
8334 +       if (mask & (ATTR_UID|ATTR_GID|ATTR_TAG)) {
8335                 /*
8336                  * These IDs could have changed since we last looked at them.
8337                  * But, we're assured that if the ownership did change
8338 @@ -174,8 +249,10 @@ xfs_setattr(
8339                  */
8340                 iuid = ip->i_d.di_uid;
8341                 igid = ip->i_d.di_gid;
8342 +               itag = ip->i_d.di_tag;
8343                 gid = (mask & ATTR_GID) ? iattr->ia_gid : igid;
8344                 uid = (mask & ATTR_UID) ? iattr->ia_uid : iuid;
8345 +               tag = (mask & ATTR_TAG) ? iattr->ia_tag : itag;
8346  
8347                 /*
8348                  * Do a quota reservation only if uid/gid is actually
8349 @@ -183,7 +260,8 @@ xfs_setattr(
8350                  */
8351                 if (XFS_IS_QUOTA_RUNNING(mp) &&
8352                     ((XFS_IS_UQUOTA_ON(mp) && iuid != uid) ||
8353 -                    (XFS_IS_GQUOTA_ON(mp) && igid != gid))) {
8354 +                    (XFS_IS_GQUOTA_ON(mp) && igid != gid) ||
8355 +                    (XFS_IS_GQUOTA_ON(mp) && itag != tag))) {
8356                         ASSERT(tp);
8357                         code = xfs_qm_vop_chown_reserve(tp, ip, udqp, gdqp,
8358                                                 capable(CAP_FOWNER) ?
8359 @@ -336,7 +414,7 @@ xfs_setattr(
8360         /*
8361          * Change file ownership.  Must be the owner or privileged.
8362          */
8363 -       if (mask & (ATTR_UID|ATTR_GID)) {
8364 +       if (mask & (ATTR_UID|ATTR_GID|ATTR_TAG)) {
8365                 /*
8366                  * CAP_FSETID overrides the following restrictions:
8367                  *
8368 @@ -352,6 +430,10 @@ xfs_setattr(
8369                  * Change the ownerships and register quota modifications
8370                  * in the transaction.
8371                  */
8372 +               if (itag != tag) {
8373 +                       ip->i_d.di_tag = tag;
8374 +                       inode->i_tag = tag;
8375 +               }
8376                 if (iuid != uid) {
8377                         if (XFS_IS_QUOTA_RUNNING(mp) && XFS_IS_UQUOTA_ON(mp)) {
8378                                 ASSERT(mask & ATTR_UID);
8379 diff -NurpP --minimal linux-2.6.32.6/fs/xfs/xfs_vnodeops.h linux-2.6.32.6-vs2.3.0.36.28/fs/xfs/xfs_vnodeops.h
8380 --- linux-2.6.32.6/fs/xfs/xfs_vnodeops.h        2009-09-10 15:26:24.000000000 +0200
8381 +++ linux-2.6.32.6-vs2.3.0.36.28/fs/xfs/xfs_vnodeops.h  2009-12-03 20:04:56.000000000 +0100
8382 @@ -14,6 +14,7 @@ struct xfs_inode;
8383  struct xfs_iomap;
8384  
8385  
8386 +int xfs_sync_xflags(struct xfs_inode *ip);
8387  int xfs_setattr(struct xfs_inode *ip, struct iattr *vap, int flags);
8388  #define        XFS_ATTR_DMI            0x01    /* invocation from a DMI function */
8389  #define        XFS_ATTR_NONBLOCK       0x02    /* return EAGAIN if operation would block */
8390 diff -NurpP --minimal linux-2.6.32.6/include/asm-generic/tlb.h linux-2.6.32.6-vs2.3.0.36.28/include/asm-generic/tlb.h
8391 --- linux-2.6.32.6/include/asm-generic/tlb.h    2009-09-10 15:26:24.000000000 +0200
8392 +++ linux-2.6.32.6-vs2.3.0.36.28/include/asm-generic/tlb.h      2009-12-03 20:04:56.000000000 +0100
8393 @@ -14,6 +14,7 @@
8394  #define _ASM_GENERIC__TLB_H
8395  
8396  #include <linux/swap.h>
8397 +#include <linux/vs_memory.h>
8398  #include <asm/pgalloc.h>
8399  #include <asm/tlbflush.h>
8400  
8401 diff -NurpP --minimal linux-2.6.32.6/include/linux/capability.h linux-2.6.32.6-vs2.3.0.36.28/include/linux/capability.h
8402 --- linux-2.6.32.6/include/linux/capability.h   2009-12-03 20:02:54.000000000 +0100
8403 +++ linux-2.6.32.6-vs2.3.0.36.28/include/linux/capability.h     2009-12-03 20:04:56.000000000 +0100
8404 @@ -285,6 +285,7 @@ struct cpu_vfs_cap_data {
8405     arbitrary SCSI commands */
8406  /* Allow setting encryption key on loopback filesystem */
8407  /* Allow setting zone reclaim policy */
8408 +/* Allow the selection of a security context */
8409  
8410  #define CAP_SYS_ADMIN        21
8411  
8412 @@ -357,7 +358,13 @@ struct cpu_vfs_cap_data {
8413  
8414  #define CAP_MAC_ADMIN        33
8415  
8416 -#define CAP_LAST_CAP         CAP_MAC_ADMIN
8417 +/* Allow context manipulations */
8418 +/* Allow changing context info on files */
8419 +
8420 +#define CAP_CONTEXT         34
8421 +
8422 +
8423 +#define CAP_LAST_CAP         CAP_CONTEXT
8424  
8425  #define cap_valid(x) ((x) >= 0 && (x) <= CAP_LAST_CAP)
8426  
8427 diff -NurpP --minimal linux-2.6.32.6/include/linux/devpts_fs.h linux-2.6.32.6-vs2.3.0.36.28/include/linux/devpts_fs.h
8428 --- linux-2.6.32.6/include/linux/devpts_fs.h    2008-12-25 00:26:37.000000000 +0100
8429 +++ linux-2.6.32.6-vs2.3.0.36.28/include/linux/devpts_fs.h      2009-12-03 20:04:56.000000000 +0100
8430 @@ -45,5 +45,4 @@ static inline void devpts_pty_kill(struc
8431  
8432  #endif
8433  
8434 -
8435  #endif /* _LINUX_DEVPTS_FS_H */
8436 diff -NurpP --minimal linux-2.6.32.6/include/linux/ext2_fs.h linux-2.6.32.6-vs2.3.0.36.28/include/linux/ext2_fs.h
8437 --- linux-2.6.32.6/include/linux/ext2_fs.h      2009-03-24 14:22:41.000000000 +0100
8438 +++ linux-2.6.32.6-vs2.3.0.36.28/include/linux/ext2_fs.h        2009-12-03 20:04:56.000000000 +0100
8439 @@ -189,8 +189,12 @@ struct ext2_group_desc
8440  #define EXT2_NOTAIL_FL                 FS_NOTAIL_FL    /* file tail should not be merged */
8441  #define EXT2_DIRSYNC_FL                        FS_DIRSYNC_FL   /* dirsync behaviour (directories only) */
8442  #define EXT2_TOPDIR_FL                 FS_TOPDIR_FL    /* Top of directory hierarchies*/
8443 +#define EXT2_IXUNLINK_FL               FS_IXUNLINK_FL  /* Immutable invert on unlink */
8444  #define EXT2_RESERVED_FL               FS_RESERVED_FL  /* reserved for ext2 lib */
8445  
8446 +#define EXT2_BARRIER_FL                        FS_BARRIER_FL   /* Barrier for chroot() */
8447 +#define EXT2_COW_FL                    FS_COW_FL       /* Copy on Write marker */
8448 +
8449  #define EXT2_FL_USER_VISIBLE           FS_FL_USER_VISIBLE      /* User visible flags */
8450  #define EXT2_FL_USER_MODIFIABLE                FS_FL_USER_MODIFIABLE   /* User modifiable flags */
8451  
8452 @@ -274,7 +278,8 @@ struct ext2_inode {
8453                         __u16   i_pad1;
8454                         __le16  l_i_uid_high;   /* these 2 fields    */
8455                         __le16  l_i_gid_high;   /* were reserved2[0] */
8456 -                       __u32   l_i_reserved2;
8457 +                       __le16  l_i_tag;        /* Context Tag */
8458 +                       __u16   l_i_reserved2;
8459                 } linux2;
8460                 struct {
8461                         __u8    h_i_frag;       /* Fragment number */
8462 @@ -303,6 +308,7 @@ struct ext2_inode {
8463  #define i_gid_low      i_gid
8464  #define i_uid_high     osd2.linux2.l_i_uid_high
8465  #define i_gid_high     osd2.linux2.l_i_gid_high
8466 +#define i_raw_tag      osd2.linux2.l_i_tag
8467  #define i_reserved2    osd2.linux2.l_i_reserved2
8468  #endif
8469  
8470 @@ -347,6 +353,7 @@ struct ext2_inode {
8471  #define EXT2_MOUNT_USRQUOTA            0x020000  /* user quota */
8472  #define EXT2_MOUNT_GRPQUOTA            0x040000  /* group quota */
8473  #define EXT2_MOUNT_RESERVATION         0x080000  /* Preallocation */
8474 +#define EXT2_MOUNT_TAGGED              (1<<24)   /* Enable Context Tags */
8475  
8476  
8477  #define clear_opt(o, opt)              o &= ~EXT2_MOUNT_##opt
8478 diff -NurpP --minimal linux-2.6.32.6/include/linux/ext3_fs.h linux-2.6.32.6-vs2.3.0.36.28/include/linux/ext3_fs.h
8479 --- linux-2.6.32.6/include/linux/ext3_fs.h      2009-09-10 15:26:25.000000000 +0200
8480 +++ linux-2.6.32.6-vs2.3.0.36.28/include/linux/ext3_fs.h        2009-12-03 20:04:56.000000000 +0100
8481 @@ -173,10 +173,14 @@ struct ext3_group_desc
8482  #define EXT3_NOTAIL_FL                 0x00008000 /* file tail should not be merged */
8483  #define EXT3_DIRSYNC_FL                        0x00010000 /* dirsync behaviour (directories only) */
8484  #define EXT3_TOPDIR_FL                 0x00020000 /* Top of directory hierarchies*/
8485 +#define EXT3_IXUNLINK_FL               0x08000000 /* Immutable invert on unlink */
8486  #define EXT3_RESERVED_FL               0x80000000 /* reserved for ext3 lib */
8487  
8488 -#define EXT3_FL_USER_VISIBLE           0x0003DFFF /* User visible flags */
8489 -#define EXT3_FL_USER_MODIFIABLE                0x000380FF /* User modifiable flags */
8490 +#define EXT3_BARRIER_FL                        0x04000000 /* Barrier for chroot() */
8491 +#define EXT3_COW_FL                    0x20000000 /* Copy on Write marker */
8492 +
8493 +#define EXT3_FL_USER_VISIBLE           0x0103DFFF /* User visible flags */
8494 +#define EXT3_FL_USER_MODIFIABLE                0x010380FF /* User modifiable flags */
8495  
8496  /* Flags that should be inherited by new inodes from their parent. */
8497  #define EXT3_FL_INHERITED (EXT3_SECRM_FL | EXT3_UNRM_FL | EXT3_COMPR_FL |\
8498 @@ -320,7 +324,8 @@ struct ext3_inode {
8499                         __u16   i_pad1;
8500                         __le16  l_i_uid_high;   /* these 2 fields    */
8501                         __le16  l_i_gid_high;   /* were reserved2[0] */
8502 -                       __u32   l_i_reserved2;
8503 +                       __le16  l_i_tag;        /* Context Tag */
8504 +                       __u16   l_i_reserved2;
8505                 } linux2;
8506                 struct {
8507                         __u8    h_i_frag;       /* Fragment number */
8508 @@ -351,6 +356,7 @@ struct ext3_inode {
8509  #define i_gid_low      i_gid
8510  #define i_uid_high     osd2.linux2.l_i_uid_high
8511  #define i_gid_high     osd2.linux2.l_i_gid_high
8512 +#define i_raw_tag      osd2.linux2.l_i_tag
8513  #define i_reserved2    osd2.linux2.l_i_reserved2
8514  
8515  #elif defined(__GNU__)
8516 @@ -414,6 +420,7 @@ struct ext3_inode {
8517  #define EXT3_MOUNT_GRPQUOTA            0x200000 /* "old" group quota */
8518  #define EXT3_MOUNT_DATA_ERR_ABORT      0x400000 /* Abort on file data write
8519                                                   * error in ordered mode */
8520 +#define EXT3_MOUNT_TAGGED              (1<<24) /* Enable Context Tags */
8521  
8522  /* Compatibility, for having both ext2_fs.h and ext3_fs.h included at once */
8523  #ifndef _LINUX_EXT2_FS_H
8524 @@ -892,6 +899,7 @@ extern void ext3_get_inode_flags(struct 
8525  extern void ext3_set_aops(struct inode *inode);
8526  extern int ext3_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo,
8527                        u64 start, u64 len);
8528 +extern int ext3_sync_flags(struct inode *, int, int);
8529  
8530  /* ioctl.c */
8531  extern long ext3_ioctl(struct file *, unsigned int, unsigned long);
8532 diff -NurpP --minimal linux-2.6.32.6/include/linux/fs.h linux-2.6.32.6-vs2.3.0.36.28/include/linux/fs.h
8533 --- linux-2.6.32.6/include/linux/fs.h   2010-01-26 19:31:27.000000000 +0100
8534 +++ linux-2.6.32.6-vs2.3.0.36.28/include/linux/fs.h     2010-01-13 14:33:47.000000000 +0100
8535 @@ -205,6 +205,9 @@ struct inodes_stat_t {
8536  #define MS_KERNMOUNT   (1<<22) /* this is a kern_mount call */
8537  #define MS_I_VERSION   (1<<23) /* Update inode I_version field */
8538  #define MS_STRICTATIME (1<<24) /* Always perform atime updates */
8539 +#define MS_TAGGED      (1<<25) /* use generic inode tagging */
8540 +#define MS_TAGID       (1<<26) /* use specific tag for this mount */
8541 +#define MS_NOTAGCHECK  (1<<27) /* don't check tags */
8542  #define MS_ACTIVE      (1<<30)
8543  #define MS_NOUSER      (1<<31)
8544  
8545 @@ -231,6 +234,14 @@ struct inodes_stat_t {
8546  #define S_NOCMTIME     128     /* Do not update file c/mtime */
8547  #define S_SWAPFILE     256     /* Do not truncate: swapon got its bmaps */
8548  #define S_PRIVATE      512     /* Inode is fs-internal */
8549 +#define S_IXUNLINK     1024    /* Immutable Invert on unlink */
8550 +
8551 +/* Linux-VServer related Inode flags */
8552 +
8553 +#define V_VALID                1
8554 +#define V_XATTR                2
8555 +#define V_BARRIER      4       /* Barrier for chroot() */
8556 +#define V_COW          8       /* Copy on Write */
8557  
8558  /*
8559   * Note that nosuid etc flags are inode-specific: setting some file-system
8560 @@ -253,12 +264,15 @@ struct inodes_stat_t {
8561  #define IS_DIRSYNC(inode)      (__IS_FLG(inode, MS_SYNCHRONOUS|MS_DIRSYNC) || \
8562                                         ((inode)->i_flags & (S_SYNC|S_DIRSYNC)))
8563  #define IS_MANDLOCK(inode)     __IS_FLG(inode, MS_MANDLOCK)
8564 -#define IS_NOATIME(inode)   __IS_FLG(inode, MS_RDONLY|MS_NOATIME)
8565 -#define IS_I_VERSION(inode)   __IS_FLG(inode, MS_I_VERSION)
8566 +#define IS_NOATIME(inode)      __IS_FLG(inode, MS_RDONLY|MS_NOATIME)
8567 +#define IS_I_VERSION(inode)    __IS_FLG(inode, MS_I_VERSION)
8568 +#define IS_TAGGED(inode)       __IS_FLG(inode, MS_TAGGED)
8569  
8570  #define IS_NOQUOTA(inode)      ((inode)->i_flags & S_NOQUOTA)
8571  #define IS_APPEND(inode)       ((inode)->i_flags & S_APPEND)
8572  #define IS_IMMUTABLE(inode)    ((inode)->i_flags & S_IMMUTABLE)
8573 +#define IS_IXUNLINK(inode)     ((inode)->i_flags & S_IXUNLINK)
8574 +#define IS_IXORUNLINK(inode)   ((IS_IXUNLINK(inode) ? S_IMMUTABLE : 0) ^ IS_IMMUTABLE(inode))
8575  #define IS_POSIXACL(inode)     __IS_FLG(inode, MS_POSIXACL)
8576  
8577  #define IS_DEADDIR(inode)      ((inode)->i_flags & S_DEAD)
8578 @@ -266,6 +280,16 @@ struct inodes_stat_t {
8579  #define IS_SWAPFILE(inode)     ((inode)->i_flags & S_SWAPFILE)
8580  #define IS_PRIVATE(inode)      ((inode)->i_flags & S_PRIVATE)
8581  
8582 +#define IS_BARRIER(inode)      (S_ISDIR((inode)->i_mode) && ((inode)->i_vflags & V_BARRIER))
8583 +
8584 +#ifdef CONFIG_VSERVER_COWBL
8585 +#  define IS_COW(inode)                (IS_IXUNLINK(inode) && IS_IMMUTABLE(inode))
8586 +#  define IS_COW_LINK(inode)   (S_ISREG((inode)->i_mode) && ((inode)->i_nlink > 1))
8587 +#else
8588 +#  define IS_COW(inode)                (0)
8589 +#  define IS_COW_LINK(inode)   (0)
8590 +#endif
8591 +
8592  /* the read-only stuff doesn't really belong here, but any other place is
8593     probably as bad and I don't want to create yet another include file. */
8594  
8595 @@ -347,11 +371,14 @@ struct inodes_stat_t {
8596  #define FS_TOPDIR_FL                   0x00020000 /* Top of directory hierarchies*/
8597  #define FS_EXTENT_FL                   0x00080000 /* Extents */
8598  #define FS_DIRECTIO_FL                 0x00100000 /* Use direct i/o */
8599 +#define FS_IXUNLINK_FL                 0x08000000 /* Immutable invert on unlink */
8600  #define FS_RESERVED_FL                 0x80000000 /* reserved for ext2 lib */
8601  
8602 -#define FS_FL_USER_VISIBLE             0x0003DFFF /* User visible flags */
8603 -#define FS_FL_USER_MODIFIABLE          0x000380FF /* User modifiable flags */
8604 +#define FS_BARRIER_FL                  0x04000000 /* Barrier for chroot() */
8605 +#define FS_COW_FL                      0x20000000 /* Copy on Write marker */
8606  
8607 +#define FS_FL_USER_VISIBLE             0x0103DFFF /* User visible flags */
8608 +#define FS_FL_USER_MODIFIABLE          0x010380FF /* User modifiable flags */
8609  
8610  #define SYNC_FILE_RANGE_WAIT_BEFORE    1
8611  #define SYNC_FILE_RANGE_WRITE          2
8612 @@ -433,6 +460,7 @@ typedef void (dio_iodone_t)(struct kiocb
8613  #define ATTR_KILL_PRIV (1 << 14)
8614  #define ATTR_OPEN      (1 << 15) /* Truncating from open(O_TRUNC) */
8615  #define ATTR_TIMES_SET (1 << 16)
8616 +#define ATTR_TAG       (1 << 17)
8617  
8618  /*
8619   * This is the Inode Attributes structure, used for notify_change().  It
8620 @@ -448,6 +476,7 @@ struct iattr {
8621         umode_t         ia_mode;
8622         uid_t           ia_uid;
8623         gid_t           ia_gid;
8624 +       tag_t           ia_tag;
8625         loff_t          ia_size;
8626         struct timespec ia_atime;
8627         struct timespec ia_mtime;
8628 @@ -461,6 +490,9 @@ struct iattr {
8629         struct file     *ia_file;
8630  };
8631  
8632 +#define ATTR_FLAG_BARRIER      512     /* Barrier for chroot() */
8633 +#define ATTR_FLAG_IXUNLINK     1024    /* Immutable invert on unlink */
8634 +
8635  /*
8636   * Includes for diskquotas.
8637   */
8638 @@ -726,7 +758,9 @@ struct inode {
8639         unsigned int            i_nlink;
8640         uid_t                   i_uid;
8641         gid_t                   i_gid;
8642 +       tag_t                   i_tag;
8643         dev_t                   i_rdev;
8644 +       dev_t                   i_mdev;
8645         u64                     i_version;
8646         loff_t                  i_size;
8647  #ifdef __NEED_I_SIZE_ORDERED
8648 @@ -773,7 +807,8 @@ struct inode {
8649         unsigned long           i_state;
8650         unsigned long           dirtied_when;   /* jiffies of first dirtying */
8651  
8652 -       unsigned int            i_flags;
8653 +       unsigned short          i_flags;
8654 +       unsigned short          i_vflags;
8655  
8656         atomic_t                i_writecount;
8657  #ifdef CONFIG_SECURITY
8658 @@ -861,12 +896,12 @@ static inline void i_size_write(struct i
8659  
8660  static inline unsigned iminor(const struct inode *inode)
8661  {
8662 -       return MINOR(inode->i_rdev);
8663 +       return MINOR(inode->i_mdev);
8664  }
8665  
8666  static inline unsigned imajor(const struct inode *inode)
8667  {
8668 -       return MAJOR(inode->i_rdev);
8669 +       return MAJOR(inode->i_mdev);
8670  }
8671  
8672  extern struct block_device *I_BDEV(struct inode *inode);
8673 @@ -925,6 +960,7 @@ struct file {
8674         loff_t                  f_pos;
8675         struct fown_struct      f_owner;
8676         const struct cred       *f_cred;
8677 +       xid_t                   f_xid;
8678         struct file_ra_state    f_ra;
8679  
8680         u64                     f_version;
8681 @@ -1066,6 +1102,7 @@ struct file_lock {
8682         struct file *fl_file;
8683         loff_t fl_start;
8684         loff_t fl_end;
8685 +       xid_t fl_xid;
8686  
8687         struct fasync_struct *  fl_fasync; /* for lease break notifications */
8688         unsigned long fl_break_time;    /* for nonblocking lease breaks */
8689 @@ -1531,6 +1568,7 @@ struct inode_operations {
8690         ssize_t (*getxattr) (struct dentry *, const char *, void *, size_t);
8691         ssize_t (*listxattr) (struct dentry *, char *, size_t);
8692         int (*removexattr) (struct dentry *, const char *);
8693 +       int (*sync_flags) (struct inode *, int, int);
8694         void (*truncate_range)(struct inode *, loff_t, loff_t);
8695         long (*fallocate)(struct inode *inode, int mode, loff_t offset,
8696                           loff_t len);
8697 @@ -1551,6 +1589,7 @@ extern ssize_t vfs_readv(struct file *, 
8698                 unsigned long, loff_t *);
8699  extern ssize_t vfs_writev(struct file *, const struct iovec __user *,
8700                 unsigned long, loff_t *);
8701 +ssize_t vfs_sendfile(struct file *, struct file *, loff_t *, size_t, loff_t);
8702  
8703  struct super_operations {
8704         struct inode *(*alloc_inode)(struct super_block *sb);
8705 @@ -2348,6 +2387,7 @@ extern int dcache_dir_open(struct inode 
8706  extern int dcache_dir_close(struct inode *, struct file *);
8707  extern loff_t dcache_dir_lseek(struct file *, loff_t, int);
8708  extern int dcache_readdir(struct file *, void *, filldir_t);
8709 +extern int dcache_readdir_filter(struct file *, void *, filldir_t, int (*)(struct dentry *));
8710  extern int simple_getattr(struct vfsmount *, struct dentry *, struct kstat *);
8711  extern int simple_statfs(struct dentry *, struct kstatfs *);
8712  extern int simple_link(struct dentry *, struct inode *, struct dentry *);
8713 diff -NurpP --minimal linux-2.6.32.6/include/linux/gfs2_ondisk.h linux-2.6.32.6-vs2.3.0.36.28/include/linux/gfs2_ondisk.h
8714 --- linux-2.6.32.6/include/linux/gfs2_ondisk.h  2009-12-03 20:02:55.000000000 +0100
8715 +++ linux-2.6.32.6-vs2.3.0.36.28/include/linux/gfs2_ondisk.h    2009-12-03 20:04:56.000000000 +0100
8716 @@ -235,6 +235,9 @@ enum {
8717         gfs2fl_NoAtime          = 7,
8718         gfs2fl_Sync             = 8,
8719         gfs2fl_System           = 9,
8720 +       gfs2fl_IXUnlink         = 16,
8721 +       gfs2fl_Barrier          = 17,
8722 +       gfs2fl_Cow              = 18,
8723         gfs2fl_TruncInProg      = 29,
8724         gfs2fl_InheritDirectio  = 30,
8725         gfs2fl_InheritJdata     = 31,
8726 @@ -251,6 +254,9 @@ enum {
8727  #define GFS2_DIF_NOATIME               0x00000080
8728  #define GFS2_DIF_SYNC                  0x00000100
8729  #define GFS2_DIF_SYSTEM                        0x00000200 /* New in gfs2 */
8730 +#define GFS2_DIF_IXUNLINK              0x00010000
8731 +#define GFS2_DIF_BARRIER               0x00020000
8732 +#define GFS2_DIF_COW                   0x00040000
8733  #define GFS2_DIF_TRUNC_IN_PROG         0x20000000 /* New in gfs2 */
8734  #define GFS2_DIF_INHERIT_DIRECTIO      0x40000000
8735  #define GFS2_DIF_INHERIT_JDATA         0x80000000
8736 diff -NurpP --minimal linux-2.6.32.6/include/linux/if_tun.h linux-2.6.32.6-vs2.3.0.36.28/include/linux/if_tun.h
8737 --- linux-2.6.32.6/include/linux/if_tun.h       2009-12-03 20:02:55.000000000 +0100
8738 +++ linux-2.6.32.6-vs2.3.0.36.28/include/linux/if_tun.h 2009-12-03 20:04:56.000000000 +0100
8739 @@ -48,6 +48,7 @@
8740  #define TUNGETIFF      _IOR('T', 210, unsigned int)
8741  #define TUNGETSNDBUF   _IOR('T', 211, int)
8742  #define TUNSETSNDBUF   _IOW('T', 212, int)
8743 +#define TUNSETNID     _IOW('T', 215, int)
8744  
8745  /* TUNSETIFF ifr flags */
8746  #define IFF_TUN                0x0001
8747 diff -NurpP --minimal linux-2.6.32.6/include/linux/init_task.h linux-2.6.32.6-vs2.3.0.36.28/include/linux/init_task.h
8748 --- linux-2.6.32.6/include/linux/init_task.h    2009-12-03 20:02:55.000000000 +0100
8749 +++ linux-2.6.32.6-vs2.3.0.36.28/include/linux/init_task.h      2009-12-03 20:04:56.000000000 +0100
8750 @@ -184,6 +184,10 @@ extern struct cred init_cred;
8751         INIT_FTRACE_GRAPH                                               \
8752         INIT_TRACE_RECURSION                                            \
8753         INIT_TASK_RCU_PREEMPT(tsk)                                      \
8754 +       .xid            = 0,                                            \
8755 +       .vx_info        = NULL,                                         \
8756 +       .nid            = 0,                                            \
8757 +       .nx_info        = NULL,                                         \
8758  }
8759  
8760  
8761 diff -NurpP --minimal linux-2.6.32.6/include/linux/ipc.h linux-2.6.32.6-vs2.3.0.36.28/include/linux/ipc.h
8762 --- linux-2.6.32.6/include/linux/ipc.h  2009-12-03 20:02:55.000000000 +0100
8763 +++ linux-2.6.32.6-vs2.3.0.36.28/include/linux/ipc.h    2009-12-03 20:04:56.000000000 +0100
8764 @@ -91,6 +91,7 @@ struct kern_ipc_perm
8765         key_t           key;
8766         uid_t           uid;
8767         gid_t           gid;
8768 +       xid_t           xid;
8769         uid_t           cuid;
8770         gid_t           cgid;
8771         mode_t          mode; 
8772 diff -NurpP --minimal linux-2.6.32.6/include/linux/Kbuild linux-2.6.32.6-vs2.3.0.36.28/include/linux/Kbuild
8773 --- linux-2.6.32.6/include/linux/Kbuild 2009-12-03 20:02:54.000000000 +0100
8774 +++ linux-2.6.32.6-vs2.3.0.36.28/include/linux/Kbuild   2009-12-03 20:04:56.000000000 +0100
8775 @@ -382,5 +382,8 @@ unifdef-y += xattr.h
8776  unifdef-y += xfrm.h
8777  
8778  objhdr-y += version.h
8779 +
8780 +header-y += vserver/
8781  header-y += wimax.h
8782  header-y += wimax/
8783 +
8784 diff -NurpP --minimal linux-2.6.32.6/include/linux/loop.h linux-2.6.32.6-vs2.3.0.36.28/include/linux/loop.h
8785 --- linux-2.6.32.6/include/linux/loop.h 2009-09-10 15:26:25.000000000 +0200
8786 +++ linux-2.6.32.6-vs2.3.0.36.28/include/linux/loop.h   2009-12-03 20:04:56.000000000 +0100
8787 @@ -45,6 +45,7 @@ struct loop_device {
8788         struct loop_func_table *lo_encryption;
8789         __u32           lo_init[2];
8790         uid_t           lo_key_owner;   /* Who set the key */
8791 +       xid_t           lo_xid;
8792         int             (*ioctl)(struct loop_device *, int cmd, 
8793                                  unsigned long arg); 
8794  
8795 diff -NurpP --minimal linux-2.6.32.6/include/linux/magic.h linux-2.6.32.6-vs2.3.0.36.28/include/linux/magic.h
8796 --- linux-2.6.32.6/include/linux/magic.h        2009-12-03 20:02:55.000000000 +0100
8797 +++ linux-2.6.32.6-vs2.3.0.36.28/include/linux/magic.h  2009-12-03 20:04:56.000000000 +0100
8798 @@ -3,7 +3,7 @@
8799  
8800  #define ADFS_SUPER_MAGIC       0xadf5
8801  #define AFFS_SUPER_MAGIC       0xadff
8802 -#define AFS_SUPER_MAGIC                0x5346414F
8803 +#define AFS_SUPER_MAGIC                0x5346414F
8804  #define AUTOFS_SUPER_MAGIC     0x0187
8805  #define CODA_SUPER_MAGIC       0x73757245
8806  #define CRAMFS_MAGIC           0x28cd3d45      /* some random number */
8807 @@ -38,6 +38,7 @@
8808  #define NFS_SUPER_MAGIC                0x6969
8809  #define OPENPROM_SUPER_MAGIC   0x9fa1
8810  #define PROC_SUPER_MAGIC       0x9fa0
8811 +#define DEVPTS_SUPER_MAGIC     0x1cd1
8812  #define QNX4_SUPER_MAGIC       0x002f          /* qnx4 fs detection */
8813  
8814  #define REISERFS_SUPER_MAGIC   0x52654973      /* used by gcc */
8815 diff -NurpP --minimal linux-2.6.32.6/include/linux/major.h linux-2.6.32.6-vs2.3.0.36.28/include/linux/major.h
8816 --- linux-2.6.32.6/include/linux/major.h        2009-09-10 15:26:25.000000000 +0200
8817 +++ linux-2.6.32.6-vs2.3.0.36.28/include/linux/major.h  2009-12-03 20:04:56.000000000 +0100
8818 @@ -15,6 +15,7 @@
8819  #define HD_MAJOR               IDE0_MAJOR
8820  #define PTY_SLAVE_MAJOR                3
8821  #define TTY_MAJOR              4
8822 +#define VROOT_MAJOR            4
8823  #define TTYAUX_MAJOR           5
8824  #define LP_MAJOR               6
8825  #define VCS_MAJOR              7
8826 diff -NurpP --minimal linux-2.6.32.6/include/linux/mm_types.h linux-2.6.32.6-vs2.3.0.36.28/include/linux/mm_types.h
8827 --- linux-2.6.32.6/include/linux/mm_types.h     2009-12-03 20:02:55.000000000 +0100
8828 +++ linux-2.6.32.6-vs2.3.0.36.28/include/linux/mm_types.h       2009-12-03 20:04:56.000000000 +0100
8829 @@ -246,6 +246,7 @@ struct mm_struct {
8830  
8831         /* Architecture-specific MM context */
8832         mm_context_t context;
8833 +       struct vx_info *mm_vx_info;
8834  
8835         /* Swap token stuff */
8836         /*
8837 diff -NurpP --minimal linux-2.6.32.6/include/linux/mount.h linux-2.6.32.6-vs2.3.0.36.28/include/linux/mount.h
8838 --- linux-2.6.32.6/include/linux/mount.h        2009-09-10 15:26:25.000000000 +0200
8839 +++ linux-2.6.32.6-vs2.3.0.36.28/include/linux/mount.h  2009-12-03 20:04:56.000000000 +0100
8840 @@ -36,6 +36,9 @@ struct mnt_namespace;
8841  #define MNT_UNBINDABLE 0x2000  /* if the vfsmount is a unbindable mount */
8842  #define MNT_PNODE_MASK 0x3000  /* propagation flag mask */
8843  
8844 +#define MNT_TAGID      0x10000
8845 +#define MNT_NOTAG      0x20000
8846 +
8847  struct vfsmount {
8848         struct list_head mnt_hash;
8849         struct vfsmount *mnt_parent;    /* fs we are mounted on */
8850 @@ -70,6 +73,7 @@ struct vfsmount {
8851  #else
8852         int mnt_writers;
8853  #endif
8854 +       tag_t mnt_tag;                  /* tagging used for vfsmount */
8855  };
8856  
8857  static inline int *get_mnt_writers_ptr(struct vfsmount *mnt)
8858 diff -NurpP --minimal linux-2.6.32.6/include/linux/net.h linux-2.6.32.6-vs2.3.0.36.28/include/linux/net.h
8859 --- linux-2.6.32.6/include/linux/net.h  2009-12-03 20:02:55.000000000 +0100
8860 +++ linux-2.6.32.6-vs2.3.0.36.28/include/linux/net.h    2009-12-03 20:04:56.000000000 +0100
8861 @@ -69,6 +69,7 @@ struct net;
8862  #define SOCK_NOSPACE           2
8863  #define SOCK_PASSCRED          3
8864  #define SOCK_PASSSEC           4
8865 +#define SOCK_USER_SOCKET       5
8866  
8867  #ifndef ARCH_HAS_SOCKET_TYPES
8868  /**
8869 diff -NurpP --minimal linux-2.6.32.6/include/linux/nfs_mount.h linux-2.6.32.6-vs2.3.0.36.28/include/linux/nfs_mount.h
8870 --- linux-2.6.32.6/include/linux/nfs_mount.h    2009-03-24 14:22:43.000000000 +0100
8871 +++ linux-2.6.32.6-vs2.3.0.36.28/include/linux/nfs_mount.h      2009-12-03 20:04:56.000000000 +0100
8872 @@ -63,7 +63,8 @@ struct nfs_mount_data {
8873  #define NFS_MOUNT_SECFLAVOUR   0x2000  /* 5 */
8874  #define NFS_MOUNT_NORDIRPLUS   0x4000  /* 5 */
8875  #define NFS_MOUNT_UNSHARED     0x8000  /* 5 */
8876 -#define NFS_MOUNT_FLAGMASK     0xFFFF
8877 +#define NFS_MOUNT_TAGGED       0x10000 /* context tagging */
8878 +#define NFS_MOUNT_FLAGMASK     0x1FFFF
8879  
8880  /* The following are for internal use only */
8881  #define NFS_MOUNT_LOOKUP_CACHE_NONEG   0x10000
8882 diff -NurpP --minimal linux-2.6.32.6/include/linux/nsproxy.h linux-2.6.32.6-vs2.3.0.36.28/include/linux/nsproxy.h
8883 --- linux-2.6.32.6/include/linux/nsproxy.h      2009-06-11 17:13:17.000000000 +0200
8884 +++ linux-2.6.32.6-vs2.3.0.36.28/include/linux/nsproxy.h        2009-12-03 20:04:56.000000000 +0100
8885 @@ -3,6 +3,7 @@
8886  
8887  #include <linux/spinlock.h>
8888  #include <linux/sched.h>
8889 +#include <linux/vserver/debug.h>
8890  
8891  struct mnt_namespace;
8892  struct uts_namespace;
8893 @@ -63,22 +64,33 @@ static inline struct nsproxy *task_nspro
8894  }
8895  
8896  int copy_namespaces(unsigned long flags, struct task_struct *tsk);
8897 +struct nsproxy *copy_nsproxy(struct nsproxy *orig);
8898  void exit_task_namespaces(struct task_struct *tsk);
8899  void switch_task_namespaces(struct task_struct *tsk, struct nsproxy *new);
8900  void free_nsproxy(struct nsproxy *ns);
8901  int unshare_nsproxy_namespaces(unsigned long, struct nsproxy **,
8902         struct fs_struct *);
8903  
8904 -static inline void put_nsproxy(struct nsproxy *ns)
8905 +#define        get_nsproxy(n)  __get_nsproxy(n, __FILE__, __LINE__)
8906 +
8907 +static inline void __get_nsproxy(struct nsproxy *ns,
8908 +       const char *_file, int _line)
8909  {
8910 -       if (atomic_dec_and_test(&ns->count)) {
8911 -               free_nsproxy(ns);
8912 -       }
8913 +       vxlprintk(VXD_CBIT(space, 0), "get_nsproxy(%p[%u])",
8914 +               ns, atomic_read(&ns->count), _file, _line);
8915 +       atomic_inc(&ns->count);
8916  }
8917  
8918 -static inline void get_nsproxy(struct nsproxy *ns)
8919 +#define        put_nsproxy(n)  __put_nsproxy(n, __FILE__, __LINE__)
8920 +
8921 +static inline void __put_nsproxy(struct nsproxy *ns,
8922 +       const char *_file, int _line)
8923  {
8924 -       atomic_inc(&ns->count);
8925 +       vxlprintk(VXD_CBIT(space, 0), "put_nsproxy(%p[%u])",
8926 +               ns, atomic_read(&ns->count), _file, _line);
8927 +       if (atomic_dec_and_test(&ns->count)) {
8928 +               free_nsproxy(ns);
8929 +       }
8930  }
8931  
8932  #ifdef CONFIG_CGROUP_NS
8933 diff -NurpP --minimal linux-2.6.32.6/include/linux/pid.h linux-2.6.32.6-vs2.3.0.36.28/include/linux/pid.h
8934 --- linux-2.6.32.6/include/linux/pid.h  2009-03-24 14:22:43.000000000 +0100
8935 +++ linux-2.6.32.6-vs2.3.0.36.28/include/linux/pid.h    2009-12-03 20:04:56.000000000 +0100
8936 @@ -8,7 +8,8 @@ enum pid_type
8937         PIDTYPE_PID,
8938         PIDTYPE_PGID,
8939         PIDTYPE_SID,
8940 -       PIDTYPE_MAX
8941 +       PIDTYPE_MAX,
8942 +       PIDTYPE_REALPID
8943  };
8944  
8945  /*
8946 @@ -160,6 +161,7 @@ static inline pid_t pid_nr(struct pid *p
8947  }
8948  
8949  pid_t pid_nr_ns(struct pid *pid, struct pid_namespace *ns);
8950 +pid_t pid_unmapped_nr_ns(struct pid *pid, struct pid_namespace *ns);
8951  pid_t pid_vnr(struct pid *pid);
8952  
8953  #define do_each_pid_task(pid, type, task)                              \
8954 diff -NurpP --minimal linux-2.6.32.6/include/linux/proc_fs.h linux-2.6.32.6-vs2.3.0.36.28/include/linux/proc_fs.h
8955 --- linux-2.6.32.6/include/linux/proc_fs.h      2009-12-03 20:02:56.000000000 +0100
8956 +++ linux-2.6.32.6-vs2.3.0.36.28/include/linux/proc_fs.h        2009-12-03 20:04:56.000000000 +0100
8957 @@ -56,6 +56,7 @@ struct proc_dir_entry {
8958         nlink_t nlink;
8959         uid_t uid;
8960         gid_t gid;
8961 +       int vx_flags;
8962         loff_t size;
8963         const struct inode_operations *proc_iops;
8964         /*
8965 @@ -250,12 +251,18 @@ kclist_add(struct kcore_list *new, void 
8966  extern void kclist_add(struct kcore_list *, void *, size_t, int type);
8967  #endif
8968  
8969 +struct vx_info;
8970 +struct nx_info;
8971 +
8972  union proc_op {
8973         int (*proc_get_link)(struct inode *, struct path *);
8974         int (*proc_read)(struct task_struct *task, char *page);
8975         int (*proc_show)(struct seq_file *m,
8976                 struct pid_namespace *ns, struct pid *pid,
8977                 struct task_struct *task);
8978 +       int (*proc_vs_read)(char *page);
8979 +       int (*proc_vxi_read)(struct vx_info *vxi, char *page);
8980 +       int (*proc_nxi_read)(struct nx_info *nxi, char *page);
8981  };
8982  
8983  struct ctl_table_header;
8984 @@ -263,6 +270,7 @@ struct ctl_table;
8985  
8986  struct proc_inode {
8987         struct pid *pid;
8988 +       int vx_flags;
8989         int fd;
8990         union proc_op op;
8991         struct proc_dir_entry *pde;
8992 diff -NurpP --minimal linux-2.6.32.6/include/linux/quotaops.h linux-2.6.32.6-vs2.3.0.36.28/include/linux/quotaops.h
8993 --- linux-2.6.32.6/include/linux/quotaops.h     2009-12-03 20:02:56.000000000 +0100
8994 +++ linux-2.6.32.6-vs2.3.0.36.28/include/linux/quotaops.h       2009-12-03 20:04:56.000000000 +0100
8995 @@ -8,6 +8,7 @@
8996  #define _LINUX_QUOTAOPS_
8997  
8998  #include <linux/fs.h>
8999 +#include <linux/vs_dlimit.h>
9000  
9001  static inline struct quota_info *sb_dqopt(struct super_block *sb)
9002  {
9003 @@ -154,10 +155,14 @@ static inline void vfs_dq_init(struct in
9004   * a transaction (deadlocks possible otherwise) */
9005  static inline int vfs_dq_prealloc_space_nodirty(struct inode *inode, qsize_t nr)
9006  {
9007 +       if (dl_alloc_space(inode, nr))
9008 +               return 1;
9009         if (sb_any_quota_active(inode->i_sb)) {
9010                 /* Used space is updated in alloc_space() */
9011 -               if (inode->i_sb->dq_op->alloc_space(inode, nr, 1) == NO_QUOTA)
9012 +               if (inode->i_sb->dq_op->alloc_space(inode, nr, 1) == NO_QUOTA) {
9013 +                       dl_free_space(inode, nr);
9014                         return 1;
9015 +               }
9016         }
9017         else
9018                 inode_add_bytes(inode, nr);
9019 @@ -174,10 +179,14 @@ static inline int vfs_dq_prealloc_space(
9020  
9021  static inline int vfs_dq_alloc_space_nodirty(struct inode *inode, qsize_t nr)
9022  {
9023 +       if (dl_alloc_space(inode, nr))
9024 +               return 1;
9025         if (sb_any_quota_active(inode->i_sb)) {
9026                 /* Used space is updated in alloc_space() */
9027 -               if (inode->i_sb->dq_op->alloc_space(inode, nr, 0) == NO_QUOTA)
9028 +               if (inode->i_sb->dq_op->alloc_space(inode, nr, 0) == NO_QUOTA) {
9029 +                       dl_free_space(inode, nr);
9030                         return 1;
9031 +               }
9032         }
9033         else
9034                 inode_add_bytes(inode, nr);
9035 @@ -194,20 +203,28 @@ static inline int vfs_dq_alloc_space(str
9036  
9037  static inline int vfs_dq_reserve_space(struct inode *inode, qsize_t nr)
9038  {
9039 +       if (dl_reserve_space(inode, nr))
9040 +               return 1;
9041         if (sb_any_quota_active(inode->i_sb)) {
9042                 /* Used space is updated in alloc_space() */
9043 -               if (inode->i_sb->dq_op->reserve_space(inode, nr, 0) == NO_QUOTA)
9044 +               if (inode->i_sb->dq_op->reserve_space(inode, nr, 0) == NO_QUOTA) {
9045 +                       dl_release_space(inode, nr);
9046                         return 1;
9047 +               }
9048         }
9049         return 0;
9050  }
9051  
9052  static inline int vfs_dq_alloc_inode(struct inode *inode)
9053  {
9054 +       if (dl_alloc_inode(inode))
9055 +               return 1;
9056         if (sb_any_quota_active(inode->i_sb)) {
9057                 vfs_dq_init(inode);
9058 -               if (inode->i_sb->dq_op->alloc_inode(inode, 1) == NO_QUOTA)
9059 +               if (inode->i_sb->dq_op->alloc_inode(inode, 1) == NO_QUOTA) {
9060 +                       dl_free_inode(inode);
9061                         return 1;
9062 +               }
9063         }
9064         return 0;
9065  }
9066 @@ -217,9 +234,13 @@ static inline int vfs_dq_alloc_inode(str
9067   */
9068  static inline int vfs_dq_claim_space(struct inode *inode, qsize_t nr)
9069  {
9070 +       if (dl_claim_space(inode, nr))
9071 +               return 1;
9072         if (sb_any_quota_active(inode->i_sb)) {
9073 -               if (inode->i_sb->dq_op->claim_space(inode, nr) == NO_QUOTA)
9074 +               if (inode->i_sb->dq_op->claim_space(inode, nr) == NO_QUOTA) {
9075 +                       dl_release_space(inode, nr);
9076                         return 1;
9077 +               }
9078         } else
9079                 inode_add_bytes(inode, nr);
9080  
9081 @@ -235,6 +256,7 @@ void vfs_dq_release_reservation_space(st
9082  {
9083         if (sb_any_quota_active(inode->i_sb))
9084                 inode->i_sb->dq_op->release_rsv(inode, nr);
9085 +       dl_release_space(inode, nr);
9086  }
9087  
9088  static inline void vfs_dq_free_space_nodirty(struct inode *inode, qsize_t nr)
9089 @@ -243,6 +265,7 @@ static inline void vfs_dq_free_space_nod
9090                 inode->i_sb->dq_op->free_space(inode, nr);
9091         else
9092                 inode_sub_bytes(inode, nr);
9093 +       dl_free_space(inode, nr);
9094  }
9095  
9096  static inline void vfs_dq_free_space(struct inode *inode, qsize_t nr)
9097 @@ -255,6 +278,7 @@ static inline void vfs_dq_free_inode(str
9098  {
9099         if (sb_any_quota_active(inode->i_sb))
9100                 inode->i_sb->dq_op->free_inode(inode, 1);
9101 +       dl_free_inode(inode);
9102  }
9103  
9104  /* Cannot be called inside a transaction */
9105 @@ -358,6 +382,8 @@ static inline int vfs_dq_transfer(struct
9106  
9107  static inline int vfs_dq_prealloc_space_nodirty(struct inode *inode, qsize_t nr)
9108  {
9109 +       if (dl_alloc_space(inode, nr))
9110 +               return 1;
9111         inode_add_bytes(inode, nr);
9112         return 0;
9113  }
9114 @@ -371,6 +397,8 @@ static inline int vfs_dq_prealloc_space(
9115  
9116  static inline int vfs_dq_alloc_space_nodirty(struct inode *inode, qsize_t nr)
9117  {
9118 +       if (dl_alloc_space(inode, nr))
9119 +               return 1;
9120         inode_add_bytes(inode, nr);
9121         return 0;
9122  }
9123 @@ -384,22 +412,28 @@ static inline int vfs_dq_alloc_space(str
9124  
9125  static inline int vfs_dq_reserve_space(struct inode *inode, qsize_t nr)
9126  {
9127 +       if (dl_reserve_space(inode, nr))
9128 +               return 1;
9129         return 0;
9130  }
9131  
9132  static inline int vfs_dq_claim_space(struct inode *inode, qsize_t nr)
9133  {
9134 +       if (dl_claim_space(inode, nr))
9135 +               return 1;
9136         return vfs_dq_alloc_space(inode, nr);
9137  }
9138  
9139  static inline
9140  int vfs_dq_release_reservation_space(struct inode *inode, qsize_t nr)
9141  {
9142 +       dl_release_space(inode, nr);
9143         return 0;
9144  }
9145  
9146  static inline void vfs_dq_free_space_nodirty(struct inode *inode, qsize_t nr)
9147  {
9148 +       dl_free_space(inode, nr);
9149         inode_sub_bytes(inode, nr);
9150  }
9151  
9152 diff -NurpP --minimal linux-2.6.32.6/include/linux/reboot.h linux-2.6.32.6-vs2.3.0.36.28/include/linux/reboot.h
9153 --- linux-2.6.32.6/include/linux/reboot.h       2008-12-25 00:26:37.000000000 +0100
9154 +++ linux-2.6.32.6-vs2.3.0.36.28/include/linux/reboot.h 2009-12-03 22:06:59.000000000 +0100
9155 @@ -33,6 +33,7 @@
9156  #define        LINUX_REBOOT_CMD_RESTART2       0xA1B2C3D4
9157  #define        LINUX_REBOOT_CMD_SW_SUSPEND     0xD000FCE2
9158  #define        LINUX_REBOOT_CMD_KEXEC          0x45584543
9159 +#define        LINUX_REBOOT_CMD_OOM            0xDEADBEEF
9160  
9161  
9162  #ifdef __KERNEL__
9163 diff -NurpP --minimal linux-2.6.32.6/include/linux/reiserfs_fs.h linux-2.6.32.6-vs2.3.0.36.28/include/linux/reiserfs_fs.h
9164 --- linux-2.6.32.6/include/linux/reiserfs_fs.h  2009-09-10 15:26:26.000000000 +0200
9165 +++ linux-2.6.32.6-vs2.3.0.36.28/include/linux/reiserfs_fs.h    2009-12-03 20:04:56.000000000 +0100
9166 @@ -899,6 +899,11 @@ struct stat_data_v1 {
9167  #define REISERFS_COMPR_FL     FS_COMPR_FL
9168  #define REISERFS_NOTAIL_FL    FS_NOTAIL_FL
9169  
9170 +/* unfortunately reiserfs sdattr is only 16 bit */
9171 +#define REISERFS_IXUNLINK_FL  (FS_IXUNLINK_FL >> 16)
9172 +#define REISERFS_BARRIER_FL   (FS_BARRIER_FL >> 16)
9173 +#define REISERFS_COW_FL       (FS_COW_FL >> 16)
9174 +
9175  /* persistent flags that file inherits from the parent directory */
9176  #define REISERFS_INHERIT_MASK ( REISERFS_IMMUTABLE_FL |        \
9177                                 REISERFS_SYNC_FL |      \
9178 @@ -908,6 +913,9 @@ struct stat_data_v1 {
9179                                 REISERFS_COMPR_FL |     \
9180                                 REISERFS_NOTAIL_FL )
9181  
9182 +#define REISERFS_FL_USER_VISIBLE       0x80FF
9183 +#define REISERFS_FL_USER_MODIFIABLE    0x80FF
9184 +
9185  /* Stat Data on disk (reiserfs version of UFS disk inode minus the
9186     address blocks) */
9187  struct stat_data {
9188 @@ -1989,6 +1997,7 @@ static inline void reiserfs_update_sd(st
9189  void sd_attrs_to_i_attrs(__u16 sd_attrs, struct inode *inode);
9190  void i_attrs_to_sd_attrs(struct inode *inode, __u16 * sd_attrs);
9191  int reiserfs_setattr(struct dentry *dentry, struct iattr *attr);
9192 +int reiserfs_sync_flags(struct inode *inode, int, int);
9193  
9194  /* namei.c */
9195  void set_de_name_and_namelen(struct reiserfs_dir_entry *de);
9196 diff -NurpP --minimal linux-2.6.32.6/include/linux/reiserfs_fs_sb.h linux-2.6.32.6-vs2.3.0.36.28/include/linux/reiserfs_fs_sb.h
9197 --- linux-2.6.32.6/include/linux/reiserfs_fs_sb.h       2009-09-10 15:26:26.000000000 +0200
9198 +++ linux-2.6.32.6-vs2.3.0.36.28/include/linux/reiserfs_fs_sb.h 2009-12-03 20:04:56.000000000 +0100
9199 @@ -456,6 +456,7 @@ enum reiserfs_mount_options {
9200         REISERFS_EXPOSE_PRIVROOT,
9201         REISERFS_BARRIER_NONE,
9202         REISERFS_BARRIER_FLUSH,
9203 +       REISERFS_TAGGED,
9204  
9205         /* Actions on error */
9206         REISERFS_ERROR_PANIC,
9207 diff -NurpP --minimal linux-2.6.32.6/include/linux/sched.h linux-2.6.32.6-vs2.3.0.36.28/include/linux/sched.h
9208 --- linux-2.6.32.6/include/linux/sched.h        2010-01-26 19:31:27.000000000 +0100
9209 +++ linux-2.6.32.6-vs2.3.0.36.28/include/linux/sched.h  2009-12-14 22:20:55.000000000 +0100
9210 @@ -390,25 +390,28 @@ extern void arch_unmap_area_topdown(stru
9211   * The mm counters are not protected by its page_table_lock,
9212   * so must be incremented atomically.
9213   */
9214 -#define set_mm_counter(mm, member, value) atomic_long_set(&(mm)->_##member, value)
9215 -#define get_mm_counter(mm, member) ((unsigned long)atomic_long_read(&(mm)->_##member))
9216 -#define add_mm_counter(mm, member, value) atomic_long_add(value, &(mm)->_##member)
9217 -#define inc_mm_counter(mm, member) atomic_long_inc(&(mm)->_##member)
9218 -#define dec_mm_counter(mm, member) atomic_long_dec(&(mm)->_##member)
9219 +#define __set_mm_counter(mm, member, value) \
9220 +       atomic_long_set(&(mm)->_##member, value)
9221 +#define get_mm_counter(mm, member) \
9222 +       ((unsigned long)atomic_long_read(&(mm)->_##member))
9223  
9224  #else  /* !USE_SPLIT_PTLOCKS */
9225  /*
9226   * The mm counters are protected by its page_table_lock,
9227   * so can be incremented directly.
9228   */
9229 -#define set_mm_counter(mm, member, value) (mm)->_##member = (value)
9230 +#define __set_mm_counter(mm, member, value) (mm)->_##member = (value)
9231  #define get_mm_counter(mm, member) ((mm)->_##member)
9232 -#define add_mm_counter(mm, member, value) (mm)->_##member += (value)
9233 -#define inc_mm_counter(mm, member) (mm)->_##member++
9234 -#define dec_mm_counter(mm, member) (mm)->_##member--
9235  
9236  #endif /* !USE_SPLIT_PTLOCKS */
9237  
9238 +#define set_mm_counter(mm, member, value) \
9239 +       vx_ ## member ## pages_sub((mm), (get_mm_counter(mm, member) - value))
9240 +#define add_mm_counter(mm, member, value) \
9241 +       vx_ ## member ## pages_add((mm), (value))
9242 +#define inc_mm_counter(mm, member) vx_ ## member ## pages_inc((mm))
9243 +#define dec_mm_counter(mm, member) vx_ ## member ## pages_dec((mm))
9244 +
9245  #define get_mm_rss(mm)                                 \
9246         (get_mm_counter(mm, file_rss) + get_mm_counter(mm, anon_rss))
9247  #define update_hiwater_rss(mm) do {                    \
9248 @@ -1183,6 +1186,12 @@ struct sched_entity {
9249         u64                     nr_wakeups_affine_attempts;
9250         u64                     nr_wakeups_passive;
9251         u64                     nr_wakeups_idle;
9252 +#ifdef CONFIG_CFS_HARD_LIMITS
9253 +       u64                     throttle_start;
9254 +       u64                     throttle_max;
9255 +       u64                     throttle_count;
9256 +       u64                     throttle_sum;
9257 +#endif
9258  #endif
9259  
9260  #ifdef CONFIG_FAIR_GROUP_SCHED
9261 @@ -1393,6 +1402,14 @@ struct task_struct {
9262  #endif
9263         seccomp_t seccomp;
9264  
9265 +/* vserver context data */
9266 +       struct vx_info *vx_info;
9267 +       struct nx_info *nx_info;
9268 +
9269 +       xid_t xid;
9270 +       nid_t nid;
9271 +       tag_t tag;
9272 +
9273  /* Thread group tracking */
9274         u32 parent_exec_id;
9275         u32 self_exec_id;
9276 @@ -1618,6 +1635,11 @@ struct pid_namespace;
9277  pid_t __task_pid_nr_ns(struct task_struct *task, enum pid_type type,
9278                         struct pid_namespace *ns);
9279  
9280 +#include <linux/vserver/base.h>
9281 +#include <linux/vserver/context.h>
9282 +#include <linux/vserver/debug.h>
9283 +#include <linux/vserver/pid.h>
9284 +
9285  static inline pid_t task_pid_nr(struct task_struct *tsk)
9286  {
9287         return tsk->pid;
9288 @@ -1631,7 +1653,8 @@ static inline pid_t task_pid_nr_ns(struc
9289  
9290  static inline pid_t task_pid_vnr(struct task_struct *tsk)
9291  {
9292 -       return __task_pid_nr_ns(tsk, PIDTYPE_PID, NULL);
9293 +       // return __task_pid_nr_ns(tsk, PIDTYPE_PID, NULL);
9294 +       return vx_map_pid(__task_pid_nr_ns(tsk, PIDTYPE_PID, NULL));
9295  }
9296  
9297  
9298 @@ -1644,7 +1667,7 @@ pid_t task_tgid_nr_ns(struct task_struct
9299  
9300  static inline pid_t task_tgid_vnr(struct task_struct *tsk)
9301  {
9302 -       return pid_vnr(task_tgid(tsk));
9303 +       return vx_map_tgid(pid_vnr(task_tgid(tsk)));
9304  }
9305  
9306  
9307 diff -NurpP --minimal linux-2.6.32.6/include/linux/shmem_fs.h linux-2.6.32.6-vs2.3.0.36.28/include/linux/shmem_fs.h
9308 --- linux-2.6.32.6/include/linux/shmem_fs.h     2009-12-03 20:02:56.000000000 +0100
9309 +++ linux-2.6.32.6-vs2.3.0.36.28/include/linux/shmem_fs.h       2009-12-03 20:04:56.000000000 +0100
9310 @@ -8,6 +8,9 @@
9311  
9312  #define SHMEM_NR_DIRECT 16
9313  
9314 +#define TMPFS_SUPER_MAGIC      0x01021994
9315 +
9316 +
9317  struct shmem_inode_info {
9318         spinlock_t              lock;
9319         unsigned long           flags;
9320 diff -NurpP --minimal linux-2.6.32.6/include/linux/stat.h linux-2.6.32.6-vs2.3.0.36.28/include/linux/stat.h
9321 --- linux-2.6.32.6/include/linux/stat.h 2008-12-25 00:26:37.000000000 +0100
9322 +++ linux-2.6.32.6-vs2.3.0.36.28/include/linux/stat.h   2009-12-03 20:04:56.000000000 +0100
9323 @@ -66,6 +66,7 @@ struct kstat {
9324         unsigned int    nlink;
9325         uid_t           uid;
9326         gid_t           gid;
9327 +       tag_t           tag;
9328         dev_t           rdev;
9329         loff_t          size;
9330         struct timespec  atime;
9331 diff -NurpP --minimal linux-2.6.32.6/include/linux/sunrpc/auth.h linux-2.6.32.6-vs2.3.0.36.28/include/linux/sunrpc/auth.h
9332 --- linux-2.6.32.6/include/linux/sunrpc/auth.h  2009-12-03 20:02:56.000000000 +0100
9333 +++ linux-2.6.32.6-vs2.3.0.36.28/include/linux/sunrpc/auth.h    2009-12-03 20:04:56.000000000 +0100
9334 @@ -25,6 +25,7 @@
9335  struct auth_cred {
9336         uid_t   uid;
9337         gid_t   gid;
9338 +       tag_t   tag;
9339         struct group_info *group_info;
9340         unsigned char machine_cred : 1;
9341  };
9342 diff -NurpP --minimal linux-2.6.32.6/include/linux/sunrpc/clnt.h linux-2.6.32.6-vs2.3.0.36.28/include/linux/sunrpc/clnt.h
9343 --- linux-2.6.32.6/include/linux/sunrpc/clnt.h  2009-12-03 20:02:56.000000000 +0100
9344 +++ linux-2.6.32.6-vs2.3.0.36.28/include/linux/sunrpc/clnt.h    2009-12-03 20:04:56.000000000 +0100
9345 @@ -49,7 +49,8 @@ struct rpc_clnt {
9346         unsigned int            cl_softrtry : 1,/* soft timeouts */
9347                                 cl_discrtry : 1,/* disconnect before retry */
9348                                 cl_autobind : 1,/* use getport() */
9349 -                               cl_chatty   : 1;/* be verbose */
9350 +                               cl_chatty   : 1,/* be verbose */
9351 +                               cl_tag      : 1;/* context tagging */
9352  
9353         struct rpc_rtt *        cl_rtt;         /* RTO estimator data */
9354         const struct rpc_timeout *cl_timeout;   /* Timeout strategy */
9355 diff -NurpP --minimal linux-2.6.32.6/include/linux/syscalls.h linux-2.6.32.6-vs2.3.0.36.28/include/linux/syscalls.h
9356 --- linux-2.6.32.6/include/linux/syscalls.h     2010-01-26 19:31:27.000000000 +0100
9357 +++ linux-2.6.32.6-vs2.3.0.36.28/include/linux/syscalls.h       2010-01-20 04:21:33.000000000 +0100
9358 @@ -546,6 +546,8 @@ asmlinkage long sys_symlink(const char _
9359  asmlinkage long sys_unlink(const char __user *pathname);
9360  asmlinkage long sys_rename(const char __user *oldname,
9361                                 const char __user *newname);
9362 +asmlinkage long sys_copyfile(const char __user *from, const char __user *to,
9363 +                               umode_t mode);
9364  asmlinkage long sys_chmod(const char __user *filename, mode_t mode);
9365  asmlinkage long sys_fchmod(unsigned int fd, mode_t mode);
9366  
9367 diff -NurpP --minimal linux-2.6.32.6/include/linux/sysctl.h linux-2.6.32.6-vs2.3.0.36.28/include/linux/sysctl.h
9368 --- linux-2.6.32.6/include/linux/sysctl.h       2009-12-03 20:02:56.000000000 +0100
9369 +++ linux-2.6.32.6-vs2.3.0.36.28/include/linux/sysctl.h 2009-12-03 20:04:56.000000000 +0100
9370 @@ -69,6 +69,7 @@ enum
9371         CTL_ABI=9,              /* Binary emulation */
9372         CTL_CPU=10,             /* CPU stuff (speed scaling, etc) */
9373         CTL_ARLAN=254,          /* arlan wireless driver */
9374 +       CTL_VSERVER=4242,       /* Linux-VServer debug */
9375         CTL_S390DBF=5677,       /* s390 debug */
9376         CTL_SUNRPC=7249,        /* sunrpc debug */
9377         CTL_PM=9899,            /* frv power management */
9378 @@ -103,6 +104,7 @@ enum
9379  
9380         KERN_PANIC=15,          /* int: panic timeout */
9381         KERN_REALROOTDEV=16,    /* real root device to mount after initrd */
9382 +       KERN_VSHELPER=17,       /* string: path to vshelper policy agent */
9383  
9384         KERN_SPARC_REBOOT=21,   /* reboot command on Sparc */
9385         KERN_CTLALTDEL=22,      /* int: allow ctl-alt-del to reboot */
9386 diff -NurpP --minimal linux-2.6.32.6/include/linux/sysfs.h linux-2.6.32.6-vs2.3.0.36.28/include/linux/sysfs.h
9387 --- linux-2.6.32.6/include/linux/sysfs.h        2008-12-25 00:26:37.000000000 +0100
9388 +++ linux-2.6.32.6-vs2.3.0.36.28/include/linux/sysfs.h  2009-12-03 20:04:56.000000000 +0100
9389 @@ -17,6 +17,8 @@
9390  #include <linux/list.h>
9391  #include <asm/atomic.h>
9392  
9393 +#define SYSFS_SUPER_MAGIC      0x62656572
9394 +
9395  struct kobject;
9396  struct module;
9397  
9398 diff -NurpP --minimal linux-2.6.32.6/include/linux/time.h linux-2.6.32.6-vs2.3.0.36.28/include/linux/time.h
9399 --- linux-2.6.32.6/include/linux/time.h 2009-12-03 20:02:56.000000000 +0100
9400 +++ linux-2.6.32.6-vs2.3.0.36.28/include/linux/time.h   2009-12-03 20:04:56.000000000 +0100
9401 @@ -237,6 +237,9 @@ static __always_inline void timespec_add
9402         a->tv_sec += __iter_div_u64_rem(a->tv_nsec + ns, NSEC_PER_SEC, &ns);
9403         a->tv_nsec = ns;
9404  }
9405 +
9406 +#include <linux/vs_time.h>
9407 +
9408  #endif /* __KERNEL__ */
9409  
9410  #define NFDBITS                        __NFDBITS
9411 diff -NurpP --minimal linux-2.6.32.6/include/linux/types.h linux-2.6.32.6-vs2.3.0.36.28/include/linux/types.h
9412 --- linux-2.6.32.6/include/linux/types.h        2009-09-10 15:26:26.000000000 +0200
9413 +++ linux-2.6.32.6-vs2.3.0.36.28/include/linux/types.h  2009-12-03 20:04:56.000000000 +0100
9414 @@ -37,6 +37,9 @@ typedef __kernel_uid32_t      uid_t;
9415  typedef __kernel_gid32_t       gid_t;
9416  typedef __kernel_uid16_t        uid16_t;
9417  typedef __kernel_gid16_t        gid16_t;
9418 +typedef unsigned int           xid_t;
9419 +typedef unsigned int           nid_t;
9420 +typedef unsigned int           tag_t;
9421  
9422  typedef unsigned long          uintptr_t;
9423  
9424 diff -NurpP --minimal linux-2.6.32.6/include/linux/vroot.h linux-2.6.32.6-vs2.3.0.36.28/include/linux/vroot.h
9425 --- linux-2.6.32.6/include/linux/vroot.h        1970-01-01 01:00:00.000000000 +0100
9426 +++ linux-2.6.32.6-vs2.3.0.36.28/include/linux/vroot.h  2009-12-03 20:04:56.000000000 +0100
9427 @@ -0,0 +1,51 @@
9428 +
9429 +/*
9430 + * include/linux/vroot.h
9431 + *
9432 + * written by Herbert Pötzl, 9/11/2002
9433 + * ported to 2.6 by Herbert Pötzl, 30/12/2004
9434 + *
9435 + * Copyright (C) 2002-2007 by Herbert Pötzl.
9436 + * Redistribution of this file is permitted under the
9437 + * GNU General Public License.
9438 + */
9439 +
9440 +#ifndef _LINUX_VROOT_H
9441 +#define _LINUX_VROOT_H
9442 +
9443 +
9444 +#ifdef __KERNEL__
9445 +
9446 +/* Possible states of device */
9447 +enum {
9448 +       Vr_unbound,
9449 +       Vr_bound,
9450 +};
9451 +
9452 +struct vroot_device {
9453 +       int             vr_number;
9454 +       int             vr_refcnt;
9455 +
9456 +       struct semaphore        vr_ctl_mutex;
9457 +       struct block_device    *vr_device;
9458 +       int                     vr_state;
9459 +};
9460 +
9461 +
9462 +typedef struct block_device *(vroot_grb_func)(struct block_device *);
9463 +
9464 +extern int register_vroot_grb(vroot_grb_func *);
9465 +extern int unregister_vroot_grb(vroot_grb_func *);
9466 +
9467 +#endif /* __KERNEL__ */
9468 +
9469 +#define MAX_VROOT_DEFAULT      8
9470 +
9471 +/*
9472 + * IOCTL commands --- we will commandeer 0x56 ('V')
9473 + */
9474 +
9475 +#define VROOT_SET_DEV          0x5600
9476 +#define VROOT_CLR_DEV          0x5601
9477 +
9478 +#endif /* _LINUX_VROOT_H */
9479 diff -NurpP --minimal linux-2.6.32.6/include/linux/vs_base.h linux-2.6.32.6-vs2.3.0.36.28/include/linux/vs_base.h
9480 --- linux-2.6.32.6/include/linux/vs_base.h      1970-01-01 01:00:00.000000000 +0100
9481 +++ linux-2.6.32.6-vs2.3.0.36.28/include/linux/vs_base.h        2009-12-03 20:04:56.000000000 +0100
9482 @@ -0,0 +1,10 @@
9483 +#ifndef _VS_BASE_H
9484 +#define _VS_BASE_H
9485 +
9486 +#include "vserver/base.h"
9487 +#include "vserver/check.h"
9488 +#include "vserver/debug.h"
9489 +
9490 +#else
9491 +#warning duplicate inclusion
9492 +#endif
9493 diff -NurpP --minimal linux-2.6.32.6/include/linux/vs_context.h linux-2.6.32.6-vs2.3.0.36.28/include/linux/vs_context.h
9494 --- linux-2.6.32.6/include/linux/vs_context.h   1970-01-01 01:00:00.000000000 +0100
9495 +++ linux-2.6.32.6-vs2.3.0.36.28/include/linux/vs_context.h     2009-12-03 20:04:56.000000000 +0100
9496 @@ -0,0 +1,242 @@
9497 +#ifndef _VS_CONTEXT_H
9498 +#define _VS_CONTEXT_H
9499 +
9500 +#include "vserver/base.h"
9501 +#include "vserver/check.h"
9502 +#include "vserver/context.h"
9503 +#include "vserver/history.h"
9504 +#include "vserver/debug.h"
9505 +
9506 +#include <linux/sched.h>
9507 +
9508 +
9509 +#define get_vx_info(i) __get_vx_info(i, __FILE__, __LINE__, __HERE__)
9510 +
9511 +static inline struct vx_info *__get_vx_info(struct vx_info *vxi,
9512 +       const char *_file, int _line, void *_here)
9513 +{
9514 +       if (!vxi)
9515 +               return NULL;
9516 +
9517 +       vxlprintk(VXD_CBIT(xid, 2), "get_vx_info(%p[#%d.%d])",
9518 +               vxi, vxi ? vxi->vx_id : 0,
9519 +               vxi ? atomic_read(&vxi->vx_usecnt) : 0,
9520 +               _file, _line);
9521 +       __vxh_get_vx_info(vxi, _here);
9522 +
9523 +       atomic_inc(&vxi->vx_usecnt);
9524 +       return vxi;
9525 +}
9526 +
9527 +
9528 +extern void free_vx_info(struct vx_info *);
9529 +
9530 +#define put_vx_info(i) __put_vx_info(i, __FILE__, __LINE__, __HERE__)
9531 +
9532 +static inline void __put_vx_info(struct vx_info *vxi,
9533 +       const char *_file, int _line, void *_here)
9534 +{
9535 +       if (!vxi)
9536 +               return;
9537 +
9538 +       vxlprintk(VXD_CBIT(xid, 2), "put_vx_info(%p[#%d.%d])",
9539 +               vxi, vxi ? vxi->vx_id : 0,
9540 +               vxi ? atomic_read(&vxi->vx_usecnt) : 0,
9541 +               _file, _line);
9542 +       __vxh_put_vx_info(vxi, _here);
9543 +
9544 +       if (atomic_dec_and_test(&vxi->vx_usecnt))
9545 +               free_vx_info(vxi);
9546 +}
9547 +
9548 +
9549 +#define init_vx_info(p, i) \
9550 +       __init_vx_info(p, i, __FILE__, __LINE__, __HERE__)
9551 +
9552 +static inline void __init_vx_info(struct vx_info **vxp, struct vx_info *vxi,
9553 +       const char *_file, int _line, void *_here)
9554 +{
9555 +       if (vxi) {
9556 +               vxlprintk(VXD_CBIT(xid, 3),
9557 +                       "init_vx_info(%p[#%d.%d])",
9558 +                       vxi, vxi ? vxi->vx_id : 0,
9559 +                       vxi ? atomic_read(&vxi->vx_usecnt) : 0,
9560 +                       _file, _line);
9561 +               __vxh_init_vx_info(vxi, vxp, _here);
9562 +
9563 +               atomic_inc(&vxi->vx_usecnt);
9564 +       }
9565 +       *vxp = vxi;
9566 +}
9567 +
9568 +
9569 +#define set_vx_info(p, i) \
9570 +       __set_vx_info(p, i, __FILE__, __LINE__, __HERE__)
9571 +
9572 +static inline void __set_vx_info(struct vx_info **vxp, struct vx_info *vxi,
9573 +       const char *_file, int _line, void *_here)
9574 +{
9575 +       struct vx_info *vxo;
9576 +
9577 +       if (!vxi)
9578 +               return;
9579 +
9580 +       vxlprintk(VXD_CBIT(xid, 3), "set_vx_info(%p[#%d.%d])",
9581 +               vxi, vxi ? vxi->vx_id : 0,
9582 +               vxi ? atomic_read(&vxi->vx_usecnt) : 0,
9583 +               _file, _line);
9584 +       __vxh_set_vx_info(vxi, vxp, _here);
9585 +
9586 +       atomic_inc(&vxi->vx_usecnt);
9587 +       vxo = xchg(vxp, vxi);
9588 +       BUG_ON(vxo);
9589 +}
9590 +
9591 +
9592 +#define clr_vx_info(p) __clr_vx_info(p, __FILE__, __LINE__, __HERE__)
9593 +
9594 +static inline void __clr_vx_info(struct vx_info **vxp,
9595 +       const char *_file, int _line, void *_here)
9596 +{
9597 +       struct vx_info *vxo;
9598 +
9599 +       vxo = xchg(vxp, NULL);
9600 +       if (!vxo)
9601 +               return;
9602 +
9603 +       vxlprintk(VXD_CBIT(xid, 3), "clr_vx_info(%p[#%d.%d])",
9604 +               vxo, vxo ? vxo->vx_id : 0,
9605 +               vxo ? atomic_read(&vxo->vx_usecnt) : 0,
9606 +               _file, _line);
9607 +       __vxh_clr_vx_info(vxo, vxp, _here);
9608 +
9609 +       if (atomic_dec_and_test(&vxo->vx_usecnt))
9610 +               free_vx_info(vxo);
9611 +}
9612 +
9613 +
9614 +#define claim_vx_info(v, p) \
9615 +       __claim_vx_info(v, p, __FILE__, __LINE__, __HERE__)
9616 +
9617 +static inline void __claim_vx_info(struct vx_info *vxi,
9618 +       struct task_struct *task,
9619 +       const char *_file, int _line, void *_here)
9620 +{
9621 +       vxlprintk(VXD_CBIT(xid, 3), "claim_vx_info(%p[#%d.%d.%d]) %p",
9622 +               vxi, vxi ? vxi->vx_id : 0,
9623 +               vxi ? atomic_read(&vxi->vx_usecnt) : 0,
9624 +               vxi ? atomic_read(&vxi->vx_tasks) : 0,
9625 +               task, _file, _line);
9626 +       __vxh_claim_vx_info(vxi, task, _here);
9627 +
9628 +       atomic_inc(&vxi->vx_tasks);
9629 +}
9630 +
9631 +
9632 +extern void unhash_vx_info(struct vx_info *);
9633 +
9634 +#define release_vx_info(v, p) \
9635 +       __release_vx_info(v, p, __FILE__, __LINE__, __HERE__)
9636 +
9637 +static inline void __release_vx_info(struct vx_info *vxi,
9638 +       struct task_struct *task,
9639 +       const char *_file, int _line, void *_here)
9640 +{
9641 +       vxlprintk(VXD_CBIT(xid, 3), "release_vx_info(%p[#%d.%d.%d]) %p",
9642 +               vxi, vxi ? vxi->vx_id : 0,
9643 +               vxi ? atomic_read(&vxi->vx_usecnt) : 0,
9644 +               vxi ? atomic_read(&vxi->vx_tasks) : 0,
9645 +               task, _file, _line);
9646 +       __vxh_release_vx_info(vxi, task, _here);
9647 +
9648 +       might_sleep();
9649 +
9650 +       if (atomic_dec_and_test(&vxi->vx_tasks))
9651 +               unhash_vx_info(vxi);
9652 +}
9653 +
9654 +
9655 +#define task_get_vx_info(p) \
9656 +       __task_get_vx_info(p, __FILE__, __LINE__, __HERE__)
9657 +
9658 +static inline struct vx_info *__task_get_vx_info(struct task_struct *p,
9659 +       const char *_file, int _line, void *_here)
9660 +{
9661 +       struct vx_info *vxi;
9662 +
9663 +       task_lock(p);
9664 +       vxlprintk(VXD_CBIT(xid, 5), "task_get_vx_info(%p)",
9665 +               p, _file, _line);
9666 +       vxi = __get_vx_info(p->vx_info, _file, _line, _here);
9667 +       task_unlock(p);
9668 +       return vxi;
9669 +}
9670 +
9671 +
9672 +static inline void __wakeup_vx_info(struct vx_info *vxi)
9673 +{
9674 +       if (waitqueue_active(&vxi->vx_wait))
9675 +               wake_up_interruptible(&vxi->vx_wait);
9676 +}
9677 +
9678 +
9679 +#define enter_vx_info(v, s) __enter_vx_info(v, s, __FILE__, __LINE__)
9680 +
9681 +static inline void __enter_vx_info(struct vx_info *vxi,
9682 +       struct vx_info_save *vxis, const char *_file, int _line)
9683 +{
9684 +       vxlprintk(VXD_CBIT(xid, 5), "enter_vx_info(%p[#%d],%p) %p[#%d,%p]",
9685 +               vxi, vxi ? vxi->vx_id : 0, vxis, current,
9686 +               current->xid, current->vx_info, _file, _line);
9687 +       vxis->vxi = xchg(&current->vx_info, vxi);
9688 +       vxis->xid = current->xid;
9689 +       current->xid = vxi ? vxi->vx_id : 0;
9690 +}
9691 +
9692 +#define leave_vx_info(s) __leave_vx_info(s, __FILE__, __LINE__)
9693 +
9694 +static inline void __leave_vx_info(struct vx_info_save *vxis,
9695 +       const char *_file, int _line)
9696 +{
9697 +       vxlprintk(VXD_CBIT(xid, 5), "leave_vx_info(%p[#%d,%p]) %p[#%d,%p]",
9698 +               vxis, vxis->xid, vxis->vxi, current,
9699 +               current->xid, current->vx_info, _file, _line);
9700 +       (void)xchg(&current->vx_info, vxis->vxi);
9701 +       current->xid = vxis->xid;
9702 +}
9703 +
9704 +
9705 +static inline void __enter_vx_admin(struct vx_info_save *vxis)
9706 +{
9707 +       vxis->vxi = xchg(&current->vx_info, NULL);
9708 +       vxis->xid = xchg(&current->xid, (xid_t)0);
9709 +}
9710 +
9711 +static inline void __leave_vx_admin(struct vx_info_save *vxis)
9712 +{
9713 +       (void)xchg(&current->xid, vxis->xid);
9714 +       (void)xchg(&current->vx_info, vxis->vxi);
9715 +}
9716 +
9717 +#define task_is_init(p) \
9718 +       __task_is_init(p, __FILE__, __LINE__, __HERE__)
9719 +
9720 +static inline int __task_is_init(struct task_struct *p,
9721 +       const char *_file, int _line, void *_here)
9722 +{
9723 +       int is_init = is_global_init(p);
9724 +
9725 +       task_lock(p);
9726 +       if (p->vx_info)
9727 +               is_init = p->vx_info->vx_initpid == p->pid;
9728 +       task_unlock(p);
9729 +       return is_init;
9730 +}
9731 +
9732 +extern void exit_vx_info(struct task_struct *, int);
9733 +extern void exit_vx_info_early(struct task_struct *, int);
9734 +
9735 +
9736 +#else
9737 +#warning duplicate inclusion
9738 +#endif
9739 diff -NurpP --minimal linux-2.6.32.6/include/linux/vs_cowbl.h linux-2.6.32.6-vs2.3.0.36.28/include/linux/vs_cowbl.h
9740 --- linux-2.6.32.6/include/linux/vs_cowbl.h     1970-01-01 01:00:00.000000000 +0100
9741 +++ linux-2.6.32.6-vs2.3.0.36.28/include/linux/vs_cowbl.h       2009-12-03 20:04:56.000000000 +0100
9742 @@ -0,0 +1,47 @@
9743 +#ifndef _VS_COWBL_H
9744 +#define _VS_COWBL_H
9745 +
9746 +#include <linux/fs.h>
9747 +#include <linux/dcache.h>
9748 +#include <linux/namei.h>
9749 +
9750 +extern struct dentry *cow_break_link(const char *pathname);
9751 +
9752 +static inline int cow_check_and_break(struct path *path)
9753 +{
9754 +       struct inode *inode = path->dentry->d_inode;
9755 +       int error = 0;
9756 +
9757 +       /* do we need this check? */
9758 +       if (IS_RDONLY(inode))
9759 +               return -EROFS;
9760 +
9761 +       if (IS_COW(inode)) {
9762 +               if (IS_COW_LINK(inode)) {
9763 +                       struct dentry *new_dentry, *old_dentry = path->dentry;
9764 +                       char *pp, *buf;
9765 +
9766 +                       buf = kmalloc(PATH_MAX, GFP_KERNEL);
9767 +                       if (!buf) {
9768 +                               return -ENOMEM;
9769 +                       }
9770 +                       pp = d_path(path, buf, PATH_MAX);
9771 +                       new_dentry = cow_break_link(pp);
9772 +                       kfree(buf);
9773 +                       if (!IS_ERR(new_dentry)) {
9774 +                               path->dentry = new_dentry;
9775 +                               dput(old_dentry);
9776 +                       } else
9777 +                               error = PTR_ERR(new_dentry);
9778 +               } else {
9779 +                       inode->i_flags &= ~(S_IXUNLINK | S_IMMUTABLE);
9780 +                       inode->i_ctime = CURRENT_TIME;
9781 +                       mark_inode_dirty(inode);
9782 +               }
9783 +       }
9784 +       return error;
9785 +}
9786 +
9787 +#else
9788 +#warning duplicate inclusion
9789 +#endif
9790 diff -NurpP --minimal linux-2.6.32.6/include/linux/vs_cvirt.h linux-2.6.32.6-vs2.3.0.36.28/include/linux/vs_cvirt.h
9791 --- linux-2.6.32.6/include/linux/vs_cvirt.h     1970-01-01 01:00:00.000000000 +0100
9792 +++ linux-2.6.32.6-vs2.3.0.36.28/include/linux/vs_cvirt.h       2009-12-03 20:04:56.000000000 +0100
9793 @@ -0,0 +1,50 @@
9794 +#ifndef _VS_CVIRT_H
9795 +#define _VS_CVIRT_H
9796 +
9797 +#include "vserver/cvirt.h"
9798 +#include "vserver/context.h"
9799 +#include "vserver/base.h"
9800 +#include "vserver/check.h"
9801 +#include "vserver/debug.h"
9802 +
9803 +
9804 +static inline void vx_activate_task(struct task_struct *p)
9805 +{
9806 +       struct vx_info *vxi;
9807 +
9808 +       if ((vxi = p->vx_info)) {
9809 +               vx_update_load(vxi);
9810 +               atomic_inc(&vxi->cvirt.nr_running);
9811 +       }
9812 +}
9813 +
9814 +static inline void vx_deactivate_task(struct task_struct *p)
9815 +{
9816 +       struct vx_info *vxi;
9817 +
9818 +       if ((vxi = p->vx_info)) {
9819 +               vx_update_load(vxi);
9820 +               atomic_dec(&vxi->cvirt.nr_running);
9821 +       }
9822 +}
9823 +
9824 +static inline void vx_uninterruptible_inc(struct task_struct *p)
9825 +{
9826 +       struct vx_info *vxi;
9827 +
9828 +       if ((vxi = p->vx_info))
9829 +               atomic_inc(&vxi->cvirt.nr_uninterruptible);
9830 +}
9831 +
9832 +static inline void vx_uninterruptible_dec(struct task_struct *p)
9833 +{
9834 +       struct vx_info *vxi;
9835 +
9836 +       if ((vxi = p->vx_info))
9837 +               atomic_dec(&vxi->cvirt.nr_uninterruptible);
9838 +}
9839 +
9840 +
9841 +#else
9842 +#warning duplicate inclusion
9843 +#endif
9844 diff -NurpP --minimal linux-2.6.32.6/include/linux/vs_device.h linux-2.6.32.6-vs2.3.0.36.28/include/linux/vs_device.h
9845 --- linux-2.6.32.6/include/linux/vs_device.h    1970-01-01 01:00:00.000000000 +0100
9846 +++ linux-2.6.32.6-vs2.3.0.36.28/include/linux/vs_device.h      2009-12-03 20:04:56.000000000 +0100
9847 @@ -0,0 +1,45 @@
9848 +#ifndef _VS_DEVICE_H
9849 +#define _VS_DEVICE_H
9850 +
9851 +#include "vserver/base.h"
9852 +#include "vserver/device.h"
9853 +#include "vserver/debug.h"
9854 +
9855 +
9856 +#ifdef CONFIG_VSERVER_DEVICE
9857 +
9858 +int vs_map_device(struct vx_info *, dev_t, dev_t *, umode_t);
9859 +
9860 +#define vs_device_perm(v, d, m, p) \
9861 +       ((vs_map_device(current_vx_info(), d, NULL, m) & (p)) == (p))
9862 +
9863 +#else
9864 +
9865 +static inline
9866 +int vs_map_device(struct vx_info *vxi,
9867 +       dev_t device, dev_t *target, umode_t mode)
9868 +{
9869 +       if (target)
9870 +               *target = device;
9871 +       return ~0;
9872 +}
9873 +
9874 +#define vs_device_perm(v, d, m, p) ((p) == (p))
9875 +
9876 +#endif
9877 +
9878 +
9879 +#define vs_map_chrdev(d, t, p) \
9880 +       ((vs_map_device(current_vx_info(), d, t, S_IFCHR) & (p)) == (p))
9881 +#define vs_map_blkdev(d, t, p) \
9882 +       ((vs_map_device(current_vx_info(), d, t, S_IFBLK) & (p)) == (p))
9883 +
9884 +#define vs_chrdev_perm(d, p) \
9885 +       vs_device_perm(current_vx_info(), d, S_IFCHR, p)
9886 +#define vs_blkdev_perm(d, p) \
9887 +       vs_device_perm(current_vx_info(), d, S_IFBLK, p)
9888 +
9889 +
9890 +#else
9891 +#warning duplicate inclusion
9892 +#endif
9893 diff -NurpP --minimal linux-2.6.32.6/include/linux/vs_dlimit.h linux-2.6.32.6-vs2.3.0.36.28/include/linux/vs_dlimit.h
9894 --- linux-2.6.32.6/include/linux/vs_dlimit.h    1970-01-01 01:00:00.000000000 +0100
9895 +++ linux-2.6.32.6-vs2.3.0.36.28/include/linux/vs_dlimit.h      2009-12-03 20:04:56.000000000 +0100
9896 @@ -0,0 +1,216 @@
9897 +#ifndef _VS_DLIMIT_H
9898 +#define _VS_DLIMIT_H
9899 +
9900 +#include <linux/fs.h>
9901 +
9902 +#include "vserver/dlimit.h"
9903 +#include "vserver/base.h"
9904 +#include "vserver/debug.h"
9905 +
9906 +
9907 +#define get_dl_info(i) __get_dl_info(i, __FILE__, __LINE__)
9908 +
9909 +static inline struct dl_info *__get_dl_info(struct dl_info *dli,
9910 +       const char *_file, int _line)
9911 +{
9912 +       if (!dli)
9913 +               return NULL;
9914 +       vxlprintk(VXD_CBIT(dlim, 4), "get_dl_info(%p[#%d.%d])",
9915 +               dli, dli ? dli->dl_tag : 0,
9916 +               dli ? atomic_read(&dli->dl_usecnt) : 0,
9917 +               _file, _line);
9918 +       atomic_inc(&dli->dl_usecnt);
9919 +       return dli;
9920 +}
9921 +
9922 +
9923 +#define free_dl_info(i) \
9924 +       call_rcu(&(i)->dl_rcu, rcu_free_dl_info)
9925 +
9926 +#define put_dl_info(i) __put_dl_info(i, __FILE__, __LINE__)
9927 +
9928 +static inline void __put_dl_info(struct dl_info *dli,
9929 +       const char *_file, int _line)
9930 +{
9931 +       if (!dli)
9932 +               return;
9933 +       vxlprintk(VXD_CBIT(dlim, 4), "put_dl_info(%p[#%d.%d])",
9934 +               dli, dli ? dli->dl_tag : 0,
9935 +               dli ? atomic_read(&dli->dl_usecnt) : 0,
9936 +               _file, _line);
9937 +       if (atomic_dec_and_test(&dli->dl_usecnt))
9938 +               free_dl_info(dli);
9939 +}
9940 +
9941 +
9942 +#define __dlimit_char(d)       ((d) ? '*' : ' ')
9943 +
9944 +static inline int __dl_alloc_space(struct super_block *sb,
9945 +       tag_t tag, dlsize_t nr, const char *file, int line)
9946 +{
9947 +       struct dl_info *dli = NULL;
9948 +       int ret = 0;
9949 +
9950 +       if (nr == 0)
9951 +               goto out;
9952 +       dli = locate_dl_info(sb, tag);
9953 +       if (!dli)
9954 +               goto out;
9955 +
9956 +       spin_lock(&dli->dl_lock);
9957 +       ret = (dli->dl_space_used + nr > dli->dl_space_total);
9958 +       if (!ret)
9959 +               dli->dl_space_used += nr;
9960 +       spin_unlock(&dli->dl_lock);
9961 +       put_dl_info(dli);
9962 +out:
9963 +       vxlprintk(VXD_CBIT(dlim, 1),
9964 +               "ALLOC (%p,#%d)%c %lld bytes (%d)",
9965 +               sb, tag, __dlimit_char(dli), (long long)nr,
9966 +               ret, file, line);
9967 +       return ret;
9968 +}
9969 +
9970 +static inline void __dl_free_space(struct super_block *sb,
9971 +       tag_t tag, dlsize_t nr, const char *_file, int _line)
9972 +{
9973 +       struct dl_info *dli = NULL;
9974 +
9975 +       if (nr == 0)
9976 +               goto out;
9977 +       dli = locate_dl_info(sb, tag);
9978 +       if (!dli)
9979 +               goto out;
9980 +
9981 +       spin_lock(&dli->dl_lock);
9982 +       if (dli->dl_space_used > nr)
9983 +               dli->dl_space_used -= nr;
9984 +       else
9985 +               dli->dl_space_used = 0;
9986 +       spin_unlock(&dli->dl_lock);
9987 +       put_dl_info(dli);
9988 +out:
9989 +       vxlprintk(VXD_CBIT(dlim, 1),
9990 +               "FREE  (%p,#%d)%c %lld bytes",
9991 +               sb, tag, __dlimit_char(dli), (long long)nr,
9992 +               _file, _line);
9993 +}
9994 +
9995 +static inline int __dl_alloc_inode(struct super_block *sb,
9996 +       tag_t tag, const char *_file, int _line)
9997 +{
9998 +       struct dl_info *dli;
9999 +       int ret = 0;
10000 +
10001 +       dli = locate_dl_info(sb, tag);
10002 +       if (!dli)
10003 +               goto out;
10004 +
10005 +       spin_lock(&dli->dl_lock);
10006 +       ret = (dli->dl_inodes_used >= dli->dl_inodes_total);
10007 +       if (!ret)
10008 +               dli->dl_inodes_used++;
10009 +       spin_unlock(&dli->dl_lock);
10010 +       put_dl_info(dli);
10011 +out:
10012 +       vxlprintk(VXD_CBIT(dlim, 0),
10013 +               "ALLOC (%p,#%d)%c inode (%d)",
10014 +               sb, tag, __dlimit_char(dli), ret, _file, _line);
10015 +       return ret;
10016 +}
10017 +
10018 +static inline void __dl_free_inode(struct super_block *sb,
10019 +       tag_t tag, const char *_file, int _line)
10020 +{
10021 +       struct dl_info *dli;
10022 +
10023 +       dli = locate_dl_info(sb, tag);
10024 +       if (!dli)
10025 +               goto out;
10026 +
10027 +       spin_lock(&dli->dl_lock);
10028 +       if (dli->dl_inodes_used > 1)
10029 +               dli->dl_inodes_used--;
10030 +       else
10031 +               dli->dl_inodes_used = 0;
10032 +       spin_unlock(&dli->dl_lock);
10033 +       put_dl_info(dli);
10034 +out:
10035 +       vxlprintk(VXD_CBIT(dlim, 0),
10036 +               "FREE  (%p,#%d)%c inode",
10037 +               sb, tag, __dlimit_char(dli), _file, _line);
10038 +}
10039 +
10040 +static inline void __dl_adjust_block(struct super_block *sb, tag_t tag,
10041 +       unsigned long long *free_blocks, unsigned long long *root_blocks,
10042 +       const char *_file, int _line)
10043 +{
10044 +       struct dl_info *dli;
10045 +       uint64_t broot, bfree;
10046 +
10047 +       dli = locate_dl_info(sb, tag);
10048 +       if (!dli)
10049 +               return;
10050 +
10051 +       spin_lock(&dli->dl_lock);
10052 +       broot = (dli->dl_space_total -
10053 +               (dli->dl_space_total >> 10) * dli->dl_nrlmult)
10054 +               >> sb->s_blocksize_bits;
10055 +       bfree = (dli->dl_space_total - dli->dl_space_used)
10056 +                       >> sb->s_blocksize_bits;
10057 +       spin_unlock(&dli->dl_lock);
10058 +
10059 +       vxlprintk(VXD_CBIT(dlim, 2),
10060 +               "ADJUST: %lld,%lld on %lld,%lld [mult=%d]",
10061 +               (long long)bfree, (long long)broot,
10062 +               *free_blocks, *root_blocks, dli->dl_nrlmult,
10063 +               _file, _line);
10064 +       if (free_blocks) {
10065 +               if (*free_blocks > bfree)
10066 +                       *free_blocks = bfree;
10067 +       }
10068 +       if (root_blocks) {
10069 +               if (*root_blocks > broot)
10070 +                       *root_blocks = broot;
10071 +       }
10072 +       put_dl_info(dli);
10073 +}
10074 +
10075 +#define dl_prealloc_space(in, bytes) \
10076 +       __dl_alloc_space((in)->i_sb, (in)->i_tag, (dlsize_t)(bytes), \
10077 +               __FILE__, __LINE__ )
10078 +
10079 +#define dl_alloc_space(in, bytes) \
10080 +       __dl_alloc_space((in)->i_sb, (in)->i_tag, (dlsize_t)(bytes), \
10081 +               __FILE__, __LINE__ )
10082 +
10083 +#define dl_reserve_space(in, bytes) \
10084 +       __dl_alloc_space((in)->i_sb, (in)->i_tag, (dlsize_t)(bytes), \
10085 +               __FILE__, __LINE__ )
10086 +
10087 +#define dl_claim_space(in, bytes) (0)
10088 +
10089 +#define dl_release_space(in, bytes) \
10090 +       __dl_free_space((in)->i_sb, (in)->i_tag, (dlsize_t)(bytes), \
10091 +               __FILE__, __LINE__ )
10092 +
10093 +#define dl_free_space(in, bytes) \
10094 +       __dl_free_space((in)->i_sb, (in)->i_tag, (dlsize_t)(bytes), \
10095 +               __FILE__, __LINE__ )
10096 +
10097 +
10098 +
10099 +#define dl_alloc_inode(in) \
10100 +       __dl_alloc_inode((in)->i_sb, (in)->i_tag, __FILE__, __LINE__ )
10101 +
10102 +#define dl_free_inode(in) \
10103 +       __dl_free_inode((in)->i_sb, (in)->i_tag, __FILE__, __LINE__ )
10104 +
10105 +
10106 +#define dl_adjust_block(sb, tag, fb, rb) \
10107 +       __dl_adjust_block(sb, tag, fb, rb, __FILE__, __LINE__ )
10108 +
10109 +
10110 +#else
10111 +#warning duplicate inclusion
10112 +#endif
10113 diff -NurpP --minimal linux-2.6.32.6/include/linux/vserver/base.h linux-2.6.32.6-vs2.3.0.36.28/include/linux/vserver/base.h
10114 --- linux-2.6.32.6/include/linux/vserver/base.h 1970-01-01 01:00:00.000000000 +0100
10115 +++ linux-2.6.32.6-vs2.3.0.36.28/include/linux/vserver/base.h   2009-12-03 20:04:56.000000000 +0100
10116 @@ -0,0 +1,170 @@
10117 +#ifndef _VX_BASE_H
10118 +#define _VX_BASE_H
10119 +
10120 +
10121 +/* context state changes */
10122 +
10123 +enum {
10124 +       VSC_STARTUP = 1,
10125 +       VSC_SHUTDOWN,
10126 +
10127 +       VSC_NETUP,
10128 +       VSC_NETDOWN,
10129 +};
10130 +
10131 +
10132 +
10133 +#define vx_task_xid(t) ((t)->xid)
10134 +
10135 +#define vx_current_xid() vx_task_xid(current)
10136 +
10137 +#define current_vx_info() (current->vx_info)
10138 +
10139 +
10140 +#define nx_task_nid(t) ((t)->nid)
10141 +
10142 +#define nx_current_nid() nx_task_nid(current)
10143 +
10144 +#define current_nx_info() (current->nx_info)
10145 +
10146 +
10147 +/* generic flag merging */
10148 +
10149 +#define vs_check_flags(v, m, f)        (((v) & (m)) ^ (f))
10150 +
10151 +#define vs_mask_flags(v, f, m) (((v) & ~(m)) | ((f) & (m)))
10152 +
10153 +#define vs_mask_mask(v, f, m)  (((v) & ~(m)) | ((v) & (f) & (m)))
10154 +
10155 +#define vs_check_bit(v, n)     ((v) & (1LL << (n)))
10156 +
10157 +
10158 +/* context flags */
10159 +
10160 +#define __vx_flags(v)  ((v) ? (v)->vx_flags : 0)
10161 +
10162 +#define vx_current_flags()     __vx_flags(current_vx_info())
10163 +
10164 +#define vx_info_flags(v, m, f) \
10165 +       vs_check_flags(__vx_flags(v), m, f)
10166 +
10167 +#define task_vx_flags(t, m, f) \
10168 +       ((t) && vx_info_flags((t)->vx_info, m, f))
10169 +
10170 +#define vx_flags(m, f) vx_info_flags(current_vx_info(), m, f)
10171 +
10172 +
10173 +/* context caps */
10174 +
10175 +#define __vx_ccaps(v)  ((v) ? (v)->vx_ccaps : 0)
10176 +
10177 +#define vx_current_ccaps()     __vx_ccaps(current_vx_info())
10178 +
10179 +#define vx_info_ccaps(v, c)    (__vx_ccaps(v) & (c))
10180 +
10181 +#define vx_ccaps(c)    vx_info_ccaps(current_vx_info(), (c))
10182 +
10183 +
10184 +
10185 +/* network flags */
10186 +
10187 +#define __nx_flags(n)  ((n) ? (n)->nx_flags : 0)
10188 +
10189 +#define nx_current_flags()     __nx_flags(current_nx_info())
10190 +
10191 +#define nx_info_flags(n, m, f) \
10192 +       vs_check_flags(__nx_flags(n), m, f)
10193 +
10194 +#define task_nx_flags(t, m, f) \
10195 +       ((t) && nx_info_flags((t)->nx_info, m, f))
10196 +
10197 +#define nx_flags(m, f) nx_info_flags(current_nx_info(), m, f)
10198 +
10199 +
10200 +/* network caps */
10201 +
10202 +#define __nx_ncaps(n)  ((n) ? (n)->nx_ncaps : 0)
10203 +
10204 +#define nx_current_ncaps()     __nx_ncaps(current_nx_info())
10205 +
10206 +#define nx_info_ncaps(n, c)    (__nx_ncaps(n) & (c))
10207 +
10208 +#define nx_ncaps(c)    nx_info_ncaps(current_nx_info(), c)
10209 +
10210 +
10211 +/* context mask capabilities */
10212 +
10213 +#define __vx_mcaps(v)  ((v) ? (v)->vx_ccaps >> 32UL : ~0 )
10214 +
10215 +#define vx_info_mcaps(v, c)    (__vx_mcaps(v) & (c))
10216 +
10217 +#define vx_mcaps(c)    vx_info_mcaps(current_vx_info(), c)
10218 +
10219 +
10220 +/* context bcap mask */
10221 +
10222 +#define __vx_bcaps(v)          ((v)->vx_bcaps)
10223 +
10224 +#define vx_current_bcaps()     __vx_bcaps(current_vx_info())
10225 +
10226 +
10227 +/* mask given bcaps */
10228 +
10229 +#define vx_info_mbcaps(v, c)   ((v) ? cap_intersect(__vx_bcaps(v), c) : c)
10230 +
10231 +#define vx_mbcaps(c)           vx_info_mbcaps(current_vx_info(), c)
10232 +
10233 +
10234 +/* masked cap_bset */
10235 +
10236 +#define vx_info_cap_bset(v)    vx_info_mbcaps(v, current->cap_bset)
10237 +
10238 +#define vx_current_cap_bset()  vx_info_cap_bset(current_vx_info())
10239 +
10240 +#if 0
10241 +#define vx_info_mbcap(v, b) \
10242 +       (!vx_info_flags(v, VXF_STATE_SETUP, 0) ? \
10243 +       vx_info_bcaps(v, b) : (b))
10244 +
10245 +#define task_vx_mbcap(t, b) \
10246 +       vx_info_mbcap((t)->vx_info, (t)->b)
10247 +
10248 +#define vx_mbcap(b)    task_vx_mbcap(current, b)
10249 +#endif
10250 +
10251 +#define vx_cap_raised(v, c, f) cap_raised(vx_info_mbcaps(v, c), f)
10252 +
10253 +#define vx_capable(b, c) (capable(b) || \
10254 +       (cap_raised(current_cap(), b) && vx_ccaps(c)))
10255 +
10256 +#define nx_capable(b, c) (capable(b) || \
10257 +       (cap_raised(current_cap(), b) && nx_ncaps(c)))
10258 +
10259 +#define vx_task_initpid(t, n) \
10260 +       ((t)->vx_info && \
10261 +       ((t)->vx_info->vx_initpid == (n)))
10262 +
10263 +#define vx_current_initpid(n)  vx_task_initpid(current, n)
10264 +
10265 +
10266 +/* context unshare mask */
10267 +
10268 +#define __vx_umask(v)          ((v)->vx_umask)
10269 +
10270 +#define vx_current_umask()     __vx_umask(current_vx_info())
10271 +
10272 +#define vx_can_unshare(b, f) (capable(b) || \
10273 +       (cap_raised(current_cap(), b) && \
10274 +       !((f) & ~vx_current_umask())))
10275 +
10276 +
10277 +#define __vx_state(v)  ((v) ? ((v)->vx_state) : 0)
10278 +
10279 +#define vx_info_state(v, m)    (__vx_state(v) & (m))
10280 +
10281 +
10282 +#define __nx_state(n)  ((n) ? ((n)->nx_state) : 0)
10283 +
10284 +#define nx_info_state(n, m)    (__nx_state(n) & (m))
10285 +
10286 +#endif
10287 diff -NurpP --minimal linux-2.6.32.6/include/linux/vserver/cacct_cmd.h linux-2.6.32.6-vs2.3.0.36.28/include/linux/vserver/cacct_cmd.h
10288 --- linux-2.6.32.6/include/linux/vserver/cacct_cmd.h    1970-01-01 01:00:00.000000000 +0100
10289 +++ linux-2.6.32.6-vs2.3.0.36.28/include/linux/vserver/cacct_cmd.h      2009-12-03 20:04:56.000000000 +0100
10290 @@ -0,0 +1,23 @@
10291 +#ifndef _VX_CACCT_CMD_H
10292 +#define _VX_CACCT_CMD_H
10293 +
10294 +
10295 +/* virtual host info name commands */
10296 +
10297 +#define VCMD_sock_stat         VC_CMD(VSTAT, 5, 0)
10298 +
10299 +struct vcmd_sock_stat_v0 {
10300 +       uint32_t field;
10301 +       uint32_t count[3];
10302 +       uint64_t total[3];
10303 +};
10304 +
10305 +
10306 +#ifdef __KERNEL__
10307 +
10308 +#include <linux/compiler.h>
10309 +
10310 +extern int vc_sock_stat(struct vx_info *, void __user *);
10311 +
10312 +#endif /* __KERNEL__ */
10313 +#endif /* _VX_CACCT_CMD_H */
10314 diff -NurpP --minimal linux-2.6.32.6/include/linux/vserver/cacct_def.h linux-2.6.32.6-vs2.3.0.36.28/include/linux/vserver/cacct_def.h
10315 --- linux-2.6.32.6/include/linux/vserver/cacct_def.h    1970-01-01 01:00:00.000000000 +0100
10316 +++ linux-2.6.32.6-vs2.3.0.36.28/include/linux/vserver/cacct_def.h      2009-12-03 20:04:56.000000000 +0100
10317 @@ -0,0 +1,43 @@
10318 +#ifndef _VX_CACCT_DEF_H
10319 +#define _VX_CACCT_DEF_H
10320 +
10321 +#include <asm/atomic.h>
10322 +#include <linux/vserver/cacct.h>
10323 +
10324 +
10325 +struct _vx_sock_acc {
10326 +       atomic_long_t count;
10327 +       atomic_long_t total;
10328 +};
10329 +
10330 +/* context sub struct */
10331 +
10332 +struct _vx_cacct {
10333 +       struct _vx_sock_acc sock[VXA_SOCK_SIZE][3];
10334 +       atomic_t slab[8];
10335 +       atomic_t page[6][8];
10336 +};
10337 +
10338 +#ifdef CONFIG_VSERVER_DEBUG
10339 +
10340 +static inline void __dump_vx_cacct(struct _vx_cacct *cacct)
10341 +{
10342 +       int i, j;
10343 +
10344 +       printk("\t_vx_cacct:");
10345 +       for (i = 0; i < 6; i++) {
10346 +               struct _vx_sock_acc *ptr = cacct->sock[i];
10347 +
10348 +               printk("\t [%d] =", i);
10349 +               for (j = 0; j < 3; j++) {
10350 +                       printk(" [%d] = %8lu, %8lu", j,
10351 +                               atomic_long_read(&ptr[j].count),
10352 +                               atomic_long_read(&ptr[j].total));
10353 +               }
10354 +               printk("\n");
10355 +       }
10356 +}
10357 +
10358 +#endif
10359 +
10360 +#endif /* _VX_CACCT_DEF_H */
10361 diff -NurpP --minimal linux-2.6.32.6/include/linux/vserver/cacct.h linux-2.6.32.6-vs2.3.0.36.28/include/linux/vserver/cacct.h
10362 --- linux-2.6.32.6/include/linux/vserver/cacct.h        1970-01-01 01:00:00.000000000 +0100
10363 +++ linux-2.6.32.6-vs2.3.0.36.28/include/linux/vserver/cacct.h  2009-12-03 20:04:56.000000000 +0100
10364 @@ -0,0 +1,15 @@
10365 +#ifndef _VX_CACCT_H
10366 +#define _VX_CACCT_H
10367 +
10368 +
10369 +enum sock_acc_field {
10370 +       VXA_SOCK_UNSPEC = 0,
10371 +       VXA_SOCK_UNIX,
10372 +       VXA_SOCK_INET,
10373 +       VXA_SOCK_INET6,
10374 +       VXA_SOCK_PACKET,
10375 +       VXA_SOCK_OTHER,
10376 +       VXA_SOCK_SIZE   /* array size */
10377 +};
10378 +
10379 +#endif /* _VX_CACCT_H */
10380 diff -NurpP --minimal linux-2.6.32.6/include/linux/vserver/cacct_int.h linux-2.6.32.6-vs2.3.0.36.28/include/linux/vserver/cacct_int.h
10381 --- linux-2.6.32.6/include/linux/vserver/cacct_int.h    1970-01-01 01:00:00.000000000 +0100
10382 +++ linux-2.6.32.6-vs2.3.0.36.28/include/linux/vserver/cacct_int.h      2009-12-03 20:04:56.000000000 +0100
10383 @@ -0,0 +1,21 @@
10384 +#ifndef _VX_CACCT_INT_H
10385 +#define _VX_CACCT_INT_H
10386 +
10387 +
10388 +#ifdef __KERNEL__
10389 +
10390 +static inline
10391 +unsigned long vx_sock_count(struct _vx_cacct *cacct, int type, int pos)
10392 +{
10393 +       return atomic_long_read(&cacct->sock[type][pos].count);
10394 +}
10395 +
10396 +
10397 +static inline
10398 +unsigned long vx_sock_total(struct _vx_cacct *cacct, int type, int pos)
10399 +{
10400 +       return atomic_long_read(&cacct->sock[type][pos].total);
10401 +}
10402 +
10403 +#endif /* __KERNEL__ */
10404 +#endif /* _VX_CACCT_INT_H */
10405 diff -NurpP --minimal linux-2.6.32.6/include/linux/vserver/check.h linux-2.6.32.6-vs2.3.0.36.28/include/linux/vserver/check.h
10406 --- linux-2.6.32.6/include/linux/vserver/check.h        1970-01-01 01:00:00.000000000 +0100
10407 +++ linux-2.6.32.6-vs2.3.0.36.28/include/linux/vserver/check.h  2009-12-03 20:04:56.000000000 +0100
10408 @@ -0,0 +1,89 @@
10409 +#ifndef _VS_CHECK_H
10410 +#define _VS_CHECK_H
10411 +
10412 +
10413 +#define MAX_S_CONTEXT  65535   /* Arbitrary limit */
10414 +
10415 +#ifdef CONFIG_VSERVER_DYNAMIC_IDS
10416 +#define MIN_D_CONTEXT  49152   /* dynamic contexts start here */
10417 +#else
10418 +#define MIN_D_CONTEXT  65536
10419 +#endif
10420 +
10421 +/* check conditions */
10422 +
10423 +#define VS_ADMIN       0x0001
10424 +#define VS_WATCH       0x0002
10425 +#define VS_HIDE                0x0004
10426 +#define VS_HOSTID      0x0008
10427 +
10428 +#define VS_IDENT       0x0010
10429 +#define VS_EQUIV       0x0020
10430 +#define VS_PARENT      0x0040
10431 +#define VS_CHILD       0x0080
10432 +
10433 +#define VS_ARG_MASK    0x00F0
10434 +
10435 +#define VS_DYNAMIC     0x0100
10436 +#define VS_STATIC      0x0200
10437 +
10438 +#define VS_ATR_MASK    0x0F00
10439 +
10440 +#ifdef CONFIG_VSERVER_PRIVACY
10441 +#define VS_ADMIN_P     (0)
10442 +#define VS_WATCH_P     (0)
10443 +#else
10444 +#define VS_ADMIN_P     VS_ADMIN
10445 +#define VS_WATCH_P     VS_WATCH
10446 +#endif
10447 +
10448 +#define VS_HARDIRQ     0x1000
10449 +#define VS_SOFTIRQ     0x2000
10450 +#define VS_IRQ         0x4000
10451 +
10452 +#define VS_IRQ_MASK    0xF000
10453 +
10454 +#include <linux/hardirq.h>
10455 +
10456 +/*
10457 + * check current context for ADMIN/WATCH and
10458 + * optionally against supplied argument
10459 + */
10460 +static inline int __vs_check(int cid, int id, unsigned int mode)
10461 +{
10462 +       if (mode & VS_ARG_MASK) {
10463 +               if ((mode & VS_IDENT) && (id == cid))
10464 +                       return 1;
10465 +       }
10466 +       if (mode & VS_ATR_MASK) {
10467 +               if ((mode & VS_DYNAMIC) &&
10468 +                       (id >= MIN_D_CONTEXT) &&
10469 +                       (id <= MAX_S_CONTEXT))
10470 +                       return 1;
10471 +               if ((mode & VS_STATIC) &&
10472 +                       (id > 1) && (id < MIN_D_CONTEXT))
10473 +                       return 1;
10474 +       }
10475 +       if (mode & VS_IRQ_MASK) {
10476 +               if ((mode & VS_IRQ) && unlikely(in_interrupt()))
10477 +                       return 1;
10478 +               if ((mode & VS_HARDIRQ) && unlikely(in_irq()))
10479 +                       return 1;
10480 +               if ((mode & VS_SOFTIRQ) && unlikely(in_softirq()))
10481 +                       return 1;
10482 +       }
10483 +       return (((mode & VS_ADMIN) && (cid == 0)) ||
10484 +               ((mode & VS_WATCH) && (cid == 1)) ||
10485 +               ((mode & VS_HOSTID) && (id == 0)));
10486 +}
10487 +
10488 +#define vx_check(c, m) __vs_check(vx_current_xid(), c, (m) | VS_IRQ)
10489 +
10490 +#define vx_weak_check(c, m)    ((m) ? vx_check(c, m) : 1)
10491 +
10492 +
10493 +#define nx_check(c, m) __vs_check(nx_current_nid(), c, m)
10494 +
10495 +#define nx_weak_check(c, m)    ((m) ? nx_check(c, m) : 1)
10496 +
10497 +#endif
10498 diff -NurpP --minimal linux-2.6.32.6/include/linux/vserver/context_cmd.h linux-2.6.32.6-vs2.3.0.36.28/include/linux/vserver/context_cmd.h
10499 --- linux-2.6.32.6/include/linux/vserver/context_cmd.h  1970-01-01 01:00:00.000000000 +0100
10500 +++ linux-2.6.32.6-vs2.3.0.36.28/include/linux/vserver/context_cmd.h    2009-12-03 20:04:56.000000000 +0100
10501 @@ -0,0 +1,145 @@
10502 +#ifndef _VX_CONTEXT_CMD_H
10503 +#define _VX_CONTEXT_CMD_H
10504 +
10505 +
10506 +/* vinfo commands */
10507 +
10508 +#define VCMD_task_xid          VC_CMD(VINFO, 1, 0)
10509 +
10510 +#ifdef __KERNEL__
10511 +extern int vc_task_xid(uint32_t);
10512 +
10513 +#endif /* __KERNEL__ */
10514 +
10515 +#define VCMD_vx_info           VC_CMD(VINFO, 5, 0)
10516 +
10517 +struct vcmd_vx_info_v0 {
10518 +       uint32_t xid;
10519 +       uint32_t initpid;
10520 +       /* more to come */
10521 +};
10522 +
10523 +#ifdef __KERNEL__
10524 +extern int vc_vx_info(struct vx_info *, void __user *);
10525 +
10526 +#endif /* __KERNEL__ */
10527 +
10528 +#define VCMD_ctx_stat          VC_CMD(VSTAT, 0, 0)
10529 +
10530 +struct vcmd_ctx_stat_v0 {
10531 +       uint32_t usecnt;
10532 +       uint32_t tasks;
10533 +       /* more to come */
10534 +};
10535 +
10536 +#ifdef __KERNEL__
10537 +extern int vc_ctx_stat(struct vx_info *, void __user *);
10538 +
10539 +#endif /* __KERNEL__ */
10540 +
10541 +/* context commands */
10542 +
10543 +#define VCMD_ctx_create_v0     VC_CMD(VPROC, 1, 0)
10544 +#define VCMD_ctx_create                VC_CMD(VPROC, 1, 1)
10545 +
10546 +struct vcmd_ctx_create {
10547 +       uint64_t flagword;
10548 +};
10549 +
10550 +#define VCMD_ctx_migrate_v0    VC_CMD(PROCMIG, 1, 0)
10551 +#define VCMD_ctx_migrate       VC_CMD(PROCMIG, 1, 1)
10552 +
10553 +struct vcmd_ctx_migrate {
10554 +       uint64_t flagword;
10555 +};
10556 +
10557 +#ifdef __KERNEL__
10558 +extern int vc_ctx_create(uint32_t, void __user *);
10559 +extern int vc_ctx_migrate(struct vx_info *, void __user *);
10560 +
10561 +#endif /* __KERNEL__ */
10562 +
10563 +
10564 +/* flag commands */
10565 +
10566 +#define VCMD_get_cflags                VC_CMD(FLAGS, 1, 0)
10567 +#define VCMD_set_cflags                VC_CMD(FLAGS, 2, 0)
10568 +
10569 +struct vcmd_ctx_flags_v0 {
10570 +       uint64_t flagword;
10571 +       uint64_t mask;
10572 +};
10573 +
10574 +#ifdef __KERNEL__
10575 +extern int vc_get_cflags(struct vx_info *, void __user *);
10576 +extern int vc_set_cflags(struct vx_info *, void __user *);
10577 +
10578 +#endif /* __KERNEL__ */
10579 +
10580 +
10581 +/* context caps commands */
10582 +
10583 +#define VCMD_get_ccaps         VC_CMD(FLAGS, 3, 1)
10584 +#define VCMD_set_ccaps         VC_CMD(FLAGS, 4, 1)
10585 +
10586 +struct vcmd_ctx_caps_v1 {
10587 +       uint64_t ccaps;
10588 +       uint64_t cmask;
10589 +};
10590 +
10591 +#ifdef __KERNEL__
10592 +extern int vc_get_ccaps(struct vx_info *, void __user *);
10593 +extern int vc_set_ccaps(struct vx_info *, void __user *);
10594 +
10595 +#endif /* __KERNEL__ */
10596 +
10597 +
10598 +/* bcaps commands */
10599 +
10600 +#define VCMD_get_bcaps         VC_CMD(FLAGS, 9, 0)
10601 +#define VCMD_set_bcaps         VC_CMD(FLAGS, 10, 0)
10602 +
10603 +struct vcmd_bcaps {
10604 +       uint64_t bcaps;
10605 +       uint64_t bmask;
10606 +};
10607 +
10608 +#ifdef __KERNEL__
10609 +extern int vc_get_bcaps(struct vx_info *, void __user *);
10610 +extern int vc_set_bcaps(struct vx_info *, void __user *);
10611 +
10612 +#endif /* __KERNEL__ */
10613 +
10614 +
10615 +/* umask commands */
10616 +
10617 +#define VCMD_get_umask         VC_CMD(FLAGS, 13, 0)
10618 +#define VCMD_set_umask         VC_CMD(FLAGS, 14, 0)
10619 +
10620 +struct vcmd_umask {
10621 +       uint64_t umask;
10622 +       uint64_t mask;
10623 +};
10624 +
10625 +#ifdef __KERNEL__
10626 +extern int vc_get_umask(struct vx_info *, void __user *);
10627 +extern int vc_set_umask(struct vx_info *, void __user *);
10628 +
10629 +#endif /* __KERNEL__ */
10630 +
10631 +
10632 +/* OOM badness */
10633 +
10634 +#define VCMD_get_badness       VC_CMD(MEMCTRL, 5, 0)
10635 +#define VCMD_set_badness       VC_CMD(MEMCTRL, 6, 0)
10636 +
10637 +struct vcmd_badness_v0 {
10638 +       int64_t bias;
10639 +};
10640 +
10641 +#ifdef __KERNEL__
10642 +extern int vc_get_badness(struct vx_info *, void __user *);
10643 +extern int vc_set_badness(struct vx_info *, void __user *);
10644 +
10645 +#endif /* __KERNEL__ */
10646 +#endif /* _VX_CONTEXT_CMD_H */
10647 diff -NurpP --minimal linux-2.6.32.6/include/linux/vserver/context.h linux-2.6.32.6-vs2.3.0.36.28/include/linux/vserver/context.h
10648 --- linux-2.6.32.6/include/linux/vserver/context.h      1970-01-01 01:00:00.000000000 +0100
10649 +++ linux-2.6.32.6-vs2.3.0.36.28/include/linux/vserver/context.h        2009-12-03 20:04:56.000000000 +0100
10650 @@ -0,0 +1,183 @@
10651 +#ifndef _VX_CONTEXT_H
10652 +#define _VX_CONTEXT_H
10653 +
10654 +#include <linux/types.h>
10655 +#include <linux/capability.h>
10656 +
10657 +
10658 +/* context flags */
10659 +
10660 +#define VXF_INFO_SCHED         0x00000002
10661 +#define VXF_INFO_NPROC         0x00000004
10662 +#define VXF_INFO_PRIVATE       0x00000008
10663 +
10664 +#define VXF_INFO_INIT          0x00000010
10665 +#define VXF_INFO_HIDE          0x00000020
10666 +#define VXF_INFO_ULIMIT                0x00000040
10667 +#define VXF_INFO_NSPACE                0x00000080
10668 +
10669 +#define VXF_SCHED_HARD         0x00000100
10670 +#define VXF_SCHED_PRIO         0x00000200
10671 +#define VXF_SCHED_PAUSE                0x00000400
10672 +
10673 +#define VXF_VIRT_MEM           0x00010000
10674 +#define VXF_VIRT_UPTIME                0x00020000
10675 +#define VXF_VIRT_CPU           0x00040000
10676 +#define VXF_VIRT_LOAD          0x00080000
10677 +#define VXF_VIRT_TIME          0x00100000
10678 +
10679 +#define VXF_HIDE_MOUNT         0x01000000
10680 +/* was VXF_HIDE_NETIF          0x02000000 */
10681 +#define VXF_HIDE_VINFO         0x04000000
10682 +
10683 +#define VXF_STATE_SETUP                (1ULL << 32)
10684 +#define VXF_STATE_INIT         (1ULL << 33)
10685 +#define VXF_STATE_ADMIN                (1ULL << 34)
10686 +
10687 +#define VXF_SC_HELPER          (1ULL << 36)
10688 +#define VXF_REBOOT_KILL                (1ULL << 37)
10689 +#define VXF_PERSISTENT         (1ULL << 38)
10690 +
10691 +#define VXF_FORK_RSS           (1ULL << 48)
10692 +#define VXF_PROLIFIC           (1ULL << 49)
10693 +
10694 +#define VXF_IGNEG_NICE         (1ULL << 52)
10695 +
10696 +#define VXF_ONE_TIME           (0x0007ULL << 32)
10697 +
10698 +#define VXF_INIT_SET           (VXF_STATE_SETUP | VXF_STATE_INIT | VXF_STATE_ADMIN)
10699 +
10700 +
10701 +/* context migration */
10702 +
10703 +#define VXM_SET_INIT           0x00000001
10704 +#define VXM_SET_REAPER         0x00000002
10705 +
10706 +/* context caps */
10707 +
10708 +#define VXC_CAP_MASK           0x00000000
10709 +
10710 +#define VXC_SET_UTSNAME                0x00000001
10711 +#define VXC_SET_RLIMIT         0x00000002
10712 +#define VXC_FS_SECURITY                0x00000004
10713 +#define VXC_TIOCSTI            0x00000010
10714 +
10715 +/* was VXC_RAW_ICMP            0x00000100 */
10716 +#define VXC_SYSLOG             0x00001000
10717 +#define VXC_OOM_ADJUST         0x00002000
10718 +#define VXC_AUDIT_CONTROL      0x00004000
10719 +
10720 +#define VXC_SECURE_MOUNT       0x00010000
10721 +#define VXC_SECURE_REMOUNT     0x00020000
10722 +#define VXC_BINARY_MOUNT       0x00040000
10723 +
10724 +#define VXC_QUOTA_CTL          0x00100000
10725 +#define VXC_ADMIN_MAPPER       0x00200000
10726 +#define VXC_ADMIN_CLOOP                0x00400000
10727 +
10728 +#define VXC_KTHREAD            0x01000000
10729 +#define VXC_NAMESPACE          0x02000000
10730 +
10731 +
10732 +#ifdef __KERNEL__
10733 +
10734 +#include <linux/list.h>
10735 +#include <linux/spinlock.h>
10736 +#include <linux/rcupdate.h>
10737 +
10738 +#include "limit_def.h"
10739 +#include "sched_def.h"
10740 +#include "cvirt_def.h"
10741 +#include "cacct_def.h"
10742 +#include "device_def.h"
10743 +
10744 +#define VX_SPACES      2
10745 +
10746 +struct _vx_info_pc {
10747 +       struct _vx_sched_pc sched_pc;
10748 +       struct _vx_cvirt_pc cvirt_pc;
10749 +};
10750 +
10751 +struct vx_info {
10752 +       struct hlist_node vx_hlist;             /* linked list of contexts */
10753 +       xid_t vx_id;                            /* context id */
10754 +       atomic_t vx_usecnt;                     /* usage count */
10755 +       atomic_t vx_tasks;                      /* tasks count */
10756 +       struct vx_info *vx_parent;              /* parent context */
10757 +       int vx_state;                           /* context state */
10758 +
10759 +       unsigned long vx_nsmask[VX_SPACES];     /* assignment mask */
10760 +       struct nsproxy *vx_nsproxy[VX_SPACES];  /* private namespaces */
10761 +       struct fs_struct *vx_fs[VX_SPACES];     /* private namespace fs */
10762 +
10763 +       uint64_t vx_flags;                      /* context flags */
10764 +       uint64_t vx_ccaps;                      /* context caps (vserver) */
10765 +       kernel_cap_t vx_bcaps;                  /* bounding caps (system) */
10766 +       unsigned long vx_umask;                 /* unshare mask (guest) */
10767 +
10768 +       struct task_struct *vx_reaper;          /* guest reaper process */
10769 +       pid_t vx_initpid;                       /* PID of guest init */
10770 +       int64_t vx_badness_bias;                /* OOM points bias */
10771 +
10772 +       struct _vx_limit limit;                 /* vserver limits */
10773 +       struct _vx_sched sched;                 /* vserver scheduler */
10774 +       struct _vx_cvirt cvirt;                 /* virtual/bias stuff */
10775 +       struct _vx_cacct cacct;                 /* context accounting */
10776 +
10777 +       struct _vx_device dmap;                 /* default device map targets */
10778 +
10779 +#ifndef CONFIG_SMP
10780 +       struct _vx_info_pc info_pc;             /* per cpu data */
10781 +#else
10782 +       struct _vx_info_pc *ptr_pc;             /* per cpu array */
10783 +#endif
10784 +
10785 +       wait_queue_head_t vx_wait;              /* context exit waitqueue */
10786 +       int reboot_cmd;                         /* last sys_reboot() cmd */
10787 +       int exit_code;                          /* last process exit code */
10788 +
10789 +       char vx_name[65];                       /* vserver name */
10790 +};
10791 +
10792 +#ifndef CONFIG_SMP
10793 +#define        vx_ptr_pc(vxi)          (&(vxi)->info_pc)
10794 +#define        vx_per_cpu(vxi, v, id)  vx_ptr_pc(vxi)->v
10795 +#else
10796 +#define        vx_ptr_pc(vxi)          ((vxi)->ptr_pc)
10797 +#define        vx_per_cpu(vxi, v, id)  per_cpu_ptr(vx_ptr_pc(vxi), id)->v
10798 +#endif
10799 +
10800 +#define        vx_cpu(vxi, v)          vx_per_cpu(vxi, v, smp_processor_id())
10801 +
10802 +
10803 +struct vx_info_save {
10804 +       struct vx_info *vxi;
10805 +       xid_t xid;
10806 +};
10807 +
10808 +
10809 +/* status flags */
10810 +
10811 +#define VXS_HASHED     0x0001
10812 +#define VXS_PAUSED     0x0010
10813 +#define VXS_SHUTDOWN   0x0100
10814 +#define VXS_HELPER     0x1000
10815 +#define VXS_RELEASED   0x8000
10816 +
10817 +
10818 +extern void claim_vx_info(struct vx_info *, struct task_struct *);
10819 +extern void release_vx_info(struct vx_info *, struct task_struct *);
10820 +
10821 +extern struct vx_info *lookup_vx_info(int);
10822 +extern struct vx_info *lookup_or_create_vx_info(int);
10823 +
10824 +extern int get_xid_list(int, unsigned int *, int);
10825 +extern int xid_is_hashed(xid_t);
10826 +
10827 +extern int vx_migrate_task(struct task_struct *, struct vx_info *, int);
10828 +
10829 +extern long vs_state_change(struct vx_info *, unsigned int);
10830 +
10831 +
10832 +#endif /* __KERNEL__ */
10833 +#endif /* _VX_CONTEXT_H */
10834 diff -NurpP --minimal linux-2.6.32.6/include/linux/vserver/cvirt_cmd.h linux-2.6.32.6-vs2.3.0.36.28/include/linux/vserver/cvirt_cmd.h
10835 --- linux-2.6.32.6/include/linux/vserver/cvirt_cmd.h    1970-01-01 01:00:00.000000000 +0100
10836 +++ linux-2.6.32.6-vs2.3.0.36.28/include/linux/vserver/cvirt_cmd.h      2009-12-03 20:04:56.000000000 +0100
10837 @@ -0,0 +1,53 @@
10838 +#ifndef _VX_CVIRT_CMD_H
10839 +#define _VX_CVIRT_CMD_H
10840 +
10841 +
10842 +/* virtual host info name commands */
10843 +
10844 +#define VCMD_set_vhi_name      VC_CMD(VHOST, 1, 0)
10845 +#define VCMD_get_vhi_name      VC_CMD(VHOST, 2, 0)
10846 +
10847 +struct vcmd_vhi_name_v0 {
10848 +       uint32_t field;
10849 +       char name[65];
10850 +};
10851 +
10852 +
10853 +enum vhi_name_field {
10854 +       VHIN_CONTEXT = 0,
10855 +       VHIN_SYSNAME,
10856 +       VHIN_NODENAME,
10857 +       VHIN_RELEASE,
10858 +       VHIN_VERSION,
10859 +       VHIN_MACHINE,
10860 +       VHIN_DOMAINNAME,
10861 +};
10862 +
10863 +
10864 +#ifdef __KERNEL__
10865 +
10866 +#include <linux/compiler.h>
10867 +
10868 +extern int vc_set_vhi_name(struct vx_info *, void __user *);
10869 +extern int vc_get_vhi_name(struct vx_info *, void __user *);
10870 +
10871 +#endif /* __KERNEL__ */
10872 +
10873 +#define VCMD_virt_stat         VC_CMD(VSTAT, 3, 0)
10874 +
10875 +struct vcmd_virt_stat_v0 {
10876 +       uint64_t offset;
10877 +       uint64_t uptime;
10878 +       uint32_t nr_threads;
10879 +       uint32_t nr_running;
10880 +       uint32_t nr_uninterruptible;
10881 +       uint32_t nr_onhold;
10882 +       uint32_t nr_forks;
10883 +       uint32_t load[3];
10884 +};
10885 +
10886 +#ifdef __KERNEL__
10887 +extern int vc_virt_stat(struct vx_info *, void __user *);
10888 +
10889 +#endif /* __KERNEL__ */
10890 +#endif /* _VX_CVIRT_CMD_H */
10891 diff -NurpP --minimal linux-2.6.32.6/include/linux/vserver/cvirt_def.h linux-2.6.32.6-vs2.3.0.36.28/include/linux/vserver/cvirt_def.h
10892 --- linux-2.6.32.6/include/linux/vserver/cvirt_def.h    1970-01-01 01:00:00.000000000 +0100
10893 +++ linux-2.6.32.6-vs2.3.0.36.28/include/linux/vserver/cvirt_def.h      2009-12-03 20:04:56.000000000 +0100
10894 @@ -0,0 +1,80 @@
10895 +#ifndef _VX_CVIRT_DEF_H
10896 +#define _VX_CVIRT_DEF_H
10897 +
10898 +#include <linux/jiffies.h>
10899 +#include <linux/spinlock.h>
10900 +#include <linux/wait.h>
10901 +#include <linux/time.h>
10902 +#include <asm/atomic.h>
10903 +
10904 +
10905 +struct _vx_usage_stat {
10906 +       uint64_t user;
10907 +       uint64_t nice;
10908 +       uint64_t system;
10909 +       uint64_t softirq;
10910 +       uint64_t irq;
10911 +       uint64_t idle;
10912 +       uint64_t iowait;
10913 +};
10914 +
10915 +struct _vx_syslog {
10916 +       wait_queue_head_t log_wait;
10917 +       spinlock_t logbuf_lock;         /* lock for the log buffer */
10918 +
10919 +       unsigned long log_start;        /* next char to be read by syslog() */
10920 +       unsigned long con_start;        /* next char to be sent to consoles */
10921 +       unsigned long log_end;  /* most-recently-written-char + 1 */
10922 +       unsigned long logged_chars;     /* #chars since last read+clear operation */
10923 +
10924 +       char log_buf[1024];
10925 +};
10926 +
10927 +
10928 +/* context sub struct */
10929 +
10930 +struct _vx_cvirt {
10931 +       atomic_t nr_threads;            /* number of current threads */
10932 +       atomic_t nr_running;            /* number of running threads */
10933 +       atomic_t nr_uninterruptible;    /* number of uninterruptible threads */
10934 +
10935 +       atomic_t nr_onhold;             /* processes on hold */
10936 +       uint32_t onhold_last;           /* jiffies when put on hold */
10937 +
10938 +       struct timeval bias_tv;         /* time offset to the host */
10939 +       struct timespec bias_idle;
10940 +       struct timespec bias_uptime;    /* context creation point */
10941 +       uint64_t bias_clock;            /* offset in clock_t */
10942 +
10943 +       spinlock_t load_lock;           /* lock for the load averages */
10944 +       atomic_t load_updates;          /* nr of load updates done so far */
10945 +       uint32_t load_last;             /* last time load was calculated */
10946 +       uint32_t load[3];               /* load averages 1,5,15 */
10947 +
10948 +       atomic_t total_forks;           /* number of forks so far */
10949 +
10950 +       struct _vx_syslog syslog;
10951 +};
10952 +
10953 +struct _vx_cvirt_pc {
10954 +       struct _vx_usage_stat cpustat;
10955 +};
10956 +
10957 +
10958 +#ifdef CONFIG_VSERVER_DEBUG
10959 +
10960 +static inline void __dump_vx_cvirt(struct _vx_cvirt *cvirt)
10961 +{
10962 +       printk("\t_vx_cvirt:\n");
10963 +       printk("\t threads: %4d, %4d, %4d, %4d\n",
10964 +               atomic_read(&cvirt->nr_threads),
10965 +               atomic_read(&cvirt->nr_running),
10966 +               atomic_read(&cvirt->nr_uninterruptible),
10967 +               atomic_read(&cvirt->nr_onhold));
10968 +       /* add rest here */
10969 +       printk("\t total_forks = %d\n", atomic_read(&cvirt->total_forks));
10970 +}
10971 +
10972 +#endif
10973 +
10974 +#endif /* _VX_CVIRT_DEF_H */
10975 diff -NurpP --minimal linux-2.6.32.6/include/linux/vserver/cvirt.h linux-2.6.32.6-vs2.3.0.36.28/include/linux/vserver/cvirt.h
10976 --- linux-2.6.32.6/include/linux/vserver/cvirt.h        1970-01-01 01:00:00.000000000 +0100
10977 +++ linux-2.6.32.6-vs2.3.0.36.28/include/linux/vserver/cvirt.h  2009-12-03 20:04:56.000000000 +0100
10978 @@ -0,0 +1,20 @@
10979 +#ifndef _VX_CVIRT_H
10980 +#define _VX_CVIRT_H
10981 +
10982 +
10983 +#ifdef __KERNEL__
10984 +
10985 +struct timespec;
10986 +
10987 +void vx_vsi_uptime(struct timespec *, struct timespec *);
10988 +
10989 +
10990 +struct vx_info;
10991 +
10992 +void vx_update_load(struct vx_info *);
10993 +
10994 +
10995 +int vx_do_syslog(int, char __user *, int);
10996 +
10997 +#endif /* __KERNEL__ */
10998 +#endif /* _VX_CVIRT_H */
10999 diff -NurpP --minimal linux-2.6.32.6/include/linux/vserver/debug_cmd.h linux-2.6.32.6-vs2.3.0.36.28/include/linux/vserver/debug_cmd.h
11000 --- linux-2.6.32.6/include/linux/vserver/debug_cmd.h    1970-01-01 01:00:00.000000000 +0100
11001 +++ linux-2.6.32.6-vs2.3.0.36.28/include/linux/vserver/debug_cmd.h      2009-12-03 20:04:56.000000000 +0100
11002 @@ -0,0 +1,58 @@
11003 +#ifndef _VX_DEBUG_CMD_H
11004 +#define _VX_DEBUG_CMD_H
11005 +
11006 +
11007 +/* debug commands */
11008 +
11009 +#define VCMD_dump_history      VC_CMD(DEBUG, 1, 0)
11010 +
11011 +#define VCMD_read_history      VC_CMD(DEBUG, 5, 0)
11012 +#define VCMD_read_monitor      VC_CMD(DEBUG, 6, 0)
11013 +
11014 +struct  vcmd_read_history_v0 {
11015 +       uint32_t index;
11016 +       uint32_t count;
11017 +       char __user *data;
11018 +};
11019 +
11020 +struct  vcmd_read_monitor_v0 {
11021 +       uint32_t index;
11022 +       uint32_t count;
11023 +       char __user *data;
11024 +};
11025 +
11026 +
11027 +#ifdef __KERNEL__
11028 +
11029 +#ifdef CONFIG_COMPAT
11030 +
11031 +#include <asm/compat.h>
11032 +
11033 +struct vcmd_read_history_v0_x32 {
11034 +       uint32_t index;
11035 +       uint32_t count;
11036 +       compat_uptr_t data_ptr;
11037 +};
11038 +
11039 +struct vcmd_read_monitor_v0_x32 {
11040 +       uint32_t index;
11041 +       uint32_t count;
11042 +       compat_uptr_t data_ptr;
11043 +};
11044 +
11045 +#endif  /* CONFIG_COMPAT */
11046 +
11047 +extern int vc_dump_history(uint32_t);
11048 +
11049 +extern int vc_read_history(uint32_t, void __user *);
11050 +extern int vc_read_monitor(uint32_t, void __user *);
11051 +
11052 +#ifdef CONFIG_COMPAT
11053 +
11054 +extern int vc_read_history_x32(uint32_t, void __user *);
11055 +extern int vc_read_monitor_x32(uint32_t, void __user *);
11056 +
11057 +#endif  /* CONFIG_COMPAT */
11058 +
11059 +#endif /* __KERNEL__ */
11060 +#endif /* _VX_DEBUG_CMD_H */
11061 diff -NurpP --minimal linux-2.6.32.6/include/linux/vserver/debug.h linux-2.6.32.6-vs2.3.0.36.28/include/linux/vserver/debug.h
11062 --- linux-2.6.32.6/include/linux/vserver/debug.h        1970-01-01 01:00:00.000000000 +0100
11063 +++ linux-2.6.32.6-vs2.3.0.36.28/include/linux/vserver/debug.h  2009-12-03 20:04:56.000000000 +0100
11064 @@ -0,0 +1,127 @@
11065 +#ifndef _VX_DEBUG_H
11066 +#define _VX_DEBUG_H
11067 +
11068 +
11069 +#define VXD_CBIT(n, m) (vx_debug_ ## n & (1 << (m)))
11070 +#define VXD_CMIN(n, m) (vx_debug_ ## n > (m))
11071 +#define VXD_MASK(n, m) (vx_debug_ ## n & (m))
11072 +
11073 +#define VXD_DEV(d)     (d), (d)->bd_inode->i_ino,              \
11074 +                       imajor((d)->bd_inode), iminor((d)->bd_inode)
11075 +#define VXF_DEV                "%p[%lu,%d:%d]"
11076 +
11077 +
11078 +#define vxd_path(p)                                            \
11079 +       ({ static char _buffer[PATH_MAX];                       \
11080 +          d_path(p, _buffer, sizeof(_buffer)); })
11081 +
11082 +#define vxd_cond_path(n)                                       \
11083 +       ((n) ? vxd_path(&(n)->path) : "<null>" )
11084 +
11085 +
11086 +#ifdef CONFIG_VSERVER_DEBUG
11087 +
11088 +extern unsigned int vx_debug_switch;
11089 +extern unsigned int vx_debug_xid;
11090 +extern unsigned int vx_debug_nid;
11091 +extern unsigned int vx_debug_tag;
11092 +extern unsigned int vx_debug_net;
11093 +extern unsigned int vx_debug_limit;
11094 +extern unsigned int vx_debug_cres;
11095 +extern unsigned int vx_debug_dlim;
11096 +extern unsigned int vx_debug_quota;
11097 +extern unsigned int vx_debug_cvirt;
11098 +extern unsigned int vx_debug_space;
11099 +extern unsigned int vx_debug_misc;
11100 +
11101 +
11102 +#define VX_LOGLEVEL    "vxD: "
11103 +#define VX_PROC_FMT    "%p: "
11104 +#define VX_PROCESS     current
11105 +
11106 +#define vxdprintk(c, f, x...)                                  \
11107 +       do {                                                    \
11108 +               if (c)                                          \
11109 +                       printk(VX_LOGLEVEL VX_PROC_FMT f "\n",  \
11110 +                               VX_PROCESS , ##x);              \
11111 +       } while (0)
11112 +
11113 +#define vxlprintk(c, f, x...)                                  \
11114 +       do {                                                    \
11115 +               if (c)                                          \
11116 +                       printk(VX_LOGLEVEL f " @%s:%d\n", x);   \
11117 +       } while (0)
11118 +
11119 +#define vxfprintk(c, f, x...)                                  \
11120 +       do {                                                    \
11121 +               if (c)                                          \
11122 +                       printk(VX_LOGLEVEL f " %s@%s:%d\n", x); \
11123 +       } while (0)
11124 +
11125 +
11126 +struct vx_info;
11127 +
11128 +void dump_vx_info(struct vx_info *, int);
11129 +void dump_vx_info_inactive(int);
11130 +
11131 +#else  /* CONFIG_VSERVER_DEBUG */
11132 +
11133 +#define vx_debug_switch 0
11134 +#define vx_debug_xid   0
11135 +#define vx_debug_nid   0
11136 +#define vx_debug_tag   0
11137 +#define vx_debug_net   0
11138 +#define vx_debug_limit 0
11139 +#define vx_debug_cres  0
11140 +#define vx_debug_dlim  0
11141 +#define vx_debug_cvirt 0
11142 +
11143 +#define vxdprintk(x...) do { } while (0)
11144 +#define vxlprintk(x...) do { } while (0)
11145 +#define vxfprintk(x...) do { } while (0)
11146 +
11147 +#endif /* CONFIG_VSERVER_DEBUG */
11148 +
11149 +
11150 +#ifdef CONFIG_VSERVER_WARN
11151 +
11152 +#define VX_WARNLEVEL   KERN_WARNING "vxW: "
11153 +#define VX_WARN_TASK   "[»%s«,%u:#%u|%u|%u] "
11154 +#define VX_WARN_XID    "[xid #%u] "
11155 +#define VX_WARN_NID    "[nid #%u] "
11156 +#define VX_WARN_TAG    "[tag #%u] "
11157 +
11158 +#define vxwprintk(c, f, x...)                                  \
11159 +       do {                                                    \
11160 +               if (c)                                          \
11161 +                       printk(VX_WARNLEVEL f "\n", ##x);       \
11162 +       } while (0)
11163 +
11164 +#else  /* CONFIG_VSERVER_WARN */
11165 +
11166 +#define vxwprintk(x...) do { } while (0)
11167 +
11168 +#endif /* CONFIG_VSERVER_WARN */
11169 +
11170 +#define vxwprintk_task(c, f, x...)                             \
11171 +       vxwprintk(c, VX_WARN_TASK f,                            \
11172 +               current->comm, current->pid,                    \
11173 +               current->xid, current->nid, current->tag, ##x)
11174 +#define vxwprintk_xid(c, f, x...)                              \
11175 +       vxwprintk(c, VX_WARN_XID f, current->xid, x)
11176 +#define vxwprintk_nid(c, f, x...)                              \
11177 +       vxwprintk(c, VX_WARN_NID f, current->nid, x)
11178 +#define vxwprintk_tag(c, f, x...)                              \
11179 +       vxwprintk(c, VX_WARN_TAG f, current->tag, x)
11180 +
11181 +#ifdef CONFIG_VSERVER_DEBUG
11182 +#define vxd_assert_lock(l)     assert_spin_locked(l)
11183 +#define vxd_assert(c, f, x...) vxlprintk(!(c), \
11184 +       "assertion [" f "] failed.", ##x, __FILE__, __LINE__)
11185 +#else
11186 +#define vxd_assert_lock(l)     do { } while (0)
11187 +#define vxd_assert(c, f, x...) do { } while (0)
11188 +#endif
11189 +
11190 +
11191 +#endif /* _VX_DEBUG_H */
11192 diff -NurpP --minimal linux-2.6.32.6/include/linux/vserver/device_cmd.h linux-2.6.32.6-vs2.3.0.36.28/include/linux/vserver/device_cmd.h
11193 --- linux-2.6.32.6/include/linux/vserver/device_cmd.h   1970-01-01 01:00:00.000000000 +0100
11194 +++ linux-2.6.32.6-vs2.3.0.36.28/include/linux/vserver/device_cmd.h     2009-12-03 20:04:56.000000000 +0100
11195 @@ -0,0 +1,44 @@
11196 +#ifndef _VX_DEVICE_CMD_H
11197 +#define _VX_DEVICE_CMD_H
11198 +
11199 +
11200 +/*  device vserver commands */
11201 +
11202 +#define VCMD_set_mapping       VC_CMD(DEVICE, 1, 0)
11203 +#define VCMD_unset_mapping     VC_CMD(DEVICE, 2, 0)
11204 +
11205 +struct vcmd_set_mapping_v0 {
11206 +       const char __user *device;
11207 +       const char __user *target;
11208 +       uint32_t flags;
11209 +};
11210 +
11211 +
11212 +#ifdef __KERNEL__
11213 +
11214 +#ifdef CONFIG_COMPAT
11215 +
11216 +#include <asm/compat.h>
11217 +
11218 +struct vcmd_set_mapping_v0_x32 {
11219 +       compat_uptr_t device_ptr;
11220 +       compat_uptr_t target_ptr;
11221 +       uint32_t flags;
11222 +};
11223 +
11224 +#endif /* CONFIG_COMPAT */
11225 +
11226 +#include <linux/compiler.h>
11227 +
11228 +extern int vc_set_mapping(struct vx_info *, void __user *);
11229 +extern int vc_unset_mapping(struct vx_info *, void __user *);
11230 +
11231 +#ifdef CONFIG_COMPAT
11232 +
11233 +extern int vc_set_mapping_x32(struct vx_info *, void __user *);
11234 +extern int vc_unset_mapping_x32(struct vx_info *, void __user *);
11235 +
11236 +#endif /* CONFIG_COMPAT */
11237 +
11238 +#endif /* __KERNEL__ */
11239 +#endif /* _VX_DEVICE_CMD_H */
11240 diff -NurpP --minimal linux-2.6.32.6/include/linux/vserver/device_def.h linux-2.6.32.6-vs2.3.0.36.28/include/linux/vserver/device_def.h
11241 --- linux-2.6.32.6/include/linux/vserver/device_def.h   1970-01-01 01:00:00.000000000 +0100
11242 +++ linux-2.6.32.6-vs2.3.0.36.28/include/linux/vserver/device_def.h     2009-12-03 20:04:56.000000000 +0100
11243 @@ -0,0 +1,17 @@
11244 +#ifndef _VX_DEVICE_DEF_H
11245 +#define _VX_DEVICE_DEF_H
11246 +
11247 +#include <linux/types.h>
11248 +
11249 +struct vx_dmap_target {
11250 +       dev_t target;
11251 +       uint32_t flags;
11252 +};
11253 +
11254 +struct _vx_device {
11255 +#ifdef CONFIG_VSERVER_DEVICE
11256 +       struct vx_dmap_target targets[2];
11257 +#endif
11258 +};
11259 +
11260 +#endif /* _VX_DEVICE_DEF_H */
11261 diff -NurpP --minimal linux-2.6.32.6/include/linux/vserver/device.h linux-2.6.32.6-vs2.3.0.36.28/include/linux/vserver/device.h
11262 --- linux-2.6.32.6/include/linux/vserver/device.h       1970-01-01 01:00:00.000000000 +0100
11263 +++ linux-2.6.32.6-vs2.3.0.36.28/include/linux/vserver/device.h 2009-12-03 20:04:56.000000000 +0100
11264 @@ -0,0 +1,15 @@
11265 +#ifndef _VX_DEVICE_H
11266 +#define _VX_DEVICE_H
11267 +
11268 +
11269 +#define DATTR_CREATE   0x00000001
11270 +#define DATTR_OPEN     0x00000002
11271 +
11272 +#define DATTR_REMAP    0x00000010
11273 +
11274 +#define DATTR_MASK     0x00000013
11275 +
11276 +
11277 +#else  /* _VX_DEVICE_H */
11278 +#warning duplicate inclusion
11279 +#endif /* _VX_DEVICE_H */
11280 diff -NurpP --minimal linux-2.6.32.6/include/linux/vserver/dlimit_cmd.h linux-2.6.32.6-vs2.3.0.36.28/include/linux/vserver/dlimit_cmd.h
11281 --- linux-2.6.32.6/include/linux/vserver/dlimit_cmd.h   1970-01-01 01:00:00.000000000 +0100
11282 +++ linux-2.6.32.6-vs2.3.0.36.28/include/linux/vserver/dlimit_cmd.h     2009-12-10 16:43:43.000000000 +0100
11283 @@ -0,0 +1,109 @@
11284 +#ifndef _VX_DLIMIT_CMD_H
11285 +#define _VX_DLIMIT_CMD_H
11286 +
11287 +
11288 +/*  dlimit vserver commands */
11289 +
11290 +#define VCMD_add_dlimit                VC_CMD(DLIMIT, 1, 0)
11291 +#define VCMD_rem_dlimit                VC_CMD(DLIMIT, 2, 0)
11292 +
11293 +#define VCMD_set_dlimit                VC_CMD(DLIMIT, 5, 0)
11294 +#define VCMD_get_dlimit                VC_CMD(DLIMIT, 6, 0)
11295 +
11296 +struct vcmd_ctx_dlimit_base_v0 {
11297 +       const char __user *name;
11298 +       uint32_t flags;
11299 +};
11300 +
11301 +struct vcmd_ctx_dlimit_v0 {
11302 +       const char __user *name;
11303 +       uint32_t space_used;                    /* used space in kbytes */
11304 +       uint32_t space_total;                   /* maximum space in kbytes */
11305 +       uint32_t inodes_used;                   /* used inodes */
11306 +       uint32_t inodes_total;                  /* maximum inodes */
11307 +       uint32_t reserved;                      /* reserved for root in % */
11308 +       uint32_t flags;
11309 +};
11310 +
11311 +#define CDLIM_UNSET            ((uint32_t)0UL)
11312 +#define CDLIM_INFINITY         ((uint32_t)~0UL)
11313 +#define CDLIM_KEEP             ((uint32_t)~1UL)
11314 +
11315 +#define DLIME_UNIT     0
11316 +#define DLIME_KILO     1
11317 +#define DLIME_MEGA     2
11318 +#define DLIME_GIGA     3
11319 +
11320 +#define DLIMF_SHIFT    0x10
11321 +
11322 +#define DLIMS_USED     0
11323 +#define DLIMS_TOTAL    2
11324 +
11325 +static inline
11326 +uint64_t dlimit_space_32to64(uint32_t val, uint32_t flags, int shift)
11327 +{
11328 +       int exp = (flags & DLIMF_SHIFT) ?
11329 +               (flags >> shift) & DLIME_GIGA : DLIME_KILO;
11330 +       return ((uint64_t)val) << (10 * exp);
11331 +}
11332 +
11333 +static inline
11334 +uint32_t dlimit_space_64to32(uint64_t val, uint32_t *flags, int shift)
11335 +{
11336 +       int exp = 0;
11337 +
11338 +       if (*flags & DLIMF_SHIFT) {
11339 +               while (val > (1LL << 32) && (exp < 3)) {
11340 +                       val >>= 10;
11341 +                       exp++;
11342 +               }
11343 +               *flags &= ~(DLIME_GIGA << shift);
11344 +               *flags |= exp << shift;
11345 +       } else
11346 +               val >>= 10;
11347 +       return val;
11348 +}
11349 +
11350 +#ifdef __KERNEL__
11351 +
11352 +#ifdef CONFIG_COMPAT
11353 +
11354 +#include <asm/compat.h>
11355 +
11356 +struct vcmd_ctx_dlimit_base_v0_x32 {
11357 +       compat_uptr_t name_ptr;
11358 +       uint32_t flags;
11359 +};
11360 +
11361 +struct vcmd_ctx_dlimit_v0_x32 {
11362 +       compat_uptr_t name_ptr;
11363 +       uint32_t space_used;                    /* used space in kbytes */
11364 +       uint32_t space_total;                   /* maximum space in kbytes */
11365 +       uint32_t inodes_used;                   /* used inodes */
11366 +       uint32_t inodes_total;                  /* maximum inodes */
11367 +       uint32_t reserved;                      /* reserved for root in % */
11368 +       uint32_t flags;
11369 +};
11370 +
11371 +#endif /* CONFIG_COMPAT */
11372 +
11373 +#include <linux/compiler.h>
11374 +
11375 +extern int vc_add_dlimit(uint32_t, void __user *);
11376 +extern int vc_rem_dlimit(uint32_t, void __user *);
11377 +
11378 +extern int vc_set_dlimit(uint32_t, void __user *);
11379 +extern int vc_get_dlimit(uint32_t, void __user *);
11380 +
11381 +#ifdef CONFIG_COMPAT
11382 +
11383 +extern int vc_add_dlimit_x32(uint32_t, void __user *);
11384 +extern int vc_rem_dlimit_x32(uint32_t, void __user *);
11385 +
11386 +extern int vc_set_dlimit_x32(uint32_t, void __user *);
11387 +extern int vc_get_dlimit_x32(uint32_t, void __user *);
11388 +
11389 +#endif /* CONFIG_COMPAT */
11390 +
11391 +#endif /* __KERNEL__ */
11392 +#endif /* _VX_DLIMIT_CMD_H */
11393 diff -NurpP --minimal linux-2.6.32.6/include/linux/vserver/dlimit.h linux-2.6.32.6-vs2.3.0.36.28/include/linux/vserver/dlimit.h
11394 --- linux-2.6.32.6/include/linux/vserver/dlimit.h       1970-01-01 01:00:00.000000000 +0100
11395 +++ linux-2.6.32.6-vs2.3.0.36.28/include/linux/vserver/dlimit.h 2009-12-03 20:04:56.000000000 +0100
11396 @@ -0,0 +1,54 @@
11397 +#ifndef _VX_DLIMIT_H
11398 +#define _VX_DLIMIT_H
11399 +
11400 +#include "switch.h"
11401 +
11402 +
11403 +#ifdef __KERNEL__
11404 +
11405 +/*      keep in sync with CDLIM_INFINITY       */
11406 +
11407 +#define DLIM_INFINITY          (~0ULL)
11408 +
11409 +#include <linux/spinlock.h>
11410 +#include <linux/rcupdate.h>
11411 +
11412 +struct super_block;
11413 +
11414 +struct dl_info {
11415 +       struct hlist_node dl_hlist;             /* linked list of contexts */
11416 +       struct rcu_head dl_rcu;                 /* the rcu head */
11417 +       tag_t dl_tag;                           /* context tag */
11418 +       atomic_t dl_usecnt;                     /* usage count */
11419 +       atomic_t dl_refcnt;                     /* reference count */
11420 +
11421 +       struct super_block *dl_sb;              /* associated superblock */
11422 +
11423 +       spinlock_t dl_lock;                     /* protect the values */
11424 +
11425 +       unsigned long long dl_space_used;       /* used space in bytes */
11426 +       unsigned long long dl_space_total;      /* maximum space in bytes */
11427 +       unsigned long dl_inodes_used;           /* used inodes */
11428 +       unsigned long dl_inodes_total;          /* maximum inodes */
11429 +
11430 +       unsigned int dl_nrlmult;                /* non root limit mult */
11431 +};
11432 +
11433 +struct rcu_head;
11434 +
11435 +extern void rcu_free_dl_info(struct rcu_head *);
11436 +extern void unhash_dl_info(struct dl_info *);
11437 +
11438 +extern struct dl_info *locate_dl_info(struct super_block *, tag_t);
11439 +
11440 +
11441 +struct kstatfs;
11442 +
11443 +extern void vx_vsi_statfs(struct super_block *, struct kstatfs *);
11444 +
11445 +typedef uint64_t dlsize_t;
11446 +
11447 +#endif /* __KERNEL__ */
11448 +#else  /* _VX_DLIMIT_H */
11449 +#warning duplicate inclusion
11450 +#endif /* _VX_DLIMIT_H */
11451 diff -NurpP --minimal linux-2.6.32.6/include/linux/vserver/global.h linux-2.6.32.6-vs2.3.0.36.28/include/linux/vserver/global.h
11452 --- linux-2.6.32.6/include/linux/vserver/global.h       1970-01-01 01:00:00.000000000 +0100
11453 +++ linux-2.6.32.6-vs2.3.0.36.28/include/linux/vserver/global.h 2009-12-03 20:04:56.000000000 +0100
11454 @@ -0,0 +1,19 @@
11455 +#ifndef _VX_GLOBAL_H
11456 +#define _VX_GLOBAL_H
11457 +
11458 +
11459 +extern atomic_t vx_global_ctotal;
11460 +extern atomic_t vx_global_cactive;
11461 +
11462 +extern atomic_t nx_global_ctotal;
11463 +extern atomic_t nx_global_cactive;
11464 +
11465 +extern atomic_t vs_global_nsproxy;
11466 +extern atomic_t vs_global_fs;
11467 +extern atomic_t vs_global_mnt_ns;
11468 +extern atomic_t vs_global_uts_ns;
11469 +extern atomic_t vs_global_user_ns;
11470 +extern atomic_t vs_global_pid_ns;
11471 +
11472 +
11473 +#endif /* _VX_GLOBAL_H */
11474 diff -NurpP --minimal linux-2.6.32.6/include/linux/vserver/history.h linux-2.6.32.6-vs2.3.0.36.28/include/linux/vserver/history.h
11475 --- linux-2.6.32.6/include/linux/vserver/history.h      1970-01-01 01:00:00.000000000 +0100
11476 +++ linux-2.6.32.6-vs2.3.0.36.28/include/linux/vserver/history.h        2009-12-03 20:04:56.000000000 +0100
11477 @@ -0,0 +1,197 @@
11478 +#ifndef _VX_HISTORY_H
11479 +#define _VX_HISTORY_H
11480 +
11481 +
11482 +enum {
11483 +       VXH_UNUSED = 0,
11484 +       VXH_THROW_OOPS = 1,
11485 +
11486 +       VXH_GET_VX_INFO,
11487 +       VXH_PUT_VX_INFO,
11488 +       VXH_INIT_VX_INFO,
11489 +       VXH_SET_VX_INFO,
11490 +       VXH_CLR_VX_INFO,
11491 +       VXH_CLAIM_VX_INFO,
11492 +       VXH_RELEASE_VX_INFO,
11493 +       VXH_ALLOC_VX_INFO,
11494 +       VXH_DEALLOC_VX_INFO,
11495 +       VXH_HASH_VX_INFO,
11496 +       VXH_UNHASH_VX_INFO,
11497 +       VXH_LOC_VX_INFO,
11498 +       VXH_LOOKUP_VX_INFO,
11499 +       VXH_CREATE_VX_INFO,
11500 +};
11501 +
11502 +struct _vxhe_vxi {
11503 +       struct vx_info *ptr;
11504 +       unsigned xid;
11505 +       unsigned usecnt;
11506 +       unsigned tasks;
11507 +};
11508 +
11509 +struct _vxhe_set_clr {
11510 +       void *data;
11511 +};
11512 +
11513 +struct _vxhe_loc_lookup {
11514 +       unsigned arg;
11515 +};
11516 +
11517 +struct _vx_hist_entry {
11518 +       void *loc;
11519 +       unsigned short seq;
11520 +       unsigned short type;
11521 +       struct _vxhe_vxi vxi;
11522 +       union {
11523 +               struct _vxhe_set_clr sc;
11524 +               struct _vxhe_loc_lookup ll;
11525 +       };
11526 +};
11527 +
11528 +#ifdef CONFIG_VSERVER_HISTORY
11529 +
11530 +extern unsigned volatile int vxh_active;
11531 +
11532 +struct _vx_hist_entry *vxh_advance(void *loc);
11533 +
11534 +
11535 +static inline
11536 +void   __vxh_copy_vxi(struct _vx_hist_entry *entry, struct vx_info *vxi)
11537 +{
11538 +       entry->vxi.ptr = vxi;
11539 +       if (vxi) {
11540 +               entry->vxi.usecnt = atomic_read(&vxi->vx_usecnt);
11541 +               entry->vxi.tasks = atomic_read(&vxi->vx_tasks);
11542 +               entry->vxi.xid = vxi->vx_id;
11543 +       }
11544 +}
11545 +
11546 +
11547 +#define        __HERE__ current_text_addr()
11548 +
11549 +#define __VXH_BODY(__type, __data, __here)     \
11550 +       struct _vx_hist_entry *entry;           \
11551 +                                               \
11552 +       preempt_disable();                      \
11553 +       entry = vxh_advance(__here);            \
11554 +       __data;                                 \
11555 +       entry->type = __type;                   \
11556 +       preempt_enable();
11557 +
11558 +
11559 +       /* pass vxi only */
11560 +
11561 +#define __VXH_SMPL                             \
11562 +       __vxh_copy_vxi(entry, vxi)
11563 +
11564 +static inline
11565 +void   __vxh_smpl(struct vx_info *vxi, int __type, void *__here)
11566 +{
11567 +       __VXH_BODY(__type, __VXH_SMPL, __here)
11568 +}
11569 +
11570 +       /* pass vxi and data (void *) */
11571 +
11572 +#define __VXH_DATA                             \
11573 +       __vxh_copy_vxi(entry, vxi);             \
11574 +       entry->sc.data = data
11575 +
11576 +static inline
11577 +void   __vxh_data(struct vx_info *vxi, void *data,
11578 +                       int __type, void *__here)
11579 +{
11580 +       __VXH_BODY(__type, __VXH_DATA, __here)
11581 +}
11582 +
11583 +       /* pass vxi and arg (long) */
11584 +
11585 +#define __VXH_LONG                             \
11586 +       __vxh_copy_vxi(entry, vxi);             \
11587 +       entry->ll.arg = arg
11588 +
11589 +static inline
11590 +void   __vxh_long(struct vx_info *vxi, long arg,
11591 +                       int __type, void *__here)
11592 +{
11593 +       __VXH_BODY(__type, __VXH_LONG, __here)
11594 +}
11595 +
11596 +
11597 +static inline
11598 +void   __vxh_throw_oops(void *__here)
11599 +{
11600 +       __VXH_BODY(VXH_THROW_OOPS, {}, __here);
11601 +       /* prevent further acquisition */
11602 +       vxh_active = 0;
11603 +}
11604 +
11605 +
11606 +#define vxh_throw_oops()       __vxh_throw_oops(__HERE__);
11607 +
11608 +#define __vxh_get_vx_info(v, h)        __vxh_smpl(v, VXH_GET_VX_INFO, h);
11609 +#define __vxh_put_vx_info(v, h)        __vxh_smpl(v, VXH_PUT_VX_INFO, h);
11610 +
11611 +#define __vxh_init_vx_info(v, d, h) \
11612 +       __vxh_data(v, d, VXH_INIT_VX_INFO, h);
11613 +#define __vxh_set_vx_info(v, d, h) \
11614 +       __vxh_data(v, d, VXH_SET_VX_INFO, h);
11615 +#define __vxh_clr_vx_info(v, d, h) \
11616 +       __vxh_data(v, d, VXH_CLR_VX_INFO, h);
11617 +
11618 +#define __vxh_claim_vx_info(v, d, h) \
11619 +       __vxh_data(v, d, VXH_CLAIM_VX_INFO, h);
11620 +#define __vxh_release_vx_info(v, d, h) \
11621 +       __vxh_data(v, d, VXH_RELEASE_VX_INFO, h);
11622 +
11623 +#define vxh_alloc_vx_info(v) \
11624 +       __vxh_smpl(v, VXH_ALLOC_VX_INFO, __HERE__);
11625 +#define vxh_dealloc_vx_info(v) \
11626 +       __vxh_smpl(v, VXH_DEALLOC_VX_INFO, __HERE__);
11627 +
11628 +#define vxh_hash_vx_info(v) \
11629 +       __vxh_smpl(v, VXH_HASH_VX_INFO, __HERE__);
11630 +#define vxh_unhash_vx_info(v) \
11631 +       __vxh_smpl(v, VXH_UNHASH_VX_INFO, __HERE__);
11632 +
11633 +#define vxh_loc_vx_info(v, l) \
11634 +       __vxh_long(v, l, VXH_LOC_VX_INFO, __HERE__);
11635 +#define vxh_lookup_vx_info(v, l) \
11636 +       __vxh_long(v, l, VXH_LOOKUP_VX_INFO, __HERE__);
11637 +#define vxh_create_vx_info(v, l) \
11638 +       __vxh_long(v, l, VXH_CREATE_VX_INFO, __HERE__);
11639 +
11640 +extern void vxh_dump_history(void);
11641 +
11642 +
11643 +#else  /* CONFIG_VSERVER_HISTORY */
11644 +
11645 +#define        __HERE__        0
11646 +
11647 +#define vxh_throw_oops()               do { } while (0)
11648 +
11649 +#define __vxh_get_vx_info(v, h)                do { } while (0)
11650 +#define __vxh_put_vx_info(v, h)                do { } while (0)
11651 +
11652 +#define __vxh_init_vx_info(v, d, h)    do { } while (0)
11653 +#define __vxh_set_vx_info(v, d, h)     do { } while (0)
11654 +#define __vxh_clr_vx_info(v, d, h)     do { } while (0)
11655 +
11656 +#define __vxh_claim_vx_info(v, d, h)   do { } while (0)
11657 +#define __vxh_release_vx_info(v, d, h) do { } while (0)
11658 +
11659 +#define vxh_alloc_vx_info(v)           do { } while (0)
11660 +#define vxh_dealloc_vx_info(v)         do { } while (0)
11661 +
11662 +#define vxh_hash_vx_info(v)            do { } while (0)
11663 +#define vxh_unhash_vx_info(v)          do { } while (0)
11664 +
11665 +#define vxh_loc_vx_info(v, l)          do { } while (0)
11666 +#define vxh_lookup_vx_info(v, l)       do { } while (0)
11667 +#define vxh_create_vx_info(v, l)       do { } while (0)
11668 +
11669 +#define vxh_dump_history()             do { } while (0)
11670 +
11671 +
11672 +#endif /* CONFIG_VSERVER_HISTORY */
11673 +
11674 +#endif /* _VX_HISTORY_H */
11675 diff -NurpP --minimal linux-2.6.32.6/include/linux/vserver/inode_cmd.h linux-2.6.32.6-vs2.3.0.36.28/include/linux/vserver/inode_cmd.h
11676 --- linux-2.6.32.6/include/linux/vserver/inode_cmd.h    1970-01-01 01:00:00.000000000 +0100
11677 +++ linux-2.6.32.6-vs2.3.0.36.28/include/linux/vserver/inode_cmd.h      2009-12-03 20:04:56.000000000 +0100
11678 @@ -0,0 +1,59 @@
11679 +#ifndef _VX_INODE_CMD_H
11680 +#define _VX_INODE_CMD_H
11681 +
11682 +
11683 +/*  inode vserver commands */
11684 +
11685 +#define VCMD_get_iattr         VC_CMD(INODE, 1, 1)
11686 +#define VCMD_set_iattr         VC_CMD(INODE, 2, 1)
11687 +
11688 +#define VCMD_fget_iattr                VC_CMD(INODE, 3, 0)
11689 +#define VCMD_fset_iattr                VC_CMD(INODE, 4, 0)
11690 +
11691 +struct vcmd_ctx_iattr_v1 {
11692 +       const char __user *name;
11693 +       uint32_t tag;
11694 +       uint32_t flags;
11695 +       uint32_t mask;
11696 +};
11697 +
11698 +struct vcmd_ctx_fiattr_v0 {
11699 +       uint32_t tag;
11700 +       uint32_t flags;
11701 +       uint32_t mask;
11702 +};
11703 +
11704 +
11705 +#ifdef __KERNEL__
11706 +
11707 +
11708 +#ifdef CONFIG_COMPAT
11709 +
11710 +#include <asm/compat.h>
11711 +
11712 +struct vcmd_ctx_iattr_v1_x32 {
11713 +       compat_uptr_t name_ptr;
11714 +       uint32_t tag;
11715 +       uint32_t flags;
11716 +       uint32_t mask;
11717 +};
11718 +
11719 +#endif /* CONFIG_COMPAT */
11720 +
11721 +#include <linux/compiler.h>
11722 +
11723 +extern int vc_get_iattr(void __user *);
11724 +extern int vc_set_iattr(void __user *);
11725 +
11726 +extern int vc_fget_iattr(uint32_t, void __user *);
11727 +extern int vc_fset_iattr(uint32_t, void __user *);
11728 +
11729 +#ifdef CONFIG_COMPAT
11730 +
11731 +extern int vc_get_iattr_x32(void __user *);
11732 +extern int vc_set_iattr_x32(void __user *);
11733 +
11734 +#endif /* CONFIG_COMPAT */
11735 +
11736 +#endif /* __KERNEL__ */
11737 +#endif /* _VX_INODE_CMD_H */
11738 diff -NurpP --minimal linux-2.6.32.6/include/linux/vserver/inode.h linux-2.6.32.6-vs2.3.0.36.28/include/linux/vserver/inode.h
11739 --- linux-2.6.32.6/include/linux/vserver/inode.h        1970-01-01 01:00:00.000000000 +0100
11740 +++ linux-2.6.32.6-vs2.3.0.36.28/include/linux/vserver/inode.h  2009-12-03 20:04:56.000000000 +0100
11741 @@ -0,0 +1,39 @@
11742 +#ifndef _VX_INODE_H
11743 +#define _VX_INODE_H
11744 +
11745 +
11746 +#define IATTR_TAG      0x01000000
11747 +
11748 +#define IATTR_ADMIN    0x00000001
11749 +#define IATTR_WATCH    0x00000002
11750 +#define IATTR_HIDE     0x00000004
11751 +#define IATTR_FLAGS    0x00000007
11752 +
11753 +#define IATTR_BARRIER  0x00010000
11754 +#define IATTR_IXUNLINK 0x00020000
11755 +#define IATTR_IMMUTABLE 0x00040000
11756 +#define IATTR_COW      0x00080000
11757 +
11758 +#ifdef __KERNEL__
11759 +
11760 +
11761 +#ifdef CONFIG_VSERVER_PROC_SECURE
11762 +#define IATTR_PROC_DEFAULT     ( IATTR_ADMIN | IATTR_HIDE )
11763 +#define IATTR_PROC_SYMLINK     ( IATTR_ADMIN )
11764 +#else
11765 +#define IATTR_PROC_DEFAULT     ( IATTR_ADMIN )
11766 +#define IATTR_PROC_SYMLINK     ( IATTR_ADMIN )
11767 +#endif
11768 +
11769 +#define vx_hide_check(c, m)    (((m) & IATTR_HIDE) ? vx_check(c, m) : 1)
11770 +
11771 +#endif /* __KERNEL__ */
11772 +
11773 +/* inode ioctls */
11774 +
11775 +#define FIOC_GETXFLG   _IOR('x', 5, long)
11776 +#define FIOC_SETXFLG   _IOW('x', 6, long)
11777 +
11778 +#else  /* _VX_INODE_H */
11779 +#warning duplicate inclusion
11780 +#endif /* _VX_INODE_H */
11781 diff -NurpP --minimal linux-2.6.32.6/include/linux/vserver/Kbuild linux-2.6.32.6-vs2.3.0.36.28/include/linux/vserver/Kbuild
11782 --- linux-2.6.32.6/include/linux/vserver/Kbuild 1970-01-01 01:00:00.000000000 +0100
11783 +++ linux-2.6.32.6-vs2.3.0.36.28/include/linux/vserver/Kbuild   2009-12-03 20:04:56.000000000 +0100
11784 @@ -0,0 +1,8 @@
11785 +
11786 +unifdef-y += context_cmd.h network_cmd.h space_cmd.h \
11787 +       cacct_cmd.h cvirt_cmd.h limit_cmd.h dlimit_cmd.h \
11788 +       inode_cmd.h tag_cmd.h sched_cmd.h signal_cmd.h \
11789 +       debug_cmd.h device_cmd.h
11790 +
11791 +unifdef-y += switch.h network.h monitor.h inode.h device.h
11792 +
11793 diff -NurpP --minimal linux-2.6.32.6/include/linux/vserver/limit_cmd.h linux-2.6.32.6-vs2.3.0.36.28/include/linux/vserver/limit_cmd.h
11794 --- linux-2.6.32.6/include/linux/vserver/limit_cmd.h    1970-01-01 01:00:00.000000000 +0100
11795 +++ linux-2.6.32.6-vs2.3.0.36.28/include/linux/vserver/limit_cmd.h      2009-12-03 20:04:56.000000000 +0100
11796 @@ -0,0 +1,71 @@
11797 +#ifndef _VX_LIMIT_CMD_H
11798 +#define _VX_LIMIT_CMD_H
11799 +
11800 +
11801 +/*  rlimit vserver commands */
11802 +
11803 +#define VCMD_get_rlimit                VC_CMD(RLIMIT, 1, 0)
11804 +#define VCMD_set_rlimit                VC_CMD(RLIMIT, 2, 0)
11805 +#define VCMD_get_rlimit_mask   VC_CMD(RLIMIT, 3, 0)
11806 +#define VCMD_reset_hits                VC_CMD(RLIMIT, 7, 0)
11807 +#define VCMD_reset_minmax      VC_CMD(RLIMIT, 9, 0)
11808 +
11809 +struct vcmd_ctx_rlimit_v0 {
11810 +       uint32_t id;
11811 +       uint64_t minimum;
11812 +       uint64_t softlimit;
11813 +       uint64_t maximum;
11814 +};
11815 +
11816 +struct vcmd_ctx_rlimit_mask_v0 {
11817 +       uint32_t minimum;
11818 +       uint32_t softlimit;
11819 +       uint32_t maximum;
11820 +};
11821 +
11822 +#define VCMD_rlimit_stat       VC_CMD(VSTAT, 1, 0)
11823 +
11824 +struct vcmd_rlimit_stat_v0 {
11825 +       uint32_t id;
11826 +       uint32_t hits;
11827 +       uint64_t value;
11828 +       uint64_t minimum;
11829 +       uint64_t maximum;
11830 +};
11831 +
11832 +#define CRLIM_UNSET            (0ULL)
11833 +#define CRLIM_INFINITY         (~0ULL)
11834 +#define CRLIM_KEEP             (~1ULL)
11835 +
11836 +#ifdef __KERNEL__
11837 +
11838 +#ifdef CONFIG_IA32_EMULATION
11839 +
11840 +struct vcmd_ctx_rlimit_v0_x32 {
11841 +       uint32_t id;
11842 +       uint64_t minimum;
11843 +       uint64_t softlimit;
11844 +       uint64_t maximum;
11845 +} __attribute__ ((packed));
11846 +
11847 +#endif /* CONFIG_IA32_EMULATION */
11848 +
11849 +#include <linux/compiler.h>
11850 +
11851 +extern int vc_get_rlimit_mask(uint32_t, void __user *);
11852 +extern int vc_get_rlimit(struct vx_info *, void __user *);
11853 +extern int vc_set_rlimit(struct vx_info *, void __user *);
11854 +extern int vc_reset_hits(struct vx_info *, void __user *);
11855 +extern int vc_reset_minmax(struct vx_info *, void __user *);
11856 +
11857 +extern int vc_rlimit_stat(struct vx_info *, void __user *);
11858 +
11859 +#ifdef CONFIG_IA32_EMULATION
11860 +
11861 +extern int vc_get_rlimit_x32(struct vx_info *, void __user *);
11862 +extern int vc_set_rlimit_x32(struct vx_info *, void __user *);
11863 +
11864 +#endif /* CONFIG_IA32_EMULATION */
11865 +
11866 +#endif /* __KERNEL__ */
11867 +#endif /* _VX_LIMIT_CMD_H */
11868 diff -NurpP --minimal linux-2.6.32.6/include/linux/vserver/limit_def.h linux-2.6.32.6-vs2.3.0.36.28/include/linux/vserver/limit_def.h
11869 --- linux-2.6.32.6/include/linux/vserver/limit_def.h    1970-01-01 01:00:00.000000000 +0100
11870 +++ linux-2.6.32.6-vs2.3.0.36.28/include/linux/vserver/limit_def.h      2009-12-03 20:04:56.000000000 +0100
11871 @@ -0,0 +1,47 @@
11872 +#ifndef _VX_LIMIT_DEF_H
11873 +#define _VX_LIMIT_DEF_H
11874 +
11875 +#include <asm/atomic.h>
11876 +#include <asm/resource.h>
11877 +
11878 +#include "limit.h"
11879 +
11880 +
11881 +struct _vx_res_limit {
11882 +       rlim_t soft;            /* Context soft limit */
11883 +       rlim_t hard;            /* Context hard limit */
11884 +
11885 +       rlim_atomic_t rcur;     /* Current value */
11886 +       rlim_t rmin;            /* Context minimum */
11887 +       rlim_t rmax;            /* Context maximum */
11888 +
11889 +       atomic_t lhit;          /* Limit hits */
11890 +};
11891 +
11892 +/* context sub struct */
11893 +
11894 +struct _vx_limit {
11895 +       struct _vx_res_limit res[NUM_LIMITS];
11896 +};
11897 +
11898 +#ifdef CONFIG_VSERVER_DEBUG
11899 +
11900 +static inline void __dump_vx_limit(struct _vx_limit *limit)
11901 +{
11902 +       int i;
11903 +
11904 +       printk("\t_vx_limit:");
11905 +       for (i = 0; i < NUM_LIMITS; i++) {
11906 +               printk("\t [%2d] = %8lu %8lu/%8lu, %8ld/%8ld, %8d\n",
11907 +                       i, (unsigned long)__rlim_get(limit, i),
11908 +                       (unsigned long)__rlim_rmin(limit, i),
11909 +                       (unsigned long)__rlim_rmax(limit, i),
11910 +                       (long)__rlim_soft(limit, i),
11911 +                       (long)__rlim_hard(limit, i),
11912 +                       atomic_read(&__rlim_lhit(limit, i)));
11913 +       }
11914 +}
11915 +
11916 +#endif
11917 +
11918 +#endif /* _VX_LIMIT_DEF_H */
11919 diff -NurpP --minimal linux-2.6.32.6/include/linux/vserver/limit.h linux-2.6.32.6-vs2.3.0.36.28/include/linux/vserver/limit.h
11920 --- linux-2.6.32.6/include/linux/vserver/limit.h        1970-01-01 01:00:00.000000000 +0100
11921 +++ linux-2.6.32.6-vs2.3.0.36.28/include/linux/vserver/limit.h  2009-12-03 20:04:56.000000000 +0100
11922 @@ -0,0 +1,70 @@
11923 +#ifndef _VX_LIMIT_H
11924 +#define _VX_LIMIT_H
11925 +
11926 +#define VLIMIT_NSOCK   16
11927 +#define VLIMIT_OPENFD  17
11928 +#define VLIMIT_ANON    18
11929 +#define VLIMIT_SHMEM   19
11930 +#define VLIMIT_SEMARY  20
11931 +#define VLIMIT_NSEMS   21
11932 +#define VLIMIT_DENTRY  22
11933 +#define VLIMIT_MAPPED  23
11934 +
11935 +
11936 +#ifdef __KERNEL__
11937 +
11938 +#define        VLIM_NOCHECK    ((1L << VLIMIT_DENTRY) | (1L << RLIMIT_RSS))
11939 +
11940 +/*     keep in sync with CRLIM_INFINITY */
11941 +
11942 +#define        VLIM_INFINITY   (~0ULL)
11943 +
11944 +#include <asm/atomic.h>
11945 +#include <asm/resource.h>
11946 +
11947 +#ifndef RLIM_INFINITY
11948 +#warning RLIM_INFINITY is undefined
11949 +#endif
11950 +
11951 +#define __rlim_val(l, r, v)    ((l)->res[r].v)
11952 +
11953 +#define __rlim_soft(l, r)      __rlim_val(l, r, soft)
11954 +#define __rlim_hard(l, r)      __rlim_val(l, r, hard)
11955 +
11956 +#define __rlim_rcur(l, r)      __rlim_val(l, r, rcur)
11957 +#define __rlim_rmin(l, r)      __rlim_val(l, r, rmin)
11958 +#define __rlim_rmax(l, r)      __rlim_val(l, r, rmax)
11959 +
11960 +#define __rlim_lhit(l, r)      __rlim_val(l, r, lhit)
11961 +#define __rlim_hit(l, r)       atomic_inc(&__rlim_lhit(l, r))
11962 +
11963 +typedef atomic_long_t rlim_atomic_t;
11964 +typedef unsigned long rlim_t;
11965 +
11966 +#define __rlim_get(l, r)       atomic_long_read(&__rlim_rcur(l, r))
11967 +#define __rlim_set(l, r, v)    atomic_long_set(&__rlim_rcur(l, r), v)
11968 +#define __rlim_inc(l, r)       atomic_long_inc(&__rlim_rcur(l, r))
11969 +#define __rlim_dec(l, r)       atomic_long_dec(&__rlim_rcur(l, r))
11970 +#define __rlim_add(l, r, v)    atomic_long_add(v, &__rlim_rcur(l, r))
11971 +#define __rlim_sub(l, r, v)    atomic_long_sub(v, &__rlim_rcur(l, r))
11972 +
11973 +
11974 +#if    (RLIM_INFINITY == VLIM_INFINITY)
11975 +#define        VX_VLIM(r) ((long long)(long)(r))
11976 +#define        VX_RLIM(v) ((rlim_t)(v))
11977 +#else
11978 +#define        VX_VLIM(r) (((r) == RLIM_INFINITY) \
11979 +               ? VLIM_INFINITY : (long long)(r))
11980 +#define        VX_RLIM(v) (((v) == VLIM_INFINITY) \
11981 +               ? RLIM_INFINITY : (rlim_t)(v))
11982 +#endif
11983 +
11984 +struct sysinfo;
11985 +
11986 +void vx_vsi_meminfo(struct sysinfo *);
11987 +void vx_vsi_swapinfo(struct sysinfo *);
11988 +
11989 +#define NUM_LIMITS     24
11990 +
11991 +#endif /* __KERNEL__ */
11992 +#endif /* _VX_LIMIT_H */
11993 diff -NurpP --minimal linux-2.6.32.6/include/linux/vserver/limit_int.h linux-2.6.32.6-vs2.3.0.36.28/include/linux/vserver/limit_int.h
11994 --- linux-2.6.32.6/include/linux/vserver/limit_int.h    1970-01-01 01:00:00.000000000 +0100
11995 +++ linux-2.6.32.6-vs2.3.0.36.28/include/linux/vserver/limit_int.h      2009-12-03 20:04:56.000000000 +0100
11996 @@ -0,0 +1,198 @@
11997 +#ifndef _VX_LIMIT_INT_H
11998 +#define _VX_LIMIT_INT_H
11999 +
12000 +#include "context.h"
12001 +
12002 +#ifdef __KERNEL__
12003 +
12004 +#define VXD_RCRES_COND(r)      VXD_CBIT(cres, r)
12005 +#define VXD_RLIMIT_COND(r)     VXD_CBIT(limit, r)
12006 +
12007 +extern const char *vlimit_name[NUM_LIMITS];
12008 +
12009 +static inline void __vx_acc_cres(struct vx_info *vxi,
12010 +       int res, int dir, void *_data, char *_file, int _line)
12011 +{
12012 +       if (VXD_RCRES_COND(res))
12013 +               vxlprintk(1, "vx_acc_cres[%5d,%s,%2d]: %5ld%s (%p)",
12014 +                       (vxi ? vxi->vx_id : -1), vlimit_name[res], res,
12015 +                       (vxi ? (long)__rlim_get(&vxi->limit, res) : 0),
12016 +                       (dir > 0) ? "++" : "--", _data, _file, _line);
12017 +       if (!vxi)
12018 +               return;
12019 +
12020 +       if (dir > 0)
12021 +               __rlim_inc(&vxi->limit, res);
12022 +       else
12023 +               __rlim_dec(&vxi->limit, res);
12024 +}
12025 +
12026 +static inline void __vx_add_cres(struct vx_info *vxi,
12027 +       int res, int amount, void *_data, char *_file, int _line)
12028 +{
12029 +       if (VXD_RCRES_COND(res))
12030 +               vxlprintk(1, "vx_add_cres[%5d,%s,%2d]: %5ld += %5d (%p)",
12031 +                       (vxi ? vxi->vx_id : -1), vlimit_name[res], res,
12032 +                       (vxi ? (long)__rlim_get(&vxi->limit, res) : 0),
12033 +                       amount, _data, _file, _line);
12034 +       if (amount == 0)
12035 +               return;
12036 +       if (!vxi)
12037 +               return;
12038 +       __rlim_add(&vxi->limit, res, amount);
12039 +}
12040 +
12041 +static inline
12042 +int __vx_cres_adjust_max(struct _vx_limit *limit, int res, rlim_t value)
12043 +{
12044 +       int cond = (value > __rlim_rmax(limit, res));
12045 +
12046 +       if (cond)
12047 +               __rlim_rmax(limit, res) = value;
12048 +       return cond;
12049 +}
12050 +
12051 +static inline
12052 +int __vx_cres_adjust_min(struct _vx_limit *limit, int res, rlim_t value)
12053 +{
12054 +       int cond = (value < __rlim_rmin(limit, res));
12055 +
12056 +       if (cond)
12057 +               __rlim_rmin(limit, res) = value;
12058 +       return cond;
12059 +}
12060 +
12061 +static inline
12062 +void __vx_cres_fixup(struct _vx_limit *limit, int res, rlim_t value)
12063 +{
12064 +       if (!__vx_cres_adjust_max(limit, res, value))
12065 +               __vx_cres_adjust_min(limit, res, value);
12066 +}
12067 +
12068 +
12069 +/*     return values:
12070 +        +1 ... no limit hit
12071 +        -1 ... over soft limit
12072 +         0 ... over hard limit         */
12073 +
12074 +static inline int __vx_cres_avail(struct vx_info *vxi,
12075 +       int res, int num, char *_file, int _line)
12076 +{
12077 +       struct _vx_limit *limit;
12078 +       rlim_t value;
12079 +
12080 +       if (VXD_RLIMIT_COND(res))
12081 +               vxlprintk(1, "vx_cres_avail[%5d,%s,%2d]: %5ld/%5ld > %5ld + %5d",
12082 +                       (vxi ? vxi->vx_id : -1), vlimit_name[res], res,
12083 +                       (vxi ? (long)__rlim_soft(&vxi->limit, res) : -1),
12084 +                       (vxi ? (long)__rlim_hard(&vxi->limit, res) : -1),
12085 +                       (vxi ? (long)__rlim_get(&vxi->limit, res) : 0),
12086 +                       num, _file, _line);
12087 +       if (!vxi)
12088 +               return 1;
12089 +
12090 +       limit = &vxi->limit;
12091 +       value = __rlim_get(limit, res);
12092 +
12093 +       if (!__vx_cres_adjust_max(limit, res, value))
12094 +               __vx_cres_adjust_min(limit, res, value);
12095 +
12096 +       if (num == 0)
12097 +               return 1;
12098 +
12099 +       if (__rlim_soft(limit, res) == RLIM_INFINITY)
12100 +               return -1;
12101 +       if (value + num <= __rlim_soft(limit, res))
12102 +               return -1;
12103 +
12104 +       if (__rlim_hard(limit, res) == RLIM_INFINITY)
12105 +               return 1;
12106 +       if (value + num <= __rlim_hard(limit, res))
12107 +               return 1;
12108 +
12109 +       __rlim_hit(limit, res);
12110 +       return 0;
12111 +}
12112 +
12113 +
12114 +static const int VLA_RSS[] = { RLIMIT_RSS, VLIMIT_ANON, VLIMIT_MAPPED, 0 };
12115 +
12116 +static inline
12117 +rlim_t __vx_cres_array_sum(struct _vx_limit *limit, const int *array)
12118 +{
12119 +       rlim_t value, sum = 0;
12120 +       int res;
12121 +
12122 +       while ((res = *array++)) {
12123 +               value = __rlim_get(limit, res);
12124 +               __vx_cres_fixup(limit, res, value);
12125 +               sum += value;
12126 +       }
12127 +       return sum;
12128 +}
12129 +
12130 +static inline
12131 +rlim_t __vx_cres_array_fixup(struct _vx_limit *limit, const int *array)
12132 +{
12133 +       rlim_t value = __vx_cres_array_sum(limit, array + 1);
12134 +       int res = *array;
12135 +
12136 +       if (value == __rlim_get(limit, res))
12137 +               return value;
12138 +
12139 +       __rlim_set(limit, res, value);
12140 +       /* now adjust min/max */
12141 +       if (!__vx_cres_adjust_max(limit, res, value))
12142 +               __vx_cres_adjust_min(limit, res, value);
12143 +
12144 +       return value;
12145 +}
12146 +
12147 +static inline int __vx_cres_array_avail(struct vx_info *vxi,
12148 +       const int *array, int num, char *_file, int _line)
12149 +{
12150 +       struct _vx_limit *limit;
12151 +       rlim_t value = 0;
12152 +       int res;
12153 +
12154 +       if (num == 0)
12155 +               return 1;
12156 +       if (!vxi)
12157 +               return 1;
12158 +
12159 +       limit = &vxi->limit;
12160 +       res = *array;
12161 +       value = __vx_cres_array_sum(limit, array + 1);
12162 +
12163 +       __rlim_set(limit, res, value);
12164 +       __vx_cres_fixup(limit, res, value);
12165 +
12166 +       return __vx_cres_avail(vxi, res, num, _file, _line);
12167 +}
12168 +
12169 +
12170 +static inline void vx_limit_fixup(struct _vx_limit *limit, int id)
12171 +{
12172 +       rlim_t value;
12173 +       int res;
12174 +
12175 +       /* complex resources first */
12176 +       if ((id < 0) || (id == RLIMIT_RSS))
12177 +               __vx_cres_array_fixup(limit, VLA_RSS);
12178 +
12179 +       for (res = 0; res < NUM_LIMITS; res++) {
12180 +               if ((id > 0) && (res != id))
12181 +                       continue;
12182 +
12183 +               value = __rlim_get(limit, res);
12184 +               __vx_cres_fixup(limit, res, value);
12185 +
12186 +               /* not supposed to happen, maybe warn? */
12187 +               if (__rlim_rmax(limit, res) > __rlim_hard(limit, res))
12188 +                       __rlim_rmax(limit, res) = __rlim_hard(limit, res);
12189 +       }
12190 +}
12191 +
12192 +
12193 +#endif /* __KERNEL__ */
12194 +#endif /* _VX_LIMIT_INT_H */
12195 diff -NurpP --minimal linux-2.6.32.6/include/linux/vserver/monitor.h linux-2.6.32.6-vs2.3.0.36.28/include/linux/vserver/monitor.h
12196 --- linux-2.6.32.6/include/linux/vserver/monitor.h      1970-01-01 01:00:00.000000000 +0100
12197 +++ linux-2.6.32.6-vs2.3.0.36.28/include/linux/vserver/monitor.h        2009-12-03 20:04:56.000000000 +0100
12198 @@ -0,0 +1,96 @@
12199 +#ifndef _VX_MONITOR_H
12200 +#define _VX_MONITOR_H
12201 +
12202 +#include <linux/types.h>
12203 +
12204 +enum {
12205 +       VXM_UNUSED = 0,
12206 +
12207 +       VXM_SYNC = 0x10,
12208 +
12209 +       VXM_UPDATE = 0x20,
12210 +       VXM_UPDATE_1,
12211 +       VXM_UPDATE_2,
12212 +
12213 +       VXM_RQINFO_1 = 0x24,
12214 +       VXM_RQINFO_2,
12215 +
12216 +       VXM_ACTIVATE = 0x40,
12217 +       VXM_DEACTIVATE,
12218 +       VXM_IDLE,
12219 +
12220 +       VXM_HOLD = 0x44,
12221 +       VXM_UNHOLD,
12222 +
12223 +       VXM_MIGRATE = 0x48,
12224 +       VXM_RESCHED,
12225 +
12226 +       /* all other bits are flags */
12227 +       VXM_SCHED = 0x80,
12228 +};
12229 +
12230 +struct _vxm_update_1 {
12231 +       uint32_t tokens_max;
12232 +       uint32_t fill_rate;
12233 +       uint32_t interval;
12234 +};
12235 +
12236 +struct _vxm_update_2 {
12237 +       uint32_t tokens_min;
12238 +       uint32_t fill_rate;
12239 +       uint32_t interval;
12240 +};
12241 +
12242 +struct _vxm_rqinfo_1 {
12243 +       uint16_t running;
12244 +       uint16_t onhold;
12245 +       uint16_t iowait;
12246 +       uint16_t uintr;
12247 +       uint32_t idle_tokens;
12248 +};
12249 +
12250 +struct _vxm_rqinfo_2 {
12251 +       uint32_t norm_time;
12252 +       uint32_t idle_time;
12253 +       uint32_t idle_skip;
12254 +};
12255 +
12256 +struct _vxm_sched {
12257 +       uint32_t tokens;
12258 +       uint32_t norm_time;
12259 +       uint32_t idle_time;
12260 +};
12261 +
12262 +struct _vxm_task {
12263 +       uint16_t pid;
12264 +       uint16_t state;
12265 +};
12266 +
12267 +struct _vxm_event {
12268 +       uint32_t jif;
12269 +       union {
12270 +               uint32_t seq;
12271 +               uint32_t sec;
12272 +       };
12273 +       union {
12274 +               uint32_t tokens;
12275 +               uint32_t nsec;
12276 +               struct _vxm_task tsk;
12277 +       };
12278 +};
12279 +
12280 +struct _vx_mon_entry {
12281 +       uint16_t type;
12282 +       uint16_t xid;
12283 +       union {
12284 +               struct _vxm_event ev;
12285 +               struct _vxm_sched sd;
12286 +               struct _vxm_update_1 u1;
12287 +               struct _vxm_update_2 u2;
12288 +               struct _vxm_rqinfo_1 q1;
12289 +               struct _vxm_rqinfo_2 q2;
12290 +       };
12291 +};
12292 +
12293 +
12294 +#endif /* _VX_MONITOR_H */
12295 diff -NurpP --minimal linux-2.6.32.6/include/linux/vserver/network_cmd.h linux-2.6.32.6-vs2.3.0.36.28/include/linux/vserver/network_cmd.h
12296 --- linux-2.6.32.6/include/linux/vserver/network_cmd.h  1970-01-01 01:00:00.000000000 +0100
12297 +++ linux-2.6.32.6-vs2.3.0.36.28/include/linux/vserver/network_cmd.h    2009-12-03 20:04:56.000000000 +0100
12298 @@ -0,0 +1,150 @@
12299 +#ifndef _VX_NETWORK_CMD_H
12300 +#define _VX_NETWORK_CMD_H
12301 +
12302 +
12303 +/* vinfo commands */
12304 +
12305 +#define VCMD_task_nid          VC_CMD(VINFO, 2, 0)
12306 +
12307 +#ifdef __KERNEL__
12308 +extern int vc_task_nid(uint32_t);
12309 +
12310 +#endif /* __KERNEL__ */
12311 +
12312 +#define VCMD_nx_info           VC_CMD(VINFO, 6, 0)
12313 +
12314 +struct vcmd_nx_info_v0 {
12315 +       uint32_t nid;
12316 +       /* more to come */
12317 +};
12318 +
12319 +#ifdef __KERNEL__
12320 +extern int vc_nx_info(struct nx_info *, void __user *);
12321 +
12322 +#endif /* __KERNEL__ */
12323 +
12324 +#include <linux/in.h>
12325 +#include <linux/in6.h>
12326 +
12327 +#define VCMD_net_create_v0     VC_CMD(VNET, 1, 0)
12328 +#define VCMD_net_create                VC_CMD(VNET, 1, 1)
12329 +
12330 +struct  vcmd_net_create {
12331 +       uint64_t flagword;
12332 +};
12333 +
12334 +#define VCMD_net_migrate       VC_CMD(NETMIG, 1, 0)
12335 +
12336 +#define VCMD_net_add           VC_CMD(NETALT, 1, 0)
12337 +#define VCMD_net_remove                VC_CMD(NETALT, 2, 0)
12338 +
12339 +struct vcmd_net_addr_v0 {
12340 +       uint16_t type;
12341 +       uint16_t count;
12342 +       struct in_addr ip[4];
12343 +       struct in_addr mask[4];
12344 +};
12345 +
12346 +#define VCMD_net_add_ipv4      VC_CMD(NETALT, 1, 1)
12347 +#define VCMD_net_remove_ipv4   VC_CMD(NETALT, 2, 1)
12348 +
12349 +struct vcmd_net_addr_ipv4_v1 {
12350 +       uint16_t type;
12351 +       uint16_t flags;
12352 +       struct in_addr ip;
12353 +       struct in_addr mask;
12354 +};
12355 +
12356 +#define VCMD_net_add_ipv6      VC_CMD(NETALT, 3, 1)
12357 +#define VCMD_net_remove_ipv6   VC_CMD(NETALT, 4, 1)
12358 +
12359 +struct vcmd_net_addr_ipv6_v1 {
12360 +       uint16_t type;
12361 +       uint16_t flags;
12362 +       uint32_t prefix;
12363 +       struct in6_addr ip;
12364 +       struct in6_addr mask;
12365 +};
12366 +
12367 +#define VCMD_add_match_ipv4    VC_CMD(NETALT, 5, 0)
12368 +#define VCMD_get_match_ipv4    VC_CMD(NETALT, 6, 0)
12369 +
12370 +struct vcmd_match_ipv4_v0 {
12371 +       uint16_t type;
12372 +       uint16_t flags;
12373 +       uint16_t parent;
12374 +       uint16_t prefix;
12375 +       struct in_addr ip;
12376 +       struct in_addr ip2;
12377 +       struct in_addr mask;
12378 +};
12379 +
12380 +#define VCMD_add_match_ipv6    VC_CMD(NETALT, 7, 0)
12381 +#define VCMD_get_match_ipv6    VC_CMD(NETALT, 8, 0)
12382 +
12383 +struct vcmd_match_ipv6_v0 {
12384 +       uint16_t type;
12385 +       uint16_t flags;
12386 +       uint16_t parent;
12387 +       uint16_t prefix;
12388 +       struct in6_addr ip;
12389 +       struct in6_addr ip2;
12390 +       struct in6_addr mask;
12391 +};
12392 +
12393 +
12394 +#ifdef __KERNEL__
12395 +extern int vc_net_create(uint32_t, void __user *);
12396 +extern int vc_net_migrate(struct nx_info *, void __user *);
12397 +
12398 +extern int vc_net_add(struct nx_info *, void __user *);
12399 +extern int vc_net_remove(struct nx_info *, void __user *);
12400 +
12401 +extern int vc_net_add_ipv4(struct nx_info *, void __user *);
12402 +extern int vc_net_remove_ipv4(struct nx_info *, void __user *);
12403 +
12404 +extern int vc_net_add_ipv6(struct nx_info *, void __user *);
12405 +extern int vc_net_remove_ipv6(struct nx_info *, void __user *);
12406 +
12407 +extern int vc_add_match_ipv4(struct nx_info *, void __user *);
12408 +extern int vc_get_match_ipv4(struct nx_info *, void __user *);
12409 +
12410 +extern int vc_add_match_ipv6(struct nx_info *, void __user *);
12411 +extern int vc_get_match_ipv6(struct nx_info *, void __user *);
12412 +
12413 +#endif /* __KERNEL__ */
12414 +
12415 +
12416 +/* flag commands */
12417 +
12418 +#define VCMD_get_nflags                VC_CMD(FLAGS, 5, 0)
12419 +#define VCMD_set_nflags                VC_CMD(FLAGS, 6, 0)
12420 +
12421 +struct vcmd_net_flags_v0 {
12422 +       uint64_t flagword;
12423 +       uint64_t mask;
12424 +};
12425 +
12426 +#ifdef __KERNEL__
12427 +extern int vc_get_nflags(struct nx_info *, void __user *);
12428 +extern int vc_set_nflags(struct nx_info *, void __user *);
12429 +
12430 +#endif /* __KERNEL__ */
12431 +
12432 +
12433 +/* network caps commands */
12434 +
12435 +#define VCMD_get_ncaps         VC_CMD(FLAGS, 7, 0)
12436 +#define VCMD_set_ncaps         VC_CMD(FLAGS, 8, 0)
12437 +
12438 +struct vcmd_net_caps_v0 {
12439 +       uint64_t ncaps;
12440 +       uint64_t cmask;
12441 +};
12442 +
12443 +#ifdef __KERNEL__
12444 +extern int vc_get_ncaps(struct nx_info *, void __user *);
12445 +extern int vc_set_ncaps(struct nx_info *, void __user *);
12446 +
12447 +#endif /* __KERNEL__ */
12448 +#endif /* _VX_CONTEXT_CMD_H */
12449 diff -NurpP --minimal linux-2.6.32.6/include/linux/vserver/network.h linux-2.6.32.6-vs2.3.0.36.28/include/linux/vserver/network.h
12450 --- linux-2.6.32.6/include/linux/vserver/network.h      1970-01-01 01:00:00.000000000 +0100
12451 +++ linux-2.6.32.6-vs2.3.0.36.28/include/linux/vserver/network.h        2009-12-03 20:04:56.000000000 +0100
12452 @@ -0,0 +1,146 @@
12453 +#ifndef _VX_NETWORK_H
12454 +#define _VX_NETWORK_H
12455 +
12456 +#include <linux/types.h>
12457 +
12458 +
12459 +#define MAX_N_CONTEXT  65535   /* Arbitrary limit */
12460 +
12461 +
12462 +/* network flags */
12463 +
12464 +#define NXF_INFO_PRIVATE       0x00000008
12465 +
12466 +#define NXF_SINGLE_IP          0x00000100
12467 +#define NXF_LBACK_REMAP                0x00000200
12468 +#define NXF_LBACK_ALLOW                0x00000400
12469 +
12470 +#define NXF_HIDE_NETIF         0x02000000
12471 +#define NXF_HIDE_LBACK         0x04000000
12472 +
12473 +#define NXF_STATE_SETUP                (1ULL << 32)
12474 +#define NXF_STATE_ADMIN                (1ULL << 34)
12475 +
12476 +#define NXF_SC_HELPER          (1ULL << 36)
12477 +#define NXF_PERSISTENT         (1ULL << 38)
12478 +
12479 +#define NXF_ONE_TIME           (0x0005ULL << 32)
12480 +
12481 +
12482 +#define        NXF_INIT_SET            (__nxf_init_set())
12483 +
12484 +static inline uint64_t __nxf_init_set(void) {
12485 +       return    NXF_STATE_ADMIN
12486 +#ifdef CONFIG_VSERVER_AUTO_LBACK
12487 +               | NXF_LBACK_REMAP
12488 +               | NXF_HIDE_LBACK
12489 +#endif
12490 +#ifdef CONFIG_VSERVER_AUTO_SINGLE
12491 +               | NXF_SINGLE_IP
12492 +#endif
12493 +               | NXF_HIDE_NETIF;
12494 +}
12495 +
12496 +
12497 +/* network caps */
12498 +
12499 +#define NXC_TUN_CREATE         0x00000001
12500 +
12501 +#define NXC_RAW_ICMP           0x00000100
12502 +
12503 +
12504 +/* address types */
12505 +
12506 +#define NXA_TYPE_IPV4          0x0001
12507 +#define NXA_TYPE_IPV6          0x0002
12508 +
12509 +#define NXA_TYPE_NONE          0x0000
12510 +#define NXA_TYPE_ANY           0x00FF
12511 +
12512 +#define NXA_TYPE_ADDR          0x0010
12513 +#define NXA_TYPE_MASK          0x0020
12514 +#define NXA_TYPE_RANGE         0x0040
12515 +
12516 +#define NXA_MASK_ALL           (NXA_TYPE_ADDR | NXA_TYPE_MASK | NXA_TYPE_RANGE)
12517 +
12518 +#define NXA_MOD_BCAST          0x0100
12519 +#define NXA_MOD_LBACK          0x0200
12520 +
12521 +#define NXA_LOOPBACK           0x1000
12522 +
12523 +#define NXA_MASK_BIND          (NXA_MASK_ALL | NXA_MOD_BCAST | NXA_MOD_LBACK)
12524 +#define NXA_MASK_SHOW          (NXA_MASK_ALL | NXA_LOOPBACK)
12525 +
12526 +#ifdef __KERNEL__
12527 +
12528 +#include <linux/list.h>
12529 +#include <linux/spinlock.h>
12530 +#include <linux/rcupdate.h>
12531 +#include <linux/in.h>
12532 +#include <linux/in6.h>
12533 +#include <asm/atomic.h>
12534 +
12535 +struct nx_addr_v4 {
12536 +       struct nx_addr_v4 *next;
12537 +       struct in_addr ip[2];
12538 +       struct in_addr mask;
12539 +       uint16_t type;
12540 +       uint16_t flags;
12541 +};
12542 +
12543 +struct nx_addr_v6 {
12544 +       struct nx_addr_v6 *next;
12545 +       struct in6_addr ip;
12546 +       struct in6_addr mask;
12547 +       uint32_t prefix;
12548 +       uint16_t type;
12549 +       uint16_t flags;
12550 +};
12551 +
12552 +struct nx_info {
12553 +       struct hlist_node nx_hlist;     /* linked list of nxinfos */
12554 +       nid_t nx_id;                    /* vnet id */
12555 +       atomic_t nx_usecnt;             /* usage count */
12556 +       atomic_t nx_tasks;              /* tasks count */
12557 +       int nx_state;                   /* context state */
12558 +
12559 +       uint64_t nx_flags;              /* network flag word */
12560 +       uint64_t nx_ncaps;              /* network capabilities */
12561 +
12562 +       struct in_addr v4_lback;        /* Loopback address */
12563 +       struct in_addr v4_bcast;        /* Broadcast address */
12564 +       struct nx_addr_v4 v4;           /* First/Single ipv4 address */
12565 +#ifdef CONFIG_IPV6
12566 +       struct nx_addr_v6 v6;           /* First/Single ipv6 address */
12567 +#endif
12568 +       char nx_name[65];               /* network context name */
12569 +};
12570 +
12571 +
12572 +/* status flags */
12573 +
12574 +#define NXS_HASHED      0x0001
12575 +#define NXS_SHUTDOWN    0x0100
12576 +#define NXS_RELEASED    0x8000
12577 +
12578 +extern struct nx_info *lookup_nx_info(int);
12579 +
12580 +extern int get_nid_list(int, unsigned int *, int);
12581 +extern int nid_is_hashed(nid_t);
12582 +
12583 +extern int nx_migrate_task(struct task_struct *, struct nx_info *);
12584 +
12585 +extern long vs_net_change(struct nx_info *, unsigned int);
12586 +
12587 +struct sock;
12588 +
12589 +
12590 +#define NX_IPV4(n)     ((n)->v4.type != NXA_TYPE_NONE)
12591 +#ifdef  CONFIG_IPV6
12592 +#define NX_IPV6(n)     ((n)->v6.type != NXA_TYPE_NONE)
12593 +#else
12594 +#define NX_IPV6(n)     (0)
12595 +#endif
12596 +
12597 +#endif /* __KERNEL__ */
12598 +#endif /* _VX_NETWORK_H */
12599 diff -NurpP --minimal linux-2.6.32.6/include/linux/vserver/percpu.h linux-2.6.32.6-vs2.3.0.36.28/include/linux/vserver/percpu.h
12600 --- linux-2.6.32.6/include/linux/vserver/percpu.h       1970-01-01 01:00:00.000000000 +0100
12601 +++ linux-2.6.32.6-vs2.3.0.36.28/include/linux/vserver/percpu.h 2009-12-03 20:04:56.000000000 +0100
12602 @@ -0,0 +1,14 @@
12603 +#ifndef _VX_PERCPU_H
12604 +#define _VX_PERCPU_H
12605 +
12606 +#include "cvirt_def.h"
12607 +#include "sched_def.h"
12608 +
12609 +struct _vx_percpu {
12610 +       struct _vx_cvirt_pc cvirt;
12611 +       struct _vx_sched_pc sched;
12612 +};
12613 +
12614 +#define        PERCPU_PERCTX   (sizeof(struct _vx_percpu))
12615 +
12616 +#endif /* _VX_PERCPU_H */
12617 diff -NurpP --minimal linux-2.6.32.6/include/linux/vserver/pid.h linux-2.6.32.6-vs2.3.0.36.28/include/linux/vserver/pid.h
12618 --- linux-2.6.32.6/include/linux/vserver/pid.h  1970-01-01 01:00:00.000000000 +0100
12619 +++ linux-2.6.32.6-vs2.3.0.36.28/include/linux/vserver/pid.h    2009-12-03 20:04:56.000000000 +0100
12620 @@ -0,0 +1,51 @@
12621 +#ifndef _VSERVER_PID_H
12622 +#define _VSERVER_PID_H
12623 +
12624 +/* pid faking stuff */
12625 +
12626 +#define vx_info_map_pid(v, p) \
12627 +       __vx_info_map_pid((v), (p), __func__, __FILE__, __LINE__)
12628 +#define vx_info_map_tgid(v,p)  vx_info_map_pid(v,p)
12629 +#define vx_map_pid(p) vx_info_map_pid(current_vx_info(), p)
12630 +#define vx_map_tgid(p) vx_map_pid(p)
12631 +
12632 +static inline int __vx_info_map_pid(struct vx_info *vxi, int pid,
12633 +       const char *func, const char *file, int line)
12634 +{
12635 +       if (vx_info_flags(vxi, VXF_INFO_INIT, 0)) {
12636 +               vxfprintk(VXD_CBIT(cvirt, 2),
12637 +                       "vx_map_tgid: %p/%llx: %d -> %d",
12638 +                       vxi, (long long)vxi->vx_flags, pid,
12639 +                       (pid && pid == vxi->vx_initpid) ? 1 : pid,
12640 +                       func, file, line);
12641 +               if (pid == 0)
12642 +                       return 0;
12643 +               if (pid == vxi->vx_initpid)
12644 +                       return 1;
12645 +       }
12646 +       return pid;
12647 +}
12648 +
12649 +#define vx_info_rmap_pid(v, p) \
12650 +       __vx_info_rmap_pid((v), (p), __func__, __FILE__, __LINE__)
12651 +#define vx_rmap_pid(p) vx_info_rmap_pid(current_vx_info(), p)
12652 +#define vx_rmap_tgid(p) vx_rmap_pid(p)
12653 +
12654 +static inline int __vx_info_rmap_pid(struct vx_info *vxi, int pid,
12655 +       const char *func, const char *file, int line)
12656 +{
12657 +       if (vx_info_flags(vxi, VXF_INFO_INIT, 0)) {
12658 +               vxfprintk(VXD_CBIT(cvirt, 2),
12659 +                       "vx_rmap_tgid: %p/%llx: %d -> %d",
12660 +                       vxi, (long long)vxi->vx_flags, pid,
12661 +                       (pid == 1) ? vxi->vx_initpid : pid,
12662 +                       func, file, line);
12663 +               if ((pid == 1) && vxi->vx_initpid)
12664 +                       return vxi->vx_initpid;
12665 +               if (pid == vxi->vx_initpid)
12666 +                       return ~0U;
12667 +       }
12668 +       return pid;
12669 +}
12670 +
12671 +#endif
12672 diff -NurpP --minimal linux-2.6.32.6/include/linux/vserver/sched_cmd.h linux-2.6.32.6-vs2.3.0.36.28/include/linux/vserver/sched_cmd.h
12673 --- linux-2.6.32.6/include/linux/vserver/sched_cmd.h    1970-01-01 01:00:00.000000000 +0100
12674 +++ linux-2.6.32.6-vs2.3.0.36.28/include/linux/vserver/sched_cmd.h      2009-12-03 20:04:56.000000000 +0100
12675 @@ -0,0 +1,108 @@
12676 +#ifndef _VX_SCHED_CMD_H
12677 +#define _VX_SCHED_CMD_H
12678 +
12679 +
12680 +/*  sched vserver commands */
12681 +
12682 +#define VCMD_set_sched_v2      VC_CMD(SCHED, 1, 2)
12683 +#define VCMD_set_sched_v3      VC_CMD(SCHED, 1, 3)
12684 +#define VCMD_set_sched_v4      VC_CMD(SCHED, 1, 4)
12685 +
12686 +struct vcmd_set_sched_v2 {
12687 +       int32_t fill_rate;
12688 +       int32_t interval;
12689 +       int32_t tokens;
12690 +       int32_t tokens_min;
12691 +       int32_t tokens_max;
12692 +       uint64_t cpu_mask;
12693 +};
12694 +
12695 +struct vcmd_set_sched_v3 {
12696 +       uint32_t set_mask;
12697 +       int32_t fill_rate;
12698 +       int32_t interval;
12699 +       int32_t tokens;
12700 +       int32_t tokens_min;
12701 +       int32_t tokens_max;
12702 +       int32_t priority_bias;
12703 +};
12704 +
12705 +struct vcmd_set_sched_v4 {
12706 +       uint32_t set_mask;
12707 +       int32_t fill_rate;
12708 +       int32_t interval;
12709 +       int32_t tokens;
12710 +       int32_t tokens_min;
12711 +       int32_t tokens_max;
12712 +       int32_t prio_bias;
12713 +       int32_t cpu_id;
12714 +       int32_t bucket_id;
12715 +};
12716 +
12717 +#define VCMD_set_sched         VC_CMD(SCHED, 1, 5)
12718 +#define VCMD_get_sched         VC_CMD(SCHED, 2, 5)
12719 +
12720 +struct vcmd_sched_v5 {
12721 +       uint32_t mask;
12722 +       int32_t cpu_id;
12723 +       int32_t bucket_id;
12724 +       int32_t fill_rate[2];
12725 +       int32_t interval[2];
12726 +       int32_t tokens;
12727 +       int32_t tokens_min;
12728 +       int32_t tokens_max;
12729 +       int32_t prio_bias;
12730 +};
12731 +
12732 +#define VXSM_FILL_RATE         0x0001
12733 +#define VXSM_INTERVAL          0x0002
12734 +#define VXSM_FILL_RATE2                0x0004
12735 +#define VXSM_INTERVAL2         0x0008
12736 +#define VXSM_TOKENS            0x0010
12737 +#define VXSM_TOKENS_MIN                0x0020
12738 +#define VXSM_TOKENS_MAX                0x0040
12739 +#define VXSM_PRIO_BIAS         0x0100
12740 +
12741 +#define VXSM_IDLE_TIME         0x0200
12742 +#define VXSM_FORCE             0x0400
12743 +
12744 +#define        VXSM_V3_MASK            0x0173
12745 +#define        VXSM_SET_MASK           0x01FF
12746 +
12747 +#define VXSM_CPU_ID            0x1000
12748 +#define VXSM_BUCKET_ID         0x2000
12749 +
12750 +#define VXSM_MSEC              0x4000
12751 +
12752 +#define SCHED_KEEP             (-2)    /* only for v2 */
12753 +
12754 +#ifdef __KERNEL__
12755 +
12756 +#include <linux/compiler.h>
12757 +
12758 +extern int vc_set_sched_v2(struct vx_info *, void __user *);
12759 +extern int vc_set_sched_v3(struct vx_info *, void __user *);
12760 +extern int vc_set_sched_v4(struct vx_info *, void __user *);
12761 +extern int vc_set_sched(struct vx_info *, void __user *);
12762 +extern int vc_get_sched(struct vx_info *, void __user *);
12763 +
12764 +#endif /* __KERNEL__ */
12765 +
12766 +#define VCMD_sched_info                VC_CMD(SCHED, 3, 0)
12767 +
12768 +struct vcmd_sched_info {
12769 +       int32_t cpu_id;
12770 +       int32_t bucket_id;
12771 +       uint64_t user_msec;
12772 +       uint64_t sys_msec;
12773 +       uint64_t hold_msec;
12774 +       uint32_t token_usec;
12775 +       int32_t vavavoom;
12776 +};
12777 +
12778 +#ifdef __KERNEL__
12779 +
12780 +extern int vc_sched_info(struct vx_info *, void __user *);
12781 +
12782 +#endif /* __KERNEL__ */
12783 +#endif /* _VX_SCHED_CMD_H */
12784 diff -NurpP --minimal linux-2.6.32.6/include/linux/vserver/sched_def.h linux-2.6.32.6-vs2.3.0.36.28/include/linux/vserver/sched_def.h
12785 --- linux-2.6.32.6/include/linux/vserver/sched_def.h    1970-01-01 01:00:00.000000000 +0100
12786 +++ linux-2.6.32.6-vs2.3.0.36.28/include/linux/vserver/sched_def.h      2009-12-03 20:04:56.000000000 +0100
12787 @@ -0,0 +1,68 @@
12788 +#ifndef _VX_SCHED_DEF_H
12789 +#define _VX_SCHED_DEF_H
12790 +
12791 +#include <linux/spinlock.h>
12792 +#include <linux/jiffies.h>
12793 +#include <linux/cpumask.h>
12794 +#include <asm/atomic.h>
12795 +#include <asm/param.h>
12796 +
12797 +
12798 +/* context sub struct */
12799 +
12800 +struct _vx_sched {
12801 +       spinlock_t tokens_lock;         /* lock for token bucket */
12802 +
12803 +       int tokens;                     /* number of CPU tokens */
12804 +       int fill_rate[2];               /* Fill rate: add X tokens... */
12805 +       int interval[2];                /* Divisor:   per Y jiffies   */
12806 +       int tokens_min;                 /* Limit:     minimum for unhold */
12807 +       int tokens_max;                 /* Limit:     no more than N tokens */
12808 +
12809 +       int prio_bias;                  /* bias offset for priority */
12810 +
12811 +       unsigned update_mask;           /* which features should be updated */
12812 +       cpumask_t update;               /* CPUs which should update */
12813 +};
12814 +
12815 +struct _vx_sched_pc {
12816 +       int tokens;                     /* number of CPU tokens */
12817 +       int flags;                      /* bucket flags */
12818 +
12819 +       int fill_rate[2];               /* Fill rate: add X tokens... */
12820 +       int interval[2];                /* Divisor:   per Y jiffies   */
12821 +       int tokens_min;                 /* Limit:     minimum for unhold */
12822 +       int tokens_max;                 /* Limit:     no more than N tokens */
12823 +
12824 +       int prio_bias;                  /* bias offset for priority */
12825 +       int vavavoom;                   /* last calculated vavavoom */
12826 +
12827 +       unsigned long norm_time;        /* last time accounted */
12828 +       unsigned long idle_time;        /* non linear time for fair sched */
12829 +       unsigned long token_time;       /* token time for accounting */
12830 +       unsigned long onhold;           /* jiffies when put on hold */
12831 +
12832 +       uint64_t user_ticks;            /* token tick events */
12833 +       uint64_t sys_ticks;             /* token tick events */
12834 +       uint64_t hold_ticks;            /* token ticks paused */
12835 +};
12836 +
12837 +
12838 +#define VXSF_ONHOLD    0x0001
12839 +#define VXSF_IDLE_TIME 0x0100
12840 +
12841 +#ifdef CONFIG_VSERVER_DEBUG
12842 +
12843 +static inline void __dump_vx_sched(struct _vx_sched *sched)
12844 +{
12845 +       printk("\t_vx_sched:\n");
12846 +       printk("\t tokens: %4d/%4d, %4d/%4d, %4d, %4d\n",
12847 +               sched->fill_rate[0], sched->interval[0],
12848 +               sched->fill_rate[1], sched->interval[1],
12849 +               sched->tokens_min, sched->tokens_max);
12850 +       printk("\t priority = %4d\n", sched->prio_bias);
12851 +}
12852 +
12853 +#endif
12854 +
12855 +#endif /* _VX_SCHED_DEF_H */
12856 diff -NurpP --minimal linux-2.6.32.6/include/linux/vserver/sched.h linux-2.6.32.6-vs2.3.0.36.28/include/linux/vserver/sched.h
12857 --- linux-2.6.32.6/include/linux/vserver/sched.h        1970-01-01 01:00:00.000000000 +0100
12858 +++ linux-2.6.32.6-vs2.3.0.36.28/include/linux/vserver/sched.h  2009-12-03 20:04:56.000000000 +0100
12859 @@ -0,0 +1,26 @@
12860 +#ifndef _VX_SCHED_H
12861 +#define _VX_SCHED_H
12862 +
12863 +
12864 +#ifdef __KERNEL__
12865 +
12866 +struct timespec;
12867 +
12868 +void vx_vsi_uptime(struct timespec *, struct timespec *);
12869 +
12870 +
12871 +struct vx_info;
12872 +
12873 +void vx_update_load(struct vx_info *);
12874 +
12875 +
12876 +int vx_tokens_recalc(struct _vx_sched_pc *,
12877 +       unsigned long *, unsigned long *, int [2]);
12878 +
12879 +void vx_update_sched_param(struct _vx_sched *sched,
12880 +       struct _vx_sched_pc *sched_pc);
12881 +
12882 +#endif /* __KERNEL__ */
12883 +#else  /* _VX_SCHED_H */
12884 +#warning duplicate inclusion
12885 +#endif /* _VX_SCHED_H */
12886 diff -NurpP --minimal linux-2.6.32.6/include/linux/vserver/signal_cmd.h linux-2.6.32.6-vs2.3.0.36.28/include/linux/vserver/signal_cmd.h
12887 --- linux-2.6.32.6/include/linux/vserver/signal_cmd.h   1970-01-01 01:00:00.000000000 +0100
12888 +++ linux-2.6.32.6-vs2.3.0.36.28/include/linux/vserver/signal_cmd.h     2009-12-03 20:04:56.000000000 +0100
12889 @@ -0,0 +1,43 @@
12890 +#ifndef _VX_SIGNAL_CMD_H
12891 +#define _VX_SIGNAL_CMD_H
12892 +
12893 +
12894 +/*  signalling vserver commands */
12895 +
12896 +#define VCMD_ctx_kill          VC_CMD(PROCTRL, 1, 0)
12897 +#define VCMD_wait_exit         VC_CMD(EVENT, 99, 0)
12898 +
12899 +struct vcmd_ctx_kill_v0 {
12900 +       int32_t pid;
12901 +       int32_t sig;
12902 +};
12903 +
12904 +struct vcmd_wait_exit_v0 {
12905 +       int32_t reboot_cmd;
12906 +       int32_t exit_code;
12907 +};
12908 +
12909 +#ifdef __KERNEL__
12910 +
12911 +extern int vc_ctx_kill(struct vx_info *, void __user *);
12912 +extern int vc_wait_exit(struct vx_info *, void __user *);
12913 +
12914 +#endif /* __KERNEL__ */
12915 +
12916 +/*  process alteration commands */
12917 +
12918 +#define VCMD_get_pflags                VC_CMD(PROCALT, 5, 0)
12919 +#define VCMD_set_pflags                VC_CMD(PROCALT, 6, 0)
12920 +
12921 +struct vcmd_pflags_v0 {
12922 +       uint32_t flagword;
12923 +       uint32_t mask;
12924 +};
12925 +
12926 +#ifdef __KERNEL__
12927 +
12928 +extern int vc_get_pflags(uint32_t pid, void __user *);
12929 +extern int vc_set_pflags(uint32_t pid, void __user *);
12930 +
12931 +#endif /* __KERNEL__ */
12932 +#endif /* _VX_SIGNAL_CMD_H */
12933 diff -NurpP --minimal linux-2.6.32.6/include/linux/vserver/signal.h linux-2.6.32.6-vs2.3.0.36.28/include/linux/vserver/signal.h
12934 --- linux-2.6.32.6/include/linux/vserver/signal.h       1970-01-01 01:00:00.000000000 +0100
12935 +++ linux-2.6.32.6-vs2.3.0.36.28/include/linux/vserver/signal.h 2009-12-03 20:04:56.000000000 +0100
12936 @@ -0,0 +1,14 @@
12937 +#ifndef _VX_SIGNAL_H
12938 +#define _VX_SIGNAL_H
12939 +
12940 +
12941 +#ifdef __KERNEL__
12942 +
12943 +struct vx_info;
12944 +
12945 +int vx_info_kill(struct vx_info *, int, int);
12946 +
12947 +#endif /* __KERNEL__ */
12948 +#else  /* _VX_SIGNAL_H */
12949 +#warning duplicate inclusion
12950 +#endif /* _VX_SIGNAL_H */
12951 diff -NurpP --minimal linux-2.6.32.6/include/linux/vserver/space_cmd.h linux-2.6.32.6-vs2.3.0.36.28/include/linux/vserver/space_cmd.h
12952 --- linux-2.6.32.6/include/linux/vserver/space_cmd.h    1970-01-01 01:00:00.000000000 +0100
12953 +++ linux-2.6.32.6-vs2.3.0.36.28/include/linux/vserver/space_cmd.h      2009-12-03 20:04:56.000000000 +0100
12954 @@ -0,0 +1,38 @@
12955 +#ifndef _VX_SPACE_CMD_H
12956 +#define _VX_SPACE_CMD_H
12957 +
12958 +
12959 +#define VCMD_enter_space_v0    VC_CMD(PROCALT, 1, 0)
12960 +#define VCMD_enter_space_v1    VC_CMD(PROCALT, 1, 1)
12961 +#define VCMD_enter_space       VC_CMD(PROCALT, 1, 2)
12962 +
12963 +#define VCMD_set_space_v0      VC_CMD(PROCALT, 3, 0)
12964 +#define VCMD_set_space_v1      VC_CMD(PROCALT, 3, 1)
12965 +#define VCMD_set_space         VC_CMD(PROCALT, 3, 2)
12966 +
12967 +#define VCMD_get_space_mask_v0 VC_CMD(PROCALT, 4, 0)
12968 +
12969 +#define VCMD_get_space_mask    VC_CMD(VSPACE, 0, 1)
12970 +#define VCMD_get_space_default VC_CMD(VSPACE, 1, 0)
12971 +
12972 +
12973 +struct vcmd_space_mask_v1 {
12974 +       uint64_t mask;
12975 +};
12976 +
12977 +struct vcmd_space_mask_v2 {
12978 +       uint64_t mask;
12979 +       uint32_t index;
12980 +};
12981 +
12982 +
12983 +#ifdef __KERNEL__
12984 +
12985 +extern int vc_enter_space_v1(struct vx_info *, void __user *);
12986 +extern int vc_set_space_v1(struct vx_info *, void __user *);
12987 +extern int vc_enter_space(struct vx_info *, void __user *);
12988 +extern int vc_set_space(struct vx_info *, void __user *);
12989 +extern int vc_get_space_mask(void __user *, int);
12990 +
12991 +#endif /* __KERNEL__ */
12992 +#endif /* _VX_SPACE_CMD_H */
12993 diff -NurpP --minimal linux-2.6.32.6/include/linux/vserver/space.h linux-2.6.32.6-vs2.3.0.36.28/include/linux/vserver/space.h
12994 --- linux-2.6.32.6/include/linux/vserver/space.h        1970-01-01 01:00:00.000000000 +0100
12995 +++ linux-2.6.32.6-vs2.3.0.36.28/include/linux/vserver/space.h  2009-12-03 20:04:56.000000000 +0100
12996 @@ -0,0 +1,12 @@
12997 +#ifndef _VX_SPACE_H
12998 +#define _VX_SPACE_H
12999 +
13000 +#include <linux/types.h>
13001 +
13002 +struct vx_info;
13003 +
13004 +int vx_set_space(struct vx_info *vxi, unsigned long mask, unsigned index);
13005 +
13006 +#else  /* _VX_SPACE_H */
13007 +#warning duplicate inclusion
13008 +#endif /* _VX_SPACE_H */
13009 diff -NurpP --minimal linux-2.6.32.6/include/linux/vserver/switch.h linux-2.6.32.6-vs2.3.0.36.28/include/linux/vserver/switch.h
13010 --- linux-2.6.32.6/include/linux/vserver/switch.h       1970-01-01 01:00:00.000000000 +0100
13011 +++ linux-2.6.32.6-vs2.3.0.36.28/include/linux/vserver/switch.h 2009-12-03 20:04:56.000000000 +0100
13012 @@ -0,0 +1,98 @@
13013 +#ifndef _VX_SWITCH_H
13014 +#define _VX_SWITCH_H
13015 +
13016 +#include <linux/types.h>
13017 +
13018 +
13019 +#define VC_CATEGORY(c)         (((c) >> 24) & 0x3F)
13020 +#define VC_COMMAND(c)          (((c) >> 16) & 0xFF)
13021 +#define VC_VERSION(c)          ((c) & 0xFFF)
13022 +
13023 +#define VC_CMD(c, i, v)                ((((VC_CAT_ ## c) & 0x3F) << 24) \
13024 +                               | (((i) & 0xFF) << 16) | ((v) & 0xFFF))
13025 +
13026 +/*
13027 +
13028 +  Syscall Matrix V2.8
13029 +
13030 +        |VERSION|CREATE |MODIFY |MIGRATE|CONTROL|EXPERIM| |SPECIAL|SPECIAL|
13031 +        |STATS  |DESTROY|ALTER  |CHANGE |LIMIT  |TEST   | |       |       |
13032 +        |INFO   |SETUP  |       |MOVE   |       |       | |       |       |
13033 +  -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
13034 +  SYSTEM |VERSION|VSETUP |VHOST  |       |       |       | |DEVICE |       |
13035 +  HOST   |     00|     01|     02|     03|     04|     05| |     06|     07|
13036 +  -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
13037 +  CPU    |       |VPROC  |PROCALT|PROCMIG|PROCTRL|       | |SCHED. |       |
13038 +  PROCESS|     08|     09|     10|     11|     12|     13| |     14|     15|
13039 +  -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
13040 +  MEMORY |       |       |       |       |MEMCTRL|       | |SWAP   |       |
13041 +        |     16|     17|     18|     19|     20|     21| |     22|     23|
13042 +  -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
13043 +  NETWORK|       |VNET   |NETALT |NETMIG |NETCTL |       | |SERIAL |       |
13044 +        |     24|     25|     26|     27|     28|     29| |     30|     31|
13045 +  -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
13046 +  DISK   |       |       |       |TAGMIG |DLIMIT |       | |INODE  |       |
13047 +  VFS    |     32|     33|     34|     35|     36|     37| |     38|     39|
13048 +  -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
13049 +  OTHER  |VSTAT  |       |       |       |       |       | |VINFO  |       |
13050 +        |     40|     41|     42|     43|     44|     45| |     46|     47|
13051 +  =======+=======+=======+=======+=======+=======+=======+ +=======+=======+
13052 +  SPECIAL|EVENT  |       |       |       |FLAGS  |       | |VSPACE |       |
13053 +        |     48|     49|     50|     51|     52|     53| |     54|     55|
13054 +  -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
13055 +  SPECIAL|DEBUG  |       |       |       |RLIMIT |SYSCALL| |       |COMPAT |
13056 +        |     56|     57|     58|     59|     60|TEST 61| |     62|     63|
13057 +  -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
13058 +
13059 +*/
13060 +
13061 +#define VC_CAT_VERSION         0
13062 +
13063 +#define VC_CAT_VSETUP          1
13064 +#define VC_CAT_VHOST           2
13065 +
13066 +#define VC_CAT_DEVICE          6
13067 +
13068 +#define VC_CAT_VPROC           9
13069 +#define VC_CAT_PROCALT         10
13070 +#define VC_CAT_PROCMIG         11
13071 +#define VC_CAT_PROCTRL         12
13072 +
13073 +#define VC_CAT_SCHED           14
13074 +#define VC_CAT_MEMCTRL         20
13075 +
13076 +#define VC_CAT_VNET            25
13077 +#define VC_CAT_NETALT          26
13078 +#define VC_CAT_NETMIG          27
13079 +#define VC_CAT_NETCTRL         28
13080 +
13081 +#define VC_CAT_TAGMIG          35
13082 +#define VC_CAT_DLIMIT          36
13083 +#define VC_CAT_INODE           38
13084 +
13085 +#define VC_CAT_VSTAT           40
13086 +#define VC_CAT_VINFO           46
13087 +#define VC_CAT_EVENT           48
13088 +
13089 +#define VC_CAT_FLAGS           52
13090 +#define VC_CAT_VSPACE          54
13091 +#define VC_CAT_DEBUG           56
13092 +#define VC_CAT_RLIMIT          60
13093 +
13094 +#define VC_CAT_SYSTEST         61
13095 +#define VC_CAT_COMPAT          63
13096 +
13097 +/*  query version */
13098 +
13099 +#define VCMD_get_version       VC_CMD(VERSION, 0, 0)
13100 +#define VCMD_get_vci           VC_CMD(VERSION, 1, 0)
13101 +
13102 +
13103 +#ifdef __KERNEL__
13104 +
13105 +#include <linux/errno.h>
13106 +
13107 +#endif /* __KERNEL__ */
13108 +
13109 +#endif /* _VX_SWITCH_H */
13110 +
13111 diff -NurpP --minimal linux-2.6.32.6/include/linux/vserver/tag_cmd.h linux-2.6.32.6-vs2.3.0.36.28/include/linux/vserver/tag_cmd.h
13112 --- linux-2.6.32.6/include/linux/vserver/tag_cmd.h      1970-01-01 01:00:00.000000000 +0100
13113 +++ linux-2.6.32.6-vs2.3.0.36.28/include/linux/vserver/tag_cmd.h        2009-12-03 20:04:56.000000000 +0100
13114 @@ -0,0 +1,22 @@
13115 +#ifndef _VX_TAG_CMD_H
13116 +#define _VX_TAG_CMD_H
13117 +
13118 +
13119 +/* vinfo commands */
13120 +
13121 +#define VCMD_task_tag          VC_CMD(VINFO, 3, 0)
13122 +
13123 +#ifdef __KERNEL__
13124 +extern int vc_task_tag(uint32_t);
13125 +
13126 +#endif /* __KERNEL__ */
13127 +
13128 +/* context commands */
13129 +
13130 +#define VCMD_tag_migrate       VC_CMD(TAGMIG, 1, 0)
13131 +
13132 +#ifdef __KERNEL__
13133 +extern int vc_tag_migrate(uint32_t);
13134 +
13135 +#endif /* __KERNEL__ */
13136 +#endif /* _VX_TAG_CMD_H */
13137 diff -NurpP --minimal linux-2.6.32.6/include/linux/vserver/tag.h linux-2.6.32.6-vs2.3.0.36.28/include/linux/vserver/tag.h
13138 --- linux-2.6.32.6/include/linux/vserver/tag.h  1970-01-01 01:00:00.000000000 +0100
13139 +++ linux-2.6.32.6-vs2.3.0.36.28/include/linux/vserver/tag.h    2009-12-03 20:04:56.000000000 +0100
13140 @@ -0,0 +1,143 @@
13141 +#ifndef _DX_TAG_H
13142 +#define _DX_TAG_H
13143 +
13144 +#include <linux/types.h>
13145 +
13146 +
13147 +#define DX_TAG(in)     (IS_TAGGED(in))
13148 +
13149 +
13150 +#ifdef CONFIG_TAG_NFSD
13151 +#define DX_TAG_NFSD    1
13152 +#else
13153 +#define DX_TAG_NFSD    0
13154 +#endif
13155 +
13156 +
13157 +#ifdef CONFIG_TAGGING_NONE
13158 +
13159 +#define MAX_UID                0xFFFFFFFF
13160 +#define MAX_GID                0xFFFFFFFF
13161 +
13162 +#define INOTAG_TAG(cond, uid, gid, tag)        (0)
13163 +
13164 +#define TAGINO_UID(cond, uid, tag)     (uid)
13165 +#define TAGINO_GID(cond, gid, tag)     (gid)
13166 +
13167 +#endif
13168 +
13169 +
13170 +#ifdef CONFIG_TAGGING_GID16
13171 +
13172 +#define MAX_UID                0xFFFFFFFF
13173 +#define MAX_GID                0x0000FFFF
13174 +
13175 +#define INOTAG_TAG(cond, uid, gid, tag)        \
13176 +       ((cond) ? (((gid) >> 16) & 0xFFFF) : 0)
13177 +
13178 +#define TAGINO_UID(cond, uid, tag)     (uid)
13179 +#define TAGINO_GID(cond, gid, tag)     \
13180 +       ((cond) ? (((gid) & 0xFFFF) | ((tag) << 16)) : (gid))
13181 +
13182 +#endif
13183 +
13184 +
13185 +#ifdef CONFIG_TAGGING_ID24
13186 +
13187 +#define MAX_UID                0x00FFFFFF
13188 +#define MAX_GID                0x00FFFFFF
13189 +
13190 +#define INOTAG_TAG(cond, uid, gid, tag)        \
13191 +       ((cond) ? ((((uid) >> 16) & 0xFF00) | (((gid) >> 24) & 0xFF)) : 0)
13192 +
13193 +#define TAGINO_UID(cond, uid, tag)     \
13194 +       ((cond) ? (((uid) & 0xFFFFFF) | (((tag) & 0xFF00) << 16)) : (uid))
13195 +#define TAGINO_GID(cond, gid, tag)     \
13196 +       ((cond) ? (((gid) & 0xFFFFFF) | (((tag) & 0x00FF) << 24)) : (gid))
13197 +
13198 +#endif
13199 +
13200 +
13201 +#ifdef CONFIG_TAGGING_UID16
13202 +
13203 +#define MAX_UID                0x0000FFFF
13204 +#define MAX_GID                0xFFFFFFFF
13205 +
13206 +#define INOTAG_TAG(cond, uid, gid, tag)        \
13207 +       ((cond) ? (((uid) >> 16) & 0xFFFF) : 0)
13208 +
13209 +#define TAGINO_UID(cond, uid, tag)     \
13210 +       ((cond) ? (((uid) & 0xFFFF) | ((tag) << 16)) : (uid))
13211 +#define TAGINO_GID(cond, gid, tag)     (gid)
13212 +
13213 +#endif
13214 +
13215 +
13216 +#ifdef CONFIG_TAGGING_INTERN
13217 +
13218 +#define MAX_UID                0xFFFFFFFF
13219 +#define MAX_GID                0xFFFFFFFF
13220 +
13221 +#define INOTAG_TAG(cond, uid, gid, tag)        \
13222 +       ((cond) ? (tag) : 0)
13223 +
13224 +#define TAGINO_UID(cond, uid, tag)     (uid)
13225 +#define TAGINO_GID(cond, gid, tag)     (gid)
13226 +
13227 +#endif
13228 +
13229 +
13230 +#ifndef CONFIG_TAGGING_NONE
13231 +#define dx_current_fstag(sb)   \
13232 +       ((sb)->s_flags & MS_TAGGED ? dx_current_tag() : 0)
13233 +#else
13234 +#define dx_current_fstag(sb)   (0)
13235 +#endif
13236 +
13237 +#ifndef CONFIG_TAGGING_INTERN
13238 +#define TAGINO_TAG(cond, tag)  (0)
13239 +#else
13240 +#define TAGINO_TAG(cond, tag)  ((cond) ? (tag) : 0)
13241 +#endif
13242 +
13243 +#define INOTAG_UID(cond, uid, gid)     \
13244 +       ((cond) ? ((uid) & MAX_UID) : (uid))
13245 +#define INOTAG_GID(cond, uid, gid)     \
13246 +       ((cond) ? ((gid) & MAX_GID) : (gid))
13247 +
13248 +
13249 +static inline uid_t dx_map_uid(uid_t uid)
13250 +{
13251 +       if ((uid > MAX_UID) && (uid != -1))
13252 +               uid = -2;
13253 +       return (uid & MAX_UID);
13254 +}
13255 +
13256 +static inline gid_t dx_map_gid(gid_t gid)
13257 +{
13258 +       if ((gid > MAX_GID) && (gid != -1))
13259 +               gid = -2;
13260 +       return (gid & MAX_GID);
13261 +}
13262 +
13263 +struct peer_tag {
13264 +       int32_t xid;
13265 +       int32_t nid;
13266 +};
13267 +
13268 +#define dx_notagcheck(sb) ((sb) && ((sb)->s_flags & MS_NOTAGCHECK))
13269 +
13270 +int dx_parse_tag(char *string, tag_t *tag, int remove, int *mnt_flags,
13271 +                unsigned long *flags);
13272 +
13273 +#ifdef CONFIG_PROPAGATE
13274 +
13275 +void __dx_propagate_tag(struct nameidata *nd, struct inode *inode);
13276 +
13277 +#define dx_propagate_tag(n, i) __dx_propagate_tag(n, i)
13278 +
13279 +#else
13280 +#define dx_propagate_tag(n, i) do { } while (0)
13281 +#endif
13282 +
13283 +#endif /* _DX_TAG_H */
13284 diff -NurpP --minimal linux-2.6.32.6/include/linux/vs_inet6.h linux-2.6.32.6-vs2.3.0.36.28/include/linux/vs_inet6.h
13285 --- linux-2.6.32.6/include/linux/vs_inet6.h     1970-01-01 01:00:00.000000000 +0100
13286 +++ linux-2.6.32.6-vs2.3.0.36.28/include/linux/vs_inet6.h       2009-12-03 20:04:56.000000000 +0100
13287 @@ -0,0 +1,246 @@
13288 +#ifndef _VS_INET6_H
13289 +#define _VS_INET6_H
13290 +
13291 +#include "vserver/base.h"
13292 +#include "vserver/network.h"
13293 +#include "vserver/debug.h"
13294 +
13295 +#include <net/ipv6.h>
13296 +
13297 +#define NXAV6(a)       &(a)->ip, &(a)->mask, (a)->prefix, (a)->type
13298 +#define NXAV6_FMT      "[%pI6/%pI6/%d:%04x]"
13299 +
13300 +
13301 +#ifdef CONFIG_IPV6
13302 +
13303 +static inline
13304 +int v6_addr_match(struct nx_addr_v6 *nxa,
13305 +       const struct in6_addr *addr, uint16_t mask)
13306 +{
13307 +       int ret = 0;
13308 +
13309 +       switch (nxa->type & mask) {
13310 +       case NXA_TYPE_MASK:
13311 +               ret = ipv6_masked_addr_cmp(&nxa->ip, &nxa->mask, addr);
13312 +               break;
13313 +       case NXA_TYPE_ADDR:
13314 +               ret = ipv6_addr_equal(&nxa->ip, addr);
13315 +               break;
13316 +       case NXA_TYPE_ANY:
13317 +               ret = 1;
13318 +               break;
13319 +       }
13320 +       vxdprintk(VXD_CBIT(net, 0),
13321 +               "v6_addr_match(%p" NXAV6_FMT ",%pI6,%04x) = %d",
13322 +               nxa, NXAV6(nxa), addr, mask, ret);
13323 +       return ret;
13324 +}
13325 +
13326 +static inline
13327 +int v6_addr_in_nx_info(struct nx_info *nxi,
13328 +       const struct in6_addr *addr, uint16_t mask)
13329 +{
13330 +       struct nx_addr_v6 *nxa;
13331 +       int ret = 1;
13332 +
13333 +       if (!nxi)
13334 +               goto out;
13335 +       for (nxa = &nxi->v6; nxa; nxa = nxa->next)
13336 +               if (v6_addr_match(nxa, addr, mask))
13337 +                       goto out;
13338 +       ret = 0;
13339 +out:
13340 +       vxdprintk(VXD_CBIT(net, 0),
13341 +               "v6_addr_in_nx_info(%p[#%u],%pI6,%04x) = %d",
13342 +               nxi, nxi ? nxi->nx_id : 0, addr, mask, ret);
13343 +       return ret;
13344 +}
13345 +
13346 +static inline
13347 +int v6_nx_addr_match(struct nx_addr_v6 *nxa, struct nx_addr_v6 *addr, uint16_t mask)
13348 +{
13349 +       /* FIXME: needs full range checks */
13350 +       return v6_addr_match(nxa, &addr->ip, mask);
13351 +}
13352 +
13353 +static inline
13354 +int v6_nx_addr_in_nx_info(struct nx_info *nxi, struct nx_addr_v6 *nxa, uint16_t mask)
13355 +{
13356 +       struct nx_addr_v6 *ptr;
13357 +
13358 +       for (ptr = &nxi->v6; ptr; ptr = ptr->next)
13359 +               if (v6_nx_addr_match(ptr, nxa, mask))
13360 +                       return 1;
13361 +       return 0;
13362 +}
13363 +
13364 +
13365 +/*
13366 + *     Check if a given address matches for a socket
13367 + *
13368 + *     nxi:            the socket's nx_info if any
13369 + *     addr:           to be verified address
13370 + */
13371 +static inline
13372 +int v6_sock_addr_match (
13373 +       struct nx_info *nxi,
13374 +       struct inet_sock *inet,
13375 +       struct in6_addr *addr)
13376 +{
13377 +       struct sock *sk = &inet->sk;
13378 +       struct in6_addr *saddr = inet6_rcv_saddr(sk);
13379 +
13380 +       if (!ipv6_addr_any(addr) &&
13381 +               ipv6_addr_equal(saddr, addr))
13382 +               return 1;
13383 +       if (ipv6_addr_any(saddr))
13384 +               return v6_addr_in_nx_info(nxi, addr, -1);
13385 +       return 0;
13386 +}
13387 +
13388 +/*
13389 + *     check if address is covered by socket
13390 + *
13391 + *     sk:     the socket to check against
13392 + *     addr:   the address in question (must be != 0)
13393 + */
13394 +
13395 +static inline
13396 +int __v6_addr_match_socket(const struct sock *sk, struct nx_addr_v6 *nxa)
13397 +{
13398 +       struct nx_info *nxi = sk->sk_nx_info;
13399 +       struct in6_addr *saddr = inet6_rcv_saddr(sk);
13400 +
13401 +       vxdprintk(VXD_CBIT(net, 5),
13402 +               "__v6_addr_in_socket(%p," NXAV6_FMT ") %p:%pI6 %p;%lx",
13403 +               sk, NXAV6(nxa), nxi, saddr, sk->sk_socket,
13404 +               (sk->sk_socket?sk->sk_socket->flags:0));
13405 +
13406 +       if (!ipv6_addr_any(saddr)) {    /* direct address match */
13407 +               return v6_addr_match(nxa, saddr, -1);
13408 +       } else if (nxi) {               /* match against nx_info */
13409 +               return v6_nx_addr_in_nx_info(nxi, nxa, -1);
13410 +       } else {                        /* unrestricted any socket */
13411 +               return 1;
13412 +       }
13413 +}
13414 +
13415 +
13416 +/* inet related checks and helpers */
13417 +
13418 +
13419 +struct in_ifaddr;
13420 +struct net_device;
13421 +struct sock;
13422 +
13423 +
13424 +#include <linux/netdevice.h>
13425 +#include <linux/inetdevice.h>
13426 +#include <net/inet_timewait_sock.h>
13427 +
13428 +
13429 +int dev_in_nx_info(struct net_device *, struct nx_info *);
13430 +int v6_dev_in_nx_info(struct net_device *, struct nx_info *);
13431 +int nx_v6_addr_conflict(struct nx_info *, struct nx_info *);
13432 +
13433 +
13434 +
13435 +static inline
13436 +int v6_ifa_in_nx_info(struct inet6_ifaddr *ifa, struct nx_info *nxi)
13437 +{
13438 +       if (!nxi)
13439 +               return 1;
13440 +       if (!ifa)
13441 +               return 0;
13442 +       return v6_addr_in_nx_info(nxi, &ifa->addr, -1);
13443 +}
13444 +
13445 +static inline
13446 +int nx_v6_ifa_visible(struct nx_info *nxi, struct inet6_ifaddr *ifa)
13447 +{
13448 +       vxdprintk(VXD_CBIT(net, 1), "nx_v6_ifa_visible(%p[#%u],%p) %d",
13449 +               nxi, nxi ? nxi->nx_id : 0, ifa,
13450 +               nxi ? v6_ifa_in_nx_info(ifa, nxi) : 0);
13451 +
13452 +       if (!nx_info_flags(nxi, NXF_HIDE_NETIF, 0))
13453 +               return 1;
13454 +       if (v6_ifa_in_nx_info(ifa, nxi))
13455 +               return 1;
13456 +       return 0;
13457 +}
13458 +
13459 +
13460 +struct nx_v6_sock_addr {
13461 +       struct in6_addr saddr;  /* Address used for validation */
13462 +       struct in6_addr baddr;  /* Address used for socket bind */
13463 +};
13464 +
13465 +static inline
13466 +int v6_map_sock_addr(struct inet_sock *inet, struct sockaddr_in6 *addr,
13467 +       struct nx_v6_sock_addr *nsa)
13468 +{
13469 +       // struct sock *sk = &inet->sk;
13470 +       // struct nx_info *nxi = sk->sk_nx_info;
13471 +       struct in6_addr saddr = addr->sin6_addr;
13472 +       struct in6_addr baddr = saddr;
13473 +
13474 +       nsa->saddr = saddr;
13475 +       nsa->baddr = baddr;
13476 +       return 0;
13477 +}
13478 +
13479 +static inline
13480 +void v6_set_sock_addr(struct inet_sock *inet, struct nx_v6_sock_addr *nsa)
13481 +{
13482 +       // struct sock *sk = &inet->sk;
13483 +       // struct in6_addr *saddr = inet6_rcv_saddr(sk);
13484 +
13485 +       // *saddr = nsa->baddr;
13486 +       // inet->saddr = nsa->baddr;
13487 +}
13488 +
13489 +static inline
13490 +int nx_info_has_v6(struct nx_info *nxi)
13491 +{
13492 +       if (!nxi)
13493 +               return 1;
13494 +       if (NX_IPV6(nxi))
13495 +               return 1;
13496 +       return 0;
13497 +}
13498 +
13499 +#else /* CONFIG_IPV6 */
13500 +
13501 +static inline
13502 +int nx_v6_dev_visible(struct nx_info *n, struct net_device *d)
13503 +{
13504 +       return 1;
13505 +}
13506 +
13507 +
13508 +static inline
13509 +int nx_v6_addr_conflict(struct nx_info *n, uint32_t a, const struct sock *s)
13510 +{
13511 +       return 1;
13512 +}
13513 +
13514 +static inline
13515 +int v6_ifa_in_nx_info(struct in_ifaddr *a, struct nx_info *n)
13516 +{
13517 +       return 1;
13518 +}
13519 +
13520 +static inline
13521 +int nx_info_has_v6(struct nx_info *nxi)
13522 +{
13523 +       return 0;
13524 +}
13525 +
13526 +#endif /* CONFIG_IPV6 */
13527 +
13528 +#define current_nx_info_has_v6() \
13529 +       nx_info_has_v6(current_nx_info())
13530 +
13531 +#else
13532 +#warning duplicate inclusion
13533 +#endif
13534 diff -NurpP --minimal linux-2.6.32.6/include/linux/vs_inet.h linux-2.6.32.6-vs2.3.0.36.28/include/linux/vs_inet.h
13535 --- linux-2.6.32.6/include/linux/vs_inet.h      1970-01-01 01:00:00.000000000 +0100
13536 +++ linux-2.6.32.6-vs2.3.0.36.28/include/linux/vs_inet.h        2009-12-03 20:04:56.000000000 +0100
13537 @@ -0,0 +1,342 @@
13538 +#ifndef _VS_INET_H
13539 +#define _VS_INET_H
13540 +
13541 +#include "vserver/base.h"
13542 +#include "vserver/network.h"
13543 +#include "vserver/debug.h"
13544 +
13545 +#define IPI_LOOPBACK   htonl(INADDR_LOOPBACK)
13546 +
13547 +#define NXAV4(a)       NIPQUAD((a)->ip[0]), NIPQUAD((a)->ip[1]), \
13548 +                       NIPQUAD((a)->mask), (a)->type
13549 +#define NXAV4_FMT      "[" NIPQUAD_FMT "-" NIPQUAD_FMT "/" NIPQUAD_FMT ":%04x]"
13550 +
13551 +
13552 +static inline
13553 +int v4_addr_match(struct nx_addr_v4 *nxa, __be32 addr, uint16_t tmask)
13554 +{
13555 +       __be32 ip = nxa->ip[0].s_addr;
13556 +       __be32 mask = nxa->mask.s_addr;
13557 +       __be32 bcast = ip | ~mask;
13558 +       int ret = 0;
13559 +
13560 +       switch (nxa->type & tmask) {
13561 +       case NXA_TYPE_MASK:
13562 +               ret = (ip == (addr & mask));
13563 +               break;
13564 +       case NXA_TYPE_ADDR:
13565 +               ret = 3;
13566 +               if (addr == ip)
13567 +                       break;
13568 +               /* fall through to broadcast */
13569 +       case NXA_MOD_BCAST:
13570 +               ret = ((tmask & NXA_MOD_BCAST) && (addr == bcast));
13571 +               break;
13572 +       case NXA_TYPE_RANGE:
13573 +               ret = ((nxa->ip[0].s_addr <= addr) &&
13574 +                       (nxa->ip[1].s_addr > addr));
13575 +               break;
13576 +       case NXA_TYPE_ANY:
13577 +               ret = 2;
13578 +               break;
13579 +       }
13580 +
13581 +       vxdprintk(VXD_CBIT(net, 0),
13582 +               "v4_addr_match(%p" NXAV4_FMT "," NIPQUAD_FMT ",%04x) = %d",
13583 +               nxa, NXAV4(nxa), NIPQUAD(addr), tmask, ret);
13584 +       return ret;
13585 +}
13586 +
13587 +static inline
13588 +int v4_addr_in_nx_info(struct nx_info *nxi, __be32 addr, uint16_t tmask)
13589 +{
13590 +       struct nx_addr_v4 *nxa;
13591 +       int ret = 1;
13592 +
13593 +       if (!nxi)
13594 +               goto out;
13595 +
13596 +       ret = 2;
13597 +       /* allow 127.0.0.1 when remapping lback */
13598 +       if ((tmask & NXA_LOOPBACK) &&
13599 +               (addr == IPI_LOOPBACK) &&
13600 +               nx_info_flags(nxi, NXF_LBACK_REMAP, 0))
13601 +               goto out;
13602 +       ret = 3;
13603 +       /* check for lback address */
13604 +       if ((tmask & NXA_MOD_LBACK) &&
13605 +               (nxi->v4_lback.s_addr == addr))
13606 +               goto out;
13607 +       ret = 4;
13608 +       /* check for broadcast address */
13609 +       if ((tmask & NXA_MOD_BCAST) &&
13610 +               (nxi->v4_bcast.s_addr == addr))
13611 +               goto out;
13612 +       ret = 5;
13613 +       /* check for v4 addresses */
13614 +       for (nxa = &nxi->v4; nxa; nxa = nxa->next)
13615 +               if (v4_addr_match(nxa, addr, tmask))
13616 +                       goto out;
13617 +       ret = 0;
13618 +out:
13619 +       vxdprintk(VXD_CBIT(net, 0),
13620 +               "v4_addr_in_nx_info(%p[#%u]," NIPQUAD_FMT ",%04x) = %d",
13621 +               nxi, nxi ? nxi->nx_id : 0, NIPQUAD(addr), tmask, ret);
13622 +       return ret;
13623 +}
13624 +
13625 +static inline
13626 +int v4_nx_addr_match(struct nx_addr_v4 *nxa, struct nx_addr_v4 *addr, uint16_t mask)
13627 +{
13628 +       /* FIXME: needs full range checks */
13629 +       return v4_addr_match(nxa, addr->ip[0].s_addr, mask);
13630 +}
13631 +
13632 +static inline
13633 +int v4_nx_addr_in_nx_info(struct nx_info *nxi, struct nx_addr_v4 *nxa, uint16_t mask)
13634 +{
13635 +       struct nx_addr_v4 *ptr;
13636 +
13637 +       for (ptr = &nxi->v4; ptr; ptr = ptr->next)
13638 +               if (v4_nx_addr_match(ptr, nxa, mask))
13639 +                       return 1;
13640 +       return 0;
13641 +}
13642 +
13643 +#include <net/inet_sock.h>
13644 +
13645 +/*
13646 + *     Check if a given address matches for a socket
13647 + *
13648 + *     nxi:            the socket's nx_info if any
13649 + *     addr:           to be verified address
13650 + */
13651 +static inline
13652 +int v4_sock_addr_match (
13653 +       struct nx_info *nxi,
13654 +       struct inet_sock *inet,
13655 +       __be32 addr)
13656 +{
13657 +       __be32 saddr = inet->rcv_saddr;
13658 +       __be32 bcast = nxi ? nxi->v4_bcast.s_addr : INADDR_BROADCAST;
13659 +
13660 +       if (addr && (saddr == addr || bcast == addr))
13661 +               return 1;
13662 +       if (!saddr)
13663 +               return v4_addr_in_nx_info(nxi, addr, NXA_MASK_BIND);
13664 +       return 0;
13665 +}
13666 +
13667 +
13668 +/* inet related checks and helpers */
13669 +
13670 +
13671 +struct in_ifaddr;
13672 +struct net_device;
13673 +struct sock;
13674 +
13675 +#ifdef CONFIG_INET
13676 +
13677 +#include <linux/netdevice.h>
13678 +#include <linux/inetdevice.h>
13679 +#include <net/inet_sock.h>
13680 +#include <net/inet_timewait_sock.h>
13681 +
13682 +
13683 +int dev_in_nx_info(struct net_device *, struct nx_info *);
13684 +int v4_dev_in_nx_info(struct net_device *, struct nx_info *);
13685 +int nx_v4_addr_conflict(struct nx_info *, struct nx_info *);
13686 +
13687 +
13688 +/*
13689 + *     check if address is covered by socket
13690 + *
13691 + *     sk:     the socket to check against
13692 + *     addr:   the address in question (must be != 0)
13693 + */
13694 +
13695 +static inline
13696 +int __v4_addr_match_socket(const struct sock *sk, struct nx_addr_v4 *nxa)
13697 +{
13698 +       struct nx_info *nxi = sk->sk_nx_info;
13699 +       __be32 saddr = inet_rcv_saddr(sk);
13700 +
13701 +       vxdprintk(VXD_CBIT(net, 5),
13702 +               "__v4_addr_in_socket(%p," NXAV4_FMT ") %p:" NIPQUAD_FMT " %p;%lx",
13703 +               sk, NXAV4(nxa), nxi, NIPQUAD(saddr), sk->sk_socket,
13704 +               (sk->sk_socket?sk->sk_socket->flags:0));
13705 +
13706 +       if (saddr) {            /* direct address match */
13707 +               return v4_addr_match(nxa, saddr, -1);
13708 +       } else if (nxi) {       /* match against nx_info */
13709 +               return v4_nx_addr_in_nx_info(nxi, nxa, -1);
13710 +       } else {                /* unrestricted any socket */
13711 +               return 1;
13712 +       }
13713 +}
13714 +
13715 +
13716 +
13717 +static inline
13718 +int nx_dev_visible(struct nx_info *nxi, struct net_device *dev)
13719 +{
13720 +       vxdprintk(VXD_CBIT(net, 1), "nx_dev_visible(%p[#%u],%p Â»%s«) %d",
13721 +               nxi, nxi ? nxi->nx_id : 0, dev, dev->name,
13722 +               nxi ? dev_in_nx_info(dev, nxi) : 0);
13723 +
13724 +       if (!nx_info_flags(nxi, NXF_HIDE_NETIF, 0))
13725 +               return 1;
13726 +       if (dev_in_nx_info(dev, nxi))
13727 +               return 1;
13728 +       return 0;
13729 +}
13730 +
13731 +
13732 +static inline
13733 +int v4_ifa_in_nx_info(struct in_ifaddr *ifa, struct nx_info *nxi)
13734 +{
13735 +       if (!nxi)
13736 +               return 1;
13737 +       if (!ifa)
13738 +               return 0;
13739 +       return v4_addr_in_nx_info(nxi, ifa->ifa_local, NXA_MASK_SHOW);
13740 +}
13741 +
13742 +static inline
13743 +int nx_v4_ifa_visible(struct nx_info *nxi, struct in_ifaddr *ifa)
13744 +{
13745 +       vxdprintk(VXD_CBIT(net, 1), "nx_v4_ifa_visible(%p[#%u],%p) %d",
13746 +               nxi, nxi ? nxi->nx_id : 0, ifa,
13747 +               nxi ? v4_ifa_in_nx_info(ifa, nxi) : 0);
13748 +
13749 +       if (!nx_info_flags(nxi, NXF_HIDE_NETIF, 0))
13750 +               return 1;
13751 +       if (v4_ifa_in_nx_info(ifa, nxi))
13752 +               return 1;
13753 +       return 0;
13754 +}
13755 +
13756 +
13757 +struct nx_v4_sock_addr {
13758 +       __be32 saddr;   /* Address used for validation */
13759 +       __be32 baddr;   /* Address used for socket bind */
13760 +};
13761 +
13762 +static inline
13763 +int v4_map_sock_addr(struct inet_sock *inet, struct sockaddr_in *addr,
13764 +       struct nx_v4_sock_addr *nsa)
13765 +{
13766 +       struct sock *sk = &inet->sk;
13767 +       struct nx_info *nxi = sk->sk_nx_info;
13768 +       __be32 saddr = addr->sin_addr.s_addr;
13769 +       __be32 baddr = saddr;
13770 +
13771 +       vxdprintk(VXD_CBIT(net, 3),
13772 +               "inet_bind(%p)* %p,%p;%lx " NIPQUAD_FMT,
13773 +               sk, sk->sk_nx_info, sk->sk_socket,
13774 +               (sk->sk_socket ? sk->sk_socket->flags : 0),
13775 +               NIPQUAD(saddr));
13776 +
13777 +       if (nxi) {
13778 +               if (saddr == INADDR_ANY) {
13779 +                       if (nx_info_flags(nxi, NXF_SINGLE_IP, 0))
13780 +                               baddr = nxi->v4.ip[0].s_addr;
13781 +               } else if (saddr == IPI_LOOPBACK) {
13782 +                       if (nx_info_flags(nxi, NXF_LBACK_REMAP, 0))
13783 +                               baddr = nxi->v4_lback.s_addr;
13784 +               } else {        /* normal address bind */
13785 +                       if (!v4_addr_in_nx_info(nxi, saddr, NXA_MASK_BIND))
13786 +                               return -EADDRNOTAVAIL;
13787 +               }
13788 +       }
13789 +
13790 +       vxdprintk(VXD_CBIT(net, 3),
13791 +               "inet_bind(%p) " NIPQUAD_FMT ", " NIPQUAD_FMT,
13792 +               sk, NIPQUAD(saddr), NIPQUAD(baddr));
13793 +
13794 +       nsa->saddr = saddr;
13795 +       nsa->baddr = baddr;
13796 +       return 0;
13797 +}
13798 +
13799 +static inline
13800 +void v4_set_sock_addr(struct inet_sock *inet, struct nx_v4_sock_addr *nsa)
13801 +{
13802 +       inet->saddr = nsa->baddr;
13803 +       inet->rcv_saddr = nsa->baddr;
13804 +}
13805 +
13806 +
13807 +/*
13808 + *      helper to simplify inet_lookup_listener
13809 + *
13810 + *      nxi:   the socket's nx_info if any
13811 + *      addr:  to be verified address
13812 + *      saddr: socket address
13813 + */
13814 +static inline int v4_inet_addr_match (
13815 +       struct nx_info *nxi,
13816 +       __be32 addr,
13817 +       __be32 saddr)
13818 +{
13819 +       if (addr && (saddr == addr))
13820 +               return 1;
13821 +       if (!saddr)
13822 +               return nxi ? v4_addr_in_nx_info(nxi, addr, NXA_MASK_BIND) : 1;
13823 +       return 0;
13824 +}
13825 +
13826 +static inline __be32 nx_map_sock_lback(struct nx_info *nxi, __be32 addr)
13827 +{
13828 +       if (nx_info_flags(nxi, NXF_HIDE_LBACK, 0) &&
13829 +               (addr == nxi->v4_lback.s_addr))
13830 +               return IPI_LOOPBACK;
13831 +       return addr;
13832 +}
13833 +
13834 +static inline
13835 +int nx_info_has_v4(struct nx_info *nxi)
13836 +{
13837 +       if (!nxi)
13838 +               return 1;
13839 +       if (NX_IPV4(nxi))
13840 +               return 1;
13841 +       if (nx_info_flags(nxi, NXF_LBACK_REMAP, 0))
13842 +               return 1;
13843 +       return 0;
13844 +}
13845 +
13846 +#else /* CONFIG_INET */
13847 +
13848 +static inline
13849 +int nx_dev_visible(struct nx_info *n, struct net_device *d)
13850 +{
13851 +       return 1;
13852 +}
13853 +
13854 +static inline
13855 +int nx_v4_addr_conflict(struct nx_info *n, uint32_t a, const struct sock *s)
13856 +{
13857 +       return 1;
13858 +}
13859 +
13860 +static inline
13861 +int v4_ifa_in_nx_info(struct in_ifaddr *a, struct nx_info *n)
13862 +{
13863 +       return 1;
13864 +}
13865 +
13866 +static inline
13867 +int nx_info_has_v4(struct nx_info *nxi)
13868 +{
13869 +       return 0;
13870 +}
13871 +
13872 +#endif /* CONFIG_INET */
13873 +
13874 +#define current_nx_info_has_v4() \
13875 +       nx_info_has_v4(current_nx_info())
13876 +
13877 +#else
13878 +// #warning duplicate inclusion
13879 +#endif
13880 diff -NurpP --minimal linux-2.6.32.6/include/linux/vs_limit.h linux-2.6.32.6-vs2.3.0.36.28/include/linux/vs_limit.h
13881 --- linux-2.6.32.6/include/linux/vs_limit.h     1970-01-01 01:00:00.000000000 +0100
13882 +++ linux-2.6.32.6-vs2.3.0.36.28/include/linux/vs_limit.h       2009-12-03 20:04:56.000000000 +0100
13883 @@ -0,0 +1,140 @@
13884 +#ifndef _VS_LIMIT_H
13885 +#define _VS_LIMIT_H
13886 +
13887 +#include "vserver/limit.h"
13888 +#include "vserver/base.h"
13889 +#include "vserver/context.h"
13890 +#include "vserver/debug.h"
13891 +#include "vserver/context.h"
13892 +#include "vserver/limit_int.h"
13893 +
13894 +
13895 +#define vx_acc_cres(v, d, p, r) \
13896 +       __vx_acc_cres(v, r, d, p, __FILE__, __LINE__)
13897 +
13898 +#define vx_acc_cres_cond(x, d, p, r) \
13899 +       __vx_acc_cres(((x) == vx_current_xid()) ? current_vx_info() : 0, \
13900 +       r, d, p, __FILE__, __LINE__)
13901 +
13902 +
13903 +#define vx_add_cres(v, a, p, r) \
13904 +       __vx_add_cres(v, r, a, p, __FILE__, __LINE__)
13905 +#define vx_sub_cres(v, a, p, r)                vx_add_cres(v, -(a), p, r)
13906 +
13907 +#define vx_add_cres_cond(x, a, p, r) \
13908 +       __vx_add_cres(((x) == vx_current_xid()) ? current_vx_info() : 0, \
13909 +       r, a, p, __FILE__, __LINE__)
13910 +#define vx_sub_cres_cond(x, a, p, r)   vx_add_cres_cond(x, -(a), p, r)
13911 +
13912 +
13913 +/* process and file limits */
13914 +
13915 +#define vx_nproc_inc(p) \
13916 +       vx_acc_cres((p)->vx_info, 1, p, RLIMIT_NPROC)
13917 +
13918 +#define vx_nproc_dec(p) \
13919 +       vx_acc_cres((p)->vx_info,-1, p, RLIMIT_NPROC)
13920 +
13921 +#define vx_files_inc(f) \
13922 +       vx_acc_cres_cond((f)->f_xid, 1, f, RLIMIT_NOFILE)
13923 +
13924 +#define vx_files_dec(f) \
13925 +       vx_acc_cres_cond((f)->f_xid,-1, f, RLIMIT_NOFILE)
13926 +
13927 +#define vx_locks_inc(l) \
13928 +       vx_acc_cres_cond((l)->fl_xid, 1, l, RLIMIT_LOCKS)
13929 +
13930 +#define vx_locks_dec(l) \
13931 +       vx_acc_cres_cond((l)->fl_xid,-1, l, RLIMIT_LOCKS)
13932 +
13933 +#define vx_openfd_inc(f) \
13934 +       vx_acc_cres(current_vx_info(), 1, (void *)(long)(f), VLIMIT_OPENFD)
13935 +
13936 +#define vx_openfd_dec(f) \
13937 +       vx_acc_cres(current_vx_info(),-1, (void *)(long)(f), VLIMIT_OPENFD)
13938 +
13939 +
13940 +#define vx_cres_avail(v, n, r) \
13941 +       __vx_cres_avail(v, r, n, __FILE__, __LINE__)
13942 +
13943 +
13944 +#define vx_nproc_avail(n) \
13945 +       vx_cres_avail(current_vx_info(), n, RLIMIT_NPROC)
13946 +
13947 +#define vx_files_avail(n) \
13948 +       vx_cres_avail(current_vx_info(), n, RLIMIT_NOFILE)
13949 +
13950 +#define vx_locks_avail(n) \
13951 +       vx_cres_avail(current_vx_info(), n, RLIMIT_LOCKS)
13952 +
13953 +#define vx_openfd_avail(n) \
13954 +       vx_cres_avail(current_vx_info(), n, VLIMIT_OPENFD)
13955 +
13956 +
13957 +/* dentry limits */
13958 +
13959 +#define vx_dentry_inc(d) do {                                          \
13960 +       if (atomic_read(&d->d_count) == 1)                              \
13961 +               vx_acc_cres(current_vx_info(), 1, d, VLIMIT_DENTRY);    \
13962 +       } while (0)
13963 +
13964 +#define vx_dentry_dec(d) do {                                          \
13965 +       if (atomic_read(&d->d_count) == 0)                              \
13966 +               vx_acc_cres(current_vx_info(),-1, d, VLIMIT_DENTRY);    \
13967 +       } while (0)
13968 +
13969 +#define vx_dentry_avail(n) \
13970 +       vx_cres_avail(current_vx_info(), n, VLIMIT_DENTRY)
13971 +
13972 +
13973 +/* socket limits */
13974 +
13975 +#define vx_sock_inc(s) \
13976 +       vx_acc_cres((s)->sk_vx_info, 1, s, VLIMIT_NSOCK)
13977 +
13978 +#define vx_sock_dec(s) \
13979 +       vx_acc_cres((s)->sk_vx_info,-1, s, VLIMIT_NSOCK)
13980 +
13981 +#define vx_sock_avail(n) \
13982 +       vx_cres_avail(current_vx_info(), n, VLIMIT_NSOCK)
13983 +
13984 +
13985 +/* ipc resource limits */
13986 +
13987 +#define vx_ipcmsg_add(v, u, a) \
13988 +       vx_add_cres(v, a, u, RLIMIT_MSGQUEUE)
13989 +
13990 +#define vx_ipcmsg_sub(v, u, a) \
13991 +       vx_sub_cres(v, a, u, RLIMIT_MSGQUEUE)
13992 +
13993 +#define vx_ipcmsg_avail(v, a) \
13994 +       vx_cres_avail(v, a, RLIMIT_MSGQUEUE)
13995 +
13996 +
13997 +#define vx_ipcshm_add(v, k, a) \
13998 +       vx_add_cres(v, a, (void *)(long)(k), VLIMIT_SHMEM)
13999 +
14000 +#define vx_ipcshm_sub(v, k, a) \
14001 +       vx_sub_cres(v, a, (void *)(long)(k), VLIMIT_SHMEM)
14002 +
14003 +#define vx_ipcshm_avail(v, a) \
14004 +       vx_cres_avail(v, a, VLIMIT_SHMEM)
14005 +
14006 +
14007 +#define vx_semary_inc(a) \
14008 +       vx_acc_cres(current_vx_info(), 1, a, VLIMIT_SEMARY)
14009 +
14010 +#define vx_semary_dec(a) \
14011 +       vx_acc_cres(current_vx_info(), -1, a, VLIMIT_SEMARY)
14012 +
14013 +
14014 +#define vx_nsems_add(a,n) \
14015 +       vx_add_cres(current_vx_info(), n, a, VLIMIT_NSEMS)
14016 +
14017 +#define vx_nsems_sub(a,n) \
14018 +       vx_sub_cres(current_vx_info(), n, a, VLIMIT_NSEMS)
14019 +
14020 +
14021 +#else
14022 +#warning duplicate inclusion
14023 +#endif
14024 diff -NurpP --minimal linux-2.6.32.6/include/linux/vs_memory.h linux-2.6.32.6-vs2.3.0.36.28/include/linux/vs_memory.h
14025 --- linux-2.6.32.6/include/linux/vs_memory.h    1970-01-01 01:00:00.000000000 +0100
14026 +++ linux-2.6.32.6-vs2.3.0.36.28/include/linux/vs_memory.h      2009-12-03 20:04:56.000000000 +0100
14027 @@ -0,0 +1,159 @@
14028 +#ifndef _VS_MEMORY_H
14029 +#define _VS_MEMORY_H
14030 +
14031 +#include "vserver/limit.h"
14032 +#include "vserver/base.h"
14033 +#include "vserver/context.h"
14034 +#include "vserver/debug.h"
14035 +#include "vserver/context.h"
14036 +#include "vserver/limit_int.h"
14037 +
14038 +
14039 +#define __acc_add_long(a, v)   (*(v) += (a))
14040 +#define __acc_inc_long(v)      (++*(v))
14041 +#define __acc_dec_long(v)      (--*(v))
14042 +
14043 +#if    NR_CPUS >= CONFIG_SPLIT_PTLOCK_CPUS
14044 +#define __acc_add_atomic(a, v) atomic_long_add(a, v)
14045 +#define __acc_inc_atomic(v)    atomic_long_inc(v)
14046 +#define __acc_dec_atomic(v)    atomic_long_dec(v)
14047 +#else  /* NR_CPUS < CONFIG_SPLIT_PTLOCK_CPUS */
14048 +#define __acc_add_atomic(a, v) __acc_add_long(a, v)
14049 +#define __acc_inc_atomic(v)    __acc_inc_long(v)
14050 +#define __acc_dec_atomic(v)    __acc_dec_long(v)
14051 +#endif /* NR_CPUS < CONFIG_SPLIT_PTLOCK_CPUS */
14052 +
14053 +
14054 +#define vx_acc_page(m, d, v, r) do {                                   \
14055 +       if ((d) > 0)                                                    \
14056 +               __acc_inc_long(&(m)->v);                                \
14057 +       else                                                            \
14058 +               __acc_dec_long(&(m)->v);                                \
14059 +       __vx_acc_cres(m->mm_vx_info, r, d, m, __FILE__, __LINE__);      \
14060 +} while (0)
14061 +
14062 +#define vx_acc_page_atomic(m, d, v, r) do {                            \
14063 +       if ((d) > 0)                                                    \
14064 +               __acc_inc_atomic(&(m)->v);                              \
14065 +       else                                                            \
14066 +               __acc_dec_atomic(&(m)->v);                              \
14067 +       __vx_acc_cres(m->mm_vx_info, r, d, m, __FILE__, __LINE__);      \
14068 +} while (0)
14069 +
14070 +
14071 +#define vx_acc_pages(m, p, v, r) do {                                  \
14072 +       unsigned long __p = (p);                                        \
14073 +       __acc_add_long(__p, &(m)->v);                                   \
14074 +       __vx_add_cres(m->mm_vx_info, r, __p, m, __FILE__, __LINE__);    \
14075 +} while (0)
14076 +
14077 +#define vx_acc_pages_atomic(m, p, v, r) do {                           \
14078 +       unsigned long __p = (p);                                        \
14079 +       __acc_add_atomic(__p, &(m)->v);                                 \
14080 +       __vx_add_cres(m->mm_vx_info, r, __p, m, __FILE__, __LINE__);    \
14081 +} while (0)
14082 +
14083 +
14084 +
14085 +#define vx_acc_vmpage(m, d) \
14086 +       vx_acc_page(m, d, total_vm,  RLIMIT_AS)
14087 +#define vx_acc_vmlpage(m, d) \
14088 +       vx_acc_page(m, d, locked_vm, RLIMIT_MEMLOCK)
14089 +#define vx_acc_file_rsspage(m, d) \
14090 +       vx_acc_page_atomic(m, d, _file_rss, VLIMIT_MAPPED)
14091 +#define vx_acc_anon_rsspage(m, d) \
14092 +       vx_acc_page_atomic(m, d, _anon_rss, VLIMIT_ANON)
14093 +
14094 +#define vx_acc_vmpages(m, p) \
14095 +       vx_acc_pages(m, p, total_vm,  RLIMIT_AS)
14096 +#define vx_acc_vmlpages(m, p) \
14097 +       vx_acc_pages(m, p, locked_vm, RLIMIT_MEMLOCK)
14098 +#define vx_acc_file_rsspages(m, p) \
14099 +       vx_acc_pages_atomic(m, p, _file_rss, VLIMIT_MAPPED)
14100 +#define vx_acc_anon_rsspages(m, p) \
14101 +       vx_acc_pages_atomic(m, p, _anon_rss, VLIMIT_ANON)
14102 +
14103 +#define vx_pages_add(s, r, p)  __vx_add_cres(s, r, p, 0, __FILE__, __LINE__)
14104 +#define vx_pages_sub(s, r, p)  vx_pages_add(s, r, -(p))
14105 +
14106 +#define vx_vmpages_inc(m)              vx_acc_vmpage(m, 1)
14107 +#define vx_vmpages_dec(m)              vx_acc_vmpage(m, -1)
14108 +#define vx_vmpages_add(m, p)           vx_acc_vmpages(m, p)
14109 +#define vx_vmpages_sub(m, p)           vx_acc_vmpages(m, -(p))
14110 +
14111 +#define vx_vmlocked_inc(m)             vx_acc_vmlpage(m, 1)
14112 +#define vx_vmlocked_dec(m)             vx_acc_vmlpage(m, -1)
14113 +#define vx_vmlocked_add(m, p)          vx_acc_vmlpages(m, p)
14114 +#define vx_vmlocked_sub(m, p)          vx_acc_vmlpages(m, -(p))
14115 +
14116 +#define vx_file_rsspages_inc(m)                vx_acc_file_rsspage(m, 1)
14117 +#define vx_file_rsspages_dec(m)                vx_acc_file_rsspage(m, -1)
14118 +#define vx_file_rsspages_add(m, p)     vx_acc_file_rsspages(m, p)
14119 +#define vx_file_rsspages_sub(m, p)     vx_acc_file_rsspages(m, -(p))
14120 +
14121 +#define vx_anon_rsspages_inc(m)                vx_acc_anon_rsspage(m, 1)
14122 +#define vx_anon_rsspages_dec(m)                vx_acc_anon_rsspage(m, -1)
14123 +#define vx_anon_rsspages_add(m, p)     vx_acc_anon_rsspages(m, p)
14124 +#define vx_anon_rsspages_sub(m, p)     vx_acc_anon_rsspages(m, -(p))
14125 +
14126 +
14127 +#define vx_pages_avail(m, p, r) \
14128 +       __vx_cres_avail((m)->mm_vx_info, r, p, __FILE__, __LINE__)
14129 +
14130 +#define vx_vmpages_avail(m, p) vx_pages_avail(m, p, RLIMIT_AS)
14131 +#define vx_vmlocked_avail(m, p)        vx_pages_avail(m, p, RLIMIT_MEMLOCK)
14132 +#define vx_anon_avail(m, p)    vx_pages_avail(m, p, VLIMIT_ANON)
14133 +#define vx_mapped_avail(m, p)  vx_pages_avail(m, p, VLIMIT_MAPPED)
14134 +
14135 +#define vx_rss_avail(m, p) \
14136 +       __vx_cres_array_avail((m)->mm_vx_info, VLA_RSS, p, __FILE__, __LINE__)
14137 +
14138 +
14139 +enum {
14140 +       VXPT_UNKNOWN = 0,
14141 +       VXPT_ANON,
14142 +       VXPT_NONE,
14143 +       VXPT_FILE,
14144 +       VXPT_SWAP,
14145 +       VXPT_WRITE
14146 +};
14147 +
14148 +#if 0
14149 +#define        vx_page_fault(mm, vma, type, ret)
14150 +#else
14151 +
14152 +static inline
14153 +void __vx_page_fault(struct mm_struct *mm,
14154 +       struct vm_area_struct *vma, int type, int ret)
14155 +{
14156 +       struct vx_info *vxi = mm->mm_vx_info;
14157 +       int what;
14158 +/*
14159 +       static char *page_type[6] =
14160 +               { "UNKNOWN", "ANON", "NONE", "FILE", "SWAP", "WRITE" };
14161 +       static char *page_what[4] =
14162 +               { "FAULT_OOM", "FAULT_SIGBUS", "FAULT_MINOR", "FAULT_MAJOR" };
14163 +*/
14164 +
14165 +       if (!vxi)
14166 +               return;
14167 +
14168 +       what = (ret & 0x3);
14169 +
14170 +/*     printk("[%d] page[%d][%d] %2x %s %s\n", vxi->vx_id,
14171 +               type, what, ret, page_type[type], page_what[what]);
14172 +*/
14173 +       if (ret & VM_FAULT_WRITE)
14174 +               what |= 0x4;
14175 +       atomic_inc(&vxi->cacct.page[type][what]);
14176 +}
14177 +
14178 +#define        vx_page_fault(mm, vma, type, ret)       __vx_page_fault(mm, vma, type, ret)
14179 +#endif
14180 +
14181 +
14182 +extern unsigned long vx_badness(struct task_struct *task, struct mm_struct *mm);
14183 +
14184 +#else
14185 +#warning duplicate inclusion
14186 +#endif
14187 diff -NurpP --minimal linux-2.6.32.6/include/linux/vs_network.h linux-2.6.32.6-vs2.3.0.36.28/include/linux/vs_network.h
14188 --- linux-2.6.32.6/include/linux/vs_network.h   1970-01-01 01:00:00.000000000 +0100
14189 +++ linux-2.6.32.6-vs2.3.0.36.28/include/linux/vs_network.h     2009-12-03 20:04:56.000000000 +0100
14190 @@ -0,0 +1,169 @@
14191 +#ifndef _NX_VS_NETWORK_H
14192 +#define _NX_VS_NETWORK_H
14193 +
14194 +#include "vserver/context.h"
14195 +#include "vserver/network.h"
14196 +#include "vserver/base.h"
14197 +#include "vserver/check.h"
14198 +#include "vserver/debug.h"
14199 +
14200 +#include <linux/sched.h>
14201 +
14202 +
14203 +#define get_nx_info(i) __get_nx_info(i, __FILE__, __LINE__)
14204 +
14205 +static inline struct nx_info *__get_nx_info(struct nx_info *nxi,
14206 +       const char *_file, int _line)
14207 +{
14208 +       if (!nxi)
14209 +               return NULL;
14210 +
14211 +       vxlprintk(VXD_CBIT(nid, 2), "get_nx_info(%p[#%d.%d])",
14212 +               nxi, nxi ? nxi->nx_id : 0,
14213 +               nxi ? atomic_read(&nxi->nx_usecnt) : 0,
14214 +               _file, _line);
14215 +
14216 +       atomic_inc(&nxi->nx_usecnt);
14217 +       return nxi;
14218 +}
14219 +
14220 +
14221 +extern void free_nx_info(struct nx_info *);
14222 +
14223 +#define put_nx_info(i) __put_nx_info(i, __FILE__, __LINE__)
14224 +
14225 +static inline void __put_nx_info(struct nx_info *nxi, const char *_file, int _line)
14226 +{
14227 +       if (!nxi)
14228 +               return;
14229 +
14230 +       vxlprintk(VXD_CBIT(nid, 2), "put_nx_info(%p[#%d.%d])",
14231 +               nxi, nxi ? nxi->nx_id : 0,
14232 +               nxi ? atomic_read(&nxi->nx_usecnt) : 0,
14233 +               _file, _line);
14234 +
14235 +       if (atomic_dec_and_test(&nxi->nx_usecnt))
14236 +               free_nx_info(nxi);
14237 +}
14238 +
14239 +
14240 +#define init_nx_info(p, i) __init_nx_info(p, i, __FILE__, __LINE__)
14241 +
14242 +static inline void __init_nx_info(struct nx_info **nxp, struct nx_info *nxi,
14243 +               const char *_file, int _line)
14244 +{
14245 +       if (nxi) {
14246 +               vxlprintk(VXD_CBIT(nid, 3),
14247 +                       "init_nx_info(%p[#%d.%d])",
14248 +                       nxi, nxi ? nxi->nx_id : 0,
14249 +                       nxi ? atomic_read(&nxi->nx_usecnt) : 0,
14250 +                       _file, _line);
14251 +
14252 +               atomic_inc(&nxi->nx_usecnt);
14253 +       }
14254 +       *nxp = nxi;
14255 +}
14256 +
14257 +
14258 +#define set_nx_info(p, i) __set_nx_info(p, i, __FILE__, __LINE__)
14259 +
14260 +static inline void __set_nx_info(struct nx_info **nxp, struct nx_info *nxi,
14261 +       const char *_file, int _line)
14262 +{
14263 +       struct nx_info *nxo;
14264 +
14265 +       if (!nxi)
14266 +               return;
14267 +
14268 +       vxlprintk(VXD_CBIT(nid, 3), "set_nx_info(%p[#%d.%d])",
14269 +               nxi, nxi ? nxi->nx_id : 0,
14270 +               nxi ? atomic_read(&nxi->nx_usecnt) : 0,
14271 +               _file, _line);
14272 +
14273 +       atomic_inc(&nxi->nx_usecnt);
14274 +       nxo = xchg(nxp, nxi);
14275 +       BUG_ON(nxo);
14276 +}
14277 +
14278 +#define clr_nx_info(p) __clr_nx_info(p, __FILE__, __LINE__)
14279 +
14280 +static inline void __clr_nx_info(struct nx_info **nxp,
14281 +       const char *_file, int _line)
14282 +{
14283 +       struct nx_info *nxo;
14284 +
14285 +       nxo = xchg(nxp, NULL);
14286 +       if (!nxo)
14287 +               return;
14288 +
14289 +       vxlprintk(VXD_CBIT(nid, 3), "clr_nx_info(%p[#%d.%d])",
14290 +               nxo, nxo ? nxo->nx_id : 0,
14291 +               nxo ? atomic_read(&nxo->nx_usecnt) : 0,
14292 +               _file, _line);
14293 +
14294 +       if (atomic_dec_and_test(&nxo->nx_usecnt))
14295 +               free_nx_info(nxo);
14296 +}
14297 +
14298 +
14299 +#define claim_nx_info(v, p) __claim_nx_info(v, p, __FILE__, __LINE__)
14300 +
14301 +static inline void __claim_nx_info(struct nx_info *nxi,
14302 +       struct task_struct *task, const char *_file, int _line)
14303 +{
14304 +       vxlprintk(VXD_CBIT(nid, 3), "claim_nx_info(%p[#%d.%d.%d]) %p",
14305 +               nxi, nxi ? nxi->nx_id : 0,
14306 +               nxi?atomic_read(&nxi->nx_usecnt):0,
14307 +               nxi?atomic_read(&nxi->nx_tasks):0,
14308 +               task, _file, _line);
14309 +
14310 +       atomic_inc(&nxi->nx_tasks);
14311 +}
14312 +
14313 +
14314 +extern void unhash_nx_info(struct nx_info *);
14315 +
14316 +#define release_nx_info(v, p) __release_nx_info(v, p, __FILE__, __LINE__)
14317 +
14318 +static inline void __release_nx_info(struct nx_info *nxi,
14319 +       struct task_struct *task, const char *_file, int _line)
14320 +{
14321 +       vxlprintk(VXD_CBIT(nid, 3), "release_nx_info(%p[#%d.%d.%d]) %p",
14322 +               nxi, nxi ? nxi->nx_id : 0,
14323 +               nxi ? atomic_read(&nxi->nx_usecnt) : 0,
14324 +               nxi ? atomic_read(&nxi->nx_tasks) : 0,
14325 +               task, _file, _line);
14326 +
14327 +       might_sleep();
14328 +
14329 +       if (atomic_dec_and_test(&nxi->nx_tasks))
14330 +               unhash_nx_info(nxi);
14331 +}
14332 +
14333 +
14334 +#define task_get_nx_info(i)    __task_get_nx_info(i, __FILE__, __LINE__)
14335 +
14336 +static __inline__ struct nx_info *__task_get_nx_info(struct task_struct *p,
14337 +       const char *_file, int _line)
14338 +{
14339 +       struct nx_info *nxi;
14340 +
14341 +       task_lock(p);
14342 +       vxlprintk(VXD_CBIT(nid, 5), "task_get_nx_info(%p)",
14343 +               p, _file, _line);
14344 +       nxi = __get_nx_info(p->nx_info, _file, _line);
14345 +       task_unlock(p);
14346 +       return nxi;
14347 +}
14348 +
14349 +
14350 +static inline void exit_nx_info(struct task_struct *p)
14351 +{
14352 +       if (p->nx_info)
14353 +               release_nx_info(p->nx_info, p);
14354 +}
14355 +
14356 +
14357 +#else
14358 +#warning duplicate inclusion
14359 +#endif
14360 diff -NurpP --minimal linux-2.6.32.6/include/linux/vs_pid.h linux-2.6.32.6-vs2.3.0.36.28/include/linux/vs_pid.h
14361 --- linux-2.6.32.6/include/linux/vs_pid.h       1970-01-01 01:00:00.000000000 +0100
14362 +++ linux-2.6.32.6-vs2.3.0.36.28/include/linux/vs_pid.h 2009-12-03 20:04:56.000000000 +0100
14363 @@ -0,0 +1,95 @@
14364 +#ifndef _VS_PID_H
14365 +#define _VS_PID_H
14366 +
14367 +#include "vserver/base.h"
14368 +#include "vserver/check.h"
14369 +#include "vserver/context.h"
14370 +#include "vserver/debug.h"
14371 +#include "vserver/pid.h"
14372 +#include <linux/pid_namespace.h>
14373 +
14374 +
14375 +#define VXF_FAKE_INIT  (VXF_INFO_INIT | VXF_STATE_INIT)
14376 +
14377 +static inline
14378 +int vx_proc_task_visible(struct task_struct *task)
14379 +{
14380 +       if ((task->pid == 1) &&
14381 +               !vx_flags(VXF_FAKE_INIT, VXF_FAKE_INIT))
14382 +               /* show a blend through init */
14383 +               goto visible;
14384 +       if (vx_check(vx_task_xid(task), VS_WATCH | VS_IDENT))
14385 +               goto visible;
14386 +       return 0;
14387 +visible:
14388 +       return 1;
14389 +}
14390 +
14391 +#define find_task_by_real_pid(pid) find_task_by_pid_ns(pid, &init_pid_ns)
14392 +
14393 +#if 0
14394 +
14395 +static inline
14396 +struct task_struct *vx_find_proc_task_by_pid(int pid)
14397 +{
14398 +       struct task_struct *task = find_task_by_real_pid(pid);
14399 +
14400 +       if (task && !vx_proc_task_visible(task)) {
14401 +               vxdprintk(VXD_CBIT(misc, 6),
14402 +                       "dropping task (find) %p[#%u,%u] for %p[#%u,%u]",
14403 +                       task, task->xid, task->pid,
14404 +                       current, current->xid, current->pid);
14405 +               task = NULL;
14406 +       }
14407 +       return task;
14408 +}
14409 +
14410 +#endif
14411 +
14412 +static inline
14413 +struct task_struct *vx_get_proc_task(struct inode *inode, struct pid *pid)
14414 +{
14415 +       struct task_struct *task = get_pid_task(pid, PIDTYPE_PID);
14416 +
14417 +       if (task && !vx_proc_task_visible(task)) {
14418 +               vxdprintk(VXD_CBIT(misc, 6),
14419 +                       "dropping task (get) %p[#%u,%u] for %p[#%u,%u]",
14420 +                       task, task->xid, task->pid,
14421 +                       current, current->xid, current->pid);
14422 +               put_task_struct(task);
14423 +               task = NULL;
14424 +       }
14425 +       return task;
14426 +}
14427 +
14428 +#if 0
14429 +
14430 +static inline
14431 +struct task_struct *vx_child_reaper(struct task_struct *p)
14432 +{
14433 +       struct vx_info *vxi = p->vx_info;
14434 +       struct task_struct *reaper = child_reaper(p);
14435 +
14436 +       if (!vxi)
14437 +               goto out;
14438 +
14439 +       BUG_ON(!p->vx_info->vx_reaper);
14440 +
14441 +       /* child reaper for the guest reaper */
14442 +       if (vxi->vx_reaper == p)
14443 +               goto out;
14444 +
14445 +       reaper = vxi->vx_reaper;
14446 +out:
14447 +       vxdprintk(VXD_CBIT(xid, 7),
14448 +               "vx_child_reaper(%p[#%u,%u]) = %p[#%u,%u]",
14449 +               p, p->xid, p->pid, reaper, reaper->xid, reaper->pid);
14450 +       return reaper;
14451 +}
14452 +
14453 +#endif
14454 +
14455 +
14456 +#else
14457 +#warning duplicate inclusion
14458 +#endif
14459 diff -NurpP --minimal linux-2.6.32.6/include/linux/vs_sched.h linux-2.6.32.6-vs2.3.0.36.28/include/linux/vs_sched.h
14460 --- linux-2.6.32.6/include/linux/vs_sched.h     1970-01-01 01:00:00.000000000 +0100
14461 +++ linux-2.6.32.6-vs2.3.0.36.28/include/linux/vs_sched.h       2009-12-03 20:04:56.000000000 +0100
14462 @@ -0,0 +1,110 @@
14463 +#ifndef _VS_SCHED_H
14464 +#define _VS_SCHED_H
14465 +
14466 +#include "vserver/base.h"
14467 +#include "vserver/context.h"
14468 +#include "vserver/sched.h"
14469 +
14470 +
14471 +#define VAVAVOOM_RATIO          50
14472 +
14473 +#define MAX_PRIO_BIAS           20
14474 +#define MIN_PRIO_BIAS          -20
14475 +
14476 +
14477 +#ifdef CONFIG_VSERVER_HARDCPU
14478 +
14479 +/*
14480 + * effective_prio - return the priority that is based on the static
14481 + * priority but is modified by bonuses/penalties.
14482 + *
14483 + * We scale the actual sleep average [0 .... MAX_SLEEP_AVG]
14484 + * into a -4 ... 0 ... +4 bonus/penalty range.
14485 + *
14486 + * Additionally, we scale another amount based on the number of
14487 + * CPU tokens currently held by the context, if the process is
14488 + * part of a context (and the appropriate SCHED flag is set).
14489 + * This ranges from -5 ... 0 ... +15, quadratically.
14490 + *
14491 + * So, the total bonus is -9 .. 0 .. +19
14492 + * We use ~50% of the full 0...39 priority range so that:
14493 + *
14494 + * 1) nice +19 interactive tasks do not preempt nice 0 CPU hogs.
14495 + * 2) nice -20 CPU hogs do not get preempted by nice 0 tasks.
14496 + *    unless that context is far exceeding its CPU allocation.
14497 + *
14498 + * Both properties are important to certain workloads.
14499 + */
14500 +static inline
14501 +int vx_effective_vavavoom(struct _vx_sched_pc *sched_pc, int max_prio)
14502 +{
14503 +       int vavavoom, max;
14504 +
14505 +       /* lots of tokens = lots of vavavoom
14506 +        *      no tokens = no vavavoom      */
14507 +       if ((vavavoom = sched_pc->tokens) >= 0) {
14508 +               max = sched_pc->tokens_max;
14509 +               vavavoom = max - vavavoom;
14510 +               max = max * max;
14511 +               vavavoom = max_prio * VAVAVOOM_RATIO / 100
14512 +                       * (vavavoom*vavavoom - (max >> 2)) / max;
14513 +               return vavavoom;
14514 +       }
14515 +       return 0;
14516 +}
14517 +
14518 +
14519 +static inline
14520 +int vx_adjust_prio(struct task_struct *p, int prio, int max_user)
14521 +{
14522 +       struct vx_info *vxi = p->vx_info;
14523 +       struct _vx_sched_pc *sched_pc;
14524 +
14525 +       if (!vxi)
14526 +               return prio;
14527 +
14528 +       sched_pc = &vx_cpu(vxi, sched_pc);
14529 +       if (vx_info_flags(vxi, VXF_SCHED_PRIO, 0)) {
14530 +               int vavavoom = vx_effective_vavavoom(sched_pc, max_user);
14531 +
14532 +               sched_pc->vavavoom = vavavoom;
14533 +               prio += vavavoom;
14534 +       }
14535 +       prio += sched_pc->prio_bias;
14536 +       return prio;
14537 +}
14538 +
14539 +#else /* !CONFIG_VSERVER_HARDCPU */
14540 +
14541 +static inline
14542 +int vx_adjust_prio(struct task_struct *p, int prio, int max_user)
14543 +{
14544 +       struct vx_info *vxi = p->vx_info;
14545 +
14546 +       if (vxi)
14547 +               prio += vx_cpu(vxi, sched_pc).prio_bias;
14548 +       return prio;
14549 +}
14550 +
14551 +#endif /* CONFIG_VSERVER_HARDCPU */
14552 +
14553 +
14554 +static inline void vx_account_user(struct vx_info *vxi,
14555 +       cputime_t cputime, int nice)
14556 +{
14557 +       if (!vxi)
14558 +               return;
14559 +       vx_cpu(vxi, sched_pc).user_ticks += cputime;
14560 +}
14561 +
14562 +static inline void vx_account_system(struct vx_info *vxi,
14563 +       cputime_t cputime, int idle)
14564 +{
14565 +       if (!vxi)
14566 +               return;
14567 +       vx_cpu(vxi, sched_pc).sys_ticks += cputime;
14568 +}
14569 +
14570 +#else
14571 +#warning duplicate inclusion
14572 +#endif
14573 diff -NurpP --minimal linux-2.6.32.6/include/linux/vs_socket.h linux-2.6.32.6-vs2.3.0.36.28/include/linux/vs_socket.h
14574 --- linux-2.6.32.6/include/linux/vs_socket.h    1970-01-01 01:00:00.000000000 +0100
14575 +++ linux-2.6.32.6-vs2.3.0.36.28/include/linux/vs_socket.h      2009-12-03 20:04:56.000000000 +0100
14576 @@ -0,0 +1,67 @@
14577 +#ifndef _VS_SOCKET_H
14578 +#define _VS_SOCKET_H
14579 +
14580 +#include "vserver/debug.h"
14581 +#include "vserver/base.h"
14582 +#include "vserver/cacct.h"
14583 +#include "vserver/context.h"
14584 +#include "vserver/tag.h"
14585 +
14586 +
14587 +/* socket accounting */
14588 +
14589 +#include <linux/socket.h>
14590 +
14591 +static inline int vx_sock_type(int family)
14592 +{
14593 +       switch (family) {
14594 +       case PF_UNSPEC:
14595 +               return VXA_SOCK_UNSPEC;
14596 +       case PF_UNIX:
14597 +               return VXA_SOCK_UNIX;
14598 +       case PF_INET:
14599 +               return VXA_SOCK_INET;
14600 +       case PF_INET6:
14601 +               return VXA_SOCK_INET6;
14602 +       case PF_PACKET:
14603 +               return VXA_SOCK_PACKET;
14604 +       default:
14605 +               return VXA_SOCK_OTHER;
14606 +       }
14607 +}
14608 +
14609 +#define vx_acc_sock(v, f, p, s) \
14610 +       __vx_acc_sock(v, f, p, s, __FILE__, __LINE__)
14611 +
14612 +static inline void __vx_acc_sock(struct vx_info *vxi,
14613 +       int family, int pos, int size, char *file, int line)
14614 +{
14615 +       if (vxi) {
14616 +               int type = vx_sock_type(family);
14617 +
14618 +               atomic_long_inc(&vxi->cacct.sock[type][pos].count);
14619 +               atomic_long_add(size, &vxi->cacct.sock[type][pos].total);
14620 +       }
14621 +}
14622 +
14623 +#define vx_sock_recv(sk, s) \
14624 +       vx_acc_sock((sk)->sk_vx_info, (sk)->sk_family, 0, s)
14625 +#define vx_sock_send(sk, s) \
14626 +       vx_acc_sock((sk)->sk_vx_info, (sk)->sk_family, 1, s)
14627 +#define vx_sock_fail(sk, s) \
14628 +       vx_acc_sock((sk)->sk_vx_info, (sk)->sk_family, 2, s)
14629 +
14630 +
14631 +#define sock_vx_init(s) do {           \
14632 +       (s)->sk_xid = 0;                \
14633 +       (s)->sk_vx_info = NULL;         \
14634 +       } while (0)
14635 +
14636 +#define sock_nx_init(s) do {           \
14637 +       (s)->sk_nid = 0;                \
14638 +       (s)->sk_nx_info = NULL;         \
14639 +       } while (0)
14640 +
14641 +#else
14642 +#warning duplicate inclusion
14643 +#endif
14644 diff -NurpP --minimal linux-2.6.32.6/include/linux/vs_tag.h linux-2.6.32.6-vs2.3.0.36.28/include/linux/vs_tag.h
14645 --- linux-2.6.32.6/include/linux/vs_tag.h       1970-01-01 01:00:00.000000000 +0100
14646 +++ linux-2.6.32.6-vs2.3.0.36.28/include/linux/vs_tag.h 2009-12-03 20:04:56.000000000 +0100
14647 @@ -0,0 +1,47 @@
14648 +#ifndef _VS_TAG_H
14649 +#define _VS_TAG_H
14650 +
14651 +#include <linux/vserver/tag.h>
14652 +
14653 +/* check conditions */
14654 +
14655 +#define DX_ADMIN       0x0001
14656 +#define DX_WATCH       0x0002
14657 +#define DX_HOSTID      0x0008
14658 +
14659 +#define DX_IDENT       0x0010
14660 +
14661 +#define DX_ARG_MASK    0x0010
14662 +
14663 +
14664 +#define dx_task_tag(t) ((t)->tag)
14665 +
14666 +#define dx_current_tag() dx_task_tag(current)
14667 +
14668 +#define dx_check(c, m) __dx_check(dx_current_tag(), c, m)
14669 +
14670 +#define dx_weak_check(c, m)    ((m) ? dx_check(c, m) : 1)
14671 +
14672 +
14673 +/*
14674 + * check current context for ADMIN/WATCH and
14675 + * optionally against supplied argument
14676 + */
14677 +static inline int __dx_check(tag_t cid, tag_t id, unsigned int mode)
14678 +{
14679 +       if (mode & DX_ARG_MASK) {
14680 +               if ((mode & DX_IDENT) && (id == cid))
14681 +                       return 1;
14682 +       }
14683 +       return (((mode & DX_ADMIN) && (cid == 0)) ||
14684 +               ((mode & DX_WATCH) && (cid == 1)) ||
14685 +               ((mode & DX_HOSTID) && (id == 0)));
14686 +}
14687 +
14688 +struct inode;
14689 +int dx_permission(const struct inode *inode, int mask);
14690 +
14691 +
14692 +#else
14693 +#warning duplicate inclusion
14694 +#endif
14695 diff -NurpP --minimal linux-2.6.32.6/include/linux/vs_time.h linux-2.6.32.6-vs2.3.0.36.28/include/linux/vs_time.h
14696 --- linux-2.6.32.6/include/linux/vs_time.h      1970-01-01 01:00:00.000000000 +0100
14697 +++ linux-2.6.32.6-vs2.3.0.36.28/include/linux/vs_time.h        2009-12-03 20:04:56.000000000 +0100
14698 @@ -0,0 +1,19 @@
14699 +#ifndef _VS_TIME_H
14700 +#define _VS_TIME_H
14701 +
14702 +
14703 +/* time faking stuff */
14704 +
14705 +#ifdef CONFIG_VSERVER_VTIME
14706 +
14707 +extern void vx_gettimeofday(struct timeval *tv);
14708 +extern int vx_settimeofday(struct timespec *ts);
14709 +
14710 +#else
14711 +#define        vx_gettimeofday(t)      do_gettimeofday(t)
14712 +#define        vx_settimeofday(t)      do_settimeofday(t)
14713 +#endif
14714 +
14715 +#else
14716 +#warning duplicate inclusion
14717 +#endif
14718 diff -NurpP --minimal linux-2.6.32.6/include/net/addrconf.h linux-2.6.32.6-vs2.3.0.36.28/include/net/addrconf.h
14719 --- linux-2.6.32.6/include/net/addrconf.h       2009-12-03 20:02:57.000000000 +0100
14720 +++ linux-2.6.32.6-vs2.3.0.36.28/include/net/addrconf.h 2009-12-03 20:04:56.000000000 +0100
14721 @@ -84,7 +84,8 @@ extern int                    ipv6_dev_get_saddr(struct n
14722                                                struct net_device *dev,
14723                                                const struct in6_addr *daddr,
14724                                                unsigned int srcprefs,
14725 -                                              struct in6_addr *saddr);
14726 +                                              struct in6_addr *saddr,
14727 +                                              struct nx_info *nxi);
14728  extern int                     ipv6_get_lladdr(struct net_device *dev,
14729                                                 struct in6_addr *addr,
14730                                                 unsigned char banned_flags);
14731 diff -NurpP --minimal linux-2.6.32.6/include/net/af_unix.h linux-2.6.32.6-vs2.3.0.36.28/include/net/af_unix.h
14732 --- linux-2.6.32.6/include/net/af_unix.h        2008-12-25 00:26:37.000000000 +0100
14733 +++ linux-2.6.32.6-vs2.3.0.36.28/include/net/af_unix.h  2009-12-03 20:04:56.000000000 +0100
14734 @@ -4,6 +4,7 @@
14735  #include <linux/socket.h>
14736  #include <linux/un.h>
14737  #include <linux/mutex.h>
14738 +#include <linux/vs_base.h>
14739  #include <net/sock.h>
14740  
14741  extern void unix_inflight(struct file *fp);
14742 diff -NurpP --minimal linux-2.6.32.6/include/net/inet_timewait_sock.h linux-2.6.32.6-vs2.3.0.36.28/include/net/inet_timewait_sock.h
14743 --- linux-2.6.32.6/include/net/inet_timewait_sock.h     2009-12-03 20:02:57.000000000 +0100
14744 +++ linux-2.6.32.6-vs2.3.0.36.28/include/net/inet_timewait_sock.h       2009-12-03 20:04:56.000000000 +0100
14745 @@ -117,6 +117,10 @@ struct inet_timewait_sock {
14746  #define tw_hash                        __tw_common.skc_hash
14747  #define tw_prot                        __tw_common.skc_prot
14748  #define tw_net                 __tw_common.skc_net
14749 +#define tw_xid                 __tw_common.skc_xid
14750 +#define tw_vx_info             __tw_common.skc_vx_info
14751 +#define tw_nid                 __tw_common.skc_nid
14752 +#define tw_nx_info             __tw_common.skc_nx_info
14753         int                     tw_timeout;
14754         volatile unsigned char  tw_substate;
14755         /* 3 bits hole, try to pack */
14756 diff -NurpP --minimal linux-2.6.32.6/include/net/route.h linux-2.6.32.6-vs2.3.0.36.28/include/net/route.h
14757 --- linux-2.6.32.6/include/net/route.h  2009-09-10 15:26:27.000000000 +0200
14758 +++ linux-2.6.32.6-vs2.3.0.36.28/include/net/route.h    2009-12-03 20:04:56.000000000 +0100
14759 @@ -135,6 +135,9 @@ static inline void ip_rt_put(struct rtab
14760                 dst_release(&rt->u.dst);
14761  }
14762  
14763 +#include <linux/vs_base.h>
14764 +#include <linux/vs_inet.h>
14765 +
14766  #define IPTOS_RT_MASK  (IPTOS_TOS_MASK & ~3)
14767  
14768  extern const __u8 ip_tos2prio[16];
14769 @@ -144,6 +147,9 @@ static inline char rt_tos2priority(u8 to
14770         return ip_tos2prio[IPTOS_TOS(tos)>>1];
14771  }
14772  
14773 +extern int ip_v4_find_src(struct net *net, struct nx_info *,
14774 +       struct rtable **, struct flowi *);
14775 +
14776  static inline int ip_route_connect(struct rtable **rp, __be32 dst,
14777                                    __be32 src, u32 tos, int oif, u8 protocol,
14778                                    __be16 sport, __be16 dport, struct sock *sk,
14779 @@ -161,11 +167,24 @@ static inline int ip_route_connect(struc
14780  
14781         int err;
14782         struct net *net = sock_net(sk);
14783 +       struct nx_info *nx_info = current_nx_info();
14784  
14785         if (inet_sk(sk)->transparent)
14786                 fl.flags |= FLOWI_FLAG_ANYSRC;
14787  
14788 -       if (!dst || !src) {
14789 +       if (sk)
14790 +               nx_info = sk->sk_nx_info;
14791 +
14792 +       vxdprintk(VXD_CBIT(net, 4),
14793 +               "ip_route_connect(%p) %p,%p;%lx",
14794 +               sk, nx_info, sk->sk_socket,
14795 +               (sk->sk_socket?sk->sk_socket->flags:0));
14796 +
14797 +       err = ip_v4_find_src(net, nx_info, rp, &fl);
14798 +       if (err)
14799 +               return err;
14800 +
14801 +       if (!fl.fl4_dst || !fl.fl4_src) {
14802                 err = __ip_route_output_key(net, rp, &fl);
14803                 if (err)
14804                         return err;
14805 diff -NurpP --minimal linux-2.6.32.6/include/net/sock.h linux-2.6.32.6-vs2.3.0.36.28/include/net/sock.h
14806 --- linux-2.6.32.6/include/net/sock.h   2009-12-03 20:02:57.000000000 +0100
14807 +++ linux-2.6.32.6-vs2.3.0.36.28/include/net/sock.h     2009-12-03 20:04:56.000000000 +0100
14808 @@ -139,6 +139,10 @@ struct sock_common {
14809  #ifdef CONFIG_NET_NS
14810         struct net              *skc_net;
14811  #endif
14812 +       xid_t                   skc_xid;
14813 +       struct vx_info          *skc_vx_info;
14814 +       nid_t                   skc_nid;
14815 +       struct nx_info          *skc_nx_info;
14816  };
14817  
14818  /**
14819 @@ -225,6 +229,10 @@ struct sock {
14820  #define sk_bind_node           __sk_common.skc_bind_node
14821  #define sk_prot                        __sk_common.skc_prot
14822  #define sk_net                 __sk_common.skc_net
14823 +#define sk_xid                 __sk_common.skc_xid
14824 +#define sk_vx_info             __sk_common.skc_vx_info
14825 +#define sk_nid                 __sk_common.skc_nid
14826 +#define sk_nx_info             __sk_common.skc_nx_info
14827         kmemcheck_bitfield_begin(flags);
14828         unsigned int            sk_shutdown  : 2,
14829                                 sk_no_check  : 2,
14830 diff -NurpP --minimal linux-2.6.32.6/init/Kconfig linux-2.6.32.6-vs2.3.0.36.28/init/Kconfig
14831 --- linux-2.6.32.6/init/Kconfig 2009-12-03 20:02:57.000000000 +0100
14832 +++ linux-2.6.32.6-vs2.3.0.36.28/init/Kconfig   2009-12-03 20:04:56.000000000 +0100
14833 @@ -477,6 +477,19 @@ config CGROUP_SCHED
14834  
14835  endchoice
14836  
14837 +config CFS_HARD_LIMITS
14838 +       bool "Hard Limits for CFS Group Scheduler"
14839 +       depends on EXPERIMENTAL
14840 +       depends on FAIR_GROUP_SCHED && CGROUP_SCHED
14841 +       default n
14842 +       help
14843 +         This option enables hard limiting of CPU time obtained by
14844 +         a fair task group. Use this if you want to throttle a group of tasks
14845 +         based on its CPU usage. For more details refer to
14846 +         Documentation/scheduler/sched-cfs-hard-limits.txt
14847 +
14848 +         Say N if unsure.
14849 +
14850  menuconfig CGROUPS
14851         boolean "Control Group support"
14852         help
14853 diff -NurpP --minimal linux-2.6.32.6/init/main.c linux-2.6.32.6-vs2.3.0.36.28/init/main.c
14854 --- linux-2.6.32.6/init/main.c  2009-12-03 20:02:57.000000000 +0100
14855 +++ linux-2.6.32.6-vs2.3.0.36.28/init/main.c    2009-12-03 20:04:56.000000000 +0100
14856 @@ -70,6 +70,7 @@
14857  #include <linux/sfi.h>
14858  #include <linux/shmem_fs.h>
14859  #include <trace/boot.h>
14860 +#include <linux/vserver/percpu.h>
14861  
14862  #include <asm/io.h>
14863  #include <asm/bugs.h>
14864 diff -NurpP --minimal linux-2.6.32.6/ipc/mqueue.c linux-2.6.32.6-vs2.3.0.36.28/ipc/mqueue.c
14865 --- linux-2.6.32.6/ipc/mqueue.c 2009-12-03 20:02:57.000000000 +0100
14866 +++ linux-2.6.32.6-vs2.3.0.36.28/ipc/mqueue.c   2009-12-03 20:04:56.000000000 +0100
14867 @@ -33,6 +33,8 @@
14868  #include <linux/pid.h>
14869  #include <linux/ipc_namespace.h>
14870  #include <linux/ima.h>
14871 +#include <linux/vs_context.h>
14872 +#include <linux/vs_limit.h>
14873  
14874  #include <net/sock.h>
14875  #include "util.h"
14876 @@ -66,6 +68,7 @@ struct mqueue_inode_info {
14877         struct sigevent notify;
14878         struct pid* notify_owner;
14879         struct user_struct *user;       /* user who created, for accounting */
14880 +       struct vx_info *vxi;
14881         struct sock *notify_sock;
14882         struct sk_buff *notify_cookie;
14883  
14884 @@ -125,6 +128,7 @@ static struct inode *mqueue_get_inode(st
14885                 if (S_ISREG(mode)) {
14886                         struct mqueue_inode_info *info;
14887                         struct task_struct *p = current;
14888 +                       struct vx_info *vxi = p->vx_info;
14889                         unsigned long mq_bytes, mq_msg_tblsz;
14890  
14891                         inode->i_fop = &mqueue_file_operations;
14892 @@ -139,6 +143,7 @@ static struct inode *mqueue_get_inode(st
14893                         info->notify_owner = NULL;
14894                         info->qsize = 0;
14895                         info->user = NULL;      /* set when all is ok */
14896 +                       info->vxi = NULL;
14897                         memset(&info->attr, 0, sizeof(info->attr));
14898                         info->attr.mq_maxmsg = ipc_ns->mq_msg_max;
14899                         info->attr.mq_msgsize = ipc_ns->mq_msgsize_max;
14900 @@ -153,22 +158,26 @@ static struct inode *mqueue_get_inode(st
14901                         spin_lock(&mq_lock);
14902                         if (u->mq_bytes + mq_bytes < u->mq_bytes ||
14903                             u->mq_bytes + mq_bytes >
14904 -                           p->signal->rlim[RLIMIT_MSGQUEUE].rlim_cur) {
14905 +                           p->signal->rlim[RLIMIT_MSGQUEUE].rlim_cur ||
14906 +                           !vx_ipcmsg_avail(vxi, mq_bytes)) {
14907                                 spin_unlock(&mq_lock);
14908                                 goto out_inode;
14909                         }
14910                         u->mq_bytes += mq_bytes;
14911 +                       vx_ipcmsg_add(vxi, u, mq_bytes);
14912                         spin_unlock(&mq_lock);
14913  
14914                         info->messages = kmalloc(mq_msg_tblsz, GFP_KERNEL);
14915                         if (!info->messages) {
14916                                 spin_lock(&mq_lock);
14917                                 u->mq_bytes -= mq_bytes;
14918 +                               vx_ipcmsg_sub(vxi, u, mq_bytes);
14919                                 spin_unlock(&mq_lock);
14920                                 goto out_inode;
14921                         }
14922                         /* all is ok */
14923                         info->user = get_uid(u);
14924 +                       info->vxi = get_vx_info(vxi);
14925                 } else if (S_ISDIR(mode)) {
14926                         inc_nlink(inode);
14927                         /* Some things misbehave if size == 0 on a directory */
14928 @@ -269,8 +278,11 @@ static void mqueue_delete_inode(struct i
14929                    (info->attr.mq_maxmsg * info->attr.mq_msgsize));
14930         user = info->user;
14931         if (user) {
14932 +               struct vx_info *vxi = info->vxi;
14933 +
14934                 spin_lock(&mq_lock);
14935                 user->mq_bytes -= mq_bytes;
14936 +               vx_ipcmsg_sub(vxi, user, mq_bytes);
14937                 /*
14938                  * get_ns_from_inode() ensures that the
14939                  * (ipc_ns = sb->s_fs_info) is either a valid ipc_ns
14940 @@ -280,6 +292,7 @@ static void mqueue_delete_inode(struct i
14941                 if (ipc_ns)
14942                         ipc_ns->mq_queues_count--;
14943                 spin_unlock(&mq_lock);
14944 +               put_vx_info(vxi);
14945                 free_uid(user);
14946         }
14947         if (ipc_ns)
14948 diff -NurpP --minimal linux-2.6.32.6/ipc/msg.c linux-2.6.32.6-vs2.3.0.36.28/ipc/msg.c
14949 --- linux-2.6.32.6/ipc/msg.c    2009-03-24 14:22:44.000000000 +0100
14950 +++ linux-2.6.32.6-vs2.3.0.36.28/ipc/msg.c      2009-12-03 20:04:56.000000000 +0100
14951 @@ -38,6 +38,7 @@
14952  #include <linux/rwsem.h>
14953  #include <linux/nsproxy.h>
14954  #include <linux/ipc_namespace.h>
14955 +#include <linux/vs_base.h>
14956  
14957  #include <asm/current.h>
14958  #include <asm/uaccess.h>
14959 @@ -190,6 +191,7 @@ static int newque(struct ipc_namespace *
14960  
14961         msq->q_perm.mode = msgflg & S_IRWXUGO;
14962         msq->q_perm.key = key;
14963 +       msq->q_perm.xid = vx_current_xid();
14964  
14965         msq->q_perm.security = NULL;
14966         retval = security_msg_queue_alloc(msq);
14967 diff -NurpP --minimal linux-2.6.32.6/ipc/namespace.c linux-2.6.32.6-vs2.3.0.36.28/ipc/namespace.c
14968 --- linux-2.6.32.6/ipc/namespace.c      2009-09-10 15:26:27.000000000 +0200
14969 +++ linux-2.6.32.6-vs2.3.0.36.28/ipc/namespace.c        2009-12-03 20:04:56.000000000 +0100
14970 @@ -11,6 +11,8 @@
14971  #include <linux/slab.h>
14972  #include <linux/fs.h>
14973  #include <linux/mount.h>
14974 +#include <linux/vs_base.h>
14975 +#include <linux/vserver/global.h>
14976  
14977  #include "util.h"
14978  
14979 diff -NurpP --minimal linux-2.6.32.6/ipc/sem.c linux-2.6.32.6-vs2.3.0.36.28/ipc/sem.c
14980 --- linux-2.6.32.6/ipc/sem.c    2009-09-10 15:26:27.000000000 +0200
14981 +++ linux-2.6.32.6-vs2.3.0.36.28/ipc/sem.c      2009-12-03 20:04:56.000000000 +0100
14982 @@ -83,6 +83,8 @@
14983  #include <linux/rwsem.h>
14984  #include <linux/nsproxy.h>
14985  #include <linux/ipc_namespace.h>
14986 +#include <linux/vs_base.h>
14987 +#include <linux/vs_limit.h>
14988  
14989  #include <asm/uaccess.h>
14990  #include "util.h"
14991 @@ -255,6 +257,7 @@ static int newary(struct ipc_namespace *
14992  
14993         sma->sem_perm.mode = (semflg & S_IRWXUGO);
14994         sma->sem_perm.key = key;
14995 +       sma->sem_perm.xid = vx_current_xid();
14996  
14997         sma->sem_perm.security = NULL;
14998         retval = security_sem_alloc(sma);
14999 @@ -270,6 +273,9 @@ static int newary(struct ipc_namespace *
15000                 return id;
15001         }
15002         ns->used_sems += nsems;
15003 +       /* FIXME: obsoleted? */
15004 +       vx_semary_inc(sma);
15005 +       vx_nsems_add(sma, nsems);
15006  
15007         sma->sem_base = (struct sem *) &sma[1];
15008         INIT_LIST_HEAD(&sma->sem_pending);
15009 @@ -546,6 +552,9 @@ static void freeary(struct ipc_namespace
15010         sem_unlock(sma);
15011  
15012         ns->used_sems -= sma->sem_nsems;
15013 +       /* FIXME: obsoleted? */
15014 +       vx_nsems_sub(sma, sma->sem_nsems);
15015 +       vx_semary_dec(sma);
15016         security_sem_free(sma);
15017         ipc_rcu_putref(sma);
15018  }
15019 diff -NurpP --minimal linux-2.6.32.6/ipc/shm.c linux-2.6.32.6-vs2.3.0.36.28/ipc/shm.c
15020 --- linux-2.6.32.6/ipc/shm.c    2010-01-26 19:31:27.000000000 +0100
15021 +++ linux-2.6.32.6-vs2.3.0.36.28/ipc/shm.c      2010-01-20 04:21:33.000000000 +0100
15022 @@ -40,6 +40,8 @@
15023  #include <linux/mount.h>
15024  #include <linux/ipc_namespace.h>
15025  #include <linux/ima.h>
15026 +#include <linux/vs_context.h>
15027 +#include <linux/vs_limit.h>
15028  
15029  #include <asm/uaccess.h>
15030  
15031 @@ -169,7 +171,12 @@ static void shm_open(struct vm_area_stru
15032   */
15033  static void shm_destroy(struct ipc_namespace *ns, struct shmid_kernel *shp)
15034  {
15035 -       ns->shm_tot -= (shp->shm_segsz + PAGE_SIZE - 1) >> PAGE_SHIFT;
15036 +       struct vx_info *vxi = lookup_vx_info(shp->shm_perm.xid);
15037 +       int numpages = (shp->shm_segsz + PAGE_SIZE - 1) >> PAGE_SHIFT;
15038 +
15039 +       vx_ipcshm_sub(vxi, shp, numpages);
15040 +       ns->shm_tot -= numpages;
15041 +
15042         shm_rmid(ns, shp);
15043         shm_unlock(shp);
15044         if (!is_file_hugepages(shp->shm_file))
15045 @@ -179,6 +186,7 @@ static void shm_destroy(struct ipc_names
15046                                                 shp->mlock_user);
15047         fput (shp->shm_file);
15048         security_shm_free(shp);
15049 +       put_vx_info(vxi);
15050         ipc_rcu_putref(shp);
15051  }
15052  
15053 @@ -349,11 +357,15 @@ static int newseg(struct ipc_namespace *
15054         if (ns->shm_tot + numpages > ns->shm_ctlall)
15055                 return -ENOSPC;
15056  
15057 +       if (!vx_ipcshm_avail(current_vx_info(), numpages))
15058 +               return -ENOSPC;
15059 +
15060         shp = ipc_rcu_alloc(sizeof(*shp));
15061         if (!shp)
15062                 return -ENOMEM;
15063  
15064         shp->shm_perm.key = key;
15065 +       shp->shm_perm.xid = vx_current_xid();
15066         shp->shm_perm.mode = (shmflg & S_IRWXUGO);
15067         shp->mlock_user = NULL;
15068  
15069 @@ -407,6 +419,7 @@ static int newseg(struct ipc_namespace *
15070         ns->shm_tot += numpages;
15071         error = shp->shm_perm.id;
15072         shm_unlock(shp);
15073 +       vx_ipcshm_add(current_vx_info(), key, numpages);
15074         return error;
15075  
15076  no_id:
15077 diff -NurpP --minimal linux-2.6.32.6/kernel/capability.c linux-2.6.32.6-vs2.3.0.36.28/kernel/capability.c
15078 --- linux-2.6.32.6/kernel/capability.c  2009-03-24 14:22:44.000000000 +0100
15079 +++ linux-2.6.32.6-vs2.3.0.36.28/kernel/capability.c    2009-12-03 20:04:56.000000000 +0100
15080 @@ -14,6 +14,7 @@
15081  #include <linux/security.h>
15082  #include <linux/syscalls.h>
15083  #include <linux/pid_namespace.h>
15084 +#include <linux/vs_context.h>
15085  #include <asm/uaccess.h>
15086  #include "cred-internals.h"
15087  
15088 @@ -122,6 +123,7 @@ static int cap_validate_magic(cap_user_h
15089         return 0;
15090  }
15091  
15092 +
15093  /*
15094   * The only thing that can change the capabilities of the current
15095   * process is the current process. As such, we can't be in this code
15096 @@ -289,6 +291,8 @@ error:
15097         return ret;
15098  }
15099  
15100 +#include <linux/vserver/base.h>
15101 +
15102  /**
15103   * capable - Determine if the current task has a superior capability in effect
15104   * @cap: The capability to be tested for
15105 @@ -301,6 +305,9 @@ error:
15106   */
15107  int capable(int cap)
15108  {
15109 +       /* here for now so we don't require task locking */
15110 +       if (vs_check_bit(VXC_CAP_MASK, cap) && !vx_mcaps(1L << cap))
15111 +               return 0;
15112         if (unlikely(!cap_valid(cap))) {
15113                 printk(KERN_CRIT "capable() called with invalid cap=%u\n", cap);
15114                 BUG();
15115 diff -NurpP --minimal linux-2.6.32.6/kernel/compat.c linux-2.6.32.6-vs2.3.0.36.28/kernel/compat.c
15116 --- linux-2.6.32.6/kernel/compat.c      2009-09-10 15:26:27.000000000 +0200
15117 +++ linux-2.6.32.6-vs2.3.0.36.28/kernel/compat.c        2009-12-03 20:04:56.000000000 +0100
15118 @@ -902,7 +902,7 @@ asmlinkage long compat_sys_time(compat_t
15119         compat_time_t i;
15120         struct timeval tv;
15121  
15122 -       do_gettimeofday(&tv);
15123 +       vx_gettimeofday(&tv);
15124         i = tv.tv_sec;
15125  
15126         if (tloc) {
15127 @@ -927,7 +927,7 @@ asmlinkage long compat_sys_stime(compat_
15128         if (err)
15129                 return err;
15130  
15131 -       do_settimeofday(&tv);
15132 +       vx_settimeofday(&tv);
15133         return 0;
15134  }
15135  
15136 diff -NurpP --minimal linux-2.6.32.6/kernel/exit.c linux-2.6.32.6-vs2.3.0.36.28/kernel/exit.c
15137 --- linux-2.6.32.6/kernel/exit.c        2009-12-03 20:02:57.000000000 +0100
15138 +++ linux-2.6.32.6-vs2.3.0.36.28/kernel/exit.c  2009-12-03 20:04:56.000000000 +0100
15139 @@ -48,6 +48,10 @@
15140  #include <linux/fs_struct.h>
15141  #include <linux/init_task.h>
15142  #include <linux/perf_event.h>
15143 +#include <linux/vs_limit.h>
15144 +#include <linux/vs_context.h>
15145 +#include <linux/vs_network.h>
15146 +#include <linux/vs_pid.h>
15147  #include <trace/events/sched.h>
15148  
15149  #include <asm/uaccess.h>
15150 @@ -488,9 +492,11 @@ static void close_files(struct files_str
15151                                         filp_close(file, files);
15152                                         cond_resched();
15153                                 }
15154 +                               vx_openfd_dec(i);
15155                         }
15156                         i++;
15157                         set >>= 1;
15158 +                       cond_resched();
15159                 }
15160         }
15161  }
15162 @@ -1011,11 +1017,16 @@ NORET_TYPE void do_exit(long code)
15163  
15164         validate_creds_for_do_exit(tsk);
15165  
15166 +       /* needs to stay after exit_notify() */
15167 +       exit_vx_info(tsk, code);
15168 +       exit_nx_info(tsk);
15169 +
15170         preempt_disable();
15171         exit_rcu();
15172         /* causes final put_task_struct in finish_task_switch(). */
15173         tsk->state = TASK_DEAD;
15174         schedule();
15175 +       printk("bad task: %p [%lx]\n", current, current->state);
15176         BUG();
15177         /* Avoid "noreturn function does return".  */
15178         for (;;)
15179 diff -NurpP --minimal linux-2.6.32.6/kernel/fork.c linux-2.6.32.6-vs2.3.0.36.28/kernel/fork.c
15180 --- linux-2.6.32.6/kernel/fork.c        2009-12-03 20:02:57.000000000 +0100
15181 +++ linux-2.6.32.6-vs2.3.0.36.28/kernel/fork.c  2009-12-03 20:04:56.000000000 +0100
15182 @@ -64,6 +64,10 @@
15183  #include <linux/magic.h>
15184  #include <linux/perf_event.h>
15185  #include <linux/posix-timers.h>
15186 +#include <linux/vs_context.h>
15187 +#include <linux/vs_network.h>
15188 +#include <linux/vs_limit.h>
15189 +#include <linux/vs_memory.h>
15190  
15191  #include <asm/pgtable.h>
15192  #include <asm/pgalloc.h>
15193 @@ -151,6 +155,8 @@ void free_task(struct task_struct *tsk)
15194         account_kernel_stack(tsk->stack, -1);
15195         free_thread_info(tsk->stack);
15196         rt_mutex_debug_task_free(tsk);
15197 +       clr_vx_info(&tsk->vx_info);
15198 +       clr_nx_info(&tsk->nx_info);
15199         ftrace_graph_exit_task(tsk);
15200         free_task_struct(tsk);
15201  }
15202 @@ -296,6 +302,8 @@ static int dup_mmap(struct mm_struct *mm
15203         mm->free_area_cache = oldmm->mmap_base;
15204         mm->cached_hole_size = ~0UL;
15205         mm->map_count = 0;
15206 +       __set_mm_counter(mm, file_rss, 0);
15207 +       __set_mm_counter(mm, anon_rss, 0);
15208         cpumask_clear(mm_cpumask(mm));
15209         mm->mm_rb = RB_ROOT;
15210         rb_link = &mm->mm_rb.rb_node;
15211 @@ -310,7 +318,7 @@ static int dup_mmap(struct mm_struct *mm
15212  
15213                 if (mpnt->vm_flags & VM_DONTCOPY) {
15214                         long pages = vma_pages(mpnt);
15215 -                       mm->total_vm -= pages;
15216 +                       vx_vmpages_sub(mm, pages);
15217                         vm_stat_account(mm, mpnt->vm_flags, mpnt->vm_file,
15218                                                                 -pages);
15219                         continue;
15220 @@ -452,8 +460,8 @@ static struct mm_struct * mm_init(struct
15221                 (current->mm->flags & MMF_INIT_MASK) : default_dump_filter;
15222         mm->core_state = NULL;
15223         mm->nr_ptes = 0;
15224 -       set_mm_counter(mm, file_rss, 0);
15225 -       set_mm_counter(mm, anon_rss, 0);
15226 +       __set_mm_counter(mm, file_rss, 0);
15227 +       __set_mm_counter(mm, anon_rss, 0);
15228         spin_lock_init(&mm->page_table_lock);
15229         mm->free_area_cache = TASK_UNMAPPED_BASE;
15230         mm->cached_hole_size = ~0UL;
15231 @@ -463,6 +471,7 @@ static struct mm_struct * mm_init(struct
15232         if (likely(!mm_alloc_pgd(mm))) {
15233                 mm->def_flags = 0;
15234                 mmu_notifier_mm_init(mm);
15235 +               set_vx_info(&mm->mm_vx_info, p->vx_info);
15236                 return mm;
15237         }
15238  
15239 @@ -496,6 +505,7 @@ void __mmdrop(struct mm_struct *mm)
15240         mm_free_pgd(mm);
15241         destroy_context(mm);
15242         mmu_notifier_mm_destroy(mm);
15243 +       clr_vx_info(&mm->mm_vx_info);
15244         free_mm(mm);
15245  }
15246  EXPORT_SYMBOL_GPL(__mmdrop);
15247 @@ -631,6 +641,7 @@ struct mm_struct *dup_mm(struct task_str
15248                 goto fail_nomem;
15249  
15250         memcpy(mm, oldmm, sizeof(*mm));
15251 +       mm->mm_vx_info = NULL;
15252  
15253         /* Initializing for Swap token stuff */
15254         mm->token_priority = 0;
15255 @@ -669,6 +680,7 @@ fail_nocontext:
15256          * If init_new_context() failed, we cannot use mmput() to free the mm
15257          * because it calls destroy_context()
15258          */
15259 +       clr_vx_info(&mm->mm_vx_info);
15260         mm_free_pgd(mm);
15261         free_mm(mm);
15262         return NULL;
15263 @@ -980,6 +992,8 @@ static struct task_struct *copy_process(
15264         int retval;
15265         struct task_struct *p;
15266         int cgroup_callbacks_done = 0;
15267 +       struct vx_info *vxi;
15268 +       struct nx_info *nxi;
15269  
15270         if ((clone_flags & (CLONE_NEWNS|CLONE_FS)) == (CLONE_NEWNS|CLONE_FS))
15271                 return ERR_PTR(-EINVAL);
15272 @@ -1026,12 +1040,28 @@ static struct task_struct *copy_process(
15273         DEBUG_LOCKS_WARN_ON(!p->hardirqs_enabled);
15274         DEBUG_LOCKS_WARN_ON(!p->softirqs_enabled);
15275  #endif
15276 +       init_vx_info(&p->vx_info, current_vx_info());
15277 +       init_nx_info(&p->nx_info, current_nx_info());
15278 +
15279 +       /* check vserver memory */
15280 +       if (p->mm && !(clone_flags & CLONE_VM)) {
15281 +               if (vx_vmpages_avail(p->mm, p->mm->total_vm))
15282 +                       vx_pages_add(p->vx_info, RLIMIT_AS, p->mm->total_vm);
15283 +               else
15284 +                       goto bad_fork_free;
15285 +       }
15286 +       if (p->mm && vx_flags(VXF_FORK_RSS, 0)) {
15287 +               if (!vx_rss_avail(p->mm, get_mm_counter(p->mm, file_rss)))
15288 +                       goto bad_fork_cleanup_vm;
15289 +       }
15290         retval = -EAGAIN;
15291 +       if (!vx_nproc_avail(1))
15292 +               goto bad_fork_cleanup_vm;
15293         if (atomic_read(&p->real_cred->user->processes) >=
15294                         p->signal->rlim[RLIMIT_NPROC].rlim_cur) {
15295                 if (!capable(CAP_SYS_ADMIN) && !capable(CAP_SYS_RESOURCE) &&
15296                     p->real_cred->user != INIT_USER)
15297 -                       goto bad_fork_free;
15298 +                       goto bad_fork_cleanup_vm;
15299         }
15300  
15301         retval = copy_creds(p, clone_flags);
15302 @@ -1300,6 +1330,18 @@ static struct task_struct *copy_process(
15303  
15304         total_forks++;
15305         spin_unlock(&current->sighand->siglock);
15306 +
15307 +       /* p is copy of current */
15308 +       vxi = p->vx_info;
15309 +       if (vxi) {
15310 +               claim_vx_info(vxi, p);
15311 +               atomic_inc(&vxi->cvirt.nr_threads);
15312 +               atomic_inc(&vxi->cvirt.total_forks);
15313 +               vx_nproc_inc(p);
15314 +       }
15315 +       nxi = p->nx_info;
15316 +       if (nxi)
15317 +               claim_nx_info(nxi, p);
15318         write_unlock_irq(&tasklist_lock);
15319         proc_fork_connector(p);
15320         cgroup_post_fork(p);
15321 @@ -1341,6 +1383,9 @@ bad_fork_cleanup_cgroup:
15322  bad_fork_cleanup_count:
15323         atomic_dec(&p->cred->user->processes);
15324         exit_creds(p);
15325 +bad_fork_cleanup_vm:
15326 +       if (p->mm && !(clone_flags & CLONE_VM))
15327 +               vx_pages_sub(p->vx_info, RLIMIT_AS, p->mm->total_vm);
15328  bad_fork_free:
15329         free_task(p);
15330  fork_out:
15331 diff -NurpP --minimal linux-2.6.32.6/kernel/kthread.c linux-2.6.32.6-vs2.3.0.36.28/kernel/kthread.c
15332 --- linux-2.6.32.6/kernel/kthread.c     2009-12-03 20:02:58.000000000 +0100
15333 +++ linux-2.6.32.6-vs2.3.0.36.28/kernel/kthread.c       2009-12-03 20:04:56.000000000 +0100
15334 @@ -14,6 +14,7 @@
15335  #include <linux/file.h>
15336  #include <linux/module.h>
15337  #include <linux/mutex.h>
15338 +#include <linux/vs_pid.h>
15339  #include <trace/events/sched.h>
15340  
15341  static DEFINE_SPINLOCK(kthread_create_lock);
15342 diff -NurpP --minimal linux-2.6.32.6/kernel/Makefile linux-2.6.32.6-vs2.3.0.36.28/kernel/Makefile
15343 --- linux-2.6.32.6/kernel/Makefile      2009-12-03 20:02:57.000000000 +0100
15344 +++ linux-2.6.32.6-vs2.3.0.36.28/kernel/Makefile        2009-12-03 20:04:56.000000000 +0100
15345 @@ -23,6 +23,7 @@ CFLAGS_REMOVE_cgroup-debug.o = -pg
15346  CFLAGS_REMOVE_sched_clock.o = -pg
15347  endif
15348  
15349 +obj-y += vserver/
15350  obj-$(CONFIG_FREEZER) += freezer.o
15351  obj-$(CONFIG_PROFILING) += profile.o
15352  obj-$(CONFIG_SYSCTL_SYSCALL_CHECK) += sysctl_check.o
15353 diff -NurpP --minimal linux-2.6.32.6/kernel/nsproxy.c linux-2.6.32.6-vs2.3.0.36.28/kernel/nsproxy.c
15354 --- linux-2.6.32.6/kernel/nsproxy.c     2009-09-10 15:26:28.000000000 +0200
15355 +++ linux-2.6.32.6-vs2.3.0.36.28/kernel/nsproxy.c       2009-12-03 20:04:56.000000000 +0100
15356 @@ -19,6 +19,8 @@
15357  #include <linux/mnt_namespace.h>
15358  #include <linux/utsname.h>
15359  #include <linux/pid_namespace.h>
15360 +#include <linux/vserver/global.h>
15361 +#include <linux/vserver/debug.h>
15362  #include <net/net_namespace.h>
15363  #include <linux/ipc_namespace.h>
15364  
15365 @@ -31,8 +33,11 @@ static inline struct nsproxy *create_nsp
15366         struct nsproxy *nsproxy;
15367  
15368         nsproxy = kmem_cache_alloc(nsproxy_cachep, GFP_KERNEL);
15369 -       if (nsproxy)
15370 +       if (nsproxy) {
15371                 atomic_set(&nsproxy->count, 1);
15372 +               atomic_inc(&vs_global_nsproxy);
15373 +       }
15374 +       vxdprintk(VXD_CBIT(space, 2), "create_nsproxy = %p[1]", nsproxy);
15375         return nsproxy;
15376  }
15377  
15378 @@ -41,41 +46,52 @@ static inline struct nsproxy *create_nsp
15379   * Return the newly created nsproxy.  Do not attach this to the task,
15380   * leave it to the caller to do proper locking and attach it to task.
15381   */
15382 -static struct nsproxy *create_new_namespaces(unsigned long flags,
15383 -                       struct task_struct *tsk, struct fs_struct *new_fs)
15384 +static struct nsproxy *unshare_namespaces(unsigned long flags,
15385 +                       struct nsproxy *orig, struct fs_struct *new_fs)
15386  {
15387         struct nsproxy *new_nsp;
15388         int err;
15389  
15390 +       vxdprintk(VXD_CBIT(space, 4),
15391 +               "unshare_namespaces(0x%08lx,%p,%p)",
15392 +               flags, orig, new_fs);
15393 +
15394         new_nsp = create_nsproxy();
15395         if (!new_nsp)
15396                 return ERR_PTR(-ENOMEM);
15397  
15398 -       new_nsp->mnt_ns = copy_mnt_ns(flags, tsk->nsproxy->mnt_ns, new_fs);
15399 +       new_nsp->mnt_ns = copy_mnt_ns(flags, orig->mnt_ns, new_fs);
15400         if (IS_ERR(new_nsp->mnt_ns)) {
15401                 err = PTR_ERR(new_nsp->mnt_ns);
15402                 goto out_ns;
15403         }
15404  
15405 -       new_nsp->uts_ns = copy_utsname(flags, tsk->nsproxy->uts_ns);
15406 +       new_nsp->uts_ns = copy_utsname(flags, orig->uts_ns);
15407         if (IS_ERR(new_nsp->uts_ns)) {
15408                 err = PTR_ERR(new_nsp->uts_ns);
15409                 goto out_uts;
15410         }
15411  
15412 -       new_nsp->ipc_ns = copy_ipcs(flags, tsk->nsproxy->ipc_ns);
15413 +       new_nsp->ipc_ns = copy_ipcs(flags, orig->ipc_ns);
15414         if (IS_ERR(new_nsp->ipc_ns)) {
15415                 err = PTR_ERR(new_nsp->ipc_ns);
15416                 goto out_ipc;
15417         }
15418  
15419 -       new_nsp->pid_ns = copy_pid_ns(flags, task_active_pid_ns(tsk));
15420 +       new_nsp->pid_ns = copy_pid_ns(flags, orig->pid_ns);
15421         if (IS_ERR(new_nsp->pid_ns)) {
15422                 err = PTR_ERR(new_nsp->pid_ns);
15423                 goto out_pid;
15424         }
15425  
15426 -       new_nsp->net_ns = copy_net_ns(flags, tsk->nsproxy->net_ns);
15427 +       /* disabled now?
15428 +       new_nsp->user_ns = copy_user_ns(flags, orig->user_ns);
15429 +       if (IS_ERR(new_nsp->user_ns)) {
15430 +               err = PTR_ERR(new_nsp->user_ns);
15431 +               goto out_user;
15432 +       } */
15433 +
15434 +       new_nsp->net_ns = copy_net_ns(flags, orig->net_ns);
15435         if (IS_ERR(new_nsp->net_ns)) {
15436                 err = PTR_ERR(new_nsp->net_ns);
15437                 goto out_net;
15438 @@ -100,6 +116,38 @@ out_ns:
15439         return ERR_PTR(err);
15440  }
15441  
15442 +static struct nsproxy *create_new_namespaces(int flags, struct task_struct *tsk,
15443 +                       struct fs_struct *new_fs)
15444 +{
15445 +       return unshare_namespaces(flags, tsk->nsproxy, new_fs);
15446 +}
15447 +
15448 +/*
15449 + * copies the nsproxy, setting refcount to 1, and grabbing a
15450 + * reference to all contained namespaces.
15451 + */
15452 +struct nsproxy *copy_nsproxy(struct nsproxy *orig)
15453 +{
15454 +       struct nsproxy *ns = create_nsproxy();
15455 +
15456 +       if (ns) {
15457 +               memcpy(ns, orig, sizeof(struct nsproxy));
15458 +               atomic_set(&ns->count, 1);
15459 +
15460 +               if (ns->mnt_ns)
15461 +                       get_mnt_ns(ns->mnt_ns);
15462 +               if (ns->uts_ns)
15463 +                       get_uts_ns(ns->uts_ns);
15464 +               if (ns->ipc_ns)
15465 +                       get_ipc_ns(ns->ipc_ns);
15466 +               if (ns->pid_ns)
15467 +                       get_pid_ns(ns->pid_ns);
15468 +               if (ns->net_ns)
15469 +                       get_net(ns->net_ns);
15470 +       }
15471 +       return ns;
15472 +}
15473 +
15474  /*
15475   * called from clone.  This now handles copy for nsproxy and all
15476   * namespaces therein.
15477 @@ -107,9 +155,12 @@ out_ns:
15478  int copy_namespaces(unsigned long flags, struct task_struct *tsk)
15479  {
15480         struct nsproxy *old_ns = tsk->nsproxy;
15481 -       struct nsproxy *new_ns;
15482 +       struct nsproxy *new_ns = NULL;
15483         int err = 0;
15484  
15485 +       vxdprintk(VXD_CBIT(space, 7), "copy_namespaces(0x%08lx,%p[%p])",
15486 +               flags, tsk, old_ns);
15487 +
15488         if (!old_ns)
15489                 return 0;
15490  
15491 @@ -119,7 +170,7 @@ int copy_namespaces(unsigned long flags,
15492                                 CLONE_NEWPID | CLONE_NEWNET)))
15493                 return 0;
15494  
15495 -       if (!capable(CAP_SYS_ADMIN)) {
15496 +       if (!vx_can_unshare(CAP_SYS_ADMIN, flags)) {
15497                 err = -EPERM;
15498                 goto out;
15499         }
15500 @@ -146,6 +197,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 @@ -159,7 +213,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 @@ -172,11 +228,15 @@ 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  
15533 -       if (!capable(CAP_SYS_ADMIN))
15534 +       if (!vx_can_unshare(CAP_SYS_ADMIN, unshare_flags))
15535                 return -EPERM;
15536  
15537         *new_nsp = create_new_namespaces(unshare_flags, current,
15538 diff -NurpP --minimal linux-2.6.32.6/kernel/pid.c linux-2.6.32.6-vs2.3.0.36.28/kernel/pid.c
15539 --- linux-2.6.32.6/kernel/pid.c 2009-12-03 20:02:58.000000000 +0100
15540 +++ linux-2.6.32.6-vs2.3.0.36.28/kernel/pid.c   2009-12-03 20:04:56.000000000 +0100
15541 @@ -36,6 +36,7 @@
15542  #include <linux/pid_namespace.h>
15543  #include <linux/init_task.h>
15544  #include <linux/syscalls.h>
15545 +#include <linux/vs_pid.h>
15546  
15547  #define pid_hashfn(nr, ns)     \
15548         hash_long((unsigned long)nr + (unsigned long)ns, pidhash_shift)
15549 @@ -305,7 +306,7 @@ EXPORT_SYMBOL_GPL(find_pid_ns);
15550  
15551  struct pid *find_vpid(int nr)
15552  {
15553 -       return find_pid_ns(nr, current->nsproxy->pid_ns);
15554 +       return find_pid_ns(vx_rmap_pid(nr), current->nsproxy->pid_ns);
15555  }
15556  EXPORT_SYMBOL_GPL(find_vpid);
15557  
15558 @@ -365,6 +366,9 @@ void transfer_pid(struct task_struct *ol
15559  struct task_struct *pid_task(struct pid *pid, enum pid_type type)
15560  {
15561         struct task_struct *result = NULL;
15562 +
15563 +       if (type == PIDTYPE_REALPID)
15564 +               type = PIDTYPE_PID;
15565         if (pid) {
15566                 struct hlist_node *first;
15567                 first = rcu_dereference(pid->tasks[type].first);
15568 @@ -380,7 +384,7 @@ EXPORT_SYMBOL(pid_task);
15569   */
15570  struct task_struct *find_task_by_pid_ns(pid_t nr, struct pid_namespace *ns)
15571  {
15572 -       return pid_task(find_pid_ns(nr, ns), PIDTYPE_PID);
15573 +       return pid_task(find_pid_ns(vx_rmap_pid(nr), ns), PIDTYPE_PID);
15574  }
15575  
15576  struct task_struct *find_task_by_vpid(pid_t vnr)
15577 @@ -422,7 +426,7 @@ struct pid *find_get_pid(pid_t nr)
15578  }
15579  EXPORT_SYMBOL_GPL(find_get_pid);
15580  
15581 -pid_t pid_nr_ns(struct pid *pid, struct pid_namespace *ns)
15582 +pid_t pid_unmapped_nr_ns(struct pid *pid, struct pid_namespace *ns)
15583  {
15584         struct upid *upid;
15585         pid_t nr = 0;
15586 @@ -435,6 +439,11 @@ pid_t pid_nr_ns(struct pid *pid, struct 
15587         return nr;
15588  }
15589  
15590 +pid_t pid_nr_ns(struct pid *pid, struct pid_namespace *ns)
15591 +{
15592 +       return vx_map_pid(pid_unmapped_nr_ns(pid, ns));
15593 +}
15594 +
15595  pid_t pid_vnr(struct pid *pid)
15596  {
15597         return pid_nr_ns(pid, current->nsproxy->pid_ns);
15598 diff -NurpP --minimal linux-2.6.32.6/kernel/pid_namespace.c linux-2.6.32.6-vs2.3.0.36.28/kernel/pid_namespace.c
15599 --- linux-2.6.32.6/kernel/pid_namespace.c       2009-12-03 20:02:58.000000000 +0100
15600 +++ linux-2.6.32.6-vs2.3.0.36.28/kernel/pid_namespace.c 2009-12-03 20:04:56.000000000 +0100
15601 @@ -13,6 +13,7 @@
15602  #include <linux/syscalls.h>
15603  #include <linux/err.h>
15604  #include <linux/acct.h>
15605 +#include <linux/vserver/global.h>
15606  
15607  #define BITS_PER_PAGE          (PAGE_SIZE*8)
15608  
15609 @@ -86,6 +87,7 @@ static struct pid_namespace *create_pid_
15610                 goto out_free_map;
15611  
15612         kref_init(&ns->kref);
15613 +       atomic_inc(&vs_global_pid_ns);
15614         ns->level = level;
15615         ns->parent = get_pid_ns(parent_pid_ns);
15616  
15617 @@ -111,6 +113,7 @@ static void destroy_pid_namespace(struct
15618  
15619         for (i = 0; i < PIDMAP_ENTRIES; i++)
15620                 kfree(ns->pidmap[i].page);
15621 +       atomic_dec(&vs_global_pid_ns);
15622         kmem_cache_free(pid_ns_cachep, ns);
15623  }
15624  
15625 diff -NurpP --minimal linux-2.6.32.6/kernel/posix-timers.c linux-2.6.32.6-vs2.3.0.36.28/kernel/posix-timers.c
15626 --- linux-2.6.32.6/kernel/posix-timers.c        2009-12-03 20:02:58.000000000 +0100
15627 +++ linux-2.6.32.6-vs2.3.0.36.28/kernel/posix-timers.c  2009-12-03 20:04:56.000000000 +0100
15628 @@ -46,6 +46,7 @@
15629  #include <linux/wait.h>
15630  #include <linux/workqueue.h>
15631  #include <linux/module.h>
15632 +#include <linux/vs_context.h>
15633  
15634  /*
15635   * Management arrays for POSIX timers.  Timers are kept in slab memory
15636 @@ -363,6 +364,7 @@ int posix_timer_event(struct k_itimer *t
15637  {
15638         struct task_struct *task;
15639         int shared, ret = -1;
15640 +
15641         /*
15642          * FIXME: if ->sigq is queued we can race with
15643          * dequeue_signal()->do_schedule_next_timer().
15644 @@ -379,10 +381,18 @@ int posix_timer_event(struct k_itimer *t
15645         rcu_read_lock();
15646         task = pid_task(timr->it_pid, PIDTYPE_PID);
15647         if (task) {
15648 +               struct vx_info_save vxis;
15649 +               struct vx_info *vxi;
15650 +
15651 +               vxi = get_vx_info(task->vx_info);
15652 +               enter_vx_info(vxi, &vxis);
15653                 shared = !(timr->it_sigev_notify & SIGEV_THREAD_ID);
15654                 ret = send_sigqueue(timr->sigq, task, shared);
15655 +               leave_vx_info(&vxis);
15656 +               put_vx_info(vxi);
15657         }
15658         rcu_read_unlock();
15659 +
15660         /* If we failed to send the signal the timer stops. */
15661         return ret > 0;
15662  }
15663 diff -NurpP --minimal linux-2.6.32.6/kernel/printk.c linux-2.6.32.6-vs2.3.0.36.28/kernel/printk.c
15664 --- linux-2.6.32.6/kernel/printk.c      2009-12-03 20:02:58.000000000 +0100
15665 +++ linux-2.6.32.6-vs2.3.0.36.28/kernel/printk.c        2009-12-03 20:04:56.000000000 +0100
15666 @@ -33,6 +33,7 @@
15667  #include <linux/bootmem.h>
15668  #include <linux/syscalls.h>
15669  #include <linux/kexec.h>
15670 +#include <linux/vs_cvirt.h>
15671  
15672  #include <asm/uaccess.h>
15673  
15674 @@ -276,18 +277,13 @@ int do_syslog(int type, char __user *buf
15675         unsigned i, j, limit, count;
15676         int do_clear = 0;
15677         char c;
15678 -       int error = 0;
15679 +       int error;
15680  
15681         error = security_syslog(type);
15682         if (error)
15683                 return error;
15684  
15685 -       switch (type) {
15686 -       case 0:         /* Close log */
15687 -               break;
15688 -       case 1:         /* Open log */
15689 -               break;
15690 -       case 2:         /* Read from log */
15691 +       if ((type >= 2) && (type <= 4)) {
15692                 error = -EINVAL;
15693                 if (!buf || len < 0)
15694                         goto out;
15695 @@ -298,6 +294,16 @@ int do_syslog(int type, char __user *buf
15696                         error = -EFAULT;
15697                         goto out;
15698                 }
15699 +       }
15700 +       if (!vx_check(0, VS_ADMIN|VS_WATCH))
15701 +               return vx_do_syslog(type, buf, len);
15702 +
15703 +       switch (type) {
15704 +       case 0:         /* Close log */
15705 +               break;
15706 +       case 1:         /* Open log */
15707 +               break;
15708 +       case 2:         /* Read from log */
15709                 error = wait_event_interruptible(log_wait,
15710                                                         (log_start - log_end));
15711                 if (error)
15712 @@ -322,16 +328,6 @@ int do_syslog(int type, char __user *buf
15713                 do_clear = 1;
15714                 /* FALL THRU */
15715         case 3:         /* Read last kernel messages */
15716 -               error = -EINVAL;
15717 -               if (!buf || len < 0)
15718 -                       goto out;
15719 -               error = 0;
15720 -               if (!len)
15721 -                       goto out;
15722 -               if (!access_ok(VERIFY_WRITE, buf, len)) {
15723 -                       error = -EFAULT;
15724 -                       goto out;
15725 -               }
15726                 count = len;
15727                 if (count > log_buf_len)
15728                         count = log_buf_len;
15729 diff -NurpP --minimal linux-2.6.32.6/kernel/ptrace.c linux-2.6.32.6-vs2.3.0.36.28/kernel/ptrace.c
15730 --- linux-2.6.32.6/kernel/ptrace.c      2009-12-03 20:02:58.000000000 +0100
15731 +++ linux-2.6.32.6-vs2.3.0.36.28/kernel/ptrace.c        2009-12-03 20:04:56.000000000 +0100
15732 @@ -22,6 +22,7 @@
15733  #include <linux/pid_namespace.h>
15734  #include <linux/syscalls.h>
15735  #include <linux/uaccess.h>
15736 +#include <linux/vs_context.h>
15737  
15738  
15739  /*
15740 @@ -151,6 +152,11 @@ int __ptrace_may_access(struct task_stru
15741                 dumpable = get_dumpable(task->mm);
15742         if (!dumpable && !capable(CAP_SYS_PTRACE))
15743                 return -EPERM;
15744 +       if (!vx_check(task->xid, VS_ADMIN_P|VS_IDENT))
15745 +               return -EPERM;
15746 +       if (!vx_check(task->xid, VS_IDENT) &&
15747 +               !task_vx_flags(task, VXF_STATE_ADMIN, 0))
15748 +               return -EACCES;
15749  
15750         return security_ptrace_access_check(task, mode);
15751  }
15752 @@ -621,6 +627,10 @@ SYSCALL_DEFINE4(ptrace, long, request, l
15753                 goto out;
15754         }
15755  
15756 +       ret = -EPERM;
15757 +       if (!vx_check(vx_task_xid(child), VS_WATCH_P | VS_IDENT))
15758 +               goto out_put_task_struct;
15759 +
15760         if (request == PTRACE_ATTACH) {
15761                 ret = ptrace_attach(child);
15762                 /*
15763 diff -NurpP --minimal linux-2.6.32.6/kernel/sched.c linux-2.6.32.6-vs2.3.0.36.28/kernel/sched.c
15764 --- linux-2.6.32.6/kernel/sched.c       2010-01-26 19:31:27.000000000 +0100
15765 +++ linux-2.6.32.6-vs2.3.0.36.28/kernel/sched.c 2010-01-26 20:35:35.000000000 +0100
15766 @@ -71,6 +71,8 @@
15767  #include <linux/debugfs.h>
15768  #include <linux/ctype.h>
15769  #include <linux/ftrace.h>
15770 +#include <linux/vs_sched.h>
15771 +#include <linux/vs_cvirt.h>
15772  
15773  #include <asm/tlb.h>
15774  #include <asm/irq_regs.h>
15775 @@ -237,6 +239,15 @@ static DEFINE_MUTEX(sched_domains_mutex)
15776  
15777  #include <linux/cgroup.h>
15778  
15779 +#if defined(CONFIG_FAIR_GROUP_SCHED) && defined(CONFIG_CFS_HARD_LIMITS)
15780 +struct cfs_bandwidth {
15781 +       spinlock_t              cfs_runtime_lock;
15782 +       ktime_t                 cfs_period;
15783 +       u64                     cfs_runtime;
15784 +       struct hrtimer          cfs_period_timer;
15785 +};
15786 +#endif
15787 +
15788  struct cfs_rq;
15789  
15790  static LIST_HEAD(task_groups);
15791 @@ -257,6 +268,9 @@ struct task_group {
15792         /* runqueue "owned" by this group on each cpu */
15793         struct cfs_rq **cfs_rq;
15794         unsigned long shares;
15795 +#ifdef CONFIG_CFS_HARD_LIMITS
15796 +       struct cfs_bandwidth cfs_bandwidth;
15797 +#endif
15798  #endif
15799  
15800  #ifdef CONFIG_RT_GROUP_SCHED
15801 @@ -446,6 +460,19 @@ struct cfs_rq {
15802         unsigned long rq_weight;
15803  #endif
15804  #endif
15805 +#ifdef CONFIG_CFS_HARD_LIMITS
15806 +       /* set when the group is throttled  on this cpu */
15807 +       int cfs_throttled;
15808 +
15809 +       /* runtime currently consumed by the group on this rq */
15810 +       u64 cfs_time;
15811 +
15812 +       /* runtime available to the group on this rq */
15813 +       u64 cfs_runtime;
15814 +
15815 +       /* Protects the cfs runtime related fields of this cfs_rq */
15816 +       spinlock_t cfs_runtime_lock;
15817 +#endif
15818  };
15819  
15820  /* Real-Time classes' related field in a runqueue: */
15821 @@ -1609,6 +1636,7 @@ static void update_group_shares_cpu(stru
15822         }
15823  }
15824  
15825 +static inline int cfs_rq_throttled(struct cfs_rq *cfs_rq);
15826  /*
15827   * Re-compute the task group their per cpu shares over the given domain.
15828   * This needs to be done in a bottom-up fashion because the rq weight of a
15829 @@ -1636,8 +1664,10 @@ static int tg_shares_up(struct task_grou
15830                  * If there are currently no tasks on the cpu pretend there
15831                  * is one of average load so that when a new task gets to
15832                  * run here it will not get delayed by group starvation.
15833 +                * Also if the group is throttled on this cpu, pretend that
15834 +                * it has no tasks.
15835                  */
15836 -               if (!weight)
15837 +               if (!weight || cfs_rq_throttled(tg->cfs_rq[i]))
15838                         weight = NICE_0_LOAD;
15839  
15840                 rq_weight += weight;
15841 @@ -1813,6 +1843,175 @@ static void cfs_rq_set_shares(struct cfs
15842  
15843  static void calc_load_account_active(struct rq *this_rq);
15844  
15845 +
15846 +#if defined(CONFIG_RT_GROUP_SCHED) || defined(CONFIG_FAIR_GROUP_SCHED)
15847 +
15848 +#ifdef CONFIG_SMP
15849 +static inline const struct cpumask *sched_bw_period_mask(void)
15850 +{
15851 +       return cpu_rq(smp_processor_id())->rd->span;
15852 +}
15853 +#else /* !CONFIG_SMP */
15854 +static inline const struct cpumask *sched_bw_period_mask(void)
15855 +{
15856 +       return cpu_online_mask;
15857 +}
15858 +#endif /* CONFIG_SMP */
15859 +
15860 +#else
15861 +static inline const struct cpumask *sched_bw_period_mask(void)
15862 +{
15863 +       return cpu_online_mask;
15864 +}
15865 +
15866 +#endif
15867 +
15868 +#ifdef CONFIG_FAIR_GROUP_SCHED
15869 +#ifdef CONFIG_CFS_HARD_LIMITS
15870 +
15871 +/*
15872 + * Runtime allowed for a cfs group before it is hard limited.
15873 + * default: Infinite which means no hard limiting.
15874 + */
15875 +u64 sched_cfs_runtime = RUNTIME_INF;
15876 +
15877 +/*
15878 + * period over which we hard limit the cfs group's bandwidth.
15879 + * default: 0.5s
15880 + */
15881 +u64 sched_cfs_period = 500000;
15882 +
15883 +static inline u64 global_cfs_period(void)
15884 +{
15885 +       return sched_cfs_period * NSEC_PER_USEC;
15886 +}
15887 +
15888 +static inline u64 global_cfs_runtime(void)
15889 +{
15890 +       return RUNTIME_INF;
15891 +}
15892 +
15893 +void do_sched_cfs_period_timer(struct cfs_bandwidth *cfs_b);
15894 +
15895 +static inline void cfs_rq_runtime_lock(struct cfs_rq *cfs_rq)
15896 +{
15897 +       spin_lock(&cfs_rq->cfs_runtime_lock);
15898 +}
15899 +
15900 +static inline void cfs_rq_runtime_unlock(struct cfs_rq *cfs_rq)
15901 +{
15902 +       spin_unlock(&cfs_rq->cfs_runtime_lock);
15903 +}
15904 +
15905 +/*
15906 + * Refresh the runtimes of the throttled groups.
15907 + * But nothing much to do now, will populate this in later patches.
15908 + */
15909 +static enum hrtimer_restart sched_cfs_period_timer(struct hrtimer *timer)
15910 +{
15911 +       struct cfs_bandwidth *cfs_b =
15912 +               container_of(timer, struct cfs_bandwidth, cfs_period_timer);
15913 +
15914 +       do_sched_cfs_period_timer(cfs_b);
15915 +       hrtimer_add_expires_ns(timer, ktime_to_ns(cfs_b->cfs_period));
15916 +       return HRTIMER_RESTART;
15917 +}
15918 +
15919 +/*
15920 + * TODO: Check if this kind of timer setup is sufficient for cfs or
15921 + * should we do what rt is doing.
15922 + */
15923 +static void start_cfs_bandwidth(struct task_group *tg)
15924 +{
15925 +       struct cfs_bandwidth *cfs_b = &tg->cfs_bandwidth;
15926 +
15927 +       /*
15928 +        * Timer isn't setup for groups with infinite runtime
15929 +        */
15930 +       if (cfs_b->cfs_runtime == RUNTIME_INF)
15931 +               return;
15932 +
15933 +       if (hrtimer_active(&cfs_b->cfs_period_timer))
15934 +               return;
15935 +
15936 +       hrtimer_start_range_ns(&cfs_b->cfs_period_timer, cfs_b->cfs_period,
15937 +                       0, HRTIMER_MODE_REL);
15938 +}
15939 +
15940 +static void init_cfs_bandwidth(struct task_group *tg)
15941 +{
15942 +       struct cfs_bandwidth *cfs_b = &tg->cfs_bandwidth;
15943 +
15944 +       cfs_b->cfs_period = ns_to_ktime(global_cfs_period());
15945 +       cfs_b->cfs_runtime = global_cfs_runtime();
15946 +
15947 +       spin_lock_init(&cfs_b->cfs_runtime_lock);
15948 +
15949 +       hrtimer_init(&cfs_b->cfs_period_timer,
15950 +                       CLOCK_MONOTONIC, HRTIMER_MODE_REL);
15951 +       cfs_b->cfs_period_timer.function = &sched_cfs_period_timer;
15952 +}
15953 +
15954 +static inline void destroy_cfs_bandwidth(struct task_group *tg)
15955 +{
15956 +       hrtimer_cancel(&tg->cfs_bandwidth.cfs_period_timer);
15957 +}
15958 +
15959 +static void init_cfs_hard_limits(struct cfs_rq *cfs_rq, struct task_group *tg)
15960 +{
15961 +       cfs_rq->cfs_time = 0;
15962 +       cfs_rq->cfs_throttled = 0;
15963 +       cfs_rq->cfs_runtime = tg->cfs_bandwidth.cfs_runtime;
15964 +       spin_lock_init(&cfs_rq->cfs_runtime_lock);
15965 +}
15966 +
15967 +#else /* !CONFIG_CFS_HARD_LIMITS */
15968 +
15969 +static void init_cfs_bandwidth(struct task_group *tg)
15970 +{
15971 +       return;
15972 +}
15973 +
15974 +static inline void destroy_cfs_bandwidth(struct task_group *tg)
15975 +{
15976 +       return;
15977 +}
15978 +
15979 +static void init_cfs_hard_limits(struct cfs_rq *cfs_rq, struct task_group *tg)
15980 +{
15981 +       return;
15982 +}
15983 +
15984 +static inline void cfs_rq_runtime_lock(struct cfs_rq *cfs_rq)
15985 +{
15986 +       return;
15987 +}
15988 +
15989 +static inline void cfs_rq_runtime_unlock(struct cfs_rq *cfs_rq)
15990 +{
15991 +       return;
15992 +}
15993 +
15994 +#endif /* CONFIG_CFS_HARD_LIMITS */
15995 +#else /* !CONFIG_FAIR_GROUP_SCHED */
15996 +
15997 +static inline void cfs_rq_runtime_lock(struct cfs_rq *cfs_rq)
15998 +{
15999 +       return;
16000 +}
16001 +
16002 +static inline void cfs_rq_runtime_unlock(struct cfs_rq *cfs_rq)
16003 +{
16004 +       return;
16005 +}
16006 +
16007 +static inline int cfs_rq_throttled(struct cfs_rq *cfs_rq)
16008 +{
16009 +       return 0;
16010 +}
16011 +
16012 +#endif /* CONFIG_FAIR_GROUP_SCHED */
16013 +
16014  #include "sched_stats.h"
16015  #include "sched_idletask.c"
16016  #include "sched_fair.c"
16017 @@ -2978,9 +3177,17 @@ EXPORT_SYMBOL(avenrun);
16018   */
16019  void get_avenrun(unsigned long *loads, unsigned long offset, int shift)
16020  {
16021 -       loads[0] = (avenrun[0] + offset) << shift;
16022 -       loads[1] = (avenrun[1] + offset) << shift;
16023 -       loads[2] = (avenrun[2] + offset) << shift;
16024 +       if (vx_flags(VXF_VIRT_LOAD, 0)) {
16025 +               struct vx_info *vxi = current_vx_info();
16026 +
16027 +               loads[0] = (vxi->cvirt.load[0] + offset) << shift;
16028 +               loads[1] = (vxi->cvirt.load[1] + offset) << shift;
16029 +               loads[2] = (vxi->cvirt.load[2] + offset) << shift;
16030 +       } else {
16031 +               loads[0] = (avenrun[0] + offset) << shift;
16032 +               loads[1] = (avenrun[1] + offset) << shift;
16033 +               loads[2] = (avenrun[2] + offset) << shift;
16034 +       }
16035  }
16036  
16037  static unsigned long
16038 @@ -5022,16 +5229,19 @@ void account_user_time(struct task_struc
16039                        cputime_t cputime_scaled)
16040  {
16041         struct cpu_usage_stat *cpustat = &kstat_this_cpu.cpustat;
16042 +       struct vx_info *vxi = p->vx_info;  /* p is _always_ current */
16043         cputime64_t tmp;
16044 +       int nice = (TASK_NICE(p) > 0);
16045  
16046         /* Add user time to process. */
16047         p->utime = cputime_add(p->utime, cputime);
16048         p->utimescaled = cputime_add(p->utimescaled, cputime_scaled);
16049 +       vx_account_user(vxi, cputime, nice);
16050         account_group_user_time(p, cputime);
16051  
16052         /* Add user time to cpustat. */
16053         tmp = cputime_to_cputime64(cputime);
16054 -       if (TASK_NICE(p) > 0)
16055 +       if (nice)
16056                 cpustat->nice = cputime64_add(cpustat->nice, tmp);
16057         else
16058                 cpustat->user = cputime64_add(cpustat->user, tmp);
16059 @@ -5077,6 +5287,7 @@ void account_system_time(struct task_str
16060                          cputime_t cputime, cputime_t cputime_scaled)
16061  {
16062         struct cpu_usage_stat *cpustat = &kstat_this_cpu.cpustat;
16063 +       struct vx_info *vxi = p->vx_info;  /* p is _always_ current */
16064         cputime64_t tmp;
16065  
16066         if ((p->flags & PF_VCPU) && (irq_count() - hardirq_offset == 0)) {
16067 @@ -5087,6 +5298,7 @@ void account_system_time(struct task_str
16068         /* Add system time to process. */
16069         p->stime = cputime_add(p->stime, cputime);
16070         p->stimescaled = cputime_add(p->stimescaled, cputime_scaled);
16071 +       vx_account_system(vxi, cputime, 0 /* do we have idle time? */);
16072         account_group_system_time(p, cputime);
16073  
16074         /* Add system time to cpustat. */
16075 @@ -6122,7 +6334,7 @@ SYSCALL_DEFINE1(nice, int, increment)
16076                 nice = 19;
16077  
16078         if (increment < 0 && !can_nice(current, nice))
16079 -               return -EPERM;
16080 +               return vx_flags(VXF_IGNEG_NICE, 0) ? 0 : -EPERM;
16081  
16082         retval = security_task_setnice(current, nice);
16083         if (retval)
16084 @@ -9182,6 +9394,32 @@ static int update_sched_domains(struct n
16085  }
16086  #endif
16087  
16088 +#ifdef CONFIG_SMP
16089 +static void disable_runtime(struct rq *rq)
16090 +{
16091 +       unsigned long flags;
16092 +
16093 +       spin_lock_irqsave(&rq->lock, flags);
16094 +#if defined(CONFIG_FAIR_GROUP_SCHED) && defined(CONFIG_CFS_HARD_LIMITS)
16095 +       disable_runtime_cfs(rq);
16096 +#endif
16097 +       disable_runtime_rt(rq);
16098 +       spin_unlock_irqrestore(&rq->lock, flags);
16099 +}
16100 +
16101 +static void enable_runtime(struct rq *rq)
16102 +{
16103 +       unsigned long flags;
16104 +
16105 +       spin_lock_irqsave(&rq->lock, flags);
16106 +#if defined(CONFIG_FAIR_GROUP_SCHED) && defined(CONFIG_CFS_HARD_LIMITS)
16107 +       enable_runtime_cfs(rq);
16108 +#endif
16109 +       enable_runtime_rt(rq);
16110 +       spin_unlock_irqrestore(&rq->lock, flags);
16111 +}
16112 +#endif
16113 +
16114  static int update_runtime(struct notifier_block *nfb,
16115                                 unsigned long action, void *hcpu)
16116  {
16117 @@ -9314,6 +9552,7 @@ static void init_tg_cfs_entry(struct tas
16118         struct rq *rq = cpu_rq(cpu);
16119         tg->cfs_rq[cpu] = cfs_rq;
16120         init_cfs_rq(cfs_rq, rq);
16121 +       init_cfs_hard_limits(cfs_rq, tg);
16122         cfs_rq->tg = tg;
16123         if (add)
16124                 list_add(&cfs_rq->leaf_cfs_rq_list, &rq->leaf_cfs_rq_list);
16125 @@ -9443,6 +9682,10 @@ void __init sched_init(void)
16126  #endif /* CONFIG_USER_SCHED */
16127  #endif /* CONFIG_RT_GROUP_SCHED */
16128  
16129 +#ifdef CONFIG_FAIR_GROUP_SCHED
16130 +       init_cfs_bandwidth(&init_task_group);
16131 +#endif
16132 +
16133  #ifdef CONFIG_GROUP_SCHED
16134         list_add(&init_task_group.list, &task_groups);
16135         INIT_LIST_HEAD(&init_task_group.children);
16136 @@ -9469,6 +9712,7 @@ void __init sched_init(void)
16137                 init_cfs_rq(&rq->cfs, rq);
16138                 init_rt_rq(&rq->rt, rq);
16139  #ifdef CONFIG_FAIR_GROUP_SCHED
16140 +               init_cfs_hard_limits(&rq->cfs, &init_task_group);
16141                 init_task_group.shares = init_task_group_load;
16142                 INIT_LIST_HEAD(&rq->leaf_cfs_rq_list);
16143  #ifdef CONFIG_CGROUP_SCHED
16144 @@ -9746,6 +9990,7 @@ static void free_fair_sched_group(struct
16145  {
16146         int i;
16147  
16148 +       destroy_cfs_bandwidth(tg);
16149         for_each_possible_cpu(i) {
16150                 if (tg->cfs_rq)
16151                         kfree(tg->cfs_rq[i]);
16152 @@ -9772,6 +10017,7 @@ int alloc_fair_sched_group(struct task_g
16153         if (!tg->se)
16154                 goto err;
16155  
16156 +       init_cfs_bandwidth(tg);
16157         tg->shares = NICE_0_LOAD;
16158  
16159         for_each_possible_cpu(i) {
16160 @@ -10495,6 +10741,100 @@ static u64 cpu_shares_read_u64(struct cg
16161  
16162         return (u64) tg->shares;
16163  }
16164 +
16165 +#ifdef CONFIG_CFS_HARD_LIMITS
16166 +
16167 +static int tg_set_cfs_bandwidth(struct task_group *tg,
16168 +               u64 cfs_period, u64 cfs_runtime)
16169 +{
16170 +       int i;
16171 +
16172 +       spin_lock_irq(&tg->cfs_bandwidth.cfs_runtime_lock);
16173 +       tg->cfs_bandwidth.cfs_period = ns_to_ktime(cfs_period);
16174 +       tg->cfs_bandwidth.cfs_runtime = cfs_runtime;
16175 +
16176 +       for_each_possible_cpu(i) {
16177 +               struct cfs_rq *cfs_rq = tg->cfs_rq[i];
16178 +
16179 +               cfs_rq_runtime_lock(cfs_rq);
16180 +               cfs_rq->cfs_runtime = cfs_runtime;
16181 +               cfs_rq_runtime_unlock(cfs_rq);
16182 +       }
16183 +
16184 +       start_cfs_bandwidth(tg);
16185 +       spin_unlock_irq(&tg->cfs_bandwidth.cfs_runtime_lock);
16186 +       return 0;
16187 +}
16188 +
16189 +int tg_set_cfs_runtime(struct task_group *tg, long cfs_runtime_us)
16190 +{
16191 +       u64 cfs_runtime, cfs_period;
16192 +
16193 +       cfs_period = ktime_to_ns(tg->cfs_bandwidth.cfs_period);
16194 +       cfs_runtime = (u64)cfs_runtime_us * NSEC_PER_USEC;
16195 +       if (cfs_runtime_us < 0)
16196 +               cfs_runtime = RUNTIME_INF;
16197 +
16198 +       return tg_set_cfs_bandwidth(tg, cfs_period, cfs_runtime);
16199 +}
16200 +
16201 +long tg_get_cfs_runtime(struct task_group *tg)
16202 +{
16203 +       u64 cfs_runtime_us;
16204 +
16205 +       if (tg->cfs_bandwidth.cfs_runtime == RUNTIME_INF)
16206 +               return -1;
16207 +
16208 +       cfs_runtime_us = tg->cfs_bandwidth.cfs_runtime;
16209 +       do_div(cfs_runtime_us, NSEC_PER_USEC);
16210 +       return cfs_runtime_us;
16211 +}
16212 +
16213 +int tg_set_cfs_period(struct task_group *tg, long cfs_period_us)
16214 +{
16215 +       u64 cfs_runtime, cfs_period;
16216 +
16217 +       cfs_period = (u64)cfs_period_us * NSEC_PER_USEC;
16218 +       cfs_runtime = tg->cfs_bandwidth.cfs_runtime;
16219 +
16220 +       if (cfs_period == 0)
16221 +               return -EINVAL;
16222 +
16223 +       return tg_set_cfs_bandwidth(tg, cfs_period, cfs_runtime);
16224 +}
16225 +
16226 +long tg_get_cfs_period(struct task_group *tg)
16227 +{
16228 +       u64 cfs_period_us;
16229 +
16230 +       cfs_period_us = ktime_to_ns(tg->cfs_bandwidth.cfs_period);
16231 +       do_div(cfs_period_us, NSEC_PER_USEC);
16232 +       return cfs_period_us;
16233 +}
16234 +
16235 +static s64 cpu_cfs_runtime_read_s64(struct cgroup *cgrp, struct cftype *cft)
16236 +{
16237 +       return tg_get_cfs_runtime(cgroup_tg(cgrp));
16238 +}
16239 +
16240 +static int cpu_cfs_runtime_write_s64(struct cgroup *cgrp, struct cftype *cftype,
16241 +                               s64 cfs_runtime_us)
16242 +{
16243 +       return tg_set_cfs_runtime(cgroup_tg(cgrp), cfs_runtime_us);
16244 +}
16245 +
16246 +static u64 cpu_cfs_period_read_u64(struct cgroup *cgrp, struct cftype *cft)
16247 +{
16248 +       return tg_get_cfs_period(cgroup_tg(cgrp));
16249 +}
16250 +
16251 +static int cpu_cfs_period_write_u64(struct cgroup *cgrp, struct cftype *cftype,
16252 +                               u64 cfs_period_us)
16253 +{
16254 +       return tg_set_cfs_period(cgroup_tg(cgrp), cfs_period_us);
16255 +}
16256 +
16257 +#endif /* CONFIG_CFS_HARD_LIMITS */
16258  #endif /* CONFIG_FAIR_GROUP_SCHED */
16259  
16260  #ifdef CONFIG_RT_GROUP_SCHED
16261 @@ -10528,6 +10868,18 @@ static struct cftype cpu_files[] = {
16262                 .read_u64 = cpu_shares_read_u64,
16263                 .write_u64 = cpu_shares_write_u64,
16264         },
16265 +#ifdef CONFIG_CFS_HARD_LIMITS
16266 +       {
16267 +               .name = "cfs_runtime_us",
16268 +               .read_s64 = cpu_cfs_runtime_read_s64,
16269 +               .write_s64 = cpu_cfs_runtime_write_s64,
16270 +       },
16271 +       {
16272 +               .name = "cfs_period_us",
16273 +               .read_u64 = cpu_cfs_period_read_u64,
16274 +               .write_u64 = cpu_cfs_period_write_u64,
16275 +       },
16276 +#endif /* CONFIG_CFS_HARD_LIMITS */
16277  #endif
16278  #ifdef CONFIG_RT_GROUP_SCHED
16279         {
16280 diff -NurpP --minimal linux-2.6.32.6/kernel/sched_debug.c linux-2.6.32.6-vs2.3.0.36.28/kernel/sched_debug.c
16281 --- linux-2.6.32.6/kernel/sched_debug.c 2010-01-26 19:31:27.000000000 +0100
16282 +++ linux-2.6.32.6-vs2.3.0.36.28/kernel/sched_debug.c   2009-12-29 00:36:26.000000000 +0100
16283 @@ -80,6 +80,11 @@ static void print_cfs_group_stats(struct
16284         PN(se->wait_max);
16285         PN(se->wait_sum);
16286         P(se->wait_count);
16287 +#ifdef CONFIG_CFS_HARD_LIMITS
16288 +       PN(se->throttle_max);
16289 +       PN(se->throttle_sum);
16290 +       P(se->throttle_count);
16291 +#endif
16292  #endif
16293         P(se->load.weight);
16294  #undef PN
16295 @@ -214,6 +219,16 @@ void print_cfs_rq(struct seq_file *m, in
16296  #ifdef CONFIG_SMP
16297         SEQ_printf(m, "  .%-30s: %lu\n", "shares", cfs_rq->shares);
16298  #endif
16299 +#ifdef CONFIG_CFS_HARD_LIMITS
16300 +       spin_lock_irqsave(&rq->lock, flags);
16301 +       SEQ_printf(m, "  .%-30s: %d\n", "cfs_throttled",
16302 +                       cfs_rq->cfs_throttled);
16303 +       SEQ_printf(m, "  .%-30s: %Ld.%06ld\n", "cfs_time",
16304 +                       SPLIT_NS(cfs_rq->cfs_time));
16305 +       SEQ_printf(m, "  .%-30s: %Ld.%06ld\n", "cfs_runtime",
16306 +                       SPLIT_NS(cfs_rq->cfs_runtime));
16307 +       spin_unlock_irqrestore(&rq->lock, flags);
16308 +#endif /* CONFIG_CFS_HARD_LIMITS */
16309         print_cfs_group_stats(m, cpu, cfs_rq->tg);
16310  #endif
16311  }
16312 @@ -314,7 +329,7 @@ static int sched_debug_show(struct seq_f
16313         u64 now = ktime_to_ns(ktime_get());
16314         int cpu;
16315  
16316 -       SEQ_printf(m, "Sched Debug Version: v0.09, %s %.*s\n",
16317 +       SEQ_printf(m, "Sched Debug Version: v0.10, %s %.*s\n",
16318                 init_utsname()->release,
16319                 (int)strcspn(init_utsname()->version, " "),
16320                 init_utsname()->version);
16321 diff -NurpP --minimal linux-2.6.32.6/kernel/sched_fair.c linux-2.6.32.6-vs2.3.0.36.28/kernel/sched_fair.c
16322 --- linux-2.6.32.6/kernel/sched_fair.c  2010-01-26 19:31:27.000000000 +0100
16323 +++ linux-2.6.32.6-vs2.3.0.36.28/kernel/sched_fair.c    2010-01-13 14:37:25.000000000 +0100
16324 @@ -189,7 +189,308 @@ find_matching_se(struct sched_entity **s
16325         }
16326  }
16327  
16328 -#else  /* !CONFIG_FAIR_GROUP_SCHED */
16329 +#ifdef CONFIG_CFS_HARD_LIMITS
16330 +
16331 +static inline void update_stats_throttle_start(struct cfs_rq *cfs_rq,
16332 +                       struct sched_entity *se)
16333 +{
16334 +       schedstat_set(se->throttle_start, rq_of(cfs_rq)->clock);
16335 +}
16336 +
16337 +static inline void update_stats_throttle_end(struct cfs_rq *cfs_rq,
16338 +                       struct sched_entity *se)
16339 +{
16340 +       schedstat_set(se->throttle_max, max(se->throttle_max,
16341 +                       rq_of(cfs_rq)->clock - se->throttle_start));
16342 +       schedstat_set(se->throttle_count, se->throttle_count + 1);
16343 +       schedstat_set(se->throttle_sum, se->throttle_sum +
16344 +                       rq_of(cfs_rq)->clock - se->throttle_start);
16345 +       schedstat_set(se->throttle_start, 0);
16346 +}
16347 +
16348 +static inline
16349 +struct cfs_rq *sched_cfs_period_cfs_rq(struct cfs_bandwidth *cfs_b, int cpu)
16350 +{
16351 +       return container_of(cfs_b, struct task_group,
16352 +                       cfs_bandwidth)->cfs_rq[cpu];
16353 +}
16354 +
16355 +static inline int cfs_rq_throttled(struct cfs_rq *cfs_rq)
16356 +{
16357 +       return cfs_rq->cfs_throttled;
16358 +}
16359 +
16360 +#ifdef CONFIG_SMP
16361 +/*
16362 + * Ensure this RQ takes back all the runtime it lend to its neighbours.
16363 + */
16364 +static void disable_runtime_cfs(struct rq *rq)
16365 +{
16366 +       struct root_domain *rd = rq->rd;
16367 +       struct cfs_rq *cfs_rq;
16368 +
16369 +       if (unlikely(!scheduler_running))
16370 +               return;
16371 +
16372 +       for_each_leaf_cfs_rq(rq, cfs_rq) {
16373 +               struct cfs_bandwidth *cfs_b = &cfs_rq->tg->cfs_bandwidth;
16374 +               s64 want;
16375 +               int i;
16376 +
16377 +               spin_lock(&cfs_b->cfs_runtime_lock);
16378 +               spin_lock(&cfs_rq->cfs_runtime_lock);
16379 +
16380 +               /*
16381 +                * Either we're all are infinity and nobody needs to borrow,
16382 +                * or we're already disabled and this have nothing to do, or
16383 +                * we have exactly the right amount of runtime to take out.
16384 +                */
16385 +                if (cfs_rq->cfs_runtime == RUNTIME_INF ||
16386 +                               cfs_rq->cfs_runtime == cfs_b->cfs_runtime)
16387 +                       goto balanced;
16388 +               spin_unlock(&cfs_rq->cfs_runtime_lock);
16389 +
16390 +               /*
16391 +                * Calculate the difference between what we started out with
16392 +                * and what we current have, that's the amount of runtime
16393 +                * we lend and now have to reclaim.
16394 +                */
16395 +                want = cfs_b->cfs_runtime - cfs_rq->cfs_runtime;
16396 +
16397 +               /*
16398 +                * Greedy reclaim, take back as much as possible.
16399 +                */
16400 +               for_each_cpu(i, rd->span) {
16401 +                       struct cfs_rq *iter = sched_cfs_period_cfs_rq(cfs_b, i);
16402 +                       s64 diff;
16403 +
16404 +                       /*
16405 +                        * Can't reclaim from ourselves or disabled runqueues.
16406 +                        */
16407 +                       if (iter == cfs_rq || iter->cfs_runtime == RUNTIME_INF)
16408 +                               continue;
16409 +
16410 +                       spin_lock(&iter->cfs_runtime_lock);
16411 +                       if (want > 0) {
16412 +                               diff = min_t(s64, iter->cfs_runtime, want);
16413 +                               iter->cfs_runtime -= diff;
16414 +                               want -= diff;
16415 +                       } else {
16416 +                               iter->cfs_runtime -= want;
16417 +                               want -= want;
16418 +                       }
16419 +
16420 +                       spin_unlock(&iter->cfs_runtime_lock);
16421 +                       if (!want)
16422 +                               break;
16423 +               }
16424 +
16425 +               spin_lock(&cfs_rq->cfs_runtime_lock);
16426 +               /*
16427 +                * We cannot be left wanting - that would mean some
16428 +                * runtime leaked out of the system.
16429 +                */
16430 +               BUG_ON(want);
16431 +balanced:
16432 +               /*
16433 +                * Disable all the borrow logic by pretending we have infinite
16434 +                * runtime - in which case borrowing doesn't make sense.
16435 +                */
16436 +                cfs_rq->cfs_runtime = RUNTIME_INF;
16437 +                spin_unlock(&cfs_rq->cfs_runtime_lock);
16438 +                spin_unlock(&cfs_b->cfs_runtime_lock);
16439 +       }
16440 +}
16441 +
16442 +static void enable_runtime_cfs(struct rq *rq)
16443 +{
16444 +       struct cfs_rq *cfs_rq;
16445 +
16446 +       if (unlikely(!scheduler_running))
16447 +               return;
16448 +
16449 +       /*
16450 +        * Reset each runqueue's bandwidth settings
16451 +        */
16452 +       for_each_leaf_cfs_rq(rq, cfs_rq) {
16453 +               struct cfs_bandwidth *cfs_b = &cfs_rq->tg->cfs_bandwidth;
16454 +
16455 +               spin_lock(&cfs_b->cfs_runtime_lock);
16456 +               spin_lock(&cfs_rq->cfs_runtime_lock);
16457 +               cfs_rq->cfs_runtime = cfs_b->cfs_runtime;
16458 +               cfs_rq->cfs_time = 0;
16459 +               cfs_rq->cfs_throttled = 0;
16460 +               spin_unlock(&cfs_rq->cfs_runtime_lock);
16461 +               spin_unlock(&cfs_b->cfs_runtime_lock);
16462 +       }
16463 +}
16464 +
16465 +/*
16466 + * Ran out of runtime, check if we can borrow some from others
16467 + * instead of getting throttled right away.
16468 + */
16469 +static void do_cfs_balance_runtime(struct cfs_rq *cfs_rq)
16470 +{
16471 +       struct cfs_bandwidth *cfs_b = &cfs_rq->tg->cfs_bandwidth;
16472 +       const struct cpumask *span = sched_bw_period_mask();
16473 +       int i, weight;
16474 +       u64 cfs_period;
16475 +
16476 +       weight = cpumask_weight(span);
16477 +       spin_lock(&cfs_b->cfs_runtime_lock);
16478 +       cfs_period = ktime_to_ns(cfs_b->cfs_period);
16479 +
16480 +       for_each_cpu(i, span) {
16481 +               struct cfs_rq *borrow_cfs_rq =
16482 +                               sched_cfs_period_cfs_rq(cfs_b, i);
16483 +               s64 diff;
16484 +
16485 +               if (borrow_cfs_rq == cfs_rq)
16486 +                       continue;
16487 +
16488 +               cfs_rq_runtime_lock(borrow_cfs_rq);
16489 +               if (borrow_cfs_rq->cfs_runtime == RUNTIME_INF) {
16490 +                       cfs_rq_runtime_unlock(borrow_cfs_rq);
16491 +                       continue;
16492 +               }
16493 +
16494 +               diff = borrow_cfs_rq->cfs_runtime - borrow_cfs_rq->cfs_time;
16495 +               if (diff > 0) {
16496 +                       diff = div_u64((u64)diff, weight);
16497 +                       if (cfs_rq->cfs_runtime + diff > cfs_period)
16498 +                               diff = cfs_period - cfs_rq->cfs_runtime;
16499 +                       borrow_cfs_rq->cfs_runtime -= diff;
16500 +                       cfs_rq->cfs_runtime += diff;
16501 +                       if (cfs_rq->cfs_runtime == cfs_period) {
16502 +                               cfs_rq_runtime_unlock(borrow_cfs_rq);
16503 +                               break;
16504 +                       }
16505 +               }
16506 +               cfs_rq_runtime_unlock(borrow_cfs_rq);
16507 +       }
16508 +       spin_unlock(&cfs_b->cfs_runtime_lock);
16509 +}
16510 +
16511 +/*
16512 + * Called with rq->runtime_lock held.
16513 + */
16514 +static void cfs_balance_runtime(struct cfs_rq *cfs_rq)
16515 +{
16516 +       cfs_rq_runtime_unlock(cfs_rq);
16517 +       do_cfs_balance_runtime(cfs_rq);
16518 +       cfs_rq_runtime_lock(cfs_rq);
16519 +}
16520 +
16521 +#else /* !CONFIG_SMP */
16522 +
16523 +static void cfs_balance_runtime(struct cfs_rq *cfs_rq)
16524 +{
16525 +       return;
16526 +}
16527 +#endif /* CONFIG_SMP */
16528 +
16529 +/*
16530 + * Check if group entity exceeded its runtime. If so, mark the cfs_rq as
16531 + * throttled mark the current task for reschedling.
16532 + */
16533 +static void sched_cfs_runtime_exceeded(struct sched_entity *se,
16534 +       struct task_struct *tsk_curr, unsigned long delta_exec)
16535 +{
16536 +       struct cfs_rq *cfs_rq;
16537 +
16538 +       cfs_rq = group_cfs_rq(se);
16539 +
16540 +       if (cfs_rq->cfs_runtime == RUNTIME_INF)
16541 +               return;
16542 +
16543 +       cfs_rq->cfs_time += delta_exec;
16544 +
16545 +       if (cfs_rq_throttled(cfs_rq))
16546 +               return;
16547 +
16548 +       if (cfs_rq->cfs_time > cfs_rq->cfs_runtime)
16549 +               cfs_balance_runtime(cfs_rq);
16550 +
16551 +       if (cfs_rq->cfs_time > cfs_rq->cfs_runtime) {
16552 +               cfs_rq->cfs_throttled = 1;
16553 +               update_stats_throttle_start(cfs_rq, se);
16554 +               resched_task(tsk_curr);
16555 +       }
16556 +}
16557 +
16558 +static inline void update_curr_group(struct sched_entity *curr,
16559 +               unsigned long delta_exec, struct task_struct *tsk_curr)
16560 +{
16561 +       sched_cfs_runtime_exceeded(curr, tsk_curr, delta_exec);
16562 +}
16563 +
16564 +static void enqueue_entity_locked(struct cfs_rq *cfs_rq,
16565 +               struct sched_entity *se, int wakeup);
16566 +
16567 +static void enqueue_throttled_entity(struct rq *rq, struct sched_entity *se)
16568 +{
16569 +       for_each_sched_entity(se) {
16570 +               struct cfs_rq *gcfs_rq = group_cfs_rq(se);
16571 +
16572 +               if (se->on_rq || cfs_rq_throttled(gcfs_rq) ||
16573 +                               !gcfs_rq->nr_running)
16574 +                       break;
16575 +               enqueue_entity_locked(cfs_rq_of(se), se, 0);
16576 +       }
16577 +}
16578 +
16579 +/*
16580 + * Refresh runtimes of all cfs_rqs in this group, i,e.,
16581 + * refresh runtimes of the representative cfs_rq of this
16582 + * tg on all cpus. Enqueue any throttled entity back.
16583 + */
16584 +void do_sched_cfs_period_timer(struct cfs_bandwidth *cfs_b)
16585 +{
16586 +       int i;
16587 +       const struct cpumask *span = sched_bw_period_mask();
16588 +       unsigned long flags;
16589 +
16590 +       for_each_cpu(i, span) {
16591 +               struct rq *rq = cpu_rq(i);
16592 +               struct cfs_rq *cfs_rq = sched_cfs_period_cfs_rq(cfs_b, i);
16593 +               struct sched_entity *se = cfs_rq->tg->se[i];
16594 +
16595 +               spin_lock_irqsave(&rq->lock, flags);
16596 +               cfs_rq_runtime_lock(cfs_rq);
16597 +               cfs_rq->cfs_time = 0;
16598 +               if (cfs_rq_throttled(cfs_rq)) {
16599 +                       update_rq_clock(rq);
16600 +                       update_stats_throttle_end(cfs_rq, se);
16601 +                       cfs_rq->cfs_throttled = 0;
16602 +                       enqueue_throttled_entity(rq, se);
16603 +               }
16604 +               cfs_rq_runtime_unlock(cfs_rq);
16605 +               spin_unlock_irqrestore(&rq->lock, flags);
16606 +       }
16607 +}
16608 +
16609 +#else
16610 +
16611 +static inline void update_curr_group(struct sched_entity *curr,
16612 +               unsigned long delta_exec, struct task_struct *tsk_curr)
16613 +{
16614 +       return;
16615 +}
16616 +
16617 +static inline int cfs_rq_throttled(struct cfs_rq *cfs_rq)
16618 +{
16619 +       return 0;
16620 +}
16621 +
16622 +#endif /* CONFIG_CFS_HARD_LIMITS */
16623 +
16624 +#else  /* CONFIG_FAIR_GROUP_SCHED */
16625 +
16626 +static inline void update_curr_group(struct sched_entity *curr,
16627 +               unsigned long delta_exec, struct task_struct *tsk_curr)
16628 +{
16629 +       return;
16630 +}
16631  
16632  static inline struct task_struct *task_of(struct sched_entity *se)
16633  {
16634 @@ -251,7 +552,6 @@ find_matching_se(struct sched_entity **s
16635  
16636  #endif /* CONFIG_FAIR_GROUP_SCHED */
16637  
16638 -
16639  /**************************************************************
16640   * Scheduling class tree data structure manipulation methods:
16641   */
16642 @@ -489,14 +789,25 @@ __update_curr(struct cfs_rq *cfs_rq, str
16643         update_min_vruntime(cfs_rq);
16644  }
16645  
16646 -static void update_curr(struct cfs_rq *cfs_rq)
16647 +static void update_curr_task(struct sched_entity *curr,
16648 +               unsigned long delta_exec)
16649 +{
16650 +       struct task_struct *curtask = task_of(curr);
16651 +
16652 +       trace_sched_stat_runtime(curtask, delta_exec, curr->vruntime);
16653 +       cpuacct_charge(curtask, delta_exec);
16654 +       account_group_exec_runtime(curtask, delta_exec);
16655 +}
16656 +
16657 +static int update_curr_common(struct cfs_rq *cfs_rq, unsigned long *delta)
16658  {
16659         struct sched_entity *curr = cfs_rq->curr;
16660 -       u64 now = rq_of(cfs_rq)->clock;
16661 +       struct rq *rq = rq_of(cfs_rq);
16662 +       u64 now = rq->clock;
16663         unsigned long delta_exec;
16664  
16665         if (unlikely(!curr))
16666 -               return;
16667 +               return 1;
16668  
16669         /*
16670          * Get the amount of time the current task was running
16671 @@ -505,17 +816,29 @@ static void update_curr(struct cfs_rq *c
16672          */
16673         delta_exec = (unsigned long)(now - curr->exec_start);
16674         if (!delta_exec)
16675 -               return;
16676 +               return 1;
16677  
16678         __update_curr(cfs_rq, curr, delta_exec);
16679         curr->exec_start = now;
16680 +       *delta = delta_exec;
16681 +       return 0;
16682 +}
16683  
16684 -       if (entity_is_task(curr)) {
16685 -               struct task_struct *curtask = task_of(curr);
16686 +static void update_curr(struct cfs_rq *cfs_rq)
16687 +{
16688 +       struct sched_entity *curr = cfs_rq->curr;
16689 +       struct rq *rq = rq_of(cfs_rq);
16690 +       unsigned long delta_exec;
16691  
16692 -               trace_sched_stat_runtime(curtask, delta_exec, curr->vruntime);
16693 -               cpuacct_charge(curtask, delta_exec);
16694 -               account_group_exec_runtime(curtask, delta_exec);
16695 +       if (update_curr_common(cfs_rq, &delta_exec))
16696 +               return ;
16697 +
16698 +       if (entity_is_task(curr))
16699 +               update_curr_task(curr, delta_exec);
16700 +       else {
16701 +               cfs_rq_runtime_lock(group_cfs_rq(curr));
16702 +               update_curr_group(curr, delta_exec, rq->curr);
16703 +               cfs_rq_runtime_unlock(group_cfs_rq(curr));
16704         }
16705  }
16706  
16707 @@ -740,13 +1063,9 @@ place_entity(struct cfs_rq *cfs_rq, stru
16708         se->vruntime = vruntime;
16709  }
16710  
16711 -static void
16712 -enqueue_entity(struct cfs_rq *cfs_rq, struct sched_entity *se, int wakeup)
16713 +static void enqueue_entity_common(struct cfs_rq *cfs_rq,
16714 +               struct sched_entity *se, int wakeup)
16715  {
16716 -       /*
16717 -        * Update run-time statistics of the 'current'.
16718 -        */
16719 -       update_curr(cfs_rq);
16720         account_entity_enqueue(cfs_rq, se);
16721  
16722         if (wakeup) {
16723 @@ -758,6 +1077,29 @@ enqueue_entity(struct cfs_rq *cfs_rq, st
16724         check_spread(cfs_rq, se);
16725         if (se != cfs_rq->curr)
16726                 __enqueue_entity(cfs_rq, se);
16727 +
16728 +       if (entity_is_task(se))
16729 +               vx_activate_task(task_of(se));
16730 +}
16731 +
16732 +static void enqueue_entity(struct cfs_rq *cfs_rq, struct sched_entity *se,
16733 +               int wakeup)
16734 +{
16735 +       /*
16736 +        * Update run-time statistics of the 'current'.
16737 +        */
16738 +       update_curr(cfs_rq);
16739 +       enqueue_entity_common(cfs_rq, se, wakeup);
16740 +}
16741 +
16742 +static void enqueue_entity_locked(struct cfs_rq *cfs_rq,
16743 +               struct sched_entity *se, int wakeup)
16744 +{
16745 +       /*
16746 +        * Update run-time statistics of the 'current'.
16747 +        */
16748 +       // update_curr_locked(cfs_rq);
16749 +       enqueue_entity_common(cfs_rq, se, wakeup);
16750  }
16751  
16752  static void __clear_buddies(struct cfs_rq *cfs_rq, struct sched_entity *se)
16753 @@ -801,6 +1143,8 @@ dequeue_entity(struct cfs_rq *cfs_rq, st
16754  
16755         if (se != cfs_rq->curr)
16756                 __dequeue_entity(cfs_rq, se);
16757 +       if (entity_is_task(se))
16758 +               vx_deactivate_task(task_of(se));
16759         account_entity_dequeue(cfs_rq, se);
16760         update_min_vruntime(cfs_rq);
16761  }
16762 @@ -897,6 +1241,32 @@ static struct sched_entity *pick_next_en
16763         return se;
16764  }
16765  
16766 +/*
16767 + * Called from put_prev_entity()
16768 + * If a group entity (@se) is found to be throttled, it will not be put back
16769 + * on @cfs_rq, which is equivalent to dequeing it.
16770 + */
16771 +static int dequeue_throttled_entity(struct cfs_rq *cfs_rq,
16772 +               struct sched_entity *se)
16773 +{
16774 +       struct cfs_rq *gcfs_rq = group_cfs_rq(se);
16775 +
16776 +       if (entity_is_task(se))
16777 +               return 0;
16778 +
16779 +       cfs_rq_runtime_lock(gcfs_rq);
16780 +       if (!cfs_rq_throttled(gcfs_rq) && gcfs_rq->nr_running) {
16781 +               cfs_rq_runtime_unlock(gcfs_rq);
16782 +               return 0;
16783 +       }
16784 +
16785 +       __clear_buddies(cfs_rq, se);
16786 +       account_entity_dequeue(cfs_rq, se);
16787 +       cfs_rq->curr = NULL;
16788 +       cfs_rq_runtime_unlock(gcfs_rq);
16789 +       return 1;
16790 +}
16791 +
16792  static void put_prev_entity(struct cfs_rq *cfs_rq, struct sched_entity *prev)
16793  {
16794         /*
16795 @@ -908,6 +1278,8 @@ static void put_prev_entity(struct cfs_r
16796  
16797         check_spread(cfs_rq, prev);
16798         if (prev->on_rq) {
16799 +               if (dequeue_throttled_entity(cfs_rq, prev))
16800 +                       return;
16801                 update_stats_wait_start(cfs_rq, prev);
16802                 /* Put 'current' back into the tree. */
16803                 __enqueue_entity(cfs_rq, prev);
16804 @@ -1004,10 +1376,28 @@ static inline void hrtick_update(struct 
16805  }
16806  #endif
16807  
16808 +static int enqueue_group_entity(struct cfs_rq *cfs_rq, struct sched_entity *se,
16809 +                int wakeup)
16810 +{
16811 +       struct cfs_rq *gcfs_rq = group_cfs_rq(se);
16812 +       int ret = 0;
16813 +
16814 +       cfs_rq_runtime_lock(gcfs_rq);
16815 +       if (cfs_rq_throttled(gcfs_rq)) {
16816 +               ret = 1;
16817 +               goto out;
16818 +       }
16819 +       enqueue_entity_locked(cfs_rq, se, wakeup);
16820 +out:
16821 +       cfs_rq_runtime_unlock(gcfs_rq);
16822 +       return ret;
16823 +}
16824 +
16825  /*
16826   * The enqueue_task method is called before nr_running is
16827   * increased. Here we update the fair scheduling stats and
16828   * then put the task into the rbtree:
16829 + * Don't enqueue a throttled entity further into the hierarchy.
16830   */
16831  static void enqueue_task_fair(struct rq *rq, struct task_struct *p, int wakeup)
16832  {
16833 @@ -1017,11 +1407,15 @@ static void enqueue_task_fair(struct rq 
16834         for_each_sched_entity(se) {
16835                 if (se->on_rq)
16836                         break;
16837 +
16838                 cfs_rq = cfs_rq_of(se);
16839 -               enqueue_entity(cfs_rq, se, wakeup);
16840 +               if (entity_is_task(se))
16841 +                       enqueue_entity(cfs_rq, se, wakeup);
16842 +               else
16843 +                       if (enqueue_group_entity(cfs_rq, se, wakeup))
16844 +                               break;
16845                 wakeup = 1;
16846         }
16847 -
16848         hrtick_update(rq);
16849  }
16850  
16851 @@ -1041,6 +1435,17 @@ static void dequeue_task_fair(struct rq 
16852                 /* Don't dequeue parent if it has other entities besides us */
16853                 if (cfs_rq->load.weight)
16854                         break;
16855 +
16856 +               /*
16857 +                * If this cfs_rq is throttled, then it is already
16858 +                * dequeued.
16859 +                */
16860 +               cfs_rq_runtime_lock(cfs_rq);
16861 +               if (cfs_rq_throttled(cfs_rq)) {
16862 +                       cfs_rq_runtime_unlock(cfs_rq);
16863 +                       break;
16864 +               }
16865 +               cfs_rq_runtime_unlock(cfs_rq);
16866                 sleep = 1;
16867         }
16868  
16869 @@ -1818,9 +2223,10 @@ load_balance_fair(struct rq *this_rq, in
16870                 u64 rem_load, moved_load;
16871  
16872                 /*
16873 -                * empty group
16874 +                * empty group or throttled group
16875                  */
16876 -               if (!busiest_cfs_rq->task_weight)
16877 +               if (!busiest_cfs_rq->task_weight ||
16878 +                               cfs_rq_throttled(busiest_cfs_rq))
16879                         continue;
16880  
16881                 rem_load = (u64)rem_load_move * busiest_weight;
16882 @@ -1869,6 +2275,12 @@ move_one_task_fair(struct rq *this_rq, i
16883  
16884         for_each_leaf_cfs_rq(busiest, busy_cfs_rq) {
16885                 /*
16886 +                * Don't move task from a throttled cfs_rq
16887 +                */
16888 +               if (cfs_rq_throttled(busy_cfs_rq))
16889 +                       continue;
16890 +
16891 +               /*
16892                  * pass busy_cfs_rq argument into
16893                  * load_balance_[start|next]_fair iterators
16894                  */
16895 diff -NurpP --minimal linux-2.6.32.6/kernel/sched_rt.c linux-2.6.32.6-vs2.3.0.36.28/kernel/sched_rt.c
16896 --- linux-2.6.32.6/kernel/sched_rt.c    2009-12-03 20:02:58.000000000 +0100
16897 +++ linux-2.6.32.6-vs2.3.0.36.28/kernel/sched_rt.c      2009-12-03 20:04:56.000000000 +0100
16898 @@ -235,18 +235,6 @@ static int rt_se_boosted(struct sched_rt
16899         return p->prio != p->normal_prio;
16900  }
16901  
16902 -#ifdef CONFIG_SMP
16903 -static inline const struct cpumask *sched_rt_period_mask(void)
16904 -{
16905 -       return cpu_rq(smp_processor_id())->rd->span;
16906 -}
16907 -#else
16908 -static inline const struct cpumask *sched_rt_period_mask(void)
16909 -{
16910 -       return cpu_online_mask;
16911 -}
16912 -#endif
16913 -
16914  static inline
16915  struct rt_rq *sched_rt_period_rt_rq(struct rt_bandwidth *rt_b, int cpu)
16916  {
16917 @@ -296,11 +284,6 @@ static inline int rt_rq_throttled(struct
16918         return rt_rq->rt_throttled;
16919  }
16920  
16921 -static inline const struct cpumask *sched_rt_period_mask(void)
16922 -{
16923 -       return cpu_online_mask;
16924 -}
16925 -
16926  static inline
16927  struct rt_rq *sched_rt_period_rt_rq(struct rt_bandwidth *rt_b, int cpu)
16928  {
16929 @@ -373,7 +356,7 @@ next:
16930  /*
16931   * Ensure this RQ takes back all the runtime it lend to its neighbours.
16932   */
16933 -static void __disable_runtime(struct rq *rq)
16934 +static void disable_runtime_rt(struct rq *rq)
16935  {
16936         struct root_domain *rd = rq->rd;
16937         struct rt_rq *rt_rq;
16938 @@ -450,16 +433,7 @@ balanced:
16939         }
16940  }
16941  
16942 -static void disable_runtime(struct rq *rq)
16943 -{
16944 -       unsigned long flags;
16945 -
16946 -       spin_lock_irqsave(&rq->lock, flags);
16947 -       __disable_runtime(rq);
16948 -       spin_unlock_irqrestore(&rq->lock, flags);
16949 -}
16950 -
16951 -static void __enable_runtime(struct rq *rq)
16952 +static void enable_runtime_rt(struct rq *rq)
16953  {
16954         struct rt_rq *rt_rq;
16955  
16956 @@ -482,15 +456,6 @@ static void __enable_runtime(struct rq *
16957         }
16958  }
16959  
16960 -static void enable_runtime(struct rq *rq)
16961 -{
16962 -       unsigned long flags;
16963 -
16964 -       spin_lock_irqsave(&rq->lock, flags);
16965 -       __enable_runtime(rq);
16966 -       spin_unlock_irqrestore(&rq->lock, flags);
16967 -}
16968 -
16969  static int balance_runtime(struct rt_rq *rt_rq)
16970  {
16971         int more = 0;
16972 @@ -518,7 +483,7 @@ static int do_sched_rt_period_timer(stru
16973         if (!rt_bandwidth_enabled() || rt_b->rt_runtime == RUNTIME_INF)
16974                 return 1;
16975  
16976 -       span = sched_rt_period_mask();
16977 +       span = sched_bw_period_mask();
16978         for_each_cpu(i, span) {
16979                 int enqueue = 0;
16980                 struct rt_rq *rt_rq = sched_rt_period_rt_rq(rt_b, i);
16981 @@ -1564,7 +1529,7 @@ static void rq_online_rt(struct rq *rq)
16982         if (rq->rt.overloaded)
16983                 rt_set_overload(rq);
16984  
16985 -       __enable_runtime(rq);
16986 +       enable_runtime_rt(rq);
16987  
16988         cpupri_set(&rq->rd->cpupri, rq->cpu, rq->rt.highest_prio.curr);
16989  }
16990 @@ -1575,7 +1540,7 @@ static void rq_offline_rt(struct rq *rq)
16991         if (rq->rt.overloaded)
16992                 rt_clear_overload(rq);
16993  
16994 -       __disable_runtime(rq);
16995 +       disable_runtime_rt(rq);
16996  
16997         cpupri_set(&rq->rd->cpupri, rq->cpu, CPUPRI_INVALID);
16998  }
16999 diff -NurpP --minimal linux-2.6.32.6/kernel/signal.c linux-2.6.32.6-vs2.3.0.36.28/kernel/signal.c
17000 --- linux-2.6.32.6/kernel/signal.c      2010-01-26 19:31:27.000000000 +0100
17001 +++ linux-2.6.32.6-vs2.3.0.36.28/kernel/signal.c        2010-01-20 04:21:33.000000000 +0100
17002 @@ -27,6 +27,8 @@
17003  #include <linux/freezer.h>
17004  #include <linux/pid_namespace.h>
17005  #include <linux/nsproxy.h>
17006 +#include <linux/vs_context.h>
17007 +#include <linux/vs_pid.h>
17008  #include <trace/events/sched.h>
17009  
17010  #include <asm/param.h>
17011 @@ -598,6 +600,14 @@ static int check_kill_permission(int sig
17012         if (!valid_signal(sig))
17013                 return -EINVAL;
17014  
17015 +       if ((info != SEND_SIG_NOINFO) &&
17016 +               (is_si_special(info) || !SI_FROMUSER(info)))
17017 +               goto skip;
17018 +
17019 +       vxdprintk(VXD_CBIT(misc, 7),
17020 +               "check_kill_permission(%d,%p,%p[#%u,%u])",
17021 +               sig, info, t, vx_task_xid(t), t->pid);
17022 +
17023         if (info != SEND_SIG_NOINFO && (is_si_special(info) || SI_FROMKERNEL(info)))
17024                 return 0;
17025  
17026 @@ -625,6 +635,20 @@ static int check_kill_permission(int sig
17027                 }
17028         }
17029  
17030 +       error = -EPERM;
17031 +       if (t->pid == 1 && current->xid)
17032 +               return error;
17033 +
17034 +       error = -ESRCH;
17035 +       /* FIXME: we shouldn't return ESRCH ever, to avoid
17036 +                 loops, maybe ENOENT or EACCES? */
17037 +       if (!vx_check(vx_task_xid(t), VS_WATCH_P | VS_IDENT)) {
17038 +               vxdprintk(current->xid || VXD_CBIT(misc, 7),
17039 +                       "signal %d[%p] xid mismatch %p[#%u,%u] xid=#%u",
17040 +                       sig, info, t, vx_task_xid(t), t->pid, current->xid);
17041 +               return error;
17042 +       }
17043 +skip:
17044         return security_task_kill(t, info, sig, 0);
17045  }
17046  
17047 @@ -1113,7 +1137,7 @@ int kill_pid_info(int sig, struct siginf
17048         rcu_read_lock();
17049  retry:
17050         p = pid_task(pid, PIDTYPE_PID);
17051 -       if (p) {
17052 +       if (p && vx_check(vx_task_xid(p), VS_IDENT)) {
17053                 error = group_send_sig_info(sig, info, p);
17054                 if (unlikely(error == -ESRCH))
17055                         /*
17056 @@ -1152,7 +1176,7 @@ int kill_pid_info_as_uid(int sig, struct
17057  
17058         read_lock(&tasklist_lock);
17059         p = pid_task(pid, PIDTYPE_PID);
17060 -       if (!p) {
17061 +       if (!p || !vx_check(vx_task_xid(p), VS_IDENT)) {
17062                 ret = -ESRCH;
17063                 goto out_unlock;
17064         }
17065 @@ -1206,8 +1230,10 @@ static int kill_something_info(int sig, 
17066                 struct task_struct * p;
17067  
17068                 for_each_process(p) {
17069 -                       if (task_pid_vnr(p) > 1 &&
17070 -                                       !same_thread_group(p, current)) {
17071 +                       if (vx_check(vx_task_xid(p), VS_ADMIN|VS_IDENT) &&
17072 +                               task_pid_vnr(p) > 1 &&
17073 +                               !same_thread_group(p, current) &&
17074 +                               !vx_current_initpid(p->pid)) {
17075                                 int err = group_send_sig_info(sig, info, p);
17076                                 ++count;
17077                                 if (err != -EPERM)
17078 @@ -1872,6 +1898,11 @@ relock:
17079                                 !sig_kernel_only(signr))
17080                         continue;
17081  
17082 +               /* virtual init is protected against user signals */
17083 +               if ((info->si_code == SI_USER) &&
17084 +                       vx_current_initpid(current->pid))
17085 +                       continue;
17086 +
17087                 if (sig_kernel_stop(signr)) {
17088                         /*
17089                          * The default action is to stop all threads in
17090 diff -NurpP --minimal linux-2.6.32.6/kernel/softirq.c linux-2.6.32.6-vs2.3.0.36.28/kernel/softirq.c
17091 --- linux-2.6.32.6/kernel/softirq.c     2009-12-03 20:02:58.000000000 +0100
17092 +++ linux-2.6.32.6-vs2.3.0.36.28/kernel/softirq.c       2009-12-03 20:04:56.000000000 +0100
17093 @@ -24,6 +24,7 @@
17094  #include <linux/ftrace.h>
17095  #include <linux/smp.h>
17096  #include <linux/tick.h>
17097 +#include <linux/vs_context.h>
17098  
17099  #define CREATE_TRACE_POINTS
17100  #include <trace/events/irq.h>
17101 diff -NurpP --minimal linux-2.6.32.6/kernel/sys.c linux-2.6.32.6-vs2.3.0.36.28/kernel/sys.c
17102 --- linux-2.6.32.6/kernel/sys.c 2009-12-03 20:02:58.000000000 +0100
17103 +++ linux-2.6.32.6-vs2.3.0.36.28/kernel/sys.c   2009-12-03 20:04:56.000000000 +0100
17104 @@ -41,6 +41,7 @@
17105  #include <linux/syscalls.h>
17106  #include <linux/kprobes.h>
17107  #include <linux/user_namespace.h>
17108 +#include <linux/vs_pid.h>
17109  
17110  #include <asm/uaccess.h>
17111  #include <asm/io.h>
17112 @@ -130,7 +131,10 @@ static int set_one_prio(struct task_stru
17113                 goto out;
17114         }
17115         if (niceval < task_nice(p) && !can_nice(p, niceval)) {
17116 -               error = -EACCES;
17117 +               if (vx_flags(VXF_IGNEG_NICE, 0))
17118 +                       error = 0;
17119 +               else
17120 +                       error = -EACCES;
17121                 goto out;
17122         }
17123         no_nice = security_task_setnice(p, niceval);
17124 @@ -179,6 +183,8 @@ SYSCALL_DEFINE3(setpriority, int, which,
17125                         else
17126                                 pgrp = task_pgrp(current);
17127                         do_each_pid_thread(pgrp, PIDTYPE_PGID, p) {
17128 +                               if (!vx_check(p->xid, VS_ADMIN_P | VS_IDENT))
17129 +                                       continue;
17130                                 error = set_one_prio(p, niceval, error);
17131                         } while_each_pid_thread(pgrp, PIDTYPE_PGID, p);
17132                         break;
17133 @@ -240,6 +246,8 @@ SYSCALL_DEFINE2(getpriority, int, which,
17134                         else
17135                                 pgrp = task_pgrp(current);
17136                         do_each_pid_thread(pgrp, PIDTYPE_PGID, p) {
17137 +                               if (!vx_check(p->xid, VS_ADMIN_P | VS_IDENT))
17138 +                                       continue;
17139                                 niceval = 20 - task_nice(p);
17140                                 if (niceval > retval)
17141                                         retval = niceval;
17142 @@ -349,6 +357,9 @@ void kernel_power_off(void)
17143         machine_power_off();
17144  }
17145  EXPORT_SYMBOL_GPL(kernel_power_off);
17146 +
17147 +long vs_reboot(unsigned int, void __user *);
17148 +
17149  /*
17150   * Reboot system call: for obvious reasons only root may call it,
17151   * and even root needs to set up some magic numbers in the registers
17152 @@ -381,6 +392,9 @@ SYSCALL_DEFINE4(reboot, int, magic1, int
17153         if ((cmd == LINUX_REBOOT_CMD_POWER_OFF) && !pm_power_off)
17154                 cmd = LINUX_REBOOT_CMD_HALT;
17155  
17156 +       if (!vx_check(0, VS_ADMIN|VS_WATCH))
17157 +               return vs_reboot(cmd, arg);
17158 +
17159         lock_kernel();
17160         switch (cmd) {
17161         case LINUX_REBOOT_CMD_RESTART:
17162 @@ -1133,7 +1147,7 @@ SYSCALL_DEFINE2(sethostname, char __user
17163         int errno;
17164         char tmp[__NEW_UTS_LEN];
17165  
17166 -       if (!capable(CAP_SYS_ADMIN))
17167 +       if (!vx_capable(CAP_SYS_ADMIN, VXC_SET_UTSNAME))
17168                 return -EPERM;
17169         if (len < 0 || len > __NEW_UTS_LEN)
17170                 return -EINVAL;
17171 @@ -1182,7 +1196,7 @@ SYSCALL_DEFINE2(setdomainname, char __us
17172         int errno;
17173         char tmp[__NEW_UTS_LEN];
17174  
17175 -       if (!capable(CAP_SYS_ADMIN))
17176 +       if (!vx_capable(CAP_SYS_ADMIN, VXC_SET_UTSNAME))
17177                 return -EPERM;
17178         if (len < 0 || len > __NEW_UTS_LEN)
17179                 return -EINVAL;
17180 @@ -1251,7 +1265,7 @@ SYSCALL_DEFINE2(setrlimit, unsigned int,
17181                 return -EINVAL;
17182         old_rlim = current->signal->rlim + resource;
17183         if ((new_rlim.rlim_max > old_rlim->rlim_max) &&
17184 -           !capable(CAP_SYS_RESOURCE))
17185 +           !vx_capable(CAP_SYS_RESOURCE, VXC_SET_RLIMIT))
17186                 return -EPERM;
17187         if (resource == RLIMIT_NOFILE && new_rlim.rlim_max > sysctl_nr_open)
17188                 return -EPERM;
17189 diff -NurpP --minimal linux-2.6.32.6/kernel/sysctl.c linux-2.6.32.6-vs2.3.0.36.28/kernel/sysctl.c
17190 --- linux-2.6.32.6/kernel/sysctl.c      2010-01-26 19:31:27.000000000 +0100
17191 +++ linux-2.6.32.6-vs2.3.0.36.28/kernel/sysctl.c        2010-01-20 04:21:33.000000000 +0100
17192 @@ -124,6 +124,7 @@ static int ngroups_max = NGROUPS_MAX;
17193  extern char modprobe_path[];
17194  extern int modules_disabled;
17195  #endif
17196 +extern char vshelper_path[];
17197  #ifdef CONFIG_CHR_DEV_SG
17198  extern int sg_big_buff;
17199  #endif
17200 @@ -593,6 +594,15 @@ static struct ctl_table kern_table[] = {
17201                 .strategy       = &sysctl_string,
17202         },
17203  #endif
17204 +       {
17205 +               .ctl_name       = KERN_VSHELPER,
17206 +               .procname       = "vshelper",
17207 +               .data           = &vshelper_path,
17208 +               .maxlen         = 256,
17209 +               .mode           = 0644,
17210 +               .proc_handler   = &proc_dostring,
17211 +               .strategy       = &sysctl_string,
17212 +       },
17213  #ifdef CONFIG_CHR_DEV_SG
17214         {
17215                 .ctl_name       = KERN_SG_BIG_BUFF,
17216 diff -NurpP --minimal linux-2.6.32.6/kernel/sysctl_check.c linux-2.6.32.6-vs2.3.0.36.28/kernel/sysctl_check.c
17217 --- linux-2.6.32.6/kernel/sysctl_check.c        2009-12-03 20:02:58.000000000 +0100
17218 +++ linux-2.6.32.6-vs2.3.0.36.28/kernel/sysctl_check.c  2009-12-03 20:04:56.000000000 +0100
17219 @@ -39,6 +39,7 @@ static const struct trans_ctl_table tran
17220  
17221         { KERN_PANIC,                   "panic" },
17222         { KERN_REALROOTDEV,             "real-root-dev" },
17223 +       { KERN_VSHELPER,                "vshelper", },
17224  
17225         { KERN_SPARC_REBOOT,            "reboot-cmd" },
17226         { KERN_CTLALTDEL,               "ctrl-alt-del" },
17227 @@ -1217,6 +1218,22 @@ static const struct trans_ctl_table tran
17228         {}
17229  };
17230  
17231 +static struct trans_ctl_table trans_vserver_table[] = {
17232 +       { 1,    "debug_switch" },
17233 +       { 2,    "debug_xid" },
17234 +       { 3,    "debug_nid" },
17235 +       { 4,    "debug_tag" },
17236 +       { 5,    "debug_net" },
17237 +       { 6,    "debug_limit" },
17238 +       { 7,    "debug_cres" },
17239 +       { 8,    "debug_dlim" },
17240 +       { 9,    "debug_quota" },
17241 +       { 10,   "debug_cvirt" },
17242 +       { 11,   "debug_space" },
17243 +       { 12,   "debug_misc" },
17244 +       {}
17245 +};
17246 +
17247  static const struct trans_ctl_table trans_root_table[] = {
17248         { CTL_KERN,     "kernel",       trans_kern_table },
17249         { CTL_VM,       "vm",           trans_vm_table },
17250 @@ -1233,6 +1250,7 @@ static const struct trans_ctl_table tran
17251         { CTL_SUNRPC,   "sunrpc",       trans_sunrpc_table },
17252         { CTL_PM,       "pm",           trans_pm_table },
17253         { CTL_FRV,      "frv",          trans_frv_table },
17254 +       { CTL_VSERVER,  "vserver",      trans_vserver_table },
17255         {}
17256  };
17257  
17258 diff -NurpP --minimal linux-2.6.32.6/kernel/time.c linux-2.6.32.6-vs2.3.0.36.28/kernel/time.c
17259 --- linux-2.6.32.6/kernel/time.c        2009-12-03 20:02:58.000000000 +0100
17260 +++ linux-2.6.32.6-vs2.3.0.36.28/kernel/time.c  2009-12-03 20:04:56.000000000 +0100
17261 @@ -63,6 +63,7 @@ EXPORT_SYMBOL(sys_tz);
17262  SYSCALL_DEFINE1(time, time_t __user *, tloc)
17263  {
17264         time_t i = get_seconds();
17265 +/*     FIXME: do_gettimeofday(&tv) -> vx_gettimeofday(&tv) */
17266  
17267         if (tloc) {
17268                 if (put_user(i,tloc))
17269 @@ -93,7 +94,7 @@ SYSCALL_DEFINE1(stime, time_t __user *, 
17270         if (err)
17271                 return err;
17272  
17273 -       do_settimeofday(&tv);
17274 +       vx_settimeofday(&tv);
17275         return 0;
17276  }
17277  
17278 @@ -104,7 +105,7 @@ SYSCALL_DEFINE2(gettimeofday, struct tim
17279  {
17280         if (likely(tv != NULL)) {
17281                 struct timeval ktv;
17282 -               do_gettimeofday(&ktv);
17283 +               vx_gettimeofday(&ktv);
17284                 if (copy_to_user(tv, &ktv, sizeof(ktv)))
17285                         return -EFAULT;
17286         }
17287 @@ -179,7 +180,7 @@ int do_sys_settimeofday(struct timespec 
17288                 /* SMP safe, again the code in arch/foo/time.c should
17289                  * globally block out interrupts when it runs.
17290                  */
17291 -               return do_settimeofday(tv);
17292 +               return vx_settimeofday(tv);
17293         }
17294         return 0;
17295  }
17296 @@ -311,7 +312,7 @@ void getnstimeofday(struct timespec *tv)
17297  {
17298         struct timeval x;
17299  
17300 -       do_gettimeofday(&x);
17301 +       vx_gettimeofday(&x);
17302         tv->tv_sec = x.tv_sec;
17303         tv->tv_nsec = x.tv_usec * NSEC_PER_USEC;
17304  }
17305 diff -NurpP --minimal linux-2.6.32.6/kernel/timer.c linux-2.6.32.6-vs2.3.0.36.28/kernel/timer.c
17306 --- linux-2.6.32.6/kernel/timer.c       2009-12-03 20:02:58.000000000 +0100
17307 +++ linux-2.6.32.6-vs2.3.0.36.28/kernel/timer.c 2009-12-03 20:04:56.000000000 +0100
17308 @@ -39,6 +39,10 @@
17309  #include <linux/kallsyms.h>
17310  #include <linux/perf_event.h>
17311  #include <linux/sched.h>
17312 +#include <linux/vs_base.h>
17313 +#include <linux/vs_cvirt.h>
17314 +#include <linux/vs_pid.h>
17315 +#include <linux/vserver/sched.h>
17316  
17317  #include <asm/uaccess.h>
17318  #include <asm/unistd.h>
17319 @@ -1255,12 +1259,6 @@ SYSCALL_DEFINE1(alarm, unsigned int, sec
17320  
17321  #endif
17322  
17323 -#ifndef __alpha__
17324 -
17325 -/*
17326 - * The Alpha uses getxpid, getxuid, and getxgid instead.  Maybe this
17327 - * should be moved into arch/i386 instead?
17328 - */
17329  
17330  /**
17331   * sys_getpid - return the thread group id of the current process
17332 @@ -1289,10 +1287,23 @@ SYSCALL_DEFINE0(getppid)
17333         rcu_read_lock();
17334         pid = task_tgid_vnr(current->real_parent);
17335         rcu_read_unlock();
17336 +       return vx_map_pid(pid);
17337 +}
17338  
17339 -       return pid;
17340 +#ifdef __alpha__
17341 +
17342 +/*
17343 + * The Alpha uses getxpid, getxuid, and getxgid instead.
17344 + */
17345 +
17346 +asmlinkage long do_getxpid(long *ppid)
17347 +{
17348 +       *ppid = sys_getppid();
17349 +       return sys_getpid();
17350  }
17351  
17352 +#else /* _alpha_ */
17353 +
17354  SYSCALL_DEFINE0(getuid)
17355  {
17356         /* Only we change this so SMP safe */
17357 diff -NurpP --minimal linux-2.6.32.6/kernel/user.c linux-2.6.32.6-vs2.3.0.36.28/kernel/user.c
17358 --- linux-2.6.32.6/kernel/user.c        2009-12-03 20:02:58.000000000 +0100
17359 +++ linux-2.6.32.6-vs2.3.0.36.28/kernel/user.c  2009-12-03 20:04:56.000000000 +0100
17360 @@ -251,10 +251,10 @@ static struct kobj_type uids_ktype = {
17361   *
17362   * See Documentation/scheduler/sched-design-CFS.txt for ramifications.
17363   */
17364 -static int uids_user_create(struct user_struct *up)
17365 +static int uids_user_create(struct user_namespace *ns, struct user_struct *up)
17366  {
17367         struct kobject *kobj = &up->kobj;
17368 -       int error;
17369 +       int error = 0;
17370  
17371         memset(kobj, 0, sizeof(struct kobject));
17372         if (up->user_ns != &init_user_ns)
17373 @@ -282,7 +282,7 @@ int __init uids_sysfs_init(void)
17374         if (!uids_kset)
17375                 return -ENOMEM;
17376  
17377 -       return uids_user_create(&root_user);
17378 +       return uids_user_create(NULL, &root_user);
17379  }
17380  
17381  /* delayed work function to remove sysfs directory for a user and free up
17382 @@ -353,7 +353,8 @@ static struct user_struct *uid_hash_find
17383  }
17384  
17385  int uids_sysfs_init(void) { return 0; }
17386 -static inline int uids_user_create(struct user_struct *up) { return 0; }
17387 +static inline int uids_user_create(struct user_namespace *ns,
17388 +       struct user_struct *up) { return 0; }
17389  static inline void uids_mutex_lock(void) { }
17390  static inline void uids_mutex_unlock(void) { }
17391  
17392 @@ -450,7 +451,7 @@ struct user_struct *alloc_uid(struct use
17393  
17394                 new->user_ns = get_user_ns(ns);
17395  
17396 -               if (uids_user_create(new))
17397 +               if (uids_user_create(ns, new))
17398                         goto out_destoy_sched;
17399  
17400                 /*
17401 diff -NurpP --minimal linux-2.6.32.6/kernel/user_namespace.c linux-2.6.32.6-vs2.3.0.36.28/kernel/user_namespace.c
17402 --- linux-2.6.32.6/kernel/user_namespace.c      2009-03-24 14:22:45.000000000 +0100
17403 +++ linux-2.6.32.6-vs2.3.0.36.28/kernel/user_namespace.c        2009-12-03 20:04:56.000000000 +0100
17404 @@ -10,6 +10,7 @@
17405  #include <linux/slab.h>
17406  #include <linux/user_namespace.h>
17407  #include <linux/cred.h>
17408 +#include <linux/vserver/global.h>
17409  
17410  /*
17411   * Create a new user namespace, deriving the creator from the user in the
17412 @@ -30,6 +31,7 @@ int create_user_ns(struct cred *new)
17413                 return -ENOMEM;
17414  
17415         kref_init(&ns->kref);
17416 +       atomic_inc(&vs_global_user_ns);
17417  
17418         for (n = 0; n < UIDHASH_SZ; ++n)
17419                 INIT_HLIST_HEAD(ns->uidhash_table + n);
17420 @@ -78,6 +80,8 @@ void free_user_ns(struct kref *kref)
17421         struct user_namespace *ns =
17422                 container_of(kref, struct user_namespace, kref);
17423  
17424 +       /* FIXME: maybe move into destroyer? */
17425 +       atomic_dec(&vs_global_user_ns);
17426         INIT_WORK(&ns->destroyer, free_user_ns_work);
17427         schedule_work(&ns->destroyer);
17428  }
17429 diff -NurpP --minimal linux-2.6.32.6/kernel/utsname.c linux-2.6.32.6-vs2.3.0.36.28/kernel/utsname.c
17430 --- linux-2.6.32.6/kernel/utsname.c     2009-09-10 15:26:28.000000000 +0200
17431 +++ linux-2.6.32.6-vs2.3.0.36.28/kernel/utsname.c       2009-12-03 20:04:56.000000000 +0100
17432 @@ -14,14 +14,17 @@
17433  #include <linux/utsname.h>
17434  #include <linux/err.h>
17435  #include <linux/slab.h>
17436 +#include <linux/vserver/global.h>
17437  
17438  static struct uts_namespace *create_uts_ns(void)
17439  {
17440         struct uts_namespace *uts_ns;
17441  
17442         uts_ns = kmalloc(sizeof(struct uts_namespace), GFP_KERNEL);
17443 -       if (uts_ns)
17444 +       if (uts_ns) {
17445                 kref_init(&uts_ns->kref);
17446 +               atomic_inc(&vs_global_uts_ns);
17447 +       }
17448         return uts_ns;
17449  }
17450  
17451 @@ -71,5 +74,6 @@ void free_uts_ns(struct kref *kref)
17452         struct uts_namespace *ns;
17453  
17454         ns = container_of(kref, struct uts_namespace, kref);
17455 +       atomic_dec(&vs_global_uts_ns);
17456         kfree(ns);
17457  }
17458 diff -NurpP --minimal linux-2.6.32.6/kernel/vserver/cacct.c linux-2.6.32.6-vs2.3.0.36.28/kernel/vserver/cacct.c
17459 --- linux-2.6.32.6/kernel/vserver/cacct.c       1970-01-01 01:00:00.000000000 +0100
17460 +++ linux-2.6.32.6-vs2.3.0.36.28/kernel/vserver/cacct.c 2009-12-03 20:04:56.000000000 +0100
17461 @@ -0,0 +1,42 @@
17462 +/*
17463 + *  linux/kernel/vserver/cacct.c
17464 + *
17465 + *  Virtual Server: Context Accounting
17466 + *
17467 + *  Copyright (C) 2006-2007 Herbert Pötzl
17468 + *
17469 + *  V0.01  added accounting stats
17470 + *
17471 + */
17472 +
17473 +#include <linux/types.h>
17474 +#include <linux/vs_context.h>
17475 +#include <linux/vserver/cacct_cmd.h>
17476 +#include <linux/vserver/cacct_int.h>
17477 +
17478 +#include <asm/errno.h>
17479 +#include <asm/uaccess.h>
17480 +
17481 +
17482 +int vc_sock_stat(struct vx_info *vxi, void __user *data)
17483 +{
17484 +       struct vcmd_sock_stat_v0 vc_data;
17485 +       int j, field;
17486 +
17487 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
17488 +               return -EFAULT;
17489 +
17490 +       field = vc_data.field;
17491 +       if ((field < 0) || (field >= VXA_SOCK_SIZE))
17492 +               return -EINVAL;
17493 +
17494 +       for (j = 0; j < 3; j++) {
17495 +               vc_data.count[j] = vx_sock_count(&vxi->cacct, field, j);
17496 +               vc_data.total[j] = vx_sock_total(&vxi->cacct, field, j);
17497 +       }
17498 +
17499 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
17500 +               return -EFAULT;
17501 +       return 0;
17502 +}
17503 +
17504 diff -NurpP --minimal linux-2.6.32.6/kernel/vserver/cacct_init.h linux-2.6.32.6-vs2.3.0.36.28/kernel/vserver/cacct_init.h
17505 --- linux-2.6.32.6/kernel/vserver/cacct_init.h  1970-01-01 01:00:00.000000000 +0100
17506 +++ linux-2.6.32.6-vs2.3.0.36.28/kernel/vserver/cacct_init.h    2009-12-03 20:04:56.000000000 +0100
17507 @@ -0,0 +1,25 @@
17508 +
17509 +
17510 +static inline void vx_info_init_cacct(struct _vx_cacct *cacct)
17511 +{
17512 +       int i, j;
17513 +
17514 +
17515 +       for (i = 0; i < VXA_SOCK_SIZE; i++) {
17516 +               for (j = 0; j < 3; j++) {
17517 +                       atomic_long_set(&cacct->sock[i][j].count, 0);
17518 +                       atomic_long_set(&cacct->sock[i][j].total, 0);
17519 +               }
17520 +       }
17521 +       for (i = 0; i < 8; i++)
17522 +               atomic_set(&cacct->slab[i], 0);
17523 +       for (i = 0; i < 5; i++)
17524 +               for (j = 0; j < 4; j++)
17525 +                       atomic_set(&cacct->page[i][j], 0);
17526 +}
17527 +
17528 +static inline void vx_info_exit_cacct(struct _vx_cacct *cacct)
17529 +{
17530 +       return;
17531 +}
17532 +
17533 diff -NurpP --minimal linux-2.6.32.6/kernel/vserver/cacct_proc.h linux-2.6.32.6-vs2.3.0.36.28/kernel/vserver/cacct_proc.h
17534 --- linux-2.6.32.6/kernel/vserver/cacct_proc.h  1970-01-01 01:00:00.000000000 +0100
17535 +++ linux-2.6.32.6-vs2.3.0.36.28/kernel/vserver/cacct_proc.h    2009-12-03 20:04:56.000000000 +0100
17536 @@ -0,0 +1,53 @@
17537 +#ifndef _VX_CACCT_PROC_H
17538 +#define _VX_CACCT_PROC_H
17539 +
17540 +#include <linux/vserver/cacct_int.h>
17541 +
17542 +
17543 +#define VX_SOCKA_TOP   \
17544 +       "Type\t    recv #/bytes\t\t   send #/bytes\t\t    fail #/bytes\n"
17545 +
17546 +static inline int vx_info_proc_cacct(struct _vx_cacct *cacct, char *buffer)
17547 +{
17548 +       int i, j, length = 0;
17549 +       static char *type[VXA_SOCK_SIZE] = {
17550 +               "UNSPEC", "UNIX", "INET", "INET6", "PACKET", "OTHER"
17551 +       };
17552 +
17553 +       length += sprintf(buffer + length, VX_SOCKA_TOP);
17554 +       for (i = 0; i < VXA_SOCK_SIZE; i++) {
17555 +               length += sprintf(buffer + length, "%s:", type[i]);
17556 +               for (j = 0; j < 3; j++) {
17557 +                       length += sprintf(buffer + length,
17558 +                               "\t%10lu/%-10lu",
17559 +                               vx_sock_count(cacct, i, j),
17560 +                               vx_sock_total(cacct, i, j));
17561 +               }
17562 +               buffer[length++] = '\n';
17563 +       }
17564 +
17565 +       length += sprintf(buffer + length, "\n");
17566 +       length += sprintf(buffer + length,
17567 +               "slab:\t %8u %8u %8u %8u\n",
17568 +               atomic_read(&cacct->slab[1]),
17569 +               atomic_read(&cacct->slab[4]),
17570 +               atomic_read(&cacct->slab[0]),
17571 +               atomic_read(&cacct->slab[2]));
17572 +
17573 +       length += sprintf(buffer + length, "\n");
17574 +       for (i = 0; i < 5; i++) {
17575 +               length += sprintf(buffer + length,
17576 +                       "page[%d]: %8u %8u %8u %8u\t %8u %8u %8u %8u\n", i,
17577 +                       atomic_read(&cacct->page[i][0]),
17578 +                       atomic_read(&cacct->page[i][1]),
17579 +                       atomic_read(&cacct->page[i][2]),
17580 +                       atomic_read(&cacct->page[i][3]),
17581 +                       atomic_read(&cacct->page[i][4]),
17582 +                       atomic_read(&cacct->page[i][5]),
17583 +                       atomic_read(&cacct->page[i][6]),
17584 +                       atomic_read(&cacct->page[i][7]));
17585 +       }
17586 +       return length;
17587 +}
17588 +
17589 +#endif /* _VX_CACCT_PROC_H */
17590 diff -NurpP --minimal linux-2.6.32.6/kernel/vserver/context.c linux-2.6.32.6-vs2.3.0.36.28/kernel/vserver/context.c
17591 --- linux-2.6.32.6/kernel/vserver/context.c     1970-01-01 01:00:00.000000000 +0100
17592 +++ linux-2.6.32.6-vs2.3.0.36.28/kernel/vserver/context.c       2009-12-03 20:04:56.000000000 +0100
17593 @@ -0,0 +1,1057 @@
17594 +/*
17595 + *  linux/kernel/vserver/context.c
17596 + *
17597 + *  Virtual Server: Context Support
17598 + *
17599 + *  Copyright (C) 2003-2007  Herbert Pötzl
17600 + *
17601 + *  V0.01  context helper
17602 + *  V0.02  vx_ctx_kill syscall command
17603 + *  V0.03  replaced context_info calls
17604 + *  V0.04  redesign of struct (de)alloc
17605 + *  V0.05  rlimit basic implementation
17606 + *  V0.06  task_xid and info commands
17607 + *  V0.07  context flags and caps
17608 + *  V0.08  switch to RCU based hash
17609 + *  V0.09  revert to non RCU for now
17610 + *  V0.10  and back to working RCU hash
17611 + *  V0.11  and back to locking again
17612 + *  V0.12  referenced context store
17613 + *  V0.13  separate per cpu data
17614 + *  V0.14  changed vcmds to vxi arg
17615 + *  V0.15  added context stat
17616 + *  V0.16  have __create claim() the vxi
17617 + *  V0.17  removed older and legacy stuff
17618 + *
17619 + */
17620 +
17621 +#include <linux/slab.h>
17622 +#include <linux/types.h>
17623 +#include <linux/security.h>
17624 +#include <linux/pid_namespace.h>
17625 +
17626 +#include <linux/vserver/context.h>
17627 +#include <linux/vserver/network.h>
17628 +#include <linux/vserver/debug.h>
17629 +#include <linux/vserver/limit.h>
17630 +#include <linux/vserver/limit_int.h>
17631 +#include <linux/vserver/space.h>
17632 +#include <linux/init_task.h>
17633 +#include <linux/fs_struct.h>
17634 +
17635 +#include <linux/vs_context.h>
17636 +#include <linux/vs_limit.h>
17637 +#include <linux/vs_pid.h>
17638 +#include <linux/vserver/context_cmd.h>
17639 +
17640 +#include "cvirt_init.h"
17641 +#include "cacct_init.h"
17642 +#include "limit_init.h"
17643 +#include "sched_init.h"
17644 +
17645 +
17646 +atomic_t vx_global_ctotal      = ATOMIC_INIT(0);
17647 +atomic_t vx_global_cactive     = ATOMIC_INIT(0);
17648 +
17649 +
17650 +/*     now inactive context structures */
17651 +
17652 +static struct hlist_head vx_info_inactive = HLIST_HEAD_INIT;
17653 +
17654 +static spinlock_t vx_info_inactive_lock = SPIN_LOCK_UNLOCKED;
17655 +
17656 +
17657 +/*     __alloc_vx_info()
17658 +
17659 +       * allocate an initialized vx_info struct
17660 +       * doesn't make it visible (hash)                        */
17661 +
17662 +static struct vx_info *__alloc_vx_info(xid_t xid)
17663 +{
17664 +       struct vx_info *new = NULL;
17665 +       int cpu, index;
17666 +
17667 +       vxdprintk(VXD_CBIT(xid, 0), "alloc_vx_info(%d)*", xid);
17668 +
17669 +       /* would this benefit from a slab cache? */
17670 +       new = kmalloc(sizeof(struct vx_info), GFP_KERNEL);
17671 +       if (!new)
17672 +               return 0;
17673 +
17674 +       memset(new, 0, sizeof(struct vx_info));
17675 +#ifdef CONFIG_SMP
17676 +       new->ptr_pc = alloc_percpu(struct _vx_info_pc);
17677 +       if (!new->ptr_pc)
17678 +               goto error;
17679 +#endif
17680 +       new->vx_id = xid;
17681 +       INIT_HLIST_NODE(&new->vx_hlist);
17682 +       atomic_set(&new->vx_usecnt, 0);
17683 +       atomic_set(&new->vx_tasks, 0);
17684 +       new->vx_parent = NULL;
17685 +       new->vx_state = 0;
17686 +       init_waitqueue_head(&new->vx_wait);
17687 +
17688 +       /* prepare reaper */
17689 +       get_task_struct(init_pid_ns.child_reaper);
17690 +       new->vx_reaper = init_pid_ns.child_reaper;
17691 +       new->vx_badness_bias = 0;
17692 +
17693 +       /* rest of init goes here */
17694 +       vx_info_init_limit(&new->limit);
17695 +       vx_info_init_sched(&new->sched);
17696 +       vx_info_init_cvirt(&new->cvirt);
17697 +       vx_info_init_cacct(&new->cacct);
17698 +
17699 +       /* per cpu data structures */
17700 +       for_each_possible_cpu(cpu) {
17701 +               vx_info_init_sched_pc(
17702 +                       &vx_per_cpu(new, sched_pc, cpu), cpu);
17703 +               vx_info_init_cvirt_pc(
17704 +                       &vx_per_cpu(new, cvirt_pc, cpu), cpu);
17705 +       }
17706 +
17707 +       new->vx_flags = VXF_INIT_SET;
17708 +       cap_set_init_eff(new->vx_bcaps);
17709 +       new->vx_ccaps = 0;
17710 +       new->vx_umask = 0;
17711 +
17712 +       new->reboot_cmd = 0;
17713 +       new->exit_code = 0;
17714 +
17715 +       // preconfig fs entries
17716 +       for (index = 0; index < VX_SPACES; index++) {
17717 +               write_lock(&init_fs.lock);
17718 +               init_fs.users++;
17719 +               write_unlock(&init_fs.lock);
17720 +               new->vx_fs[index] = &init_fs;
17721 +       }
17722 +
17723 +       vxdprintk(VXD_CBIT(xid, 0),
17724 +               "alloc_vx_info(%d) = %p", xid, new);
17725 +       vxh_alloc_vx_info(new);
17726 +       atomic_inc(&vx_global_ctotal);
17727 +       return new;
17728 +#ifdef CONFIG_SMP
17729 +error:
17730 +       kfree(new);
17731 +       return 0;
17732 +#endif
17733 +}
17734 +
17735 +/*     __dealloc_vx_info()
17736 +
17737 +       * final disposal of vx_info                             */
17738 +
17739 +static void __dealloc_vx_info(struct vx_info *vxi)
17740 +{
17741 +       struct vx_info_save vxis;
17742 +       int cpu;
17743 +
17744 +       vxdprintk(VXD_CBIT(xid, 0),
17745 +               "dealloc_vx_info(%p)", vxi);
17746 +       vxh_dealloc_vx_info(vxi);
17747 +
17748 +#ifdef CONFIG_VSERVER_WARN
17749 +       enter_vx_info(vxi, &vxis);
17750 +       vx_info_exit_limit(&vxi->limit);
17751 +       vx_info_exit_sched(&vxi->sched);
17752 +       vx_info_exit_cvirt(&vxi->cvirt);
17753 +       vx_info_exit_cacct(&vxi->cacct);
17754 +
17755 +       for_each_possible_cpu(cpu) {
17756 +               vx_info_exit_sched_pc(
17757 +                       &vx_per_cpu(vxi, sched_pc, cpu), cpu);
17758 +               vx_info_exit_cvirt_pc(
17759 +                       &vx_per_cpu(vxi, cvirt_pc, cpu), cpu);
17760 +       }
17761 +       leave_vx_info(&vxis);
17762 +#endif
17763 +
17764 +       vxi->vx_id = -1;
17765 +       vxi->vx_state |= VXS_RELEASED;
17766 +
17767 +#ifdef CONFIG_SMP
17768 +       free_percpu(vxi->ptr_pc);
17769 +#endif
17770 +       kfree(vxi);
17771 +       atomic_dec(&vx_global_ctotal);
17772 +}
17773 +
17774 +static void __shutdown_vx_info(struct vx_info *vxi)
17775 +{
17776 +       struct nsproxy *nsproxy;
17777 +       struct fs_struct *fs;
17778 +       int index, kill;
17779 +
17780 +       might_sleep();
17781 +
17782 +       vxi->vx_state |= VXS_SHUTDOWN;
17783 +       vs_state_change(vxi, VSC_SHUTDOWN);
17784 +
17785 +       for (index = 0; index < VX_SPACES; index++) {
17786 +               nsproxy = xchg(&vxi->vx_nsproxy[index], NULL);
17787 +               if (nsproxy)
17788 +                       put_nsproxy(nsproxy);
17789 +
17790 +               fs = xchg(&vxi->vx_fs[index], NULL);
17791 +               write_lock(&fs->lock);
17792 +               kill = !--fs->users;
17793 +               write_unlock(&fs->lock);
17794 +               if (kill)
17795 +                       free_fs_struct(fs);
17796 +       }
17797 +}
17798 +
17799 +/* exported stuff */
17800 +
17801 +void free_vx_info(struct vx_info *vxi)
17802 +{
17803 +       unsigned long flags;
17804 +       unsigned index;
17805 +
17806 +       /* check for reference counts first */
17807 +       BUG_ON(atomic_read(&vxi->vx_usecnt));
17808 +       BUG_ON(atomic_read(&vxi->vx_tasks));
17809 +
17810 +       /* context must not be hashed */
17811 +       BUG_ON(vx_info_state(vxi, VXS_HASHED));
17812 +
17813 +       /* context shutdown is mandatory */
17814 +       BUG_ON(!vx_info_state(vxi, VXS_SHUTDOWN));
17815 +
17816 +       /* nsproxy and fs check */
17817 +       for (index = 0; index < VX_SPACES; index++) {
17818 +               BUG_ON(vxi->vx_nsproxy[index]);
17819 +               BUG_ON(vxi->vx_fs[index]);
17820 +       }
17821 +
17822 +       spin_lock_irqsave(&vx_info_inactive_lock, flags);
17823 +       hlist_del(&vxi->vx_hlist);
17824 +       spin_unlock_irqrestore(&vx_info_inactive_lock, flags);
17825 +
17826 +       __dealloc_vx_info(vxi);
17827 +}
17828 +
17829 +
17830 +/*     hash table for vx_info hash */
17831 +
17832 +#define VX_HASH_SIZE   13
17833 +
17834 +static struct hlist_head vx_info_hash[VX_HASH_SIZE] =
17835 +       { [0 ... VX_HASH_SIZE-1] = HLIST_HEAD_INIT };
17836 +
17837 +static spinlock_t vx_info_hash_lock = SPIN_LOCK_UNLOCKED;
17838 +
17839 +
17840 +static inline unsigned int __hashval(xid_t xid)
17841 +{
17842 +       return (xid % VX_HASH_SIZE);
17843 +}
17844 +
17845 +
17846 +
17847 +/*     __hash_vx_info()
17848 +
17849 +       * add the vxi to the global hash table
17850 +       * requires the hash_lock to be held                     */
17851 +
17852 +static inline void __hash_vx_info(struct vx_info *vxi)
17853 +{
17854 +       struct hlist_head *head;
17855 +
17856 +       vxd_assert_lock(&vx_info_hash_lock);
17857 +       vxdprintk(VXD_CBIT(xid, 4),
17858 +               "__hash_vx_info: %p[#%d]", vxi, vxi->vx_id);
17859 +       vxh_hash_vx_info(vxi);
17860 +
17861 +       /* context must not be hashed */
17862 +       BUG_ON(vx_info_state(vxi, VXS_HASHED));
17863 +
17864 +       vxi->vx_state |= VXS_HASHED;
17865 +       head = &vx_info_hash[__hashval(vxi->vx_id)];
17866 +       hlist_add_head(&vxi->vx_hlist, head);
17867 +       atomic_inc(&vx_global_cactive);
17868 +}
17869 +
17870 +/*     __unhash_vx_info()
17871 +
17872 +       * remove the vxi from the global hash table
17873 +       * requires the hash_lock to be held                     */
17874 +
17875 +static inline void __unhash_vx_info(struct vx_info *vxi)
17876 +{
17877 +       unsigned long flags;
17878 +
17879 +       vxd_assert_lock(&vx_info_hash_lock);
17880 +       vxdprintk(VXD_CBIT(xid, 4),
17881 +               "__unhash_vx_info: %p[#%d.%d.%d]", vxi, vxi->vx_id,
17882 +               atomic_read(&vxi->vx_usecnt), atomic_read(&vxi->vx_tasks));
17883 +       vxh_unhash_vx_info(vxi);
17884 +
17885 +       /* context must be hashed */
17886 +       BUG_ON(!vx_info_state(vxi, VXS_HASHED));
17887 +       /* but without tasks */
17888 +       BUG_ON(atomic_read(&vxi->vx_tasks));
17889 +
17890 +       vxi->vx_state &= ~VXS_HASHED;
17891 +       hlist_del_init(&vxi->vx_hlist);
17892 +       spin_lock_irqsave(&vx_info_inactive_lock, flags);
17893 +       hlist_add_head(&vxi->vx_hlist, &vx_info_inactive);
17894 +       spin_unlock_irqrestore(&vx_info_inactive_lock, flags);
17895 +       atomic_dec(&vx_global_cactive);
17896 +}
17897 +
17898 +
17899 +/*     __lookup_vx_info()
17900 +
17901 +       * requires the hash_lock to be held
17902 +       * doesn't increment the vx_refcnt                       */
17903 +
17904 +static inline struct vx_info *__lookup_vx_info(xid_t xid)
17905 +{
17906 +       struct hlist_head *head = &vx_info_hash[__hashval(xid)];
17907 +       struct hlist_node *pos;
17908 +       struct vx_info *vxi;
17909 +
17910 +       vxd_assert_lock(&vx_info_hash_lock);
17911 +       hlist_for_each(pos, head) {
17912 +               vxi = hlist_entry(pos, struct vx_info, vx_hlist);
17913 +
17914 +               if (vxi->vx_id == xid)
17915 +                       goto found;
17916 +       }
17917 +       vxi = NULL;
17918 +found:
17919 +       vxdprintk(VXD_CBIT(xid, 0),
17920 +               "__lookup_vx_info(#%u): %p[#%u]",
17921 +               xid, vxi, vxi ? vxi->vx_id : 0);
17922 +       vxh_lookup_vx_info(vxi, xid);
17923 +       return vxi;
17924 +}
17925 +
17926 +
17927 +/*     __create_vx_info()
17928 +
17929 +       * create the requested context
17930 +       * get(), claim() and hash it                            */
17931 +
17932 +static struct vx_info *__create_vx_info(int id)
17933 +{
17934 +       struct vx_info *new, *vxi = NULL;
17935 +
17936 +       vxdprintk(VXD_CBIT(xid, 1), "create_vx_info(%d)*", id);
17937 +
17938 +       if (!(new = __alloc_vx_info(id)))
17939 +               return ERR_PTR(-ENOMEM);
17940 +
17941 +       /* required to make dynamic xids unique */
17942 +       spin_lock(&vx_info_hash_lock);
17943 +
17944 +       /* static context requested */
17945 +       if ((vxi = __lookup_vx_info(id))) {
17946 +               vxdprintk(VXD_CBIT(xid, 0),
17947 +                       "create_vx_info(%d) = %p (already there)", id, vxi);
17948 +               if (vx_info_flags(vxi, VXF_STATE_SETUP, 0))
17949 +                       vxi = ERR_PTR(-EBUSY);
17950 +               else
17951 +                       vxi = ERR_PTR(-EEXIST);
17952 +               goto out_unlock;
17953 +       }
17954 +       /* new context */
17955 +       vxdprintk(VXD_CBIT(xid, 0),
17956 +               "create_vx_info(%d) = %p (new)", id, new);
17957 +       claim_vx_info(new, NULL);
17958 +       __hash_vx_info(get_vx_info(new));
17959 +       vxi = new, new = NULL;
17960 +
17961 +out_unlock:
17962 +       spin_unlock(&vx_info_hash_lock);
17963 +       vxh_create_vx_info(IS_ERR(vxi) ? NULL : vxi, id);
17964 +       if (new)
17965 +               __dealloc_vx_info(new);
17966 +       return vxi;
17967 +}
17968 +
17969 +
17970 +/*     exported stuff                                          */
17971 +
17972 +
17973 +void unhash_vx_info(struct vx_info *vxi)
17974 +{
17975 +       __shutdown_vx_info(vxi);
17976 +       spin_lock(&vx_info_hash_lock);
17977 +       __unhash_vx_info(vxi);
17978 +       spin_unlock(&vx_info_hash_lock);
17979 +       __wakeup_vx_info(vxi);
17980 +}
17981 +
17982 +
17983 +/*     lookup_vx_info()
17984 +
17985 +       * search for a vx_info and get() it
17986 +       * negative id means current                             */
17987 +
17988 +struct vx_info *lookup_vx_info(int id)
17989 +{
17990 +       struct vx_info *vxi = NULL;
17991 +
17992 +       if (id < 0) {
17993 +               vxi = get_vx_info(current_vx_info());
17994 +       } else if (id > 1) {
17995 +               spin_lock(&vx_info_hash_lock);
17996 +               vxi = get_vx_info(__lookup_vx_info(id));
17997 +               spin_unlock(&vx_info_hash_lock);
17998 +       }
17999 +       return vxi;
18000 +}
18001 +
18002 +/*     xid_is_hashed()
18003 +
18004 +       * verify that xid is still hashed                       */
18005 +
18006 +int xid_is_hashed(xid_t xid)
18007 +{
18008 +       int hashed;
18009 +
18010 +       spin_lock(&vx_info_hash_lock);
18011 +       hashed = (__lookup_vx_info(xid) != NULL);
18012 +       spin_unlock(&vx_info_hash_lock);
18013 +       return hashed;
18014 +}
18015 +
18016 +#ifdef CONFIG_PROC_FS
18017 +
18018 +/*     get_xid_list()
18019 +
18020 +       * get a subset of hashed xids for proc
18021 +       * assumes size is at least one                          */
18022 +
18023 +int get_xid_list(int index, unsigned int *xids, int size)
18024 +{
18025 +       int hindex, nr_xids = 0;
18026 +
18027 +       /* only show current and children */
18028 +       if (!vx_check(0, VS_ADMIN | VS_WATCH)) {
18029 +               if (index > 0)
18030 +                       return 0;
18031 +               xids[nr_xids] = vx_current_xid();
18032 +               return 1;
18033 +       }
18034 +
18035 +       for (hindex = 0; hindex < VX_HASH_SIZE; hindex++) {
18036 +               struct hlist_head *head = &vx_info_hash[hindex];
18037 +               struct hlist_node *pos;
18038 +
18039 +               spin_lock(&vx_info_hash_lock);
18040 +               hlist_for_each(pos, head) {
18041 +                       struct vx_info *vxi;
18042 +
18043 +                       if (--index > 0)
18044 +                               continue;
18045 +
18046 +                       vxi = hlist_entry(pos, struct vx_info, vx_hlist);
18047 +                       xids[nr_xids] = vxi->vx_id;
18048 +                       if (++nr_xids >= size) {
18049 +                               spin_unlock(&vx_info_hash_lock);
18050 +                               goto out;
18051 +                       }
18052 +               }
18053 +               /* keep the lock time short */
18054 +               spin_unlock(&vx_info_hash_lock);
18055 +       }
18056 +out:
18057 +       return nr_xids;
18058 +}
18059 +#endif
18060 +
18061 +#ifdef CONFIG_VSERVER_DEBUG
18062 +
18063 +void   dump_vx_info_inactive(int level)
18064 +{
18065 +       struct hlist_node *entry, *next;
18066 +
18067 +       hlist_for_each_safe(entry, next, &vx_info_inactive) {
18068 +               struct vx_info *vxi =
18069 +                       list_entry(entry, struct vx_info, vx_hlist);
18070 +
18071 +               dump_vx_info(vxi, level);
18072 +       }
18073 +}
18074 +
18075 +#endif
18076 +
18077 +#if 0
18078 +int vx_migrate_user(struct task_struct *p, struct vx_info *vxi)
18079 +{
18080 +       struct user_struct *new_user, *old_user;
18081 +
18082 +       if (!p || !vxi)
18083 +               BUG();
18084 +
18085 +       if (vx_info_flags(vxi, VXF_INFO_PRIVATE, 0))
18086 +               return -EACCES;
18087 +
18088 +       new_user = alloc_uid(vxi->vx_id, p->uid);
18089 +       if (!new_user)
18090 +               return -ENOMEM;
18091 +
18092 +       old_user = p->user;
18093 +       if (new_user != old_user) {
18094 +               atomic_inc(&new_user->processes);
18095 +               atomic_dec(&old_user->processes);
18096 +               p->user = new_user;
18097 +       }
18098 +       free_uid(old_user);
18099 +       return 0;
18100 +}
18101 +#endif
18102 +
18103 +#if 0
18104 +void vx_mask_cap_bset(struct vx_info *vxi, struct task_struct *p)
18105 +{
18106 +       // p->cap_effective &= vxi->vx_cap_bset;
18107 +       p->cap_effective =
18108 +               cap_intersect(p->cap_effective, vxi->cap_bset);
18109 +       // p->cap_inheritable &= vxi->vx_cap_bset;
18110 +       p->cap_inheritable =
18111 +               cap_intersect(p->cap_inheritable, vxi->cap_bset);
18112 +       // p->cap_permitted &= vxi->vx_cap_bset;
18113 +       p->cap_permitted =
18114 +               cap_intersect(p->cap_permitted, vxi->cap_bset);
18115 +}
18116 +#endif
18117 +
18118 +
18119 +#include <linux/file.h>
18120 +#include <linux/fdtable.h>
18121 +
18122 +static int vx_openfd_task(struct task_struct *tsk)
18123 +{
18124 +       struct files_struct *files = tsk->files;
18125 +       struct fdtable *fdt;
18126 +       const unsigned long *bptr;
18127 +       int count, total;
18128 +
18129 +       /* no rcu_read_lock() because of spin_lock() */
18130 +       spin_lock(&files->file_lock);
18131 +       fdt = files_fdtable(files);
18132 +       bptr = fdt->open_fds->fds_bits;
18133 +       count = fdt->max_fds / (sizeof(unsigned long) * 8);
18134 +       for (total = 0; count > 0; count--) {
18135 +               if (*bptr)
18136 +                       total += hweight_long(*bptr);
18137 +               bptr++;
18138 +       }
18139 +       spin_unlock(&files->file_lock);
18140 +       return total;
18141 +}
18142 +
18143 +
18144 +/*     for *space compatibility */
18145 +
18146 +asmlinkage long sys_unshare(unsigned long);
18147 +
18148 +/*
18149 + *     migrate task to new context
18150 + *     gets vxi, puts old_vxi on change
18151 + *     optionally unshares namespaces (hack)
18152 + */
18153 +
18154 +int vx_migrate_task(struct task_struct *p, struct vx_info *vxi, int unshare)
18155 +{
18156 +       struct vx_info *old_vxi;
18157 +       int ret = 0;
18158 +
18159 +       if (!p || !vxi)
18160 +               BUG();
18161 +
18162 +       vxdprintk(VXD_CBIT(xid, 5),
18163 +               "vx_migrate_task(%p,%p[#%d.%d])", p, vxi,
18164 +               vxi->vx_id, atomic_read(&vxi->vx_usecnt));
18165 +
18166 +       if (vx_info_flags(vxi, VXF_INFO_PRIVATE, 0) &&
18167 +               !vx_info_flags(vxi, VXF_STATE_SETUP, 0))
18168 +               return -EACCES;
18169 +
18170 +       if (vx_info_state(vxi, VXS_SHUTDOWN))
18171 +               return -EFAULT;
18172 +
18173 +       old_vxi = task_get_vx_info(p);
18174 +       if (old_vxi == vxi)
18175 +               goto out;
18176 +
18177 +//     if (!(ret = vx_migrate_user(p, vxi))) {
18178 +       {
18179 +               int openfd;
18180 +
18181 +               task_lock(p);
18182 +               openfd = vx_openfd_task(p);
18183 +
18184 +               if (old_vxi) {
18185 +                       atomic_dec(&old_vxi->cvirt.nr_threads);
18186 +                       atomic_dec(&old_vxi->cvirt.nr_running);
18187 +                       __rlim_dec(&old_vxi->limit, RLIMIT_NPROC);
18188 +                       /* FIXME: what about the struct files here? */
18189 +                       __rlim_sub(&old_vxi->limit, VLIMIT_OPENFD, openfd);
18190 +                       /* account for the executable */
18191 +                       __rlim_dec(&old_vxi->limit, VLIMIT_DENTRY);
18192 +               }
18193 +               atomic_inc(&vxi->cvirt.nr_threads);
18194 +               atomic_inc(&vxi->cvirt.nr_running);
18195 +               __rlim_inc(&vxi->limit, RLIMIT_NPROC);
18196 +               /* FIXME: what about the struct files here? */
18197 +               __rlim_add(&vxi->limit, VLIMIT_OPENFD, openfd);
18198 +               /* account for the executable */
18199 +               __rlim_inc(&vxi->limit, VLIMIT_DENTRY);
18200 +
18201 +               if (old_vxi) {
18202 +                       release_vx_info(old_vxi, p);
18203 +                       clr_vx_info(&p->vx_info);
18204 +               }
18205 +               claim_vx_info(vxi, p);
18206 +               set_vx_info(&p->vx_info, vxi);
18207 +               p->xid = vxi->vx_id;
18208 +
18209 +               vxdprintk(VXD_CBIT(xid, 5),
18210 +                       "moved task %p into vxi:%p[#%d]",
18211 +                       p, vxi, vxi->vx_id);
18212 +
18213 +               // vx_mask_cap_bset(vxi, p);
18214 +               task_unlock(p);
18215 +
18216 +               /* hack for *spaces to provide compatibility */
18217 +               if (unshare) {
18218 +                       struct nsproxy *old_nsp, *new_nsp;
18219 +
18220 +                       ret = unshare_nsproxy_namespaces(
18221 +                               CLONE_NEWUTS | CLONE_NEWIPC | CLONE_NEWUSER,
18222 +                               &new_nsp, NULL);
18223 +                       if (ret)
18224 +                               goto out;
18225 +
18226 +                       old_nsp = xchg(&p->nsproxy, new_nsp);
18227 +                       vx_set_space(vxi,
18228 +                               CLONE_NEWUTS | CLONE_NEWIPC | CLONE_NEWUSER, 0);
18229 +                       put_nsproxy(old_nsp);
18230 +               }
18231 +       }
18232 +out:
18233 +       put_vx_info(old_vxi);
18234 +       return ret;
18235 +}
18236 +
18237 +int vx_set_reaper(struct vx_info *vxi, struct task_struct *p)
18238 +{
18239 +       struct task_struct *old_reaper;
18240 +
18241 +       if (!vxi)
18242 +               return -EINVAL;
18243 +
18244 +       vxdprintk(VXD_CBIT(xid, 6),
18245 +               "vx_set_reaper(%p[#%d],%p[#%d,%d])",
18246 +               vxi, vxi->vx_id, p, p->xid, p->pid);
18247 +
18248 +       old_reaper = vxi->vx_reaper;
18249 +       if (old_reaper == p)
18250 +               return 0;
18251 +
18252 +       /* set new child reaper */
18253 +       get_task_struct(p);
18254 +       vxi->vx_reaper = p;
18255 +       put_task_struct(old_reaper);
18256 +       return 0;
18257 +}
18258 +
18259 +int vx_set_init(struct vx_info *vxi, struct task_struct *p)
18260 +{
18261 +       if (!vxi)
18262 +               return -EINVAL;
18263 +
18264 +       vxdprintk(VXD_CBIT(xid, 6),
18265 +               "vx_set_init(%p[#%d],%p[#%d,%d,%d])",
18266 +               vxi, vxi->vx_id, p, p->xid, p->pid, p->tgid);
18267 +
18268 +       vxi->vx_flags &= ~VXF_STATE_INIT;
18269 +       // vxi->vx_initpid = p->tgid;
18270 +       vxi->vx_initpid = p->pid;
18271 +       return 0;
18272 +}
18273 +
18274 +void vx_exit_init(struct vx_info *vxi, struct task_struct *p, int code)
18275 +{
18276 +       vxdprintk(VXD_CBIT(xid, 6),
18277 +               "vx_exit_init(%p[#%d],%p[#%d,%d,%d])",
18278 +               vxi, vxi->vx_id, p, p->xid, p->pid, p->tgid);
18279 +
18280 +       vxi->exit_code = code;
18281 +       vxi->vx_initpid = 0;
18282 +}
18283 +
18284 +
18285 +void vx_set_persistent(struct vx_info *vxi)
18286 +{
18287 +       vxdprintk(VXD_CBIT(xid, 6),
18288 +               "vx_set_persistent(%p[#%d])", vxi, vxi->vx_id);
18289 +
18290 +       get_vx_info(vxi);
18291 +       claim_vx_info(vxi, NULL);
18292 +}
18293 +
18294 +void vx_clear_persistent(struct vx_info *vxi)
18295 +{
18296 +       vxdprintk(VXD_CBIT(xid, 6),
18297 +               "vx_clear_persistent(%p[#%d])", vxi, vxi->vx_id);
18298 +
18299 +       release_vx_info(vxi, NULL);
18300 +       put_vx_info(vxi);
18301 +}
18302 +
18303 +void vx_update_persistent(struct vx_info *vxi)
18304 +{
18305 +       if (vx_info_flags(vxi, VXF_PERSISTENT, 0))
18306 +               vx_set_persistent(vxi);
18307 +       else
18308 +               vx_clear_persistent(vxi);
18309 +}
18310 +
18311 +
18312 +/*     task must be current or locked          */
18313 +
18314 +void   exit_vx_info(struct task_struct *p, int code)
18315 +{
18316 +       struct vx_info *vxi = p->vx_info;
18317 +
18318 +       if (vxi) {
18319 +               atomic_dec(&vxi->cvirt.nr_threads);
18320 +               vx_nproc_dec(p);
18321 +
18322 +               vxi->exit_code = code;
18323 +               release_vx_info(vxi, p);
18324 +       }
18325 +}
18326 +
18327 +void   exit_vx_info_early(struct task_struct *p, int code)
18328 +{
18329 +       struct vx_info *vxi = p->vx_info;
18330 +
18331 +       if (vxi) {
18332 +               if (vxi->vx_initpid == p->pid)
18333 +                       vx_exit_init(vxi, p, code);
18334 +               if (vxi->vx_reaper == p)
18335 +                       vx_set_reaper(vxi, init_pid_ns.child_reaper);
18336 +       }
18337 +}
18338 +
18339 +
18340 +/* vserver syscall commands below here */
18341 +
18342 +/* taks xid and vx_info functions */
18343 +
18344 +#include <asm/uaccess.h>
18345 +
18346 +
18347 +int vc_task_xid(uint32_t id)
18348 +{
18349 +       xid_t xid;
18350 +
18351 +       if (id) {
18352 +               struct task_struct *tsk;
18353 +
18354 +               read_lock(&tasklist_lock);
18355 +               tsk = find_task_by_real_pid(id);
18356 +               xid = (tsk) ? tsk->xid : -ESRCH;
18357 +               read_unlock(&tasklist_lock);
18358 +       } else
18359 +               xid = vx_current_xid();
18360 +       return xid;
18361 +}
18362 +
18363 +
18364 +int vc_vx_info(struct vx_info *vxi, void __user *data)
18365 +{
18366 +       struct vcmd_vx_info_v0 vc_data;
18367 +
18368 +       vc_data.xid = vxi->vx_id;
18369 +       vc_data.initpid = vxi->vx_initpid;
18370 +
18371 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
18372 +               return -EFAULT;
18373 +       return 0;
18374 +}
18375 +
18376 +
18377 +int vc_ctx_stat(struct vx_info *vxi, void __user *data)
18378 +{
18379 +       struct vcmd_ctx_stat_v0 vc_data;
18380 +
18381 +       vc_data.usecnt = atomic_read(&vxi->vx_usecnt);
18382 +       vc_data.tasks = atomic_read(&vxi->vx_tasks);
18383 +
18384 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
18385 +               return -EFAULT;
18386 +       return 0;
18387 +}
18388 +
18389 +
18390 +/* context functions */
18391 +
18392 +int vc_ctx_create(uint32_t xid, void __user *data)
18393 +{
18394 +       struct vcmd_ctx_create vc_data = { .flagword = VXF_INIT_SET };
18395 +       struct vx_info *new_vxi;
18396 +       int ret;
18397 +
18398 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
18399 +               return -EFAULT;
18400 +
18401 +       if ((xid > MAX_S_CONTEXT) || (xid < 2))
18402 +               return -EINVAL;
18403 +
18404 +       new_vxi = __create_vx_info(xid);
18405 +       if (IS_ERR(new_vxi))
18406 +               return PTR_ERR(new_vxi);
18407 +
18408 +       /* initial flags */
18409 +       new_vxi->vx_flags = vc_data.flagword;
18410 +
18411 +       ret = -ENOEXEC;
18412 +       if (vs_state_change(new_vxi, VSC_STARTUP))
18413 +               goto out;
18414 +
18415 +       ret = vx_migrate_task(current, new_vxi, (!data));
18416 +       if (ret)
18417 +               goto out;
18418 +
18419 +       /* return context id on success */
18420 +       ret = new_vxi->vx_id;
18421 +
18422 +       /* get a reference for persistent contexts */
18423 +       if ((vc_data.flagword & VXF_PERSISTENT))
18424 +               vx_set_persistent(new_vxi);
18425 +out:
18426 +       release_vx_info(new_vxi, NULL);
18427 +       put_vx_info(new_vxi);
18428 +       return ret;
18429 +}
18430 +
18431 +
18432 +int vc_ctx_migrate(struct vx_info *vxi, void __user *data)
18433 +{
18434 +       struct vcmd_ctx_migrate vc_data = { .flagword = 0 };
18435 +       int ret;
18436 +
18437 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
18438 +               return -EFAULT;
18439 +
18440 +       ret = vx_migrate_task(current, vxi, 0);
18441 +       if (ret)
18442 +               return ret;
18443 +       if (vc_data.flagword & VXM_SET_INIT)
18444 +               ret = vx_set_init(vxi, current);
18445 +       if (ret)
18446 +               return ret;
18447 +       if (vc_data.flagword & VXM_SET_REAPER)
18448 +               ret = vx_set_reaper(vxi, current);
18449 +       return ret;
18450 +}
18451 +
18452 +
18453 +int vc_get_cflags(struct vx_info *vxi, void __user *data)
18454 +{
18455 +       struct vcmd_ctx_flags_v0 vc_data;
18456 +
18457 +       vc_data.flagword = vxi->vx_flags;
18458 +
18459 +       /* special STATE flag handling */
18460 +       vc_data.mask = vs_mask_flags(~0ULL, vxi->vx_flags, VXF_ONE_TIME);
18461 +
18462 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
18463 +               return -EFAULT;
18464 +       return 0;
18465 +}
18466 +
18467 +int vc_set_cflags(struct vx_info *vxi, void __user *data)
18468 +{
18469 +       struct vcmd_ctx_flags_v0 vc_data;
18470 +       uint64_t mask, trigger;
18471 +
18472 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18473 +               return -EFAULT;
18474 +
18475 +       /* special STATE flag handling */
18476 +       mask = vs_mask_mask(vc_data.mask, vxi->vx_flags, VXF_ONE_TIME);
18477 +       trigger = (mask & vxi->vx_flags) ^ (mask & vc_data.flagword);
18478 +
18479 +       if (vxi == current_vx_info()) {
18480 +               /* if (trigger & VXF_STATE_SETUP)
18481 +                       vx_mask_cap_bset(vxi, current); */
18482 +               if (trigger & VXF_STATE_INIT) {
18483 +                       int ret;
18484 +
18485 +                       ret = vx_set_init(vxi, current);
18486 +                       if (ret)
18487 +                               return ret;
18488 +                       ret = vx_set_reaper(vxi, current);
18489 +                       if (ret)
18490 +                               return ret;
18491 +               }
18492 +       }
18493 +
18494 +       vxi->vx_flags = vs_mask_flags(vxi->vx_flags,
18495 +               vc_data.flagword, mask);
18496 +       if (trigger & VXF_PERSISTENT)
18497 +               vx_update_persistent(vxi);
18498 +
18499 +       return 0;
18500 +}
18501 +
18502 +
18503 +static inline uint64_t caps_from_cap_t(kernel_cap_t c)
18504 +{
18505 +       uint64_t v = c.cap[0] | ((uint64_t)c.cap[1] << 32);
18506 +
18507 +       // printk("caps_from_cap_t(%08x:%08x) = %016llx\n", c.cap[1], c.cap[0], v);
18508 +       return v;
18509 +}
18510 +
18511 +static inline kernel_cap_t cap_t_from_caps(uint64_t v)
18512 +{
18513 +       kernel_cap_t c = __cap_empty_set;
18514 +
18515 +       c.cap[0] = v & 0xFFFFFFFF;
18516 +       c.cap[1] = (v >> 32) & 0xFFFFFFFF;
18517 +
18518 +       // printk("cap_t_from_caps(%016llx) = %08x:%08x\n", v, c.cap[1], c.cap[0]);
18519 +       return c;
18520 +}
18521 +
18522 +
18523 +static int do_get_caps(struct vx_info *vxi, uint64_t *bcaps, uint64_t *ccaps)
18524 +{
18525 +       if (bcaps)
18526 +               *bcaps = caps_from_cap_t(vxi->vx_bcaps);
18527 +       if (ccaps)
18528 +               *ccaps = vxi->vx_ccaps;
18529 +
18530 +       return 0;
18531 +}
18532 +
18533 +int vc_get_ccaps(struct vx_info *vxi, void __user *data)
18534 +{
18535 +       struct vcmd_ctx_caps_v1 vc_data;
18536 +       int ret;
18537 +
18538 +       ret = do_get_caps(vxi, NULL, &vc_data.ccaps);
18539 +       if (ret)
18540 +               return ret;
18541 +       vc_data.cmask = ~0ULL;
18542 +
18543 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
18544 +               return -EFAULT;
18545 +       return 0;
18546 +}
18547 +
18548 +static int do_set_caps(struct vx_info *vxi,
18549 +       uint64_t bcaps, uint64_t bmask, uint64_t ccaps, uint64_t cmask)
18550 +{
18551 +       uint64_t bcold = caps_from_cap_t(vxi->vx_bcaps);
18552 +
18553 +#if 0
18554 +       printk("do_set_caps(%16llx, %16llx, %16llx, %16llx)\n",
18555 +               bcaps, bmask, ccaps, cmask);
18556 +#endif
18557 +       vxi->vx_bcaps = cap_t_from_caps(
18558 +               vs_mask_flags(bcold, bcaps, bmask));
18559 +       vxi->vx_ccaps = vs_mask_flags(vxi->vx_ccaps, ccaps, cmask);
18560 +
18561 +       return 0;
18562 +}
18563 +
18564 +int vc_set_ccaps(struct vx_info *vxi, void __user *data)
18565 +{
18566 +       struct vcmd_ctx_caps_v1 vc_data;
18567 +
18568 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18569 +               return -EFAULT;
18570 +
18571 +       return do_set_caps(vxi, 0, 0, vc_data.ccaps, vc_data.cmask);
18572 +}
18573 +
18574 +int vc_get_bcaps(struct vx_info *vxi, void __user *data)
18575 +{
18576 +       struct vcmd_bcaps vc_data;
18577 +       int ret;
18578 +
18579 +       ret = do_get_caps(vxi, &vc_data.bcaps, NULL);
18580 +       if (ret)
18581 +               return ret;
18582 +       vc_data.bmask = ~0ULL;
18583 +
18584 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
18585 +               return -EFAULT;
18586 +       return 0;
18587 +}
18588 +
18589 +int vc_set_bcaps(struct vx_info *vxi, void __user *data)
18590 +{
18591 +       struct vcmd_bcaps vc_data;
18592 +
18593 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18594 +               return -EFAULT;
18595 +
18596 +       return do_set_caps(vxi, vc_data.bcaps, vc_data.bmask, 0, 0);
18597 +}
18598 +
18599 +
18600 +int vc_get_umask(struct vx_info *vxi, void __user *data)
18601 +{
18602 +       struct vcmd_umask vc_data;
18603 +
18604 +       vc_data.umask = vxi->vx_umask;
18605 +       vc_data.mask = ~0ULL;
18606 +
18607 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
18608 +               return -EFAULT;
18609 +       return 0;
18610 +}
18611 +
18612 +int vc_set_umask(struct vx_info *vxi, void __user *data)
18613 +{
18614 +       struct vcmd_umask vc_data;
18615 +
18616 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18617 +               return -EFAULT;
18618 +
18619 +       vxi->vx_umask = vs_mask_flags(vxi->vx_umask,
18620 +               vc_data.umask, vc_data.mask);
18621 +       return 0;
18622 +}
18623 +
18624 +
18625 +int vc_get_badness(struct vx_info *vxi, void __user *data)
18626 +{
18627 +       struct vcmd_badness_v0 vc_data;
18628 +
18629 +       vc_data.bias = vxi->vx_badness_bias;
18630 +
18631 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
18632 +               return -EFAULT;
18633 +       return 0;
18634 +}
18635 +
18636 +int vc_set_badness(struct vx_info *vxi, void __user *data)
18637 +{
18638 +       struct vcmd_badness_v0 vc_data;
18639 +
18640 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18641 +               return -EFAULT;
18642 +
18643 +       vxi->vx_badness_bias = vc_data.bias;
18644 +       return 0;
18645 +}
18646 +
18647 +#include <linux/module.h>
18648 +
18649 +EXPORT_SYMBOL_GPL(free_vx_info);
18650 +
18651 diff -NurpP --minimal linux-2.6.32.6/kernel/vserver/cvirt.c linux-2.6.32.6-vs2.3.0.36.28/kernel/vserver/cvirt.c
18652 --- linux-2.6.32.6/kernel/vserver/cvirt.c       1970-01-01 01:00:00.000000000 +0100
18653 +++ linux-2.6.32.6-vs2.3.0.36.28/kernel/vserver/cvirt.c 2009-12-03 20:04:56.000000000 +0100
18654 @@ -0,0 +1,304 @@
18655 +/*
18656 + *  linux/kernel/vserver/cvirt.c
18657 + *
18658 + *  Virtual Server: Context Virtualization
18659 + *
18660 + *  Copyright (C) 2004-2007  Herbert Pötzl
18661 + *
18662 + *  V0.01  broken out from limit.c
18663 + *  V0.02  added utsname stuff
18664 + *  V0.03  changed vcmds to vxi arg
18665 + *
18666 + */
18667 +
18668 +#include <linux/types.h>
18669 +#include <linux/utsname.h>
18670 +#include <linux/vs_cvirt.h>
18671 +#include <linux/vserver/switch.h>
18672 +#include <linux/vserver/cvirt_cmd.h>
18673 +
18674 +#include <asm/uaccess.h>
18675 +
18676 +
18677 +void vx_vsi_uptime(struct timespec *uptime, struct timespec *idle)
18678 +{
18679 +       struct vx_info *vxi = current_vx_info();
18680 +
18681 +       set_normalized_timespec(uptime,
18682 +               uptime->tv_sec - vxi->cvirt.bias_uptime.tv_sec,
18683 +               uptime->tv_nsec - vxi->cvirt.bias_uptime.tv_nsec);
18684 +       if (!idle)
18685 +               return;
18686 +       set_normalized_timespec(idle,
18687 +               idle->tv_sec - vxi->cvirt.bias_idle.tv_sec,
18688 +               idle->tv_nsec - vxi->cvirt.bias_idle.tv_nsec);
18689 +       return;
18690 +}
18691 +
18692 +uint64_t vx_idle_jiffies(void)
18693 +{
18694 +       return init_task.utime + init_task.stime;
18695 +}
18696 +
18697 +
18698 +
18699 +static inline uint32_t __update_loadavg(uint32_t load,
18700 +       int wsize, int delta, int n)
18701 +{
18702 +       unsigned long long calc, prev;
18703 +
18704 +       /* just set it to n */
18705 +       if (unlikely(delta >= wsize))
18706 +               return (n << FSHIFT);
18707 +
18708 +       calc = delta * n;
18709 +       calc <<= FSHIFT;
18710 +       prev = (wsize - delta);
18711 +       prev *= load;
18712 +       calc += prev;
18713 +       do_div(calc, wsize);
18714 +       return calc;
18715 +}
18716 +
18717 +
18718 +void vx_update_load(struct vx_info *vxi)
18719 +{
18720 +       uint32_t now, last, delta;
18721 +       unsigned int nr_running, nr_uninterruptible;
18722 +       unsigned int total;
18723 +       unsigned long flags;
18724 +
18725 +       spin_lock_irqsave(&vxi->cvirt.load_lock, flags);
18726 +
18727 +       now = jiffies;
18728 +       last = vxi->cvirt.load_last;
18729 +       delta = now - last;
18730 +
18731 +       if (delta < 5*HZ)
18732 +               goto out;
18733 +
18734 +       nr_running = atomic_read(&vxi->cvirt.nr_running);
18735 +       nr_uninterruptible = atomic_read(&vxi->cvirt.nr_uninterruptible);
18736 +       total = nr_running + nr_uninterruptible;
18737 +
18738 +       vxi->cvirt.load[0] = __update_loadavg(vxi->cvirt.load[0],
18739 +               60*HZ, delta, total);
18740 +       vxi->cvirt.load[1] = __update_loadavg(vxi->cvirt.load[1],
18741 +               5*60*HZ, delta, total);
18742 +       vxi->cvirt.load[2] = __update_loadavg(vxi->cvirt.load[2],
18743 +               15*60*HZ, delta, total);
18744 +
18745 +       vxi->cvirt.load_last = now;
18746 +out:
18747 +       atomic_inc(&vxi->cvirt.load_updates);
18748 +       spin_unlock_irqrestore(&vxi->cvirt.load_lock, flags);
18749 +}
18750 +
18751 +
18752 +/*
18753 + * Commands to do_syslog:
18754 + *
18755 + *      0 -- Close the log.  Currently a NOP.
18756 + *      1 -- Open the log. Currently a NOP.
18757 + *      2 -- Read from the log.
18758 + *      3 -- Read all messages remaining in the ring buffer.
18759 + *      4 -- Read and clear all messages remaining in the ring buffer
18760 + *      5 -- Clear ring buffer.
18761 + *      6 -- Disable printk's to console
18762 + *      7 -- Enable printk's to console
18763 + *      8 -- Set level of messages printed to console
18764 + *      9 -- Return number of unread characters in the log buffer
18765 + *     10 -- Return size of the log buffer
18766 + */
18767 +int vx_do_syslog(int type, char __user *buf, int len)
18768 +{
18769 +       int error = 0;
18770 +       int do_clear = 0;
18771 +       struct vx_info *vxi = current_vx_info();
18772 +       struct _vx_syslog *log;
18773 +
18774 +       if (!vxi)
18775 +               return -EINVAL;
18776 +       log = &vxi->cvirt.syslog;
18777 +
18778 +       switch (type) {
18779 +       case 0:         /* Close log */
18780 +       case 1:         /* Open log */
18781 +               break;
18782 +       case 2:         /* Read from log */
18783 +               error = wait_event_interruptible(log->log_wait,
18784 +                       (log->log_start - log->log_end));
18785 +               if (error)
18786 +                       break;
18787 +               spin_lock_irq(&log->logbuf_lock);
18788 +               spin_unlock_irq(&log->logbuf_lock);
18789 +               break;
18790 +       case 4:         /* Read/clear last kernel messages */
18791 +               do_clear = 1;
18792 +               /* fall through */
18793 +       case 3:         /* Read last kernel messages */
18794 +               return 0;
18795 +
18796 +       case 5:         /* Clear ring buffer */
18797 +               return 0;
18798 +
18799 +       case 6:         /* Disable logging to console */
18800 +       case 7:         /* Enable logging to console */
18801 +       case 8:         /* Set level of messages printed to console */
18802 +               break;
18803 +
18804 +       case 9:         /* Number of chars in the log buffer */
18805 +               return 0;
18806 +       case 10:        /* Size of the log buffer */
18807 +               return 0;
18808 +       default:
18809 +               error = -EINVAL;
18810 +               break;
18811 +       }
18812 +       return error;
18813 +}
18814 +
18815 +
18816 +/* virtual host info names */
18817 +
18818 +static char *vx_vhi_name(struct vx_info *vxi, int id)
18819 +{
18820 +       struct nsproxy *nsproxy;
18821 +       struct uts_namespace *uts;
18822 +
18823 +       if (id == VHIN_CONTEXT)
18824 +               return vxi->vx_name;
18825 +
18826 +       nsproxy = vxi->vx_nsproxy[0];
18827 +       if (!nsproxy)
18828 +               return NULL;
18829 +
18830 +       uts = nsproxy->uts_ns;
18831 +       if (!uts)
18832 +               return NULL;
18833 +
18834 +       switch (id) {
18835 +       case VHIN_SYSNAME:
18836 +               return uts->name.sysname;
18837 +       case VHIN_NODENAME:
18838 +               return uts->name.nodename;
18839 +       case VHIN_RELEASE:
18840 +               return uts->name.release;
18841 +       case VHIN_VERSION:
18842 +               return uts->name.version;
18843 +       case VHIN_MACHINE:
18844 +               return uts->name.machine;
18845 +       case VHIN_DOMAINNAME:
18846 +               return uts->name.domainname;
18847 +       default:
18848 +               return NULL;
18849 +       }
18850 +       return NULL;
18851 +}
18852 +
18853 +int vc_set_vhi_name(struct vx_info *vxi, void __user *data)
18854 +{
18855 +       struct vcmd_vhi_name_v0 vc_data;
18856 +       char *name;
18857 +
18858 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18859 +               return -EFAULT;
18860 +
18861 +       name = vx_vhi_name(vxi, vc_data.field);
18862 +       if (!name)
18863 +               return -EINVAL;
18864 +
18865 +       memcpy(name, vc_data.name, 65);
18866 +       return 0;
18867 +}
18868 +
18869 +int vc_get_vhi_name(struct vx_info *vxi, void __user *data)
18870 +{
18871 +       struct vcmd_vhi_name_v0 vc_data;
18872 +       char *name;
18873 +
18874 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18875 +               return -EFAULT;
18876 +
18877 +       name = vx_vhi_name(vxi, vc_data.field);
18878 +       if (!name)
18879 +               return -EINVAL;
18880 +
18881 +       memcpy(vc_data.name, name, 65);
18882 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
18883 +               return -EFAULT;
18884 +       return 0;
18885 +}
18886 +
18887 +
18888 +int vc_virt_stat(struct vx_info *vxi, void __user *data)
18889 +{
18890 +       struct vcmd_virt_stat_v0 vc_data;
18891 +       struct _vx_cvirt *cvirt = &vxi->cvirt;
18892 +       struct timespec uptime;
18893 +
18894 +       do_posix_clock_monotonic_gettime(&uptime);
18895 +       set_normalized_timespec(&uptime,
18896 +               uptime.tv_sec - cvirt->bias_uptime.tv_sec,
18897 +               uptime.tv_nsec - cvirt->bias_uptime.tv_nsec);
18898 +
18899 +       vc_data.offset = timeval_to_ns(&cvirt->bias_tv);
18900 +       vc_data.uptime = timespec_to_ns(&uptime);
18901 +       vc_data.nr_threads = atomic_read(&cvirt->nr_threads);
18902 +       vc_data.nr_running = atomic_read(&cvirt->nr_running);
18903 +       vc_data.nr_uninterruptible = atomic_read(&cvirt->nr_uninterruptible);
18904 +       vc_data.nr_onhold = atomic_read(&cvirt->nr_onhold);
18905 +       vc_data.nr_forks = atomic_read(&cvirt->total_forks);
18906 +       vc_data.load[0] = cvirt->load[0];
18907 +       vc_data.load[1] = cvirt->load[1];
18908 +       vc_data.load[2] = cvirt->load[2];
18909 +
18910 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
18911 +               return -EFAULT;
18912 +       return 0;
18913 +}
18914 +
18915 +
18916 +#ifdef CONFIG_VSERVER_VTIME
18917 +
18918 +/* virtualized time base */
18919 +
18920 +void vx_gettimeofday(struct timeval *tv)
18921 +{
18922 +       struct vx_info *vxi;
18923 +
18924 +       do_gettimeofday(tv);
18925 +       if (!vx_flags(VXF_VIRT_TIME, 0))
18926 +               return;
18927 +
18928 +       vxi = current_vx_info();
18929 +       tv->tv_sec += vxi->cvirt.bias_tv.tv_sec;
18930 +       tv->tv_usec += vxi->cvirt.bias_tv.tv_usec;
18931 +
18932 +       if (tv->tv_usec >= USEC_PER_SEC) {
18933 +               tv->tv_sec++;
18934 +               tv->tv_usec -= USEC_PER_SEC;
18935 +       } else if (tv->tv_usec < 0) {
18936 +               tv->tv_sec--;
18937 +               tv->tv_usec += USEC_PER_SEC;
18938 +       }
18939 +}
18940 +
18941 +int vx_settimeofday(struct timespec *ts)
18942 +{
18943 +       struct timeval tv;
18944 +       struct vx_info *vxi;
18945 +
18946 +       if (!vx_flags(VXF_VIRT_TIME, 0))
18947 +               return do_settimeofday(ts);
18948 +
18949 +       do_gettimeofday(&tv);
18950 +       vxi = current_vx_info();
18951 +       vxi->cvirt.bias_tv.tv_sec = ts->tv_sec - tv.tv_sec;
18952 +       vxi->cvirt.bias_tv.tv_usec =
18953 +               (ts->tv_nsec/NSEC_PER_USEC) - tv.tv_usec;
18954 +       return 0;
18955 +}
18956 +
18957 +#endif
18958 +
18959 diff -NurpP --minimal linux-2.6.32.6/kernel/vserver/cvirt_init.h linux-2.6.32.6-vs2.3.0.36.28/kernel/vserver/cvirt_init.h
18960 --- linux-2.6.32.6/kernel/vserver/cvirt_init.h  1970-01-01 01:00:00.000000000 +0100
18961 +++ linux-2.6.32.6-vs2.3.0.36.28/kernel/vserver/cvirt_init.h    2009-12-03 20:04:56.000000000 +0100
18962 @@ -0,0 +1,69 @@
18963 +
18964 +
18965 +extern uint64_t vx_idle_jiffies(void);
18966 +
18967 +static inline void vx_info_init_cvirt(struct _vx_cvirt *cvirt)
18968 +{
18969 +       uint64_t idle_jiffies = vx_idle_jiffies();
18970 +       uint64_t nsuptime;
18971 +
18972 +       do_posix_clock_monotonic_gettime(&cvirt->bias_uptime);
18973 +       nsuptime = (unsigned long long)cvirt->bias_uptime.tv_sec
18974 +               * NSEC_PER_SEC + cvirt->bias_uptime.tv_nsec;
18975 +       cvirt->bias_clock = nsec_to_clock_t(nsuptime);
18976 +       cvirt->bias_tv.tv_sec = 0;
18977 +       cvirt->bias_tv.tv_usec = 0;
18978 +
18979 +       jiffies_to_timespec(idle_jiffies, &cvirt->bias_idle);
18980 +       atomic_set(&cvirt->nr_threads, 0);
18981 +       atomic_set(&cvirt->nr_running, 0);
18982 +       atomic_set(&cvirt->nr_uninterruptible, 0);
18983 +       atomic_set(&cvirt->nr_onhold, 0);
18984 +
18985 +       spin_lock_init(&cvirt->load_lock);
18986 +       cvirt->load_last = jiffies;
18987 +       atomic_set(&cvirt->load_updates, 0);
18988 +       cvirt->load[0] = 0;
18989 +       cvirt->load[1] = 0;
18990 +       cvirt->load[2] = 0;
18991 +       atomic_set(&cvirt->total_forks, 0);
18992 +
18993 +       spin_lock_init(&cvirt->syslog.logbuf_lock);
18994 +       init_waitqueue_head(&cvirt->syslog.log_wait);
18995 +       cvirt->syslog.log_start = 0;
18996 +       cvirt->syslog.log_end = 0;
18997 +       cvirt->syslog.con_start = 0;
18998 +       cvirt->syslog.logged_chars = 0;
18999 +}
19000 +
19001 +static inline
19002 +void vx_info_init_cvirt_pc(struct _vx_cvirt_pc *cvirt_pc, int cpu)
19003 +{
19004 +       // cvirt_pc->cpustat = { 0 };
19005 +}
19006 +
19007 +static inline void vx_info_exit_cvirt(struct _vx_cvirt *cvirt)
19008 +{
19009 +       int value;
19010 +
19011 +       vxwprintk_xid((value = atomic_read(&cvirt->nr_threads)),
19012 +               "!!! cvirt: %p[nr_threads] = %d on exit.",
19013 +               cvirt, value);
19014 +       vxwprintk_xid((value = atomic_read(&cvirt->nr_running)),
19015 +               "!!! cvirt: %p[nr_running] = %d on exit.",
19016 +               cvirt, value);
19017 +       vxwprintk_xid((value = atomic_read(&cvirt->nr_uninterruptible)),
19018 +               "!!! cvirt: %p[nr_uninterruptible] = %d on exit.",
19019 +               cvirt, value);
19020 +       vxwprintk_xid((value = atomic_read(&cvirt->nr_onhold)),
19021 +               "!!! cvirt: %p[nr_onhold] = %d on exit.",
19022 +               cvirt, value);
19023 +       return;
19024 +}
19025 +
19026 +static inline
19027 +void vx_info_exit_cvirt_pc(struct _vx_cvirt_pc *cvirt_pc, int cpu)
19028 +{
19029 +       return;
19030 +}
19031 +
19032 diff -NurpP --minimal linux-2.6.32.6/kernel/vserver/cvirt_proc.h linux-2.6.32.6-vs2.3.0.36.28/kernel/vserver/cvirt_proc.h
19033 --- linux-2.6.32.6/kernel/vserver/cvirt_proc.h  1970-01-01 01:00:00.000000000 +0100
19034 +++ linux-2.6.32.6-vs2.3.0.36.28/kernel/vserver/cvirt_proc.h    2009-12-03 20:04:56.000000000 +0100
19035 @@ -0,0 +1,135 @@
19036 +#ifndef _VX_CVIRT_PROC_H
19037 +#define _VX_CVIRT_PROC_H
19038 +
19039 +#include <linux/nsproxy.h>
19040 +#include <linux/mnt_namespace.h>
19041 +#include <linux/ipc_namespace.h>
19042 +#include <linux/utsname.h>
19043 +#include <linux/ipc.h>
19044 +
19045 +
19046 +static inline
19047 +int vx_info_proc_nsproxy(struct nsproxy *nsproxy, char *buffer)
19048 +{
19049 +       struct mnt_namespace *ns;
19050 +       struct uts_namespace *uts;
19051 +       struct ipc_namespace *ipc;
19052 +       struct path path;
19053 +       char *pstr, *root;
19054 +       int length = 0;
19055 +
19056 +       if (!nsproxy)
19057 +               goto out;
19058 +
19059 +       length += sprintf(buffer + length,
19060 +               "NSProxy:\t%p [%p,%p,%p]\n",
19061 +               nsproxy, nsproxy->mnt_ns,
19062 +               nsproxy->uts_ns, nsproxy->ipc_ns);
19063 +
19064 +       ns = nsproxy->mnt_ns;
19065 +       if (!ns)
19066 +               goto skip_ns;
19067 +
19068 +       pstr = kmalloc(PATH_MAX, GFP_KERNEL);
19069 +       if (!pstr)
19070 +               goto skip_ns;
19071 +
19072 +       path.mnt = ns->root;
19073 +       path.dentry = ns->root->mnt_root;
19074 +       root = d_path(&path, pstr, PATH_MAX - 2);
19075 +       length += sprintf(buffer + length,
19076 +               "Namespace:\t%p [#%u]\n"
19077 +               "RootPath:\t%s\n",
19078 +               ns, atomic_read(&ns->count),
19079 +               root);
19080 +       kfree(pstr);
19081 +skip_ns:
19082 +
19083 +       uts = nsproxy->uts_ns;
19084 +       if (!uts)
19085 +               goto skip_uts;
19086 +
19087 +       length += sprintf(buffer + length,
19088 +               "SysName:\t%.*s\n"
19089 +               "NodeName:\t%.*s\n"
19090 +               "Release:\t%.*s\n"
19091 +               "Version:\t%.*s\n"
19092 +               "Machine:\t%.*s\n"
19093 +               "DomainName:\t%.*s\n",
19094 +               __NEW_UTS_LEN, uts->name.sysname,
19095 +               __NEW_UTS_LEN, uts->name.nodename,
19096 +               __NEW_UTS_LEN, uts->name.release,
19097 +               __NEW_UTS_LEN, uts->name.version,
19098 +               __NEW_UTS_LEN, uts->name.machine,
19099 +               __NEW_UTS_LEN, uts->name.domainname);
19100 +skip_uts:
19101 +
19102 +       ipc = nsproxy->ipc_ns;
19103 +       if (!ipc)
19104 +               goto skip_ipc;
19105 +
19106 +       length += sprintf(buffer + length,
19107 +               "SEMS:\t\t%d %d %d %d  %d\n"
19108 +               "MSG:\t\t%d %d %d\n"
19109 +               "SHM:\t\t%lu %lu  %d %d\n",
19110 +               ipc->sem_ctls[0], ipc->sem_ctls[1],
19111 +               ipc->sem_ctls[2], ipc->sem_ctls[3],
19112 +               ipc->used_sems,
19113 +               ipc->msg_ctlmax, ipc->msg_ctlmnb, ipc->msg_ctlmni,
19114 +               (unsigned long)ipc->shm_ctlmax,
19115 +               (unsigned long)ipc->shm_ctlall,
19116 +               ipc->shm_ctlmni, ipc->shm_tot);
19117 +skip_ipc:
19118 +out:
19119 +       return length;
19120 +}
19121 +
19122 +
19123 +#include <linux/sched.h>
19124 +
19125 +#define LOAD_INT(x) ((x) >> FSHIFT)
19126 +#define LOAD_FRAC(x) LOAD_INT(((x) & (FIXED_1 - 1)) * 100)
19127 +
19128 +static inline
19129 +int vx_info_proc_cvirt(struct _vx_cvirt *cvirt, char *buffer)
19130 +{
19131 +       int length = 0;
19132 +       int a, b, c;
19133 +
19134 +       length += sprintf(buffer + length,
19135 +               "BiasUptime:\t%lu.%02lu\n",
19136 +               (unsigned long)cvirt->bias_uptime.tv_sec,
19137 +               (cvirt->bias_uptime.tv_nsec / (NSEC_PER_SEC / 100)));
19138 +
19139 +       a = cvirt->load[0] + (FIXED_1 / 200);
19140 +       b = cvirt->load[1] + (FIXED_1 / 200);
19141 +       c = cvirt->load[2] + (FIXED_1 / 200);
19142 +       length += sprintf(buffer + length,
19143 +               "nr_threads:\t%d\n"
19144 +               "nr_running:\t%d\n"
19145 +               "nr_unintr:\t%d\n"
19146 +               "nr_onhold:\t%d\n"
19147 +               "load_updates:\t%d\n"
19148 +               "loadavg:\t%d.%02d %d.%02d %d.%02d\n"
19149 +               "total_forks:\t%d\n",
19150 +               atomic_read(&cvirt->nr_threads),
19151 +               atomic_read(&cvirt->nr_running),
19152 +               atomic_read(&cvirt->nr_uninterruptible),
19153 +               atomic_read(&cvirt->nr_onhold),
19154 +               atomic_read(&cvirt->load_updates),
19155 +               LOAD_INT(a), LOAD_FRAC(a),
19156 +               LOAD_INT(b), LOAD_FRAC(b),
19157 +               LOAD_INT(c), LOAD_FRAC(c),
19158 +               atomic_read(&cvirt->total_forks));
19159 +       return length;
19160 +}
19161 +
19162 +static inline
19163 +int vx_info_proc_cvirt_pc(struct _vx_cvirt_pc *cvirt_pc,
19164 +       char *buffer, int cpu)
19165 +{
19166 +       int length = 0;
19167 +       return length;
19168 +}
19169 +
19170 +#endif /* _VX_CVIRT_PROC_H */
19171 diff -NurpP --minimal linux-2.6.32.6/kernel/vserver/debug.c linux-2.6.32.6-vs2.3.0.36.28/kernel/vserver/debug.c
19172 --- linux-2.6.32.6/kernel/vserver/debug.c       1970-01-01 01:00:00.000000000 +0100
19173 +++ linux-2.6.32.6-vs2.3.0.36.28/kernel/vserver/debug.c 2009-12-03 20:04:56.000000000 +0100
19174 @@ -0,0 +1,32 @@
19175 +/*
19176 + *  kernel/vserver/debug.c
19177 + *
19178 + *  Copyright (C) 2005-2007 Herbert Pötzl
19179 + *
19180 + *  V0.01  vx_info dump support
19181 + *
19182 + */
19183 +
19184 +#include <linux/module.h>
19185 +
19186 +#include <linux/vserver/context.h>
19187 +
19188 +
19189 +void   dump_vx_info(struct vx_info *vxi, int level)
19190 +{
19191 +       printk("vx_info %p[#%d, %d.%d, %4x]\n", vxi, vxi->vx_id,
19192 +               atomic_read(&vxi->vx_usecnt),
19193 +               atomic_read(&vxi->vx_tasks),
19194 +               vxi->vx_state);
19195 +       if (level > 0) {
19196 +               __dump_vx_limit(&vxi->limit);
19197 +               __dump_vx_sched(&vxi->sched);
19198 +               __dump_vx_cvirt(&vxi->cvirt);
19199 +               __dump_vx_cacct(&vxi->cacct);
19200 +       }
19201 +       printk("---\n");
19202 +}
19203 +
19204 +
19205 +EXPORT_SYMBOL_GPL(dump_vx_info);
19206 +
19207 diff -NurpP --minimal linux-2.6.32.6/kernel/vserver/device.c linux-2.6.32.6-vs2.3.0.36.28/kernel/vserver/device.c
19208 --- linux-2.6.32.6/kernel/vserver/device.c      1970-01-01 01:00:00.000000000 +0100
19209 +++ linux-2.6.32.6-vs2.3.0.36.28/kernel/vserver/device.c        2009-12-03 20:04:56.000000000 +0100
19210 @@ -0,0 +1,443 @@
19211 +/*
19212 + *  linux/kernel/vserver/device.c
19213 + *
19214 + *  Linux-VServer: Device Support
19215 + *
19216 + *  Copyright (C) 2006  Herbert Pötzl
19217 + *  Copyright (C) 2007  Daniel Hokka Zakrisson
19218 + *
19219 + *  V0.01  device mapping basics
19220 + *  V0.02  added defaults
19221 + *
19222 + */
19223 +
19224 +#include <linux/slab.h>
19225 +#include <linux/rcupdate.h>
19226 +#include <linux/fs.h>
19227 +#include <linux/namei.h>
19228 +#include <linux/hash.h>
19229 +
19230 +#include <asm/errno.h>
19231 +#include <asm/uaccess.h>
19232 +#include <linux/vserver/base.h>
19233 +#include <linux/vserver/debug.h>
19234 +#include <linux/vserver/context.h>
19235 +#include <linux/vserver/device.h>
19236 +#include <linux/vserver/device_cmd.h>
19237 +
19238 +
19239 +#define DMAP_HASH_BITS 4
19240 +
19241 +
19242 +struct vs_mapping {
19243 +       union {
19244 +               struct hlist_node hlist;
19245 +               struct list_head list;
19246 +       } u;
19247 +#define dm_hlist       u.hlist
19248 +#define dm_list                u.list
19249 +       xid_t xid;
19250 +       dev_t device;
19251 +       struct vx_dmap_target target;
19252 +};
19253 +
19254 +
19255 +static struct hlist_head dmap_main_hash[1 << DMAP_HASH_BITS];
19256 +
19257 +static spinlock_t dmap_main_hash_lock = SPIN_LOCK_UNLOCKED;
19258 +
19259 +static struct vx_dmap_target dmap_defaults[2] = {
19260 +       { .flags = DATTR_OPEN },
19261 +       { .flags = DATTR_OPEN },
19262 +};
19263 +
19264 +
19265 +struct kmem_cache *dmap_cachep __read_mostly;
19266 +
19267 +int __init dmap_cache_init(void)
19268 +{
19269 +       dmap_cachep = kmem_cache_create("dmap_cache",
19270 +               sizeof(struct vs_mapping), 0,
19271 +               SLAB_HWCACHE_ALIGN|SLAB_PANIC, NULL);
19272 +       return 0;
19273 +}
19274 +
19275 +__initcall(dmap_cache_init);
19276 +
19277 +
19278 +static inline unsigned int __hashval(dev_t dev, int bits)
19279 +{
19280 +       return hash_long((unsigned long)dev, bits);
19281 +}
19282 +
19283 +
19284 +/*     __hash_mapping()
19285 + *     add the mapping to the hash table
19286 + */
19287 +static inline void __hash_mapping(struct vx_info *vxi, struct vs_mapping *vdm)
19288 +{
19289 +       spinlock_t *hash_lock = &dmap_main_hash_lock;
19290 +       struct hlist_head *head, *hash = dmap_main_hash;
19291 +       int device = vdm->device;
19292 +
19293 +       spin_lock(hash_lock);
19294 +       vxdprintk(VXD_CBIT(misc, 8), "__hash_mapping: %p[#%d] %08x:%08x",
19295 +               vxi, vxi ? vxi->vx_id : 0, device, vdm->target.target);
19296 +
19297 +       head = &hash[__hashval(device, DMAP_HASH_BITS)];
19298 +       hlist_add_head(&vdm->dm_hlist, head);
19299 +       spin_unlock(hash_lock);
19300 +}
19301 +
19302 +
19303 +static inline int __mode_to_default(umode_t mode)
19304 +{
19305 +       switch (mode) {
19306 +       case S_IFBLK:
19307 +               return 0;
19308 +       case S_IFCHR:
19309 +               return 1;
19310 +       default:
19311 +               BUG();
19312 +       }
19313 +}
19314 +
19315 +
19316 +/*     __set_default()
19317 + *     set a default
19318 + */
19319 +static inline void __set_default(struct vx_info *vxi, umode_t mode,
19320 +       struct vx_dmap_target *vdmt)
19321 +{
19322 +       spinlock_t *hash_lock = &dmap_main_hash_lock;
19323 +       spin_lock(hash_lock);
19324 +
19325 +       if (vxi)
19326 +               vxi->dmap.targets[__mode_to_default(mode)] = *vdmt;
19327 +       else
19328 +               dmap_defaults[__mode_to_default(mode)] = *vdmt;
19329 +
19330 +
19331 +       spin_unlock(hash_lock);
19332 +
19333 +       vxdprintk(VXD_CBIT(misc, 8), "__set_default: %p[#%u] %08x %04x",
19334 +                 vxi, vxi ? vxi->vx_id : 0, vdmt->target, vdmt->flags);
19335 +}
19336 +
19337 +
19338 +/*     __remove_default()
19339 + *     remove a default
19340 + */
19341 +static inline int __remove_default(struct vx_info *vxi, umode_t mode)
19342 +{
19343 +       spinlock_t *hash_lock = &dmap_main_hash_lock;
19344 +       spin_lock(hash_lock);
19345 +
19346 +       if (vxi)
19347 +               vxi->dmap.targets[__mode_to_default(mode)].flags = 0;
19348 +       else    /* remove == reset */
19349 +               dmap_defaults[__mode_to_default(mode)].flags = DATTR_OPEN | mode;
19350 +
19351 +       spin_unlock(hash_lock);
19352 +       return 0;
19353 +}
19354 +
19355 +
19356 +/*     __find_mapping()
19357 + *     find a mapping in the hash table
19358 + *
19359 + *     caller must hold hash_lock
19360 + */
19361 +static inline int __find_mapping(xid_t xid, dev_t device, umode_t mode,
19362 +       struct vs_mapping **local, struct vs_mapping **global)
19363 +{
19364 +       struct hlist_head *hash = dmap_main_hash;
19365 +       struct hlist_head *head = &hash[__hashval(device, DMAP_HASH_BITS)];
19366 +       struct hlist_node *pos;
19367 +       struct vs_mapping *vdm;
19368 +
19369 +       *local = NULL;
19370 +       if (global)
19371 +               *global = NULL;
19372 +
19373 +       hlist_for_each(pos, head) {
19374 +               vdm = hlist_entry(pos, struct vs_mapping, dm_hlist);
19375 +
19376 +               if ((vdm->device == device) &&
19377 +                       !((vdm->target.flags ^ mode) & S_IFMT)) {
19378 +                       if (vdm->xid == xid) {
19379 +                               *local = vdm;
19380 +                               return 1;
19381 +                       } else if (global && vdm->xid == 0)
19382 +                               *global = vdm;
19383 +               }
19384 +       }
19385 +
19386 +       if (global && *global)
19387 +               return 0;
19388 +       else
19389 +               return -ENOENT;
19390 +}
19391 +
19392 +
19393 +/*     __lookup_mapping()
19394 + *     find a mapping and store the result in target and flags
19395 + */
19396 +static inline int __lookup_mapping(struct vx_info *vxi,
19397 +       dev_t device, dev_t *target, int *flags, umode_t mode)
19398 +{
19399 +       spinlock_t *hash_lock = &dmap_main_hash_lock;
19400 +       struct vs_mapping *vdm, *global;
19401 +       struct vx_dmap_target *vdmt;
19402 +       int ret = 0;
19403 +       xid_t xid = vxi->vx_id;
19404 +       int index;
19405 +
19406 +       spin_lock(hash_lock);
19407 +       if (__find_mapping(xid, device, mode, &vdm, &global) > 0) {
19408 +               ret = 1;
19409 +               vdmt = &vdm->target;
19410 +               goto found;
19411 +       }
19412 +
19413 +       index = __mode_to_default(mode);
19414 +       if (vxi && vxi->dmap.targets[index].flags) {
19415 +               ret = 2;
19416 +               vdmt = &vxi->dmap.targets[index];
19417 +       } else if (global) {
19418 +               ret = 3;
19419 +               vdmt = &global->target;
19420 +               goto found;
19421 +       } else {
19422 +               ret = 4;
19423 +               vdmt = &dmap_defaults[index];
19424 +       }
19425 +
19426 +found:
19427 +       if (target && (vdmt->flags & DATTR_REMAP))
19428 +               *target = vdmt->target;
19429 +       else if (target)
19430 +               *target = device;
19431 +       if (flags)
19432 +               *flags = vdmt->flags;
19433 +
19434 +       spin_unlock(hash_lock);
19435 +
19436 +       return ret;
19437 +}
19438 +
19439 +
19440 +/*     __remove_mapping()
19441 + *     remove a mapping from the hash table
19442 + */
19443 +static inline int __remove_mapping(struct vx_info *vxi, dev_t device,
19444 +       umode_t mode)
19445 +{
19446 +       spinlock_t *hash_lock = &dmap_main_hash_lock;
19447 +       struct vs_mapping *vdm = NULL;
19448 +       int ret = 0;
19449 +
19450 +       spin_lock(hash_lock);
19451 +
19452 +       ret = __find_mapping((vxi ? vxi->vx_id : 0), device, mode, &vdm,
19453 +               NULL);
19454 +       vxdprintk(VXD_CBIT(misc, 8), "__remove_mapping: %p[#%d] %08x %04x",
19455 +               vxi, vxi ? vxi->vx_id : 0, device, mode);
19456 +       if (ret < 0)
19457 +               goto out;
19458 +       hlist_del(&vdm->dm_hlist);
19459 +
19460 +out:
19461 +       spin_unlock(hash_lock);
19462 +       if (vdm)
19463 +               kmem_cache_free(dmap_cachep, vdm);
19464 +       return ret;
19465 +}
19466 +
19467 +
19468 +
19469 +int vs_map_device(struct vx_info *vxi,
19470 +       dev_t device, dev_t *target, umode_t mode)
19471 +{
19472 +       int ret, flags = DATTR_MASK;
19473 +
19474 +       if (!vxi) {
19475 +               if (target)
19476 +                       *target = device;
19477 +               goto out;
19478 +       }
19479 +       ret = __lookup_mapping(vxi, device, target, &flags, mode);
19480 +       vxdprintk(VXD_CBIT(misc, 8), "vs_map_device: %08x target: %08x flags: %04x mode: %04x mapped=%d",
19481 +               device, target ? *target : 0, flags, mode, ret);
19482 +out:
19483 +       return (flags & DATTR_MASK);
19484 +}
19485 +
19486 +
19487 +
19488 +static int do_set_mapping(struct vx_info *vxi,
19489 +       dev_t device, dev_t target, int flags, umode_t mode)
19490 +{
19491 +       if (device) {
19492 +               struct vs_mapping *new;
19493 +
19494 +               new = kmem_cache_alloc(dmap_cachep, GFP_KERNEL);
19495 +               if (!new)
19496 +                       return -ENOMEM;
19497 +
19498 +               INIT_HLIST_NODE(&new->dm_hlist);
19499 +               new->device = device;
19500 +               new->target.target = target;
19501 +               new->target.flags = flags | mode;
19502 +               new->xid = (vxi ? vxi->vx_id : 0);
19503 +
19504 +               vxdprintk(VXD_CBIT(misc, 8), "do_set_mapping: %08x target: %08x flags: %04x", device, target, flags);
19505 +               __hash_mapping(vxi, new);
19506 +       } else {
19507 +               struct vx_dmap_target new = {
19508 +                       .target = target,
19509 +                       .flags = flags | mode,
19510 +               };
19511 +               __set_default(vxi, mode, &new);
19512 +       }
19513 +       return 0;
19514 +}
19515 +
19516 +
19517 +static int do_unset_mapping(struct vx_info *vxi,
19518 +       dev_t device, dev_t target, int flags, umode_t mode)
19519 +{
19520 +       int ret = -EINVAL;
19521 +
19522 +       if (device) {
19523 +               ret = __remove_mapping(vxi, device, mode);
19524 +               if (ret < 0)
19525 +                       goto out;
19526 +       } else {
19527 +               ret = __remove_default(vxi, mode);
19528 +               if (ret < 0)
19529 +                       goto out;
19530 +       }
19531 +
19532 +out:
19533 +       return ret;
19534 +}
19535 +
19536 +
19537 +static inline int __user_device(const char __user *name, dev_t *dev,
19538 +       umode_t *mode)
19539 +{
19540 +       struct nameidata nd;
19541 +       int ret;
19542 +
19543 +       if (!name) {
19544 +               *dev = 0;
19545 +               return 0;
19546 +       }
19547 +       ret = user_lpath(name, &nd.path);
19548 +       if (ret)
19549 +               return ret;
19550 +       if (nd.path.dentry->d_inode) {
19551 +               *dev = nd.path.dentry->d_inode->i_rdev;
19552 +               *mode = nd.path.dentry->d_inode->i_mode;
19553 +       }
19554 +       path_put(&nd.path);
19555 +       return 0;
19556 +}
19557 +
19558 +static inline int __mapping_mode(dev_t device, dev_t target,
19559 +       umode_t device_mode, umode_t target_mode, umode_t *mode)
19560 +{
19561 +       if (device)
19562 +               *mode = device_mode & S_IFMT;
19563 +       else if (target)
19564 +               *mode = target_mode & S_IFMT;
19565 +       else
19566 +               return -EINVAL;
19567 +
19568 +       /* if both given, device and target mode have to match */
19569 +       if (device && target &&
19570 +               ((device_mode ^ target_mode) & S_IFMT))
19571 +               return -EINVAL;
19572 +       return 0;
19573 +}
19574 +
19575 +
19576 +static inline int do_mapping(struct vx_info *vxi, const char __user *device_path,
19577 +       const char __user *target_path, int flags, int set)
19578 +{
19579 +       dev_t device = ~0, target = ~0;
19580 +       umode_t device_mode = 0, target_mode = 0, mode;
19581 +       int ret;
19582 +
19583 +       ret = __user_device(device_path, &device, &device_mode);
19584 +       if (ret)
19585 +               return ret;
19586 +       ret = __user_device(target_path, &target, &target_mode);
19587 +       if (ret)
19588 +               return ret;
19589 +
19590 +       ret = __mapping_mode(device, target,
19591 +               device_mode, target_mode, &mode);
19592 +       if (ret)
19593 +               return ret;
19594 +
19595 +       if (set)
19596 +               return do_set_mapping(vxi, device, target,
19597 +                       flags, mode);
19598 +       else
19599 +               return do_unset_mapping(vxi, device, target,
19600 +                       flags, mode);
19601 +}
19602 +
19603 +
19604 +int vc_set_mapping(struct vx_info *vxi, void __user *data)
19605 +{
19606 +       struct vcmd_set_mapping_v0 vc_data;
19607 +
19608 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19609 +               return -EFAULT;
19610 +
19611 +       return do_mapping(vxi, vc_data.device, vc_data.target,
19612 +               vc_data.flags, 1);
19613 +}
19614 +
19615 +int vc_unset_mapping(struct vx_info *vxi, void __user *data)
19616 +{
19617 +       struct vcmd_set_mapping_v0 vc_data;
19618 +
19619 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19620 +               return -EFAULT;
19621 +
19622 +       return do_mapping(vxi, vc_data.device, vc_data.target,
19623 +               vc_data.flags, 0);
19624 +}
19625 +
19626 +
19627 +#ifdef CONFIG_COMPAT
19628 +
19629 +int vc_set_mapping_x32(struct vx_info *vxi, void __user *data)
19630 +{
19631 +       struct vcmd_set_mapping_v0_x32 vc_data;
19632 +
19633 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19634 +               return -EFAULT;
19635 +
19636 +       return do_mapping(vxi, compat_ptr(vc_data.device_ptr),
19637 +               compat_ptr(vc_data.target_ptr), vc_data.flags, 1);
19638 +}
19639 +
19640 +int vc_unset_mapping_x32(struct vx_info *vxi, void __user *data)
19641 +{
19642 +       struct vcmd_set_mapping_v0_x32 vc_data;
19643 +
19644 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19645 +               return -EFAULT;
19646 +
19647 +       return do_mapping(vxi, compat_ptr(vc_data.device_ptr),
19648 +               compat_ptr(vc_data.target_ptr), vc_data.flags, 0);
19649 +}
19650 +
19651 +#endif /* CONFIG_COMPAT */
19652 +
19653 +
19654 diff -NurpP --minimal linux-2.6.32.6/kernel/vserver/dlimit.c linux-2.6.32.6-vs2.3.0.36.28/kernel/vserver/dlimit.c
19655 --- linux-2.6.32.6/kernel/vserver/dlimit.c      1970-01-01 01:00:00.000000000 +0100
19656 +++ linux-2.6.32.6-vs2.3.0.36.28/kernel/vserver/dlimit.c        2009-12-03 20:04:56.000000000 +0100
19657 @@ -0,0 +1,529 @@
19658 +/*
19659 + *  linux/kernel/vserver/dlimit.c
19660 + *
19661 + *  Virtual Server: Context Disk Limits
19662 + *
19663 + *  Copyright (C) 2004-2009  Herbert Pötzl
19664 + *
19665 + *  V0.01  initial version
19666 + *  V0.02  compat32 splitup
19667 + *  V0.03  extended interface
19668 + *
19669 + */
19670 +
19671 +#include <linux/statfs.h>
19672 +#include <linux/sched.h>
19673 +#include <linux/namei.h>
19674 +#include <linux/vs_tag.h>
19675 +#include <linux/vs_dlimit.h>
19676 +#include <linux/vserver/dlimit_cmd.h>
19677 +
19678 +#include <asm/uaccess.h>
19679 +
19680 +/*     __alloc_dl_info()
19681 +
19682 +       * allocate an initialized dl_info struct
19683 +       * doesn't make it visible (hash)                        */
19684 +
19685 +static struct dl_info *__alloc_dl_info(struct super_block *sb, tag_t tag)
19686 +{
19687 +       struct dl_info *new = NULL;
19688 +
19689 +       vxdprintk(VXD_CBIT(dlim, 5),
19690 +               "alloc_dl_info(%p,%d)*", sb, tag);
19691 +
19692 +       /* would this benefit from a slab cache? */
19693 +       new = kmalloc(sizeof(struct dl_info), GFP_KERNEL);
19694 +       if (!new)
19695 +               return 0;
19696 +
19697 +       memset(new, 0, sizeof(struct dl_info));
19698 +       new->dl_tag = tag;
19699 +       new->dl_sb = sb;
19700 +       INIT_RCU_HEAD(&new->dl_rcu);
19701 +       INIT_HLIST_NODE(&new->dl_hlist);
19702 +       spin_lock_init(&new->dl_lock);
19703 +       atomic_set(&new->dl_refcnt, 0);
19704 +       atomic_set(&new->dl_usecnt, 0);
19705 +
19706 +       /* rest of init goes here */
19707 +
19708 +       vxdprintk(VXD_CBIT(dlim, 4),
19709 +               "alloc_dl_info(%p,%d) = %p", sb, tag, new);
19710 +       return new;
19711 +}
19712 +
19713 +/*     __dealloc_dl_info()
19714 +
19715 +       * final disposal of dl_info                             */
19716 +
19717 +static void __dealloc_dl_info(struct dl_info *dli)
19718 +{
19719 +       vxdprintk(VXD_CBIT(dlim, 4),
19720 +               "dealloc_dl_info(%p)", dli);
19721 +
19722 +       dli->dl_hlist.next = LIST_POISON1;
19723 +       dli->dl_tag = -1;
19724 +       dli->dl_sb = 0;
19725 +
19726 +       BUG_ON(atomic_read(&dli->dl_usecnt));
19727 +       BUG_ON(atomic_read(&dli->dl_refcnt));
19728 +
19729 +       kfree(dli);
19730 +}
19731 +
19732 +
19733 +/*     hash table for dl_info hash */
19734 +
19735 +#define DL_HASH_SIZE   13
19736 +
19737 +struct hlist_head dl_info_hash[DL_HASH_SIZE];
19738 +
19739 +static spinlock_t dl_info_hash_lock = SPIN_LOCK_UNLOCKED;
19740 +
19741 +
19742 +static inline unsigned int __hashval(struct super_block *sb, tag_t tag)
19743 +{
19744 +       return ((tag ^ (unsigned long)sb) % DL_HASH_SIZE);
19745 +}
19746 +
19747 +
19748 +
19749 +/*     __hash_dl_info()
19750 +
19751 +       * add the dli to the global hash table
19752 +       * requires the hash_lock to be held                     */
19753 +
19754 +static inline void __hash_dl_info(struct dl_info *dli)
19755 +{
19756 +       struct hlist_head *head;
19757 +
19758 +       vxdprintk(VXD_CBIT(dlim, 6),
19759 +               "__hash_dl_info: %p[#%d]", dli, dli->dl_tag);
19760 +       get_dl_info(dli);
19761 +       head = &dl_info_hash[__hashval(dli->dl_sb, dli->dl_tag)];
19762 +       hlist_add_head_rcu(&dli->dl_hlist, head);
19763 +}
19764 +
19765 +/*     __unhash_dl_info()
19766 +
19767 +       * remove the dli from the global hash table
19768 +       * requires the hash_lock to be held                     */
19769 +
19770 +static inline void __unhash_dl_info(struct dl_info *dli)
19771 +{
19772 +       vxdprintk(VXD_CBIT(dlim, 6),
19773 +               "__unhash_dl_info: %p[#%d]", dli, dli->dl_tag);
19774 +       hlist_del_rcu(&dli->dl_hlist);
19775 +       put_dl_info(dli);
19776 +}
19777 +
19778 +
19779 +/*     __lookup_dl_info()
19780 +
19781 +       * requires the rcu_read_lock()
19782 +       * doesn't increment the dl_refcnt                       */
19783 +
19784 +static inline struct dl_info *__lookup_dl_info(struct super_block *sb, tag_t tag)
19785 +{
19786 +       struct hlist_head *head = &dl_info_hash[__hashval(sb, tag)];
19787 +       struct hlist_node *pos;
19788 +       struct dl_info *dli;
19789 +
19790 +       hlist_for_each_entry_rcu(dli, pos, head, dl_hlist) {
19791 +
19792 +               if (dli->dl_tag == tag && dli->dl_sb == sb) {
19793 +                       return dli;
19794 +               }
19795 +       }
19796 +       return NULL;
19797 +}
19798 +
19799 +
19800 +struct dl_info *locate_dl_info(struct super_block *sb, tag_t tag)
19801 +{
19802 +       struct dl_info *dli;
19803 +
19804 +       rcu_read_lock();
19805 +       dli = get_dl_info(__lookup_dl_info(sb, tag));
19806 +       vxdprintk(VXD_CBIT(dlim, 7),
19807 +               "locate_dl_info(%p,#%d) = %p", sb, tag, dli);
19808 +       rcu_read_unlock();
19809 +       return dli;
19810 +}
19811 +
19812 +void rcu_free_dl_info(struct rcu_head *head)
19813 +{
19814 +       struct dl_info *dli = container_of(head, struct dl_info, dl_rcu);
19815 +       int usecnt, refcnt;
19816 +
19817 +       BUG_ON(!dli || !head);
19818 +
19819 +       usecnt = atomic_read(&dli->dl_usecnt);
19820 +       BUG_ON(usecnt < 0);
19821 +
19822 +       refcnt = atomic_read(&dli->dl_refcnt);
19823 +       BUG_ON(refcnt < 0);
19824 +
19825 +       vxdprintk(VXD_CBIT(dlim, 3),
19826 +               "rcu_free_dl_info(%p)", dli);
19827 +       if (!usecnt)
19828 +               __dealloc_dl_info(dli);
19829 +       else
19830 +               printk("!!! rcu didn't free\n");
19831 +}
19832 +
19833 +
19834 +
19835 +
19836 +static int do_addrem_dlimit(uint32_t id, const char __user *name,
19837 +       uint32_t flags, int add)
19838 +{
19839 +       struct path path;
19840 +       int ret;
19841 +
19842 +       ret = user_lpath(name, &path);
19843 +       if (!ret) {
19844 +               struct super_block *sb;
19845 +               struct dl_info *dli;
19846 +
19847 +               ret = -EINVAL;
19848 +               if (!path.dentry->d_inode)
19849 +                       goto out_release;
19850 +               if (!(sb = path.dentry->d_inode->i_sb))
19851 +                       goto out_release;
19852 +
19853 +               if (add) {
19854 +                       dli = __alloc_dl_info(sb, id);
19855 +                       spin_lock(&dl_info_hash_lock);
19856 +
19857 +                       ret = -EEXIST;
19858 +                       if (__lookup_dl_info(sb, id))
19859 +                               goto out_unlock;
19860 +                       __hash_dl_info(dli);
19861 +                       dli = NULL;
19862 +               } else {
19863 +                       spin_lock(&dl_info_hash_lock);
19864 +                       dli = __lookup_dl_info(sb, id);
19865 +
19866 +                       ret = -ESRCH;
19867 +                       if (!dli)
19868 +                               goto out_unlock;
19869 +                       __unhash_dl_info(dli);
19870 +               }
19871 +               ret = 0;
19872 +       out_unlock:
19873 +               spin_unlock(&dl_info_hash_lock);
19874 +               if (add && dli)
19875 +                       __dealloc_dl_info(dli);
19876 +       out_release:
19877 +               path_put(&path);
19878 +       }
19879 +       return ret;
19880 +}
19881 +
19882 +int vc_add_dlimit(uint32_t id, void __user *data)
19883 +{
19884 +       struct vcmd_ctx_dlimit_base_v0 vc_data;
19885 +
19886 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19887 +               return -EFAULT;
19888 +
19889 +       return do_addrem_dlimit(id, vc_data.name, vc_data.flags, 1);
19890 +}
19891 +
19892 +int vc_rem_dlimit(uint32_t id, void __user *data)
19893 +{
19894 +       struct vcmd_ctx_dlimit_base_v0 vc_data;
19895 +
19896 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19897 +               return -EFAULT;
19898 +
19899 +       return do_addrem_dlimit(id, vc_data.name, vc_data.flags, 0);
19900 +}
19901 +
19902 +#ifdef CONFIG_COMPAT
19903 +
19904 +int vc_add_dlimit_x32(uint32_t id, void __user *data)
19905 +{
19906 +       struct vcmd_ctx_dlimit_base_v0_x32 vc_data;
19907 +
19908 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19909 +               return -EFAULT;
19910 +
19911 +       return do_addrem_dlimit(id,
19912 +               compat_ptr(vc_data.name_ptr), vc_data.flags, 1);
19913 +}
19914 +
19915 +int vc_rem_dlimit_x32(uint32_t id, void __user *data)
19916 +{
19917 +       struct vcmd_ctx_dlimit_base_v0_x32 vc_data;
19918 +
19919 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19920 +               return -EFAULT;
19921 +
19922 +       return do_addrem_dlimit(id,
19923 +               compat_ptr(vc_data.name_ptr), vc_data.flags, 0);
19924 +}
19925 +
19926 +#endif /* CONFIG_COMPAT */
19927 +
19928 +
19929 +static inline
19930 +int do_set_dlimit(uint32_t id, const char __user *name,
19931 +       uint32_t space_used, uint32_t space_total,
19932 +       uint32_t inodes_used, uint32_t inodes_total,
19933 +       uint32_t reserved, uint32_t flags)
19934 +{
19935 +       struct path path;
19936 +       int ret;
19937 +
19938 +       ret = user_lpath(name, &path);
19939 +       if (!ret) {
19940 +               struct super_block *sb;
19941 +               struct dl_info *dli;
19942 +
19943 +               ret = -EINVAL;
19944 +               if (!path.dentry->d_inode)
19945 +                       goto out_release;
19946 +               if (!(sb = path.dentry->d_inode->i_sb))
19947 +                       goto out_release;
19948 +
19949 +               /* sanity checks */
19950 +               if ((reserved != CDLIM_KEEP &&
19951 +                       reserved > 100) ||
19952 +                       (inodes_used != CDLIM_KEEP &&
19953 +                       inodes_used > inodes_total) ||
19954 +                       (space_used != CDLIM_KEEP &&
19955 +                       space_used > space_total))
19956 +                       goto out_release;
19957 +
19958 +               ret = -ESRCH;
19959 +               dli = locate_dl_info(sb, id);
19960 +               if (!dli)
19961 +                       goto out_release;
19962 +
19963 +               spin_lock(&dli->dl_lock);
19964 +
19965 +               if (inodes_used != CDLIM_KEEP)
19966 +                       dli->dl_inodes_used = inodes_used;
19967 +               if (inodes_total != CDLIM_KEEP)
19968 +                       dli->dl_inodes_total = inodes_total;
19969 +               if (space_used != CDLIM_KEEP)
19970 +                       dli->dl_space_used = dlimit_space_32to64(
19971 +                               space_used, flags, DLIMS_USED);
19972 +
19973 +               if (space_total == CDLIM_INFINITY)
19974 +                       dli->dl_space_total = DLIM_INFINITY;
19975 +               else if (space_total != CDLIM_KEEP)
19976 +                       dli->dl_space_total = dlimit_space_32to64(
19977 +                               space_total, flags, DLIMS_TOTAL);
19978 +
19979 +               if (reserved != CDLIM_KEEP)
19980 +                       dli->dl_nrlmult = (1 << 10) * (100 - reserved) / 100;
19981 +
19982 +               spin_unlock(&dli->dl_lock);
19983 +
19984 +               put_dl_info(dli);
19985 +               ret = 0;
19986 +
19987 +       out_release:
19988 +               path_put(&path);
19989 +       }
19990 +       return ret;
19991 +}
19992 +
19993 +int vc_set_dlimit(uint32_t id, void __user *data)
19994 +{
19995 +       struct vcmd_ctx_dlimit_v0 vc_data;
19996 +
19997 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19998 +               return -EFAULT;
19999 +
20000 +       return do_set_dlimit(id, vc_data.name,
20001 +               vc_data.space_used, vc_data.space_total,
20002 +               vc_data.inodes_used, vc_data.inodes_total,
20003 +               vc_data.reserved, vc_data.flags);
20004 +}
20005 +
20006 +#ifdef CONFIG_COMPAT
20007 +
20008 +int vc_set_dlimit_x32(uint32_t id, void __user *data)
20009 +{
20010 +       struct vcmd_ctx_dlimit_v0_x32 vc_data;
20011 +
20012 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
20013 +               return -EFAULT;
20014 +
20015 +       return do_set_dlimit(id, compat_ptr(vc_data.name_ptr),
20016 +               vc_data.space_used, vc_data.space_total,
20017 +               vc_data.inodes_used, vc_data.inodes_total,
20018 +               vc_data.reserved, vc_data.flags);
20019 +}
20020 +
20021 +#endif /* CONFIG_COMPAT */
20022 +
20023 +
20024 +static inline
20025 +int do_get_dlimit(uint32_t id, const char __user *name,
20026 +       uint32_t *space_used, uint32_t *space_total,
20027 +       uint32_t *inodes_used, uint32_t *inodes_total,
20028 +       uint32_t *reserved, uint32_t *flags)
20029 +{
20030 +       struct path path;
20031 +       int ret;
20032 +
20033 +       ret = user_lpath(name, &path);
20034 +       if (!ret) {
20035 +               struct super_block *sb;
20036 +               struct dl_info *dli;
20037 +
20038 +               ret = -EINVAL;
20039 +               if (!path.dentry->d_inode)
20040 +                       goto out_release;
20041 +               if (!(sb = path.dentry->d_inode->i_sb))
20042 +                       goto out_release;
20043 +
20044 +               ret = -ESRCH;
20045 +               dli = locate_dl_info(sb, id);
20046 +               if (!dli)
20047 +                       goto out_release;
20048 +
20049 +               spin_lock(&dli->dl_lock);
20050 +               *inodes_used = dli->dl_inodes_used;
20051 +               *inodes_total = dli->dl_inodes_total;
20052 +
20053 +               *space_used = dlimit_space_64to32(
20054 +                       dli->dl_space_used, flags, DLIMS_USED);
20055 +
20056 +               if (dli->dl_space_total == DLIM_INFINITY)
20057 +                       *space_total = CDLIM_INFINITY;
20058 +               else
20059 +                       *space_total = dlimit_space_64to32(
20060 +                               dli->dl_space_total, flags, DLIMS_TOTAL);
20061 +
20062 +               *reserved = 100 - ((dli->dl_nrlmult * 100 + 512) >> 10);
20063 +               spin_unlock(&dli->dl_lock);
20064 +
20065 +               put_dl_info(dli);
20066 +               ret = -EFAULT;
20067 +
20068 +               ret = 0;
20069 +       out_release:
20070 +               path_put(&path);
20071 +       }
20072 +       return ret;
20073 +}
20074 +
20075 +
20076 +int vc_get_dlimit(uint32_t id, void __user *data)
20077 +{
20078 +       struct vcmd_ctx_dlimit_v0 vc_data;
20079 +       int ret;
20080 +
20081 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
20082 +               return -EFAULT;
20083 +
20084 +       ret = do_get_dlimit(id, vc_data.name,
20085 +               &vc_data.space_used, &vc_data.space_total,
20086 +               &vc_data.inodes_used, &vc_data.inodes_total,
20087 +               &vc_data.reserved, &vc_data.flags);
20088 +       if (ret)
20089 +               return ret;
20090 +
20091 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
20092 +               return -EFAULT;
20093 +       return 0;
20094 +}
20095 +
20096 +#ifdef CONFIG_COMPAT
20097 +
20098 +int vc_get_dlimit_x32(uint32_t id, void __user *data)
20099 +{
20100 +       struct vcmd_ctx_dlimit_v0_x32 vc_data;
20101 +       int ret;
20102 +
20103 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
20104 +               return -EFAULT;
20105 +
20106 +       ret = do_get_dlimit(id, compat_ptr(vc_data.name_ptr),
20107 +               &vc_data.space_used, &vc_data.space_total,
20108 +               &vc_data.inodes_used, &vc_data.inodes_total,
20109 +               &vc_data.reserved, &vc_data.flags);
20110 +       if (ret)
20111 +               return ret;
20112 +
20113 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
20114 +               return -EFAULT;
20115 +       return 0;
20116 +}
20117 +
20118 +#endif /* CONFIG_COMPAT */
20119 +
20120 +
20121 +void vx_vsi_statfs(struct super_block *sb, struct kstatfs *buf)
20122 +{
20123 +       struct dl_info *dli;
20124 +       __u64 blimit, bfree, bavail;
20125 +       __u32 ifree;
20126 +
20127 +       dli = locate_dl_info(sb, dx_current_tag());
20128 +       if (!dli)
20129 +               return;
20130 +
20131 +       spin_lock(&dli->dl_lock);
20132 +       if (dli->dl_inodes_total == (unsigned long)DLIM_INFINITY)
20133 +               goto no_ilim;
20134 +
20135 +       /* reduce max inodes available to limit */
20136 +       if (buf->f_files > dli->dl_inodes_total)
20137 +               buf->f_files = dli->dl_inodes_total;
20138 +
20139 +       ifree = dli->dl_inodes_total - dli->dl_inodes_used;
20140 +       /* reduce free inodes to min */
20141 +       if (ifree < buf->f_ffree)
20142 +               buf->f_ffree = ifree;
20143 +
20144 +no_ilim:
20145 +       if (dli->dl_space_total == DLIM_INFINITY)
20146 +               goto no_blim;
20147 +
20148 +       blimit = dli->dl_space_total >> sb->s_blocksize_bits;
20149 +
20150 +       if (dli->dl_space_total < dli->dl_space_used)
20151 +               bfree = 0;
20152 +       else
20153 +               bfree = (dli->dl_space_total - dli->dl_space_used)
20154 +                       >> sb->s_blocksize_bits;
20155 +
20156 +       bavail = ((dli->dl_space_total >> 10) * dli->dl_nrlmult);
20157 +       if (bavail < dli->dl_space_used)
20158 +               bavail = 0;
20159 +       else
20160 +               bavail = (bavail - dli->dl_space_used)
20161 +                       >> sb->s_blocksize_bits;
20162 +
20163 +       /* reduce max space available to limit */
20164 +       if (buf->f_blocks > blimit)
20165 +               buf->f_blocks = blimit;
20166 +
20167 +       /* reduce free space to min */
20168 +       if (bfree < buf->f_bfree)
20169 +               buf->f_bfree = bfree;
20170 +
20171 +       /* reduce avail space to min */
20172 +       if (bavail < buf->f_bavail)
20173 +               buf->f_bavail = bavail;
20174 +
20175 +no_blim:
20176 +       spin_unlock(&dli->dl_lock);
20177 +       put_dl_info(dli);
20178 +
20179 +       return;
20180 +}
20181 +
20182 +#include <linux/module.h>
20183 +
20184 +EXPORT_SYMBOL_GPL(locate_dl_info);
20185 +EXPORT_SYMBOL_GPL(rcu_free_dl_info);
20186 +
20187 diff -NurpP --minimal linux-2.6.32.6/kernel/vserver/helper.c linux-2.6.32.6-vs2.3.0.36.28/kernel/vserver/helper.c
20188 --- linux-2.6.32.6/kernel/vserver/helper.c      1970-01-01 01:00:00.000000000 +0100
20189 +++ linux-2.6.32.6-vs2.3.0.36.28/kernel/vserver/helper.c        2009-12-03 22:20:22.000000000 +0100
20190 @@ -0,0 +1,223 @@
20191 +/*
20192 + *  linux/kernel/vserver/helper.c
20193 + *
20194 + *  Virtual Context Support
20195 + *
20196 + *  Copyright (C) 2004-2007  Herbert Pötzl
20197 + *
20198 + *  V0.01  basic helper
20199 + *
20200 + */
20201 +
20202 +#include <linux/kmod.h>
20203 +#include <linux/reboot.h>
20204 +#include <linux/vs_context.h>
20205 +#include <linux/vs_network.h>
20206 +#include <linux/vserver/signal.h>
20207 +
20208 +
20209 +char vshelper_path[255] = "/sbin/vshelper";
20210 +
20211 +
20212 +static int do_vshelper(char *name, char *argv[], char *envp[], int sync)
20213 +{
20214 +       int ret;
20215 +
20216 +       if ((ret = call_usermodehelper(name, argv, envp, sync))) {
20217 +               printk( KERN_WARNING
20218 +                       "%s: (%s %s) returned %s with %d\n",
20219 +                       name, argv[1], argv[2],
20220 +                       sync ? "sync" : "async", ret);
20221 +       }
20222 +       vxdprintk(VXD_CBIT(switch, 4),
20223 +               "%s: (%s %s) returned %s with %d",
20224 +               name, argv[1], argv[2], sync ? "sync" : "async", ret);
20225 +       return ret;
20226 +}
20227 +
20228 +/*
20229 + *      vshelper path is set via /proc/sys
20230 + *      invoked by vserver sys_reboot(), with
20231 + *      the following arguments
20232 + *
20233 + *      argv [0] = vshelper_path;
20234 + *      argv [1] = action: "restart", "halt", "poweroff", ...
20235 + *      argv [2] = context identifier
20236 + *
20237 + *      envp [*] = type-specific parameters
20238 + */
20239 +
20240 +long vs_reboot_helper(struct vx_info *vxi, int cmd, void __user *arg)
20241 +{
20242 +       char id_buf[8], cmd_buf[16];
20243 +       char uid_buf[16], pid_buf[16];
20244 +       int ret;
20245 +
20246 +       char *argv[] = {vshelper_path, NULL, id_buf, 0};
20247 +       char *envp[] = {"HOME=/", "TERM=linux",
20248 +                       "PATH=/sbin:/usr/sbin:/bin:/usr/bin",
20249 +                       uid_buf, pid_buf, cmd_buf, 0};
20250 +
20251 +       if (vx_info_state(vxi, VXS_HELPER))
20252 +               return -EAGAIN;
20253 +       vxi->vx_state |= VXS_HELPER;
20254 +
20255 +       snprintf(id_buf, sizeof(id_buf)-1, "%d", vxi->vx_id);
20256 +
20257 +       snprintf(cmd_buf, sizeof(cmd_buf)-1, "VS_CMD=%08x", cmd);
20258 +       snprintf(uid_buf, sizeof(uid_buf)-1, "VS_UID=%d", current_uid());
20259 +       snprintf(pid_buf, sizeof(pid_buf)-1, "VS_PID=%d", current->pid);
20260 +
20261 +       switch (cmd) {
20262 +       case LINUX_REBOOT_CMD_RESTART:
20263 +               argv[1] = "restart";
20264 +               break;
20265 +
20266 +       case LINUX_REBOOT_CMD_HALT:
20267 +               argv[1] = "halt";
20268 +               break;
20269 +
20270 +       case LINUX_REBOOT_CMD_POWER_OFF:
20271 +               argv[1] = "poweroff";
20272 +               break;
20273 +
20274 +       case LINUX_REBOOT_CMD_SW_SUSPEND:
20275 +               argv[1] = "swsusp";
20276 +               break;
20277 +
20278 +       case LINUX_REBOOT_CMD_OOM:
20279 +               argv[1] = "oom";
20280 +               break;
20281 +
20282 +       default:
20283 +               vxi->vx_state &= ~VXS_HELPER;
20284 +               return 0;
20285 +       }
20286 +
20287 +       ret = do_vshelper(vshelper_path, argv, envp, 0);
20288 +       vxi->vx_state &= ~VXS_HELPER;
20289 +       __wakeup_vx_info(vxi);
20290 +       return (ret) ? -EPERM : 0;
20291 +}
20292 +
20293 +
20294 +long vs_reboot(unsigned int cmd, void __user *arg)
20295 +{
20296 +       struct vx_info *vxi = current_vx_info();
20297 +       long ret = 0;
20298 +
20299 +       vxdprintk(VXD_CBIT(misc, 5),
20300 +               "vs_reboot(%p[#%d],%u)",
20301 +               vxi, vxi ? vxi->vx_id : 0, cmd);
20302 +
20303 +       ret = vs_reboot_helper(vxi, cmd, arg);
20304 +       if (ret)
20305 +               return ret;
20306 +
20307 +       vxi->reboot_cmd = cmd;
20308 +       if (vx_info_flags(vxi, VXF_REBOOT_KILL, 0)) {
20309 +               switch (cmd) {
20310 +               case LINUX_REBOOT_CMD_RESTART:
20311 +               case LINUX_REBOOT_CMD_HALT:
20312 +               case LINUX_REBOOT_CMD_POWER_OFF:
20313 +                       vx_info_kill(vxi, 0, SIGKILL);
20314 +                       vx_info_kill(vxi, 1, SIGKILL);
20315 +               default:
20316 +                       break;
20317 +               }
20318 +       }
20319 +       return 0;
20320 +}
20321 +
20322 +long vs_oom_action(unsigned int cmd)
20323 +{
20324 +       struct vx_info *vxi = current_vx_info();
20325 +       long ret = 0;
20326 +
20327 +       vxdprintk(VXD_CBIT(misc, 5),
20328 +               "vs_oom_action(%p[#%d],%u)",
20329 +               vxi, vxi ? vxi->vx_id : 0, cmd);
20330 +
20331 +       ret = vs_reboot_helper(vxi, cmd, NULL);
20332 +       if (ret)
20333 +               return ret;
20334 +
20335 +       vxi->reboot_cmd = cmd;
20336 +       if (vx_info_flags(vxi, VXF_REBOOT_KILL, 0)) {
20337 +               vx_info_kill(vxi, 0, SIGKILL);
20338 +               vx_info_kill(vxi, 1, SIGKILL);
20339 +       }
20340 +       return 0;
20341 +}
20342 +
20343 +/*
20344 + *      argv [0] = vshelper_path;
20345 + *      argv [1] = action: "startup", "shutdown"
20346 + *      argv [2] = context identifier
20347 + *
20348 + *      envp [*] = type-specific parameters
20349 + */
20350 +
20351 +long vs_state_change(struct vx_info *vxi, unsigned int cmd)
20352 +{
20353 +       char id_buf[8], cmd_buf[16];
20354 +       char *argv[] = {vshelper_path, NULL, id_buf, 0};
20355 +       char *envp[] = {"HOME=/", "TERM=linux",
20356 +                       "PATH=/sbin:/usr/sbin:/bin:/usr/bin", cmd_buf, 0};
20357 +
20358 +       if (!vx_info_flags(vxi, VXF_SC_HELPER, 0))
20359 +               return 0;
20360 +
20361 +       snprintf(id_buf, sizeof(id_buf)-1, "%d", vxi->vx_id);
20362 +       snprintf(cmd_buf, sizeof(cmd_buf)-1, "VS_CMD=%08x", cmd);
20363 +
20364 +       switch (cmd) {
20365 +       case VSC_STARTUP:
20366 +               argv[1] = "startup";
20367 +               break;
20368 +       case VSC_SHUTDOWN:
20369 +               argv[1] = "shutdown";
20370 +               break;
20371 +       default:
20372 +               return 0;
20373 +       }
20374 +
20375 +       return do_vshelper(vshelper_path, argv, envp, 1);
20376 +}
20377 +
20378 +
20379 +/*
20380 + *      argv [0] = vshelper_path;
20381 + *      argv [1] = action: "netup", "netdown"
20382 + *      argv [2] = context identifier
20383 + *
20384 + *      envp [*] = type-specific parameters
20385 + */
20386 +
20387 +long vs_net_change(struct nx_info *nxi, unsigned int cmd)
20388 +{
20389 +       char id_buf[8], cmd_buf[16];
20390 +       char *argv[] = {vshelper_path, NULL, id_buf, 0};
20391 +       char *envp[] = {"HOME=/", "TERM=linux",
20392 +                       "PATH=/sbin:/usr/sbin:/bin:/usr/bin", cmd_buf, 0};
20393 +
20394 +       if (!nx_info_flags(nxi, NXF_SC_HELPER, 0))
20395 +               return 0;
20396 +
20397 +       snprintf(id_buf, sizeof(id_buf)-1, "%d", nxi->nx_id);
20398 +       snprintf(cmd_buf, sizeof(cmd_buf)-1, "VS_CMD=%08x", cmd);
20399 +
20400 +       switch (cmd) {
20401 +       case VSC_NETUP:
20402 +               argv[1] = "netup";
20403 +               break;
20404 +       case VSC_NETDOWN:
20405 +               argv[1] = "netdown";
20406 +               break;
20407 +       default:
20408 +               return 0;
20409 +       }
20410 +
20411 +       return do_vshelper(vshelper_path, argv, envp, 1);
20412 +}
20413 +
20414 diff -NurpP --minimal linux-2.6.32.6/kernel/vserver/history.c linux-2.6.32.6-vs2.3.0.36.28/kernel/vserver/history.c
20415 --- linux-2.6.32.6/kernel/vserver/history.c     1970-01-01 01:00:00.000000000 +0100
20416 +++ linux-2.6.32.6-vs2.3.0.36.28/kernel/vserver/history.c       2009-12-03 20:04:56.000000000 +0100
20417 @@ -0,0 +1,258 @@
20418 +/*
20419 + *  kernel/vserver/history.c
20420 + *
20421 + *  Virtual Context History Backtrace
20422 + *
20423 + *  Copyright (C) 2004-2007  Herbert Pötzl
20424 + *
20425 + *  V0.01  basic structure
20426 + *  V0.02  hash/unhash and trace
20427 + *  V0.03  preemption fixes
20428 + *
20429 + */
20430 +
20431 +#include <linux/module.h>
20432 +#include <asm/uaccess.h>
20433 +
20434 +#include <linux/vserver/context.h>
20435 +#include <linux/vserver/debug.h>
20436 +#include <linux/vserver/debug_cmd.h>
20437 +#include <linux/vserver/history.h>
20438 +
20439 +
20440 +#ifdef CONFIG_VSERVER_HISTORY
20441 +#define VXH_SIZE       CONFIG_VSERVER_HISTORY_SIZE
20442 +#else
20443 +#define VXH_SIZE       64
20444 +#endif
20445 +
20446 +struct _vx_history {
20447 +       unsigned int counter;
20448 +
20449 +       struct _vx_hist_entry entry[VXH_SIZE + 1];
20450 +};
20451 +
20452 +
20453 +DEFINE_PER_CPU(struct _vx_history, vx_history_buffer);
20454 +
20455 +unsigned volatile int vxh_active = 1;
20456 +
20457 +static atomic_t sequence = ATOMIC_INIT(0);
20458 +
20459 +
20460 +/*     vxh_advance()
20461 +
20462 +       * requires disabled preemption                          */
20463 +
20464 +struct _vx_hist_entry *vxh_advance(void *loc)
20465 +{
20466 +       unsigned int cpu = smp_processor_id();
20467 +       struct _vx_history *hist = &per_cpu(vx_history_buffer, cpu);
20468 +       struct _vx_hist_entry *entry;
20469 +       unsigned int index;
20470 +
20471 +       index = vxh_active ? (hist->counter++ % VXH_SIZE) : VXH_SIZE;
20472 +       entry = &hist->entry[index];
20473 +
20474 +       entry->seq = atomic_inc_return(&sequence);
20475 +       entry->loc = loc;
20476 +       return entry;
20477 +}
20478 +
20479 +EXPORT_SYMBOL_GPL(vxh_advance);
20480 +
20481 +
20482 +#define VXH_LOC_FMTS   "(#%04x,*%d):%p"
20483 +
20484 +#define VXH_LOC_ARGS(e)        (e)->seq, cpu, (e)->loc
20485 +
20486 +
20487 +#define VXH_VXI_FMTS   "%p[#%d,%d.%d]"
20488 +
20489 +#define VXH_VXI_ARGS(e)        (e)->vxi.ptr,                           \
20490 +                       (e)->vxi.ptr ? (e)->vxi.xid : 0,        \
20491 +                       (e)->vxi.ptr ? (e)->vxi.usecnt : 0,     \
20492 +                       (e)->vxi.ptr ? (e)->vxi.tasks : 0
20493 +
20494 +void   vxh_dump_entry(struct _vx_hist_entry *e, unsigned cpu)
20495 +{
20496 +       switch (e->type) {
20497 +       case VXH_THROW_OOPS:
20498 +               printk( VXH_LOC_FMTS " oops \n", VXH_LOC_ARGS(e));
20499 +               break;
20500 +
20501 +       case VXH_GET_VX_INFO:
20502 +       case VXH_PUT_VX_INFO:
20503 +               printk( VXH_LOC_FMTS " %s_vx_info " VXH_VXI_FMTS "\n",
20504 +                       VXH_LOC_ARGS(e),
20505 +                       (e->type == VXH_GET_VX_INFO) ? "get" : "put",
20506 +                       VXH_VXI_ARGS(e));
20507 +               break;
20508 +
20509 +       case VXH_INIT_VX_INFO:
20510 +       case VXH_SET_VX_INFO:
20511 +       case VXH_CLR_VX_INFO:
20512 +               printk( VXH_LOC_FMTS " %s_vx_info " VXH_VXI_FMTS " @%p\n",
20513 +                       VXH_LOC_ARGS(e),
20514 +                       (e->type == VXH_INIT_VX_INFO) ? "init" :
20515 +                       ((e->type == VXH_SET_VX_INFO) ? "set" : "clr"),
20516 +                       VXH_VXI_ARGS(e), e->sc.data);
20517 +               break;
20518 +
20519 +       case VXH_CLAIM_VX_INFO:
20520 +       case VXH_RELEASE_VX_INFO:
20521 +               printk( VXH_LOC_FMTS " %s_vx_info " VXH_VXI_FMTS " @%p\n",
20522 +                       VXH_LOC_ARGS(e),
20523 +                       (e->type == VXH_CLAIM_VX_INFO) ? "claim" : "release",
20524 +                       VXH_VXI_ARGS(e), e->sc.data);
20525 +               break;
20526 +
20527 +       case VXH_ALLOC_VX_INFO:
20528 +       case VXH_DEALLOC_VX_INFO:
20529 +               printk( VXH_LOC_FMTS " %s_vx_info " VXH_VXI_FMTS "\n",
20530 +                       VXH_LOC_ARGS(e),
20531 +                       (e->type == VXH_ALLOC_VX_INFO) ? "alloc" : "dealloc",
20532 +                       VXH_VXI_ARGS(e));
20533 +               break;
20534 +
20535 +       case VXH_HASH_VX_INFO:
20536 +       case VXH_UNHASH_VX_INFO:
20537 +               printk( VXH_LOC_FMTS " __%s_vx_info " VXH_VXI_FMTS "\n",
20538 +                       VXH_LOC_ARGS(e),
20539 +                       (e->type == VXH_HASH_VX_INFO) ? "hash" : "unhash",
20540 +                       VXH_VXI_ARGS(e));
20541 +               break;
20542 +
20543 +       case VXH_LOC_VX_INFO:
20544 +       case VXH_LOOKUP_VX_INFO:
20545 +       case VXH_CREATE_VX_INFO:
20546 +               printk( VXH_LOC_FMTS " __%s_vx_info [#%d] -> " VXH_VXI_FMTS "\n",
20547 +                       VXH_LOC_ARGS(e),
20548 +                       (e->type == VXH_CREATE_VX_INFO) ? "create" :
20549 +                       ((e->type == VXH_LOC_VX_INFO) ? "loc" : "lookup"),
20550 +                       e->ll.arg, VXH_VXI_ARGS(e));
20551 +               break;
20552 +       }
20553 +}
20554 +
20555 +static void __vxh_dump_history(void)
20556 +{
20557 +       unsigned int i, cpu;
20558 +
20559 +       printk("History:\tSEQ: %8x\tNR_CPUS: %d\n",
20560 +               atomic_read(&sequence), NR_CPUS);
20561 +
20562 +       for (i = 0; i < VXH_SIZE; i++) {
20563 +               for_each_online_cpu(cpu) {
20564 +                       struct _vx_history *hist =
20565 +                               &per_cpu(vx_history_buffer, cpu);
20566 +                       unsigned int index = (hist->counter - i) % VXH_SIZE;
20567 +                       struct _vx_hist_entry *entry = &hist->entry[index];
20568 +
20569 +                       vxh_dump_entry(entry, cpu);
20570 +               }
20571 +       }
20572 +}
20573 +
20574 +void   vxh_dump_history(void)
20575 +{
20576 +       vxh_active = 0;
20577 +#ifdef CONFIG_SMP
20578 +       local_irq_enable();
20579 +       smp_send_stop();
20580 +       local_irq_disable();
20581 +#endif
20582 +       __vxh_dump_history();
20583 +}
20584 +
20585 +
20586 +/* vserver syscall commands below here */
20587 +
20588 +
20589 +int vc_dump_history(uint32_t id)
20590 +{
20591 +       vxh_active = 0;
20592 +       __vxh_dump_history();
20593 +       vxh_active = 1;
20594 +
20595 +       return 0;
20596 +}
20597 +
20598 +
20599 +int do_read_history(struct __user _vx_hist_entry *data,
20600 +       int cpu, uint32_t *index, uint32_t *count)
20601 +{
20602 +       int pos, ret = 0;
20603 +       struct _vx_history *hist = &per_cpu(vx_history_buffer, cpu);
20604 +       int end = hist->counter;
20605 +       int start = end - VXH_SIZE + 2;
20606 +       int idx = *index;
20607 +
20608 +       /* special case: get current pos */
20609 +       if (!*count) {
20610 +               *index = end;
20611 +               return 0;
20612 +       }
20613 +
20614 +       /* have we lost some data? */
20615 +       if (idx < start)
20616 +               idx = start;
20617 +
20618 +       for (pos = 0; (pos < *count) && (idx < end); pos++, idx++) {
20619 +               struct _vx_hist_entry *entry =
20620 +                       &hist->entry[idx % VXH_SIZE];
20621 +
20622 +               /* send entry to userspace */
20623 +               ret = copy_to_user(&data[pos], entry, sizeof(*entry));
20624 +               if (ret)
20625 +                       break;
20626 +       }
20627 +       /* save new index and count */
20628 +       *index = idx;
20629 +       *count = pos;
20630 +       return ret ? ret : (*index < end);
20631 +}
20632 +
20633 +int vc_read_history(uint32_t id, void __user *data)
20634 +{
20635 +       struct vcmd_read_history_v0 vc_data;
20636 +       int ret;
20637 +
20638 +       if (id >= NR_CPUS)
20639 +               return -EINVAL;
20640 +
20641 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
20642 +               return -EFAULT;
20643 +
20644 +       ret = do_read_history((struct __user _vx_hist_entry *)vc_data.data,
20645 +               id, &vc_data.index, &vc_data.count);
20646 +
20647 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
20648 +               return -EFAULT;
20649 +       return ret;
20650 +}
20651 +
20652 +#ifdef CONFIG_COMPAT
20653 +
20654 +int vc_read_history_x32(uint32_t id, void __user *data)
20655 +{
20656 +       struct vcmd_read_history_v0_x32 vc_data;
20657 +       int ret;
20658 +
20659 +       if (id >= NR_CPUS)
20660 +               return -EINVAL;
20661 +
20662 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
20663 +               return -EFAULT;
20664 +
20665 +       ret = do_read_history((struct __user _vx_hist_entry *)
20666 +               compat_ptr(vc_data.data_ptr),
20667 +               id, &vc_data.index, &vc_data.count);
20668 +
20669 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
20670 +               return -EFAULT;
20671 +       return ret;
20672 +}
20673 +
20674 +#endif /* CONFIG_COMPAT */
20675 +
20676 diff -NurpP --minimal linux-2.6.32.6/kernel/vserver/inet.c linux-2.6.32.6-vs2.3.0.36.28/kernel/vserver/inet.c
20677 --- linux-2.6.32.6/kernel/vserver/inet.c        1970-01-01 01:00:00.000000000 +0100
20678 +++ linux-2.6.32.6-vs2.3.0.36.28/kernel/vserver/inet.c  2009-12-03 20:04:56.000000000 +0100
20679 @@ -0,0 +1,225 @@
20680 +
20681 +#include <linux/in.h>
20682 +#include <linux/inetdevice.h>
20683 +#include <linux/vs_inet.h>
20684 +#include <linux/vs_inet6.h>
20685 +#include <linux/vserver/debug.h>
20686 +#include <net/route.h>
20687 +#include <net/addrconf.h>
20688 +
20689 +
20690 +int nx_v4_addr_conflict(struct nx_info *nxi1, struct nx_info *nxi2)
20691 +{
20692 +       int ret = 0;
20693 +
20694 +       if (!nxi1 || !nxi2 || nxi1 == nxi2)
20695 +               ret = 1;
20696 +       else {
20697 +               struct nx_addr_v4 *ptr;
20698 +
20699 +               for (ptr = &nxi1->v4; ptr; ptr = ptr->next) {
20700 +                       if (v4_nx_addr_in_nx_info(nxi2, ptr, -1)) {
20701 +                               ret = 1;
20702 +                               break;
20703 +                       }
20704 +               }
20705 +       }
20706 +
20707 +       vxdprintk(VXD_CBIT(net, 2),
20708 +               "nx_v4_addr_conflict(%p,%p): %d",
20709 +               nxi1, nxi2, ret);
20710 +
20711 +       return ret;
20712 +}
20713 +
20714 +
20715 +#ifdef CONFIG_IPV6
20716 +
20717 +int nx_v6_addr_conflict(struct nx_info *nxi1, struct nx_info *nxi2)
20718 +{
20719 +       int ret = 0;
20720 +
20721 +       if (!nxi1 || !nxi2 || nxi1 == nxi2)
20722 +               ret = 1;
20723 +       else {
20724 +               struct nx_addr_v6 *ptr;
20725 +
20726 +               for (ptr = &nxi1->v6; ptr; ptr = ptr->next) {
20727 +                       if (v6_nx_addr_in_nx_info(nxi2, ptr, -1)) {
20728 +                               ret = 1;
20729 +                               break;
20730 +                       }
20731 +               }
20732 +       }
20733 +
20734 +       vxdprintk(VXD_CBIT(net, 2),
20735 +               "nx_v6_addr_conflict(%p,%p): %d",
20736 +               nxi1, nxi2, ret);
20737 +
20738 +       return ret;
20739 +}
20740 +
20741 +#endif
20742 +
20743 +int v4_dev_in_nx_info(struct net_device *dev, struct nx_info *nxi)
20744 +{
20745 +       struct in_device *in_dev;
20746 +       struct in_ifaddr **ifap;
20747 +       struct in_ifaddr *ifa;
20748 +       int ret = 0;
20749 +
20750 +       if (!dev)
20751 +               goto out;
20752 +       in_dev = in_dev_get(dev);
20753 +       if (!in_dev)
20754 +               goto out;
20755 +
20756 +       for (ifap = &in_dev->ifa_list; (ifa = *ifap) != NULL;
20757 +               ifap = &ifa->ifa_next) {
20758 +               if (v4_addr_in_nx_info(nxi, ifa->ifa_local, NXA_MASK_SHOW)) {
20759 +                       ret = 1;
20760 +                       break;
20761 +               }
20762 +       }
20763 +       in_dev_put(in_dev);
20764 +out:
20765 +       return ret;
20766 +}
20767 +
20768 +
20769 +#ifdef CONFIG_IPV6
20770 +
20771 +int v6_dev_in_nx_info(struct net_device *dev, struct nx_info *nxi)
20772 +{
20773 +       struct inet6_dev *in_dev;
20774 +       struct inet6_ifaddr **ifap;
20775 +       struct inet6_ifaddr *ifa;
20776 +       int ret = 0;
20777 +
20778 +       if (!dev)
20779 +               goto out;
20780 +       in_dev = in6_dev_get(dev);
20781 +       if (!in_dev)
20782 +               goto out;
20783 +
20784 +       for (ifap = &in_dev->addr_list; (ifa = *ifap) != NULL;
20785 +               ifap = &ifa->if_next) {
20786 +               if (v6_addr_in_nx_info(nxi, &ifa->addr, -1)) {
20787 +                       ret = 1;
20788 +                       break;
20789 +               }
20790 +       }
20791 +       in6_dev_put(in_dev);
20792 +out:
20793 +       return ret;
20794 +}
20795 +
20796 +#endif
20797 +
20798 +int dev_in_nx_info(struct net_device *dev, struct nx_info *nxi)
20799 +{
20800 +       int ret = 1;
20801 +
20802 +       if (!nxi)
20803 +               goto out;
20804 +       if (nxi->v4.type && v4_dev_in_nx_info(dev, nxi))
20805 +               goto out;
20806 +#ifdef CONFIG_IPV6
20807 +       ret = 2;
20808 +       if (nxi->v6.type && v6_dev_in_nx_info(dev, nxi))
20809 +               goto out;
20810 +#endif
20811 +       ret = 0;
20812 +out:
20813 +       vxdprintk(VXD_CBIT(net, 3),
20814 +               "dev_in_nx_info(%p,%p[#%d]) = %d",
20815 +               dev, nxi, nxi ? nxi->nx_id : 0, ret);
20816 +       return ret;
20817 +}
20818 +
20819 +int ip_v4_find_src(struct net *net, struct nx_info *nxi,
20820 +       struct rtable **rp, struct flowi *fl)
20821 +{
20822 +       if (!nxi)
20823 +               return 0;
20824 +
20825 +       /* FIXME: handle lback only case */
20826 +       if (!NX_IPV4(nxi))
20827 +               return -EPERM;
20828 +
20829 +       vxdprintk(VXD_CBIT(net, 4),
20830 +               "ip_v4_find_src(%p[#%u]) " NIPQUAD_FMT " -> " NIPQUAD_FMT,
20831 +               nxi, nxi ? nxi->nx_id : 0,
20832 +               NIPQUAD(fl->fl4_src), NIPQUAD(fl->fl4_dst));
20833 +
20834 +       /* single IP is unconditional */
20835 +       if (nx_info_flags(nxi, NXF_SINGLE_IP, 0) &&
20836 +               (fl->fl4_src == INADDR_ANY))
20837 +               fl->fl4_src = nxi->v4.ip[0].s_addr;
20838 +
20839 +       if (fl->fl4_src == INADDR_ANY) {
20840 +               struct nx_addr_v4 *ptr;
20841 +               __be32 found = 0;
20842 +               int err;
20843 +
20844 +               err = __ip_route_output_key(net, rp, fl);
20845 +               if (!err) {
20846 +                       found = (*rp)->rt_src;
20847 +                       ip_rt_put(*rp);
20848 +                       vxdprintk(VXD_CBIT(net, 4),
20849 +                               "ip_v4_find_src(%p[#%u]) rok[%u]: " NIPQUAD_FMT,
20850 +                               nxi, nxi ? nxi->nx_id : 0, fl->oif, NIPQUAD(found));
20851 +                       if (v4_addr_in_nx_info(nxi, found, NXA_MASK_BIND))
20852 +                               goto found;
20853 +               }
20854 +
20855 +               for (ptr = &nxi->v4; ptr; ptr = ptr->next) {
20856 +                       __be32 primary = ptr->ip[0].s_addr;
20857 +                       __be32 mask = ptr->mask.s_addr;
20858 +                       __be32 neta = primary & mask;
20859 +
20860 +                       vxdprintk(VXD_CBIT(net, 4), "ip_v4_find_src(%p[#%u]) chk: "
20861 +                               NIPQUAD_FMT "/" NIPQUAD_FMT "/" NIPQUAD_FMT,
20862 +                               nxi, nxi ? nxi->nx_id : 0, NIPQUAD(primary),
20863 +                               NIPQUAD(mask), NIPQUAD(neta));
20864 +                       if ((found & mask) != neta)
20865 +                               continue;
20866 +
20867 +                       fl->fl4_src = primary;
20868 +                       err = __ip_route_output_key(net, rp, fl);
20869 +                       vxdprintk(VXD_CBIT(net, 4),
20870 +                               "ip_v4_find_src(%p[#%u]) rok[%u]: " NIPQUAD_FMT,
20871 +                               nxi, nxi ? nxi->nx_id : 0, fl->oif, NIPQUAD(primary));
20872 +                       if (!err) {
20873 +                               found = (*rp)->rt_src;
20874 +                               ip_rt_put(*rp);
20875 +                               if (found == primary)
20876 +                                       goto found;
20877 +                       }
20878 +               }
20879 +               /* still no source ip? */
20880 +               found = ipv4_is_loopback(fl->fl4_dst)
20881 +                       ? IPI_LOOPBACK : nxi->v4.ip[0].s_addr;
20882 +       found:
20883 +               /* assign src ip to flow */
20884 +               fl->fl4_src = found;
20885 +
20886 +       } else {
20887 +               if (!v4_addr_in_nx_info(nxi, fl->fl4_src, NXA_MASK_BIND))
20888 +                       return -EPERM;
20889 +       }
20890 +
20891 +       if (nx_info_flags(nxi, NXF_LBACK_REMAP, 0)) {
20892 +               if (ipv4_is_loopback(fl->fl4_dst))
20893 +                       fl->fl4_dst = nxi->v4_lback.s_addr;
20894 +               if (ipv4_is_loopback(fl->fl4_src))
20895 +                       fl->fl4_src = nxi->v4_lback.s_addr;
20896 +       } else if (ipv4_is_loopback(fl->fl4_dst) &&
20897 +               !nx_info_flags(nxi, NXF_LBACK_ALLOW, 0))
20898 +               return -EPERM;
20899 +
20900 +       return 0;
20901 +}
20902 +
20903 +EXPORT_SYMBOL_GPL(ip_v4_find_src);
20904 +
20905 diff -NurpP --minimal linux-2.6.32.6/kernel/vserver/init.c linux-2.6.32.6-vs2.3.0.36.28/kernel/vserver/init.c
20906 --- linux-2.6.32.6/kernel/vserver/init.c        1970-01-01 01:00:00.000000000 +0100
20907 +++ linux-2.6.32.6-vs2.3.0.36.28/kernel/vserver/init.c  2009-12-03 20:04:56.000000000 +0100
20908 @@ -0,0 +1,45 @@
20909 +/*
20910 + *  linux/kernel/init.c
20911 + *
20912 + *  Virtual Server Init
20913 + *
20914 + *  Copyright (C) 2004-2007  Herbert Pötzl
20915 + *
20916 + *  V0.01  basic structure
20917 + *
20918 + */
20919 +
20920 +#include <linux/init.h>
20921 +
20922 +int    vserver_register_sysctl(void);
20923 +void   vserver_unregister_sysctl(void);
20924 +
20925 +
20926 +static int __init init_vserver(void)
20927 +{
20928 +       int ret = 0;
20929 +
20930 +#ifdef CONFIG_VSERVER_DEBUG
20931 +       vserver_register_sysctl();
20932 +#endif
20933 +       return ret;
20934 +}
20935 +
20936 +
20937 +static void __exit exit_vserver(void)
20938 +{
20939 +
20940 +#ifdef CONFIG_VSERVER_DEBUG
20941 +       vserver_unregister_sysctl();
20942 +#endif
20943 +       return;
20944 +}
20945 +
20946 +/* FIXME: GFP_ZONETYPES gone
20947 +long vx_slab[GFP_ZONETYPES]; */
20948 +long vx_area;
20949 +
20950 +
20951 +module_init(init_vserver);
20952 +module_exit(exit_vserver);
20953 +
20954 diff -NurpP --minimal linux-2.6.32.6/kernel/vserver/inode.c linux-2.6.32.6-vs2.3.0.36.28/kernel/vserver/inode.c
20955 --- linux-2.6.32.6/kernel/vserver/inode.c       1970-01-01 01:00:00.000000000 +0100
20956 +++ linux-2.6.32.6-vs2.3.0.36.28/kernel/vserver/inode.c 2009-12-03 20:04:56.000000000 +0100
20957 @@ -0,0 +1,433 @@
20958 +/*
20959 + *  linux/kernel/vserver/inode.c
20960 + *
20961 + *  Virtual Server: File System Support
20962 + *
20963 + *  Copyright (C) 2004-2007  Herbert Pötzl
20964 + *
20965 + *  V0.01  separated from vcontext V0.05
20966 + *  V0.02  moved to tag (instead of xid)
20967 + *
20968 + */
20969 +
20970 +#include <linux/tty.h>
20971 +#include <linux/proc_fs.h>
20972 +#include <linux/devpts_fs.h>
20973 +#include <linux/fs.h>
20974 +#include <linux/file.h>
20975 +#include <linux/mount.h>
20976 +#include <linux/parser.h>
20977 +#include <linux/namei.h>
20978 +#include <linux/vserver/inode.h>
20979 +#include <linux/vserver/inode_cmd.h>
20980 +#include <linux/vs_base.h>
20981 +#include <linux/vs_tag.h>
20982 +
20983 +#include <asm/uaccess.h>
20984 +
20985 +
20986 +static int __vc_get_iattr(struct inode *in, uint32_t *tag, uint32_t *flags, uint32_t *mask)
20987 +{
20988 +       struct proc_dir_entry *entry;
20989 +
20990 +       if (!in || !in->i_sb)
20991 +               return -ESRCH;
20992 +
20993 +       *flags = IATTR_TAG
20994 +               | (IS_IMMUTABLE(in) ? IATTR_IMMUTABLE : 0)
20995 +               | (IS_IXUNLINK(in) ? IATTR_IXUNLINK : 0)
20996 +               | (IS_BARRIER(in) ? IATTR_BARRIER : 0)
20997 +               | (IS_COW(in) ? IATTR_COW : 0);
20998 +       *mask = IATTR_IXUNLINK | IATTR_IMMUTABLE | IATTR_COW;
20999 +
21000 +       if (S_ISDIR(in->i_mode))
21001 +               *mask |= IATTR_BARRIER;
21002 +
21003 +       if (IS_TAGGED(in)) {
21004 +               *tag = in->i_tag;
21005 +               *mask |= IATTR_TAG;
21006 +       }
21007 +
21008 +       switch (in->i_sb->s_magic) {
21009 +       case PROC_SUPER_MAGIC:
21010 +               entry = PROC_I(in)->pde;
21011 +
21012 +               /* check for specific inodes? */
21013 +               if (entry)
21014 +                       *mask |= IATTR_FLAGS;
21015 +               if (entry)
21016 +                       *flags |= (entry->vx_flags & IATTR_FLAGS);
21017 +               else
21018 +                       *flags |= (PROC_I(in)->vx_flags & IATTR_FLAGS);
21019 +               break;
21020 +
21021 +       case DEVPTS_SUPER_MAGIC:
21022 +               *tag = in->i_tag;
21023 +               *mask |= IATTR_TAG;
21024 +               break;
21025 +
21026 +       default:
21027 +               break;
21028 +       }
21029 +       return 0;
21030 +}
21031 +
21032 +int vc_get_iattr(void __user *data)
21033 +{
21034 +       struct path path;
21035 +       struct vcmd_ctx_iattr_v1 vc_data = { .tag = -1 };
21036 +       int ret;
21037 +
21038 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
21039 +               return -EFAULT;
21040 +
21041 +       ret = user_lpath(vc_data.name, &path);
21042 +       if (!ret) {
21043 +               ret = __vc_get_iattr(path.dentry->d_inode,
21044 +                       &vc_data.tag, &vc_data.flags, &vc_data.mask);
21045 +               path_put(&path);
21046 +       }
21047 +       if (ret)
21048 +               return ret;
21049 +
21050 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
21051 +               ret = -EFAULT;
21052 +       return ret;
21053 +}
21054 +
21055 +#ifdef CONFIG_COMPAT
21056 +
21057 +int vc_get_iattr_x32(void __user *data)
21058 +{
21059 +       struct path path;
21060 +       struct vcmd_ctx_iattr_v1_x32 vc_data = { .tag = -1 };
21061 +       int ret;
21062 +
21063 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
21064 +               return -EFAULT;
21065 +
21066 +       ret = user_lpath(compat_ptr(vc_data.name_ptr), &path);
21067 +       if (!ret) {
21068 +               ret = __vc_get_iattr(path.dentry->d_inode,
21069 +                       &vc_data.tag, &vc_data.flags, &vc_data.mask);
21070 +               path_put(&path);
21071 +       }
21072 +       if (ret)
21073 +               return ret;
21074 +
21075 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
21076 +               ret = -EFAULT;
21077 +       return ret;
21078 +}
21079 +
21080 +#endif /* CONFIG_COMPAT */
21081 +
21082 +
21083 +int vc_fget_iattr(uint32_t fd, void __user *data)
21084 +{
21085 +       struct file *filp;
21086 +       struct vcmd_ctx_fiattr_v0 vc_data = { .tag = -1 };
21087 +       int ret;
21088 +
21089 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
21090 +               return -EFAULT;
21091 +
21092 +       filp = fget(fd);
21093 +       if (!filp || !filp->f_dentry || !filp->f_dentry->d_inode)
21094 +               return -EBADF;
21095 +
21096 +       ret = __vc_get_iattr(filp->f_dentry->d_inode,
21097 +               &vc_data.tag, &vc_data.flags, &vc_data.mask);
21098 +
21099 +       fput(filp);
21100 +
21101 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
21102 +               ret = -EFAULT;
21103 +       return ret;
21104 +}
21105 +
21106 +
21107 +static int __vc_set_iattr(struct dentry *de, uint32_t *tag, uint32_t *flags, uint32_t *mask)
21108 +{
21109 +       struct inode *in = de->d_inode;
21110 +       int error = 0, is_proc = 0, has_tag = 0;
21111 +       struct iattr attr = { 0 };
21112 +
21113 +       if (!in || !in->i_sb)
21114 +               return -ESRCH;
21115 +
21116 +       is_proc = (in->i_sb->s_magic == PROC_SUPER_MAGIC);
21117 +       if ((*mask & IATTR_FLAGS) && !is_proc)
21118 +               return -EINVAL;
21119 +
21120 +       has_tag = IS_TAGGED(in) ||
21121 +               (in->i_sb->s_magic == DEVPTS_SUPER_MAGIC);
21122 +       if ((*mask & IATTR_TAG) && !has_tag)
21123 +               return -EINVAL;
21124 +
21125 +       mutex_lock(&in->i_mutex);
21126 +       if (*mask & IATTR_TAG) {
21127 +               attr.ia_tag = *tag;
21128 +               attr.ia_valid |= ATTR_TAG;
21129 +       }
21130 +
21131 +       if (*mask & IATTR_FLAGS) {
21132 +               struct proc_dir_entry *entry = PROC_I(in)->pde;
21133 +               unsigned int iflags = PROC_I(in)->vx_flags;
21134 +
21135 +               iflags = (iflags & ~(*mask & IATTR_FLAGS))
21136 +                       | (*flags & IATTR_FLAGS);
21137 +               PROC_I(in)->vx_flags = iflags;
21138 +               if (entry)
21139 +                       entry->vx_flags = iflags;
21140 +       }
21141 +
21142 +       if (*mask & (IATTR_IMMUTABLE | IATTR_IXUNLINK |
21143 +               IATTR_BARRIER | IATTR_COW)) {
21144 +               int iflags = in->i_flags;
21145 +               int vflags = in->i_vflags;
21146 +
21147 +               if (*mask & IATTR_IMMUTABLE) {
21148 +                       if (*flags & IATTR_IMMUTABLE)
21149 +                               iflags |= S_IMMUTABLE;
21150 +                       else
21151 +                               iflags &= ~S_IMMUTABLE;
21152 +               }
21153 +               if (*mask & IATTR_IXUNLINK) {
21154 +                       if (*flags & IATTR_IXUNLINK)
21155 +                               iflags |= S_IXUNLINK;
21156 +                       else
21157 +                               iflags &= ~S_IXUNLINK;
21158 +               }
21159 +               if (S_ISDIR(in->i_mode) && (*mask & IATTR_BARRIER)) {
21160 +                       if (*flags & IATTR_BARRIER)
21161 +                               vflags |= V_BARRIER;
21162 +                       else
21163 +                               vflags &= ~V_BARRIER;
21164 +               }
21165 +               if (S_ISREG(in->i_mode) && (*mask & IATTR_COW)) {
21166 +                       if (*flags & IATTR_COW)
21167 +                               vflags |= V_COW;
21168 +                       else
21169 +                               vflags &= ~V_COW;
21170 +               }
21171 +               if (in->i_op && in->i_op->sync_flags) {
21172 +                       error = in->i_op->sync_flags(in, iflags, vflags);
21173 +                       if (error)
21174 +                               goto out;
21175 +               }
21176 +       }
21177 +
21178 +       if (attr.ia_valid) {
21179 +               if (in->i_op && in->i_op->setattr)
21180 +                       error = in->i_op->setattr(de, &attr);
21181 +               else {
21182 +                       error = inode_change_ok(in, &attr);
21183 +                       if (!error)
21184 +                               error = inode_setattr(in, &attr);
21185 +               }
21186 +       }
21187 +
21188 +out:
21189 +       mutex_unlock(&in->i_mutex);
21190 +       return error;
21191 +}
21192 +
21193 +int vc_set_iattr(void __user *data)
21194 +{
21195 +       struct path path;
21196 +       struct vcmd_ctx_iattr_v1 vc_data;
21197 +       int ret;
21198 +
21199 +       if (!capable(CAP_LINUX_IMMUTABLE))
21200 +               return -EPERM;
21201 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
21202 +               return -EFAULT;
21203 +
21204 +       ret = user_lpath(vc_data.name, &path);
21205 +       if (!ret) {
21206 +               ret = __vc_set_iattr(path.dentry,
21207 +                       &vc_data.tag, &vc_data.flags, &vc_data.mask);
21208 +               path_put(&path);
21209 +       }
21210 +
21211 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
21212 +               ret = -EFAULT;
21213 +       return ret;
21214 +}
21215 +
21216 +#ifdef CONFIG_COMPAT
21217 +
21218 +int vc_set_iattr_x32(void __user *data)
21219 +{
21220 +       struct path path;
21221 +       struct vcmd_ctx_iattr_v1_x32 vc_data;
21222 +       int ret;
21223 +
21224 +       if (!capable(CAP_LINUX_IMMUTABLE))
21225 +               return -EPERM;
21226 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
21227 +               return -EFAULT;
21228 +
21229 +       ret = user_lpath(compat_ptr(vc_data.name_ptr), &path);
21230 +       if (!ret) {
21231 +               ret = __vc_set_iattr(path.dentry,
21232 +                       &vc_data.tag, &vc_data.flags, &vc_data.mask);
21233 +               path_put(&path);
21234 +       }
21235 +
21236 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
21237 +               ret = -EFAULT;
21238 +       return ret;
21239 +}
21240 +
21241 +#endif /* CONFIG_COMPAT */
21242 +
21243 +int vc_fset_iattr(uint32_t fd, void __user *data)
21244 +{
21245 +       struct file *filp;
21246 +       struct vcmd_ctx_fiattr_v0 vc_data;
21247 +       int ret;
21248 +
21249 +       if (!capable(CAP_LINUX_IMMUTABLE))
21250 +               return -EPERM;
21251 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
21252 +               return -EFAULT;
21253 +
21254 +       filp = fget(fd);
21255 +       if (!filp || !filp->f_dentry || !filp->f_dentry->d_inode)
21256 +               return -EBADF;
21257 +
21258 +       ret = __vc_set_iattr(filp->f_dentry, &vc_data.tag,
21259 +               &vc_data.flags, &vc_data.mask);
21260 +
21261 +       fput(filp);
21262 +
21263 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
21264 +               return -EFAULT;
21265 +       return ret;
21266 +}
21267 +
21268 +
21269 +enum { Opt_notagcheck, Opt_tag, Opt_notag, Opt_tagid, Opt_err };
21270 +
21271 +static match_table_t tokens = {
21272 +       {Opt_notagcheck, "notagcheck"},
21273 +#ifdef CONFIG_PROPAGATE
21274 +       {Opt_notag, "notag"},
21275 +       {Opt_tag, "tag"},
21276 +       {Opt_tagid, "tagid=%u"},
21277 +#endif
21278 +       {Opt_err, NULL}
21279 +};
21280 +
21281 +
21282 +static void __dx_parse_remove(char *string, char *opt)
21283 +{
21284 +       char *p = strstr(string, opt);
21285 +       char *q = p;
21286 +
21287 +       if (p) {
21288 +               while (*q != '\0' && *q != ',')
21289 +                       q++;
21290 +               while (*q)
21291 +                       *p++ = *q++;
21292 +               while (*p)
21293 +                       *p++ = '\0';
21294 +       }
21295 +}
21296 +
21297 +int dx_parse_tag(char *string, tag_t *tag, int remove, int *mnt_flags,
21298 +                unsigned long *flags)
21299 +{
21300 +       int set = 0;
21301 +       substring_t args[MAX_OPT_ARGS];
21302 +       int token, option = 0;
21303 +       char *s, *p, *opts;
21304 +
21305 +       if (!string)
21306 +               return 0;
21307 +       s = kstrdup(string, GFP_KERNEL | GFP_ATOMIC);
21308 +       if (!s)
21309 +               return 0;
21310 +
21311 +       opts = s;
21312 +       while ((p = strsep(&opts, ",")) != NULL) {
21313 +               token = match_token(p, tokens, args);
21314 +
21315 +               vxdprintk(VXD_CBIT(tag, 7),
21316 +                       "dx_parse_tag(»%s«): %d:#%d",
21317 +                       p, token, option);
21318 +
21319 +               switch (token) {
21320 +#ifdef CONFIG_PROPAGATE
21321 +               case Opt_tag:
21322 +                       if (tag)
21323 +                               *tag = 0;
21324 +                       if (remove)
21325 +                               __dx_parse_remove(s, "tag");
21326 +                       *mnt_flags |= MNT_TAGID;
21327 +                       set |= MNT_TAGID;
21328 +                       break;
21329 +               case Opt_notag:
21330 +                       if (remove)
21331 +                               __dx_parse_remove(s, "notag");
21332 +                       *mnt_flags |= MNT_NOTAG;
21333 +                       set |= MNT_NOTAG;
21334 +                       break;
21335 +               case Opt_tagid:
21336 +                       if (tag && !match_int(args, &option))
21337 +                               *tag = option;
21338 +                       if (remove)
21339 +                               __dx_parse_remove(s, "tagid");
21340 +                       *mnt_flags |= MNT_TAGID;
21341 +                       set |= MNT_TAGID;
21342 +                       break;
21343 +#endif
21344 +               case Opt_notagcheck:
21345 +                       if (remove)
21346 +                               __dx_parse_remove(s, "notagcheck");
21347 +                       *flags |= MS_NOTAGCHECK;
21348 +                       set |= MS_NOTAGCHECK;
21349 +                       break;
21350 +               }
21351 +       }
21352 +       if (set)
21353 +               strcpy(string, s);
21354 +       kfree(s);
21355 +       return set;
21356 +}
21357 +
21358 +#ifdef CONFIG_PROPAGATE
21359 +
21360 +void __dx_propagate_tag(struct nameidata *nd, struct inode *inode)
21361 +{
21362 +       tag_t new_tag = 0;
21363 +       struct vfsmount *mnt;
21364 +       int propagate;
21365 +
21366 +       if (!nd)
21367 +               return;
21368 +       mnt = nd->path.mnt;
21369 +       if (!mnt)
21370 +               return;
21371 +
21372 +       propagate = (mnt->mnt_flags & MNT_TAGID);
21373 +       if (propagate)
21374 +               new_tag = mnt->mnt_tag;
21375 +
21376 +       vxdprintk(VXD_CBIT(tag, 7),
21377 +               "dx_propagate_tag(%p[#%lu.%d]): %d,%d",
21378 +               inode, inode->i_ino, inode->i_tag,
21379 +               new_tag, (propagate) ? 1 : 0);
21380 +
21381 +       if (propagate)
21382 +               inode->i_tag = new_tag;
21383 +}
21384 +
21385 +#include <linux/module.h>
21386 +
21387 +EXPORT_SYMBOL_GPL(__dx_propagate_tag);
21388 +
21389 +#endif /* CONFIG_PROPAGATE */
21390 +
21391 diff -NurpP --minimal linux-2.6.32.6/kernel/vserver/Kconfig linux-2.6.32.6-vs2.3.0.36.28/kernel/vserver/Kconfig
21392 --- linux-2.6.32.6/kernel/vserver/Kconfig       1970-01-01 01:00:00.000000000 +0100
21393 +++ linux-2.6.32.6-vs2.3.0.36.28/kernel/vserver/Kconfig 2009-12-03 20:04:56.000000000 +0100
21394 @@ -0,0 +1,251 @@
21395 +#
21396 +# Linux VServer configuration
21397 +#
21398 +
21399 +menu "Linux VServer"
21400 +
21401 +config VSERVER_AUTO_LBACK
21402 +       bool    "Automatically Assign Loopback IP"
21403 +       default y
21404 +       help
21405 +         Automatically assign a guest specific loopback
21406 +         IP and add it to the kernel network stack on
21407 +         startup.
21408 +
21409 +config VSERVER_AUTO_SINGLE
21410 +       bool    "Automatic Single IP Special Casing"
21411 +       depends on EXPERIMENTAL
21412 +       default y
21413 +       help
21414 +         This allows network contexts with a single IP to
21415 +         automatically remap 0.0.0.0 bindings to that IP,
21416 +         avoiding further network checks and improving
21417 +         performance.
21418 +
21419 +         (note: such guests do not allow to change the ip
21420 +          on the fly and do not show loopback addresses)
21421 +
21422 +config VSERVER_COWBL
21423 +       bool    "Enable COW Immutable Link Breaking"
21424 +       default y
21425 +       help
21426 +         This enables the COW (Copy-On-Write) link break code.
21427 +         It allows you to treat unified files like normal files
21428 +         when writing to them (which will implicitely break the
21429 +         link and create a copy of the unified file)
21430 +
21431 +config VSERVER_VTIME
21432 +       bool    "Enable Virtualized Guest Time"
21433 +       depends on EXPERIMENTAL
21434 +       default n
21435 +       help
21436 +         This enables per guest time offsets to allow for
21437 +         adjusting the system clock individually per guest.
21438 +         this adds some overhead to the time functions and
21439 +         therefore should not be enabled without good reason.
21440 +
21441 +config VSERVER_DEVICE
21442 +       bool    "Enable Guest Device Mapping"
21443 +       depends on EXPERIMENTAL
21444 +       default n
21445 +       help
21446 +         This enables generic device remapping.
21447 +
21448 +config VSERVER_PROC_SECURE
21449 +       bool    "Enable Proc Security"
21450 +       depends on PROC_FS
21451 +       default y
21452 +       help
21453 +         This configures ProcFS security to initially hide
21454 +         non-process entries for all contexts except the main and
21455 +         spectator context (i.e. for all guests), which is a secure
21456 +         default.
21457 +
21458 +         (note: on 1.2x the entries were visible by default)
21459 +
21460 +config VSERVER_HARDCPU
21461 +       bool    "Enable Hard CPU Limits"
21462 +       default y
21463 +       help
21464 +         Activate the Hard CPU Limits
21465 +
21466 +         This will compile in code that allows the Token Bucket
21467 +         Scheduler to put processes on hold when a context's
21468 +         tokens are depleted (provided that its per-context
21469 +         sched_hard flag is set).
21470 +
21471 +         Processes belonging to that context will not be able
21472 +         to consume CPU resources again until a per-context
21473 +         configured minimum of tokens has been reached.
21474 +
21475 +config VSERVER_IDLETIME
21476 +       bool    "Avoid idle CPUs by skipping Time"
21477 +       depends on VSERVER_HARDCPU
21478 +       default y
21479 +       help
21480 +         This option allows the scheduler to artificially
21481 +         advance time (per cpu) when otherwise the idle
21482 +         task would be scheduled, thus keeping the cpu
21483 +         busy and sharing the available resources among
21484 +         certain contexts.
21485 +
21486 +config VSERVER_IDLELIMIT
21487 +       bool    "Limit the IDLE task"
21488 +       depends on VSERVER_HARDCPU
21489 +       default n
21490 +       help
21491 +         Limit the idle slices, so the the next context
21492 +         will be scheduled as soon as possible.
21493 +
21494 +         This might improve interactivity and latency, but
21495 +         will also marginally increase scheduling overhead.
21496 +
21497 +choice
21498 +       prompt  "Persistent Inode Tagging"
21499 +       default TAGGING_ID24
21500 +       help
21501 +         This adds persistent context information to filesystems
21502 +         mounted with the tagxid option. Tagging is a requirement
21503 +         for per-context disk limits and per-context quota.
21504 +
21505 +
21506 +config TAGGING_NONE
21507 +       bool    "Disabled"
21508 +       help
21509 +         do not store per-context information in inodes.
21510 +
21511 +config TAGGING_UID16
21512 +       bool    "UID16/GID32"
21513 +       help
21514 +         reduces UID to 16 bit, but leaves GID at 32 bit.
21515 +
21516 +config TAGGING_GID16
21517 +       bool    "UID32/GID16"
21518 +       help
21519 +         reduces GID to 16 bit, but leaves UID at 32 bit.
21520 +
21521 +config TAGGING_ID24
21522 +       bool    "UID24/GID24"
21523 +       help
21524 +         uses the upper 8bit from UID and GID for XID tagging
21525 +         which leaves 24bit for UID/GID each, which should be
21526 +         more than sufficient for normal use.
21527 +
21528 +config TAGGING_INTERN
21529 +       bool    "UID32/GID32"
21530 +       help
21531 +         this uses otherwise reserved inode fields in the on
21532 +         disk representation, which limits the use to a few
21533 +         filesystems (currently ext2 and ext3)
21534 +
21535 +endchoice
21536 +
21537 +config TAG_NFSD
21538 +       bool    "Tag NFSD User Auth and Files"
21539 +       default n
21540 +       help
21541 +         Enable this if you do want the in-kernel NFS
21542 +         Server to use the tagging specified above.
21543 +         (will require patched clients too)
21544 +
21545 +config VSERVER_PRIVACY
21546 +       bool    "Honor Privacy Aspects of Guests"
21547 +       default n
21548 +       help
21549 +         When enabled, most context checks will disallow
21550 +         access to structures assigned to a specific context,
21551 +         like ptys or loop devices.
21552 +
21553 +config VSERVER_CONTEXTS
21554 +       int     "Maximum number of Contexts (1-65533)"  if EMBEDDED
21555 +       range 1 65533
21556 +       default "768"   if 64BIT
21557 +       default "256"
21558 +       help
21559 +         This setting will optimize certain data structures
21560 +         and memory allocations according to the expected
21561 +         maximum.
21562 +
21563 +         note: this is not a strict upper limit.
21564 +
21565 +config VSERVER_WARN
21566 +       bool    "VServer Warnings"
21567 +       default y
21568 +       help
21569 +         This enables various runtime warnings, which will
21570 +         notify about potential manipulation attempts or
21571 +         resource shortage. It is generally considered to
21572 +         be a good idea to have that enabled.
21573 +
21574 +config VSERVER_DEBUG
21575 +       bool    "VServer Debugging Code"
21576 +       default n
21577 +       help
21578 +         Set this to yes if you want to be able to activate
21579 +         debugging output at runtime. It adds a very small
21580 +         overhead to all vserver related functions and
21581 +         increases the kernel size by about 20k.
21582 +
21583 +config VSERVER_HISTORY
21584 +       bool    "VServer History Tracing"
21585 +       depends on VSERVER_DEBUG
21586 +       default n
21587 +       help
21588 +         Set this to yes if you want to record the history of
21589 +         linux-vserver activities, so they can be replayed in
21590 +         the event of a kernel panic or oops.
21591 +
21592 +config VSERVER_HISTORY_SIZE
21593 +       int     "Per-CPU History Size (32-65536)"
21594 +       depends on VSERVER_HISTORY
21595 +       range 32 65536
21596 +       default 64
21597 +       help
21598 +         This allows you to specify the number of entries in
21599 +         the per-CPU history buffer.
21600 +
21601 +config VSERVER_MONITOR
21602 +       bool    "VServer Scheduling Monitor"
21603 +       depends on VSERVER_DISABLED
21604 +       default n
21605 +       help
21606 +         Set this to yes if you want to record the scheduling
21607 +         decisions, so that they can be relayed to userspace
21608 +         for detailed analysis.
21609 +
21610 +config VSERVER_MONITOR_SIZE
21611 +       int     "Per-CPU Monitor Queue Size (32-65536)"
21612 +       depends on VSERVER_MONITOR
21613 +       range 32 65536
21614 +       default 1024
21615 +       help
21616 +         This allows you to specify the number of entries in
21617 +         the per-CPU scheduling monitor buffer.
21618 +
21619 +config VSERVER_MONITOR_SYNC
21620 +       int     "Per-CPU Monitor Sync Interval (0-65536)"
21621 +       depends on VSERVER_MONITOR
21622 +       range 0 65536
21623 +       default 256
21624 +       help
21625 +         This allows you to specify the interval in ticks
21626 +         when a time sync entry is inserted.
21627 +
21628 +endmenu
21629 +
21630 +
21631 +config VSERVER
21632 +       bool
21633 +       default y
21634 +       select NAMESPACES
21635 +       select UTS_NS
21636 +       select IPC_NS
21637 +       select USER_NS
21638 +       select SYSVIPC
21639 +
21640 +config VSERVER_SECURITY
21641 +       bool
21642 +       depends on SECURITY
21643 +       default y
21644 +       select SECURITY_CAPABILITIES
21645 +
21646 diff -NurpP --minimal linux-2.6.32.6/kernel/vserver/limit.c linux-2.6.32.6-vs2.3.0.36.28/kernel/vserver/limit.c
21647 --- linux-2.6.32.6/kernel/vserver/limit.c       1970-01-01 01:00:00.000000000 +0100
21648 +++ linux-2.6.32.6-vs2.3.0.36.28/kernel/vserver/limit.c 2009-12-03 20:04:56.000000000 +0100
21649 @@ -0,0 +1,333 @@
21650 +/*
21651 + *  linux/kernel/vserver/limit.c
21652 + *
21653 + *  Virtual Server: Context Limits
21654 + *
21655 + *  Copyright (C) 2004-2007  Herbert Pötzl
21656 + *
21657 + *  V0.01  broken out from vcontext V0.05
21658 + *  V0.02  changed vcmds to vxi arg
21659 + *
21660 + */
21661 +
21662 +#include <linux/sched.h>
21663 +#include <linux/module.h>
21664 +#include <linux/vs_limit.h>
21665 +#include <linux/vserver/limit.h>
21666 +#include <linux/vserver/limit_cmd.h>
21667 +
21668 +#include <asm/uaccess.h>
21669 +
21670 +
21671 +const char *vlimit_name[NUM_LIMITS] = {
21672 +       [RLIMIT_CPU]            = "CPU",
21673 +       [RLIMIT_RSS]            = "RSS",
21674 +       [RLIMIT_NPROC]          = "NPROC",
21675 +       [RLIMIT_NOFILE]         = "NOFILE",
21676 +       [RLIMIT_MEMLOCK]        = "VML",
21677 +       [RLIMIT_AS]             = "VM",
21678 +       [RLIMIT_LOCKS]          = "LOCKS",
21679 +       [RLIMIT_SIGPENDING]     = "SIGP",
21680 +       [RLIMIT_MSGQUEUE]       = "MSGQ",
21681 +
21682 +       [VLIMIT_NSOCK]          = "NSOCK",
21683 +       [VLIMIT_OPENFD]         = "OPENFD",
21684 +       [VLIMIT_ANON]           = "ANON",
21685 +       [VLIMIT_SHMEM]          = "SHMEM",
21686 +       [VLIMIT_DENTRY]         = "DENTRY",
21687 +};
21688 +
21689 +EXPORT_SYMBOL_GPL(vlimit_name);
21690 +
21691 +#define MASK_ENTRY(x)  (1 << (x))
21692 +
21693 +const struct vcmd_ctx_rlimit_mask_v0 vlimit_mask = {
21694 +               /* minimum */
21695 +       0
21696 +       ,       /* softlimit */
21697 +       MASK_ENTRY( RLIMIT_RSS          ) |
21698 +       MASK_ENTRY( VLIMIT_ANON         ) |
21699 +       0
21700 +       ,       /* maximum */
21701 +       MASK_ENTRY( RLIMIT_RSS          ) |
21702 +       MASK_ENTRY( RLIMIT_NPROC        ) |
21703 +       MASK_ENTRY( RLIMIT_NOFILE       ) |
21704 +       MASK_ENTRY( RLIMIT_MEMLOCK      ) |
21705 +       MASK_ENTRY( RLIMIT_AS           ) |
21706 +       MASK_ENTRY( RLIMIT_LOCKS        ) |
21707 +       MASK_ENTRY( RLIMIT_MSGQUEUE     ) |
21708 +
21709 +       MASK_ENTRY( VLIMIT_NSOCK        ) |
21710 +       MASK_ENTRY( VLIMIT_OPENFD       ) |
21711 +       MASK_ENTRY( VLIMIT_ANON         ) |
21712 +       MASK_ENTRY( VLIMIT_SHMEM        ) |
21713 +       MASK_ENTRY( VLIMIT_DENTRY       ) |
21714 +       0
21715 +};
21716 +               /* accounting only */
21717 +uint32_t account_mask =
21718 +       MASK_ENTRY( VLIMIT_SEMARY       ) |
21719 +       MASK_ENTRY( VLIMIT_NSEMS        ) |
21720 +       MASK_ENTRY( VLIMIT_MAPPED       ) |
21721 +       0;
21722 +
21723 +
21724 +static int is_valid_vlimit(int id)
21725 +{
21726 +       uint32_t mask = vlimit_mask.minimum |
21727 +               vlimit_mask.softlimit | vlimit_mask.maximum;
21728 +       return mask & (1 << id);
21729 +}
21730 +
21731 +static int is_accounted_vlimit(int id)
21732 +{
21733 +       if (is_valid_vlimit(id))
21734 +               return 1;
21735 +       return account_mask & (1 << id);
21736 +}
21737 +
21738 +
21739 +static inline uint64_t vc_get_soft(struct vx_info *vxi, int id)
21740 +{
21741 +       rlim_t limit = __rlim_soft(&vxi->limit, id);
21742 +       return VX_VLIM(limit);
21743 +}
21744 +
21745 +static inline uint64_t vc_get_hard(struct vx_info *vxi, int id)
21746 +{
21747 +       rlim_t limit = __rlim_hard(&vxi->limit, id);
21748 +       return VX_VLIM(limit);
21749 +}
21750 +
21751 +static int do_get_rlimit(struct vx_info *vxi, uint32_t id,
21752 +       uint64_t *minimum, uint64_t *softlimit, uint64_t *maximum)
21753 +{
21754 +       if (!is_valid_vlimit(id))
21755 +               return -EINVAL;
21756 +
21757 +       if (minimum)
21758 +               *minimum = CRLIM_UNSET;
21759 +       if (softlimit)
21760 +               *softlimit = vc_get_soft(vxi, id);
21761 +       if (maximum)
21762 +               *maximum = vc_get_hard(vxi, id);
21763 +       return 0;
21764 +}
21765 +
21766 +int vc_get_rlimit(struct vx_info *vxi, void __user *data)
21767 +{
21768 +       struct vcmd_ctx_rlimit_v0 vc_data;
21769 +       int ret;
21770 +
21771 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
21772 +               return -EFAULT;
21773 +
21774 +       ret = do_get_rlimit(vxi, vc_data.id,
21775 +               &vc_data.minimum, &vc_data.softlimit, &vc_data.maximum);
21776 +       if (ret)
21777 +               return ret;
21778 +
21779 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
21780 +               return -EFAULT;
21781 +       return 0;
21782 +}
21783 +
21784 +static int do_set_rlimit(struct vx_info *vxi, uint32_t id,
21785 +       uint64_t minimum, uint64_t softlimit, uint64_t maximum)
21786 +{
21787 +       if (!is_valid_vlimit(id))
21788 +               return -EINVAL;
21789 +
21790 +       if (maximum != CRLIM_KEEP)
21791 +               __rlim_hard(&vxi->limit, id) = VX_RLIM(maximum);
21792 +       if (softlimit != CRLIM_KEEP)
21793 +               __rlim_soft(&vxi->limit, id) = VX_RLIM(softlimit);
21794 +
21795 +       /* clamp soft limit */
21796 +       if (__rlim_soft(&vxi->limit, id) > __rlim_hard(&vxi->limit, id))
21797 +               __rlim_soft(&vxi->limit, id) = __rlim_hard(&vxi->limit, id);
21798 +
21799 +       return 0;
21800 +}
21801 +
21802 +int vc_set_rlimit(struct vx_info *vxi, void __user *data)
21803 +{
21804 +       struct vcmd_ctx_rlimit_v0 vc_data;
21805 +
21806 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
21807 +               return -EFAULT;
21808 +
21809 +       return do_set_rlimit(vxi, vc_data.id,
21810 +               vc_data.minimum, vc_data.softlimit, vc_data.maximum);
21811 +}
21812 +
21813 +#ifdef CONFIG_IA32_EMULATION
21814 +
21815 +int vc_set_rlimit_x32(struct vx_info *vxi, void __user *data)
21816 +{
21817 +       struct vcmd_ctx_rlimit_v0_x32 vc_data;
21818 +
21819 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
21820 +               return -EFAULT;
21821 +
21822 +       return do_set_rlimit(vxi, vc_data.id,
21823 +               vc_data.minimum, vc_data.softlimit, vc_data.maximum);
21824 +}
21825 +
21826 +int vc_get_rlimit_x32(struct vx_info *vxi, void __user *data)
21827 +{
21828 +       struct vcmd_ctx_rlimit_v0_x32 vc_data;
21829 +       int ret;
21830 +
21831 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
21832 +               return -EFAULT;
21833 +
21834 +       ret = do_get_rlimit(vxi, vc_data.id,
21835 +               &vc_data.minimum, &vc_data.softlimit, &vc_data.maximum);
21836 +       if (ret)
21837 +               return ret;
21838 +
21839 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
21840 +               return -EFAULT;
21841 +       return 0;
21842 +}
21843 +
21844 +#endif /* CONFIG_IA32_EMULATION */
21845 +
21846 +
21847 +int vc_get_rlimit_mask(uint32_t id, void __user *data)
21848 +{
21849 +       if (copy_to_user(data, &vlimit_mask, sizeof(vlimit_mask)))
21850 +               return -EFAULT;
21851 +       return 0;
21852 +}
21853 +
21854 +
21855 +static inline void vx_reset_hits(struct _vx_limit *limit)
21856 +{
21857 +       int lim;
21858 +
21859 +       for (lim = 0; lim < NUM_LIMITS; lim++) {
21860 +               atomic_set(&__rlim_lhit(limit, lim), 0);
21861 +       }
21862 +}
21863 +
21864 +int vc_reset_hits(struct vx_info *vxi, void __user *data)
21865 +{
21866 +       vx_reset_hits(&vxi->limit);
21867 +       return 0;
21868 +}
21869 +
21870 +static inline void vx_reset_minmax(struct _vx_limit *limit)
21871 +{
21872 +       rlim_t value;
21873 +       int lim;
21874 +
21875 +       for (lim = 0; lim < NUM_LIMITS; lim++) {
21876 +               value = __rlim_get(limit, lim);
21877 +               __rlim_rmax(limit, lim) = value;
21878 +               __rlim_rmin(limit, lim) = value;
21879 +       }
21880 +}
21881 +
21882 +int vc_reset_minmax(struct vx_info *vxi, void __user *data)
21883 +{
21884 +       vx_reset_minmax(&vxi->limit);
21885 +       return 0;
21886 +}
21887 +
21888 +
21889 +int vc_rlimit_stat(struct vx_info *vxi, void __user *data)
21890 +{
21891 +       struct vcmd_rlimit_stat_v0 vc_data;
21892 +       struct _vx_limit *limit = &vxi->limit;
21893 +       int id;
21894 +
21895 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
21896 +               return -EFAULT;
21897 +
21898 +       id = vc_data.id;
21899 +       if (!is_accounted_vlimit(id))
21900 +               return -EINVAL;
21901 +
21902 +       vx_limit_fixup(limit, id);
21903 +       vc_data.hits = atomic_read(&__rlim_lhit(limit, id));
21904 +       vc_data.value = __rlim_get(limit, id);
21905 +       vc_data.minimum = __rlim_rmin(limit, id);
21906 +       vc_data.maximum = __rlim_rmax(limit, id);
21907 +
21908 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
21909 +               return -EFAULT;
21910 +       return 0;
21911 +}
21912 +
21913 +
21914 +void vx_vsi_meminfo(struct sysinfo *val)
21915 +{
21916 +       struct vx_info *vxi = current_vx_info();
21917 +       unsigned long totalram, freeram;
21918 +       rlim_t v;
21919 +
21920 +       /* we blindly accept the max */
21921 +       v = __rlim_soft(&vxi->limit, RLIMIT_RSS);
21922 +       totalram = (v != RLIM_INFINITY) ? v : val->totalram;
21923 +
21924 +       /* total minus used equals free */
21925 +       v = __vx_cres_array_fixup(&vxi->limit, VLA_RSS);
21926 +       freeram = (v < totalram) ? totalram - v : 0;
21927 +
21928 +       val->totalram = totalram;
21929 +       val->freeram = freeram;
21930 +       val->bufferram = 0;
21931 +       val->totalhigh = 0;
21932 +       val->freehigh = 0;
21933 +       return;
21934 +}
21935 +
21936 +void vx_vsi_swapinfo(struct sysinfo *val)
21937 +{
21938 +       struct vx_info *vxi = current_vx_info();
21939 +       unsigned long totalswap, freeswap;
21940 +       rlim_t v, w;
21941 +
21942 +       v = __rlim_soft(&vxi->limit, RLIMIT_RSS);
21943 +       if (v == RLIM_INFINITY) {
21944 +               val->freeswap = val->totalswap;
21945 +               return;
21946 +       }
21947 +
21948 +       /* we blindly accept the max */
21949 +       w = __rlim_hard(&vxi->limit, RLIMIT_RSS);
21950 +       totalswap = (w != RLIM_INFINITY) ? (w - v) : val->totalswap;
21951 +
21952 +       /* currently 'used' swap */
21953 +       w = __vx_cres_array_fixup(&vxi->limit, VLA_RSS);
21954 +       w -= (w > v) ? v : w;
21955 +
21956 +       /* total minus used equals free */
21957 +       freeswap = (w < totalswap) ? totalswap - w : 0;
21958 +
21959 +       val->totalswap = totalswap;
21960 +       val->freeswap = freeswap;
21961 +       return;
21962 +}
21963 +
21964 +
21965 +unsigned long vx_badness(struct task_struct *task, struct mm_struct *mm)
21966 +{
21967 +       struct vx_info *vxi = mm->mm_vx_info;
21968 +       unsigned long points;
21969 +       rlim_t v, w;
21970 +
21971 +       if (!vxi)
21972 +               return 0;
21973 +
21974 +       points = vxi->vx_badness_bias;
21975 +
21976 +       v = __vx_cres_array_fixup(&vxi->limit, VLA_RSS);
21977 +       w = __rlim_soft(&vxi->limit, RLIMIT_RSS);
21978 +       points += (v > w) ? (v - w) : 0;
21979 +
21980 +       return points;
21981 +}
21982 +
21983 diff -NurpP --minimal linux-2.6.32.6/kernel/vserver/limit_init.h linux-2.6.32.6-vs2.3.0.36.28/kernel/vserver/limit_init.h
21984 --- linux-2.6.32.6/kernel/vserver/limit_init.h  1970-01-01 01:00:00.000000000 +0100
21985 +++ linux-2.6.32.6-vs2.3.0.36.28/kernel/vserver/limit_init.h    2009-12-03 20:04:56.000000000 +0100
21986 @@ -0,0 +1,31 @@
21987 +
21988 +
21989 +static inline void vx_info_init_limit(struct _vx_limit *limit)
21990 +{
21991 +       int lim;
21992 +
21993 +       for (lim = 0; lim < NUM_LIMITS; lim++) {
21994 +               __rlim_soft(limit, lim) = RLIM_INFINITY;
21995 +               __rlim_hard(limit, lim) = RLIM_INFINITY;
21996 +               __rlim_set(limit, lim, 0);
21997 +               atomic_set(&__rlim_lhit(limit, lim), 0);
21998 +               __rlim_rmin(limit, lim) = 0;
21999 +               __rlim_rmax(limit, lim) = 0;
22000 +       }
22001 +}
22002 +
22003 +static inline void vx_info_exit_limit(struct _vx_limit *limit)
22004 +{
22005 +       rlim_t value;
22006 +       int lim;
22007 +
22008 +       for (lim = 0; lim < NUM_LIMITS; lim++) {
22009 +               if ((1 << lim) & VLIM_NOCHECK)
22010 +                       continue;
22011 +               value = __rlim_get(limit, lim);
22012 +               vxwprintk_xid(value,
22013 +                       "!!! limit: %p[%s,%d] = %ld on exit.",
22014 +                       limit, vlimit_name[lim], lim, (long)value);
22015 +       }
22016 +}
22017 +
22018 diff -NurpP --minimal linux-2.6.32.6/kernel/vserver/limit_proc.h linux-2.6.32.6-vs2.3.0.36.28/kernel/vserver/limit_proc.h
22019 --- linux-2.6.32.6/kernel/vserver/limit_proc.h  1970-01-01 01:00:00.000000000 +0100
22020 +++ linux-2.6.32.6-vs2.3.0.36.28/kernel/vserver/limit_proc.h    2009-12-03 20:04:56.000000000 +0100
22021 @@ -0,0 +1,57 @@
22022 +#ifndef _VX_LIMIT_PROC_H
22023 +#define _VX_LIMIT_PROC_H
22024 +
22025 +#include <linux/vserver/limit_int.h>
22026 +
22027 +
22028 +#define VX_LIMIT_FMT   ":\t%8ld\t%8ld/%8ld\t%8lld/%8lld\t%6d\n"
22029 +#define VX_LIMIT_TOP   \
22030 +       "Limit\t current\t     min/max\t\t    soft/hard\t\thits\n"
22031 +
22032 +#define VX_LIMIT_ARG(r)                                \
22033 +       (unsigned long)__rlim_get(limit, r),    \
22034 +       (unsigned long)__rlim_rmin(limit, r),   \
22035 +       (unsigned long)__rlim_rmax(limit, r),   \
22036 +       VX_VLIM(__rlim_soft(limit, r)),         \
22037 +       VX_VLIM(__rlim_hard(limit, r)),         \
22038 +       atomic_read(&__rlim_lhit(limit, r))
22039 +
22040 +static inline int vx_info_proc_limit(struct _vx_limit *limit, char *buffer)
22041 +{
22042 +       vx_limit_fixup(limit, -1);
22043 +       return sprintf(buffer, VX_LIMIT_TOP
22044 +               "PROC"  VX_LIMIT_FMT
22045 +               "VM"    VX_LIMIT_FMT
22046 +               "VML"   VX_LIMIT_FMT
22047 +               "RSS"   VX_LIMIT_FMT
22048 +               "ANON"  VX_LIMIT_FMT
22049 +               "RMAP"  VX_LIMIT_FMT
22050 +               "FILES" VX_LIMIT_FMT
22051 +               "OFD"   VX_LIMIT_FMT
22052 +               "LOCKS" VX_LIMIT_FMT
22053 +               "SOCK"  VX_LIMIT_FMT
22054 +               "MSGQ"  VX_LIMIT_FMT
22055 +               "SHM"   VX_LIMIT_FMT
22056 +               "SEMA"  VX_LIMIT_FMT
22057 +               "SEMS"  VX_LIMIT_FMT
22058 +               "DENT"  VX_LIMIT_FMT,
22059 +               VX_LIMIT_ARG(RLIMIT_NPROC),
22060 +               VX_LIMIT_ARG(RLIMIT_AS),
22061 +               VX_LIMIT_ARG(RLIMIT_MEMLOCK),
22062 +               VX_LIMIT_ARG(RLIMIT_RSS),
22063 +               VX_LIMIT_ARG(VLIMIT_ANON),
22064 +               VX_LIMIT_ARG(VLIMIT_MAPPED),
22065 +               VX_LIMIT_ARG(RLIMIT_NOFILE),
22066 +               VX_LIMIT_ARG(VLIMIT_OPENFD),
22067 +               VX_LIMIT_ARG(RLIMIT_LOCKS),
22068 +               VX_LIMIT_ARG(VLIMIT_NSOCK),
22069 +               VX_LIMIT_ARG(RLIMIT_MSGQUEUE),
22070 +               VX_LIMIT_ARG(VLIMIT_SHMEM),
22071 +               VX_LIMIT_ARG(VLIMIT_SEMARY),
22072 +               VX_LIMIT_ARG(VLIMIT_NSEMS),
22073 +               VX_LIMIT_ARG(VLIMIT_DENTRY));
22074 +}
22075 +
22076 +#endif /* _VX_LIMIT_PROC_H */
22077 +
22078 +
22079 diff -NurpP --minimal linux-2.6.32.6/kernel/vserver/Makefile linux-2.6.32.6-vs2.3.0.36.28/kernel/vserver/Makefile
22080 --- linux-2.6.32.6/kernel/vserver/Makefile      1970-01-01 01:00:00.000000000 +0100
22081 +++ linux-2.6.32.6-vs2.3.0.36.28/kernel/vserver/Makefile        2009-12-03 20:04:56.000000000 +0100
22082 @@ -0,0 +1,18 @@
22083 +#
22084 +# Makefile for the Linux vserver routines.
22085 +#
22086 +
22087 +
22088 +obj-y          += vserver.o
22089 +
22090 +vserver-y      := switch.o context.o space.o sched.o network.o inode.o \
22091 +                  limit.o cvirt.o cacct.o signal.o helper.o init.o \
22092 +                  dlimit.o tag.o
22093 +
22094 +vserver-$(CONFIG_INET) += inet.o
22095 +vserver-$(CONFIG_PROC_FS) += proc.o
22096 +vserver-$(CONFIG_VSERVER_DEBUG) += sysctl.o debug.o
22097 +vserver-$(CONFIG_VSERVER_HISTORY) += history.o
22098 +vserver-$(CONFIG_VSERVER_MONITOR) += monitor.o
22099 +vserver-$(CONFIG_VSERVER_DEVICE) += device.o
22100 +
22101 diff -NurpP --minimal linux-2.6.32.6/kernel/vserver/monitor.c linux-2.6.32.6-vs2.3.0.36.28/kernel/vserver/monitor.c
22102 --- linux-2.6.32.6/kernel/vserver/monitor.c     1970-01-01 01:00:00.000000000 +0100
22103 +++ linux-2.6.32.6-vs2.3.0.36.28/kernel/vserver/monitor.c       2009-12-03 20:04:56.000000000 +0100
22104 @@ -0,0 +1,138 @@
22105 +/*
22106 + *  kernel/vserver/monitor.c
22107 + *
22108 + *  Virtual Context Scheduler Monitor
22109 + *
22110 + *  Copyright (C) 2006-2007 Herbert Pötzl
22111 + *
22112 + *  V0.01  basic design
22113 + *
22114 + */
22115 +
22116 +#include <linux/module.h>
22117 +#include <linux/jiffies.h>
22118 +#include <asm/uaccess.h>
22119 +#include <asm/atomic.h>
22120 +
22121 +#include <linux/vserver/monitor.h>
22122 +#include <linux/vserver/debug_cmd.h>
22123 +
22124 +
22125 +#ifdef CONFIG_VSERVER_MONITOR
22126 +#define VXM_SIZE       CONFIG_VSERVER_MONITOR_SIZE
22127 +#else
22128 +#define VXM_SIZE       64
22129 +#endif
22130 +
22131 +struct _vx_monitor {
22132 +       unsigned int counter;
22133 +
22134 +       struct _vx_mon_entry entry[VXM_SIZE+1];
22135 +};
22136 +
22137 +
22138 +DEFINE_PER_CPU(struct _vx_monitor, vx_monitor_buffer);
22139 +
22140 +unsigned volatile int vxm_active = 1;
22141 +
22142 +static atomic_t sequence = ATOMIC_INIT(0);
22143 +
22144 +
22145 +/*     vxm_advance()
22146 +
22147 +       * requires disabled preemption                          */
22148 +
22149 +struct _vx_mon_entry *vxm_advance(int cpu)
22150 +{
22151 +       struct _vx_monitor *mon = &per_cpu(vx_monitor_buffer, cpu);
22152 +       struct _vx_mon_entry *entry;
22153 +       unsigned int index;
22154 +
22155 +       index = vxm_active ? (mon->counter++ % VXM_SIZE) : VXM_SIZE;
22156 +       entry = &mon->entry[index];
22157 +
22158 +       entry->ev.seq = atomic_inc_return(&sequence);
22159 +       entry->ev.jif = jiffies;
22160 +       return entry;
22161 +}
22162 +
22163 +EXPORT_SYMBOL_GPL(vxm_advance);
22164 +
22165 +
22166 +int do_read_monitor(struct __user _vx_mon_entry *data,
22167 +       int cpu, uint32_t *index, uint32_t *count)
22168 +{
22169 +       int pos, ret = 0;
22170 +       struct _vx_monitor *mon = &per_cpu(vx_monitor_buffer, cpu);
22171 +       int end = mon->counter;
22172 +       int start = end - VXM_SIZE + 2;
22173 +       int idx = *index;
22174 +
22175 +       /* special case: get current pos */
22176 +       if (!*count) {
22177 +               *index = end;
22178 +               return 0;
22179 +       }
22180 +
22181 +       /* have we lost some data? */
22182 +       if (idx < start)
22183 +               idx = start;
22184 +
22185 +       for (pos = 0; (pos < *count) && (idx < end); pos++, idx++) {
22186 +               struct _vx_mon_entry *entry =
22187 +                       &mon->entry[idx % VXM_SIZE];
22188 +
22189 +               /* send entry to userspace */
22190 +               ret = copy_to_user(&data[pos], entry, sizeof(*entry));
22191 +               if (ret)
22192 +                       break;
22193 +       }
22194 +       /* save new index and count */
22195 +       *index = idx;
22196 +       *count = pos;
22197 +       return ret ? ret : (*index < end);
22198 +}
22199 +
22200 +int vc_read_monitor(uint32_t id, void __user *data)
22201 +{
22202 +       struct vcmd_read_monitor_v0 vc_data;
22203 +       int ret;
22204 +
22205 +       if (id >= NR_CPUS)
22206 +               return -EINVAL;
22207 +
22208 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
22209 +               return -EFAULT;
22210 +
22211 +       ret = do_read_monitor((struct __user _vx_mon_entry *)vc_data.data,
22212 +               id, &vc_data.index, &vc_data.count);
22213 +
22214 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
22215 +               return -EFAULT;
22216 +       return ret;
22217 +}
22218 +
22219 +#ifdef CONFIG_COMPAT
22220 +
22221 +int vc_read_monitor_x32(uint32_t id, void __user *data)
22222 +{
22223 +       struct vcmd_read_monitor_v0_x32 vc_data;
22224 +       int ret;
22225 +
22226 +       if (id >= NR_CPUS)
22227 +               return -EINVAL;
22228 +
22229 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
22230 +               return -EFAULT;
22231 +
22232 +       ret = do_read_monitor((struct __user _vx_mon_entry *)
22233 +               compat_ptr(vc_data.data_ptr),
22234 +               id, &vc_data.index, &vc_data.count);
22235 +
22236 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
22237 +               return -EFAULT;
22238 +       return ret;
22239 +}
22240 +
22241 +#endif /* CONFIG_COMPAT */
22242 +
22243 diff -NurpP --minimal linux-2.6.32.6/kernel/vserver/network.c linux-2.6.32.6-vs2.3.0.36.28/kernel/vserver/network.c
22244 --- linux-2.6.32.6/kernel/vserver/network.c     1970-01-01 01:00:00.000000000 +0100
22245 +++ linux-2.6.32.6-vs2.3.0.36.28/kernel/vserver/network.c       2009-12-03 20:04:56.000000000 +0100
22246 @@ -0,0 +1,864 @@
22247 +/*
22248 + *  linux/kernel/vserver/network.c
22249 + *
22250 + *  Virtual Server: Network Support
22251 + *
22252 + *  Copyright (C) 2003-2007  Herbert Pötzl
22253 + *
22254 + *  V0.01  broken out from vcontext V0.05
22255 + *  V0.02  cleaned up implementation
22256 + *  V0.03  added equiv nx commands
22257 + *  V0.04  switch to RCU based hash
22258 + *  V0.05  and back to locking again
22259 + *  V0.06  changed vcmds to nxi arg
22260 + *  V0.07  have __create claim() the nxi
22261 + *
22262 + */
22263 +
22264 +#include <linux/err.h>
22265 +#include <linux/slab.h>
22266 +#include <linux/rcupdate.h>
22267 +
22268 +#include <linux/vs_network.h>
22269 +#include <linux/vs_pid.h>
22270 +#include <linux/vserver/network_cmd.h>
22271 +
22272 +
22273 +atomic_t nx_global_ctotal      = ATOMIC_INIT(0);
22274 +atomic_t nx_global_cactive     = ATOMIC_INIT(0);
22275 +
22276 +static struct kmem_cache *nx_addr_v4_cachep = NULL;
22277 +static struct kmem_cache *nx_addr_v6_cachep = NULL;
22278 +
22279 +
22280 +static int __init init_network(void)
22281 +{
22282 +       nx_addr_v4_cachep = kmem_cache_create("nx_v4_addr_cache",
22283 +               sizeof(struct nx_addr_v4), 0,
22284 +               SLAB_HWCACHE_ALIGN|SLAB_PANIC, NULL);
22285 +       nx_addr_v6_cachep = kmem_cache_create("nx_v6_addr_cache",
22286 +               sizeof(struct nx_addr_v6), 0,
22287 +               SLAB_HWCACHE_ALIGN|SLAB_PANIC, NULL);
22288 +       return 0;
22289 +}
22290 +
22291 +
22292 +/*     __alloc_nx_addr_v4()                                    */
22293 +
22294 +static inline struct nx_addr_v4 *__alloc_nx_addr_v4(void)
22295 +{
22296 +       struct nx_addr_v4 *nxa = kmem_cache_alloc(
22297 +               nx_addr_v4_cachep, GFP_KERNEL);
22298 +
22299 +       if (!IS_ERR(nxa))
22300 +               memset(nxa, 0, sizeof(*nxa));
22301 +       return nxa;
22302 +}
22303 +
22304 +/*     __dealloc_nx_addr_v4()                                  */
22305 +
22306 +static inline void __dealloc_nx_addr_v4(struct nx_addr_v4 *nxa)
22307 +{
22308 +       kmem_cache_free(nx_addr_v4_cachep, nxa);
22309 +}
22310 +
22311 +/*     __dealloc_nx_addr_v4_all()                              */
22312 +
22313 +static inline void __dealloc_nx_addr_v4_all(struct nx_addr_v4 *nxa)
22314 +{
22315 +       while (nxa) {
22316 +               struct nx_addr_v4 *next = nxa->next;
22317 +
22318 +               __dealloc_nx_addr_v4(nxa);
22319 +               nxa = next;
22320 +       }
22321 +}
22322 +
22323 +
22324 +#ifdef CONFIG_IPV6
22325 +
22326 +/*     __alloc_nx_addr_v6()                                    */
22327 +
22328 +static inline struct nx_addr_v6 *__alloc_nx_addr_v6(void)
22329 +{
22330 +       struct nx_addr_v6 *nxa = kmem_cache_alloc(
22331 +               nx_addr_v6_cachep, GFP_KERNEL);
22332 +
22333 +       if (!IS_ERR(nxa))
22334 +               memset(nxa, 0, sizeof(*nxa));
22335 +       return nxa;
22336 +}
22337 +
22338 +/*     __dealloc_nx_addr_v6()                                  */
22339 +
22340 +static inline void __dealloc_nx_addr_v6(struct nx_addr_v6 *nxa)
22341 +{
22342 +       kmem_cache_free(nx_addr_v6_cachep, nxa);
22343 +}
22344 +
22345 +/*     __dealloc_nx_addr_v6_all()                              */
22346 +
22347 +static inline void __dealloc_nx_addr_v6_all(struct nx_addr_v6 *nxa)
22348 +{
22349 +       while (nxa) {
22350 +               struct nx_addr_v6 *next = nxa->next;
22351 +
22352 +               __dealloc_nx_addr_v6(nxa);
22353 +               nxa = next;
22354 +       }
22355 +}
22356 +
22357 +#endif /* CONFIG_IPV6 */
22358 +
22359 +/*     __alloc_nx_info()
22360 +
22361 +       * allocate an initialized nx_info struct
22362 +       * doesn't make it visible (hash)                        */
22363 +
22364 +static struct nx_info *__alloc_nx_info(nid_t nid)
22365 +{
22366 +       struct nx_info *new = NULL;
22367 +
22368 +       vxdprintk(VXD_CBIT(nid, 1), "alloc_nx_info(%d)*", nid);
22369 +
22370 +       /* would this benefit from a slab cache? */
22371 +       new = kmalloc(sizeof(struct nx_info), GFP_KERNEL);
22372 +       if (!new)
22373 +               return 0;
22374 +
22375 +       memset(new, 0, sizeof(struct nx_info));
22376 +       new->nx_id = nid;
22377 +       INIT_HLIST_NODE(&new->nx_hlist);
22378 +       atomic_set(&new->nx_usecnt, 0);
22379 +       atomic_set(&new->nx_tasks, 0);
22380 +       new->nx_state = 0;
22381 +
22382 +       new->nx_flags = NXF_INIT_SET;
22383 +
22384 +       /* rest of init goes here */
22385 +
22386 +       new->v4_lback.s_addr = htonl(INADDR_LOOPBACK);
22387 +       new->v4_bcast.s_addr = htonl(INADDR_BROADCAST);
22388 +
22389 +       vxdprintk(VXD_CBIT(nid, 0),
22390 +               "alloc_nx_info(%d) = %p", nid, new);
22391 +       atomic_inc(&nx_global_ctotal);
22392 +       return new;
22393 +}
22394 +
22395 +/*     __dealloc_nx_info()
22396 +
22397 +       * final disposal of nx_info                             */
22398 +
22399 +static void __dealloc_nx_info(struct nx_info *nxi)
22400 +{
22401 +       vxdprintk(VXD_CBIT(nid, 0),
22402 +               "dealloc_nx_info(%p)", nxi);
22403 +
22404 +       nxi->nx_hlist.next = LIST_POISON1;
22405 +       nxi->nx_id = -1;
22406 +
22407 +       BUG_ON(atomic_read(&nxi->nx_usecnt));
22408 +       BUG_ON(atomic_read(&nxi->nx_tasks));
22409 +
22410 +       __dealloc_nx_addr_v4_all(nxi->v4.next);
22411 +
22412 +       nxi->nx_state |= NXS_RELEASED;
22413 +       kfree(nxi);
22414 +       atomic_dec(&nx_global_ctotal);
22415 +}
22416 +
22417 +static void __shutdown_nx_info(struct nx_info *nxi)
22418 +{
22419 +       nxi->nx_state |= NXS_SHUTDOWN;
22420 +       vs_net_change(nxi, VSC_NETDOWN);
22421 +}
22422 +
22423 +/*     exported stuff                                          */
22424 +
22425 +void free_nx_info(struct nx_info *nxi)
22426 +{
22427 +       /* context shutdown is mandatory */
22428 +       BUG_ON(nxi->nx_state != NXS_SHUTDOWN);
22429 +
22430 +       /* context must not be hashed */
22431 +       BUG_ON(nxi->nx_state & NXS_HASHED);
22432 +
22433 +       BUG_ON(atomic_read(&nxi->nx_usecnt));
22434 +       BUG_ON(atomic_read(&nxi->nx_tasks));
22435 +
22436 +       __dealloc_nx_info(nxi);
22437 +}
22438 +
22439 +
22440 +void __nx_set_lback(struct nx_info *nxi)
22441 +{
22442 +       int nid = nxi->nx_id;
22443 +       __be32 lback = htonl(INADDR_LOOPBACK ^ ((nid & 0xFFFF) << 8));
22444 +
22445 +       nxi->v4_lback.s_addr = lback;
22446 +}
22447 +
22448 +extern int __nx_inet_add_lback(__be32 addr);
22449 +extern int __nx_inet_del_lback(__be32 addr);
22450 +
22451 +
22452 +/*     hash table for nx_info hash */
22453 +
22454 +#define NX_HASH_SIZE   13
22455 +
22456 +struct hlist_head nx_info_hash[NX_HASH_SIZE];
22457 +
22458 +static spinlock_t nx_info_hash_lock = SPIN_LOCK_UNLOCKED;
22459 +
22460 +
22461 +static inline unsigned int __hashval(nid_t nid)
22462 +{
22463 +       return (nid % NX_HASH_SIZE);
22464 +}
22465 +
22466 +
22467 +
22468 +/*     __hash_nx_info()
22469 +
22470 +       * add the nxi to the global hash table
22471 +       * requires the hash_lock to be held                     */
22472 +
22473 +static inline void __hash_nx_info(struct nx_info *nxi)
22474 +{
22475 +       struct hlist_head *head;
22476 +
22477 +       vxd_assert_lock(&nx_info_hash_lock);
22478 +       vxdprintk(VXD_CBIT(nid, 4),
22479 +               "__hash_nx_info: %p[#%d]", nxi, nxi->nx_id);
22480 +
22481 +       /* context must not be hashed */
22482 +       BUG_ON(nx_info_state(nxi, NXS_HASHED));
22483 +
22484 +       nxi->nx_state |= NXS_HASHED;
22485 +       head = &nx_info_hash[__hashval(nxi->nx_id)];
22486 +       hlist_add_head(&nxi->nx_hlist, head);
22487 +       atomic_inc(&nx_global_cactive);
22488 +}
22489 +
22490 +/*     __unhash_nx_info()
22491 +
22492 +       * remove the nxi from the global hash table
22493 +       * requires the hash_lock to be held                     */
22494 +
22495 +static inline void __unhash_nx_info(struct nx_info *nxi)
22496 +{
22497 +       vxd_assert_lock(&nx_info_hash_lock);
22498 +       vxdprintk(VXD_CBIT(nid, 4),
22499 +               "__unhash_nx_info: %p[#%d.%d.%d]", nxi, nxi->nx_id,
22500 +               atomic_read(&nxi->nx_usecnt), atomic_read(&nxi->nx_tasks));
22501 +
22502 +       /* context must be hashed */
22503 +       BUG_ON(!nx_info_state(nxi, NXS_HASHED));
22504 +       /* but without tasks */
22505 +       BUG_ON(atomic_read(&nxi->nx_tasks));
22506 +
22507 +       nxi->nx_state &= ~NXS_HASHED;
22508 +       hlist_del(&nxi->nx_hlist);
22509 +       atomic_dec(&nx_global_cactive);
22510 +}
22511 +
22512 +
22513 +/*     __lookup_nx_info()
22514 +
22515 +       * requires the hash_lock to be held
22516 +       * doesn't increment the nx_refcnt                       */
22517 +
22518 +static inline struct nx_info *__lookup_nx_info(nid_t nid)
22519 +{
22520 +       struct hlist_head *head = &nx_info_hash[__hashval(nid)];
22521 +       struct hlist_node *pos;
22522 +       struct nx_info *nxi;
22523 +
22524 +       vxd_assert_lock(&nx_info_hash_lock);
22525 +       hlist_for_each(pos, head) {
22526 +               nxi = hlist_entry(pos, struct nx_info, nx_hlist);
22527 +
22528 +               if (nxi->nx_id == nid)
22529 +                       goto found;
22530 +       }
22531 +       nxi = NULL;
22532 +found:
22533 +       vxdprintk(VXD_CBIT(nid, 0),
22534 +               "__lookup_nx_info(#%u): %p[#%u]",
22535 +               nid, nxi, nxi ? nxi->nx_id : 0);
22536 +       return nxi;
22537 +}
22538 +
22539 +
22540 +/*     __create_nx_info()
22541 +
22542 +       * create the requested context
22543 +       * get(), claim() and hash it                            */
22544 +
22545 +static struct nx_info *__create_nx_info(int id)
22546 +{
22547 +       struct nx_info *new, *nxi = NULL;
22548 +
22549 +       vxdprintk(VXD_CBIT(nid, 1), "create_nx_info(%d)*", id);
22550 +
22551 +       if (!(new = __alloc_nx_info(id)))
22552 +               return ERR_PTR(-ENOMEM);
22553 +
22554 +       /* required to make dynamic xids unique */
22555 +       spin_lock(&nx_info_hash_lock);
22556 +
22557 +       /* static context requested */
22558 +       if ((nxi = __lookup_nx_info(id))) {
22559 +               vxdprintk(VXD_CBIT(nid, 0),
22560 +                       "create_nx_info(%d) = %p (already there)", id, nxi);
22561 +               if (nx_info_flags(nxi, NXF_STATE_SETUP, 0))
22562 +                       nxi = ERR_PTR(-EBUSY);
22563 +               else
22564 +                       nxi = ERR_PTR(-EEXIST);
22565 +               goto out_unlock;
22566 +       }
22567 +       /* new context */
22568 +       vxdprintk(VXD_CBIT(nid, 0),
22569 +               "create_nx_info(%d) = %p (new)", id, new);
22570 +       claim_nx_info(new, NULL);
22571 +       __nx_set_lback(new);
22572 +       __hash_nx_info(get_nx_info(new));
22573 +       nxi = new, new = NULL;
22574 +
22575 +out_unlock:
22576 +       spin_unlock(&nx_info_hash_lock);
22577 +       if (new)
22578 +               __dealloc_nx_info(new);
22579 +       return nxi;
22580 +}
22581 +
22582 +
22583 +
22584 +/*     exported stuff                                          */
22585 +
22586 +
22587 +void unhash_nx_info(struct nx_info *nxi)
22588 +{
22589 +       __shutdown_nx_info(nxi);
22590 +       spin_lock(&nx_info_hash_lock);
22591 +       __unhash_nx_info(nxi);
22592 +       spin_unlock(&nx_info_hash_lock);
22593 +}
22594 +
22595 +/*     lookup_nx_info()
22596 +
22597 +       * search for a nx_info and get() it
22598 +       * negative id means current                             */
22599 +
22600 +struct nx_info *lookup_nx_info(int id)
22601 +{
22602 +       struct nx_info *nxi = NULL;
22603 +
22604 +       if (id < 0) {
22605 +               nxi = get_nx_info(current_nx_info());
22606 +       } else if (id > 1) {
22607 +               spin_lock(&nx_info_hash_lock);
22608 +               nxi = get_nx_info(__lookup_nx_info(id));
22609 +               spin_unlock(&nx_info_hash_lock);
22610 +       }
22611 +       return nxi;
22612 +}
22613 +
22614 +/*     nid_is_hashed()
22615 +
22616 +       * verify that nid is still hashed                       */
22617 +
22618 +int nid_is_hashed(nid_t nid)
22619 +{
22620 +       int hashed;
22621 +
22622 +       spin_lock(&nx_info_hash_lock);
22623 +       hashed = (__lookup_nx_info(nid) != NULL);
22624 +       spin_unlock(&nx_info_hash_lock);
22625 +       return hashed;
22626 +}
22627 +
22628 +
22629 +#ifdef CONFIG_PROC_FS
22630 +
22631 +/*     get_nid_list()
22632 +
22633 +       * get a subset of hashed nids for proc
22634 +       * assumes size is at least one                          */
22635 +
22636 +int get_nid_list(int index, unsigned int *nids, int size)
22637 +{
22638 +       int hindex, nr_nids = 0;
22639 +
22640 +       /* only show current and children */
22641 +       if (!nx_check(0, VS_ADMIN | VS_WATCH)) {
22642 +               if (index > 0)
22643 +                       return 0;
22644 +               nids[nr_nids] = nx_current_nid();
22645 +               return 1;
22646 +       }
22647 +
22648 +       for (hindex = 0; hindex < NX_HASH_SIZE; hindex++) {
22649 +               struct hlist_head *head = &nx_info_hash[hindex];
22650 +               struct hlist_node *pos;
22651 +
22652 +               spin_lock(&nx_info_hash_lock);
22653 +               hlist_for_each(pos, head) {
22654 +                       struct nx_info *nxi;
22655 +
22656 +                       if (--index > 0)
22657 +                               continue;
22658 +
22659 +                       nxi = hlist_entry(pos, struct nx_info, nx_hlist);
22660 +                       nids[nr_nids] = nxi->nx_id;
22661 +                       if (++nr_nids >= size) {
22662 +                               spin_unlock(&nx_info_hash_lock);
22663 +                               goto out;
22664 +                       }
22665 +               }
22666 +               /* keep the lock time short */
22667 +               spin_unlock(&nx_info_hash_lock);
22668 +       }
22669 +out:
22670 +       return nr_nids;
22671 +}
22672 +#endif
22673 +
22674 +
22675 +/*
22676 + *     migrate task to new network
22677 + *     gets nxi, puts old_nxi on change
22678 + */
22679 +
22680 +int nx_migrate_task(struct task_struct *p, struct nx_info *nxi)
22681 +{
22682 +       struct nx_info *old_nxi;
22683 +       int ret = 0;
22684 +
22685 +       if (!p || !nxi)
22686 +               BUG();
22687 +
22688 +       vxdprintk(VXD_CBIT(nid, 5),
22689 +               "nx_migrate_task(%p,%p[#%d.%d.%d])",
22690 +               p, nxi, nxi->nx_id,
22691 +               atomic_read(&nxi->nx_usecnt),
22692 +               atomic_read(&nxi->nx_tasks));
22693 +
22694 +       if (nx_info_flags(nxi, NXF_INFO_PRIVATE, 0) &&
22695 +               !nx_info_flags(nxi, NXF_STATE_SETUP, 0))
22696 +               return -EACCES;
22697 +
22698 +       if (nx_info_state(nxi, NXS_SHUTDOWN))
22699 +               return -EFAULT;
22700 +
22701 +       /* maybe disallow this completely? */
22702 +       old_nxi = task_get_nx_info(p);
22703 +       if (old_nxi == nxi)
22704 +               goto out;
22705 +
22706 +       task_lock(p);
22707 +       if (old_nxi)
22708 +               clr_nx_info(&p->nx_info);
22709 +       claim_nx_info(nxi, p);
22710 +       set_nx_info(&p->nx_info, nxi);
22711 +       p->nid = nxi->nx_id;
22712 +       task_unlock(p);
22713 +
22714 +       vxdprintk(VXD_CBIT(nid, 5),
22715 +               "moved task %p into nxi:%p[#%d]",
22716 +               p, nxi, nxi->nx_id);
22717 +
22718 +       if (old_nxi)
22719 +               release_nx_info(old_nxi, p);
22720 +       ret = 0;
22721 +out:
22722 +       put_nx_info(old_nxi);
22723 +       return ret;
22724 +}
22725 +
22726 +
22727 +void nx_set_persistent(struct nx_info *nxi)
22728 +{
22729 +       vxdprintk(VXD_CBIT(nid, 6),
22730 +               "nx_set_persistent(%p[#%d])", nxi, nxi->nx_id);
22731 +
22732 +       get_nx_info(nxi);
22733 +       claim_nx_info(nxi, NULL);
22734 +}
22735 +
22736 +void nx_clear_persistent(struct nx_info *nxi)
22737 +{
22738 +       vxdprintk(VXD_CBIT(nid, 6),
22739 +               "nx_clear_persistent(%p[#%d])", nxi, nxi->nx_id);
22740 +
22741 +       release_nx_info(nxi, NULL);
22742 +       put_nx_info(nxi);
22743 +}
22744 +
22745 +void nx_update_persistent(struct nx_info *nxi)
22746 +{
22747 +       if (nx_info_flags(nxi, NXF_PERSISTENT, 0))
22748 +               nx_set_persistent(nxi);
22749 +       else
22750 +               nx_clear_persistent(nxi);
22751 +}
22752 +
22753 +/* vserver syscall commands below here */
22754 +
22755 +/* taks nid and nx_info functions */
22756 +
22757 +#include <asm/uaccess.h>
22758 +
22759 +
22760 +int vc_task_nid(uint32_t id)
22761 +{
22762 +       nid_t nid;
22763 +
22764 +       if (id) {
22765 +               struct task_struct *tsk;
22766 +
22767 +               read_lock(&tasklist_lock);
22768 +               tsk = find_task_by_real_pid(id);
22769 +               nid = (tsk) ? tsk->nid : -ESRCH;
22770 +               read_unlock(&tasklist_lock);
22771 +       } else
22772 +               nid = nx_current_nid();
22773 +       return nid;
22774 +}
22775 +
22776 +
22777 +int vc_nx_info(struct nx_info *nxi, void __user *data)
22778 +{
22779 +       struct vcmd_nx_info_v0 vc_data;
22780 +
22781 +       vc_data.nid = nxi->nx_id;
22782 +
22783 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
22784 +               return -EFAULT;
22785 +       return 0;
22786 +}
22787 +
22788 +
22789 +/* network functions */
22790 +
22791 +int vc_net_create(uint32_t nid, void __user *data)
22792 +{
22793 +       struct vcmd_net_create vc_data = { .flagword = NXF_INIT_SET };
22794 +       struct nx_info *new_nxi;
22795 +       int ret;
22796 +
22797 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
22798 +               return -EFAULT;
22799 +
22800 +       if ((nid > MAX_S_CONTEXT) || (nid < 2))
22801 +               return -EINVAL;
22802 +
22803 +       new_nxi = __create_nx_info(nid);
22804 +       if (IS_ERR(new_nxi))
22805 +               return PTR_ERR(new_nxi);
22806 +
22807 +       /* initial flags */
22808 +       new_nxi->nx_flags = vc_data.flagword;
22809 +
22810 +       ret = -ENOEXEC;
22811 +       if (vs_net_change(new_nxi, VSC_NETUP))
22812 +               goto out;
22813 +
22814 +       ret = nx_migrate_task(current, new_nxi);
22815 +       if (ret)
22816 +               goto out;
22817 +
22818 +       /* return context id on success */
22819 +       ret = new_nxi->nx_id;
22820 +
22821 +       /* get a reference for persistent contexts */
22822 +       if ((vc_data.flagword & NXF_PERSISTENT))
22823 +               nx_set_persistent(new_nxi);
22824 +out:
22825 +       release_nx_info(new_nxi, NULL);
22826 +       put_nx_info(new_nxi);
22827 +       return ret;
22828 +}
22829 +
22830 +
22831 +int vc_net_migrate(struct nx_info *nxi, void __user *data)
22832 +{
22833 +       return nx_migrate_task(current, nxi);
22834 +}
22835 +
22836 +
22837 +
22838 +int do_add_v4_addr(struct nx_info *nxi, __be32 ip, __be32 ip2, __be32 mask,
22839 +       uint16_t type, uint16_t flags)
22840 +{
22841 +       struct nx_addr_v4 *nxa = &nxi->v4;
22842 +
22843 +       if (NX_IPV4(nxi)) {
22844 +               /* locate last entry */
22845 +               for (; nxa->next; nxa = nxa->next);
22846 +               nxa->next = __alloc_nx_addr_v4();
22847 +               nxa = nxa->next;
22848 +
22849 +               if (IS_ERR(nxa))
22850 +                       return PTR_ERR(nxa);
22851 +       }
22852 +
22853 +       if (nxi->v4.next)
22854 +               /* remove single ip for ip list */
22855 +               nxi->nx_flags &= ~NXF_SINGLE_IP;
22856 +
22857 +       nxa->ip[0].s_addr = ip;
22858 +       nxa->ip[1].s_addr = ip2;
22859 +       nxa->mask.s_addr = mask;
22860 +       nxa->type = type;
22861 +       nxa->flags = flags;
22862 +       return 0;
22863 +}
22864 +
22865 +
22866 +int vc_net_add(struct nx_info *nxi, void __user *data)
22867 +{
22868 +       struct vcmd_net_addr_v0 vc_data;
22869 +       int index, ret = 0;
22870 +
22871 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
22872 +               return -EFAULT;
22873 +
22874 +       switch (vc_data.type) {
22875 +       case NXA_TYPE_IPV4:
22876 +               if ((vc_data.count < 1) || (vc_data.count > 4))
22877 +                       return -EINVAL;
22878 +
22879 +               index = 0;
22880 +               while (index < vc_data.count) {
22881 +                       ret = do_add_v4_addr(nxi, vc_data.ip[index].s_addr, 0,
22882 +                               vc_data.mask[index].s_addr, NXA_TYPE_ADDR, 0);
22883 +                       if (ret)
22884 +                               return ret;
22885 +                       index++;
22886 +               }
22887 +               ret = index;
22888 +               break;
22889 +
22890 +       case NXA_TYPE_IPV4|NXA_MOD_BCAST:
22891 +               nxi->v4_bcast = vc_data.ip[0];
22892 +               ret = 1;
22893 +               break;
22894 +
22895 +       case NXA_TYPE_IPV4|NXA_MOD_LBACK:
22896 +               nxi->v4_lback = vc_data.ip[0];
22897 +               ret = 1;
22898 +               break;
22899 +
22900 +       default:
22901 +               ret = -EINVAL;
22902 +               break;
22903 +       }
22904 +       return ret;
22905 +}
22906 +
22907 +int vc_net_remove(struct nx_info *nxi, void __user *data)
22908 +{
22909 +       struct vcmd_net_addr_v0 vc_data;
22910 +
22911 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
22912 +               return -EFAULT;
22913 +
22914 +       switch (vc_data.type) {
22915 +       case NXA_TYPE_ANY:
22916 +               __dealloc_nx_addr_v4_all(xchg(&nxi->v4.next, NULL));
22917 +               memset(&nxi->v4, 0, sizeof(nxi->v4));
22918 +               break;
22919 +
22920 +       default:
22921 +               return -EINVAL;
22922 +       }
22923 +       return 0;
22924 +}
22925 +
22926 +
22927 +int vc_net_add_ipv4(struct nx_info *nxi, void __user *data)
22928 +{
22929 +       struct vcmd_net_addr_ipv4_v1 vc_data;
22930 +
22931 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
22932 +               return -EFAULT;
22933 +
22934 +       switch (vc_data.type) {
22935 +       case NXA_TYPE_ADDR:
22936 +       case NXA_TYPE_RANGE:
22937 +       case NXA_TYPE_MASK:
22938 +               return do_add_v4_addr(nxi, vc_data.ip.s_addr, 0,
22939 +                       vc_data.mask.s_addr, vc_data.type, vc_data.flags);
22940 +
22941 +       case NXA_TYPE_ADDR | NXA_MOD_BCAST:
22942 +               nxi->v4_bcast = vc_data.ip;
22943 +               break;
22944 +
22945 +       case NXA_TYPE_ADDR | NXA_MOD_LBACK:
22946 +               nxi->v4_lback = vc_data.ip;
22947 +               break;
22948 +
22949 +       default:
22950 +               return -EINVAL;
22951 +       }
22952 +       return 0;
22953 +}
22954 +
22955 +int vc_net_remove_ipv4(struct nx_info *nxi, void __user *data)
22956 +{
22957 +       struct vcmd_net_addr_ipv4_v1 vc_data;
22958 +
22959 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
22960 +               return -EFAULT;
22961 +
22962 +       switch (vc_data.type) {
22963 +/*     case NXA_TYPE_ADDR:
22964 +               break;          */
22965 +
22966 +       case NXA_TYPE_ANY:
22967 +               __dealloc_nx_addr_v4_all(xchg(&nxi->v4.next, NULL));
22968 +               memset(&nxi->v4, 0, sizeof(nxi->v4));
22969 +               break;
22970 +
22971 +       default:
22972 +               return -EINVAL;
22973 +       }
22974 +       return 0;
22975 +}
22976 +
22977 +
22978 +#ifdef CONFIG_IPV6
22979 +
22980 +int do_add_v6_addr(struct nx_info *nxi,
22981 +       struct in6_addr *ip, struct in6_addr *mask,
22982 +       uint32_t prefix, uint16_t type, uint16_t flags)
22983 +{
22984 +       struct nx_addr_v6 *nxa = &nxi->v6;
22985 +
22986 +       if (NX_IPV6(nxi)) {
22987 +               /* locate last entry */
22988 +               for (; nxa->next; nxa = nxa->next);
22989 +               nxa->next = __alloc_nx_addr_v6();
22990 +               nxa = nxa->next;
22991 +
22992 +               if (IS_ERR(nxa))
22993 +                       return PTR_ERR(nxa);
22994 +       }
22995 +
22996 +       nxa->ip = *ip;
22997 +       nxa->mask = *mask;
22998 +       nxa->prefix = prefix;
22999 +       nxa->type = type;
23000 +       nxa->flags = flags;
23001 +       return 0;
23002 +}
23003 +
23004 +
23005 +int vc_net_add_ipv6(struct nx_info *nxi, void __user *data)
23006 +{
23007 +       struct vcmd_net_addr_ipv6_v1 vc_data;
23008 +
23009 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
23010 +               return -EFAULT;
23011 +
23012 +       switch (vc_data.type) {
23013 +       case NXA_TYPE_ADDR:
23014 +       case NXA_TYPE_MASK:
23015 +               return do_add_v6_addr(nxi, &vc_data.ip, &vc_data.mask,
23016 +                       vc_data.prefix, vc_data.type, vc_data.flags);
23017 +       default:
23018 +               return -EINVAL;
23019 +       }
23020 +       return 0;
23021 +}
23022 +
23023 +int vc_net_remove_ipv6(struct nx_info *nxi, void __user *data)
23024 +{
23025 +       struct vcmd_net_addr_ipv6_v1 vc_data;
23026 +
23027 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
23028 +               return -EFAULT;
23029 +
23030 +       switch (vc_data.type) {
23031 +       case NXA_TYPE_ANY:
23032 +               __dealloc_nx_addr_v6_all(xchg(&nxi->v6.next, NULL));
23033 +               memset(&nxi->v6, 0, sizeof(nxi->v6));
23034 +               break;
23035 +
23036 +       default:
23037 +               return -EINVAL;
23038 +       }
23039 +       return 0;
23040 +}
23041 +
23042 +#endif /* CONFIG_IPV6 */
23043 +
23044 +
23045 +int vc_get_nflags(struct nx_info *nxi, void __user *data)
23046 +{
23047 +       struct vcmd_net_flags_v0 vc_data;
23048 +
23049 +       vc_data.flagword = nxi->nx_flags;
23050 +
23051 +       /* special STATE flag handling */
23052 +       vc_data.mask = vs_mask_flags(~0ULL, nxi->nx_flags, NXF_ONE_TIME);
23053 +
23054 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
23055 +               return -EFAULT;
23056 +       return 0;
23057 +}
23058 +
23059 +int vc_set_nflags(struct nx_info *nxi, void __user *data)
23060 +{
23061 +       struct vcmd_net_flags_v0 vc_data;
23062 +       uint64_t mask, trigger;
23063 +
23064 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
23065 +               return -EFAULT;
23066 +
23067 +       /* special STATE flag handling */
23068 +       mask = vs_mask_mask(vc_data.mask, nxi->nx_flags, NXF_ONE_TIME);
23069 +       trigger = (mask & nxi->nx_flags) ^ (mask & vc_data.flagword);
23070 +
23071 +       nxi->nx_flags = vs_mask_flags(nxi->nx_flags,
23072 +               vc_data.flagword, mask);
23073 +       if (trigger & NXF_PERSISTENT)
23074 +               nx_update_persistent(nxi);
23075 +
23076 +       return 0;
23077 +}
23078 +
23079 +int vc_get_ncaps(struct nx_info *nxi, void __user *data)
23080 +{
23081 +       struct vcmd_net_caps_v0 vc_data;
23082 +
23083 +       vc_data.ncaps = nxi->nx_ncaps;
23084 +       vc_data.cmask = ~0ULL;
23085 +
23086 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
23087 +               return -EFAULT;
23088 +       return 0;
23089 +}
23090 +
23091 +int vc_set_ncaps(struct nx_info *nxi, void __user *data)
23092 +{
23093 +       struct vcmd_net_caps_v0 vc_data;
23094 +
23095 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
23096 +               return -EFAULT;
23097 +
23098 +       nxi->nx_ncaps = vs_mask_flags(nxi->nx_ncaps,
23099 +               vc_data.ncaps, vc_data.cmask);
23100 +       return 0;
23101 +}
23102 +
23103 +
23104 +#include <linux/module.h>
23105 +
23106 +module_init(init_network);
23107 +
23108 +EXPORT_SYMBOL_GPL(free_nx_info);
23109 +EXPORT_SYMBOL_GPL(unhash_nx_info);
23110 +
23111 diff -NurpP --minimal linux-2.6.32.6/kernel/vserver/proc.c linux-2.6.32.6-vs2.3.0.36.28/kernel/vserver/proc.c
23112 --- linux-2.6.32.6/kernel/vserver/proc.c        1970-01-01 01:00:00.000000000 +0100
23113 +++ linux-2.6.32.6-vs2.3.0.36.28/kernel/vserver/proc.c  2009-12-03 20:04:56.000000000 +0100
23114 @@ -0,0 +1,1098 @@
23115 +/*
23116 + *  linux/kernel/vserver/proc.c
23117 + *
23118 + *  Virtual Context Support
23119 + *
23120 + *  Copyright (C) 2003-2007  Herbert Pötzl
23121 + *
23122 + *  V0.01  basic structure
23123 + *  V0.02  adaptation vs1.3.0
23124 + *  V0.03  proc permissions
23125 + *  V0.04  locking/generic
23126 + *  V0.05  next generation procfs
23127 + *  V0.06  inode validation
23128 + *  V0.07  generic rewrite vid
23129 + *  V0.08  remove inode type
23130 + *
23131 + */
23132 +
23133 +#include <linux/proc_fs.h>
23134 +#include <linux/fs_struct.h>
23135 +#include <linux/mount.h>
23136 +#include <asm/unistd.h>
23137 +
23138 +#include <linux/vs_context.h>
23139 +#include <linux/vs_network.h>
23140 +#include <linux/vs_cvirt.h>
23141 +
23142 +#include <linux/in.h>
23143 +#include <linux/inetdevice.h>
23144 +#include <linux/vs_inet.h>
23145 +#include <linux/vs_inet6.h>
23146 +
23147 +#include <linux/vserver/global.h>
23148 +
23149 +#include "cvirt_proc.h"
23150 +#include "cacct_proc.h"
23151 +#include "limit_proc.h"
23152 +#include "sched_proc.h"
23153 +#include "vci_config.h"
23154 +
23155 +
23156 +static inline char *print_cap_t(char *buffer, kernel_cap_t *c)
23157 +{
23158 +       unsigned __capi;
23159 +
23160 +       CAP_FOR_EACH_U32(__capi) {
23161 +               buffer += sprintf(buffer, "%08x",
23162 +                       c->cap[(_KERNEL_CAPABILITY_U32S-1) - __capi]);
23163 +       }
23164 +       return buffer;
23165 +}
23166 +
23167 +
23168 +static struct proc_dir_entry *proc_virtual;
23169 +
23170 +static struct proc_dir_entry *proc_virtnet;
23171 +
23172 +
23173 +/* first the actual feeds */
23174 +
23175 +
23176 +static int proc_vci(char *buffer)
23177 +{
23178 +       return sprintf(buffer,
23179 +               "VCIVersion:\t%04x:%04x\n"
23180 +               "VCISyscall:\t%d\n"
23181 +               "VCIKernel:\t%08x\n",
23182 +               VCI_VERSION >> 16,
23183 +               VCI_VERSION & 0xFFFF,
23184 +               __NR_vserver,
23185 +               vci_kernel_config());
23186 +}
23187 +
23188 +static int proc_virtual_info(char *buffer)
23189 +{
23190 +       return proc_vci(buffer);
23191 +}
23192 +
23193 +static int proc_virtual_status(char *buffer)
23194 +{
23195 +       return sprintf(buffer,
23196 +               "#CTotal:\t%d\n"
23197 +               "#CActive:\t%d\n"
23198 +               "#NSProxy:\t%d\t%d %d %d %d %d %d\n"
23199 +               "#InitTask:\t%d\t%d %d\n",
23200 +               atomic_read(&vx_global_ctotal),
23201 +               atomic_read(&vx_global_cactive),
23202 +               atomic_read(&vs_global_nsproxy),
23203 +               atomic_read(&vs_global_fs),
23204 +               atomic_read(&vs_global_mnt_ns),
23205 +               atomic_read(&vs_global_uts_ns),
23206 +               atomic_read(&nr_ipc_ns),
23207 +               atomic_read(&vs_global_user_ns),
23208 +               atomic_read(&vs_global_pid_ns),
23209 +               atomic_read(&init_task.usage),
23210 +               atomic_read(&init_task.nsproxy->count),
23211 +               init_task.fs->users);
23212 +}
23213 +
23214 +
23215 +int proc_vxi_info(struct vx_info *vxi, char *buffer)
23216 +{
23217 +       int length;
23218 +
23219 +       length = sprintf(buffer,
23220 +               "ID:\t%d\n"
23221 +               "Info:\t%p\n"
23222 +               "Init:\t%d\n"
23223 +               "OOM:\t%lld\n",
23224 +               vxi->vx_id,
23225 +               vxi,
23226 +               vxi->vx_initpid,
23227 +               vxi->vx_badness_bias);
23228 +       return length;
23229 +}
23230 +
23231 +int proc_vxi_status(struct vx_info *vxi, char *buffer)
23232 +{
23233 +       char *orig = buffer;
23234 +
23235 +       buffer += sprintf(buffer,
23236 +               "UseCnt:\t%d\n"
23237 +               "Tasks:\t%d\n"
23238 +               "Flags:\t%016llx\n",
23239 +               atomic_read(&vxi->vx_usecnt),
23240 +               atomic_read(&vxi->vx_tasks),
23241 +               (unsigned long long)vxi->vx_flags);
23242 +
23243 +       buffer += sprintf(buffer, "BCaps:\t");
23244 +       buffer = print_cap_t(buffer, &vxi->vx_bcaps);
23245 +       buffer += sprintf(buffer, "\n");
23246 +
23247 +       buffer += sprintf(buffer,
23248 +               "CCaps:\t%016llx\n"
23249 +               "Spaces:\t%08lx %08lx\n",
23250 +               (unsigned long long)vxi->vx_ccaps,
23251 +               vxi->vx_nsmask[0], vxi->vx_nsmask[1]);
23252 +       return buffer - orig;
23253 +}
23254 +
23255 +int proc_vxi_limit(struct vx_info *vxi, char *buffer)
23256 +{
23257 +       return vx_info_proc_limit(&vxi->limit, buffer);
23258 +}
23259 +
23260 +int proc_vxi_sched(struct vx_info *vxi, char *buffer)
23261 +{
23262 +       int cpu, length;
23263 +
23264 +       length = vx_info_proc_sched(&vxi->sched, buffer);
23265 +       for_each_online_cpu(cpu) {
23266 +               length += vx_info_proc_sched_pc(
23267 +                       &vx_per_cpu(vxi, sched_pc, cpu),
23268 +                       buffer + length, cpu);
23269 +       }
23270 +       return length;
23271 +}
23272 +
23273 +int proc_vxi_nsproxy0(struct vx_info *vxi, char *buffer)
23274 +{
23275 +       return vx_info_proc_nsproxy(vxi->vx_nsproxy[0], buffer);
23276 +}
23277 +
23278 +int proc_vxi_nsproxy1(struct vx_info *vxi, char *buffer)
23279 +{
23280 +       return vx_info_proc_nsproxy(vxi->vx_nsproxy[1], buffer);
23281 +}
23282 +
23283 +int proc_vxi_cvirt(struct vx_info *vxi, char *buffer)
23284 +{
23285 +       int cpu, length;
23286 +
23287 +       vx_update_load(vxi);
23288 +       length = vx_info_proc_cvirt(&vxi->cvirt, buffer);
23289 +       for_each_online_cpu(cpu) {
23290 +               length += vx_info_proc_cvirt_pc(
23291 +                       &vx_per_cpu(vxi, cvirt_pc, cpu),
23292 +                       buffer + length, cpu);
23293 +       }
23294 +       return length;
23295 +}
23296 +
23297 +int proc_vxi_cacct(struct vx_info *vxi, char *buffer)
23298 +{
23299 +       return vx_info_proc_cacct(&vxi->cacct, buffer);
23300 +}
23301 +
23302 +
23303 +static int proc_virtnet_info(char *buffer)
23304 +{
23305 +       return proc_vci(buffer);
23306 +}
23307 +
23308 +static int proc_virtnet_status(char *buffer)
23309 +{
23310 +       return sprintf(buffer,
23311 +               "#CTotal:\t%d\n"
23312 +               "#CActive:\t%d\n",
23313 +               atomic_read(&nx_global_ctotal),
23314 +               atomic_read(&nx_global_cactive));
23315 +}
23316 +
23317 +int proc_nxi_info(struct nx_info *nxi, char *buffer)
23318 +{
23319 +       struct nx_addr_v4 *v4a;
23320 +#ifdef CONFIG_IPV6
23321 +       struct nx_addr_v6 *v6a;
23322 +#endif
23323 +       int length, i;
23324 +
23325 +       length = sprintf(buffer,
23326 +               "ID:\t%d\n"
23327 +               "Info:\t%p\n"
23328 +               "Bcast:\t" NIPQUAD_FMT "\n"
23329 +               "Lback:\t" NIPQUAD_FMT "\n",
23330 +               nxi->nx_id,
23331 +               nxi,
23332 +               NIPQUAD(nxi->v4_bcast.s_addr),
23333 +               NIPQUAD(nxi->v4_lback.s_addr));
23334 +
23335 +       if (!NX_IPV4(nxi))
23336 +               goto skip_v4;
23337 +       for (i = 0, v4a = &nxi->v4; v4a; i++, v4a = v4a->next)
23338 +               length += sprintf(buffer + length, "%d:\t" NXAV4_FMT "\n",
23339 +                       i, NXAV4(v4a));
23340 +skip_v4:
23341 +#ifdef CONFIG_IPV6
23342 +       if (!NX_IPV6(nxi))
23343 +               goto skip_v6;
23344 +       for (i = 0, v6a = &nxi->v6; v6a; i++, v6a = v6a->next)
23345 +               length += sprintf(buffer + length, "%d:\t" NXAV6_FMT "\n",
23346 +                       i, NXAV6(v6a));
23347 +skip_v6:
23348 +#endif
23349 +       return length;
23350 +}
23351 +
23352 +int proc_nxi_status(struct nx_info *nxi, char *buffer)
23353 +{
23354 +       int length;
23355 +
23356 +       length = sprintf(buffer,
23357 +               "UseCnt:\t%d\n"
23358 +               "Tasks:\t%d\n"
23359 +               "Flags:\t%016llx\n"
23360 +               "NCaps:\t%016llx\n",
23361 +               atomic_read(&nxi->nx_usecnt),
23362 +               atomic_read(&nxi->nx_tasks),
23363 +               (unsigned long long)nxi->nx_flags,
23364 +               (unsigned long long)nxi->nx_ncaps);
23365 +       return length;
23366 +}
23367 +
23368 +
23369 +
23370 +/* here the inode helpers */
23371 +
23372 +struct vs_entry {
23373 +       int len;
23374 +       char *name;
23375 +       mode_t mode;
23376 +       struct inode_operations *iop;
23377 +       struct file_operations *fop;
23378 +       union proc_op op;
23379 +};
23380 +
23381 +static struct inode *vs_proc_make_inode(struct super_block *sb, struct vs_entry *p)
23382 +{
23383 +       struct inode *inode = new_inode(sb);
23384 +
23385 +       if (!inode)
23386 +               goto out;
23387 +
23388 +       inode->i_mode = p->mode;
23389 +       if (p->iop)
23390 +               inode->i_op = p->iop;
23391 +       if (p->fop)
23392 +               inode->i_fop = p->fop;
23393 +
23394 +       inode->i_nlink = (p->mode & S_IFDIR) ? 2 : 1;
23395 +       inode->i_flags |= S_IMMUTABLE;
23396 +
23397 +       inode->i_mtime = inode->i_atime = inode->i_ctime = CURRENT_TIME;
23398 +
23399 +       inode->i_uid = 0;
23400 +       inode->i_gid = 0;
23401 +       inode->i_tag = 0;
23402 +out:
23403 +       return inode;
23404 +}
23405 +
23406 +static struct dentry *vs_proc_instantiate(struct inode *dir,
23407 +       struct dentry *dentry, int id, void *ptr)
23408 +{
23409 +       struct vs_entry *p = ptr;
23410 +       struct inode *inode = vs_proc_make_inode(dir->i_sb, p);
23411 +       struct dentry *error = ERR_PTR(-EINVAL);
23412 +
23413 +       if (!inode)
23414 +               goto out;
23415 +
23416 +       PROC_I(inode)->op = p->op;
23417 +       PROC_I(inode)->fd = id;
23418 +       d_add(dentry, inode);
23419 +       error = NULL;
23420 +out:
23421 +       return error;
23422 +}
23423 +
23424 +/* Lookups */
23425 +
23426 +typedef struct dentry *instantiate_t(struct inode *, struct dentry *, int, void *);
23427 +
23428 +/*
23429 + * Fill a directory entry.
23430 + *
23431 + * If possible create the dcache entry and derive our inode number and
23432 + * file type from dcache entry.
23433 + *
23434 + * Since all of the proc inode numbers are dynamically generated, the inode
23435 + * numbers do not exist until the inode is cache.  This means creating the
23436 + * the dcache entry in readdir is necessary to keep the inode numbers
23437 + * reported by readdir in sync with the inode numbers reported
23438 + * by stat.
23439 + */
23440 +static int proc_fill_cache(struct file *filp, void *dirent, filldir_t filldir,
23441 +       char *name, int len, instantiate_t instantiate, int id, void *ptr)
23442 +{
23443 +       struct dentry *child, *dir = filp->f_dentry;
23444 +       struct inode *inode;
23445 +       struct qstr qname;
23446 +       ino_t ino = 0;
23447 +       unsigned type = DT_UNKNOWN;
23448 +
23449 +       qname.name = name;
23450 +       qname.len  = len;
23451 +       qname.hash = full_name_hash(name, len);
23452 +
23453 +       child = d_lookup(dir, &qname);
23454 +       if (!child) {
23455 +               struct dentry *new;
23456 +               new = d_alloc(dir, &qname);
23457 +               if (new) {
23458 +                       child = instantiate(dir->d_inode, new, id, ptr);
23459 +                       if (child)
23460 +                               dput(new);
23461 +                       else
23462 +                               child = new;
23463 +               }
23464 +       }
23465 +       if (!child || IS_ERR(child) || !child->d_inode)
23466 +               goto end_instantiate;
23467 +       inode = child->d_inode;
23468 +       if (inode) {
23469 +               ino = inode->i_ino;
23470 +               type = inode->i_mode >> 12;
23471 +       }
23472 +       dput(child);
23473 +end_instantiate:
23474 +       if (!ino)
23475 +               ino = find_inode_number(dir, &qname);
23476 +       if (!ino)
23477 +               ino = 1;
23478 +       return filldir(dirent, name, len, filp->f_pos, ino, type);
23479 +}
23480 +
23481 +
23482 +
23483 +/* get and revalidate vx_info/xid */
23484 +
23485 +static inline
23486 +struct vx_info *get_proc_vx_info(struct inode *inode)
23487 +{
23488 +       return lookup_vx_info(PROC_I(inode)->fd);
23489 +}
23490 +
23491 +static int proc_xid_revalidate(struct dentry *dentry, struct nameidata *nd)
23492 +{
23493 +       struct inode *inode = dentry->d_inode;
23494 +       xid_t xid = PROC_I(inode)->fd;
23495 +
23496 +       if (!xid || xid_is_hashed(xid))
23497 +               return 1;
23498 +       d_drop(dentry);
23499 +       return 0;
23500 +}
23501 +
23502 +
23503 +/* get and revalidate nx_info/nid */
23504 +
23505 +static int proc_nid_revalidate(struct dentry *dentry, struct nameidata *nd)
23506 +{
23507 +       struct inode *inode = dentry->d_inode;
23508 +       nid_t nid = PROC_I(inode)->fd;
23509 +
23510 +       if (!nid || nid_is_hashed(nid))
23511 +               return 1;
23512 +       d_drop(dentry);
23513 +       return 0;
23514 +}
23515 +
23516 +
23517 +
23518 +#define PROC_BLOCK_SIZE (PAGE_SIZE - 1024)
23519 +
23520 +static ssize_t proc_vs_info_read(struct file *file, char __user *buf,
23521 +                         size_t count, loff_t *ppos)
23522 +{
23523 +       struct inode *inode = file->f_dentry->d_inode;
23524 +       unsigned long page;
23525 +       ssize_t length = 0;
23526 +
23527 +       if (count > PROC_BLOCK_SIZE)
23528 +               count = PROC_BLOCK_SIZE;
23529 +
23530 +       /* fade that out as soon as stable */
23531 +       WARN_ON(PROC_I(inode)->fd);
23532 +
23533 +       if (!(page = __get_free_page(GFP_KERNEL)))
23534 +               return -ENOMEM;
23535 +
23536 +       BUG_ON(!PROC_I(inode)->op.proc_vs_read);
23537 +       length = PROC_I(inode)->op.proc_vs_read((char *)page);
23538 +
23539 +       if (length >= 0)
23540 +               length = simple_read_from_buffer(buf, count, ppos,
23541 +                       (char *)page, length);
23542 +
23543 +       free_page(page);
23544 +       return length;
23545 +}
23546 +
23547 +static ssize_t proc_vx_info_read(struct file *file, char __user *buf,
23548 +                         size_t count, loff_t *ppos)
23549 +{
23550 +       struct inode *inode = file->f_dentry->d_inode;
23551 +       struct vx_info *vxi = NULL;
23552 +       xid_t xid = PROC_I(inode)->fd;
23553 +       unsigned long page;
23554 +       ssize_t length = 0;
23555 +
23556 +       if (count > PROC_BLOCK_SIZE)
23557 +               count = PROC_BLOCK_SIZE;
23558 +
23559 +       /* fade that out as soon as stable */
23560 +       WARN_ON(!xid);
23561 +       vxi = lookup_vx_info(xid);
23562 +       if (!vxi)
23563 +               goto out;
23564 +
23565 +       length = -ENOMEM;
23566 +       if (!(page = __get_free_page(GFP_KERNEL)))
23567 +               goto out_put;
23568 +
23569 +       BUG_ON(!PROC_I(inode)->op.proc_vxi_read);
23570 +       length = PROC_I(inode)->op.proc_vxi_read(vxi, (char *)page);
23571 +
23572 +       if (length >= 0)
23573 +               length = simple_read_from_buffer(buf, count, ppos,
23574 +                       (char *)page, length);
23575 +
23576 +       free_page(page);
23577 +out_put:
23578 +       put_vx_info(vxi);
23579 +out:
23580 +       return length;
23581 +}
23582 +
23583 +static ssize_t proc_nx_info_read(struct file *file, char __user *buf,
23584 +                         size_t count, loff_t *ppos)
23585 +{
23586 +       struct inode *inode = file->f_dentry->d_inode;
23587 +       struct nx_info *nxi = NULL;
23588 +       nid_t nid = PROC_I(inode)->fd;
23589 +       unsigned long page;
23590 +       ssize_t length = 0;
23591 +
23592 +       if (count > PROC_BLOCK_SIZE)
23593 +               count = PROC_BLOCK_SIZE;
23594 +
23595 +       /* fade that out as soon as stable */
23596 +       WARN_ON(!nid);
23597 +       nxi = lookup_nx_info(nid);
23598 +       if (!nxi)
23599 +               goto out;
23600 +
23601 +       length = -ENOMEM;
23602 +       if (!(page = __get_free_page(GFP_KERNEL)))
23603 +               goto out_put;
23604 +
23605 +       BUG_ON(!PROC_I(inode)->op.proc_nxi_read);
23606 +       length = PROC_I(inode)->op.proc_nxi_read(nxi, (char *)page);
23607 +
23608 +       if (length >= 0)
23609 +               length = simple_read_from_buffer(buf, count, ppos,
23610 +                       (char *)page, length);
23611 +
23612 +       free_page(page);
23613 +out_put:
23614 +       put_nx_info(nxi);
23615 +out:
23616 +       return length;
23617 +}
23618 +
23619 +
23620 +
23621 +/* here comes the lower level */
23622 +
23623 +
23624 +#define NOD(NAME, MODE, IOP, FOP, OP) {        \
23625 +       .len  = sizeof(NAME) - 1,       \
23626 +       .name = (NAME),                 \
23627 +       .mode = MODE,                   \
23628 +       .iop  = IOP,                    \
23629 +       .fop  = FOP,                    \
23630 +       .op   = OP,                     \
23631 +}
23632 +
23633 +
23634 +#define DIR(NAME, MODE, OTYPE)                         \
23635 +       NOD(NAME, (S_IFDIR | (MODE)),                   \
23636 +               &proc_ ## OTYPE ## _inode_operations,   \
23637 +               &proc_ ## OTYPE ## _file_operations, { } )
23638 +
23639 +#define INF(NAME, MODE, OTYPE)                         \
23640 +       NOD(NAME, (S_IFREG | (MODE)), NULL,             \
23641 +               &proc_vs_info_file_operations,          \
23642 +               { .proc_vs_read = &proc_##OTYPE } )
23643 +
23644 +#define VINF(NAME, MODE, OTYPE)                                \
23645 +       NOD(NAME, (S_IFREG | (MODE)), NULL,             \
23646 +               &proc_vx_info_file_operations,          \
23647 +               { .proc_vxi_read = &proc_##OTYPE } )
23648 +
23649 +#define NINF(NAME, MODE, OTYPE)                                \
23650 +       NOD(NAME, (S_IFREG | (MODE)), NULL,             \
23651 +               &proc_nx_info_file_operations,          \
23652 +               { .proc_nxi_read = &proc_##OTYPE } )
23653 +
23654 +
23655 +static struct file_operations proc_vs_info_file_operations = {
23656 +       .read =         proc_vs_info_read,
23657 +};
23658 +
23659 +static struct file_operations proc_vx_info_file_operations = {
23660 +       .read =         proc_vx_info_read,
23661 +};
23662 +
23663 +static struct dentry_operations proc_xid_dentry_operations = {
23664 +       .d_revalidate = proc_xid_revalidate,
23665 +};
23666 +
23667 +static struct vs_entry vx_base_stuff[] = {
23668 +       VINF("info",    S_IRUGO, vxi_info),
23669 +       VINF("status",  S_IRUGO, vxi_status),
23670 +       VINF("limit",   S_IRUGO, vxi_limit),
23671 +       VINF("sched",   S_IRUGO, vxi_sched),
23672 +       VINF("nsproxy", S_IRUGO, vxi_nsproxy0),
23673 +       VINF("nsproxy1",S_IRUGO, vxi_nsproxy1),
23674 +       VINF("cvirt",   S_IRUGO, vxi_cvirt),
23675 +       VINF("cacct",   S_IRUGO, vxi_cacct),
23676 +       {}
23677 +};
23678 +
23679 +
23680 +
23681 +
23682 +static struct dentry *proc_xid_instantiate(struct inode *dir,
23683 +       struct dentry *dentry, int id, void *ptr)
23684 +{
23685 +       dentry->d_op = &proc_xid_dentry_operations;
23686 +       return vs_proc_instantiate(dir, dentry, id, ptr);
23687 +}
23688 +
23689 +static struct dentry *proc_xid_lookup(struct inode *dir,
23690 +       struct dentry *dentry, struct nameidata *nd)
23691 +{
23692 +       struct vs_entry *p = vx_base_stuff;
23693 +       struct dentry *error = ERR_PTR(-ENOENT);
23694 +
23695 +       for (; p->name; p++) {
23696 +               if (p->len != dentry->d_name.len)
23697 +                       continue;
23698 +               if (!memcmp(dentry->d_name.name, p->name, p->len))
23699 +                       break;
23700 +       }
23701 +       if (!p->name)
23702 +               goto out;
23703 +
23704 +       error = proc_xid_instantiate(dir, dentry, PROC_I(dir)->fd, p);
23705 +out:
23706 +       return error;
23707 +}
23708 +
23709 +static int proc_xid_readdir(struct file *filp,
23710 +       void *dirent, filldir_t filldir)
23711 +{
23712 +       struct dentry *dentry = filp->f_dentry;
23713 +       struct inode *inode = dentry->d_inode;
23714 +       struct vs_entry *p = vx_base_stuff;
23715 +       int size = sizeof(vx_base_stuff) / sizeof(struct vs_entry);
23716 +       int pos, index;
23717 +       u64 ino;
23718 +
23719 +       pos = filp->f_pos;
23720 +       switch (pos) {
23721 +       case 0:
23722 +               ino = inode->i_ino;
23723 +               if (filldir(dirent, ".", 1, pos, ino, DT_DIR) < 0)
23724 +                       goto out;
23725 +               pos++;
23726 +               /* fall through */
23727 +       case 1:
23728 +               ino = parent_ino(dentry);
23729 +               if (filldir(dirent, "..", 2, pos, ino, DT_DIR) < 0)
23730 +                       goto out;
23731 +               pos++;
23732 +               /* fall through */
23733 +       default:
23734 +               index = pos - 2;
23735 +               if (index >= size)
23736 +                       goto out;
23737 +               for (p += index; p->name; p++) {
23738 +                       if (proc_fill_cache(filp, dirent, filldir, p->name, p->len,
23739 +                               vs_proc_instantiate, PROC_I(inode)->fd, p))
23740 +                               goto out;
23741 +                       pos++;
23742 +               }
23743 +       }
23744 +out:
23745 +       filp->f_pos = pos;
23746 +       return 1;
23747 +}
23748 +
23749 +
23750 +
23751 +static struct file_operations proc_nx_info_file_operations = {
23752 +       .read =         proc_nx_info_read,
23753 +};
23754 +
23755 +static struct dentry_operations proc_nid_dentry_operations = {
23756 +       .d_revalidate = proc_nid_revalidate,
23757 +};
23758 +
23759 +static struct vs_entry nx_base_stuff[] = {
23760 +       NINF("info",    S_IRUGO, nxi_info),
23761 +       NINF("status",  S_IRUGO, nxi_status),
23762 +       {}
23763 +};
23764 +
23765 +
23766 +static struct dentry *proc_nid_instantiate(struct inode *dir,
23767 +       struct dentry *dentry, int id, void *ptr)
23768 +{
23769 +       dentry->d_op = &proc_nid_dentry_operations;
23770 +       return vs_proc_instantiate(dir, dentry, id, ptr);
23771 +}
23772 +
23773 +static struct dentry *proc_nid_lookup(struct inode *dir,
23774 +       struct dentry *dentry, struct nameidata *nd)
23775 +{
23776 +       struct vs_entry *p = nx_base_stuff;
23777 +       struct dentry *error = ERR_PTR(-ENOENT);
23778 +
23779 +       for (; p->name; p++) {
23780 +               if (p->len != dentry->d_name.len)
23781 +                       continue;
23782 +               if (!memcmp(dentry->d_name.name, p->name, p->len))
23783 +                       break;
23784 +       }
23785 +       if (!p->name)
23786 +               goto out;
23787 +
23788 +       error = proc_nid_instantiate(dir, dentry, PROC_I(dir)->fd, p);
23789 +out:
23790 +       return error;
23791 +}
23792 +
23793 +static int proc_nid_readdir(struct file *filp,
23794 +       void *dirent, filldir_t filldir)
23795 +{
23796 +       struct dentry *dentry = filp->f_dentry;
23797 +       struct inode *inode = dentry->d_inode;
23798 +       struct vs_entry *p = nx_base_stuff;
23799 +       int size = sizeof(nx_base_stuff) / sizeof(struct vs_entry);
23800 +       int pos, index;
23801 +       u64 ino;
23802 +
23803 +       pos = filp->f_pos;
23804 +       switch (pos) {
23805 +       case 0:
23806 +               ino = inode->i_ino;
23807 +               if (filldir(dirent, ".", 1, pos, ino, DT_DIR) < 0)
23808 +                       goto out;
23809 +               pos++;
23810 +               /* fall through */
23811 +       case 1:
23812 +               ino = parent_ino(dentry);
23813 +               if (filldir(dirent, "..", 2, pos, ino, DT_DIR) < 0)
23814 +                       goto out;
23815 +               pos++;
23816 +               /* fall through */
23817 +       default:
23818 +               index = pos - 2;
23819 +               if (index >= size)
23820 +                       goto out;
23821 +               for (p += index; p->name; p++) {
23822 +                       if (proc_fill_cache(filp, dirent, filldir, p->name, p->len,
23823 +                               vs_proc_instantiate, PROC_I(inode)->fd, p))
23824 +                               goto out;
23825 +                       pos++;
23826 +               }
23827 +       }
23828 +out:
23829 +       filp->f_pos = pos;
23830 +       return 1;
23831 +}
23832 +
23833 +
23834 +#define MAX_MULBY10    ((~0U - 9) / 10)
23835 +
23836 +static inline int atovid(const char *str, int len)
23837 +{
23838 +       int vid, c;
23839 +
23840 +       vid = 0;
23841 +       while (len-- > 0) {
23842 +               c = *str - '0';
23843 +               str++;
23844 +               if (c > 9)
23845 +                       return -1;
23846 +               if (vid >= MAX_MULBY10)
23847 +                       return -1;
23848 +               vid *= 10;
23849 +               vid += c;
23850 +               if (!vid)
23851 +                       return -1;
23852 +       }
23853 +       return vid;
23854 +}
23855 +
23856 +/* now the upper level (virtual) */
23857 +
23858 +
23859 +static struct file_operations proc_xid_file_operations = {
23860 +       .read =         generic_read_dir,
23861 +       .readdir =      proc_xid_readdir,
23862 +};
23863 +
23864 +static struct inode_operations proc_xid_inode_operations = {
23865 +       .lookup =       proc_xid_lookup,
23866 +};
23867 +
23868 +static struct vs_entry vx_virtual_stuff[] = {
23869 +       INF("info",     S_IRUGO, virtual_info),
23870 +       INF("status",   S_IRUGO, virtual_status),
23871 +       DIR(NULL,       S_IRUGO | S_IXUGO, xid),
23872 +};
23873 +
23874 +
23875 +static struct dentry *proc_virtual_lookup(struct inode *dir,
23876 +       struct dentry *dentry, struct nameidata *nd)
23877 +{
23878 +       struct vs_entry *p = vx_virtual_stuff;
23879 +       struct dentry *error = ERR_PTR(-ENOENT);
23880 +       int id = 0;
23881 +
23882 +       for (; p->name; p++) {
23883 +               if (p->len != dentry->d_name.len)
23884 +                       continue;
23885 +               if (!memcmp(dentry->d_name.name, p->name, p->len))
23886 +                       break;
23887 +       }
23888 +       if (p->name)
23889 +               goto instantiate;
23890 +
23891 +       id = atovid(dentry->d_name.name, dentry->d_name.len);
23892 +       if ((id < 0) || !xid_is_hashed(id))
23893 +               goto out;
23894 +
23895 +instantiate:
23896 +       error = proc_xid_instantiate(dir, dentry, id, p);
23897 +out:
23898 +       return error;
23899 +}
23900 +
23901 +static struct file_operations proc_nid_file_operations = {
23902 +       .read =         generic_read_dir,
23903 +       .readdir =      proc_nid_readdir,
23904 +};
23905 +
23906 +static struct inode_operations proc_nid_inode_operations = {
23907 +       .lookup =       proc_nid_lookup,
23908 +};
23909 +
23910 +static struct vs_entry nx_virtnet_stuff[] = {
23911 +       INF("info",     S_IRUGO, virtnet_info),
23912 +       INF("status",   S_IRUGO, virtnet_status),
23913 +       DIR(NULL,       S_IRUGO | S_IXUGO, nid),
23914 +};
23915 +
23916 +
23917 +static struct dentry *proc_virtnet_lookup(struct inode *dir,
23918 +       struct dentry *dentry, struct nameidata *nd)
23919 +{
23920 +       struct vs_entry *p = nx_virtnet_stuff;
23921 +       struct dentry *error = ERR_PTR(-ENOENT);
23922 +       int id = 0;
23923 +
23924 +       for (; p->name; p++) {
23925 +               if (p->len != dentry->d_name.len)
23926 +                       continue;
23927 +               if (!memcmp(dentry->d_name.name, p->name, p->len))
23928 +                       break;
23929 +       }
23930 +       if (p->name)
23931 +               goto instantiate;
23932 +
23933 +       id = atovid(dentry->d_name.name, dentry->d_name.len);
23934 +       if ((id < 0) || !nid_is_hashed(id))
23935 +               goto out;
23936 +
23937 +instantiate:
23938 +       error = proc_nid_instantiate(dir, dentry, id, p);
23939 +out:
23940 +       return error;
23941 +}
23942 +
23943 +
23944 +#define PROC_MAXVIDS 32
23945 +
23946 +int proc_virtual_readdir(struct file *filp,
23947 +       void *dirent, filldir_t filldir)
23948 +{
23949 +       struct dentry *dentry = filp->f_dentry;
23950 +       struct inode *inode = dentry->d_inode;
23951 +       struct vs_entry *p = vx_virtual_stuff;
23952 +       int size = sizeof(vx_virtual_stuff) / sizeof(struct vs_entry);
23953 +       int pos, index;
23954 +       unsigned int xid_array[PROC_MAXVIDS];
23955 +       char buf[PROC_NUMBUF];
23956 +       unsigned int nr_xids, i;
23957 +       u64 ino;
23958 +
23959 +       pos = filp->f_pos;
23960 +       switch (pos) {
23961 +       case 0:
23962 +               ino = inode->i_ino;
23963 +               if (filldir(dirent, ".", 1, pos, ino, DT_DIR) < 0)
23964 +                       goto out;
23965 +               pos++;
23966 +               /* fall through */
23967 +       case 1:
23968 +               ino = parent_ino(dentry);
23969 +               if (filldir(dirent, "..", 2, pos, ino, DT_DIR) < 0)
23970 +                       goto out;
23971 +               pos++;
23972 +               /* fall through */
23973 +       default:
23974 +               index = pos - 2;
23975 +               if (index >= size)
23976 +                       goto entries;
23977 +               for (p += index; p->name; p++) {
23978 +                       if (proc_fill_cache(filp, dirent, filldir, p->name, p->len,
23979 +                               vs_proc_instantiate, 0, p))
23980 +                               goto out;
23981 +                       pos++;
23982 +               }
23983 +       entries:
23984 +               index = pos - size;
23985 +               p = &vx_virtual_stuff[size - 1];
23986 +               nr_xids = get_xid_list(index, xid_array, PROC_MAXVIDS);
23987 +               for (i = 0; i < nr_xids; i++) {
23988 +                       int n, xid = xid_array[i];
23989 +                       unsigned int j = PROC_NUMBUF;
23990 +
23991 +                       n = xid;
23992 +                       do
23993 +                               buf[--j] = '0' + (n % 10);
23994 +                       while (n /= 10);
23995 +
23996 +                       if (proc_fill_cache(filp, dirent, filldir,
23997 +                               buf + j, PROC_NUMBUF - j,
23998 +                               vs_proc_instantiate, xid, p))
23999 +                               goto out;
24000 +                       pos++;
24001 +               }
24002 +       }
24003 +out:
24004 +       filp->f_pos = pos;
24005 +       return 0;
24006 +}
24007 +
24008 +static int proc_virtual_getattr(struct vfsmount *mnt,
24009 +       struct dentry *dentry, struct kstat *stat)
24010 +{
24011 +       struct inode *inode = dentry->d_inode;
24012 +
24013 +       generic_fillattr(inode, stat);
24014 +       stat->nlink = 2 + atomic_read(&vx_global_cactive);
24015 +       return 0;
24016 +}
24017 +
24018 +static struct file_operations proc_virtual_dir_operations = {
24019 +       .read =         generic_read_dir,
24020 +       .readdir =      proc_virtual_readdir,
24021 +};
24022 +
24023 +static struct inode_operations proc_virtual_dir_inode_operations = {
24024 +       .getattr =      proc_virtual_getattr,
24025 +       .lookup =       proc_virtual_lookup,
24026 +};
24027 +
24028 +
24029 +
24030 +
24031 +
24032 +int proc_virtnet_readdir(struct file *filp,
24033 +       void *dirent, filldir_t filldir)
24034 +{
24035 +       struct dentry *dentry = filp->f_dentry;
24036 +       struct inode *inode = dentry->d_inode;
24037 +       struct vs_entry *p = nx_virtnet_stuff;
24038 +       int size = sizeof(nx_virtnet_stuff) / sizeof(struct vs_entry);
24039 +       int pos, index;
24040 +       unsigned int nid_array[PROC_MAXVIDS];
24041 +       char buf[PROC_NUMBUF];
24042 +       unsigned int nr_nids, i;
24043 +       u64 ino;
24044 +
24045 +       pos = filp->f_pos;
24046 +       switch (pos) {
24047 +       case 0:
24048 +               ino = inode->i_ino;
24049 +               if (filldir(dirent, ".", 1, pos, ino, DT_DIR) < 0)
24050 +                       goto out;
24051 +               pos++;
24052 +               /* fall through */
24053 +       case 1:
24054 +               ino = parent_ino(dentry);
24055 +               if (filldir(dirent, "..", 2, pos, ino, DT_DIR) < 0)
24056 +                       goto out;
24057 +               pos++;
24058 +               /* fall through */
24059 +       default:
24060 +               index = pos - 2;
24061 +               if (index >= size)
24062 +                       goto entries;
24063 +               for (p += index; p->name; p++) {
24064 +                       if (proc_fill_cache(filp, dirent, filldir, p->name, p->len,
24065 +                               vs_proc_instantiate, 0, p))
24066 +                               goto out;
24067 +                       pos++;
24068 +               }
24069 +       entries:
24070 +               index = pos - size;
24071 +               p = &nx_virtnet_stuff[size - 1];
24072 +               nr_nids = get_nid_list(index, nid_array, PROC_MAXVIDS);
24073 +               for (i = 0; i < nr_nids; i++) {
24074 +                       int n, nid = nid_array[i];
24075 +                       unsigned int j = PROC_NUMBUF;
24076 +
24077 +                       n = nid;
24078 +                       do
24079 +                               buf[--j] = '0' + (n % 10);
24080 +                       while (n /= 10);
24081 +
24082 +                       if (proc_fill_cache(filp, dirent, filldir,
24083 +                               buf + j, PROC_NUMBUF - j,
24084 +                               vs_proc_instantiate, nid, p))
24085 +                               goto out;
24086 +                       pos++;
24087 +               }
24088 +       }
24089 +out:
24090 +       filp->f_pos = pos;
24091 +       return 0;
24092 +}
24093 +
24094 +static int proc_virtnet_getattr(struct vfsmount *mnt,
24095 +       struct dentry *dentry, struct kstat *stat)
24096 +{
24097 +       struct inode *inode = dentry->d_inode;
24098 +
24099 +       generic_fillattr(inode, stat);
24100 +       stat->nlink = 2 + atomic_read(&nx_global_cactive);
24101 +       return 0;
24102 +}
24103 +
24104 +static struct file_operations proc_virtnet_dir_operations = {
24105 +       .read =         generic_read_dir,
24106 +       .readdir =      proc_virtnet_readdir,
24107 +};
24108 +
24109 +static struct inode_operations proc_virtnet_dir_inode_operations = {
24110 +       .getattr =      proc_virtnet_getattr,
24111 +       .lookup =       proc_virtnet_lookup,
24112 +};
24113 +
24114 +
24115 +
24116 +void proc_vx_init(void)
24117 +{
24118 +       struct proc_dir_entry *ent;
24119 +
24120 +       ent = proc_mkdir("virtual", 0);
24121 +       if (ent) {
24122 +               ent->proc_fops = &proc_virtual_dir_operations;
24123 +               ent->proc_iops = &proc_virtual_dir_inode_operations;
24124 +       }
24125 +       proc_virtual = ent;
24126 +
24127 +       ent = proc_mkdir("virtnet", 0);
24128 +       if (ent) {
24129 +               ent->proc_fops = &proc_virtnet_dir_operations;
24130 +               ent->proc_iops = &proc_virtnet_dir_inode_operations;
24131 +       }
24132 +       proc_virtnet = ent;
24133 +}
24134 +
24135 +
24136 +
24137 +
24138 +/* per pid info */
24139 +
24140 +
24141 +int proc_pid_vx_info(struct task_struct *p, char *buffer)
24142 +{
24143 +       struct vx_info *vxi;
24144 +       char *orig = buffer;
24145 +
24146 +       buffer += sprintf(buffer, "XID:\t%d\n", vx_task_xid(p));
24147 +
24148 +       vxi = task_get_vx_info(p);
24149 +       if (!vxi)
24150 +               goto out;
24151 +
24152 +       buffer += sprintf(buffer, "BCaps:\t");
24153 +       buffer = print_cap_t(buffer, &vxi->vx_bcaps);
24154 +       buffer += sprintf(buffer, "\n");
24155 +       buffer += sprintf(buffer, "CCaps:\t%016llx\n",
24156 +               (unsigned long long)vxi->vx_ccaps);
24157 +       buffer += sprintf(buffer, "CFlags:\t%016llx\n",
24158 +               (unsigned long long)vxi->vx_flags);
24159 +       buffer += sprintf(buffer, "CIPid:\t%d\n", vxi->vx_initpid);
24160 +
24161 +       put_vx_info(vxi);
24162 +out:
24163 +       return buffer - orig;
24164 +}
24165 +
24166 +
24167 +int proc_pid_nx_info(struct task_struct *p, char *buffer)
24168 +{
24169 +       struct nx_info *nxi;
24170 +       struct nx_addr_v4 *v4a;
24171 +#ifdef CONFIG_IPV6
24172 +       struct nx_addr_v6 *v6a;
24173 +#endif
24174 +       char *orig = buffer;
24175 +       int i;
24176 +
24177 +       buffer += sprintf(buffer, "NID:\t%d\n", nx_task_nid(p));
24178 +
24179 +       nxi = task_get_nx_info(p);
24180 +       if (!nxi)
24181 +               goto out;
24182 +
24183 +       buffer += sprintf(buffer, "NCaps:\t%016llx\n",
24184 +               (unsigned long long)nxi->nx_ncaps);
24185 +       buffer += sprintf(buffer, "NFlags:\t%016llx\n",
24186 +               (unsigned long long)nxi->nx_flags);
24187 +
24188 +       buffer += sprintf(buffer,
24189 +               "V4Root[bcast]:\t" NIPQUAD_FMT "\n",
24190 +               NIPQUAD(nxi->v4_bcast.s_addr));
24191 +       buffer += sprintf (buffer,
24192 +               "V4Root[lback]:\t" NIPQUAD_FMT "\n",
24193 +               NIPQUAD(nxi->v4_lback.s_addr));
24194 +       if (!NX_IPV4(nxi))
24195 +               goto skip_v4;
24196 +       for (i = 0, v4a = &nxi->v4; v4a; i++, v4a = v4a->next)
24197 +               buffer += sprintf(buffer, "V4Root[%d]:\t" NXAV4_FMT "\n",
24198 +                       i, NXAV4(v4a));
24199 +skip_v4:
24200 +#ifdef CONFIG_IPV6
24201 +       if (!NX_IPV6(nxi))
24202 +               goto skip_v6;
24203 +       for (i = 0, v6a = &nxi->v6; v6a; i++, v6a = v6a->next)
24204 +               buffer += sprintf(buffer, "V6Root[%d]:\t" NXAV6_FMT "\n",
24205 +                       i, NXAV6(v6a));
24206 +skip_v6:
24207 +#endif
24208 +       put_nx_info(nxi);
24209 +out:
24210 +       return buffer - orig;
24211 +}
24212 +
24213 diff -NurpP --minimal linux-2.6.32.6/kernel/vserver/sched.c linux-2.6.32.6-vs2.3.0.36.28/kernel/vserver/sched.c
24214 --- linux-2.6.32.6/kernel/vserver/sched.c       1970-01-01 01:00:00.000000000 +0100
24215 +++ linux-2.6.32.6-vs2.3.0.36.28/kernel/vserver/sched.c 2009-12-03 20:04:56.000000000 +0100
24216 @@ -0,0 +1,414 @@
24217 +/*
24218 + *  linux/kernel/vserver/sched.c
24219 + *
24220 + *  Virtual Server: Scheduler Support
24221 + *
24222 + *  Copyright (C) 2004-2007  Herbert Pötzl
24223 + *
24224 + *  V0.01  adapted Sam Vilains version to 2.6.3
24225 + *  V0.02  removed legacy interface
24226 + *  V0.03  changed vcmds to vxi arg
24227 + *  V0.04  removed older and legacy interfaces
24228 + *
24229 + */
24230 +
24231 +#include <linux/vs_context.h>
24232 +#include <linux/vs_sched.h>
24233 +#include <linux/vserver/sched_cmd.h>
24234 +
24235 +#include <asm/uaccess.h>
24236 +
24237 +
24238 +#define vxd_check_range(val, min, max) do {            \
24239 +       vxlprintk((val < min) || (val > max),           \
24240 +               "check_range(%ld,%ld,%ld)",             \
24241 +               (long)val, (long)min, (long)max,        \
24242 +               __FILE__, __LINE__);                    \
24243 +       } while (0)
24244 +
24245 +
24246 +void vx_update_sched_param(struct _vx_sched *sched,
24247 +       struct _vx_sched_pc *sched_pc)
24248 +{
24249 +       unsigned int set_mask = sched->update_mask;
24250 +
24251 +       if (set_mask & VXSM_FILL_RATE)
24252 +               sched_pc->fill_rate[0] = sched->fill_rate[0];
24253 +       if (set_mask & VXSM_INTERVAL)
24254 +               sched_pc->interval[0] = sched->interval[0];
24255 +       if (set_mask & VXSM_FILL_RATE2)
24256 +               sched_pc->fill_rate[1] = sched->fill_rate[1];
24257 +       if (set_mask & VXSM_INTERVAL2)
24258 +               sched_pc->interval[1] = sched->interval[1];
24259 +       if (set_mask & VXSM_TOKENS)
24260 +               sched_pc->tokens = sched->tokens;
24261 +       if (set_mask & VXSM_TOKENS_MIN)
24262 +               sched_pc->tokens_min = sched->tokens_min;
24263 +       if (set_mask & VXSM_TOKENS_MAX)
24264 +               sched_pc->tokens_max = sched->tokens_max;
24265 +       if (set_mask & VXSM_PRIO_BIAS)
24266 +               sched_pc->prio_bias = sched->prio_bias;
24267 +
24268 +       if (set_mask & VXSM_IDLE_TIME)
24269 +               sched_pc->flags |= VXSF_IDLE_TIME;
24270 +       else
24271 +               sched_pc->flags &= ~VXSF_IDLE_TIME;
24272 +
24273 +       /* reset time */
24274 +       sched_pc->norm_time = jiffies;
24275 +}
24276 +
24277 +
24278 +/*
24279 + * recalculate the context's scheduling tokens
24280 + *
24281 + * ret > 0 : number of tokens available
24282 + * ret < 0 : on hold, check delta_min[]
24283 + *          -1 only jiffies
24284 + *          -2 also idle time
24285 + *
24286 + */
24287 +int vx_tokens_recalc(struct _vx_sched_pc *sched_pc,
24288 +       unsigned long *norm_time, unsigned long *idle_time, int delta_min[2])
24289 +{
24290 +       long delta;
24291 +       long tokens = 0;
24292 +       int flags = sched_pc->flags;
24293 +
24294 +       /* how much time did pass? */
24295 +       delta = *norm_time - sched_pc->norm_time;
24296 +       // printk("@ %ld, %ld, %ld\n", *norm_time, sched_pc->norm_time, jiffies);
24297 +       vxd_check_range(delta, 0, INT_MAX);
24298 +
24299 +       if (delta >= sched_pc->interval[0]) {
24300 +               long tokens, integral;
24301 +
24302 +               /* calc integral token part */
24303 +               tokens = delta / sched_pc->interval[0];
24304 +               integral = tokens * sched_pc->interval[0];
24305 +               tokens *= sched_pc->fill_rate[0];
24306 +#ifdef CONFIG_VSERVER_HARDCPU
24307 +               delta_min[0] = delta - integral;
24308 +               vxd_check_range(delta_min[0], 0, sched_pc->interval[0]);
24309 +#endif
24310 +               /* advance time */
24311 +               sched_pc->norm_time += delta;
24312 +
24313 +               /* add tokens */
24314 +               sched_pc->tokens += tokens;
24315 +               sched_pc->token_time += tokens;
24316 +       } else
24317 +               delta_min[0] = delta;
24318 +
24319 +#ifdef CONFIG_VSERVER_IDLETIME
24320 +       if (!(flags & VXSF_IDLE_TIME))
24321 +               goto skip_idle;
24322 +
24323 +       /* how much was the idle skip? */
24324 +       delta = *idle_time - sched_pc->idle_time;
24325 +       vxd_check_range(delta, 0, INT_MAX);
24326 +
24327 +       if (delta >= sched_pc->interval[1]) {
24328 +               long tokens, integral;
24329 +
24330 +               /* calc fair share token part */
24331 +               tokens = delta / sched_pc->interval[1];
24332 +               integral = tokens * sched_pc->interval[1];
24333 +               tokens *= sched_pc->fill_rate[1];
24334 +               delta_min[1] = delta - integral;
24335 +               vxd_check_range(delta_min[1], 0, sched_pc->interval[1]);
24336 +
24337 +               /* advance idle time */
24338 +               sched_pc->idle_time += integral;
24339 +
24340 +               /* add tokens */
24341 +               sched_pc->tokens += tokens;
24342 +               sched_pc->token_time += tokens;
24343 +       } else
24344 +               delta_min[1] = delta;
24345 +skip_idle:
24346 +#endif
24347 +
24348 +       /* clip at maximum */
24349 +       if (sched_pc->tokens > sched_pc->tokens_max)
24350 +               sched_pc->tokens = sched_pc->tokens_max;
24351 +       tokens = sched_pc->tokens;
24352 +
24353 +       if ((flags & VXSF_ONHOLD)) {
24354 +               /* can we unhold? */
24355 +               if (tokens >= sched_pc->tokens_min) {
24356 +                       flags &= ~VXSF_ONHOLD;
24357 +                       sched_pc->hold_ticks +=
24358 +                               *norm_time - sched_pc->onhold;
24359 +               } else
24360 +                       goto on_hold;
24361 +       } else {
24362 +               /* put on hold? */
24363 +               if (tokens <= 0) {
24364 +                       flags |= VXSF_ONHOLD;
24365 +                       sched_pc->onhold = *norm_time;
24366 +                       goto on_hold;
24367 +               }
24368 +       }
24369 +       sched_pc->flags = flags;
24370 +       return tokens;
24371 +
24372 +on_hold:
24373 +       tokens = sched_pc->tokens_min - tokens;
24374 +       sched_pc->flags = flags;
24375 +       // BUG_ON(tokens < 0); probably doesn't hold anymore
24376 +
24377 +#ifdef CONFIG_VSERVER_HARDCPU
24378 +       /* next interval? */
24379 +       if (!sched_pc->fill_rate[0])
24380 +               delta_min[0] = HZ;
24381 +       else if (tokens > sched_pc->fill_rate[0])
24382 +               delta_min[0] += sched_pc->interval[0] *
24383 +                       tokens / sched_pc->fill_rate[0];
24384 +       else
24385 +               delta_min[0] = sched_pc->interval[0] - delta_min[0];
24386 +       vxd_check_range(delta_min[0], 0, INT_MAX);
24387 +
24388 +#ifdef CONFIG_VSERVER_IDLETIME
24389 +       if (!(flags & VXSF_IDLE_TIME))
24390 +               return -1;
24391 +
24392 +       /* next interval? */
24393 +       if (!sched_pc->fill_rate[1])
24394 +               delta_min[1] = HZ;
24395 +       else if (tokens > sched_pc->fill_rate[1])
24396 +               delta_min[1] += sched_pc->interval[1] *
24397 +                       tokens / sched_pc->fill_rate[1];
24398 +       else
24399 +               delta_min[1] = sched_pc->interval[1] - delta_min[1];
24400 +       vxd_check_range(delta_min[1], 0, INT_MAX);
24401 +
24402 +       return -2;
24403 +#else
24404 +       return -1;
24405 +#endif /* CONFIG_VSERVER_IDLETIME */
24406 +#else
24407 +       return 0;
24408 +#endif /* CONFIG_VSERVER_HARDCPU */
24409 +}
24410 +
24411 +static inline unsigned long msec_to_ticks(unsigned long msec)
24412 +{
24413 +       return msecs_to_jiffies(msec);
24414 +}
24415 +
24416 +static inline unsigned long ticks_to_msec(unsigned long ticks)
24417 +{
24418 +       return jiffies_to_msecs(ticks);
24419 +}
24420 +
24421 +static inline unsigned long ticks_to_usec(unsigned long ticks)
24422 +{
24423 +       return jiffies_to_usecs(ticks);
24424 +}
24425 +
24426 +
24427 +static int do_set_sched(struct vx_info *vxi, struct vcmd_sched_v5 *data)
24428 +{
24429 +       unsigned int set_mask = data->mask;
24430 +       unsigned int update_mask;
24431 +       int i, cpu;
24432 +
24433 +       /* Sanity check data values */
24434 +       if (data->tokens_max <= 0)
24435 +               data->tokens_max = HZ;
24436 +       if (data->tokens_min < 0)
24437 +               data->tokens_min = HZ / 3;
24438 +       if (data->tokens_min >= data->tokens_max)
24439 +               data->tokens_min = data->tokens_max;
24440 +
24441 +       if (data->prio_bias > MAX_PRIO_BIAS)
24442 +               data->prio_bias = MAX_PRIO_BIAS;
24443 +       if (data->prio_bias < MIN_PRIO_BIAS)
24444 +               data->prio_bias = MIN_PRIO_BIAS;
24445 +
24446 +       spin_lock(&vxi->sched.tokens_lock);
24447 +
24448 +       /* sync up on delayed updates */
24449 +       for_each_cpu_mask(cpu, vxi->sched.update)
24450 +               vx_update_sched_param(&vxi->sched,
24451 +                       &vx_per_cpu(vxi, sched_pc, cpu));
24452 +
24453 +       if (set_mask & VXSM_FILL_RATE)
24454 +               vxi->sched.fill_rate[0] = data->fill_rate[0];
24455 +       if (set_mask & VXSM_FILL_RATE2)
24456 +               vxi->sched.fill_rate[1] = data->fill_rate[1];
24457 +       if (set_mask & VXSM_INTERVAL)
24458 +               vxi->sched.interval[0] = (set_mask & VXSM_MSEC) ?
24459 +                       msec_to_ticks(data->interval[0]) : data->interval[0];
24460 +       if (set_mask & VXSM_INTERVAL2)
24461 +               vxi->sched.interval[1] = (set_mask & VXSM_MSEC) ?
24462 +                       msec_to_ticks(data->interval[1]) : data->interval[1];
24463 +       if (set_mask & VXSM_TOKENS)
24464 +               vxi->sched.tokens = data->tokens;
24465 +       if (set_mask & VXSM_TOKENS_MIN)
24466 +               vxi->sched.tokens_min = data->tokens_min;
24467 +       if (set_mask & VXSM_TOKENS_MAX)
24468 +               vxi->sched.tokens_max = data->tokens_max;
24469 +       if (set_mask & VXSM_PRIO_BIAS)
24470 +               vxi->sched.prio_bias = data->prio_bias;
24471 +
24472 +       /* Sanity check rate/interval */
24473 +       for (i = 0; i < 2; i++) {
24474 +               if (data->fill_rate[i] < 0)
24475 +                       data->fill_rate[i] = 0;
24476 +               if (data->interval[i] <= 0)
24477 +                       data->interval[i] = HZ;
24478 +       }
24479 +
24480 +       update_mask = vxi->sched.update_mask & VXSM_SET_MASK;
24481 +       update_mask |= (set_mask & (VXSM_SET_MASK | VXSM_IDLE_TIME));
24482 +       vxi->sched.update_mask = update_mask;
24483 +
24484 +#ifdef CONFIG_SMP
24485 +       rmb();
24486 +       if (set_mask & VXSM_CPU_ID) {
24487 +               vxi->sched.update = cpumask_of_cpu(data->cpu_id);
24488 +               cpus_and(vxi->sched.update, cpu_online_map,
24489 +                       vxi->sched.update);
24490 +       } else
24491 +               vxi->sched.update = cpu_online_map;
24492 +
24493 +       /* forced reload? */
24494 +       if (set_mask & VXSM_FORCE) {
24495 +               for_each_cpu_mask(cpu, vxi->sched.update)
24496 +                       vx_update_sched_param(&vxi->sched,
24497 +                               &vx_per_cpu(vxi, sched_pc, cpu));
24498 +               vxi->sched.update = CPU_MASK_NONE;
24499 +       }
24500 +#else
24501 +       /* on UP we update immediately */
24502 +       vx_update_sched_param(&vxi->sched,
24503 +               &vx_per_cpu(vxi, sched_pc, 0));
24504 +#endif
24505 +
24506 +       spin_unlock(&vxi->sched.tokens_lock);
24507 +       return 0;
24508 +}
24509 +
24510 +
24511 +#define COPY_IDS(C) C(cpu_id); C(bucket_id)
24512 +#define COPY_PRI(C) C(prio_bias)
24513 +#define COPY_TOK(C) C(tokens); C(tokens_min); C(tokens_max)
24514 +#define COPY_FRI(C) C(fill_rate[0]); C(interval[0]);   \
24515 +                   C(fill_rate[1]); C(interval[1]);
24516 +
24517 +#define COPY_VALUE(name) vc_data.name = data->name
24518 +
24519 +static int do_set_sched_v4(struct vx_info *vxi, struct vcmd_set_sched_v4 *data)
24520 +{
24521 +       struct vcmd_sched_v5 vc_data;
24522 +
24523 +       vc_data.mask = data->set_mask;
24524 +       COPY_IDS(COPY_VALUE);
24525 +       COPY_PRI(COPY_VALUE);
24526 +       COPY_TOK(COPY_VALUE);
24527 +       vc_data.fill_rate[0] = vc_data.fill_rate[1] = data->fill_rate;
24528 +       vc_data.interval[0] = vc_data.interval[1] = data->interval;
24529 +       return do_set_sched(vxi, &vc_data);
24530 +}
24531 +
24532 +int vc_set_sched_v4(struct vx_info *vxi, void __user *data)
24533 +{
24534 +       struct vcmd_set_sched_v4 vc_data;
24535 +
24536 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
24537 +               return -EFAULT;
24538 +
24539 +       return do_set_sched_v4(vxi, &vc_data);
24540 +}
24541 +
24542 +       /* latest interface is v5 */
24543 +
24544 +int vc_set_sched(struct vx_info *vxi, void __user *data)
24545 +{
24546 +       struct vcmd_sched_v5 vc_data;
24547 +
24548 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
24549 +               return -EFAULT;
24550 +
24551 +       return do_set_sched(vxi, &vc_data);
24552 +}
24553 +
24554 +
24555 +#define COPY_PRI(C) C(prio_bias)
24556 +#define COPY_TOK(C) C(tokens); C(tokens_min); C(tokens_max)
24557 +#define COPY_FRI(C) C(fill_rate[0]); C(interval[0]);    \
24558 +                   C(fill_rate[1]); C(interval[1]);
24559 +
24560 +#define COPY_VALUE(name) vc_data.name = data->name
24561 +
24562 +
24563 +int vc_get_sched(struct vx_info *vxi, void __user *data)
24564 +{
24565 +       struct vcmd_sched_v5 vc_data;
24566 +
24567 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
24568 +               return -EFAULT;
24569 +
24570 +       if (vc_data.mask & VXSM_CPU_ID) {
24571 +               int cpu = vc_data.cpu_id;
24572 +               struct _vx_sched_pc *data;
24573 +
24574 +               if (!cpu_possible(cpu))
24575 +                       return -EINVAL;
24576 +
24577 +               data = &vx_per_cpu(vxi, sched_pc, cpu);
24578 +               COPY_TOK(COPY_VALUE);
24579 +               COPY_PRI(COPY_VALUE);
24580 +               COPY_FRI(COPY_VALUE);
24581 +
24582 +               if (data->flags & VXSF_IDLE_TIME)
24583 +                       vc_data.mask |= VXSM_IDLE_TIME;
24584 +       } else {
24585 +               struct _vx_sched *data = &vxi->sched;
24586 +
24587 +               COPY_TOK(COPY_VALUE);
24588 +               COPY_PRI(COPY_VALUE);
24589 +               COPY_FRI(COPY_VALUE);
24590 +       }
24591 +
24592 +       if (vc_data.mask & VXSM_MSEC) {
24593 +               vc_data.interval[0] = ticks_to_msec(vc_data.interval[0]);
24594 +               vc_data.interval[1] = ticks_to_msec(vc_data.interval[1]);
24595 +       }
24596 +
24597 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
24598 +               return -EFAULT;
24599 +       return 0;
24600 +}
24601 +
24602 +
24603 +int vc_sched_info(struct vx_info *vxi, void __user *data)
24604 +{
24605 +       struct vcmd_sched_info vc_data;
24606 +       int cpu;
24607 +
24608 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
24609 +               return -EFAULT;
24610 +
24611 +       cpu = vc_data.cpu_id;
24612 +       if (!cpu_possible(cpu))
24613 +               return -EINVAL;
24614 +
24615 +       if (vxi) {
24616 +               struct _vx_sched_pc *sched_pc =
24617 +                       &vx_per_cpu(vxi, sched_pc, cpu);
24618 +
24619 +               vc_data.user_msec = ticks_to_msec(sched_pc->user_ticks);
24620 +               vc_data.sys_msec = ticks_to_msec(sched_pc->sys_ticks);
24621 +               vc_data.hold_msec = ticks_to_msec(sched_pc->hold_ticks);
24622 +               vc_data.vavavoom = sched_pc->vavavoom;
24623 +       }
24624 +       vc_data.token_usec = ticks_to_usec(1);
24625 +
24626 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
24627 +               return -EFAULT;
24628 +       return 0;
24629 +}
24630 +
24631 diff -NurpP --minimal linux-2.6.32.6/kernel/vserver/sched_init.h linux-2.6.32.6-vs2.3.0.36.28/kernel/vserver/sched_init.h
24632 --- linux-2.6.32.6/kernel/vserver/sched_init.h  1970-01-01 01:00:00.000000000 +0100
24633 +++ linux-2.6.32.6-vs2.3.0.36.28/kernel/vserver/sched_init.h    2009-12-03 20:04:56.000000000 +0100
24634 @@ -0,0 +1,50 @@
24635 +
24636 +static inline void vx_info_init_sched(struct _vx_sched *sched)
24637 +{
24638 +       static struct lock_class_key tokens_lock_key;
24639 +
24640 +       /* scheduling; hard code starting values as constants */
24641 +       sched->fill_rate[0]     = 1;
24642 +       sched->interval[0]      = 4;
24643 +       sched->fill_rate[1]     = 1;
24644 +       sched->interval[1]      = 8;
24645 +       sched->tokens           = HZ >> 2;
24646 +       sched->tokens_min       = HZ >> 4;
24647 +       sched->tokens_max       = HZ >> 1;
24648 +       sched->tokens_lock      = SPIN_LOCK_UNLOCKED;
24649 +       sched->prio_bias        = 0;
24650 +
24651 +       lockdep_set_class(&sched->tokens_lock, &tokens_lock_key);
24652 +}
24653 +
24654 +static inline
24655 +void vx_info_init_sched_pc(struct _vx_sched_pc *sched_pc, int cpu)
24656 +{
24657 +       sched_pc->fill_rate[0]  = 1;
24658 +       sched_pc->interval[0]   = 4;
24659 +       sched_pc->fill_rate[1]  = 1;
24660 +       sched_pc->interval[1]   = 8;
24661 +       sched_pc->tokens        = HZ >> 2;
24662 +       sched_pc->tokens_min    = HZ >> 4;
24663 +       sched_pc->tokens_max    = HZ >> 1;
24664 +       sched_pc->prio_bias     = 0;
24665 +       sched_pc->vavavoom      = 0;
24666 +       sched_pc->token_time    = 0;
24667 +       sched_pc->idle_time     = 0;
24668 +       sched_pc->norm_time     = jiffies;
24669 +
24670 +       sched_pc->user_ticks = 0;
24671 +       sched_pc->sys_ticks = 0;
24672 +       sched_pc->hold_ticks = 0;
24673 +}
24674 +
24675 +static inline void vx_info_exit_sched(struct _vx_sched *sched)
24676 +{
24677 +       return;
24678 +}
24679 +
24680 +static inline
24681 +void vx_info_exit_sched_pc(struct _vx_sched_pc *sched_pc, int cpu)
24682 +{
24683 +       return;
24684 +}
24685 diff -NurpP --minimal linux-2.6.32.6/kernel/vserver/sched_proc.h linux-2.6.32.6-vs2.3.0.36.28/kernel/vserver/sched_proc.h
24686 --- linux-2.6.32.6/kernel/vserver/sched_proc.h  1970-01-01 01:00:00.000000000 +0100
24687 +++ linux-2.6.32.6-vs2.3.0.36.28/kernel/vserver/sched_proc.h    2009-12-03 20:04:56.000000000 +0100
24688 @@ -0,0 +1,57 @@
24689 +#ifndef _VX_SCHED_PROC_H
24690 +#define _VX_SCHED_PROC_H
24691 +
24692 +
24693 +static inline
24694 +int vx_info_proc_sched(struct _vx_sched *sched, char *buffer)
24695 +{
24696 +       int length = 0;
24697 +
24698 +       length += sprintf(buffer,
24699 +               "FillRate:\t%8d,%d\n"
24700 +               "Interval:\t%8d,%d\n"
24701 +               "TokensMin:\t%8d\n"
24702 +               "TokensMax:\t%8d\n"
24703 +               "PrioBias:\t%8d\n",
24704 +               sched->fill_rate[0],
24705 +               sched->fill_rate[1],
24706 +               sched->interval[0],
24707 +               sched->interval[1],
24708 +               sched->tokens_min,
24709 +               sched->tokens_max,
24710 +               sched->prio_bias);
24711 +       return length;
24712 +}
24713 +
24714 +static inline
24715 +int vx_info_proc_sched_pc(struct _vx_sched_pc *sched_pc,
24716 +       char *buffer, int cpu)
24717 +{
24718 +       int length = 0;
24719 +
24720 +       length += sprintf(buffer + length,
24721 +               "cpu %d: %lld %lld %lld %ld %ld", cpu,
24722 +               (unsigned long long)sched_pc->user_ticks,
24723 +               (unsigned long long)sched_pc->sys_ticks,
24724 +               (unsigned long long)sched_pc->hold_ticks,
24725 +               sched_pc->token_time,
24726 +               sched_pc->idle_time);
24727 +       length += sprintf(buffer + length,
24728 +               " %c%c %d %d %d %d/%d %d/%d",
24729 +               (sched_pc->flags & VXSF_ONHOLD) ? 'H' : 'R',
24730 +               (sched_pc->flags & VXSF_IDLE_TIME) ? 'I' : '-',
24731 +               sched_pc->tokens,
24732 +               sched_pc->tokens_min,
24733 +               sched_pc->tokens_max,
24734 +               sched_pc->fill_rate[0],
24735 +               sched_pc->interval[0],
24736 +               sched_pc->fill_rate[1],
24737 +               sched_pc->interval[1]);
24738 +       length += sprintf(buffer + length,
24739 +               " %d %d\n",
24740 +               sched_pc->prio_bias,
24741 +               sched_pc->vavavoom);
24742 +       return length;
24743 +}
24744 +
24745 +#endif /* _VX_SCHED_PROC_H */
24746 diff -NurpP --minimal linux-2.6.32.6/kernel/vserver/signal.c linux-2.6.32.6-vs2.3.0.36.28/kernel/vserver/signal.c
24747 --- linux-2.6.32.6/kernel/vserver/signal.c      1970-01-01 01:00:00.000000000 +0100
24748 +++ linux-2.6.32.6-vs2.3.0.36.28/kernel/vserver/signal.c        2009-12-03 20:04:56.000000000 +0100
24749 @@ -0,0 +1,132 @@
24750 +/*
24751 + *  linux/kernel/vserver/signal.c
24752 + *
24753 + *  Virtual Server: Signal Support
24754 + *
24755 + *  Copyright (C) 2003-2007  Herbert Pötzl
24756 + *
24757 + *  V0.01  broken out from vcontext V0.05
24758 + *  V0.02  changed vcmds to vxi arg
24759 + *  V0.03  adjusted siginfo for kill
24760 + *
24761 + */
24762 +
24763 +#include <asm/uaccess.h>
24764 +
24765 +#include <linux/vs_context.h>
24766 +#include <linux/vs_pid.h>
24767 +#include <linux/vserver/signal_cmd.h>
24768 +
24769 +
24770 +int vx_info_kill(struct vx_info *vxi, int pid, int sig)
24771 +{
24772 +       int retval, count = 0;
24773 +       struct task_struct *p;
24774 +       struct siginfo *sip = SEND_SIG_PRIV;
24775 +
24776 +       retval = -ESRCH;
24777 +       vxdprintk(VXD_CBIT(misc, 4),
24778 +               "vx_info_kill(%p[#%d],%d,%d)*",
24779 +               vxi, vxi->vx_id, pid, sig);
24780 +       read_lock(&tasklist_lock);
24781 +       switch (pid) {
24782 +       case  0:
24783 +       case -1:
24784 +               for_each_process(p) {
24785 +                       int err = 0;
24786 +
24787 +                       if (vx_task_xid(p) != vxi->vx_id || p->pid <= 1 ||
24788 +                               (pid && vxi->vx_initpid == p->pid))
24789 +                               continue;
24790 +
24791 +                       err = group_send_sig_info(sig, sip, p);
24792 +                       ++count;
24793 +                       if (err != -EPERM)
24794 +                               retval = err;
24795 +               }
24796 +               break;
24797 +
24798 +       case 1:
24799 +               if (vxi->vx_initpid) {
24800 +                       pid = vxi->vx_initpid;
24801 +                       /* for now, only SIGINT to private init ... */
24802 +                       if (!vx_info_flags(vxi, VXF_STATE_ADMIN, 0) &&
24803 +                               /* ... as long as there are tasks left */
24804 +                               (atomic_read(&vxi->vx_tasks) > 1))
24805 +                               sig = SIGINT;
24806 +               }
24807 +               /* fallthrough */
24808 +       default:
24809 +               p = find_task_by_real_pid(pid);
24810 +               if (p) {
24811 +                       if (vx_task_xid(p) == vxi->vx_id)
24812 +                               retval = group_send_sig_info(sig, sip, p);
24813 +               }
24814 +               break;
24815 +       }
24816 +       read_unlock(&tasklist_lock);
24817 +       vxdprintk(VXD_CBIT(misc, 4),
24818 +               "vx_info_kill(%p[#%d],%d,%d,%ld) = %d",
24819 +               vxi, vxi->vx_id, pid, sig, (long)sip, retval);
24820 +       return retval;
24821 +}
24822 +
24823 +int vc_ctx_kill(struct vx_info *vxi, void __user *data)
24824 +{
24825 +       struct vcmd_ctx_kill_v0 vc_data;
24826 +
24827 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
24828 +               return -EFAULT;
24829 +
24830 +       /* special check to allow guest shutdown */
24831 +       if (!vx_info_flags(vxi, VXF_STATE_ADMIN, 0) &&
24832 +               /* forbid killall pid=0 when init is present */
24833 +               (((vc_data.pid < 1) && vxi->vx_initpid) ||
24834 +               (vc_data.pid > 1)))
24835 +               return -EACCES;
24836 +
24837 +       return vx_info_kill(vxi, vc_data.pid, vc_data.sig);
24838 +}
24839 +
24840 +
24841 +static int __wait_exit(struct vx_info *vxi)
24842 +{
24843 +       DECLARE_WAITQUEUE(wait, current);
24844 +       int ret = 0;
24845 +
24846 +       add_wait_queue(&vxi->vx_wait, &wait);
24847 +       set_current_state(TASK_INTERRUPTIBLE);
24848 +
24849 +wait:
24850 +       if (vx_info_state(vxi,
24851 +               VXS_SHUTDOWN | VXS_HASHED | VXS_HELPER) == VXS_SHUTDOWN)
24852 +               goto out;
24853 +       if (signal_pending(current)) {
24854 +               ret = -ERESTARTSYS;
24855 +               goto out;
24856 +       }
24857 +       schedule();
24858 +       goto wait;
24859 +
24860 +out:
24861 +       set_current_state(TASK_RUNNING);
24862 +       remove_wait_queue(&vxi->vx_wait, &wait);
24863 +       return ret;
24864 +}
24865 +
24866 +
24867 +
24868 +int vc_wait_exit(struct vx_info *vxi, void __user *data)
24869 +{
24870 +       struct vcmd_wait_exit_v0 vc_data;
24871 +       int ret;
24872 +
24873 +       ret = __wait_exit(vxi);
24874 +       vc_data.reboot_cmd = vxi->reboot_cmd;
24875 +       vc_data.exit_code = vxi->exit_code;
24876 +
24877 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
24878 +               ret = -EFAULT;
24879 +       return ret;
24880 +}
24881 +
24882 diff -NurpP --minimal linux-2.6.32.6/kernel/vserver/space.c linux-2.6.32.6-vs2.3.0.36.28/kernel/vserver/space.c
24883 --- linux-2.6.32.6/kernel/vserver/space.c       1970-01-01 01:00:00.000000000 +0100
24884 +++ linux-2.6.32.6-vs2.3.0.36.28/kernel/vserver/space.c 2009-12-03 20:04:56.000000000 +0100
24885 @@ -0,0 +1,375 @@
24886 +/*
24887 + *  linux/kernel/vserver/space.c
24888 + *
24889 + *  Virtual Server: Context Space Support
24890 + *
24891 + *  Copyright (C) 2003-2007  Herbert Pötzl
24892 + *
24893 + *  V0.01  broken out from context.c 0.07
24894 + *  V0.02  added task locking for namespace
24895 + *  V0.03  broken out vx_enter_namespace
24896 + *  V0.04  added *space support and commands
24897 + *
24898 + */
24899 +
24900 +#include <linux/utsname.h>
24901 +#include <linux/nsproxy.h>
24902 +#include <linux/err.h>
24903 +#include <linux/fs_struct.h>
24904 +#include <asm/uaccess.h>
24905 +
24906 +#include <linux/vs_context.h>
24907 +#include <linux/vserver/space.h>
24908 +#include <linux/vserver/space_cmd.h>
24909 +
24910 +atomic_t vs_global_nsproxy     = ATOMIC_INIT(0);
24911 +atomic_t vs_global_fs          = ATOMIC_INIT(0);
24912 +atomic_t vs_global_mnt_ns      = ATOMIC_INIT(0);
24913 +atomic_t vs_global_uts_ns      = ATOMIC_INIT(0);
24914 +atomic_t vs_global_user_ns     = ATOMIC_INIT(0);
24915 +atomic_t vs_global_pid_ns      = ATOMIC_INIT(0);
24916 +
24917 +
24918 +/* namespace functions */
24919 +
24920 +#include <linux/mnt_namespace.h>
24921 +#include <linux/user_namespace.h>
24922 +#include <linux/pid_namespace.h>
24923 +#include <linux/ipc_namespace.h>
24924 +#include <net/net_namespace.h>
24925 +
24926 +
24927 +static const struct vcmd_space_mask_v1 space_mask_v0 = {
24928 +       .mask = CLONE_FS |
24929 +               CLONE_NEWNS |
24930 +               CLONE_NEWUTS |
24931 +               CLONE_NEWIPC |
24932 +               CLONE_NEWUSER |
24933 +               0
24934 +};
24935 +
24936 +static const struct vcmd_space_mask_v1 space_mask = {
24937 +       .mask = CLONE_FS |
24938 +               CLONE_NEWNS |
24939 +               CLONE_NEWUTS |
24940 +               CLONE_NEWIPC |
24941 +               CLONE_NEWUSER |
24942 +#ifdef CONFIG_PID_NS
24943 +               CLONE_NEWPID |
24944 +#endif
24945 +#ifdef CONFIG_NET_NS
24946 +               CLONE_NEWNET |
24947 +#endif
24948 +               0
24949 +};
24950 +
24951 +static const struct vcmd_space_mask_v1 default_space_mask = {
24952 +       .mask = CLONE_FS |
24953 +               CLONE_NEWNS |
24954 +               CLONE_NEWUTS |
24955 +               CLONE_NEWIPC |
24956 +               CLONE_NEWUSER |
24957 +#ifdef CONFIG_PID_NS
24958 +//             CLONE_NEWPID |
24959 +#endif
24960 +               0
24961 +};
24962 +
24963 +/*
24964 + *     build a new nsproxy mix
24965 + *      assumes that both proxies are 'const'
24966 + *     does not touch nsproxy refcounts
24967 + *     will hold a reference on the result.
24968 + */
24969 +
24970 +struct nsproxy *vs_mix_nsproxy(struct nsproxy *old_nsproxy,
24971 +       struct nsproxy *new_nsproxy, unsigned long mask)
24972 +{
24973 +       struct mnt_namespace *old_ns;
24974 +       struct uts_namespace *old_uts;
24975 +       struct ipc_namespace *old_ipc;
24976 +#ifdef CONFIG_PID_NS
24977 +       struct pid_namespace *old_pid;
24978 +#endif
24979 +#ifdef CONFIG_NET_NS
24980 +       struct net *old_net;
24981 +#endif
24982 +       struct nsproxy *nsproxy;
24983 +
24984 +       nsproxy = copy_nsproxy(old_nsproxy);
24985 +       if (!nsproxy)
24986 +               goto out;
24987 +
24988 +       if (mask & CLONE_NEWNS) {
24989 +               old_ns = nsproxy->mnt_ns;
24990 +               nsproxy->mnt_ns = new_nsproxy->mnt_ns;
24991 +               if (nsproxy->mnt_ns)
24992 +                       get_mnt_ns(nsproxy->mnt_ns);
24993 +       } else
24994 +               old_ns = NULL;
24995 +
24996 +       if (mask & CLONE_NEWUTS) {
24997 +               old_uts = nsproxy->uts_ns;
24998 +               nsproxy->uts_ns = new_nsproxy->uts_ns;
24999 +               if (nsproxy->uts_ns)
25000 +                       get_uts_ns(nsproxy->uts_ns);
25001 +       } else
25002 +               old_uts = NULL;
25003 +
25004 +       if (mask & CLONE_NEWIPC) {
25005 +               old_ipc = nsproxy->ipc_ns;
25006 +               nsproxy->ipc_ns = new_nsproxy->ipc_ns;
25007 +               if (nsproxy->ipc_ns)
25008 +                       get_ipc_ns(nsproxy->ipc_ns);
25009 +       } else
25010 +               old_ipc = NULL;
25011 +
25012 +#ifdef CONFIG_PID_NS
25013 +       if (mask & CLONE_NEWPID) {
25014 +               old_pid = nsproxy->pid_ns;
25015 +               nsproxy->pid_ns = new_nsproxy->pid_ns;
25016 +               if (nsproxy->pid_ns)
25017 +                       get_pid_ns(nsproxy->pid_ns);
25018 +       } else
25019 +               old_pid = NULL;
25020 +#endif
25021 +#ifdef CONFIG_NET_NS
25022 +       if (mask & CLONE_NEWNET) {
25023 +               old_net = nsproxy->net_ns;
25024 +               nsproxy->net_ns = new_nsproxy->net_ns;
25025 +               if (nsproxy->net_ns)
25026 +                       get_net(nsproxy->net_ns);
25027 +       } else
25028 +               old_net = NULL;
25029 +#endif
25030 +       if (old_ns)
25031 +               put_mnt_ns(old_ns);
25032 +       if (old_uts)
25033 +               put_uts_ns(old_uts);
25034 +       if (old_ipc)
25035 +               put_ipc_ns(old_ipc);
25036 +#ifdef CONFIG_PID_NS
25037 +       if (old_pid)
25038 +               put_pid_ns(old_pid);
25039 +#endif
25040 +#ifdef CONFIG_NET_NS
25041 +       if (old_net)
25042 +               put_net(old_net);
25043 +#endif
25044 +out:
25045 +       return nsproxy;
25046 +}
25047 +
25048 +
25049 +/*
25050 + *     merge two nsproxy structs into a new one.
25051 + *     will hold a reference on the result.
25052 + */
25053 +
25054 +static inline
25055 +struct nsproxy *__vs_merge_nsproxy(struct nsproxy *old,
25056 +       struct nsproxy *proxy, unsigned long mask)
25057 +{
25058 +       struct nsproxy null_proxy = { .mnt_ns = NULL };
25059 +
25060 +       if (!proxy)
25061 +               return NULL;
25062 +
25063 +       if (mask) {
25064 +               /* vs_mix_nsproxy returns with reference */
25065 +               return vs_mix_nsproxy(old ? old : &null_proxy,
25066 +                       proxy, mask);
25067 +       }
25068 +       get_nsproxy(proxy);
25069 +       return proxy;
25070 +}
25071 +
25072 +
25073 +int vx_enter_space(struct vx_info *vxi, unsigned long mask, unsigned index)
25074 +{
25075 +       struct nsproxy *proxy, *proxy_cur, *proxy_new;
25076 +       struct fs_struct *fs_cur, *fs = NULL;
25077 +       int ret, kill = 0;
25078 +
25079 +       vxdprintk(VXD_CBIT(space, 8), "vx_enter_space(%p[#%u],0x%08lx,%d)",
25080 +               vxi, vxi->vx_id, mask, index);
25081 +
25082 +       if (vx_info_flags(vxi, VXF_INFO_PRIVATE, 0))
25083 +               return -EACCES;
25084 +
25085 +       if (!mask)
25086 +               mask = vxi->vx_nsmask[index];
25087 +
25088 +       if ((mask & vxi->vx_nsmask[index]) != mask)
25089 +               return -EINVAL;
25090 +
25091 +       if (mask & CLONE_FS) {
25092 +               fs = copy_fs_struct(vxi->vx_fs[index]);
25093 +               if (!fs)
25094 +                       return -ENOMEM;
25095 +       }
25096 +       proxy = vxi->vx_nsproxy[index];
25097 +
25098 +       vxdprintk(VXD_CBIT(space, 9),
25099 +               "vx_enter_space(%p[#%u],0x%08lx,%d) -> (%p,%p)",
25100 +               vxi, vxi->vx_id, mask, index, proxy, fs);
25101 +
25102 +       task_lock(current);
25103 +       fs_cur = current->fs;
25104 +
25105 +       if (mask & CLONE_FS) {
25106 +               write_lock(&fs_cur->lock);
25107 +               current->fs = fs;
25108 +               kill = !--fs_cur->users;
25109 +               write_unlock(&fs_cur->lock);
25110 +       }
25111 +
25112 +       proxy_cur = current->nsproxy;
25113 +       get_nsproxy(proxy_cur);
25114 +       task_unlock(current);
25115 +
25116 +       if (kill)
25117 +               free_fs_struct(fs_cur);
25118 +
25119 +       proxy_new = __vs_merge_nsproxy(proxy_cur, proxy, mask);
25120 +       if (IS_ERR(proxy_new)) {
25121 +               ret = PTR_ERR(proxy_new);
25122 +               goto out_put;
25123 +       }
25124 +
25125 +       proxy_new = xchg(&current->nsproxy, proxy_new);
25126 +       ret = 0;
25127 +
25128 +       if (proxy_new)
25129 +               put_nsproxy(proxy_new);
25130 +out_put:
25131 +       if (proxy_cur)
25132 +               put_nsproxy(proxy_cur);
25133 +       return ret;
25134 +}
25135 +
25136 +
25137 +int vx_set_space(struct vx_info *vxi, unsigned long mask, unsigned index)
25138 +{
25139 +       struct nsproxy *proxy_vxi, *proxy_cur, *proxy_new;
25140 +       struct fs_struct *fs_vxi, *fs;
25141 +       int ret, kill = 0;
25142 +
25143 +       vxdprintk(VXD_CBIT(space, 8), "vx_set_space(%p[#%u],0x%08lx,%d)",
25144 +               vxi, vxi->vx_id, mask, index);
25145 +#if 0
25146 +       if (!mask)
25147 +               mask = default_space_mask.mask;
25148 +#endif
25149 +       if ((mask & space_mask.mask) != mask)
25150 +               return -EINVAL;
25151 +
25152 +       proxy_vxi = vxi->vx_nsproxy[index];
25153 +       fs_vxi = vxi->vx_fs[index];
25154 +
25155 +       if (mask & CLONE_FS) {
25156 +               fs = copy_fs_struct(current->fs);
25157 +               if (!fs)
25158 +                       return -ENOMEM;
25159 +       }
25160 +
25161 +       task_lock(current);
25162 +
25163 +       if (mask & CLONE_FS) {
25164 +               write_lock(&fs_vxi->lock);
25165 +               vxi->vx_fs[index] = fs;
25166 +               kill = !--fs_vxi->users;
25167 +               write_unlock(&fs_vxi->lock);
25168 +       }
25169 +
25170 +       proxy_cur = current->nsproxy;
25171 +       get_nsproxy(proxy_cur);
25172 +       task_unlock(current);
25173 +
25174 +       if (kill)
25175 +               free_fs_struct(fs_vxi);
25176 +
25177 +       proxy_new = __vs_merge_nsproxy(proxy_vxi, proxy_cur, mask);
25178 +       if (IS_ERR(proxy_new)) {
25179 +               ret = PTR_ERR(proxy_new);
25180 +               goto out_put;
25181 +       }
25182 +
25183 +       proxy_new = xchg(&vxi->vx_nsproxy[index], proxy_new);
25184 +       vxi->vx_nsmask[index] |= mask;
25185 +       ret = 0;
25186 +
25187 +       if (proxy_new)
25188 +               put_nsproxy(proxy_new);
25189 +out_put:
25190 +       if (proxy_cur)
25191 +               put_nsproxy(proxy_cur);
25192 +       return ret;
25193 +}
25194 +
25195 +
25196 +int vc_enter_space_v1(struct vx_info *vxi, void __user *data)
25197 +{
25198 +       struct vcmd_space_mask_v1 vc_data = { .mask = 0 };
25199 +
25200 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
25201 +               return -EFAULT;
25202 +
25203 +       return vx_enter_space(vxi, vc_data.mask, 0);
25204 +}
25205 +
25206 +int vc_enter_space(struct vx_info *vxi, void __user *data)
25207 +{
25208 +       struct vcmd_space_mask_v2 vc_data = { .mask = 0 };
25209 +
25210 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
25211 +               return -EFAULT;
25212 +
25213 +       if (vc_data.index >= VX_SPACES)
25214 +               return -EINVAL;
25215 +
25216 +       return vx_enter_space(vxi, vc_data.mask, vc_data.index);
25217 +}
25218 +
25219 +int vc_set_space_v1(struct vx_info *vxi, void __user *data)
25220 +{
25221 +       struct vcmd_space_mask_v1 vc_data = { .mask = 0 };
25222 +
25223 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
25224 +               return -EFAULT;
25225 +
25226 +       return vx_set_space(vxi, vc_data.mask, 0);
25227 +}
25228 +
25229 +int vc_set_space(struct vx_info *vxi, void __user *data)
25230 +{
25231 +       struct vcmd_space_mask_v2 vc_data = { .mask = 0 };
25232 +
25233 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
25234 +               return -EFAULT;
25235 +
25236 +       if (vc_data.index >= VX_SPACES)
25237 +               return -EINVAL;
25238 +
25239 +       return vx_set_space(vxi, vc_data.mask, vc_data.index);
25240 +}
25241 +
25242 +int vc_get_space_mask(void __user *data, int type)
25243 +{
25244 +       const struct vcmd_space_mask_v1 *mask;
25245 +
25246 +       if (type == 0)
25247 +               mask = &space_mask_v0;
25248 +       else if (type == 1)
25249 +               mask = &space_mask;
25250 +       else
25251 +               mask = &default_space_mask;
25252 +
25253 +       vxdprintk(VXD_CBIT(space, 10),
25254 +               "vc_get_space_mask(%d) = %08llx", type, mask->mask);
25255 +
25256 +       if (copy_to_user(data, mask, sizeof(*mask)))
25257 +               return -EFAULT;
25258 +       return 0;
25259 +}
25260 +
25261 diff -NurpP --minimal linux-2.6.32.6/kernel/vserver/switch.c linux-2.6.32.6-vs2.3.0.36.28/kernel/vserver/switch.c
25262 --- linux-2.6.32.6/kernel/vserver/switch.c      1970-01-01 01:00:00.000000000 +0100
25263 +++ linux-2.6.32.6-vs2.3.0.36.28/kernel/vserver/switch.c        2009-12-03 20:04:56.000000000 +0100
25264 @@ -0,0 +1,546 @@
25265 +/*
25266 + *  linux/kernel/vserver/switch.c
25267 + *
25268 + *  Virtual Server: Syscall Switch
25269 + *
25270 + *  Copyright (C) 2003-2007  Herbert Pötzl
25271 + *
25272 + *  V0.01  syscall switch
25273 + *  V0.02  added signal to context
25274 + *  V0.03  added rlimit functions
25275 + *  V0.04  added iattr, task/xid functions
25276 + *  V0.05  added debug/history stuff
25277 + *  V0.06  added compat32 layer
25278 + *  V0.07  vcmd args and perms
25279 + *  V0.08  added status commands
25280 + *  V0.09  added tag commands
25281 + *  V0.10  added oom bias
25282 + *  V0.11  added device commands
25283 + *
25284 + */
25285 +
25286 +#include <linux/vs_context.h>
25287 +#include <linux/vs_network.h>
25288 +#include <linux/vserver/switch.h>
25289 +
25290 +#include "vci_config.h"
25291 +
25292 +
25293 +static inline
25294 +int vc_get_version(uint32_t id)
25295 +{
25296 +       return VCI_VERSION;
25297 +}
25298 +
25299 +static inline
25300 +int vc_get_vci(uint32_t id)
25301 +{
25302 +       return vci_kernel_config();
25303 +}
25304 +
25305 +#include <linux/vserver/context_cmd.h>
25306 +#include <linux/vserver/cvirt_cmd.h>
25307 +#include <linux/vserver/cacct_cmd.h>
25308 +#include <linux/vserver/limit_cmd.h>
25309 +#include <linux/vserver/network_cmd.h>
25310 +#include <linux/vserver/sched_cmd.h>
25311 +#include <linux/vserver/debug_cmd.h>
25312 +#include <linux/vserver/inode_cmd.h>
25313 +#include <linux/vserver/dlimit_cmd.h>
25314 +#include <linux/vserver/signal_cmd.h>
25315 +#include <linux/vserver/space_cmd.h>
25316 +#include <linux/vserver/tag_cmd.h>
25317 +#include <linux/vserver/device_cmd.h>
25318 +
25319 +#include <linux/vserver/inode.h>
25320 +#include <linux/vserver/dlimit.h>
25321 +
25322 +
25323 +#ifdef CONFIG_COMPAT
25324 +#define __COMPAT(name, id, data, compat)       \
25325 +       (compat) ? name ## _x32(id, data) : name(id, data)
25326 +#define __COMPAT_NO_ID(name, data, compat)     \
25327 +       (compat) ? name ## _x32(data) : name(data)
25328 +#else
25329 +#define __COMPAT(name, id, data, compat)       \
25330 +       name(id, data)
25331 +#define __COMPAT_NO_ID(name, data, compat)     \
25332 +       name(data)
25333 +#endif
25334 +
25335 +
25336 +static inline
25337 +long do_vcmd(uint32_t cmd, uint32_t id,
25338 +       struct vx_info *vxi, struct nx_info *nxi,
25339 +       void __user *data, int compat)
25340 +{
25341 +       switch (cmd) {
25342 +
25343 +       case VCMD_get_version:
25344 +               return vc_get_version(id);
25345 +       case VCMD_get_vci:
25346 +               return vc_get_vci(id);
25347 +
25348 +       case VCMD_task_xid:
25349 +               return vc_task_xid(id);
25350 +       case VCMD_vx_info:
25351 +               return vc_vx_info(vxi, data);
25352 +
25353 +       case VCMD_task_nid:
25354 +               return vc_task_nid(id);
25355 +       case VCMD_nx_info:
25356 +               return vc_nx_info(nxi, data);
25357 +
25358 +       case VCMD_task_tag:
25359 +               return vc_task_tag(id);
25360 +
25361 +       case VCMD_set_space_v1:
25362 +               return vc_set_space_v1(vxi, data);
25363 +       /* this is version 2 */
25364 +       case VCMD_set_space:
25365 +               return vc_set_space(vxi, data);
25366 +
25367 +       case VCMD_get_space_mask_v0:
25368 +               return vc_get_space_mask(data, 0);
25369 +       /* this is version 1 */
25370 +       case VCMD_get_space_mask:
25371 +               return vc_get_space_mask(data, 1);
25372 +
25373 +       case VCMD_get_space_default:
25374 +               return vc_get_space_mask(data, -1);
25375 +
25376 +#ifdef CONFIG_IA32_EMULATION
25377 +       case VCMD_get_rlimit:
25378 +               return __COMPAT(vc_get_rlimit, vxi, data, compat);
25379 +       case VCMD_set_rlimit:
25380 +               return __COMPAT(vc_set_rlimit, vxi, data, compat);
25381 +#else
25382 +       case VCMD_get_rlimit:
25383 +               return vc_get_rlimit(vxi, data);
25384 +       case VCMD_set_rlimit:
25385 +               return vc_set_rlimit(vxi, data);
25386 +#endif
25387 +       case VCMD_get_rlimit_mask:
25388 +               return vc_get_rlimit_mask(id, data);
25389 +       case VCMD_reset_hits:
25390 +               return vc_reset_hits(vxi, data);
25391 +       case VCMD_reset_minmax:
25392 +               return vc_reset_minmax(vxi, data);
25393 +
25394 +       case VCMD_get_vhi_name:
25395 +               return vc_get_vhi_name(vxi, data);
25396 +       case VCMD_set_vhi_name:
25397 +               return vc_set_vhi_name(vxi, data);
25398 +
25399 +       case VCMD_ctx_stat:
25400 +               return vc_ctx_stat(vxi, data);
25401 +       case VCMD_virt_stat:
25402 +               return vc_virt_stat(vxi, data);
25403 +       case VCMD_sock_stat:
25404 +               return vc_sock_stat(vxi, data);
25405 +       case VCMD_rlimit_stat:
25406 +               return vc_rlimit_stat(vxi, data);
25407 +
25408 +       case VCMD_set_cflags:
25409 +               return vc_set_cflags(vxi, data);
25410 +       case VCMD_get_cflags:
25411 +               return vc_get_cflags(vxi, data);
25412 +
25413 +       /* this is version 1 */
25414 +       case VCMD_set_ccaps:
25415 +               return vc_set_ccaps(vxi, data);
25416 +       /* this is version 1 */
25417 +       case VCMD_get_ccaps:
25418 +               return vc_get_ccaps(vxi, data);
25419 +       case VCMD_set_bcaps:
25420 +               return vc_set_bcaps(vxi, data);
25421 +       case VCMD_get_bcaps:
25422 +               return vc_get_bcaps(vxi, data);
25423 +
25424 +       case VCMD_set_badness:
25425 +               return vc_set_badness(vxi, data);
25426 +       case VCMD_get_badness:
25427 +               return vc_get_badness(vxi, data);
25428 +
25429 +       case VCMD_set_nflags:
25430 +               return vc_set_nflags(nxi, data);
25431 +       case VCMD_get_nflags:
25432 +               return vc_get_nflags(nxi, data);
25433 +
25434 +       case VCMD_set_ncaps:
25435 +               return vc_set_ncaps(nxi, data);
25436 +       case VCMD_get_ncaps:
25437 +               return vc_get_ncaps(nxi, data);
25438 +
25439 +       case VCMD_set_sched_v4:
25440 +               return vc_set_sched_v4(vxi, data);
25441 +       /* this is version 5 */
25442 +       case VCMD_set_sched:
25443 +               return vc_set_sched(vxi, data);
25444 +       case VCMD_get_sched:
25445 +               return vc_get_sched(vxi, data);
25446 +       case VCMD_sched_info:
25447 +               return vc_sched_info(vxi, data);
25448 +
25449 +       case VCMD_add_dlimit:
25450 +               return __COMPAT(vc_add_dlimit, id, data, compat);
25451 +       case VCMD_rem_dlimit:
25452 +               return __COMPAT(vc_rem_dlimit, id, data, compat);
25453 +       case VCMD_set_dlimit:
25454 +               return __COMPAT(vc_set_dlimit, id, data, compat);
25455 +       case VCMD_get_dlimit:
25456 +               return __COMPAT(vc_get_dlimit, id, data, compat);
25457 +
25458 +       case VCMD_ctx_kill:
25459 +               return vc_ctx_kill(vxi, data);
25460 +
25461 +       case VCMD_wait_exit:
25462 +               return vc_wait_exit(vxi, data);
25463 +
25464 +       case VCMD_get_iattr:
25465 +               return __COMPAT_NO_ID(vc_get_iattr, data, compat);
25466 +       case VCMD_set_iattr:
25467 +               return __COMPAT_NO_ID(vc_set_iattr, data, compat);
25468 +
25469 +       case VCMD_fget_iattr:
25470 +               return vc_fget_iattr(id, data);
25471 +       case VCMD_fset_iattr:
25472 +               return vc_fset_iattr(id, data);
25473 +
25474 +       case VCMD_enter_space_v0:
25475 +               return vc_enter_space_v1(vxi, NULL);
25476 +       case VCMD_enter_space_v1:
25477 +               return vc_enter_space_v1(vxi, data);
25478 +       /* this is version 2 */
25479 +       case VCMD_enter_space:
25480 +               return vc_enter_space(vxi, data);
25481 +
25482 +       case VCMD_ctx_create_v0:
25483 +               return vc_ctx_create(id, NULL);
25484 +       case VCMD_ctx_create:
25485 +               return vc_ctx_create(id, data);
25486 +       case VCMD_ctx_migrate_v0:
25487 +               return vc_ctx_migrate(vxi, NULL);
25488 +       case VCMD_ctx_migrate:
25489 +               return vc_ctx_migrate(vxi, data);
25490 +
25491 +       case VCMD_net_create_v0:
25492 +               return vc_net_create(id, NULL);
25493 +       case VCMD_net_create:
25494 +               return vc_net_create(id, data);
25495 +       case VCMD_net_migrate:
25496 +               return vc_net_migrate(nxi, data);
25497 +
25498 +       case VCMD_tag_migrate:
25499 +               return vc_tag_migrate(id);
25500 +
25501 +       case VCMD_net_add:
25502 +               return vc_net_add(nxi, data);
25503 +       case VCMD_net_remove:
25504 +               return vc_net_remove(nxi, data);
25505 +
25506 +       case VCMD_net_add_ipv4:
25507 +               return vc_net_add_ipv4(nxi, data);
25508 +       case VCMD_net_remove_ipv4:
25509 +               return vc_net_remove_ipv4(nxi, data);
25510 +#ifdef CONFIG_IPV6
25511 +       case VCMD_net_add_ipv6:
25512 +               return vc_net_add_ipv6(nxi, data);
25513 +       case VCMD_net_remove_ipv6:
25514 +               return vc_net_remove_ipv6(nxi, data);
25515 +#endif
25516 +/*     case VCMD_add_match_ipv4:
25517 +               return vc_add_match_ipv4(nxi, data);
25518 +       case VCMD_get_match_ipv4:
25519 +               return vc_get_match_ipv4(nxi, data);
25520 +#ifdef CONFIG_IPV6
25521 +       case VCMD_add_match_ipv6:
25522 +               return vc_add_match_ipv6(nxi, data);
25523 +       case VCMD_get_match_ipv6:
25524 +               return vc_get_match_ipv6(nxi, data);
25525 +#endif */
25526 +
25527 +#ifdef CONFIG_VSERVER_DEVICE
25528 +       case VCMD_set_mapping:
25529 +               return __COMPAT(vc_set_mapping, vxi, data, compat);
25530 +       case VCMD_unset_mapping:
25531 +               return __COMPAT(vc_unset_mapping, vxi, data, compat);
25532 +#endif
25533 +#ifdef CONFIG_VSERVER_HISTORY
25534 +       case VCMD_dump_history:
25535 +               return vc_dump_history(id);
25536 +       case VCMD_read_history:
25537 +               return __COMPAT(vc_read_history, id, data, compat);
25538 +#endif
25539 +#ifdef CONFIG_VSERVER_MONITOR
25540 +       case VCMD_read_monitor:
25541 +               return __COMPAT(vc_read_monitor, id, data, compat);
25542 +#endif
25543 +       default:
25544 +               vxwprintk_task(1, "unimplemented VCMD_%02d_%d[%d]",
25545 +                       VC_CATEGORY(cmd), VC_COMMAND(cmd), VC_VERSION(cmd));
25546 +       }
25547 +       return -ENOSYS;
25548 +}
25549 +
25550 +
25551 +#define        __VCMD(vcmd, _perm, _args, _flags)              \
25552 +       case VCMD_ ## vcmd: perm = _perm;               \
25553 +               args = _args; flags = _flags; break
25554 +
25555 +
25556 +#define VCA_NONE       0x00
25557 +#define VCA_VXI                0x01
25558 +#define VCA_NXI                0x02
25559 +
25560 +#define VCF_NONE       0x00
25561 +#define VCF_INFO       0x01
25562 +#define VCF_ADMIN      0x02
25563 +#define VCF_ARES       0x06    /* includes admin */
25564 +#define VCF_SETUP      0x08
25565 +
25566 +#define VCF_ZIDOK      0x10    /* zero id okay */
25567 +
25568 +
25569 +static inline
25570 +long do_vserver(uint32_t cmd, uint32_t id, void __user *data, int compat)
25571 +{
25572 +       long ret;
25573 +       int permit = -1, state = 0;
25574 +       int perm = -1, args = 0, flags = 0;
25575 +       struct vx_info *vxi = NULL;
25576 +       struct nx_info *nxi = NULL;
25577 +
25578 +       switch (cmd) {
25579 +       /* unpriviledged commands */
25580 +       __VCMD(get_version,      0, VCA_NONE,   0);
25581 +       __VCMD(get_vci,          0, VCA_NONE,   0);
25582 +       __VCMD(get_rlimit_mask,  0, VCA_NONE,   0);
25583 +       __VCMD(get_space_mask_v0,0, VCA_NONE,   0);
25584 +       __VCMD(get_space_mask,   0, VCA_NONE,   0);
25585 +       __VCMD(get_space_default,0, VCA_NONE,   0);
25586 +
25587 +       /* info commands */
25588 +       __VCMD(task_xid,         2, VCA_NONE,   0);
25589 +       __VCMD(reset_hits,       2, VCA_VXI,    0);
25590 +       __VCMD(reset_minmax,     2, VCA_VXI,    0);
25591 +       __VCMD(vx_info,          3, VCA_VXI,    VCF_INFO);
25592 +       __VCMD(get_bcaps,        3, VCA_VXI,    VCF_INFO);
25593 +       __VCMD(get_ccaps,        3, VCA_VXI,    VCF_INFO);
25594 +       __VCMD(get_cflags,       3, VCA_VXI,    VCF_INFO);
25595 +       __VCMD(get_badness,      3, VCA_VXI,    VCF_INFO);
25596 +       __VCMD(get_vhi_name,     3, VCA_VXI,    VCF_INFO);
25597 +       __VCMD(get_rlimit,       3, VCA_VXI,    VCF_INFO);
25598 +
25599 +       __VCMD(ctx_stat,         3, VCA_VXI,    VCF_INFO);
25600 +       __VCMD(virt_stat,        3, VCA_VXI,    VCF_INFO);
25601 +       __VCMD(sock_stat,        3, VCA_VXI,    VCF_INFO);
25602 +       __VCMD(rlimit_stat,      3, VCA_VXI,    VCF_INFO);
25603 +
25604 +       __VCMD(task_nid,         2, VCA_NONE,   0);
25605 +       __VCMD(nx_info,          3, VCA_NXI,    VCF_INFO);
25606 +       __VCMD(get_ncaps,        3, VCA_NXI,    VCF_INFO);
25607 +       __VCMD(get_nflags,       3, VCA_NXI,    VCF_INFO);
25608 +
25609 +       __VCMD(task_tag,         2, VCA_NONE,   0);
25610 +
25611 +       __VCMD(get_iattr,        2, VCA_NONE,   0);
25612 +       __VCMD(fget_iattr,       2, VCA_NONE,   0);
25613 +       __VCMD(get_dlimit,       3, VCA_NONE,   VCF_INFO);
25614 +       __VCMD(get_sched,        3, VCA_VXI,    VCF_INFO);
25615 +       __VCMD(sched_info,       3, VCA_VXI,    VCF_INFO | VCF_ZIDOK);
25616 +
25617 +       /* lower admin commands */
25618 +       __VCMD(wait_exit,        4, VCA_VXI,    VCF_INFO);
25619 +       __VCMD(ctx_create_v0,    5, VCA_NONE,   0);
25620 +       __VCMD(ctx_create,       5, VCA_NONE,   0);
25621 +       __VCMD(ctx_migrate_v0,   5, VCA_VXI,    VCF_ADMIN);
25622 +       __VCMD(ctx_migrate,      5, VCA_VXI,    VCF_ADMIN);
25623 +       __VCMD(enter_space_v0,   5, VCA_VXI,    VCF_ADMIN);
25624 +       __VCMD(enter_space_v1,   5, VCA_VXI,    VCF_ADMIN);
25625 +       __VCMD(enter_space,      5, VCA_VXI,    VCF_ADMIN);
25626 +
25627 +       __VCMD(net_create_v0,    5, VCA_NONE,   0);
25628 +       __VCMD(net_create,       5, VCA_NONE,   0);
25629 +       __VCMD(net_migrate,      5, VCA_NXI,    VCF_ADMIN);
25630 +
25631 +       __VCMD(tag_migrate,      5, VCA_NONE,   VCF_ADMIN);
25632 +
25633 +       /* higher admin commands */
25634 +       __VCMD(ctx_kill,         6, VCA_VXI,    VCF_ARES);
25635 +       __VCMD(set_space_v1,     7, VCA_VXI,    VCF_ARES | VCF_SETUP);
25636 +       __VCMD(set_space,        7, VCA_VXI,    VCF_ARES | VCF_SETUP);
25637 +
25638 +       __VCMD(set_ccaps,        7, VCA_VXI,    VCF_ARES | VCF_SETUP);
25639 +       __VCMD(set_bcaps,        7, VCA_VXI,    VCF_ARES | VCF_SETUP);
25640 +       __VCMD(set_cflags,       7, VCA_VXI,    VCF_ARES | VCF_SETUP);
25641 +       __VCMD(set_badness,      7, VCA_VXI,    VCF_ARES | VCF_SETUP);
25642 +
25643 +       __VCMD(set_vhi_name,     7, VCA_VXI,    VCF_ARES | VCF_SETUP);
25644 +       __VCMD(set_rlimit,       7, VCA_VXI,    VCF_ARES | VCF_SETUP);
25645 +       __VCMD(set_sched,        7, VCA_VXI,    VCF_ARES | VCF_SETUP);
25646 +       __VCMD(set_sched_v4,     7, VCA_VXI,    VCF_ARES | VCF_SETUP);
25647 +
25648 +       __VCMD(set_ncaps,        7, VCA_NXI,    VCF_ARES | VCF_SETUP);
25649 +       __VCMD(set_nflags,       7, VCA_NXI,    VCF_ARES | VCF_SETUP);
25650 +       __VCMD(net_add,          8, VCA_NXI,    VCF_ARES | VCF_SETUP);
25651 +       __VCMD(net_remove,       8, VCA_NXI,    VCF_ARES | VCF_SETUP);
25652 +       __VCMD(net_add_ipv4,     8, VCA_NXI,    VCF_ARES | VCF_SETUP);
25653 +       __VCMD(net_remove_ipv4,  8, VCA_NXI,    VCF_ARES | VCF_SETUP);
25654 +#ifdef CONFIG_IPV6
25655 +       __VCMD(net_add_ipv6,     8, VCA_NXI,    VCF_ARES | VCF_SETUP);
25656 +       __VCMD(net_remove_ipv6,  8, VCA_NXI,    VCF_ARES | VCF_SETUP);
25657 +#endif
25658 +       __VCMD(set_iattr,        7, VCA_NONE,   0);
25659 +       __VCMD(fset_iattr,       7, VCA_NONE,   0);
25660 +       __VCMD(set_dlimit,       7, VCA_NONE,   VCF_ARES);
25661 +       __VCMD(add_dlimit,       8, VCA_NONE,   VCF_ARES);
25662 +       __VCMD(rem_dlimit,       8, VCA_NONE,   VCF_ARES);
25663 +
25664 +#ifdef CONFIG_VSERVER_DEVICE
25665 +       __VCMD(set_mapping,      8, VCA_VXI,    VCF_ARES|VCF_ZIDOK);
25666 +       __VCMD(unset_mapping,    8, VCA_VXI,    VCF_ARES|VCF_ZIDOK);
25667 +#endif
25668 +       /* debug level admin commands */
25669 +#ifdef CONFIG_VSERVER_HISTORY
25670 +       __VCMD(dump_history,     9, VCA_NONE,   0);
25671 +       __VCMD(read_history,     9, VCA_NONE,   0);
25672 +#endif
25673 +#ifdef CONFIG_VSERVER_MONITOR
25674 +       __VCMD(read_monitor,     9, VCA_NONE,   0);
25675 +#endif
25676 +
25677 +       default:
25678 +               perm = -1;
25679 +       }
25680 +
25681 +       vxdprintk(VXD_CBIT(switch, 0),
25682 +               "vc: VCMD_%02d_%d[%d], %d,%p [%d,%d,%x,%x]",
25683 +               VC_CATEGORY(cmd), VC_COMMAND(cmd),
25684 +               VC_VERSION(cmd), id, data, compat,
25685 +               perm, args, flags);
25686 +
25687 +       ret = -ENOSYS;
25688 +       if (perm < 0)
25689 +               goto out;
25690 +
25691 +       state = 1;
25692 +       if (!capable(CAP_CONTEXT))
25693 +               goto out;
25694 +
25695 +       state = 2;
25696 +       /* moved here from the individual commands */
25697 +       ret = -EPERM;
25698 +       if ((perm > 1) && !capable(CAP_SYS_ADMIN))
25699 +               goto out;
25700 +
25701 +       state = 3;
25702 +       /* vcmd involves resource management  */
25703 +       ret = -EPERM;
25704 +       if ((flags & VCF_ARES) && !capable(CAP_SYS_RESOURCE))
25705 +               goto out;
25706 +
25707 +       state = 4;
25708 +       /* various legacy exceptions */
25709 +       switch (cmd) {
25710 +       /* will go away when spectator is a cap */
25711 +       case VCMD_ctx_migrate_v0:
25712 +       case VCMD_ctx_migrate:
25713 +               if (id == 1) {
25714 +                       current->xid = 1;
25715 +                       ret = 1;
25716 +                       goto out;
25717 +               }
25718 +               break;
25719 +
25720 +       /* will go away when spectator is a cap */
25721 +       case VCMD_net_migrate:
25722 +               if (id == 1) {
25723 +                       current->nid = 1;
25724 +                       ret = 1;
25725 +                       goto out;
25726 +               }
25727 +               break;
25728 +       }
25729 +
25730 +       /* vcmds are fine by default */
25731 +       permit = 1;
25732 +
25733 +       /* admin type vcmds require admin ... */
25734 +       if (flags & VCF_ADMIN)
25735 +               permit = vx_check(0, VS_ADMIN) ? 1 : 0;
25736 +
25737 +       /* ... but setup type vcmds override that */
25738 +       if (!permit && (flags & VCF_SETUP))
25739 +               permit = vx_flags(VXF_STATE_SETUP, 0) ? 2 : 0;
25740 +
25741 +       state = 5;
25742 +       ret = -EPERM;
25743 +       if (!permit)
25744 +               goto out;
25745 +
25746 +       state = 6;
25747 +       if (!id && (flags & VCF_ZIDOK))
25748 +               goto skip_id;
25749 +
25750 +       ret = -ESRCH;
25751 +       if (args & VCA_VXI) {
25752 +               vxi = lookup_vx_info(id);
25753 +               if (!vxi)
25754 +                       goto out;
25755 +
25756 +               if ((flags & VCF_ADMIN) &&
25757 +                       /* special case kill for shutdown */
25758 +                       (cmd != VCMD_ctx_kill) &&
25759 +                       /* can context be administrated? */
25760 +                       !vx_info_flags(vxi, VXF_STATE_ADMIN, 0)) {
25761 +                       ret = -EACCES;
25762 +                       goto out_vxi;
25763 +               }
25764 +       }
25765 +       state = 7;
25766 +       if (args & VCA_NXI) {
25767 +               nxi = lookup_nx_info(id);
25768 +               if (!nxi)
25769 +                       goto out_vxi;
25770 +
25771 +               if ((flags & VCF_ADMIN) &&
25772 +                       /* can context be administrated? */
25773 +                       !nx_info_flags(nxi, NXF_STATE_ADMIN, 0)) {
25774 +                       ret = -EACCES;
25775 +                       goto out_nxi;
25776 +               }
25777 +       }
25778 +skip_id:
25779 +       state = 8;
25780 +       ret = do_vcmd(cmd, id, vxi, nxi, data, compat);
25781 +
25782 +out_nxi:
25783 +       if ((args & VCA_NXI) && nxi)
25784 +               put_nx_info(nxi);
25785 +out_vxi:
25786 +       if ((args & VCA_VXI) && vxi)
25787 +               put_vx_info(vxi);
25788 +out:
25789 +       vxdprintk(VXD_CBIT(switch, 1),
25790 +               "vc: VCMD_%02d_%d[%d] = %08lx(%ld) [%d,%d]",
25791 +               VC_CATEGORY(cmd), VC_COMMAND(cmd),
25792 +               VC_VERSION(cmd), ret, ret, state, permit);
25793 +       return ret;
25794 +}
25795 +
25796 +asmlinkage long
25797 +sys_vserver(uint32_t cmd, uint32_t id, void __user *data)
25798 +{
25799 +       return do_vserver(cmd, id, data, 0);
25800 +}
25801 +
25802 +#ifdef CONFIG_COMPAT
25803 +
25804 +asmlinkage long
25805 +sys32_vserver(uint32_t cmd, uint32_t id, void __user *data)
25806 +{
25807 +       return do_vserver(cmd, id, data, 1);
25808 +}
25809 +
25810 +#endif /* CONFIG_COMPAT */
25811 diff -NurpP --minimal linux-2.6.32.6/kernel/vserver/sysctl.c linux-2.6.32.6-vs2.3.0.36.28/kernel/vserver/sysctl.c
25812 --- linux-2.6.32.6/kernel/vserver/sysctl.c      1970-01-01 01:00:00.000000000 +0100
25813 +++ linux-2.6.32.6-vs2.3.0.36.28/kernel/vserver/sysctl.c        2010-01-13 15:21:01.000000000 +0100
25814 @@ -0,0 +1,245 @@
25815 +/*
25816 + *  kernel/vserver/sysctl.c
25817 + *
25818 + *  Virtual Context Support
25819 + *
25820 + *  Copyright (C) 2004-2007  Herbert Pötzl
25821 + *
25822 + *  V0.01  basic structure
25823 + *
25824 + */
25825 +
25826 +#include <linux/module.h>
25827 +#include <linux/ctype.h>
25828 +#include <linux/sysctl.h>
25829 +#include <linux/parser.h>
25830 +#include <asm/uaccess.h>
25831 +
25832 +
25833 +enum {
25834 +       CTL_DEBUG_ERROR         = 0,
25835 +       CTL_DEBUG_SWITCH        = 1,
25836 +       CTL_DEBUG_XID,
25837 +       CTL_DEBUG_NID,
25838 +       CTL_DEBUG_TAG,
25839 +       CTL_DEBUG_NET,
25840 +       CTL_DEBUG_LIMIT,
25841 +       CTL_DEBUG_CRES,
25842 +       CTL_DEBUG_DLIM,
25843 +       CTL_DEBUG_QUOTA,
25844 +       CTL_DEBUG_CVIRT,
25845 +       CTL_DEBUG_SPACE,
25846 +       CTL_DEBUG_MISC,
25847 +};
25848 +
25849 +
25850 +unsigned int vx_debug_switch   = 0;
25851 +unsigned int vx_debug_xid      = 0;
25852 +unsigned int vx_debug_nid      = 0;
25853 +unsigned int vx_debug_tag      = 0;
25854 +unsigned int vx_debug_net      = 0;
25855 +unsigned int vx_debug_limit    = 0;
25856 +unsigned int vx_debug_cres     = 0;
25857 +unsigned int vx_debug_dlim     = 0;
25858 +unsigned int vx_debug_quota    = 0;
25859 +unsigned int vx_debug_cvirt    = 0;
25860 +unsigned int vx_debug_space    = 0;
25861 +unsigned int vx_debug_misc     = 0;
25862 +
25863 +
25864 +static struct ctl_table_header *vserver_table_header;
25865 +static ctl_table vserver_root_table[];
25866 +
25867 +
25868 +void vserver_register_sysctl(void)
25869 +{
25870 +       if (!vserver_table_header) {
25871 +               vserver_table_header = register_sysctl_table(vserver_root_table);
25872 +       }
25873 +
25874 +}
25875 +
25876 +void vserver_unregister_sysctl(void)
25877 +{
25878 +       if (vserver_table_header) {
25879 +               unregister_sysctl_table(vserver_table_header);
25880 +               vserver_table_header = NULL;
25881 +       }
25882 +}
25883 +
25884 +
25885 +static int proc_dodebug(ctl_table *table, int write,
25886 +       void __user *buffer, size_t *lenp, loff_t *ppos)
25887 +{
25888 +       char            tmpbuf[20], *p, c;
25889 +       unsigned int    value;
25890 +       size_t          left, len;
25891 +
25892 +       if ((*ppos && !write) || !*lenp) {
25893 +               *lenp = 0;
25894 +               return 0;
25895 +       }
25896 +
25897 +       left = *lenp;
25898 +
25899 +       if (write) {
25900 +               if (!access_ok(VERIFY_READ, buffer, left))
25901 +                       return -EFAULT;
25902 +               p = (char *)buffer;
25903 +               while (left && __get_user(c, p) >= 0 && isspace(c))
25904 +                       left--, p++;
25905 +               if (!left)
25906 +                       goto done;
25907 +
25908 +               if (left > sizeof(tmpbuf) - 1)
25909 +                       return -EINVAL;
25910 +               if (copy_from_user(tmpbuf, p, left))
25911 +                       return -EFAULT;
25912 +               tmpbuf[left] = '\0';
25913 +
25914 +               for (p = tmpbuf, value = 0; '0' <= *p && *p <= '9'; p++, left--)
25915 +                       value = 10 * value + (*p - '0');
25916 +               if (*p && !isspace(*p))
25917 +                       return -EINVAL;
25918 +               while (left && isspace(*p))
25919 +                       left--, p++;
25920 +               *(unsigned int *)table->data = value;
25921 +       } else {
25922 +               if (!access_ok(VERIFY_WRITE, buffer, left))
25923 +                       return -EFAULT;
25924 +               len = sprintf(tmpbuf, "%d", *(unsigned int *)table->data);
25925 +               if (len > left)
25926 +                       len = left;
25927 +               if (__copy_to_user(buffer, tmpbuf, len))
25928 +                       return -EFAULT;
25929 +               if ((left -= len) > 0) {
25930 +                       if (put_user('\n', (char *)buffer + len))
25931 +                               return -EFAULT;
25932 +                       left--;
25933 +               }
25934 +       }
25935 +
25936 +done:
25937 +       *lenp -= left;
25938 +       *ppos += *lenp;
25939 +       return 0;
25940 +}
25941 +
25942 +static int zero;
25943 +
25944 +#define        CTL_ENTRY(ctl, name)                            \
25945 +       {                                               \
25946 +               .ctl_name       = ctl,                  \
25947 +               .procname       = #name,                \
25948 +               .data           = &vx_ ## name,         \
25949 +               .maxlen         = sizeof(int),          \
25950 +               .mode           = 0644,                 \
25951 +               .proc_handler   = &proc_dodebug,        \
25952 +               .strategy       = &sysctl_intvec,       \
25953 +               .extra1         = &zero,                \
25954 +               .extra2         = &zero,                \
25955 +       }
25956 +
25957 +static ctl_table vserver_debug_table[] = {
25958 +       CTL_ENTRY(CTL_DEBUG_SWITCH,     debug_switch),
25959 +       CTL_ENTRY(CTL_DEBUG_XID,        debug_xid),
25960 +       CTL_ENTRY(CTL_DEBUG_NID,        debug_nid),
25961 +       CTL_ENTRY(CTL_DEBUG_TAG,        debug_tag),
25962 +       CTL_ENTRY(CTL_DEBUG_NET,        debug_net),
25963 +       CTL_ENTRY(CTL_DEBUG_LIMIT,      debug_limit),
25964 +       CTL_ENTRY(CTL_DEBUG_CRES,       debug_cres),
25965 +       CTL_ENTRY(CTL_DEBUG_DLIM,       debug_dlim),
25966 +       CTL_ENTRY(CTL_DEBUG_QUOTA,      debug_quota),
25967 +       CTL_ENTRY(CTL_DEBUG_CVIRT,      debug_cvirt),
25968 +       CTL_ENTRY(CTL_DEBUG_SPACE,      debug_space),
25969 +       CTL_ENTRY(CTL_DEBUG_MISC,       debug_misc),
25970 +       { .ctl_name = 0 }
25971 +};
25972 +
25973 +static ctl_table vserver_root_table[] = {
25974 +       {
25975 +               .ctl_name       = CTL_VSERVER,
25976 +               .procname       = "vserver",
25977 +               .mode           = 0555,
25978 +               .child          = vserver_debug_table
25979 +       },
25980 +       { .ctl_name = 0 }
25981 +};
25982 +
25983 +
25984 +static match_table_t tokens = {
25985 +       { CTL_DEBUG_SWITCH,     "switch=%x"     },
25986 +       { CTL_DEBUG_XID,        "xid=%x"        },
25987 +       { CTL_DEBUG_NID,        "nid=%x"        },
25988 +       { CTL_DEBUG_TAG,        "tag=%x"        },
25989 +       { CTL_DEBUG_NET,        "net=%x"        },
25990 +       { CTL_DEBUG_LIMIT,      "limit=%x"      },
25991 +       { CTL_DEBUG_CRES,       "cres=%x"       },
25992 +       { CTL_DEBUG_DLIM,       "dlim=%x"       },
25993 +       { CTL_DEBUG_QUOTA,      "quota=%x"      },
25994 +       { CTL_DEBUG_CVIRT,      "cvirt=%x"      },
25995 +       { CTL_DEBUG_SPACE,      "space=%x"      },
25996 +       { CTL_DEBUG_MISC,       "misc=%x"       },
25997 +       { CTL_DEBUG_ERROR,      NULL            }
25998 +};
25999 +
26000 +#define        HANDLE_CASE(id, name, val)                              \
26001 +       case CTL_DEBUG_ ## id:                                  \
26002 +               vx_debug_ ## name = val;                        \
26003 +               printk("vs_debug_" #name "=0x%x\n", val);       \
26004 +               break
26005 +
26006 +
26007 +static int __init vs_debug_setup(char *str)
26008 +{
26009 +       char *p;
26010 +       int token;
26011 +
26012 +       printk("vs_debug_setup(%s)\n", str);
26013 +       while ((p = strsep(&str, ",")) != NULL) {
26014 +               substring_t args[MAX_OPT_ARGS];
26015 +               unsigned int value;
26016 +
26017 +               if (!*p)
26018 +                       continue;
26019 +
26020 +               token = match_token(p, tokens, args);
26021 +               value = (token > 0) ? simple_strtoul(args[0].from, NULL, 0) : 0;
26022 +
26023 +               switch (token) {
26024 +               HANDLE_CASE(SWITCH, switch, value);
26025 +               HANDLE_CASE(XID,    xid,    value);
26026 +               HANDLE_CASE(NID,    nid,    value);
26027 +               HANDLE_CASE(TAG,    tag,    value);
26028 +               HANDLE_CASE(NET,    net,    value);
26029 +               HANDLE_CASE(LIMIT,  limit,  value);
26030 +               HANDLE_CASE(CRES,   cres,   value);
26031 +               HANDLE_CASE(DLIM,   dlim,   value);
26032 +               HANDLE_CASE(QUOTA,  quota,  value);
26033 +               HANDLE_CASE(CVIRT,  cvirt,  value);
26034 +               HANDLE_CASE(SPACE,  space,  value);
26035 +               HANDLE_CASE(MISC,   misc,   value);
26036 +               default:
26037 +                       return -EINVAL;
26038 +                       break;
26039 +               }
26040 +       }
26041 +       return 1;
26042 +}
26043 +
26044 +__setup("vsdebug=", vs_debug_setup);
26045 +
26046 +
26047 +
26048 +EXPORT_SYMBOL_GPL(vx_debug_switch);
26049 +EXPORT_SYMBOL_GPL(vx_debug_xid);
26050 +EXPORT_SYMBOL_GPL(vx_debug_nid);
26051 +EXPORT_SYMBOL_GPL(vx_debug_net);
26052 +EXPORT_SYMBOL_GPL(vx_debug_limit);
26053 +EXPORT_SYMBOL_GPL(vx_debug_cres);
26054 +EXPORT_SYMBOL_GPL(vx_debug_dlim);
26055 +EXPORT_SYMBOL_GPL(vx_debug_quota);
26056 +EXPORT_SYMBOL_GPL(vx_debug_cvirt);
26057 +EXPORT_SYMBOL_GPL(vx_debug_space);
26058 +EXPORT_SYMBOL_GPL(vx_debug_misc);
26059 +
26060 diff -NurpP --minimal linux-2.6.32.6/kernel/vserver/tag.c linux-2.6.32.6-vs2.3.0.36.28/kernel/vserver/tag.c
26061 --- linux-2.6.32.6/kernel/vserver/tag.c 1970-01-01 01:00:00.000000000 +0100
26062 +++ linux-2.6.32.6-vs2.3.0.36.28/kernel/vserver/tag.c   2009-12-03 20:04:56.000000000 +0100
26063 @@ -0,0 +1,63 @@
26064 +/*
26065 + *  linux/kernel/vserver/tag.c
26066 + *
26067 + *  Virtual Server: Shallow Tag Space
26068 + *
26069 + *  Copyright (C) 2007  Herbert Pötzl
26070 + *
26071 + *  V0.01  basic implementation
26072 + *
26073 + */
26074 +
26075 +#include <linux/sched.h>
26076 +#include <linux/vserver/debug.h>
26077 +#include <linux/vs_pid.h>
26078 +#include <linux/vs_tag.h>
26079 +
26080 +#include <linux/vserver/tag_cmd.h>
26081 +
26082 +
26083 +int dx_migrate_task(struct task_struct *p, tag_t tag)
26084 +{
26085 +       if (!p)
26086 +               BUG();
26087 +
26088 +       vxdprintk(VXD_CBIT(tag, 5),
26089 +               "dx_migrate_task(%p[#%d],#%d)", p, p->tag, tag);
26090 +
26091 +       task_lock(p);
26092 +       p->tag = tag;
26093 +       task_unlock(p);
26094 +
26095 +       vxdprintk(VXD_CBIT(tag, 5),
26096 +               "moved task %p into [#%d]", p, tag);
26097 +       return 0;
26098 +}
26099 +
26100 +/* vserver syscall commands below here */
26101 +
26102 +/* taks xid and vx_info functions */
26103 +
26104 +
26105 +int vc_task_tag(uint32_t id)
26106 +{
26107 +       tag_t tag;
26108 +
26109 +       if (id) {
26110 +               struct task_struct *tsk;
26111 +               read_lock(&tasklist_lock);
26112 +               tsk = find_task_by_real_pid(id);
26113 +               tag = (tsk) ? tsk->tag : -ESRCH;
26114 +               read_unlock(&tasklist_lock);
26115 +       } else
26116 +               tag = dx_current_tag();
26117 +       return tag;
26118 +}
26119 +
26120 +
26121 +int vc_tag_migrate(uint32_t tag)
26122 +{
26123 +       return dx_migrate_task(current, tag & 0xFFFF);
26124 +}
26125 +
26126 +
26127 diff -NurpP --minimal linux-2.6.32.6/kernel/vserver/vci_config.h linux-2.6.32.6-vs2.3.0.36.28/kernel/vserver/vci_config.h
26128 --- linux-2.6.32.6/kernel/vserver/vci_config.h  1970-01-01 01:00:00.000000000 +0100
26129 +++ linux-2.6.32.6-vs2.3.0.36.28/kernel/vserver/vci_config.h    2009-12-03 20:04:56.000000000 +0100
26130 @@ -0,0 +1,81 @@
26131 +
26132 +/*  interface version */
26133 +
26134 +#define VCI_VERSION            0x00020305
26135 +
26136 +
26137 +enum {
26138 +       VCI_KCBIT_NO_DYNAMIC = 0,
26139 +
26140 +       VCI_KCBIT_PROC_SECURE = 4,
26141 +       VCI_KCBIT_HARDCPU = 5,
26142 +       VCI_KCBIT_IDLELIMIT = 6,
26143 +       VCI_KCBIT_IDLETIME = 7,
26144 +
26145 +       VCI_KCBIT_COWBL = 8,
26146 +       VCI_KCBIT_FULLCOWBL = 9,
26147 +       VCI_KCBIT_SPACES = 10,
26148 +       VCI_KCBIT_NETV2 = 11,
26149 +
26150 +       VCI_KCBIT_DEBUG = 16,
26151 +       VCI_KCBIT_HISTORY = 20,
26152 +       VCI_KCBIT_TAGGED = 24,
26153 +       VCI_KCBIT_PPTAG = 28,
26154 +
26155 +       VCI_KCBIT_MORE = 31,
26156 +};
26157 +
26158 +
26159 +static inline uint32_t vci_kernel_config(void)
26160 +{
26161 +       return
26162 +       (1 << VCI_KCBIT_NO_DYNAMIC) |
26163 +
26164 +       /* configured features */
26165 +#ifdef CONFIG_VSERVER_PROC_SECURE
26166 +       (1 << VCI_KCBIT_PROC_SECURE) |
26167 +#endif
26168 +#ifdef CONFIG_VSERVER_HARDCPU
26169 +       (1 << VCI_KCBIT_HARDCPU) |
26170 +#endif
26171 +#ifdef CONFIG_VSERVER_IDLELIMIT
26172 +       (1 << VCI_KCBIT_IDLELIMIT) |
26173 +#endif
26174 +#ifdef CONFIG_VSERVER_IDLETIME
26175 +       (1 << VCI_KCBIT_IDLETIME) |
26176 +#endif
26177 +#ifdef CONFIG_VSERVER_COWBL
26178 +       (1 << VCI_KCBIT_COWBL) |
26179 +       (1 << VCI_KCBIT_FULLCOWBL) |
26180 +#endif
26181 +       (1 << VCI_KCBIT_SPACES) |
26182 +       (1 << VCI_KCBIT_NETV2) |
26183 +
26184 +       /* debug options */
26185 +#ifdef CONFIG_VSERVER_DEBUG
26186 +       (1 << VCI_KCBIT_DEBUG) |
26187 +#endif
26188 +#ifdef CONFIG_VSERVER_HISTORY
26189 +       (1 << VCI_KCBIT_HISTORY) |
26190 +#endif
26191 +
26192 +       /* inode context tagging */
26193 +#if    defined(CONFIG_TAGGING_NONE)
26194 +       (0 << VCI_KCBIT_TAGGED) |
26195 +#elif  defined(CONFIG_TAGGING_UID16)
26196 +       (1 << VCI_KCBIT_TAGGED) |
26197 +#elif  defined(CONFIG_TAGGING_GID16)
26198 +       (2 << VCI_KCBIT_TAGGED) |
26199 +#elif  defined(CONFIG_TAGGING_ID24)
26200 +       (3 << VCI_KCBIT_TAGGED) |
26201 +#elif  defined(CONFIG_TAGGING_INTERN)
26202 +       (4 << VCI_KCBIT_TAGGED) |
26203 +#elif  defined(CONFIG_TAGGING_RUNTIME)
26204 +       (5 << VCI_KCBIT_TAGGED) |
26205 +#else
26206 +       (7 << VCI_KCBIT_TAGGED) |
26207 +#endif
26208 +       (1 << VCI_KCBIT_PPTAG) |
26209 +       0;
26210 +}
26211 +
26212 diff -NurpP --minimal linux-2.6.32.6/mm/allocpercpu.c linux-2.6.32.6-vs2.3.0.36.28/mm/allocpercpu.c
26213 --- linux-2.6.32.6/mm/allocpercpu.c     2009-12-03 20:02:58.000000000 +0100
26214 +++ linux-2.6.32.6-vs2.3.0.36.28/mm/allocpercpu.c       2009-12-03 20:04:56.000000000 +0100
26215 @@ -160,12 +160,14 @@ EXPORT_SYMBOL(__per_cpu_offset);
26216  
26217  void __init setup_per_cpu_areas(void)
26218  {
26219 -       unsigned long size, i;
26220 +       unsigned long size, vspc, i;
26221         char *ptr;
26222         unsigned long nr_possible_cpus = num_possible_cpus();
26223  
26224 +       vspc = PERCPU_PERCTX * CONFIG_VSERVER_CONTEXTS;
26225 +
26226         /* Copy section for each CPU (we discard the original) */
26227 -       size = ALIGN(PERCPU_ENOUGH_ROOM, PAGE_SIZE);
26228 +       size = ALIGN(PERCPU_ENOUGH_ROOM + vspc, PAGE_SIZE);
26229         ptr = alloc_bootmem_pages(size * nr_possible_cpus);
26230  
26231         for_each_possible_cpu(i) {
26232 diff -NurpP --minimal linux-2.6.32.6/mm/filemap_xip.c linux-2.6.32.6-vs2.3.0.36.28/mm/filemap_xip.c
26233 --- linux-2.6.32.6/mm/filemap_xip.c     2009-12-03 20:02:58.000000000 +0100
26234 +++ linux-2.6.32.6-vs2.3.0.36.28/mm/filemap_xip.c       2009-12-03 20:04:56.000000000 +0100
26235 @@ -17,6 +17,7 @@
26236  #include <linux/sched.h>
26237  #include <linux/seqlock.h>
26238  #include <linux/mutex.h>
26239 +#include <linux/vs_memory.h>
26240  #include <asm/tlbflush.h>
26241  #include <asm/io.h>
26242  
26243 diff -NurpP --minimal linux-2.6.32.6/mm/fremap.c linux-2.6.32.6-vs2.3.0.36.28/mm/fremap.c
26244 --- linux-2.6.32.6/mm/fremap.c  2009-03-24 14:22:45.000000000 +0100
26245 +++ linux-2.6.32.6-vs2.3.0.36.28/mm/fremap.c    2009-12-03 20:04:56.000000000 +0100
26246 @@ -16,6 +16,7 @@
26247  #include <linux/module.h>
26248  #include <linux/syscalls.h>
26249  #include <linux/mmu_notifier.h>
26250 +#include <linux/vs_memory.h>
26251  
26252  #include <asm/mmu_context.h>
26253  #include <asm/cacheflush.h>
26254 diff -NurpP --minimal linux-2.6.32.6/mm/hugetlb.c linux-2.6.32.6-vs2.3.0.36.28/mm/hugetlb.c
26255 --- linux-2.6.32.6/mm/hugetlb.c 2009-12-03 20:02:58.000000000 +0100
26256 +++ linux-2.6.32.6-vs2.3.0.36.28/mm/hugetlb.c   2009-12-03 20:04:56.000000000 +0100
26257 @@ -24,6 +24,7 @@
26258  #include <asm/io.h>
26259  
26260  #include <linux/hugetlb.h>
26261 +#include <linux/vs_memory.h>
26262  #include "internal.h"
26263  
26264  const unsigned long hugetlb_zero = 0, hugetlb_infinity = ~0UL;
26265 diff -NurpP --minimal linux-2.6.32.6/mm/memory.c linux-2.6.32.6-vs2.3.0.36.28/mm/memory.c
26266 --- linux-2.6.32.6/mm/memory.c  2010-01-26 19:31:27.000000000 +0100
26267 +++ linux-2.6.32.6-vs2.3.0.36.28/mm/memory.c    2009-12-30 00:58:19.000000000 +0100
26268 @@ -56,6 +56,7 @@
26269  #include <linux/kallsyms.h>
26270  #include <linux/swapops.h>
26271  #include <linux/elf.h>
26272 +// #include <linux/vs_memory.h>
26273  
26274  #include <asm/io.h>
26275  #include <asm/pgalloc.h>
26276 @@ -647,6 +648,9 @@ static int copy_pte_range(struct mm_stru
26277         int progress = 0;
26278         int rss[2];
26279  
26280 +       if (!vx_rss_avail(dst_mm, ((end - addr)/PAGE_SIZE + 1)))
26281 +               return -ENOMEM;
26282 +
26283  again:
26284         rss[1] = rss[0] = 0;
26285         dst_pte = pte_alloc_map_lock(dst_mm, dst_pmd, addr, &dst_ptl);
26286 @@ -2645,6 +2649,8 @@ static int do_anonymous_page(struct mm_s
26287         /* Allocate our own private page. */
26288         pte_unmap(page_table);
26289  
26290 +       if (!vx_rss_avail(mm, 1))
26291 +               goto oom;
26292         if (unlikely(anon_vma_prepare(vma)))
26293                 goto oom;
26294         page = alloc_zeroed_user_highpage_movable(vma, address);
26295 @@ -2936,6 +2942,7 @@ static inline int handle_pte_fault(struc
26296  {
26297         pte_t entry;
26298         spinlock_t *ptl;
26299 +       int ret = 0, type = VXPT_UNKNOWN;
26300  
26301         entry = *pte;
26302         if (!pte_present(entry)) {
26303 @@ -2960,9 +2967,12 @@ static inline int handle_pte_fault(struc
26304         if (unlikely(!pte_same(*pte, entry)))
26305                 goto unlock;
26306         if (flags & FAULT_FLAG_WRITE) {
26307 -               if (!pte_write(entry))
26308 -                       return do_wp_page(mm, vma, address,
26309 +               if (!pte_write(entry)) {
26310 +                       ret = do_wp_page(mm, vma, address,
26311                                         pte, pmd, ptl, entry);
26312 +                       type = VXPT_WRITE;
26313 +                       goto out;
26314 +               }
26315                 entry = pte_mkdirty(entry);
26316         }
26317         entry = pte_mkyoung(entry);
26318 @@ -2980,7 +2990,10 @@ static inline int handle_pte_fault(struc
26319         }
26320  unlock:
26321         pte_unmap_unlock(pte, ptl);
26322 -       return 0;
26323 +       ret = 0;
26324 +out:
26325 +       vx_page_fault(mm, vma, type, ret);
26326 +       return ret;
26327  }
26328  
26329  /*
26330 diff -NurpP --minimal linux-2.6.32.6/mm/mlock.c linux-2.6.32.6-vs2.3.0.36.28/mm/mlock.c
26331 --- linux-2.6.32.6/mm/mlock.c   2010-01-26 19:31:27.000000000 +0100
26332 +++ linux-2.6.32.6-vs2.3.0.36.28/mm/mlock.c     2010-01-13 14:33:47.000000000 +0100
26333 @@ -18,6 +18,7 @@
26334  #include <linux/rmap.h>
26335  #include <linux/mmzone.h>
26336  #include <linux/hugetlb.h>
26337 +#include <linux/vs_memory.h>
26338  
26339  #include "internal.h"
26340  
26341 @@ -401,7 +402,7 @@ success:
26342         nr_pages = (end - start) >> PAGE_SHIFT;
26343         if (!lock)
26344                 nr_pages = -nr_pages;
26345 -       mm->locked_vm += nr_pages;
26346 +       vx_vmlocked_add(mm, nr_pages);
26347  
26348         /*
26349          * vm_flags is protected by the mmap_sem held in write mode.
26350 @@ -474,7 +475,7 @@ static int do_mlock(unsigned long start,
26351  
26352  SYSCALL_DEFINE2(mlock, unsigned long, start, size_t, len)
26353  {
26354 -       unsigned long locked;
26355 +       unsigned long locked, grow;
26356         unsigned long lock_limit;
26357         int error = -ENOMEM;
26358  
26359 @@ -487,8 +488,10 @@ SYSCALL_DEFINE2(mlock, unsigned long, st
26360         len = PAGE_ALIGN(len + (start & ~PAGE_MASK));
26361         start &= PAGE_MASK;
26362  
26363 -       locked = len >> PAGE_SHIFT;
26364 -       locked += current->mm->locked_vm;
26365 +       grow = len >> PAGE_SHIFT;
26366 +       if (!vx_vmlocked_avail(current->mm, grow))
26367 +               goto out;
26368 +       locked = current->mm->locked_vm + grow;
26369  
26370         lock_limit = current->signal->rlim[RLIMIT_MEMLOCK].rlim_cur;
26371         lock_limit >>= PAGE_SHIFT;
26372 @@ -496,6 +499,7 @@ SYSCALL_DEFINE2(mlock, unsigned long, st
26373         /* check against resource limits */
26374         if ((locked <= lock_limit) || capable(CAP_IPC_LOCK))
26375                 error = do_mlock(start, len, 1);
26376 +out:
26377         up_write(&current->mm->mmap_sem);
26378         return error;
26379  }
26380 @@ -557,6 +561,8 @@ SYSCALL_DEFINE1(mlockall, int, flags)
26381         lock_limit >>= PAGE_SHIFT;
26382  
26383         ret = -ENOMEM;
26384 +       if (!vx_vmlocked_avail(current->mm, current->mm->total_vm))
26385 +               goto out;
26386         if (!(flags & MCL_CURRENT) || (current->mm->total_vm <= lock_limit) ||
26387             capable(CAP_IPC_LOCK))
26388                 ret = do_mlockall(flags);
26389 @@ -631,8 +637,10 @@ int account_locked_memory(struct mm_stru
26390         if (lim < vm)
26391                 goto out;
26392  
26393 -       mm->total_vm  += pgsz;
26394 -       mm->locked_vm += pgsz;
26395 +       // mm->total_vm  += pgsz;
26396 +       vx_vmpages_add(mm, pgsz);
26397 +       // mm->locked_vm += pgsz;
26398 +       vx_vmlocked_add(mm, pgsz);
26399  
26400         error = 0;
26401   out:
26402 @@ -646,8 +654,10 @@ void refund_locked_memory(struct mm_stru
26403  
26404         down_write(&mm->mmap_sem);
26405  
26406 -       mm->total_vm  -= pgsz;
26407 -       mm->locked_vm -= pgsz;
26408 +       // mm->total_vm  -= pgsz;
26409 +       vx_vmpages_sub(mm, pgsz);
26410 +       // mm->locked_vm -= pgsz;
26411 +       vx_vmlocked_sub(mm, pgsz);
26412  
26413         up_write(&mm->mmap_sem);
26414  }
26415 diff -NurpP --minimal linux-2.6.32.6/mm/mmap.c linux-2.6.32.6-vs2.3.0.36.28/mm/mmap.c
26416 --- linux-2.6.32.6/mm/mmap.c    2010-01-26 19:31:27.000000000 +0100
26417 +++ linux-2.6.32.6-vs2.3.0.36.28/mm/mmap.c      2010-01-20 04:21:33.000000000 +0100
26418 @@ -1214,7 +1214,8 @@ munmap_back:
26419  out:
26420         perf_event_mmap(vma);
26421  
26422 -       mm->total_vm += len >> PAGE_SHIFT;
26423 +       // mm->total_vm += len >> PAGE_SHIFT;
26424 +       vx_vmpages_add(mm, len >> PAGE_SHIFT);
26425         vm_stat_account(mm, vm_flags, file, len >> PAGE_SHIFT);
26426         if (vm_flags & VM_LOCKED) {
26427                 /*
26428 @@ -1223,7 +1224,8 @@ out:
26429                 long nr_pages = mlock_vma_pages_range(vma, addr, addr + len);
26430                 if (nr_pages < 0)
26431                         return nr_pages;        /* vma gone! */
26432 -               mm->locked_vm += (len >> PAGE_SHIFT) - nr_pages;
26433 +               // mm->locked_vm += (len >> PAGE_SHIFT) - nr_pages;
26434 +               vx_vmlocked_add(mm, (len >> PAGE_SHIFT) - nr_pages);
26435         } else if ((flags & MAP_POPULATE) && !(flags & MAP_NONBLOCK))
26436                 make_pages_present(addr, addr + len);
26437         return addr;
26438 @@ -1578,9 +1580,9 @@ static int acct_stack_growth(struct vm_a
26439                 return -ENOMEM;
26440  
26441         /* Ok, everything looks good - let it rip */
26442 -       mm->total_vm += grow;
26443 +       vx_vmpages_add(mm, grow);
26444         if (vma->vm_flags & VM_LOCKED)
26445 -               mm->locked_vm += grow;
26446 +               vx_vmlocked_add(mm, grow);
26447         vm_stat_account(mm, vma->vm_flags, vma->vm_file, grow);
26448         return 0;
26449  }
26450 @@ -1755,7 +1757,8 @@ static void remove_vma_list(struct mm_st
26451         do {
26452                 long nrpages = vma_pages(vma);
26453  
26454 -               mm->total_vm -= nrpages;
26455 +               // mm->total_vm -= nrpages;
26456 +               vx_vmpages_sub(mm, nrpages);
26457                 vm_stat_account(mm, vma->vm_flags, vma->vm_file, -nrpages);
26458                 vma = remove_vma(vma);
26459         } while (vma);
26460 @@ -1927,7 +1930,8 @@ int do_munmap(struct mm_struct *mm, unsi
26461                 struct vm_area_struct *tmp = vma;
26462                 while (tmp && tmp->vm_start < end) {
26463                         if (tmp->vm_flags & VM_LOCKED) {
26464 -                               mm->locked_vm -= vma_pages(tmp);
26465 +                               // mm->locked_vm -= vma_pages(tmp);
26466 +                               vx_vmlocked_sub(mm, vma_pages(tmp));
26467                                 munlock_vma_pages_all(tmp);
26468                         }
26469                         tmp = tmp->vm_next;
26470 @@ -2010,6 +2014,8 @@ unsigned long do_brk(unsigned long addr,
26471                 lock_limit >>= PAGE_SHIFT;
26472                 if (locked > lock_limit && !capable(CAP_IPC_LOCK))
26473                         return -EAGAIN;
26474 +               if (!vx_vmlocked_avail(mm, len >> PAGE_SHIFT))
26475 +                       return -ENOMEM;
26476         }
26477  
26478         /*
26479 @@ -2036,7 +2042,8 @@ unsigned long do_brk(unsigned long addr,
26480         if (mm->map_count > sysctl_max_map_count)
26481                 return -ENOMEM;
26482  
26483 -       if (security_vm_enough_memory(len >> PAGE_SHIFT))
26484 +       if (security_vm_enough_memory(len >> PAGE_SHIFT) ||
26485 +               !vx_vmpages_avail(mm, len >> PAGE_SHIFT))
26486                 return -ENOMEM;
26487  
26488         /* Can we just expand an old private anonymous mapping? */
26489 @@ -2062,10 +2069,13 @@ unsigned long do_brk(unsigned long addr,
26490         vma->vm_page_prot = vm_get_page_prot(flags);
26491         vma_link(mm, vma, prev, rb_link, rb_parent);
26492  out:
26493 -       mm->total_vm += len >> PAGE_SHIFT;
26494 +       // mm->total_vm += len >> PAGE_SHIFT;
26495 +       vx_vmpages_add(mm, len >> PAGE_SHIFT);
26496 +
26497         if (flags & VM_LOCKED) {
26498                 if (!mlock_vma_pages_range(vma, addr, addr + len))
26499 -                       mm->locked_vm += (len >> PAGE_SHIFT);
26500 +                       // mm->locked_vm += (len >> PAGE_SHIFT);
26501 +                       vx_vmlocked_add(mm, len >> PAGE_SHIFT);
26502         }
26503         return addr;
26504  }
26505 @@ -2109,6 +2119,11 @@ void exit_mmap(struct mm_struct *mm)
26506         free_pgtables(tlb, vma, FIRST_USER_ADDRESS, 0);
26507         tlb_finish_mmu(tlb, 0, end);
26508  
26509 +       set_mm_counter(mm, file_rss, 0);
26510 +       set_mm_counter(mm, anon_rss, 0);
26511 +       vx_vmpages_sub(mm, mm->total_vm);
26512 +       vx_vmlocked_sub(mm, mm->locked_vm);
26513 +
26514         /*
26515          * Walk the list again, actually closing and freeing it,
26516          * with preemption enabled, without holding any MM locks.
26517 @@ -2148,7 +2163,8 @@ int insert_vm_struct(struct mm_struct * 
26518         if (__vma && __vma->vm_start < vma->vm_end)
26519                 return -ENOMEM;
26520         if ((vma->vm_flags & VM_ACCOUNT) &&
26521 -            security_vm_enough_memory_mm(mm, vma_pages(vma)))
26522 +               (security_vm_enough_memory_mm(mm, vma_pages(vma)) ||
26523 +               !vx_vmpages_avail(mm, vma_pages(vma))))
26524                 return -ENOMEM;
26525         vma_link(mm, vma, prev, rb_link, rb_parent);
26526         return 0;
26527 @@ -2224,6 +2240,8 @@ int may_expand_vm(struct mm_struct *mm, 
26528  
26529         if (cur + npages > lim)
26530                 return 0;
26531 +       if (!vx_vmpages_avail(mm, npages))
26532 +               return 0;
26533         return 1;
26534  }
26535  
26536 @@ -2301,7 +2319,7 @@ int install_special_mapping(struct mm_st
26537                 return -ENOMEM;
26538         }
26539  
26540 -       mm->total_vm += len >> PAGE_SHIFT;
26541 +       vx_vmpages_add(mm, len >> PAGE_SHIFT);
26542  
26543         perf_event_mmap(vma);
26544  
26545 diff -NurpP --minimal linux-2.6.32.6/mm/mremap.c linux-2.6.32.6-vs2.3.0.36.28/mm/mremap.c
26546 --- linux-2.6.32.6/mm/mremap.c  2010-01-26 19:31:27.000000000 +0100
26547 +++ linux-2.6.32.6-vs2.3.0.36.28/mm/mremap.c    2010-01-20 04:28:22.000000000 +0100
26548 @@ -20,6 +20,7 @@
26549  #include <linux/security.h>
26550  #include <linux/syscalls.h>
26551  #include <linux/mmu_notifier.h>
26552 +#include <linux/vs_memory.h>
26553  
26554  #include <asm/uaccess.h>
26555  #include <asm/cacheflush.h>
26556 @@ -234,7 +235,7 @@ static unsigned long move_vma(struct vm_
26557          * If this were a serious issue, we'd add a flag to do_munmap().
26558          */
26559         hiwater_vm = mm->hiwater_vm;
26560 -       mm->total_vm += new_len >> PAGE_SHIFT;
26561 +       vx_vmpages_add(mm, new_len >> PAGE_SHIFT);
26562         vm_stat_account(mm, vma->vm_flags, vma->vm_file, new_len>>PAGE_SHIFT);
26563  
26564         if (do_munmap(mm, old_addr, old_len) < 0) {
26565 @@ -252,7 +253,7 @@ static unsigned long move_vma(struct vm_
26566         }
26567  
26568         if (vm_flags & VM_LOCKED) {
26569 -               mm->locked_vm += new_len >> PAGE_SHIFT;
26570 +               vx_vmlocked_add(mm, new_len >> PAGE_SHIFT);
26571                 if (new_len > old_len)
26572                         mlock_vma_pages_range(new_vma, new_addr + old_len,
26573                                                        new_addr + new_len);
26574 @@ -463,10 +464,12 @@ unsigned long do_mremap(unsigned long ad
26575                         vma_adjust(vma, vma->vm_start,
26576                                 addr + new_len, vma->vm_pgoff, NULL);
26577  
26578 -                       mm->total_vm += pages;
26579 +                       // mm->total_vm += pages;
26580 +                       vx_vmpages_add(mm, pages);
26581                         vm_stat_account(mm, vma->vm_flags, vma->vm_file, pages);
26582                         if (vma->vm_flags & VM_LOCKED) {
26583 -                               mm->locked_vm += pages;
26584 +                               // mm->locked_vm += pages;
26585 +                               vx_vmlocked_add(mm, pages);
26586                                 mlock_vma_pages_range(vma, addr + old_len,
26587                                                    addr + new_len);
26588                         }
26589 diff -NurpP --minimal linux-2.6.32.6/mm/nommu.c linux-2.6.32.6-vs2.3.0.36.28/mm/nommu.c
26590 --- linux-2.6.32.6/mm/nommu.c   2009-12-03 20:02:58.000000000 +0100
26591 +++ linux-2.6.32.6-vs2.3.0.36.28/mm/nommu.c     2009-12-03 20:04:56.000000000 +0100
26592 @@ -1346,7 +1346,7 @@ unsigned long do_mmap_pgoff(struct file 
26593         /* okay... we have a mapping; now we have to register it */
26594         result = vma->vm_start;
26595  
26596 -       current->mm->total_vm += len >> PAGE_SHIFT;
26597 +       vx_vmpages_add(current->mm, len >> PAGE_SHIFT);
26598  
26599  share:
26600         add_vma_to_mm(current->mm, vma);
26601 @@ -1606,7 +1606,7 @@ void exit_mmap(struct mm_struct *mm)
26602  
26603         kenter("");
26604  
26605 -       mm->total_vm = 0;
26606 +       vx_vmpages_sub(mm, mm->total_vm);
26607  
26608         while ((vma = mm->mmap)) {
26609                 mm->mmap = vma->vm_next;
26610 diff -NurpP --minimal linux-2.6.32.6/mm/oom_kill.c linux-2.6.32.6-vs2.3.0.36.28/mm/oom_kill.c
26611 --- linux-2.6.32.6/mm/oom_kill.c        2010-01-26 19:31:27.000000000 +0100
26612 +++ linux-2.6.32.6-vs2.3.0.36.28/mm/oom_kill.c  2010-01-13 14:33:47.000000000 +0100
26613 @@ -27,6 +27,9 @@
26614  #include <linux/notifier.h>
26615  #include <linux/memcontrol.h>
26616  #include <linux/security.h>
26617 +#include <linux/reboot.h>
26618 +#include <linux/vs_memory.h>
26619 +#include <linux/vs_context.h>
26620  
26621  int sysctl_panic_on_oom;
26622  int sysctl_oom_kill_allocating_task;
26623 @@ -186,9 +189,21 @@ unsigned long badness(struct task_struct
26624                         points >>= -(oom_adj);
26625         }
26626  
26627 +       /*
26628 +        * add points for context badness and
26629 +        * reduce badness for processes belonging to
26630 +        * a different context
26631 +        */
26632 +
26633 +       points += vx_badness(p, mm);
26634 +
26635 +       if ((vx_current_xid() > 1) &&
26636 +               vx_current_xid() != vx_task_xid(p))
26637 +               points /= 16;
26638 +
26639  #ifdef DEBUG
26640 -       printk(KERN_DEBUG "OOMkill: task %d (%s) got %lu points\n",
26641 -       p->pid, p->comm, points);
26642 +       printk(KERN_DEBUG "OOMkill: task %d:#%u (%s) got %d points\n",
26643 +               task_pid_nr(p), p->xid, p->comm, points);
26644  #endif
26645         return points;
26646  }
26647 @@ -230,6 +245,7 @@ static struct task_struct *select_bad_pr
26648         struct task_struct *p;
26649         struct task_struct *chosen = NULL;
26650         struct timespec uptime;
26651 +       unsigned xid = vx_current_xid();
26652         *ppoints = 0;
26653  
26654         do_posix_clock_monotonic_gettime(&uptime);
26655 @@ -242,11 +258,14 @@ static struct task_struct *select_bad_pr
26656                  */
26657                 if (!p->mm)
26658                         continue;
26659 -               /* skip the init task */
26660 -               if (is_global_init(p))
26661 +               /* skip the init task, global and per guest */
26662 +               if (task_is_init(p))
26663                         continue;
26664                 if (mem && !task_in_mem_cgroup(p, mem))
26665                         continue;
26666 +               /* skip other guest and host processes if oom in guest */
26667 +               if (xid && vx_task_xid(p) != xid)
26668 +                       continue;
26669  
26670                 /*
26671                  * This task already has access to memory reserves and is
26672 @@ -357,8 +376,8 @@ static void __oom_kill_task(struct task_
26673         }
26674  
26675         if (verbose)
26676 -               printk(KERN_ERR "Killed process %d (%s)\n",
26677 -                               task_pid_nr(p), p->comm);
26678 +               printk(KERN_ERR "Killed process %s(%d:#%u)\n",
26679 +                       p->comm, task_pid_nr(p), p->xid);
26680  
26681         /*
26682          * We give our sacrificial lamb high priority and access to
26683 @@ -419,8 +438,8 @@ static int oom_kill_process(struct task_
26684                 return 0;
26685         }
26686  
26687 -       printk(KERN_ERR "%s: kill process %d (%s) score %li or a child\n",
26688 -                                       message, task_pid_nr(p), p->comm, points);
26689 +       printk(KERN_ERR "%s: kill process %s(%d:#%u) score %li or a child\n",
26690 +               message, p->comm, task_pid_nr(p), p->xid, points);
26691  
26692         /* Try to kill a child first */
26693         list_for_each_entry(c, &p->children, sibling) {
26694 @@ -519,6 +538,8 @@ void clear_zonelist_oom(struct zonelist 
26695         spin_unlock(&zone_scan_lock);
26696  }
26697  
26698 +long vs_oom_action(unsigned int);
26699 +
26700  /*
26701   * Must be called with tasklist_lock held for read.
26702   */
26703 @@ -544,7 +565,11 @@ retry:
26704         /* Found nothing?!?! Either we hang forever, or we panic. */
26705         if (!p) {
26706                 read_unlock(&tasklist_lock);
26707 -               panic("Out of memory and no killable processes...\n");
26708 +               /* avoid panic for guest OOM */
26709 +               if (current->xid)
26710 +                       vs_oom_action(LINUX_REBOOT_CMD_OOM);
26711 +               else
26712 +                       panic("Out of memory and no killable processes...\n");
26713         }
26714  
26715         if (oom_kill_process(p, gfp_mask, order, points, NULL,
26716 diff -NurpP --minimal linux-2.6.32.6/mm/page_alloc.c linux-2.6.32.6-vs2.3.0.36.28/mm/page_alloc.c
26717 --- linux-2.6.32.6/mm/page_alloc.c      2010-01-26 19:31:27.000000000 +0100
26718 +++ linux-2.6.32.6-vs2.3.0.36.28/mm/page_alloc.c        2010-01-26 20:35:35.000000000 +0100
26719 @@ -48,6 +48,8 @@
26720  #include <linux/page_cgroup.h>
26721  #include <linux/debugobjects.h>
26722  #include <linux/kmemleak.h>
26723 +#include <linux/vs_base.h>
26724 +#include <linux/vs_limit.h>
26725  #include <trace/events/kmem.h>
26726  
26727  #include <asm/tlbflush.h>
26728 @@ -2130,6 +2132,9 @@ void si_meminfo(struct sysinfo *val)
26729         val->totalhigh = totalhigh_pages;
26730         val->freehigh = nr_free_highpages();
26731         val->mem_unit = PAGE_SIZE;
26732 +
26733 +       if (vx_flags(VXF_VIRT_MEM, 0))
26734 +               vx_vsi_meminfo(val);
26735  }
26736  
26737  EXPORT_SYMBOL(si_meminfo);
26738 @@ -2150,6 +2155,9 @@ void si_meminfo_node(struct sysinfo *val
26739         val->freehigh = 0;
26740  #endif
26741         val->mem_unit = PAGE_SIZE;
26742 +
26743 +       if (vx_flags(VXF_VIRT_MEM, 0))
26744 +               vx_vsi_meminfo(val);
26745  }
26746  #endif
26747  
26748 diff -NurpP --minimal linux-2.6.32.6/mm/rmap.c linux-2.6.32.6-vs2.3.0.36.28/mm/rmap.c
26749 --- linux-2.6.32.6/mm/rmap.c    2009-12-03 20:02:58.000000000 +0100
26750 +++ linux-2.6.32.6-vs2.3.0.36.28/mm/rmap.c      2009-12-03 20:04:56.000000000 +0100
26751 @@ -55,6 +55,7 @@
26752  #include <linux/memcontrol.h>
26753  #include <linux/mmu_notifier.h>
26754  #include <linux/migrate.h>
26755 +#include <linux/vs_memory.h>
26756  
26757  #include <asm/tlbflush.h>
26758  
26759 diff -NurpP --minimal linux-2.6.32.6/mm/shmem.c linux-2.6.32.6-vs2.3.0.36.28/mm/shmem.c
26760 --- linux-2.6.32.6/mm/shmem.c   2009-12-03 20:02:58.000000000 +0100
26761 +++ linux-2.6.32.6-vs2.3.0.36.28/mm/shmem.c     2009-12-03 20:04:56.000000000 +0100
26762 @@ -1781,7 +1781,7 @@ static int shmem_statfs(struct dentry *d
26763  {
26764         struct shmem_sb_info *sbinfo = SHMEM_SB(dentry->d_sb);
26765  
26766 -       buf->f_type = TMPFS_MAGIC;
26767 +       buf->f_type = TMPFS_SUPER_MAGIC;
26768         buf->f_bsize = PAGE_CACHE_SIZE;
26769         buf->f_namelen = NAME_MAX;
26770         spin_lock(&sbinfo->stat_lock);
26771 @@ -2346,7 +2346,7 @@ int shmem_fill_super(struct super_block 
26772         sb->s_maxbytes = SHMEM_MAX_BYTES;
26773         sb->s_blocksize = PAGE_CACHE_SIZE;
26774         sb->s_blocksize_bits = PAGE_CACHE_SHIFT;
26775 -       sb->s_magic = TMPFS_MAGIC;
26776 +       sb->s_magic = TMPFS_SUPER_MAGIC;
26777         sb->s_op = &shmem_ops;
26778         sb->s_time_gran = 1;
26779  #ifdef CONFIG_TMPFS_POSIX_ACL
26780 diff -NurpP --minimal linux-2.6.32.6/mm/slab.c linux-2.6.32.6-vs2.3.0.36.28/mm/slab.c
26781 --- linux-2.6.32.6/mm/slab.c    2009-12-03 20:02:58.000000000 +0100
26782 +++ linux-2.6.32.6-vs2.3.0.36.28/mm/slab.c      2009-12-03 20:04:56.000000000 +0100
26783 @@ -431,6 +431,8 @@ static void kmem_list3_init(struct kmem_
26784  #define STATS_INC_FREEMISS(x)  do { } while (0)
26785  #endif
26786  
26787 +#include "slab_vs.h"
26788 +
26789  #if DEBUG
26790  
26791  /*
26792 @@ -3253,6 +3255,7 @@ retry:
26793  
26794         obj = slab_get_obj(cachep, slabp, nodeid);
26795         check_slabp(cachep, slabp);
26796 +       vx_slab_alloc(cachep, flags);
26797         l3->free_objects--;
26798         /* move slabp to correct slabp list: */
26799         list_del(&slabp->list);
26800 @@ -3329,6 +3332,7 @@ __cache_alloc_node(struct kmem_cache *ca
26801         /* ___cache_alloc_node can fall back to other nodes */
26802         ptr = ____cache_alloc_node(cachep, flags, nodeid);
26803    out:
26804 +       vx_slab_alloc(cachep, flags);
26805         local_irq_restore(save_flags);
26806         ptr = cache_alloc_debugcheck_after(cachep, flags, ptr, caller);
26807         kmemleak_alloc_recursive(ptr, obj_size(cachep), 1, cachep->flags,
26808 @@ -3515,6 +3519,7 @@ static inline void __cache_free(struct k
26809         check_irq_off();
26810         kmemleak_free_recursive(objp, cachep->flags);
26811         objp = cache_free_debugcheck(cachep, objp, __builtin_return_address(0));
26812 +       vx_slab_free(cachep);
26813  
26814         kmemcheck_slab_free(cachep, objp, obj_size(cachep));
26815  
26816 diff -NurpP --minimal linux-2.6.32.6/mm/slab_vs.h linux-2.6.32.6-vs2.3.0.36.28/mm/slab_vs.h
26817 --- linux-2.6.32.6/mm/slab_vs.h 1970-01-01 01:00:00.000000000 +0100
26818 +++ linux-2.6.32.6-vs2.3.0.36.28/mm/slab_vs.h   2009-12-03 20:04:56.000000000 +0100
26819 @@ -0,0 +1,29 @@
26820 +
26821 +#include <linux/vserver/context.h>
26822 +
26823 +#include <linux/vs_context.h>
26824 +
26825 +static inline
26826 +void vx_slab_alloc(struct kmem_cache *cachep, gfp_t flags)
26827 +{
26828 +       int what = gfp_zone(cachep->gfpflags);
26829 +       struct vx_info *vxi = current_vx_info();
26830 +
26831 +       if (!vxi)
26832 +               return;
26833 +
26834 +       atomic_add(cachep->buffer_size, &vxi->cacct.slab[what]);
26835 +}
26836 +
26837 +static inline
26838 +void vx_slab_free(struct kmem_cache *cachep)
26839 +{
26840 +       int what = gfp_zone(cachep->gfpflags);
26841 +       struct vx_info *vxi = current_vx_info();
26842 +
26843 +       if (!vxi)
26844 +               return;
26845 +
26846 +       atomic_sub(cachep->buffer_size, &vxi->cacct.slab[what]);
26847 +}
26848 +
26849 diff -NurpP --minimal linux-2.6.32.6/mm/swapfile.c linux-2.6.32.6-vs2.3.0.36.28/mm/swapfile.c
26850 --- linux-2.6.32.6/mm/swapfile.c        2009-12-03 20:02:58.000000000 +0100
26851 +++ linux-2.6.32.6-vs2.3.0.36.28/mm/swapfile.c  2009-12-03 20:04:56.000000000 +0100
26852 @@ -34,6 +34,8 @@
26853  #include <asm/tlbflush.h>
26854  #include <linux/swapops.h>
26855  #include <linux/page_cgroup.h>
26856 +#include <linux/vs_base.h>
26857 +#include <linux/vs_memory.h>
26858  
26859  static DEFINE_SPINLOCK(swap_lock);
26860  static unsigned int nr_swapfiles;
26861 @@ -1680,6 +1682,8 @@ static void *swap_next(struct seq_file *
26862         if (v == SEQ_START_TOKEN)
26863                 ptr = swap_info;
26864         else {
26865 +               if (vx_flags(VXF_VIRT_MEM, 0))
26866 +                       return NULL;
26867                 ptr = v;
26868                 ptr++;
26869         }
26870 @@ -1707,6 +1711,16 @@ static int swap_show(struct seq_file *sw
26871  
26872         if (ptr == SEQ_START_TOKEN) {
26873                 seq_puts(swap,"Filename\t\t\t\tType\t\tSize\tUsed\tPriority\n");
26874 +               if (vx_flags(VXF_VIRT_MEM, 0)) {
26875 +                       struct sysinfo si;
26876 +
26877 +                       vx_vsi_swapinfo(&si);
26878 +                       if (si.totalswap < (1 << 10))
26879 +                               return 0;
26880 +                       seq_printf(swap, "%s\t\t\t\t\t%s\t%lu\t%lu\t%d\n",
26881 +                               "hdv0", "partition", si.totalswap >> 10,
26882 +                               (si.totalswap - si.freeswap) >> 10, -1);
26883 +               }
26884                 return 0;
26885         }
26886  
26887 @@ -2064,6 +2078,8 @@ void si_swapinfo(struct sysinfo *val)
26888         val->freeswap = nr_swap_pages + nr_to_be_unused;
26889         val->totalswap = total_swap_pages + nr_to_be_unused;
26890         spin_unlock(&swap_lock);
26891 +       if (vx_flags(VXF_VIRT_MEM, 0))
26892 +               vx_vsi_swapinfo(val);
26893  }
26894  
26895  /*
26896 diff -NurpP --minimal linux-2.6.32.6/net/core/dev.c linux-2.6.32.6-vs2.3.0.36.28/net/core/dev.c
26897 --- linux-2.6.32.6/net/core/dev.c       2010-01-26 19:31:28.000000000 +0100
26898 +++ linux-2.6.32.6-vs2.3.0.36.28/net/core/dev.c 2010-01-04 18:37:03.000000000 +0100
26899 @@ -126,6 +126,7 @@
26900  #include <linux/in.h>
26901  #include <linux/jhash.h>
26902  #include <linux/random.h>
26903 +#include <linux/vs_inet.h>
26904  #include <trace/events/napi.h>
26905  
26906  #include "net-sysfs.h"
26907 @@ -591,7 +592,8 @@ struct net_device *__dev_get_by_name(str
26908         hlist_for_each(p, dev_name_hash(net, name)) {
26909                 struct net_device *dev
26910                         = hlist_entry(p, struct net_device, name_hlist);
26911 -               if (!strncmp(dev->name, name, IFNAMSIZ))
26912 +               if (!strncmp(dev->name, name, IFNAMSIZ) &&
26913 +                   nx_dev_visible(current_nx_info(), dev))
26914                         return dev;
26915         }
26916         return NULL;
26917 @@ -642,7 +644,8 @@ struct net_device *__dev_get_by_index(st
26918         hlist_for_each(p, dev_index_hash(net, ifindex)) {
26919                 struct net_device *dev
26920                         = hlist_entry(p, struct net_device, index_hlist);
26921 -               if (dev->ifindex == ifindex)
26922 +               if ((dev->ifindex == ifindex) &&
26923 +                   nx_dev_visible(current_nx_info(), dev))
26924                         return dev;
26925         }
26926         return NULL;
26927 @@ -695,10 +698,12 @@ struct net_device *dev_getbyhwaddr(struc
26928  
26929         ASSERT_RTNL();
26930  
26931 -       for_each_netdev(net, dev)
26932 +       for_each_netdev(net, dev) {
26933                 if (dev->type == type &&
26934 -                   !memcmp(dev->dev_addr, ha, dev->addr_len))
26935 +                   !memcmp(dev->dev_addr, ha, dev->addr_len) &&
26936 +                   nx_dev_visible(current_nx_info(), dev))
26937                         return dev;
26938 +       }
26939  
26940         return NULL;
26941  }
26942 @@ -709,9 +714,11 @@ struct net_device *__dev_getfirstbyhwtyp
26943         struct net_device *dev;
26944  
26945         ASSERT_RTNL();
26946 -       for_each_netdev(net, dev)
26947 -               if (dev->type == type)
26948 +       for_each_netdev(net, dev) {
26949 +               if ((dev->type == type) &&
26950 +                   nx_dev_visible(current_nx_info(), dev))
26951                         return dev;
26952 +       }
26953  
26954         return NULL;
26955  }
26956 @@ -830,6 +837,8 @@ static int __dev_alloc_name(struct net *
26957                                 continue;
26958                         if (i < 0 || i >= max_netdevices)
26959                                 continue;
26960 +                       if (!nx_dev_visible(current_nx_info(), d))
26961 +                               continue;
26962  
26963                         /*  avoid cases where sscanf is not exact inverse of printf */
26964                         snprintf(buf, IFNAMSIZ, name, i);
26965 @@ -2984,6 +2993,8 @@ static int dev_ifconf(struct net *net, c
26966  
26967         total = 0;
26968         for_each_netdev(net, dev) {
26969 +               if (!nx_dev_visible(current_nx_info(), dev))
26970 +                       continue;
26971                 for (i = 0; i < NPROTO; i++) {
26972                         if (gifconf_list[i]) {
26973                                 int done;
26974 @@ -3052,6 +3063,9 @@ static void dev_seq_printf_stats(struct 
26975  {
26976         const struct net_device_stats *stats = dev_get_stats(dev);
26977  
26978 +       if (!nx_dev_visible(current_nx_info(), dev))
26979 +               return;
26980 +
26981         seq_printf(seq, "%6s:%8lu %7lu %4lu %4lu %4lu %5lu %10lu %9lu "
26982                    "%8lu %7lu %4lu %4lu %4lu %5lu %7lu %10lu\n",
26983                    dev->name, stats->rx_bytes, stats->rx_packets,
26984 @@ -5317,7 +5331,6 @@ int dev_change_net_namespace(struct net_
26985         if (dev->dev.parent)
26986                 goto out;
26987  #endif
26988 -
26989         /* Ensure the device has been registrered */
26990         err = -EINVAL;
26991         if (dev->reg_state != NETREG_REGISTERED)
26992 diff -NurpP --minimal linux-2.6.32.6/net/core/rtnetlink.c linux-2.6.32.6-vs2.3.0.36.28/net/core/rtnetlink.c
26993 --- linux-2.6.32.6/net/core/rtnetlink.c 2010-01-26 19:31:28.000000000 +0100
26994 +++ linux-2.6.32.6-vs2.3.0.36.28/net/core/rtnetlink.c   2009-12-29 00:36:26.000000000 +0100
26995 @@ -688,6 +688,8 @@ static int rtnl_dump_ifinfo(struct sk_bu
26996  
26997         idx = 0;
26998         for_each_netdev(net, dev) {
26999 +               if (!nx_dev_visible(skb->sk->sk_nx_info, dev))
27000 +                       continue;
27001                 if (idx < s_idx)
27002                         goto cont;
27003                 if (rtnl_fill_ifinfo(skb, dev, RTM_NEWLINK,
27004 @@ -1222,6 +1224,9 @@ void rtmsg_ifinfo(int type, struct net_d
27005         struct sk_buff *skb;
27006         int err = -ENOBUFS;
27007  
27008 +       if (!nx_dev_visible(current_nx_info(), dev))
27009 +               return;
27010 +
27011         skb = nlmsg_new(if_nlmsg_size(dev), GFP_KERNEL);
27012         if (skb == NULL)
27013                 goto errout;
27014 diff -NurpP --minimal linux-2.6.32.6/net/core/sock.c linux-2.6.32.6-vs2.3.0.36.28/net/core/sock.c
27015 --- linux-2.6.32.6/net/core/sock.c      2009-12-03 20:02:59.000000000 +0100
27016 +++ linux-2.6.32.6-vs2.3.0.36.28/net/core/sock.c        2009-12-03 20:04:56.000000000 +0100
27017 @@ -125,6 +125,10 @@
27018  #include <linux/ipsec.h>
27019  
27020  #include <linux/filter.h>
27021 +#include <linux/vs_socket.h>
27022 +#include <linux/vs_limit.h>
27023 +#include <linux/vs_context.h>
27024 +#include <linux/vs_network.h>
27025  
27026  #ifdef CONFIG_INET
27027  #include <net/tcp.h>
27028 @@ -984,6 +988,8 @@ static struct sock *sk_prot_alloc(struct
27029                 if (!try_module_get(prot->owner))
27030                         goto out_free_sec;
27031         }
27032 +               sock_vx_init(sk);
27033 +               sock_nx_init(sk);
27034  
27035         return sk;
27036  
27037 @@ -1063,6 +1069,11 @@ static void __sk_free(struct sock *sk)
27038                        __func__, atomic_read(&sk->sk_omem_alloc));
27039  
27040         put_net(sock_net(sk));
27041 +       vx_sock_dec(sk);
27042 +       clr_vx_info(&sk->sk_vx_info);
27043 +       sk->sk_xid = -1;
27044 +       clr_nx_info(&sk->sk_nx_info);
27045 +       sk->sk_nid = -1;
27046         sk_prot_free(sk->sk_prot_creator, sk);
27047  }
27048  
27049 @@ -1110,6 +1121,8 @@ struct sock *sk_clone(const struct sock 
27050  
27051                 /* SANITY */
27052                 get_net(sock_net(newsk));
27053 +               sock_vx_init(newsk);
27054 +               sock_nx_init(newsk);
27055                 sk_node_init(&newsk->sk_node);
27056                 sock_lock_init(newsk);
27057                 bh_lock_sock(newsk);
27058 @@ -1164,6 +1177,12 @@ struct sock *sk_clone(const struct sock 
27059                 smp_wmb();
27060                 atomic_set(&newsk->sk_refcnt, 2);
27061  
27062 +               set_vx_info(&newsk->sk_vx_info, sk->sk_vx_info);
27063 +               newsk->sk_xid = sk->sk_xid;
27064 +               vx_sock_inc(newsk);
27065 +               set_nx_info(&newsk->sk_nx_info, sk->sk_nx_info);
27066 +               newsk->sk_nid = sk->sk_nid;
27067 +
27068                 /*
27069                  * Increment the counter in the same struct proto as the master
27070                  * sock (sk_refcnt_debug_inc uses newsk->sk_prot->socks, that
27071 @@ -1882,6 +1901,12 @@ void sock_init_data(struct socket *sock,
27072  
27073         sk->sk_stamp = ktime_set(-1L, 0);
27074  
27075 +       set_vx_info(&sk->sk_vx_info, current_vx_info());
27076 +       sk->sk_xid = vx_current_xid();
27077 +       vx_sock_inc(sk);
27078 +       set_nx_info(&sk->sk_nx_info, current_nx_info());
27079 +       sk->sk_nid = nx_current_nid();
27080 +
27081         /*
27082          * Before updating sk_refcnt, we must commit prior changes to memory
27083          * (Documentation/RCU/rculist_nulls.txt for details)
27084 diff -NurpP --minimal linux-2.6.32.6/net/ipv4/af_inet.c linux-2.6.32.6-vs2.3.0.36.28/net/ipv4/af_inet.c
27085 --- linux-2.6.32.6/net/ipv4/af_inet.c   2009-12-03 20:02:59.000000000 +0100
27086 +++ linux-2.6.32.6-vs2.3.0.36.28/net/ipv4/af_inet.c     2009-12-03 20:04:56.000000000 +0100
27087 @@ -115,6 +115,7 @@
27088  #ifdef CONFIG_IP_MROUTE
27089  #include <linux/mroute.h>
27090  #endif
27091 +#include <linux/vs_limit.h>
27092  
27093  
27094  /* The inetsw table contains everything that inet_create needs to
27095 @@ -325,9 +326,12 @@ lookup_protocol:
27096         }
27097  
27098         err = -EPERM;
27099 +       if ((protocol == IPPROTO_ICMP) &&
27100 +               nx_capable(answer->capability, NXC_RAW_ICMP))
27101 +               goto override;
27102         if (answer->capability > 0 && !capable(answer->capability))
27103                 goto out_rcu_unlock;
27104 -
27105 +override:
27106         err = -EAFNOSUPPORT;
27107         if (!inet_netns_ok(net, protocol))
27108                 goto out_rcu_unlock;
27109 @@ -447,6 +451,7 @@ int inet_bind(struct socket *sock, struc
27110         struct sockaddr_in *addr = (struct sockaddr_in *)uaddr;
27111         struct sock *sk = sock->sk;
27112         struct inet_sock *inet = inet_sk(sk);
27113 +       struct nx_v4_sock_addr nsa;
27114         unsigned short snum;
27115         int chk_addr_ret;
27116         int err;
27117 @@ -460,7 +465,11 @@ int inet_bind(struct socket *sock, struc
27118         if (addr_len < sizeof(struct sockaddr_in))
27119                 goto out;
27120  
27121 -       chk_addr_ret = inet_addr_type(sock_net(sk), addr->sin_addr.s_addr);
27122 +       err = v4_map_sock_addr(inet, addr, &nsa);
27123 +       if (err)
27124 +               goto out;
27125 +
27126 +       chk_addr_ret = inet_addr_type(sock_net(sk), nsa.saddr);
27127  
27128         /* Not specified by any standard per-se, however it breaks too
27129          * many applications when removed.  It is unfortunate since
27130 @@ -472,7 +481,7 @@ int inet_bind(struct socket *sock, struc
27131         err = -EADDRNOTAVAIL;
27132         if (!sysctl_ip_nonlocal_bind &&
27133             !(inet->freebind || inet->transparent) &&
27134 -           addr->sin_addr.s_addr != htonl(INADDR_ANY) &&
27135 +           nsa.saddr != htonl(INADDR_ANY) &&
27136             chk_addr_ret != RTN_LOCAL &&
27137             chk_addr_ret != RTN_MULTICAST &&
27138             chk_addr_ret != RTN_BROADCAST)
27139 @@ -497,7 +506,7 @@ int inet_bind(struct socket *sock, struc
27140         if (sk->sk_state != TCP_CLOSE || inet->num)
27141                 goto out_release_sock;
27142  
27143 -       inet->rcv_saddr = inet->saddr = addr->sin_addr.s_addr;
27144 +       v4_set_sock_addr(inet, &nsa);
27145         if (chk_addr_ret == RTN_MULTICAST || chk_addr_ret == RTN_BROADCAST)
27146                 inet->saddr = 0;  /* Use device */
27147  
27148 @@ -694,11 +703,13 @@ int inet_getname(struct socket *sock, st
27149                      peer == 1))
27150                         return -ENOTCONN;
27151                 sin->sin_port = inet->dport;
27152 -               sin->sin_addr.s_addr = inet->daddr;
27153 +               sin->sin_addr.s_addr =
27154 +                       nx_map_sock_lback(sk->sk_nx_info, inet->daddr);
27155         } else {
27156                 __be32 addr = inet->rcv_saddr;
27157                 if (!addr)
27158                         addr = inet->saddr;
27159 +               addr = nx_map_sock_lback(sk->sk_nx_info, addr);
27160                 sin->sin_port = inet->sport;
27161                 sin->sin_addr.s_addr = addr;
27162         }
27163 diff -NurpP --minimal linux-2.6.32.6/net/ipv4/devinet.c linux-2.6.32.6-vs2.3.0.36.28/net/ipv4/devinet.c
27164 --- linux-2.6.32.6/net/ipv4/devinet.c   2009-12-03 20:02:59.000000000 +0100
27165 +++ linux-2.6.32.6-vs2.3.0.36.28/net/ipv4/devinet.c     2009-12-03 20:04:56.000000000 +0100
27166 @@ -413,6 +413,7 @@ struct in_device *inetdev_by_index(struc
27167         return in_dev;
27168  }
27169  
27170 +
27171  /* Called only from RTNL semaphored context. No locks. */
27172  
27173  struct in_ifaddr *inet_ifa_byprefix(struct in_device *in_dev, __be32 prefix,
27174 @@ -653,6 +654,8 @@ int devinet_ioctl(struct net *net, unsig
27175                 *colon = ':';
27176  
27177         if ((in_dev = __in_dev_get_rtnl(dev)) != NULL) {
27178 +               struct nx_info *nxi = current_nx_info();
27179 +
27180                 if (tryaddrmatch) {
27181                         /* Matthias Andree */
27182                         /* compare label and address (4.4BSD style) */
27183 @@ -661,6 +664,8 @@ int devinet_ioctl(struct net *net, unsig
27184                            This is checked above. */
27185                         for (ifap = &in_dev->ifa_list; (ifa = *ifap) != NULL;
27186                              ifap = &ifa->ifa_next) {
27187 +                               if (!nx_v4_ifa_visible(nxi, ifa))
27188 +                                       continue;
27189                                 if (!strcmp(ifr.ifr_name, ifa->ifa_label) &&
27190                                     sin_orig.sin_addr.s_addr ==
27191                                                         ifa->ifa_address) {
27192 @@ -673,9 +678,12 @@ int devinet_ioctl(struct net *net, unsig
27193                    comparing just the label */
27194                 if (!ifa) {
27195                         for (ifap = &in_dev->ifa_list; (ifa = *ifap) != NULL;
27196 -                            ifap = &ifa->ifa_next)
27197 +                            ifap = &ifa->ifa_next) {
27198 +                               if (!nx_v4_ifa_visible(nxi, ifa))
27199 +                                       continue;
27200                                 if (!strcmp(ifr.ifr_name, ifa->ifa_label))
27201                                         break;
27202 +                       }
27203                 }
27204         }
27205  
27206 @@ -826,6 +834,8 @@ static int inet_gifconf(struct net_devic
27207                 goto out;
27208  
27209         for (; ifa; ifa = ifa->ifa_next) {
27210 +               if (!nx_v4_ifa_visible(current_nx_info(), ifa))
27211 +                       continue;
27212                 if (!buf) {
27213                         done += sizeof(ifr);
27214                         continue;
27215 @@ -1174,6 +1184,7 @@ static int inet_dump_ifaddr(struct sk_bu
27216         struct net_device *dev;
27217         struct in_device *in_dev;
27218         struct in_ifaddr *ifa;
27219 +       struct sock *sk = skb->sk;
27220         int s_ip_idx, s_idx = cb->args[0];
27221  
27222         s_ip_idx = ip_idx = cb->args[1];
27223 @@ -1188,6 +1199,8 @@ static int inet_dump_ifaddr(struct sk_bu
27224  
27225                 for (ifa = in_dev->ifa_list, ip_idx = 0; ifa;
27226                      ifa = ifa->ifa_next, ip_idx++) {
27227 +                       if (sk && !nx_v4_ifa_visible(sk->sk_nx_info, ifa))
27228 +                               continue;
27229                         if (ip_idx < s_ip_idx)
27230                                 continue;
27231                         if (inet_fill_ifaddr(skb, ifa, NETLINK_CB(cb->skb).pid,
27232 diff -NurpP --minimal linux-2.6.32.6/net/ipv4/fib_hash.c linux-2.6.32.6-vs2.3.0.36.28/net/ipv4/fib_hash.c
27233 --- linux-2.6.32.6/net/ipv4/fib_hash.c  2009-09-10 15:26:29.000000000 +0200
27234 +++ linux-2.6.32.6-vs2.3.0.36.28/net/ipv4/fib_hash.c    2009-12-03 20:04:56.000000000 +0100
27235 @@ -1021,7 +1021,7 @@ static int fib_seq_show(struct seq_file 
27236         prefix  = f->fn_key;
27237         mask    = FZ_MASK(iter->zone);
27238         flags   = fib_flag_trans(fa->fa_type, mask, fi);
27239 -       if (fi)
27240 +       if (fi && nx_dev_visible(current_nx_info(), fi->fib_dev))
27241                 seq_printf(seq,
27242                          "%s\t%08X\t%08X\t%04X\t%d\t%u\t%d\t%08X\t%d\t%u\t%u%n",
27243                          fi->fib_dev ? fi->fib_dev->name : "*", prefix,
27244 diff -NurpP --minimal linux-2.6.32.6/net/ipv4/inet_connection_sock.c linux-2.6.32.6-vs2.3.0.36.28/net/ipv4/inet_connection_sock.c
27245 --- linux-2.6.32.6/net/ipv4/inet_connection_sock.c      2009-12-03 20:02:59.000000000 +0100
27246 +++ linux-2.6.32.6-vs2.3.0.36.28/net/ipv4/inet_connection_sock.c        2009-12-03 20:04:56.000000000 +0100
27247 @@ -49,10 +49,40 @@ void inet_get_local_port_range(int *low,
27248  }
27249  EXPORT_SYMBOL(inet_get_local_port_range);
27250  
27251 +int ipv4_rcv_saddr_equal(const struct sock *sk1, const struct sock *sk2)
27252 +{
27253 +       __be32  sk1_rcv_saddr = inet_rcv_saddr(sk1),
27254 +               sk2_rcv_saddr = inet_rcv_saddr(sk2);
27255 +
27256 +       if (inet_v6_ipv6only(sk2))
27257 +               return 0;
27258 +
27259 +       if (sk1_rcv_saddr &&
27260 +           sk2_rcv_saddr &&
27261 +           sk1_rcv_saddr == sk2_rcv_saddr)
27262 +               return 1;
27263 +
27264 +       if (sk1_rcv_saddr &&
27265 +           !sk2_rcv_saddr &&
27266 +           v4_addr_in_nx_info(sk2->sk_nx_info, sk1_rcv_saddr, NXA_MASK_BIND))
27267 +               return 1;
27268 +
27269 +       if (sk2_rcv_saddr &&
27270 +           !sk1_rcv_saddr &&
27271 +           v4_addr_in_nx_info(sk1->sk_nx_info, sk2_rcv_saddr, NXA_MASK_BIND))
27272 +               return 1;
27273 +
27274 +       if (!sk1_rcv_saddr &&
27275 +           !sk2_rcv_saddr &&
27276 +           nx_v4_addr_conflict(sk1->sk_nx_info, sk2->sk_nx_info))
27277 +               return 1;
27278 +
27279 +       return 0;
27280 +}
27281 +
27282  int inet_csk_bind_conflict(const struct sock *sk,
27283                            const struct inet_bind_bucket *tb)
27284  {
27285 -       const __be32 sk_rcv_saddr = inet_rcv_saddr(sk);
27286         struct sock *sk2;
27287         struct hlist_node *node;
27288         int reuse = sk->sk_reuse;
27289 @@ -72,9 +102,7 @@ int inet_csk_bind_conflict(const struct 
27290                      sk->sk_bound_dev_if == sk2->sk_bound_dev_if)) {
27291                         if (!reuse || !sk2->sk_reuse ||
27292                             sk2->sk_state == TCP_LISTEN) {
27293 -                               const __be32 sk2_rcv_saddr = inet_rcv_saddr(sk2);
27294 -                               if (!sk2_rcv_saddr || !sk_rcv_saddr ||
27295 -                                   sk2_rcv_saddr == sk_rcv_saddr)
27296 +                               if (ipv4_rcv_saddr_equal(sk, sk2))
27297                                         break;
27298                         }
27299                 }
27300 diff -NurpP --minimal linux-2.6.32.6/net/ipv4/inet_diag.c linux-2.6.32.6-vs2.3.0.36.28/net/ipv4/inet_diag.c
27301 --- linux-2.6.32.6/net/ipv4/inet_diag.c 2009-09-10 15:26:29.000000000 +0200
27302 +++ linux-2.6.32.6-vs2.3.0.36.28/net/ipv4/inet_diag.c   2009-12-03 20:04:56.000000000 +0100
27303 @@ -32,6 +32,8 @@
27304  #include <linux/stddef.h>
27305  
27306  #include <linux/inet_diag.h>
27307 +#include <linux/vs_network.h>
27308 +#include <linux/vs_inet.h>
27309  
27310  static const struct inet_diag_handler **inet_diag_table;
27311  
27312 @@ -118,8 +120,8 @@ static int inet_csk_diag_fill(struct soc
27313  
27314         r->id.idiag_sport = inet->sport;
27315         r->id.idiag_dport = inet->dport;
27316 -       r->id.idiag_src[0] = inet->rcv_saddr;
27317 -       r->id.idiag_dst[0] = inet->daddr;
27318 +       r->id.idiag_src[0] = nx_map_sock_lback(sk->sk_nx_info, inet->rcv_saddr);
27319 +       r->id.idiag_dst[0] = nx_map_sock_lback(sk->sk_nx_info, inet->daddr);
27320  
27321  #if defined(CONFIG_IPV6) || defined (CONFIG_IPV6_MODULE)
27322         if (r->idiag_family == AF_INET6) {
27323 @@ -204,8 +206,8 @@ static int inet_twsk_diag_fill(struct in
27324         r->id.idiag_cookie[1] = (u32)(((unsigned long)tw >> 31) >> 1);
27325         r->id.idiag_sport     = tw->tw_sport;
27326         r->id.idiag_dport     = tw->tw_dport;
27327 -       r->id.idiag_src[0]    = tw->tw_rcv_saddr;
27328 -       r->id.idiag_dst[0]    = tw->tw_daddr;
27329 +       r->id.idiag_src[0]    = nx_map_sock_lback(tw->tw_nx_info, tw->tw_rcv_saddr);
27330 +       r->id.idiag_dst[0]    = nx_map_sock_lback(tw->tw_nx_info, tw->tw_daddr);
27331         r->idiag_state        = tw->tw_substate;
27332         r->idiag_timer        = 3;
27333         r->idiag_expires      = DIV_ROUND_UP(tmo * 1000, HZ);
27334 @@ -262,6 +264,7 @@ static int inet_diag_get_exact(struct sk
27335         err = -EINVAL;
27336  
27337         if (req->idiag_family == AF_INET) {
27338 +               /* TODO: lback */
27339                 sk = inet_lookup(&init_net, hashinfo, req->id.idiag_dst[0],
27340                                  req->id.idiag_dport, req->id.idiag_src[0],
27341                                  req->id.idiag_sport, req->id.idiag_if);
27342 @@ -504,6 +507,7 @@ static int inet_csk_diag_dump(struct soc
27343                 } else
27344  #endif
27345                 {
27346 +                       /* TODO: lback */
27347                         entry.saddr = &inet->rcv_saddr;
27348                         entry.daddr = &inet->daddr;
27349                 }
27350 @@ -540,6 +544,7 @@ static int inet_twsk_diag_dump(struct in
27351                 } else
27352  #endif
27353                 {
27354 +                       /* TODO: lback */
27355                         entry.saddr = &tw->tw_rcv_saddr;
27356                         entry.daddr = &tw->tw_daddr;
27357                 }
27358 @@ -586,8 +591,8 @@ static int inet_diag_fill_req(struct sk_
27359  
27360         r->id.idiag_sport = inet->sport;
27361         r->id.idiag_dport = ireq->rmt_port;
27362 -       r->id.idiag_src[0] = ireq->loc_addr;
27363 -       r->id.idiag_dst[0] = ireq->rmt_addr;
27364 +       r->id.idiag_src[0] = nx_map_sock_lback(sk->sk_nx_info, ireq->loc_addr);
27365 +       r->id.idiag_dst[0] = nx_map_sock_lback(sk->sk_nx_info, ireq->rmt_addr);
27366         r->idiag_expires = jiffies_to_msecs(tmo);
27367         r->idiag_rqueue = 0;
27368         r->idiag_wqueue = 0;
27369 @@ -657,6 +662,7 @@ static int inet_diag_dump_reqs(struct sk
27370                                 continue;
27371  
27372                         if (bc) {
27373 +                               /* TODO: lback */
27374                                 entry.saddr =
27375  #if defined(CONFIG_IPV6) || defined (CONFIG_IPV6_MODULE)
27376                                         (entry.family == AF_INET6) ?
27377 @@ -727,6 +733,8 @@ static int inet_diag_dump(struct sk_buff
27378                         sk_nulls_for_each(sk, node, &ilb->head) {
27379                                 struct inet_sock *inet = inet_sk(sk);
27380  
27381 +                               if (!nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
27382 +                                       continue;
27383                                 if (num < s_num) {
27384                                         num++;
27385                                         continue;
27386 @@ -793,6 +801,8 @@ skip_listen_ht:
27387                 sk_nulls_for_each(sk, node, &head->chain) {
27388                         struct inet_sock *inet = inet_sk(sk);
27389  
27390 +                       if (!nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
27391 +                               continue;
27392                         if (num < s_num)
27393                                 goto next_normal;
27394                         if (!(r->idiag_states & (1 << sk->sk_state)))
27395 @@ -817,6 +827,8 @@ next_normal:
27396                         inet_twsk_for_each(tw, node,
27397                                     &head->twchain) {
27398  
27399 +                               if (!nx_check(tw->tw_nid, VS_WATCH_P | VS_IDENT))
27400 +                                       continue;
27401                                 if (num < s_num)
27402                                         goto next_dying;
27403                                 if (r->id.idiag_sport != tw->tw_sport &&
27404 diff -NurpP --minimal linux-2.6.32.6/net/ipv4/inet_hashtables.c linux-2.6.32.6-vs2.3.0.36.28/net/ipv4/inet_hashtables.c
27405 --- linux-2.6.32.6/net/ipv4/inet_hashtables.c   2009-06-11 17:13:29.000000000 +0200
27406 +++ linux-2.6.32.6-vs2.3.0.36.28/net/ipv4/inet_hashtables.c     2009-12-03 20:04:56.000000000 +0100
27407 @@ -21,6 +21,7 @@
27408  
27409  #include <net/inet_connection_sock.h>
27410  #include <net/inet_hashtables.h>
27411 +#include <net/route.h>
27412  #include <net/ip.h>
27413  
27414  /*
27415 @@ -134,6 +135,11 @@ static inline int compute_score(struct s
27416                         if (rcv_saddr != daddr)
27417                                 return -1;
27418                         score += 2;
27419 +               } else {
27420 +                       /* block non nx_info ips */
27421 +                       if (!v4_addr_in_nx_info(sk->sk_nx_info,
27422 +                               daddr, NXA_MASK_BIND))
27423 +                               return -1;
27424                 }
27425                 if (sk->sk_bound_dev_if) {
27426                         if (sk->sk_bound_dev_if != dif)
27427 @@ -151,7 +157,6 @@ static inline int compute_score(struct s
27428   * wildcarded during the search since they can never be otherwise.
27429   */
27430  
27431 -
27432  struct sock *__inet_lookup_listener(struct net *net,
27433                                     struct inet_hashinfo *hashinfo,
27434                                     const __be32 daddr, const unsigned short hnum,
27435 @@ -174,6 +179,7 @@ begin:
27436                         hiscore = score;
27437                 }
27438         }
27439 +
27440         /*
27441          * if the nulls value we got at the end of this lookup is
27442          * not the expected one, we must restart lookup.
27443 diff -NurpP --minimal linux-2.6.32.6/net/ipv4/netfilter/nf_nat_helper.c linux-2.6.32.6-vs2.3.0.36.28/net/ipv4/netfilter/nf_nat_helper.c
27444 --- linux-2.6.32.6/net/ipv4/netfilter/nf_nat_helper.c   2009-12-03 20:02:59.000000000 +0100
27445 +++ linux-2.6.32.6-vs2.3.0.36.28/net/ipv4/netfilter/nf_nat_helper.c     2009-12-03 20:04:56.000000000 +0100
27446 @@ -19,6 +19,7 @@
27447  #include <net/route.h>
27448  
27449  #include <linux/netfilter_ipv4.h>
27450 +#include <net/route.h>
27451  #include <net/netfilter/nf_conntrack.h>
27452  #include <net/netfilter/nf_conntrack_helper.h>
27453  #include <net/netfilter/nf_conntrack_ecache.h>
27454 diff -NurpP --minimal linux-2.6.32.6/net/ipv4/netfilter.c linux-2.6.32.6-vs2.3.0.36.28/net/ipv4/netfilter.c
27455 --- linux-2.6.32.6/net/ipv4/netfilter.c 2009-09-10 15:26:29.000000000 +0200
27456 +++ linux-2.6.32.6-vs2.3.0.36.28/net/ipv4/netfilter.c   2009-12-03 20:04:56.000000000 +0100
27457 @@ -4,7 +4,7 @@
27458  #include <linux/netfilter_ipv4.h>
27459  #include <linux/ip.h>
27460  #include <linux/skbuff.h>
27461 -#include <net/route.h>
27462 +// #include <net/route.h>
27463  #include <net/xfrm.h>
27464  #include <net/ip.h>
27465  #include <net/netfilter/nf_queue.h>
27466 diff -NurpP --minimal linux-2.6.32.6/net/ipv4/raw.c linux-2.6.32.6-vs2.3.0.36.28/net/ipv4/raw.c
27467 --- linux-2.6.32.6/net/ipv4/raw.c       2009-12-03 20:02:59.000000000 +0100
27468 +++ linux-2.6.32.6-vs2.3.0.36.28/net/ipv4/raw.c 2009-12-03 20:04:56.000000000 +0100
27469 @@ -117,7 +117,7 @@ static struct sock *__raw_v4_lookup(stru
27470  
27471                 if (net_eq(sock_net(sk), net) && inet->num == num       &&
27472                     !(inet->daddr && inet->daddr != raddr)              &&
27473 -                   !(inet->rcv_saddr && inet->rcv_saddr != laddr)      &&
27474 +                   v4_sock_addr_match(sk->sk_nx_info, inet, laddr)     &&
27475                     !(sk->sk_bound_dev_if && sk->sk_bound_dev_if != dif))
27476                         goto found; /* gotcha */
27477         }
27478 @@ -383,6 +383,12 @@ static int raw_send_hdrinc(struct sock *
27479                 icmp_out_count(net, ((struct icmphdr *)
27480                         skb_transport_header(skb))->type);
27481  
27482 +       err = -EPERM;
27483 +       if (!nx_check(0, VS_ADMIN) && !capable(CAP_NET_RAW) &&
27484 +               sk->sk_nx_info &&
27485 +               !v4_addr_in_nx_info(sk->sk_nx_info, iph->saddr, NXA_MASK_BIND))
27486 +               goto error_free;
27487 +
27488         err = NF_HOOK(PF_INET, NF_INET_LOCAL_OUT, skb, NULL, rt->u.dst.dev,
27489                       dst_output);
27490         if (err > 0)
27491 @@ -563,6 +569,13 @@ static int raw_sendmsg(struct kiocb *ioc
27492                 }
27493  
27494                 security_sk_classify_flow(sk, &fl);
27495 +               if (sk->sk_nx_info) {
27496 +                       err = ip_v4_find_src(sock_net(sk),
27497 +                               sk->sk_nx_info, &rt, &fl);
27498 +
27499 +                       if (err)
27500 +                               goto done;
27501 +               }
27502                 err = ip_route_output_flow(sock_net(sk), &rt, &fl, sk, 1);
27503         }
27504         if (err)
27505 @@ -635,17 +648,19 @@ static int raw_bind(struct sock *sk, str
27506  {
27507         struct inet_sock *inet = inet_sk(sk);
27508         struct sockaddr_in *addr = (struct sockaddr_in *) uaddr;
27509 +       struct nx_v4_sock_addr nsa = { 0 };
27510         int ret = -EINVAL;
27511         int chk_addr_ret;
27512  
27513         if (sk->sk_state != TCP_CLOSE || addr_len < sizeof(struct sockaddr_in))
27514                 goto out;
27515 -       chk_addr_ret = inet_addr_type(sock_net(sk), addr->sin_addr.s_addr);
27516 +       v4_map_sock_addr(inet, addr, &nsa);
27517 +       chk_addr_ret = inet_addr_type(sock_net(sk), nsa.saddr);
27518         ret = -EADDRNOTAVAIL;
27519 -       if (addr->sin_addr.s_addr && chk_addr_ret != RTN_LOCAL &&
27520 +       if (nsa.saddr && chk_addr_ret != RTN_LOCAL &&
27521             chk_addr_ret != RTN_MULTICAST && chk_addr_ret != RTN_BROADCAST)
27522                 goto out;
27523 -       inet->rcv_saddr = inet->saddr = addr->sin_addr.s_addr;
27524 +       v4_set_sock_addr(inet, &nsa);
27525         if (chk_addr_ret == RTN_MULTICAST || chk_addr_ret == RTN_BROADCAST)
27526                 inet->saddr = 0;  /* Use device */
27527         sk_dst_reset(sk);
27528 @@ -697,7 +712,8 @@ static int raw_recvmsg(struct kiocb *ioc
27529         /* Copy the address. */
27530         if (sin) {
27531                 sin->sin_family = AF_INET;
27532 -               sin->sin_addr.s_addr = ip_hdr(skb)->saddr;
27533 +               sin->sin_addr.s_addr =
27534 +                       nx_map_sock_lback(sk->sk_nx_info, ip_hdr(skb)->saddr);
27535                 sin->sin_port = 0;
27536                 memset(&sin->sin_zero, 0, sizeof(sin->sin_zero));
27537         }
27538 @@ -875,7 +891,8 @@ static struct sock *raw_get_first(struct
27539                 struct hlist_node *node;
27540  
27541                 sk_for_each(sk, node, &state->h->ht[state->bucket])
27542 -                       if (sock_net(sk) == seq_file_net(seq))
27543 +                       if ((sock_net(sk) == seq_file_net(seq)) &&
27544 +                               nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
27545                                 goto found;
27546         }
27547         sk = NULL;
27548 @@ -891,7 +908,8 @@ static struct sock *raw_get_next(struct 
27549                 sk = sk_next(sk);
27550  try_again:
27551                 ;
27552 -       } while (sk && sock_net(sk) != seq_file_net(seq));
27553 +       } while (sk && ((sock_net(sk) != seq_file_net(seq)) ||
27554 +               !nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT)));
27555  
27556         if (!sk && ++state->bucket < RAW_HTABLE_SIZE) {
27557                 sk = sk_head(&state->h->ht[state->bucket]);
27558 @@ -950,7 +968,10 @@ static void raw_sock_seq_show(struct seq
27559  
27560         seq_printf(seq, "%4d: %08X:%04X %08X:%04X"
27561                 " %02X %08X:%08X %02X:%08lX %08X %5d %8d %lu %d %p %d\n",
27562 -               i, src, srcp, dest, destp, sp->sk_state,
27563 +               i,
27564 +               nx_map_sock_lback(current_nx_info(), src), srcp,
27565 +               nx_map_sock_lback(current_nx_info(), dest), destp,
27566 +               sp->sk_state,
27567                 sk_wmem_alloc_get(sp),
27568                 sk_rmem_alloc_get(sp),
27569                 0, 0L, 0, sock_i_uid(sp), 0, sock_i_ino(sp),
27570 diff -NurpP --minimal linux-2.6.32.6/net/ipv4/tcp.c linux-2.6.32.6-vs2.3.0.36.28/net/ipv4/tcp.c
27571 --- linux-2.6.32.6/net/ipv4/tcp.c       2009-12-03 20:02:59.000000000 +0100
27572 +++ linux-2.6.32.6-vs2.3.0.36.28/net/ipv4/tcp.c 2009-12-03 20:04:56.000000000 +0100
27573 @@ -264,6 +264,7 @@
27574  #include <linux/cache.h>
27575  #include <linux/err.h>
27576  #include <linux/crypto.h>
27577 +#include <linux/in.h>
27578  
27579  #include <net/icmp.h>
27580  #include <net/tcp.h>
27581 diff -NurpP --minimal linux-2.6.32.6/net/ipv4/tcp_ipv4.c linux-2.6.32.6-vs2.3.0.36.28/net/ipv4/tcp_ipv4.c
27582 --- linux-2.6.32.6/net/ipv4/tcp_ipv4.c  2009-12-03 20:03:00.000000000 +0100
27583 +++ linux-2.6.32.6-vs2.3.0.36.28/net/ipv4/tcp_ipv4.c    2009-12-03 20:04:56.000000000 +0100
27584 @@ -1925,6 +1925,12 @@ static void *listening_get_next(struct s
27585                 req = req->dl_next;
27586                 while (1) {
27587                         while (req) {
27588 +                               vxdprintk(VXD_CBIT(net, 6),
27589 +                                       "sk,req: %p [#%d] (from %d)", req->sk,
27590 +                                       (req->sk)?req->sk->sk_nid:0, nx_current_nid());
27591 +                               if (req->sk &&
27592 +                                       !nx_check(req->sk->sk_nid, VS_WATCH_P | VS_IDENT))
27593 +                                       continue;
27594                                 if (req->rsk_ops->family == st->family) {
27595                                         cur = req;
27596                                         goto out;
27597 @@ -1949,6 +1955,10 @@ get_req:
27598         }
27599  get_sk:
27600         sk_nulls_for_each_from(sk, node) {
27601 +               vxdprintk(VXD_CBIT(net, 6), "sk: %p [#%d] (from %d)",
27602 +                       sk, sk->sk_nid, nx_current_nid());
27603 +               if (!nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
27604 +                       continue;
27605                 if (sk->sk_family == st->family && net_eq(sock_net(sk), net)) {
27606                         cur = sk;
27607                         goto out;
27608 @@ -2012,6 +2022,11 @@ static void *established_get_first(struc
27609  
27610                 spin_lock_bh(lock);
27611                 sk_nulls_for_each(sk, node, &tcp_hashinfo.ehash[st->bucket].chain) {
27612 +                       vxdprintk(VXD_CBIT(net, 6),
27613 +                               "sk,egf: %p [#%d] (from %d)",
27614 +                               sk, sk->sk_nid, nx_current_nid());
27615 +                       if (!nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
27616 +                               continue;
27617                         if (sk->sk_family != st->family ||
27618                             !net_eq(sock_net(sk), net)) {
27619                                 continue;
27620 @@ -2022,6 +2037,11 @@ static void *established_get_first(struc
27621                 st->state = TCP_SEQ_STATE_TIME_WAIT;
27622                 inet_twsk_for_each(tw, node,
27623                                    &tcp_hashinfo.ehash[st->bucket].twchain) {
27624 +                       vxdprintk(VXD_CBIT(net, 6),
27625 +                               "tw: %p [#%d] (from %d)",
27626 +                               tw, tw->tw_nid, nx_current_nid());
27627 +                       if (!nx_check(tw->tw_nid, VS_WATCH_P | VS_IDENT))
27628 +                               continue;
27629                         if (tw->tw_family != st->family ||
27630                             !net_eq(twsk_net(tw), net)) {
27631                                 continue;
27632 @@ -2050,7 +2070,9 @@ static void *established_get_next(struct
27633                 tw = cur;
27634                 tw = tw_next(tw);
27635  get_tw:
27636 -               while (tw && (tw->tw_family != st->family || !net_eq(twsk_net(tw), net))) {
27637 +               while (tw && (tw->tw_family != st->family ||
27638 +                       !net_eq(twsk_net(tw), net) ||
27639 +                       !nx_check(tw->tw_nid, VS_WATCH_P | VS_IDENT))) {
27640                         tw = tw_next(tw);
27641                 }
27642                 if (tw) {
27643 @@ -2073,6 +2095,11 @@ get_tw:
27644                 sk = sk_nulls_next(sk);
27645  
27646         sk_nulls_for_each_from(sk, node) {
27647 +               vxdprintk(VXD_CBIT(net, 6),
27648 +                       "sk,egn: %p [#%d] (from %d)",
27649 +                       sk, sk->sk_nid, nx_current_nid());
27650 +               if (!nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
27651 +                       continue;
27652                 if (sk->sk_family == st->family && net_eq(sock_net(sk), net))
27653                         goto found;
27654         }
27655 @@ -2224,9 +2251,9 @@ static void get_openreq4(struct sock *sk
27656         seq_printf(f, "%4d: %08X:%04X %08X:%04X"
27657                 " %02X %08X:%08X %02X:%08lX %08X %5d %8d %u %d %p%n",
27658                 i,
27659 -               ireq->loc_addr,
27660 +               nx_map_sock_lback(current_nx_info(), ireq->loc_addr),
27661                 ntohs(inet_sk(sk)->sport),
27662 -               ireq->rmt_addr,
27663 +               nx_map_sock_lback(current_nx_info(), ireq->rmt_addr),
27664                 ntohs(ireq->rmt_port),
27665                 TCP_SYN_RECV,
27666                 0, 0, /* could print option size, but that is af dependent. */
27667 @@ -2269,7 +2296,10 @@ static void get_tcp4_sock(struct sock *s
27668  
27669         seq_printf(f, "%4d: %08X:%04X %08X:%04X %02X %08X:%08X %02X:%08lX "
27670                         "%08X %5d %8d %lu %d %p %lu %lu %u %u %d%n",
27671 -               i, src, srcp, dest, destp, sk->sk_state,
27672 +               i,
27673 +               nx_map_sock_lback(current_nx_info(), src), srcp,
27674 +               nx_map_sock_lback(current_nx_info(), dest), destp,
27675 +               sk->sk_state,
27676                 tp->write_seq - tp->snd_una,
27677                 sk->sk_state == TCP_LISTEN ? sk->sk_ack_backlog :
27678                                              (tp->rcv_nxt - tp->copied_seq),
27679 @@ -2305,7 +2335,10 @@ static void get_timewait4_sock(struct in
27680  
27681         seq_printf(f, "%4d: %08X:%04X %08X:%04X"
27682                 " %02X %08X:%08X %02X:%08lX %08X %5d %8d %d %d %p%n",
27683 -               i, src, srcp, dest, destp, tw->tw_substate, 0, 0,
27684 +               i,
27685 +               nx_map_sock_lback(current_nx_info(), src), srcp,
27686 +               nx_map_sock_lback(current_nx_info(), dest), destp,
27687 +               tw->tw_substate, 0, 0,
27688                 3, jiffies_to_clock_t(ttd), 0, 0, 0, 0,
27689                 atomic_read(&tw->tw_refcnt), tw, len);
27690  }
27691 diff -NurpP --minimal linux-2.6.32.6/net/ipv4/tcp_minisocks.c linux-2.6.32.6-vs2.3.0.36.28/net/ipv4/tcp_minisocks.c
27692 --- linux-2.6.32.6/net/ipv4/tcp_minisocks.c     2009-12-03 20:03:00.000000000 +0100
27693 +++ linux-2.6.32.6-vs2.3.0.36.28/net/ipv4/tcp_minisocks.c       2009-12-03 20:04:56.000000000 +0100
27694 @@ -26,6 +26,10 @@
27695  #include <net/inet_common.h>
27696  #include <net/xfrm.h>
27697  
27698 +#include <linux/vs_limit.h>
27699 +#include <linux/vs_socket.h>
27700 +#include <linux/vs_context.h>
27701 +
27702  #ifdef CONFIG_SYSCTL
27703  #define SYNC_INIT 0 /* let the user enable it */
27704  #else
27705 @@ -294,6 +298,11 @@ void tcp_time_wait(struct sock *sk, int 
27706                 tcptw->tw_ts_recent     = tp->rx_opt.ts_recent;
27707                 tcptw->tw_ts_recent_stamp = tp->rx_opt.ts_recent_stamp;
27708  
27709 +               tw->tw_xid              = sk->sk_xid;
27710 +               tw->tw_vx_info          = NULL;
27711 +               tw->tw_nid              = sk->sk_nid;
27712 +               tw->tw_nx_info          = NULL;
27713 +
27714  #if defined(CONFIG_IPV6) || defined(CONFIG_IPV6_MODULE)
27715                 if (tw->tw_family == PF_INET6) {
27716                         struct ipv6_pinfo *np = inet6_sk(sk);
27717 diff -NurpP --minimal linux-2.6.32.6/net/ipv4/udp.c linux-2.6.32.6-vs2.3.0.36.28/net/ipv4/udp.c
27718 --- linux-2.6.32.6/net/ipv4/udp.c       2009-12-03 20:03:00.000000000 +0100
27719 +++ linux-2.6.32.6-vs2.3.0.36.28/net/ipv4/udp.c 2009-12-03 20:04:56.000000000 +0100
27720 @@ -224,14 +224,7 @@ fail:
27721  }
27722  EXPORT_SYMBOL(udp_lib_get_port);
27723  
27724 -static int ipv4_rcv_saddr_equal(const struct sock *sk1, const struct sock *sk2)
27725 -{
27726 -       struct inet_sock *inet1 = inet_sk(sk1), *inet2 = inet_sk(sk2);
27727 -
27728 -       return  (!ipv6_only_sock(sk2)  &&
27729 -                (!inet1->rcv_saddr || !inet2->rcv_saddr ||
27730 -                  inet1->rcv_saddr == inet2->rcv_saddr));
27731 -}
27732 +extern int ipv4_rcv_saddr_equal(const struct sock *, const struct sock *);
27733  
27734  int udp_v4_get_port(struct sock *sk, unsigned short snum)
27735  {
27736 @@ -253,6 +246,11 @@ static inline int compute_score(struct s
27737                         if (inet->rcv_saddr != daddr)
27738                                 return -1;
27739                         score += 2;
27740 +               } else {
27741 +                       /* block non nx_info ips */
27742 +                       if (!v4_addr_in_nx_info(sk->sk_nx_info,
27743 +                               daddr, NXA_MASK_BIND))
27744 +                               return -1;
27745                 }
27746                 if (inet->daddr) {
27747                         if (inet->daddr != saddr)
27748 @@ -273,6 +271,7 @@ static inline int compute_score(struct s
27749         return score;
27750  }
27751  
27752 +
27753  /* UDP is nearly always wildcards out the wazoo, it makes no sense to try
27754   * harder than this. -DaveM
27755   */
27756 @@ -294,6 +293,11 @@ begin:
27757         sk_nulls_for_each_rcu(sk, node, &hslot->head) {
27758                 score = compute_score(sk, net, saddr, hnum, sport,
27759                                       daddr, dport, dif);
27760 +               /* FIXME: disabled?
27761 +               if (score == 9) {
27762 +                       result = sk;
27763 +                       break;
27764 +               } else */
27765                 if (score > badness) {
27766                         result = sk;
27767                         badness = score;
27768 @@ -307,6 +311,7 @@ begin:
27769         if (get_nulls_value(node) != hash)
27770                 goto begin;
27771  
27772 +
27773         if (result) {
27774                 if (unlikely(!atomic_inc_not_zero(&result->sk_refcnt)))
27775                         result = NULL;
27776 @@ -316,6 +321,7 @@ begin:
27777                         goto begin;
27778                 }
27779         }
27780 +
27781         rcu_read_unlock();
27782         return result;
27783  }
27784 @@ -358,7 +364,7 @@ static inline struct sock *udp_v4_mcast_
27785                     s->sk_hash != hnum                                  ||
27786                     (inet->daddr && inet->daddr != rmt_addr)            ||
27787                     (inet->dport != rmt_port && inet->dport)            ||
27788 -                   (inet->rcv_saddr && inet->rcv_saddr != loc_addr)    ||
27789 +                   !v4_sock_addr_match(sk->sk_nx_info, inet, loc_addr) ||
27790                     ipv6_only_sock(s)                                   ||
27791                     (s->sk_bound_dev_if && s->sk_bound_dev_if != dif))
27792                         continue;
27793 @@ -707,8 +713,13 @@ int udp_sendmsg(struct kiocb *iocb, stru
27794                                                { .sport = inet->sport,
27795                                                  .dport = dport } } };
27796                 struct net *net = sock_net(sk);
27797 +               struct nx_info *nxi = sk->sk_nx_info;
27798  
27799                 security_sk_classify_flow(sk, &fl);
27800 +               err = ip_v4_find_src(net, nxi, &rt, &fl);
27801 +               if (err)
27802 +                       goto out;
27803 +
27804                 err = ip_route_output_flow(net, &rt, &fl, sk, 1);
27805                 if (err) {
27806                         if (err == -ENETUNREACH)
27807 @@ -988,7 +999,8 @@ try_again:
27808         if (sin) {
27809                 sin->sin_family = AF_INET;
27810                 sin->sin_port = udp_hdr(skb)->source;
27811 -               sin->sin_addr.s_addr = ip_hdr(skb)->saddr;
27812 +               sin->sin_addr.s_addr = nx_map_sock_lback(
27813 +                       skb->sk->sk_nx_info, ip_hdr(skb)->saddr);
27814                 memset(sin->sin_zero, 0, sizeof(sin->sin_zero));
27815         }
27816         if (inet->cmsg_flags)
27817 @@ -1627,6 +1639,8 @@ static struct sock *udp_get_first(struct
27818                 sk_nulls_for_each(sk, node, &hslot->head) {
27819                         if (!net_eq(sock_net(sk), net))
27820                                 continue;
27821 +                       if (!nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
27822 +                               continue;
27823                         if (sk->sk_family == state->family)
27824                                 goto found;
27825                 }
27826 @@ -1644,7 +1658,9 @@ static struct sock *udp_get_next(struct 
27827  
27828         do {
27829                 sk = sk_nulls_next(sk);
27830 -       } while (sk && (!net_eq(sock_net(sk), net) || sk->sk_family != state->family));
27831 +       } while (sk && (!net_eq(sock_net(sk), net) ||
27832 +               sk->sk_family != state->family ||
27833 +               !nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT)));
27834  
27835         if (!sk) {
27836                 if (state->bucket < UDP_HTABLE_SIZE)
27837 @@ -1751,7 +1767,10 @@ static void udp4_format_sock(struct sock
27838  
27839         seq_printf(f, "%4d: %08X:%04X %08X:%04X"
27840                 " %02X %08X:%08X %02X:%08lX %08X %5d %8d %lu %d %p %d%n",
27841 -               bucket, src, srcp, dest, destp, sp->sk_state,
27842 +               bucket,
27843 +               nx_map_sock_lback(current_nx_info(), src), srcp,
27844 +               nx_map_sock_lback(current_nx_info(), dest), destp,
27845 +               sp->sk_state,
27846                 sk_wmem_alloc_get(sp),
27847                 sk_rmem_alloc_get(sp),
27848                 0, 0L, 0, sock_i_uid(sp), 0, sock_i_ino(sp),
27849 diff -NurpP --minimal linux-2.6.32.6/net/ipv6/addrconf.c linux-2.6.32.6-vs2.3.0.36.28/net/ipv6/addrconf.c
27850 --- linux-2.6.32.6/net/ipv6/addrconf.c  2009-12-03 20:03:00.000000000 +0100
27851 +++ linux-2.6.32.6-vs2.3.0.36.28/net/ipv6/addrconf.c    2009-12-03 20:04:56.000000000 +0100
27852 @@ -86,6 +86,8 @@
27853  
27854  #include <linux/proc_fs.h>
27855  #include <linux/seq_file.h>
27856 +#include <linux/vs_network.h>
27857 +#include <linux/vs_inet6.h>
27858  
27859  /* Set to 3 to get tracing... */
27860  #define ACONF_DEBUG 2
27861 @@ -1119,7 +1121,7 @@ out:
27862  
27863  int ipv6_dev_get_saddr(struct net *net, struct net_device *dst_dev,
27864                        const struct in6_addr *daddr, unsigned int prefs,
27865 -                      struct in6_addr *saddr)
27866 +                      struct in6_addr *saddr, struct nx_info *nxi)
27867  {
27868         struct ipv6_saddr_score scores[2],
27869                                 *score = &scores[0], *hiscore = &scores[1];
27870 @@ -1192,6 +1194,8 @@ int ipv6_dev_get_saddr(struct net *net, 
27871                                                dev->name);
27872                                 continue;
27873                         }
27874 +                       if (!v6_addr_in_nx_info(nxi, &score->ifa->addr, -1))
27875 +                               continue;
27876  
27877                         score->rule = -1;
27878                         bitmap_zero(score->scorebits, IPV6_SADDR_RULE_MAX);
27879 @@ -3000,7 +3004,10 @@ static void if6_seq_stop(struct seq_file
27880  static int if6_seq_show(struct seq_file *seq, void *v)
27881  {
27882         struct inet6_ifaddr *ifp = (struct inet6_ifaddr *)v;
27883 -       seq_printf(seq, "%pi6 %02x %02x %02x %02x %8s\n",
27884 +
27885 +       if (nx_check(0, VS_ADMIN|VS_WATCH) ||
27886 +           v6_addr_in_nx_info(current_nx_info(), &ifp->addr, -1))
27887 +               seq_printf(seq, "%pi6 %02x %02x %02x %02x %8s\n",
27888                    &ifp->addr,
27889                    ifp->idev->dev->ifindex,
27890                    ifp->prefix_len,
27891 @@ -3497,6 +3504,12 @@ static int inet6_dump_addr(struct sk_buf
27892         struct ifmcaddr6 *ifmca;
27893         struct ifacaddr6 *ifaca;
27894         struct net *net = sock_net(skb->sk);
27895 +       struct nx_info *nxi = skb->sk ? skb->sk->sk_nx_info : NULL;
27896 +
27897 +       /* disable ipv6 on non v6 guests */
27898 +       if (nxi && !nx_info_has_v6(nxi))
27899 +               return skb->len;
27900 +
27901  
27902         s_idx = cb->args[0];
27903         s_ip_idx = ip_idx = cb->args[1];
27904 @@ -3518,6 +3531,8 @@ static int inet6_dump_addr(struct sk_buf
27905                              ifa = ifa->if_next, ip_idx++) {
27906                                 if (ip_idx < s_ip_idx)
27907                                         continue;
27908 +                               if (!v6_addr_in_nx_info(nxi, &ifa->addr, -1))
27909 +                                       continue;
27910                                 err = inet6_fill_ifaddr(skb, ifa,
27911                                                         NETLINK_CB(cb->skb).pid,
27912                                                         cb->nlh->nlmsg_seq,
27913 @@ -3531,6 +3546,8 @@ static int inet6_dump_addr(struct sk_buf
27914                              ifmca = ifmca->next, ip_idx++) {
27915                                 if (ip_idx < s_ip_idx)
27916                                         continue;
27917 +                               if (!v6_addr_in_nx_info(nxi, &ifmca->mca_addr, -1))
27918 +                                       continue;
27919                                 err = inet6_fill_ifmcaddr(skb, ifmca,
27920                                                           NETLINK_CB(cb->skb).pid,
27921                                                           cb->nlh->nlmsg_seq,
27922 @@ -3544,6 +3561,8 @@ static int inet6_dump_addr(struct sk_buf
27923                              ifaca = ifaca->aca_next, ip_idx++) {
27924                                 if (ip_idx < s_ip_idx)
27925                                         continue;
27926 +                               if (!v6_addr_in_nx_info(nxi, &ifaca->aca_addr, -1))
27927 +                                       continue;
27928                                 err = inet6_fill_ifacaddr(skb, ifaca,
27929                                                           NETLINK_CB(cb->skb).pid,
27930                                                           cb->nlh->nlmsg_seq,
27931 @@ -3830,12 +3849,19 @@ static int inet6_dump_ifinfo(struct sk_b
27932         int s_idx = cb->args[0];
27933         struct net_device *dev;
27934         struct inet6_dev *idev;
27935 +       struct nx_info *nxi = skb->sk ? skb->sk->sk_nx_info : NULL;
27936 +
27937 +       /* FIXME: maybe disable ipv6 on non v6 guests?
27938 +       if (skb->sk && skb->sk->sk_vx_info)
27939 +               return skb->len; */
27940  
27941         read_lock(&dev_base_lock);
27942         idx = 0;
27943         for_each_netdev(net, dev) {
27944                 if (idx < s_idx)
27945                         goto cont;
27946 +               if (!v6_dev_in_nx_info(dev, nxi))
27947 +                       goto cont;
27948                 if ((idev = in6_dev_get(dev)) == NULL)
27949                         goto cont;
27950                 err = inet6_fill_ifinfo(skb, idev, NETLINK_CB(cb->skb).pid,
27951 diff -NurpP --minimal linux-2.6.32.6/net/ipv6/af_inet6.c linux-2.6.32.6-vs2.3.0.36.28/net/ipv6/af_inet6.c
27952 --- linux-2.6.32.6/net/ipv6/af_inet6.c  2009-12-03 20:03:00.000000000 +0100
27953 +++ linux-2.6.32.6-vs2.3.0.36.28/net/ipv6/af_inet6.c    2009-12-03 20:04:56.000000000 +0100
27954 @@ -41,6 +41,8 @@
27955  #include <linux/netdevice.h>
27956  #include <linux/icmpv6.h>
27957  #include <linux/netfilter_ipv6.h>
27958 +#include <linux/vs_inet.h>
27959 +#include <linux/vs_inet6.h>
27960  
27961  #include <net/ip.h>
27962  #include <net/ipv6.h>
27963 @@ -158,9 +160,12 @@ lookup_protocol:
27964         }
27965  
27966         err = -EPERM;
27967 +       if ((protocol == IPPROTO_ICMPV6) &&
27968 +               nx_capable(answer->capability, NXC_RAW_ICMP))
27969 +               goto override;
27970         if (answer->capability > 0 && !capable(answer->capability))
27971                 goto out_rcu_unlock;
27972 -
27973 +override:
27974         sock->ops = answer->ops;
27975         answer_prot = answer->prot;
27976         answer_no_check = answer->no_check;
27977 @@ -259,6 +264,7 @@ int inet6_bind(struct socket *sock, stru
27978         struct inet_sock *inet = inet_sk(sk);
27979         struct ipv6_pinfo *np = inet6_sk(sk);
27980         struct net *net = sock_net(sk);
27981 +       struct nx_v6_sock_addr nsa;
27982         __be32 v4addr = 0;
27983         unsigned short snum;
27984         int addr_type = 0;
27985 @@ -270,6 +276,11 @@ int inet6_bind(struct socket *sock, stru
27986  
27987         if (addr_len < SIN6_LEN_RFC2133)
27988                 return -EINVAL;
27989 +
27990 +       err = v6_map_sock_addr(inet, addr, &nsa);
27991 +       if (err)
27992 +               return err;
27993 +
27994         addr_type = ipv6_addr_type(&addr->sin6_addr);
27995         if ((addr_type & IPV6_ADDR_MULTICAST) && sock->type == SOCK_STREAM)
27996                 return -EINVAL;
27997 @@ -301,6 +312,7 @@ int inet6_bind(struct socket *sock, stru
27998                 /* Reproduce AF_INET checks to make the bindings consitant */
27999                 v4addr = addr->sin6_addr.s6_addr32[3];
28000                 chk_addr_ret = inet_addr_type(net, v4addr);
28001 +
28002                 if (!sysctl_ip_nonlocal_bind &&
28003                     !(inet->freebind || inet->transparent) &&
28004                     v4addr != htonl(INADDR_ANY) &&
28005 @@ -310,6 +322,10 @@ int inet6_bind(struct socket *sock, stru
28006                         err = -EADDRNOTAVAIL;
28007                         goto out;
28008                 }
28009 +               if (!v4_addr_in_nx_info(sk->sk_nx_info, v4addr, NXA_MASK_BIND)) {
28010 +                       err = -EADDRNOTAVAIL;
28011 +                       goto out;
28012 +               }
28013         } else {
28014                 if (addr_type != IPV6_ADDR_ANY) {
28015                         struct net_device *dev = NULL;
28016 @@ -335,6 +351,11 @@ int inet6_bind(struct socket *sock, stru
28017                                 }
28018                         }
28019  
28020 +                       if (!v6_addr_in_nx_info(sk->sk_nx_info, &addr->sin6_addr, -1)) {
28021 +                               err = -EADDRNOTAVAIL;
28022 +                               goto out;
28023 +                       }
28024 +
28025                         /* ipv4 addr of the socket is invalid.  Only the
28026                          * unspecified and mapped address have a v4 equivalent.
28027                          */
28028 @@ -353,6 +374,8 @@ int inet6_bind(struct socket *sock, stru
28029                 }
28030         }
28031  
28032 +       v6_set_sock_addr(inet, &nsa);
28033 +
28034         inet->rcv_saddr = v4addr;
28035         inet->saddr = v4addr;
28036  
28037 @@ -448,9 +471,11 @@ int inet6_getname(struct socket *sock, s
28038                         return -ENOTCONN;
28039                 sin->sin6_port = inet->dport;
28040                 ipv6_addr_copy(&sin->sin6_addr, &np->daddr);
28041 +               /* FIXME: remap lback? */
28042                 if (np->sndflow)
28043                         sin->sin6_flowinfo = np->flow_label;
28044         } else {
28045 +               /* FIXME: remap lback? */
28046                 if (ipv6_addr_any(&np->rcv_saddr))
28047                         ipv6_addr_copy(&sin->sin6_addr, &np->saddr);
28048                 else
28049 diff -NurpP --minimal linux-2.6.32.6/net/ipv6/fib6_rules.c linux-2.6.32.6-vs2.3.0.36.28/net/ipv6/fib6_rules.c
28050 --- linux-2.6.32.6/net/ipv6/fib6_rules.c        2009-09-10 15:26:30.000000000 +0200
28051 +++ linux-2.6.32.6-vs2.3.0.36.28/net/ipv6/fib6_rules.c  2009-12-03 20:04:56.000000000 +0100
28052 @@ -96,7 +96,7 @@ static int fib6_rule_action(struct fib_r
28053                         if (ipv6_dev_get_saddr(net,
28054                                                ip6_dst_idev(&rt->u.dst)->dev,
28055                                                &flp->fl6_dst, srcprefs,
28056 -                                              &saddr))
28057 +                                              &saddr, NULL))
28058                                 goto again;
28059                         if (!ipv6_prefix_equal(&saddr, &r->src.addr,
28060                                                r->src.plen))
28061 diff -NurpP --minimal linux-2.6.32.6/net/ipv6/inet6_hashtables.c linux-2.6.32.6-vs2.3.0.36.28/net/ipv6/inet6_hashtables.c
28062 --- linux-2.6.32.6/net/ipv6/inet6_hashtables.c  2009-03-24 14:22:46.000000000 +0100
28063 +++ linux-2.6.32.6-vs2.3.0.36.28/net/ipv6/inet6_hashtables.c    2009-12-03 20:04:56.000000000 +0100
28064 @@ -16,6 +16,7 @@
28065  
28066  #include <linux/module.h>
28067  #include <linux/random.h>
28068 +#include <linux/vs_inet6.h>
28069  
28070  #include <net/inet_connection_sock.h>
28071  #include <net/inet_hashtables.h>
28072 @@ -76,7 +77,6 @@ struct sock *__inet6_lookup_established(
28073         unsigned int slot = hash & (hashinfo->ehash_size - 1);
28074         struct inet_ehash_bucket *head = &hashinfo->ehash[slot];
28075  
28076 -
28077         rcu_read_lock();
28078  begin:
28079         sk_nulls_for_each_rcu(sk, node, &head->chain) {
28080 @@ -88,7 +88,7 @@ begin:
28081                                 sock_put(sk);
28082                                 goto begin;
28083                         }
28084 -               goto out;
28085 +                       goto out;
28086                 }
28087         }
28088         if (get_nulls_value(node) != slot)
28089 @@ -134,6 +134,9 @@ static int inline compute_score(struct s
28090                         if (!ipv6_addr_equal(&np->rcv_saddr, daddr))
28091                                 return -1;
28092                         score++;
28093 +               } else {
28094 +                       if (!v6_addr_in_nx_info(sk->sk_nx_info, daddr, -1))
28095 +                               return -1;
28096                 }
28097                 if (sk->sk_bound_dev_if) {
28098                         if (sk->sk_bound_dev_if != dif)
28099 diff -NurpP --minimal linux-2.6.32.6/net/ipv6/ip6_output.c linux-2.6.32.6-vs2.3.0.36.28/net/ipv6/ip6_output.c
28100 --- linux-2.6.32.6/net/ipv6/ip6_output.c        2009-12-03 20:03:00.000000000 +0100
28101 +++ linux-2.6.32.6-vs2.3.0.36.28/net/ipv6/ip6_output.c  2009-12-03 20:04:56.000000000 +0100
28102 @@ -934,7 +934,7 @@ static int ip6_dst_lookup_tail(struct so
28103                 err = ipv6_dev_get_saddr(net, ip6_dst_idev(*dst)->dev,
28104                                          &fl->fl6_dst,
28105                                          sk ? inet6_sk(sk)->srcprefs : 0,
28106 -                                        &fl->fl6_src);
28107 +                                        &fl->fl6_src, sk->sk_nx_info);
28108                 if (err)
28109                         goto out_err_release;
28110         }
28111 diff -NurpP --minimal linux-2.6.32.6/net/ipv6/Kconfig linux-2.6.32.6-vs2.3.0.36.28/net/ipv6/Kconfig
28112 --- linux-2.6.32.6/net/ipv6/Kconfig     2009-09-10 15:26:30.000000000 +0200
28113 +++ linux-2.6.32.6-vs2.3.0.36.28/net/ipv6/Kconfig       2009-12-03 20:04:56.000000000 +0100
28114 @@ -4,8 +4,8 @@
28115  
28116  #   IPv6 as module will cause a CRASH if you try to unload it
28117  menuconfig IPV6
28118 -       tristate "The IPv6 protocol"
28119 -       default m
28120 +       bool "The IPv6 protocol"
28121 +       default n
28122         ---help---
28123           This is complemental support for the IP version 6.
28124           You will still be able to do traditional IPv4 networking as well.
28125 diff -NurpP --minimal linux-2.6.32.6/net/ipv6/ndisc.c linux-2.6.32.6-vs2.3.0.36.28/net/ipv6/ndisc.c
28126 --- linux-2.6.32.6/net/ipv6/ndisc.c     2009-12-03 20:03:00.000000000 +0100
28127 +++ linux-2.6.32.6-vs2.3.0.36.28/net/ipv6/ndisc.c       2009-12-03 20:04:56.000000000 +0100
28128 @@ -589,7 +589,7 @@ static void ndisc_send_na(struct net_dev
28129         } else {
28130                 if (ipv6_dev_get_saddr(dev_net(dev), dev, daddr,
28131                                        inet6_sk(dev_net(dev)->ipv6.ndisc_sk)->srcprefs,
28132 -                                      &tmpaddr))
28133 +                                      &tmpaddr, NULL /* FIXME: ? */ ))
28134                         return;
28135                 src_addr = &tmpaddr;
28136         }
28137 diff -NurpP --minimal linux-2.6.32.6/net/ipv6/raw.c linux-2.6.32.6-vs2.3.0.36.28/net/ipv6/raw.c
28138 --- linux-2.6.32.6/net/ipv6/raw.c       2009-12-03 20:03:00.000000000 +0100
28139 +++ linux-2.6.32.6-vs2.3.0.36.28/net/ipv6/raw.c 2009-12-03 20:04:56.000000000 +0100
28140 @@ -29,6 +29,7 @@
28141  #include <linux/icmpv6.h>
28142  #include <linux/netfilter.h>
28143  #include <linux/netfilter_ipv6.h>
28144 +#include <linux/vs_inet6.h>
28145  #include <linux/skbuff.h>
28146  #include <asm/uaccess.h>
28147  #include <asm/ioctls.h>
28148 @@ -281,6 +282,13 @@ static int rawv6_bind(struct sock *sk, s
28149                         }
28150                 }
28151  
28152 +               if (!v6_addr_in_nx_info(sk->sk_nx_info, &addr->sin6_addr, -1)) {
28153 +                       err = -EADDRNOTAVAIL;
28154 +                       if (dev)
28155 +                               dev_put(dev);
28156 +                       goto out;
28157 +               }
28158 +
28159                 /* ipv4 addr of the socket is invalid.  Only the
28160                  * unspecified and mapped address have a v4 equivalent.
28161                  */
28162 diff -NurpP --minimal linux-2.6.32.6/net/ipv6/route.c linux-2.6.32.6-vs2.3.0.36.28/net/ipv6/route.c
28163 --- linux-2.6.32.6/net/ipv6/route.c     2009-12-03 20:03:00.000000000 +0100
28164 +++ linux-2.6.32.6-vs2.3.0.36.28/net/ipv6/route.c       2009-12-03 20:04:56.000000000 +0100
28165 @@ -2257,7 +2257,8 @@ static int rt6_fill_node(struct net *net
28166                 struct inet6_dev *idev = ip6_dst_idev(&rt->u.dst);
28167                 struct in6_addr saddr_buf;
28168                 if (ipv6_dev_get_saddr(net, idev ? idev->dev : NULL,
28169 -                                      dst, 0, &saddr_buf) == 0)
28170 +                       dst, 0, &saddr_buf,
28171 +                       (skb->sk ? skb->sk->sk_nx_info : NULL)) == 0)
28172                         NLA_PUT(skb, RTA_PREFSRC, 16, &saddr_buf);
28173         }
28174  
28175 diff -NurpP --minimal linux-2.6.32.6/net/ipv6/tcp_ipv6.c linux-2.6.32.6-vs2.3.0.36.28/net/ipv6/tcp_ipv6.c
28176 --- linux-2.6.32.6/net/ipv6/tcp_ipv6.c  2009-12-03 20:03:00.000000000 +0100
28177 +++ linux-2.6.32.6-vs2.3.0.36.28/net/ipv6/tcp_ipv6.c    2009-12-03 20:04:56.000000000 +0100
28178 @@ -68,6 +68,7 @@
28179  
28180  #include <linux/crypto.h>
28181  #include <linux/scatterlist.h>
28182 +#include <linux/vs_inet6.h>
28183  
28184  static void    tcp_v6_send_reset(struct sock *sk, struct sk_buff *skb);
28185  static void    tcp_v6_reqsk_send_ack(struct sock *sk, struct sk_buff *skb,
28186 @@ -156,8 +157,15 @@ static int tcp_v6_connect(struct sock *s
28187          *      connect() to INADDR_ANY means loopback (BSD'ism).
28188          */
28189  
28190 -       if(ipv6_addr_any(&usin->sin6_addr))
28191 -               usin->sin6_addr.s6_addr[15] = 0x1;
28192 +       if(ipv6_addr_any(&usin->sin6_addr)) {
28193 +               struct nx_info *nxi =  sk->sk_nx_info;
28194 +
28195 +               if (nxi && nx_info_has_v6(nxi))
28196 +                       /* FIXME: remap lback? */
28197 +                       usin->sin6_addr = nxi->v6.ip;
28198 +               else
28199 +                       usin->sin6_addr.s6_addr[15] = 0x1;
28200 +       }
28201  
28202         addr_type = ipv6_addr_type(&usin->sin6_addr);
28203  
28204 diff -NurpP --minimal linux-2.6.32.6/net/ipv6/udp.c linux-2.6.32.6-vs2.3.0.36.28/net/ipv6/udp.c
28205 --- linux-2.6.32.6/net/ipv6/udp.c       2009-12-03 20:03:00.000000000 +0100
28206 +++ linux-2.6.32.6-vs2.3.0.36.28/net/ipv6/udp.c 2009-12-03 20:04:56.000000000 +0100
28207 @@ -47,6 +47,7 @@
28208  
28209  #include <linux/proc_fs.h>
28210  #include <linux/seq_file.h>
28211 +#include <linux/vs_inet6.h>
28212  #include "udp_impl.h"
28213  
28214  int ipv6_rcv_saddr_equal(const struct sock *sk, const struct sock *sk2)
28215 @@ -61,24 +62,49 @@ int ipv6_rcv_saddr_equal(const struct so
28216         int addr_type2 = sk2_rcv_saddr6 ? ipv6_addr_type(sk2_rcv_saddr6) : IPV6_ADDR_MAPPED;
28217  
28218         /* if both are mapped, treat as IPv4 */
28219 -       if (addr_type == IPV6_ADDR_MAPPED && addr_type2 == IPV6_ADDR_MAPPED)
28220 -               return (!sk2_ipv6only &&
28221 +       if (addr_type == IPV6_ADDR_MAPPED && addr_type2 == IPV6_ADDR_MAPPED) {
28222 +               if (!sk2_ipv6only &&
28223                         (!sk_rcv_saddr || !sk2_rcv_saddr ||
28224 -                         sk_rcv_saddr == sk2_rcv_saddr));
28225 +                         sk_rcv_saddr == sk2_rcv_saddr))
28226 +                       goto vs_v4;
28227 +               else
28228 +                       return 0;
28229 +       }
28230  
28231         if (addr_type2 == IPV6_ADDR_ANY &&
28232             !(sk2_ipv6only && addr_type == IPV6_ADDR_MAPPED))
28233 -               return 1;
28234 +               goto vs;
28235  
28236         if (addr_type == IPV6_ADDR_ANY &&
28237             !(sk_ipv6only && addr_type2 == IPV6_ADDR_MAPPED))
28238 -               return 1;
28239 +               goto vs;
28240  
28241         if (sk2_rcv_saddr6 &&
28242             ipv6_addr_equal(sk_rcv_saddr6, sk2_rcv_saddr6))
28243 -               return 1;
28244 +               goto vs;
28245  
28246         return 0;
28247 +
28248 +vs_v4:
28249 +       if (!sk_rcv_saddr && !sk2_rcv_saddr)
28250 +               return nx_v4_addr_conflict(sk->sk_nx_info, sk2->sk_nx_info);
28251 +       if (!sk2_rcv_saddr)
28252 +               return v4_addr_in_nx_info(sk->sk_nx_info, sk2_rcv_saddr, -1);
28253 +       if (!sk_rcv_saddr)
28254 +               return v4_addr_in_nx_info(sk2->sk_nx_info, sk_rcv_saddr, -1);
28255 +       return 1;
28256 +vs:
28257 +       if (addr_type2 == IPV6_ADDR_ANY && addr_type == IPV6_ADDR_ANY)
28258 +               return nx_v6_addr_conflict(sk->sk_nx_info, sk2->sk_nx_info);
28259 +       else if (addr_type2 == IPV6_ADDR_ANY)
28260 +               return v6_addr_in_nx_info(sk2->sk_nx_info, sk_rcv_saddr6, -1);
28261 +       else if (addr_type == IPV6_ADDR_ANY) {
28262 +               if (addr_type2 == IPV6_ADDR_MAPPED)
28263 +                       return nx_v4_addr_conflict(sk->sk_nx_info, sk2->sk_nx_info);
28264 +               else
28265 +                       return v6_addr_in_nx_info(sk->sk_nx_info, sk2_rcv_saddr6, -1);
28266 +       }
28267 +       return 1;
28268  }
28269  
28270  int udp_v6_get_port(struct sock *sk, unsigned short snum)
28271 @@ -109,6 +135,10 @@ static inline int compute_score(struct s
28272                         if (!ipv6_addr_equal(&np->rcv_saddr, daddr))
28273                                 return -1;
28274                         score++;
28275 +               } else {
28276 +                       /* block non nx_info ips */
28277 +                       if (!v6_addr_in_nx_info(sk->sk_nx_info, daddr, -1))
28278 +                               return -1;
28279                 }
28280                 if (!ipv6_addr_any(&np->daddr)) {
28281                         if (!ipv6_addr_equal(&np->daddr, saddr))
28282 diff -NurpP --minimal linux-2.6.32.6/net/ipv6/xfrm6_policy.c linux-2.6.32.6-vs2.3.0.36.28/net/ipv6/xfrm6_policy.c
28283 --- linux-2.6.32.6/net/ipv6/xfrm6_policy.c      2009-12-03 20:03:00.000000000 +0100
28284 +++ linux-2.6.32.6-vs2.3.0.36.28/net/ipv6/xfrm6_policy.c        2009-12-03 20:04:56.000000000 +0100
28285 @@ -63,7 +63,7 @@ static int xfrm6_get_saddr(struct net *n
28286         dev = ip6_dst_idev(dst)->dev;
28287         ipv6_dev_get_saddr(dev_net(dev), dev,
28288                            (struct in6_addr *)&daddr->a6, 0,
28289 -                          (struct in6_addr *)&saddr->a6);
28290 +                          (struct in6_addr *)&saddr->a6, NULL);
28291         dst_release(dst);
28292         return 0;
28293  }
28294 diff -NurpP --minimal linux-2.6.32.6/net/netlink/af_netlink.c linux-2.6.32.6-vs2.3.0.36.28/net/netlink/af_netlink.c
28295 --- linux-2.6.32.6/net/netlink/af_netlink.c     2009-12-03 20:03:01.000000000 +0100
28296 +++ linux-2.6.32.6-vs2.3.0.36.28/net/netlink/af_netlink.c       2009-12-03 20:04:56.000000000 +0100
28297 @@ -55,6 +55,9 @@
28298  #include <linux/types.h>
28299  #include <linux/audit.h>
28300  #include <linux/mutex.h>
28301 +#include <linux/vs_context.h>
28302 +#include <linux/vs_network.h>
28303 +#include <linux/vs_limit.h>
28304  
28305  #include <net/net_namespace.h>
28306  #include <net/sock.h>
28307 @@ -1899,6 +1902,8 @@ static struct sock *netlink_seq_socket_i
28308                         sk_for_each(s, node, &hash->table[j]) {
28309                                 if (sock_net(s) != seq_file_net(seq))
28310                                         continue;
28311 +                               if (!nx_check(s->sk_nid, VS_WATCH_P | VS_IDENT))
28312 +                                       continue;
28313                                 if (off == pos) {
28314                                         iter->link = i;
28315                                         iter->hash_idx = j;
28316 @@ -1933,7 +1938,8 @@ static void *netlink_seq_next(struct seq
28317         s = v;
28318         do {
28319                 s = sk_next(s);
28320 -       } while (s && sock_net(s) != seq_file_net(seq));
28321 +       } while (s && (sock_net(s) != seq_file_net(seq) ||
28322 +               !nx_check(s->sk_nid, VS_WATCH_P | VS_IDENT)));
28323         if (s)
28324                 return s;
28325  
28326 @@ -1945,7 +1951,8 @@ static void *netlink_seq_next(struct seq
28327  
28328                 for (; j <= hash->mask; j++) {
28329                         s = sk_head(&hash->table[j]);
28330 -                       while (s && sock_net(s) != seq_file_net(seq))
28331 +                       while (s && (sock_net(s) != seq_file_net(seq) ||
28332 +                               !nx_check(s->sk_nid, VS_WATCH_P | VS_IDENT)))
28333                                 s = sk_next(s);
28334                         if (s) {
28335                                 iter->link = i;
28336 diff -NurpP --minimal linux-2.6.32.6/net/sctp/ipv6.c linux-2.6.32.6-vs2.3.0.36.28/net/sctp/ipv6.c
28337 --- linux-2.6.32.6/net/sctp/ipv6.c      2009-12-03 20:03:01.000000000 +0100
28338 +++ linux-2.6.32.6-vs2.3.0.36.28/net/sctp/ipv6.c        2009-12-03 20:04:56.000000000 +0100
28339 @@ -316,7 +316,8 @@ static void sctp_v6_get_saddr(struct sct
28340                                    dst ? ip6_dst_idev(dst)->dev : NULL,
28341                                    &daddr->v6.sin6_addr,
28342                                    inet6_sk(&sk->inet.sk)->srcprefs,
28343 -                                  &saddr->v6.sin6_addr);
28344 +                                  &saddr->v6.sin6_addr,
28345 +                                  asoc->base.sk->sk_nx_info);
28346                 SCTP_DEBUG_PRINTK("saddr from ipv6_get_saddr: %pI6\n",
28347                                   &saddr->v6.sin6_addr);
28348                 return;
28349 diff -NurpP --minimal linux-2.6.32.6/net/socket.c linux-2.6.32.6-vs2.3.0.36.28/net/socket.c
28350 --- linux-2.6.32.6/net/socket.c 2009-12-03 20:03:01.000000000 +0100
28351 +++ linux-2.6.32.6-vs2.3.0.36.28/net/socket.c   2009-12-03 20:04:56.000000000 +0100
28352 @@ -96,6 +96,10 @@
28353  
28354  #include <net/sock.h>
28355  #include <linux/netfilter.h>
28356 +#include <linux/vs_base.h>
28357 +#include <linux/vs_socket.h>
28358 +#include <linux/vs_inet.h>
28359 +#include <linux/vs_inet6.h>
28360  
28361  static int sock_no_open(struct inode *irrelevant, struct file *dontcare);
28362  static ssize_t sock_aio_read(struct kiocb *iocb, const struct iovec *iov,
28363 @@ -559,7 +563,7 @@ static inline int __sock_sendmsg(struct 
28364                                  struct msghdr *msg, size_t size)
28365  {
28366         struct sock_iocb *si = kiocb_to_siocb(iocb);
28367 -       int err;
28368 +       int err, len;
28369  
28370         si->sock = sock;
28371         si->scm = NULL;
28372 @@ -570,7 +574,22 @@ static inline int __sock_sendmsg(struct 
28373         if (err)
28374                 return err;
28375  
28376 -       return sock->ops->sendmsg(iocb, sock, msg, size);
28377 +       len = sock->ops->sendmsg(iocb, sock, msg, size);
28378 +       if (sock->sk) {
28379 +               if (len == size)
28380 +                       vx_sock_send(sock->sk, size);
28381 +               else
28382 +                       vx_sock_fail(sock->sk, size);
28383 +       }
28384 +       vxdprintk(VXD_CBIT(net, 7),
28385 +               "__sock_sendmsg: %p[%p,%p,%p;%d/%d]:%d/%d",
28386 +               sock, sock->sk,
28387 +               (sock->sk)?sock->sk->sk_nx_info:0,
28388 +               (sock->sk)?sock->sk->sk_vx_info:0,
28389 +               (sock->sk)?sock->sk->sk_xid:0,
28390 +               (sock->sk)?sock->sk->sk_nid:0,
28391 +               (unsigned int)size, len);
28392 +       return len;
28393  }
28394  
28395  int sock_sendmsg(struct socket *sock, struct msghdr *msg, size_t size)
28396 @@ -671,7 +690,7 @@ EXPORT_SYMBOL_GPL(__sock_recv_timestamp)
28397  static inline int __sock_recvmsg(struct kiocb *iocb, struct socket *sock,
28398                                  struct msghdr *msg, size_t size, int flags)
28399  {
28400 -       int err;
28401 +       int err, len;
28402         struct sock_iocb *si = kiocb_to_siocb(iocb);
28403  
28404         si->sock = sock;
28405 @@ -684,7 +703,18 @@ static inline int __sock_recvmsg(struct 
28406         if (err)
28407                 return err;
28408  
28409 -       return sock->ops->recvmsg(iocb, sock, msg, size, flags);
28410 +       len = sock->ops->recvmsg(iocb, sock, msg, size, flags);
28411 +       if ((len >= 0) && sock->sk)
28412 +               vx_sock_recv(sock->sk, len);
28413 +       vxdprintk(VXD_CBIT(net, 7),
28414 +               "__sock_recvmsg: %p[%p,%p,%p;%d/%d]:%d/%d",
28415 +               sock, sock->sk,
28416 +               (sock->sk)?sock->sk->sk_nx_info:0,
28417 +               (sock->sk)?sock->sk->sk_vx_info:0,
28418 +               (sock->sk)?sock->sk->sk_xid:0,
28419 +               (sock->sk)?sock->sk->sk_nid:0,
28420 +               (unsigned int)size, len);
28421 +       return len;
28422  }
28423  
28424  int sock_recvmsg(struct socket *sock, struct msghdr *msg,
28425 @@ -1155,6 +1185,13 @@ static int __sock_create(struct net *net
28426         if (type < 0 || type >= SOCK_MAX)
28427                 return -EINVAL;
28428  
28429 +       if (!nx_check(0, VS_ADMIN)) {
28430 +               if (family == PF_INET && !current_nx_info_has_v4())
28431 +                       return -EAFNOSUPPORT;
28432 +               if (family == PF_INET6 && !current_nx_info_has_v6())
28433 +                       return -EAFNOSUPPORT;
28434 +       }
28435 +
28436         /* Compatibility.
28437  
28438            This uglymoron is moved from INET layer to here to avoid
28439 @@ -1287,6 +1324,7 @@ SYSCALL_DEFINE3(socket, int, family, int
28440         if (retval < 0)
28441                 goto out;
28442  
28443 +       set_bit(SOCK_USER_SOCKET, &sock->flags);
28444         retval = sock_map_fd(sock, flags & (O_CLOEXEC | O_NONBLOCK));
28445         if (retval < 0)
28446                 goto out_release;
28447 @@ -1328,10 +1366,12 @@ SYSCALL_DEFINE4(socketpair, int, family,
28448         err = sock_create(family, type, protocol, &sock1);
28449         if (err < 0)
28450                 goto out;
28451 +       set_bit(SOCK_USER_SOCKET, &sock1->flags);
28452  
28453         err = sock_create(family, type, protocol, &sock2);
28454         if (err < 0)
28455                 goto out_release_1;
28456 +       set_bit(SOCK_USER_SOCKET, &sock2->flags);
28457  
28458         err = sock1->ops->socketpair(sock1, sock2);
28459         if (err < 0)
28460 diff -NurpP --minimal linux-2.6.32.6/net/sunrpc/auth.c linux-2.6.32.6-vs2.3.0.36.28/net/sunrpc/auth.c
28461 --- linux-2.6.32.6/net/sunrpc/auth.c    2009-12-03 20:03:01.000000000 +0100
28462 +++ linux-2.6.32.6-vs2.3.0.36.28/net/sunrpc/auth.c      2009-12-03 20:04:56.000000000 +0100
28463 @@ -14,6 +14,7 @@
28464  #include <linux/hash.h>
28465  #include <linux/sunrpc/clnt.h>
28466  #include <linux/spinlock.h>
28467 +#include <linux/vs_tag.h>
28468  
28469  #ifdef RPC_DEBUG
28470  # define RPCDBG_FACILITY       RPCDBG_AUTH
28471 @@ -360,6 +361,7 @@ rpcauth_lookupcred(struct rpc_auth *auth
28472         memset(&acred, 0, sizeof(acred));
28473         acred.uid = cred->fsuid;
28474         acred.gid = cred->fsgid;
28475 +       acred.tag = dx_current_tag();
28476         acred.group_info = get_group_info(((struct cred *)cred)->group_info);
28477  
28478         ret = auth->au_ops->lookup_cred(auth, &acred, flags);
28479 @@ -400,6 +402,7 @@ rpcauth_bind_root_cred(struct rpc_task *
28480         struct auth_cred acred = {
28481                 .uid = 0,
28482                 .gid = 0,
28483 +               .tag = dx_current_tag(),
28484         };
28485         struct rpc_cred *ret;
28486  
28487 diff -NurpP --minimal linux-2.6.32.6/net/sunrpc/auth_unix.c linux-2.6.32.6-vs2.3.0.36.28/net/sunrpc/auth_unix.c
28488 --- linux-2.6.32.6/net/sunrpc/auth_unix.c       2008-12-25 00:26:37.000000000 +0100
28489 +++ linux-2.6.32.6-vs2.3.0.36.28/net/sunrpc/auth_unix.c 2009-12-03 20:04:56.000000000 +0100
28490 @@ -11,12 +11,14 @@
28491  #include <linux/module.h>
28492  #include <linux/sunrpc/clnt.h>
28493  #include <linux/sunrpc/auth.h>
28494 +#include <linux/vs_tag.h>
28495  
28496  #define NFS_NGROUPS    16
28497  
28498  struct unx_cred {
28499         struct rpc_cred         uc_base;
28500         gid_t                   uc_gid;
28501 +       tag_t                   uc_tag;
28502         gid_t                   uc_gids[NFS_NGROUPS];
28503  };
28504  #define uc_uid                 uc_base.cr_uid
28505 @@ -78,6 +80,7 @@ unx_create_cred(struct rpc_auth *auth, s
28506                 groups = NFS_NGROUPS;
28507  
28508         cred->uc_gid = acred->gid;
28509 +       cred->uc_tag = acred->tag;
28510         for (i = 0; i < groups; i++)
28511                 cred->uc_gids[i] = GROUP_AT(acred->group_info, i);
28512         if (i < NFS_NGROUPS)
28513 @@ -119,7 +122,9 @@ unx_match(struct auth_cred *acred, struc
28514         unsigned int i;
28515  
28516  
28517 -       if (cred->uc_uid != acred->uid || cred->uc_gid != acred->gid)
28518 +       if (cred->uc_uid != acred->uid ||
28519 +               cred->uc_gid != acred->gid ||
28520 +               cred->uc_tag != acred->tag)
28521                 return 0;
28522  
28523         if (acred->group_info != NULL)
28524 @@ -142,7 +147,7 @@ unx_marshal(struct rpc_task *task, __be3
28525         struct rpc_clnt *clnt = task->tk_client;
28526         struct unx_cred *cred = container_of(task->tk_msg.rpc_cred, struct unx_cred, uc_base);
28527         __be32          *base, *hold;
28528 -       int             i;
28529 +       int             i, tag;
28530  
28531         *p++ = htonl(RPC_AUTH_UNIX);
28532         base = p++;
28533 @@ -152,9 +157,12 @@ unx_marshal(struct rpc_task *task, __be3
28534          * Copy the UTS nodename captured when the client was created.
28535          */
28536         p = xdr_encode_array(p, clnt->cl_nodename, clnt->cl_nodelen);
28537 +       tag = task->tk_client->cl_tag;
28538  
28539 -       *p++ = htonl((u32) cred->uc_uid);
28540 -       *p++ = htonl((u32) cred->uc_gid);
28541 +       *p++ = htonl((u32) TAGINO_UID(tag,
28542 +               cred->uc_uid, cred->uc_tag));
28543 +       *p++ = htonl((u32) TAGINO_GID(tag,
28544 +               cred->uc_gid, cred->uc_tag));
28545         hold = p++;
28546         for (i = 0; i < 16 && cred->uc_gids[i] != (gid_t) NOGROUP; i++)
28547                 *p++ = htonl((u32) cred->uc_gids[i]);
28548 diff -NurpP --minimal linux-2.6.32.6/net/sunrpc/clnt.c linux-2.6.32.6-vs2.3.0.36.28/net/sunrpc/clnt.c
28549 --- linux-2.6.32.6/net/sunrpc/clnt.c    2009-12-03 20:03:01.000000000 +0100
28550 +++ linux-2.6.32.6-vs2.3.0.36.28/net/sunrpc/clnt.c      2009-12-03 20:04:56.000000000 +0100
28551 @@ -33,6 +33,7 @@
28552  #include <linux/utsname.h>
28553  #include <linux/workqueue.h>
28554  #include <linux/in6.h>
28555 +#include <linux/vs_cvirt.h>
28556  
28557  #include <linux/sunrpc/clnt.h>
28558  #include <linux/sunrpc/rpc_pipe_fs.h>
28559 @@ -358,6 +359,9 @@ struct rpc_clnt *rpc_create(struct rpc_c
28560         if (!(args->flags & RPC_CLNT_CREATE_QUIET))
28561                 clnt->cl_chatty = 1;
28562  
28563 +       /* TODO: handle RPC_CLNT_CREATE_TAGGED
28564 +       if (args->flags & RPC_CLNT_CREATE_TAGGED)
28565 +               clnt->cl_tag = 1; */
28566         return clnt;
28567  }
28568  EXPORT_SYMBOL_GPL(rpc_create);
28569 diff -NurpP --minimal linux-2.6.32.6/net/unix/af_unix.c linux-2.6.32.6-vs2.3.0.36.28/net/unix/af_unix.c
28570 --- linux-2.6.32.6/net/unix/af_unix.c   2009-12-03 20:03:01.000000000 +0100
28571 +++ linux-2.6.32.6-vs2.3.0.36.28/net/unix/af_unix.c     2009-12-03 20:04:56.000000000 +0100
28572 @@ -114,6 +114,8 @@
28573  #include <linux/mount.h>
28574  #include <net/checksum.h>
28575  #include <linux/security.h>
28576 +#include <linux/vs_context.h>
28577 +#include <linux/vs_limit.h>
28578  
28579  static struct hlist_head unix_socket_table[UNIX_HASH_SIZE + 1];
28580  static DEFINE_SPINLOCK(unix_table_lock);
28581 @@ -258,6 +260,8 @@ static struct sock *__unix_find_socket_b
28582                 if (!net_eq(sock_net(s), net))
28583                         continue;
28584  
28585 +               if (!nx_check(s->sk_nid, VS_WATCH_P | VS_IDENT))
28586 +                       continue;
28587                 if (u->addr->len == len &&
28588                     !memcmp(u->addr->name, sunname, len))
28589                         goto found;
28590 @@ -2114,6 +2118,8 @@ static struct sock *unix_seq_idx(struct 
28591         for (s = first_unix_socket(&iter->i); s; s = next_unix_socket(&iter->i, s)) {
28592                 if (sock_net(s) != seq_file_net(seq))
28593                         continue;
28594 +               if (!nx_check(s->sk_nid, VS_WATCH_P | VS_IDENT))
28595 +                       continue;
28596                 if (off == pos)
28597                         return s;
28598                 ++off;
28599 @@ -2138,7 +2144,8 @@ static void *unix_seq_next(struct seq_fi
28600                 sk = first_unix_socket(&iter->i);
28601         else
28602                 sk = next_unix_socket(&iter->i, sk);
28603 -       while (sk && (sock_net(sk) != seq_file_net(seq)))
28604 +       while (sk && (sock_net(sk) != seq_file_net(seq) ||
28605 +               !nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT)))
28606                 sk = next_unix_socket(&iter->i, sk);
28607         return sk;
28608  }
28609 diff -NurpP --minimal linux-2.6.32.6/net/x25/af_x25.c linux-2.6.32.6-vs2.3.0.36.28/net/x25/af_x25.c
28610 --- linux-2.6.32.6/net/x25/af_x25.c     2009-12-03 20:03:01.000000000 +0100
28611 +++ linux-2.6.32.6-vs2.3.0.36.28/net/x25/af_x25.c       2009-12-03 20:04:56.000000000 +0100
28612 @@ -519,7 +519,10 @@ static int x25_create(struct net *net, s
28613  
28614         x25 = x25_sk(sk);
28615  
28616 -       sock_init_data(sock, sk);
28617 +       sk->sk_socket = sock;
28618 +       sk->sk_type = sock->type;
28619 +       sk->sk_sleep = &sock->wait;
28620 +       sock->sk = sk;
28621  
28622         x25_init_timers(sk);
28623  
28624 diff -NurpP --minimal linux-2.6.32.6/scripts/checksyscalls.sh linux-2.6.32.6-vs2.3.0.36.28/scripts/checksyscalls.sh
28625 --- linux-2.6.32.6/scripts/checksyscalls.sh     2009-09-10 15:26:31.000000000 +0200
28626 +++ linux-2.6.32.6-vs2.3.0.36.28/scripts/checksyscalls.sh       2009-12-03 20:04:56.000000000 +0100
28627 @@ -194,7 +194,6 @@ cat << EOF
28628  #define __IGNORE_afs_syscall
28629  #define __IGNORE_getpmsg
28630  #define __IGNORE_putpmsg
28631 -#define __IGNORE_vserver
28632  EOF
28633  }
28634  
28635 diff -NurpP --minimal linux-2.6.32.6/security/commoncap.c linux-2.6.32.6-vs2.3.0.36.28/security/commoncap.c
28636 --- linux-2.6.32.6/security/commoncap.c 2009-12-03 20:03:02.000000000 +0100
28637 +++ linux-2.6.32.6-vs2.3.0.36.28/security/commoncap.c   2009-12-03 20:04:56.000000000 +0100
28638 @@ -27,6 +27,7 @@
28639  #include <linux/sched.h>
28640  #include <linux/prctl.h>
28641  #include <linux/securebits.h>
28642 +#include <linux/vs_context.h>
28643  
28644  /*
28645   * If a non-root user executes a setuid-root binary in
28646 @@ -52,7 +53,7 @@ static void warn_setuid_and_fcaps_mixed(
28647  
28648  int cap_netlink_send(struct sock *sk, struct sk_buff *skb)
28649  {
28650 -       NETLINK_CB(skb).eff_cap = current_cap();
28651 +       NETLINK_CB(skb).eff_cap = vx_mbcaps(current_cap());
28652         return 0;
28653  }
28654  
28655 @@ -62,6 +63,7 @@ int cap_netlink_recv(struct sk_buff *skb
28656                 return -EPERM;
28657         return 0;
28658  }
28659 +
28660  EXPORT_SYMBOL(cap_netlink_recv);
28661  
28662  /**
28663 @@ -82,7 +84,22 @@ EXPORT_SYMBOL(cap_netlink_recv);
28664  int cap_capable(struct task_struct *tsk, const struct cred *cred, int cap,
28665                 int audit)
28666  {
28667 -       return cap_raised(cred->cap_effective, cap) ? 0 : -EPERM;
28668 +       struct vx_info *vxi = tsk->vx_info;
28669 +
28670 +#if 0
28671 +       printk("cap_capable() VXF_STATE_SETUP = %llx, raised = %x, eff = %08x:%08x\n",
28672 +               vx_info_flags(vxi, VXF_STATE_SETUP, 0),
28673 +               cap_raised(tsk->cap_effective, cap),
28674 +               tsk->cap_effective.cap[1], tsk->cap_effective.cap[0]);
28675 +#endif
28676 +
28677 +       /* special case SETUP */
28678 +       if (vx_info_flags(vxi, VXF_STATE_SETUP, 0) &&
28679 +               /* FIXME: maybe use cred instead? */
28680 +               cap_raised(tsk->cred->cap_effective, cap))
28681 +               return 0;
28682 +
28683 +       return vx_cap_raised(vxi, cred->cap_effective, cap) ? 0 : -EPERM;
28684  }
28685  
28686  /**
28687 @@ -618,7 +635,7 @@ int cap_inode_setxattr(struct dentry *de
28688  
28689         if (!strncmp(name, XATTR_SECURITY_PREFIX,
28690                      sizeof(XATTR_SECURITY_PREFIX) - 1)  &&
28691 -           !capable(CAP_SYS_ADMIN))
28692 +               !vx_capable(CAP_SYS_ADMIN, VXC_FS_SECURITY))
28693                 return -EPERM;
28694         return 0;
28695  }
28696 @@ -962,7 +979,8 @@ error:
28697   */
28698  int cap_syslog(int type)
28699  {
28700 -       if ((type != 3 && type != 10) && !capable(CAP_SYS_ADMIN))
28701 +       if ((type != 3 && type != 10) &&
28702 +               !vx_capable(CAP_SYS_ADMIN, VXC_SYSLOG))
28703                 return -EPERM;
28704         return 0;
28705  }
28706 @@ -1014,3 +1032,4 @@ int cap_file_mmap(struct file *file, uns
28707         }
28708         return ret;
28709  }
28710 +
28711 diff -NurpP --minimal linux-2.6.32.6/security/selinux/hooks.c linux-2.6.32.6-vs2.3.0.36.28/security/selinux/hooks.c
28712 --- linux-2.6.32.6/security/selinux/hooks.c     2009-12-03 20:03:02.000000000 +0100
28713 +++ linux-2.6.32.6-vs2.3.0.36.28/security/selinux/hooks.c       2009-12-03 20:04:56.000000000 +0100
28714 @@ -64,7 +64,6 @@
28715  #include <linux/dccp.h>
28716  #include <linux/quota.h>
28717  #include <linux/un.h>          /* for Unix socket types */
28718 -#include <net/af_unix.h>       /* for Unix socket types */
28719  #include <linux/parser.h>
28720  #include <linux/nfs_mount.h>
28721  #include <net/ipv6.h>
28722 diff -NurpP --minimal linux-2.6.32.6/security/selinux/include/av_permissions.h linux-2.6.32.6-vs2.3.0.36.28/security/selinux/include/av_permissions.h
28723 --- linux-2.6.32.6/security/selinux/include/av_permissions.h    2009-12-03 20:03:02.000000000 +0100
28724 +++ linux-2.6.32.6-vs2.3.0.36.28/security/selinux/include/av_permissions.h      2009-12-03 20:04:56.000000000 +0100
28725 @@ -565,6 +565,7 @@
28726  #define CAPABILITY__SETFCAP                       0x80000000UL
28727  #define CAPABILITY2__MAC_OVERRIDE                 0x00000001UL
28728  #define CAPABILITY2__MAC_ADMIN                    0x00000002UL
28729 +#define CAPABILITY2__CONTEXT                      0x00000004UL
28730  #define NETLINK_ROUTE_SOCKET__IOCTL               0x00000001UL
28731  #define NETLINK_ROUTE_SOCKET__READ                0x00000002UL
28732  #define NETLINK_ROUTE_SOCKET__WRITE               0x00000004UL
28733 diff -NurpP --minimal linux-2.6.32.6/security/selinux/include/av_perm_to_string.h linux-2.6.32.6-vs2.3.0.36.28/security/selinux/include/av_perm_to_string.h
28734 --- linux-2.6.32.6/security/selinux/include/av_perm_to_string.h 2009-12-03 20:03:02.000000000 +0100
28735 +++ linux-2.6.32.6-vs2.3.0.36.28/security/selinux/include/av_perm_to_string.h   2009-12-03 20:04:56.000000000 +0100
28736 @@ -142,6 +142,7 @@
28737     S_(SECCLASS_CAPABILITY, CAPABILITY__SETFCAP, "setfcap")
28738     S_(SECCLASS_CAPABILITY2, CAPABILITY2__MAC_OVERRIDE, "mac_override")
28739     S_(SECCLASS_CAPABILITY2, CAPABILITY2__MAC_ADMIN, "mac_admin")
28740 +   S_(SECCLASS_CAPABILITY2, CAPABILITY2__CONTEXT, "context")
28741     S_(SECCLASS_NETLINK_ROUTE_SOCKET, NETLINK_ROUTE_SOCKET__NLMSG_READ, "nlmsg_read")
28742     S_(SECCLASS_NETLINK_ROUTE_SOCKET, NETLINK_ROUTE_SOCKET__NLMSG_WRITE, "nlmsg_write")
28743     S_(SECCLASS_NETLINK_FIREWALL_SOCKET, NETLINK_FIREWALL_SOCKET__NLMSG_READ, "nlmsg_read")
This page took 2.706172 seconds and 4 git commands to generate.