]> git.pld-linux.org Git - packages/kernel.git/blob - kernel-vserver-2.3.patch
- package modules.order, empty other ghost files (12.2k in size)
[packages/kernel.git] / kernel-vserver-2.3.patch
1 diff -NurpP --minimal linux-2.6.32.1/arch/alpha/Kconfig linux-2.6.32.1-vs2.3.0.36.27/arch/alpha/Kconfig
2 --- linux-2.6.32.1/arch/alpha/Kconfig   2009-12-03 20:01:49.000000000 +0100
3 +++ linux-2.6.32.1-vs2.3.0.36.27/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.1/arch/alpha/kernel/entry.S linux-2.6.32.1-vs2.3.0.36.27/arch/alpha/kernel/entry.S
14 --- linux-2.6.32.1/arch/alpha/kernel/entry.S    2009-06-11 17:11:46.000000000 +0200
15 +++ linux-2.6.32.1-vs2.3.0.36.27/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.1/arch/alpha/kernel/osf_sys.c linux-2.6.32.1-vs2.3.0.36.27/arch/alpha/kernel/osf_sys.c
49 --- linux-2.6.32.1/arch/alpha/kernel/osf_sys.c  2009-09-10 15:25:14.000000000 +0200
50 +++ linux-2.6.32.1-vs2.3.0.36.27/arch/alpha/kernel/osf_sys.c    2009-12-03 20:04:56.000000000 +0100
51 @@ -872,7 +872,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.1/arch/alpha/kernel/ptrace.c linux-2.6.32.1-vs2.3.0.36.27/arch/alpha/kernel/ptrace.c
61 --- linux-2.6.32.1/arch/alpha/kernel/ptrace.c   2009-09-10 15:25:14.000000000 +0200
62 +++ linux-2.6.32.1-vs2.3.0.36.27/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.1/arch/alpha/kernel/systbls.S linux-2.6.32.1-vs2.3.0.36.27/arch/alpha/kernel/systbls.S
72 --- linux-2.6.32.1/arch/alpha/kernel/systbls.S  2009-03-24 14:18:08.000000000 +0100
73 +++ linux-2.6.32.1-vs2.3.0.36.27/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.1/arch/alpha/kernel/traps.c linux-2.6.32.1-vs2.3.0.36.27/arch/alpha/kernel/traps.c
84 --- linux-2.6.32.1/arch/alpha/kernel/traps.c    2009-06-11 17:11:46.000000000 +0200
85 +++ linux-2.6.32.1-vs2.3.0.36.27/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.1/arch/alpha/mm/fault.c linux-2.6.32.1-vs2.3.0.36.27/arch/alpha/mm/fault.c
97 --- linux-2.6.32.1/arch/alpha/mm/fault.c        2009-09-10 15:25:14.000000000 +0200
98 +++ linux-2.6.32.1-vs2.3.0.36.27/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.1/arch/arm/Kconfig linux-2.6.32.1-vs2.3.0.36.27/arch/arm/Kconfig
111 --- linux-2.6.32.1/arch/arm/Kconfig     2009-12-03 20:01:49.000000000 +0100
112 +++ linux-2.6.32.1-vs2.3.0.36.27/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.1/arch/arm/kernel/calls.S linux-2.6.32.1-vs2.3.0.36.27/arch/arm/kernel/calls.S
123 --- linux-2.6.32.1/arch/arm/kernel/calls.S      2009-12-03 20:01:50.000000000 +0100
124 +++ linux-2.6.32.1-vs2.3.0.36.27/arch/arm/kernel/calls.S        2009-12-03 20:04:56.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.1/arch/arm/kernel/process.c linux-2.6.32.1-vs2.3.0.36.27/arch/arm/kernel/process.c
135 --- linux-2.6.32.1/arch/arm/kernel/process.c    2009-12-03 20:01:50.000000000 +0100
136 +++ linux-2.6.32.1-vs2.3.0.36.27/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.1/arch/arm/kernel/traps.c linux-2.6.32.1-vs2.3.0.36.27/arch/arm/kernel/traps.c
148 --- linux-2.6.32.1/arch/arm/kernel/traps.c      2009-12-03 20:01:50.000000000 +0100
149 +++ linux-2.6.32.1-vs2.3.0.36.27/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.1/arch/avr32/mm/fault.c linux-2.6.32.1-vs2.3.0.36.27/arch/avr32/mm/fault.c
162 --- linux-2.6.32.1/arch/avr32/mm/fault.c        2009-09-10 15:25:20.000000000 +0200
163 +++ linux-2.6.32.1-vs2.3.0.36.27/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.1/arch/cris/Kconfig linux-2.6.32.1-vs2.3.0.36.27/arch/cris/Kconfig
175 --- linux-2.6.32.1/arch/cris/Kconfig    2009-06-11 17:11:56.000000000 +0200
176 +++ linux-2.6.32.1-vs2.3.0.36.27/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.1/arch/cris/mm/fault.c linux-2.6.32.1-vs2.3.0.36.27/arch/cris/mm/fault.c
187 --- linux-2.6.32.1/arch/cris/mm/fault.c 2009-12-03 20:01:56.000000000 +0100
188 +++ linux-2.6.32.1-vs2.3.0.36.27/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.1/arch/frv/kernel/kernel_thread.S linux-2.6.32.1-vs2.3.0.36.27/arch/frv/kernel/kernel_thread.S
200 --- linux-2.6.32.1/arch/frv/kernel/kernel_thread.S      2008-12-25 00:26:37.000000000 +0100
201 +++ linux-2.6.32.1-vs2.3.0.36.27/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.1/arch/frv/mm/fault.c linux-2.6.32.1-vs2.3.0.36.27/arch/frv/mm/fault.c
212 --- linux-2.6.32.1/arch/frv/mm/fault.c  2009-09-10 15:25:22.000000000 +0200
213 +++ linux-2.6.32.1-vs2.3.0.36.27/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.1/arch/h8300/Kconfig linux-2.6.32.1-vs2.3.0.36.27/arch/h8300/Kconfig
225 --- linux-2.6.32.1/arch/h8300/Kconfig   2009-03-24 14:18:24.000000000 +0100
226 +++ linux-2.6.32.1-vs2.3.0.36.27/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.1/arch/ia64/ia32/ia32_entry.S linux-2.6.32.1-vs2.3.0.36.27/arch/ia64/ia32/ia32_entry.S
237 --- linux-2.6.32.1/arch/ia64/ia32/ia32_entry.S  2009-06-11 17:11:57.000000000 +0200
238 +++ linux-2.6.32.1-vs2.3.0.36.27/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.1/arch/ia64/Kconfig linux-2.6.32.1-vs2.3.0.36.27/arch/ia64/Kconfig
249 --- linux-2.6.32.1/arch/ia64/Kconfig    2009-12-03 20:01:56.000000000 +0100
250 +++ linux-2.6.32.1-vs2.3.0.36.27/arch/ia64/Kconfig      2009-12-03 20:04:56.000000000 +0100
251 @@ -685,6 +685,8 @@ source "fs/Kconfig"
252  
253  source "arch/ia64/Kconfig.debug"
254  
255 +source "kernel/vserver/Kconfig"
256 +
257  source "security/Kconfig"
258  
259  source "crypto/Kconfig"
260 diff -NurpP --minimal linux-2.6.32.1/arch/ia64/kernel/entry.S linux-2.6.32.1-vs2.3.0.36.27/arch/ia64/kernel/entry.S
261 --- linux-2.6.32.1/arch/ia64/kernel/entry.S     2009-09-10 15:25:22.000000000 +0200
262 +++ linux-2.6.32.1-vs2.3.0.36.27/arch/ia64/kernel/entry.S       2009-12-03 20:04:56.000000000 +0100
263 @@ -1753,7 +1753,7 @@ sys_call_table:
264         data8 sys_mq_notify
265         data8 sys_mq_getsetattr
266         data8 sys_kexec_load
267 -       data8 sys_ni_syscall                    // reserved for vserver
268 +       data8 sys_vserver
269         data8 sys_waitid                        // 1270
270         data8 sys_add_key
271         data8 sys_request_key
272 diff -NurpP --minimal linux-2.6.32.1/arch/ia64/kernel/perfmon.c linux-2.6.32.1-vs2.3.0.36.27/arch/ia64/kernel/perfmon.c
273 --- linux-2.6.32.1/arch/ia64/kernel/perfmon.c   2009-09-10 15:25:22.000000000 +0200
274 +++ linux-2.6.32.1-vs2.3.0.36.27/arch/ia64/kernel/perfmon.c     2009-12-03 20:04:56.000000000 +0100
275 @@ -41,6 +41,7 @@
276  #include <linux/rcupdate.h>
277  #include <linux/completion.h>
278  #include <linux/tracehook.h>
279 +#include <linux/vs_memory.h>
280  
281  #include <asm/errno.h>
282  #include <asm/intrinsics.h>
283 @@ -2372,7 +2373,7 @@ pfm_smpl_buffer_alloc(struct task_struct
284          */
285         insert_vm_struct(mm, vma);
286  
287 -       mm->total_vm  += size >> PAGE_SHIFT;
288 +       vx_vmpages_add(mm, size >> PAGE_SHIFT);
289         vm_stat_account(vma->vm_mm, vma->vm_flags, vma->vm_file,
290                                                         vma_pages(vma));
291         up_write(&task->mm->mmap_sem);
292 diff -NurpP --minimal linux-2.6.32.1/arch/ia64/kernel/process.c linux-2.6.32.1-vs2.3.0.36.27/arch/ia64/kernel/process.c
293 --- linux-2.6.32.1/arch/ia64/kernel/process.c   2009-12-03 20:01:56.000000000 +0100
294 +++ linux-2.6.32.1-vs2.3.0.36.27/arch/ia64/kernel/process.c     2009-12-03 20:04:56.000000000 +0100
295 @@ -110,8 +110,8 @@ show_regs (struct pt_regs *regs)
296         unsigned long ip = regs->cr_iip + ia64_psr(regs)->ri;
297  
298         print_modules();
299 -       printk("\nPid: %d, CPU %d, comm: %20s\n", task_pid_nr(current),
300 -                       smp_processor_id(), current->comm);
301 +       printk("\nPid: %d[#%u], CPU %d, comm: %20s\n", task_pid_nr(current),
302 +                       current->xid, smp_processor_id(), current->comm);
303         printk("psr : %016lx ifs : %016lx ip  : [<%016lx>]    %s (%s)\n",
304                regs->cr_ipsr, regs->cr_ifs, ip, print_tainted(),
305                init_utsname()->release);
306 diff -NurpP --minimal linux-2.6.32.1/arch/ia64/kernel/ptrace.c linux-2.6.32.1-vs2.3.0.36.27/arch/ia64/kernel/ptrace.c
307 --- linux-2.6.32.1/arch/ia64/kernel/ptrace.c    2009-09-10 15:25:22.000000000 +0200
308 +++ linux-2.6.32.1-vs2.3.0.36.27/arch/ia64/kernel/ptrace.c      2009-12-03 20:04:56.000000000 +0100
309 @@ -22,6 +22,7 @@
310  #include <linux/regset.h>
311  #include <linux/elf.h>
312  #include <linux/tracehook.h>
313 +#include <linux/vs_base.h>
314  
315  #include <asm/pgtable.h>
316  #include <asm/processor.h>
317 diff -NurpP --minimal linux-2.6.32.1/arch/ia64/kernel/traps.c linux-2.6.32.1-vs2.3.0.36.27/arch/ia64/kernel/traps.c
318 --- linux-2.6.32.1/arch/ia64/kernel/traps.c     2008-12-25 00:26:37.000000000 +0100
319 +++ linux-2.6.32.1-vs2.3.0.36.27/arch/ia64/kernel/traps.c       2009-12-03 20:04:56.000000000 +0100
320 @@ -60,8 +60,9 @@ die (const char *str, struct pt_regs *re
321         put_cpu();
322  
323         if (++die.lock_owner_depth < 3) {
324 -               printk("%s[%d]: %s %ld [%d]\n",
325 -               current->comm, task_pid_nr(current), str, err, ++die_counter);
326 +               printk("%s[%d[#%u]]: %s %ld [%d]\n",
327 +                       current->comm, task_pid_nr(current), current->xid,
328 +                       str, err, ++die_counter);
329                 if (notify_die(DIE_OOPS, str, regs, err, 255, SIGSEGV)
330                     != NOTIFY_STOP)
331                         show_regs(regs);
332 @@ -324,8 +325,9 @@ handle_fpu_swa (int fp_fault, struct pt_
333                         if ((last.count & 15) < 5 && (ia64_fetchadd(1, &last.count, acq) & 15) < 5) {
334                                 last.time = current_jiffies + 5 * HZ;
335                                 printk(KERN_WARNING
336 -                                       "%s(%d): floating-point assist fault at ip %016lx, isr %016lx\n",
337 -                                       current->comm, task_pid_nr(current), regs->cr_iip + ia64_psr(regs)->ri, isr);
338 +                                       "%s(%d[#%u]): floating-point assist fault at ip %016lx, isr %016lx\n",
339 +                                       current->comm, task_pid_nr(current), current->xid,
340 +                                       regs->cr_iip + ia64_psr(regs)->ri, isr);
341                         }
342                 }
343         }
344 diff -NurpP --minimal linux-2.6.32.1/arch/ia64/mm/fault.c linux-2.6.32.1-vs2.3.0.36.27/arch/ia64/mm/fault.c
345 --- linux-2.6.32.1/arch/ia64/mm/fault.c 2009-09-10 15:25:23.000000000 +0200
346 +++ linux-2.6.32.1-vs2.3.0.36.27/arch/ia64/mm/fault.c   2009-12-03 20:04:56.000000000 +0100
347 @@ -10,6 +10,7 @@
348  #include <linux/interrupt.h>
349  #include <linux/kprobes.h>
350  #include <linux/kdebug.h>
351 +#include <linux/vs_memory.h>
352  
353  #include <asm/pgtable.h>
354  #include <asm/processor.h>
355 @@ -281,7 +282,8 @@ ia64_do_page_fault (unsigned long addres
356                 down_read(&mm->mmap_sem);
357                 goto survive;
358         }
359 -       printk(KERN_CRIT "VM: killing process %s\n", current->comm);
360 +       printk(KERN_CRIT "VM: killing process %s(%d:#%u)\n",
361 +               current->comm, task_pid_nr(current), current->xid);
362         if (user_mode(regs))
363                 do_group_exit(SIGKILL);
364         goto no_context;
365 diff -NurpP --minimal linux-2.6.32.1/arch/m32r/kernel/traps.c linux-2.6.32.1-vs2.3.0.36.27/arch/m32r/kernel/traps.c
366 --- linux-2.6.32.1/arch/m32r/kernel/traps.c     2009-12-03 20:01:57.000000000 +0100
367 +++ linux-2.6.32.1-vs2.3.0.36.27/arch/m32r/kernel/traps.c       2009-12-03 20:04:56.000000000 +0100
368 @@ -196,8 +196,9 @@ static void show_registers(struct pt_reg
369         } else {
370                 printk("SPI: %08lx\n", sp);
371         }
372 -       printk("Process %s (pid: %d, process nr: %d, stackpage=%08lx)",
373 -               current->comm, task_pid_nr(current), 0xffff & i, 4096+(unsigned long)current);
374 +       printk("Process %s (pid: %d[#%u], process nr: %d, stackpage=%08lx)",
375 +               current->comm, task_pid_nr(current), current->xid,
376 +               0xffff & i, 4096+(unsigned long)current);
377  
378         /*
379          * When in-kernel, we also print out the stack and code at the
380 diff -NurpP --minimal linux-2.6.32.1/arch/m32r/mm/fault.c linux-2.6.32.1-vs2.3.0.36.27/arch/m32r/mm/fault.c
381 --- linux-2.6.32.1/arch/m32r/mm/fault.c 2009-09-10 15:25:23.000000000 +0200
382 +++ linux-2.6.32.1-vs2.3.0.36.27/arch/m32r/mm/fault.c   2009-12-03 20:04:56.000000000 +0100
383 @@ -276,7 +276,8 @@ out_of_memory:
384                 down_read(&mm->mmap_sem);
385                 goto survive;
386         }
387 -       printk("VM: killing process %s\n", tsk->comm);
388 +       printk("VM: killing process %s(%d:#%u)\n",
389 +               tsk->comm, task_pid_nr(tsk), tsk->xid);
390         if (error_code & ACE_USERMODE)
391                 do_group_exit(SIGKILL);
392         goto no_context;
393 diff -NurpP --minimal linux-2.6.32.1/arch/m68k/Kconfig linux-2.6.32.1-vs2.3.0.36.27/arch/m68k/Kconfig
394 --- linux-2.6.32.1/arch/m68k/Kconfig    2009-12-03 20:01:57.000000000 +0100
395 +++ linux-2.6.32.1-vs2.3.0.36.27/arch/m68k/Kconfig      2009-12-03 20:04:56.000000000 +0100
396 @@ -622,6 +622,8 @@ source "fs/Kconfig"
397  
398  source "arch/m68k/Kconfig.debug"
399  
400 +source "kernel/vserver/Kconfig"
401 +
402  source "security/Kconfig"
403  
404  source "crypto/Kconfig"
405 diff -NurpP --minimal linux-2.6.32.1/arch/m68k/kernel/ptrace.c linux-2.6.32.1-vs2.3.0.36.27/arch/m68k/kernel/ptrace.c
406 --- linux-2.6.32.1/arch/m68k/kernel/ptrace.c    2008-12-25 00:26:37.000000000 +0100
407 +++ linux-2.6.32.1-vs2.3.0.36.27/arch/m68k/kernel/ptrace.c      2009-12-03 20:04:56.000000000 +0100
408 @@ -18,6 +18,7 @@
409  #include <linux/ptrace.h>
410  #include <linux/user.h>
411  #include <linux/signal.h>
412 +#include <linux/vs_base.h>
413  
414  #include <asm/uaccess.h>
415  #include <asm/page.h>
416 @@ -269,6 +270,8 @@ long arch_ptrace(struct task_struct *chi
417                 ret = ptrace_request(child, request, addr, data);
418                 break;
419         }
420 +       if (!vx_check(vx_task_xid(child), VS_WATCH_P | VS_IDENT))
421 +               goto out_tsk;
422  
423         return ret;
424  out_eio:
425 diff -NurpP --minimal linux-2.6.32.1/arch/m68k/kernel/traps.c linux-2.6.32.1-vs2.3.0.36.27/arch/m68k/kernel/traps.c
426 --- linux-2.6.32.1/arch/m68k/kernel/traps.c     2009-09-10 15:25:23.000000000 +0200
427 +++ linux-2.6.32.1-vs2.3.0.36.27/arch/m68k/kernel/traps.c       2009-12-03 20:04:56.000000000 +0100
428 @@ -906,8 +906,8 @@ void show_registers(struct pt_regs *regs
429         printk("d4: %08lx    d5: %08lx    a0: %08lx    a1: %08lx\n",
430                regs->d4, regs->d5, regs->a0, regs->a1);
431  
432 -       printk("Process %s (pid: %d, task=%p)\n",
433 -               current->comm, task_pid_nr(current), current);
434 +       printk("Process %s (pid: %d[#%u], task=%p)\n",
435 +               current->comm, task_pid_nr(current), current->xid, current);
436         addr = (unsigned long)&fp->un;
437         printk("Frame format=%X ", regs->format);
438         switch (regs->format) {
439 diff -NurpP --minimal linux-2.6.32.1/arch/m68k/mm/fault.c linux-2.6.32.1-vs2.3.0.36.27/arch/m68k/mm/fault.c
440 --- linux-2.6.32.1/arch/m68k/mm/fault.c 2009-09-10 15:25:23.000000000 +0200
441 +++ linux-2.6.32.1-vs2.3.0.36.27/arch/m68k/mm/fault.c   2009-12-03 20:04:56.000000000 +0100
442 @@ -186,7 +186,8 @@ out_of_memory:
443                 goto survive;
444         }
445  
446 -       printk("VM: killing process %s\n", current->comm);
447 +       printk("VM: killing process %s(%d:#%u)\n",
448 +               current->comm, task_pid_nr(current), current->xid);
449         if (user_mode(regs))
450                 do_group_exit(SIGKILL);
451  
452 diff -NurpP --minimal linux-2.6.32.1/arch/m68knommu/Kconfig linux-2.6.32.1-vs2.3.0.36.27/arch/m68knommu/Kconfig
453 --- linux-2.6.32.1/arch/m68knommu/Kconfig       2009-12-03 20:01:57.000000000 +0100
454 +++ linux-2.6.32.1-vs2.3.0.36.27/arch/m68knommu/Kconfig 2009-12-03 20:04:56.000000000 +0100
455 @@ -727,6 +727,8 @@ source "fs/Kconfig"
456  
457  source "arch/m68knommu/Kconfig.debug"
458  
459 +source "kernel/vserver/Kconfig"
460 +
461  source "security/Kconfig"
462  
463  source "crypto/Kconfig"
464 diff -NurpP --minimal linux-2.6.32.1/arch/m68knommu/kernel/traps.c linux-2.6.32.1-vs2.3.0.36.27/arch/m68knommu/kernel/traps.c
465 --- linux-2.6.32.1/arch/m68knommu/kernel/traps.c        2009-09-10 15:25:23.000000000 +0200
466 +++ linux-2.6.32.1-vs2.3.0.36.27/arch/m68knommu/kernel/traps.c  2009-12-03 20:04:56.000000000 +0100
467 @@ -78,8 +78,9 @@ void die_if_kernel(char *str, struct pt_
468         printk(KERN_EMERG "d4: %08lx    d5: %08lx    a0: %08lx    a1: %08lx\n",
469                fp->d4, fp->d5, fp->a0, fp->a1);
470  
471 -       printk(KERN_EMERG "Process %s (pid: %d, stackpage=%08lx)\n",
472 -               current->comm, current->pid, PAGE_SIZE+(unsigned long)current);
473 +       printk(KERN_EMERG "Process %s (pid: %d[#%u], stackpage=%08lx)\n",
474 +               current->comm, task_pid_nr(current), current->xid,
475 +               PAGE_SIZE+(unsigned long)current);
476         show_stack(NULL, (unsigned long *)(fp + 1));
477         add_taint(TAINT_DIE);
478         do_exit(SIGSEGV);
479 diff -NurpP --minimal linux-2.6.32.1/arch/microblaze/mm/fault.c linux-2.6.32.1-vs2.3.0.36.27/arch/microblaze/mm/fault.c
480 --- linux-2.6.32.1/arch/microblaze/mm/fault.c   2009-09-10 15:25:24.000000000 +0200
481 +++ linux-2.6.32.1-vs2.3.0.36.27/arch/microblaze/mm/fault.c     2009-12-03 20:04:56.000000000 +0100
482 @@ -279,7 +279,8 @@ out_of_memory:
483                 goto survive;
484         }
485         up_read(&mm->mmap_sem);
486 -       printk(KERN_WARNING "VM: killing process %s\n", current->comm);
487 +       printk(KERN_WARNING "VM: killing process %s(%d:#%u)\n",
488 +               current->comm, task_pid_nr(current), current->xid);
489         if (user_mode(regs))
490                 do_exit(SIGKILL);
491         bad_page_fault(regs, address, SIGKILL);
492 diff -NurpP --minimal linux-2.6.32.1/arch/mips/Kconfig linux-2.6.32.1-vs2.3.0.36.27/arch/mips/Kconfig
493 --- linux-2.6.32.1/arch/mips/Kconfig    2009-12-03 20:01:58.000000000 +0100
494 +++ linux-2.6.32.1-vs2.3.0.36.27/arch/mips/Kconfig      2009-12-03 20:04:56.000000000 +0100
495 @@ -2188,6 +2188,8 @@ source "fs/Kconfig"
496  
497  source "arch/mips/Kconfig.debug"
498  
499 +source "kernel/vserver/Kconfig"
500 +
501  source "security/Kconfig"
502  
503  source "crypto/Kconfig"
504 diff -NurpP --minimal linux-2.6.32.1/arch/mips/kernel/ptrace.c linux-2.6.32.1-vs2.3.0.36.27/arch/mips/kernel/ptrace.c
505 --- linux-2.6.32.1/arch/mips/kernel/ptrace.c    2008-12-25 00:26:37.000000000 +0100
506 +++ linux-2.6.32.1-vs2.3.0.36.27/arch/mips/kernel/ptrace.c      2009-12-03 20:04:56.000000000 +0100
507 @@ -25,6 +25,7 @@
508  #include <linux/security.h>
509  #include <linux/audit.h>
510  #include <linux/seccomp.h>
511 +#include <linux/vs_base.h>
512  
513  #include <asm/byteorder.h>
514  #include <asm/cpu.h>
515 @@ -259,6 +260,9 @@ long arch_ptrace(struct task_struct *chi
516  {
517         int ret;
518  
519 +       if (!vx_check(vx_task_xid(child), VS_WATCH_P | VS_IDENT))
520 +               goto out;
521 +
522         switch (request) {
523         /* when I and D space are separate, these will need to be fixed. */
524         case PTRACE_PEEKTEXT: /* read word at location addr. */
525 diff -NurpP --minimal linux-2.6.32.1/arch/mips/kernel/scall32-o32.S linux-2.6.32.1-vs2.3.0.36.27/arch/mips/kernel/scall32-o32.S
526 --- linux-2.6.32.1/arch/mips/kernel/scall32-o32.S       2009-12-03 20:01:59.000000000 +0100
527 +++ linux-2.6.32.1-vs2.3.0.36.27/arch/mips/kernel/scall32-o32.S 2009-12-03 20:04:56.000000000 +0100
528 @@ -525,7 +525,7 @@ einval:     li      v0, -ENOSYS
529         sys     sys_mq_timedreceive     5
530         sys     sys_mq_notify           2       /* 4275 */
531         sys     sys_mq_getsetattr       3
532 -       sys     sys_ni_syscall          0       /* sys_vserver */
533 +       sys     sys_vserver             3
534         sys     sys_waitid              5
535         sys     sys_ni_syscall          0       /* available, was setaltroot */
536         sys     sys_add_key             5       /* 4280 */
537 diff -NurpP --minimal linux-2.6.32.1/arch/mips/kernel/scall64-64.S linux-2.6.32.1-vs2.3.0.36.27/arch/mips/kernel/scall64-64.S
538 --- linux-2.6.32.1/arch/mips/kernel/scall64-64.S        2009-12-03 20:01:59.000000000 +0100
539 +++ linux-2.6.32.1-vs2.3.0.36.27/arch/mips/kernel/scall64-64.S  2009-12-03 20:04:56.000000000 +0100
540 @@ -362,7 +362,7 @@ sys_call_table:
541         PTR     sys_mq_timedreceive
542         PTR     sys_mq_notify
543         PTR     sys_mq_getsetattr               /* 5235 */
544 -       PTR     sys_ni_syscall                  /* sys_vserver */
545 +       PTR     sys_vserver
546         PTR     sys_waitid
547         PTR     sys_ni_syscall                  /* available, was setaltroot */
548         PTR     sys_add_key
549 diff -NurpP --minimal linux-2.6.32.1/arch/mips/kernel/scall64-n32.S linux-2.6.32.1-vs2.3.0.36.27/arch/mips/kernel/scall64-n32.S
550 --- linux-2.6.32.1/arch/mips/kernel/scall64-n32.S       2009-12-03 20:01:59.000000000 +0100
551 +++ linux-2.6.32.1-vs2.3.0.36.27/arch/mips/kernel/scall64-n32.S 2009-12-03 20:04:56.000000000 +0100
552 @@ -360,7 +360,7 @@ EXPORT(sysn32_call_table)
553         PTR     compat_sys_mq_timedreceive
554         PTR     compat_sys_mq_notify
555         PTR     compat_sys_mq_getsetattr
556 -       PTR     sys_ni_syscall                  /* 6240, sys_vserver */
557 +       PTR     sys32_vserver                   /* 6240 */
558         PTR     compat_sys_waitid
559         PTR     sys_ni_syscall                  /* available, was setaltroot */
560         PTR     sys_add_key
561 diff -NurpP --minimal linux-2.6.32.1/arch/mips/kernel/scall64-o32.S linux-2.6.32.1-vs2.3.0.36.27/arch/mips/kernel/scall64-o32.S
562 --- linux-2.6.32.1/arch/mips/kernel/scall64-o32.S       2009-12-03 20:01:59.000000000 +0100
563 +++ linux-2.6.32.1-vs2.3.0.36.27/arch/mips/kernel/scall64-o32.S 2009-12-03 20:04:56.000000000 +0100
564 @@ -480,7 +480,7 @@ sys_call_table:
565         PTR     compat_sys_mq_timedreceive
566         PTR     compat_sys_mq_notify            /* 4275 */
567         PTR     compat_sys_mq_getsetattr
568 -       PTR     sys_ni_syscall                  /* sys_vserver */
569 +       PTR     sys32_vserver
570         PTR     sys_32_waitid
571         PTR     sys_ni_syscall                  /* available, was setaltroot */
572         PTR     sys_add_key                     /* 4280 */
573 diff -NurpP --minimal linux-2.6.32.1/arch/mips/kernel/traps.c linux-2.6.32.1-vs2.3.0.36.27/arch/mips/kernel/traps.c
574 --- linux-2.6.32.1/arch/mips/kernel/traps.c     2009-12-03 20:01:59.000000000 +0100
575 +++ linux-2.6.32.1-vs2.3.0.36.27/arch/mips/kernel/traps.c       2009-12-03 20:04:56.000000000 +0100
576 @@ -335,9 +335,10 @@ void show_registers(const struct pt_regs
577  
578         __show_regs(regs);
579         print_modules();
580 -       printk("Process %s (pid: %d, threadinfo=%p, task=%p, tls=%0*lx)\n",
581 -              current->comm, current->pid, current_thread_info(), current,
582 -             field, current_thread_info()->tp_value);
583 +       printk("Process %s (pid: %d:#%u, threadinfo=%p, task=%p, tls=%0*lx)\n",
584 +               current->comm, task_pid_nr(current), current->xid,
585 +               current_thread_info(), current,
586 +               field, current_thread_info()->tp_value);
587         if (cpu_has_userlocal) {
588                 unsigned long tls;
589  
590 diff -NurpP --minimal linux-2.6.32.1/arch/mn10300/mm/fault.c linux-2.6.32.1-vs2.3.0.36.27/arch/mn10300/mm/fault.c
591 --- linux-2.6.32.1/arch/mn10300/mm/fault.c      2009-09-10 15:25:39.000000000 +0200
592 +++ linux-2.6.32.1-vs2.3.0.36.27/arch/mn10300/mm/fault.c        2009-12-03 20:04:56.000000000 +0100
593 @@ -339,7 +339,8 @@ no_context:
594  out_of_memory:
595         up_read(&mm->mmap_sem);
596         monitor_signal(regs);
597 -       printk(KERN_ALERT "VM: killing process %s\n", tsk->comm);
598 +       printk(KERN_ALERT "VM: killing process %s(%d:#%u)\n",
599 +               tsk->comm, task_pid_nr(tsk), tsk->xid);
600         if ((fault_code & MMUFCR_xFC_ACCESS) == MMUFCR_xFC_ACCESS_USR)
601                 do_exit(SIGKILL);
602         goto no_context;
603 diff -NurpP --minimal linux-2.6.32.1/arch/parisc/Kconfig linux-2.6.32.1-vs2.3.0.36.27/arch/parisc/Kconfig
604 --- linux-2.6.32.1/arch/parisc/Kconfig  2009-12-03 20:02:00.000000000 +0100
605 +++ linux-2.6.32.1-vs2.3.0.36.27/arch/parisc/Kconfig    2009-12-03 20:04:56.000000000 +0100
606 @@ -294,6 +294,8 @@ source "fs/Kconfig"
607  
608  source "arch/parisc/Kconfig.debug"
609  
610 +source "kernel/vserver/Kconfig"
611 +
612  source "security/Kconfig"
613  
614  source "crypto/Kconfig"
615 diff -NurpP --minimal linux-2.6.32.1/arch/parisc/kernel/syscall_table.S linux-2.6.32.1-vs2.3.0.36.27/arch/parisc/kernel/syscall_table.S
616 --- linux-2.6.32.1/arch/parisc/kernel/syscall_table.S   2009-12-03 20:02:00.000000000 +0100
617 +++ linux-2.6.32.1-vs2.3.0.36.27/arch/parisc/kernel/syscall_table.S     2009-12-03 20:04:56.000000000 +0100
618 @@ -361,7 +361,7 @@
619         ENTRY_COMP(mbind)               /* 260 */
620         ENTRY_COMP(get_mempolicy)
621         ENTRY_COMP(set_mempolicy)
622 -       ENTRY_SAME(ni_syscall)  /* 263: reserved for vserver */
623 +       ENTRY_DIFF(vserver)
624         ENTRY_SAME(add_key)
625         ENTRY_SAME(request_key)         /* 265 */
626         ENTRY_SAME(keyctl)
627 diff -NurpP --minimal linux-2.6.32.1/arch/parisc/kernel/traps.c linux-2.6.32.1-vs2.3.0.36.27/arch/parisc/kernel/traps.c
628 --- linux-2.6.32.1/arch/parisc/kernel/traps.c   2009-09-10 15:25:40.000000000 +0200
629 +++ linux-2.6.32.1-vs2.3.0.36.27/arch/parisc/kernel/traps.c     2009-12-03 20:04:56.000000000 +0100
630 @@ -236,8 +236,9 @@ void die_if_kernel(char *str, struct pt_
631                 if (err == 0)
632                         return; /* STFU */
633  
634 -               printk(KERN_CRIT "%s (pid %d): %s (code %ld) at " RFMT "\n",
635 -                       current->comm, task_pid_nr(current), str, err, regs->iaoq[0]);
636 +               printk(KERN_CRIT "%s (pid %d:#%u): %s (code %ld) at " RFMT "\n",
637 +                       current->comm, task_pid_nr(current), current->xid,
638 +                       str, err, regs->iaoq[0]);
639  #ifdef PRINT_USER_FAULTS
640                 /* XXX for debugging only */
641                 show_regs(regs);
642 @@ -270,8 +271,8 @@ void die_if_kernel(char *str, struct pt_
643                 pdc_console_restart();
644         
645         if (err)
646 -               printk(KERN_CRIT "%s (pid %d): %s (code %ld)\n",
647 -                       current->comm, task_pid_nr(current), str, err);
648 +               printk(KERN_CRIT "%s (pid %d:#%u): %s (code %ld)\n",
649 +                       current->comm, task_pid_nr(current), current->xid, str, err);
650  
651         /* Wot's wrong wif bein' racy? */
652         if (current->thread.flags & PARISC_KERNEL_DEATH) {
653 diff -NurpP --minimal linux-2.6.32.1/arch/parisc/mm/fault.c linux-2.6.32.1-vs2.3.0.36.27/arch/parisc/mm/fault.c
654 --- linux-2.6.32.1/arch/parisc/mm/fault.c       2009-09-10 15:25:40.000000000 +0200
655 +++ linux-2.6.32.1-vs2.3.0.36.27/arch/parisc/mm/fault.c 2009-12-03 20:04:56.000000000 +0100
656 @@ -237,8 +237,9 @@ bad_area:
657  
658  #ifdef PRINT_USER_FAULTS
659                 printk(KERN_DEBUG "\n");
660 -               printk(KERN_DEBUG "do_page_fault() pid=%d command='%s' type=%lu address=0x%08lx\n",
661 -                   task_pid_nr(tsk), tsk->comm, code, address);
662 +               printk(KERN_DEBUG "do_page_fault() pid=%d:#%u "
663 +                   "command='%s' type=%lu address=0x%08lx\n",
664 +                   task_pid_nr(tsk), tsk->xid, tsk->comm, code, address);
665                 if (vma) {
666                         printk(KERN_DEBUG "vm_start = 0x%08lx, vm_end = 0x%08lx\n",
667                                         vma->vm_start, vma->vm_end);
668 @@ -264,7 +265,8 @@ no_context:
669  
670    out_of_memory:
671         up_read(&mm->mmap_sem);
672 -       printk(KERN_CRIT "VM: killing process %s\n", current->comm);
673 +       printk(KERN_CRIT "VM: killing process %s(%d:#%u)\n",
674 +               current->comm, current->pid, current->xid);
675         if (user_mode(regs))
676                 do_group_exit(SIGKILL);
677         goto no_context;
678 diff -NurpP --minimal linux-2.6.32.1/arch/powerpc/include/asm/unistd.h linux-2.6.32.1-vs2.3.0.36.27/arch/powerpc/include/asm/unistd.h
679 --- linux-2.6.32.1/arch/powerpc/include/asm/unistd.h    2009-12-03 20:02:01.000000000 +0100
680 +++ linux-2.6.32.1-vs2.3.0.36.27/arch/powerpc/include/asm/unistd.h      2009-12-03 20:04:56.000000000 +0100
681 @@ -275,7 +275,7 @@
682  #endif
683  #define __NR_rtas              255
684  #define __NR_sys_debug_setcontext 256
685 -/* Number 257 is reserved for vserver */
686 +#define __NR_vserver           257
687  #define __NR_migrate_pages     258
688  #define __NR_mbind             259
689  #define __NR_get_mempolicy     260
690 diff -NurpP --minimal linux-2.6.32.1/arch/powerpc/Kconfig linux-2.6.32.1-vs2.3.0.36.27/arch/powerpc/Kconfig
691 --- linux-2.6.32.1/arch/powerpc/Kconfig 2009-12-03 20:02:00.000000000 +0100
692 +++ linux-2.6.32.1-vs2.3.0.36.27/arch/powerpc/Kconfig   2009-12-03 20:04:56.000000000 +0100
693 @@ -943,6 +943,8 @@ source "lib/Kconfig"
694  
695  source "arch/powerpc/Kconfig.debug"
696  
697 +source "kernel/vserver/Kconfig"
698 +
699  source "security/Kconfig"
700  
701  config KEYS_COMPAT
702 diff -NurpP --minimal linux-2.6.32.1/arch/powerpc/kernel/irq.c linux-2.6.32.1-vs2.3.0.36.27/arch/powerpc/kernel/irq.c
703 --- linux-2.6.32.1/arch/powerpc/kernel/irq.c    2009-12-03 20:02:01.000000000 +0100
704 +++ linux-2.6.32.1-vs2.3.0.36.27/arch/powerpc/kernel/irq.c      2009-12-03 20:04:56.000000000 +0100
705 @@ -54,6 +54,7 @@
706  #include <linux/pci.h>
707  #include <linux/debugfs.h>
708  #include <linux/perf_event.h>
709 +// #include <linux/vs_context.h>
710  
711  #include <asm/uaccess.h>
712  #include <asm/system.h>
713 diff -NurpP --minimal linux-2.6.32.1/arch/powerpc/kernel/process.c linux-2.6.32.1-vs2.3.0.36.27/arch/powerpc/kernel/process.c
714 --- linux-2.6.32.1/arch/powerpc/kernel/process.c        2009-12-03 20:02:02.000000000 +0100
715 +++ linux-2.6.32.1-vs2.3.0.36.27/arch/powerpc/kernel/process.c  2009-12-03 20:04:56.000000000 +0100
716 @@ -519,8 +519,9 @@ void show_regs(struct pt_regs * regs)
717  #else
718                 printk("DAR: "REG", DSISR: "REG"\n", regs->dar, regs->dsisr);
719  #endif
720 -       printk("TASK = %p[%d] '%s' THREAD: %p",
721 -              current, task_pid_nr(current), current->comm, task_thread_info(current));
722 +       printk("TASK = %p[%d,#%u] '%s' THREAD: %p",
723 +              current, task_pid_nr(current), current->xid,
724 +              current->comm, task_thread_info(current));
725  
726  #ifdef CONFIG_SMP
727         printk(" CPU: %d", raw_smp_processor_id());
728 diff -NurpP --minimal linux-2.6.32.1/arch/powerpc/kernel/traps.c linux-2.6.32.1-vs2.3.0.36.27/arch/powerpc/kernel/traps.c
729 --- linux-2.6.32.1/arch/powerpc/kernel/traps.c  2009-09-10 15:25:41.000000000 +0200
730 +++ linux-2.6.32.1-vs2.3.0.36.27/arch/powerpc/kernel/traps.c    2009-12-03 20:04:56.000000000 +0100
731 @@ -931,8 +931,9 @@ void nonrecoverable_exception(struct pt_
732  
733  void trace_syscall(struct pt_regs *regs)
734  {
735 -       printk("Task: %p(%d), PC: %08lX/%08lX, Syscall: %3ld, Result: %s%ld    %s\n",
736 -              current, task_pid_nr(current), regs->nip, regs->link, regs->gpr[0],
737 +       printk("Task: %p(%d[#%u]), PC: %08lX/%08lX, Syscall: %3ld, Result: %s%ld    %s\n",
738 +              current, task_pid_nr(current), current->xid,
739 +              regs->nip, regs->link, regs->gpr[0],
740                regs->ccr&0x10000000?"Error=":"", regs->gpr[3], print_tainted());
741  }
742  
743 diff -NurpP --minimal linux-2.6.32.1/arch/powerpc/kernel/vdso.c linux-2.6.32.1-vs2.3.0.36.27/arch/powerpc/kernel/vdso.c
744 --- linux-2.6.32.1/arch/powerpc/kernel/vdso.c   2009-12-03 20:02:02.000000000 +0100
745 +++ linux-2.6.32.1-vs2.3.0.36.27/arch/powerpc/kernel/vdso.c     2009-12-03 20:04:56.000000000 +0100
746 @@ -23,6 +23,7 @@
747  #include <linux/security.h>
748  #include <linux/bootmem.h>
749  #include <linux/lmb.h>
750 +#include <linux/vs_memory.h>
751  
752  #include <asm/pgtable.h>
753  #include <asm/system.h>
754 diff -NurpP --minimal linux-2.6.32.1/arch/powerpc/mm/fault.c linux-2.6.32.1-vs2.3.0.36.27/arch/powerpc/mm/fault.c
755 --- linux-2.6.32.1/arch/powerpc/mm/fault.c      2009-12-03 20:02:02.000000000 +0100
756 +++ linux-2.6.32.1-vs2.3.0.36.27/arch/powerpc/mm/fault.c        2009-12-03 20:04:56.000000000 +0100
757 @@ -358,7 +358,8 @@ out_of_memory:
758                 down_read(&mm->mmap_sem);
759                 goto survive;
760         }
761 -       printk("VM: killing process %s\n", current->comm);
762 +       printk("VM: killing process %s(%d:#%u)\n",
763 +               current->comm, current->pid, current->xid);
764         if (user_mode(regs))
765                 do_group_exit(SIGKILL);
766         return SIGKILL;
767 diff -NurpP --minimal linux-2.6.32.1/arch/s390/Kconfig linux-2.6.32.1-vs2.3.0.36.27/arch/s390/Kconfig
768 --- linux-2.6.32.1/arch/s390/Kconfig    2009-12-03 20:02:03.000000000 +0100
769 +++ linux-2.6.32.1-vs2.3.0.36.27/arch/s390/Kconfig      2009-12-03 20:04:56.000000000 +0100
770 @@ -616,6 +616,8 @@ source "fs/Kconfig"
771  
772  source "arch/s390/Kconfig.debug"
773  
774 +source "kernel/vserver/Kconfig"
775 +
776  source "security/Kconfig"
777  
778  source "crypto/Kconfig"
779 diff -NurpP --minimal linux-2.6.32.1/arch/s390/kernel/ptrace.c linux-2.6.32.1-vs2.3.0.36.27/arch/s390/kernel/ptrace.c
780 --- linux-2.6.32.1/arch/s390/kernel/ptrace.c    2009-12-03 20:02:03.000000000 +0100
781 +++ linux-2.6.32.1-vs2.3.0.36.27/arch/s390/kernel/ptrace.c      2009-12-03 20:04:56.000000000 +0100
782 @@ -36,6 +36,7 @@
783  #include <linux/regset.h>
784  #include <linux/tracehook.h>
785  #include <linux/seccomp.h>
786 +#include <linux/vs_base.h>
787  #include <trace/syscall.h>
788  #include <asm/compat.h>
789  #include <asm/segment.h>
790 diff -NurpP --minimal linux-2.6.32.1/arch/s390/kernel/syscalls.S linux-2.6.32.1-vs2.3.0.36.27/arch/s390/kernel/syscalls.S
791 --- linux-2.6.32.1/arch/s390/kernel/syscalls.S  2009-12-03 20:02:03.000000000 +0100
792 +++ linux-2.6.32.1-vs2.3.0.36.27/arch/s390/kernel/syscalls.S    2009-12-03 20:04:56.000000000 +0100
793 @@ -271,7 +271,7 @@ SYSCALL(sys_clock_settime,sys_clock_sett
794  SYSCALL(sys_clock_gettime,sys_clock_gettime,sys32_clock_gettime_wrapper)       /* 260 */
795  SYSCALL(sys_clock_getres,sys_clock_getres,sys32_clock_getres_wrapper)
796  SYSCALL(sys_clock_nanosleep,sys_clock_nanosleep,sys32_clock_nanosleep_wrapper)
797 -NI_SYSCALL                                                     /* reserved for vserver */
798 +SYSCALL(sys_vserver,sys_vserver,sys32_vserver)
799  SYSCALL(sys_s390_fadvise64_64,sys_ni_syscall,sys32_fadvise64_64_wrapper)
800  SYSCALL(sys_statfs64,sys_statfs64,compat_sys_statfs64_wrapper)
801  SYSCALL(sys_fstatfs64,sys_fstatfs64,compat_sys_fstatfs64_wrapper)
802 diff -NurpP --minimal linux-2.6.32.1/arch/s390/lib/uaccess_pt.c linux-2.6.32.1-vs2.3.0.36.27/arch/s390/lib/uaccess_pt.c
803 --- linux-2.6.32.1/arch/s390/lib/uaccess_pt.c   2009-09-10 15:25:43.000000000 +0200
804 +++ linux-2.6.32.1-vs2.3.0.36.27/arch/s390/lib/uaccess_pt.c     2009-12-03 20:04:56.000000000 +0100
805 @@ -90,7 +90,8 @@ out_of_memory:
806                 down_read(&mm->mmap_sem);
807                 goto survive;
808         }
809 -       printk("VM: killing process %s\n", current->comm);
810 +       printk("VM: killing process %s(%d:#%u)\n",
811 +               current->comm, task_pid_nr(current), current->xid);
812         return ret;
813  
814  out_sigbus:
815 diff -NurpP --minimal linux-2.6.32.1/arch/sh/Kconfig linux-2.6.32.1-vs2.3.0.36.27/arch/sh/Kconfig
816 --- linux-2.6.32.1/arch/sh/Kconfig      2009-12-03 20:02:03.000000000 +0100
817 +++ linux-2.6.32.1-vs2.3.0.36.27/arch/sh/Kconfig        2009-12-03 20:04:56.000000000 +0100
818 @@ -853,6 +853,8 @@ source "fs/Kconfig"
819  
820  source "arch/sh/Kconfig.debug"
821  
822 +source "kernel/vserver/Kconfig"
823 +
824  source "security/Kconfig"
825  
826  source "crypto/Kconfig"
827 diff -NurpP --minimal linux-2.6.32.1/arch/sh/kernel/irq.c linux-2.6.32.1-vs2.3.0.36.27/arch/sh/kernel/irq.c
828 --- linux-2.6.32.1/arch/sh/kernel/irq.c 2009-12-03 20:02:10.000000000 +0100
829 +++ linux-2.6.32.1-vs2.3.0.36.27/arch/sh/kernel/irq.c   2009-12-03 20:04:56.000000000 +0100
830 @@ -12,6 +12,7 @@
831  #include <linux/kernel_stat.h>
832  #include <linux/seq_file.h>
833  #include <linux/ftrace.h>
834 +// #include <linux/vs_context.h>
835  #include <asm/processor.h>
836  #include <asm/machvec.h>
837  #include <asm/uaccess.h>
838 diff -NurpP --minimal linux-2.6.32.1/arch/sh/kernel/vsyscall/vsyscall.c linux-2.6.32.1-vs2.3.0.36.27/arch/sh/kernel/vsyscall/vsyscall.c
839 --- linux-2.6.32.1/arch/sh/kernel/vsyscall/vsyscall.c   2009-03-24 14:18:42.000000000 +0100
840 +++ linux-2.6.32.1-vs2.3.0.36.27/arch/sh/kernel/vsyscall/vsyscall.c     2009-12-03 20:04:56.000000000 +0100
841 @@ -19,6 +19,7 @@
842  #include <linux/elf.h>
843  #include <linux/sched.h>
844  #include <linux/err.h>
845 +#include <linux/vs_memory.h>
846  
847  /*
848   * Should the kernel map a VDSO page into processes and pass its
849 diff -NurpP --minimal linux-2.6.32.1/arch/sh/mm/fault_32.c linux-2.6.32.1-vs2.3.0.36.27/arch/sh/mm/fault_32.c
850 --- linux-2.6.32.1/arch/sh/mm/fault_32.c        2009-12-03 20:02:14.000000000 +0100
851 +++ linux-2.6.32.1-vs2.3.0.36.27/arch/sh/mm/fault_32.c  2009-12-03 20:04:56.000000000 +0100
852 @@ -292,7 +292,8 @@ out_of_memory:
853                 down_read(&mm->mmap_sem);
854                 goto survive;
855         }
856 -       printk("VM: killing process %s\n", tsk->comm);
857 +       printk("VM: killing process %s(%d:#%u)\n",
858 +               tsk->comm, task_pid_nr(tsk), tsk->xid);
859         if (user_mode(regs))
860                 do_group_exit(SIGKILL);
861         goto no_context;
862 diff -NurpP --minimal linux-2.6.32.1/arch/sh/mm/tlbflush_64.c linux-2.6.32.1-vs2.3.0.36.27/arch/sh/mm/tlbflush_64.c
863 --- linux-2.6.32.1/arch/sh/mm/tlbflush_64.c     2009-12-03 20:02:14.000000000 +0100
864 +++ linux-2.6.32.1-vs2.3.0.36.27/arch/sh/mm/tlbflush_64.c       2009-12-03 20:04:56.000000000 +0100
865 @@ -306,7 +306,8 @@ out_of_memory:
866                 down_read(&mm->mmap_sem);
867                 goto survive;
868         }
869 -       printk("VM: killing process %s\n", tsk->comm);
870 +       printk("VM: killing process %s(%d:#%u)\n",
871 +               tsk->comm, task_pid_nr(tsk), tsk->xid);
872         if (user_mode(regs))
873                 do_group_exit(SIGKILL);
874         goto no_context;
875 diff -NurpP --minimal linux-2.6.32.1/arch/sparc/include/asm/tlb_64.h linux-2.6.32.1-vs2.3.0.36.27/arch/sparc/include/asm/tlb_64.h
876 --- linux-2.6.32.1/arch/sparc/include/asm/tlb_64.h      2009-09-10 15:25:45.000000000 +0200
877 +++ linux-2.6.32.1-vs2.3.0.36.27/arch/sparc/include/asm/tlb_64.h        2009-12-03 20:04:56.000000000 +0100
878 @@ -3,6 +3,7 @@
879  
880  #include <linux/swap.h>
881  #include <linux/pagemap.h>
882 +#include <linux/vs_memory.h>
883  #include <asm/pgalloc.h>
884  #include <asm/tlbflush.h>
885  #include <asm/mmu_context.h>
886 diff -NurpP --minimal linux-2.6.32.1/arch/sparc/include/asm/unistd.h linux-2.6.32.1-vs2.3.0.36.27/arch/sparc/include/asm/unistd.h
887 --- linux-2.6.32.1/arch/sparc/include/asm/unistd.h      2009-12-03 20:02:15.000000000 +0100
888 +++ linux-2.6.32.1-vs2.3.0.36.27/arch/sparc/include/asm/unistd.h        2009-12-03 20:04:56.000000000 +0100
889 @@ -335,7 +335,7 @@
890  #define __NR_timer_getoverrun  264
891  #define __NR_timer_delete      265
892  #define __NR_timer_create      266
893 -/* #define __NR_vserver                267 Reserved for VSERVER */
894 +#define __NR_vserver           267
895  #define __NR_io_setup          268
896  #define __NR_io_destroy                269
897  #define __NR_io_submit         270
898 diff -NurpP --minimal linux-2.6.32.1/arch/sparc/Kconfig linux-2.6.32.1-vs2.3.0.36.27/arch/sparc/Kconfig
899 --- linux-2.6.32.1/arch/sparc/Kconfig   2009-12-03 20:02:14.000000000 +0100
900 +++ linux-2.6.32.1-vs2.3.0.36.27/arch/sparc/Kconfig     2009-12-03 20:04:56.000000000 +0100
901 @@ -550,6 +550,8 @@ source "fs/Kconfig"
902  
903  source "arch/sparc/Kconfig.debug"
904  
905 +source "kernel/vserver/Kconfig"
906 +
907  source "security/Kconfig"
908  
909  source "crypto/Kconfig"
910 diff -NurpP --minimal linux-2.6.32.1/arch/sparc/kernel/systbls_32.S linux-2.6.32.1-vs2.3.0.36.27/arch/sparc/kernel/systbls_32.S
911 --- linux-2.6.32.1/arch/sparc/kernel/systbls_32.S       2009-12-03 20:02:15.000000000 +0100
912 +++ linux-2.6.32.1-vs2.3.0.36.27/arch/sparc/kernel/systbls_32.S 2009-12-03 20:04:56.000000000 +0100
913 @@ -70,7 +70,7 @@ sys_call_table:
914  /*250*/        .long sparc_mremap, sys_sysctl, sys_getsid, sys_fdatasync, sys_nfsservctl
915  /*255*/        .long sys_sync_file_range, sys_clock_settime, sys_clock_gettime, sys_clock_getres, sys_clock_nanosleep
916  /*260*/        .long sys_sched_getaffinity, sys_sched_setaffinity, sys_timer_settime, sys_timer_gettime, sys_timer_getoverrun
917 -/*265*/        .long sys_timer_delete, sys_timer_create, sys_nis_syscall, sys_io_setup, sys_io_destroy
918 +/*265*/        .long sys_timer_delete, sys_timer_create, sys_vserver, sys_io_setup, sys_io_destroy
919  /*270*/        .long sys_io_submit, sys_io_cancel, sys_io_getevents, sys_mq_open, sys_mq_unlink
920  /*275*/        .long sys_mq_timedsend, sys_mq_timedreceive, sys_mq_notify, sys_mq_getsetattr, sys_waitid
921  /*280*/        .long sys_tee, sys_add_key, sys_request_key, sys_keyctl, sys_openat
922 diff -NurpP --minimal linux-2.6.32.1/arch/sparc/kernel/systbls_64.S linux-2.6.32.1-vs2.3.0.36.27/arch/sparc/kernel/systbls_64.S
923 --- linux-2.6.32.1/arch/sparc/kernel/systbls_64.S       2009-12-03 20:02:15.000000000 +0100
924 +++ linux-2.6.32.1-vs2.3.0.36.27/arch/sparc/kernel/systbls_64.S 2009-12-03 20:04:56.000000000 +0100
925 @@ -71,7 +71,7 @@ sys_call_table32:
926  /*250*/        .word sys32_mremap, sys32_sysctl, sys32_getsid, sys_fdatasync, sys32_nfsservctl
927         .word sys32_sync_file_range, compat_sys_clock_settime, compat_sys_clock_gettime, compat_sys_clock_getres, sys32_clock_nanosleep
928  /*260*/        .word compat_sys_sched_getaffinity, compat_sys_sched_setaffinity, sys32_timer_settime, compat_sys_timer_gettime, sys_timer_getoverrun
929 -       .word sys_timer_delete, compat_sys_timer_create, sys_ni_syscall, compat_sys_io_setup, sys_io_destroy
930 +       .word sys_timer_delete, compat_sys_timer_create, sys32_vserver, compat_sys_io_setup, sys_io_destroy
931  /*270*/        .word sys32_io_submit, sys_io_cancel, compat_sys_io_getevents, sys32_mq_open, sys_mq_unlink
932         .word compat_sys_mq_timedsend, compat_sys_mq_timedreceive, compat_sys_mq_notify, compat_sys_mq_getsetattr, compat_sys_waitid
933  /*280*/        .word sys32_tee, sys_add_key, sys_request_key, sys_keyctl, compat_sys_openat
934 @@ -146,7 +146,7 @@ sys_call_table:
935  /*250*/        .word sys_64_mremap, sys_sysctl, sys_getsid, sys_fdatasync, sys_nfsservctl
936         .word sys_sync_file_range, sys_clock_settime, sys_clock_gettime, sys_clock_getres, sys_clock_nanosleep
937  /*260*/        .word sys_sched_getaffinity, sys_sched_setaffinity, sys_timer_settime, sys_timer_gettime, sys_timer_getoverrun
938 -       .word sys_timer_delete, sys_timer_create, sys_ni_syscall, sys_io_setup, sys_io_destroy
939 +       .word sys_timer_delete, sys_timer_create, sys_vserver, sys_io_setup, sys_io_destroy
940  /*270*/        .word sys_io_submit, sys_io_cancel, sys_io_getevents, sys_mq_open, sys_mq_unlink
941         .word sys_mq_timedsend, sys_mq_timedreceive, sys_mq_notify, sys_mq_getsetattr, sys_waitid
942  /*280*/        .word sys_tee, sys_add_key, sys_request_key, sys_keyctl, sys_openat
943 diff -NurpP --minimal linux-2.6.32.1/arch/x86/ia32/ia32entry.S linux-2.6.32.1-vs2.3.0.36.27/arch/x86/ia32/ia32entry.S
944 --- linux-2.6.32.1/arch/x86/ia32/ia32entry.S    2009-12-03 20:02:15.000000000 +0100
945 +++ linux-2.6.32.1-vs2.3.0.36.27/arch/x86/ia32/ia32entry.S      2009-12-03 20:04:56.000000000 +0100
946 @@ -777,7 +777,7 @@ ia32_sys_call_table:
947         .quad sys_tgkill                /* 270 */
948         .quad compat_sys_utimes
949         .quad sys32_fadvise64_64
950 -       .quad quiet_ni_syscall  /* sys_vserver */
951 +       .quad sys32_vserver
952         .quad sys_mbind
953         .quad compat_sys_get_mempolicy  /* 275 */
954         .quad sys_set_mempolicy
955 diff -NurpP --minimal linux-2.6.32.1/arch/x86/include/asm/unistd_64.h linux-2.6.32.1-vs2.3.0.36.27/arch/x86/include/asm/unistd_64.h
956 --- linux-2.6.32.1/arch/x86/include/asm/unistd_64.h     2009-12-03 20:02:16.000000000 +0100
957 +++ linux-2.6.32.1-vs2.3.0.36.27/arch/x86/include/asm/unistd_64.h       2009-12-03 20:04:56.000000000 +0100
958 @@ -535,7 +535,7 @@ __SYSCALL(__NR_tgkill, sys_tgkill)
959  #define __NR_utimes                            235
960  __SYSCALL(__NR_utimes, sys_utimes)
961  #define __NR_vserver                           236
962 -__SYSCALL(__NR_vserver, sys_ni_syscall)
963 +__SYSCALL(__NR_vserver, sys_vserver)
964  #define __NR_mbind                             237
965  __SYSCALL(__NR_mbind, sys_mbind)
966  #define __NR_set_mempolicy                     238
967 diff -NurpP --minimal linux-2.6.32.1/arch/x86/Kconfig linux-2.6.32.1-vs2.3.0.36.27/arch/x86/Kconfig
968 --- linux-2.6.32.1/arch/x86/Kconfig     2009-12-03 20:02:15.000000000 +0100
969 +++ linux-2.6.32.1-vs2.3.0.36.27/arch/x86/Kconfig       2009-12-03 20:04:56.000000000 +0100
970 @@ -2085,6 +2085,8 @@ source "fs/Kconfig"
971  
972  source "arch/x86/Kconfig.debug"
973  
974 +source "kernel/vserver/Kconfig"
975 +
976  source "security/Kconfig"
977  
978  source "crypto/Kconfig"
979 diff -NurpP --minimal linux-2.6.32.1/arch/x86/kernel/syscall_table_32.S linux-2.6.32.1-vs2.3.0.36.27/arch/x86/kernel/syscall_table_32.S
980 --- linux-2.6.32.1/arch/x86/kernel/syscall_table_32.S   2009-12-03 20:02:16.000000000 +0100
981 +++ linux-2.6.32.1-vs2.3.0.36.27/arch/x86/kernel/syscall_table_32.S     2009-12-03 20:04:56.000000000 +0100
982 @@ -272,7 +272,7 @@ ENTRY(sys_call_table)
983         .long sys_tgkill        /* 270 */
984         .long sys_utimes
985         .long sys_fadvise64_64
986 -       .long sys_ni_syscall    /* sys_vserver */
987 +       .long sys_vserver
988         .long sys_mbind
989         .long sys_get_mempolicy
990         .long sys_set_mempolicy
991 diff -NurpP --minimal linux-2.6.32.1/arch/xtensa/mm/fault.c linux-2.6.32.1-vs2.3.0.36.27/arch/xtensa/mm/fault.c
992 --- linux-2.6.32.1/arch/xtensa/mm/fault.c       2009-09-10 15:25:48.000000000 +0200
993 +++ linux-2.6.32.1-vs2.3.0.36.27/arch/xtensa/mm/fault.c 2009-12-03 20:04:56.000000000 +0100
994 @@ -151,7 +151,8 @@ out_of_memory:
995                 down_read(&mm->mmap_sem);
996                 goto survive;
997         }
998 -       printk("VM: killing process %s\n", current->comm);
999 +       printk("VM: killing process %s(%d:#%u)\n",
1000 +               current->comm, task_pid_nr(current), current->xid);
1001         if (user_mode(regs))
1002                 do_group_exit(SIGKILL);
1003         bad_page_fault(regs, address, SIGKILL);
1004 diff -NurpP --minimal linux-2.6.32.1/Documentation/scheduler/sched-cfs-hard-limits.txt linux-2.6.32.1-vs2.3.0.36.27/Documentation/scheduler/sched-cfs-hard-limits.txt
1005 --- linux-2.6.32.1/Documentation/scheduler/sched-cfs-hard-limits.txt    1970-01-01 01:00:00.000000000 +0100
1006 +++ linux-2.6.32.1-vs2.3.0.36.27/Documentation/scheduler/sched-cfs-hard-limits.txt      2009-12-03 20:04:56.000000000 +0100
1007 @@ -0,0 +1,48 @@
1008 +CPU HARD LIMITS FOR CFS GROUPS
1009 +==============================
1010 +
1011 +1. Overview
1012 +2. Interface
1013 +3. Examples
1014 +
1015 +1. Overview
1016 +-----------
1017 +
1018 +CFS is a proportional share scheduler which tries to divide the CPU time
1019 +proportionately between tasks or groups of tasks (task group/cgroup) depending
1020 +on the priority/weight of the task or shares assigned to groups of tasks.
1021 +In CFS, a task/task group can get more than its share of CPU if there are
1022 +enough idle CPU cycles available in the system, due to the work conserving
1023 +nature of the scheduler. However in certain scenarios (like pay-per-use),
1024 +it is desirable not to provide extra time to a group even in the presence
1025 +of idle CPU cycles. This is where hard limiting can be of use.
1026 +
1027 +Hard limits for task groups can be set by specifying how much CPU runtime a
1028 +group can consume within a given period. If the group consumes more CPU time
1029 +than the runtime in a given period, it gets throttled. None of the tasks of
1030 +the throttled group gets to run until the runtime of the group gets refreshed
1031 +at the beginning of the next period.
1032 +
1033 +2. Interface
1034 +------------
1035 +
1036 +Hard limit feature adds 2 cgroup files for CFS group scheduler:
1037 +
1038 +cfs_runtime_us: Hard limit for the group in microseconds.
1039 +
1040 +cfs_period_us: Time period in microseconds within which hard limits is
1041 +enforced.
1042 +
1043 +A group gets created with default values for runtime (infinite runtime which
1044 +means hard limits disabled) and period (0.5s). Each group can set its own
1045 +values for runtime and period independent of other groups in the system.
1046 +
1047 +3. Examples
1048 +-----------
1049 +
1050 +# mount -t cgroup -ocpu none /cgroups/
1051 +# cd /cgroups
1052 +# mkdir 1
1053 +# cd 1/
1054 +# echo 250000 > cfs_runtime_us /* set a 250ms runtime or limit */
1055 +# echo 500000 > cfs_period_us /* set a 500ms period */
1056 diff -NurpP --minimal linux-2.6.32.1/Documentation/vserver/debug.txt linux-2.6.32.1-vs2.3.0.36.27/Documentation/vserver/debug.txt
1057 --- linux-2.6.32.1/Documentation/vserver/debug.txt      1970-01-01 01:00:00.000000000 +0100
1058 +++ linux-2.6.32.1-vs2.3.0.36.27/Documentation/vserver/debug.txt        2009-12-03 20:04:56.000000000 +0100
1059 @@ -0,0 +1,154 @@
1060 +
1061 +debug_cvirt:
1062 +
1063 + 2   4 "vx_map_tgid: %p/%llx: %d -> %d"
1064 +       "vx_rmap_tgid: %p/%llx: %d -> %d"
1065 +
1066 +debug_dlim:
1067 +
1068 + 0   1 "ALLOC (%p,#%d)%c inode (%d)"
1069 +       "FREE  (%p,#%d)%c inode"
1070 + 1   2 "ALLOC (%p,#%d)%c %lld bytes (%d)"
1071 +       "FREE  (%p,#%d)%c %lld bytes"
1072 + 2   4 "ADJUST: %lld,%lld on %ld,%ld [mult=%d]"
1073 + 3   8 "ext3_has_free_blocks(%p): %lu<%lu+1, %c, %u!=%u r=%d"
1074 +       "ext3_has_free_blocks(%p): free=%lu, root=%lu"
1075 +       "rcu_free_dl_info(%p)"
1076 + 4  10 "alloc_dl_info(%p,%d) = %p"
1077 +       "dealloc_dl_info(%p)"
1078 +       "get_dl_info(%p[#%d.%d])"
1079 +       "put_dl_info(%p[#%d.%d])"
1080 + 5  20 "alloc_dl_info(%p,%d)*"
1081 + 6  40 "__hash_dl_info: %p[#%d]"
1082 +       "__unhash_dl_info: %p[#%d]"
1083 + 7  80 "locate_dl_info(%p,#%d) = %p"
1084 +
1085 +debug_misc:
1086 +
1087 + 0   1 "destroy_dqhash: %p [#0x%08x] c=%d"
1088 +       "new_dqhash: %p [#0x%08x]"
1089 +       "vroot[%d]_clr_dev: dev=%p[%lu,%d:%d]"
1090 +       "vroot[%d]_get_real_bdev: dev=%p[%lu,%d:%d]"
1091 +       "vroot[%d]_set_dev: dev=%p[%lu,%d:%d]"
1092 +       "vroot_get_real_bdev not set"
1093 + 1   2 "cow_break_link(»%s«)"
1094 +       "temp copy Â»%s«"
1095 + 2   4 "dentry_open(new): %p"
1096 +       "dentry_open(old): %p"
1097 +       "lookup_create(new): %p"
1098 +       "old path Â»%s«"
1099 +       "path_lookup(old): %d"
1100 +       "vfs_create(new): %d"
1101 +       "vfs_rename: %d"
1102 +       "vfs_sendfile: %d"
1103 + 3   8 "fput(new_file=%p[#%d])"
1104 +       "fput(old_file=%p[#%d])"
1105 + 4  10 "vx_info_kill(%p[#%d],%d,%d) = %d"
1106 +       "vx_info_kill(%p[#%d],%d,%d)*"
1107 + 5  20 "vs_reboot(%p[#%d],%d)"
1108 + 6  40 "dropping task %p[#%u,%u] for %p[#%u,%u]"
1109 +
1110 +debug_net:
1111 +
1112 + 2   4 "nx_addr_conflict(%p,%p) %d.%d,%d.%d"
1113 + 3   8 "inet_bind(%p) %d.%d.%d.%d, %d.%d.%d.%d, %d.%d.%d.%d"
1114 +       "inet_bind(%p)* %p,%p;%lx %d.%d.%d.%d"
1115 + 4  10 "ip_route_connect(%p) %p,%p;%lx"
1116 + 5  20 "__addr_in_socket(%p,%d.%d.%d.%d) %p:%d.%d.%d.%d %p;%lx"
1117 + 6  40 "sk,egf: %p [#%d] (from %d)"
1118 +       "sk,egn: %p [#%d] (from %d)"
1119 +       "sk,req: %p [#%d] (from %d)"
1120 +       "sk: %p [#%d] (from %d)"
1121 +       "tw: %p [#%d] (from %d)"
1122 + 7  80 "__sock_recvmsg: %p[%p,%p,%p;%d]:%d/%d"
1123 +       "__sock_sendmsg: %p[%p,%p,%p;%d]:%d/%d"
1124 +
1125 +debug_nid:
1126 +
1127 + 0   1 "__lookup_nx_info(#%u): %p[#%u]"
1128 +       "alloc_nx_info(%d) = %p"
1129 +       "create_nx_info(%d) (dynamic rejected)"
1130 +       "create_nx_info(%d) = %p (already there)"
1131 +       "create_nx_info(%d) = %p (new)"
1132 +       "dealloc_nx_info(%p)"
1133 + 1   2 "alloc_nx_info(%d)*"
1134 +       "create_nx_info(%d)*"
1135 + 2   4 "get_nx_info(%p[#%d.%d])"
1136 +       "put_nx_info(%p[#%d.%d])"
1137 + 3   8 "claim_nx_info(%p[#%d.%d.%d]) %p"
1138 +       "clr_nx_info(%p[#%d.%d])"
1139 +       "init_nx_info(%p[#%d.%d])"
1140 +       "release_nx_info(%p[#%d.%d.%d]) %p"
1141 +       "set_nx_info(%p[#%d.%d])"
1142 + 4  10 "__hash_nx_info: %p[#%d]"
1143 +       "__nx_dynamic_id: [#%d]"
1144 +       "__unhash_nx_info: %p[#%d.%d.%d]"
1145 + 5  20 "moved task %p into nxi:%p[#%d]"
1146 +       "nx_migrate_task(%p,%p[#%d.%d.%d])"
1147 +       "task_get_nx_info(%p)"
1148 + 6  40 "nx_clear_persistent(%p[#%d])"
1149 +
1150 +debug_quota:
1151 +
1152 + 0   1 "quota_sync_dqh(%p,%d) discard inode %p"
1153 + 1   2 "quota_sync_dqh(%p,%d)"
1154 +       "sync_dquots(%p,%d)"
1155 +       "sync_dquots_dqh(%p,%d)"
1156 + 3   8 "do_quotactl(%p,%d,cmd=%d,id=%d,%p)"
1157 +
1158 +debug_switch:
1159 +
1160 + 0   1 "vc: VCMD_%02d_%d[%d], %d,%p [%d,%d,%x,%x]"
1161 + 1   2 "vc: VCMD_%02d_%d[%d] = %08lx(%ld) [%d,%d]"
1162 + 4  10 "%s: (%s %s) returned %s with %d"
1163 +
1164 +debug_tag:
1165 +
1166 + 7  80 "dx_parse_tag(»%s«): %d:#%d"
1167 +       "dx_propagate_tag(%p[#%lu.%d]): %d,%d"
1168 +
1169 +debug_xid:
1170 +
1171 + 0   1 "__lookup_vx_info(#%u): %p[#%u]"
1172 +       "alloc_vx_info(%d) = %p"
1173 +       "alloc_vx_info(%d)*"
1174 +       "create_vx_info(%d) (dynamic rejected)"
1175 +       "create_vx_info(%d) = %p (already there)"
1176 +       "create_vx_info(%d) = %p (new)"
1177 +       "dealloc_vx_info(%p)"
1178 +       "loc_vx_info(%d) = %p (found)"
1179 +       "loc_vx_info(%d) = %p (new)"
1180 +       "loc_vx_info(%d) = %p (not available)"
1181 + 1   2 "create_vx_info(%d)*"
1182 +       "loc_vx_info(%d)*"
1183 + 2   4 "get_vx_info(%p[#%d.%d])"
1184 +       "put_vx_info(%p[#%d.%d])"
1185 + 3   8 "claim_vx_info(%p[#%d.%d.%d]) %p"
1186 +       "clr_vx_info(%p[#%d.%d])"
1187 +       "init_vx_info(%p[#%d.%d])"
1188 +       "release_vx_info(%p[#%d.%d.%d]) %p"
1189 +       "set_vx_info(%p[#%d.%d])"
1190 + 4  10 "__hash_vx_info: %p[#%d]"
1191 +       "__unhash_vx_info: %p[#%d.%d.%d]"
1192 +       "__vx_dynamic_id: [#%d]"
1193 + 5  20 "enter_vx_info(%p[#%d],%p) %p[#%d,%p]"
1194 +       "leave_vx_info(%p[#%d,%p]) %p[#%d,%p]"
1195 +       "moved task %p into vxi:%p[#%d]"
1196 +       "task_get_vx_info(%p)"
1197 +       "vx_migrate_task(%p,%p[#%d.%d])"
1198 + 6  40 "vx_clear_persistent(%p[#%d])"
1199 +       "vx_exit_init(%p[#%d],%p[#%d,%d,%d])"
1200 +       "vx_set_init(%p[#%d],%p[#%d,%d,%d])"
1201 +       "vx_set_persistent(%p[#%d])"
1202 +       "vx_set_reaper(%p[#%d],%p[#%d,%d])"
1203 + 7  80 "vx_child_reaper(%p[#%u,%u]) = %p[#%u,%u]"
1204 +
1205 +
1206 +debug_limit:
1207 +
1208 + n 2^n "vx_acc_cres[%5d,%s,%2d]: %5d%s"
1209 +       "vx_cres_avail[%5d,%s,%2d]: %5ld > %5d + %5d"
1210 +
1211 + m 2^m "vx_acc_page[%5d,%s,%2d]: %5d%s"
1212 +       "vx_acc_pages[%5d,%s,%2d]: %5d += %5d"
1213 +       "vx_pages_avail[%5d,%s,%2d]: %5ld > %5d + %5d"
1214 diff -NurpP --minimal linux-2.6.32.1/drivers/block/Kconfig linux-2.6.32.1-vs2.3.0.36.27/drivers/block/Kconfig
1215 --- linux-2.6.32.1/drivers/block/Kconfig        2009-09-10 15:25:49.000000000 +0200
1216 +++ linux-2.6.32.1-vs2.3.0.36.27/drivers/block/Kconfig  2009-12-03 20:04:56.000000000 +0100
1217 @@ -271,6 +271,13 @@ config BLK_DEV_CRYPTOLOOP
1218           instead, which can be configured to be on-disk compatible with the
1219           cryptoloop device.
1220  
1221 +config BLK_DEV_VROOT
1222 +       tristate "Virtual Root device support"
1223 +       depends on QUOTACTL
1224 +       ---help---
1225 +         Saying Y here will allow you to use quota/fs ioctls on a shared
1226 +         partition within a virtual server without compromising security.
1227 +
1228  config BLK_DEV_NBD
1229         tristate "Network block device support"
1230         depends on NET
1231 diff -NurpP --minimal linux-2.6.32.1/drivers/block/loop.c linux-2.6.32.1-vs2.3.0.36.27/drivers/block/loop.c
1232 --- linux-2.6.32.1/drivers/block/loop.c 2009-12-03 20:02:19.000000000 +0100
1233 +++ linux-2.6.32.1-vs2.3.0.36.27/drivers/block/loop.c   2009-12-03 20:04:56.000000000 +0100
1234 @@ -74,6 +74,7 @@
1235  #include <linux/gfp.h>
1236  #include <linux/kthread.h>
1237  #include <linux/splice.h>
1238 +#include <linux/vs_context.h>
1239  
1240  #include <asm/uaccess.h>
1241  
1242 @@ -812,6 +813,7 @@ static int loop_set_fd(struct loop_devic
1243         lo->lo_blocksize = lo_blocksize;
1244         lo->lo_device = bdev;
1245         lo->lo_flags = lo_flags;
1246 +       lo->lo_xid = vx_current_xid();
1247         lo->lo_backing_file = file;
1248         lo->transfer = transfer_none;
1249         lo->ioctl = NULL;
1250 @@ -937,6 +939,7 @@ static int loop_clr_fd(struct loop_devic
1251         lo->lo_encrypt_key_size = 0;
1252         lo->lo_flags = 0;
1253         lo->lo_thread = NULL;
1254 +       lo->lo_xid = 0;
1255         memset(lo->lo_encrypt_key, 0, LO_KEY_SIZE);
1256         memset(lo->lo_crypt_name, 0, LO_NAME_SIZE);
1257         memset(lo->lo_file_name, 0, LO_NAME_SIZE);
1258 @@ -971,7 +974,7 @@ loop_set_status(struct loop_device *lo, 
1259  
1260         if (lo->lo_encrypt_key_size &&
1261             lo->lo_key_owner != uid &&
1262 -           !capable(CAP_SYS_ADMIN))
1263 +           !vx_capable(CAP_SYS_ADMIN, VXC_ADMIN_CLOOP))
1264                 return -EPERM;
1265         if (lo->lo_state != Lo_bound)
1266                 return -ENXIO;
1267 @@ -1055,7 +1058,8 @@ loop_get_status(struct loop_device *lo, 
1268         memcpy(info->lo_crypt_name, lo->lo_crypt_name, LO_NAME_SIZE);
1269         info->lo_encrypt_type =
1270                 lo->lo_encryption ? lo->lo_encryption->number : 0;
1271 -       if (lo->lo_encrypt_key_size && capable(CAP_SYS_ADMIN)) {
1272 +       if (lo->lo_encrypt_key_size &&
1273 +               vx_capable(CAP_SYS_ADMIN, VXC_ADMIN_CLOOP)) {
1274                 info->lo_encrypt_key_size = lo->lo_encrypt_key_size;
1275                 memcpy(info->lo_encrypt_key, lo->lo_encrypt_key,
1276                        lo->lo_encrypt_key_size);
1277 @@ -1399,6 +1403,9 @@ static int lo_open(struct block_device *
1278  {
1279         struct loop_device *lo = bdev->bd_disk->private_data;
1280  
1281 +       if (!vx_check(lo->lo_xid, VS_IDENT|VS_HOSTID|VS_ADMIN_P))
1282 +               return -EACCES;
1283 +
1284         mutex_lock(&lo->lo_ctl_mutex);
1285         lo->lo_refcnt++;
1286         mutex_unlock(&lo->lo_ctl_mutex);
1287 diff -NurpP --minimal linux-2.6.32.1/drivers/block/Makefile linux-2.6.32.1-vs2.3.0.36.27/drivers/block/Makefile
1288 --- linux-2.6.32.1/drivers/block/Makefile       2009-09-10 15:25:49.000000000 +0200
1289 +++ linux-2.6.32.1-vs2.3.0.36.27/drivers/block/Makefile 2009-12-03 20:04:56.000000000 +0100
1290 @@ -34,6 +34,7 @@ obj-$(CONFIG_VIODASD)         += viodasd.o
1291  obj-$(CONFIG_BLK_DEV_SX8)      += sx8.o
1292  obj-$(CONFIG_BLK_DEV_UB)       += ub.o
1293  obj-$(CONFIG_BLK_DEV_HD)       += hd.o
1294 +obj-$(CONFIG_BLK_DEV_VROOT)    += vroot.o
1295  
1296  obj-$(CONFIG_XEN_BLKDEV_FRONTEND)      += xen-blkfront.o
1297  
1298 diff -NurpP --minimal linux-2.6.32.1/drivers/block/vroot.c linux-2.6.32.1-vs2.3.0.36.27/drivers/block/vroot.c
1299 --- linux-2.6.32.1/drivers/block/vroot.c        1970-01-01 01:00:00.000000000 +0100
1300 +++ linux-2.6.32.1-vs2.3.0.36.27/drivers/block/vroot.c  2009-12-03 20:04:56.000000000 +0100
1301 @@ -0,0 +1,281 @@
1302 +/*
1303 + *  linux/drivers/block/vroot.c
1304 + *
1305 + *  written by Herbert Pötzl, 9/11/2002
1306 + *  ported to 2.6.10 by Herbert Pötzl, 30/12/2004
1307 + *
1308 + *  based on the loop.c code by Theodore Ts'o.
1309 + *
1310 + * Copyright (C) 2002-2007 by Herbert Pötzl.
1311 + * Redistribution of this file is permitted under the
1312 + * GNU General Public License.
1313 + *
1314 + */
1315 +
1316 +#include <linux/module.h>
1317 +#include <linux/moduleparam.h>
1318 +#include <linux/file.h>
1319 +#include <linux/major.h>
1320 +#include <linux/blkdev.h>
1321 +
1322 +#include <linux/vroot.h>
1323 +#include <linux/vs_context.h>
1324 +
1325 +
1326 +static int max_vroot = 8;
1327 +
1328 +static struct vroot_device *vroot_dev;
1329 +static struct gendisk **disks;
1330 +
1331 +
1332 +static int vroot_set_dev(
1333 +       struct vroot_device *vr,
1334 +       struct block_device *bdev,
1335 +       unsigned int arg)
1336 +{
1337 +       struct block_device *real_bdev;
1338 +       struct file *file;
1339 +       struct inode *inode;
1340 +       int error;
1341 +
1342 +       error = -EBUSY;
1343 +       if (vr->vr_state != Vr_unbound)
1344 +               goto out;
1345 +
1346 +       error = -EBADF;
1347 +       file = fget(arg);
1348 +       if (!file)
1349 +               goto out;
1350 +
1351 +       error = -EINVAL;
1352 +       inode = file->f_dentry->d_inode;
1353 +
1354 +
1355 +       if (S_ISBLK(inode->i_mode)) {
1356 +               real_bdev = inode->i_bdev;
1357 +               vr->vr_device = real_bdev;
1358 +               __iget(real_bdev->bd_inode);
1359 +       } else
1360 +               goto out_fput;
1361 +
1362 +       vxdprintk(VXD_CBIT(misc, 0),
1363 +               "vroot[%d]_set_dev: dev=" VXF_DEV,
1364 +               vr->vr_number, VXD_DEV(real_bdev));
1365 +
1366 +       vr->vr_state = Vr_bound;
1367 +       error = 0;
1368 +
1369 + out_fput:
1370 +       fput(file);
1371 + out:
1372 +       return error;
1373 +}
1374 +
1375 +static int vroot_clr_dev(
1376 +       struct vroot_device *vr,
1377 +       struct block_device *bdev)
1378 +{
1379 +       struct block_device *real_bdev;
1380 +
1381 +       if (vr->vr_state != Vr_bound)
1382 +               return -ENXIO;
1383 +       if (vr->vr_refcnt > 1)  /* we needed one fd for the ioctl */
1384 +               return -EBUSY;
1385 +
1386 +       real_bdev = vr->vr_device;
1387 +
1388 +       vxdprintk(VXD_CBIT(misc, 0),
1389 +               "vroot[%d]_clr_dev: dev=" VXF_DEV,
1390 +               vr->vr_number, VXD_DEV(real_bdev));
1391 +
1392 +       bdput(real_bdev);
1393 +       vr->vr_state = Vr_unbound;
1394 +       vr->vr_device = NULL;
1395 +       return 0;
1396 +}
1397 +
1398 +
1399 +static int vr_ioctl(struct block_device *bdev, fmode_t mode,
1400 +       unsigned int cmd, unsigned long arg)
1401 +{
1402 +       struct vroot_device *vr = bdev->bd_disk->private_data;
1403 +       int err;
1404 +
1405 +       down(&vr->vr_ctl_mutex);
1406 +       switch (cmd) {
1407 +       case VROOT_SET_DEV:
1408 +               err = vroot_set_dev(vr, bdev, arg);
1409 +               break;
1410 +       case VROOT_CLR_DEV:
1411 +               err = vroot_clr_dev(vr, bdev);
1412 +               break;
1413 +       default:
1414 +               err = -EINVAL;
1415 +               break;
1416 +       }
1417 +       up(&vr->vr_ctl_mutex);
1418 +       return err;
1419 +}
1420 +
1421 +static int vr_open(struct block_device *bdev, fmode_t mode)
1422 +{
1423 +       struct vroot_device *vr = bdev->bd_disk->private_data;
1424 +
1425 +       down(&vr->vr_ctl_mutex);
1426 +       vr->vr_refcnt++;
1427 +       up(&vr->vr_ctl_mutex);
1428 +       return 0;
1429 +}
1430 +
1431 +static int vr_release(struct gendisk *disk, fmode_t mode)
1432 +{
1433 +       struct vroot_device *vr = disk->private_data;
1434 +
1435 +       down(&vr->vr_ctl_mutex);
1436 +       --vr->vr_refcnt;
1437 +       up(&vr->vr_ctl_mutex);
1438 +       return 0;
1439 +}
1440 +
1441 +static struct block_device_operations vr_fops = {
1442 +       .owner =        THIS_MODULE,
1443 +       .open =         vr_open,
1444 +       .release =      vr_release,
1445 +       .ioctl =        vr_ioctl,
1446 +};
1447 +
1448 +struct block_device *__vroot_get_real_bdev(struct block_device *bdev)
1449 +{
1450 +       struct inode *inode = bdev->bd_inode;
1451 +       struct vroot_device *vr;
1452 +       struct block_device *real_bdev;
1453 +       int minor = iminor(inode);
1454 +
1455 +       vr = &vroot_dev[minor];
1456 +       real_bdev = vr->vr_device;
1457 +
1458 +       vxdprintk(VXD_CBIT(misc, 0),
1459 +               "vroot[%d]_get_real_bdev: dev=" VXF_DEV,
1460 +               vr->vr_number, VXD_DEV(real_bdev));
1461 +
1462 +       if (vr->vr_state != Vr_bound)
1463 +               return ERR_PTR(-ENXIO);
1464 +
1465 +       __iget(real_bdev->bd_inode);
1466 +       return real_bdev;
1467 +}
1468 +
1469 +/*
1470 + * And now the modules code and kernel interface.
1471 + */
1472 +
1473 +module_param(max_vroot, int, 0);
1474 +
1475 +MODULE_PARM_DESC(max_vroot, "Maximum number of vroot devices (1-256)");
1476 +MODULE_LICENSE("GPL");
1477 +MODULE_ALIAS_BLOCKDEV_MAJOR(VROOT_MAJOR);
1478 +
1479 +MODULE_AUTHOR ("Herbert Pötzl");
1480 +MODULE_DESCRIPTION ("Virtual Root Device Mapper");
1481 +
1482 +
1483 +int __init vroot_init(void)
1484 +{
1485 +       int err, i;
1486 +
1487 +       if (max_vroot < 1 || max_vroot > 256) {
1488 +               max_vroot = MAX_VROOT_DEFAULT;
1489 +               printk(KERN_WARNING "vroot: invalid max_vroot "
1490 +                       "(must be between 1 and 256), "
1491 +                       "using default (%d)\n", max_vroot);
1492 +       }
1493 +
1494 +       if (register_blkdev(VROOT_MAJOR, "vroot"))
1495 +               return -EIO;
1496 +
1497 +       err = -ENOMEM;
1498 +       vroot_dev = kmalloc(max_vroot * sizeof(struct vroot_device), GFP_KERNEL);
1499 +       if (!vroot_dev)
1500 +               goto out_mem1;
1501 +       memset(vroot_dev, 0, max_vroot * sizeof(struct vroot_device));
1502 +
1503 +       disks = kmalloc(max_vroot * sizeof(struct gendisk *), GFP_KERNEL);
1504 +       if (!disks)
1505 +               goto out_mem2;
1506 +
1507 +       for (i = 0; i < max_vroot; i++) {
1508 +               disks[i] = alloc_disk(1);
1509 +               if (!disks[i])
1510 +                       goto out_mem3;
1511 +               disks[i]->queue = blk_alloc_queue(GFP_KERNEL);
1512 +               if (!disks[i]->queue)
1513 +                       goto out_mem3;
1514 +       }
1515 +
1516 +       for (i = 0; i < max_vroot; i++) {
1517 +               struct vroot_device *vr = &vroot_dev[i];
1518 +               struct gendisk *disk = disks[i];
1519 +
1520 +               memset(vr, 0, sizeof(*vr));
1521 +               init_MUTEX(&vr->vr_ctl_mutex);
1522 +               vr->vr_number = i;
1523 +               disk->major = VROOT_MAJOR;
1524 +               disk->first_minor = i;
1525 +               disk->fops = &vr_fops;
1526 +               sprintf(disk->disk_name, "vroot%d", i);
1527 +               disk->private_data = vr;
1528 +       }
1529 +
1530 +       err = register_vroot_grb(&__vroot_get_real_bdev);
1531 +       if (err)
1532 +               goto out_mem3;
1533 +
1534 +       for (i = 0; i < max_vroot; i++)
1535 +               add_disk(disks[i]);
1536 +       printk(KERN_INFO "vroot: loaded (max %d devices)\n", max_vroot);
1537 +       return 0;
1538 +
1539 +out_mem3:
1540 +       while (i--)
1541 +               put_disk(disks[i]);
1542 +       kfree(disks);
1543 +out_mem2:
1544 +       kfree(vroot_dev);
1545 +out_mem1:
1546 +       unregister_blkdev(VROOT_MAJOR, "vroot");
1547 +       printk(KERN_ERR "vroot: ran out of memory\n");
1548 +       return err;
1549 +}
1550 +
1551 +void vroot_exit(void)
1552 +{
1553 +       int i;
1554 +
1555 +       if (unregister_vroot_grb(&__vroot_get_real_bdev))
1556 +               printk(KERN_WARNING "vroot: cannot unregister grb\n");
1557 +
1558 +       for (i = 0; i < max_vroot; i++) {
1559 +               del_gendisk(disks[i]);
1560 +               put_disk(disks[i]);
1561 +       }
1562 +       unregister_blkdev(VROOT_MAJOR, "vroot");
1563 +
1564 +       kfree(disks);
1565 +       kfree(vroot_dev);
1566 +}
1567 +
1568 +module_init(vroot_init);
1569 +module_exit(vroot_exit);
1570 +
1571 +#ifndef MODULE
1572 +
1573 +static int __init max_vroot_setup(char *str)
1574 +{
1575 +       max_vroot = simple_strtol(str, NULL, 0);
1576 +       return 1;
1577 +}
1578 +
1579 +__setup("max_vroot=", max_vroot_setup);
1580 +
1581 +#endif
1582 +
1583 diff -NurpP --minimal linux-2.6.32.1/drivers/char/sysrq.c linux-2.6.32.1-vs2.3.0.36.27/drivers/char/sysrq.c
1584 --- linux-2.6.32.1/drivers/char/sysrq.c 2009-12-03 20:02:20.000000000 +0100
1585 +++ linux-2.6.32.1-vs2.3.0.36.27/drivers/char/sysrq.c   2009-12-03 20:04:56.000000000 +0100
1586 @@ -38,6 +38,7 @@
1587  #include <linux/workqueue.h>
1588  #include <linux/hrtimer.h>
1589  #include <linux/oom.h>
1590 +#include <linux/vserver/debug.h>
1591  
1592  #include <asm/ptrace.h>
1593  #include <asm/irq_regs.h>
1594 @@ -391,6 +392,21 @@ static struct sysrq_key_op sysrq_unrt_op
1595         .enable_mask    = SYSRQ_ENABLE_RTNICE,
1596  };
1597  
1598 +
1599 +#ifdef CONFIG_VSERVER_DEBUG
1600 +static void sysrq_handle_vxinfo(int key, struct tty_struct *tty)
1601 +{
1602 +       dump_vx_info_inactive((key == 'x')?0:1);
1603 +}
1604 +
1605 +static struct sysrq_key_op sysrq_showvxinfo_op = {
1606 +       .handler        = sysrq_handle_vxinfo,
1607 +       .help_msg       = "conteXt",
1608 +       .action_msg     = "Show Context Info",
1609 +       .enable_mask    = SYSRQ_ENABLE_DUMP,
1610 +};
1611 +#endif
1612 +
1613  /* Key Operations table and lock */
1614  static DEFINE_SPINLOCK(sysrq_key_table_lock);
1615  
1616 @@ -445,7 +461,11 @@ static struct sysrq_key_op *sysrq_key_ta
1617         NULL,                           /* v */
1618         &sysrq_showstate_blocked_op,    /* w */
1619         /* x: May be registered on ppc/powerpc for xmon */
1620 +#ifdef CONFIG_VSERVER_DEBUG
1621 +       &sysrq_showvxinfo_op,           /* x */
1622 +#else
1623         NULL,                           /* x */
1624 +#endif
1625         /* y: May be registered on sparc64 for global register dump */
1626         NULL,                           /* y */
1627         &sysrq_ftrace_dump_op,          /* z */
1628 @@ -460,6 +480,8 @@ static int sysrq_key_table_key2index(int
1629                 retval = key - '0';
1630         else if ((key >= 'a') && (key <= 'z'))
1631                 retval = key + 10 - 'a';
1632 +       else if ((key >= 'A') && (key <= 'Z'))
1633 +               retval = key + 10 - 'A';
1634         else
1635                 retval = -1;
1636         return retval;
1637 diff -NurpP --minimal linux-2.6.32.1/drivers/char/tty_io.c linux-2.6.32.1-vs2.3.0.36.27/drivers/char/tty_io.c
1638 --- linux-2.6.32.1/drivers/char/tty_io.c        2009-12-03 20:02:20.000000000 +0100
1639 +++ linux-2.6.32.1-vs2.3.0.36.27/drivers/char/tty_io.c  2009-12-03 20:04:56.000000000 +0100
1640 @@ -106,6 +106,7 @@
1641  
1642  #include <linux/kmod.h>
1643  #include <linux/nsproxy.h>
1644 +#include <linux/vs_pid.h>
1645  
1646  #undef TTY_DEBUG_HANGUP
1647  
1648 @@ -1966,7 +1967,8 @@ static int tiocsti(struct tty_struct *tt
1649         char ch, mbz = 0;
1650         struct tty_ldisc *ld;
1651  
1652 -       if ((current->signal->tty != tty) && !capable(CAP_SYS_ADMIN))
1653 +       if (((current->signal->tty != tty) && !capable(CAP_SYS_ADMIN)) ||
1654 +               !vx_ccaps(VXC_TIOCSTI))
1655                 return -EPERM;
1656         if (get_user(ch, p))
1657                 return -EFAULT;
1658 @@ -2254,6 +2256,7 @@ static int tiocspgrp(struct tty_struct *
1659                 return -ENOTTY;
1660         if (get_user(pgrp_nr, p))
1661                 return -EFAULT;
1662 +       pgrp_nr = vx_rmap_pid(pgrp_nr);
1663         if (pgrp_nr < 0)
1664                 return -EINVAL;
1665         rcu_read_lock();
1666 diff -NurpP --minimal linux-2.6.32.1/drivers/infiniband/hw/ipath/ipath_user_pages.c linux-2.6.32.1-vs2.3.0.36.27/drivers/infiniband/hw/ipath/ipath_user_pages.c
1667 --- linux-2.6.32.1/drivers/infiniband/hw/ipath/ipath_user_pages.c       2009-12-03 20:02:23.000000000 +0100
1668 +++ linux-2.6.32.1-vs2.3.0.36.27/drivers/infiniband/hw/ipath/ipath_user_pages.c 2009-12-04 23:31:17.000000000 +0100
1669 @@ -34,6 +34,7 @@
1670  #include <linux/mm.h>
1671  #include <linux/device.h>
1672  #include <linux/sched.h>
1673 +#include <linux/vs_memory.h>
1674  
1675  #include "ipath_kernel.h"
1676  
1677 @@ -62,7 +63,8 @@ static int __get_user_pages(unsigned lon
1678         lock_limit = current->signal->rlim[RLIMIT_MEMLOCK].rlim_cur >>
1679                 PAGE_SHIFT;
1680  
1681 -       if (num_pages > lock_limit) {
1682 +       if (num_pages > lock_limit ||
1683 +               !vx_vmlocked_avail(current->mm, num_pages)) {
1684                 ret = -ENOMEM;
1685                 goto bail;
1686         }
1687 @@ -79,7 +81,7 @@ static int __get_user_pages(unsigned lon
1688                         goto bail_release;
1689         }
1690  
1691 -       current->mm->locked_vm += num_pages;
1692 +       vx_vmlocked_add(current->mm, num_pages);
1693  
1694         ret = 0;
1695         goto bail;
1696 @@ -178,7 +180,7 @@ void ipath_release_user_pages(struct pag
1697  
1698         __ipath_release_user_pages(p, num_pages, 1);
1699  
1700 -       current->mm->locked_vm -= num_pages;
1701 +       vx_vmlocked_sub(current->mm, num_pages);
1702  
1703         up_write(&current->mm->mmap_sem);
1704  }
1705 @@ -195,7 +197,7 @@ static void user_pages_account(struct wo
1706                 container_of(_work, struct ipath_user_pages_work, work);
1707  
1708         down_write(&work->mm->mmap_sem);
1709 -       work->mm->locked_vm -= work->num_pages;
1710 +       vx_vmlocked_sub(work->mm, work->num_pages);
1711         up_write(&work->mm->mmap_sem);
1712         mmput(work->mm);
1713         kfree(work);
1714 diff -NurpP --minimal linux-2.6.32.1/drivers/md/dm.c linux-2.6.32.1-vs2.3.0.36.27/drivers/md/dm.c
1715 --- linux-2.6.32.1/drivers/md/dm.c      2009-12-03 20:02:25.000000000 +0100
1716 +++ linux-2.6.32.1-vs2.3.0.36.27/drivers/md/dm.c        2009-12-03 20:04:56.000000000 +0100
1717 @@ -19,6 +19,7 @@
1718  #include <linux/slab.h>
1719  #include <linux/idr.h>
1720  #include <linux/hdreg.h>
1721 +#include <linux/vs_base.h>
1722  
1723  #include <trace/events/block.h>
1724  
1725 @@ -119,6 +120,7 @@ struct mapped_device {
1726         rwlock_t map_lock;
1727         atomic_t holders;
1728         atomic_t open_count;
1729 +       xid_t xid;
1730  
1731         unsigned long flags;
1732  
1733 @@ -323,6 +325,7 @@ static void __exit dm_exit(void)
1734  static int dm_blk_open(struct block_device *bdev, fmode_t mode)
1735  {
1736         struct mapped_device *md;
1737 +       int ret = -ENXIO;
1738  
1739         spin_lock(&_minor_lock);
1740  
1741 @@ -331,18 +334,19 @@ static int dm_blk_open(struct block_devi
1742                 goto out;
1743  
1744         if (test_bit(DMF_FREEING, &md->flags) ||
1745 -           test_bit(DMF_DELETING, &md->flags)) {
1746 -               md = NULL;
1747 +           test_bit(DMF_DELETING, &md->flags))
1748 +               goto out;
1749 +
1750 +       ret = -EACCES;
1751 +       if (!vx_check(md->xid, VS_IDENT|VS_HOSTID))
1752                 goto out;
1753 -       }
1754  
1755         dm_get(md);
1756         atomic_inc(&md->open_count);
1757 -
1758 +       ret = 0;
1759  out:
1760         spin_unlock(&_minor_lock);
1761 -
1762 -       return md ? 0 : -ENXIO;
1763 +       return ret;
1764  }
1765  
1766  static int dm_blk_close(struct gendisk *disk, fmode_t mode)
1767 @@ -553,6 +557,14 @@ int dm_set_geometry(struct mapped_device
1768         return 0;
1769  }
1770  
1771 +/*
1772 + * Get the xid associated with a dm device
1773 + */
1774 +xid_t dm_get_xid(struct mapped_device *md)
1775 +{
1776 +       return md->xid;
1777 +}
1778 +
1779  /*-----------------------------------------------------------------
1780   * CRUD START:
1781   *   A more elegant soln is in the works that uses the queue
1782 @@ -1762,6 +1774,7 @@ static struct mapped_device *alloc_dev(i
1783         INIT_LIST_HEAD(&md->uevent_list);
1784         spin_lock_init(&md->uevent_lock);
1785  
1786 +       md->xid = vx_current_xid();
1787         md->queue = blk_init_queue(dm_request_fn, NULL);
1788         if (!md->queue)
1789                 goto bad_queue;
1790 diff -NurpP --minimal linux-2.6.32.1/drivers/md/dm.h linux-2.6.32.1-vs2.3.0.36.27/drivers/md/dm.h
1791 --- linux-2.6.32.1/drivers/md/dm.h      2009-09-10 15:25:55.000000000 +0200
1792 +++ linux-2.6.32.1-vs2.3.0.36.27/drivers/md/dm.h        2009-12-03 20:04:56.000000000 +0100
1793 @@ -41,6 +41,8 @@ struct dm_dev_internal {
1794  struct dm_table;
1795  struct dm_md_mempools;
1796  
1797 +xid_t dm_get_xid(struct mapped_device *md);
1798 +
1799  /*-----------------------------------------------------------------
1800   * Internal table functions.
1801   *---------------------------------------------------------------*/
1802 diff -NurpP --minimal linux-2.6.32.1/drivers/md/dm-ioctl.c linux-2.6.32.1-vs2.3.0.36.27/drivers/md/dm-ioctl.c
1803 --- linux-2.6.32.1/drivers/md/dm-ioctl.c        2009-12-03 20:02:25.000000000 +0100
1804 +++ linux-2.6.32.1-vs2.3.0.36.27/drivers/md/dm-ioctl.c  2009-12-03 20:04:56.000000000 +0100
1805 @@ -16,6 +16,7 @@
1806  #include <linux/dm-ioctl.h>
1807  #include <linux/hdreg.h>
1808  #include <linux/compat.h>
1809 +#include <linux/vs_context.h>
1810  
1811  #include <asm/uaccess.h>
1812  
1813 @@ -101,7 +102,8 @@ static struct hash_cell *__get_name_cell
1814         unsigned int h = hash_str(str);
1815  
1816         list_for_each_entry (hc, _name_buckets + h, name_list)
1817 -               if (!strcmp(hc->name, str)) {
1818 +               if (vx_check(dm_get_xid(hc->md), VS_WATCH_P | VS_IDENT) &&
1819 +                       !strcmp(hc->name, str)) {
1820                         dm_get(hc->md);
1821                         return hc;
1822                 }
1823 @@ -115,7 +117,8 @@ static struct hash_cell *__get_uuid_cell
1824         unsigned int h = hash_str(str);
1825  
1826         list_for_each_entry (hc, _uuid_buckets + h, uuid_list)
1827 -               if (!strcmp(hc->uuid, str)) {
1828 +               if (vx_check(dm_get_xid(hc->md), VS_WATCH_P | VS_IDENT) &&
1829 +                       !strcmp(hc->uuid, str)) {
1830                         dm_get(hc->md);
1831                         return hc;
1832                 }
1833 @@ -352,6 +355,9 @@ typedef int (*ioctl_fn)(struct dm_ioctl 
1834  
1835  static int remove_all(struct dm_ioctl *param, size_t param_size)
1836  {
1837 +       if (!vx_check(0, VS_ADMIN))
1838 +               return -EPERM;
1839 +
1840         dm_hash_remove_all(1);
1841         param->data_size = 0;
1842         return 0;
1843 @@ -399,6 +405,8 @@ static int list_devices(struct dm_ioctl 
1844          */
1845         for (i = 0; i < NUM_BUCKETS; i++) {
1846                 list_for_each_entry (hc, _name_buckets + i, name_list) {
1847 +                       if (!vx_check(dm_get_xid(hc->md), VS_WATCH_P | VS_IDENT))
1848 +                               continue;
1849                         needed += sizeof(struct dm_name_list);
1850                         needed += strlen(hc->name) + 1;
1851                         needed += ALIGN_MASK;
1852 @@ -422,6 +430,8 @@ static int list_devices(struct dm_ioctl 
1853          */
1854         for (i = 0; i < NUM_BUCKETS; i++) {
1855                 list_for_each_entry (hc, _name_buckets + i, name_list) {
1856 +                       if (!vx_check(dm_get_xid(hc->md), VS_WATCH_P | VS_IDENT))
1857 +                               continue;
1858                         if (old_nl)
1859                                 old_nl->next = (uint32_t) ((void *) nl -
1860                                                            (void *) old_nl);
1861 @@ -612,10 +622,11 @@ static struct hash_cell *__find_device_h
1862         if (!md)
1863                 goto out;
1864  
1865 -       mdptr = dm_get_mdptr(md);
1866 +       if (vx_check(dm_get_xid(md), VS_WATCH_P | VS_IDENT))
1867 +               mdptr = dm_get_mdptr(md);
1868 +
1869         if (!mdptr)
1870                 dm_put(md);
1871 -
1872  out:
1873         return mdptr;
1874  }
1875 @@ -1445,8 +1456,8 @@ static int ctl_ioctl(uint command, struc
1876         ioctl_fn fn = NULL;
1877         size_t param_size;
1878  
1879 -       /* only root can play with this */
1880 -       if (!capable(CAP_SYS_ADMIN))
1881 +       /* only root and certain contexts can play with this */
1882 +       if (!vx_capable(CAP_SYS_ADMIN, VXC_ADMIN_MAPPER))
1883                 return -EACCES;
1884  
1885         if (_IOC_TYPE(command) != DM_IOCTL)
1886 diff -NurpP --minimal linux-2.6.32.1/drivers/net/tun.c linux-2.6.32.1-vs2.3.0.36.27/drivers/net/tun.c
1887 --- linux-2.6.32.1/drivers/net/tun.c    2009-12-03 20:02:32.000000000 +0100
1888 +++ linux-2.6.32.1-vs2.3.0.36.27/drivers/net/tun.c      2009-12-03 20:04:56.000000000 +0100
1889 @@ -61,6 +61,7 @@
1890  #include <linux/crc32.h>
1891  #include <linux/nsproxy.h>
1892  #include <linux/virtio_net.h>
1893 +#include <linux/vs_network.h>
1894  #include <net/net_namespace.h>
1895  #include <net/netns/generic.h>
1896  #include <net/rtnetlink.h>
1897 @@ -102,6 +103,7 @@ struct tun_struct {
1898         unsigned int            flags;
1899         uid_t                   owner;
1900         gid_t                   group;
1901 +       nid_t                   nid;
1902  
1903         struct net_device       *dev;
1904         struct fasync_struct    *fasync;
1905 @@ -816,6 +818,7 @@ static void tun_setup(struct net_device 
1906  
1907         tun->owner = -1;
1908         tun->group = -1;
1909 +       tun->nid = current->nid;
1910  
1911         dev->ethtool_ops = &tun_ethtool_ops;
1912         dev->destructor = tun_free_netdev;
1913 @@ -932,7 +935,7 @@ static int tun_set_iff(struct net *net, 
1914  
1915                 if (((tun->owner != -1 && cred->euid != tun->owner) ||
1916                      (tun->group != -1 && !in_egroup_p(tun->group))) &&
1917 -                   !capable(CAP_NET_ADMIN))
1918 +               !cap_raised(current_cap(), CAP_NET_ADMIN))
1919                         return -EPERM;
1920                 err = security_tun_dev_attach(tun->socket.sk);
1921                 if (err < 0)
1922 @@ -946,7 +949,7 @@ static int tun_set_iff(struct net *net, 
1923                 char *name;
1924                 unsigned long flags = 0;
1925  
1926 -               if (!capable(CAP_NET_ADMIN))
1927 +               if (!nx_capable(CAP_NET_ADMIN, NXC_TUN_CREATE))
1928                         return -EPERM;
1929                 err = security_tun_dev_create();
1930                 if (err < 0)
1931 @@ -1013,6 +1016,9 @@ static int tun_set_iff(struct net *net, 
1932  
1933                 sk->sk_destruct = tun_sock_destruct;
1934  
1935 +               if (!nx_check(tun->nid, VS_IDENT | VS_HOSTID | VS_ADMIN_P))
1936 +                       return -EPERM;
1937 +
1938                 err = tun_attach(tun, file);
1939                 if (err < 0)
1940                         goto failed;
1941 @@ -1202,6 +1208,16 @@ static long tun_chr_ioctl(struct file *f
1942                 DBG(KERN_INFO "%s: group set to %d\n", tun->dev->name, tun->group);
1943                 break;
1944  
1945 +       case TUNSETNID:
1946 +               if (!capable(CAP_CONTEXT))
1947 +                       return -EPERM;
1948 +
1949 +               /* Set nid owner of the device */
1950 +               tun->nid = (nid_t) arg;
1951 +
1952 +               DBG(KERN_INFO "%s: nid owner set to %u\n", tun->dev->name, tun->nid);
1953 +               break;
1954 +
1955         case TUNSETLINK:
1956                 /* Only allow setting the type when the interface is down */
1957                 if (tun->dev->flags & IFF_UP) {
1958 diff -NurpP --minimal linux-2.6.32.1/fs/attr.c linux-2.6.32.1-vs2.3.0.36.27/fs/attr.c
1959 --- linux-2.6.32.1/fs/attr.c    2009-12-03 20:02:51.000000000 +0100
1960 +++ linux-2.6.32.1-vs2.3.0.36.27/fs/attr.c      2009-12-03 20:04:56.000000000 +0100
1961 @@ -14,6 +14,9 @@
1962  #include <linux/fcntl.h>
1963  #include <linux/quotaops.h>
1964  #include <linux/security.h>
1965 +#include <linux/proc_fs.h>
1966 +#include <linux/devpts_fs.h>
1967 +#include <linux/vs_tag.h>
1968  
1969  /* Taken over from the old code... */
1970  
1971 @@ -55,6 +58,10 @@ int inode_change_ok(const struct inode *
1972                 if (!is_owner_or_cap(inode))
1973                         goto error;
1974         }
1975 +
1976 +       if (dx_permission(inode, MAY_WRITE))
1977 +               goto error;
1978 +
1979  fine:
1980         retval = 0;
1981  error:
1982 @@ -120,6 +127,8 @@ int inode_setattr(struct inode * inode, 
1983                 inode->i_uid = attr->ia_uid;
1984         if (ia_valid & ATTR_GID)
1985                 inode->i_gid = attr->ia_gid;
1986 +       if ((ia_valid & ATTR_TAG) && IS_TAGGED(inode))
1987 +               inode->i_tag = attr->ia_tag;
1988         if (ia_valid & ATTR_ATIME)
1989                 inode->i_atime = timespec_trunc(attr->ia_atime,
1990                                                 inode->i_sb->s_time_gran);
1991 @@ -214,7 +223,8 @@ int notify_change(struct dentry * dentry
1992                 error = inode_change_ok(inode, attr);
1993                 if (!error) {
1994                         if ((ia_valid & ATTR_UID && attr->ia_uid != inode->i_uid) ||
1995 -                           (ia_valid & ATTR_GID && attr->ia_gid != inode->i_gid))
1996 +                           (ia_valid & ATTR_GID && attr->ia_gid != inode->i_gid) ||
1997 +                           (ia_valid & ATTR_TAG && attr->ia_tag != inode->i_tag))
1998                                 error = vfs_dq_transfer(inode, attr) ?
1999                                         -EDQUOT : 0;
2000                         if (!error)
2001 diff -NurpP --minimal linux-2.6.32.1/fs/binfmt_aout.c linux-2.6.32.1-vs2.3.0.36.27/fs/binfmt_aout.c
2002 --- linux-2.6.32.1/fs/binfmt_aout.c     2009-03-24 14:22:24.000000000 +0100
2003 +++ linux-2.6.32.1-vs2.3.0.36.27/fs/binfmt_aout.c       2009-12-03 20:04:56.000000000 +0100
2004 @@ -24,6 +24,7 @@
2005  #include <linux/binfmts.h>
2006  #include <linux/personality.h>
2007  #include <linux/init.h>
2008 +#include <linux/vs_memory.h>
2009  
2010  #include <asm/system.h>
2011  #include <asm/uaccess.h>
2012 diff -NurpP --minimal linux-2.6.32.1/fs/binfmt_elf.c linux-2.6.32.1-vs2.3.0.36.27/fs/binfmt_elf.c
2013 --- linux-2.6.32.1/fs/binfmt_elf.c      2009-12-03 20:02:51.000000000 +0100
2014 +++ linux-2.6.32.1-vs2.3.0.36.27/fs/binfmt_elf.c        2009-12-03 20:04:56.000000000 +0100
2015 @@ -31,6 +31,7 @@
2016  #include <linux/random.h>
2017  #include <linux/elf.h>
2018  #include <linux/utsname.h>
2019 +#include <linux/vs_memory.h>
2020  #include <asm/uaccess.h>
2021  #include <asm/param.h>
2022  #include <asm/page.h>
2023 diff -NurpP --minimal linux-2.6.32.1/fs/binfmt_flat.c linux-2.6.32.1-vs2.3.0.36.27/fs/binfmt_flat.c
2024 --- linux-2.6.32.1/fs/binfmt_flat.c     2009-12-03 20:02:51.000000000 +0100
2025 +++ linux-2.6.32.1-vs2.3.0.36.27/fs/binfmt_flat.c       2009-12-03 20:04:56.000000000 +0100
2026 @@ -35,6 +35,7 @@
2027  #include <linux/init.h>
2028  #include <linux/flat.h>
2029  #include <linux/syscalls.h>
2030 +#include <linux/vs_memory.h>
2031  
2032  #include <asm/byteorder.h>
2033  #include <asm/system.h>
2034 diff -NurpP --minimal linux-2.6.32.1/fs/binfmt_som.c linux-2.6.32.1-vs2.3.0.36.27/fs/binfmt_som.c
2035 --- linux-2.6.32.1/fs/binfmt_som.c      2009-06-11 17:13:02.000000000 +0200
2036 +++ linux-2.6.32.1-vs2.3.0.36.27/fs/binfmt_som.c        2009-12-03 20:04:56.000000000 +0100
2037 @@ -28,6 +28,7 @@
2038  #include <linux/shm.h>
2039  #include <linux/personality.h>
2040  #include <linux/init.h>
2041 +#include <linux/vs_memory.h>
2042  
2043  #include <asm/uaccess.h>
2044  #include <asm/pgtable.h>
2045 diff -NurpP --minimal linux-2.6.32.1/fs/block_dev.c linux-2.6.32.1-vs2.3.0.36.27/fs/block_dev.c
2046 --- linux-2.6.32.1/fs/block_dev.c       2009-12-03 20:02:51.000000000 +0100
2047 +++ linux-2.6.32.1-vs2.3.0.36.27/fs/block_dev.c 2009-12-03 20:04:56.000000000 +0100
2048 @@ -26,6 +26,7 @@
2049  #include <linux/namei.h>
2050  #include <linux/log2.h>
2051  #include <linux/kmemleak.h>
2052 +#include <linux/vs_device.h>
2053  #include <asm/uaccess.h>
2054  #include "internal.h"
2055  
2056 @@ -555,6 +556,7 @@ struct block_device *bdget(dev_t dev)
2057                 bdev->bd_invalidated = 0;
2058                 inode->i_mode = S_IFBLK;
2059                 inode->i_rdev = dev;
2060 +               inode->i_mdev = dev;
2061                 inode->i_bdev = bdev;
2062                 inode->i_data.a_ops = &def_blk_aops;
2063                 mapping_set_gfp_mask(&inode->i_data, GFP_USER);
2064 @@ -601,6 +603,11 @@ EXPORT_SYMBOL(bdput);
2065  static struct block_device *bd_acquire(struct inode *inode)
2066  {
2067         struct block_device *bdev;
2068 +       dev_t mdev;
2069 +
2070 +       if (!vs_map_blkdev(inode->i_rdev, &mdev, DATTR_OPEN))
2071 +               return NULL;
2072 +       inode->i_mdev = mdev;
2073  
2074         spin_lock(&bdev_lock);
2075         bdev = inode->i_bdev;
2076 @@ -611,7 +618,7 @@ static struct block_device *bd_acquire(s
2077         }
2078         spin_unlock(&bdev_lock);
2079  
2080 -       bdev = bdget(inode->i_rdev);
2081 +       bdev = bdget(mdev);
2082         if (bdev) {
2083                 spin_lock(&bdev_lock);
2084                 if (!inode->i_bdev) {
2085 diff -NurpP --minimal linux-2.6.32.1/fs/btrfs/ctree.h linux-2.6.32.1-vs2.3.0.36.27/fs/btrfs/ctree.h
2086 --- linux-2.6.32.1/fs/btrfs/ctree.h     2009-12-03 20:02:51.000000000 +0100
2087 +++ linux-2.6.32.1-vs2.3.0.36.27/fs/btrfs/ctree.h       2009-12-03 20:04:56.000000000 +0100
2088 @@ -544,11 +544,14 @@ struct btrfs_inode_item {
2089         /* modification sequence number for NFS */
2090         __le64 sequence;
2091  
2092 +       __le16 tag;
2093         /*
2094          * a little future expansion, for more than this we can
2095          * just grow the inode item and version it
2096          */
2097 -       __le64 reserved[4];
2098 +       __le16 reserved16;
2099 +       __le32 reserved32;
2100 +       __le64 reserved[3];
2101         struct btrfs_timespec atime;
2102         struct btrfs_timespec ctime;
2103         struct btrfs_timespec mtime;
2104 @@ -1155,6 +1158,8 @@ struct btrfs_root {
2105  #define BTRFS_MOUNT_NOSSD              (1 << 9)
2106  #define BTRFS_MOUNT_DISCARD            (1 << 10)
2107  
2108 +#define BTRFS_MOUNT_TAGGED             (1 << 24)
2109 +
2110  #define btrfs_clear_opt(o, opt)                ((o) &= ~BTRFS_MOUNT_##opt)
2111  #define btrfs_set_opt(o, opt)          ((o) |= BTRFS_MOUNT_##opt)
2112  #define btrfs_test_opt(root, opt)      ((root)->fs_info->mount_opt & \
2113 @@ -1174,6 +1179,10 @@ struct btrfs_root {
2114  #define BTRFS_INODE_NOATIME            (1 << 9)
2115  #define BTRFS_INODE_DIRSYNC            (1 << 10)
2116  
2117 +#define BTRFS_INODE_IXUNLINK           (1 << 24)
2118 +#define BTRFS_INODE_BARRIER            (1 << 25)
2119 +#define BTRFS_INODE_COW                        (1 << 26)
2120 +
2121  
2122  /* some macros to generate set/get funcs for the struct fields.  This
2123   * assumes there is a lefoo_to_cpu for every type, so lets make a simple
2124 @@ -1376,6 +1385,7 @@ BTRFS_SETGET_FUNCS(inode_block_group, st
2125  BTRFS_SETGET_FUNCS(inode_nlink, struct btrfs_inode_item, nlink, 32);
2126  BTRFS_SETGET_FUNCS(inode_uid, struct btrfs_inode_item, uid, 32);
2127  BTRFS_SETGET_FUNCS(inode_gid, struct btrfs_inode_item, gid, 32);
2128 +BTRFS_SETGET_FUNCS(inode_tag, struct btrfs_inode_item, tag, 16);
2129  BTRFS_SETGET_FUNCS(inode_mode, struct btrfs_inode_item, mode, 32);
2130  BTRFS_SETGET_FUNCS(inode_rdev, struct btrfs_inode_item, rdev, 64);
2131  BTRFS_SETGET_FUNCS(inode_flags, struct btrfs_inode_item, flags, 64);
2132 @@ -2338,6 +2348,7 @@ extern const struct dentry_operations bt
2133  long btrfs_ioctl(struct file *file, unsigned int cmd, unsigned long arg);
2134  void btrfs_update_iflags(struct inode *inode);
2135  void btrfs_inherit_iflags(struct inode *inode, struct inode *dir);
2136 +int btrfs_sync_flags(struct inode *inode, int, int);
2137  
2138  /* file.c */
2139  int btrfs_sync_file(struct file *file, struct dentry *dentry, int datasync);
2140 diff -NurpP --minimal linux-2.6.32.1/fs/btrfs/disk-io.c linux-2.6.32.1-vs2.3.0.36.27/fs/btrfs/disk-io.c
2141 --- linux-2.6.32.1/fs/btrfs/disk-io.c   2009-12-03 20:02:51.000000000 +0100
2142 +++ linux-2.6.32.1-vs2.3.0.36.27/fs/btrfs/disk-io.c     2009-12-03 20:04:56.000000000 +0100
2143 @@ -1723,6 +1723,9 @@ struct btrfs_root *open_ctree(struct sup
2144                 goto fail_iput;
2145         }
2146  
2147 +       if (btrfs_test_opt(tree_root, TAGGED))
2148 +               sb->s_flags |= MS_TAGGED;
2149 +
2150         features = btrfs_super_incompat_flags(disk_super) &
2151                 ~BTRFS_FEATURE_INCOMPAT_SUPP;
2152         if (features) {
2153 diff -NurpP --minimal linux-2.6.32.1/fs/btrfs/inode.c linux-2.6.32.1-vs2.3.0.36.27/fs/btrfs/inode.c
2154 --- linux-2.6.32.1/fs/btrfs/inode.c     2009-12-03 20:02:51.000000000 +0100
2155 +++ linux-2.6.32.1-vs2.3.0.36.27/fs/btrfs/inode.c       2009-12-03 20:04:56.000000000 +0100
2156 @@ -36,6 +36,8 @@
2157  #include <linux/xattr.h>
2158  #include <linux/posix_acl.h>
2159  #include <linux/falloc.h>
2160 +#include <linux/vs_tag.h>
2161 +
2162  #include "compat.h"
2163  #include "ctree.h"
2164  #include "disk-io.h"
2165 @@ -2242,6 +2244,8 @@ static void btrfs_read_locked_inode(stru
2166         int maybe_acls;
2167         u64 alloc_group_block;
2168         u32 rdev;
2169 +       uid_t uid;
2170 +       gid_t gid;
2171         int ret;
2172  
2173         path = btrfs_alloc_path();
2174 @@ -2258,8 +2262,13 @@ static void btrfs_read_locked_inode(stru
2175  
2176         inode->i_mode = btrfs_inode_mode(leaf, inode_item);
2177         inode->i_nlink = btrfs_inode_nlink(leaf, inode_item);
2178 -       inode->i_uid = btrfs_inode_uid(leaf, inode_item);
2179 -       inode->i_gid = btrfs_inode_gid(leaf, inode_item);
2180 +
2181 +       uid = btrfs_inode_uid(leaf, inode_item);
2182 +       gid = btrfs_inode_gid(leaf, inode_item);
2183 +       inode->i_uid = INOTAG_UID(DX_TAG(inode), uid, gid);
2184 +       inode->i_gid = INOTAG_GID(DX_TAG(inode), uid, gid);
2185 +       inode->i_tag = INOTAG_TAG(DX_TAG(inode), uid, gid,
2186 +               btrfs_inode_tag(leaf, inode_item));
2187         btrfs_i_size_write(inode, btrfs_inode_size(leaf, inode_item));
2188  
2189         tspec = btrfs_inode_atime(inode_item);
2190 @@ -2341,8 +2350,15 @@ static void fill_inode_item(struct btrfs
2191                             struct btrfs_inode_item *item,
2192                             struct inode *inode)
2193  {
2194 -       btrfs_set_inode_uid(leaf, item, inode->i_uid);
2195 -       btrfs_set_inode_gid(leaf, item, inode->i_gid);
2196 +       uid_t uid = TAGINO_UID(DX_TAG(inode), inode->i_uid, inode->i_tag);
2197 +       gid_t gid = TAGINO_GID(DX_TAG(inode), inode->i_gid, inode->i_tag);
2198 +
2199 +       btrfs_set_inode_uid(leaf, item, uid);
2200 +       btrfs_set_inode_gid(leaf, item, gid);
2201 +#ifdef CONFIG_TAGGING_INTERN
2202 +       btrfs_set_inode_tag(leaf, item, inode->i_tag);
2203 +#endif
2204 +
2205         btrfs_set_inode_size(leaf, item, BTRFS_I(inode)->disk_i_size);
2206         btrfs_set_inode_mode(leaf, item, inode->i_mode);
2207         btrfs_set_inode_nlink(leaf, item, inode->i_nlink);
2208 @@ -4065,6 +4081,7 @@ static struct inode *btrfs_new_inode(str
2209         } else
2210                 inode->i_gid = current_fsgid();
2211  
2212 +       inode->i_tag = dx_current_fstag(root->fs_info->sb);
2213         inode->i_mode = mode;
2214         inode->i_ino = objectid;
2215         inode_set_bytes(inode, 0);
2216 @@ -5836,6 +5853,7 @@ static const struct inode_operations btr
2217         .listxattr      = btrfs_listxattr,
2218         .removexattr    = btrfs_removexattr,
2219         .permission     = btrfs_permission,
2220 +       .sync_flags     = btrfs_sync_flags,
2221  };
2222  static const struct inode_operations btrfs_dir_ro_inode_operations = {
2223         .lookup         = btrfs_lookup,
2224 @@ -5911,6 +5929,7 @@ static const struct inode_operations btr
2225         .permission     = btrfs_permission,
2226         .fallocate      = btrfs_fallocate,
2227         .fiemap         = btrfs_fiemap,
2228 +       .sync_flags     = btrfs_sync_flags,
2229  };
2230  static const struct inode_operations btrfs_special_inode_operations = {
2231         .getattr        = btrfs_getattr,
2232 diff -NurpP --minimal linux-2.6.32.1/fs/btrfs/ioctl.c linux-2.6.32.1-vs2.3.0.36.27/fs/btrfs/ioctl.c
2233 --- linux-2.6.32.1/fs/btrfs/ioctl.c     2009-12-03 20:02:51.000000000 +0100
2234 +++ linux-2.6.32.1-vs2.3.0.36.27/fs/btrfs/ioctl.c       2009-12-03 20:04:56.000000000 +0100
2235 @@ -67,10 +67,13 @@ static unsigned int btrfs_flags_to_ioctl
2236  {
2237         unsigned int iflags = 0;
2238  
2239 -       if (flags & BTRFS_INODE_SYNC)
2240 -               iflags |= FS_SYNC_FL;
2241         if (flags & BTRFS_INODE_IMMUTABLE)
2242                 iflags |= FS_IMMUTABLE_FL;
2243 +       if (flags & BTRFS_INODE_IXUNLINK)
2244 +               iflags |= FS_IXUNLINK_FL;
2245 +
2246 +       if (flags & BTRFS_INODE_SYNC)
2247 +               iflags |= FS_SYNC_FL;
2248         if (flags & BTRFS_INODE_APPEND)
2249                 iflags |= FS_APPEND_FL;
2250         if (flags & BTRFS_INODE_NODUMP)
2251 @@ -80,28 +83,78 @@ static unsigned int btrfs_flags_to_ioctl
2252         if (flags & BTRFS_INODE_DIRSYNC)
2253                 iflags |= FS_DIRSYNC_FL;
2254  
2255 +       if (flags & BTRFS_INODE_BARRIER)
2256 +               iflags |= FS_BARRIER_FL;
2257 +       if (flags & BTRFS_INODE_COW)
2258 +               iflags |= FS_COW_FL;
2259         return iflags;
2260  }
2261  
2262  /*
2263 - * Update inode->i_flags based on the btrfs internal flags.
2264 + * Update inode->i_(v)flags based on the btrfs internal flags.
2265   */
2266  void btrfs_update_iflags(struct inode *inode)
2267  {
2268         struct btrfs_inode *ip = BTRFS_I(inode);
2269  
2270 -       inode->i_flags &= ~(S_SYNC|S_APPEND|S_IMMUTABLE|S_NOATIME|S_DIRSYNC);
2271 +       inode->i_flags &= ~(S_IMMUTABLE | S_IXUNLINK |
2272 +               S_SYNC | S_APPEND | S_NOATIME | S_DIRSYNC);
2273  
2274 -       if (ip->flags & BTRFS_INODE_SYNC)
2275 -               inode->i_flags |= S_SYNC;
2276         if (ip->flags & BTRFS_INODE_IMMUTABLE)
2277                 inode->i_flags |= S_IMMUTABLE;
2278 +       if (ip->flags & BTRFS_INODE_IXUNLINK)
2279 +               inode->i_flags |= S_IXUNLINK;
2280 +
2281 +       if (ip->flags & BTRFS_INODE_SYNC)
2282 +               inode->i_flags |= S_SYNC;
2283         if (ip->flags & BTRFS_INODE_APPEND)
2284                 inode->i_flags |= S_APPEND;
2285         if (ip->flags & BTRFS_INODE_NOATIME)
2286                 inode->i_flags |= S_NOATIME;
2287         if (ip->flags & BTRFS_INODE_DIRSYNC)
2288                 inode->i_flags |= S_DIRSYNC;
2289 +
2290 +       inode->i_vflags &= ~(V_BARRIER | V_COW);
2291 +
2292 +       if (ip->flags & BTRFS_INODE_BARRIER)
2293 +               inode->i_vflags |= V_BARRIER;
2294 +       if (ip->flags & BTRFS_INODE_COW)
2295 +               inode->i_vflags |= V_COW;
2296 +}
2297 +
2298 +/*
2299 + * Update btrfs internal flags from inode->i_(v)flags.
2300 + */
2301 +void btrfs_update_flags(struct inode *inode)
2302 +{
2303 +       struct btrfs_inode *ip = BTRFS_I(inode);
2304 +
2305 +       unsigned int flags = inode->i_flags;
2306 +       unsigned int vflags = inode->i_vflags;
2307 +
2308 +       ip->flags &= ~(BTRFS_INODE_SYNC | BTRFS_INODE_APPEND |
2309 +                       BTRFS_INODE_IMMUTABLE | BTRFS_INODE_IXUNLINK |
2310 +                       BTRFS_INODE_NOATIME | BTRFS_INODE_DIRSYNC |
2311 +                       BTRFS_INODE_BARRIER | BTRFS_INODE_COW);
2312 +
2313 +       if (flags & S_IMMUTABLE)
2314 +               ip->flags |= BTRFS_INODE_IMMUTABLE;
2315 +       if (flags & S_IXUNLINK)
2316 +               ip->flags |= BTRFS_INODE_IXUNLINK;
2317 +
2318 +       if (flags & S_SYNC)
2319 +               ip->flags |= BTRFS_INODE_SYNC;
2320 +       if (flags & S_APPEND)
2321 +               ip->flags |= BTRFS_INODE_APPEND;
2322 +       if (flags & S_NOATIME)
2323 +               ip->flags |= BTRFS_INODE_NOATIME;
2324 +       if (flags & S_DIRSYNC)
2325 +               ip->flags |= BTRFS_INODE_DIRSYNC;
2326 +
2327 +       if (vflags & V_BARRIER)
2328 +               ip->flags |= BTRFS_INODE_BARRIER;
2329 +       if (vflags & V_COW)
2330 +               ip->flags |= BTRFS_INODE_COW;
2331  }
2332  
2333  /*
2334 @@ -119,7 +172,7 @@ void btrfs_inherit_iflags(struct inode *
2335         flags = BTRFS_I(dir)->flags;
2336  
2337         if (S_ISREG(inode->i_mode))
2338 -               flags &= ~BTRFS_INODE_DIRSYNC;
2339 +               flags &= ~(BTRFS_INODE_DIRSYNC | BTRFS_INODE_BARRIER);
2340         else if (!S_ISDIR(inode->i_mode))
2341                 flags &= (BTRFS_INODE_NODUMP | BTRFS_INODE_NOATIME);
2342  
2343 @@ -127,6 +180,30 @@ void btrfs_inherit_iflags(struct inode *
2344         btrfs_update_iflags(inode);
2345  }
2346  
2347 +int btrfs_sync_flags(struct inode *inode, int flags, int vflags)
2348 +{
2349 +       struct btrfs_inode *ip = BTRFS_I(inode);
2350 +       struct btrfs_root *root = ip->root;
2351 +       struct btrfs_trans_handle *trans;
2352 +       int ret;
2353 +
2354 +       trans = btrfs_join_transaction(root, 1);
2355 +       BUG_ON(!trans);
2356 +
2357 +       inode->i_flags = flags;
2358 +       inode->i_vflags = vflags;
2359 +       btrfs_update_flags(inode);
2360 +
2361 +       ret = btrfs_update_inode(trans, root, inode);
2362 +       BUG_ON(ret);
2363 +
2364 +       btrfs_update_iflags(inode);
2365 +       inode->i_ctime = CURRENT_TIME;
2366 +       btrfs_end_transaction(trans, root);
2367 +
2368 +       return 0;
2369 +}
2370 +
2371  static int btrfs_ioctl_getflags(struct file *file, void __user *arg)
2372  {
2373         struct btrfs_inode *ip = BTRFS_I(file->f_path.dentry->d_inode);
2374 @@ -149,6 +226,7 @@ static int btrfs_ioctl_setflags(struct f
2375         if (copy_from_user(&flags, arg, sizeof(flags)))
2376                 return -EFAULT;
2377  
2378 +       /* maybe add FS_IXUNLINK_FL ? */
2379         if (flags & ~(FS_IMMUTABLE_FL | FS_APPEND_FL | \
2380                       FS_NOATIME_FL | FS_NODUMP_FL | \
2381                       FS_SYNC_FL | FS_DIRSYNC_FL))
2382 @@ -161,7 +239,8 @@ static int btrfs_ioctl_setflags(struct f
2383  
2384         flags = btrfs_mask_flags(inode->i_mode, flags);
2385         oldflags = btrfs_flags_to_ioctl(ip->flags);
2386 -       if ((flags ^ oldflags) & (FS_APPEND_FL | FS_IMMUTABLE_FL)) {
2387 +       if ((flags ^ oldflags) & (FS_APPEND_FL |
2388 +               FS_IMMUTABLE_FL | FS_IXUNLINK_FL)) {
2389                 if (!capable(CAP_LINUX_IMMUTABLE)) {
2390                         ret = -EPERM;
2391                         goto out_unlock;
2392 @@ -172,14 +251,19 @@ static int btrfs_ioctl_setflags(struct f
2393         if (ret)
2394                 goto out_unlock;
2395  
2396 -       if (flags & FS_SYNC_FL)
2397 -               ip->flags |= BTRFS_INODE_SYNC;
2398 -       else
2399 -               ip->flags &= ~BTRFS_INODE_SYNC;
2400         if (flags & FS_IMMUTABLE_FL)
2401                 ip->flags |= BTRFS_INODE_IMMUTABLE;
2402         else
2403                 ip->flags &= ~BTRFS_INODE_IMMUTABLE;
2404 +       if (flags & FS_IXUNLINK_FL)
2405 +               ip->flags |= BTRFS_INODE_IXUNLINK;
2406 +       else
2407 +               ip->flags &= ~BTRFS_INODE_IXUNLINK;
2408 +
2409 +       if (flags & FS_SYNC_FL)
2410 +               ip->flags |= BTRFS_INODE_SYNC;
2411 +       else
2412 +               ip->flags &= ~BTRFS_INODE_SYNC;
2413         if (flags & FS_APPEND_FL)
2414                 ip->flags |= BTRFS_INODE_APPEND;
2415         else
2416 diff -NurpP --minimal linux-2.6.32.1/fs/btrfs/super.c linux-2.6.32.1-vs2.3.0.36.27/fs/btrfs/super.c
2417 --- linux-2.6.32.1/fs/btrfs/super.c     2009-12-03 20:02:51.000000000 +0100
2418 +++ linux-2.6.32.1-vs2.3.0.36.27/fs/btrfs/super.c       2009-12-03 20:04:56.000000000 +0100
2419 @@ -67,7 +67,7 @@ enum {
2420         Opt_max_extent, Opt_max_inline, Opt_alloc_start, Opt_nobarrier,
2421         Opt_ssd, Opt_nossd, Opt_ssd_spread, Opt_thread_pool, Opt_noacl,
2422         Opt_compress, Opt_notreelog, Opt_ratio, Opt_flushoncommit,
2423 -       Opt_discard, Opt_err,
2424 +       Opt_tag, Opt_notag, Opt_tagid, Opt_discard, Opt_err,
2425  };
2426  
2427  static match_table_t tokens = {
2428 @@ -90,6 +90,9 @@ static match_table_t tokens = {
2429         {Opt_flushoncommit, "flushoncommit"},
2430         {Opt_ratio, "metadata_ratio=%d"},
2431         {Opt_discard, "discard"},
2432 +       {Opt_tag, "tag"},
2433 +       {Opt_notag, "notag"},
2434 +       {Opt_tagid, "tagid=%u"},
2435         {Opt_err, NULL},
2436  };
2437  
2438 @@ -262,6 +265,22 @@ int btrfs_parse_options(struct btrfs_roo
2439                 case Opt_discard:
2440                         btrfs_set_opt(info->mount_opt, DISCARD);
2441                         break;
2442 +#ifndef CONFIG_TAGGING_NONE
2443 +               case Opt_tag:
2444 +                       printk(KERN_INFO "btrfs: use tagging\n");
2445 +                       btrfs_set_opt(info->mount_opt, TAGGED);
2446 +                       break;
2447 +               case Opt_notag:
2448 +                       printk(KERN_INFO "btrfs: disabled tagging\n");
2449 +                       btrfs_clear_opt(info->mount_opt, TAGGED);
2450 +                       break;
2451 +#endif
2452 +#ifdef CONFIG_PROPAGATE
2453 +               case Opt_tagid:
2454 +                       /* use args[0] */
2455 +                       btrfs_set_opt(info->mount_opt, TAGGED);
2456 +                       break;
2457 +#endif
2458                 default:
2459                         break;
2460                 }
2461 @@ -575,6 +594,12 @@ static int btrfs_remount(struct super_bl
2462         if (ret)
2463                 return -EINVAL;
2464  
2465 +       if (btrfs_test_opt(root, TAGGED) && !(sb->s_flags & MS_TAGGED)) {
2466 +               printk("btrfs: %s: tagging not permitted on remount.\n",
2467 +                       sb->s_id);
2468 +               return -EINVAL;
2469 +       }
2470 +
2471         if ((*flags & MS_RDONLY) == (sb->s_flags & MS_RDONLY))
2472                 return 0;
2473  
2474 diff -NurpP --minimal linux-2.6.32.1/fs/char_dev.c linux-2.6.32.1-vs2.3.0.36.27/fs/char_dev.c
2475 --- linux-2.6.32.1/fs/char_dev.c        2009-12-03 20:02:51.000000000 +0100
2476 +++ linux-2.6.32.1-vs2.3.0.36.27/fs/char_dev.c  2009-12-03 20:04:56.000000000 +0100
2477 @@ -20,6 +20,8 @@
2478  #include <linux/cdev.h>
2479  #include <linux/mutex.h>
2480  #include <linux/backing-dev.h>
2481 +#include <linux/vs_context.h>
2482 +#include <linux/vs_device.h>
2483  
2484  #include "internal.h"
2485  
2486 @@ -368,14 +370,21 @@ static int chrdev_open(struct inode *ino
2487         struct cdev *p;
2488         struct cdev *new = NULL;
2489         int ret = 0;
2490 +       dev_t mdev;
2491 +
2492 +       if (!vs_map_chrdev(inode->i_rdev, &mdev, DATTR_OPEN))
2493 +               return -EPERM;
2494 +       inode->i_mdev = mdev;
2495  
2496         spin_lock(&cdev_lock);
2497         p = inode->i_cdev;
2498         if (!p) {
2499                 struct kobject *kobj;
2500                 int idx;
2501 +
2502                 spin_unlock(&cdev_lock);
2503 -               kobj = kobj_lookup(cdev_map, inode->i_rdev, &idx);
2504 +
2505 +               kobj = kobj_lookup(cdev_map, mdev, &idx);
2506                 if (!kobj)
2507                         return -ENXIO;
2508                 new = container_of(kobj, struct cdev, kobj);
2509 diff -NurpP --minimal linux-2.6.32.1/fs/dcache.c linux-2.6.32.1-vs2.3.0.36.27/fs/dcache.c
2510 --- linux-2.6.32.1/fs/dcache.c  2009-12-03 20:02:51.000000000 +0100
2511 +++ linux-2.6.32.1-vs2.3.0.36.27/fs/dcache.c    2009-12-03 20:04:56.000000000 +0100
2512 @@ -33,6 +33,7 @@
2513  #include <linux/bootmem.h>
2514  #include <linux/fs_struct.h>
2515  #include <linux/hardirq.h>
2516 +#include <linux/vs_limit.h>
2517  #include "internal.h"
2518  
2519  int sysctl_vfs_cache_pressure __read_mostly = 100;
2520 @@ -230,6 +231,8 @@ repeat:
2521                 return;
2522         }
2523  
2524 +       vx_dentry_dec(dentry);
2525 +
2526         /*
2527          * AV: ->d_delete() is _NOT_ allowed to block now.
2528          */
2529 @@ -321,6 +324,7 @@ static inline struct dentry * __dget_loc
2530  {
2531         atomic_inc(&dentry->d_count);
2532         dentry_lru_del_init(dentry);
2533 +       vx_dentry_inc(dentry);
2534         return dentry;
2535  }
2536  
2537 @@ -919,6 +923,9 @@ struct dentry *d_alloc(struct dentry * p
2538         struct dentry *dentry;
2539         char *dname;
2540  
2541 +       if (!vx_dentry_avail(1))
2542 +               return NULL;
2543 +
2544         dentry = kmem_cache_alloc(dentry_cache, GFP_KERNEL);
2545         if (!dentry)
2546                 return NULL;
2547 @@ -964,6 +971,7 @@ struct dentry *d_alloc(struct dentry * p
2548         if (parent)
2549                 list_add(&dentry->d_u.d_child, &parent->d_subdirs);
2550         dentry_stat.nr_dentry++;
2551 +       vx_dentry_inc(dentry);
2552         spin_unlock(&dcache_lock);
2553  
2554         return dentry;
2555 @@ -1407,6 +1415,7 @@ struct dentry * __d_lookup(struct dentry
2556                 }
2557  
2558                 atomic_inc(&dentry->d_count);
2559 +               vx_dentry_inc(dentry);
2560                 found = dentry;
2561                 spin_unlock(&dentry->d_lock);
2562                 break;
2563 diff -NurpP --minimal linux-2.6.32.1/fs/devpts/inode.c linux-2.6.32.1-vs2.3.0.36.27/fs/devpts/inode.c
2564 --- linux-2.6.32.1/fs/devpts/inode.c    2009-12-03 20:02:51.000000000 +0100
2565 +++ linux-2.6.32.1-vs2.3.0.36.27/fs/devpts/inode.c      2009-12-03 20:04:56.000000000 +0100
2566 @@ -24,6 +24,7 @@
2567  #include <linux/parser.h>
2568  #include <linux/fsnotify.h>
2569  #include <linux/seq_file.h>
2570 +#include <linux/vs_base.h>
2571  
2572  #define DEVPTS_DEFAULT_MODE 0600
2573  /*
2574 @@ -35,6 +36,20 @@
2575  #define DEVPTS_DEFAULT_PTMX_MODE 0000
2576  #define PTMX_MINOR     2
2577  
2578 +static int devpts_permission(struct inode *inode, int mask)
2579 +{
2580 +       int ret = -EACCES;
2581 +
2582 +       /* devpts is xid tagged */
2583 +       if (vx_check((xid_t)inode->i_tag, VS_WATCH_P | VS_IDENT))
2584 +               ret = generic_permission(inode, mask, NULL);
2585 +       return ret;
2586 +}
2587 +
2588 +static struct inode_operations devpts_file_inode_operations = {
2589 +       .permission     = devpts_permission,
2590 +};
2591 +
2592  extern int pty_limit;                  /* Config limit on Unix98 ptys */
2593  static DEFINE_MUTEX(allocated_ptys_lock);
2594  
2595 @@ -262,6 +277,25 @@ static int devpts_show_options(struct se
2596         return 0;
2597  }
2598  
2599 +static int devpts_filter(struct dentry *de)
2600 +{
2601 +       /* devpts is xid tagged */
2602 +       return vx_check((xid_t)de->d_inode->i_tag, VS_WATCH_P | VS_IDENT);
2603 +}
2604 +
2605 +static int devpts_readdir(struct file * filp, void * dirent, filldir_t filldir)
2606 +{
2607 +       return dcache_readdir_filter(filp, dirent, filldir, devpts_filter);
2608 +}
2609 +
2610 +static struct file_operations devpts_dir_operations = {
2611 +       .open           = dcache_dir_open,
2612 +       .release        = dcache_dir_close,
2613 +       .llseek         = dcache_dir_lseek,
2614 +       .read           = generic_read_dir,
2615 +       .readdir        = devpts_readdir,
2616 +};
2617 +
2618  static const struct super_operations devpts_sops = {
2619         .statfs         = simple_statfs,
2620         .remount_fs     = devpts_remount,
2621 @@ -301,12 +335,15 @@ devpts_fill_super(struct super_block *s,
2622         inode = new_inode(s);
2623         if (!inode)
2624                 goto free_fsi;
2625 +
2626         inode->i_ino = 1;
2627         inode->i_mtime = inode->i_atime = inode->i_ctime = CURRENT_TIME;
2628         inode->i_mode = S_IFDIR | S_IRUGO | S_IXUGO | S_IWUSR;
2629         inode->i_op = &simple_dir_inode_operations;
2630 -       inode->i_fop = &simple_dir_operations;
2631 +       inode->i_fop = &devpts_dir_operations;
2632         inode->i_nlink = 2;
2633 +       /* devpts is xid tagged */
2634 +       inode->i_tag = (tag_t)vx_current_xid();
2635  
2636         s->s_root = d_alloc_root(inode);
2637         if (s->s_root)
2638 @@ -497,6 +534,9 @@ int devpts_pty_new(struct inode *ptmx_in
2639         inode->i_gid = opts->setgid ? opts->gid : current_fsgid();
2640         inode->i_mtime = inode->i_atime = inode->i_ctime = CURRENT_TIME;
2641         init_special_inode(inode, S_IFCHR|opts->mode, device);
2642 +       /* devpts is xid tagged */
2643 +       inode->i_tag = (tag_t)vx_current_xid();
2644 +       inode->i_op = &devpts_file_inode_operations;
2645         inode->i_private = tty;
2646         tty->driver_data = inode;
2647  
2648 diff -NurpP --minimal linux-2.6.32.1/fs/exec.c linux-2.6.32.1-vs2.3.0.36.27/fs/exec.c
2649 --- linux-2.6.32.1/fs/exec.c    2009-12-03 20:02:51.000000000 +0100
2650 +++ linux-2.6.32.1-vs2.3.0.36.27/fs/exec.c      2009-12-03 20:04:56.000000000 +0100
2651 @@ -251,7 +251,9 @@ static int __bprm_mm_init(struct linux_b
2652         if (err)
2653                 goto err;
2654  
2655 -       mm->stack_vm = mm->total_vm = 1;
2656 +       mm->total_vm = 0;
2657 +       vx_vmpages_inc(mm);
2658 +       mm->stack_vm = 1;
2659         up_write(&mm->mmap_sem);
2660         bprm->p = vma->vm_end - sizeof(void *);
2661         return 0;
2662 @@ -1474,7 +1476,7 @@ static int format_corename(char *corenam
2663                         /* UNIX time of coredump */
2664                         case 't': {
2665                                 struct timeval tv;
2666 -                               do_gettimeofday(&tv);
2667 +                               vx_gettimeofday(&tv);
2668                                 rc = snprintf(out_ptr, out_end - out_ptr,
2669                                               "%lu", tv.tv_sec);
2670                                 if (rc > out_end - out_ptr)
2671 diff -NurpP --minimal linux-2.6.32.1/fs/ext2/balloc.c linux-2.6.32.1-vs2.3.0.36.27/fs/ext2/balloc.c
2672 --- linux-2.6.32.1/fs/ext2/balloc.c     2009-06-11 17:13:03.000000000 +0200
2673 +++ linux-2.6.32.1-vs2.3.0.36.27/fs/ext2/balloc.c       2009-12-03 20:04:56.000000000 +0100
2674 @@ -701,7 +701,6 @@ ext2_try_to_allocate(struct super_block 
2675                         start = 0;
2676                 end = EXT2_BLOCKS_PER_GROUP(sb);
2677         }
2678 -
2679         BUG_ON(start > EXT2_BLOCKS_PER_GROUP(sb));
2680  
2681  repeat:
2682 diff -NurpP --minimal linux-2.6.32.1/fs/ext2/ext2.h linux-2.6.32.1-vs2.3.0.36.27/fs/ext2/ext2.h
2683 --- linux-2.6.32.1/fs/ext2/ext2.h       2009-09-10 15:26:21.000000000 +0200
2684 +++ linux-2.6.32.1-vs2.3.0.36.27/fs/ext2/ext2.h 2009-12-03 20:04:56.000000000 +0100
2685 @@ -131,6 +131,7 @@ extern int ext2_fiemap(struct inode *ino
2686  int __ext2_write_begin(struct file *file, struct address_space *mapping,
2687                 loff_t pos, unsigned len, unsigned flags,
2688                 struct page **pagep, void **fsdata);
2689 +extern int ext2_sync_flags(struct inode *, int, int);
2690  
2691  /* ioctl.c */
2692  extern long ext2_ioctl(struct file *, unsigned int, unsigned long);
2693 diff -NurpP --minimal linux-2.6.32.1/fs/ext2/file.c linux-2.6.32.1-vs2.3.0.36.27/fs/ext2/file.c
2694 --- linux-2.6.32.1/fs/ext2/file.c       2009-12-03 20:02:51.000000000 +0100
2695 +++ linux-2.6.32.1-vs2.3.0.36.27/fs/ext2/file.c 2009-12-03 20:04:56.000000000 +0100
2696 @@ -87,4 +87,5 @@ const struct inode_operations ext2_file_
2697         .setattr        = ext2_setattr,
2698         .check_acl      = ext2_check_acl,
2699         .fiemap         = ext2_fiemap,
2700 +       .sync_flags     = ext2_sync_flags,
2701  };
2702 diff -NurpP --minimal linux-2.6.32.1/fs/ext2/ialloc.c linux-2.6.32.1-vs2.3.0.36.27/fs/ext2/ialloc.c
2703 --- linux-2.6.32.1/fs/ext2/ialloc.c     2009-06-11 17:13:03.000000000 +0200
2704 +++ linux-2.6.32.1-vs2.3.0.36.27/fs/ext2/ialloc.c       2009-12-03 20:04:56.000000000 +0100
2705 @@ -17,6 +17,7 @@
2706  #include <linux/backing-dev.h>
2707  #include <linux/buffer_head.h>
2708  #include <linux/random.h>
2709 +#include <linux/vs_tag.h>
2710  #include "ext2.h"
2711  #include "xattr.h"
2712  #include "acl.h"
2713 @@ -560,6 +561,7 @@ got:
2714         } else
2715                 inode->i_gid = current_fsgid();
2716         inode->i_mode = mode;
2717 +       inode->i_tag = dx_current_fstag(sb);
2718  
2719         inode->i_ino = ino;
2720         inode->i_blocks = 0;
2721 diff -NurpP --minimal linux-2.6.32.1/fs/ext2/inode.c linux-2.6.32.1-vs2.3.0.36.27/fs/ext2/inode.c
2722 --- linux-2.6.32.1/fs/ext2/inode.c      2009-12-03 20:02:51.000000000 +0100
2723 +++ linux-2.6.32.1-vs2.3.0.36.27/fs/ext2/inode.c        2009-12-03 20:04:56.000000000 +0100
2724 @@ -33,6 +33,7 @@
2725  #include <linux/mpage.h>
2726  #include <linux/fiemap.h>
2727  #include <linux/namei.h>
2728 +#include <linux/vs_tag.h>
2729  #include "ext2.h"
2730  #include "acl.h"
2731  #include "xip.h"
2732 @@ -1040,7 +1041,7 @@ void ext2_truncate(struct inode *inode)
2733                 return;
2734         if (ext2_inode_is_fast_symlink(inode))
2735                 return;
2736 -       if (IS_APPEND(inode) || IS_IMMUTABLE(inode))
2737 +       if (IS_APPEND(inode) || IS_IXORUNLINK(inode))
2738                 return;
2739  
2740         blocksize = inode->i_sb->s_blocksize;
2741 @@ -1178,36 +1179,61 @@ void ext2_set_inode_flags(struct inode *
2742  {
2743         unsigned int flags = EXT2_I(inode)->i_flags;
2744  
2745 -       inode->i_flags &= ~(S_SYNC|S_APPEND|S_IMMUTABLE|S_NOATIME|S_DIRSYNC);
2746 +       inode->i_flags &= ~(S_IMMUTABLE | S_IXUNLINK |
2747 +               S_SYNC | S_APPEND | S_NOATIME | S_DIRSYNC);
2748 +
2749 +
2750 +       if (flags & EXT2_IMMUTABLE_FL)
2751 +               inode->i_flags |= S_IMMUTABLE;
2752 +       if (flags & EXT2_IXUNLINK_FL)
2753 +               inode->i_flags |= S_IXUNLINK;
2754 +
2755         if (flags & EXT2_SYNC_FL)
2756                 inode->i_flags |= S_SYNC;
2757         if (flags & EXT2_APPEND_FL)
2758                 inode->i_flags |= S_APPEND;
2759 -       if (flags & EXT2_IMMUTABLE_FL)
2760 -               inode->i_flags |= S_IMMUTABLE;
2761         if (flags & EXT2_NOATIME_FL)
2762                 inode->i_flags |= S_NOATIME;
2763         if (flags & EXT2_DIRSYNC_FL)
2764                 inode->i_flags |= S_DIRSYNC;
2765 +
2766 +       inode->i_vflags &= ~(V_BARRIER | V_COW);
2767 +
2768 +       if (flags & EXT2_BARRIER_FL)
2769 +               inode->i_vflags |= V_BARRIER;
2770 +       if (flags & EXT2_COW_FL)
2771 +               inode->i_vflags |= V_COW;
2772  }
2773  
2774  /* Propagate flags from i_flags to EXT2_I(inode)->i_flags */
2775  void ext2_get_inode_flags(struct ext2_inode_info *ei)
2776  {
2777         unsigned int flags = ei->vfs_inode.i_flags;
2778 +       unsigned int vflags = ei->vfs_inode.i_vflags;
2779 +
2780 +       ei->i_flags &= ~(EXT2_SYNC_FL | EXT2_APPEND_FL |
2781 +                       EXT2_IMMUTABLE_FL | EXT2_IXUNLINK_FL |
2782 +                       EXT2_NOATIME_FL | EXT2_DIRSYNC_FL |
2783 +                       EXT2_BARRIER_FL | EXT2_COW_FL);
2784 +
2785 +       if (flags & S_IMMUTABLE)
2786 +               ei->i_flags |= EXT2_IMMUTABLE_FL;
2787 +       if (flags & S_IXUNLINK)
2788 +               ei->i_flags |= EXT2_IXUNLINK_FL;
2789  
2790 -       ei->i_flags &= ~(EXT2_SYNC_FL|EXT2_APPEND_FL|
2791 -                       EXT2_IMMUTABLE_FL|EXT2_NOATIME_FL|EXT2_DIRSYNC_FL);
2792         if (flags & S_SYNC)
2793                 ei->i_flags |= EXT2_SYNC_FL;
2794         if (flags & S_APPEND)
2795                 ei->i_flags |= EXT2_APPEND_FL;
2796 -       if (flags & S_IMMUTABLE)
2797 -               ei->i_flags |= EXT2_IMMUTABLE_FL;
2798         if (flags & S_NOATIME)
2799                 ei->i_flags |= EXT2_NOATIME_FL;
2800         if (flags & S_DIRSYNC)
2801                 ei->i_flags |= EXT2_DIRSYNC_FL;
2802 +
2803 +       if (vflags & V_BARRIER)
2804 +               ei->i_flags |= EXT2_BARRIER_FL;
2805 +       if (vflags & V_COW)
2806 +               ei->i_flags |= EXT2_COW_FL;
2807  }
2808  
2809  struct inode *ext2_iget (struct super_block *sb, unsigned long ino)
2810 @@ -1217,6 +1243,8 @@ struct inode *ext2_iget (struct super_bl
2811         struct ext2_inode *raw_inode;
2812         struct inode *inode;
2813         long ret = -EIO;
2814 +       uid_t uid;
2815 +       gid_t gid;
2816         int n;
2817  
2818         inode = iget_locked(sb, ino);
2819 @@ -1235,12 +1263,17 @@ struct inode *ext2_iget (struct super_bl
2820         }
2821  
2822         inode->i_mode = le16_to_cpu(raw_inode->i_mode);
2823 -       inode->i_uid = (uid_t)le16_to_cpu(raw_inode->i_uid_low);
2824 -       inode->i_gid = (gid_t)le16_to_cpu(raw_inode->i_gid_low);
2825 +       uid = (uid_t)le16_to_cpu(raw_inode->i_uid_low);
2826 +       gid = (gid_t)le16_to_cpu(raw_inode->i_gid_low);
2827         if (!(test_opt (inode->i_sb, NO_UID32))) {
2828 -               inode->i_uid |= le16_to_cpu(raw_inode->i_uid_high) << 16;
2829 -               inode->i_gid |= le16_to_cpu(raw_inode->i_gid_high) << 16;
2830 +               uid |= le16_to_cpu(raw_inode->i_uid_high) << 16;
2831 +               gid |= le16_to_cpu(raw_inode->i_gid_high) << 16;
2832         }
2833 +       inode->i_uid = INOTAG_UID(DX_TAG(inode), uid, gid);
2834 +       inode->i_gid = INOTAG_GID(DX_TAG(inode), uid, gid);
2835 +       inode->i_tag = INOTAG_TAG(DX_TAG(inode), uid, gid,
2836 +               le16_to_cpu(raw_inode->i_raw_tag));
2837 +
2838         inode->i_nlink = le16_to_cpu(raw_inode->i_links_count);
2839         inode->i_size = le32_to_cpu(raw_inode->i_size);
2840         inode->i_atime.tv_sec = (signed)le32_to_cpu(raw_inode->i_atime);
2841 @@ -1338,8 +1371,8 @@ int ext2_write_inode(struct inode *inode
2842         struct ext2_inode_info *ei = EXT2_I(inode);
2843         struct super_block *sb = inode->i_sb;
2844         ino_t ino = inode->i_ino;
2845 -       uid_t uid = inode->i_uid;
2846 -       gid_t gid = inode->i_gid;
2847 +       uid_t uid = TAGINO_UID(DX_TAG(inode), inode->i_uid, inode->i_tag);
2848 +       gid_t gid = TAGINO_GID(DX_TAG(inode), inode->i_gid, inode->i_tag);
2849         struct buffer_head * bh;
2850         struct ext2_inode * raw_inode = ext2_get_inode(sb, ino, &bh);
2851         int n;
2852 @@ -1375,6 +1408,9 @@ int ext2_write_inode(struct inode *inode
2853                 raw_inode->i_uid_high = 0;
2854                 raw_inode->i_gid_high = 0;
2855         }
2856 +#ifdef CONFIG_TAGGING_INTERN
2857 +       raw_inode->i_raw_tag = cpu_to_le16(inode->i_tag);
2858 +#endif
2859         raw_inode->i_links_count = cpu_to_le16(inode->i_nlink);
2860         raw_inode->i_size = cpu_to_le32(inode->i_size);
2861         raw_inode->i_atime = cpu_to_le32(inode->i_atime.tv_sec);
2862 @@ -1456,7 +1492,8 @@ int ext2_setattr(struct dentry *dentry, 
2863         if (error)
2864                 return error;
2865         if ((iattr->ia_valid & ATTR_UID && iattr->ia_uid != inode->i_uid) ||
2866 -           (iattr->ia_valid & ATTR_GID && iattr->ia_gid != inode->i_gid)) {
2867 +           (iattr->ia_valid & ATTR_GID && iattr->ia_gid != inode->i_gid) ||
2868 +           (iattr->ia_valid & ATTR_TAG && iattr->ia_tag != inode->i_tag)) {
2869                 error = vfs_dq_transfer(inode, iattr) ? -EDQUOT : 0;
2870                 if (error)
2871                         return error;
2872 diff -NurpP --minimal linux-2.6.32.1/fs/ext2/ioctl.c linux-2.6.32.1-vs2.3.0.36.27/fs/ext2/ioctl.c
2873 --- linux-2.6.32.1/fs/ext2/ioctl.c      2009-09-10 15:26:21.000000000 +0200
2874 +++ linux-2.6.32.1-vs2.3.0.36.27/fs/ext2/ioctl.c        2009-12-03 20:04:56.000000000 +0100
2875 @@ -17,6 +17,16 @@
2876  #include <asm/uaccess.h>
2877  
2878  
2879 +int ext2_sync_flags(struct inode *inode, int flags, int vflags)
2880 +{
2881 +       inode->i_flags = flags;
2882 +       inode->i_vflags = vflags;
2883 +       ext2_get_inode_flags(EXT2_I(inode));
2884 +       inode->i_ctime = CURRENT_TIME_SEC;
2885 +       mark_inode_dirty(inode);
2886 +       return 0;
2887 +}
2888 +
2889  long ext2_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
2890  {
2891         struct inode *inode = filp->f_dentry->d_inode;
2892 @@ -51,6 +61,11 @@ long ext2_ioctl(struct file *filp, unsig
2893  
2894                 flags = ext2_mask_flags(inode->i_mode, flags);
2895  
2896 +               if (IS_BARRIER(inode)) {
2897 +                       vxwprintk_task(1, "messing with the barrier.");
2898 +                       return -EACCES;
2899 +               }
2900 +
2901                 mutex_lock(&inode->i_mutex);
2902                 /* Is it quota file? Do not allow user to mess with it */
2903                 if (IS_NOQUOTA(inode)) {
2904 @@ -66,7 +81,9 @@ long ext2_ioctl(struct file *filp, unsig
2905                  *
2906                  * This test looks nicer. Thanks to Pauline Middelink
2907                  */
2908 -               if ((flags ^ oldflags) & (EXT2_APPEND_FL | EXT2_IMMUTABLE_FL)) {
2909 +               if ((oldflags & EXT2_IMMUTABLE_FL) ||
2910 +                       ((flags ^ oldflags) & (EXT2_APPEND_FL |
2911 +                       EXT2_IMMUTABLE_FL | EXT2_IXUNLINK_FL))) {
2912                         if (!capable(CAP_LINUX_IMMUTABLE)) {
2913                                 mutex_unlock(&inode->i_mutex);
2914                                 ret = -EPERM;
2915 @@ -74,7 +91,7 @@ long ext2_ioctl(struct file *filp, unsig
2916                         }
2917                 }
2918  
2919 -               flags = flags & EXT2_FL_USER_MODIFIABLE;
2920 +               flags &= EXT2_FL_USER_MODIFIABLE;
2921                 flags |= oldflags & ~EXT2_FL_USER_MODIFIABLE;
2922                 ei->i_flags = flags;
2923                 mutex_unlock(&inode->i_mutex);
2924 diff -NurpP --minimal linux-2.6.32.1/fs/ext2/namei.c linux-2.6.32.1-vs2.3.0.36.27/fs/ext2/namei.c
2925 --- linux-2.6.32.1/fs/ext2/namei.c      2009-12-03 20:02:51.000000000 +0100
2926 +++ linux-2.6.32.1-vs2.3.0.36.27/fs/ext2/namei.c        2009-12-03 20:04:56.000000000 +0100
2927 @@ -31,6 +31,7 @@
2928   */
2929  
2930  #include <linux/pagemap.h>
2931 +#include <linux/vs_tag.h>
2932  #include "ext2.h"
2933  #include "xattr.h"
2934  #include "acl.h"
2935 @@ -74,6 +75,7 @@ static struct dentry *ext2_lookup(struct
2936                                 return ERR_PTR(-EIO);
2937                         } else {
2938                                 return ERR_CAST(inode);
2939 +               dx_propagate_tag(nd, inode);
2940                         }
2941                 }
2942         }
2943 @@ -401,6 +403,7 @@ const struct inode_operations ext2_dir_i
2944  #endif
2945         .setattr        = ext2_setattr,
2946         .check_acl      = ext2_check_acl,
2947 +       .sync_flags     = ext2_sync_flags,
2948  };
2949  
2950  const struct inode_operations ext2_special_inode_operations = {
2951 diff -NurpP --minimal linux-2.6.32.1/fs/ext2/super.c linux-2.6.32.1-vs2.3.0.36.27/fs/ext2/super.c
2952 --- linux-2.6.32.1/fs/ext2/super.c      2009-09-10 15:26:21.000000000 +0200
2953 +++ linux-2.6.32.1-vs2.3.0.36.27/fs/ext2/super.c        2009-12-03 20:04:56.000000000 +0100
2954 @@ -382,7 +382,8 @@ enum {
2955         Opt_err_ro, Opt_nouid32, Opt_nocheck, Opt_debug,
2956         Opt_oldalloc, Opt_orlov, Opt_nobh, Opt_user_xattr, Opt_nouser_xattr,
2957         Opt_acl, Opt_noacl, Opt_xip, Opt_ignore, Opt_err, Opt_quota,
2958 -       Opt_usrquota, Opt_grpquota, Opt_reservation, Opt_noreservation
2959 +       Opt_usrquota, Opt_grpquota, Opt_reservation, Opt_noreservation,
2960 +       Opt_tag, Opt_notag, Opt_tagid
2961  };
2962  
2963  static const match_table_t tokens = {
2964 @@ -410,6 +411,9 @@ static const match_table_t tokens = {
2965         {Opt_acl, "acl"},
2966         {Opt_noacl, "noacl"},
2967         {Opt_xip, "xip"},
2968 +       {Opt_tag, "tag"},
2969 +       {Opt_notag, "notag"},
2970 +       {Opt_tagid, "tagid=%u"},
2971         {Opt_grpquota, "grpquota"},
2972         {Opt_ignore, "noquota"},
2973         {Opt_quota, "quota"},
2974 @@ -480,6 +484,20 @@ static int parse_options (char * options
2975                 case Opt_nouid32:
2976                         set_opt (sbi->s_mount_opt, NO_UID32);
2977                         break;
2978 +#ifndef CONFIG_TAGGING_NONE
2979 +               case Opt_tag:
2980 +                       set_opt (sbi->s_mount_opt, TAGGED);
2981 +                       break;
2982 +               case Opt_notag:
2983 +                       clear_opt (sbi->s_mount_opt, TAGGED);
2984 +                       break;
2985 +#endif
2986 +#ifdef CONFIG_PROPAGATE
2987 +               case Opt_tagid:
2988 +                       /* use args[0] */
2989 +                       set_opt (sbi->s_mount_opt, TAGGED);
2990 +                       break;
2991 +#endif
2992                 case Opt_nocheck:
2993                         clear_opt (sbi->s_mount_opt, CHECK);
2994                         break;
2995 @@ -829,6 +847,8 @@ static int ext2_fill_super(struct super_
2996         if (!parse_options ((char *) data, sbi))
2997                 goto failed_mount;
2998  
2999 +       if (EXT2_SB(sb)->s_mount_opt & EXT2_MOUNT_TAGGED)
3000 +               sb->s_flags |= MS_TAGGED;
3001         sb->s_flags = (sb->s_flags & ~MS_POSIXACL) |
3002                 ((EXT2_SB(sb)->s_mount_opt & EXT2_MOUNT_POSIX_ACL) ?
3003                  MS_POSIXACL : 0);
3004 @@ -1175,6 +1195,14 @@ static int ext2_remount (struct super_bl
3005                 goto restore_opts;
3006         }
3007  
3008 +       if ((sbi->s_mount_opt & EXT2_MOUNT_TAGGED) &&
3009 +               !(sb->s_flags & MS_TAGGED)) {
3010 +               printk("EXT2-fs: %s: tagging not permitted on remount.\n",
3011 +                      sb->s_id);
3012 +               err = -EINVAL;
3013 +               goto restore_opts;
3014 +       }
3015 +
3016         sb->s_flags = (sb->s_flags & ~MS_POSIXACL) |
3017                 ((sbi->s_mount_opt & EXT2_MOUNT_POSIX_ACL) ? MS_POSIXACL : 0);
3018  
3019 diff -NurpP --minimal linux-2.6.32.1/fs/ext3/file.c linux-2.6.32.1-vs2.3.0.36.27/fs/ext3/file.c
3020 --- linux-2.6.32.1/fs/ext3/file.c       2009-12-03 20:02:51.000000000 +0100
3021 +++ linux-2.6.32.1-vs2.3.0.36.27/fs/ext3/file.c 2009-12-03 20:04:56.000000000 +0100
3022 @@ -80,5 +80,6 @@ const struct inode_operations ext3_file_
3023  #endif
3024         .check_acl      = ext3_check_acl,
3025         .fiemap         = ext3_fiemap,
3026 +       .sync_flags     = ext3_sync_flags,
3027  };
3028  
3029 diff -NurpP --minimal linux-2.6.32.1/fs/ext3/ialloc.c linux-2.6.32.1-vs2.3.0.36.27/fs/ext3/ialloc.c
3030 --- linux-2.6.32.1/fs/ext3/ialloc.c     2009-09-10 15:26:21.000000000 +0200
3031 +++ linux-2.6.32.1-vs2.3.0.36.27/fs/ext3/ialloc.c       2009-12-03 20:04:56.000000000 +0100
3032 @@ -23,6 +23,7 @@
3033  #include <linux/buffer_head.h>
3034  #include <linux/random.h>
3035  #include <linux/bitops.h>
3036 +#include <linux/vs_tag.h>
3037  
3038  #include <asm/byteorder.h>
3039  
3040 @@ -548,6 +549,7 @@ got:
3041         } else
3042                 inode->i_gid = current_fsgid();
3043         inode->i_mode = mode;
3044 +       inode->i_tag = dx_current_fstag(sb);
3045  
3046         inode->i_ino = ino;
3047         /* This is the optimal IO size (for stat), not the fs block size */
3048 diff -NurpP --minimal linux-2.6.32.1/fs/ext3/inode.c linux-2.6.32.1-vs2.3.0.36.27/fs/ext3/inode.c
3049 --- linux-2.6.32.1/fs/ext3/inode.c      2009-12-03 20:02:51.000000000 +0100
3050 +++ linux-2.6.32.1-vs2.3.0.36.27/fs/ext3/inode.c        2009-12-03 20:04:56.000000000 +0100
3051 @@ -38,6 +38,7 @@
3052  #include <linux/bio.h>
3053  #include <linux/fiemap.h>
3054  #include <linux/namei.h>
3055 +#include <linux/vs_tag.h>
3056  #include "xattr.h"
3057  #include "acl.h"
3058  
3059 @@ -2333,7 +2334,7 @@ static void ext3_free_branches(handle_t 
3060  
3061  int ext3_can_truncate(struct inode *inode)
3062  {
3063 -       if (IS_APPEND(inode) || IS_IMMUTABLE(inode))
3064 +       if (IS_APPEND(inode) || IS_IXORUNLINK(inode))
3065                 return 0;
3066         if (S_ISREG(inode->i_mode))
3067                 return 1;
3068 @@ -2718,36 +2719,60 @@ void ext3_set_inode_flags(struct inode *
3069  {
3070         unsigned int flags = EXT3_I(inode)->i_flags;
3071  
3072 -       inode->i_flags &= ~(S_SYNC|S_APPEND|S_IMMUTABLE|S_NOATIME|S_DIRSYNC);
3073 +       inode->i_flags &= ~(S_IMMUTABLE | S_IXUNLINK |
3074 +               S_SYNC | S_APPEND | S_NOATIME | S_DIRSYNC);
3075 +
3076 +       if (flags & EXT3_IMMUTABLE_FL)
3077 +               inode->i_flags |= S_IMMUTABLE;
3078 +       if (flags & EXT3_IXUNLINK_FL)
3079 +               inode->i_flags |= S_IXUNLINK;
3080 +
3081         if (flags & EXT3_SYNC_FL)
3082                 inode->i_flags |= S_SYNC;
3083         if (flags & EXT3_APPEND_FL)
3084                 inode->i_flags |= S_APPEND;
3085 -       if (flags & EXT3_IMMUTABLE_FL)
3086 -               inode->i_flags |= S_IMMUTABLE;
3087         if (flags & EXT3_NOATIME_FL)
3088                 inode->i_flags |= S_NOATIME;
3089         if (flags & EXT3_DIRSYNC_FL)
3090                 inode->i_flags |= S_DIRSYNC;
3091 +
3092 +       inode->i_vflags &= ~(V_BARRIER | V_COW);
3093 +
3094 +       if (flags & EXT3_BARRIER_FL)
3095 +               inode->i_vflags |= V_BARRIER;
3096 +       if (flags & EXT3_COW_FL)
3097 +               inode->i_vflags |= V_COW;
3098  }
3099  
3100  /* Propagate flags from i_flags to EXT3_I(inode)->i_flags */
3101  void ext3_get_inode_flags(struct ext3_inode_info *ei)
3102  {
3103         unsigned int flags = ei->vfs_inode.i_flags;
3104 +       unsigned int vflags = ei->vfs_inode.i_vflags;
3105 +
3106 +       ei->i_flags &= ~(EXT3_SYNC_FL | EXT3_APPEND_FL |
3107 +                       EXT3_IMMUTABLE_FL | EXT3_IXUNLINK_FL |
3108 +                       EXT3_NOATIME_FL | EXT3_DIRSYNC_FL |
3109 +                       EXT3_BARRIER_FL | EXT3_COW_FL);
3110 +
3111 +       if (flags & S_IMMUTABLE)
3112 +               ei->i_flags |= EXT3_IMMUTABLE_FL;
3113 +       if (flags & S_IXUNLINK)
3114 +               ei->i_flags |= EXT3_IXUNLINK_FL;
3115  
3116 -       ei->i_flags &= ~(EXT3_SYNC_FL|EXT3_APPEND_FL|
3117 -                       EXT3_IMMUTABLE_FL|EXT3_NOATIME_FL|EXT3_DIRSYNC_FL);
3118         if (flags & S_SYNC)
3119                 ei->i_flags |= EXT3_SYNC_FL;
3120         if (flags & S_APPEND)
3121                 ei->i_flags |= EXT3_APPEND_FL;
3122 -       if (flags & S_IMMUTABLE)
3123 -               ei->i_flags |= EXT3_IMMUTABLE_FL;
3124         if (flags & S_NOATIME)
3125                 ei->i_flags |= EXT3_NOATIME_FL;
3126         if (flags & S_DIRSYNC)
3127                 ei->i_flags |= EXT3_DIRSYNC_FL;
3128 +
3129 +       if (vflags & V_BARRIER)
3130 +               ei->i_flags |= EXT3_BARRIER_FL;
3131 +       if (vflags & V_COW)
3132 +               ei->i_flags |= EXT3_COW_FL;
3133  }
3134  
3135  struct inode *ext3_iget(struct super_block *sb, unsigned long ino)
3136 @@ -2761,6 +2786,8 @@ struct inode *ext3_iget(struct super_blo
3137         transaction_t *transaction;
3138         long ret;
3139         int block;
3140 +       uid_t uid;
3141 +       gid_t gid;
3142  
3143         inode = iget_locked(sb, ino);
3144         if (!inode)
3145 @@ -2777,12 +2804,17 @@ struct inode *ext3_iget(struct super_blo
3146         bh = iloc.bh;
3147         raw_inode = ext3_raw_inode(&iloc);
3148         inode->i_mode = le16_to_cpu(raw_inode->i_mode);
3149 -       inode->i_uid = (uid_t)le16_to_cpu(raw_inode->i_uid_low);
3150 -       inode->i_gid = (gid_t)le16_to_cpu(raw_inode->i_gid_low);
3151 +       uid = (uid_t)le16_to_cpu(raw_inode->i_uid_low);
3152 +       gid = (gid_t)le16_to_cpu(raw_inode->i_gid_low);
3153         if(!(test_opt (inode->i_sb, NO_UID32))) {
3154 -               inode->i_uid |= le16_to_cpu(raw_inode->i_uid_high) << 16;
3155 -               inode->i_gid |= le16_to_cpu(raw_inode->i_gid_high) << 16;
3156 +               uid |= le16_to_cpu(raw_inode->i_uid_high) << 16;
3157 +               gid |= le16_to_cpu(raw_inode->i_gid_high) << 16;
3158         }
3159 +       inode->i_uid = INOTAG_UID(DX_TAG(inode), uid, gid);
3160 +       inode->i_gid = INOTAG_GID(DX_TAG(inode), uid, gid);
3161 +       inode->i_tag = INOTAG_TAG(DX_TAG(inode), uid, gid,
3162 +               le16_to_cpu(raw_inode->i_raw_tag));
3163 +
3164         inode->i_nlink = le16_to_cpu(raw_inode->i_links_count);
3165         inode->i_size = le32_to_cpu(raw_inode->i_size);
3166         inode->i_atime.tv_sec = (signed)le32_to_cpu(raw_inode->i_atime);
3167 @@ -2937,6 +2969,8 @@ static int ext3_do_update_inode(handle_t
3168         struct ext3_inode *raw_inode = ext3_raw_inode(iloc);
3169         struct ext3_inode_info *ei = EXT3_I(inode);
3170         struct buffer_head *bh = iloc->bh;
3171 +       uid_t uid = TAGINO_UID(DX_TAG(inode), inode->i_uid, inode->i_tag);
3172 +       gid_t gid = TAGINO_GID(DX_TAG(inode), inode->i_gid, inode->i_tag);
3173         int err = 0, rc, block;
3174  
3175  again:
3176 @@ -2951,29 +2985,32 @@ again:
3177         ext3_get_inode_flags(ei);
3178         raw_inode->i_mode = cpu_to_le16(inode->i_mode);
3179         if(!(test_opt(inode->i_sb, NO_UID32))) {
3180 -               raw_inode->i_uid_low = cpu_to_le16(low_16_bits(inode->i_uid));
3181 -               raw_inode->i_gid_low = cpu_to_le16(low_16_bits(inode->i_gid));
3182 +               raw_inode->i_uid_low = cpu_to_le16(low_16_bits(uid));
3183 +               raw_inode->i_gid_low = cpu_to_le16(low_16_bits(gid));
3184  /*
3185   * Fix up interoperability with old kernels. Otherwise, old inodes get
3186   * re-used with the upper 16 bits of the uid/gid intact
3187   */
3188                 if(!ei->i_dtime) {
3189                         raw_inode->i_uid_high =
3190 -                               cpu_to_le16(high_16_bits(inode->i_uid));
3191 +                               cpu_to_le16(high_16_bits(uid));
3192                         raw_inode->i_gid_high =
3193 -                               cpu_to_le16(high_16_bits(inode->i_gid));
3194 +                               cpu_to_le16(high_16_bits(gid));
3195                 } else {
3196                         raw_inode->i_uid_high = 0;
3197                         raw_inode->i_gid_high = 0;
3198                 }
3199         } else {
3200                 raw_inode->i_uid_low =
3201 -                       cpu_to_le16(fs_high2lowuid(inode->i_uid));
3202 +                       cpu_to_le16(fs_high2lowuid(uid));
3203                 raw_inode->i_gid_low =
3204 -                       cpu_to_le16(fs_high2lowgid(inode->i_gid));
3205 +                       cpu_to_le16(fs_high2lowgid(gid));
3206                 raw_inode->i_uid_high = 0;
3207                 raw_inode->i_gid_high = 0;
3208         }
3209 +#ifdef CONFIG_TAGGING_INTERN
3210 +       raw_inode->i_raw_tag = cpu_to_le16(inode->i_tag);
3211 +#endif
3212         raw_inode->i_links_count = cpu_to_le16(inode->i_nlink);
3213         raw_inode->i_size = cpu_to_le32(ei->i_disksize);
3214         raw_inode->i_atime = cpu_to_le32(inode->i_atime.tv_sec);
3215 @@ -3131,7 +3168,8 @@ int ext3_setattr(struct dentry *dentry, 
3216                 return error;
3217  
3218         if ((ia_valid & ATTR_UID && attr->ia_uid != inode->i_uid) ||
3219 -               (ia_valid & ATTR_GID && attr->ia_gid != inode->i_gid)) {
3220 +               (ia_valid & ATTR_GID && attr->ia_gid != inode->i_gid) ||
3221 +               (ia_valid & ATTR_TAG && attr->ia_tag != inode->i_tag)) {
3222                 handle_t *handle;
3223  
3224                 /* (user+group)*(old+new) structure, inode write (sb,
3225 @@ -3153,6 +3191,8 @@ int ext3_setattr(struct dentry *dentry, 
3226                         inode->i_uid = attr->ia_uid;
3227                 if (attr->ia_valid & ATTR_GID)
3228                         inode->i_gid = attr->ia_gid;
3229 +               if ((attr->ia_valid & ATTR_TAG) && IS_TAGGED(inode))
3230 +                       inode->i_tag = attr->ia_tag;
3231                 error = ext3_mark_inode_dirty(handle, inode);
3232                 ext3_journal_stop(handle);
3233         }
3234 diff -NurpP --minimal linux-2.6.32.1/fs/ext3/ioctl.c linux-2.6.32.1-vs2.3.0.36.27/fs/ext3/ioctl.c
3235 --- linux-2.6.32.1/fs/ext3/ioctl.c      2009-06-11 17:13:03.000000000 +0200
3236 +++ linux-2.6.32.1-vs2.3.0.36.27/fs/ext3/ioctl.c        2009-12-03 20:04:56.000000000 +0100
3237 @@ -8,6 +8,7 @@
3238   */
3239  
3240  #include <linux/fs.h>
3241 +#include <linux/mount.h>
3242  #include <linux/jbd.h>
3243  #include <linux/capability.h>
3244  #include <linux/ext3_fs.h>
3245 @@ -17,6 +18,34 @@
3246  #include <linux/compat.h>
3247  #include <asm/uaccess.h>
3248  
3249 +
3250 +int ext3_sync_flags(struct inode *inode, int flags, int vflags)
3251 +{
3252 +       handle_t *handle = NULL;
3253 +       struct ext3_iloc iloc;
3254 +       int err;
3255 +
3256 +       handle = ext3_journal_start(inode, 1);
3257 +       if (IS_ERR(handle))
3258 +               return PTR_ERR(handle);
3259 +
3260 +       if (IS_SYNC(inode))
3261 +               handle->h_sync = 1;
3262 +       err = ext3_reserve_inode_write(handle, inode, &iloc);
3263 +       if (err)
3264 +               goto flags_err;
3265 +
3266 +       inode->i_flags = flags;
3267 +       inode->i_vflags = vflags;
3268 +       ext3_get_inode_flags(EXT3_I(inode));
3269 +       inode->i_ctime = CURRENT_TIME_SEC;
3270 +
3271 +       err = ext3_mark_iloc_dirty(handle, inode, &iloc);
3272 +flags_err:
3273 +       ext3_journal_stop(handle);
3274 +       return err;
3275 +}
3276 +
3277  long ext3_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
3278  {
3279         struct inode *inode = filp->f_dentry->d_inode;
3280 @@ -50,6 +79,11 @@ long ext3_ioctl(struct file *filp, unsig
3281  
3282                 flags = ext3_mask_flags(inode->i_mode, flags);
3283  
3284 +               if (IS_BARRIER(inode)) {
3285 +                       vxwprintk_task(1, "messing with the barrier.");
3286 +                       return -EACCES;
3287 +               }
3288 +
3289                 mutex_lock(&inode->i_mutex);
3290  
3291                 /* Is it quota file? Do not allow user to mess with it */
3292 @@ -68,7 +102,9 @@ long ext3_ioctl(struct file *filp, unsig
3293                  *
3294                  * This test looks nicer. Thanks to Pauline Middelink
3295                  */
3296 -               if ((flags ^ oldflags) & (EXT3_APPEND_FL | EXT3_IMMUTABLE_FL)) {
3297 +               if ((oldflags & EXT3_IMMUTABLE_FL) ||
3298 +                       ((flags ^ oldflags) & (EXT3_APPEND_FL |
3299 +                       EXT3_IMMUTABLE_FL | EXT3_IXUNLINK_FL))) {
3300                         if (!capable(CAP_LINUX_IMMUTABLE))
3301                                 goto flags_out;
3302                 }
3303 @@ -93,7 +129,7 @@ long ext3_ioctl(struct file *filp, unsig
3304                 if (err)
3305                         goto flags_err;
3306  
3307 -               flags = flags & EXT3_FL_USER_MODIFIABLE;
3308 +               flags &= EXT3_FL_USER_MODIFIABLE;
3309                 flags |= oldflags & ~EXT3_FL_USER_MODIFIABLE;
3310                 ei->i_flags = flags;
3311  
3312 diff -NurpP --minimal linux-2.6.32.1/fs/ext3/namei.c linux-2.6.32.1-vs2.3.0.36.27/fs/ext3/namei.c
3313 --- linux-2.6.32.1/fs/ext3/namei.c      2009-12-03 20:02:51.000000000 +0100
3314 +++ linux-2.6.32.1-vs2.3.0.36.27/fs/ext3/namei.c        2009-12-03 20:04:56.000000000 +0100
3315 @@ -36,6 +36,7 @@
3316  #include <linux/quotaops.h>
3317  #include <linux/buffer_head.h>
3318  #include <linux/bio.h>
3319 +#include <linux/vs_tag.h>
3320  
3321  #include "namei.h"
3322  #include "xattr.h"
3323 @@ -912,6 +913,7 @@ restart:
3324                                 if (bh)
3325                                         ll_rw_block(READ_META, 1, &bh);
3326                         }
3327 +               dx_propagate_tag(nd, inode);
3328                 }
3329                 if ((bh = bh_use[ra_ptr++]) == NULL)
3330                         goto next;
3331 @@ -2446,6 +2448,7 @@ const struct inode_operations ext3_dir_i
3332         .removexattr    = generic_removexattr,
3333  #endif
3334         .check_acl      = ext3_check_acl,
3335 +       .sync_flags     = ext3_sync_flags,
3336  };
3337  
3338  const struct inode_operations ext3_special_inode_operations = {
3339 diff -NurpP --minimal linux-2.6.32.1/fs/ext3/super.c linux-2.6.32.1-vs2.3.0.36.27/fs/ext3/super.c
3340 --- linux-2.6.32.1/fs/ext3/super.c      2009-12-03 20:02:51.000000000 +0100
3341 +++ linux-2.6.32.1-vs2.3.0.36.27/fs/ext3/super.c        2009-12-03 20:04:56.000000000 +0100
3342 @@ -789,7 +789,7 @@ enum {
3343         Opt_usrjquota, Opt_grpjquota, Opt_offusrjquota, Opt_offgrpjquota,
3344         Opt_jqfmt_vfsold, Opt_jqfmt_vfsv0, Opt_quota, Opt_noquota,
3345         Opt_ignore, Opt_barrier, Opt_err, Opt_resize, Opt_usrquota,
3346 -       Opt_grpquota
3347 +       Opt_grpquota, Opt_tag, Opt_notag, Opt_tagid
3348  };
3349  
3350  static const match_table_t tokens = {
3351 @@ -842,6 +842,9 @@ static const match_table_t tokens = {
3352         {Opt_usrquota, "usrquota"},
3353         {Opt_barrier, "barrier=%u"},
3354         {Opt_resize, "resize"},
3355 +       {Opt_tag, "tag"},
3356 +       {Opt_notag, "notag"},
3357 +       {Opt_tagid, "tagid=%u"},
3358         {Opt_err, NULL},
3359  };
3360  
3361 @@ -934,6 +937,20 @@ static int parse_options (char *options,
3362                 case Opt_nouid32:
3363                         set_opt (sbi->s_mount_opt, NO_UID32);
3364                         break;
3365 +#ifndef CONFIG_TAGGING_NONE
3366 +               case Opt_tag:
3367 +                       set_opt (sbi->s_mount_opt, TAGGED);
3368 +                       break;
3369 +               case Opt_notag:
3370 +                       clear_opt (sbi->s_mount_opt, TAGGED);
3371 +                       break;
3372 +#endif
3373 +#ifdef CONFIG_PROPAGATE
3374 +               case Opt_tagid:
3375 +                       /* use args[0] */
3376 +                       set_opt (sbi->s_mount_opt, TAGGED);
3377 +                       break;
3378 +#endif
3379                 case Opt_nocheck:
3380                         clear_opt (sbi->s_mount_opt, CHECK);
3381                         break;
3382 @@ -1658,6 +1675,9 @@ static int ext3_fill_super (struct super
3383                             NULL, 0))
3384                 goto failed_mount;
3385  
3386 +       if (EXT3_SB(sb)->s_mount_opt & EXT3_MOUNT_TAGGED)
3387 +               sb->s_flags |= MS_TAGGED;
3388 +
3389         sb->s_flags = (sb->s_flags & ~MS_POSIXACL) |
3390                 ((sbi->s_mount_opt & EXT3_MOUNT_POSIX_ACL) ? MS_POSIXACL : 0);
3391  
3392 @@ -2527,6 +2547,14 @@ static int ext3_remount (struct super_bl
3393         if (sbi->s_mount_opt & EXT3_MOUNT_ABORT)
3394                 ext3_abort(sb, __func__, "Abort forced by user");
3395  
3396 +       if ((sbi->s_mount_opt & EXT3_MOUNT_TAGGED) &&
3397 +               !(sb->s_flags & MS_TAGGED)) {
3398 +               printk("EXT3-fs: %s: tagging not permitted on remount.\n",
3399 +                       sb->s_id);
3400 +               err = -EINVAL;
3401 +               goto restore_opts;
3402 +       }
3403 +
3404         sb->s_flags = (sb->s_flags & ~MS_POSIXACL) |
3405                 ((sbi->s_mount_opt & EXT3_MOUNT_POSIX_ACL) ? MS_POSIXACL : 0);
3406  
3407 diff -NurpP --minimal linux-2.6.32.1/fs/ext4/ext4.h linux-2.6.32.1-vs2.3.0.36.27/fs/ext4/ext4.h
3408 --- linux-2.6.32.1/fs/ext4/ext4.h       2009-12-14 21:29:46.000000000 +0100
3409 +++ linux-2.6.32.1-vs2.3.0.36.27/fs/ext4/ext4.h 2009-12-14 22:20:55.000000000 +0100
3410 @@ -284,8 +284,12 @@ struct flex_groups {
3411  #define EXT4_TOPDIR_FL                 0x00020000 /* Top of directory hierarchies*/
3412  #define EXT4_HUGE_FILE_FL               0x00040000 /* Set to each huge file */
3413  #define EXT4_EXTENTS_FL                        0x00080000 /* Inode uses extents */
3414 +#define EXT4_IXUNLINK_FL               0x08000000 /* Immutable invert on unlink */
3415  #define EXT4_RESERVED_FL               0x80000000 /* reserved for ext4 lib */
3416  
3417 +#define EXT4_BARRIER_FL                        0x04000000 /* Barrier for chroot() */
3418 +#define EXT4_COW_FL                    0x20000000 /* Copy on Write marker */
3419 +
3420  #define EXT4_FL_USER_VISIBLE           0x000BDFFF /* User visible flags */
3421  #define EXT4_FL_USER_MODIFIABLE                0x000B80FF /* User modifiable flags */
3422  
3423 @@ -469,7 +473,8 @@ struct ext4_inode {
3424                         __le16  l_i_file_acl_high;
3425                         __le16  l_i_uid_high;   /* these 2 fields */
3426                         __le16  l_i_gid_high;   /* were reserved2[0] */
3427 -                       __u32   l_i_reserved2;
3428 +                       __le16  l_i_tag;        /* Context Tag */
3429 +                       __u16   l_i_reserved2;
3430                 } linux2;
3431                 struct {
3432                         __le16  h_i_reserved1;  /* Obsoleted fragment number/size which are removed in ext4 */
3433 @@ -583,6 +588,7 @@ do {                                                                               \
3434  #define i_gid_low      i_gid
3435  #define i_uid_high     osd2.linux2.l_i_uid_high
3436  #define i_gid_high     osd2.linux2.l_i_gid_high
3437 +#define i_raw_tag      osd2.linux2.l_i_tag
3438  #define i_reserved2    osd2.linux2.l_i_reserved2
3439  
3440  #elif defined(__GNU__)
3441 @@ -751,6 +757,7 @@ struct ext4_inode_info {
3442  #define EXT4_MOUNT_QUOTA               0x80000 /* Some quota option set */
3443  #define EXT4_MOUNT_USRQUOTA            0x100000 /* "old" user quota */
3444  #define EXT4_MOUNT_GRPQUOTA            0x200000 /* "old" group quota */
3445 +#define EXT4_MOUNT_TAGGED              0x400000 /* Enable Context Tags */
3446  #define EXT4_MOUNT_JOURNAL_CHECKSUM    0x800000 /* Journal checksums */
3447  #define EXT4_MOUNT_JOURNAL_ASYNC_COMMIT        0x1000000 /* Journal Async Commit */
3448  #define EXT4_MOUNT_I_VERSION            0x2000000 /* i_version support */
3449 @@ -1742,6 +1749,7 @@ extern int ext4_get_blocks(handle_t *han
3450                            struct buffer_head *bh, int flags);
3451  extern int ext4_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo,
3452                         __u64 start, __u64 len);
3453 +extern int ext4_sync_flags(struct inode *, int, int);
3454  /* move_extent.c */
3455  extern int ext4_move_extents(struct file *o_filp, struct file *d_filp,
3456                              __u64 start_orig, __u64 start_donor,
3457 diff -NurpP --minimal linux-2.6.32.1/fs/ext4/file.c linux-2.6.32.1-vs2.3.0.36.27/fs/ext4/file.c
3458 --- linux-2.6.32.1/fs/ext4/file.c       2009-12-03 20:02:51.000000000 +0100
3459 +++ linux-2.6.32.1-vs2.3.0.36.27/fs/ext4/file.c 2009-12-03 20:04:56.000000000 +0100
3460 @@ -161,5 +161,6 @@ const struct inode_operations ext4_file_
3461         .check_acl      = ext4_check_acl,
3462         .fallocate      = ext4_fallocate,
3463         .fiemap         = ext4_fiemap,
3464 +       .sync_flags     = ext4_sync_flags,
3465  };
3466  
3467 diff -NurpP --minimal linux-2.6.32.1/fs/ext4/ialloc.c linux-2.6.32.1-vs2.3.0.36.27/fs/ext4/ialloc.c
3468 --- linux-2.6.32.1/fs/ext4/ialloc.c     2009-12-03 20:02:51.000000000 +0100
3469 +++ linux-2.6.32.1-vs2.3.0.36.27/fs/ext4/ialloc.c       2009-12-03 20:04:56.000000000 +0100
3470 @@ -22,6 +22,7 @@
3471  #include <linux/random.h>
3472  #include <linux/bitops.h>
3473  #include <linux/blkdev.h>
3474 +#include <linux/vs_tag.h>
3475  #include <asm/byteorder.h>
3476  
3477  #include "ext4.h"
3478 @@ -995,6 +996,7 @@ got:
3479         } else
3480                 inode->i_gid = current_fsgid();
3481         inode->i_mode = mode;
3482 +       inode->i_tag = dx_current_fstag(sb);
3483  
3484         inode->i_ino = ino + group * EXT4_INODES_PER_GROUP(sb);
3485         /* This is the optimal IO size (for stat), not the fs block size */
3486 diff -NurpP --minimal linux-2.6.32.1/fs/ext4/inode.c linux-2.6.32.1-vs2.3.0.36.27/fs/ext4/inode.c
3487 --- linux-2.6.32.1/fs/ext4/inode.c      2009-12-14 21:29:46.000000000 +0100
3488 +++ linux-2.6.32.1-vs2.3.0.36.27/fs/ext4/inode.c        2009-12-14 22:20:55.000000000 +0100
3489 @@ -38,6 +38,7 @@
3490  #include <linux/uio.h>
3491  #include <linux/bio.h>
3492  #include <linux/workqueue.h>
3493 +#include <linux/vs_tag.h>
3494  
3495  #include "ext4_jbd2.h"
3496  #include "xattr.h"
3497 @@ -4384,7 +4385,7 @@ static void ext4_free_branches(handle_t 
3498  
3499  int ext4_can_truncate(struct inode *inode)
3500  {
3501 -       if (IS_APPEND(inode) || IS_IMMUTABLE(inode))
3502 +       if (IS_APPEND(inode) || IS_IXORUNLINK(inode))
3503                 return 0;
3504         if (S_ISREG(inode->i_mode))
3505                 return 1;
3506 @@ -4735,36 +4736,60 @@ void ext4_set_inode_flags(struct inode *
3507  {
3508         unsigned int flags = EXT4_I(inode)->i_flags;
3509  
3510 -       inode->i_flags &= ~(S_SYNC|S_APPEND|S_IMMUTABLE|S_NOATIME|S_DIRSYNC);
3511 +       inode->i_flags &= ~(S_IMMUTABLE | S_IXUNLINK |
3512 +               S_SYNC | S_APPEND | S_NOATIME | S_DIRSYNC);
3513 +
3514 +       if (flags & EXT4_IMMUTABLE_FL)
3515 +               inode->i_flags |= S_IMMUTABLE;
3516 +       if (flags & EXT4_IXUNLINK_FL)
3517 +               inode->i_flags |= S_IXUNLINK;
3518 +
3519         if (flags & EXT4_SYNC_FL)
3520                 inode->i_flags |= S_SYNC;
3521         if (flags & EXT4_APPEND_FL)
3522                 inode->i_flags |= S_APPEND;
3523 -       if (flags & EXT4_IMMUTABLE_FL)
3524 -               inode->i_flags |= S_IMMUTABLE;
3525         if (flags & EXT4_NOATIME_FL)
3526                 inode->i_flags |= S_NOATIME;
3527         if (flags & EXT4_DIRSYNC_FL)
3528                 inode->i_flags |= S_DIRSYNC;
3529 +
3530 +       inode->i_vflags &= ~(V_BARRIER | V_COW);
3531 +
3532 +       if (flags & EXT4_BARRIER_FL)
3533 +               inode->i_vflags |= V_BARRIER;
3534 +       if (flags & EXT4_COW_FL)
3535 +               inode->i_vflags |= V_COW;
3536  }
3537  
3538  /* Propagate flags from i_flags to EXT4_I(inode)->i_flags */
3539  void ext4_get_inode_flags(struct ext4_inode_info *ei)
3540  {
3541         unsigned int flags = ei->vfs_inode.i_flags;
3542 +       unsigned int vflags = ei->vfs_inode.i_vflags;
3543 +
3544 +       ei->i_flags &= ~(EXT4_SYNC_FL | EXT4_APPEND_FL |
3545 +                       EXT4_IMMUTABLE_FL | EXT4_IXUNLINK_FL |
3546 +                       EXT4_NOATIME_FL | EXT4_DIRSYNC_FL |
3547 +                       EXT4_BARRIER_FL | EXT4_COW_FL);
3548 +
3549 +       if (flags & S_IMMUTABLE)
3550 +               ei->i_flags |= EXT4_IMMUTABLE_FL;
3551 +       if (flags & S_IXUNLINK)
3552 +               ei->i_flags |= EXT4_IXUNLINK_FL;
3553  
3554 -       ei->i_flags &= ~(EXT4_SYNC_FL|EXT4_APPEND_FL|
3555 -                       EXT4_IMMUTABLE_FL|EXT4_NOATIME_FL|EXT4_DIRSYNC_FL);
3556         if (flags & S_SYNC)
3557                 ei->i_flags |= EXT4_SYNC_FL;
3558         if (flags & S_APPEND)
3559                 ei->i_flags |= EXT4_APPEND_FL;
3560 -       if (flags & S_IMMUTABLE)
3561 -               ei->i_flags |= EXT4_IMMUTABLE_FL;
3562         if (flags & S_NOATIME)
3563                 ei->i_flags |= EXT4_NOATIME_FL;
3564         if (flags & S_DIRSYNC)
3565                 ei->i_flags |= EXT4_DIRSYNC_FL;
3566 +
3567 +       if (vflags & V_BARRIER)
3568 +               ei->i_flags |= EXT4_BARRIER_FL;
3569 +       if (vflags & V_COW)
3570 +               ei->i_flags |= EXT4_COW_FL;
3571  }
3572  
3573  static blkcnt_t ext4_inode_blocks(struct ext4_inode *raw_inode,
3574 @@ -4799,6 +4824,8 @@ struct inode *ext4_iget(struct super_blo
3575         journal_t *journal = EXT4_SB(sb)->s_journal;
3576         long ret;
3577         int block;
3578 +       uid_t uid;
3579 +       gid_t gid;
3580  
3581         inode = iget_locked(sb, ino);
3582         if (!inode)
3583 @@ -4814,12 +4841,16 @@ struct inode *ext4_iget(struct super_blo
3584                 goto bad_inode;
3585         raw_inode = ext4_raw_inode(&iloc);
3586         inode->i_mode = le16_to_cpu(raw_inode->i_mode);
3587 -       inode->i_uid = (uid_t)le16_to_cpu(raw_inode->i_uid_low);
3588 -       inode->i_gid = (gid_t)le16_to_cpu(raw_inode->i_gid_low);
3589 +       uid = (uid_t)le16_to_cpu(raw_inode->i_uid_low);
3590 +       gid = (gid_t)le16_to_cpu(raw_inode->i_gid_low);
3591         if (!(test_opt(inode->i_sb, NO_UID32))) {
3592 -               inode->i_uid |= le16_to_cpu(raw_inode->i_uid_high) << 16;
3593 -               inode->i_gid |= le16_to_cpu(raw_inode->i_gid_high) << 16;
3594 +               uid |= le16_to_cpu(raw_inode->i_uid_high) << 16;
3595 +               gid |= le16_to_cpu(raw_inode->i_gid_high) << 16;
3596         }
3597 +       inode->i_uid = INOTAG_UID(DX_TAG(inode), uid, gid);
3598 +       inode->i_gid = INOTAG_GID(DX_TAG(inode), uid, gid);
3599 +       inode->i_tag = INOTAG_TAG(DX_TAG(inode), uid, gid,
3600 +               le16_to_cpu(raw_inode->i_raw_tag));
3601         inode->i_nlink = le16_to_cpu(raw_inode->i_links_count);
3602  
3603         ei->i_state = 0;
3604 @@ -5038,6 +5069,8 @@ static int ext4_do_update_inode(handle_t
3605         struct ext4_inode *raw_inode = ext4_raw_inode(iloc);
3606         struct ext4_inode_info *ei = EXT4_I(inode);
3607         struct buffer_head *bh = iloc->bh;
3608 +       uid_t uid = TAGINO_UID(DX_TAG(inode), inode->i_uid, inode->i_tag);
3609 +       gid_t gid = TAGINO_GID(DX_TAG(inode), inode->i_gid, inode->i_tag);
3610         int err = 0, rc, block;
3611  
3612         /* For fields not not tracking in the in-memory inode,
3613 @@ -5048,29 +5081,32 @@ static int ext4_do_update_inode(handle_t
3614         ext4_get_inode_flags(ei);
3615         raw_inode->i_mode = cpu_to_le16(inode->i_mode);
3616         if (!(test_opt(inode->i_sb, NO_UID32))) {
3617 -               raw_inode->i_uid_low = cpu_to_le16(low_16_bits(inode->i_uid));
3618 -               raw_inode->i_gid_low = cpu_to_le16(low_16_bits(inode->i_gid));
3619 +               raw_inode->i_uid_low = cpu_to_le16(low_16_bits(uid));
3620 +               raw_inode->i_gid_low = cpu_to_le16(low_16_bits(gid));
3621  /*
3622   * Fix up interoperability with old kernels. Otherwise, old inodes get
3623   * re-used with the upper 16 bits of the uid/gid intact
3624   */
3625                 if (!ei->i_dtime) {
3626                         raw_inode->i_uid_high =
3627 -                               cpu_to_le16(high_16_bits(inode->i_uid));
3628 +                               cpu_to_le16(high_16_bits(uid));
3629                         raw_inode->i_gid_high =
3630 -                               cpu_to_le16(high_16_bits(inode->i_gid));
3631 +                               cpu_to_le16(high_16_bits(gid));
3632                 } else {
3633                         raw_inode->i_uid_high = 0;
3634                         raw_inode->i_gid_high = 0;
3635                 }
3636         } else {
3637                 raw_inode->i_uid_low =
3638 -                       cpu_to_le16(fs_high2lowuid(inode->i_uid));
3639 +                       cpu_to_le16(fs_high2lowuid(uid));
3640                 raw_inode->i_gid_low =
3641 -                       cpu_to_le16(fs_high2lowgid(inode->i_gid));
3642 +                       cpu_to_le16(fs_high2lowgid(gid));
3643                 raw_inode->i_uid_high = 0;
3644                 raw_inode->i_gid_high = 0;
3645         }
3646 +#ifdef CONFIG_TAGGING_INTERN
3647 +       raw_inode->i_raw_tag = cpu_to_le16(inode->i_tag);
3648 +#endif
3649         raw_inode->i_links_count = cpu_to_le16(inode->i_nlink);
3650  
3651         EXT4_INODE_SET_XTIME(i_ctime, inode, raw_inode);
3652 @@ -5255,7 +5291,8 @@ int ext4_setattr(struct dentry *dentry, 
3653                 return error;
3654  
3655         if ((ia_valid & ATTR_UID && attr->ia_uid != inode->i_uid) ||
3656 -               (ia_valid & ATTR_GID && attr->ia_gid != inode->i_gid)) {
3657 +               (ia_valid & ATTR_GID && attr->ia_gid != inode->i_gid) ||
3658 +               (ia_valid & ATTR_TAG && attr->ia_tag != inode->i_tag)) {
3659                 handle_t *handle;
3660  
3661                 /* (user+group)*(old+new) structure, inode write (sb,
3662 @@ -5277,6 +5314,8 @@ int ext4_setattr(struct dentry *dentry, 
3663                         inode->i_uid = attr->ia_uid;
3664                 if (attr->ia_valid & ATTR_GID)
3665                         inode->i_gid = attr->ia_gid;
3666 +               if ((attr->ia_valid & ATTR_TAG) && IS_TAGGED(inode))
3667 +                       inode->i_tag = attr->ia_tag;
3668                 error = ext4_mark_inode_dirty(handle, inode);
3669                 ext4_journal_stop(handle);
3670         }
3671 diff -NurpP --minimal linux-2.6.32.1/fs/ext4/ioctl.c linux-2.6.32.1-vs2.3.0.36.27/fs/ext4/ioctl.c
3672 --- linux-2.6.32.1/fs/ext4/ioctl.c      2009-12-14 21:29:46.000000000 +0100
3673 +++ linux-2.6.32.1-vs2.3.0.36.27/fs/ext4/ioctl.c        2009-12-14 22:20:55.000000000 +0100
3674 @@ -14,10 +14,39 @@
3675  #include <linux/compat.h>
3676  #include <linux/mount.h>
3677  #include <linux/file.h>
3678 +#include <linux/vs_tag.h>
3679  #include <asm/uaccess.h>
3680  #include "ext4_jbd2.h"
3681  #include "ext4.h"
3682  
3683 +
3684 +int ext4_sync_flags(struct inode *inode, int flags, int vflags)
3685 +{
3686 +       handle_t *handle = NULL;
3687 +       struct ext4_iloc iloc;
3688 +       int err;
3689 +
3690 +       handle = ext4_journal_start(inode, 1);
3691 +       if (IS_ERR(handle))
3692 +               return PTR_ERR(handle);
3693 +
3694 +       if (IS_SYNC(inode))
3695 +               ext4_handle_sync(handle);
3696 +       err = ext4_reserve_inode_write(handle, inode, &iloc);
3697 +       if (err)
3698 +               goto flags_err;
3699 +
3700 +       inode->i_flags = flags;
3701 +       inode->i_vflags = vflags;
3702 +       ext4_get_inode_flags(EXT4_I(inode));
3703 +       inode->i_ctime = ext4_current_time(inode);
3704 +
3705 +       err = ext4_mark_iloc_dirty(handle, inode, &iloc);
3706 +flags_err:
3707 +       ext4_journal_stop(handle);
3708 +       return err;
3709 +}
3710 +
3711  long ext4_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
3712  {
3713         struct inode *inode = filp->f_dentry->d_inode;
3714 @@ -50,6 +79,11 @@ long ext4_ioctl(struct file *filp, unsig
3715  
3716                 flags = ext4_mask_flags(inode->i_mode, flags);
3717  
3718 +               if (IS_BARRIER(inode)) {
3719 +                       vxwprintk_task(1, "messing with the barrier.");
3720 +                       return -EACCES;
3721 +               }
3722 +
3723                 err = -EPERM;
3724                 mutex_lock(&inode->i_mutex);
3725                 /* Is it quota file? Do not allow user to mess with it */
3726 @@ -67,7 +101,9 @@ long ext4_ioctl(struct file *filp, unsig
3727                  *
3728                  * This test looks nicer. Thanks to Pauline Middelink
3729                  */
3730 -               if ((flags ^ oldflags) & (EXT4_APPEND_FL | EXT4_IMMUTABLE_FL)) {
3731 +               if ((oldflags & EXT4_IMMUTABLE_FL) ||
3732 +                       ((flags ^ oldflags) & (EXT4_APPEND_FL |
3733 +                       EXT4_IMMUTABLE_FL | EXT4_IXUNLINK_FL))) {
3734                         if (!capable(CAP_LINUX_IMMUTABLE))
3735                                 goto flags_out;
3736                 }
3737 diff -NurpP --minimal linux-2.6.32.1/fs/ext4/namei.c linux-2.6.32.1-vs2.3.0.36.27/fs/ext4/namei.c
3738 --- linux-2.6.32.1/fs/ext4/namei.c      2009-12-14 21:29:46.000000000 +0100
3739 +++ linux-2.6.32.1-vs2.3.0.36.27/fs/ext4/namei.c        2009-12-14 22:20:55.000000000 +0100
3740 @@ -34,6 +34,7 @@
3741  #include <linux/quotaops.h>
3742  #include <linux/buffer_head.h>
3743  #include <linux/bio.h>
3744 +#include <linux/vs_tag.h>
3745  #include "ext4.h"
3746  #include "ext4_jbd2.h"
3747  
3748 @@ -941,6 +942,7 @@ restart:
3749                                 if (bh)
3750                                         ll_rw_block(READ_META, 1, &bh);
3751                         }
3752 +               dx_propagate_tag(nd, inode);
3753                 }
3754                 if ((bh = bh_use[ra_ptr++]) == NULL)
3755                         goto next;
3756 @@ -2533,6 +2535,7 @@ const struct inode_operations ext4_dir_i
3757  #endif
3758         .check_acl      = ext4_check_acl,
3759         .fiemap         = ext4_fiemap,
3760 +       .sync_flags     = ext4_sync_flags,
3761  };
3762  
3763  const struct inode_operations ext4_special_inode_operations = {
3764 diff -NurpP --minimal linux-2.6.32.1/fs/ext4/super.c linux-2.6.32.1-vs2.3.0.36.27/fs/ext4/super.c
3765 --- linux-2.6.32.1/fs/ext4/super.c      2009-12-14 21:29:46.000000000 +0100
3766 +++ linux-2.6.32.1-vs2.3.0.36.27/fs/ext4/super.c        2009-12-14 22:22:03.000000000 +0100
3767 @@ -1091,6 +1091,7 @@ enum {
3768         Opt_block_validity, Opt_noblock_validity,
3769         Opt_inode_readahead_blks, Opt_journal_ioprio,
3770         Opt_discard, Opt_nodiscard,
3771 +       Opt_tag, Opt_notag, Opt_tagid
3772  };
3773  
3774  static const match_table_t tokens = {
3775 @@ -1158,6 +1159,9 @@ static const match_table_t tokens = {
3776         {Opt_noauto_da_alloc, "noauto_da_alloc"},
3777         {Opt_discard, "discard"},
3778         {Opt_nodiscard, "nodiscard"},
3779 +       {Opt_tag, "tag"},
3780 +       {Opt_notag, "notag"},
3781 +       {Opt_tagid, "tagid=%u"},
3782         {Opt_err, NULL},
3783  };
3784  
3785 @@ -1255,6 +1259,20 @@ static int parse_options(char *options, 
3786                 case Opt_nouid32:
3787                         set_opt(sbi->s_mount_opt, NO_UID32);
3788                         break;
3789 +#ifndef CONFIG_TAGGING_NONE
3790 +               case Opt_tag:
3791 +                       set_opt (sbi->s_mount_opt, TAGGED);
3792 +                       break;
3793 +               case Opt_notag:
3794 +                       clear_opt (sbi->s_mount_opt, TAGGED);
3795 +                       break;
3796 +#endif
3797 +#ifdef CONFIG_PROPAGATE
3798 +               case Opt_tagid:
3799 +                       /* use args[0] */
3800 +                       set_opt (sbi->s_mount_opt, TAGGED);
3801 +                       break;
3802 +#endif
3803                 case Opt_debug:
3804                         set_opt(sbi->s_mount_opt, DEBUG);
3805                         break;
3806 @@ -2455,6 +2473,9 @@ static int ext4_fill_super(struct super_
3807                            &journal_ioprio, NULL, 0))
3808                 goto failed_mount;
3809  
3810 +       if (EXT4_SB(sb)->s_mount_opt & EXT4_MOUNT_TAGGED)
3811 +               sb->s_flags |= MS_TAGGED;
3812 +
3813         sb->s_flags = (sb->s_flags & ~MS_POSIXACL) |
3814                 ((sbi->s_mount_opt & EXT4_MOUNT_POSIX_ACL) ? MS_POSIXACL : 0);
3815  
3816 @@ -3512,6 +3533,14 @@ static int ext4_remount(struct super_blo
3817         if (sbi->s_mount_flags & EXT4_MF_FS_ABORTED)
3818                 ext4_abort(sb, __func__, "Abort forced by user");
3819  
3820 +       if ((sbi->s_mount_opt & EXT4_MOUNT_TAGGED) &&
3821 +               !(sb->s_flags & MS_TAGGED)) {
3822 +               printk("EXT4-fs: %s: tagging not permitted on remount.\n",
3823 +                       sb->s_id);
3824 +               err = -EINVAL;
3825 +               goto restore_opts;
3826 +       }
3827 +
3828         sb->s_flags = (sb->s_flags & ~MS_POSIXACL) |
3829                 ((sbi->s_mount_opt & EXT4_MOUNT_POSIX_ACL) ? MS_POSIXACL : 0);
3830  
3831 diff -NurpP --minimal linux-2.6.32.1/fs/fcntl.c linux-2.6.32.1-vs2.3.0.36.27/fs/fcntl.c
3832 --- linux-2.6.32.1/fs/fcntl.c   2009-12-03 20:02:51.000000000 +0100
3833 +++ linux-2.6.32.1-vs2.3.0.36.27/fs/fcntl.c     2009-12-03 20:04:56.000000000 +0100
3834 @@ -19,6 +19,7 @@
3835  #include <linux/signal.h>
3836  #include <linux/rcupdate.h>
3837  #include <linux/pid_namespace.h>
3838 +#include <linux/vs_limit.h>
3839  
3840  #include <asm/poll.h>
3841  #include <asm/siginfo.h>
3842 @@ -102,6 +103,8 @@ SYSCALL_DEFINE3(dup3, unsigned int, oldf
3843  
3844         if (tofree)
3845                 filp_close(tofree, files);
3846 +       else
3847 +               vx_openfd_inc(newfd);   /* fd was unused */
3848  
3849         return newfd;
3850  
3851 @@ -426,6 +429,8 @@ SYSCALL_DEFINE3(fcntl, unsigned int, fd,
3852         filp = fget(fd);
3853         if (!filp)
3854                 goto out;
3855 +       if (!vx_files_avail(1))
3856 +               goto out;
3857  
3858         err = security_file_fcntl(filp, cmd, arg);
3859         if (err) {
3860 diff -NurpP --minimal linux-2.6.32.1/fs/file.c linux-2.6.32.1-vs2.3.0.36.27/fs/file.c
3861 --- linux-2.6.32.1/fs/file.c    2009-12-03 20:02:51.000000000 +0100
3862 +++ linux-2.6.32.1-vs2.3.0.36.27/fs/file.c      2009-12-03 20:04:56.000000000 +0100
3863 @@ -20,6 +20,7 @@
3864  #include <linux/spinlock.h>
3865  #include <linux/rcupdate.h>
3866  #include <linux/workqueue.h>
3867 +#include <linux/vs_limit.h>
3868  
3869  struct fdtable_defer {
3870         spinlock_t lock;
3871 @@ -368,6 +369,8 @@ struct files_struct *dup_fd(struct files
3872                 struct file *f = *old_fds++;
3873                 if (f) {
3874                         get_file(f);
3875 +                       /* TODO: sum it first for check and performance */
3876 +                       vx_openfd_inc(open_files - i);
3877                 } else {
3878                         /*
3879                          * The fd may be claimed in the fd bitmap but not yet
3880 @@ -476,6 +479,7 @@ repeat:
3881         else
3882                 FD_CLR(fd, fdt->close_on_exec);
3883         error = fd;
3884 +       vx_openfd_inc(fd);
3885  #if 1
3886         /* Sanity check */
3887         if (rcu_dereference(fdt->fd[fd]) != NULL) {
3888 diff -NurpP --minimal linux-2.6.32.1/fs/file_table.c linux-2.6.32.1-vs2.3.0.36.27/fs/file_table.c
3889 --- linux-2.6.32.1/fs/file_table.c      2009-12-03 20:02:51.000000000 +0100
3890 +++ linux-2.6.32.1-vs2.3.0.36.27/fs/file_table.c        2009-12-03 20:04:56.000000000 +0100
3891 @@ -22,6 +22,8 @@
3892  #include <linux/fsnotify.h>
3893  #include <linux/sysctl.h>
3894  #include <linux/percpu_counter.h>
3895 +#include <linux/vs_limit.h>
3896 +#include <linux/vs_context.h>
3897  
3898  #include <asm/atomic.h>
3899  
3900 @@ -131,6 +133,8 @@ struct file *get_empty_filp(void)
3901         spin_lock_init(&f->f_lock);
3902         eventpoll_init_file(f);
3903         /* f->f_version: 0 */
3904 +       f->f_xid = vx_current_xid();
3905 +       vx_files_inc(f);
3906         return f;
3907  
3908  over:
3909 @@ -285,6 +289,8 @@ void __fput(struct file *file)
3910                 cdev_put(inode->i_cdev);
3911         fops_put(file->f_op);
3912         put_pid(file->f_owner.pid);
3913 +       vx_files_dec(file);
3914 +       file->f_xid = 0;
3915         file_kill(file);
3916         if (file->f_mode & FMODE_WRITE)
3917                 drop_file_write_access(file);
3918 @@ -352,6 +358,8 @@ void put_filp(struct file *file)
3919  {
3920         if (atomic_long_dec_and_test(&file->f_count)) {
3921                 security_file_free(file);
3922 +               vx_files_dec(file);
3923 +               file->f_xid = 0;
3924                 file_kill(file);
3925                 file_free(file);
3926         }
3927 diff -NurpP --minimal linux-2.6.32.1/fs/fs_struct.c linux-2.6.32.1-vs2.3.0.36.27/fs/fs_struct.c
3928 --- linux-2.6.32.1/fs/fs_struct.c       2009-06-11 17:13:04.000000000 +0200
3929 +++ linux-2.6.32.1-vs2.3.0.36.27/fs/fs_struct.c 2009-12-03 20:04:56.000000000 +0100
3930 @@ -4,6 +4,7 @@
3931  #include <linux/path.h>
3932  #include <linux/slab.h>
3933  #include <linux/fs_struct.h>
3934 +#include <linux/vserver/global.h>
3935  
3936  /*
3937   * Replace the fs->{rootmnt,root} with {mnt,dentry}. Put the old values.
3938 @@ -77,6 +78,7 @@ void free_fs_struct(struct fs_struct *fs
3939  {
3940         path_put(&fs->root);
3941         path_put(&fs->pwd);
3942 +       atomic_dec(&vs_global_fs);
3943         kmem_cache_free(fs_cachep, fs);
3944  }
3945  
3946 @@ -112,6 +114,7 @@ struct fs_struct *copy_fs_struct(struct 
3947                 fs->pwd = old->pwd;
3948                 path_get(&old->pwd);
3949                 read_unlock(&old->lock);
3950 +               atomic_inc(&vs_global_fs);
3951         }
3952         return fs;
3953  }
3954 diff -NurpP --minimal linux-2.6.32.1/fs/gfs2/file.c linux-2.6.32.1-vs2.3.0.36.27/fs/gfs2/file.c
3955 --- linux-2.6.32.1/fs/gfs2/file.c       2009-12-03 20:02:52.000000000 +0100
3956 +++ linux-2.6.32.1-vs2.3.0.36.27/fs/gfs2/file.c 2009-12-03 20:04:56.000000000 +0100
3957 @@ -132,6 +132,9 @@ static const u32 fsflags_to_gfs2[32] = {
3958         [7] = GFS2_DIF_NOATIME,
3959         [12] = GFS2_DIF_EXHASH,
3960         [14] = GFS2_DIF_INHERIT_JDATA,
3961 +       [27] = GFS2_DIF_IXUNLINK,
3962 +       [26] = GFS2_DIF_BARRIER,
3963 +       [29] = GFS2_DIF_COW,
3964  };
3965  
3966  static const u32 gfs2_to_fsflags[32] = {
3967 @@ -141,6 +144,9 @@ static const u32 gfs2_to_fsflags[32] = {
3968         [gfs2fl_NoAtime] = FS_NOATIME_FL,
3969         [gfs2fl_ExHash] = FS_INDEX_FL,
3970         [gfs2fl_InheritJdata] = FS_JOURNAL_DATA_FL,
3971 +       [gfs2fl_IXUnlink] = FS_IXUNLINK_FL,
3972 +       [gfs2fl_Barrier] = FS_BARRIER_FL,
3973 +       [gfs2fl_Cow] = FS_COW_FL,
3974  };
3975  
3976  static int gfs2_get_flags(struct file *filp, u32 __user *ptr)
3977 @@ -171,10 +177,16 @@ void gfs2_set_inode_flags(struct inode *
3978  {
3979         struct gfs2_inode *ip = GFS2_I(inode);
3980         unsigned int flags = inode->i_flags;
3981 +       unsigned int vflags = inode->i_vflags;
3982 +
3983 +       flags &= ~(S_IMMUTABLE | S_IXUNLINK |
3984 +               S_SYNC | S_APPEND | S_NOATIME | S_DIRSYNC);
3985  
3986 -       flags &= ~(S_SYNC|S_APPEND|S_IMMUTABLE|S_NOATIME|S_DIRSYNC);
3987         if (ip->i_diskflags & GFS2_DIF_IMMUTABLE)
3988                 flags |= S_IMMUTABLE;
3989 +       if (ip->i_diskflags & GFS2_DIF_IXUNLINK)
3990 +               flags |= S_IXUNLINK;
3991 +
3992         if (ip->i_diskflags & GFS2_DIF_APPENDONLY)
3993                 flags |= S_APPEND;
3994         if (ip->i_diskflags & GFS2_DIF_NOATIME)
3995 @@ -182,6 +194,43 @@ void gfs2_set_inode_flags(struct inode *
3996         if (ip->i_diskflags & GFS2_DIF_SYNC)
3997                 flags |= S_SYNC;
3998         inode->i_flags = flags;
3999 +
4000 +       vflags &= ~(V_BARRIER | V_COW);
4001 +
4002 +       if (ip->i_diskflags & GFS2_DIF_BARRIER)
4003 +               vflags |= V_BARRIER;
4004 +       if (ip->i_diskflags & GFS2_DIF_COW)
4005 +               vflags |= V_COW;
4006 +       inode->i_vflags = vflags;
4007 +}
4008 +
4009 +void gfs2_get_inode_flags(struct inode *inode)
4010 +{
4011 +       struct gfs2_inode *ip = GFS2_I(inode);
4012 +       unsigned int flags = inode->i_flags;
4013 +       unsigned int vflags = inode->i_vflags;
4014 +
4015 +       ip->i_diskflags &= ~(GFS2_DIF_APPENDONLY |
4016 +                       GFS2_DIF_NOATIME | GFS2_DIF_SYNC |
4017 +                       GFS2_DIF_IMMUTABLE | GFS2_DIF_IXUNLINK |
4018 +                       GFS2_DIF_BARRIER | GFS2_DIF_COW);
4019 +
4020 +       if (flags & S_IMMUTABLE)
4021 +               ip->i_diskflags |= GFS2_DIF_IMMUTABLE;
4022 +       if (flags & S_IXUNLINK)
4023 +               ip->i_diskflags |= GFS2_DIF_IXUNLINK;
4024 +
4025 +       if (flags & S_APPEND)
4026 +               ip->i_diskflags |= GFS2_DIF_APPENDONLY;
4027 +       if (flags & S_NOATIME)
4028 +               ip->i_diskflags |= GFS2_DIF_NOATIME;
4029 +       if (flags & S_SYNC)
4030 +               ip->i_diskflags |= GFS2_DIF_SYNC;
4031 +
4032 +       if (vflags & V_BARRIER)
4033 +               ip->i_diskflags |= GFS2_DIF_BARRIER;
4034 +       if (vflags & V_COW)
4035 +               ip->i_diskflags |= GFS2_DIF_COW;
4036  }
4037  
4038  /* Flags that can be set by user space */
4039 @@ -286,6 +335,37 @@ static int gfs2_set_flags(struct file *f
4040         return do_gfs2_set_flags(filp, gfsflags, ~GFS2_DIF_JDATA);
4041  }
4042  
4043 +int gfs2_sync_flags(struct inode *inode, int flags, int vflags)
4044 +{
4045 +       struct gfs2_inode *ip = GFS2_I(inode);
4046 +       struct gfs2_sbd *sdp = GFS2_SB(inode);
4047 +       struct buffer_head *bh;
4048 +       struct gfs2_holder gh;
4049 +       int error;
4050 +
4051 +       error = gfs2_glock_nq_init(ip->i_gl, LM_ST_EXCLUSIVE, 0, &gh);
4052 +       if (error)
4053 +               return error;
4054 +       error = gfs2_trans_begin(sdp, RES_DINODE, 0);
4055 +       if (error)
4056 +               goto out;
4057 +       error = gfs2_meta_inode_buffer(ip, &bh);
4058 +       if (error)
4059 +               goto out_trans_end;
4060 +       gfs2_trans_add_bh(ip->i_gl, bh, 1);
4061 +       inode->i_flags = flags;
4062 +       inode->i_vflags = vflags;
4063 +       gfs2_get_inode_flags(inode);
4064 +       gfs2_dinode_out(ip, bh->b_data);
4065 +       brelse(bh);
4066 +       gfs2_set_aops(inode);
4067 +out_trans_end:
4068 +       gfs2_trans_end(sdp);
4069 +out:
4070 +       gfs2_glock_dq_uninit(&gh);
4071 +       return error;
4072 +}
4073 +
4074  static long gfs2_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
4075  {
4076         switch(cmd) {
4077 diff -NurpP --minimal linux-2.6.32.1/fs/gfs2/inode.h linux-2.6.32.1-vs2.3.0.36.27/fs/gfs2/inode.h
4078 --- linux-2.6.32.1/fs/gfs2/inode.h      2009-09-10 15:26:22.000000000 +0200
4079 +++ linux-2.6.32.1-vs2.3.0.36.27/fs/gfs2/inode.h        2009-12-03 20:04:56.000000000 +0100
4080 @@ -109,6 +109,7 @@ extern const struct file_operations gfs2
4081  extern const struct file_operations gfs2_dir_fops_nolock;
4082  
4083  extern void gfs2_set_inode_flags(struct inode *inode);
4084 +extern int gfs2_sync_flags(struct inode *inode, int flags, int vflags);
4085   
4086  #ifdef CONFIG_GFS2_FS_LOCKING_DLM
4087  extern const struct file_operations gfs2_file_fops;
4088 diff -NurpP --minimal linux-2.6.32.1/fs/gfs2/ops_inode.c linux-2.6.32.1-vs2.3.0.36.27/fs/gfs2/ops_inode.c
4089 --- linux-2.6.32.1/fs/gfs2/ops_inode.c  2009-12-03 20:02:52.000000000 +0100
4090 +++ linux-2.6.32.1-vs2.3.0.36.27/fs/gfs2/ops_inode.c    2009-12-03 20:04:56.000000000 +0100
4091 @@ -1400,6 +1400,7 @@ const struct inode_operations gfs2_file_
4092         .listxattr = gfs2_listxattr,
4093         .removexattr = gfs2_removexattr,
4094         .fiemap = gfs2_fiemap,
4095 +       .sync_flags = gfs2_sync_flags,
4096  };
4097  
4098  const struct inode_operations gfs2_dir_iops = {
4099 @@ -1420,6 +1421,7 @@ const struct inode_operations gfs2_dir_i
4100         .listxattr = gfs2_listxattr,
4101         .removexattr = gfs2_removexattr,
4102         .fiemap = gfs2_fiemap,
4103 +       .sync_flags = gfs2_sync_flags,
4104  };
4105  
4106  const struct inode_operations gfs2_symlink_iops = {
4107 diff -NurpP --minimal linux-2.6.32.1/fs/hfsplus/ioctl.c linux-2.6.32.1-vs2.3.0.36.27/fs/hfsplus/ioctl.c
4108 --- linux-2.6.32.1/fs/hfsplus/ioctl.c   2008-12-25 00:26:37.000000000 +0100
4109 +++ linux-2.6.32.1-vs2.3.0.36.27/fs/hfsplus/ioctl.c     2009-12-03 20:04:56.000000000 +0100
4110 @@ -17,6 +17,7 @@
4111  #include <linux/mount.h>
4112  #include <linux/sched.h>
4113  #include <linux/xattr.h>
4114 +#include <linux/mount.h>
4115  #include <asm/uaccess.h>
4116  #include "hfsplus_fs.h"
4117  
4118 diff -NurpP --minimal linux-2.6.32.1/fs/inode.c linux-2.6.32.1-vs2.3.0.36.27/fs/inode.c
4119 --- linux-2.6.32.1/fs/inode.c   2009-12-03 20:02:52.000000000 +0100
4120 +++ linux-2.6.32.1-vs2.3.0.36.27/fs/inode.c     2009-12-03 20:04:56.000000000 +0100
4121 @@ -133,6 +133,9 @@ int inode_init_always(struct super_block
4122         struct address_space *const mapping = &inode->i_data;
4123  
4124         inode->i_sb = sb;
4125 +
4126 +       /* essential because of inode slab reuse */
4127 +       inode->i_tag = 0;
4128         inode->i_blkbits = sb->s_blocksize_bits;
4129         inode->i_flags = 0;
4130         atomic_set(&inode->i_count, 1);
4131 @@ -153,6 +156,7 @@ int inode_init_always(struct super_block
4132         inode->i_bdev = NULL;
4133         inode->i_cdev = NULL;
4134         inode->i_rdev = 0;
4135 +       inode->i_mdev = 0;
4136         inode->dirtied_when = 0;
4137  
4138         if (security_inode_alloc(inode))
4139 @@ -307,6 +311,8 @@ void __iget(struct inode *inode)
4140         inodes_stat.nr_unused--;
4141  }
4142  
4143 +EXPORT_SYMBOL_GPL(__iget);
4144 +
4145  /**
4146   * clear_inode - clear an inode
4147   * @inode: inode to clear
4148 @@ -1611,9 +1617,11 @@ void init_special_inode(struct inode *in
4149         if (S_ISCHR(mode)) {
4150                 inode->i_fop = &def_chr_fops;
4151                 inode->i_rdev = rdev;
4152 +               inode->i_mdev = rdev;
4153         } else if (S_ISBLK(mode)) {
4154                 inode->i_fop = &def_blk_fops;
4155                 inode->i_rdev = rdev;
4156 +               inode->i_mdev = rdev;
4157         } else if (S_ISFIFO(mode))
4158                 inode->i_fop = &def_fifo_fops;
4159         else if (S_ISSOCK(mode))
4160 diff -NurpP --minimal linux-2.6.32.1/fs/ioctl.c linux-2.6.32.1-vs2.3.0.36.27/fs/ioctl.c
4161 --- linux-2.6.32.1/fs/ioctl.c   2009-12-03 20:02:52.000000000 +0100
4162 +++ linux-2.6.32.1-vs2.3.0.36.27/fs/ioctl.c     2009-12-03 20:04:56.000000000 +0100
4163 @@ -16,6 +16,9 @@
4164  #include <linux/writeback.h>
4165  #include <linux/buffer_head.h>
4166  #include <linux/falloc.h>
4167 +#include <linux/proc_fs.h>
4168 +#include <linux/vserver/inode.h>
4169 +#include <linux/vs_tag.h>
4170  
4171  #include <asm/ioctls.h>
4172  
4173 diff -NurpP --minimal linux-2.6.32.1/fs/ioprio.c linux-2.6.32.1-vs2.3.0.36.27/fs/ioprio.c
4174 --- linux-2.6.32.1/fs/ioprio.c  2009-03-24 14:22:26.000000000 +0100
4175 +++ linux-2.6.32.1-vs2.3.0.36.27/fs/ioprio.c    2009-12-03 20:04:56.000000000 +0100
4176 @@ -26,6 +26,7 @@
4177  #include <linux/syscalls.h>
4178  #include <linux/security.h>
4179  #include <linux/pid_namespace.h>
4180 +#include <linux/vs_base.h>
4181  
4182  int set_task_ioprio(struct task_struct *task, int ioprio)
4183  {
4184 @@ -123,6 +124,8 @@ SYSCALL_DEFINE3(ioprio_set, int, which, 
4185                         else
4186                                 pgrp = find_vpid(who);
4187                         do_each_pid_thread(pgrp, PIDTYPE_PGID, p) {
4188 +                               if (!vx_check(p->xid, VS_ADMIN_P | VS_IDENT))
4189 +                                       continue;
4190                                 ret = set_task_ioprio(p, ioprio);
4191                                 if (ret)
4192                                         break;
4193 @@ -212,6 +215,8 @@ SYSCALL_DEFINE2(ioprio_get, int, which, 
4194                         else
4195                                 pgrp = find_vpid(who);
4196                         do_each_pid_thread(pgrp, PIDTYPE_PGID, p) {
4197 +                               if (!vx_check(p->xid, VS_ADMIN_P | VS_IDENT))
4198 +                                       continue;
4199                                 tmpio = get_task_ioprio(p);
4200                                 if (tmpio < 0)
4201                                         continue;
4202 diff -NurpP --minimal linux-2.6.32.1/fs/jfs/acl.c linux-2.6.32.1-vs2.3.0.36.27/fs/jfs/acl.c
4203 --- linux-2.6.32.1/fs/jfs/acl.c 2009-12-03 20:02:52.000000000 +0100
4204 +++ linux-2.6.32.1-vs2.3.0.36.27/fs/jfs/acl.c   2009-12-03 20:04:56.000000000 +0100
4205 @@ -216,7 +216,8 @@ int jfs_setattr(struct dentry *dentry, s
4206                 return rc;
4207  
4208         if ((iattr->ia_valid & ATTR_UID && iattr->ia_uid != inode->i_uid) ||
4209 -           (iattr->ia_valid & ATTR_GID && iattr->ia_gid != inode->i_gid)) {
4210 +           (iattr->ia_valid & ATTR_GID && iattr->ia_gid != inode->i_gid) ||
4211 +           (iattr->ia_valid & ATTR_TAG && iattr->ia_tag != inode->i_tag)) {
4212                 if (vfs_dq_transfer(inode, iattr))
4213                         return -EDQUOT;
4214         }
4215 diff -NurpP --minimal linux-2.6.32.1/fs/jfs/file.c linux-2.6.32.1-vs2.3.0.36.27/fs/jfs/file.c
4216 --- linux-2.6.32.1/fs/jfs/file.c        2009-12-03 20:02:52.000000000 +0100
4217 +++ linux-2.6.32.1-vs2.3.0.36.27/fs/jfs/file.c  2009-12-03 20:04:56.000000000 +0100
4218 @@ -98,6 +98,7 @@ const struct inode_operations jfs_file_i
4219         .setattr        = jfs_setattr,
4220         .check_acl      = jfs_check_acl,
4221  #endif
4222 +       .sync_flags     = jfs_sync_flags,
4223  };
4224  
4225  const struct file_operations jfs_file_operations = {
4226 diff -NurpP --minimal linux-2.6.32.1/fs/jfs/ioctl.c linux-2.6.32.1-vs2.3.0.36.27/fs/jfs/ioctl.c
4227 --- linux-2.6.32.1/fs/jfs/ioctl.c       2008-12-25 00:26:37.000000000 +0100
4228 +++ linux-2.6.32.1-vs2.3.0.36.27/fs/jfs/ioctl.c 2009-12-03 20:04:56.000000000 +0100
4229 @@ -11,6 +11,7 @@
4230  #include <linux/mount.h>
4231  #include <linux/time.h>
4232  #include <linux/sched.h>
4233 +#include <linux/mount.h>
4234  #include <asm/current.h>
4235  #include <asm/uaccess.h>
4236  
4237 @@ -52,6 +53,16 @@ static long jfs_map_ext2(unsigned long f
4238  }
4239  
4240  
4241 +int jfs_sync_flags(struct inode *inode, int flags, int vflags)
4242 +{
4243 +       inode->i_flags = flags;
4244 +       inode->i_vflags = vflags;
4245 +       jfs_get_inode_flags(JFS_IP(inode));
4246 +       inode->i_ctime = CURRENT_TIME_SEC;
4247 +       mark_inode_dirty(inode);
4248 +       return 0;
4249 +}
4250 +
4251  long jfs_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
4252  {
4253         struct inode *inode = filp->f_dentry->d_inode;
4254 @@ -85,6 +96,11 @@ long jfs_ioctl(struct file *filp, unsign
4255                 if (!S_ISDIR(inode->i_mode))
4256                         flags &= ~JFS_DIRSYNC_FL;
4257  
4258 +               if (IS_BARRIER(inode)) {
4259 +                       vxwprintk_task(1, "messing with the barrier.");
4260 +                       return -EACCES;
4261 +               }
4262 +
4263                 /* Is it quota file? Do not allow user to mess with it */
4264                 if (IS_NOQUOTA(inode)) {
4265                         err = -EPERM;
4266 @@ -102,8 +118,8 @@ long jfs_ioctl(struct file *filp, unsign
4267                  * the relevant capability.
4268                  */
4269                 if ((oldflags & JFS_IMMUTABLE_FL) ||
4270 -                       ((flags ^ oldflags) &
4271 -                       (JFS_APPEND_FL | JFS_IMMUTABLE_FL))) {
4272 +                       ((flags ^ oldflags) & (JFS_APPEND_FL |
4273 +                       JFS_IMMUTABLE_FL | JFS_IXUNLINK_FL))) {
4274                         if (!capable(CAP_LINUX_IMMUTABLE)) {
4275                                 mutex_unlock(&inode->i_mutex);
4276                                 err = -EPERM;
4277 @@ -111,7 +127,7 @@ long jfs_ioctl(struct file *filp, unsign
4278                         }
4279                 }
4280  
4281 -               flags = flags & JFS_FL_USER_MODIFIABLE;
4282 +               flags &= JFS_FL_USER_MODIFIABLE;
4283                 flags |= oldflags & ~JFS_FL_USER_MODIFIABLE;
4284                 jfs_inode->mode2 = flags;
4285  
4286 diff -NurpP --minimal linux-2.6.32.1/fs/jfs/jfs_dinode.h linux-2.6.32.1-vs2.3.0.36.27/fs/jfs/jfs_dinode.h
4287 --- linux-2.6.32.1/fs/jfs/jfs_dinode.h  2008-12-25 00:26:37.000000000 +0100
4288 +++ linux-2.6.32.1-vs2.3.0.36.27/fs/jfs/jfs_dinode.h    2009-12-03 20:04:56.000000000 +0100
4289 @@ -161,9 +161,13 @@ struct dinode {
4290  
4291  #define JFS_APPEND_FL          0x01000000 /* writes to file may only append */
4292  #define JFS_IMMUTABLE_FL       0x02000000 /* Immutable file */
4293 +#define JFS_IXUNLINK_FL                0x08000000 /* Immutable invert on unlink */
4294  
4295 -#define JFS_FL_USER_VISIBLE    0x03F80000
4296 -#define JFS_FL_USER_MODIFIABLE 0x03F80000
4297 +#define JFS_BARRIER_FL         0x04000000 /* Barrier for chroot() */
4298 +#define JFS_COW_FL             0x20000000 /* Copy on Write marker */
4299 +
4300 +#define JFS_FL_USER_VISIBLE    0x07F80000
4301 +#define JFS_FL_USER_MODIFIABLE 0x07F80000
4302  #define JFS_FL_INHERIT         0x03C80000
4303  
4304  /* These are identical to EXT[23]_IOC_GETFLAGS/SETFLAGS */
4305 diff -NurpP --minimal linux-2.6.32.1/fs/jfs/jfs_filsys.h linux-2.6.32.1-vs2.3.0.36.27/fs/jfs/jfs_filsys.h
4306 --- linux-2.6.32.1/fs/jfs/jfs_filsys.h  2008-12-25 00:26:37.000000000 +0100
4307 +++ linux-2.6.32.1-vs2.3.0.36.27/fs/jfs/jfs_filsys.h    2009-12-03 20:04:56.000000000 +0100
4308 @@ -263,6 +263,7 @@
4309  #define JFS_NAME_MAX   255
4310  #define JFS_PATH_MAX   BPSIZE
4311  
4312 +#define JFS_TAGGED             0x00800000      /* Context Tagging */
4313  
4314  /*
4315   *     file system state (superblock state)
4316 diff -NurpP --minimal linux-2.6.32.1/fs/jfs/jfs_imap.c linux-2.6.32.1-vs2.3.0.36.27/fs/jfs/jfs_imap.c
4317 --- linux-2.6.32.1/fs/jfs/jfs_imap.c    2009-09-10 15:26:22.000000000 +0200
4318 +++ linux-2.6.32.1-vs2.3.0.36.27/fs/jfs/jfs_imap.c      2009-12-03 20:04:56.000000000 +0100
4319 @@ -45,6 +45,7 @@
4320  #include <linux/buffer_head.h>
4321  #include <linux/pagemap.h>
4322  #include <linux/quotaops.h>
4323 +#include <linux/vs_tag.h>
4324  
4325  #include "jfs_incore.h"
4326  #include "jfs_inode.h"
4327 @@ -3059,6 +3060,8 @@ static int copy_from_dinode(struct dinod
4328  {
4329         struct jfs_inode_info *jfs_ip = JFS_IP(ip);
4330         struct jfs_sb_info *sbi = JFS_SBI(ip->i_sb);
4331 +       uid_t uid;
4332 +       gid_t gid;
4333  
4334         jfs_ip->fileset = le32_to_cpu(dip->di_fileset);
4335         jfs_ip->mode2 = le32_to_cpu(dip->di_mode);
4336 @@ -3079,14 +3082,18 @@ static int copy_from_dinode(struct dinod
4337         }
4338         ip->i_nlink = le32_to_cpu(dip->di_nlink);
4339  
4340 -       jfs_ip->saved_uid = le32_to_cpu(dip->di_uid);
4341 +       uid = le32_to_cpu(dip->di_uid);
4342 +       gid = le32_to_cpu(dip->di_gid);
4343 +       ip->i_tag = INOTAG_TAG(DX_TAG(ip), uid, gid, 0);
4344 +
4345 +       jfs_ip->saved_uid = INOTAG_UID(DX_TAG(ip), uid, gid);
4346         if (sbi->uid == -1)
4347                 ip->i_uid = jfs_ip->saved_uid;
4348         else {
4349                 ip->i_uid = sbi->uid;
4350         }
4351  
4352 -       jfs_ip->saved_gid = le32_to_cpu(dip->di_gid);
4353 +       jfs_ip->saved_gid = INOTAG_GID(DX_TAG(ip), uid, gid);
4354         if (sbi->gid == -1)
4355                 ip->i_gid = jfs_ip->saved_gid;
4356         else {
4357 @@ -3151,14 +3158,12 @@ static void copy_to_dinode(struct dinode
4358         dip->di_size = cpu_to_le64(ip->i_size);
4359         dip->di_nblocks = cpu_to_le64(PBLK2LBLK(ip->i_sb, ip->i_blocks));
4360         dip->di_nlink = cpu_to_le32(ip->i_nlink);
4361 -       if (sbi->uid == -1)
4362 -               dip->di_uid = cpu_to_le32(ip->i_uid);
4363 -       else
4364 -               dip->di_uid = cpu_to_le32(jfs_ip->saved_uid);
4365 -       if (sbi->gid == -1)
4366 -               dip->di_gid = cpu_to_le32(ip->i_gid);
4367 -       else
4368 -               dip->di_gid = cpu_to_le32(jfs_ip->saved_gid);
4369 +
4370 +       dip->di_uid = cpu_to_le32(TAGINO_UID(DX_TAG(ip),
4371 +               (sbi->uid == -1) ? ip->i_uid : jfs_ip->saved_uid, ip->i_tag));
4372 +       dip->di_gid = cpu_to_le32(TAGINO_GID(DX_TAG(ip),
4373 +               (sbi->gid == -1) ? ip->i_gid : jfs_ip->saved_gid, ip->i_tag));
4374 +
4375         jfs_get_inode_flags(jfs_ip);
4376         /*
4377          * mode2 is only needed for storing the higher order bits.
4378 diff -NurpP --minimal linux-2.6.32.1/fs/jfs/jfs_inode.c linux-2.6.32.1-vs2.3.0.36.27/fs/jfs/jfs_inode.c
4379 --- linux-2.6.32.1/fs/jfs/jfs_inode.c   2009-06-11 17:13:05.000000000 +0200
4380 +++ linux-2.6.32.1-vs2.3.0.36.27/fs/jfs/jfs_inode.c     2009-12-03 20:04:56.000000000 +0100
4381 @@ -18,6 +18,7 @@
4382  
4383  #include <linux/fs.h>
4384  #include <linux/quotaops.h>
4385 +#include <linux/vs_tag.h>
4386  #include "jfs_incore.h"
4387  #include "jfs_inode.h"
4388  #include "jfs_filsys.h"
4389 @@ -30,29 +31,46 @@ void jfs_set_inode_flags(struct inode *i
4390  {
4391         unsigned int flags = JFS_IP(inode)->mode2;
4392  
4393 -       inode->i_flags &= ~(S_IMMUTABLE | S_APPEND |
4394 -               S_NOATIME | S_DIRSYNC | S_SYNC);
4395 +       inode->i_flags &= ~(S_IMMUTABLE | S_IXUNLINK |
4396 +               S_SYNC | S_APPEND | S_NOATIME | S_DIRSYNC);
4397  
4398         if (flags & JFS_IMMUTABLE_FL)
4399                 inode->i_flags |= S_IMMUTABLE;
4400 +       if (flags & JFS_IXUNLINK_FL)
4401 +               inode->i_flags |= S_IXUNLINK;
4402 +
4403 +       if (flags & JFS_SYNC_FL)
4404 +               inode->i_flags |= S_SYNC;
4405         if (flags & JFS_APPEND_FL)
4406                 inode->i_flags |= S_APPEND;
4407         if (flags & JFS_NOATIME_FL)
4408                 inode->i_flags |= S_NOATIME;
4409         if (flags & JFS_DIRSYNC_FL)
4410                 inode->i_flags |= S_DIRSYNC;
4411 -       if (flags & JFS_SYNC_FL)
4412 -               inode->i_flags |= S_SYNC;
4413 +
4414 +       inode->i_vflags &= ~(V_BARRIER | V_COW);
4415 +
4416 +       if (flags & JFS_BARRIER_FL)
4417 +               inode->i_vflags |= V_BARRIER;
4418 +       if (flags & JFS_COW_FL)
4419 +               inode->i_vflags |= V_COW;
4420  }
4421  
4422  void jfs_get_inode_flags(struct jfs_inode_info *jfs_ip)
4423  {
4424         unsigned int flags = jfs_ip->vfs_inode.i_flags;
4425 +       unsigned int vflags = jfs_ip->vfs_inode.i_vflags;
4426 +
4427 +       jfs_ip->mode2 &= ~(JFS_IMMUTABLE_FL | JFS_IXUNLINK_FL |
4428 +                          JFS_APPEND_FL | JFS_NOATIME_FL |
4429 +                          JFS_DIRSYNC_FL | JFS_SYNC_FL |
4430 +                          JFS_BARRIER_FL | JFS_COW_FL);
4431  
4432 -       jfs_ip->mode2 &= ~(JFS_IMMUTABLE_FL | JFS_APPEND_FL | JFS_NOATIME_FL |
4433 -                          JFS_DIRSYNC_FL | JFS_SYNC_FL);
4434         if (flags & S_IMMUTABLE)
4435                 jfs_ip->mode2 |= JFS_IMMUTABLE_FL;
4436 +       if (flags & S_IXUNLINK)
4437 +               jfs_ip->mode2 |= JFS_IXUNLINK_FL;
4438 +
4439         if (flags & S_APPEND)
4440                 jfs_ip->mode2 |= JFS_APPEND_FL;
4441         if (flags & S_NOATIME)
4442 @@ -61,6 +79,11 @@ void jfs_get_inode_flags(struct jfs_inod
4443                 jfs_ip->mode2 |= JFS_DIRSYNC_FL;
4444         if (flags & S_SYNC)
4445                 jfs_ip->mode2 |= JFS_SYNC_FL;
4446 +
4447 +       if (vflags & V_BARRIER)
4448 +               jfs_ip->mode2 |= JFS_BARRIER_FL;
4449 +       if (vflags & V_COW)
4450 +               jfs_ip->mode2 |= JFS_COW_FL;
4451  }
4452  
4453  /*
4454 @@ -105,6 +128,7 @@ struct inode *ialloc(struct inode *paren
4455                         mode |= S_ISGID;
4456         } else
4457                 inode->i_gid = current_fsgid();
4458 +       inode->i_tag = dx_current_fstag(sb);
4459  
4460         /*
4461          * New inodes need to save sane values on disk when
4462 diff -NurpP --minimal linux-2.6.32.1/fs/jfs/jfs_inode.h linux-2.6.32.1-vs2.3.0.36.27/fs/jfs/jfs_inode.h
4463 --- linux-2.6.32.1/fs/jfs/jfs_inode.h   2009-06-11 17:13:05.000000000 +0200
4464 +++ linux-2.6.32.1-vs2.3.0.36.27/fs/jfs/jfs_inode.h     2009-12-03 20:04:56.000000000 +0100
4465 @@ -39,6 +39,7 @@ extern struct dentry *jfs_fh_to_dentry(s
4466  extern struct dentry *jfs_fh_to_parent(struct super_block *sb, struct fid *fid,
4467         int fh_len, int fh_type);
4468  extern void jfs_set_inode_flags(struct inode *);
4469 +extern int jfs_sync_flags(struct inode *, int, int);
4470  extern int jfs_get_block(struct inode *, sector_t, struct buffer_head *, int);
4471  
4472  extern const struct address_space_operations jfs_aops;
4473 diff -NurpP --minimal linux-2.6.32.1/fs/jfs/namei.c linux-2.6.32.1-vs2.3.0.36.27/fs/jfs/namei.c
4474 --- linux-2.6.32.1/fs/jfs/namei.c       2009-12-03 20:02:52.000000000 +0100
4475 +++ linux-2.6.32.1-vs2.3.0.36.27/fs/jfs/namei.c 2009-12-03 20:04:56.000000000 +0100
4476 @@ -21,6 +21,7 @@
4477  #include <linux/ctype.h>
4478  #include <linux/quotaops.h>
4479  #include <linux/exportfs.h>
4480 +#include <linux/vs_tag.h>
4481  #include "jfs_incore.h"
4482  #include "jfs_superblock.h"
4483  #include "jfs_inode.h"
4484 @@ -1476,6 +1477,7 @@ static struct dentry *jfs_lookup(struct 
4485                 return ERR_CAST(ip);
4486         }
4487  
4488 +       dx_propagate_tag(nd, ip);
4489         dentry = d_splice_alias(ip, dentry);
4490  
4491         if (dentry && (JFS_SBI(dip->i_sb)->mntflag & JFS_OS2))
4492 @@ -1545,6 +1547,7 @@ const struct inode_operations jfs_dir_in
4493         .setattr        = jfs_setattr,
4494         .check_acl      = jfs_check_acl,
4495  #endif
4496 +       .sync_flags     = jfs_sync_flags,
4497  };
4498  
4499  const struct file_operations jfs_dir_operations = {
4500 diff -NurpP --minimal linux-2.6.32.1/fs/jfs/super.c linux-2.6.32.1-vs2.3.0.36.27/fs/jfs/super.c
4501 --- linux-2.6.32.1/fs/jfs/super.c       2009-12-03 20:02:52.000000000 +0100
4502 +++ linux-2.6.32.1-vs2.3.0.36.27/fs/jfs/super.c 2009-12-03 20:04:56.000000000 +0100
4503 @@ -192,7 +192,8 @@ static void jfs_put_super(struct super_b
4504  enum {
4505         Opt_integrity, Opt_nointegrity, Opt_iocharset, Opt_resize,
4506         Opt_resize_nosize, Opt_errors, Opt_ignore, Opt_err, Opt_quota,
4507 -       Opt_usrquota, Opt_grpquota, Opt_uid, Opt_gid, Opt_umask
4508 +       Opt_usrquota, Opt_grpquota, Opt_uid, Opt_gid, Opt_umask,
4509 +       Opt_tag, Opt_notag, Opt_tagid
4510  };
4511  
4512  static const match_table_t tokens = {
4513 @@ -202,6 +203,10 @@ static const match_table_t tokens = {
4514         {Opt_resize, "resize=%u"},
4515         {Opt_resize_nosize, "resize"},
4516         {Opt_errors, "errors=%s"},
4517 +       {Opt_tag, "tag"},
4518 +       {Opt_notag, "notag"},
4519 +       {Opt_tagid, "tagid=%u"},
4520 +       {Opt_tag, "tagxid"},
4521         {Opt_ignore, "noquota"},
4522         {Opt_ignore, "quota"},
4523         {Opt_usrquota, "usrquota"},
4524 @@ -336,6 +341,20 @@ static int parse_options(char *options, 
4525                         }
4526                         break;
4527                 }
4528 +#ifndef CONFIG_TAGGING_NONE
4529 +               case Opt_tag:
4530 +                       *flag |= JFS_TAGGED;
4531 +                       break;
4532 +               case Opt_notag:
4533 +                       *flag &= JFS_TAGGED;
4534 +                       break;
4535 +#endif
4536 +#ifdef CONFIG_PROPAGATE
4537 +               case Opt_tagid:
4538 +                       /* use args[0] */
4539 +                       *flag |= JFS_TAGGED;
4540 +                       break;
4541 +#endif
4542                 default:
4543                         printk("jfs: Unrecognized mount option \"%s\" "
4544                                         " or missing value\n", p);
4545 @@ -366,6 +385,12 @@ static int jfs_remount(struct super_bloc
4546         if (!parse_options(data, sb, &newLVSize, &flag)) {
4547                 return -EINVAL;
4548         }
4549 +       if ((flag & JFS_TAGGED) && !(sb->s_flags & MS_TAGGED)) {
4550 +               printk(KERN_ERR "JFS: %s: tagging not permitted on remount.\n",
4551 +                       sb->s_id);
4552 +               return -EINVAL;
4553 +       }
4554 +
4555         lock_kernel();
4556         if (newLVSize) {
4557                 if (sb->s_flags & MS_RDONLY) {
4558 @@ -449,6 +474,9 @@ static int jfs_fill_super(struct super_b
4559  #ifdef CONFIG_JFS_POSIX_ACL
4560         sb->s_flags |= MS_POSIXACL;
4561  #endif
4562 +       /* map mount option tagxid */
4563 +       if (sbi->flag & JFS_TAGGED)
4564 +               sb->s_flags |= MS_TAGGED;
4565  
4566         if (newLVSize) {
4567                 printk(KERN_ERR "resize option for remount only\n");
4568 diff -NurpP --minimal linux-2.6.32.1/fs/libfs.c linux-2.6.32.1-vs2.3.0.36.27/fs/libfs.c
4569 --- linux-2.6.32.1/fs/libfs.c   2009-12-03 20:02:52.000000000 +0100
4570 +++ linux-2.6.32.1-vs2.3.0.36.27/fs/libfs.c     2009-12-03 20:04:56.000000000 +0100
4571 @@ -127,7 +127,8 @@ static inline unsigned char dt_type(stru
4572   * both impossible due to the lock on directory.
4573   */
4574  
4575 -int dcache_readdir(struct file * filp, void * dirent, filldir_t filldir)
4576 +static inline int do_dcache_readdir_filter(struct file *filp,
4577 +       void *dirent, filldir_t filldir, int (*filter)(struct dentry *dentry))
4578  {
4579         struct dentry *dentry = filp->f_path.dentry;
4580         struct dentry *cursor = filp->private_data;
4581 @@ -160,6 +161,8 @@ int dcache_readdir(struct file * filp, v
4582                                 next = list_entry(p, struct dentry, d_u.d_child);
4583                                 if (d_unhashed(next) || !next->d_inode)
4584                                         continue;
4585 +                               if (filter && !filter(next))
4586 +                                       continue;
4587  
4588                                 spin_unlock(&dcache_lock);
4589                                 if (filldir(dirent, next->d_name.name, 
4590 @@ -178,6 +181,18 @@ int dcache_readdir(struct file * filp, v
4591         return 0;
4592  }
4593  
4594 +int dcache_readdir(struct file *filp, void *dirent, filldir_t filldir)
4595 +{
4596 +       return do_dcache_readdir_filter(filp, dirent, filldir, NULL);
4597 +}
4598 +
4599 +int dcache_readdir_filter(struct file *filp, void *dirent, filldir_t filldir,
4600 +       int (*filter)(struct dentry *))
4601 +{
4602 +       return do_dcache_readdir_filter(filp, dirent, filldir, filter);
4603 +}
4604 +
4605 +
4606  ssize_t generic_read_dir(struct file *filp, char __user *buf, size_t siz, loff_t *ppos)
4607  {
4608         return -EISDIR;
4609 @@ -841,6 +856,7 @@ EXPORT_SYMBOL(dcache_dir_close);
4610  EXPORT_SYMBOL(dcache_dir_lseek);
4611  EXPORT_SYMBOL(dcache_dir_open);
4612  EXPORT_SYMBOL(dcache_readdir);
4613 +EXPORT_SYMBOL(dcache_readdir_filter);
4614  EXPORT_SYMBOL(generic_read_dir);
4615  EXPORT_SYMBOL(get_sb_pseudo);
4616  EXPORT_SYMBOL(simple_write_begin);
4617 diff -NurpP --minimal linux-2.6.32.1/fs/locks.c linux-2.6.32.1-vs2.3.0.36.27/fs/locks.c
4618 --- linux-2.6.32.1/fs/locks.c   2009-12-03 20:02:52.000000000 +0100
4619 +++ linux-2.6.32.1-vs2.3.0.36.27/fs/locks.c     2009-12-03 20:04:56.000000000 +0100
4620 @@ -127,6 +127,8 @@
4621  #include <linux/time.h>
4622  #include <linux/rcupdate.h>
4623  #include <linux/pid_namespace.h>
4624 +#include <linux/vs_base.h>
4625 +#include <linux/vs_limit.h>
4626  
4627  #include <asm/uaccess.h>
4628  
4629 @@ -148,6 +150,8 @@ static struct kmem_cache *filelock_cache
4630  /* Allocate an empty lock structure. */
4631  static struct file_lock *locks_alloc_lock(void)
4632  {
4633 +       if (!vx_locks_avail(1))
4634 +               return NULL;
4635         return kmem_cache_alloc(filelock_cache, GFP_KERNEL);
4636  }
4637  
4638 @@ -174,6 +178,7 @@ static void locks_free_lock(struct file_
4639         BUG_ON(!list_empty(&fl->fl_block));
4640         BUG_ON(!list_empty(&fl->fl_link));
4641  
4642 +       vx_locks_dec(fl);
4643         locks_release_private(fl);
4644         kmem_cache_free(filelock_cache, fl);
4645  }
4646 @@ -194,6 +199,7 @@ void locks_init_lock(struct file_lock *f
4647         fl->fl_start = fl->fl_end = 0;
4648         fl->fl_ops = NULL;
4649         fl->fl_lmops = NULL;
4650 +       fl->fl_xid = -1;
4651  }
4652  
4653  EXPORT_SYMBOL(locks_init_lock);
4654 @@ -248,6 +254,7 @@ void locks_copy_lock(struct file_lock *n
4655         new->fl_file = fl->fl_file;
4656         new->fl_ops = fl->fl_ops;
4657         new->fl_lmops = fl->fl_lmops;
4658 +       new->fl_xid = fl->fl_xid;
4659  
4660         locks_copy_private(new, fl);
4661  }
4662 @@ -286,6 +293,11 @@ static int flock_make_lock(struct file *
4663         fl->fl_flags = FL_FLOCK;
4664         fl->fl_type = type;
4665         fl->fl_end = OFFSET_MAX;
4666 +
4667 +       vxd_assert(filp->f_xid == vx_current_xid(),
4668 +               "f_xid(%d) == current(%d)", filp->f_xid, vx_current_xid());
4669 +       fl->fl_xid = filp->f_xid;
4670 +       vx_locks_inc(fl);
4671         
4672         *lock = fl;
4673         return 0;
4674 @@ -451,6 +463,7 @@ static int lease_init(struct file *filp,
4675  
4676         fl->fl_owner = current->files;
4677         fl->fl_pid = current->tgid;
4678 +       fl->fl_xid = vx_current_xid();
4679  
4680         fl->fl_file = filp;
4681         fl->fl_flags = FL_LEASE;
4682 @@ -470,6 +483,11 @@ static struct file_lock *lease_alloc(str
4683         if (fl == NULL)
4684                 return ERR_PTR(error);
4685  
4686 +       fl->fl_xid = vx_current_xid();
4687 +       if (filp)
4688 +               vxd_assert(filp->f_xid == fl->fl_xid,
4689 +                       "f_xid(%d) == fl_xid(%d)", filp->f_xid, fl->fl_xid);
4690 +       vx_locks_inc(fl);
4691         error = lease_init(filp, type, fl);
4692         if (error) {
4693                 locks_free_lock(fl);
4694 @@ -770,6 +788,7 @@ static int flock_lock_file(struct file *
4695         if (found)
4696                 cond_resched();
4697  
4698 +       new_fl->fl_xid = -1;
4699  find_conflict:
4700         for_each_lock(inode, before) {
4701                 struct file_lock *fl = *before;
4702 @@ -790,6 +809,7 @@ find_conflict:
4703                 goto out;
4704         locks_copy_lock(new_fl, request);
4705         locks_insert_lock(before, new_fl);
4706 +       vx_locks_inc(new_fl);
4707         new_fl = NULL;
4708         error = 0;
4709  
4710 @@ -800,7 +820,8 @@ out:
4711         return error;
4712  }
4713  
4714 -static int __posix_lock_file(struct inode *inode, struct file_lock *request, struct file_lock *conflock)
4715 +static int __posix_lock_file(struct inode *inode, struct file_lock *request,
4716 +       struct file_lock *conflock, xid_t xid)
4717  {
4718         struct file_lock *fl;
4719         struct file_lock *new_fl = NULL;
4720 @@ -810,6 +831,8 @@ static int __posix_lock_file(struct inod
4721         struct file_lock **before;
4722         int error, added = 0;
4723  
4724 +       vxd_assert(xid == vx_current_xid(),
4725 +               "xid(%d) == current(%d)", xid, vx_current_xid());
4726         /*
4727          * We may need two file_lock structures for this operation,
4728          * so we get them in advance to avoid races.
4729 @@ -820,7 +843,11 @@ static int __posix_lock_file(struct inod
4730             (request->fl_type != F_UNLCK ||
4731              request->fl_start != 0 || request->fl_end != OFFSET_MAX)) {
4732                 new_fl = locks_alloc_lock();
4733 +               new_fl->fl_xid = xid;
4734 +               vx_locks_inc(new_fl);
4735                 new_fl2 = locks_alloc_lock();
4736 +               new_fl2->fl_xid = xid;
4737 +               vx_locks_inc(new_fl2);
4738         }
4739  
4740         lock_kernel();
4741 @@ -1019,7 +1046,8 @@ static int __posix_lock_file(struct inod
4742  int posix_lock_file(struct file *filp, struct file_lock *fl,
4743                         struct file_lock *conflock)
4744  {
4745 -       return __posix_lock_file(filp->f_path.dentry->d_inode, fl, conflock);
4746 +       return __posix_lock_file(filp->f_path.dentry->d_inode,
4747 +               fl, conflock, filp->f_xid);
4748  }
4749  EXPORT_SYMBOL(posix_lock_file);
4750  
4751 @@ -1109,7 +1137,7 @@ int locks_mandatory_area(int read_write,
4752         fl.fl_end = offset + count - 1;
4753  
4754         for (;;) {
4755 -               error = __posix_lock_file(inode, &fl, NULL);
4756 +               error = __posix_lock_file(inode, &fl, NULL, filp->f_xid);
4757                 if (error != FILE_LOCK_DEFERRED)
4758                         break;
4759                 error = wait_event_interruptible(fl.fl_wait, !fl.fl_next);
4760 @@ -1424,6 +1452,7 @@ int generic_setlease(struct file *filp, 
4761  
4762         locks_copy_lock(new_fl, lease);
4763         locks_insert_lock(before, new_fl);
4764 +       vx_locks_inc(new_fl);
4765  
4766         *flp = new_fl;
4767         return 0;
4768 @@ -1779,6 +1808,11 @@ int fcntl_setlk(unsigned int fd, struct 
4769         if (file_lock == NULL)
4770                 return -ENOLCK;
4771  
4772 +       vxd_assert(filp->f_xid == vx_current_xid(),
4773 +               "f_xid(%d) == current(%d)", filp->f_xid, vx_current_xid());
4774 +       file_lock->fl_xid = filp->f_xid;
4775 +       vx_locks_inc(file_lock);
4776 +
4777         /*
4778          * This might block, so we do it before checking the inode.
4779          */
4780 @@ -1897,6 +1931,11 @@ int fcntl_setlk64(unsigned int fd, struc
4781         if (file_lock == NULL)
4782                 return -ENOLCK;
4783  
4784 +       vxd_assert(filp->f_xid == vx_current_xid(),
4785 +               "f_xid(%d) == current(%d)", filp->f_xid, vx_current_xid());
4786 +       file_lock->fl_xid = filp->f_xid;
4787 +       vx_locks_inc(file_lock);
4788 +
4789         /*
4790          * This might block, so we do it before checking the inode.
4791          */
4792 @@ -2162,8 +2201,11 @@ static int locks_show(struct seq_file *f
4793  
4794         lock_get_status(f, fl, (long)f->private, "");
4795  
4796 -       list_for_each_entry(bfl, &fl->fl_block, fl_block)
4797 +       list_for_each_entry(bfl, &fl->fl_block, fl_block) {
4798 +               if (!vx_check(fl->fl_xid, VS_WATCH_P | VS_IDENT))
4799 +                       continue;
4800                 lock_get_status(f, bfl, (long)f->private, " ->");
4801 +       }
4802  
4803         f->private++;
4804         return 0;
4805 diff -NurpP --minimal linux-2.6.32.1/fs/namei.c linux-2.6.32.1-vs2.3.0.36.27/fs/namei.c
4806 --- linux-2.6.32.1/fs/namei.c   2009-12-03 20:02:52.000000000 +0100
4807 +++ linux-2.6.32.1-vs2.3.0.36.27/fs/namei.c     2009-12-03 20:04:56.000000000 +0100
4808 @@ -33,6 +33,14 @@
4809  #include <linux/fcntl.h>
4810  #include <linux/device_cgroup.h>
4811  #include <linux/fs_struct.h>
4812 +#include <linux/proc_fs.h>
4813 +#include <linux/vserver/inode.h>
4814 +#include <linux/vs_base.h>
4815 +#include <linux/vs_tag.h>
4816 +#include <linux/vs_cowbl.h>
4817 +#include <linux/vs_device.h>
4818 +#include <linux/vs_context.h>
4819 +#include <linux/pid_namespace.h>
4820  #include <asm/uaccess.h>
4821  
4822  #define ACC_MODE(x) ("\000\004\002\006"[(x)&O_ACCMODE])
4823 @@ -169,6 +177,77 @@ void putname(const char *name)
4824  EXPORT_SYMBOL(putname);
4825  #endif
4826  
4827 +static inline int dx_barrier(const struct inode *inode)
4828 +{
4829 +       if (IS_BARRIER(inode) && !vx_check(0, VS_ADMIN | VS_WATCH)) {
4830 +               vxwprintk_task(1, "did hit the barrier.");
4831 +               return 1;
4832 +       }
4833 +       return 0;
4834 +}
4835 +
4836 +static int __dx_permission(const struct inode *inode, int mask)
4837 +{
4838 +       if (dx_barrier(inode))
4839 +               return -EACCES;
4840 +
4841 +       if (inode->i_sb->s_magic == DEVPTS_SUPER_MAGIC) {
4842 +               /* devpts is xid tagged */
4843 +               if (S_ISDIR(inode->i_mode) ||
4844 +                   vx_check((xid_t)inode->i_tag, VS_IDENT | VS_WATCH_P))
4845 +                       return 0;
4846 +       }
4847 +       else if (inode->i_sb->s_magic == PROC_SUPER_MAGIC) {
4848 +               struct proc_dir_entry *de = PDE(inode);
4849 +
4850 +               if (de && !vx_hide_check(0, de->vx_flags))
4851 +                       goto out;
4852 +
4853 +               if ((mask & (MAY_WRITE | MAY_APPEND))) {
4854 +                       struct pid *pid;
4855 +                       struct task_struct *tsk;
4856 +
4857 +                       if (vx_check(0, VS_ADMIN | VS_WATCH_P) ||
4858 +                           vx_flags(VXF_STATE_SETUP, 0))
4859 +                               return 0;
4860 +
4861 +                       pid = PROC_I(inode)->pid;
4862 +                       if (!pid)
4863 +                               goto out;
4864 +
4865 +                       tsk = pid_task(pid, PIDTYPE_PID);
4866 +                       vxdprintk(VXD_CBIT(tag, 0), "accessing %p[#%u]",
4867 +                                 tsk, (tsk ? vx_task_xid(tsk) : 0));
4868 +                       if (tsk && vx_check(vx_task_xid(tsk), VS_IDENT | VS_WATCH_P))
4869 +                               return 0;
4870 +               }
4871 +               else {
4872 +                       /* FIXME: Should we block some entries here? */
4873 +                       return 0;
4874 +               }
4875 +       }
4876 +       else {
4877 +               if (dx_notagcheck(inode->i_sb) ||
4878 +                   dx_check(inode->i_tag, DX_HOSTID | DX_ADMIN | DX_WATCH |
4879 +                            DX_IDENT))
4880 +                       return 0;
4881 +       }
4882 +
4883 +out:
4884 +       return -EACCES;
4885 +}
4886 +
4887 +int dx_permission(const struct inode *inode, int mask)
4888 +{
4889 +       int ret = __dx_permission(inode, mask);
4890 +       if (unlikely(ret)) {
4891 +               vxwprintk_task(1, "denied %x access to %s:%p[#%d,%lu]",
4892 +                       mask, inode->i_sb->s_id, inode, inode->i_tag,
4893 +                       inode->i_ino);
4894 +       }
4895 +       return ret;
4896 +}
4897 +
4898  /*
4899   * This does basic POSIX ACL permission checking
4900   */
4901 @@ -268,10 +347,14 @@ int inode_permission(struct inode *inode
4902                 /*
4903                  * Nobody gets write access to an immutable file.
4904                  */
4905 -               if (IS_IMMUTABLE(inode))
4906 +               if (IS_IMMUTABLE(inode) && !IS_COW(inode))
4907                         return -EACCES;
4908         }
4909  
4910 +       retval = dx_permission(inode, mask);
4911 +       if (retval)
4912 +               return retval;
4913 +
4914         if (inode->i_op->permission)
4915                 retval = inode->i_op->permission(inode, mask);
4916         else
4917 @@ -447,6 +530,9 @@ static int exec_permission_lite(struct i
4918  {
4919         int ret;
4920  
4921 +       if (dx_barrier(inode))
4922 +               return -EACCES;
4923 +
4924         if (inode->i_op->permission) {
4925                 ret = inode->i_op->permission(inode, MAY_EXEC);
4926                 if (!ret)
4927 @@ -762,7 +848,8 @@ static __always_inline void follow_dotdo
4928  
4929                 if (nd->path.dentry == nd->root.dentry &&
4930                     nd->path.mnt == nd->root.mnt) {
4931 -                       break;
4932 +                       /* for sane '/' avoid follow_mount() */
4933 +                       return;
4934                 }
4935                 spin_lock(&dcache_lock);
4936                 if (nd->path.dentry != nd->path.mnt->mnt_root) {
4937 @@ -798,16 +885,30 @@ static int do_lookup(struct nameidata *n
4938  {
4939         struct vfsmount *mnt = nd->path.mnt;
4940         struct dentry *dentry = __d_lookup(nd->path.dentry, name);
4941 +       struct inode *inode;
4942  
4943         if (!dentry)
4944                 goto need_lookup;
4945         if (dentry->d_op && dentry->d_op->d_revalidate)
4946                 goto need_revalidate;
4947 +       inode = dentry->d_inode;
4948 +       if (!inode)
4949 +               goto done;
4950 +
4951 +       if (__dx_permission(inode, MAY_ACCESS))
4952 +               goto hidden;
4953 +
4954  done:
4955         path->mnt = mnt;
4956         path->dentry = dentry;
4957         __follow_mount(path);
4958         return 0;
4959 +hidden:
4960 +       vxwprintk_task(1, "did lookup hidden %s:%p[#%d,%lu] Â»%s/%.*s«.",
4961 +               inode->i_sb->s_id, inode, inode->i_tag, inode->i_ino,
4962 +               vxd_path(&nd->path), name->len, name->name);
4963 +       dput(dentry);
4964 +       return -ENOENT;
4965  
4966  need_lookup:
4967         dentry = real_lookup(nd->path.dentry, name, nd);
4968 @@ -1389,7 +1490,7 @@ static int may_delete(struct inode *dir,
4969         if (IS_APPEND(dir))
4970                 return -EPERM;
4971         if (check_sticky(dir, victim->d_inode)||IS_APPEND(victim->d_inode)||
4972 -           IS_IMMUTABLE(victim->d_inode) || IS_SWAPFILE(victim->d_inode))
4973 +               IS_IXORUNLINK(victim->d_inode) || IS_SWAPFILE(victim->d_inode))
4974                 return -EPERM;
4975         if (isdir) {
4976                 if (!S_ISDIR(victim->d_inode->i_mode))
4977 @@ -1529,6 +1630,14 @@ int may_open(struct path *path, int acc_
4978                 break;
4979         }
4980  
4981 +#ifdef CONFIG_VSERVER_COWBL
4982 +       if (IS_COW(inode) && (flag & FMODE_WRITE)) {
4983 +               if (IS_COW_LINK(inode))
4984 +                       return -EMLINK;
4985 +               inode->i_flags &= ~(S_IXUNLINK|S_IMMUTABLE);
4986 +               mark_inode_dirty(inode);
4987 +       }
4988 +#endif
4989         error = inode_permission(inode, acc_mode);
4990         if (error)
4991                 return error;
4992 @@ -1677,7 +1786,11 @@ struct file *do_filp_open(int dfd, const
4993         int count = 0;
4994         int will_write;
4995         int flag = open_to_namei_flags(open_flag);
4996 -
4997 +#ifdef CONFIG_VSERVER_COWBL
4998 +       int rflag = flag;
4999 +       int rmode = mode;
5000 +restart:
5001 +#endif
5002         if (!acc_mode)
5003                 acc_mode = MAY_OPEN | ACC_MODE(flag);
5004  
5005 @@ -1825,6 +1938,25 @@ ok:
5006                         goto exit;
5007         }
5008         error = may_open(&nd.path, acc_mode, flag);
5009 +#ifdef CONFIG_VSERVER_COWBL
5010 +       if (error == -EMLINK) {
5011 +               struct dentry *dentry;
5012 +               dentry = cow_break_link(pathname);
5013 +               if (IS_ERR(dentry)) {
5014 +                       error = PTR_ERR(dentry);
5015 +                       goto exit_cow;
5016 +               }
5017 +               dput(dentry);
5018 +               if (will_write)
5019 +                       mnt_drop_write(nd.path.mnt);
5020 +               release_open_intent(&nd);
5021 +               path_put(&nd.path);
5022 +               flag = rflag;
5023 +               mode = rmode;
5024 +               goto restart;
5025 +       }
5026 +exit_cow:
5027 +#endif
5028         if (error) {
5029                 if (will_write)
5030                         mnt_drop_write(nd.path.mnt);
5031 @@ -1987,9 +2119,17 @@ int vfs_mknod(struct inode *dir, struct 
5032         if (error)
5033                 return error;
5034  
5035 -       if ((S_ISCHR(mode) || S_ISBLK(mode)) && !capable(CAP_MKNOD))
5036 +       if (!(S_ISCHR(mode) || S_ISBLK(mode)))
5037 +               goto okay;
5038 +
5039 +       if (!capable(CAP_MKNOD))
5040                 return -EPERM;
5041  
5042 +       if (S_ISCHR(mode) && !vs_chrdev_perm(dev, DATTR_CREATE))
5043 +               return -EPERM;
5044 +       if (S_ISBLK(mode) && !vs_blkdev_perm(dev, DATTR_CREATE))
5045 +               return -EPERM;
5046 +okay:
5047         if (!dir->i_op->mknod)
5048                 return -EPERM;
5049  
5050 @@ -2456,7 +2596,7 @@ int vfs_link(struct dentry *old_dentry, 
5051         /*
5052          * A link to an append-only or immutable file cannot be created.
5053          */
5054 -       if (IS_APPEND(inode) || IS_IMMUTABLE(inode))
5055 +       if (IS_APPEND(inode) || IS_IXORUNLINK(inode))
5056                 return -EPERM;
5057         if (!dir->i_op->link)
5058                 return -EPERM;
5059 @@ -2829,6 +2969,219 @@ int vfs_follow_link(struct nameidata *nd
5060         return __vfs_follow_link(nd, link);
5061  }
5062  
5063 +
5064 +#ifdef CONFIG_VSERVER_COWBL
5065 +
5066 +#include <linux/file.h>
5067 +
5068 +static inline
5069 +long do_cow_splice(struct file *in, struct file *out, size_t len)
5070 +{
5071 +       loff_t ppos = 0;
5072 +
5073 +       return do_splice_direct(in, &ppos, out, len, 0);
5074 +}
5075 +
5076 +struct dentry *cow_break_link(const char *pathname)
5077 +{
5078 +       int ret, mode, pathlen, redo = 0;
5079 +       struct nameidata old_nd, dir_nd;
5080 +       struct path old_path, new_path;
5081 +       struct dentry *dir, *res = NULL;
5082 +       struct file *old_file;
5083 +       struct file *new_file;
5084 +       char *to, *path, pad='\251';
5085 +       loff_t size;
5086 +
5087 +       vxdprintk(VXD_CBIT(misc, 1), "cow_break_link(»%s«)", pathname);
5088 +       path = kmalloc(PATH_MAX, GFP_KERNEL);
5089 +       ret = -ENOMEM;
5090 +       if (!path)
5091 +               goto out;
5092 +
5093 +       /* old_nd will have refs to dentry and mnt */
5094 +       ret = path_lookup(pathname, LOOKUP_FOLLOW, &old_nd);
5095 +       vxdprintk(VXD_CBIT(misc, 2), "path_lookup(old): %d", ret);
5096 +       if (ret < 0)
5097 +               goto out_free_path;
5098 +
5099 +       old_path = old_nd.path;
5100 +       mode = old_path.dentry->d_inode->i_mode;
5101 +
5102 +       to = d_path(&old_path, path, PATH_MAX-2);
5103 +       pathlen = strlen(to);
5104 +       vxdprintk(VXD_CBIT(misc, 2), "old path Â»%s« [»%.*s«:%d]", to,
5105 +               old_path.dentry->d_name.len, old_path.dentry->d_name.name,
5106 +               old_path.dentry->d_name.len);
5107 +
5108 +       to[pathlen + 1] = 0;
5109 +retry:
5110 +       to[pathlen] = pad--;
5111 +       ret = -EMLINK;
5112 +       if (pad <= '\240')
5113 +               goto out_rel_old;
5114 +
5115 +       vxdprintk(VXD_CBIT(misc, 1), "temp copy Â»%s«", to);
5116 +       /* dir_nd will have refs to dentry and mnt */
5117 +       ret = path_lookup(to,
5118 +               LOOKUP_PARENT | LOOKUP_OPEN | LOOKUP_CREATE, &dir_nd);
5119 +       vxdprintk(VXD_CBIT(misc, 2),
5120 +               "path_lookup(new): %d", ret);
5121 +       if (ret < 0)
5122 +               goto retry;
5123 +
5124 +       /* this puppy downs the inode mutex */
5125 +       new_path.dentry = lookup_create(&dir_nd, 0);
5126 +       if (!new_path.dentry || IS_ERR(new_path.dentry)) {
5127 +               vxdprintk(VXD_CBIT(misc, 2),
5128 +                       "lookup_create(new): %p", new_path.dentry);
5129 +               mutex_unlock(&dir_nd.path.dentry->d_inode->i_mutex);
5130 +               path_put(&dir_nd.path);
5131 +               goto retry;
5132 +       }
5133 +       vxdprintk(VXD_CBIT(misc, 2),
5134 +               "lookup_create(new): %p [»%.*s«:%d]", new_path.dentry,
5135 +               new_path.dentry->d_name.len, new_path.dentry->d_name.name,
5136 +               new_path.dentry->d_name.len);
5137 +       dir = dir_nd.path.dentry;
5138 +
5139 +       ret = vfs_create(dir_nd.path.dentry->d_inode, new_path.dentry, mode, &dir_nd);
5140 +       vxdprintk(VXD_CBIT(misc, 2),
5141 +               "vfs_create(new): %d", ret);
5142 +       if (ret == -EEXIST) {
5143 +               mutex_unlock(&dir->d_inode->i_mutex);
5144 +               dput(new_path.dentry);
5145 +               path_put(&dir_nd.path);
5146 +               goto retry;
5147 +       }
5148 +       else if (ret < 0)
5149 +               goto out_unlock_new;
5150 +
5151 +       /* drop out early, ret passes ENOENT */
5152 +       ret = -ENOENT;
5153 +       if ((redo = d_unhashed(old_path.dentry)))
5154 +               goto out_unlock_new;
5155 +
5156 +       new_path.mnt = dir_nd.path.mnt;
5157 +       dget(old_path.dentry);
5158 +       mntget(old_path.mnt);
5159 +       /* this one cleans up the dentry/mnt in case of failure */
5160 +       old_file = dentry_open(old_path.dentry, old_path.mnt,
5161 +               O_RDONLY, current_cred());
5162 +       vxdprintk(VXD_CBIT(misc, 2),
5163 +               "dentry_open(old): %p", old_file);
5164 +       if (!old_file || IS_ERR(old_file)) {
5165 +               res = IS_ERR(old_file) ? (void *) old_file : res;
5166 +               goto out_unlock_new;
5167 +       }
5168 +
5169 +       dget(new_path.dentry);
5170 +       mntget(new_path.mnt);
5171 +       /* this one cleans up the dentry/mnt in case of failure */
5172 +       new_file = dentry_open(new_path.dentry, new_path.mnt,
5173 +               O_WRONLY, current_cred());
5174 +       vxdprintk(VXD_CBIT(misc, 2),
5175 +               "dentry_open(new): %p", new_file);
5176 +
5177 +       ret = IS_ERR(new_file) ? PTR_ERR(new_file) : -ENOENT;
5178 +       if (!new_file || IS_ERR(new_file))
5179 +               goto out_fput_old;
5180 +
5181 +       size = i_size_read(old_file->f_dentry->d_inode);
5182 +       ret = do_cow_splice(old_file, new_file, size);
5183 +       vxdprintk(VXD_CBIT(misc, 2), "do_splice_direct: %d", ret);
5184 +       if (ret < 0) {
5185 +               goto out_fput_both;
5186 +       } else if (ret < size) {
5187 +               ret = -ENOSPC;
5188 +               goto out_fput_both;
5189 +       } else {
5190 +               struct inode *old_inode = old_path.dentry->d_inode;
5191 +               struct inode *new_inode = new_path.dentry->d_inode;
5192 +               struct iattr attr = {
5193 +                       .ia_uid = old_inode->i_uid,
5194 +                       .ia_gid = old_inode->i_gid,
5195 +                       .ia_valid = ATTR_UID | ATTR_GID
5196 +                       };
5197 +
5198 +               ret = inode_setattr(new_inode, &attr);
5199 +               if (ret)
5200 +                       goto out_fput_both;
5201 +       }
5202 +
5203 +       mutex_lock(&old_path.dentry->d_inode->i_sb->s_vfs_rename_mutex);
5204 +
5205 +       /* drop out late */
5206 +       ret = -ENOENT;
5207 +       if ((redo = d_unhashed(old_path.dentry)))
5208 +               goto out_unlock;
5209 +
5210 +       vxdprintk(VXD_CBIT(misc, 2),
5211 +               "vfs_rename: [»%*s«:%d] -> [»%*s«:%d]",
5212 +               new_path.dentry->d_name.len, new_path.dentry->d_name.name,
5213 +               new_path.dentry->d_name.len,
5214 +               old_path.dentry->d_name.len, old_path.dentry->d_name.name,
5215 +               old_path.dentry->d_name.len);
5216 +       ret = vfs_rename(dir_nd.path.dentry->d_inode, new_path.dentry,
5217 +               old_nd.path.dentry->d_parent->d_inode, old_path.dentry);
5218 +       vxdprintk(VXD_CBIT(misc, 2), "vfs_rename: %d", ret);
5219 +       res = new_path.dentry;
5220 +
5221 +out_unlock:
5222 +       mutex_unlock(&old_path.dentry->d_inode->i_sb->s_vfs_rename_mutex);
5223 +
5224 +out_fput_both:
5225 +       vxdprintk(VXD_CBIT(misc, 3),
5226 +               "fput(new_file=%p[#%ld])", new_file,
5227 +               atomic_long_read(&new_file->f_count));
5228 +       fput(new_file);
5229 +
5230 +out_fput_old:
5231 +       vxdprintk(VXD_CBIT(misc, 3),
5232 +               "fput(old_file=%p[#%ld])", old_file,
5233 +               atomic_long_read(&old_file->f_count));
5234 +       fput(old_file);
5235 +
5236 +out_unlock_new:
5237 +       mutex_unlock(&dir->d_inode->i_mutex);
5238 +       if (!ret)
5239 +               goto out_redo;
5240 +
5241 +       /* error path cleanup */
5242 +       vfs_unlink(dir->d_inode, new_path.dentry);
5243 +       dput(new_path.dentry);
5244 +
5245 +out_redo:
5246 +       if (!redo)
5247 +               goto out_rel_both;
5248 +       /* lookup dentry once again */
5249 +       path_put(&old_nd.path);
5250 +       ret = path_lookup(pathname, LOOKUP_FOLLOW, &old_nd);
5251 +       if (ret)
5252 +               goto out_rel_both;
5253 +
5254 +       new_path.dentry = old_nd.path.dentry;
5255 +       vxdprintk(VXD_CBIT(misc, 2),
5256 +               "path_lookup(redo): %p [»%.*s«:%d]", new_path.dentry,
5257 +               new_path.dentry->d_name.len, new_path.dentry->d_name.name,
5258 +               new_path.dentry->d_name.len);
5259 +       dget(new_path.dentry);
5260 +       res = new_path.dentry;
5261 +
5262 +out_rel_both:
5263 +       path_put(&dir_nd.path);
5264 +out_rel_old:
5265 +       path_put(&old_nd.path);
5266 +out_free_path:
5267 +       kfree(path);
5268 +out:
5269 +       if (ret)
5270 +               res = ERR_PTR(ret);
5271 +       return res;
5272 +}
5273 +
5274 +#endif
5275 +
5276  /* get the link contents into pagecache */
5277  static char *page_getlink(struct dentry * dentry, struct page **ppage)
5278  {
5279 diff -NurpP --minimal linux-2.6.32.1/fs/namespace.c linux-2.6.32.1-vs2.3.0.36.27/fs/namespace.c
5280 --- linux-2.6.32.1/fs/namespace.c       2009-12-03 20:02:52.000000000 +0100
5281 +++ linux-2.6.32.1-vs2.3.0.36.27/fs/namespace.c 2009-12-03 20:04:56.000000000 +0100
5282 @@ -29,6 +29,11 @@
5283  #include <linux/log2.h>
5284  #include <linux/idr.h>
5285  #include <linux/fs_struct.h>
5286 +#include <linux/vs_base.h>
5287 +#include <linux/vs_context.h>
5288 +#include <linux/vs_tag.h>
5289 +#include <linux/vserver/space.h>
5290 +#include <linux/vserver/global.h>
5291  #include <asm/uaccess.h>
5292  #include <asm/unistd.h>
5293  #include "pnode.h"
5294 @@ -567,6 +572,7 @@ static struct vfsmount *clone_mnt(struct
5295                 mnt->mnt_root = dget(root);
5296                 mnt->mnt_mountpoint = mnt->mnt_root;
5297                 mnt->mnt_parent = mnt;
5298 +               mnt->mnt_tag = old->mnt_tag;
5299  
5300                 if (flag & CL_SLAVE) {
5301                         list_add(&mnt->mnt_slave, &old->mnt_slave_list);
5302 @@ -661,6 +667,31 @@ static inline void mangle(struct seq_fil
5303         seq_escape(m, s, " \t\n\\");
5304  }
5305  
5306 +static int mnt_is_reachable(struct vfsmount *mnt)
5307 +{
5308 +       struct path root;
5309 +       struct dentry *point;
5310 +       int ret;
5311 +
5312 +       if (mnt == mnt->mnt_ns->root)
5313 +               return 1;
5314 +
5315 +       spin_lock(&vfsmount_lock);
5316 +       root = current->fs->root;
5317 +       point = root.dentry;
5318 +
5319 +       while ((mnt != mnt->mnt_parent) && (mnt != root.mnt)) {
5320 +               point = mnt->mnt_mountpoint;
5321 +               mnt = mnt->mnt_parent;
5322 +       }
5323 +
5324 +       ret = (mnt == root.mnt) && is_subdir(point, root.dentry);
5325 +
5326 +       spin_unlock(&vfsmount_lock);
5327 +
5328 +       return ret;
5329 +}
5330 +
5331  /*
5332   * Simple .show_options callback for filesystems which don't want to
5333   * implement more complex mount option showing.
5334 @@ -748,6 +779,8 @@ static int show_sb_opts(struct seq_file 
5335                 { MS_SYNCHRONOUS, ",sync" },
5336                 { MS_DIRSYNC, ",dirsync" },
5337                 { MS_MANDLOCK, ",mand" },
5338 +               { MS_TAGGED, ",tag" },
5339 +               { MS_NOTAGCHECK, ",notagcheck" },
5340                 { 0, NULL }
5341         };
5342         const struct proc_fs_info *fs_infop;
5343 @@ -795,10 +828,20 @@ static int show_vfsmnt(struct seq_file *
5344         int err = 0;
5345         struct path mnt_path = { .dentry = mnt->mnt_root, .mnt = mnt };
5346  
5347 -       mangle(m, mnt->mnt_devname ? mnt->mnt_devname : "none");
5348 -       seq_putc(m, ' ');
5349 -       seq_path(m, &mnt_path, " \t\n\\");
5350 -       seq_putc(m, ' ');
5351 +       if (vx_flags(VXF_HIDE_MOUNT, 0))
5352 +               return SEQ_SKIP;
5353 +       if (!mnt_is_reachable(mnt) && !vx_check(0, VS_WATCH_P))
5354 +               return SEQ_SKIP;
5355 +
5356 +       if (!vx_check(0, VS_ADMIN|VS_WATCH) &&
5357 +               mnt == current->fs->root.mnt) {
5358 +               seq_puts(m, "/dev/root / ");
5359 +       } else {
5360 +               mangle(m, mnt->mnt_devname ? mnt->mnt_devname : "none");
5361 +               seq_putc(m, ' ');
5362 +               seq_path(m, &mnt_path, " \t\n\\");
5363 +               seq_putc(m, ' ');
5364 +       }
5365         show_type(m, mnt->mnt_sb);
5366         seq_puts(m, __mnt_is_readonly(mnt) ? " ro" : " rw");
5367         err = show_sb_opts(m, mnt->mnt_sb);
5368 @@ -828,6 +871,11 @@ static int show_mountinfo(struct seq_fil
5369         struct path root = p->root;
5370         int err = 0;
5371  
5372 +       if (vx_flags(VXF_HIDE_MOUNT, 0))
5373 +               return SEQ_SKIP;
5374 +       if (!mnt_is_reachable(mnt) && !vx_check(0, VS_WATCH_P))
5375 +               return SEQ_SKIP;
5376 +
5377         seq_printf(m, "%i %i %u:%u ", mnt->mnt_id, mnt->mnt_parent->mnt_id,
5378                    MAJOR(sb->s_dev), MINOR(sb->s_dev));
5379         seq_dentry(m, mnt->mnt_root, " \t\n\\");
5380 @@ -886,17 +934,27 @@ static int show_vfsstat(struct seq_file 
5381         struct path mnt_path = { .dentry = mnt->mnt_root, .mnt = mnt };
5382         int err = 0;
5383  
5384 -       /* device */
5385 -       if (mnt->mnt_devname) {
5386 -               seq_puts(m, "device ");
5387 -               mangle(m, mnt->mnt_devname);
5388 -       } else
5389 -               seq_puts(m, "no device");
5390 +       if (vx_flags(VXF_HIDE_MOUNT, 0))
5391 +               return SEQ_SKIP;
5392 +       if (!mnt_is_reachable(mnt) && !vx_check(0, VS_WATCH_P))
5393 +               return SEQ_SKIP;
5394  
5395 -       /* mount point */
5396 -       seq_puts(m, " mounted on ");
5397 -       seq_path(m, &mnt_path, " \t\n\\");
5398 -       seq_putc(m, ' ');
5399 +       if (!vx_check(0, VS_ADMIN|VS_WATCH) &&
5400 +               mnt == current->fs->root.mnt) {
5401 +               seq_puts(m, "device /dev/root mounted on / ");
5402 +       } else {
5403 +               /* device */
5404 +               if (mnt->mnt_devname) {
5405 +                       seq_puts(m, "device ");
5406 +                       mangle(m, mnt->mnt_devname);
5407 +               } else
5408 +                       seq_puts(m, "no device");
5409 +
5410 +               /* mount point */
5411 +               seq_puts(m, " mounted on ");
5412 +               seq_path(m, &mnt_path, " \t\n\\");
5413 +               seq_putc(m, ' ');
5414 +       }
5415  
5416         /* file system type */
5417         seq_puts(m, "with fstype ");
5418 @@ -1130,7 +1188,7 @@ SYSCALL_DEFINE2(umount, char __user *, n
5419                 goto dput_and_out;
5420  
5421         retval = -EPERM;
5422 -       if (!capable(CAP_SYS_ADMIN))
5423 +       if (!vx_capable(CAP_SYS_ADMIN, VXC_SECURE_MOUNT))
5424                 goto dput_and_out;
5425  
5426         retval = do_umount(path.mnt, flags);
5427 @@ -1156,7 +1214,7 @@ SYSCALL_DEFINE1(oldumount, char __user *
5428  
5429  static int mount_is_safe(struct path *path)
5430  {
5431 -       if (capable(CAP_SYS_ADMIN))
5432 +       if (vx_capable(CAP_SYS_ADMIN, VXC_SECURE_MOUNT))
5433                 return 0;
5434         return -EPERM;
5435  #ifdef notyet
5436 @@ -1420,7 +1478,7 @@ static int do_change_type(struct path *p
5437         int type = flag & ~MS_REC;
5438         int err = 0;
5439  
5440 -       if (!capable(CAP_SYS_ADMIN))
5441 +       if (!vx_capable(CAP_SYS_ADMIN, VXC_NAMESPACE))
5442                 return -EPERM;
5443  
5444         if (path->dentry != path->mnt->mnt_root)
5445 @@ -1447,11 +1505,13 @@ static int do_change_type(struct path *p
5446   * do loopback mount.
5447   */
5448  static int do_loopback(struct path *path, char *old_name,
5449 -                               int recurse)
5450 +       tag_t tag, unsigned long flags, int mnt_flags)
5451  {
5452         struct path old_path;
5453         struct vfsmount *mnt = NULL;
5454         int err = mount_is_safe(path);
5455 +       int recurse = flags & MS_REC;
5456 +
5457         if (err)
5458                 return err;
5459         if (!old_name || !*old_name)
5460 @@ -1485,6 +1545,7 @@ static int do_loopback(struct path *path
5461                 spin_unlock(&vfsmount_lock);
5462                 release_mounts(&umount_list);
5463         }
5464 +       mnt->mnt_flags = mnt_flags;
5465  
5466  out:
5467         up_write(&namespace_sem);
5468 @@ -1515,12 +1576,12 @@ static int change_mount_flags(struct vfs
5469   * on it - tough luck.
5470   */
5471  static int do_remount(struct path *path, int flags, int mnt_flags,
5472 -                     void *data)
5473 +       void *data, xid_t xid)
5474  {
5475         int err;
5476         struct super_block *sb = path->mnt->mnt_sb;
5477  
5478 -       if (!capable(CAP_SYS_ADMIN))
5479 +       if (!vx_capable(CAP_SYS_ADMIN, VXC_SECURE_REMOUNT))
5480                 return -EPERM;
5481  
5482         if (!check_mnt(path->mnt))
5483 @@ -1562,7 +1623,7 @@ static int do_move_mount(struct path *pa
5484         struct path old_path, parent_path;
5485         struct vfsmount *p;
5486         int err = 0;
5487 -       if (!capable(CAP_SYS_ADMIN))
5488 +       if (!vx_capable(CAP_SYS_ADMIN, VXC_SECURE_MOUNT))
5489                 return -EPERM;
5490         if (!old_name || !*old_name)
5491                 return -EINVAL;
5492 @@ -1644,7 +1705,7 @@ static int do_new_mount(struct path *pat
5493                 return -EINVAL;
5494  
5495         /* we need capabilities... */
5496 -       if (!capable(CAP_SYS_ADMIN))
5497 +       if (!vx_capable(CAP_SYS_ADMIN, VXC_SECURE_MOUNT))
5498                 return -EPERM;
5499  
5500         lock_kernel();
5501 @@ -1908,6 +1969,7 @@ long do_mount(char *dev_name, char *dir_
5502         struct path path;
5503         int retval = 0;
5504         int mnt_flags = 0;
5505 +       tag_t tag = 0;
5506  
5507         /* Discard magic */
5508         if ((flags & MS_MGC_MSK) == MS_MGC_VAL)
5509 @@ -1925,6 +1987,12 @@ long do_mount(char *dev_name, char *dir_
5510         if (!(flags & MS_NOATIME))
5511                 mnt_flags |= MNT_RELATIME;
5512  
5513 +       if (dx_parse_tag(data_page, &tag, 1, &mnt_flags, &flags)) {
5514 +               /* FIXME: bind and re-mounts get the tag flag? */
5515 +               if (flags & (MS_BIND|MS_REMOUNT))
5516 +                       flags |= MS_TAGID;
5517 +       }
5518 +
5519         /* Separate the per-mountpoint flags */
5520         if (flags & MS_NOSUID)
5521                 mnt_flags |= MNT_NOSUID;
5522 @@ -1941,6 +2009,8 @@ long do_mount(char *dev_name, char *dir_
5523         if (flags & MS_RDONLY)
5524                 mnt_flags |= MNT_READONLY;
5525  
5526 +       if (!capable(CAP_SYS_ADMIN))
5527 +               mnt_flags |= MNT_NODEV;
5528         flags &= ~(MS_NOSUID | MS_NOEXEC | MS_NODEV | MS_ACTIVE |
5529                    MS_NOATIME | MS_NODIRATIME | MS_RELATIME| MS_KERNMOUNT |
5530                    MS_STRICTATIME);
5531 @@ -1957,9 +2027,9 @@ long do_mount(char *dev_name, char *dir_
5532  
5533         if (flags & MS_REMOUNT)
5534                 retval = do_remount(&path, flags & ~MS_REMOUNT, mnt_flags,
5535 -                                   data_page);
5536 +                                   data_page, tag);
5537         else if (flags & MS_BIND)
5538 -               retval = do_loopback(&path, dev_name, flags & MS_REC);
5539 +               retval = do_loopback(&path, dev_name, tag, flags, mnt_flags);
5540         else if (flags & (MS_SHARED | MS_PRIVATE | MS_SLAVE | MS_UNBINDABLE))
5541                 retval = do_change_type(&path, flags);
5542         else if (flags & MS_MOVE)
5543 @@ -2038,6 +2108,7 @@ static struct mnt_namespace *dup_mnt_ns(
5544                 q = next_mnt(q, new_ns->root);
5545         }
5546         up_write(&namespace_sem);
5547 +       atomic_inc(&vs_global_mnt_ns);
5548  
5549         if (rootmnt)
5550                 mntput(rootmnt);
5551 @@ -2182,9 +2253,10 @@ SYSCALL_DEFINE2(pivot_root, const char _
5552         down_write(&namespace_sem);
5553         mutex_lock(&old.dentry->d_inode->i_mutex);
5554         error = -EINVAL;
5555 -       if (IS_MNT_SHARED(old.mnt) ||
5556 +       if ((IS_MNT_SHARED(old.mnt) ||
5557                 IS_MNT_SHARED(new.mnt->mnt_parent) ||
5558 -               IS_MNT_SHARED(root.mnt->mnt_parent))
5559 +               IS_MNT_SHARED(root.mnt->mnt_parent)) &&
5560 +               !vx_flags(VXF_STATE_SETUP, 0))
5561                 goto out2;
5562         if (!check_mnt(root.mnt))
5563                 goto out2;
5564 @@ -2320,6 +2392,7 @@ void put_mnt_ns(struct mnt_namespace *ns
5565         spin_unlock(&vfsmount_lock);
5566         up_write(&namespace_sem);
5567         release_mounts(&umount_list);
5568 +       atomic_dec(&vs_global_mnt_ns);
5569         kfree(ns);
5570  }
5571  EXPORT_SYMBOL(put_mnt_ns);
5572 diff -NurpP --minimal linux-2.6.32.1/fs/nfs/client.c linux-2.6.32.1-vs2.3.0.36.27/fs/nfs/client.c
5573 --- linux-2.6.32.1/fs/nfs/client.c      2009-12-03 20:02:52.000000000 +0100
5574 +++ linux-2.6.32.1-vs2.3.0.36.27/fs/nfs/client.c        2009-12-03 20:04:56.000000000 +0100
5575 @@ -738,6 +738,9 @@ static int nfs_init_server_rpcclient(str
5576         if (server->flags & NFS_MOUNT_SOFT)
5577                 server->client->cl_softrtry = 1;
5578  
5579 +       server->client->cl_tag = 0;
5580 +       if (server->flags & NFS_MOUNT_TAGGED)
5581 +               server->client->cl_tag = 1;
5582         return 0;
5583  }
5584  
5585 @@ -909,6 +912,10 @@ static void nfs_server_set_fsinfo(struct
5586                 server->acdirmin = server->acdirmax = 0;
5587         }
5588  
5589 +       /* FIXME: needs fsinfo
5590 +       if (server->flags & NFS_MOUNT_TAGGED)
5591 +               sb->s_flags |= MS_TAGGED;       */
5592 +
5593         server->maxfilesize = fsinfo->maxfilesize;
5594  
5595         /* We're airborne Set socket buffersize */
5596 diff -NurpP --minimal linux-2.6.32.1/fs/nfs/dir.c linux-2.6.32.1-vs2.3.0.36.27/fs/nfs/dir.c
5597 --- linux-2.6.32.1/fs/nfs/dir.c 2009-12-03 20:02:52.000000000 +0100
5598 +++ linux-2.6.32.1-vs2.3.0.36.27/fs/nfs/dir.c   2009-12-03 20:04:56.000000000 +0100
5599 @@ -33,6 +33,7 @@
5600  #include <linux/namei.h>
5601  #include <linux/mount.h>
5602  #include <linux/sched.h>
5603 +#include <linux/vs_tag.h>
5604  
5605  #include "nfs4_fs.h"
5606  #include "delegation.h"
5607 @@ -949,6 +950,7 @@ static struct dentry *nfs_lookup(struct 
5608         if (IS_ERR(res))
5609                 goto out_unblock_sillyrename;
5610  
5611 +       dx_propagate_tag(nd, inode);
5612  no_entry:
5613         res = d_materialise_unique(dentry, inode);
5614         if (res != NULL) {
5615 diff -NurpP --minimal linux-2.6.32.1/fs/nfs/inode.c linux-2.6.32.1-vs2.3.0.36.27/fs/nfs/inode.c
5616 --- linux-2.6.32.1/fs/nfs/inode.c       2009-12-03 20:02:52.000000000 +0100
5617 +++ linux-2.6.32.1-vs2.3.0.36.27/fs/nfs/inode.c 2009-12-03 20:04:56.000000000 +0100
5618 @@ -36,6 +36,7 @@
5619  #include <linux/vfs.h>
5620  #include <linux/inet.h>
5621  #include <linux/nfs_xdr.h>
5622 +#include <linux/vs_tag.h>
5623  
5624  #include <asm/system.h>
5625  #include <asm/uaccess.h>
5626 @@ -279,6 +280,8 @@ nfs_fhget(struct super_block *sb, struct
5627         if (inode->i_state & I_NEW) {
5628                 struct nfs_inode *nfsi = NFS_I(inode);
5629                 unsigned long now = jiffies;
5630 +               uid_t uid;
5631 +               gid_t gid;
5632  
5633                 /* We set i_ino for the few things that still rely on it,
5634                  * such as stat(2) */
5635 @@ -327,8 +330,8 @@ nfs_fhget(struct super_block *sb, struct
5636                 nfsi->change_attr = 0;
5637                 inode->i_size = 0;
5638                 inode->i_nlink = 0;
5639 -               inode->i_uid = -2;
5640 -               inode->i_gid = -2;
5641 +               uid = -2;
5642 +               gid = -2;
5643                 inode->i_blocks = 0;
5644                 memset(nfsi->cookieverf, 0, sizeof(nfsi->cookieverf));
5645  
5646 @@ -365,13 +368,13 @@ nfs_fhget(struct super_block *sb, struct
5647                 else if (nfs_server_capable(inode, NFS_CAP_NLINK))
5648                         nfsi->cache_validity |= NFS_INO_INVALID_ATTR;
5649                 if (fattr->valid & NFS_ATTR_FATTR_OWNER)
5650 -                       inode->i_uid = fattr->uid;
5651 +                       uid = fattr->uid;
5652                 else if (nfs_server_capable(inode, NFS_CAP_OWNER))
5653                         nfsi->cache_validity |= NFS_INO_INVALID_ATTR
5654                                 | NFS_INO_INVALID_ACCESS
5655                                 | NFS_INO_INVALID_ACL;
5656                 if (fattr->valid & NFS_ATTR_FATTR_GROUP)
5657 -                       inode->i_gid = fattr->gid;
5658 +                       gid = fattr->gid;
5659                 else if (nfs_server_capable(inode, NFS_CAP_OWNER_GROUP))
5660                         nfsi->cache_validity |= NFS_INO_INVALID_ATTR
5661                                 | NFS_INO_INVALID_ACCESS
5662 @@ -384,6 +387,11 @@ nfs_fhget(struct super_block *sb, struct
5663                          */
5664                         inode->i_blocks = nfs_calc_block_size(fattr->du.nfs3.used);
5665                 }
5666 +               inode->i_uid = INOTAG_UID(DX_TAG(inode), uid, gid);
5667 +               inode->i_gid = INOTAG_GID(DX_TAG(inode), uid, gid);
5668 +               inode->i_tag = INOTAG_TAG(DX_TAG(inode), uid, gid, 0);
5669 +                               /* maybe fattr->xid someday */
5670 +
5671                 nfsi->attrtimeo = NFS_MINATTRTIMEO(inode);
5672                 nfsi->attrtimeo_timestamp = now;
5673                 nfsi->access_cache = RB_ROOT;
5674 @@ -496,6 +504,8 @@ void nfs_setattr_update_inode(struct ino
5675                         inode->i_uid = attr->ia_uid;
5676                 if ((attr->ia_valid & ATTR_GID) != 0)
5677                         inode->i_gid = attr->ia_gid;
5678 +               if ((attr->ia_valid & ATTR_TAG) && IS_TAGGED(inode))
5679 +                       inode->i_tag = attr->ia_tag;
5680                 NFS_I(inode)->cache_validity |= NFS_INO_INVALID_ACCESS|NFS_INO_INVALID_ACL;
5681                 spin_unlock(&inode->i_lock);
5682         }
5683 @@ -906,6 +916,9 @@ static int nfs_check_inode_attributes(st
5684         struct nfs_inode *nfsi = NFS_I(inode);
5685         loff_t cur_size, new_isize;
5686         unsigned long invalid = 0;
5687 +       uid_t uid;
5688 +       gid_t gid;
5689 +       tag_t tag;
5690  
5691  
5692         /* Has the inode gone and changed behind our back? */
5693 @@ -929,13 +942,18 @@ static int nfs_check_inode_attributes(st
5694                         invalid |= NFS_INO_INVALID_ATTR|NFS_INO_REVAL_PAGECACHE;
5695         }
5696  
5697 +       uid = INOTAG_UID(DX_TAG(inode), fattr->uid, fattr->gid);
5698 +       gid = INOTAG_GID(DX_TAG(inode), fattr->uid, fattr->gid);
5699 +       tag = INOTAG_TAG(DX_TAG(inode), fattr->uid, fattr->gid, 0);
5700 +
5701         /* Have any file permissions changed? */
5702         if ((fattr->valid & NFS_ATTR_FATTR_MODE) && (inode->i_mode & S_IALLUGO) != (fattr->mode & S_IALLUGO))
5703                 invalid |= NFS_INO_INVALID_ATTR | NFS_INO_INVALID_ACCESS | NFS_INO_INVALID_ACL;
5704 -       if ((fattr->valid & NFS_ATTR_FATTR_OWNER) && inode->i_uid != fattr->uid)
5705 +       if ((fattr->valid & NFS_ATTR_FATTR_OWNER) && uid != fattr->uid)
5706                 invalid |= NFS_INO_INVALID_ATTR | NFS_INO_INVALID_ACCESS | NFS_INO_INVALID_ACL;
5707 -       if ((fattr->valid & NFS_ATTR_FATTR_GROUP) && inode->i_gid != fattr->gid)
5708 +       if ((fattr->valid & NFS_ATTR_FATTR_GROUP) && gid != fattr->gid)
5709                 invalid |= NFS_INO_INVALID_ATTR | NFS_INO_INVALID_ACCESS | NFS_INO_INVALID_ACL;
5710 +               /* maybe check for tag too? */
5711  
5712         /* Has the link count changed? */
5713         if ((fattr->valid & NFS_ATTR_FATTR_NLINK) && inode->i_nlink != fattr->nlink)
5714 @@ -1150,6 +1168,9 @@ static int nfs_update_inode(struct inode
5715         unsigned long invalid = 0;
5716         unsigned long now = jiffies;
5717         unsigned long save_cache_validity;
5718 +       uid_t uid;
5719 +       gid_t gid;
5720 +       tag_t tag;
5721  
5722         dfprintk(VFS, "NFS: %s(%s/%ld ct=%d info=0x%x)\n",
5723                         __func__, inode->i_sb->s_id, inode->i_ino,
5724 @@ -1252,6 +1273,9 @@ static int nfs_update_inode(struct inode
5725                                 | NFS_INO_REVAL_PAGECACHE
5726                                 | NFS_INO_REVAL_FORCED);
5727  
5728 +       uid = INOTAG_UID(DX_TAG(inode), fattr->uid, fattr->gid);
5729 +       gid = INOTAG_GID(DX_TAG(inode), fattr->uid, fattr->gid);
5730 +       tag = INOTAG_TAG(DX_TAG(inode), fattr->uid, fattr->gid, 0);
5731  
5732         if (fattr->valid & NFS_ATTR_FATTR_ATIME)
5733                 memcpy(&inode->i_atime, &fattr->atime, sizeof(inode->i_atime));
5734 @@ -1271,9 +1295,9 @@ static int nfs_update_inode(struct inode
5735                                 | NFS_INO_REVAL_FORCED);
5736  
5737         if (fattr->valid & NFS_ATTR_FATTR_OWNER) {
5738 -               if (inode->i_uid != fattr->uid) {
5739 +               if (uid != fattr->uid) {
5740                         invalid |= NFS_INO_INVALID_ATTR|NFS_INO_INVALID_ACCESS|NFS_INO_INVALID_ACL;
5741 -                       inode->i_uid = fattr->uid;
5742 +                       uid = fattr->uid;
5743                 }
5744         } else if (server->caps & NFS_CAP_OWNER)
5745                 invalid |= save_cache_validity & (NFS_INO_INVALID_ATTR
5746 @@ -1282,9 +1306,9 @@ static int nfs_update_inode(struct inode
5747                                 | NFS_INO_REVAL_FORCED);
5748  
5749         if (fattr->valid & NFS_ATTR_FATTR_GROUP) {
5750 -               if (inode->i_gid != fattr->gid) {
5751 +               if (gid != fattr->gid) {
5752                         invalid |= NFS_INO_INVALID_ATTR|NFS_INO_INVALID_ACCESS|NFS_INO_INVALID_ACL;
5753 -                       inode->i_gid = fattr->gid;
5754 +                       gid = fattr->gid;
5755                 }
5756         } else if (server->caps & NFS_CAP_OWNER_GROUP)
5757                 invalid |= save_cache_validity & (NFS_INO_INVALID_ATTR
5758 @@ -1292,6 +1316,10 @@ static int nfs_update_inode(struct inode
5759                                 | NFS_INO_INVALID_ACL
5760                                 | NFS_INO_REVAL_FORCED);
5761  
5762 +       inode->i_uid = uid;
5763 +       inode->i_gid = gid;
5764 +       inode->i_tag = tag;
5765 +
5766         if (fattr->valid & NFS_ATTR_FATTR_NLINK) {
5767                 if (inode->i_nlink != fattr->nlink) {
5768                         invalid |= NFS_INO_INVALID_ATTR;
5769 diff -NurpP --minimal linux-2.6.32.1/fs/nfs/nfs3xdr.c linux-2.6.32.1-vs2.3.0.36.27/fs/nfs/nfs3xdr.c
5770 --- linux-2.6.32.1/fs/nfs/nfs3xdr.c     2009-12-03 20:02:52.000000000 +0100
5771 +++ linux-2.6.32.1-vs2.3.0.36.27/fs/nfs/nfs3xdr.c       2009-12-03 20:04:56.000000000 +0100
5772 @@ -21,6 +21,7 @@
5773  #include <linux/nfs3.h>
5774  #include <linux/nfs_fs.h>
5775  #include <linux/nfsacl.h>
5776 +#include <linux/vs_tag.h>
5777  #include "internal.h"
5778  
5779  #define NFSDBG_FACILITY                NFSDBG_XDR
5780 @@ -176,7 +177,7 @@ xdr_decode_fattr(__be32 *p, struct nfs_f
5781  }
5782  
5783  static inline __be32 *
5784 -xdr_encode_sattr(__be32 *p, struct iattr *attr)
5785 +xdr_encode_sattr(__be32 *p, struct iattr *attr, int tag)
5786  {
5787         if (attr->ia_valid & ATTR_MODE) {
5788                 *p++ = xdr_one;
5789 @@ -184,15 +185,17 @@ xdr_encode_sattr(__be32 *p, struct iattr
5790         } else {
5791                 *p++ = xdr_zero;
5792         }
5793 -       if (attr->ia_valid & ATTR_UID) {
5794 +       if (attr->ia_valid & ATTR_UID ||
5795 +               (tag && (attr->ia_valid & ATTR_TAG))) {
5796                 *p++ = xdr_one;
5797 -               *p++ = htonl(attr->ia_uid);
5798 +               *p++ = htonl(TAGINO_UID(tag, attr->ia_uid, attr->ia_tag));
5799         } else {
5800                 *p++ = xdr_zero;
5801         }
5802 -       if (attr->ia_valid & ATTR_GID) {
5803 +       if (attr->ia_valid & ATTR_GID ||
5804 +               (tag && (attr->ia_valid & ATTR_TAG))) {
5805                 *p++ = xdr_one;
5806 -               *p++ = htonl(attr->ia_gid);
5807 +               *p++ = htonl(TAGINO_GID(tag, attr->ia_gid, attr->ia_tag));
5808         } else {
5809                 *p++ = xdr_zero;
5810         }
5811 @@ -279,7 +282,8 @@ static int
5812  nfs3_xdr_sattrargs(struct rpc_rqst *req, __be32 *p, struct nfs3_sattrargs *args)
5813  {
5814         p = xdr_encode_fhandle(p, args->fh);
5815 -       p = xdr_encode_sattr(p, args->sattr);
5816 +       p = xdr_encode_sattr(p, args->sattr,
5817 +               req->rq_task->tk_client->cl_tag);
5818         *p++ = htonl(args->guard);
5819         if (args->guard)
5820                 p = xdr_encode_time3(p, &args->guardtime);
5821 @@ -384,7 +388,8 @@ nfs3_xdr_createargs(struct rpc_rqst *req
5822                 *p++ = args->verifier[0];
5823                 *p++ = args->verifier[1];
5824         } else
5825 -               p = xdr_encode_sattr(p, args->sattr);
5826 +               p = xdr_encode_sattr(p, args->sattr,
5827 +                       req->rq_task->tk_client->cl_tag);
5828  
5829         req->rq_slen = xdr_adjust_iovec(req->rq_svec, p);
5830         return 0;
5831 @@ -398,7 +403,8 @@ nfs3_xdr_mkdirargs(struct rpc_rqst *req,
5832  {
5833         p = xdr_encode_fhandle(p, args->fh);
5834         p = xdr_encode_array(p, args->name, args->len);
5835 -       p = xdr_encode_sattr(p, args->sattr);
5836 +       p = xdr_encode_sattr(p, args->sattr,
5837 +               req->rq_task->tk_client->cl_tag);
5838         req->rq_slen = xdr_adjust_iovec(req->rq_svec, p);
5839         return 0;
5840  }
5841 @@ -411,7 +417,8 @@ nfs3_xdr_symlinkargs(struct rpc_rqst *re
5842  {
5843         p = xdr_encode_fhandle(p, args->fromfh);
5844         p = xdr_encode_array(p, args->fromname, args->fromlen);
5845 -       p = xdr_encode_sattr(p, args->sattr);
5846 +       p = xdr_encode_sattr(p, args->sattr,
5847 +               req->rq_task->tk_client->cl_tag);
5848         *p++ = htonl(args->pathlen);
5849         req->rq_slen = xdr_adjust_iovec(req->rq_svec, p);
5850  
5851 @@ -429,7 +436,8 @@ nfs3_xdr_mknodargs(struct rpc_rqst *req,
5852         p = xdr_encode_fhandle(p, args->fh);
5853         p = xdr_encode_array(p, args->name, args->len);
5854         *p++ = htonl(args->type);
5855 -       p = xdr_encode_sattr(p, args->sattr);
5856 +       p = xdr_encode_sattr(p, args->sattr,
5857 +               req->rq_task->tk_client->cl_tag);
5858         if (args->type == NF3CHR || args->type == NF3BLK) {
5859                 *p++ = htonl(MAJOR(args->rdev));
5860                 *p++ = htonl(MINOR(args->rdev));
5861 diff -NurpP --minimal linux-2.6.32.1/fs/nfs/nfsroot.c linux-2.6.32.1-vs2.3.0.36.27/fs/nfs/nfsroot.c
5862 --- linux-2.6.32.1/fs/nfs/nfsroot.c     2009-09-10 15:26:23.000000000 +0200
5863 +++ linux-2.6.32.1-vs2.3.0.36.27/fs/nfs/nfsroot.c       2009-12-03 20:04:56.000000000 +0100
5864 @@ -122,12 +122,12 @@ static int mount_port __initdata = 0;             /
5865  enum {
5866         /* Options that take integer arguments */
5867         Opt_port, Opt_rsize, Opt_wsize, Opt_timeo, Opt_retrans, Opt_acregmin,
5868 -       Opt_acregmax, Opt_acdirmin, Opt_acdirmax,
5869 +       Opt_acregmax, Opt_acdirmin, Opt_acdirmax, Opt_tagid,
5870         /* Options that take no arguments */
5871         Opt_soft, Opt_hard, Opt_intr,
5872         Opt_nointr, Opt_posix, Opt_noposix, Opt_cto, Opt_nocto, Opt_ac, 
5873         Opt_noac, Opt_lock, Opt_nolock, Opt_v2, Opt_v3, Opt_udp, Opt_tcp,
5874 -       Opt_acl, Opt_noacl,
5875 +       Opt_acl, Opt_noacl, Opt_tag, Opt_notag,
5876         /* Error token */
5877         Opt_err
5878  };
5879 @@ -164,6 +164,9 @@ static const match_table_t tokens __init
5880         {Opt_tcp, "tcp"},
5881         {Opt_acl, "acl"},
5882         {Opt_noacl, "noacl"},
5883 +       {Opt_tag, "tag"},
5884 +       {Opt_notag, "notag"},
5885 +       {Opt_tagid, "tagid=%u"},
5886         {Opt_err, NULL}
5887         
5888  };
5889 @@ -275,6 +278,20 @@ static int __init root_nfs_parse(char *n
5890                         case Opt_noacl:
5891                                 nfs_data.flags |= NFS_MOUNT_NOACL;
5892                                 break;
5893 +#ifndef CONFIG_TAGGING_NONE
5894 +                       case Opt_tag:
5895 +                               nfs_data.flags |= NFS_MOUNT_TAGGED;
5896 +                               break;
5897 +                       case Opt_notag:
5898 +                               nfs_data.flags &= ~NFS_MOUNT_TAGGED;
5899 +                               break;
5900 +#endif
5901 +#ifdef CONFIG_PROPAGATE
5902 +                       case Opt_tagid:
5903 +                               /* use args[0] */
5904 +                               nfs_data.flags |= NFS_MOUNT_TAGGED;
5905 +                               break;
5906 +#endif
5907                         default:
5908                                 printk(KERN_WARNING "Root-NFS: unknown "
5909                                         "option: %s\n", p);
5910 diff -NurpP --minimal linux-2.6.32.1/fs/nfs/super.c linux-2.6.32.1-vs2.3.0.36.27/fs/nfs/super.c
5911 --- linux-2.6.32.1/fs/nfs/super.c       2009-12-03 20:02:52.000000000 +0100
5912 +++ linux-2.6.32.1-vs2.3.0.36.27/fs/nfs/super.c 2009-12-03 20:04:56.000000000 +0100
5913 @@ -53,6 +53,7 @@
5914  #include <linux/nfs_xdr.h>
5915  #include <linux/magic.h>
5916  #include <linux/parser.h>
5917 +#include <linux/vs_tag.h>
5918  
5919  #include <asm/system.h>
5920  #include <asm/uaccess.h>
5921 @@ -551,6 +552,7 @@ static void nfs_show_mount_options(struc
5922                 { NFS_MOUNT_NORDIRPLUS, ",nordirplus", "" },
5923                 { NFS_MOUNT_UNSHARED, ",nosharecache", "" },
5924                 { NFS_MOUNT_NORESVPORT, ",noresvport", "" },
5925 +               { NFS_MOUNT_TAGGED, ",tag", "" },
5926                 { 0, NULL, NULL }
5927         };
5928         const struct proc_nfs_info *nfs_infop;
5929 diff -NurpP --minimal linux-2.6.32.1/fs/nfsd/auth.c linux-2.6.32.1-vs2.3.0.36.27/fs/nfsd/auth.c
5930 --- linux-2.6.32.1/fs/nfsd/auth.c       2009-12-03 20:02:52.000000000 +0100
5931 +++ linux-2.6.32.1-vs2.3.0.36.27/fs/nfsd/auth.c 2009-12-03 20:04:56.000000000 +0100
5932 @@ -10,6 +10,7 @@
5933  #include <linux/sunrpc/svcauth.h>
5934  #include <linux/nfsd/nfsd.h>
5935  #include <linux/nfsd/export.h>
5936 +#include <linux/vs_tag.h>
5937  #include "auth.h"
5938  
5939  int nfsexp_flags(struct svc_rqst *rqstp, struct svc_export *exp)
5940 @@ -44,6 +45,9 @@ int nfsd_setuser(struct svc_rqst *rqstp,
5941  
5942         new->fsuid = rqstp->rq_cred.cr_uid;
5943         new->fsgid = rqstp->rq_cred.cr_gid;
5944 +       /* FIXME: this desperately needs a tag :)
5945 +       new->xid = (xid_t)INOTAG_TAG(DX_TAG_NFSD, cred.cr_uid, cred.cr_gid, 0);
5946 +                       */
5947  
5948         rqgi = rqstp->rq_cred.cr_group_info;
5949  
5950 diff -NurpP --minimal linux-2.6.32.1/fs/nfsd/nfs3xdr.c linux-2.6.32.1-vs2.3.0.36.27/fs/nfsd/nfs3xdr.c
5951 --- linux-2.6.32.1/fs/nfsd/nfs3xdr.c    2009-12-03 20:02:52.000000000 +0100
5952 +++ linux-2.6.32.1-vs2.3.0.36.27/fs/nfsd/nfs3xdr.c      2009-12-03 20:04:56.000000000 +0100
5953 @@ -21,6 +21,7 @@
5954  #include <linux/sunrpc/svc.h>
5955  #include <linux/nfsd/nfsd.h>
5956  #include <linux/nfsd/xdr3.h>
5957 +#include <linux/vs_tag.h>
5958  #include "auth.h"
5959  
5960  #define NFSDDBG_FACILITY               NFSDDBG_XDR
5961 @@ -108,6 +109,8 @@ static __be32 *
5962  decode_sattr3(__be32 *p, struct iattr *iap)
5963  {
5964         u32     tmp;
5965 +       uid_t   uid = 0;
5966 +       gid_t   gid = 0;
5967  
5968         iap->ia_valid = 0;
5969  
5970 @@ -117,12 +120,15 @@ decode_sattr3(__be32 *p, struct iattr *i
5971         }
5972         if (*p++) {
5973                 iap->ia_valid |= ATTR_UID;
5974 -               iap->ia_uid = ntohl(*p++);
5975 +               uid = ntohl(*p++);
5976         }
5977         if (*p++) {
5978                 iap->ia_valid |= ATTR_GID;
5979 -               iap->ia_gid = ntohl(*p++);
5980 +               gid = ntohl(*p++);
5981         }
5982 +       iap->ia_uid = INOTAG_UID(DX_TAG_NFSD, uid, gid);
5983 +       iap->ia_gid = INOTAG_GID(DX_TAG_NFSD, uid, gid);
5984 +       iap->ia_tag = INOTAG_TAG(DX_TAG_NFSD, uid, gid, 0);
5985         if (*p++) {
5986                 u64     newsize;
5987  
5988 @@ -178,8 +184,12 @@ encode_fattr3(struct svc_rqst *rqstp, __
5989         *p++ = htonl(nfs3_ftypes[(stat->mode & S_IFMT) >> 12]);
5990         *p++ = htonl((u32) stat->mode);
5991         *p++ = htonl((u32) stat->nlink);
5992 -       *p++ = htonl((u32) nfsd_ruid(rqstp, stat->uid));
5993 -       *p++ = htonl((u32) nfsd_rgid(rqstp, stat->gid));
5994 +       *p++ = htonl((u32) nfsd_ruid(rqstp,
5995 +               TAGINO_UID(0 /* FIXME: DX_TAG(dentry->d_inode) */,
5996 +               stat->uid, stat->tag)));
5997 +       *p++ = htonl((u32) nfsd_rgid(rqstp,
5998 +               TAGINO_GID(0 /* FIXME: DX_TAG(dentry->d_inode) */,
5999 +               stat->gid, stat->tag)));
6000         if (S_ISLNK(stat->mode) && stat->size > NFS3_MAXPATHLEN) {
6001                 p = xdr_encode_hyper(p, (u64) NFS3_MAXPATHLEN);
6002         } else {
6003 diff -NurpP --minimal linux-2.6.32.1/fs/nfsd/nfs4xdr.c linux-2.6.32.1-vs2.3.0.36.27/fs/nfsd/nfs4xdr.c
6004 --- linux-2.6.32.1/fs/nfsd/nfs4xdr.c    2009-12-03 20:02:52.000000000 +0100
6005 +++ linux-2.6.32.1-vs2.3.0.36.27/fs/nfsd/nfs4xdr.c      2009-12-03 20:04:56.000000000 +0100
6006 @@ -57,6 +57,7 @@
6007  #include <linux/nfs4_acl.h>
6008  #include <linux/sunrpc/gss_api.h>
6009  #include <linux/sunrpc/svcauth_gss.h>
6010 +#include <linux/vs_tag.h>
6011  
6012  #define NFSDDBG_FACILITY               NFSDDBG_XDR
6013  
6014 @@ -2050,14 +2051,18 @@ out_acl:
6015                 WRITE32(stat.nlink);
6016         }
6017         if (bmval1 & FATTR4_WORD1_OWNER) {
6018 -               status = nfsd4_encode_user(rqstp, stat.uid, &p, &buflen);
6019 +               status = nfsd4_encode_user(rqstp,
6020 +                       TAGINO_UID(DX_TAG(dentry->d_inode),
6021 +                       stat.uid, stat.tag), &p, &buflen);
6022                 if (status == nfserr_resource)
6023                         goto out_resource;
6024                 if (status)
6025                         goto out;
6026         }
6027         if (bmval1 & FATTR4_WORD1_OWNER_GROUP) {
6028 -               status = nfsd4_encode_group(rqstp, stat.gid, &p, &buflen);
6029 +               status = nfsd4_encode_group(rqstp,
6030 +                       TAGINO_GID(DX_TAG(dentry->d_inode),
6031 +                       stat.gid, stat.tag), &p, &buflen);
6032                 if (status == nfserr_resource)
6033                         goto out_resource;
6034                 if (status)
6035 diff -NurpP --minimal linux-2.6.32.1/fs/nfsd/nfsxdr.c linux-2.6.32.1-vs2.3.0.36.27/fs/nfsd/nfsxdr.c
6036 --- linux-2.6.32.1/fs/nfsd/nfsxdr.c     2008-12-25 00:26:37.000000000 +0100
6037 +++ linux-2.6.32.1-vs2.3.0.36.27/fs/nfsd/nfsxdr.c       2009-12-03 20:04:56.000000000 +0100
6038 @@ -15,6 +15,7 @@
6039  #include <linux/nfsd/nfsd.h>
6040  #include <linux/nfsd/xdr.h>
6041  #include <linux/mm.h>
6042 +#include <linux/vs_tag.h>
6043  #include "auth.h"
6044  
6045  #define NFSDDBG_FACILITY               NFSDDBG_XDR
6046 @@ -98,6 +99,8 @@ static __be32 *
6047  decode_sattr(__be32 *p, struct iattr *iap)
6048  {
6049         u32     tmp, tmp1;
6050 +       uid_t   uid = 0;
6051 +       gid_t   gid = 0;
6052  
6053         iap->ia_valid = 0;
6054  
6055 @@ -111,12 +114,15 @@ decode_sattr(__be32 *p, struct iattr *ia
6056         }
6057         if ((tmp = ntohl(*p++)) != (u32)-1) {
6058                 iap->ia_valid |= ATTR_UID;
6059 -               iap->ia_uid = tmp;
6060 +               uid = tmp;
6061         }
6062         if ((tmp = ntohl(*p++)) != (u32)-1) {
6063                 iap->ia_valid |= ATTR_GID;
6064 -               iap->ia_gid = tmp;
6065 +               gid = tmp;
6066         }
6067 +       iap->ia_uid = INOTAG_UID(DX_TAG_NFSD, uid, gid);
6068 +       iap->ia_gid = INOTAG_GID(DX_TAG_NFSD, uid, gid);
6069 +       iap->ia_tag = INOTAG_TAG(DX_TAG_NFSD, uid, gid, 0);
6070         if ((tmp = ntohl(*p++)) != (u32)-1) {
6071                 iap->ia_valid |= ATTR_SIZE;
6072                 iap->ia_size = tmp;
6073 @@ -161,8 +167,10 @@ encode_fattr(struct svc_rqst *rqstp, __b
6074         *p++ = htonl(nfs_ftypes[type >> 12]);
6075         *p++ = htonl((u32) stat->mode);
6076         *p++ = htonl((u32) stat->nlink);
6077 -       *p++ = htonl((u32) nfsd_ruid(rqstp, stat->uid));
6078 -       *p++ = htonl((u32) nfsd_rgid(rqstp, stat->gid));
6079 +       *p++ = htonl((u32) nfsd_ruid(rqstp,
6080 +               TAGINO_UID(DX_TAG(dentry->d_inode), stat->uid, stat->tag)));
6081 +       *p++ = htonl((u32) nfsd_rgid(rqstp,
6082 +               TAGINO_GID(DX_TAG(dentry->d_inode), stat->gid, stat->tag)));
6083  
6084         if (S_ISLNK(type) && stat->size > NFS_MAXPATHLEN) {
6085                 *p++ = htonl(NFS_MAXPATHLEN);
6086 diff -NurpP --minimal linux-2.6.32.1/fs/ocfs2/dlm/dlmfs.c linux-2.6.32.1-vs2.3.0.36.27/fs/ocfs2/dlm/dlmfs.c
6087 --- linux-2.6.32.1/fs/ocfs2/dlm/dlmfs.c 2009-12-03 20:02:53.000000000 +0100
6088 +++ linux-2.6.32.1-vs2.3.0.36.27/fs/ocfs2/dlm/dlmfs.c   2009-12-03 20:04:56.000000000 +0100
6089 @@ -43,6 +43,7 @@
6090  #include <linux/init.h>
6091  #include <linux/string.h>
6092  #include <linux/backing-dev.h>
6093 +#include <linux/vs_tag.h>
6094  
6095  #include <asm/uaccess.h>
6096  
6097 @@ -342,6 +343,7 @@ static struct inode *dlmfs_get_root_inod
6098                 inode->i_mode = mode;
6099                 inode->i_uid = current_fsuid();
6100                 inode->i_gid = current_fsgid();
6101 +               inode->i_tag = dx_current_fstag(sb);
6102                 inode->i_mapping->backing_dev_info = &dlmfs_backing_dev_info;
6103                 inode->i_atime = inode->i_mtime = inode->i_ctime = CURRENT_TIME;
6104                 inc_nlink(inode);
6105 @@ -367,6 +369,7 @@ static struct inode *dlmfs_get_inode(str
6106         inode->i_mode = mode;
6107         inode->i_uid = current_fsuid();
6108         inode->i_gid = current_fsgid();
6109 +       inode->i_tag = dx_current_fstag(sb);
6110         inode->i_mapping->backing_dev_info = &dlmfs_backing_dev_info;
6111         inode->i_atime = inode->i_mtime = inode->i_ctime = CURRENT_TIME;
6112  
6113 diff -NurpP --minimal linux-2.6.32.1/fs/ocfs2/dlmglue.c linux-2.6.32.1-vs2.3.0.36.27/fs/ocfs2/dlmglue.c
6114 --- linux-2.6.32.1/fs/ocfs2/dlmglue.c   2009-12-03 20:02:53.000000000 +0100
6115 +++ linux-2.6.32.1-vs2.3.0.36.27/fs/ocfs2/dlmglue.c     2009-12-03 20:04:56.000000000 +0100
6116 @@ -1991,6 +1991,7 @@ static void __ocfs2_stuff_meta_lvb(struc
6117         lvb->lvb_iclusters = cpu_to_be32(oi->ip_clusters);
6118         lvb->lvb_iuid      = cpu_to_be32(inode->i_uid);
6119         lvb->lvb_igid      = cpu_to_be32(inode->i_gid);
6120 +       lvb->lvb_itag      = cpu_to_be16(inode->i_tag);
6121         lvb->lvb_imode     = cpu_to_be16(inode->i_mode);
6122         lvb->lvb_inlink    = cpu_to_be16(inode->i_nlink);
6123         lvb->lvb_iatime_packed  =
6124 @@ -2045,6 +2046,7 @@ static void ocfs2_refresh_inode_from_lvb
6125  
6126         inode->i_uid     = be32_to_cpu(lvb->lvb_iuid);
6127         inode->i_gid     = be32_to_cpu(lvb->lvb_igid);
6128 +       inode->i_tag     = be16_to_cpu(lvb->lvb_itag);
6129         inode->i_mode    = be16_to_cpu(lvb->lvb_imode);
6130         inode->i_nlink   = be16_to_cpu(lvb->lvb_inlink);
6131         ocfs2_unpack_timespec(&inode->i_atime,
6132 diff -NurpP --minimal linux-2.6.32.1/fs/ocfs2/dlmglue.h linux-2.6.32.1-vs2.3.0.36.27/fs/ocfs2/dlmglue.h
6133 --- linux-2.6.32.1/fs/ocfs2/dlmglue.h   2009-12-03 20:02:53.000000000 +0100
6134 +++ linux-2.6.32.1-vs2.3.0.36.27/fs/ocfs2/dlmglue.h     2009-12-03 20:04:56.000000000 +0100
6135 @@ -46,7 +46,8 @@ struct ocfs2_meta_lvb {
6136         __be16       lvb_inlink;
6137         __be32       lvb_iattr;
6138         __be32       lvb_igeneration;
6139 -       __be32       lvb_reserved2;
6140 +       __be16       lvb_itag;
6141 +       __be16       lvb_reserved2;
6142  };
6143  
6144  #define OCFS2_QINFO_LVB_VERSION 1
6145 diff -NurpP --minimal linux-2.6.32.1/fs/ocfs2/file.c linux-2.6.32.1-vs2.3.0.36.27/fs/ocfs2/file.c
6146 --- linux-2.6.32.1/fs/ocfs2/file.c      2009-12-03 20:02:53.000000000 +0100
6147 +++ linux-2.6.32.1-vs2.3.0.36.27/fs/ocfs2/file.c        2009-12-03 20:04:56.000000000 +0100
6148 @@ -960,13 +960,15 @@ int ocfs2_setattr(struct dentry *dentry,
6149                 mlog(0, "uid change: %d\n", attr->ia_uid);
6150         if (attr->ia_valid & ATTR_GID)
6151                 mlog(0, "gid change: %d\n", attr->ia_gid);
6152 +       if (attr->ia_valid & ATTR_TAG)
6153 +               mlog(0, "tag change: %d\n", attr->ia_tag);
6154         if (attr->ia_valid & ATTR_SIZE)
6155                 mlog(0, "size change...\n");
6156         if (attr->ia_valid & (ATTR_ATIME | ATTR_MTIME | ATTR_CTIME))
6157                 mlog(0, "time change...\n");
6158  
6159  #define OCFS2_VALID_ATTRS (ATTR_ATIME | ATTR_MTIME | ATTR_CTIME | ATTR_SIZE \
6160 -                          | ATTR_GID | ATTR_UID | ATTR_MODE)
6161 +                          | ATTR_GID | ATTR_UID | ATTR_TAG | ATTR_MODE)
6162         if (!(attr->ia_valid & OCFS2_VALID_ATTRS)) {
6163                 mlog(0, "can't handle attrs: 0x%x\n", attr->ia_valid);
6164                 return 0;
6165 diff -NurpP --minimal linux-2.6.32.1/fs/ocfs2/inode.c linux-2.6.32.1-vs2.3.0.36.27/fs/ocfs2/inode.c
6166 --- linux-2.6.32.1/fs/ocfs2/inode.c     2009-12-03 20:02:53.000000000 +0100
6167 +++ linux-2.6.32.1-vs2.3.0.36.27/fs/ocfs2/inode.c       2009-12-03 20:04:56.000000000 +0100
6168 @@ -29,6 +29,7 @@
6169  #include <linux/highmem.h>
6170  #include <linux/pagemap.h>
6171  #include <linux/quotaops.h>
6172 +#include <linux/vs_tag.h>
6173  
6174  #include <asm/byteorder.h>
6175  
6176 @@ -79,11 +80,13 @@ void ocfs2_set_inode_flags(struct inode 
6177  {
6178         unsigned int flags = OCFS2_I(inode)->ip_attr;
6179  
6180 -       inode->i_flags &= ~(S_IMMUTABLE |
6181 +       inode->i_flags &= ~(S_IMMUTABLE | S_IXUNLINK |
6182                 S_SYNC | S_APPEND | S_NOATIME | S_DIRSYNC);
6183  
6184         if (flags & OCFS2_IMMUTABLE_FL)
6185                 inode->i_flags |= S_IMMUTABLE;
6186 +       if (flags & OCFS2_IXUNLINK_FL)
6187 +               inode->i_flags |= S_IXUNLINK;
6188  
6189         if (flags & OCFS2_SYNC_FL)
6190                 inode->i_flags |= S_SYNC;
6191 @@ -93,25 +96,44 @@ void ocfs2_set_inode_flags(struct inode 
6192                 inode->i_flags |= S_NOATIME;
6193         if (flags & OCFS2_DIRSYNC_FL)
6194                 inode->i_flags |= S_DIRSYNC;
6195 +
6196 +       inode->i_vflags &= ~(V_BARRIER | V_COW);
6197 +
6198 +       if (flags & OCFS2_BARRIER_FL)
6199 +               inode->i_vflags |= V_BARRIER;
6200 +       if (flags & OCFS2_COW_FL)
6201 +               inode->i_vflags |= V_COW;
6202  }
6203  
6204  /* Propagate flags from i_flags to OCFS2_I(inode)->ip_attr */
6205  void ocfs2_get_inode_flags(struct ocfs2_inode_info *oi)
6206  {
6207         unsigned int flags = oi->vfs_inode.i_flags;
6208 +       unsigned int vflags = oi->vfs_inode.i_vflags;
6209 +
6210 +       oi->ip_attr &= ~(OCFS2_SYNC_FL | OCFS2_APPEND_FL |
6211 +                       OCFS2_IMMUTABLE_FL | OCFS2_IXUNLINK_FL |
6212 +                       OCFS2_NOATIME_FL | OCFS2_DIRSYNC_FL |
6213 +                       OCFS2_BARRIER_FL | OCFS2_COW_FL);
6214 +
6215 +       if (flags & S_IMMUTABLE)
6216 +               oi->ip_attr |= OCFS2_IMMUTABLE_FL;
6217 +       if (flags & S_IXUNLINK)
6218 +               oi->ip_attr |= OCFS2_IXUNLINK_FL;
6219  
6220 -       oi->ip_attr &= ~(OCFS2_SYNC_FL|OCFS2_APPEND_FL|
6221 -                       OCFS2_IMMUTABLE_FL|OCFS2_NOATIME_FL|OCFS2_DIRSYNC_FL);
6222         if (flags & S_SYNC)
6223                 oi->ip_attr |= OCFS2_SYNC_FL;
6224         if (flags & S_APPEND)
6225                 oi->ip_attr |= OCFS2_APPEND_FL;
6226 -       if (flags & S_IMMUTABLE)
6227 -               oi->ip_attr |= OCFS2_IMMUTABLE_FL;
6228         if (flags & S_NOATIME)
6229                 oi->ip_attr |= OCFS2_NOATIME_FL;
6230         if (flags & S_DIRSYNC)
6231                 oi->ip_attr |= OCFS2_DIRSYNC_FL;
6232 +
6233 +       if (vflags & V_BARRIER)
6234 +               oi->ip_attr |= OCFS2_BARRIER_FL;
6235 +       if (vflags & V_COW)
6236 +               oi->ip_attr |= OCFS2_COW_FL;
6237  }
6238  
6239  struct inode *ocfs2_ilookup(struct super_block *sb, u64 blkno)
6240 @@ -246,6 +268,8 @@ void ocfs2_populate_inode(struct inode *
6241         struct super_block *sb;
6242         struct ocfs2_super *osb;
6243         int use_plocks = 1;
6244 +       uid_t uid;
6245 +       gid_t gid;
6246  
6247         mlog_entry("(0x%p, size:%llu)\n", inode,
6248                    (unsigned long long)le64_to_cpu(fe->i_size));
6249 @@ -277,8 +301,12 @@ void ocfs2_populate_inode(struct inode *
6250         inode->i_generation = le32_to_cpu(fe->i_generation);
6251         inode->i_rdev = huge_decode_dev(le64_to_cpu(fe->id1.dev1.i_rdev));
6252         inode->i_mode = le16_to_cpu(fe->i_mode);
6253 -       inode->i_uid = le32_to_cpu(fe->i_uid);
6254 -       inode->i_gid = le32_to_cpu(fe->i_gid);
6255 +       uid = le32_to_cpu(fe->i_uid);
6256 +       gid = le32_to_cpu(fe->i_gid);
6257 +       inode->i_uid = INOTAG_UID(DX_TAG(inode), uid, gid);
6258 +       inode->i_gid = INOTAG_GID(DX_TAG(inode), uid, gid);
6259 +       inode->i_tag = INOTAG_TAG(DX_TAG(inode), uid, gid,
6260 +               /* le16_to_cpu(raw_inode->i_raw_tag)i */ 0);
6261  
6262         /* Fast symlinks will have i_size but no allocated clusters. */
6263         if (S_ISLNK(inode->i_mode) && !fe->i_clusters)
6264 diff -NurpP --minimal linux-2.6.32.1/fs/ocfs2/inode.h linux-2.6.32.1-vs2.3.0.36.27/fs/ocfs2/inode.h
6265 --- linux-2.6.32.1/fs/ocfs2/inode.h     2009-12-03 20:02:53.000000000 +0100
6266 +++ linux-2.6.32.1-vs2.3.0.36.27/fs/ocfs2/inode.h       2009-12-03 20:04:56.000000000 +0100
6267 @@ -150,6 +150,7 @@ struct buffer_head *ocfs2_bread(struct i
6268  
6269  void ocfs2_set_inode_flags(struct inode *inode);
6270  void ocfs2_get_inode_flags(struct ocfs2_inode_info *oi);
6271 +int ocfs2_sync_flags(struct inode *inode, int, int);
6272  
6273  static inline blkcnt_t ocfs2_inode_sector_count(struct inode *inode)
6274  {
6275 diff -NurpP --minimal linux-2.6.32.1/fs/ocfs2/ioctl.c linux-2.6.32.1-vs2.3.0.36.27/fs/ocfs2/ioctl.c
6276 --- linux-2.6.32.1/fs/ocfs2/ioctl.c     2009-12-03 20:02:53.000000000 +0100
6277 +++ linux-2.6.32.1-vs2.3.0.36.27/fs/ocfs2/ioctl.c       2009-12-03 20:04:56.000000000 +0100
6278 @@ -42,7 +42,41 @@ static int ocfs2_get_inode_attr(struct i
6279         return status;
6280  }
6281  
6282 -static int ocfs2_set_inode_attr(struct inode *inode, unsigned flags,
6283 +int ocfs2_sync_flags(struct inode *inode, int flags, int vflags)
6284 +{
6285 +       struct ocfs2_super *osb = OCFS2_SB(inode->i_sb);
6286 +       struct buffer_head *bh = NULL;
6287 +       handle_t *handle = NULL;
6288 +       int status;
6289 +
6290 +       status = ocfs2_inode_lock(inode, &bh, 1);
6291 +       if (status < 0) {
6292 +               mlog_errno(status);
6293 +               return status;
6294 +       }
6295 +       handle = ocfs2_start_trans(osb, OCFS2_INODE_UPDATE_CREDITS);
6296 +       if (IS_ERR(handle)) {
6297 +               status = PTR_ERR(handle);
6298 +               mlog_errno(status);
6299 +               goto bail_unlock;
6300 +       }
6301 +
6302 +       inode->i_flags = flags;
6303 +       inode->i_vflags = vflags;
6304 +       ocfs2_get_inode_flags(OCFS2_I(inode));
6305 +
6306 +       status = ocfs2_mark_inode_dirty(handle, inode, bh);
6307 +       if (status < 0)
6308 +               mlog_errno(status);
6309 +
6310 +       ocfs2_commit_trans(osb, handle);
6311 +bail_unlock:
6312 +       ocfs2_inode_unlock(inode, 1);
6313 +       brelse(bh);
6314 +       return status;
6315 +}
6316 +
6317 +int ocfs2_set_inode_attr(struct inode *inode, unsigned flags,
6318                                 unsigned mask)
6319  {
6320         struct ocfs2_inode_info *ocfs2_inode = OCFS2_I(inode);
6321 @@ -67,6 +101,11 @@ static int ocfs2_set_inode_attr(struct i
6322         if (!S_ISDIR(inode->i_mode))
6323                 flags &= ~OCFS2_DIRSYNC_FL;
6324  
6325 +       if (IS_BARRIER(inode)) {
6326 +               vxwprintk_task(1, "messing with the barrier.");
6327 +               goto bail_unlock;
6328 +       }
6329 +
6330         handle = ocfs2_start_trans(osb, OCFS2_INODE_UPDATE_CREDITS);
6331         if (IS_ERR(handle)) {
6332                 status = PTR_ERR(handle);
6333 @@ -108,6 +147,7 @@ bail:
6334         return status;
6335  }
6336  
6337 +
6338  long ocfs2_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
6339  {
6340         struct inode *inode = filp->f_path.dentry->d_inode;
6341 diff -NurpP --minimal linux-2.6.32.1/fs/ocfs2/namei.c linux-2.6.32.1-vs2.3.0.36.27/fs/ocfs2/namei.c
6342 --- linux-2.6.32.1/fs/ocfs2/namei.c     2009-12-03 20:02:53.000000000 +0100
6343 +++ linux-2.6.32.1-vs2.3.0.36.27/fs/ocfs2/namei.c       2009-12-03 20:04:56.000000000 +0100
6344 @@ -41,6 +41,7 @@
6345  #include <linux/slab.h>
6346  #include <linux/highmem.h>
6347  #include <linux/quotaops.h>
6348 +#include <linux/vs_tag.h>
6349  
6350  #define MLOG_MASK_PREFIX ML_NAMEI
6351  #include <cluster/masklog.h>
6352 @@ -481,6 +482,7 @@ static int ocfs2_mknod_locked(struct ocf
6353         u64 fe_blkno = 0;
6354         u16 suballoc_bit;
6355         u16 feat;
6356 +       tag_t tag;
6357  
6358         *new_fe_bh = NULL;
6359  
6360 @@ -524,8 +526,11 @@ static int ocfs2_mknod_locked(struct ocf
6361         fe->i_blkno = cpu_to_le64(fe_blkno);
6362         fe->i_suballoc_bit = cpu_to_le16(suballoc_bit);
6363         fe->i_suballoc_slot = cpu_to_le16(inode_ac->ac_alloc_slot);
6364 -       fe->i_uid = cpu_to_le32(inode->i_uid);
6365 -       fe->i_gid = cpu_to_le32(inode->i_gid);
6366 +
6367 +       tag = dx_current_fstag(osb->sb);
6368 +       fe->i_uid = cpu_to_le32(TAGINO_UID(DX_TAG(inode), inode->i_uid, tag));
6369 +       fe->i_gid = cpu_to_le32(TAGINO_GID(DX_TAG(inode), inode->i_gid, tag));
6370 +       inode->i_tag = tag;
6371         fe->i_mode = cpu_to_le16(inode->i_mode);
6372         if (S_ISCHR(inode->i_mode) || S_ISBLK(inode->i_mode))
6373                 fe->id1.dev1.i_rdev = cpu_to_le64(huge_encode_dev(dev));
6374 diff -NurpP --minimal linux-2.6.32.1/fs/ocfs2/ocfs2_fs.h linux-2.6.32.1-vs2.3.0.36.27/fs/ocfs2/ocfs2_fs.h
6375 --- linux-2.6.32.1/fs/ocfs2/ocfs2_fs.h  2009-12-03 20:02:53.000000000 +0100
6376 +++ linux-2.6.32.1-vs2.3.0.36.27/fs/ocfs2/ocfs2_fs.h    2009-12-03 20:04:56.000000000 +0100
6377 @@ -231,18 +231,23 @@
6378  #define OCFS2_HAS_REFCOUNT_FL   (0x0010)
6379  
6380  /* Inode attributes, keep in sync with EXT2 */
6381 -#define OCFS2_SECRM_FL         (0x00000001)    /* Secure deletion */
6382 -#define OCFS2_UNRM_FL          (0x00000002)    /* Undelete */
6383 -#define OCFS2_COMPR_FL         (0x00000004)    /* Compress file */
6384 -#define OCFS2_SYNC_FL          (0x00000008)    /* Synchronous updates */
6385 -#define OCFS2_IMMUTABLE_FL     (0x00000010)    /* Immutable file */
6386 -#define OCFS2_APPEND_FL                (0x00000020)    /* writes to file may only append */
6387 -#define OCFS2_NODUMP_FL                (0x00000040)    /* do not dump file */
6388 -#define OCFS2_NOATIME_FL       (0x00000080)    /* do not update atime */
6389 -#define OCFS2_DIRSYNC_FL       (0x00010000)    /* dirsync behaviour (directories only) */
6390 +#define OCFS2_SECRM_FL         FS_SECRM_FL     /* Secure deletion */
6391 +#define OCFS2_UNRM_FL          FS_UNRM_FL      /* Undelete */
6392 +#define OCFS2_COMPR_FL         FS_COMPR_FL     /* Compress file */
6393 +#define OCFS2_SYNC_FL          FS_SYNC_FL      /* Synchronous updates */
6394 +#define OCFS2_IMMUTABLE_FL     FS_IMMUTABLE_FL /* Immutable file */
6395 +#define OCFS2_APPEND_FL                FS_APPEND_FL    /* writes to file may only append */
6396 +#define OCFS2_NODUMP_FL                FS_NODUMP_FL    /* do not dump file */
6397 +#define OCFS2_NOATIME_FL       FS_NOATIME_FL   /* do not update atime */
6398  
6399 -#define OCFS2_FL_VISIBLE       (0x000100FF)    /* User visible flags */
6400 -#define OCFS2_FL_MODIFIABLE    (0x000100FF)    /* User modifiable flags */
6401 +#define OCFS2_DIRSYNC_FL       FS_DIRSYNC_FL   /* dirsync behaviour (directories only) */
6402 +#define OCFS2_IXUNLINK_FL      FS_IXUNLINK_FL  /* Immutable invert on unlink */
6403 +
6404 +#define OCFS2_BARRIER_FL       FS_BARRIER_FL   /* Barrier for chroot() */
6405 +#define OCFS2_COW_FL           FS_COW_FL       /* Copy on Write marker */
6406 +
6407 +#define OCFS2_FL_VISIBLE       (0x010300FF)    /* User visible flags */
6408 +#define OCFS2_FL_MODIFIABLE    (0x010300FF)    /* User modifiable flags */
6409  
6410  /*
6411   * Extent record flags (e_node.leaf.flags)
6412 diff -NurpP --minimal linux-2.6.32.1/fs/ocfs2/ocfs2.h linux-2.6.32.1-vs2.3.0.36.27/fs/ocfs2/ocfs2.h
6413 --- linux-2.6.32.1/fs/ocfs2/ocfs2.h     2009-12-03 20:02:53.000000000 +0100
6414 +++ linux-2.6.32.1-vs2.3.0.36.27/fs/ocfs2/ocfs2.h       2009-12-03 20:04:56.000000000 +0100
6415 @@ -248,6 +248,7 @@ enum ocfs2_mount_options
6416         OCFS2_MOUNT_POSIX_ACL = 1 << 8, /* POSIX access control lists */
6417         OCFS2_MOUNT_USRQUOTA = 1 << 9, /* We support user quotas */
6418         OCFS2_MOUNT_GRPQUOTA = 1 << 10, /* We support group quotas */
6419 +       OCFS2_MOUNT_TAGGED = 1 << 11, /* use tagging */
6420  };
6421  
6422  #define OCFS2_OSB_SOFT_RO                      0x0001
6423 diff -NurpP --minimal linux-2.6.32.1/fs/ocfs2/super.c linux-2.6.32.1-vs2.3.0.36.27/fs/ocfs2/super.c
6424 --- linux-2.6.32.1/fs/ocfs2/super.c     2009-12-03 20:02:53.000000000 +0100
6425 +++ linux-2.6.32.1-vs2.3.0.36.27/fs/ocfs2/super.c       2009-12-03 20:04:56.000000000 +0100
6426 @@ -173,6 +173,7 @@ enum {
6427         Opt_noacl,
6428         Opt_usrquota,
6429         Opt_grpquota,
6430 +       Opt_tag, Opt_notag, Opt_tagid,
6431         Opt_err,
6432  };
6433  
6434 @@ -199,6 +200,9 @@ static const match_table_t tokens = {
6435         {Opt_noacl, "noacl"},
6436         {Opt_usrquota, "usrquota"},
6437         {Opt_grpquota, "grpquota"},
6438 +       {Opt_tag, "tag"},
6439 +       {Opt_notag, "notag"},
6440 +       {Opt_tagid, "tagid=%u"},
6441         {Opt_err, NULL}
6442  };
6443  
6444 @@ -605,6 +609,13 @@ static int ocfs2_remount(struct super_bl
6445                 goto out;
6446         }
6447  
6448 +       if ((osb->s_mount_opt & OCFS2_MOUNT_TAGGED) !=
6449 +           (parsed_options.mount_opt & OCFS2_MOUNT_TAGGED)) {
6450 +               ret = -EINVAL;
6451 +               mlog(ML_ERROR, "Cannot change tagging on remount\n");
6452 +               goto out;
6453 +       }
6454 +
6455         if ((osb->s_mount_opt & OCFS2_MOUNT_HB_LOCAL) !=
6456             (parsed_options.mount_opt & OCFS2_MOUNT_HB_LOCAL)) {
6457                 ret = -EINVAL;
6458 @@ -1148,6 +1159,9 @@ static int ocfs2_fill_super(struct super
6459  
6460         ocfs2_complete_mount_recovery(osb);
6461  
6462 +       if (osb->s_mount_opt & OCFS2_MOUNT_TAGGED)
6463 +               sb->s_flags |= MS_TAGGED;
6464 +
6465         if (ocfs2_mount_local(osb))
6466                 snprintf(nodestr, sizeof(nodestr), "local");
6467         else
6468 @@ -1426,6 +1440,20 @@ static int ocfs2_parse_options(struct su
6469                         printk(KERN_INFO "ocfs2 (no)acl options not supported\n");
6470                         break;
6471  #endif
6472 +#ifndef CONFIG_TAGGING_NONE
6473 +               case Opt_tag:
6474 +                       mopt->mount_opt |= OCFS2_MOUNT_TAGGED;
6475 +                       break;
6476 +               case Opt_notag:
6477 +                       mopt->mount_opt &= ~OCFS2_MOUNT_TAGGED;
6478 +                       break;
6479 +#endif
6480 +#ifdef CONFIG_PROPAGATE
6481 +               case Opt_tagid:
6482 +                       /* use args[0] */
6483 +                       mopt->mount_opt |= OCFS2_MOUNT_TAGGED;
6484 +                       break;
6485 +#endif
6486                 default:
6487                         mlog(ML_ERROR,
6488                              "Unrecognized mount option \"%s\" "
6489 diff -NurpP --minimal linux-2.6.32.1/fs/open.c linux-2.6.32.1-vs2.3.0.36.27/fs/open.c
6490 --- linux-2.6.32.1/fs/open.c    2009-12-03 20:02:53.000000000 +0100
6491 +++ linux-2.6.32.1-vs2.3.0.36.27/fs/open.c      2009-12-03 20:04:56.000000000 +0100
6492 @@ -30,22 +30,30 @@
6493  #include <linux/audit.h>
6494  #include <linux/falloc.h>
6495  #include <linux/fs_struct.h>
6496 +#include <linux/vs_base.h>
6497 +#include <linux/vs_limit.h>
6498 +#include <linux/vs_tag.h>
6499 +#include <linux/vs_cowbl.h>
6500  
6501  int vfs_statfs(struct dentry *dentry, struct kstatfs *buf)
6502  {
6503         int retval = -ENODEV;
6504  
6505         if (dentry) {
6506 +               struct super_block *sb = dentry->d_sb;
6507 +
6508                 retval = -ENOSYS;
6509 -               if (dentry->d_sb->s_op->statfs) {
6510 +               if (sb->s_op->statfs) {
6511                         memset(buf, 0, sizeof(*buf));
6512                         retval = security_sb_statfs(dentry);
6513                         if (retval)
6514                                 return retval;
6515 -                       retval = dentry->d_sb->s_op->statfs(dentry, buf);
6516 +                       retval = sb->s_op->statfs(dentry, buf);
6517                         if (retval == 0 && buf->f_frsize == 0)
6518                                 buf->f_frsize = buf->f_bsize;
6519                 }
6520 +               if (!vx_check(0, VS_ADMIN|VS_WATCH))
6521 +                       vx_vsi_statfs(sb, buf);
6522         }
6523         return retval;
6524  }
6525 @@ -640,6 +648,10 @@ SYSCALL_DEFINE3(fchmodat, int, dfd, cons
6526         error = user_path_at(dfd, filename, LOOKUP_FOLLOW, &path);
6527         if (error)
6528                 goto out;
6529 +
6530 +       error = cow_check_and_break(&path);
6531 +       if (error)
6532 +               goto dput_and_out;
6533         inode = path.dentry->d_inode;
6534  
6535         error = mnt_want_write(path.mnt);
6536 @@ -673,11 +685,11 @@ static int chown_common(struct dentry * 
6537         newattrs.ia_valid =  ATTR_CTIME;
6538         if (user != (uid_t) -1) {
6539                 newattrs.ia_valid |= ATTR_UID;
6540 -               newattrs.ia_uid = user;
6541 +               newattrs.ia_uid = dx_map_uid(user);
6542         }
6543         if (group != (gid_t) -1) {
6544                 newattrs.ia_valid |= ATTR_GID;
6545 -               newattrs.ia_gid = group;
6546 +               newattrs.ia_gid = dx_map_gid(group);
6547         }
6548         if (!S_ISDIR(inode->i_mode))
6549                 newattrs.ia_valid |=
6550 @@ -700,7 +712,11 @@ SYSCALL_DEFINE3(chown, const char __user
6551         error = mnt_want_write(path.mnt);
6552         if (error)
6553                 goto out_release;
6554 -       error = chown_common(path.dentry, user, group);
6555 +#ifdef CONFIG_VSERVER_COWBL
6556 +       error = cow_check_and_break(&path);
6557 +       if (!error)
6558 +#endif
6559 +               error = chown_common(path.dentry, user, group);
6560         mnt_drop_write(path.mnt);
6561  out_release:
6562         path_put(&path);
6563 @@ -725,7 +741,11 @@ SYSCALL_DEFINE5(fchownat, int, dfd, cons
6564         error = mnt_want_write(path.mnt);
6565         if (error)
6566                 goto out_release;
6567 -       error = chown_common(path.dentry, user, group);
6568 +#ifdef CONFIG_VSERVER_COWBL
6569 +       error = cow_check_and_break(&path);
6570 +       if (!error)
6571 +#endif
6572 +               error = chown_common(path.dentry, user, group);
6573         mnt_drop_write(path.mnt);
6574  out_release:
6575         path_put(&path);
6576 @@ -744,7 +764,11 @@ SYSCALL_DEFINE3(lchown, const char __use
6577         error = mnt_want_write(path.mnt);
6578         if (error)
6579                 goto out_release;
6580 -       error = chown_common(path.dentry, user, group);
6581 +#ifdef CONFIG_VSERVER_COWBL
6582 +       error = cow_check_and_break(&path);
6583 +       if (!error)
6584 +#endif
6585 +               error = chown_common(path.dentry, user, group);
6586         mnt_drop_write(path.mnt);
6587  out_release:
6588         path_put(&path);
6589 @@ -990,6 +1014,7 @@ static void __put_unused_fd(struct files
6590         __FD_CLR(fd, fdt->open_fds);
6591         if (fd < files->next_fd)
6592                 files->next_fd = fd;
6593 +       vx_openfd_dec(fd);
6594  }
6595  
6596  void put_unused_fd(unsigned int fd)
6597 diff -NurpP --minimal linux-2.6.32.1/fs/proc/array.c linux-2.6.32.1-vs2.3.0.36.27/fs/proc/array.c
6598 --- linux-2.6.32.1/fs/proc/array.c      2009-12-03 20:02:53.000000000 +0100
6599 +++ linux-2.6.32.1-vs2.3.0.36.27/fs/proc/array.c        2009-12-03 20:04:56.000000000 +0100
6600 @@ -83,6 +83,8 @@
6601  #include <linux/ptrace.h>
6602  #include <linux/tracehook.h>
6603  #include <linux/swapops.h>
6604 +#include <linux/vs_context.h>
6605 +#include <linux/vs_network.h>
6606  
6607  #include <asm/pgtable.h>
6608  #include <asm/processor.h>
6609 @@ -139,8 +141,9 @@ static const char *task_state_array[] = 
6610         "D (disk sleep)",       /*  2 */
6611         "T (stopped)",          /*  4 */
6612         "T (tracing stop)",     /*  8 */
6613 -       "Z (zombie)",           /* 16 */
6614 -       "X (dead)"              /* 32 */
6615 +       "H (on hold)",          /* 16 */
6616 +       "Z (zombie)",           /* 32 */
6617 +       "X (dead)",             /* 64 */
6618  };
6619  
6620  static inline const char *get_task_state(struct task_struct *tsk)
6621 @@ -167,6 +170,9 @@ static inline void task_state(struct seq
6622         rcu_read_lock();
6623         ppid = pid_alive(p) ?
6624                 task_tgid_nr_ns(rcu_dereference(p->real_parent), ns) : 0;
6625 +       if (unlikely(vx_current_initpid(p->pid)))
6626 +               ppid = 0;
6627 +
6628         tpid = 0;
6629         if (pid_alive(p)) {
6630                 struct task_struct *tracer = tracehook_tracer_task(p);
6631 @@ -282,7 +288,7 @@ static inline void task_sig(struct seq_f
6632  }
6633  
6634  static void render_cap_t(struct seq_file *m, const char *header,
6635 -                       kernel_cap_t *a)
6636 +                       struct vx_info *vxi, kernel_cap_t *a)
6637  {
6638         unsigned __capi;
6639  
6640 @@ -307,10 +313,11 @@ static inline void task_cap(struct seq_f
6641         cap_bset        = cred->cap_bset;
6642         rcu_read_unlock();
6643  
6644 -       render_cap_t(m, "CapInh:\t", &cap_inheritable);
6645 -       render_cap_t(m, "CapPrm:\t", &cap_permitted);
6646 -       render_cap_t(m, "CapEff:\t", &cap_effective);
6647 -       render_cap_t(m, "CapBnd:\t", &cap_bset);
6648 +       /* FIXME: maybe move the p->vx_info masking to __task_cred() ? */
6649 +       render_cap_t(m, "CapInh:\t", p->vx_info, &cap_inheritable);
6650 +       render_cap_t(m, "CapPrm:\t", p->vx_info, &cap_permitted);
6651 +       render_cap_t(m, "CapEff:\t", p->vx_info, &cap_effective);
6652 +       render_cap_t(m, "CapBnd:\t", p->vx_info, &cap_bset);
6653  }
6654  
6655  static inline void task_context_switch_counts(struct seq_file *m,
6656 @@ -410,6 +417,42 @@ static void task_show_stack_usage(struct
6657  }
6658  #endif         /* CONFIG_MMU */
6659  
6660 +int proc_pid_nsproxy(struct seq_file *m, struct pid_namespace *ns,
6661 +                       struct pid *pid, struct task_struct *task)
6662 +{
6663 +       seq_printf(m,   "Proxy:\t%p(%c)\n"
6664 +                       "Count:\t%u\n"
6665 +                       "uts:\t%p(%c)\n"
6666 +                       "ipc:\t%p(%c)\n"
6667 +                       "mnt:\t%p(%c)\n"
6668 +                       "pid:\t%p(%c)\n"
6669 +                       "net:\t%p(%c)\n",
6670 +                       task->nsproxy,
6671 +                       (task->nsproxy == init_task.nsproxy ? 'I' : '-'),
6672 +                       atomic_read(&task->nsproxy->count),
6673 +                       task->nsproxy->uts_ns,
6674 +                       (task->nsproxy->uts_ns == init_task.nsproxy->uts_ns ? 'I' : '-'),
6675 +                       task->nsproxy->ipc_ns,
6676 +                       (task->nsproxy->ipc_ns == init_task.nsproxy->ipc_ns ? 'I' : '-'),
6677 +                       task->nsproxy->mnt_ns,
6678 +                       (task->nsproxy->mnt_ns == init_task.nsproxy->mnt_ns ? 'I' : '-'),
6679 +                       task->nsproxy->pid_ns,
6680 +                       (task->nsproxy->pid_ns == init_task.nsproxy->pid_ns ? 'I' : '-'),
6681 +                       task->nsproxy->net_ns,
6682 +                       (task->nsproxy->net_ns == init_task.nsproxy->net_ns ? 'I' : '-'));
6683 +       return 0;
6684 +}
6685 +
6686 +void task_vs_id(struct seq_file *m, struct task_struct *task)
6687 +{
6688 +       if (task_vx_flags(task, VXF_HIDE_VINFO, 0))
6689 +               return;
6690 +
6691 +       seq_printf(m, "VxID: %d\n", vx_task_xid(task));
6692 +       seq_printf(m, "NxID: %d\n", nx_task_nid(task));
6693 +}
6694 +
6695 +
6696  int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
6697                         struct pid *pid, struct task_struct *task)
6698  {
6699 @@ -425,6 +468,7 @@ int proc_pid_status(struct seq_file *m, 
6700         task_sig(m, task);
6701         task_cap(m, task);
6702         cpuset_task_status_allowed(m, task);
6703 +       task_vs_id(m, task);
6704  #if defined(CONFIG_S390)
6705         task_show_regs(m, task);
6706  #endif
6707 @@ -542,6 +586,17 @@ static int do_task_stat(struct seq_file 
6708         /* convert nsec -> ticks */
6709         start_time = nsec_to_clock_t(start_time);
6710  
6711 +       /* fixup start time for virt uptime */
6712 +       if (vx_flags(VXF_VIRT_UPTIME, 0)) {
6713 +               unsigned long long bias =
6714 +                       current->vx_info->cvirt.bias_clock;
6715 +
6716 +               if (start_time > bias)
6717 +                       start_time -= bias;
6718 +               else
6719 +                       start_time = 0;
6720 +       }
6721 +
6722         seq_printf(m, "%d (%s) %c %d %d %d %d %d %u %lu \
6723  %lu %lu %lu %lu %lu %ld %ld %ld %ld %d 0 %llu %lu %ld %lu %lu %lu %lu %lu \
6724  %lu %lu %lu %lu %lu %lu %lu %lu %d %d %u %u %llu %lu %ld\n",
6725 diff -NurpP --minimal linux-2.6.32.1/fs/proc/base.c linux-2.6.32.1-vs2.3.0.36.27/fs/proc/base.c
6726 --- linux-2.6.32.1/fs/proc/base.c       2009-12-03 20:02:53.000000000 +0100
6727 +++ linux-2.6.32.1-vs2.3.0.36.27/fs/proc/base.c 2009-12-03 20:04:56.000000000 +0100
6728 @@ -81,6 +81,8 @@
6729  #include <linux/elf.h>
6730  #include <linux/pid_namespace.h>
6731  #include <linux/fs_struct.h>
6732 +#include <linux/vs_context.h>
6733 +#include <linux/vs_network.h>
6734  #include "internal.h"
6735  
6736  /* NOTE:
6737 @@ -1047,12 +1049,17 @@ static ssize_t oom_adjust_write(struct f
6738                 return -ESRCH;
6739         }
6740  
6741 -       if (oom_adjust < task->signal->oom_adj && !capable(CAP_SYS_RESOURCE)) {
6742 +       if (oom_adjust < task->signal->oom_adj &&
6743 +               !vx_capable(CAP_SYS_RESOURCE, VXC_OOM_ADJUST)) {
6744                 unlock_task_sighand(task, &flags);
6745                 put_task_struct(task);
6746                 return -EACCES;
6747         }
6748  
6749 +       /* prevent guest processes from circumventing the oom killer */
6750 +       if (vx_current_xid() && (oom_adjust == OOM_DISABLE))
6751 +               oom_adjust = OOM_ADJUST_MIN;
6752 +
6753         task->signal->oom_adj = oom_adjust;
6754  
6755         unlock_task_sighand(task, &flags);
6756 @@ -1092,7 +1099,7 @@ static ssize_t proc_loginuid_write(struc
6757         ssize_t length;
6758         uid_t loginuid;
6759  
6760 -       if (!capable(CAP_AUDIT_CONTROL))
6761 +       if (!vx_capable(CAP_AUDIT_CONTROL, VXC_AUDIT_CONTROL))
6762                 return -EPERM;
6763  
6764         if (current != pid_task(proc_pid(inode), PIDTYPE_PID))
6765 @@ -1458,6 +1465,8 @@ static struct inode *proc_pid_make_inode
6766                 inode->i_gid = cred->egid;
6767                 rcu_read_unlock();
6768         }
6769 +       /* procfs is xid tagged */
6770 +       inode->i_tag = (tag_t)vx_task_xid(task);
6771         security_task_to_inode(task, inode);
6772  
6773  out:
6774 @@ -2008,6 +2017,13 @@ static struct dentry *proc_pident_lookup
6775         if (!task)
6776                 goto out_no_task;
6777  
6778 +       /* TODO: maybe we can come up with a generic approach? */
6779 +       if (task_vx_flags(task, VXF_HIDE_VINFO, 0) &&
6780 +               (dentry->d_name.len == 5) &&
6781 +               (!memcmp(dentry->d_name.name, "vinfo", 5) ||
6782 +               !memcmp(dentry->d_name.name, "ninfo", 5)))
6783 +               goto out;
6784 +
6785         /*
6786          * Yes, it does not scale. And it should not. Don't add
6787          * new entries into /proc/<tgid>/ without very good reasons.
6788 @@ -2399,7 +2415,7 @@ out_iput:
6789  static struct dentry *proc_base_lookup(struct inode *dir, struct dentry *dentry)
6790  {
6791         struct dentry *error;
6792 -       struct task_struct *task = get_proc_task(dir);
6793 +       struct task_struct *task = get_proc_task_real(dir);
6794         const struct pid_entry *p, *last;
6795  
6796         error = ERR_PTR(-ENOENT);
6797 @@ -2489,6 +2505,9 @@ static int proc_pid_personality(struct s
6798  static const struct file_operations proc_task_operations;
6799  static const struct inode_operations proc_task_inode_operations;
6800  
6801 +extern int proc_pid_vx_info(struct task_struct *, char *);
6802 +extern int proc_pid_nx_info(struct task_struct *, char *);
6803 +
6804  static const struct pid_entry tgid_base_stuff[] = {
6805         DIR("task",       S_IRUGO|S_IXUGO, proc_task_inode_operations, proc_task_operations),
6806         DIR("fd",         S_IRUSR|S_IXUSR, proc_fd_inode_operations, proc_fd_operations),
6807 @@ -2547,6 +2566,8 @@ static const struct pid_entry tgid_base_
6808  #ifdef CONFIG_CGROUPS
6809         REG("cgroup",  S_IRUGO, proc_cgroup_operations),
6810  #endif
6811 +       INF("vinfo",      S_IRUGO, proc_pid_vx_info),
6812 +       INF("ninfo",      S_IRUGO, proc_pid_nx_info),
6813         INF("oom_score",  S_IRUGO, proc_oom_score),
6814         REG("oom_adj",    S_IRUGO|S_IWUSR, proc_oom_adjust_operations),
6815  #ifdef CONFIG_AUDITSYSCALL
6816 @@ -2562,6 +2583,7 @@ static const struct pid_entry tgid_base_
6817  #ifdef CONFIG_TASK_IO_ACCOUNTING
6818         INF("io",       S_IRUGO, proc_tgid_io_accounting),
6819  #endif
6820 +       ONE("nsproxy",  S_IRUGO, proc_pid_nsproxy),
6821  };
6822  
6823  static int proc_tgid_base_readdir(struct file * filp,
6824 @@ -2753,7 +2775,7 @@ retry:
6825         iter.task = NULL;
6826         pid = find_ge_pid(iter.tgid, ns);
6827         if (pid) {
6828 -               iter.tgid = pid_nr_ns(pid, ns);
6829 +               iter.tgid = pid_unmapped_nr_ns(pid, ns);
6830                 iter.task = pid_task(pid, PIDTYPE_PID);
6831                 /* What we to know is if the pid we have find is the
6832                  * pid of a thread_group_leader.  Testing for task
6833 @@ -2783,7 +2805,7 @@ static int proc_pid_fill_cache(struct fi
6834         struct tgid_iter iter)
6835  {
6836         char name[PROC_NUMBUF];
6837 -       int len = snprintf(name, sizeof(name), "%d", iter.tgid);
6838 +       int len = snprintf(name, sizeof(name), "%d", vx_map_tgid(iter.tgid));
6839         return proc_fill_cache(filp, dirent, filldir, name, len,
6840                                 proc_pid_instantiate, iter.task, NULL);
6841  }
6842 @@ -2792,7 +2814,7 @@ static int proc_pid_fill_cache(struct fi
6843  int proc_pid_readdir(struct file * filp, void * dirent, filldir_t filldir)
6844  {
6845         unsigned int nr = filp->f_pos - FIRST_PROCESS_ENTRY;
6846 -       struct task_struct *reaper = get_proc_task(filp->f_path.dentry->d_inode);
6847 +       struct task_struct *reaper = get_proc_task_real(filp->f_path.dentry->d_inode);
6848         struct tgid_iter iter;
6849         struct pid_namespace *ns;
6850  
6851 @@ -2812,6 +2834,8 @@ int proc_pid_readdir(struct file * filp,
6852              iter.task;
6853              iter.tgid += 1, iter = next_tgid(ns, iter)) {
6854                 filp->f_pos = iter.tgid + TGID_OFFSET;
6855 +               if (!vx_proc_task_visible(iter.task))
6856 +                       continue;
6857                 if (proc_pid_fill_cache(filp, dirent, filldir, iter) < 0) {
6858                         put_task_struct(iter.task);
6859                         goto out;
6860 @@ -2958,6 +2982,8 @@ static struct dentry *proc_task_lookup(s
6861         tid = name_to_int(dentry);
6862         if (tid == ~0U)
6863                 goto out;
6864 +       if (vx_current_initpid(tid))
6865 +               goto out;
6866  
6867         ns = dentry->d_sb->s_fs_info;
6868         rcu_read_lock();
6869 diff -NurpP --minimal linux-2.6.32.1/fs/proc/generic.c linux-2.6.32.1-vs2.3.0.36.27/fs/proc/generic.c
6870 --- linux-2.6.32.1/fs/proc/generic.c    2009-06-11 17:13:07.000000000 +0200
6871 +++ linux-2.6.32.1-vs2.3.0.36.27/fs/proc/generic.c      2009-12-03 20:04:56.000000000 +0100
6872 @@ -20,6 +20,7 @@
6873  #include <linux/bitops.h>
6874  #include <linux/spinlock.h>
6875  #include <linux/completion.h>
6876 +#include <linux/vserver/inode.h>
6877  #include <asm/uaccess.h>
6878  
6879  #include "internal.h"
6880 @@ -425,6 +426,8 @@ struct dentry *proc_lookup_de(struct pro
6881         for (de = de->subdir; de ; de = de->next) {
6882                 if (de->namelen != dentry->d_name.len)
6883                         continue;
6884 +                       if (!vx_hide_check(0, de->vx_flags))
6885 +                               continue;
6886                 if (!memcmp(dentry->d_name.name, de->name, de->namelen)) {
6887                         unsigned int ino;
6888  
6889 @@ -433,6 +436,8 @@ struct dentry *proc_lookup_de(struct pro
6890                         spin_unlock(&proc_subdir_lock);
6891                         error = -EINVAL;
6892                         inode = proc_get_inode(dir->i_sb, ino, de);
6893 +                               /* generic proc entries belong to the host */
6894 +                               inode->i_tag = 0;
6895                         goto out_unlock;
6896                 }
6897         }
6898 @@ -510,6 +515,8 @@ int proc_readdir_de(struct proc_dir_entr
6899  
6900                                 /* filldir passes info to user space */
6901                                 de_get(de);
6902 +                               if (!vx_hide_check(0, de->vx_flags))
6903 +                                       goto skip;
6904                                 spin_unlock(&proc_subdir_lock);
6905                                 if (filldir(dirent, de->name, de->namelen, filp->f_pos,
6906                                             de->low_ino, de->mode >> 12) < 0) {
6907 @@ -517,6 +524,7 @@ int proc_readdir_de(struct proc_dir_entr
6908                                         goto out;
6909                                 }
6910                                 spin_lock(&proc_subdir_lock);
6911 +                       skip:
6912                                 filp->f_pos++;
6913                                 next = de->next;
6914                                 de_put(de);
6915 @@ -631,6 +639,7 @@ static struct proc_dir_entry *__proc_cre
6916         ent->nlink = nlink;
6917         atomic_set(&ent->count, 1);
6918         ent->pde_users = 0;
6919 +       ent->vx_flags = IATTR_PROC_DEFAULT;
6920         spin_lock_init(&ent->pde_unload_lock);
6921         ent->pde_unload_completion = NULL;
6922         INIT_LIST_HEAD(&ent->pde_openers);
6923 @@ -654,7 +663,8 @@ struct proc_dir_entry *proc_symlink(cons
6924                                 kfree(ent->data);
6925                                 kfree(ent);
6926                                 ent = NULL;
6927 -                       }
6928 +                       } else
6929 +                               ent->vx_flags = IATTR_PROC_SYMLINK;
6930                 } else {
6931                         kfree(ent);
6932                         ent = NULL;
6933 diff -NurpP --minimal linux-2.6.32.1/fs/proc/inode.c linux-2.6.32.1-vs2.3.0.36.27/fs/proc/inode.c
6934 --- linux-2.6.32.1/fs/proc/inode.c      2009-06-11 17:13:07.000000000 +0200
6935 +++ linux-2.6.32.1-vs2.3.0.36.27/fs/proc/inode.c        2009-12-03 20:04:56.000000000 +0100
6936 @@ -459,6 +459,8 @@ struct inode *proc_get_inode(struct supe
6937                         inode->i_uid = de->uid;
6938                         inode->i_gid = de->gid;
6939                 }
6940 +               if (de->vx_flags)
6941 +                       PROC_I(inode)->vx_flags = de->vx_flags;
6942                 if (de->size)
6943                         inode->i_size = de->size;
6944                 if (de->nlink)
6945 diff -NurpP --minimal linux-2.6.32.1/fs/proc/internal.h linux-2.6.32.1-vs2.3.0.36.27/fs/proc/internal.h
6946 --- linux-2.6.32.1/fs/proc/internal.h   2009-09-10 15:26:23.000000000 +0200
6947 +++ linux-2.6.32.1-vs2.3.0.36.27/fs/proc/internal.h     2009-12-03 20:04:56.000000000 +0100
6948 @@ -10,6 +10,7 @@
6949   */
6950  
6951  #include <linux/proc_fs.h>
6952 +#include <linux/vs_pid.h>
6953  
6954  extern struct proc_dir_entry proc_root;
6955  #ifdef CONFIG_PROC_SYSCTL
6956 @@ -51,6 +52,9 @@ extern int proc_pid_status(struct seq_fi
6957                                 struct pid *pid, struct task_struct *task);
6958  extern int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns,
6959                                 struct pid *pid, struct task_struct *task);
6960 +extern int proc_pid_nsproxy(struct seq_file *m, struct pid_namespace *ns,
6961 +                               struct pid *pid, struct task_struct *task);
6962 +
6963  extern loff_t mem_lseek(struct file *file, loff_t offset, int orig);
6964  
6965  extern const struct file_operations proc_maps_operations;
6966 @@ -70,11 +74,16 @@ static inline struct pid *proc_pid(struc
6967         return PROC_I(inode)->pid;
6968  }
6969  
6970 -static inline struct task_struct *get_proc_task(struct inode *inode)
6971 +static inline struct task_struct *get_proc_task_real(struct inode *inode)
6972  {
6973         return get_pid_task(proc_pid(inode), PIDTYPE_PID);
6974  }
6975  
6976 +static inline struct task_struct *get_proc_task(struct inode *inode)
6977 +{
6978 +       return vx_get_proc_task(inode, proc_pid(inode));
6979 +}
6980 +
6981  static inline int proc_fd(struct inode *inode)
6982  {
6983         return PROC_I(inode)->fd;
6984 diff -NurpP --minimal linux-2.6.32.1/fs/proc/loadavg.c linux-2.6.32.1-vs2.3.0.36.27/fs/proc/loadavg.c
6985 --- linux-2.6.32.1/fs/proc/loadavg.c    2009-09-10 15:26:23.000000000 +0200
6986 +++ linux-2.6.32.1-vs2.3.0.36.27/fs/proc/loadavg.c      2009-12-03 20:04:56.000000000 +0100
6987 @@ -12,15 +12,27 @@
6988  
6989  static int loadavg_proc_show(struct seq_file *m, void *v)
6990  {
6991 +       unsigned long running;
6992 +       unsigned int threads;
6993         unsigned long avnrun[3];
6994  
6995         get_avenrun(avnrun, FIXED_1/200, 0);
6996  
6997 +       if (vx_flags(VXF_VIRT_LOAD, 0)) {
6998 +               struct vx_info *vxi = current_vx_info();
6999 +
7000 +               running = atomic_read(&vxi->cvirt.nr_running);
7001 +               threads = atomic_read(&vxi->cvirt.nr_threads);
7002 +       } else {
7003 +               running = nr_running();
7004 +               threads = nr_threads;
7005 +       }
7006 +
7007         seq_printf(m, "%lu.%02lu %lu.%02lu %lu.%02lu %ld/%d %d\n",
7008                 LOAD_INT(avnrun[0]), LOAD_FRAC(avnrun[0]),
7009                 LOAD_INT(avnrun[1]), LOAD_FRAC(avnrun[1]),
7010                 LOAD_INT(avnrun[2]), LOAD_FRAC(avnrun[2]),
7011 -               nr_running(), nr_threads,
7012 +               running, threads,
7013                 task_active_pid_ns(current)->last_pid);
7014         return 0;
7015  }
7016 diff -NurpP --minimal linux-2.6.32.1/fs/proc/meminfo.c linux-2.6.32.1-vs2.3.0.36.27/fs/proc/meminfo.c
7017 --- linux-2.6.32.1/fs/proc/meminfo.c    2009-12-03 20:02:53.000000000 +0100
7018 +++ linux-2.6.32.1-vs2.3.0.36.27/fs/proc/meminfo.c      2009-12-03 20:04:56.000000000 +0100
7019 @@ -41,7 +41,7 @@ static int meminfo_proc_show(struct seq_
7020  
7021         cached = global_page_state(NR_FILE_PAGES) -
7022                         total_swapcache_pages - i.bufferram;
7023 -       if (cached < 0)
7024 +       if (cached < 0 || vx_flags(VXF_VIRT_MEM, 0))
7025                 cached = 0;
7026  
7027         get_vmalloc_info(&vmi);
7028 diff -NurpP --minimal linux-2.6.32.1/fs/proc/root.c linux-2.6.32.1-vs2.3.0.36.27/fs/proc/root.c
7029 --- linux-2.6.32.1/fs/proc/root.c       2009-06-11 17:13:07.000000000 +0200
7030 +++ linux-2.6.32.1-vs2.3.0.36.27/fs/proc/root.c 2009-12-03 20:04:56.000000000 +0100
7031 @@ -18,9 +18,14 @@
7032  #include <linux/bitops.h>
7033  #include <linux/mount.h>
7034  #include <linux/pid_namespace.h>
7035 +#include <linux/vserver/inode.h>
7036  
7037  #include "internal.h"
7038  
7039 +struct proc_dir_entry *proc_virtual;
7040 +
7041 +extern void proc_vx_init(void);
7042 +
7043  static int proc_test_super(struct super_block *sb, void *data)
7044  {
7045         return sb->s_fs_info == data;
7046 @@ -136,6 +141,7 @@ void __init proc_root_init(void)
7047  #endif
7048         proc_mkdir("bus", NULL);
7049         proc_sys_init();
7050 +       proc_vx_init();
7051  }
7052  
7053  static int proc_root_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat
7054 @@ -203,6 +209,7 @@ struct proc_dir_entry proc_root = {
7055         .proc_iops      = &proc_root_inode_operations, 
7056         .proc_fops      = &proc_root_operations,
7057         .parent         = &proc_root,
7058 +       .vx_flags       = IATTR_ADMIN | IATTR_WATCH,
7059  };
7060  
7061  int pid_ns_prepare_proc(struct pid_namespace *ns)
7062 diff -NurpP --minimal linux-2.6.32.1/fs/proc/uptime.c linux-2.6.32.1-vs2.3.0.36.27/fs/proc/uptime.c
7063 --- linux-2.6.32.1/fs/proc/uptime.c     2009-12-03 20:02:53.000000000 +0100
7064 +++ linux-2.6.32.1-vs2.3.0.36.27/fs/proc/uptime.c       2009-12-03 20:04:56.000000000 +0100
7065 @@ -4,22 +4,22 @@
7066  #include <linux/sched.h>
7067  #include <linux/seq_file.h>
7068  #include <linux/time.h>
7069 -#include <linux/kernel_stat.h>
7070 +#include <linux/vserver/cvirt.h>
7071  #include <asm/cputime.h>
7072  
7073  static int uptime_proc_show(struct seq_file *m, void *v)
7074  {
7075         struct timespec uptime;
7076         struct timespec idle;
7077 -       int i;
7078 -       cputime_t idletime = cputime_zero;
7079 -
7080 -       for_each_possible_cpu(i)
7081 -               idletime = cputime64_add(idletime, kstat_cpu(i).cpustat.idle);
7082 +       cputime_t idletime = cputime_add(init_task.utime, init_task.stime);
7083  
7084         do_posix_clock_monotonic_gettime(&uptime);
7085         monotonic_to_bootbased(&uptime);
7086         cputime_to_timespec(idletime, &idle);
7087 +
7088 +       if (vx_flags(VXF_VIRT_UPTIME, 0))
7089 +               vx_vsi_uptime(&uptime, &idle);
7090 +
7091         seq_printf(m, "%lu.%02lu %lu.%02lu\n",
7092                         (unsigned long) uptime.tv_sec,
7093                         (uptime.tv_nsec / (NSEC_PER_SEC / 100)),
7094 diff -NurpP --minimal linux-2.6.32.1/fs/quota/quota.c linux-2.6.32.1-vs2.3.0.36.27/fs/quota/quota.c
7095 --- linux-2.6.32.1/fs/quota/quota.c     2009-09-10 15:26:24.000000000 +0200
7096 +++ linux-2.6.32.1-vs2.3.0.36.27/fs/quota/quota.c       2009-12-03 20:04:56.000000000 +0100
7097 @@ -18,6 +18,7 @@
7098  #include <linux/capability.h>
7099  #include <linux/quotaops.h>
7100  #include <linux/types.h>
7101 +#include <linux/vs_context.h>
7102  
7103  /* Check validity of generic quotactl commands */
7104  static int generic_quotactl_valid(struct super_block *sb, int type, int cmd,
7105 @@ -83,11 +84,11 @@ static int generic_quotactl_valid(struct
7106         if (cmd == Q_GETQUOTA) {
7107                 if (((type == USRQUOTA && current_euid() != id) ||
7108                      (type == GRPQUOTA && !in_egroup_p(id))) &&
7109 -                   !capable(CAP_SYS_ADMIN))
7110 +                   !vx_capable(CAP_SYS_ADMIN, VXC_QUOTA_CTL))
7111                         return -EPERM;
7112         }
7113         else if (cmd != Q_GETFMT && cmd != Q_SYNC && cmd != Q_GETINFO)
7114 -               if (!capable(CAP_SYS_ADMIN))
7115 +               if (!vx_capable(CAP_SYS_ADMIN, VXC_QUOTA_CTL))
7116                         return -EPERM;
7117  
7118         return 0;
7119 @@ -135,10 +136,10 @@ static int xqm_quotactl_valid(struct sup
7120         if (cmd == Q_XGETQUOTA) {
7121                 if (((type == XQM_USRQUOTA && current_euid() != id) ||
7122                      (type == XQM_GRPQUOTA && !in_egroup_p(id))) &&
7123 -                    !capable(CAP_SYS_ADMIN))
7124 +                    !vx_capable(CAP_SYS_ADMIN, VXC_QUOTA_CTL))
7125                         return -EPERM;
7126         } else if (cmd != Q_XGETQSTAT && cmd != Q_XQUOTASYNC) {
7127 -               if (!capable(CAP_SYS_ADMIN))
7128 +               if (!vx_capable(CAP_SYS_ADMIN, VXC_QUOTA_CTL))
7129                         return -EPERM;
7130         }
7131  
7132 @@ -351,6 +352,46 @@ static int do_quotactl(struct super_bloc
7133         return 0;
7134  }
7135  
7136 +#if defined(CONFIG_BLK_DEV_VROOT) || defined(CONFIG_BLK_DEV_VROOT_MODULE)
7137 +
7138 +#include <linux/vroot.h>
7139 +#include <linux/major.h>
7140 +#include <linux/module.h>
7141 +#include <linux/kallsyms.h>
7142 +#include <linux/vserver/debug.h>
7143 +
7144 +static vroot_grb_func *vroot_get_real_bdev = NULL;
7145 +
7146 +static spinlock_t vroot_grb_lock = SPIN_LOCK_UNLOCKED;
7147 +
7148 +int register_vroot_grb(vroot_grb_func *func) {
7149 +       int ret = -EBUSY;
7150 +
7151 +       spin_lock(&vroot_grb_lock);
7152 +       if (!vroot_get_real_bdev) {
7153 +               vroot_get_real_bdev = func;
7154 +               ret = 0;
7155 +       }
7156 +       spin_unlock(&vroot_grb_lock);
7157 +       return ret;
7158 +}
7159 +EXPORT_SYMBOL(register_vroot_grb);
7160 +
7161 +int unregister_vroot_grb(vroot_grb_func *func) {
7162 +       int ret = -EINVAL;
7163 +
7164 +       spin_lock(&vroot_grb_lock);
7165 +       if (vroot_get_real_bdev) {
7166 +               vroot_get_real_bdev = NULL;
7167 +               ret = 0;
7168 +       }
7169 +       spin_unlock(&vroot_grb_lock);
7170 +       return ret;
7171 +}
7172 +EXPORT_SYMBOL(unregister_vroot_grb);
7173 +
7174 +#endif
7175 +
7176  /*
7177   * look up a superblock on which quota ops will be performed
7178   * - use the name of a block device to find the superblock thereon
7179 @@ -368,6 +409,22 @@ static struct super_block *quotactl_bloc
7180         putname(tmp);
7181         if (IS_ERR(bdev))
7182                 return ERR_CAST(bdev);
7183 +#if defined(CONFIG_BLK_DEV_VROOT) || defined(CONFIG_BLK_DEV_VROOT_MODULE)
7184 +       if (bdev && bdev->bd_inode &&
7185 +                       imajor(bdev->bd_inode) == VROOT_MAJOR) {
7186 +               struct block_device *bdnew = (void *)-EINVAL;
7187 +
7188 +               if (vroot_get_real_bdev)
7189 +                       bdnew = vroot_get_real_bdev(bdev);
7190 +               else
7191 +                       vxdprintk(VXD_CBIT(misc, 0),
7192 +                                       "vroot_get_real_bdev not set");
7193 +               bdput(bdev);
7194 +               if (IS_ERR(bdnew))
7195 +                       return ERR_PTR(PTR_ERR(bdnew));
7196 +               bdev = bdnew;
7197 +       }
7198 +#endif
7199         sb = get_super(bdev);
7200         bdput(bdev);
7201         if (!sb)
7202 diff -NurpP --minimal linux-2.6.32.1/fs/reiserfs/file.c linux-2.6.32.1-vs2.3.0.36.27/fs/reiserfs/file.c
7203 --- linux-2.6.32.1/fs/reiserfs/file.c   2009-06-11 17:13:08.000000000 +0200
7204 +++ linux-2.6.32.1-vs2.3.0.36.27/fs/reiserfs/file.c     2009-12-03 20:04:56.000000000 +0100
7205 @@ -307,4 +307,5 @@ const struct inode_operations reiserfs_f
7206         .listxattr = reiserfs_listxattr,
7207         .removexattr = reiserfs_removexattr,
7208         .permission = reiserfs_permission,
7209 +       .sync_flags = reiserfs_sync_flags,
7210  };
7211 diff -NurpP --minimal linux-2.6.32.1/fs/reiserfs/inode.c linux-2.6.32.1-vs2.3.0.36.27/fs/reiserfs/inode.c
7212 --- linux-2.6.32.1/fs/reiserfs/inode.c  2009-09-10 15:26:24.000000000 +0200
7213 +++ linux-2.6.32.1-vs2.3.0.36.27/fs/reiserfs/inode.c    2009-12-03 20:04:56.000000000 +0100
7214 @@ -18,6 +18,7 @@
7215  #include <linux/writeback.h>
7216  #include <linux/quotaops.h>
7217  #include <linux/swap.h>
7218 +#include <linux/vs_tag.h>
7219  
7220  int reiserfs_commit_write(struct file *f, struct page *page,
7221                           unsigned from, unsigned to);
7222 @@ -1117,6 +1118,8 @@ static void init_inode(struct inode *ino
7223         struct buffer_head *bh;
7224         struct item_head *ih;
7225         __u32 rdev;
7226 +       uid_t uid;
7227 +       gid_t gid;
7228         //int version = ITEM_VERSION_1;
7229  
7230         bh = PATH_PLAST_BUFFER(path);
7231 @@ -1138,12 +1141,13 @@ static void init_inode(struct inode *ino
7232                     (struct stat_data_v1 *)B_I_PITEM(bh, ih);
7233                 unsigned long blocks;
7234  
7235 +               uid = sd_v1_uid(sd);
7236 +               gid = sd_v1_gid(sd);
7237 +
7238                 set_inode_item_key_version(inode, KEY_FORMAT_3_5);
7239                 set_inode_sd_version(inode, STAT_DATA_V1);
7240                 inode->i_mode = sd_v1_mode(sd);
7241                 inode->i_nlink = sd_v1_nlink(sd);
7242 -               inode->i_uid = sd_v1_uid(sd);
7243 -               inode->i_gid = sd_v1_gid(sd);
7244                 inode->i_size = sd_v1_size(sd);
7245                 inode->i_atime.tv_sec = sd_v1_atime(sd);
7246                 inode->i_mtime.tv_sec = sd_v1_mtime(sd);
7247 @@ -1185,11 +1189,12 @@ static void init_inode(struct inode *ino
7248                 // (directories and symlinks)
7249                 struct stat_data *sd = (struct stat_data *)B_I_PITEM(bh, ih);
7250  
7251 +               uid    = sd_v2_uid(sd);
7252 +               gid    = sd_v2_gid(sd);
7253 +
7254                 inode->i_mode = sd_v2_mode(sd);
7255                 inode->i_nlink = sd_v2_nlink(sd);
7256 -               inode->i_uid = sd_v2_uid(sd);
7257                 inode->i_size = sd_v2_size(sd);
7258 -               inode->i_gid = sd_v2_gid(sd);
7259                 inode->i_mtime.tv_sec = sd_v2_mtime(sd);
7260                 inode->i_atime.tv_sec = sd_v2_atime(sd);
7261                 inode->i_ctime.tv_sec = sd_v2_ctime(sd);
7262 @@ -1219,6 +1224,10 @@ static void init_inode(struct inode *ino
7263                 sd_attrs_to_i_attrs(sd_v2_attrs(sd), inode);
7264         }
7265  
7266 +       inode->i_uid = INOTAG_UID(DX_TAG(inode), uid, gid);
7267 +       inode->i_gid = INOTAG_GID(DX_TAG(inode), uid, gid);
7268 +       inode->i_tag = INOTAG_TAG(DX_TAG(inode), uid, gid, 0);
7269 +
7270         pathrelse(path);
7271         if (S_ISREG(inode->i_mode)) {
7272                 inode->i_op = &reiserfs_file_inode_operations;
7273 @@ -1241,13 +1250,15 @@ static void init_inode(struct inode *ino
7274  static void inode2sd(void *sd, struct inode *inode, loff_t size)
7275  {
7276         struct stat_data *sd_v2 = (struct stat_data *)sd;
7277 +       uid_t uid = TAGINO_UID(DX_TAG(inode), inode->i_uid, inode->i_tag);
7278 +       gid_t gid = TAGINO_GID(DX_TAG(inode), inode->i_gid, inode->i_tag);
7279         __u16 flags;
7280  
7281 +       set_sd_v2_uid(sd_v2, uid);
7282 +       set_sd_v2_gid(sd_v2, gid);
7283         set_sd_v2_mode(sd_v2, inode->i_mode);
7284         set_sd_v2_nlink(sd_v2, inode->i_nlink);
7285 -       set_sd_v2_uid(sd_v2, inode->i_uid);
7286         set_sd_v2_size(sd_v2, size);
7287 -       set_sd_v2_gid(sd_v2, inode->i_gid);
7288         set_sd_v2_mtime(sd_v2, inode->i_mtime.tv_sec);
7289         set_sd_v2_atime(sd_v2, inode->i_atime.tv_sec);
7290         set_sd_v2_ctime(sd_v2, inode->i_ctime.tv_sec);
7291 @@ -2828,14 +2839,19 @@ int reiserfs_commit_write(struct file *f
7292  void sd_attrs_to_i_attrs(__u16 sd_attrs, struct inode *inode)
7293  {
7294         if (reiserfs_attrs(inode->i_sb)) {
7295 -               if (sd_attrs & REISERFS_SYNC_FL)
7296 -                       inode->i_flags |= S_SYNC;
7297 -               else
7298 -                       inode->i_flags &= ~S_SYNC;
7299                 if (sd_attrs & REISERFS_IMMUTABLE_FL)
7300                         inode->i_flags |= S_IMMUTABLE;
7301                 else
7302                         inode->i_flags &= ~S_IMMUTABLE;
7303 +               if (sd_attrs & REISERFS_IXUNLINK_FL)
7304 +                       inode->i_flags |= S_IXUNLINK;
7305 +               else
7306 +                       inode->i_flags &= ~S_IXUNLINK;
7307 +
7308 +               if (sd_attrs & REISERFS_SYNC_FL)
7309 +                       inode->i_flags |= S_SYNC;
7310 +               else
7311 +                       inode->i_flags &= ~S_SYNC;
7312                 if (sd_attrs & REISERFS_APPEND_FL)
7313                         inode->i_flags |= S_APPEND;
7314                 else
7315 @@ -2848,6 +2864,15 @@ void sd_attrs_to_i_attrs(__u16 sd_attrs,
7316                         REISERFS_I(inode)->i_flags |= i_nopack_mask;
7317                 else
7318                         REISERFS_I(inode)->i_flags &= ~i_nopack_mask;
7319 +
7320 +               if (sd_attrs & REISERFS_BARRIER_FL)
7321 +                       inode->i_vflags |= V_BARRIER;
7322 +               else
7323 +                       inode->i_vflags &= ~V_BARRIER;
7324 +               if (sd_attrs & REISERFS_COW_FL)
7325 +                       inode->i_vflags |= V_COW;
7326 +               else
7327 +                       inode->i_vflags &= ~V_COW;
7328         }
7329  }
7330  
7331 @@ -2858,6 +2883,11 @@ void i_attrs_to_sd_attrs(struct inode *i
7332                         *sd_attrs |= REISERFS_IMMUTABLE_FL;
7333                 else
7334                         *sd_attrs &= ~REISERFS_IMMUTABLE_FL;
7335 +               if (inode->i_flags & S_IXUNLINK)
7336 +                       *sd_attrs |= REISERFS_IXUNLINK_FL;
7337 +               else
7338 +                       *sd_attrs &= ~REISERFS_IXUNLINK_FL;
7339 +
7340                 if (inode->i_flags & S_SYNC)
7341                         *sd_attrs |= REISERFS_SYNC_FL;
7342                 else
7343 @@ -2870,6 +2900,15 @@ void i_attrs_to_sd_attrs(struct inode *i
7344                         *sd_attrs |= REISERFS_NOTAIL_FL;
7345                 else
7346                         *sd_attrs &= ~REISERFS_NOTAIL_FL;
7347 +
7348 +               if (inode->i_vflags & V_BARRIER)
7349 +                       *sd_attrs |= REISERFS_BARRIER_FL;
7350 +               else
7351 +                       *sd_attrs &= ~REISERFS_BARRIER_FL;
7352 +               if (inode->i_vflags & V_COW)
7353 +                       *sd_attrs |= REISERFS_COW_FL;
7354 +               else
7355 +                       *sd_attrs &= ~REISERFS_COW_FL;
7356         }
7357  }
7358  
7359 @@ -3090,9 +3129,11 @@ int reiserfs_setattr(struct dentry *dent
7360         }
7361  
7362         error = inode_change_ok(inode, attr);
7363 +
7364         if (!error) {
7365                 if ((ia_valid & ATTR_UID && attr->ia_uid != inode->i_uid) ||
7366 -                   (ia_valid & ATTR_GID && attr->ia_gid != inode->i_gid)) {
7367 +                   (ia_valid & ATTR_GID && attr->ia_gid != inode->i_gid) ||
7368 +                   (ia_valid & ATTR_TAG && attr->ia_tag != inode->i_tag)) {
7369                         error = reiserfs_chown_xattrs(inode, attr);
7370  
7371                         if (!error) {
7372 @@ -3122,6 +3163,9 @@ int reiserfs_setattr(struct dentry *dent
7373                                         inode->i_uid = attr->ia_uid;
7374                                 if (attr->ia_valid & ATTR_GID)
7375                                         inode->i_gid = attr->ia_gid;
7376 +                               if ((attr->ia_valid & ATTR_TAG) &&
7377 +                                       IS_TAGGED(inode))
7378 +                                       inode->i_tag = attr->ia_tag;
7379                                 mark_inode_dirty(inode);
7380                                 error =
7381                                     journal_end(&th, inode->i_sb, jbegin_count);
7382 diff -NurpP --minimal linux-2.6.32.1/fs/reiserfs/ioctl.c linux-2.6.32.1-vs2.3.0.36.27/fs/reiserfs/ioctl.c
7383 --- linux-2.6.32.1/fs/reiserfs/ioctl.c  2009-06-11 17:13:08.000000000 +0200
7384 +++ linux-2.6.32.1-vs2.3.0.36.27/fs/reiserfs/ioctl.c    2009-12-03 20:04:56.000000000 +0100
7385 @@ -7,11 +7,27 @@
7386  #include <linux/mount.h>
7387  #include <linux/reiserfs_fs.h>
7388  #include <linux/time.h>
7389 +#include <linux/mount.h>
7390  #include <asm/uaccess.h>
7391  #include <linux/pagemap.h>
7392  #include <linux/smp_lock.h>
7393  #include <linux/compat.h>
7394  
7395 +
7396 +int reiserfs_sync_flags(struct inode *inode, int flags, int vflags)
7397 +{
7398 +       __u16 sd_attrs = 0;
7399 +
7400 +       inode->i_flags = flags;
7401 +       inode->i_vflags = vflags;
7402 +
7403 +       i_attrs_to_sd_attrs(inode, &sd_attrs);
7404 +       REISERFS_I(inode)->i_attrs = sd_attrs;
7405 +       inode->i_ctime = CURRENT_TIME_SEC;
7406 +       mark_inode_dirty(inode);
7407 +       return 0;
7408 +}
7409 +
7410  /*
7411  ** reiserfs_ioctl - handler for ioctl for inode
7412  ** supported commands:
7413 @@ -23,7 +39,7 @@
7414  int reiserfs_ioctl(struct inode *inode, struct file *filp, unsigned int cmd,
7415                    unsigned long arg)
7416  {
7417 -       unsigned int flags;
7418 +       unsigned int flags, oldflags;
7419         int err = 0;
7420  
7421         switch (cmd) {
7422 @@ -43,6 +59,7 @@ int reiserfs_ioctl(struct inode *inode, 
7423  
7424                 flags = REISERFS_I(inode)->i_attrs;
7425                 i_attrs_to_sd_attrs(inode, (__u16 *) & flags);
7426 +               flags &= REISERFS_FL_USER_VISIBLE;
7427                 return put_user(flags, (int __user *)arg);
7428         case REISERFS_IOC_SETFLAGS:{
7429                         if (!reiserfs_attrs(inode->i_sb))
7430 @@ -60,6 +77,10 @@ int reiserfs_ioctl(struct inode *inode, 
7431                                 err = -EFAULT;
7432                                 goto setflags_out;
7433                         }
7434 +                       if (IS_BARRIER(inode)) {
7435 +                               vxwprintk_task(1, "messing with the barrier.");
7436 +                               return -EACCES;
7437 +                       }
7438                         /*
7439                          * Is it quota file? Do not allow user to mess with it
7440                          */
7441 @@ -84,6 +105,10 @@ int reiserfs_ioctl(struct inode *inode, 
7442                                         goto setflags_out;
7443                                 }
7444                         }
7445 +
7446 +                       oldflags = REISERFS_I(inode)->i_attrs;
7447 +                       flags &= REISERFS_FL_USER_MODIFIABLE;
7448 +                       flags |= oldflags & ~REISERFS_FL_USER_MODIFIABLE;
7449                         sd_attrs_to_i_attrs(flags, inode);
7450                         REISERFS_I(inode)->i_attrs = flags;
7451                         inode->i_ctime = CURRENT_TIME_SEC;
7452 diff -NurpP --minimal linux-2.6.32.1/fs/reiserfs/namei.c linux-2.6.32.1-vs2.3.0.36.27/fs/reiserfs/namei.c
7453 --- linux-2.6.32.1/fs/reiserfs/namei.c  2009-06-11 17:13:08.000000000 +0200
7454 +++ linux-2.6.32.1-vs2.3.0.36.27/fs/reiserfs/namei.c    2009-12-03 20:04:56.000000000 +0100
7455 @@ -17,6 +17,7 @@
7456  #include <linux/reiserfs_acl.h>
7457  #include <linux/reiserfs_xattr.h>
7458  #include <linux/quotaops.h>
7459 +#include <linux/vs_tag.h>
7460  
7461  #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; }
7462  #define DEC_DIR_INODE_NLINK(i) if (i->i_nlink != 1) drop_nlink(i);
7463 @@ -354,6 +355,7 @@ static struct dentry *reiserfs_lookup(st
7464         if (retval == IO_ERROR) {
7465                 return ERR_PTR(-EIO);
7466         }
7467 +               dx_propagate_tag(nd, inode);
7468  
7469         return d_splice_alias(inode, dentry);
7470  }
7471 @@ -570,6 +572,7 @@ static int new_inode_init(struct inode *
7472         } else {
7473                 inode->i_gid = current_fsgid();
7474         }
7475 +       inode->i_tag = dx_current_fstag(inode->i_sb);
7476         vfs_dq_init(inode);
7477         return 0;
7478  }
7479 @@ -1515,6 +1518,7 @@ const struct inode_operations reiserfs_d
7480         .listxattr = reiserfs_listxattr,
7481         .removexattr = reiserfs_removexattr,
7482         .permission = reiserfs_permission,
7483 +       .sync_flags = reiserfs_sync_flags,
7484  };
7485  
7486  /*
7487 diff -NurpP --minimal linux-2.6.32.1/fs/reiserfs/super.c linux-2.6.32.1-vs2.3.0.36.27/fs/reiserfs/super.c
7488 --- linux-2.6.32.1/fs/reiserfs/super.c  2009-12-03 20:02:53.000000000 +0100
7489 +++ linux-2.6.32.1-vs2.3.0.36.27/fs/reiserfs/super.c    2009-12-03 20:04:56.000000000 +0100
7490 @@ -884,6 +884,14 @@ static int reiserfs_parse_options(struct
7491                 {"user_xattr",.setmask = 1 << REISERFS_UNSUPPORTED_OPT},
7492                 {"nouser_xattr",.clrmask = 1 << REISERFS_UNSUPPORTED_OPT},
7493  #endif
7494 +#ifndef CONFIG_TAGGING_NONE
7495 +               {"tagxid",.setmask = 1 << REISERFS_TAGGED},
7496 +               {"tag",.setmask = 1 << REISERFS_TAGGED},
7497 +               {"notag",.clrmask = 1 << REISERFS_TAGGED},
7498 +#endif
7499 +#ifdef CONFIG_PROPAGATE
7500 +               {"tag",.arg_required = 'T',.values = NULL},
7501 +#endif
7502  #ifdef CONFIG_REISERFS_FS_POSIX_ACL
7503                 {"acl",.setmask = 1 << REISERFS_POSIXACL},
7504                 {"noacl",.clrmask = 1 << REISERFS_POSIXACL},
7505 @@ -1190,6 +1198,14 @@ static int reiserfs_remount(struct super
7506         handle_quota_files(s, qf_names, &qfmt);
7507  #endif
7508  
7509 +       if ((mount_options & (1 << REISERFS_TAGGED)) &&
7510 +               !(s->s_flags & MS_TAGGED)) {
7511 +               reiserfs_warning(s, "super-vs01",
7512 +                       "reiserfs: tagging not permitted on remount.");
7513 +               err = -EINVAL;
7514 +               goto out_err;
7515 +       }
7516 +
7517         handle_attrs(s);
7518  
7519         /* Add options that are safe here */
7520 @@ -1652,6 +1668,10 @@ static int reiserfs_fill_super(struct su
7521                 goto error;
7522         }
7523  
7524 +       /* map mount option tagxid */
7525 +       if (REISERFS_SB(s)->s_mount_opt & (1 << REISERFS_TAGGED))
7526 +               s->s_flags |= MS_TAGGED;
7527 +
7528         rs = SB_DISK_SUPER_BLOCK(s);
7529         /* Let's do basic sanity check to verify that underlying device is not
7530            smaller than the filesystem. If the check fails then abort and scream,
7531 diff -NurpP --minimal linux-2.6.32.1/fs/reiserfs/xattr.c linux-2.6.32.1-vs2.3.0.36.27/fs/reiserfs/xattr.c
7532 --- linux-2.6.32.1/fs/reiserfs/xattr.c  2009-09-10 15:26:24.000000000 +0200
7533 +++ linux-2.6.32.1-vs2.3.0.36.27/fs/reiserfs/xattr.c    2009-12-03 20:04:56.000000000 +0100
7534 @@ -39,6 +39,7 @@
7535  #include <linux/namei.h>
7536  #include <linux/errno.h>
7537  #include <linux/fs.h>
7538 +#include <linux/mount.h>
7539  #include <linux/file.h>
7540  #include <linux/pagemap.h>
7541  #include <linux/xattr.h>
7542 diff -NurpP --minimal linux-2.6.32.1/fs/stat.c linux-2.6.32.1-vs2.3.0.36.27/fs/stat.c
7543 --- linux-2.6.32.1/fs/stat.c    2009-06-11 17:13:08.000000000 +0200
7544 +++ linux-2.6.32.1-vs2.3.0.36.27/fs/stat.c      2009-12-03 20:04:56.000000000 +0100
7545 @@ -26,6 +26,7 @@ void generic_fillattr(struct inode *inod
7546         stat->nlink = inode->i_nlink;
7547         stat->uid = inode->i_uid;
7548         stat->gid = inode->i_gid;
7549 +       stat->tag = inode->i_tag;
7550         stat->rdev = inode->i_rdev;
7551         stat->atime = inode->i_atime;
7552         stat->mtime = inode->i_mtime;
7553 diff -NurpP --minimal linux-2.6.32.1/fs/super.c linux-2.6.32.1-vs2.3.0.36.27/fs/super.c
7554 --- linux-2.6.32.1/fs/super.c   2009-12-03 20:02:53.000000000 +0100
7555 +++ linux-2.6.32.1-vs2.3.0.36.27/fs/super.c     2009-12-03 20:04:56.000000000 +0100
7556 @@ -37,6 +37,9 @@
7557  #include <linux/kobject.h>
7558  #include <linux/mutex.h>
7559  #include <linux/file.h>
7560 +#include <linux/devpts_fs.h>
7561 +#include <linux/proc_fs.h>
7562 +#include <linux/vs_context.h>
7563  #include <asm/uaccess.h>
7564  #include "internal.h"
7565  
7566 @@ -913,12 +916,18 @@ struct vfsmount *
7567  vfs_kern_mount(struct file_system_type *type, int flags, const char *name, void *data)
7568  {
7569         struct vfsmount *mnt;
7570 +       struct super_block *sb;
7571         char *secdata = NULL;
7572         int error;
7573  
7574         if (!type)
7575                 return ERR_PTR(-ENODEV);
7576  
7577 +       error = -EPERM;
7578 +       if ((type->fs_flags & FS_BINARY_MOUNTDATA) &&
7579 +               !vx_capable(CAP_SYS_ADMIN, VXC_BINARY_MOUNT))
7580 +               goto out;
7581 +
7582         error = -ENOMEM;
7583         mnt = alloc_vfsmnt(name);
7584         if (!mnt)
7585 @@ -937,9 +946,17 @@ vfs_kern_mount(struct file_system_type *
7586         error = type->get_sb(type, flags, name, data, mnt);
7587         if (error < 0)
7588                 goto out_free_secdata;
7589 -       BUG_ON(!mnt->mnt_sb);
7590  
7591 -       error = security_sb_kern_mount(mnt->mnt_sb, flags, secdata);
7592 +       sb = mnt->mnt_sb;
7593 +       BUG_ON(!sb);
7594 +
7595 +       error = -EPERM;
7596 +       if (!vx_capable(CAP_SYS_ADMIN, VXC_BINARY_MOUNT) && !sb->s_bdev &&
7597 +               (sb->s_magic != PROC_SUPER_MAGIC) &&
7598 +               (sb->s_magic != DEVPTS_SUPER_MAGIC))
7599 +               goto out_sb;
7600 +
7601 +       error = security_sb_kern_mount(sb, flags, secdata);
7602         if (error)
7603                 goto out_sb;
7604  
7605 diff -NurpP --minimal linux-2.6.32.1/fs/sysfs/mount.c linux-2.6.32.1-vs2.3.0.36.27/fs/sysfs/mount.c
7606 --- linux-2.6.32.1/fs/sysfs/mount.c     2009-06-11 17:13:08.000000000 +0200
7607 +++ linux-2.6.32.1-vs2.3.0.36.27/fs/sysfs/mount.c       2009-12-03 20:04:56.000000000 +0100
7608 @@ -47,7 +47,7 @@ static int sysfs_fill_super(struct super
7609  
7610         sb->s_blocksize = PAGE_CACHE_SIZE;
7611         sb->s_blocksize_bits = PAGE_CACHE_SHIFT;
7612 -       sb->s_magic = SYSFS_MAGIC;
7613 +       sb->s_magic = SYSFS_SUPER_MAGIC;
7614         sb->s_op = &sysfs_ops;
7615         sb->s_time_gran = 1;
7616         sysfs_sb = sb;
7617 diff -NurpP --minimal linux-2.6.32.1/fs/utimes.c linux-2.6.32.1-vs2.3.0.36.27/fs/utimes.c
7618 --- linux-2.6.32.1/fs/utimes.c  2009-03-24 14:22:37.000000000 +0100
7619 +++ linux-2.6.32.1-vs2.3.0.36.27/fs/utimes.c    2009-12-03 20:04:56.000000000 +0100
7620 @@ -8,6 +8,8 @@
7621  #include <linux/stat.h>
7622  #include <linux/utime.h>
7623  #include <linux/syscalls.h>
7624 +#include <linux/mount.h>
7625 +#include <linux/vs_cowbl.h>
7626  #include <asm/uaccess.h>
7627  #include <asm/unistd.h>
7628  
7629 diff -NurpP --minimal linux-2.6.32.1/fs/xattr.c linux-2.6.32.1-vs2.3.0.36.27/fs/xattr.c
7630 --- linux-2.6.32.1/fs/xattr.c   2009-12-03 20:02:53.000000000 +0100
7631 +++ linux-2.6.32.1-vs2.3.0.36.27/fs/xattr.c     2009-12-03 20:04:56.000000000 +0100
7632 @@ -18,6 +18,7 @@
7633  #include <linux/module.h>
7634  #include <linux/fsnotify.h>
7635  #include <linux/audit.h>
7636 +#include <linux/mount.h>
7637  #include <asm/uaccess.h>
7638  
7639  
7640 diff -NurpP --minimal linux-2.6.32.1/fs/xfs/linux-2.6/xfs_ioctl.c linux-2.6.32.1-vs2.3.0.36.27/fs/xfs/linux-2.6/xfs_ioctl.c
7641 --- linux-2.6.32.1/fs/xfs/linux-2.6/xfs_ioctl.c 2009-09-10 15:26:24.000000000 +0200
7642 +++ linux-2.6.32.1-vs2.3.0.36.27/fs/xfs/linux-2.6/xfs_ioctl.c   2009-12-03 20:04:56.000000000 +0100
7643 @@ -34,7 +34,6 @@
7644  #include "xfs_dir2_sf.h"
7645  #include "xfs_dinode.h"
7646  #include "xfs_inode.h"
7647 -#include "xfs_ioctl.h"
7648  #include "xfs_btree.h"
7649  #include "xfs_ialloc.h"
7650  #include "xfs_rtalloc.h"
7651 @@ -742,6 +741,10 @@ xfs_merge_ioc_xflags(
7652                 xflags |= XFS_XFLAG_IMMUTABLE;
7653         else
7654                 xflags &= ~XFS_XFLAG_IMMUTABLE;
7655 +       if (flags & FS_IXUNLINK_FL)
7656 +               xflags |= XFS_XFLAG_IXUNLINK;
7657 +       else
7658 +               xflags &= ~XFS_XFLAG_IXUNLINK;
7659         if (flags & FS_APPEND_FL)
7660                 xflags |= XFS_XFLAG_APPEND;
7661         else
7662 @@ -770,6 +773,8 @@ xfs_di2lxflags(
7663  
7664         if (di_flags & XFS_DIFLAG_IMMUTABLE)
7665                 flags |= FS_IMMUTABLE_FL;
7666 +       if (di_flags & XFS_DIFLAG_IXUNLINK)
7667 +               flags |= FS_IXUNLINK_FL;
7668         if (di_flags & XFS_DIFLAG_APPEND)
7669                 flags |= FS_APPEND_FL;
7670         if (di_flags & XFS_DIFLAG_SYNC)
7671 @@ -828,6 +833,8 @@ xfs_set_diflags(
7672         di_flags = (ip->i_d.di_flags & XFS_DIFLAG_PREALLOC);
7673         if (xflags & XFS_XFLAG_IMMUTABLE)
7674                 di_flags |= XFS_DIFLAG_IMMUTABLE;
7675 +       if (xflags & XFS_XFLAG_IXUNLINK)
7676 +               di_flags |= XFS_DIFLAG_IXUNLINK;
7677         if (xflags & XFS_XFLAG_APPEND)
7678                 di_flags |= XFS_DIFLAG_APPEND;
7679         if (xflags & XFS_XFLAG_SYNC)
7680 @@ -870,6 +877,10 @@ xfs_diflags_to_linux(
7681                 inode->i_flags |= S_IMMUTABLE;
7682         else
7683                 inode->i_flags &= ~S_IMMUTABLE;
7684 +       if (xflags & XFS_XFLAG_IXUNLINK)
7685 +               inode->i_flags |= S_IXUNLINK;
7686 +       else
7687 +               inode->i_flags &= ~S_IXUNLINK;
7688         if (xflags & XFS_XFLAG_APPEND)
7689                 inode->i_flags |= S_APPEND;
7690         else
7691 @@ -1346,10 +1357,18 @@ xfs_file_ioctl(
7692         case XFS_IOC_FSGETXATTRA:
7693                 return xfs_ioc_fsgetxattr(ip, 1, arg);
7694         case XFS_IOC_FSSETXATTR:
7695 +               if (IS_BARRIER(inode)) {
7696 +                       vxwprintk_task(1, "messing with the barrier.");
7697 +                       return -XFS_ERROR(EACCES);
7698 +               }
7699                 return xfs_ioc_fssetxattr(ip, filp, arg);
7700         case XFS_IOC_GETXFLAGS:
7701                 return xfs_ioc_getxflags(ip, arg);
7702         case XFS_IOC_SETXFLAGS:
7703 +               if (IS_BARRIER(inode)) {
7704 +                       vxwprintk_task(1, "messing with the barrier.");
7705 +                       return -XFS_ERROR(EACCES);
7706 +               }
7707                 return xfs_ioc_setxflags(ip, filp, arg);
7708  
7709         case XFS_IOC_FSSETDM: {
7710 diff -NurpP --minimal linux-2.6.32.1/fs/xfs/linux-2.6/xfs_ioctl.h linux-2.6.32.1-vs2.3.0.36.27/fs/xfs/linux-2.6/xfs_ioctl.h
7711 --- linux-2.6.32.1/fs/xfs/linux-2.6/xfs_ioctl.h 2009-03-24 14:22:37.000000000 +0100
7712 +++ linux-2.6.32.1-vs2.3.0.36.27/fs/xfs/linux-2.6/xfs_ioctl.h   2009-12-03 20:04:56.000000000 +0100
7713 @@ -70,6 +70,12 @@ xfs_handle_to_dentry(
7714         void __user             *uhandle,
7715         u32                     hlen);
7716  
7717 +extern int
7718 +xfs_sync_flags(
7719 +       struct inode            *inode,
7720 +       int                     flags,
7721 +       int                     vflags);
7722 +
7723  extern long
7724  xfs_file_ioctl(
7725         struct file             *filp,
7726 diff -NurpP --minimal linux-2.6.32.1/fs/xfs/linux-2.6/xfs_iops.c linux-2.6.32.1-vs2.3.0.36.27/fs/xfs/linux-2.6/xfs_iops.c
7727 --- linux-2.6.32.1/fs/xfs/linux-2.6/xfs_iops.c  2009-12-03 20:02:53.000000000 +0100
7728 +++ linux-2.6.32.1-vs2.3.0.36.27/fs/xfs/linux-2.6/xfs_iops.c    2009-12-03 20:04:56.000000000 +0100
7729 @@ -36,6 +36,7 @@
7730  #include "xfs_attr_sf.h"
7731  #include "xfs_dinode.h"
7732  #include "xfs_inode.h"
7733 +#include "xfs_ioctl.h"
7734  #include "xfs_bmap.h"
7735  #include "xfs_btree.h"
7736  #include "xfs_ialloc.h"
7737 @@ -55,6 +56,7 @@
7738  #include <linux/security.h>
7739  #include <linux/falloc.h>
7740  #include <linux/fiemap.h>
7741 +#include <linux/vs_tag.h>
7742  
7743  /*
7744   * Bring the timestamps in the XFS inode uptodate.
7745 @@ -495,6 +497,7 @@ xfs_vn_getattr(
7746         stat->nlink = ip->i_d.di_nlink;
7747         stat->uid = ip->i_d.di_uid;
7748         stat->gid = ip->i_d.di_gid;
7749 +       stat->tag = ip->i_d.di_tag;
7750         stat->ino = ip->i_ino;
7751         stat->atime = inode->i_atime;
7752         stat->mtime = inode->i_mtime;
7753 @@ -686,6 +689,7 @@ static const struct inode_operations xfs
7754         .listxattr              = xfs_vn_listxattr,
7755         .fallocate              = xfs_vn_fallocate,
7756         .fiemap                 = xfs_vn_fiemap,
7757 +       .sync_flags             = xfs_sync_flags,
7758  };
7759  
7760  static const struct inode_operations xfs_dir_inode_operations = {
7761 @@ -711,6 +715,7 @@ static const struct inode_operations xfs
7762         .getxattr               = generic_getxattr,
7763         .removexattr            = generic_removexattr,
7764         .listxattr              = xfs_vn_listxattr,
7765 +       .sync_flags             = xfs_sync_flags,
7766  };
7767  
7768  static const struct inode_operations xfs_dir_ci_inode_operations = {
7769 @@ -760,6 +765,10 @@ xfs_diflags_to_iflags(
7770                 inode->i_flags |= S_IMMUTABLE;
7771         else
7772                 inode->i_flags &= ~S_IMMUTABLE;
7773 +       if (ip->i_d.di_flags & XFS_DIFLAG_IXUNLINK)
7774 +               inode->i_flags |= S_IXUNLINK;
7775 +       else
7776 +               inode->i_flags &= ~S_IXUNLINK;
7777         if (ip->i_d.di_flags & XFS_DIFLAG_APPEND)
7778                 inode->i_flags |= S_APPEND;
7779         else
7780 @@ -772,6 +781,15 @@ xfs_diflags_to_iflags(
7781                 inode->i_flags |= S_NOATIME;
7782         else
7783                 inode->i_flags &= ~S_NOATIME;
7784 +
7785 +       if (ip->i_d.di_vflags & XFS_DIVFLAG_BARRIER)
7786 +               inode->i_vflags |= V_BARRIER;
7787 +       else
7788 +               inode->i_vflags &= ~V_BARRIER;
7789 +       if (ip->i_d.di_vflags & XFS_DIVFLAG_COW)
7790 +               inode->i_vflags |= V_COW;
7791 +       else
7792 +               inode->i_vflags &= ~V_COW;
7793  }
7794  
7795  /*
7796 @@ -800,6 +818,7 @@ xfs_setup_inode(
7797         inode->i_nlink  = ip->i_d.di_nlink;
7798         inode->i_uid    = ip->i_d.di_uid;
7799         inode->i_gid    = ip->i_d.di_gid;
7800 +       inode->i_tag    = ip->i_d.di_tag;
7801  
7802         switch (inode->i_mode & S_IFMT) {
7803         case S_IFBLK:
7804 diff -NurpP --minimal linux-2.6.32.1/fs/xfs/linux-2.6/xfs_linux.h linux-2.6.32.1-vs2.3.0.36.27/fs/xfs/linux-2.6/xfs_linux.h
7805 --- linux-2.6.32.1/fs/xfs/linux-2.6/xfs_linux.h 2009-09-10 15:26:24.000000000 +0200
7806 +++ linux-2.6.32.1-vs2.3.0.36.27/fs/xfs/linux-2.6/xfs_linux.h   2009-12-03 20:04:56.000000000 +0100
7807 @@ -119,6 +119,7 @@
7808  
7809  #define current_cpu()          (raw_smp_processor_id())
7810  #define current_pid()          (current->pid)
7811 +#define current_fstag(cred,vp) (dx_current_fstag((vp)->i_sb))
7812  #define current_test_flags(f)  (current->flags & (f))
7813  #define current_set_flags_nested(sp, f)                \
7814                 (*(sp) = current->flags, current->flags |= (f))
7815 diff -NurpP --minimal linux-2.6.32.1/fs/xfs/linux-2.6/xfs_super.c linux-2.6.32.1-vs2.3.0.36.27/fs/xfs/linux-2.6/xfs_super.c
7816 --- linux-2.6.32.1/fs/xfs/linux-2.6/xfs_super.c 2009-12-03 20:02:53.000000000 +0100
7817 +++ linux-2.6.32.1-vs2.3.0.36.27/fs/xfs/linux-2.6/xfs_super.c   2009-12-03 20:04:56.000000000 +0100
7818 @@ -117,6 +117,9 @@ mempool_t *xfs_ioend_pool;
7819  #define MNTOPT_DMAPI   "dmapi"         /* DMI enabled (DMAPI / XDSM) */
7820  #define MNTOPT_XDSM    "xdsm"          /* DMI enabled (DMAPI / XDSM) */
7821  #define MNTOPT_DMI     "dmi"           /* DMI enabled (DMAPI / XDSM) */
7822 +#define MNTOPT_TAGXID  "tagxid"        /* context tagging for inodes */
7823 +#define MNTOPT_TAGGED  "tag"           /* context tagging for inodes */
7824 +#define MNTOPT_NOTAGTAG        "notag"         /* do not use context tagging */
7825  
7826  /*
7827   * Table driven mount option parser.
7828 @@ -125,10 +128,14 @@ mempool_t *xfs_ioend_pool;
7829   * in the future, too.
7830   */
7831  enum {
7832 +       Opt_tag, Opt_notag,
7833         Opt_barrier, Opt_nobarrier, Opt_err
7834  };
7835  
7836  static const match_table_t tokens = {
7837 +       {Opt_tag, "tagxid"},
7838 +       {Opt_tag, "tag"},
7839 +       {Opt_notag, "notag"},
7840         {Opt_barrier, "barrier"},
7841         {Opt_nobarrier, "nobarrier"},
7842         {Opt_err, NULL}
7843 @@ -382,6 +389,19 @@ xfs_parseargs(
7844                 } else if (!strcmp(this_char, "irixsgid")) {
7845                         cmn_err(CE_WARN,
7846         "XFS: irixsgid is now a sysctl(2) variable, option is deprecated.");
7847 +#ifndef CONFIG_TAGGING_NONE
7848 +               } else if (!strcmp(this_char, MNTOPT_TAGGED)) {
7849 +                       mp->m_flags |= XFS_MOUNT_TAGGED;
7850 +               } else if (!strcmp(this_char, MNTOPT_NOTAGTAG)) {
7851 +                       mp->m_flags &= ~XFS_MOUNT_TAGGED;
7852 +               } else if (!strcmp(this_char, MNTOPT_TAGXID)) {
7853 +                       mp->m_flags |= XFS_MOUNT_TAGGED;
7854 +#endif
7855 +#ifdef CONFIG_PROPAGATE
7856 +               } else if (!strcmp(this_char, MNTOPT_TAGGED)) {
7857 +                       /* use value */
7858 +                       mp->m_flags |= XFS_MOUNT_TAGGED;
7859 +#endif
7860                 } else {
7861                         cmn_err(CE_WARN,
7862                                 "XFS: unknown mount option [%s].", this_char);
7863 @@ -1270,6 +1290,16 @@ xfs_fs_remount(
7864                 case Opt_nobarrier:
7865                         mp->m_flags &= ~XFS_MOUNT_BARRIER;
7866                         break;
7867 +               case Opt_tag:
7868 +                       if (!(sb->s_flags & MS_TAGGED)) {
7869 +                               printk(KERN_INFO
7870 +                                       "XFS: %s: tagging not permitted on remount.\n",
7871 +                                       sb->s_id);
7872 +                               return -EINVAL;
7873 +                       }
7874 +                       break;
7875 +               case Opt_notag:
7876 +                       break;
7877                 default:
7878                         /*
7879                          * Logically we would return an error here to prevent
7880 @@ -1477,6 +1507,9 @@ xfs_fs_fill_super(
7881  
7882         XFS_SEND_MOUNT(mp, DM_RIGHT_NULL, mtpt, mp->m_fsname);
7883  
7884 +       if (mp->m_flags & XFS_MOUNT_TAGGED)
7885 +               sb->s_flags |= MS_TAGGED;
7886 +
7887         sb->s_magic = XFS_SB_MAGIC;
7888         sb->s_blocksize = mp->m_sb.sb_blocksize;
7889         sb->s_blocksize_bits = ffs(sb->s_blocksize) - 1;
7890 diff -NurpP --minimal linux-2.6.32.1/fs/xfs/xfs_dinode.h linux-2.6.32.1-vs2.3.0.36.27/fs/xfs/xfs_dinode.h
7891 --- linux-2.6.32.1/fs/xfs/xfs_dinode.h  2009-06-11 17:13:09.000000000 +0200
7892 +++ linux-2.6.32.1-vs2.3.0.36.27/fs/xfs/xfs_dinode.h    2009-12-03 20:04:56.000000000 +0100
7893 @@ -50,7 +50,9 @@ typedef struct xfs_dinode {
7894         __be32          di_gid;         /* owner's group id */
7895         __be32          di_nlink;       /* number of links to file */
7896         __be16          di_projid;      /* owner's project id */
7897 -       __u8            di_pad[8];      /* unused, zeroed space */
7898 +       __be16          di_tag;         /* context tagging */
7899 +       __be16          di_vflags;      /* vserver specific flags */
7900 +       __u8            di_pad[4];      /* unused, zeroed space */
7901         __be16          di_flushiter;   /* incremented on flush */
7902         xfs_timestamp_t di_atime;       /* time last accessed */
7903         xfs_timestamp_t di_mtime;       /* time last modified */
7904 @@ -183,6 +185,8 @@ static inline void xfs_dinode_put_rdev(s
7905  #define XFS_DIFLAG_EXTSZINHERIT_BIT 12 /* inherit inode extent size */
7906  #define XFS_DIFLAG_NODEFRAG_BIT     13 /* do not reorganize/defragment */
7907  #define XFS_DIFLAG_FILESTREAM_BIT   14  /* use filestream allocator */
7908 +#define XFS_DIFLAG_IXUNLINK_BIT     15 /* Immutable inver on unlink */
7909 +
7910  #define XFS_DIFLAG_REALTIME      (1 << XFS_DIFLAG_REALTIME_BIT)
7911  #define XFS_DIFLAG_PREALLOC      (1 << XFS_DIFLAG_PREALLOC_BIT)
7912  #define XFS_DIFLAG_NEWRTBM       (1 << XFS_DIFLAG_NEWRTBM_BIT)
7913 @@ -198,6 +202,7 @@ static inline void xfs_dinode_put_rdev(s
7914  #define XFS_DIFLAG_EXTSZINHERIT  (1 << XFS_DIFLAG_EXTSZINHERIT_BIT)
7915  #define XFS_DIFLAG_NODEFRAG      (1 << XFS_DIFLAG_NODEFRAG_BIT)
7916  #define XFS_DIFLAG_FILESTREAM    (1 << XFS_DIFLAG_FILESTREAM_BIT)
7917 +#define XFS_DIFLAG_IXUNLINK      (1 << XFS_DIFLAG_IXUNLINK_BIT)
7918  
7919  #ifdef CONFIG_XFS_RT
7920  #define XFS_IS_REALTIME_INODE(ip) ((ip)->i_d.di_flags & XFS_DIFLAG_REALTIME)
7921 @@ -210,6 +215,10 @@ static inline void xfs_dinode_put_rdev(s
7922          XFS_DIFLAG_IMMUTABLE | XFS_DIFLAG_APPEND | XFS_DIFLAG_SYNC | \
7923          XFS_DIFLAG_NOATIME | XFS_DIFLAG_NODUMP | XFS_DIFLAG_RTINHERIT | \
7924          XFS_DIFLAG_PROJINHERIT | XFS_DIFLAG_NOSYMLINKS | XFS_DIFLAG_EXTSIZE | \
7925 -        XFS_DIFLAG_EXTSZINHERIT | XFS_DIFLAG_NODEFRAG | XFS_DIFLAG_FILESTREAM)
7926 +        XFS_DIFLAG_EXTSZINHERIT | XFS_DIFLAG_NODEFRAG | XFS_DIFLAG_FILESTREAM | \
7927 +        XFS_DIFLAG_IXUNLINK)
7928 +
7929 +#define XFS_DIVFLAG_BARRIER    0x01
7930 +#define XFS_DIVFLAG_COW                0x02
7931  
7932  #endif /* __XFS_DINODE_H__ */
7933 diff -NurpP --minimal linux-2.6.32.1/fs/xfs/xfs_fs.h linux-2.6.32.1-vs2.3.0.36.27/fs/xfs/xfs_fs.h
7934 --- linux-2.6.32.1/fs/xfs/xfs_fs.h      2009-12-03 20:02:53.000000000 +0100
7935 +++ linux-2.6.32.1-vs2.3.0.36.27/fs/xfs/xfs_fs.h        2009-12-03 20:04:56.000000000 +0100
7936 @@ -67,6 +67,9 @@ struct fsxattr {
7937  #define XFS_XFLAG_EXTSZINHERIT 0x00001000      /* inherit inode extent size */
7938  #define XFS_XFLAG_NODEFRAG     0x00002000      /* do not defragment */
7939  #define XFS_XFLAG_FILESTREAM   0x00004000      /* use filestream allocator */
7940 +#define XFS_XFLAG_IXUNLINK     0x00008000      /* immutable invert on unlink */
7941 +#define XFS_XFLAG_BARRIER      0x10000000      /* chroot() barrier */
7942 +#define XFS_XFLAG_COW          0x20000000      /* copy on write mark */
7943  #define XFS_XFLAG_HASATTR      0x80000000      /* no DIFLAG for this   */
7944  
7945  /*
7946 @@ -292,7 +295,8 @@ typedef struct xfs_bstat {
7947         __s32           bs_extents;     /* number of extents            */
7948         __u32           bs_gen;         /* generation count             */
7949         __u16           bs_projid;      /* project id                   */
7950 -       unsigned char   bs_pad[14];     /* pad space, unused            */
7951 +       __u16           bs_tag;         /* context tagging              */
7952 +       unsigned char   bs_pad[12];     /* pad space, unused            */
7953         __u32           bs_dmevmask;    /* DMIG event mask              */
7954         __u16           bs_dmstate;     /* DMIG state info              */
7955         __u16           bs_aextents;    /* attribute number of extents  */
7956 diff -NurpP --minimal linux-2.6.32.1/fs/xfs/xfs_ialloc.c linux-2.6.32.1-vs2.3.0.36.27/fs/xfs/xfs_ialloc.c
7957 --- linux-2.6.32.1/fs/xfs/xfs_ialloc.c  2009-12-03 20:02:53.000000000 +0100
7958 +++ linux-2.6.32.1-vs2.3.0.36.27/fs/xfs/xfs_ialloc.c    2009-12-03 20:04:56.000000000 +0100
7959 @@ -41,7 +41,6 @@
7960  #include "xfs_error.h"
7961  #include "xfs_bmap.h"
7962  
7963 -
7964  /*
7965   * Allocation group level functions.
7966   */
7967 diff -NurpP --minimal linux-2.6.32.1/fs/xfs/xfs_inode.c linux-2.6.32.1-vs2.3.0.36.27/fs/xfs/xfs_inode.c
7968 --- linux-2.6.32.1/fs/xfs/xfs_inode.c   2009-12-03 20:02:54.000000000 +0100
7969 +++ linux-2.6.32.1-vs2.3.0.36.27/fs/xfs/xfs_inode.c     2009-12-03 20:04:56.000000000 +0100
7970 @@ -249,6 +249,7 @@ xfs_inotobp(
7971         return 0;
7972  }
7973  
7974 +#include <linux/vs_tag.h>
7975  
7976  /*
7977   * This routine is called to map an inode to the buffer containing
7978 @@ -654,15 +655,25 @@ xfs_iformat_btree(
7979  STATIC void
7980  xfs_dinode_from_disk(
7981         xfs_icdinode_t          *to,
7982 -       xfs_dinode_t            *from)
7983 +       xfs_dinode_t            *from,
7984 +       int tagged)
7985  {
7986 +       uint32_t uid, gid, tag;
7987 +
7988         to->di_magic = be16_to_cpu(from->di_magic);
7989         to->di_mode = be16_to_cpu(from->di_mode);
7990         to->di_version = from ->di_version;
7991         to->di_format = from->di_format;
7992         to->di_onlink = be16_to_cpu(from->di_onlink);
7993 -       to->di_uid = be32_to_cpu(from->di_uid);
7994 -       to->di_gid = be32_to_cpu(from->di_gid);
7995 +
7996 +       uid = be32_to_cpu(from->di_uid);
7997 +       gid = be32_to_cpu(from->di_gid);
7998 +       tag = be16_to_cpu(from->di_tag);
7999 +
8000 +       to->di_uid = INOTAG_UID(tagged, uid, gid);
8001 +       to->di_gid = INOTAG_GID(tagged, uid, gid);
8002 +       to->di_tag = INOTAG_TAG(tagged, uid, gid, tag);
8003 +
8004         to->di_nlink = be32_to_cpu(from->di_nlink);
8005         to->di_projid = be16_to_cpu(from->di_projid);
8006         memcpy(to->di_pad, from->di_pad, sizeof(to->di_pad));
8007 @@ -683,21 +694,26 @@ xfs_dinode_from_disk(
8008         to->di_dmevmask = be32_to_cpu(from->di_dmevmask);
8009         to->di_dmstate  = be16_to_cpu(from->di_dmstate);
8010         to->di_flags    = be16_to_cpu(from->di_flags);
8011 +       to->di_vflags   = be16_to_cpu(from->di_vflags);
8012         to->di_gen      = be32_to_cpu(from->di_gen);
8013  }
8014  
8015  void
8016  xfs_dinode_to_disk(
8017         xfs_dinode_t            *to,
8018 -       xfs_icdinode_t          *from)
8019 +       xfs_icdinode_t          *from,
8020 +       int tagged)
8021  {
8022         to->di_magic = cpu_to_be16(from->di_magic);
8023         to->di_mode = cpu_to_be16(from->di_mode);
8024         to->di_version = from ->di_version;
8025         to->di_format = from->di_format;
8026         to->di_onlink = cpu_to_be16(from->di_onlink);
8027 -       to->di_uid = cpu_to_be32(from->di_uid);
8028 -       to->di_gid = cpu_to_be32(from->di_gid);
8029 +
8030 +       to->di_uid = cpu_to_be32(TAGINO_UID(tagged, from->di_uid, from->di_tag));
8031 +       to->di_gid = cpu_to_be32(TAGINO_GID(tagged, from->di_gid, from->di_tag));
8032 +       to->di_tag = cpu_to_be16(TAGINO_TAG(tagged, from->di_tag));
8033 +
8034         to->di_nlink = cpu_to_be32(from->di_nlink);
8035         to->di_projid = cpu_to_be16(from->di_projid);
8036         memcpy(to->di_pad, from->di_pad, sizeof(to->di_pad));
8037 @@ -718,12 +734,14 @@ xfs_dinode_to_disk(
8038         to->di_dmevmask = cpu_to_be32(from->di_dmevmask);
8039         to->di_dmstate = cpu_to_be16(from->di_dmstate);
8040         to->di_flags = cpu_to_be16(from->di_flags);
8041 +       to->di_vflags = cpu_to_be16(from->di_vflags);
8042         to->di_gen = cpu_to_be32(from->di_gen);
8043  }
8044  
8045  STATIC uint
8046  _xfs_dic2xflags(
8047 -       __uint16_t              di_flags)
8048 +       __uint16_t              di_flags,
8049 +       __uint16_t              di_vflags)
8050  {
8051         uint                    flags = 0;
8052  
8053 @@ -734,6 +752,8 @@ _xfs_dic2xflags(
8054                         flags |= XFS_XFLAG_PREALLOC;
8055                 if (di_flags & XFS_DIFLAG_IMMUTABLE)
8056                         flags |= XFS_XFLAG_IMMUTABLE;
8057 +               if (di_flags & XFS_DIFLAG_IXUNLINK)
8058 +                       flags |= XFS_XFLAG_IXUNLINK;
8059                 if (di_flags & XFS_DIFLAG_APPEND)
8060                         flags |= XFS_XFLAG_APPEND;
8061                 if (di_flags & XFS_DIFLAG_SYNC)
8062 @@ -758,6 +778,10 @@ _xfs_dic2xflags(
8063                         flags |= XFS_XFLAG_FILESTREAM;
8064         }
8065  
8066 +       if (di_vflags & XFS_DIVFLAG_BARRIER)
8067 +               flags |= FS_BARRIER_FL;
8068 +       if (di_vflags & XFS_DIVFLAG_COW)
8069 +               flags |= FS_COW_FL;
8070         return flags;
8071  }
8072  
8073 @@ -767,7 +791,7 @@ xfs_ip2xflags(
8074  {
8075         xfs_icdinode_t          *dic = &ip->i_d;
8076  
8077 -       return _xfs_dic2xflags(dic->di_flags) |
8078 +       return _xfs_dic2xflags(dic->di_flags, dic->di_vflags) |
8079                                 (XFS_IFORK_Q(ip) ? XFS_XFLAG_HASATTR : 0);
8080  }
8081  
8082 @@ -775,7 +799,8 @@ uint
8083  xfs_dic2xflags(
8084         xfs_dinode_t            *dip)
8085  {
8086 -       return _xfs_dic2xflags(be16_to_cpu(dip->di_flags)) |
8087 +       return _xfs_dic2xflags(be16_to_cpu(dip->di_flags),
8088 +                               be16_to_cpu(dip->di_vflags)) |
8089                                 (XFS_DFORK_Q(dip) ? XFS_XFLAG_HASATTR : 0);
8090  }
8091  
8092 @@ -811,7 +836,6 @@ xfs_iread(
8093         if (error)
8094                 return error;
8095         dip = (xfs_dinode_t *)xfs_buf_offset(bp, ip->i_imap.im_boffset);
8096 -
8097         /*
8098          * If we got something that isn't an inode it means someone
8099          * (nfs or dmi) has a stale handle.
8100 @@ -836,7 +860,8 @@ xfs_iread(
8101          * Otherwise, just get the truly permanent information.
8102          */
8103         if (dip->di_mode) {
8104 -               xfs_dinode_from_disk(&ip->i_d, dip);
8105 +               xfs_dinode_from_disk(&ip->i_d, dip,
8106 +                       mp->m_flags & XFS_MOUNT_TAGGED);
8107                 error = xfs_iformat(ip, dip);
8108                 if (error)  {
8109  #ifdef DEBUG
8110 @@ -1036,6 +1061,7 @@ xfs_ialloc(
8111         ASSERT(ip->i_d.di_nlink == nlink);
8112         ip->i_d.di_uid = current_fsuid();
8113         ip->i_d.di_gid = current_fsgid();
8114 +       ip->i_d.di_tag = current_fstag(cr, &ip->i_vnode);
8115         ip->i_d.di_projid = prid;
8116         memset(&(ip->i_d.di_pad[0]), 0, sizeof(ip->i_d.di_pad));
8117  
8118 @@ -1096,6 +1122,7 @@ xfs_ialloc(
8119         ip->i_d.di_dmevmask = 0;
8120         ip->i_d.di_dmstate = 0;
8121         ip->i_d.di_flags = 0;
8122 +       ip->i_d.di_vflags = 0;
8123         flags = XFS_ILOG_CORE;
8124         switch (mode & S_IFMT) {
8125         case S_IFIFO:
8126 @@ -2172,6 +2199,7 @@ xfs_ifree(
8127         }
8128         ip->i_d.di_mode = 0;            /* mark incore inode as free */
8129         ip->i_d.di_flags = 0;
8130 +       ip->i_d.di_vflags = 0;
8131         ip->i_d.di_dmevmask = 0;
8132         ip->i_d.di_forkoff = 0;         /* mark the attr fork not in use */
8133         ip->i_df.if_ext_max =
8134 @@ -3139,7 +3167,8 @@ xfs_iflush_int(
8135          * because if the inode is dirty at all the core must
8136          * be.
8137          */
8138 -       xfs_dinode_to_disk(dip, &ip->i_d);
8139 +       xfs_dinode_to_disk(dip, &ip->i_d,
8140 +               mp->m_flags & XFS_MOUNT_TAGGED);
8141  
8142         /* Wrap, we never let the log put out DI_MAX_FLUSH */
8143         if (ip->i_d.di_flushiter == DI_MAX_FLUSH)
8144 diff -NurpP --minimal linux-2.6.32.1/fs/xfs/xfs_inode.h linux-2.6.32.1-vs2.3.0.36.27/fs/xfs/xfs_inode.h
8145 --- linux-2.6.32.1/fs/xfs/xfs_inode.h   2009-12-03 20:02:54.000000000 +0100
8146 +++ linux-2.6.32.1-vs2.3.0.36.27/fs/xfs/xfs_inode.h     2009-12-03 20:04:56.000000000 +0100
8147 @@ -135,7 +135,9 @@ typedef struct xfs_icdinode {
8148         __uint32_t      di_gid;         /* owner's group id */
8149         __uint32_t      di_nlink;       /* number of links to file */
8150         __uint16_t      di_projid;      /* owner's project id */
8151 -       __uint8_t       di_pad[8];      /* unused, zeroed space */
8152 +       __uint16_t      di_tag;         /* context tagging */
8153 +       __uint16_t      di_vflags;      /* vserver specific flags */
8154 +       __uint8_t       di_pad[4];      /* unused, zeroed space */
8155         __uint16_t      di_flushiter;   /* incremented on flush */
8156         xfs_ictimestamp_t di_atime;     /* time last accessed */
8157         xfs_ictimestamp_t di_mtime;     /* time last modified */
8158 @@ -569,7 +571,7 @@ int         xfs_itobp(struct xfs_mount *, struc
8159  int            xfs_iread(struct xfs_mount *, struct xfs_trans *,
8160                           struct xfs_inode *, xfs_daddr_t, uint);
8161  void           xfs_dinode_to_disk(struct xfs_dinode *,
8162 -                                  struct xfs_icdinode *);
8163 +                                  struct xfs_icdinode *, int);
8164  void           xfs_idestroy_fork(struct xfs_inode *, int);
8165  void           xfs_idata_realloc(struct xfs_inode *, int, int);
8166  void           xfs_iroot_realloc(struct xfs_inode *, int, int);
8167 diff -NurpP --minimal linux-2.6.32.1/fs/xfs/xfs_itable.c linux-2.6.32.1-vs2.3.0.36.27/fs/xfs/xfs_itable.c
8168 --- linux-2.6.32.1/fs/xfs/xfs_itable.c  2009-12-03 20:02:54.000000000 +0100
8169 +++ linux-2.6.32.1-vs2.3.0.36.27/fs/xfs/xfs_itable.c    2009-12-03 20:04:56.000000000 +0100
8170 @@ -84,6 +84,7 @@ xfs_bulkstat_one_iget(
8171         buf->bs_mode = dic->di_mode;
8172         buf->bs_uid = dic->di_uid;
8173         buf->bs_gid = dic->di_gid;
8174 +       buf->bs_tag = dic->di_tag;
8175         buf->bs_size = dic->di_size;
8176  
8177         /*
8178 diff -NurpP --minimal linux-2.6.32.1/fs/xfs/xfs_log_recover.c linux-2.6.32.1-vs2.3.0.36.27/fs/xfs/xfs_log_recover.c
8179 --- linux-2.6.32.1/fs/xfs/xfs_log_recover.c     2009-12-03 20:02:54.000000000 +0100
8180 +++ linux-2.6.32.1-vs2.3.0.36.27/fs/xfs/xfs_log_recover.c       2009-12-03 20:04:56.000000000 +0100
8181 @@ -2467,7 +2467,8 @@ xlog_recover_do_inode_trans(
8182         }
8183  
8184         /* The core is in in-core format */
8185 -       xfs_dinode_to_disk(dip, (xfs_icdinode_t *)item->ri_buf[1].i_addr);
8186 +       xfs_dinode_to_disk(dip, (xfs_icdinode_t *)item->ri_buf[1].i_addr,
8187 +               mp->m_flags & XFS_MOUNT_TAGGED);
8188  
8189         /* the rest is in on-disk format */
8190         if (item->ri_buf[1].i_len > sizeof(struct xfs_icdinode)) {
8191 diff -NurpP --minimal linux-2.6.32.1/fs/xfs/xfs_mount.h linux-2.6.32.1-vs2.3.0.36.27/fs/xfs/xfs_mount.h
8192 --- linux-2.6.32.1/fs/xfs/xfs_mount.h   2009-12-03 20:02:54.000000000 +0100
8193 +++ linux-2.6.32.1-vs2.3.0.36.27/fs/xfs/xfs_mount.h     2009-12-03 20:04:56.000000000 +0100
8194 @@ -283,6 +283,7 @@ typedef struct xfs_mount {
8195                                                    allocator */
8196  #define XFS_MOUNT_NOATTR2      (1ULL << 25)    /* disable use of attr2 format */
8197  
8198 +#define XFS_MOUNT_TAGGED       (1ULL << 31)    /* context tagging */
8199  
8200  /*
8201   * Default minimum read and write sizes.
8202 diff -NurpP --minimal linux-2.6.32.1/fs/xfs/xfs_vnodeops.c linux-2.6.32.1-vs2.3.0.36.27/fs/xfs/xfs_vnodeops.c
8203 --- linux-2.6.32.1/fs/xfs/xfs_vnodeops.c        2009-12-03 20:02:54.000000000 +0100
8204 +++ linux-2.6.32.1-vs2.3.0.36.27/fs/xfs/xfs_vnodeops.c  2009-12-03 20:04:56.000000000 +0100
8205 @@ -54,6 +54,80 @@
8206  #include "xfs_filestream.h"
8207  #include "xfs_vnodeops.h"
8208  
8209 +
8210 +STATIC void
8211 +xfs_get_inode_flags(
8212 +       xfs_inode_t     *ip)
8213 +{
8214 +       struct inode    *inode = VFS_I(ip);
8215 +       unsigned int    flags = inode->i_flags;
8216 +       unsigned int    vflags = inode->i_vflags;
8217 +
8218 +       if (flags & S_IMMUTABLE)
8219 +               ip->i_d.di_flags |= XFS_DIFLAG_IMMUTABLE;
8220 +       else
8221 +               ip->i_d.di_flags &= ~XFS_DIFLAG_IMMUTABLE;
8222 +       if (flags & S_IXUNLINK)
8223 +               ip->i_d.di_flags |= XFS_DIFLAG_IXUNLINK;
8224 +       else
8225 +               ip->i_d.di_flags &= ~XFS_DIFLAG_IXUNLINK;
8226 +
8227 +       if (vflags & V_BARRIER)
8228 +               ip->i_d.di_vflags |= XFS_DIVFLAG_BARRIER;
8229 +       else
8230 +               ip->i_d.di_vflags &= ~XFS_DIVFLAG_BARRIER;
8231 +       if (vflags & V_COW)
8232 +               ip->i_d.di_vflags |= XFS_DIVFLAG_COW;
8233 +       else
8234 +               ip->i_d.di_vflags &= ~XFS_DIVFLAG_COW;
8235 +}
8236 +
8237 +int
8238 +xfs_sync_flags(
8239 +       struct inode            *inode,
8240 +       int                     flags,
8241 +       int                     vflags)
8242 +{
8243 +       struct xfs_inode        *ip = XFS_I(inode);
8244 +       struct xfs_mount        *mp = ip->i_mount;
8245 +       struct xfs_trans        *tp;
8246 +       unsigned int            lock_flags = 0;
8247 +       int                     code;
8248 +
8249 +       tp = xfs_trans_alloc(mp, XFS_TRANS_SETATTR_NOT_SIZE);
8250 +       code = xfs_trans_reserve(tp, 0, XFS_ICHANGE_LOG_RES(mp), 0, 0, 0);
8251 +       if (code)
8252 +               goto error_out;
8253 +
8254 +       lock_flags = XFS_ILOCK_EXCL;
8255 +       xfs_ilock(ip, lock_flags);
8256 +
8257 +       xfs_trans_ijoin(tp, ip, lock_flags);
8258 +       xfs_trans_ihold(tp, ip);
8259 +
8260 +       inode->i_flags = flags;
8261 +       inode->i_vflags = vflags;
8262 +       xfs_get_inode_flags(ip);
8263 +
8264 +       xfs_trans_log_inode(tp, ip, XFS_ILOG_CORE);
8265 +       xfs_ichgtime(ip, XFS_ICHGTIME_CHG);
8266 +
8267 +       XFS_STATS_INC(xs_ig_attrchg);
8268 +
8269 +       if (mp->m_flags & XFS_MOUNT_WSYNC)
8270 +               xfs_trans_set_sync(tp);
8271 +       code = xfs_trans_commit(tp, 0);
8272 +       xfs_iunlock(ip, lock_flags);
8273 +       return code;
8274 +
8275 +error_out:
8276 +       xfs_trans_cancel(tp, 0);
8277 +       if (lock_flags)
8278 +               xfs_iunlock(ip, lock_flags);
8279 +       return code;
8280 +}
8281 +
8282 +
8283  int
8284  xfs_setattr(
8285         struct xfs_inode        *ip,
8286 @@ -69,6 +143,7 @@ xfs_setattr(
8287         uint                    commit_flags=0;
8288         uid_t                   uid=0, iuid=0;
8289         gid_t                   gid=0, igid=0;
8290 +       tag_t                   tag=0, itag=0;
8291         int                     timeflags = 0;
8292         struct xfs_dquot        *udqp, *gdqp, *olddquot1, *olddquot2;
8293         int                     need_iolock = 1;
8294 @@ -165,7 +240,7 @@ xfs_setattr(
8295         /*
8296          * Change file ownership.  Must be the owner or privileged.
8297          */
8298 -       if (mask & (ATTR_UID|ATTR_GID)) {
8299 +       if (mask & (ATTR_UID|ATTR_GID|ATTR_TAG)) {
8300                 /*
8301                  * These IDs could have changed since we last looked at them.
8302                  * But, we're assured that if the ownership did change
8303 @@ -174,8 +249,10 @@ xfs_setattr(
8304                  */
8305                 iuid = ip->i_d.di_uid;
8306                 igid = ip->i_d.di_gid;
8307 +               itag = ip->i_d.di_tag;
8308                 gid = (mask & ATTR_GID) ? iattr->ia_gid : igid;
8309                 uid = (mask & ATTR_UID) ? iattr->ia_uid : iuid;
8310 +               tag = (mask & ATTR_TAG) ? iattr->ia_tag : itag;
8311  
8312                 /*
8313                  * Do a quota reservation only if uid/gid is actually
8314 @@ -183,7 +260,8 @@ xfs_setattr(
8315                  */
8316                 if (XFS_IS_QUOTA_RUNNING(mp) &&
8317                     ((XFS_IS_UQUOTA_ON(mp) && iuid != uid) ||
8318 -                    (XFS_IS_GQUOTA_ON(mp) && igid != gid))) {
8319 +                    (XFS_IS_GQUOTA_ON(mp) && igid != gid) ||
8320 +                    (XFS_IS_GQUOTA_ON(mp) && itag != tag))) {
8321                         ASSERT(tp);
8322                         code = xfs_qm_vop_chown_reserve(tp, ip, udqp, gdqp,
8323                                                 capable(CAP_FOWNER) ?
8324 @@ -336,7 +414,7 @@ xfs_setattr(
8325         /*
8326          * Change file ownership.  Must be the owner or privileged.
8327          */
8328 -       if (mask & (ATTR_UID|ATTR_GID)) {
8329 +       if (mask & (ATTR_UID|ATTR_GID|ATTR_TAG)) {
8330                 /*
8331                  * CAP_FSETID overrides the following restrictions:
8332                  *
8333 @@ -352,6 +430,10 @@ xfs_setattr(
8334                  * Change the ownerships and register quota modifications
8335                  * in the transaction.
8336                  */
8337 +               if (itag != tag) {
8338 +                       ip->i_d.di_tag = tag;
8339 +                       inode->i_tag = tag;
8340 +               }
8341                 if (iuid != uid) {
8342                         if (XFS_IS_QUOTA_RUNNING(mp) && XFS_IS_UQUOTA_ON(mp)) {
8343                                 ASSERT(mask & ATTR_UID);
8344 diff -NurpP --minimal linux-2.6.32.1/fs/xfs/xfs_vnodeops.h linux-2.6.32.1-vs2.3.0.36.27/fs/xfs/xfs_vnodeops.h
8345 --- linux-2.6.32.1/fs/xfs/xfs_vnodeops.h        2009-09-10 15:26:24.000000000 +0200
8346 +++ linux-2.6.32.1-vs2.3.0.36.27/fs/xfs/xfs_vnodeops.h  2009-12-03 20:04:56.000000000 +0100
8347 @@ -14,6 +14,7 @@ struct xfs_inode;
8348  struct xfs_iomap;
8349  
8350  
8351 +int xfs_sync_xflags(struct xfs_inode *ip);
8352  int xfs_setattr(struct xfs_inode *ip, struct iattr *vap, int flags);
8353  #define        XFS_ATTR_DMI            0x01    /* invocation from a DMI function */
8354  #define        XFS_ATTR_NONBLOCK       0x02    /* return EAGAIN if operation would block */
8355 diff -NurpP --minimal linux-2.6.32.1/include/asm-generic/tlb.h linux-2.6.32.1-vs2.3.0.36.27/include/asm-generic/tlb.h
8356 --- linux-2.6.32.1/include/asm-generic/tlb.h    2009-09-10 15:26:24.000000000 +0200
8357 +++ linux-2.6.32.1-vs2.3.0.36.27/include/asm-generic/tlb.h      2009-12-03 20:04:56.000000000 +0100
8358 @@ -14,6 +14,7 @@
8359  #define _ASM_GENERIC__TLB_H
8360  
8361  #include <linux/swap.h>
8362 +#include <linux/vs_memory.h>
8363  #include <asm/pgalloc.h>
8364  #include <asm/tlbflush.h>
8365  
8366 diff -NurpP --minimal linux-2.6.32.1/include/linux/capability.h linux-2.6.32.1-vs2.3.0.36.27/include/linux/capability.h
8367 --- linux-2.6.32.1/include/linux/capability.h   2009-12-03 20:02:54.000000000 +0100
8368 +++ linux-2.6.32.1-vs2.3.0.36.27/include/linux/capability.h     2009-12-03 20:04:56.000000000 +0100
8369 @@ -285,6 +285,7 @@ struct cpu_vfs_cap_data {
8370     arbitrary SCSI commands */
8371  /* Allow setting encryption key on loopback filesystem */
8372  /* Allow setting zone reclaim policy */
8373 +/* Allow the selection of a security context */
8374  
8375  #define CAP_SYS_ADMIN        21
8376  
8377 @@ -357,7 +358,13 @@ struct cpu_vfs_cap_data {
8378  
8379  #define CAP_MAC_ADMIN        33
8380  
8381 -#define CAP_LAST_CAP         CAP_MAC_ADMIN
8382 +/* Allow context manipulations */
8383 +/* Allow changing context info on files */
8384 +
8385 +#define CAP_CONTEXT         34
8386 +
8387 +
8388 +#define CAP_LAST_CAP         CAP_CONTEXT
8389  
8390  #define cap_valid(x) ((x) >= 0 && (x) <= CAP_LAST_CAP)
8391  
8392 diff -NurpP --minimal linux-2.6.32.1/include/linux/devpts_fs.h linux-2.6.32.1-vs2.3.0.36.27/include/linux/devpts_fs.h
8393 --- linux-2.6.32.1/include/linux/devpts_fs.h    2008-12-25 00:26:37.000000000 +0100
8394 +++ linux-2.6.32.1-vs2.3.0.36.27/include/linux/devpts_fs.h      2009-12-03 20:04:56.000000000 +0100
8395 @@ -45,5 +45,4 @@ static inline void devpts_pty_kill(struc
8396  
8397  #endif
8398  
8399 -
8400  #endif /* _LINUX_DEVPTS_FS_H */
8401 diff -NurpP --minimal linux-2.6.32.1/include/linux/ext2_fs.h linux-2.6.32.1-vs2.3.0.36.27/include/linux/ext2_fs.h
8402 --- linux-2.6.32.1/include/linux/ext2_fs.h      2009-03-24 14:22:41.000000000 +0100
8403 +++ linux-2.6.32.1-vs2.3.0.36.27/include/linux/ext2_fs.h        2009-12-03 20:04:56.000000000 +0100
8404 @@ -189,8 +189,12 @@ struct ext2_group_desc
8405  #define EXT2_NOTAIL_FL                 FS_NOTAIL_FL    /* file tail should not be merged */
8406  #define EXT2_DIRSYNC_FL                        FS_DIRSYNC_FL   /* dirsync behaviour (directories only) */
8407  #define EXT2_TOPDIR_FL                 FS_TOPDIR_FL    /* Top of directory hierarchies*/
8408 +#define EXT2_IXUNLINK_FL               FS_IXUNLINK_FL  /* Immutable invert on unlink */
8409  #define EXT2_RESERVED_FL               FS_RESERVED_FL  /* reserved for ext2 lib */
8410  
8411 +#define EXT2_BARRIER_FL                        FS_BARRIER_FL   /* Barrier for chroot() */
8412 +#define EXT2_COW_FL                    FS_COW_FL       /* Copy on Write marker */
8413 +
8414  #define EXT2_FL_USER_VISIBLE           FS_FL_USER_VISIBLE      /* User visible flags */
8415  #define EXT2_FL_USER_MODIFIABLE                FS_FL_USER_MODIFIABLE   /* User modifiable flags */
8416  
8417 @@ -274,7 +278,8 @@ struct ext2_inode {
8418                         __u16   i_pad1;
8419                         __le16  l_i_uid_high;   /* these 2 fields    */
8420                         __le16  l_i_gid_high;   /* were reserved2[0] */
8421 -                       __u32   l_i_reserved2;
8422 +                       __le16  l_i_tag;        /* Context Tag */
8423 +                       __u16   l_i_reserved2;
8424                 } linux2;
8425                 struct {
8426                         __u8    h_i_frag;       /* Fragment number */
8427 @@ -303,6 +308,7 @@ struct ext2_inode {
8428  #define i_gid_low      i_gid
8429  #define i_uid_high     osd2.linux2.l_i_uid_high
8430  #define i_gid_high     osd2.linux2.l_i_gid_high
8431 +#define i_raw_tag      osd2.linux2.l_i_tag
8432  #define i_reserved2    osd2.linux2.l_i_reserved2
8433  #endif
8434  
8435 @@ -347,6 +353,7 @@ struct ext2_inode {
8436  #define EXT2_MOUNT_USRQUOTA            0x020000  /* user quota */
8437  #define EXT2_MOUNT_GRPQUOTA            0x040000  /* group quota */
8438  #define EXT2_MOUNT_RESERVATION         0x080000  /* Preallocation */
8439 +#define EXT2_MOUNT_TAGGED              (1<<24)   /* Enable Context Tags */
8440  
8441  
8442  #define clear_opt(o, opt)              o &= ~EXT2_MOUNT_##opt
8443 diff -NurpP --minimal linux-2.6.32.1/include/linux/ext3_fs.h linux-2.6.32.1-vs2.3.0.36.27/include/linux/ext3_fs.h
8444 --- linux-2.6.32.1/include/linux/ext3_fs.h      2009-09-10 15:26:25.000000000 +0200
8445 +++ linux-2.6.32.1-vs2.3.0.36.27/include/linux/ext3_fs.h        2009-12-03 20:04:56.000000000 +0100
8446 @@ -173,10 +173,14 @@ struct ext3_group_desc
8447  #define EXT3_NOTAIL_FL                 0x00008000 /* file tail should not be merged */
8448  #define EXT3_DIRSYNC_FL                        0x00010000 /* dirsync behaviour (directories only) */
8449  #define EXT3_TOPDIR_FL                 0x00020000 /* Top of directory hierarchies*/
8450 +#define EXT3_IXUNLINK_FL               0x08000000 /* Immutable invert on unlink */
8451  #define EXT3_RESERVED_FL               0x80000000 /* reserved for ext3 lib */
8452  
8453 -#define EXT3_FL_USER_VISIBLE           0x0003DFFF /* User visible flags */
8454 -#define EXT3_FL_USER_MODIFIABLE                0x000380FF /* User modifiable flags */
8455 +#define EXT3_BARRIER_FL                        0x04000000 /* Barrier for chroot() */
8456 +#define EXT3_COW_FL                    0x20000000 /* Copy on Write marker */
8457 +
8458 +#define EXT3_FL_USER_VISIBLE           0x0103DFFF /* User visible flags */
8459 +#define EXT3_FL_USER_MODIFIABLE                0x010380FF /* User modifiable flags */
8460  
8461  /* Flags that should be inherited by new inodes from their parent. */
8462  #define EXT3_FL_INHERITED (EXT3_SECRM_FL | EXT3_UNRM_FL | EXT3_COMPR_FL |\
8463 @@ -320,7 +324,8 @@ struct ext3_inode {
8464                         __u16   i_pad1;
8465                         __le16  l_i_uid_high;   /* these 2 fields    */
8466                         __le16  l_i_gid_high;   /* were reserved2[0] */
8467 -                       __u32   l_i_reserved2;
8468 +                       __le16  l_i_tag;        /* Context Tag */
8469 +                       __u16   l_i_reserved2;
8470                 } linux2;
8471                 struct {
8472                         __u8    h_i_frag;       /* Fragment number */
8473 @@ -351,6 +356,7 @@ struct ext3_inode {
8474  #define i_gid_low      i_gid
8475  #define i_uid_high     osd2.linux2.l_i_uid_high
8476  #define i_gid_high     osd2.linux2.l_i_gid_high
8477 +#define i_raw_tag      osd2.linux2.l_i_tag
8478  #define i_reserved2    osd2.linux2.l_i_reserved2
8479  
8480  #elif defined(__GNU__)
8481 @@ -414,6 +420,7 @@ struct ext3_inode {
8482  #define EXT3_MOUNT_GRPQUOTA            0x200000 /* "old" group quota */
8483  #define EXT3_MOUNT_DATA_ERR_ABORT      0x400000 /* Abort on file data write
8484                                                   * error in ordered mode */
8485 +#define EXT3_MOUNT_TAGGED              (1<<24) /* Enable Context Tags */
8486  
8487  /* Compatibility, for having both ext2_fs.h and ext3_fs.h included at once */
8488  #ifndef _LINUX_EXT2_FS_H
8489 @@ -892,6 +899,7 @@ extern void ext3_get_inode_flags(struct 
8490  extern void ext3_set_aops(struct inode *inode);
8491  extern int ext3_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo,
8492                        u64 start, u64 len);
8493 +extern int ext3_sync_flags(struct inode *, int, int);
8494  
8495  /* ioctl.c */
8496  extern long ext3_ioctl(struct file *, unsigned int, unsigned long);
8497 diff -NurpP --minimal linux-2.6.32.1/include/linux/fs.h linux-2.6.32.1-vs2.3.0.36.27/include/linux/fs.h
8498 --- linux-2.6.32.1/include/linux/fs.h   2009-12-03 20:02:55.000000000 +0100
8499 +++ linux-2.6.32.1-vs2.3.0.36.27/include/linux/fs.h     2009-12-03 20:04:56.000000000 +0100
8500 @@ -205,6 +205,9 @@ struct inodes_stat_t {
8501  #define MS_KERNMOUNT   (1<<22) /* this is a kern_mount call */
8502  #define MS_I_VERSION   (1<<23) /* Update inode I_version field */
8503  #define MS_STRICTATIME (1<<24) /* Always perform atime updates */
8504 +#define MS_TAGGED      (1<<25) /* use generic inode tagging */
8505 +#define MS_TAGID       (1<<26) /* use specific tag for this mount */
8506 +#define MS_NOTAGCHECK  (1<<27) /* don't check tags */
8507  #define MS_ACTIVE      (1<<30)
8508  #define MS_NOUSER      (1<<31)
8509  
8510 @@ -231,6 +234,14 @@ struct inodes_stat_t {
8511  #define S_NOCMTIME     128     /* Do not update file c/mtime */
8512  #define S_SWAPFILE     256     /* Do not truncate: swapon got its bmaps */
8513  #define S_PRIVATE      512     /* Inode is fs-internal */
8514 +#define S_IXUNLINK     1024    /* Immutable Invert on unlink */
8515 +
8516 +/* Linux-VServer related Inode flags */
8517 +
8518 +#define V_VALID                1
8519 +#define V_XATTR                2
8520 +#define V_BARRIER      4       /* Barrier for chroot() */
8521 +#define V_COW          8       /* Copy on Write */
8522  
8523  /*
8524   * Note that nosuid etc flags are inode-specific: setting some file-system
8525 @@ -253,12 +264,15 @@ struct inodes_stat_t {
8526  #define IS_DIRSYNC(inode)      (__IS_FLG(inode, MS_SYNCHRONOUS|MS_DIRSYNC) || \
8527                                         ((inode)->i_flags & (S_SYNC|S_DIRSYNC)))
8528  #define IS_MANDLOCK(inode)     __IS_FLG(inode, MS_MANDLOCK)
8529 -#define IS_NOATIME(inode)   __IS_FLG(inode, MS_RDONLY|MS_NOATIME)
8530 -#define IS_I_VERSION(inode)   __IS_FLG(inode, MS_I_VERSION)
8531 +#define IS_NOATIME(inode)      __IS_FLG(inode, MS_RDONLY|MS_NOATIME)
8532 +#define IS_I_VERSION(inode)    __IS_FLG(inode, MS_I_VERSION)
8533 +#define IS_TAGGED(inode)       __IS_FLG(inode, MS_TAGGED)
8534  
8535  #define IS_NOQUOTA(inode)      ((inode)->i_flags & S_NOQUOTA)
8536  #define IS_APPEND(inode)       ((inode)->i_flags & S_APPEND)
8537  #define IS_IMMUTABLE(inode)    ((inode)->i_flags & S_IMMUTABLE)
8538 +#define IS_IXUNLINK(inode)     ((inode)->i_flags & S_IXUNLINK)
8539 +#define IS_IXORUNLINK(inode)   ((IS_IXUNLINK(inode) ? S_IMMUTABLE : 0) ^ IS_IMMUTABLE(inode))
8540  #define IS_POSIXACL(inode)     __IS_FLG(inode, MS_POSIXACL)
8541  
8542  #define IS_DEADDIR(inode)      ((inode)->i_flags & S_DEAD)
8543 @@ -266,6 +280,16 @@ struct inodes_stat_t {
8544  #define IS_SWAPFILE(inode)     ((inode)->i_flags & S_SWAPFILE)
8545  #define IS_PRIVATE(inode)      ((inode)->i_flags & S_PRIVATE)
8546  
8547 +#define IS_BARRIER(inode)      (S_ISDIR((inode)->i_mode) && ((inode)->i_vflags & V_BARRIER))
8548 +
8549 +#ifdef CONFIG_VSERVER_COWBL
8550 +#  define IS_COW(inode)                (IS_IXUNLINK(inode) && IS_IMMUTABLE(inode))
8551 +#  define IS_COW_LINK(inode)   (S_ISREG((inode)->i_mode) && ((inode)->i_nlink > 1))
8552 +#else
8553 +#  define IS_COW(inode)                (0)
8554 +#  define IS_COW_LINK(inode)   (0)
8555 +#endif
8556 +
8557  /* the read-only stuff doesn't really belong here, but any other place is
8558     probably as bad and I don't want to create yet another include file. */
8559  
8560 @@ -347,11 +371,14 @@ struct inodes_stat_t {
8561  #define FS_TOPDIR_FL                   0x00020000 /* Top of directory hierarchies*/
8562  #define FS_EXTENT_FL                   0x00080000 /* Extents */
8563  #define FS_DIRECTIO_FL                 0x00100000 /* Use direct i/o */
8564 +#define FS_IXUNLINK_FL                 0x08000000 /* Immutable invert on unlink */
8565  #define FS_RESERVED_FL                 0x80000000 /* reserved for ext2 lib */
8566  
8567 -#define FS_FL_USER_VISIBLE             0x0003DFFF /* User visible flags */
8568 -#define FS_FL_USER_MODIFIABLE          0x000380FF /* User modifiable flags */
8569 +#define FS_BARRIER_FL                  0x04000000 /* Barrier for chroot() */
8570 +#define FS_COW_FL                      0x20000000 /* Copy on Write marker */
8571  
8572 +#define FS_FL_USER_VISIBLE             0x0103DFFF /* User visible flags */
8573 +#define FS_FL_USER_MODIFIABLE          0x010380FF /* User modifiable flags */
8574  
8575  #define SYNC_FILE_RANGE_WAIT_BEFORE    1
8576  #define SYNC_FILE_RANGE_WRITE          2
8577 @@ -433,6 +460,7 @@ typedef void (dio_iodone_t)(struct kiocb
8578  #define ATTR_KILL_PRIV (1 << 14)
8579  #define ATTR_OPEN      (1 << 15) /* Truncating from open(O_TRUNC) */
8580  #define ATTR_TIMES_SET (1 << 16)
8581 +#define ATTR_TAG       (1 << 17)
8582  
8583  /*
8584   * This is the Inode Attributes structure, used for notify_change().  It
8585 @@ -448,6 +476,7 @@ struct iattr {
8586         umode_t         ia_mode;
8587         uid_t           ia_uid;
8588         gid_t           ia_gid;
8589 +       tag_t           ia_tag;
8590         loff_t          ia_size;
8591         struct timespec ia_atime;
8592         struct timespec ia_mtime;
8593 @@ -461,6 +490,9 @@ struct iattr {
8594         struct file     *ia_file;
8595  };
8596  
8597 +#define ATTR_FLAG_BARRIER      512     /* Barrier for chroot() */
8598 +#define ATTR_FLAG_IXUNLINK     1024    /* Immutable invert on unlink */
8599 +
8600  /*
8601   * Includes for diskquotas.
8602   */
8603 @@ -726,7 +758,9 @@ struct inode {
8604         unsigned int            i_nlink;
8605         uid_t                   i_uid;
8606         gid_t                   i_gid;
8607 +       tag_t                   i_tag;
8608         dev_t                   i_rdev;
8609 +       dev_t                   i_mdev;
8610         u64                     i_version;
8611         loff_t                  i_size;
8612  #ifdef __NEED_I_SIZE_ORDERED
8613 @@ -773,7 +807,8 @@ struct inode {
8614         unsigned long           i_state;
8615         unsigned long           dirtied_when;   /* jiffies of first dirtying */
8616  
8617 -       unsigned int            i_flags;
8618 +       unsigned short          i_flags;
8619 +       unsigned short          i_vflags;
8620  
8621         atomic_t                i_writecount;
8622  #ifdef CONFIG_SECURITY
8623 @@ -861,12 +896,12 @@ static inline void i_size_write(struct i
8624  
8625  static inline unsigned iminor(const struct inode *inode)
8626  {
8627 -       return MINOR(inode->i_rdev);
8628 +       return MINOR(inode->i_mdev);
8629  }
8630  
8631  static inline unsigned imajor(const struct inode *inode)
8632  {
8633 -       return MAJOR(inode->i_rdev);
8634 +       return MAJOR(inode->i_mdev);
8635  }
8636  
8637  extern struct block_device *I_BDEV(struct inode *inode);
8638 @@ -925,6 +960,7 @@ struct file {
8639         loff_t                  f_pos;
8640         struct fown_struct      f_owner;
8641         const struct cred       *f_cred;
8642 +       xid_t                   f_xid;
8643         struct file_ra_state    f_ra;
8644  
8645         u64                     f_version;
8646 @@ -1066,6 +1102,7 @@ struct file_lock {
8647         struct file *fl_file;
8648         loff_t fl_start;
8649         loff_t fl_end;
8650 +       xid_t fl_xid;
8651  
8652         struct fasync_struct *  fl_fasync; /* for lease break notifications */
8653         unsigned long fl_break_time;    /* for nonblocking lease breaks */
8654 @@ -1531,6 +1568,7 @@ struct inode_operations {
8655         ssize_t (*getxattr) (struct dentry *, const char *, void *, size_t);
8656         ssize_t (*listxattr) (struct dentry *, char *, size_t);
8657         int (*removexattr) (struct dentry *, const char *);
8658 +       int (*sync_flags) (struct inode *, int, int);
8659         void (*truncate_range)(struct inode *, loff_t, loff_t);
8660         long (*fallocate)(struct inode *inode, int mode, loff_t offset,
8661                           loff_t len);
8662 @@ -1551,6 +1589,7 @@ extern ssize_t vfs_readv(struct file *, 
8663                 unsigned long, loff_t *);
8664  extern ssize_t vfs_writev(struct file *, const struct iovec __user *,
8665                 unsigned long, loff_t *);
8666 +ssize_t vfs_sendfile(struct file *, struct file *, loff_t *, size_t, loff_t);
8667  
8668  struct super_operations {
8669         struct inode *(*alloc_inode)(struct super_block *sb);
8670 @@ -2347,6 +2386,7 @@ extern int dcache_dir_open(struct inode 
8671  extern int dcache_dir_close(struct inode *, struct file *);
8672  extern loff_t dcache_dir_lseek(struct file *, loff_t, int);
8673  extern int dcache_readdir(struct file *, void *, filldir_t);
8674 +extern int dcache_readdir_filter(struct file *, void *, filldir_t, int (*)(struct dentry *));
8675  extern int simple_getattr(struct vfsmount *, struct dentry *, struct kstat *);
8676  extern int simple_statfs(struct dentry *, struct kstatfs *);
8677  extern int simple_link(struct dentry *, struct inode *, struct dentry *);
8678 diff -NurpP --minimal linux-2.6.32.1/include/linux/gfs2_ondisk.h linux-2.6.32.1-vs2.3.0.36.27/include/linux/gfs2_ondisk.h
8679 --- linux-2.6.32.1/include/linux/gfs2_ondisk.h  2009-12-03 20:02:55.000000000 +0100
8680 +++ linux-2.6.32.1-vs2.3.0.36.27/include/linux/gfs2_ondisk.h    2009-12-03 20:04:56.000000000 +0100
8681 @@ -235,6 +235,9 @@ enum {
8682         gfs2fl_NoAtime          = 7,
8683         gfs2fl_Sync             = 8,
8684         gfs2fl_System           = 9,
8685 +       gfs2fl_IXUnlink         = 16,
8686 +       gfs2fl_Barrier          = 17,
8687 +       gfs2fl_Cow              = 18,
8688         gfs2fl_TruncInProg      = 29,
8689         gfs2fl_InheritDirectio  = 30,
8690         gfs2fl_InheritJdata     = 31,
8691 @@ -251,6 +254,9 @@ enum {
8692  #define GFS2_DIF_NOATIME               0x00000080
8693  #define GFS2_DIF_SYNC                  0x00000100
8694  #define GFS2_DIF_SYSTEM                        0x00000200 /* New in gfs2 */
8695 +#define GFS2_DIF_IXUNLINK              0x00010000
8696 +#define GFS2_DIF_BARRIER               0x00020000
8697 +#define GFS2_DIF_COW                   0x00040000
8698  #define GFS2_DIF_TRUNC_IN_PROG         0x20000000 /* New in gfs2 */
8699  #define GFS2_DIF_INHERIT_DIRECTIO      0x40000000
8700  #define GFS2_DIF_INHERIT_JDATA         0x80000000
8701 diff -NurpP --minimal linux-2.6.32.1/include/linux/if_tun.h linux-2.6.32.1-vs2.3.0.36.27/include/linux/if_tun.h
8702 --- linux-2.6.32.1/include/linux/if_tun.h       2009-12-03 20:02:55.000000000 +0100
8703 +++ linux-2.6.32.1-vs2.3.0.36.27/include/linux/if_tun.h 2009-12-03 20:04:56.000000000 +0100
8704 @@ -48,6 +48,7 @@
8705  #define TUNGETIFF      _IOR('T', 210, unsigned int)
8706  #define TUNGETSNDBUF   _IOR('T', 211, int)
8707  #define TUNSETSNDBUF   _IOW('T', 212, int)
8708 +#define TUNSETNID     _IOW('T', 215, int)
8709  
8710  /* TUNSETIFF ifr flags */
8711  #define IFF_TUN                0x0001
8712 diff -NurpP --minimal linux-2.6.32.1/include/linux/init_task.h linux-2.6.32.1-vs2.3.0.36.27/include/linux/init_task.h
8713 --- linux-2.6.32.1/include/linux/init_task.h    2009-12-03 20:02:55.000000000 +0100
8714 +++ linux-2.6.32.1-vs2.3.0.36.27/include/linux/init_task.h      2009-12-03 20:04:56.000000000 +0100
8715 @@ -184,6 +184,10 @@ extern struct cred init_cred;
8716         INIT_FTRACE_GRAPH                                               \
8717         INIT_TRACE_RECURSION                                            \
8718         INIT_TASK_RCU_PREEMPT(tsk)                                      \
8719 +       .xid            = 0,                                            \
8720 +       .vx_info        = NULL,                                         \
8721 +       .nid            = 0,                                            \
8722 +       .nx_info        = NULL,                                         \
8723  }
8724  
8725  
8726 diff -NurpP --minimal linux-2.6.32.1/include/linux/ipc.h linux-2.6.32.1-vs2.3.0.36.27/include/linux/ipc.h
8727 --- linux-2.6.32.1/include/linux/ipc.h  2009-12-03 20:02:55.000000000 +0100
8728 +++ linux-2.6.32.1-vs2.3.0.36.27/include/linux/ipc.h    2009-12-03 20:04:56.000000000 +0100
8729 @@ -91,6 +91,7 @@ struct kern_ipc_perm
8730         key_t           key;
8731         uid_t           uid;
8732         gid_t           gid;
8733 +       xid_t           xid;
8734         uid_t           cuid;
8735         gid_t           cgid;
8736         mode_t          mode; 
8737 diff -NurpP --minimal linux-2.6.32.1/include/linux/Kbuild linux-2.6.32.1-vs2.3.0.36.27/include/linux/Kbuild
8738 --- linux-2.6.32.1/include/linux/Kbuild 2009-12-03 20:02:54.000000000 +0100
8739 +++ linux-2.6.32.1-vs2.3.0.36.27/include/linux/Kbuild   2009-12-03 20:04:56.000000000 +0100
8740 @@ -382,5 +382,8 @@ unifdef-y += xattr.h
8741  unifdef-y += xfrm.h
8742  
8743  objhdr-y += version.h
8744 +
8745 +header-y += vserver/
8746  header-y += wimax.h
8747  header-y += wimax/
8748 +
8749 diff -NurpP --minimal linux-2.6.32.1/include/linux/loop.h linux-2.6.32.1-vs2.3.0.36.27/include/linux/loop.h
8750 --- linux-2.6.32.1/include/linux/loop.h 2009-09-10 15:26:25.000000000 +0200
8751 +++ linux-2.6.32.1-vs2.3.0.36.27/include/linux/loop.h   2009-12-03 20:04:56.000000000 +0100
8752 @@ -45,6 +45,7 @@ struct loop_device {
8753         struct loop_func_table *lo_encryption;
8754         __u32           lo_init[2];
8755         uid_t           lo_key_owner;   /* Who set the key */
8756 +       xid_t           lo_xid;
8757         int             (*ioctl)(struct loop_device *, int cmd, 
8758                                  unsigned long arg); 
8759  
8760 diff -NurpP --minimal linux-2.6.32.1/include/linux/magic.h linux-2.6.32.1-vs2.3.0.36.27/include/linux/magic.h
8761 --- linux-2.6.32.1/include/linux/magic.h        2009-12-03 20:02:55.000000000 +0100
8762 +++ linux-2.6.32.1-vs2.3.0.36.27/include/linux/magic.h  2009-12-03 20:04:56.000000000 +0100
8763 @@ -3,7 +3,7 @@
8764  
8765  #define ADFS_SUPER_MAGIC       0xadf5
8766  #define AFFS_SUPER_MAGIC       0xadff
8767 -#define AFS_SUPER_MAGIC                0x5346414F
8768 +#define AFS_SUPER_MAGIC                0x5346414F
8769  #define AUTOFS_SUPER_MAGIC     0x0187
8770  #define CODA_SUPER_MAGIC       0x73757245
8771  #define CRAMFS_MAGIC           0x28cd3d45      /* some random number */
8772 @@ -38,6 +38,7 @@
8773  #define NFS_SUPER_MAGIC                0x6969
8774  #define OPENPROM_SUPER_MAGIC   0x9fa1
8775  #define PROC_SUPER_MAGIC       0x9fa0
8776 +#define DEVPTS_SUPER_MAGIC     0x1cd1
8777  #define QNX4_SUPER_MAGIC       0x002f          /* qnx4 fs detection */
8778  
8779  #define REISERFS_SUPER_MAGIC   0x52654973      /* used by gcc */
8780 diff -NurpP --minimal linux-2.6.32.1/include/linux/major.h linux-2.6.32.1-vs2.3.0.36.27/include/linux/major.h
8781 --- linux-2.6.32.1/include/linux/major.h        2009-09-10 15:26:25.000000000 +0200
8782 +++ linux-2.6.32.1-vs2.3.0.36.27/include/linux/major.h  2009-12-03 20:04:56.000000000 +0100
8783 @@ -15,6 +15,7 @@
8784  #define HD_MAJOR               IDE0_MAJOR
8785  #define PTY_SLAVE_MAJOR                3
8786  #define TTY_MAJOR              4
8787 +#define VROOT_MAJOR            4
8788  #define TTYAUX_MAJOR           5
8789  #define LP_MAJOR               6
8790  #define VCS_MAJOR              7
8791 diff -NurpP --minimal linux-2.6.32.1/include/linux/mm_types.h linux-2.6.32.1-vs2.3.0.36.27/include/linux/mm_types.h
8792 --- linux-2.6.32.1/include/linux/mm_types.h     2009-12-03 20:02:55.000000000 +0100
8793 +++ linux-2.6.32.1-vs2.3.0.36.27/include/linux/mm_types.h       2009-12-03 20:04:56.000000000 +0100
8794 @@ -246,6 +246,7 @@ struct mm_struct {
8795  
8796         /* Architecture-specific MM context */
8797         mm_context_t context;
8798 +       struct vx_info *mm_vx_info;
8799  
8800         /* Swap token stuff */
8801         /*
8802 diff -NurpP --minimal linux-2.6.32.1/include/linux/mount.h linux-2.6.32.1-vs2.3.0.36.27/include/linux/mount.h
8803 --- linux-2.6.32.1/include/linux/mount.h        2009-09-10 15:26:25.000000000 +0200
8804 +++ linux-2.6.32.1-vs2.3.0.36.27/include/linux/mount.h  2009-12-03 20:04:56.000000000 +0100
8805 @@ -36,6 +36,9 @@ struct mnt_namespace;
8806  #define MNT_UNBINDABLE 0x2000  /* if the vfsmount is a unbindable mount */
8807  #define MNT_PNODE_MASK 0x3000  /* propagation flag mask */
8808  
8809 +#define MNT_TAGID      0x10000
8810 +#define MNT_NOTAG      0x20000
8811 +
8812  struct vfsmount {
8813         struct list_head mnt_hash;
8814         struct vfsmount *mnt_parent;    /* fs we are mounted on */
8815 @@ -70,6 +73,7 @@ struct vfsmount {
8816  #else
8817         int mnt_writers;
8818  #endif
8819 +       tag_t mnt_tag;                  /* tagging used for vfsmount */
8820  };
8821  
8822  static inline int *get_mnt_writers_ptr(struct vfsmount *mnt)
8823 diff -NurpP --minimal linux-2.6.32.1/include/linux/net.h linux-2.6.32.1-vs2.3.0.36.27/include/linux/net.h
8824 --- linux-2.6.32.1/include/linux/net.h  2009-12-03 20:02:55.000000000 +0100
8825 +++ linux-2.6.32.1-vs2.3.0.36.27/include/linux/net.h    2009-12-03 20:04:56.000000000 +0100
8826 @@ -69,6 +69,7 @@ struct net;
8827  #define SOCK_NOSPACE           2
8828  #define SOCK_PASSCRED          3
8829  #define SOCK_PASSSEC           4
8830 +#define SOCK_USER_SOCKET       5
8831  
8832  #ifndef ARCH_HAS_SOCKET_TYPES
8833  /**
8834 diff -NurpP --minimal linux-2.6.32.1/include/linux/nfs_mount.h linux-2.6.32.1-vs2.3.0.36.27/include/linux/nfs_mount.h
8835 --- linux-2.6.32.1/include/linux/nfs_mount.h    2009-03-24 14:22:43.000000000 +0100
8836 +++ linux-2.6.32.1-vs2.3.0.36.27/include/linux/nfs_mount.h      2009-12-03 20:04:56.000000000 +0100
8837 @@ -63,7 +63,8 @@ struct nfs_mount_data {
8838  #define NFS_MOUNT_SECFLAVOUR   0x2000  /* 5 */
8839  #define NFS_MOUNT_NORDIRPLUS   0x4000  /* 5 */
8840  #define NFS_MOUNT_UNSHARED     0x8000  /* 5 */
8841 -#define NFS_MOUNT_FLAGMASK     0xFFFF
8842 +#define NFS_MOUNT_TAGGED       0x10000 /* context tagging */
8843 +#define NFS_MOUNT_FLAGMASK     0x1FFFF
8844  
8845  /* The following are for internal use only */
8846  #define NFS_MOUNT_LOOKUP_CACHE_NONEG   0x10000
8847 diff -NurpP --minimal linux-2.6.32.1/include/linux/nsproxy.h linux-2.6.32.1-vs2.3.0.36.27/include/linux/nsproxy.h
8848 --- linux-2.6.32.1/include/linux/nsproxy.h      2009-06-11 17:13:17.000000000 +0200
8849 +++ linux-2.6.32.1-vs2.3.0.36.27/include/linux/nsproxy.h        2009-12-03 20:04:56.000000000 +0100
8850 @@ -3,6 +3,7 @@
8851  
8852  #include <linux/spinlock.h>
8853  #include <linux/sched.h>
8854 +#include <linux/vserver/debug.h>
8855  
8856  struct mnt_namespace;
8857  struct uts_namespace;
8858 @@ -63,22 +64,33 @@ static inline struct nsproxy *task_nspro
8859  }
8860  
8861  int copy_namespaces(unsigned long flags, struct task_struct *tsk);
8862 +struct nsproxy *copy_nsproxy(struct nsproxy *orig);
8863  void exit_task_namespaces(struct task_struct *tsk);
8864  void switch_task_namespaces(struct task_struct *tsk, struct nsproxy *new);
8865  void free_nsproxy(struct nsproxy *ns);
8866  int unshare_nsproxy_namespaces(unsigned long, struct nsproxy **,
8867         struct fs_struct *);
8868  
8869 -static inline void put_nsproxy(struct nsproxy *ns)
8870 +#define        get_nsproxy(n)  __get_nsproxy(n, __FILE__, __LINE__)
8871 +
8872 +static inline void __get_nsproxy(struct nsproxy *ns,
8873 +       const char *_file, int _line)
8874  {
8875 -       if (atomic_dec_and_test(&ns->count)) {
8876 -               free_nsproxy(ns);
8877 -       }
8878 +       vxlprintk(VXD_CBIT(space, 0), "get_nsproxy(%p[%u])",
8879 +               ns, atomic_read(&ns->count), _file, _line);
8880 +       atomic_inc(&ns->count);
8881  }
8882  
8883 -static inline void get_nsproxy(struct nsproxy *ns)
8884 +#define        put_nsproxy(n)  __put_nsproxy(n, __FILE__, __LINE__)
8885 +
8886 +static inline void __put_nsproxy(struct nsproxy *ns,
8887 +       const char *_file, int _line)
8888  {
8889 -       atomic_inc(&ns->count);
8890 +       vxlprintk(VXD_CBIT(space, 0), "put_nsproxy(%p[%u])",
8891 +               ns, atomic_read(&ns->count), _file, _line);
8892 +       if (atomic_dec_and_test(&ns->count)) {
8893 +               free_nsproxy(ns);
8894 +       }
8895  }
8896  
8897  #ifdef CONFIG_CGROUP_NS
8898 diff -NurpP --minimal linux-2.6.32.1/include/linux/pid.h linux-2.6.32.1-vs2.3.0.36.27/include/linux/pid.h
8899 --- linux-2.6.32.1/include/linux/pid.h  2009-03-24 14:22:43.000000000 +0100
8900 +++ linux-2.6.32.1-vs2.3.0.36.27/include/linux/pid.h    2009-12-03 20:04:56.000000000 +0100
8901 @@ -8,7 +8,8 @@ enum pid_type
8902         PIDTYPE_PID,
8903         PIDTYPE_PGID,
8904         PIDTYPE_SID,
8905 -       PIDTYPE_MAX
8906 +       PIDTYPE_MAX,
8907 +       PIDTYPE_REALPID
8908  };
8909  
8910  /*
8911 @@ -160,6 +161,7 @@ static inline pid_t pid_nr(struct pid *p
8912  }
8913  
8914  pid_t pid_nr_ns(struct pid *pid, struct pid_namespace *ns);
8915 +pid_t pid_unmapped_nr_ns(struct pid *pid, struct pid_namespace *ns);
8916  pid_t pid_vnr(struct pid *pid);
8917  
8918  #define do_each_pid_task(pid, type, task)                              \
8919 diff -NurpP --minimal linux-2.6.32.1/include/linux/proc_fs.h linux-2.6.32.1-vs2.3.0.36.27/include/linux/proc_fs.h
8920 --- linux-2.6.32.1/include/linux/proc_fs.h      2009-12-03 20:02:56.000000000 +0100
8921 +++ linux-2.6.32.1-vs2.3.0.36.27/include/linux/proc_fs.h        2009-12-03 20:04:56.000000000 +0100
8922 @@ -56,6 +56,7 @@ struct proc_dir_entry {
8923         nlink_t nlink;
8924         uid_t uid;
8925         gid_t gid;
8926 +       int vx_flags;
8927         loff_t size;
8928         const struct inode_operations *proc_iops;
8929         /*
8930 @@ -250,12 +251,18 @@ kclist_add(struct kcore_list *new, void 
8931  extern void kclist_add(struct kcore_list *, void *, size_t, int type);
8932  #endif
8933  
8934 +struct vx_info;
8935 +struct nx_info;
8936 +
8937  union proc_op {
8938         int (*proc_get_link)(struct inode *, struct path *);
8939         int (*proc_read)(struct task_struct *task, char *page);
8940         int (*proc_show)(struct seq_file *m,
8941                 struct pid_namespace *ns, struct pid *pid,
8942                 struct task_struct *task);
8943 +       int (*proc_vs_read)(char *page);
8944 +       int (*proc_vxi_read)(struct vx_info *vxi, char *page);
8945 +       int (*proc_nxi_read)(struct nx_info *nxi, char *page);
8946  };
8947  
8948  struct ctl_table_header;
8949 @@ -263,6 +270,7 @@ struct ctl_table;
8950  
8951  struct proc_inode {
8952         struct pid *pid;
8953 +       int vx_flags;
8954         int fd;
8955         union proc_op op;
8956         struct proc_dir_entry *pde;
8957 diff -NurpP --minimal linux-2.6.32.1/include/linux/quotaops.h linux-2.6.32.1-vs2.3.0.36.27/include/linux/quotaops.h
8958 --- linux-2.6.32.1/include/linux/quotaops.h     2009-12-03 20:02:56.000000000 +0100
8959 +++ linux-2.6.32.1-vs2.3.0.36.27/include/linux/quotaops.h       2009-12-03 20:04:56.000000000 +0100
8960 @@ -8,6 +8,7 @@
8961  #define _LINUX_QUOTAOPS_
8962  
8963  #include <linux/fs.h>
8964 +#include <linux/vs_dlimit.h>
8965  
8966  static inline struct quota_info *sb_dqopt(struct super_block *sb)
8967  {
8968 @@ -154,10 +155,14 @@ static inline void vfs_dq_init(struct in
8969   * a transaction (deadlocks possible otherwise) */
8970  static inline int vfs_dq_prealloc_space_nodirty(struct inode *inode, qsize_t nr)
8971  {
8972 +       if (dl_alloc_space(inode, nr))
8973 +               return 1;
8974         if (sb_any_quota_active(inode->i_sb)) {
8975                 /* Used space is updated in alloc_space() */
8976 -               if (inode->i_sb->dq_op->alloc_space(inode, nr, 1) == NO_QUOTA)
8977 +               if (inode->i_sb->dq_op->alloc_space(inode, nr, 1) == NO_QUOTA) {
8978 +                       dl_free_space(inode, nr);
8979                         return 1;
8980 +               }
8981         }
8982         else
8983                 inode_add_bytes(inode, nr);
8984 @@ -174,10 +179,14 @@ static inline int vfs_dq_prealloc_space(
8985  
8986  static inline int vfs_dq_alloc_space_nodirty(struct inode *inode, qsize_t nr)
8987  {
8988 +       if (dl_alloc_space(inode, nr))
8989 +               return 1;
8990         if (sb_any_quota_active(inode->i_sb)) {
8991                 /* Used space is updated in alloc_space() */
8992 -               if (inode->i_sb->dq_op->alloc_space(inode, nr, 0) == NO_QUOTA)
8993 +               if (inode->i_sb->dq_op->alloc_space(inode, nr, 0) == NO_QUOTA) {
8994 +                       dl_free_space(inode, nr);
8995                         return 1;
8996 +               }
8997         }
8998         else
8999                 inode_add_bytes(inode, nr);
9000 @@ -194,20 +203,28 @@ static inline int vfs_dq_alloc_space(str
9001  
9002  static inline int vfs_dq_reserve_space(struct inode *inode, qsize_t nr)
9003  {
9004 +       if (dl_reserve_space(inode, nr))
9005 +               return 1;
9006         if (sb_any_quota_active(inode->i_sb)) {
9007                 /* Used space is updated in alloc_space() */
9008 -               if (inode->i_sb->dq_op->reserve_space(inode, nr, 0) == NO_QUOTA)
9009 +               if (inode->i_sb->dq_op->reserve_space(inode, nr, 0) == NO_QUOTA) {
9010 +                       dl_release_space(inode, nr);
9011                         return 1;
9012 +               }
9013         }
9014         return 0;
9015  }
9016  
9017  static inline int vfs_dq_alloc_inode(struct inode *inode)
9018  {
9019 +       if (dl_alloc_inode(inode))
9020 +               return 1;
9021         if (sb_any_quota_active(inode->i_sb)) {
9022                 vfs_dq_init(inode);
9023 -               if (inode->i_sb->dq_op->alloc_inode(inode, 1) == NO_QUOTA)
9024 +               if (inode->i_sb->dq_op->alloc_inode(inode, 1) == NO_QUOTA) {
9025 +                       dl_free_inode(inode);
9026                         return 1;
9027 +               }
9028         }
9029         return 0;
9030  }
9031 @@ -217,9 +234,13 @@ static inline int vfs_dq_alloc_inode(str
9032   */
9033  static inline int vfs_dq_claim_space(struct inode *inode, qsize_t nr)
9034  {
9035 +       if (dl_claim_space(inode, nr))
9036 +               return 1;
9037         if (sb_any_quota_active(inode->i_sb)) {
9038 -               if (inode->i_sb->dq_op->claim_space(inode, nr) == NO_QUOTA)
9039 +               if (inode->i_sb->dq_op->claim_space(inode, nr) == NO_QUOTA) {
9040 +                       dl_release_space(inode, nr);
9041                         return 1;
9042 +               }
9043         } else
9044                 inode_add_bytes(inode, nr);
9045  
9046 @@ -235,6 +256,7 @@ void vfs_dq_release_reservation_space(st
9047  {
9048         if (sb_any_quota_active(inode->i_sb))
9049                 inode->i_sb->dq_op->release_rsv(inode, nr);
9050 +       dl_release_space(inode, nr);
9051  }
9052  
9053  static inline void vfs_dq_free_space_nodirty(struct inode *inode, qsize_t nr)
9054 @@ -243,6 +265,7 @@ static inline void vfs_dq_free_space_nod
9055                 inode->i_sb->dq_op->free_space(inode, nr);
9056         else
9057                 inode_sub_bytes(inode, nr);
9058 +       dl_free_space(inode, nr);
9059  }
9060  
9061  static inline void vfs_dq_free_space(struct inode *inode, qsize_t nr)
9062 @@ -255,6 +278,7 @@ static inline void vfs_dq_free_inode(str
9063  {
9064         if (sb_any_quota_active(inode->i_sb))
9065                 inode->i_sb->dq_op->free_inode(inode, 1);
9066 +       dl_free_inode(inode);
9067  }
9068  
9069  /* Cannot be called inside a transaction */
9070 @@ -358,6 +382,8 @@ static inline int vfs_dq_transfer(struct
9071  
9072  static inline int vfs_dq_prealloc_space_nodirty(struct inode *inode, qsize_t nr)
9073  {
9074 +       if (dl_alloc_space(inode, nr))
9075 +               return 1;
9076         inode_add_bytes(inode, nr);
9077         return 0;
9078  }
9079 @@ -371,6 +397,8 @@ static inline int vfs_dq_prealloc_space(
9080  
9081  static inline int vfs_dq_alloc_space_nodirty(struct inode *inode, qsize_t nr)
9082  {
9083 +       if (dl_alloc_space(inode, nr))
9084 +               return 1;
9085         inode_add_bytes(inode, nr);
9086         return 0;
9087  }
9088 @@ -384,22 +412,28 @@ static inline int vfs_dq_alloc_space(str
9089  
9090  static inline int vfs_dq_reserve_space(struct inode *inode, qsize_t nr)
9091  {
9092 +       if (dl_reserve_space(inode, nr))
9093 +               return 1;
9094         return 0;
9095  }
9096  
9097  static inline int vfs_dq_claim_space(struct inode *inode, qsize_t nr)
9098  {
9099 +       if (dl_claim_space(inode, nr))
9100 +               return 1;
9101         return vfs_dq_alloc_space(inode, nr);
9102  }
9103  
9104  static inline
9105  int vfs_dq_release_reservation_space(struct inode *inode, qsize_t nr)
9106  {
9107 +       dl_release_space(inode, nr);
9108         return 0;
9109  }
9110  
9111  static inline void vfs_dq_free_space_nodirty(struct inode *inode, qsize_t nr)
9112  {
9113 +       dl_free_space(inode, nr);
9114         inode_sub_bytes(inode, nr);
9115  }
9116  
9117 diff -NurpP --minimal linux-2.6.32.1/include/linux/reboot.h linux-2.6.32.1-vs2.3.0.36.27/include/linux/reboot.h
9118 --- linux-2.6.32.1/include/linux/reboot.h       2008-12-25 00:26:37.000000000 +0100
9119 +++ linux-2.6.32.1-vs2.3.0.36.27/include/linux/reboot.h 2009-12-03 22:06:59.000000000 +0100
9120 @@ -33,6 +33,7 @@
9121  #define        LINUX_REBOOT_CMD_RESTART2       0xA1B2C3D4
9122  #define        LINUX_REBOOT_CMD_SW_SUSPEND     0xD000FCE2
9123  #define        LINUX_REBOOT_CMD_KEXEC          0x45584543
9124 +#define        LINUX_REBOOT_CMD_OOM            0xDEADBEEF
9125  
9126  
9127  #ifdef __KERNEL__
9128 diff -NurpP --minimal linux-2.6.32.1/include/linux/reiserfs_fs.h linux-2.6.32.1-vs2.3.0.36.27/include/linux/reiserfs_fs.h
9129 --- linux-2.6.32.1/include/linux/reiserfs_fs.h  2009-09-10 15:26:26.000000000 +0200
9130 +++ linux-2.6.32.1-vs2.3.0.36.27/include/linux/reiserfs_fs.h    2009-12-03 20:04:56.000000000 +0100
9131 @@ -899,6 +899,11 @@ struct stat_data_v1 {
9132  #define REISERFS_COMPR_FL     FS_COMPR_FL
9133  #define REISERFS_NOTAIL_FL    FS_NOTAIL_FL
9134  
9135 +/* unfortunately reiserfs sdattr is only 16 bit */
9136 +#define REISERFS_IXUNLINK_FL  (FS_IXUNLINK_FL >> 16)
9137 +#define REISERFS_BARRIER_FL   (FS_BARRIER_FL >> 16)
9138 +#define REISERFS_COW_FL       (FS_COW_FL >> 16)
9139 +
9140  /* persistent flags that file inherits from the parent directory */
9141  #define REISERFS_INHERIT_MASK ( REISERFS_IMMUTABLE_FL |        \
9142                                 REISERFS_SYNC_FL |      \
9143 @@ -908,6 +913,9 @@ struct stat_data_v1 {
9144                                 REISERFS_COMPR_FL |     \
9145                                 REISERFS_NOTAIL_FL )
9146  
9147 +#define REISERFS_FL_USER_VISIBLE       0x80FF
9148 +#define REISERFS_FL_USER_MODIFIABLE    0x80FF
9149 +
9150  /* Stat Data on disk (reiserfs version of UFS disk inode minus the
9151     address blocks) */
9152  struct stat_data {
9153 @@ -1989,6 +1997,7 @@ static inline void reiserfs_update_sd(st
9154  void sd_attrs_to_i_attrs(__u16 sd_attrs, struct inode *inode);
9155  void i_attrs_to_sd_attrs(struct inode *inode, __u16 * sd_attrs);
9156  int reiserfs_setattr(struct dentry *dentry, struct iattr *attr);
9157 +int reiserfs_sync_flags(struct inode *inode, int, int);
9158  
9159  /* namei.c */
9160  void set_de_name_and_namelen(struct reiserfs_dir_entry *de);
9161 diff -NurpP --minimal linux-2.6.32.1/include/linux/reiserfs_fs_sb.h linux-2.6.32.1-vs2.3.0.36.27/include/linux/reiserfs_fs_sb.h
9162 --- linux-2.6.32.1/include/linux/reiserfs_fs_sb.h       2009-09-10 15:26:26.000000000 +0200
9163 +++ linux-2.6.32.1-vs2.3.0.36.27/include/linux/reiserfs_fs_sb.h 2009-12-03 20:04:56.000000000 +0100
9164 @@ -456,6 +456,7 @@ enum reiserfs_mount_options {
9165         REISERFS_EXPOSE_PRIVROOT,
9166         REISERFS_BARRIER_NONE,
9167         REISERFS_BARRIER_FLUSH,
9168 +       REISERFS_TAGGED,
9169  
9170         /* Actions on error */
9171         REISERFS_ERROR_PANIC,
9172 diff -NurpP --minimal linux-2.6.32.1/include/linux/sched.h linux-2.6.32.1-vs2.3.0.36.27/include/linux/sched.h
9173 --- linux-2.6.32.1/include/linux/sched.h        2009-12-14 21:29:46.000000000 +0100
9174 +++ linux-2.6.32.1-vs2.3.0.36.27/include/linux/sched.h  2009-12-14 22:20:55.000000000 +0100
9175 @@ -390,25 +390,28 @@ extern void arch_unmap_area_topdown(stru
9176   * The mm counters are not protected by its page_table_lock,
9177   * so must be incremented atomically.
9178   */
9179 -#define set_mm_counter(mm, member, value) atomic_long_set(&(mm)->_##member, value)
9180 -#define get_mm_counter(mm, member) ((unsigned long)atomic_long_read(&(mm)->_##member))
9181 -#define add_mm_counter(mm, member, value) atomic_long_add(value, &(mm)->_##member)
9182 -#define inc_mm_counter(mm, member) atomic_long_inc(&(mm)->_##member)
9183 -#define dec_mm_counter(mm, member) atomic_long_dec(&(mm)->_##member)
9184 +#define __set_mm_counter(mm, member, value) \
9185 +       atomic_long_set(&(mm)->_##member, value)
9186 +#define get_mm_counter(mm, member) \
9187 +       ((unsigned long)atomic_long_read(&(mm)->_##member))
9188  
9189  #else  /* !USE_SPLIT_PTLOCKS */
9190  /*
9191   * The mm counters are protected by its page_table_lock,
9192   * so can be incremented directly.
9193   */
9194 -#define set_mm_counter(mm, member, value) (mm)->_##member = (value)
9195 +#define __set_mm_counter(mm, member, value) (mm)->_##member = (value)
9196  #define get_mm_counter(mm, member) ((mm)->_##member)
9197 -#define add_mm_counter(mm, member, value) (mm)->_##member += (value)
9198 -#define inc_mm_counter(mm, member) (mm)->_##member++
9199 -#define dec_mm_counter(mm, member) (mm)->_##member--
9200  
9201  #endif /* !USE_SPLIT_PTLOCKS */
9202  
9203 +#define set_mm_counter(mm, member, value) \
9204 +       vx_ ## member ## pages_sub((mm), (get_mm_counter(mm, member) - value))
9205 +#define add_mm_counter(mm, member, value) \
9206 +       vx_ ## member ## pages_add((mm), (value))
9207 +#define inc_mm_counter(mm, member) vx_ ## member ## pages_inc((mm))
9208 +#define dec_mm_counter(mm, member) vx_ ## member ## pages_dec((mm))
9209 +
9210  #define get_mm_rss(mm)                                 \
9211         (get_mm_counter(mm, file_rss) + get_mm_counter(mm, anon_rss))
9212  #define update_hiwater_rss(mm) do {                    \
9213 @@ -1183,6 +1186,12 @@ struct sched_entity {
9214         u64                     nr_wakeups_affine_attempts;
9215         u64                     nr_wakeups_passive;
9216         u64                     nr_wakeups_idle;
9217 +#ifdef CONFIG_CFS_HARD_LIMITS
9218 +       u64                     throttle_start;
9219 +       u64                     throttle_max;
9220 +       u64                     throttle_count;
9221 +       u64                     throttle_sum;
9222 +#endif
9223  #endif
9224  
9225  #ifdef CONFIG_FAIR_GROUP_SCHED
9226 @@ -1393,6 +1402,14 @@ struct task_struct {
9227  #endif
9228         seccomp_t seccomp;
9229  
9230 +/* vserver context data */
9231 +       struct vx_info *vx_info;
9232 +       struct nx_info *nx_info;
9233 +
9234 +       xid_t xid;
9235 +       nid_t nid;
9236 +       tag_t tag;
9237 +
9238  /* Thread group tracking */
9239         u32 parent_exec_id;
9240         u32 self_exec_id;
9241 @@ -1618,6 +1635,11 @@ struct pid_namespace;
9242  pid_t __task_pid_nr_ns(struct task_struct *task, enum pid_type type,
9243                         struct pid_namespace *ns);
9244  
9245 +#include <linux/vserver/base.h>
9246 +#include <linux/vserver/context.h>
9247 +#include <linux/vserver/debug.h>
9248 +#include <linux/vserver/pid.h>
9249 +
9250  static inline pid_t task_pid_nr(struct task_struct *tsk)
9251  {
9252         return tsk->pid;
9253 @@ -1631,7 +1653,8 @@ static inline pid_t task_pid_nr_ns(struc
9254  
9255  static inline pid_t task_pid_vnr(struct task_struct *tsk)
9256  {
9257 -       return __task_pid_nr_ns(tsk, PIDTYPE_PID, NULL);
9258 +       // return __task_pid_nr_ns(tsk, PIDTYPE_PID, NULL);
9259 +       return vx_map_pid(__task_pid_nr_ns(tsk, PIDTYPE_PID, NULL));
9260  }
9261  
9262  
9263 @@ -1644,7 +1667,7 @@ pid_t task_tgid_nr_ns(struct task_struct
9264  
9265  static inline pid_t task_tgid_vnr(struct task_struct *tsk)
9266  {
9267 -       return pid_vnr(task_tgid(tsk));
9268 +       return vx_map_tgid(pid_vnr(task_tgid(tsk)));
9269  }
9270  
9271  
9272 diff -NurpP --minimal linux-2.6.32.1/include/linux/shmem_fs.h linux-2.6.32.1-vs2.3.0.36.27/include/linux/shmem_fs.h
9273 --- linux-2.6.32.1/include/linux/shmem_fs.h     2009-12-03 20:02:56.000000000 +0100
9274 +++ linux-2.6.32.1-vs2.3.0.36.27/include/linux/shmem_fs.h       2009-12-03 20:04:56.000000000 +0100
9275 @@ -8,6 +8,9 @@
9276  
9277  #define SHMEM_NR_DIRECT 16
9278  
9279 +#define TMPFS_SUPER_MAGIC      0x01021994
9280 +
9281 +
9282  struct shmem_inode_info {
9283         spinlock_t              lock;
9284         unsigned long           flags;
9285 diff -NurpP --minimal linux-2.6.32.1/include/linux/stat.h linux-2.6.32.1-vs2.3.0.36.27/include/linux/stat.h
9286 --- linux-2.6.32.1/include/linux/stat.h 2008-12-25 00:26:37.000000000 +0100
9287 +++ linux-2.6.32.1-vs2.3.0.36.27/include/linux/stat.h   2009-12-03 20:04:56.000000000 +0100
9288 @@ -66,6 +66,7 @@ struct kstat {
9289         unsigned int    nlink;
9290         uid_t           uid;
9291         gid_t           gid;
9292 +       tag_t           tag;
9293         dev_t           rdev;
9294         loff_t          size;
9295         struct timespec  atime;
9296 diff -NurpP --minimal linux-2.6.32.1/include/linux/sunrpc/auth.h linux-2.6.32.1-vs2.3.0.36.27/include/linux/sunrpc/auth.h
9297 --- linux-2.6.32.1/include/linux/sunrpc/auth.h  2009-12-03 20:02:56.000000000 +0100
9298 +++ linux-2.6.32.1-vs2.3.0.36.27/include/linux/sunrpc/auth.h    2009-12-03 20:04:56.000000000 +0100
9299 @@ -25,6 +25,7 @@
9300  struct auth_cred {
9301         uid_t   uid;
9302         gid_t   gid;
9303 +       tag_t   tag;
9304         struct group_info *group_info;
9305         unsigned char machine_cred : 1;
9306  };
9307 diff -NurpP --minimal linux-2.6.32.1/include/linux/sunrpc/clnt.h linux-2.6.32.1-vs2.3.0.36.27/include/linux/sunrpc/clnt.h
9308 --- linux-2.6.32.1/include/linux/sunrpc/clnt.h  2009-12-03 20:02:56.000000000 +0100
9309 +++ linux-2.6.32.1-vs2.3.0.36.27/include/linux/sunrpc/clnt.h    2009-12-03 20:04:56.000000000 +0100
9310 @@ -49,7 +49,8 @@ struct rpc_clnt {
9311         unsigned int            cl_softrtry : 1,/* soft timeouts */
9312                                 cl_discrtry : 1,/* disconnect before retry */
9313                                 cl_autobind : 1,/* use getport() */
9314 -                               cl_chatty   : 1;/* be verbose */
9315 +                               cl_chatty   : 1,/* be verbose */
9316 +                               cl_tag      : 1;/* context tagging */
9317  
9318         struct rpc_rtt *        cl_rtt;         /* RTO estimator data */
9319         const struct rpc_timeout *cl_timeout;   /* Timeout strategy */
9320 diff -NurpP --minimal linux-2.6.32.1/include/linux/syscalls.h linux-2.6.32.1-vs2.3.0.36.27/include/linux/syscalls.h
9321 --- linux-2.6.32.1/include/linux/syscalls.h     2009-12-03 20:02:56.000000000 +0100
9322 +++ linux-2.6.32.1-vs2.3.0.36.27/include/linux/syscalls.h       2009-12-03 20:04:56.000000000 +0100
9323 @@ -546,6 +546,8 @@ asmlinkage long sys_symlink(const char _
9324  asmlinkage long sys_unlink(const char __user *pathname);
9325  asmlinkage long sys_rename(const char __user *oldname,
9326                                 const char __user *newname);
9327 +asmlinkage long sys_copyfile(const char __user *from, const char __user *to,
9328 +                               umode_t mode);
9329  asmlinkage long sys_chmod(const char __user *filename, mode_t mode);
9330  asmlinkage long sys_fchmod(unsigned int fd, mode_t mode);
9331  
9332 diff -NurpP --minimal linux-2.6.32.1/include/linux/sysctl.h linux-2.6.32.1-vs2.3.0.36.27/include/linux/sysctl.h
9333 --- linux-2.6.32.1/include/linux/sysctl.h       2009-12-03 20:02:56.000000000 +0100
9334 +++ linux-2.6.32.1-vs2.3.0.36.27/include/linux/sysctl.h 2009-12-03 20:04:56.000000000 +0100
9335 @@ -69,6 +69,7 @@ enum
9336         CTL_ABI=9,              /* Binary emulation */
9337         CTL_CPU=10,             /* CPU stuff (speed scaling, etc) */
9338         CTL_ARLAN=254,          /* arlan wireless driver */
9339 +       CTL_VSERVER=4242,       /* Linux-VServer debug */
9340         CTL_S390DBF=5677,       /* s390 debug */
9341         CTL_SUNRPC=7249,        /* sunrpc debug */
9342         CTL_PM=9899,            /* frv power management */
9343 @@ -103,6 +104,7 @@ enum
9344  
9345         KERN_PANIC=15,          /* int: panic timeout */
9346         KERN_REALROOTDEV=16,    /* real root device to mount after initrd */
9347 +       KERN_VSHELPER=17,       /* string: path to vshelper policy agent */
9348  
9349         KERN_SPARC_REBOOT=21,   /* reboot command on Sparc */
9350         KERN_CTLALTDEL=22,      /* int: allow ctl-alt-del to reboot */
9351 diff -NurpP --minimal linux-2.6.32.1/include/linux/sysfs.h linux-2.6.32.1-vs2.3.0.36.27/include/linux/sysfs.h
9352 --- linux-2.6.32.1/include/linux/sysfs.h        2008-12-25 00:26:37.000000000 +0100
9353 +++ linux-2.6.32.1-vs2.3.0.36.27/include/linux/sysfs.h  2009-12-03 20:04:56.000000000 +0100
9354 @@ -17,6 +17,8 @@
9355  #include <linux/list.h>
9356  #include <asm/atomic.h>
9357  
9358 +#define SYSFS_SUPER_MAGIC      0x62656572
9359 +
9360  struct kobject;
9361  struct module;
9362  
9363 diff -NurpP --minimal linux-2.6.32.1/include/linux/time.h linux-2.6.32.1-vs2.3.0.36.27/include/linux/time.h
9364 --- linux-2.6.32.1/include/linux/time.h 2009-12-03 20:02:56.000000000 +0100
9365 +++ linux-2.6.32.1-vs2.3.0.36.27/include/linux/time.h   2009-12-03 20:04:56.000000000 +0100
9366 @@ -237,6 +237,9 @@ static __always_inline void timespec_add
9367         a->tv_sec += __iter_div_u64_rem(a->tv_nsec + ns, NSEC_PER_SEC, &ns);
9368         a->tv_nsec = ns;
9369  }
9370 +
9371 +#include <linux/vs_time.h>
9372 +
9373  #endif /* __KERNEL__ */
9374  
9375  #define NFDBITS                        __NFDBITS
9376 diff -NurpP --minimal linux-2.6.32.1/include/linux/types.h linux-2.6.32.1-vs2.3.0.36.27/include/linux/types.h
9377 --- linux-2.6.32.1/include/linux/types.h        2009-09-10 15:26:26.000000000 +0200
9378 +++ linux-2.6.32.1-vs2.3.0.36.27/include/linux/types.h  2009-12-03 20:04:56.000000000 +0100
9379 @@ -37,6 +37,9 @@ typedef __kernel_uid32_t      uid_t;
9380  typedef __kernel_gid32_t       gid_t;
9381  typedef __kernel_uid16_t        uid16_t;
9382  typedef __kernel_gid16_t        gid16_t;
9383 +typedef unsigned int           xid_t;
9384 +typedef unsigned int           nid_t;
9385 +typedef unsigned int           tag_t;
9386  
9387  typedef unsigned long          uintptr_t;
9388  
9389 diff -NurpP --minimal linux-2.6.32.1/include/linux/vroot.h linux-2.6.32.1-vs2.3.0.36.27/include/linux/vroot.h
9390 --- linux-2.6.32.1/include/linux/vroot.h        1970-01-01 01:00:00.000000000 +0100
9391 +++ linux-2.6.32.1-vs2.3.0.36.27/include/linux/vroot.h  2009-12-03 20:04:56.000000000 +0100
9392 @@ -0,0 +1,51 @@
9393 +
9394 +/*
9395 + * include/linux/vroot.h
9396 + *
9397 + * written by Herbert Pötzl, 9/11/2002
9398 + * ported to 2.6 by Herbert Pötzl, 30/12/2004
9399 + *
9400 + * Copyright (C) 2002-2007 by Herbert Pötzl.
9401 + * Redistribution of this file is permitted under the
9402 + * GNU General Public License.
9403 + */
9404 +
9405 +#ifndef _LINUX_VROOT_H
9406 +#define _LINUX_VROOT_H
9407 +
9408 +
9409 +#ifdef __KERNEL__
9410 +
9411 +/* Possible states of device */
9412 +enum {
9413 +       Vr_unbound,
9414 +       Vr_bound,
9415 +};
9416 +
9417 +struct vroot_device {
9418 +       int             vr_number;
9419 +       int             vr_refcnt;
9420 +
9421 +       struct semaphore        vr_ctl_mutex;
9422 +       struct block_device    *vr_device;
9423 +       int                     vr_state;
9424 +};
9425 +
9426 +
9427 +typedef struct block_device *(vroot_grb_func)(struct block_device *);
9428 +
9429 +extern int register_vroot_grb(vroot_grb_func *);
9430 +extern int unregister_vroot_grb(vroot_grb_func *);
9431 +
9432 +#endif /* __KERNEL__ */
9433 +
9434 +#define MAX_VROOT_DEFAULT      8
9435 +
9436 +/*
9437 + * IOCTL commands --- we will commandeer 0x56 ('V')
9438 + */
9439 +
9440 +#define VROOT_SET_DEV          0x5600
9441 +#define VROOT_CLR_DEV          0x5601
9442 +
9443 +#endif /* _LINUX_VROOT_H */
9444 diff -NurpP --minimal linux-2.6.32.1/include/linux/vs_base.h linux-2.6.32.1-vs2.3.0.36.27/include/linux/vs_base.h
9445 --- linux-2.6.32.1/include/linux/vs_base.h      1970-01-01 01:00:00.000000000 +0100
9446 +++ linux-2.6.32.1-vs2.3.0.36.27/include/linux/vs_base.h        2009-12-03 20:04:56.000000000 +0100
9447 @@ -0,0 +1,10 @@
9448 +#ifndef _VS_BASE_H
9449 +#define _VS_BASE_H
9450 +
9451 +#include "vserver/base.h"
9452 +#include "vserver/check.h"
9453 +#include "vserver/debug.h"
9454 +
9455 +#else
9456 +#warning duplicate inclusion
9457 +#endif
9458 diff -NurpP --minimal linux-2.6.32.1/include/linux/vs_context.h linux-2.6.32.1-vs2.3.0.36.27/include/linux/vs_context.h
9459 --- linux-2.6.32.1/include/linux/vs_context.h   1970-01-01 01:00:00.000000000 +0100
9460 +++ linux-2.6.32.1-vs2.3.0.36.27/include/linux/vs_context.h     2009-12-03 20:04:56.000000000 +0100
9461 @@ -0,0 +1,242 @@
9462 +#ifndef _VS_CONTEXT_H
9463 +#define _VS_CONTEXT_H
9464 +
9465 +#include "vserver/base.h"
9466 +#include "vserver/check.h"
9467 +#include "vserver/context.h"
9468 +#include "vserver/history.h"
9469 +#include "vserver/debug.h"
9470 +
9471 +#include <linux/sched.h>
9472 +
9473 +
9474 +#define get_vx_info(i) __get_vx_info(i, __FILE__, __LINE__, __HERE__)
9475 +
9476 +static inline struct vx_info *__get_vx_info(struct vx_info *vxi,
9477 +       const char *_file, int _line, void *_here)
9478 +{
9479 +       if (!vxi)
9480 +               return NULL;
9481 +
9482 +       vxlprintk(VXD_CBIT(xid, 2), "get_vx_info(%p[#%d.%d])",
9483 +               vxi, vxi ? vxi->vx_id : 0,
9484 +               vxi ? atomic_read(&vxi->vx_usecnt) : 0,
9485 +               _file, _line);
9486 +       __vxh_get_vx_info(vxi, _here);
9487 +
9488 +       atomic_inc(&vxi->vx_usecnt);
9489 +       return vxi;
9490 +}
9491 +
9492 +
9493 +extern void free_vx_info(struct vx_info *);
9494 +
9495 +#define put_vx_info(i) __put_vx_info(i, __FILE__, __LINE__, __HERE__)
9496 +
9497 +static inline void __put_vx_info(struct vx_info *vxi,
9498 +       const char *_file, int _line, void *_here)
9499 +{
9500 +       if (!vxi)
9501 +               return;
9502 +
9503 +       vxlprintk(VXD_CBIT(xid, 2), "put_vx_info(%p[#%d.%d])",
9504 +               vxi, vxi ? vxi->vx_id : 0,
9505 +               vxi ? atomic_read(&vxi->vx_usecnt) : 0,
9506 +               _file, _line);
9507 +       __vxh_put_vx_info(vxi, _here);
9508 +
9509 +       if (atomic_dec_and_test(&vxi->vx_usecnt))
9510 +               free_vx_info(vxi);
9511 +}
9512 +
9513 +
9514 +#define init_vx_info(p, i) \
9515 +       __init_vx_info(p, i, __FILE__, __LINE__, __HERE__)
9516 +
9517 +static inline void __init_vx_info(struct vx_info **vxp, struct vx_info *vxi,
9518 +       const char *_file, int _line, void *_here)
9519 +{
9520 +       if (vxi) {
9521 +               vxlprintk(VXD_CBIT(xid, 3),
9522 +                       "init_vx_info(%p[#%d.%d])",
9523 +                       vxi, vxi ? vxi->vx_id : 0,
9524 +                       vxi ? atomic_read(&vxi->vx_usecnt) : 0,
9525 +                       _file, _line);
9526 +               __vxh_init_vx_info(vxi, vxp, _here);
9527 +
9528 +               atomic_inc(&vxi->vx_usecnt);
9529 +       }
9530 +       *vxp = vxi;
9531 +}
9532 +
9533 +
9534 +#define set_vx_info(p, i) \
9535 +       __set_vx_info(p, i, __FILE__, __LINE__, __HERE__)
9536 +
9537 +static inline void __set_vx_info(struct vx_info **vxp, struct vx_info *vxi,
9538 +       const char *_file, int _line, void *_here)
9539 +{
9540 +       struct vx_info *vxo;
9541 +
9542 +       if (!vxi)
9543 +               return;
9544 +
9545 +       vxlprintk(VXD_CBIT(xid, 3), "set_vx_info(%p[#%d.%d])",
9546 +               vxi, vxi ? vxi->vx_id : 0,
9547 +               vxi ? atomic_read(&vxi->vx_usecnt) : 0,
9548 +               _file, _line);
9549 +       __vxh_set_vx_info(vxi, vxp, _here);
9550 +
9551 +       atomic_inc(&vxi->vx_usecnt);
9552 +       vxo = xchg(vxp, vxi);
9553 +       BUG_ON(vxo);
9554 +}
9555 +
9556 +
9557 +#define clr_vx_info(p) __clr_vx_info(p, __FILE__, __LINE__, __HERE__)
9558 +
9559 +static inline void __clr_vx_info(struct vx_info **vxp,
9560 +       const char *_file, int _line, void *_here)
9561 +{
9562 +       struct vx_info *vxo;
9563 +
9564 +       vxo = xchg(vxp, NULL);
9565 +       if (!vxo)
9566 +               return;
9567 +
9568 +       vxlprintk(VXD_CBIT(xid, 3), "clr_vx_info(%p[#%d.%d])",
9569 +               vxo, vxo ? vxo->vx_id : 0,
9570 +               vxo ? atomic_read(&vxo->vx_usecnt) : 0,
9571 +               _file, _line);
9572 +       __vxh_clr_vx_info(vxo, vxp, _here);
9573 +
9574 +       if (atomic_dec_and_test(&vxo->vx_usecnt))
9575 +               free_vx_info(vxo);
9576 +}
9577 +
9578 +
9579 +#define claim_vx_info(v, p) \
9580 +       __claim_vx_info(v, p, __FILE__, __LINE__, __HERE__)
9581 +
9582 +static inline void __claim_vx_info(struct vx_info *vxi,
9583 +       struct task_struct *task,
9584 +       const char *_file, int _line, void *_here)
9585 +{
9586 +       vxlprintk(VXD_CBIT(xid, 3), "claim_vx_info(%p[#%d.%d.%d]) %p",
9587 +               vxi, vxi ? vxi->vx_id : 0,
9588 +               vxi ? atomic_read(&vxi->vx_usecnt) : 0,
9589 +               vxi ? atomic_read(&vxi->vx_tasks) : 0,
9590 +               task, _file, _line);
9591 +       __vxh_claim_vx_info(vxi, task, _here);
9592 +
9593 +       atomic_inc(&vxi->vx_tasks);
9594 +}
9595 +
9596 +
9597 +extern void unhash_vx_info(struct vx_info *);
9598 +
9599 +#define release_vx_info(v, p) \
9600 +       __release_vx_info(v, p, __FILE__, __LINE__, __HERE__)
9601 +
9602 +static inline void __release_vx_info(struct vx_info *vxi,
9603 +       struct task_struct *task,
9604 +       const char *_file, int _line, void *_here)
9605 +{
9606 +       vxlprintk(VXD_CBIT(xid, 3), "release_vx_info(%p[#%d.%d.%d]) %p",
9607 +               vxi, vxi ? vxi->vx_id : 0,
9608 +               vxi ? atomic_read(&vxi->vx_usecnt) : 0,
9609 +               vxi ? atomic_read(&vxi->vx_tasks) : 0,
9610 +               task, _file, _line);
9611 +       __vxh_release_vx_info(vxi, task, _here);
9612 +
9613 +       might_sleep();
9614 +
9615 +       if (atomic_dec_and_test(&vxi->vx_tasks))
9616 +               unhash_vx_info(vxi);
9617 +}
9618 +
9619 +
9620 +#define task_get_vx_info(p) \
9621 +       __task_get_vx_info(p, __FILE__, __LINE__, __HERE__)
9622 +
9623 +static inline struct vx_info *__task_get_vx_info(struct task_struct *p,
9624 +       const char *_file, int _line, void *_here)
9625 +{
9626 +       struct vx_info *vxi;
9627 +
9628 +       task_lock(p);
9629 +       vxlprintk(VXD_CBIT(xid, 5), "task_get_vx_info(%p)",
9630 +               p, _file, _line);
9631 +       vxi = __get_vx_info(p->vx_info, _file, _line, _here);
9632 +       task_unlock(p);
9633 +       return vxi;
9634 +}
9635 +
9636 +
9637 +static inline void __wakeup_vx_info(struct vx_info *vxi)
9638 +{
9639 +       if (waitqueue_active(&vxi->vx_wait))
9640 +               wake_up_interruptible(&vxi->vx_wait);
9641 +}
9642 +
9643 +
9644 +#define enter_vx_info(v, s) __enter_vx_info(v, s, __FILE__, __LINE__)
9645 +
9646 +static inline void __enter_vx_info(struct vx_info *vxi,
9647 +       struct vx_info_save *vxis, const char *_file, int _line)
9648 +{
9649 +       vxlprintk(VXD_CBIT(xid, 5), "enter_vx_info(%p[#%d],%p) %p[#%d,%p]",
9650 +               vxi, vxi ? vxi->vx_id : 0, vxis, current,
9651 +               current->xid, current->vx_info, _file, _line);
9652 +       vxis->vxi = xchg(&current->vx_info, vxi);
9653 +       vxis->xid = current->xid;
9654 +       current->xid = vxi ? vxi->vx_id : 0;
9655 +}
9656 +
9657 +#define leave_vx_info(s) __leave_vx_info(s, __FILE__, __LINE__)
9658 +
9659 +static inline void __leave_vx_info(struct vx_info_save *vxis,
9660 +       const char *_file, int _line)
9661 +{
9662 +       vxlprintk(VXD_CBIT(xid, 5), "leave_vx_info(%p[#%d,%p]) %p[#%d,%p]",
9663 +               vxis, vxis->xid, vxis->vxi, current,
9664 +               current->xid, current->vx_info, _file, _line);
9665 +       (void)xchg(&current->vx_info, vxis->vxi);
9666 +       current->xid = vxis->xid;
9667 +}
9668 +
9669 +
9670 +static inline void __enter_vx_admin(struct vx_info_save *vxis)
9671 +{
9672 +       vxis->vxi = xchg(&current->vx_info, NULL);
9673 +       vxis->xid = xchg(&current->xid, (xid_t)0);
9674 +}
9675 +
9676 +static inline void __leave_vx_admin(struct vx_info_save *vxis)
9677 +{
9678 +       (void)xchg(&current->xid, vxis->xid);
9679 +       (void)xchg(&current->vx_info, vxis->vxi);
9680 +}
9681 +
9682 +#define task_is_init(p) \
9683 +       __task_is_init(p, __FILE__, __LINE__, __HERE__)
9684 +
9685 +static inline int __task_is_init(struct task_struct *p,
9686 +       const char *_file, int _line, void *_here)
9687 +{
9688 +       int is_init = is_global_init(p);
9689 +
9690 +       task_lock(p);
9691 +       if (p->vx_info)
9692 +               is_init = p->vx_info->vx_initpid == p->pid;
9693 +       task_unlock(p);
9694 +       return is_init;
9695 +}
9696 +
9697 +extern void exit_vx_info(struct task_struct *, int);
9698 +extern void exit_vx_info_early(struct task_struct *, int);
9699 +
9700 +
9701 +#else
9702 +#warning duplicate inclusion
9703 +#endif
9704 diff -NurpP --minimal linux-2.6.32.1/include/linux/vs_cowbl.h linux-2.6.32.1-vs2.3.0.36.27/include/linux/vs_cowbl.h
9705 --- linux-2.6.32.1/include/linux/vs_cowbl.h     1970-01-01 01:00:00.000000000 +0100
9706 +++ linux-2.6.32.1-vs2.3.0.36.27/include/linux/vs_cowbl.h       2009-12-03 20:04:56.000000000 +0100
9707 @@ -0,0 +1,47 @@
9708 +#ifndef _VS_COWBL_H
9709 +#define _VS_COWBL_H
9710 +
9711 +#include <linux/fs.h>
9712 +#include <linux/dcache.h>
9713 +#include <linux/namei.h>
9714 +
9715 +extern struct dentry *cow_break_link(const char *pathname);
9716 +
9717 +static inline int cow_check_and_break(struct path *path)
9718 +{
9719 +       struct inode *inode = path->dentry->d_inode;
9720 +       int error = 0;
9721 +
9722 +       /* do we need this check? */
9723 +       if (IS_RDONLY(inode))
9724 +               return -EROFS;
9725 +
9726 +       if (IS_COW(inode)) {
9727 +               if (IS_COW_LINK(inode)) {
9728 +                       struct dentry *new_dentry, *old_dentry = path->dentry;
9729 +                       char *pp, *buf;
9730 +
9731 +                       buf = kmalloc(PATH_MAX, GFP_KERNEL);
9732 +                       if (!buf) {
9733 +                               return -ENOMEM;
9734 +                       }
9735 +                       pp = d_path(path, buf, PATH_MAX);
9736 +                       new_dentry = cow_break_link(pp);
9737 +                       kfree(buf);
9738 +                       if (!IS_ERR(new_dentry)) {
9739 +                               path->dentry = new_dentry;
9740 +                               dput(old_dentry);
9741 +                       } else
9742 +                               error = PTR_ERR(new_dentry);
9743 +               } else {
9744 +                       inode->i_flags &= ~(S_IXUNLINK | S_IMMUTABLE);
9745 +                       inode->i_ctime = CURRENT_TIME;
9746 +                       mark_inode_dirty(inode);
9747 +               }
9748 +       }
9749 +       return error;
9750 +}
9751 +
9752 +#else
9753 +#warning duplicate inclusion
9754 +#endif
9755 diff -NurpP --minimal linux-2.6.32.1/include/linux/vs_cvirt.h linux-2.6.32.1-vs2.3.0.36.27/include/linux/vs_cvirt.h
9756 --- linux-2.6.32.1/include/linux/vs_cvirt.h     1970-01-01 01:00:00.000000000 +0100
9757 +++ linux-2.6.32.1-vs2.3.0.36.27/include/linux/vs_cvirt.h       2009-12-03 20:04:56.000000000 +0100
9758 @@ -0,0 +1,50 @@
9759 +#ifndef _VS_CVIRT_H
9760 +#define _VS_CVIRT_H
9761 +
9762 +#include "vserver/cvirt.h"
9763 +#include "vserver/context.h"
9764 +#include "vserver/base.h"
9765 +#include "vserver/check.h"
9766 +#include "vserver/debug.h"
9767 +
9768 +
9769 +static inline void vx_activate_task(struct task_struct *p)
9770 +{
9771 +       struct vx_info *vxi;
9772 +
9773 +       if ((vxi = p->vx_info)) {
9774 +               vx_update_load(vxi);
9775 +               atomic_inc(&vxi->cvirt.nr_running);
9776 +       }
9777 +}
9778 +
9779 +static inline void vx_deactivate_task(struct task_struct *p)
9780 +{
9781 +       struct vx_info *vxi;
9782 +
9783 +       if ((vxi = p->vx_info)) {
9784 +               vx_update_load(vxi);
9785 +               atomic_dec(&vxi->cvirt.nr_running);
9786 +       }
9787 +}
9788 +
9789 +static inline void vx_uninterruptible_inc(struct task_struct *p)
9790 +{
9791 +       struct vx_info *vxi;
9792 +
9793 +       if ((vxi = p->vx_info))
9794 +               atomic_inc(&vxi->cvirt.nr_uninterruptible);
9795 +}
9796 +
9797 +static inline void vx_uninterruptible_dec(struct task_struct *p)
9798 +{
9799 +       struct vx_info *vxi;
9800 +
9801 +       if ((vxi = p->vx_info))
9802 +               atomic_dec(&vxi->cvirt.nr_uninterruptible);
9803 +}
9804 +
9805 +
9806 +#else
9807 +#warning duplicate inclusion
9808 +#endif
9809 diff -NurpP --minimal linux-2.6.32.1/include/linux/vs_device.h linux-2.6.32.1-vs2.3.0.36.27/include/linux/vs_device.h
9810 --- linux-2.6.32.1/include/linux/vs_device.h    1970-01-01 01:00:00.000000000 +0100
9811 +++ linux-2.6.32.1-vs2.3.0.36.27/include/linux/vs_device.h      2009-12-03 20:04:56.000000000 +0100
9812 @@ -0,0 +1,45 @@
9813 +#ifndef _VS_DEVICE_H
9814 +#define _VS_DEVICE_H
9815 +
9816 +#include "vserver/base.h"
9817 +#include "vserver/device.h"
9818 +#include "vserver/debug.h"
9819 +
9820 +
9821 +#ifdef CONFIG_VSERVER_DEVICE
9822 +
9823 +int vs_map_device(struct vx_info *, dev_t, dev_t *, umode_t);
9824 +
9825 +#define vs_device_perm(v, d, m, p) \
9826 +       ((vs_map_device(current_vx_info(), d, NULL, m) & (p)) == (p))
9827 +
9828 +#else
9829 +
9830 +static inline
9831 +int vs_map_device(struct vx_info *vxi,
9832 +       dev_t device, dev_t *target, umode_t mode)
9833 +{
9834 +       if (target)
9835 +               *target = device;
9836 +       return ~0;
9837 +}
9838 +
9839 +#define vs_device_perm(v, d, m, p) ((p) == (p))
9840 +
9841 +#endif
9842 +
9843 +
9844 +#define vs_map_chrdev(d, t, p) \
9845 +       ((vs_map_device(current_vx_info(), d, t, S_IFCHR) & (p)) == (p))
9846 +#define vs_map_blkdev(d, t, p) \
9847 +       ((vs_map_device(current_vx_info(), d, t, S_IFBLK) & (p)) == (p))
9848 +
9849 +#define vs_chrdev_perm(d, p) \
9850 +       vs_device_perm(current_vx_info(), d, S_IFCHR, p)
9851 +#define vs_blkdev_perm(d, p) \
9852 +       vs_device_perm(current_vx_info(), d, S_IFBLK, p)
9853 +
9854 +
9855 +#else
9856 +#warning duplicate inclusion
9857 +#endif
9858 diff -NurpP --minimal linux-2.6.32.1/include/linux/vs_dlimit.h linux-2.6.32.1-vs2.3.0.36.27/include/linux/vs_dlimit.h
9859 --- linux-2.6.32.1/include/linux/vs_dlimit.h    1970-01-01 01:00:00.000000000 +0100
9860 +++ linux-2.6.32.1-vs2.3.0.36.27/include/linux/vs_dlimit.h      2009-12-03 20:04:56.000000000 +0100
9861 @@ -0,0 +1,216 @@
9862 +#ifndef _VS_DLIMIT_H
9863 +#define _VS_DLIMIT_H
9864 +
9865 +#include <linux/fs.h>
9866 +
9867 +#include "vserver/dlimit.h"
9868 +#include "vserver/base.h"
9869 +#include "vserver/debug.h"
9870 +
9871 +
9872 +#define get_dl_info(i) __get_dl_info(i, __FILE__, __LINE__)
9873 +
9874 +static inline struct dl_info *__get_dl_info(struct dl_info *dli,
9875 +       const char *_file, int _line)
9876 +{
9877 +       if (!dli)
9878 +               return NULL;
9879 +       vxlprintk(VXD_CBIT(dlim, 4), "get_dl_info(%p[#%d.%d])",
9880 +               dli, dli ? dli->dl_tag : 0,
9881 +               dli ? atomic_read(&dli->dl_usecnt) : 0,
9882 +               _file, _line);
9883 +       atomic_inc(&dli->dl_usecnt);
9884 +       return dli;
9885 +}
9886 +
9887 +
9888 +#define free_dl_info(i) \
9889 +       call_rcu(&(i)->dl_rcu, rcu_free_dl_info)
9890 +
9891 +#define put_dl_info(i) __put_dl_info(i, __FILE__, __LINE__)
9892 +
9893 +static inline void __put_dl_info(struct dl_info *dli,
9894 +       const char *_file, int _line)
9895 +{
9896 +       if (!dli)
9897 +               return;
9898 +       vxlprintk(VXD_CBIT(dlim, 4), "put_dl_info(%p[#%d.%d])",
9899 +               dli, dli ? dli->dl_tag : 0,
9900 +               dli ? atomic_read(&dli->dl_usecnt) : 0,
9901 +               _file, _line);
9902 +       if (atomic_dec_and_test(&dli->dl_usecnt))
9903 +               free_dl_info(dli);
9904 +}
9905 +
9906 +
9907 +#define __dlimit_char(d)       ((d) ? '*' : ' ')
9908 +
9909 +static inline int __dl_alloc_space(struct super_block *sb,
9910 +       tag_t tag, dlsize_t nr, const char *file, int line)
9911 +{
9912 +       struct dl_info *dli = NULL;
9913 +       int ret = 0;
9914 +
9915 +       if (nr == 0)
9916 +               goto out;
9917 +       dli = locate_dl_info(sb, tag);
9918 +       if (!dli)
9919 +               goto out;
9920 +
9921 +       spin_lock(&dli->dl_lock);
9922 +       ret = (dli->dl_space_used + nr > dli->dl_space_total);
9923 +       if (!ret)
9924 +               dli->dl_space_used += nr;
9925 +       spin_unlock(&dli->dl_lock);
9926 +       put_dl_info(dli);
9927 +out:
9928 +       vxlprintk(VXD_CBIT(dlim, 1),
9929 +               "ALLOC (%p,#%d)%c %lld bytes (%d)",
9930 +               sb, tag, __dlimit_char(dli), (long long)nr,
9931 +               ret, file, line);
9932 +       return ret;
9933 +}
9934 +
9935 +static inline void __dl_free_space(struct super_block *sb,
9936 +       tag_t tag, dlsize_t nr, const char *_file, int _line)
9937 +{
9938 +       struct dl_info *dli = NULL;
9939 +
9940 +       if (nr == 0)
9941 +               goto out;
9942 +       dli = locate_dl_info(sb, tag);
9943 +       if (!dli)
9944 +               goto out;
9945 +
9946 +       spin_lock(&dli->dl_lock);
9947 +       if (dli->dl_space_used > nr)
9948 +               dli->dl_space_used -= nr;
9949 +       else
9950 +               dli->dl_space_used = 0;
9951 +       spin_unlock(&dli->dl_lock);
9952 +       put_dl_info(dli);
9953 +out:
9954 +       vxlprintk(VXD_CBIT(dlim, 1),
9955 +               "FREE  (%p,#%d)%c %lld bytes",
9956 +               sb, tag, __dlimit_char(dli), (long long)nr,
9957 +               _file, _line);
9958 +}
9959 +
9960 +static inline int __dl_alloc_inode(struct super_block *sb,
9961 +       tag_t tag, const char *_file, int _line)
9962 +{
9963 +       struct dl_info *dli;
9964 +       int ret = 0;
9965 +
9966 +       dli = locate_dl_info(sb, tag);
9967 +       if (!dli)
9968 +               goto out;
9969 +
9970 +       spin_lock(&dli->dl_lock);
9971 +       ret = (dli->dl_inodes_used >= dli->dl_inodes_total);
9972 +       if (!ret)
9973 +               dli->dl_inodes_used++;
9974 +       spin_unlock(&dli->dl_lock);
9975 +       put_dl_info(dli);
9976 +out:
9977 +       vxlprintk(VXD_CBIT(dlim, 0),
9978 +               "ALLOC (%p,#%d)%c inode (%d)",
9979 +               sb, tag, __dlimit_char(dli), ret, _file, _line);
9980 +       return ret;
9981 +}
9982 +
9983 +static inline void __dl_free_inode(struct super_block *sb,
9984 +       tag_t tag, const char *_file, int _line)
9985 +{
9986 +       struct dl_info *dli;
9987 +
9988 +       dli = locate_dl_info(sb, tag);
9989 +       if (!dli)
9990 +               goto out;
9991 +
9992 +       spin_lock(&dli->dl_lock);
9993 +       if (dli->dl_inodes_used > 1)
9994 +               dli->dl_inodes_used--;
9995 +       else
9996 +               dli->dl_inodes_used = 0;
9997 +       spin_unlock(&dli->dl_lock);
9998 +       put_dl_info(dli);
9999 +out:
10000 +       vxlprintk(VXD_CBIT(dlim, 0),
10001 +               "FREE  (%p,#%d)%c inode",
10002 +               sb, tag, __dlimit_char(dli), _file, _line);
10003 +}
10004 +
10005 +static inline void __dl_adjust_block(struct super_block *sb, tag_t tag,
10006 +       unsigned long long *free_blocks, unsigned long long *root_blocks,
10007 +       const char *_file, int _line)
10008 +{
10009 +       struct dl_info *dli;
10010 +       uint64_t broot, bfree;
10011 +
10012 +       dli = locate_dl_info(sb, tag);
10013 +       if (!dli)
10014 +               return;
10015 +
10016 +       spin_lock(&dli->dl_lock);
10017 +       broot = (dli->dl_space_total -
10018 +               (dli->dl_space_total >> 10) * dli->dl_nrlmult)
10019 +               >> sb->s_blocksize_bits;
10020 +       bfree = (dli->dl_space_total - dli->dl_space_used)
10021 +                       >> sb->s_blocksize_bits;
10022 +       spin_unlock(&dli->dl_lock);
10023 +
10024 +       vxlprintk(VXD_CBIT(dlim, 2),
10025 +               "ADJUST: %lld,%lld on %lld,%lld [mult=%d]",
10026 +               (long long)bfree, (long long)broot,
10027 +               *free_blocks, *root_blocks, dli->dl_nrlmult,
10028 +               _file, _line);
10029 +       if (free_blocks) {
10030 +               if (*free_blocks > bfree)
10031 +                       *free_blocks = bfree;
10032 +       }
10033 +       if (root_blocks) {
10034 +               if (*root_blocks > broot)
10035 +                       *root_blocks = broot;
10036 +       }
10037 +       put_dl_info(dli);
10038 +}
10039 +
10040 +#define dl_prealloc_space(in, bytes) \
10041 +       __dl_alloc_space((in)->i_sb, (in)->i_tag, (dlsize_t)(bytes), \
10042 +               __FILE__, __LINE__ )
10043 +
10044 +#define dl_alloc_space(in, bytes) \
10045 +       __dl_alloc_space((in)->i_sb, (in)->i_tag, (dlsize_t)(bytes), \
10046 +               __FILE__, __LINE__ )
10047 +
10048 +#define dl_reserve_space(in, bytes) \
10049 +       __dl_alloc_space((in)->i_sb, (in)->i_tag, (dlsize_t)(bytes), \
10050 +               __FILE__, __LINE__ )
10051 +
10052 +#define dl_claim_space(in, bytes) (0)
10053 +
10054 +#define dl_release_space(in, bytes) \
10055 +       __dl_free_space((in)->i_sb, (in)->i_tag, (dlsize_t)(bytes), \
10056 +               __FILE__, __LINE__ )
10057 +
10058 +#define dl_free_space(in, bytes) \
10059 +       __dl_free_space((in)->i_sb, (in)->i_tag, (dlsize_t)(bytes), \
10060 +               __FILE__, __LINE__ )
10061 +
10062 +
10063 +
10064 +#define dl_alloc_inode(in) \
10065 +       __dl_alloc_inode((in)->i_sb, (in)->i_tag, __FILE__, __LINE__ )
10066 +
10067 +#define dl_free_inode(in) \
10068 +       __dl_free_inode((in)->i_sb, (in)->i_tag, __FILE__, __LINE__ )
10069 +
10070 +
10071 +#define dl_adjust_block(sb, tag, fb, rb) \
10072 +       __dl_adjust_block(sb, tag, fb, rb, __FILE__, __LINE__ )
10073 +
10074 +
10075 +#else
10076 +#warning duplicate inclusion
10077 +#endif
10078 diff -NurpP --minimal linux-2.6.32.1/include/linux/vserver/base.h linux-2.6.32.1-vs2.3.0.36.27/include/linux/vserver/base.h
10079 --- linux-2.6.32.1/include/linux/vserver/base.h 1970-01-01 01:00:00.000000000 +0100
10080 +++ linux-2.6.32.1-vs2.3.0.36.27/include/linux/vserver/base.h   2009-12-03 20:04:56.000000000 +0100
10081 @@ -0,0 +1,170 @@
10082 +#ifndef _VX_BASE_H
10083 +#define _VX_BASE_H
10084 +
10085 +
10086 +/* context state changes */
10087 +
10088 +enum {
10089 +       VSC_STARTUP = 1,
10090 +       VSC_SHUTDOWN,
10091 +
10092 +       VSC_NETUP,
10093 +       VSC_NETDOWN,
10094 +};
10095 +
10096 +
10097 +
10098 +#define vx_task_xid(t) ((t)->xid)
10099 +
10100 +#define vx_current_xid() vx_task_xid(current)
10101 +
10102 +#define current_vx_info() (current->vx_info)
10103 +
10104 +
10105 +#define nx_task_nid(t) ((t)->nid)
10106 +
10107 +#define nx_current_nid() nx_task_nid(current)
10108 +
10109 +#define current_nx_info() (current->nx_info)
10110 +
10111 +
10112 +/* generic flag merging */
10113 +
10114 +#define vs_check_flags(v, m, f)        (((v) & (m)) ^ (f))
10115 +
10116 +#define vs_mask_flags(v, f, m) (((v) & ~(m)) | ((f) & (m)))
10117 +
10118 +#define vs_mask_mask(v, f, m)  (((v) & ~(m)) | ((v) & (f) & (m)))
10119 +
10120 +#define vs_check_bit(v, n)     ((v) & (1LL << (n)))
10121 +
10122 +
10123 +/* context flags */
10124 +
10125 +#define __vx_flags(v)  ((v) ? (v)->vx_flags : 0)
10126 +
10127 +#define vx_current_flags()     __vx_flags(current_vx_info())
10128 +
10129 +#define vx_info_flags(v, m, f) \
10130 +       vs_check_flags(__vx_flags(v), m, f)
10131 +
10132 +#define task_vx_flags(t, m, f) \
10133 +       ((t) && vx_info_flags((t)->vx_info, m, f))
10134 +
10135 +#define vx_flags(m, f) vx_info_flags(current_vx_info(), m, f)
10136 +
10137 +
10138 +/* context caps */
10139 +
10140 +#define __vx_ccaps(v)  ((v) ? (v)->vx_ccaps : 0)
10141 +
10142 +#define vx_current_ccaps()     __vx_ccaps(current_vx_info())
10143 +
10144 +#define vx_info_ccaps(v, c)    (__vx_ccaps(v) & (c))
10145 +
10146 +#define vx_ccaps(c)    vx_info_ccaps(current_vx_info(), (c))
10147 +
10148 +
10149 +
10150 +/* network flags */
10151 +
10152 +#define __nx_flags(n)  ((n) ? (n)->nx_flags : 0)
10153 +
10154 +#define nx_current_flags()     __nx_flags(current_nx_info())
10155 +
10156 +#define nx_info_flags(n, m, f) \
10157 +       vs_check_flags(__nx_flags(n), m, f)
10158 +
10159 +#define task_nx_flags(t, m, f) \
10160 +       ((t) && nx_info_flags((t)->nx_info, m, f))
10161 +
10162 +#define nx_flags(m, f) nx_info_flags(current_nx_info(), m, f)
10163 +
10164 +
10165 +/* network caps */
10166 +
10167 +#define __nx_ncaps(n)  ((n) ? (n)->nx_ncaps : 0)
10168 +
10169 +#define nx_current_ncaps()     __nx_ncaps(current_nx_info())
10170 +
10171 +#define nx_info_ncaps(n, c)    (__nx_ncaps(n) & (c))
10172 +
10173 +#define nx_ncaps(c)    nx_info_ncaps(current_nx_info(), c)
10174 +
10175 +
10176 +/* context mask capabilities */
10177 +
10178 +#define __vx_mcaps(v)  ((v) ? (v)->vx_ccaps >> 32UL : ~0 )
10179 +
10180 +#define vx_info_mcaps(v, c)    (__vx_mcaps(v) & (c))
10181 +
10182 +#define vx_mcaps(c)    vx_info_mcaps(current_vx_info(), c)
10183 +
10184 +
10185 +/* context bcap mask */
10186 +
10187 +#define __vx_bcaps(v)          ((v)->vx_bcaps)
10188 +
10189 +#define vx_current_bcaps()     __vx_bcaps(current_vx_info())
10190 +
10191 +
10192 +/* mask given bcaps */
10193 +
10194 +#define vx_info_mbcaps(v, c)   ((v) ? cap_intersect(__vx_bcaps(v), c) : c)
10195 +
10196 +#define vx_mbcaps(c)           vx_info_mbcaps(current_vx_info(), c)
10197 +
10198 +
10199 +/* masked cap_bset */
10200 +
10201 +#define vx_info_cap_bset(v)    vx_info_mbcaps(v, current->cap_bset)
10202 +
10203 +#define vx_current_cap_bset()  vx_info_cap_bset(current_vx_info())
10204 +
10205 +#if 0
10206 +#define vx_info_mbcap(v, b) \
10207 +       (!vx_info_flags(v, VXF_STATE_SETUP, 0) ? \
10208 +       vx_info_bcaps(v, b) : (b))
10209 +
10210 +#define task_vx_mbcap(t, b) \
10211 +       vx_info_mbcap((t)->vx_info, (t)->b)
10212 +
10213 +#define vx_mbcap(b)    task_vx_mbcap(current, b)
10214 +#endif
10215 +
10216 +#define vx_cap_raised(v, c, f) cap_raised(vx_info_mbcaps(v, c), f)
10217 +
10218 +#define vx_capable(b, c) (capable(b) || \
10219 +       (cap_raised(current_cap(), b) && vx_ccaps(c)))
10220 +
10221 +#define nx_capable(b, c) (capable(b) || \
10222 +       (cap_raised(current_cap(), b) && nx_ncaps(c)))
10223 +
10224 +#define vx_task_initpid(t, n) \
10225 +       ((t)->vx_info && \
10226 +       ((t)->vx_info->vx_initpid == (n)))
10227 +
10228 +#define vx_current_initpid(n)  vx_task_initpid(current, n)
10229 +
10230 +
10231 +/* context unshare mask */
10232 +
10233 +#define __vx_umask(v)          ((v)->vx_umask)
10234 +
10235 +#define vx_current_umask()     __vx_umask(current_vx_info())
10236 +
10237 +#define vx_can_unshare(b, f) (capable(b) || \
10238 +       (cap_raised(current_cap(), b) && \
10239 +       !((f) & ~vx_current_umask())))
10240 +
10241 +
10242 +#define __vx_state(v)  ((v) ? ((v)->vx_state) : 0)
10243 +
10244 +#define vx_info_state(v, m)    (__vx_state(v) & (m))
10245 +
10246 +
10247 +#define __nx_state(n)  ((n) ? ((n)->nx_state) : 0)
10248 +
10249 +#define nx_info_state(n, m)    (__nx_state(n) & (m))
10250 +
10251 +#endif
10252 diff -NurpP --minimal linux-2.6.32.1/include/linux/vserver/cacct_cmd.h linux-2.6.32.1-vs2.3.0.36.27/include/linux/vserver/cacct_cmd.h
10253 --- linux-2.6.32.1/include/linux/vserver/cacct_cmd.h    1970-01-01 01:00:00.000000000 +0100
10254 +++ linux-2.6.32.1-vs2.3.0.36.27/include/linux/vserver/cacct_cmd.h      2009-12-03 20:04:56.000000000 +0100
10255 @@ -0,0 +1,23 @@
10256 +#ifndef _VX_CACCT_CMD_H
10257 +#define _VX_CACCT_CMD_H
10258 +
10259 +
10260 +/* virtual host info name commands */
10261 +
10262 +#define VCMD_sock_stat         VC_CMD(VSTAT, 5, 0)
10263 +
10264 +struct vcmd_sock_stat_v0 {
10265 +       uint32_t field;
10266 +       uint32_t count[3];
10267 +       uint64_t total[3];
10268 +};
10269 +
10270 +
10271 +#ifdef __KERNEL__
10272 +
10273 +#include <linux/compiler.h>
10274 +
10275 +extern int vc_sock_stat(struct vx_info *, void __user *);
10276 +
10277 +#endif /* __KERNEL__ */
10278 +#endif /* _VX_CACCT_CMD_H */
10279 diff -NurpP --minimal linux-2.6.32.1/include/linux/vserver/cacct_def.h linux-2.6.32.1-vs2.3.0.36.27/include/linux/vserver/cacct_def.h
10280 --- linux-2.6.32.1/include/linux/vserver/cacct_def.h    1970-01-01 01:00:00.000000000 +0100
10281 +++ linux-2.6.32.1-vs2.3.0.36.27/include/linux/vserver/cacct_def.h      2009-12-03 20:04:56.000000000 +0100
10282 @@ -0,0 +1,43 @@
10283 +#ifndef _VX_CACCT_DEF_H
10284 +#define _VX_CACCT_DEF_H
10285 +
10286 +#include <asm/atomic.h>
10287 +#include <linux/vserver/cacct.h>
10288 +
10289 +
10290 +struct _vx_sock_acc {
10291 +       atomic_long_t count;
10292 +       atomic_long_t total;
10293 +};
10294 +
10295 +/* context sub struct */
10296 +
10297 +struct _vx_cacct {
10298 +       struct _vx_sock_acc sock[VXA_SOCK_SIZE][3];
10299 +       atomic_t slab[8];
10300 +       atomic_t page[6][8];
10301 +};
10302 +
10303 +#ifdef CONFIG_VSERVER_DEBUG
10304 +
10305 +static inline void __dump_vx_cacct(struct _vx_cacct *cacct)
10306 +{
10307 +       int i, j;
10308 +
10309 +       printk("\t_vx_cacct:");
10310 +       for (i = 0; i < 6; i++) {
10311 +               struct _vx_sock_acc *ptr = cacct->sock[i];
10312 +
10313 +               printk("\t [%d] =", i);
10314 +               for (j = 0; j < 3; j++) {
10315 +                       printk(" [%d] = %8lu, %8lu", j,
10316 +                               atomic_long_read(&ptr[j].count),
10317 +                               atomic_long_read(&ptr[j].total));
10318 +               }
10319 +               printk("\n");
10320 +       }
10321 +}
10322 +
10323 +#endif
10324 +
10325 +#endif /* _VX_CACCT_DEF_H */
10326 diff -NurpP --minimal linux-2.6.32.1/include/linux/vserver/cacct.h linux-2.6.32.1-vs2.3.0.36.27/include/linux/vserver/cacct.h
10327 --- linux-2.6.32.1/include/linux/vserver/cacct.h        1970-01-01 01:00:00.000000000 +0100
10328 +++ linux-2.6.32.1-vs2.3.0.36.27/include/linux/vserver/cacct.h  2009-12-03 20:04:56.000000000 +0100
10329 @@ -0,0 +1,15 @@
10330 +#ifndef _VX_CACCT_H
10331 +#define _VX_CACCT_H
10332 +
10333 +
10334 +enum sock_acc_field {
10335 +       VXA_SOCK_UNSPEC = 0,
10336 +       VXA_SOCK_UNIX,
10337 +       VXA_SOCK_INET,
10338 +       VXA_SOCK_INET6,
10339 +       VXA_SOCK_PACKET,
10340 +       VXA_SOCK_OTHER,
10341 +       VXA_SOCK_SIZE   /* array size */
10342 +};
10343 +
10344 +#endif /* _VX_CACCT_H */
10345 diff -NurpP --minimal linux-2.6.32.1/include/linux/vserver/cacct_int.h linux-2.6.32.1-vs2.3.0.36.27/include/linux/vserver/cacct_int.h
10346 --- linux-2.6.32.1/include/linux/vserver/cacct_int.h    1970-01-01 01:00:00.000000000 +0100
10347 +++ linux-2.6.32.1-vs2.3.0.36.27/include/linux/vserver/cacct_int.h      2009-12-03 20:04:56.000000000 +0100
10348 @@ -0,0 +1,21 @@
10349 +#ifndef _VX_CACCT_INT_H
10350 +#define _VX_CACCT_INT_H
10351 +
10352 +
10353 +#ifdef __KERNEL__
10354 +
10355 +static inline
10356 +unsigned long vx_sock_count(struct _vx_cacct *cacct, int type, int pos)
10357 +{
10358 +       return atomic_long_read(&cacct->sock[type][pos].count);
10359 +}
10360 +
10361 +
10362 +static inline
10363 +unsigned long vx_sock_total(struct _vx_cacct *cacct, int type, int pos)
10364 +{
10365 +       return atomic_long_read(&cacct->sock[type][pos].total);
10366 +}
10367 +
10368 +#endif /* __KERNEL__ */
10369 +#endif /* _VX_CACCT_INT_H */
10370 diff -NurpP --minimal linux-2.6.32.1/include/linux/vserver/check.h linux-2.6.32.1-vs2.3.0.36.27/include/linux/vserver/check.h
10371 --- linux-2.6.32.1/include/linux/vserver/check.h        1970-01-01 01:00:00.000000000 +0100
10372 +++ linux-2.6.32.1-vs2.3.0.36.27/include/linux/vserver/check.h  2009-12-03 20:04:56.000000000 +0100
10373 @@ -0,0 +1,89 @@
10374 +#ifndef _VS_CHECK_H
10375 +#define _VS_CHECK_H
10376 +
10377 +
10378 +#define MAX_S_CONTEXT  65535   /* Arbitrary limit */
10379 +
10380 +#ifdef CONFIG_VSERVER_DYNAMIC_IDS
10381 +#define MIN_D_CONTEXT  49152   /* dynamic contexts start here */
10382 +#else
10383 +#define MIN_D_CONTEXT  65536
10384 +#endif
10385 +
10386 +/* check conditions */
10387 +
10388 +#define VS_ADMIN       0x0001
10389 +#define VS_WATCH       0x0002
10390 +#define VS_HIDE                0x0004
10391 +#define VS_HOSTID      0x0008
10392 +
10393 +#define VS_IDENT       0x0010
10394 +#define VS_EQUIV       0x0020
10395 +#define VS_PARENT      0x0040
10396 +#define VS_CHILD       0x0080
10397 +
10398 +#define VS_ARG_MASK    0x00F0
10399 +
10400 +#define VS_DYNAMIC     0x0100
10401 +#define VS_STATIC      0x0200
10402 +
10403 +#define VS_ATR_MASK    0x0F00
10404 +
10405 +#ifdef CONFIG_VSERVER_PRIVACY
10406 +#define VS_ADMIN_P     (0)
10407 +#define VS_WATCH_P     (0)
10408 +#else
10409 +#define VS_ADMIN_P     VS_ADMIN
10410 +#define VS_WATCH_P     VS_WATCH
10411 +#endif
10412 +
10413 +#define VS_HARDIRQ     0x1000
10414 +#define VS_SOFTIRQ     0x2000
10415 +#define VS_IRQ         0x4000
10416 +
10417 +#define VS_IRQ_MASK    0xF000
10418 +
10419 +#include <linux/hardirq.h>
10420 +
10421 +/*
10422 + * check current context for ADMIN/WATCH and
10423 + * optionally against supplied argument
10424 + */
10425 +static inline int __vs_check(int cid, int id, unsigned int mode)
10426 +{
10427 +       if (mode & VS_ARG_MASK) {
10428 +               if ((mode & VS_IDENT) && (id == cid))
10429 +                       return 1;
10430 +       }
10431 +       if (mode & VS_ATR_MASK) {
10432 +               if ((mode & VS_DYNAMIC) &&
10433 +                       (id >= MIN_D_CONTEXT) &&
10434 +                       (id <= MAX_S_CONTEXT))
10435 +                       return 1;
10436 +               if ((mode & VS_STATIC) &&
10437 +                       (id > 1) && (id < MIN_D_CONTEXT))
10438 +                       return 1;
10439 +       }
10440 +       if (mode & VS_IRQ_MASK) {
10441 +               if ((mode & VS_IRQ) && unlikely(in_interrupt()))
10442 +                       return 1;
10443 +               if ((mode & VS_HARDIRQ) && unlikely(in_irq()))
10444 +                       return 1;
10445 +               if ((mode & VS_SOFTIRQ) && unlikely(in_softirq()))
10446 +                       return 1;
10447 +       }
10448 +       return (((mode & VS_ADMIN) && (cid == 0)) ||
10449 +               ((mode & VS_WATCH) && (cid == 1)) ||
10450 +               ((mode & VS_HOSTID) && (id == 0)));
10451 +}
10452 +
10453 +#define vx_check(c, m) __vs_check(vx_current_xid(), c, (m) | VS_IRQ)
10454 +
10455 +#define vx_weak_check(c, m)    ((m) ? vx_check(c, m) : 1)
10456 +
10457 +
10458 +#define nx_check(c, m) __vs_check(nx_current_nid(), c, m)
10459 +
10460 +#define nx_weak_check(c, m)    ((m) ? nx_check(c, m) : 1)
10461 +
10462 +#endif
10463 diff -NurpP --minimal linux-2.6.32.1/include/linux/vserver/context_cmd.h linux-2.6.32.1-vs2.3.0.36.27/include/linux/vserver/context_cmd.h
10464 --- linux-2.6.32.1/include/linux/vserver/context_cmd.h  1970-01-01 01:00:00.000000000 +0100
10465 +++ linux-2.6.32.1-vs2.3.0.36.27/include/linux/vserver/context_cmd.h    2009-12-03 20:04:56.000000000 +0100
10466 @@ -0,0 +1,145 @@
10467 +#ifndef _VX_CONTEXT_CMD_H
10468 +#define _VX_CONTEXT_CMD_H
10469 +
10470 +
10471 +/* vinfo commands */
10472 +
10473 +#define VCMD_task_xid          VC_CMD(VINFO, 1, 0)
10474 +
10475 +#ifdef __KERNEL__
10476 +extern int vc_task_xid(uint32_t);
10477 +
10478 +#endif /* __KERNEL__ */
10479 +
10480 +#define VCMD_vx_info           VC_CMD(VINFO, 5, 0)
10481 +
10482 +struct vcmd_vx_info_v0 {
10483 +       uint32_t xid;
10484 +       uint32_t initpid;
10485 +       /* more to come */
10486 +};
10487 +
10488 +#ifdef __KERNEL__
10489 +extern int vc_vx_info(struct vx_info *, void __user *);
10490 +
10491 +#endif /* __KERNEL__ */
10492 +
10493 +#define VCMD_ctx_stat          VC_CMD(VSTAT, 0, 0)
10494 +
10495 +struct vcmd_ctx_stat_v0 {
10496 +       uint32_t usecnt;
10497 +       uint32_t tasks;
10498 +       /* more to come */
10499 +};
10500 +
10501 +#ifdef __KERNEL__
10502 +extern int vc_ctx_stat(struct vx_info *, void __user *);
10503 +
10504 +#endif /* __KERNEL__ */
10505 +
10506 +/* context commands */
10507 +
10508 +#define VCMD_ctx_create_v0     VC_CMD(VPROC, 1, 0)
10509 +#define VCMD_ctx_create                VC_CMD(VPROC, 1, 1)
10510 +
10511 +struct vcmd_ctx_create {
10512 +       uint64_t flagword;
10513 +};
10514 +
10515 +#define VCMD_ctx_migrate_v0    VC_CMD(PROCMIG, 1, 0)
10516 +#define VCMD_ctx_migrate       VC_CMD(PROCMIG, 1, 1)
10517 +
10518 +struct vcmd_ctx_migrate {
10519 +       uint64_t flagword;
10520 +};
10521 +
10522 +#ifdef __KERNEL__
10523 +extern int vc_ctx_create(uint32_t, void __user *);
10524 +extern int vc_ctx_migrate(struct vx_info *, void __user *);
10525 +
10526 +#endif /* __KERNEL__ */
10527 +
10528 +
10529 +/* flag commands */
10530 +
10531 +#define VCMD_get_cflags                VC_CMD(FLAGS, 1, 0)
10532 +#define VCMD_set_cflags                VC_CMD(FLAGS, 2, 0)
10533 +
10534 +struct vcmd_ctx_flags_v0 {
10535 +       uint64_t flagword;
10536 +       uint64_t mask;
10537 +};
10538 +
10539 +#ifdef __KERNEL__
10540 +extern int vc_get_cflags(struct vx_info *, void __user *);
10541 +extern int vc_set_cflags(struct vx_info *, void __user *);
10542 +
10543 +#endif /* __KERNEL__ */
10544 +
10545 +
10546 +/* context caps commands */
10547 +
10548 +#define VCMD_get_ccaps         VC_CMD(FLAGS, 3, 1)
10549 +#define VCMD_set_ccaps         VC_CMD(FLAGS, 4, 1)
10550 +
10551 +struct vcmd_ctx_caps_v1 {
10552 +       uint64_t ccaps;
10553 +       uint64_t cmask;
10554 +};
10555 +
10556 +#ifdef __KERNEL__
10557 +extern int vc_get_ccaps(struct vx_info *, void __user *);
10558 +extern int vc_set_ccaps(struct vx_info *, void __user *);
10559 +
10560 +#endif /* __KERNEL__ */
10561 +
10562 +
10563 +/* bcaps commands */
10564 +
10565 +#define VCMD_get_bcaps         VC_CMD(FLAGS, 9, 0)
10566 +#define VCMD_set_bcaps         VC_CMD(FLAGS, 10, 0)
10567 +
10568 +struct vcmd_bcaps {
10569 +       uint64_t bcaps;
10570 +       uint64_t bmask;
10571 +};
10572 +
10573 +#ifdef __KERNEL__
10574 +extern int vc_get_bcaps(struct vx_info *, void __user *);
10575 +extern int vc_set_bcaps(struct vx_info *, void __user *);
10576 +
10577 +#endif /* __KERNEL__ */
10578 +
10579 +
10580 +/* umask commands */
10581 +
10582 +#define VCMD_get_umask         VC_CMD(FLAGS, 13, 0)
10583 +#define VCMD_set_umask         VC_CMD(FLAGS, 14, 0)
10584 +
10585 +struct vcmd_umask {
10586 +       uint64_t umask;
10587 +       uint64_t mask;
10588 +};
10589 +
10590 +#ifdef __KERNEL__
10591 +extern int vc_get_umask(struct vx_info *, void __user *);
10592 +extern int vc_set_umask(struct vx_info *, void __user *);
10593 +
10594 +#endif /* __KERNEL__ */
10595 +
10596 +
10597 +/* OOM badness */
10598 +
10599 +#define VCMD_get_badness       VC_CMD(MEMCTRL, 5, 0)
10600 +#define VCMD_set_badness       VC_CMD(MEMCTRL, 6, 0)
10601 +
10602 +struct vcmd_badness_v0 {
10603 +       int64_t bias;
10604 +};
10605 +
10606 +#ifdef __KERNEL__
10607 +extern int vc_get_badness(struct vx_info *, void __user *);
10608 +extern int vc_set_badness(struct vx_info *, void __user *);
10609 +
10610 +#endif /* __KERNEL__ */
10611 +#endif /* _VX_CONTEXT_CMD_H */
10612 diff -NurpP --minimal linux-2.6.32.1/include/linux/vserver/context.h linux-2.6.32.1-vs2.3.0.36.27/include/linux/vserver/context.h
10613 --- linux-2.6.32.1/include/linux/vserver/context.h      1970-01-01 01:00:00.000000000 +0100
10614 +++ linux-2.6.32.1-vs2.3.0.36.27/include/linux/vserver/context.h        2009-12-03 20:04:56.000000000 +0100
10615 @@ -0,0 +1,183 @@
10616 +#ifndef _VX_CONTEXT_H
10617 +#define _VX_CONTEXT_H
10618 +
10619 +#include <linux/types.h>
10620 +#include <linux/capability.h>
10621 +
10622 +
10623 +/* context flags */
10624 +
10625 +#define VXF_INFO_SCHED         0x00000002
10626 +#define VXF_INFO_NPROC         0x00000004
10627 +#define VXF_INFO_PRIVATE       0x00000008
10628 +
10629 +#define VXF_INFO_INIT          0x00000010
10630 +#define VXF_INFO_HIDE          0x00000020
10631 +#define VXF_INFO_ULIMIT                0x00000040
10632 +#define VXF_INFO_NSPACE                0x00000080
10633 +
10634 +#define VXF_SCHED_HARD         0x00000100
10635 +#define VXF_SCHED_PRIO         0x00000200
10636 +#define VXF_SCHED_PAUSE                0x00000400
10637 +
10638 +#define VXF_VIRT_MEM           0x00010000
10639 +#define VXF_VIRT_UPTIME                0x00020000
10640 +#define VXF_VIRT_CPU           0x00040000
10641 +#define VXF_VIRT_LOAD          0x00080000
10642 +#define VXF_VIRT_TIME          0x00100000
10643 +
10644 +#define VXF_HIDE_MOUNT         0x01000000
10645 +/* was VXF_HIDE_NETIF          0x02000000 */
10646 +#define VXF_HIDE_VINFO         0x04000000
10647 +
10648 +#define VXF_STATE_SETUP                (1ULL << 32)
10649 +#define VXF_STATE_INIT         (1ULL << 33)
10650 +#define VXF_STATE_ADMIN                (1ULL << 34)
10651 +
10652 +#define VXF_SC_HELPER          (1ULL << 36)
10653 +#define VXF_REBOOT_KILL                (1ULL << 37)
10654 +#define VXF_PERSISTENT         (1ULL << 38)
10655 +
10656 +#define VXF_FORK_RSS           (1ULL << 48)
10657 +#define VXF_PROLIFIC           (1ULL << 49)
10658 +
10659 +#define VXF_IGNEG_NICE         (1ULL << 52)
10660 +
10661 +#define VXF_ONE_TIME           (0x0007ULL << 32)
10662 +
10663 +#define VXF_INIT_SET           (VXF_STATE_SETUP | VXF_STATE_INIT | VXF_STATE_ADMIN)
10664 +
10665 +
10666 +/* context migration */
10667 +
10668 +#define VXM_SET_INIT           0x00000001
10669 +#define VXM_SET_REAPER         0x00000002
10670 +
10671 +/* context caps */
10672 +
10673 +#define VXC_CAP_MASK           0x00000000
10674 +
10675 +#define VXC_SET_UTSNAME                0x00000001
10676 +#define VXC_SET_RLIMIT         0x00000002
10677 +#define VXC_FS_SECURITY                0x00000004
10678 +#define VXC_TIOCSTI            0x00000010
10679 +
10680 +/* was VXC_RAW_ICMP            0x00000100 */
10681 +#define VXC_SYSLOG             0x00001000
10682 +#define VXC_OOM_ADJUST         0x00002000
10683 +#define VXC_AUDIT_CONTROL      0x00004000
10684 +
10685 +#define VXC_SECURE_MOUNT       0x00010000
10686 +#define VXC_SECURE_REMOUNT     0x00020000
10687 +#define VXC_BINARY_MOUNT       0x00040000
10688 +
10689 +#define VXC_QUOTA_CTL          0x00100000
10690 +#define VXC_ADMIN_MAPPER       0x00200000
10691 +#define VXC_ADMIN_CLOOP                0x00400000
10692 +
10693 +#define VXC_KTHREAD            0x01000000
10694 +#define VXC_NAMESPACE          0x02000000
10695 +
10696 +
10697 +#ifdef __KERNEL__
10698 +
10699 +#include <linux/list.h>
10700 +#include <linux/spinlock.h>
10701 +#include <linux/rcupdate.h>
10702 +
10703 +#include "limit_def.h"
10704 +#include "sched_def.h"
10705 +#include "cvirt_def.h"
10706 +#include "cacct_def.h"
10707 +#include "device_def.h"
10708 +
10709 +#define VX_SPACES      2
10710 +
10711 +struct _vx_info_pc {
10712 +       struct _vx_sched_pc sched_pc;
10713 +       struct _vx_cvirt_pc cvirt_pc;
10714 +};
10715 +
10716 +struct vx_info {
10717 +       struct hlist_node vx_hlist;             /* linked list of contexts */
10718 +       xid_t vx_id;                            /* context id */
10719 +       atomic_t vx_usecnt;                     /* usage count */
10720 +       atomic_t vx_tasks;                      /* tasks count */
10721 +       struct vx_info *vx_parent;              /* parent context */
10722 +       int vx_state;                           /* context state */
10723 +
10724 +       unsigned long vx_nsmask[VX_SPACES];     /* assignment mask */
10725 +       struct nsproxy *vx_nsproxy[VX_SPACES];  /* private namespaces */
10726 +       struct fs_struct *vx_fs[VX_SPACES];     /* private namespace fs */
10727 +
10728 +       uint64_t vx_flags;                      /* context flags */
10729 +       uint64_t vx_ccaps;                      /* context caps (vserver) */
10730 +       kernel_cap_t vx_bcaps;                  /* bounding caps (system) */
10731 +       unsigned long vx_umask;                 /* unshare mask (guest) */
10732 +
10733 +       struct task_struct *vx_reaper;          /* guest reaper process */
10734 +       pid_t vx_initpid;                       /* PID of guest init */
10735 +       int64_t vx_badness_bias;                /* OOM points bias */
10736 +
10737 +       struct _vx_limit limit;                 /* vserver limits */
10738 +       struct _vx_sched sched;                 /* vserver scheduler */
10739 +       struct _vx_cvirt cvirt;                 /* virtual/bias stuff */
10740 +       struct _vx_cacct cacct;                 /* context accounting */
10741 +
10742 +       struct _vx_device dmap;                 /* default device map targets */
10743 +
10744 +#ifndef CONFIG_SMP
10745 +       struct _vx_info_pc info_pc;             /* per cpu data */
10746 +#else
10747 +       struct _vx_info_pc *ptr_pc;             /* per cpu array */
10748 +#endif
10749 +
10750 +       wait_queue_head_t vx_wait;              /* context exit waitqueue */
10751 +       int reboot_cmd;                         /* last sys_reboot() cmd */
10752 +       int exit_code;                          /* last process exit code */
10753 +
10754 +       char vx_name[65];                       /* vserver name */
10755 +};
10756 +
10757 +#ifndef CONFIG_SMP
10758 +#define        vx_ptr_pc(vxi)          (&(vxi)->info_pc)
10759 +#define        vx_per_cpu(vxi, v, id)  vx_ptr_pc(vxi)->v
10760 +#else
10761 +#define        vx_ptr_pc(vxi)          ((vxi)->ptr_pc)
10762 +#define        vx_per_cpu(vxi, v, id)  per_cpu_ptr(vx_ptr_pc(vxi), id)->v
10763 +#endif
10764 +
10765 +#define        vx_cpu(vxi, v)          vx_per_cpu(vxi, v, smp_processor_id())
10766 +
10767 +
10768 +struct vx_info_save {
10769 +       struct vx_info *vxi;
10770 +       xid_t xid;
10771 +};
10772 +
10773 +
10774 +/* status flags */
10775 +
10776 +#define VXS_HASHED     0x0001
10777 +#define VXS_PAUSED     0x0010
10778 +#define VXS_SHUTDOWN   0x0100
10779 +#define VXS_HELPER     0x1000
10780 +#define VXS_RELEASED   0x8000
10781 +
10782 +
10783 +extern void claim_vx_info(struct vx_info *, struct task_struct *);
10784 +extern void release_vx_info(struct vx_info *, struct task_struct *);
10785 +
10786 +extern struct vx_info *lookup_vx_info(int);
10787 +extern struct vx_info *lookup_or_create_vx_info(int);
10788 +
10789 +extern int get_xid_list(int, unsigned int *, int);
10790 +extern int xid_is_hashed(xid_t);
10791 +
10792 +extern int vx_migrate_task(struct task_struct *, struct vx_info *, int);
10793 +
10794 +extern long vs_state_change(struct vx_info *, unsigned int);
10795 +
10796 +
10797 +#endif /* __KERNEL__ */
10798 +#endif /* _VX_CONTEXT_H */
10799 diff -NurpP --minimal linux-2.6.32.1/include/linux/vserver/cvirt_cmd.h linux-2.6.32.1-vs2.3.0.36.27/include/linux/vserver/cvirt_cmd.h
10800 --- linux-2.6.32.1/include/linux/vserver/cvirt_cmd.h    1970-01-01 01:00:00.000000000 +0100
10801 +++ linux-2.6.32.1-vs2.3.0.36.27/include/linux/vserver/cvirt_cmd.h      2009-12-03 20:04:56.000000000 +0100
10802 @@ -0,0 +1,53 @@
10803 +#ifndef _VX_CVIRT_CMD_H
10804 +#define _VX_CVIRT_CMD_H
10805 +
10806 +
10807 +/* virtual host info name commands */
10808 +
10809 +#define VCMD_set_vhi_name      VC_CMD(VHOST, 1, 0)
10810 +#define VCMD_get_vhi_name      VC_CMD(VHOST, 2, 0)
10811 +
10812 +struct vcmd_vhi_name_v0 {
10813 +       uint32_t field;
10814 +       char name[65];
10815 +};
10816 +
10817 +
10818 +enum vhi_name_field {
10819 +       VHIN_CONTEXT = 0,
10820 +       VHIN_SYSNAME,
10821 +       VHIN_NODENAME,
10822 +       VHIN_RELEASE,
10823 +       VHIN_VERSION,
10824 +       VHIN_MACHINE,
10825 +       VHIN_DOMAINNAME,
10826 +};
10827 +
10828 +
10829 +#ifdef __KERNEL__
10830 +
10831 +#include <linux/compiler.h>
10832 +
10833 +extern int vc_set_vhi_name(struct vx_info *, void __user *);
10834 +extern int vc_get_vhi_name(struct vx_info *, void __user *);
10835 +
10836 +#endif /* __KERNEL__ */
10837 +
10838 +#define VCMD_virt_stat         VC_CMD(VSTAT, 3, 0)
10839 +
10840 +struct vcmd_virt_stat_v0 {
10841 +       uint64_t offset;
10842 +       uint64_t uptime;
10843 +       uint32_t nr_threads;
10844 +       uint32_t nr_running;
10845 +       uint32_t nr_uninterruptible;
10846 +       uint32_t nr_onhold;
10847 +       uint32_t nr_forks;
10848 +       uint32_t load[3];
10849 +};
10850 +
10851 +#ifdef __KERNEL__
10852 +extern int vc_virt_stat(struct vx_info *, void __user *);
10853 +
10854 +#endif /* __KERNEL__ */
10855 +#endif /* _VX_CVIRT_CMD_H */
10856 diff -NurpP --minimal linux-2.6.32.1/include/linux/vserver/cvirt_def.h linux-2.6.32.1-vs2.3.0.36.27/include/linux/vserver/cvirt_def.h
10857 --- linux-2.6.32.1/include/linux/vserver/cvirt_def.h    1970-01-01 01:00:00.000000000 +0100
10858 +++ linux-2.6.32.1-vs2.3.0.36.27/include/linux/vserver/cvirt_def.h      2009-12-03 20:04:56.000000000 +0100
10859 @@ -0,0 +1,80 @@
10860 +#ifndef _VX_CVIRT_DEF_H
10861 +#define _VX_CVIRT_DEF_H
10862 +
10863 +#include <linux/jiffies.h>
10864 +#include <linux/spinlock.h>
10865 +#include <linux/wait.h>
10866 +#include <linux/time.h>
10867 +#include <asm/atomic.h>
10868 +
10869 +
10870 +struct _vx_usage_stat {
10871 +       uint64_t user;
10872 +       uint64_t nice;
10873 +       uint64_t system;
10874 +       uint64_t softirq;
10875 +       uint64_t irq;
10876 +       uint64_t idle;
10877 +       uint64_t iowait;
10878 +};
10879 +
10880 +struct _vx_syslog {
10881 +       wait_queue_head_t log_wait;
10882 +       spinlock_t logbuf_lock;         /* lock for the log buffer */
10883 +
10884 +       unsigned long log_start;        /* next char to be read by syslog() */
10885 +       unsigned long con_start;        /* next char to be sent to consoles */
10886 +       unsigned long log_end;  /* most-recently-written-char + 1 */
10887 +       unsigned long logged_chars;     /* #chars since last read+clear operation */
10888 +
10889 +       char log_buf[1024];
10890 +};
10891 +
10892 +
10893 +/* context sub struct */
10894 +
10895 +struct _vx_cvirt {
10896 +       atomic_t nr_threads;            /* number of current threads */
10897 +       atomic_t nr_running;            /* number of running threads */
10898 +       atomic_t nr_uninterruptible;    /* number of uninterruptible threads */
10899 +
10900 +       atomic_t nr_onhold;             /* processes on hold */
10901 +       uint32_t onhold_last;           /* jiffies when put on hold */
10902 +
10903 +       struct timeval bias_tv;         /* time offset to the host */
10904 +       struct timespec bias_idle;
10905 +       struct timespec bias_uptime;    /* context creation point */
10906 +       uint64_t bias_clock;            /* offset in clock_t */
10907 +
10908 +       spinlock_t load_lock;           /* lock for the load averages */
10909 +       atomic_t load_updates;          /* nr of load updates done so far */
10910 +       uint32_t load_last;             /* last time load was calculated */
10911 +       uint32_t load[3];               /* load averages 1,5,15 */
10912 +
10913 +       atomic_t total_forks;           /* number of forks so far */
10914 +
10915 +       struct _vx_syslog syslog;
10916 +};
10917 +
10918 +struct _vx_cvirt_pc {
10919 +       struct _vx_usage_stat cpustat;
10920 +};
10921 +
10922 +
10923 +#ifdef CONFIG_VSERVER_DEBUG
10924 +
10925 +static inline void __dump_vx_cvirt(struct _vx_cvirt *cvirt)
10926 +{
10927 +       printk("\t_vx_cvirt:\n");
10928 +       printk("\t threads: %4d, %4d, %4d, %4d\n",
10929 +               atomic_read(&cvirt->nr_threads),
10930 +               atomic_read(&cvirt->nr_running),
10931 +               atomic_read(&cvirt->nr_uninterruptible),
10932 +               atomic_read(&cvirt->nr_onhold));
10933 +       /* add rest here */
10934 +       printk("\t total_forks = %d\n", atomic_read(&cvirt->total_forks));
10935 +}
10936 +
10937 +#endif
10938 +
10939 +#endif /* _VX_CVIRT_DEF_H */
10940 diff -NurpP --minimal linux-2.6.32.1/include/linux/vserver/cvirt.h linux-2.6.32.1-vs2.3.0.36.27/include/linux/vserver/cvirt.h
10941 --- linux-2.6.32.1/include/linux/vserver/cvirt.h        1970-01-01 01:00:00.000000000 +0100
10942 +++ linux-2.6.32.1-vs2.3.0.36.27/include/linux/vserver/cvirt.h  2009-12-03 20:04:56.000000000 +0100
10943 @@ -0,0 +1,20 @@
10944 +#ifndef _VX_CVIRT_H
10945 +#define _VX_CVIRT_H
10946 +
10947 +
10948 +#ifdef __KERNEL__
10949 +
10950 +struct timespec;
10951 +
10952 +void vx_vsi_uptime(struct timespec *, struct timespec *);
10953 +
10954 +
10955 +struct vx_info;
10956 +
10957 +void vx_update_load(struct vx_info *);
10958 +
10959 +
10960 +int vx_do_syslog(int, char __user *, int);
10961 +
10962 +#endif /* __KERNEL__ */
10963 +#endif /* _VX_CVIRT_H */
10964 diff -NurpP --minimal linux-2.6.32.1/include/linux/vserver/debug_cmd.h linux-2.6.32.1-vs2.3.0.36.27/include/linux/vserver/debug_cmd.h
10965 --- linux-2.6.32.1/include/linux/vserver/debug_cmd.h    1970-01-01 01:00:00.000000000 +0100
10966 +++ linux-2.6.32.1-vs2.3.0.36.27/include/linux/vserver/debug_cmd.h      2009-12-03 20:04:56.000000000 +0100
10967 @@ -0,0 +1,58 @@
10968 +#ifndef _VX_DEBUG_CMD_H
10969 +#define _VX_DEBUG_CMD_H
10970 +
10971 +
10972 +/* debug commands */
10973 +
10974 +#define VCMD_dump_history      VC_CMD(DEBUG, 1, 0)
10975 +
10976 +#define VCMD_read_history      VC_CMD(DEBUG, 5, 0)
10977 +#define VCMD_read_monitor      VC_CMD(DEBUG, 6, 0)
10978 +
10979 +struct  vcmd_read_history_v0 {
10980 +       uint32_t index;
10981 +       uint32_t count;
10982 +       char __user *data;
10983 +};
10984 +
10985 +struct  vcmd_read_monitor_v0 {
10986 +       uint32_t index;
10987 +       uint32_t count;
10988 +       char __user *data;
10989 +};
10990 +
10991 +
10992 +#ifdef __KERNEL__
10993 +
10994 +#ifdef CONFIG_COMPAT
10995 +
10996 +#include <asm/compat.h>
10997 +
10998 +struct vcmd_read_history_v0_x32 {
10999 +       uint32_t index;
11000 +       uint32_t count;
11001 +       compat_uptr_t data_ptr;
11002 +};
11003 +
11004 +struct vcmd_read_monitor_v0_x32 {
11005 +       uint32_t index;
11006 +       uint32_t count;
11007 +       compat_uptr_t data_ptr;
11008 +};
11009 +
11010 +#endif  /* CONFIG_COMPAT */
11011 +
11012 +extern int vc_dump_history(uint32_t);
11013 +
11014 +extern int vc_read_history(uint32_t, void __user *);
11015 +extern int vc_read_monitor(uint32_t, void __user *);
11016 +
11017 +#ifdef CONFIG_COMPAT
11018 +
11019 +extern int vc_read_history_x32(uint32_t, void __user *);
11020 +extern int vc_read_monitor_x32(uint32_t, void __user *);
11021 +
11022 +#endif  /* CONFIG_COMPAT */
11023 +
11024 +#endif /* __KERNEL__ */
11025 +#endif /* _VX_DEBUG_CMD_H */
11026 diff -NurpP --minimal linux-2.6.32.1/include/linux/vserver/debug.h linux-2.6.32.1-vs2.3.0.36.27/include/linux/vserver/debug.h
11027 --- linux-2.6.32.1/include/linux/vserver/debug.h        1970-01-01 01:00:00.000000000 +0100
11028 +++ linux-2.6.32.1-vs2.3.0.36.27/include/linux/vserver/debug.h  2009-12-03 20:04:56.000000000 +0100
11029 @@ -0,0 +1,127 @@
11030 +#ifndef _VX_DEBUG_H
11031 +#define _VX_DEBUG_H
11032 +
11033 +
11034 +#define VXD_CBIT(n, m) (vx_debug_ ## n & (1 << (m)))
11035 +#define VXD_CMIN(n, m) (vx_debug_ ## n > (m))
11036 +#define VXD_MASK(n, m) (vx_debug_ ## n & (m))
11037 +
11038 +#define VXD_DEV(d)     (d), (d)->bd_inode->i_ino,              \
11039 +                       imajor((d)->bd_inode), iminor((d)->bd_inode)
11040 +#define VXF_DEV                "%p[%lu,%d:%d]"
11041 +
11042 +
11043 +#define vxd_path(p)                                            \
11044 +       ({ static char _buffer[PATH_MAX];                       \
11045 +          d_path(p, _buffer, sizeof(_buffer)); })
11046 +
11047 +#define vxd_cond_path(n)                                       \
11048 +       ((n) ? vxd_path(&(n)->path) : "<null>" )
11049 +
11050 +
11051 +#ifdef CONFIG_VSERVER_DEBUG
11052 +
11053 +extern unsigned int vx_debug_switch;
11054 +extern unsigned int vx_debug_xid;
11055 +extern unsigned int vx_debug_nid;
11056 +extern unsigned int vx_debug_tag;
11057 +extern unsigned int vx_debug_net;
11058 +extern unsigned int vx_debug_limit;
11059 +extern unsigned int vx_debug_cres;
11060 +extern unsigned int vx_debug_dlim;
11061 +extern unsigned int vx_debug_quota;
11062 +extern unsigned int vx_debug_cvirt;
11063 +extern unsigned int vx_debug_space;
11064 +extern unsigned int vx_debug_misc;
11065 +
11066 +
11067 +#define VX_LOGLEVEL    "vxD: "
11068 +#define VX_PROC_FMT    "%p: "
11069 +#define VX_PROCESS     current
11070 +
11071 +#define vxdprintk(c, f, x...)                                  \
11072 +       do {                                                    \
11073 +               if (c)                                          \
11074 +                       printk(VX_LOGLEVEL VX_PROC_FMT f "\n",  \
11075 +                               VX_PROCESS , ##x);              \
11076 +       } while (0)
11077 +
11078 +#define vxlprintk(c, f, x...)                                  \
11079 +       do {                                                    \
11080 +               if (c)                                          \
11081 +                       printk(VX_LOGLEVEL f " @%s:%d\n", x);   \
11082 +       } while (0)
11083 +
11084 +#define vxfprintk(c, f, x...)                                  \
11085 +       do {                                                    \
11086 +               if (c)                                          \
11087 +                       printk(VX_LOGLEVEL f " %s@%s:%d\n", x); \
11088 +       } while (0)
11089 +
11090 +
11091 +struct vx_info;
11092 +
11093 +void dump_vx_info(struct vx_info *, int);
11094 +void dump_vx_info_inactive(int);
11095 +
11096 +#else  /* CONFIG_VSERVER_DEBUG */
11097 +
11098 +#define vx_debug_switch 0
11099 +#define vx_debug_xid   0
11100 +#define vx_debug_nid   0
11101 +#define vx_debug_tag   0
11102 +#define vx_debug_net   0
11103 +#define vx_debug_limit 0
11104 +#define vx_debug_cres  0
11105 +#define vx_debug_dlim  0
11106 +#define vx_debug_cvirt 0
11107 +
11108 +#define vxdprintk(x...) do { } while (0)
11109 +#define vxlprintk(x...) do { } while (0)
11110 +#define vxfprintk(x...) do { } while (0)
11111 +
11112 +#endif /* CONFIG_VSERVER_DEBUG */
11113 +
11114 +
11115 +#ifdef CONFIG_VSERVER_WARN
11116 +
11117 +#define VX_WARNLEVEL   KERN_WARNING "vxW: "
11118 +#define VX_WARN_TASK   "[»%s«,%u:#%u|%u|%u] "
11119 +#define VX_WARN_XID    "[xid #%u] "
11120 +#define VX_WARN_NID    "[nid #%u] "
11121 +#define VX_WARN_TAG    "[tag #%u] "
11122 +
11123 +#define vxwprintk(c, f, x...)                                  \
11124 +       do {                                                    \
11125 +               if (c)                                          \
11126 +                       printk(VX_WARNLEVEL f "\n", ##x);       \
11127 +       } while (0)
11128 +
11129 +#else  /* CONFIG_VSERVER_WARN */
11130 +
11131 +#define vxwprintk(x...) do { } while (0)
11132 +
11133 +#endif /* CONFIG_VSERVER_WARN */
11134 +
11135 +#define vxwprintk_task(c, f, x...)                             \
11136 +       vxwprintk(c, VX_WARN_TASK f,                            \
11137 +               current->comm, current->pid,                    \
11138 +               current->xid, current->nid, current->tag, ##x)
11139 +#define vxwprintk_xid(c, f, x...)                              \
11140 +       vxwprintk(c, VX_WARN_XID f, current->xid, x)
11141 +#define vxwprintk_nid(c, f, x...)                              \
11142 +       vxwprintk(c, VX_WARN_NID f, current->nid, x)
11143 +#define vxwprintk_tag(c, f, x...)                              \
11144 +       vxwprintk(c, VX_WARN_TAG f, current->tag, x)
11145 +
11146 +#ifdef CONFIG_VSERVER_DEBUG
11147 +#define vxd_assert_lock(l)     assert_spin_locked(l)
11148 +#define vxd_assert(c, f, x...) vxlprintk(!(c), \
11149 +       "assertion [" f "] failed.", ##x, __FILE__, __LINE__)
11150 +#else
11151 +#define vxd_assert_lock(l)     do { } while (0)
11152 +#define vxd_assert(c, f, x...) do { } while (0)
11153 +#endif
11154 +
11155 +
11156 +#endif /* _VX_DEBUG_H */
11157 diff -NurpP --minimal linux-2.6.32.1/include/linux/vserver/device_cmd.h linux-2.6.32.1-vs2.3.0.36.27/include/linux/vserver/device_cmd.h
11158 --- linux-2.6.32.1/include/linux/vserver/device_cmd.h   1970-01-01 01:00:00.000000000 +0100
11159 +++ linux-2.6.32.1-vs2.3.0.36.27/include/linux/vserver/device_cmd.h     2009-12-03 20:04:56.000000000 +0100
11160 @@ -0,0 +1,44 @@
11161 +#ifndef _VX_DEVICE_CMD_H
11162 +#define _VX_DEVICE_CMD_H
11163 +
11164 +
11165 +/*  device vserver commands */
11166 +
11167 +#define VCMD_set_mapping       VC_CMD(DEVICE, 1, 0)
11168 +#define VCMD_unset_mapping     VC_CMD(DEVICE, 2, 0)
11169 +
11170 +struct vcmd_set_mapping_v0 {
11171 +       const char __user *device;
11172 +       const char __user *target;
11173 +       uint32_t flags;
11174 +};
11175 +
11176 +
11177 +#ifdef __KERNEL__
11178 +
11179 +#ifdef CONFIG_COMPAT
11180 +
11181 +#include <asm/compat.h>
11182 +
11183 +struct vcmd_set_mapping_v0_x32 {
11184 +       compat_uptr_t device_ptr;
11185 +       compat_uptr_t target_ptr;
11186 +       uint32_t flags;
11187 +};
11188 +
11189 +#endif /* CONFIG_COMPAT */
11190 +
11191 +#include <linux/compiler.h>
11192 +
11193 +extern int vc_set_mapping(struct vx_info *, void __user *);
11194 +extern int vc_unset_mapping(struct vx_info *, void __user *);
11195 +
11196 +#ifdef CONFIG_COMPAT
11197 +
11198 +extern int vc_set_mapping_x32(struct vx_info *, void __user *);
11199 +extern int vc_unset_mapping_x32(struct vx_info *, void __user *);
11200 +
11201 +#endif /* CONFIG_COMPAT */
11202 +
11203 +#endif /* __KERNEL__ */
11204 +#endif /* _VX_DEVICE_CMD_H */
11205 diff -NurpP --minimal linux-2.6.32.1/include/linux/vserver/device_def.h linux-2.6.32.1-vs2.3.0.36.27/include/linux/vserver/device_def.h
11206 --- linux-2.6.32.1/include/linux/vserver/device_def.h   1970-01-01 01:00:00.000000000 +0100
11207 +++ linux-2.6.32.1-vs2.3.0.36.27/include/linux/vserver/device_def.h     2009-12-03 20:04:56.000000000 +0100
11208 @@ -0,0 +1,17 @@
11209 +#ifndef _VX_DEVICE_DEF_H
11210 +#define _VX_DEVICE_DEF_H
11211 +
11212 +#include <linux/types.h>
11213 +
11214 +struct vx_dmap_target {
11215 +       dev_t target;
11216 +       uint32_t flags;
11217 +};
11218 +
11219 +struct _vx_device {
11220 +#ifdef CONFIG_VSERVER_DEVICE
11221 +       struct vx_dmap_target targets[2];
11222 +#endif
11223 +};
11224 +
11225 +#endif /* _VX_DEVICE_DEF_H */
11226 diff -NurpP --minimal linux-2.6.32.1/include/linux/vserver/device.h linux-2.6.32.1-vs2.3.0.36.27/include/linux/vserver/device.h
11227 --- linux-2.6.32.1/include/linux/vserver/device.h       1970-01-01 01:00:00.000000000 +0100
11228 +++ linux-2.6.32.1-vs2.3.0.36.27/include/linux/vserver/device.h 2009-12-03 20:04:56.000000000 +0100
11229 @@ -0,0 +1,15 @@
11230 +#ifndef _VX_DEVICE_H
11231 +#define _VX_DEVICE_H
11232 +
11233 +
11234 +#define DATTR_CREATE   0x00000001
11235 +#define DATTR_OPEN     0x00000002
11236 +
11237 +#define DATTR_REMAP    0x00000010
11238 +
11239 +#define DATTR_MASK     0x00000013
11240 +
11241 +
11242 +#else  /* _VX_DEVICE_H */
11243 +#warning duplicate inclusion
11244 +#endif /* _VX_DEVICE_H */
11245 diff -NurpP --minimal linux-2.6.32.1/include/linux/vserver/dlimit_cmd.h linux-2.6.32.1-vs2.3.0.36.27/include/linux/vserver/dlimit_cmd.h
11246 --- linux-2.6.32.1/include/linux/vserver/dlimit_cmd.h   1970-01-01 01:00:00.000000000 +0100
11247 +++ linux-2.6.32.1-vs2.3.0.36.27/include/linux/vserver/dlimit_cmd.h     2009-12-10 16:43:43.000000000 +0100
11248 @@ -0,0 +1,109 @@
11249 +#ifndef _VX_DLIMIT_CMD_H
11250 +#define _VX_DLIMIT_CMD_H
11251 +
11252 +
11253 +/*  dlimit vserver commands */
11254 +
11255 +#define VCMD_add_dlimit                VC_CMD(DLIMIT, 1, 0)
11256 +#define VCMD_rem_dlimit                VC_CMD(DLIMIT, 2, 0)
11257 +
11258 +#define VCMD_set_dlimit                VC_CMD(DLIMIT, 5, 0)
11259 +#define VCMD_get_dlimit                VC_CMD(DLIMIT, 6, 0)
11260 +
11261 +struct vcmd_ctx_dlimit_base_v0 {
11262 +       const char __user *name;
11263 +       uint32_t flags;
11264 +};
11265 +
11266 +struct vcmd_ctx_dlimit_v0 {
11267 +       const char __user *name;
11268 +       uint32_t space_used;                    /* used space in kbytes */
11269 +       uint32_t space_total;                   /* maximum space in kbytes */
11270 +       uint32_t inodes_used;                   /* used inodes */
11271 +       uint32_t inodes_total;                  /* maximum inodes */
11272 +       uint32_t reserved;                      /* reserved for root in % */
11273 +       uint32_t flags;
11274 +};
11275 +
11276 +#define CDLIM_UNSET            ((uint32_t)0UL)
11277 +#define CDLIM_INFINITY         ((uint32_t)~0UL)
11278 +#define CDLIM_KEEP             ((uint32_t)~1UL)
11279 +
11280 +#define DLIME_UNIT     0
11281 +#define DLIME_KILO     1
11282 +#define DLIME_MEGA     2
11283 +#define DLIME_GIGA     3
11284 +
11285 +#define DLIMF_SHIFT    0x10
11286 +
11287 +#define DLIMS_USED     0
11288 +#define DLIMS_TOTAL    2
11289 +
11290 +static inline
11291 +uint64_t dlimit_space_32to64(uint32_t val, uint32_t flags, int shift)
11292 +{
11293 +       int exp = (flags & DLIMF_SHIFT) ?
11294 +               (flags >> shift) & DLIME_GIGA : DLIME_KILO;
11295 +       return ((uint64_t)val) << (10 * exp);
11296 +}
11297 +
11298 +static inline
11299 +uint32_t dlimit_space_64to32(uint64_t val, uint32_t *flags, int shift)
11300 +{
11301 +       int exp = 0;
11302 +
11303 +       if (*flags & DLIMF_SHIFT) {
11304 +               while (val > (1LL << 32) && (exp < 3)) {
11305 +                       val >>= 10;
11306 +                       exp++;
11307 +               }
11308 +               *flags &= ~(DLIME_GIGA << shift);
11309 +               *flags |= exp << shift;
11310 +       } else
11311 +               val >>= 10;
11312 +       return val;
11313 +}
11314 +
11315 +#ifdef __KERNEL__
11316 +
11317 +#ifdef CONFIG_COMPAT
11318 +
11319 +#include <asm/compat.h>
11320 +
11321 +struct vcmd_ctx_dlimit_base_v0_x32 {
11322 +       compat_uptr_t name_ptr;
11323 +       uint32_t flags;
11324 +};
11325 +
11326 +struct vcmd_ctx_dlimit_v0_x32 {
11327 +       compat_uptr_t name_ptr;
11328 +       uint32_t space_used;                    /* used space in kbytes */
11329 +       uint32_t space_total;                   /* maximum space in kbytes */
11330 +       uint32_t inodes_used;                   /* used inodes */
11331 +       uint32_t inodes_total;                  /* maximum inodes */
11332 +       uint32_t reserved;                      /* reserved for root in % */
11333 +       uint32_t flags;
11334 +};
11335 +
11336 +#endif /* CONFIG_COMPAT */
11337 +
11338 +#include <linux/compiler.h>
11339 +
11340 +extern int vc_add_dlimit(uint32_t, void __user *);
11341 +extern int vc_rem_dlimit(uint32_t, void __user *);
11342 +
11343 +extern int vc_set_dlimit(uint32_t, void __user *);
11344 +extern int vc_get_dlimit(uint32_t, void __user *);
11345 +
11346 +#ifdef CONFIG_COMPAT
11347 +
11348 +extern int vc_add_dlimit_x32(uint32_t, void __user *);
11349 +extern int vc_rem_dlimit_x32(uint32_t, void __user *);
11350 +
11351 +extern int vc_set_dlimit_x32(uint32_t, void __user *);
11352 +extern int vc_get_dlimit_x32(uint32_t, void __user *);
11353 +
11354 +#endif /* CONFIG_COMPAT */
11355 +
11356 +#endif /* __KERNEL__ */
11357 +#endif /* _VX_DLIMIT_CMD_H */
11358 diff -NurpP --minimal linux-2.6.32.1/include/linux/vserver/dlimit.h linux-2.6.32.1-vs2.3.0.36.27/include/linux/vserver/dlimit.h
11359 --- linux-2.6.32.1/include/linux/vserver/dlimit.h       1970-01-01 01:00:00.000000000 +0100
11360 +++ linux-2.6.32.1-vs2.3.0.36.27/include/linux/vserver/dlimit.h 2009-12-03 20:04:56.000000000 +0100
11361 @@ -0,0 +1,54 @@
11362 +#ifndef _VX_DLIMIT_H
11363 +#define _VX_DLIMIT_H
11364 +
11365 +#include "switch.h"
11366 +
11367 +
11368 +#ifdef __KERNEL__
11369 +
11370 +/*      keep in sync with CDLIM_INFINITY       */
11371 +
11372 +#define DLIM_INFINITY          (~0ULL)
11373 +
11374 +#include <linux/spinlock.h>
11375 +#include <linux/rcupdate.h>
11376 +
11377 +struct super_block;
11378 +
11379 +struct dl_info {
11380 +       struct hlist_node dl_hlist;             /* linked list of contexts */
11381 +       struct rcu_head dl_rcu;                 /* the rcu head */
11382 +       tag_t dl_tag;                           /* context tag */
11383 +       atomic_t dl_usecnt;                     /* usage count */
11384 +       atomic_t dl_refcnt;                     /* reference count */
11385 +
11386 +       struct super_block *dl_sb;              /* associated superblock */
11387 +
11388 +       spinlock_t dl_lock;                     /* protect the values */
11389 +
11390 +       unsigned long long dl_space_used;       /* used space in bytes */
11391 +       unsigned long long dl_space_total;      /* maximum space in bytes */
11392 +       unsigned long dl_inodes_used;           /* used inodes */
11393 +       unsigned long dl_inodes_total;          /* maximum inodes */
11394 +
11395 +       unsigned int dl_nrlmult;                /* non root limit mult */
11396 +};
11397 +
11398 +struct rcu_head;
11399 +
11400 +extern void rcu_free_dl_info(struct rcu_head *);
11401 +extern void unhash_dl_info(struct dl_info *);
11402 +
11403 +extern struct dl_info *locate_dl_info(struct super_block *, tag_t);
11404 +
11405 +
11406 +struct kstatfs;
11407 +
11408 +extern void vx_vsi_statfs(struct super_block *, struct kstatfs *);
11409 +
11410 +typedef uint64_t dlsize_t;
11411 +
11412 +#endif /* __KERNEL__ */
11413 +#else  /* _VX_DLIMIT_H */
11414 +#warning duplicate inclusion
11415 +#endif /* _VX_DLIMIT_H */
11416 diff -NurpP --minimal linux-2.6.32.1/include/linux/vserver/global.h linux-2.6.32.1-vs2.3.0.36.27/include/linux/vserver/global.h
11417 --- linux-2.6.32.1/include/linux/vserver/global.h       1970-01-01 01:00:00.000000000 +0100
11418 +++ linux-2.6.32.1-vs2.3.0.36.27/include/linux/vserver/global.h 2009-12-03 20:04:56.000000000 +0100
11419 @@ -0,0 +1,19 @@
11420 +#ifndef _VX_GLOBAL_H
11421 +#define _VX_GLOBAL_H
11422 +
11423 +
11424 +extern atomic_t vx_global_ctotal;
11425 +extern atomic_t vx_global_cactive;
11426 +
11427 +extern atomic_t nx_global_ctotal;
11428 +extern atomic_t nx_global_cactive;
11429 +
11430 +extern atomic_t vs_global_nsproxy;
11431 +extern atomic_t vs_global_fs;
11432 +extern atomic_t vs_global_mnt_ns;
11433 +extern atomic_t vs_global_uts_ns;
11434 +extern atomic_t vs_global_user_ns;
11435 +extern atomic_t vs_global_pid_ns;
11436 +
11437 +
11438 +#endif /* _VX_GLOBAL_H */
11439 diff -NurpP --minimal linux-2.6.32.1/include/linux/vserver/history.h linux-2.6.32.1-vs2.3.0.36.27/include/linux/vserver/history.h
11440 --- linux-2.6.32.1/include/linux/vserver/history.h      1970-01-01 01:00:00.000000000 +0100
11441 +++ linux-2.6.32.1-vs2.3.0.36.27/include/linux/vserver/history.h        2009-12-03 20:04:56.000000000 +0100
11442 @@ -0,0 +1,197 @@
11443 +#ifndef _VX_HISTORY_H
11444 +#define _VX_HISTORY_H
11445 +
11446 +
11447 +enum {
11448 +       VXH_UNUSED = 0,
11449 +       VXH_THROW_OOPS = 1,
11450 +
11451 +       VXH_GET_VX_INFO,
11452 +       VXH_PUT_VX_INFO,
11453 +       VXH_INIT_VX_INFO,
11454 +       VXH_SET_VX_INFO,
11455 +       VXH_CLR_VX_INFO,
11456 +       VXH_CLAIM_VX_INFO,
11457 +       VXH_RELEASE_VX_INFO,
11458 +       VXH_ALLOC_VX_INFO,
11459 +       VXH_DEALLOC_VX_INFO,
11460 +       VXH_HASH_VX_INFO,
11461 +       VXH_UNHASH_VX_INFO,
11462 +       VXH_LOC_VX_INFO,
11463 +       VXH_LOOKUP_VX_INFO,
11464 +       VXH_CREATE_VX_INFO,
11465 +};
11466 +
11467 +struct _vxhe_vxi {
11468 +       struct vx_info *ptr;
11469 +       unsigned xid;
11470 +       unsigned usecnt;
11471 +       unsigned tasks;
11472 +};
11473 +
11474 +struct _vxhe_set_clr {
11475 +       void *data;
11476 +};
11477 +
11478 +struct _vxhe_loc_lookup {
11479 +       unsigned arg;
11480 +};
11481 +
11482 +struct _vx_hist_entry {
11483 +       void *loc;
11484 +       unsigned short seq;
11485 +       unsigned short type;
11486 +       struct _vxhe_vxi vxi;
11487 +       union {
11488 +               struct _vxhe_set_clr sc;
11489 +               struct _vxhe_loc_lookup ll;
11490 +       };
11491 +};
11492 +
11493 +#ifdef CONFIG_VSERVER_HISTORY
11494 +
11495 +extern unsigned volatile int vxh_active;
11496 +
11497 +struct _vx_hist_entry *vxh_advance(void *loc);
11498 +
11499 +
11500 +static inline
11501 +void   __vxh_copy_vxi(struct _vx_hist_entry *entry, struct vx_info *vxi)
11502 +{
11503 +       entry->vxi.ptr = vxi;
11504 +       if (vxi) {
11505 +               entry->vxi.usecnt = atomic_read(&vxi->vx_usecnt);
11506 +               entry->vxi.tasks = atomic_read(&vxi->vx_tasks);
11507 +               entry->vxi.xid = vxi->vx_id;
11508 +       }
11509 +}
11510 +
11511 +
11512 +#define        __HERE__ current_text_addr()
11513 +
11514 +#define __VXH_BODY(__type, __data, __here)     \
11515 +       struct _vx_hist_entry *entry;           \
11516 +                                               \
11517 +       preempt_disable();                      \
11518 +       entry = vxh_advance(__here);            \
11519 +       __data;                                 \
11520 +       entry->type = __type;                   \
11521 +       preempt_enable();
11522 +
11523 +
11524 +       /* pass vxi only */
11525 +
11526 +#define __VXH_SMPL                             \
11527 +       __vxh_copy_vxi(entry, vxi)
11528 +
11529 +static inline
11530 +void   __vxh_smpl(struct vx_info *vxi, int __type, void *__here)
11531 +{
11532 +       __VXH_BODY(__type, __VXH_SMPL, __here)
11533 +}
11534 +
11535 +       /* pass vxi and data (void *) */
11536 +
11537 +#define __VXH_DATA                             \
11538 +       __vxh_copy_vxi(entry, vxi);             \
11539 +       entry->sc.data = data
11540 +
11541 +static inline
11542 +void   __vxh_data(struct vx_info *vxi, void *data,
11543 +                       int __type, void *__here)
11544 +{
11545 +       __VXH_BODY(__type, __VXH_DATA, __here)
11546 +}
11547 +
11548 +       /* pass vxi and arg (long) */
11549 +
11550 +#define __VXH_LONG                             \
11551 +       __vxh_copy_vxi(entry, vxi);             \
11552 +       entry->ll.arg = arg
11553 +
11554 +static inline
11555 +void   __vxh_long(struct vx_info *vxi, long arg,
11556 +                       int __type, void *__here)
11557 +{
11558 +       __VXH_BODY(__type, __VXH_LONG, __here)
11559 +}
11560 +
11561 +
11562 +static inline
11563 +void   __vxh_throw_oops(void *__here)
11564 +{
11565 +       __VXH_BODY(VXH_THROW_OOPS, {}, __here);
11566 +       /* prevent further acquisition */
11567 +       vxh_active = 0;
11568 +}
11569 +
11570 +
11571 +#define vxh_throw_oops()       __vxh_throw_oops(__HERE__);
11572 +
11573 +#define __vxh_get_vx_info(v, h)        __vxh_smpl(v, VXH_GET_VX_INFO, h);
11574 +#define __vxh_put_vx_info(v, h)        __vxh_smpl(v, VXH_PUT_VX_INFO, h);
11575 +
11576 +#define __vxh_init_vx_info(v, d, h) \
11577 +       __vxh_data(v, d, VXH_INIT_VX_INFO, h);
11578 +#define __vxh_set_vx_info(v, d, h) \
11579 +       __vxh_data(v, d, VXH_SET_VX_INFO, h);
11580 +#define __vxh_clr_vx_info(v, d, h) \
11581 +       __vxh_data(v, d, VXH_CLR_VX_INFO, h);
11582 +
11583 +#define __vxh_claim_vx_info(v, d, h) \
11584 +       __vxh_data(v, d, VXH_CLAIM_VX_INFO, h);
11585 +#define __vxh_release_vx_info(v, d, h) \
11586 +       __vxh_data(v, d, VXH_RELEASE_VX_INFO, h);
11587 +
11588 +#define vxh_alloc_vx_info(v) \
11589 +       __vxh_smpl(v, VXH_ALLOC_VX_INFO, __HERE__);
11590 +#define vxh_dealloc_vx_info(v) \
11591 +       __vxh_smpl(v, VXH_DEALLOC_VX_INFO, __HERE__);
11592 +
11593 +#define vxh_hash_vx_info(v) \
11594 +       __vxh_smpl(v, VXH_HASH_VX_INFO, __HERE__);
11595 +#define vxh_unhash_vx_info(v) \
11596 +       __vxh_smpl(v, VXH_UNHASH_VX_INFO, __HERE__);
11597 +
11598 +#define vxh_loc_vx_info(v, l) \
11599 +       __vxh_long(v, l, VXH_LOC_VX_INFO, __HERE__);
11600 +#define vxh_lookup_vx_info(v, l) \
11601 +       __vxh_long(v, l, VXH_LOOKUP_VX_INFO, __HERE__);
11602 +#define vxh_create_vx_info(v, l) \
11603 +       __vxh_long(v, l, VXH_CREATE_VX_INFO, __HERE__);
11604 +
11605 +extern void vxh_dump_history(void);
11606 +
11607 +
11608 +#else  /* CONFIG_VSERVER_HISTORY */
11609 +
11610 +#define        __HERE__        0
11611 +
11612 +#define vxh_throw_oops()               do { } while (0)
11613 +
11614 +#define __vxh_get_vx_info(v, h)                do { } while (0)
11615 +#define __vxh_put_vx_info(v, h)                do { } while (0)
11616 +
11617 +#define __vxh_init_vx_info(v, d, h)    do { } while (0)
11618 +#define __vxh_set_vx_info(v, d, h)     do { } while (0)
11619 +#define __vxh_clr_vx_info(v, d, h)     do { } while (0)
11620 +
11621 +#define __vxh_claim_vx_info(v, d, h)   do { } while (0)
11622 +#define __vxh_release_vx_info(v, d, h) do { } while (0)
11623 +
11624 +#define vxh_alloc_vx_info(v)           do { } while (0)
11625 +#define vxh_dealloc_vx_info(v)         do { } while (0)
11626 +
11627 +#define vxh_hash_vx_info(v)            do { } while (0)
11628 +#define vxh_unhash_vx_info(v)          do { } while (0)
11629 +
11630 +#define vxh_loc_vx_info(v, l)          do { } while (0)
11631 +#define vxh_lookup_vx_info(v, l)       do { } while (0)
11632 +#define vxh_create_vx_info(v, l)       do { } while (0)
11633 +
11634 +#define vxh_dump_history()             do { } while (0)
11635 +
11636 +
11637 +#endif /* CONFIG_VSERVER_HISTORY */
11638 +
11639 +#endif /* _VX_HISTORY_H */
11640 diff -NurpP --minimal linux-2.6.32.1/include/linux/vserver/inode_cmd.h linux-2.6.32.1-vs2.3.0.36.27/include/linux/vserver/inode_cmd.h
11641 --- linux-2.6.32.1/include/linux/vserver/inode_cmd.h    1970-01-01 01:00:00.000000000 +0100
11642 +++ linux-2.6.32.1-vs2.3.0.36.27/include/linux/vserver/inode_cmd.h      2009-12-03 20:04:56.000000000 +0100
11643 @@ -0,0 +1,59 @@
11644 +#ifndef _VX_INODE_CMD_H
11645 +#define _VX_INODE_CMD_H
11646 +
11647 +
11648 +/*  inode vserver commands */
11649 +
11650 +#define VCMD_get_iattr         VC_CMD(INODE, 1, 1)
11651 +#define VCMD_set_iattr         VC_CMD(INODE, 2, 1)
11652 +
11653 +#define VCMD_fget_iattr                VC_CMD(INODE, 3, 0)
11654 +#define VCMD_fset_iattr                VC_CMD(INODE, 4, 0)
11655 +
11656 +struct vcmd_ctx_iattr_v1 {
11657 +       const char __user *name;
11658 +       uint32_t tag;
11659 +       uint32_t flags;
11660 +       uint32_t mask;
11661 +};
11662 +
11663 +struct vcmd_ctx_fiattr_v0 {
11664 +       uint32_t tag;
11665 +       uint32_t flags;
11666 +       uint32_t mask;
11667 +};
11668 +
11669 +
11670 +#ifdef __KERNEL__
11671 +
11672 +
11673 +#ifdef CONFIG_COMPAT
11674 +
11675 +#include <asm/compat.h>
11676 +
11677 +struct vcmd_ctx_iattr_v1_x32 {
11678 +       compat_uptr_t name_ptr;
11679 +       uint32_t tag;
11680 +       uint32_t flags;
11681 +       uint32_t mask;
11682 +};
11683 +
11684 +#endif /* CONFIG_COMPAT */
11685 +
11686 +#include <linux/compiler.h>
11687 +
11688 +extern int vc_get_iattr(void __user *);
11689 +extern int vc_set_iattr(void __user *);
11690 +
11691 +extern int vc_fget_iattr(uint32_t, void __user *);
11692 +extern int vc_fset_iattr(uint32_t, void __user *);
11693 +
11694 +#ifdef CONFIG_COMPAT
11695 +
11696 +extern int vc_get_iattr_x32(void __user *);
11697 +extern int vc_set_iattr_x32(void __user *);
11698 +
11699 +#endif /* CONFIG_COMPAT */
11700 +
11701 +#endif /* __KERNEL__ */
11702 +#endif /* _VX_INODE_CMD_H */
11703 diff -NurpP --minimal linux-2.6.32.1/include/linux/vserver/inode.h linux-2.6.32.1-vs2.3.0.36.27/include/linux/vserver/inode.h
11704 --- linux-2.6.32.1/include/linux/vserver/inode.h        1970-01-01 01:00:00.000000000 +0100
11705 +++ linux-2.6.32.1-vs2.3.0.36.27/include/linux/vserver/inode.h  2009-12-03 20:04:56.000000000 +0100
11706 @@ -0,0 +1,39 @@
11707 +#ifndef _VX_INODE_H
11708 +#define _VX_INODE_H
11709 +
11710 +
11711 +#define IATTR_TAG      0x01000000
11712 +
11713 +#define IATTR_ADMIN    0x00000001
11714 +#define IATTR_WATCH    0x00000002
11715 +#define IATTR_HIDE     0x00000004
11716 +#define IATTR_FLAGS    0x00000007
11717 +
11718 +#define IATTR_BARRIER  0x00010000
11719 +#define IATTR_IXUNLINK 0x00020000
11720 +#define IATTR_IMMUTABLE 0x00040000
11721 +#define IATTR_COW      0x00080000
11722 +
11723 +#ifdef __KERNEL__
11724 +
11725 +
11726 +#ifdef CONFIG_VSERVER_PROC_SECURE
11727 +#define IATTR_PROC_DEFAULT     ( IATTR_ADMIN | IATTR_HIDE )
11728 +#define IATTR_PROC_SYMLINK     ( IATTR_ADMIN )
11729 +#else
11730 +#define IATTR_PROC_DEFAULT     ( IATTR_ADMIN )
11731 +#define IATTR_PROC_SYMLINK     ( IATTR_ADMIN )
11732 +#endif
11733 +
11734 +#define vx_hide_check(c, m)    (((m) & IATTR_HIDE) ? vx_check(c, m) : 1)
11735 +
11736 +#endif /* __KERNEL__ */
11737 +
11738 +/* inode ioctls */
11739 +
11740 +#define FIOC_GETXFLG   _IOR('x', 5, long)
11741 +#define FIOC_SETXFLG   _IOW('x', 6, long)
11742 +
11743 +#else  /* _VX_INODE_H */
11744 +#warning duplicate inclusion
11745 +#endif /* _VX_INODE_H */
11746 diff -NurpP --minimal linux-2.6.32.1/include/linux/vserver/Kbuild linux-2.6.32.1-vs2.3.0.36.27/include/linux/vserver/Kbuild
11747 --- linux-2.6.32.1/include/linux/vserver/Kbuild 1970-01-01 01:00:00.000000000 +0100
11748 +++ linux-2.6.32.1-vs2.3.0.36.27/include/linux/vserver/Kbuild   2009-12-03 20:04:56.000000000 +0100
11749 @@ -0,0 +1,8 @@
11750 +
11751 +unifdef-y += context_cmd.h network_cmd.h space_cmd.h \
11752 +       cacct_cmd.h cvirt_cmd.h limit_cmd.h dlimit_cmd.h \
11753 +       inode_cmd.h tag_cmd.h sched_cmd.h signal_cmd.h \
11754 +       debug_cmd.h device_cmd.h
11755 +
11756 +unifdef-y += switch.h network.h monitor.h inode.h device.h
11757 +
11758 diff -NurpP --minimal linux-2.6.32.1/include/linux/vserver/limit_cmd.h linux-2.6.32.1-vs2.3.0.36.27/include/linux/vserver/limit_cmd.h
11759 --- linux-2.6.32.1/include/linux/vserver/limit_cmd.h    1970-01-01 01:00:00.000000000 +0100
11760 +++ linux-2.6.32.1-vs2.3.0.36.27/include/linux/vserver/limit_cmd.h      2009-12-03 20:04:56.000000000 +0100
11761 @@ -0,0 +1,71 @@
11762 +#ifndef _VX_LIMIT_CMD_H
11763 +#define _VX_LIMIT_CMD_H
11764 +
11765 +
11766 +/*  rlimit vserver commands */
11767 +
11768 +#define VCMD_get_rlimit                VC_CMD(RLIMIT, 1, 0)
11769 +#define VCMD_set_rlimit                VC_CMD(RLIMIT, 2, 0)
11770 +#define VCMD_get_rlimit_mask   VC_CMD(RLIMIT, 3, 0)
11771 +#define VCMD_reset_hits                VC_CMD(RLIMIT, 7, 0)
11772 +#define VCMD_reset_minmax      VC_CMD(RLIMIT, 9, 0)
11773 +
11774 +struct vcmd_ctx_rlimit_v0 {
11775 +       uint32_t id;
11776 +       uint64_t minimum;
11777 +       uint64_t softlimit;
11778 +       uint64_t maximum;
11779 +};
11780 +
11781 +struct vcmd_ctx_rlimit_mask_v0 {
11782 +       uint32_t minimum;
11783 +       uint32_t softlimit;
11784 +       uint32_t maximum;
11785 +};
11786 +
11787 +#define VCMD_rlimit_stat       VC_CMD(VSTAT, 1, 0)
11788 +
11789 +struct vcmd_rlimit_stat_v0 {
11790 +       uint32_t id;
11791 +       uint32_t hits;
11792 +       uint64_t value;
11793 +       uint64_t minimum;
11794 +       uint64_t maximum;
11795 +};
11796 +
11797 +#define CRLIM_UNSET            (0ULL)
11798 +#define CRLIM_INFINITY         (~0ULL)
11799 +#define CRLIM_KEEP             (~1ULL)
11800 +
11801 +#ifdef __KERNEL__
11802 +
11803 +#ifdef CONFIG_IA32_EMULATION
11804 +
11805 +struct vcmd_ctx_rlimit_v0_x32 {
11806 +       uint32_t id;
11807 +       uint64_t minimum;
11808 +       uint64_t softlimit;
11809 +       uint64_t maximum;
11810 +} __attribute__ ((packed));
11811 +
11812 +#endif /* CONFIG_IA32_EMULATION */
11813 +
11814 +#include <linux/compiler.h>
11815 +
11816 +extern int vc_get_rlimit_mask(uint32_t, void __user *);
11817 +extern int vc_get_rlimit(struct vx_info *, void __user *);
11818 +extern int vc_set_rlimit(struct vx_info *, void __user *);
11819 +extern int vc_reset_hits(struct vx_info *, void __user *);
11820 +extern int vc_reset_minmax(struct vx_info *, void __user *);
11821 +
11822 +extern int vc_rlimit_stat(struct vx_info *, void __user *);
11823 +
11824 +#ifdef CONFIG_IA32_EMULATION
11825 +
11826 +extern int vc_get_rlimit_x32(struct vx_info *, void __user *);
11827 +extern int vc_set_rlimit_x32(struct vx_info *, void __user *);
11828 +
11829 +#endif /* CONFIG_IA32_EMULATION */
11830 +
11831 +#endif /* __KERNEL__ */
11832 +#endif /* _VX_LIMIT_CMD_H */
11833 diff -NurpP --minimal linux-2.6.32.1/include/linux/vserver/limit_def.h linux-2.6.32.1-vs2.3.0.36.27/include/linux/vserver/limit_def.h
11834 --- linux-2.6.32.1/include/linux/vserver/limit_def.h    1970-01-01 01:00:00.000000000 +0100
11835 +++ linux-2.6.32.1-vs2.3.0.36.27/include/linux/vserver/limit_def.h      2009-12-03 20:04:56.000000000 +0100
11836 @@ -0,0 +1,47 @@
11837 +#ifndef _VX_LIMIT_DEF_H
11838 +#define _VX_LIMIT_DEF_H
11839 +
11840 +#include <asm/atomic.h>
11841 +#include <asm/resource.h>
11842 +
11843 +#include "limit.h"
11844 +
11845 +
11846 +struct _vx_res_limit {
11847 +       rlim_t soft;            /* Context soft limit */
11848 +       rlim_t hard;            /* Context hard limit */
11849 +
11850 +       rlim_atomic_t rcur;     /* Current value */
11851 +       rlim_t rmin;            /* Context minimum */
11852 +       rlim_t rmax;            /* Context maximum */
11853 +
11854 +       atomic_t lhit;          /* Limit hits */
11855 +};
11856 +
11857 +/* context sub struct */
11858 +
11859 +struct _vx_limit {
11860 +       struct _vx_res_limit res[NUM_LIMITS];
11861 +};
11862 +
11863 +#ifdef CONFIG_VSERVER_DEBUG
11864 +
11865 +static inline void __dump_vx_limit(struct _vx_limit *limit)
11866 +{
11867 +       int i;
11868 +
11869 +       printk("\t_vx_limit:");
11870 +       for (i = 0; i < NUM_LIMITS; i++) {
11871 +               printk("\t [%2d] = %8lu %8lu/%8lu, %8ld/%8ld, %8d\n",
11872 +                       i, (unsigned long)__rlim_get(limit, i),
11873 +                       (unsigned long)__rlim_rmin(limit, i),
11874 +                       (unsigned long)__rlim_rmax(limit, i),
11875 +                       (long)__rlim_soft(limit, i),
11876 +                       (long)__rlim_hard(limit, i),
11877 +                       atomic_read(&__rlim_lhit(limit, i)));
11878 +       }
11879 +}
11880 +
11881 +#endif
11882 +
11883 +#endif /* _VX_LIMIT_DEF_H */
11884 diff -NurpP --minimal linux-2.6.32.1/include/linux/vserver/limit.h linux-2.6.32.1-vs2.3.0.36.27/include/linux/vserver/limit.h
11885 --- linux-2.6.32.1/include/linux/vserver/limit.h        1970-01-01 01:00:00.000000000 +0100
11886 +++ linux-2.6.32.1-vs2.3.0.36.27/include/linux/vserver/limit.h  2009-12-03 20:04:56.000000000 +0100
11887 @@ -0,0 +1,70 @@
11888 +#ifndef _VX_LIMIT_H
11889 +#define _VX_LIMIT_H
11890 +
11891 +#define VLIMIT_NSOCK   16
11892 +#define VLIMIT_OPENFD  17
11893 +#define VLIMIT_ANON    18
11894 +#define VLIMIT_SHMEM   19
11895 +#define VLIMIT_SEMARY  20
11896 +#define VLIMIT_NSEMS   21
11897 +#define VLIMIT_DENTRY  22
11898 +#define VLIMIT_MAPPED  23
11899 +
11900 +
11901 +#ifdef __KERNEL__
11902 +
11903 +#define        VLIM_NOCHECK    ((1L << VLIMIT_DENTRY) | (1L << RLIMIT_RSS))
11904 +
11905 +/*     keep in sync with CRLIM_INFINITY */
11906 +
11907 +#define        VLIM_INFINITY   (~0ULL)
11908 +
11909 +#include <asm/atomic.h>
11910 +#include <asm/resource.h>
11911 +
11912 +#ifndef RLIM_INFINITY
11913 +#warning RLIM_INFINITY is undefined
11914 +#endif
11915 +
11916 +#define __rlim_val(l, r, v)    ((l)->res[r].v)
11917 +
11918 +#define __rlim_soft(l, r)      __rlim_val(l, r, soft)
11919 +#define __rlim_hard(l, r)      __rlim_val(l, r, hard)
11920 +
11921 +#define __rlim_rcur(l, r)      __rlim_val(l, r, rcur)
11922 +#define __rlim_rmin(l, r)      __rlim_val(l, r, rmin)
11923 +#define __rlim_rmax(l, r)      __rlim_val(l, r, rmax)
11924 +
11925 +#define __rlim_lhit(l, r)      __rlim_val(l, r, lhit)
11926 +#define __rlim_hit(l, r)       atomic_inc(&__rlim_lhit(l, r))
11927 +
11928 +typedef atomic_long_t rlim_atomic_t;
11929 +typedef unsigned long rlim_t;
11930 +
11931 +#define __rlim_get(l, r)       atomic_long_read(&__rlim_rcur(l, r))
11932 +#define __rlim_set(l, r, v)    atomic_long_set(&__rlim_rcur(l, r), v)
11933 +#define __rlim_inc(l, r)       atomic_long_inc(&__rlim_rcur(l, r))
11934 +#define __rlim_dec(l, r)       atomic_long_dec(&__rlim_rcur(l, r))
11935 +#define __rlim_add(l, r, v)    atomic_long_add(v, &__rlim_rcur(l, r))
11936 +#define __rlim_sub(l, r, v)    atomic_long_sub(v, &__rlim_rcur(l, r))
11937 +
11938 +
11939 +#if    (RLIM_INFINITY == VLIM_INFINITY)
11940 +#define        VX_VLIM(r) ((long long)(long)(r))
11941 +#define        VX_RLIM(v) ((rlim_t)(v))
11942 +#else
11943 +#define        VX_VLIM(r) (((r) == RLIM_INFINITY) \
11944 +               ? VLIM_INFINITY : (long long)(r))
11945 +#define        VX_RLIM(v) (((v) == VLIM_INFINITY) \
11946 +               ? RLIM_INFINITY : (rlim_t)(v))
11947 +#endif
11948 +
11949 +struct sysinfo;
11950 +
11951 +void vx_vsi_meminfo(struct sysinfo *);
11952 +void vx_vsi_swapinfo(struct sysinfo *);
11953 +
11954 +#define NUM_LIMITS     24
11955 +
11956 +#endif /* __KERNEL__ */
11957 +#endif /* _VX_LIMIT_H */
11958 diff -NurpP --minimal linux-2.6.32.1/include/linux/vserver/limit_int.h linux-2.6.32.1-vs2.3.0.36.27/include/linux/vserver/limit_int.h
11959 --- linux-2.6.32.1/include/linux/vserver/limit_int.h    1970-01-01 01:00:00.000000000 +0100
11960 +++ linux-2.6.32.1-vs2.3.0.36.27/include/linux/vserver/limit_int.h      2009-12-03 20:04:56.000000000 +0100
11961 @@ -0,0 +1,198 @@
11962 +#ifndef _VX_LIMIT_INT_H
11963 +#define _VX_LIMIT_INT_H
11964 +
11965 +#include "context.h"
11966 +
11967 +#ifdef __KERNEL__
11968 +
11969 +#define VXD_RCRES_COND(r)      VXD_CBIT(cres, r)
11970 +#define VXD_RLIMIT_COND(r)     VXD_CBIT(limit, r)
11971 +
11972 +extern const char *vlimit_name[NUM_LIMITS];
11973 +
11974 +static inline void __vx_acc_cres(struct vx_info *vxi,
11975 +       int res, int dir, void *_data, char *_file, int _line)
11976 +{
11977 +       if (VXD_RCRES_COND(res))
11978 +               vxlprintk(1, "vx_acc_cres[%5d,%s,%2d]: %5ld%s (%p)",
11979 +                       (vxi ? vxi->vx_id : -1), vlimit_name[res], res,
11980 +                       (vxi ? (long)__rlim_get(&vxi->limit, res) : 0),
11981 +                       (dir > 0) ? "++" : "--", _data, _file, _line);
11982 +       if (!vxi)
11983 +               return;
11984 +
11985 +       if (dir > 0)
11986 +               __rlim_inc(&vxi->limit, res);
11987 +       else
11988 +               __rlim_dec(&vxi->limit, res);
11989 +}
11990 +
11991 +static inline void __vx_add_cres(struct vx_info *vxi,
11992 +       int res, int amount, void *_data, char *_file, int _line)
11993 +{
11994 +       if (VXD_RCRES_COND(res))
11995 +               vxlprintk(1, "vx_add_cres[%5d,%s,%2d]: %5ld += %5d (%p)",
11996 +                       (vxi ? vxi->vx_id : -1), vlimit_name[res], res,
11997 +                       (vxi ? (long)__rlim_get(&vxi->limit, res) : 0),
11998 +                       amount, _data, _file, _line);
11999 +       if (amount == 0)
12000 +               return;
12001 +       if (!vxi)
12002 +               return;
12003 +       __rlim_add(&vxi->limit, res, amount);
12004 +}
12005 +
12006 +static inline
12007 +int __vx_cres_adjust_max(struct _vx_limit *limit, int res, rlim_t value)
12008 +{
12009 +       int cond = (value > __rlim_rmax(limit, res));
12010 +
12011 +       if (cond)
12012 +               __rlim_rmax(limit, res) = value;
12013 +       return cond;
12014 +}
12015 +
12016 +static inline
12017 +int __vx_cres_adjust_min(struct _vx_limit *limit, int res, rlim_t value)
12018 +{
12019 +       int cond = (value < __rlim_rmin(limit, res));
12020 +
12021 +       if (cond)
12022 +               __rlim_rmin(limit, res) = value;
12023 +       return cond;
12024 +}
12025 +
12026 +static inline
12027 +void __vx_cres_fixup(struct _vx_limit *limit, int res, rlim_t value)
12028 +{
12029 +       if (!__vx_cres_adjust_max(limit, res, value))
12030 +               __vx_cres_adjust_min(limit, res, value);
12031 +}
12032 +
12033 +
12034 +/*     return values:
12035 +        +1 ... no limit hit
12036 +        -1 ... over soft limit
12037 +         0 ... over hard limit         */
12038 +
12039 +static inline int __vx_cres_avail(struct vx_info *vxi,
12040 +       int res, int num, char *_file, int _line)
12041 +{
12042 +       struct _vx_limit *limit;
12043 +       rlim_t value;
12044 +
12045 +       if (VXD_RLIMIT_COND(res))
12046 +               vxlprintk(1, "vx_cres_avail[%5d,%s,%2d]: %5ld/%5ld > %5ld + %5d",
12047 +                       (vxi ? vxi->vx_id : -1), vlimit_name[res], res,
12048 +                       (vxi ? (long)__rlim_soft(&vxi->limit, res) : -1),
12049 +                       (vxi ? (long)__rlim_hard(&vxi->limit, res) : -1),
12050 +                       (vxi ? (long)__rlim_get(&vxi->limit, res) : 0),
12051 +                       num, _file, _line);
12052 +       if (!vxi)
12053 +               return 1;
12054 +
12055 +       limit = &vxi->limit;
12056 +       value = __rlim_get(limit, res);
12057 +
12058 +       if (!__vx_cres_adjust_max(limit, res, value))
12059 +               __vx_cres_adjust_min(limit, res, value);
12060 +
12061 +       if (num == 0)
12062 +               return 1;
12063 +
12064 +       if (__rlim_soft(limit, res) == RLIM_INFINITY)
12065 +               return -1;
12066 +       if (value + num <= __rlim_soft(limit, res))
12067 +               return -1;
12068 +
12069 +       if (__rlim_hard(limit, res) == RLIM_INFINITY)
12070 +               return 1;
12071 +       if (value + num <= __rlim_hard(limit, res))
12072 +               return 1;
12073 +
12074 +       __rlim_hit(limit, res);
12075 +       return 0;
12076 +}
12077 +
12078 +
12079 +static const int VLA_RSS[] = { RLIMIT_RSS, VLIMIT_ANON, VLIMIT_MAPPED, 0 };
12080 +
12081 +static inline
12082 +rlim_t __vx_cres_array_sum(struct _vx_limit *limit, const int *array)
12083 +{
12084 +       rlim_t value, sum = 0;
12085 +       int res;
12086 +
12087 +       while ((res = *array++)) {
12088 +               value = __rlim_get(limit, res);
12089 +               __vx_cres_fixup(limit, res, value);
12090 +               sum += value;
12091 +       }
12092 +       return sum;
12093 +}
12094 +
12095 +static inline
12096 +rlim_t __vx_cres_array_fixup(struct _vx_limit *limit, const int *array)
12097 +{
12098 +       rlim_t value = __vx_cres_array_sum(limit, array + 1);
12099 +       int res = *array;
12100 +
12101 +       if (value == __rlim_get(limit, res))
12102 +               return value;
12103 +
12104 +       __rlim_set(limit, res, value);
12105 +       /* now adjust min/max */
12106 +       if (!__vx_cres_adjust_max(limit, res, value))
12107 +               __vx_cres_adjust_min(limit, res, value);
12108 +
12109 +       return value;
12110 +}
12111 +
12112 +static inline int __vx_cres_array_avail(struct vx_info *vxi,
12113 +       const int *array, int num, char *_file, int _line)
12114 +{
12115 +       struct _vx_limit *limit;
12116 +       rlim_t value = 0;
12117 +       int res;
12118 +
12119 +       if (num == 0)
12120 +               return 1;
12121 +       if (!vxi)
12122 +               return 1;
12123 +
12124 +       limit = &vxi->limit;
12125 +       res = *array;
12126 +       value = __vx_cres_array_sum(limit, array + 1);
12127 +
12128 +       __rlim_set(limit, res, value);
12129 +       __vx_cres_fixup(limit, res, value);
12130 +
12131 +       return __vx_cres_avail(vxi, res, num, _file, _line);
12132 +}
12133 +
12134 +
12135 +static inline void vx_limit_fixup(struct _vx_limit *limit, int id)
12136 +{
12137 +       rlim_t value;
12138 +       int res;
12139 +
12140 +       /* complex resources first */
12141 +       if ((id < 0) || (id == RLIMIT_RSS))
12142 +               __vx_cres_array_fixup(limit, VLA_RSS);
12143 +
12144 +       for (res = 0; res < NUM_LIMITS; res++) {
12145 +               if ((id > 0) && (res != id))
12146 +                       continue;
12147 +
12148 +               value = __rlim_get(limit, res);
12149 +               __vx_cres_fixup(limit, res, value);
12150 +
12151 +               /* not supposed to happen, maybe warn? */
12152 +               if (__rlim_rmax(limit, res) > __rlim_hard(limit, res))
12153 +                       __rlim_rmax(limit, res) = __rlim_hard(limit, res);
12154 +       }
12155 +}
12156 +
12157 +
12158 +#endif /* __KERNEL__ */
12159 +#endif /* _VX_LIMIT_INT_H */
12160 diff -NurpP --minimal linux-2.6.32.1/include/linux/vserver/monitor.h linux-2.6.32.1-vs2.3.0.36.27/include/linux/vserver/monitor.h
12161 --- linux-2.6.32.1/include/linux/vserver/monitor.h      1970-01-01 01:00:00.000000000 +0100
12162 +++ linux-2.6.32.1-vs2.3.0.36.27/include/linux/vserver/monitor.h        2009-12-03 20:04:56.000000000 +0100
12163 @@ -0,0 +1,96 @@
12164 +#ifndef _VX_MONITOR_H
12165 +#define _VX_MONITOR_H
12166 +
12167 +#include <linux/types.h>
12168 +
12169 +enum {
12170 +       VXM_UNUSED = 0,
12171 +
12172 +       VXM_SYNC = 0x10,
12173 +
12174 +       VXM_UPDATE = 0x20,
12175 +       VXM_UPDATE_1,
12176 +       VXM_UPDATE_2,
12177 +
12178 +       VXM_RQINFO_1 = 0x24,
12179 +       VXM_RQINFO_2,
12180 +
12181 +       VXM_ACTIVATE = 0x40,
12182 +       VXM_DEACTIVATE,
12183 +       VXM_IDLE,
12184 +
12185 +       VXM_HOLD = 0x44,
12186 +       VXM_UNHOLD,
12187 +
12188 +       VXM_MIGRATE = 0x48,
12189 +       VXM_RESCHED,
12190 +
12191 +       /* all other bits are flags */
12192 +       VXM_SCHED = 0x80,
12193 +};
12194 +
12195 +struct _vxm_update_1 {
12196 +       uint32_t tokens_max;
12197 +       uint32_t fill_rate;
12198 +       uint32_t interval;
12199 +};
12200 +
12201 +struct _vxm_update_2 {
12202 +       uint32_t tokens_min;
12203 +       uint32_t fill_rate;
12204 +       uint32_t interval;
12205 +};
12206 +
12207 +struct _vxm_rqinfo_1 {
12208 +       uint16_t running;
12209 +       uint16_t onhold;
12210 +       uint16_t iowait;
12211 +       uint16_t uintr;
12212 +       uint32_t idle_tokens;
12213 +};
12214 +
12215 +struct _vxm_rqinfo_2 {
12216 +       uint32_t norm_time;
12217 +       uint32_t idle_time;
12218 +       uint32_t idle_skip;
12219 +};
12220 +
12221 +struct _vxm_sched {
12222 +       uint32_t tokens;
12223 +       uint32_t norm_time;
12224 +       uint32_t idle_time;
12225 +};
12226 +
12227 +struct _vxm_task {
12228 +       uint16_t pid;
12229 +       uint16_t state;
12230 +};
12231 +
12232 +struct _vxm_event {
12233 +       uint32_t jif;
12234 +       union {
12235 +               uint32_t seq;
12236 +               uint32_t sec;
12237 +       };
12238 +       union {
12239 +               uint32_t tokens;
12240 +               uint32_t nsec;
12241 +               struct _vxm_task tsk;
12242 +       };
12243 +};
12244 +
12245 +struct _vx_mon_entry {
12246 +       uint16_t type;
12247 +       uint16_t xid;
12248 +       union {
12249 +               struct _vxm_event ev;
12250 +               struct _vxm_sched sd;
12251 +               struct _vxm_update_1 u1;
12252 +               struct _vxm_update_2 u2;
12253 +               struct _vxm_rqinfo_1 q1;
12254 +               struct _vxm_rqinfo_2 q2;
12255 +       };
12256 +};
12257 +
12258 +
12259 +#endif /* _VX_MONITOR_H */
12260 diff -NurpP --minimal linux-2.6.32.1/include/linux/vserver/network_cmd.h linux-2.6.32.1-vs2.3.0.36.27/include/linux/vserver/network_cmd.h
12261 --- linux-2.6.32.1/include/linux/vserver/network_cmd.h  1970-01-01 01:00:00.000000000 +0100
12262 +++ linux-2.6.32.1-vs2.3.0.36.27/include/linux/vserver/network_cmd.h    2009-12-03 20:04:56.000000000 +0100
12263 @@ -0,0 +1,150 @@
12264 +#ifndef _VX_NETWORK_CMD_H
12265 +#define _VX_NETWORK_CMD_H
12266 +
12267 +
12268 +/* vinfo commands */
12269 +
12270 +#define VCMD_task_nid          VC_CMD(VINFO, 2, 0)
12271 +
12272 +#ifdef __KERNEL__
12273 +extern int vc_task_nid(uint32_t);
12274 +
12275 +#endif /* __KERNEL__ */
12276 +
12277 +#define VCMD_nx_info           VC_CMD(VINFO, 6, 0)
12278 +
12279 +struct vcmd_nx_info_v0 {
12280 +       uint32_t nid;
12281 +       /* more to come */
12282 +};
12283 +
12284 +#ifdef __KERNEL__
12285 +extern int vc_nx_info(struct nx_info *, void __user *);
12286 +
12287 +#endif /* __KERNEL__ */
12288 +
12289 +#include <linux/in.h>
12290 +#include <linux/in6.h>
12291 +
12292 +#define VCMD_net_create_v0     VC_CMD(VNET, 1, 0)
12293 +#define VCMD_net_create                VC_CMD(VNET, 1, 1)
12294 +
12295 +struct  vcmd_net_create {
12296 +       uint64_t flagword;
12297 +};
12298 +
12299 +#define VCMD_net_migrate       VC_CMD(NETMIG, 1, 0)
12300 +
12301 +#define VCMD_net_add           VC_CMD(NETALT, 1, 0)
12302 +#define VCMD_net_remove                VC_CMD(NETALT, 2, 0)
12303 +
12304 +struct vcmd_net_addr_v0 {
12305 +       uint16_t type;
12306 +       uint16_t count;
12307 +       struct in_addr ip[4];
12308 +       struct in_addr mask[4];
12309 +};
12310 +
12311 +#define VCMD_net_add_ipv4      VC_CMD(NETALT, 1, 1)
12312 +#define VCMD_net_remove_ipv4   VC_CMD(NETALT, 2, 1)
12313 +
12314 +struct vcmd_net_addr_ipv4_v1 {
12315 +       uint16_t type;
12316 +       uint16_t flags;
12317 +       struct in_addr ip;
12318 +       struct in_addr mask;
12319 +};
12320 +
12321 +#define VCMD_net_add_ipv6      VC_CMD(NETALT, 3, 1)
12322 +#define VCMD_net_remove_ipv6   VC_CMD(NETALT, 4, 1)
12323 +
12324 +struct vcmd_net_addr_ipv6_v1 {
12325 +       uint16_t type;
12326 +       uint16_t flags;
12327 +       uint32_t prefix;
12328 +       struct in6_addr ip;
12329 +       struct in6_addr mask;
12330 +};
12331 +
12332 +#define VCMD_add_match_ipv4    VC_CMD(NETALT, 5, 0)
12333 +#define VCMD_get_match_ipv4    VC_CMD(NETALT, 6, 0)
12334 +
12335 +struct vcmd_match_ipv4_v0 {
12336 +       uint16_t type;
12337 +       uint16_t flags;
12338 +       uint16_t parent;
12339 +       uint16_t prefix;
12340 +       struct in_addr ip;
12341 +       struct in_addr ip2;
12342 +       struct in_addr mask;
12343 +};
12344 +
12345 +#define VCMD_add_match_ipv6    VC_CMD(NETALT, 7, 0)
12346 +#define VCMD_get_match_ipv6    VC_CMD(NETALT, 8, 0)
12347 +
12348 +struct vcmd_match_ipv6_v0 {
12349 +       uint16_t type;
12350 +       uint16_t flags;
12351 +       uint16_t parent;
12352 +       uint16_t prefix;
12353 +       struct in6_addr ip;
12354 +       struct in6_addr ip2;
12355 +       struct in6_addr mask;
12356 +};
12357 +
12358 +
12359 +#ifdef __KERNEL__
12360 +extern int vc_net_create(uint32_t, void __user *);
12361 +extern int vc_net_migrate(struct nx_info *, void __user *);
12362 +
12363 +extern int vc_net_add(struct nx_info *, void __user *);
12364 +extern int vc_net_remove(struct nx_info *, void __user *);
12365 +
12366 +extern int vc_net_add_ipv4(struct nx_info *, void __user *);
12367 +extern int vc_net_remove_ipv4(struct nx_info *, void __user *);
12368 +
12369 +extern int vc_net_add_ipv6(struct nx_info *, void __user *);
12370 +extern int vc_net_remove_ipv6(struct nx_info *, void __user *);
12371 +
12372 +extern int vc_add_match_ipv4(struct nx_info *, void __user *);
12373 +extern int vc_get_match_ipv4(struct nx_info *, void __user *);
12374 +
12375 +extern int vc_add_match_ipv6(struct nx_info *, void __user *);
12376 +extern int vc_get_match_ipv6(struct nx_info *, void __user *);
12377 +
12378 +#endif /* __KERNEL__ */
12379 +
12380 +
12381 +/* flag commands */
12382 +
12383 +#define VCMD_get_nflags                VC_CMD(FLAGS, 5, 0)
12384 +#define VCMD_set_nflags                VC_CMD(FLAGS, 6, 0)
12385 +
12386 +struct vcmd_net_flags_v0 {
12387 +       uint64_t flagword;
12388 +       uint64_t mask;
12389 +};
12390 +
12391 +#ifdef __KERNEL__
12392 +extern int vc_get_nflags(struct nx_info *, void __user *);
12393 +extern int vc_set_nflags(struct nx_info *, void __user *);
12394 +
12395 +#endif /* __KERNEL__ */
12396 +
12397 +
12398 +/* network caps commands */
12399 +
12400 +#define VCMD_get_ncaps         VC_CMD(FLAGS, 7, 0)
12401 +#define VCMD_set_ncaps         VC_CMD(FLAGS, 8, 0)
12402 +
12403 +struct vcmd_net_caps_v0 {
12404 +       uint64_t ncaps;
12405 +       uint64_t cmask;
12406 +};
12407 +
12408 +#ifdef __KERNEL__
12409 +extern int vc_get_ncaps(struct nx_info *, void __user *);
12410 +extern int vc_set_ncaps(struct nx_info *, void __user *);
12411 +
12412 +#endif /* __KERNEL__ */
12413 +#endif /* _VX_CONTEXT_CMD_H */
12414 diff -NurpP --minimal linux-2.6.32.1/include/linux/vserver/network.h linux-2.6.32.1-vs2.3.0.36.27/include/linux/vserver/network.h
12415 --- linux-2.6.32.1/include/linux/vserver/network.h      1970-01-01 01:00:00.000000000 +0100
12416 +++ linux-2.6.32.1-vs2.3.0.36.27/include/linux/vserver/network.h        2009-12-03 20:04:56.000000000 +0100
12417 @@ -0,0 +1,146 @@
12418 +#ifndef _VX_NETWORK_H
12419 +#define _VX_NETWORK_H
12420 +
12421 +#include <linux/types.h>
12422 +
12423 +
12424 +#define MAX_N_CONTEXT  65535   /* Arbitrary limit */
12425 +
12426 +
12427 +/* network flags */
12428 +
12429 +#define NXF_INFO_PRIVATE       0x00000008
12430 +
12431 +#define NXF_SINGLE_IP          0x00000100
12432 +#define NXF_LBACK_REMAP                0x00000200
12433 +#define NXF_LBACK_ALLOW                0x00000400
12434 +
12435 +#define NXF_HIDE_NETIF         0x02000000
12436 +#define NXF_HIDE_LBACK         0x04000000
12437 +
12438 +#define NXF_STATE_SETUP                (1ULL << 32)
12439 +#define NXF_STATE_ADMIN                (1ULL << 34)
12440 +
12441 +#define NXF_SC_HELPER          (1ULL << 36)
12442 +#define NXF_PERSISTENT         (1ULL << 38)
12443 +
12444 +#define NXF_ONE_TIME           (0x0005ULL << 32)
12445 +
12446 +
12447 +#define        NXF_INIT_SET            (__nxf_init_set())
12448 +
12449 +static inline uint64_t __nxf_init_set(void) {
12450 +       return    NXF_STATE_ADMIN
12451 +#ifdef CONFIG_VSERVER_AUTO_LBACK
12452 +               | NXF_LBACK_REMAP
12453 +               | NXF_HIDE_LBACK
12454 +#endif
12455 +#ifdef CONFIG_VSERVER_AUTO_SINGLE
12456 +               | NXF_SINGLE_IP
12457 +#endif
12458 +               | NXF_HIDE_NETIF;
12459 +}
12460 +
12461 +
12462 +/* network caps */
12463 +
12464 +#define NXC_TUN_CREATE         0x00000001
12465 +
12466 +#define NXC_RAW_ICMP           0x00000100
12467 +
12468 +
12469 +/* address types */
12470 +
12471 +#define NXA_TYPE_IPV4          0x0001
12472 +#define NXA_TYPE_IPV6          0x0002
12473 +
12474 +#define NXA_TYPE_NONE          0x0000
12475 +#define NXA_TYPE_ANY           0x00FF
12476 +
12477 +#define NXA_TYPE_ADDR          0x0010
12478 +#define NXA_TYPE_MASK          0x0020
12479 +#define NXA_TYPE_RANGE         0x0040
12480 +
12481 +#define NXA_MASK_ALL           (NXA_TYPE_ADDR | NXA_TYPE_MASK | NXA_TYPE_RANGE)
12482 +
12483 +#define NXA_MOD_BCAST          0x0100
12484 +#define NXA_MOD_LBACK          0x0200
12485 +
12486 +#define NXA_LOOPBACK           0x1000
12487 +
12488 +#define NXA_MASK_BIND          (NXA_MASK_ALL | NXA_MOD_BCAST | NXA_MOD_LBACK)
12489 +#define NXA_MASK_SHOW          (NXA_MASK_ALL | NXA_LOOPBACK)
12490 +
12491 +#ifdef __KERNEL__
12492 +
12493 +#include <linux/list.h>
12494 +#include <linux/spinlock.h>
12495 +#include <linux/rcupdate.h>
12496 +#include <linux/in.h>
12497 +#include <linux/in6.h>
12498 +#include <asm/atomic.h>
12499 +
12500 +struct nx_addr_v4 {
12501 +       struct nx_addr_v4 *next;
12502 +       struct in_addr ip[2];
12503 +       struct in_addr mask;
12504 +       uint16_t type;
12505 +       uint16_t flags;
12506 +};
12507 +
12508 +struct nx_addr_v6 {
12509 +       struct nx_addr_v6 *next;
12510 +       struct in6_addr ip;
12511 +       struct in6_addr mask;
12512 +       uint32_t prefix;
12513 +       uint16_t type;
12514 +       uint16_t flags;
12515 +};
12516 +
12517 +struct nx_info {
12518 +       struct hlist_node nx_hlist;     /* linked list of nxinfos */
12519 +       nid_t nx_id;                    /* vnet id */
12520 +       atomic_t nx_usecnt;             /* usage count */
12521 +       atomic_t nx_tasks;              /* tasks count */
12522 +       int nx_state;                   /* context state */
12523 +
12524 +       uint64_t nx_flags;              /* network flag word */
12525 +       uint64_t nx_ncaps;              /* network capabilities */
12526 +
12527 +       struct in_addr v4_lback;        /* Loopback address */
12528 +       struct in_addr v4_bcast;        /* Broadcast address */
12529 +       struct nx_addr_v4 v4;           /* First/Single ipv4 address */
12530 +#ifdef CONFIG_IPV6
12531 +       struct nx_addr_v6 v6;           /* First/Single ipv6 address */
12532 +#endif
12533 +       char nx_name[65];               /* network context name */
12534 +};
12535 +
12536 +
12537 +/* status flags */
12538 +
12539 +#define NXS_HASHED      0x0001
12540 +#define NXS_SHUTDOWN    0x0100
12541 +#define NXS_RELEASED    0x8000
12542 +
12543 +extern struct nx_info *lookup_nx_info(int);
12544 +
12545 +extern int get_nid_list(int, unsigned int *, int);
12546 +extern int nid_is_hashed(nid_t);
12547 +
12548 +extern int nx_migrate_task(struct task_struct *, struct nx_info *);
12549 +
12550 +extern long vs_net_change(struct nx_info *, unsigned int);
12551 +
12552 +struct sock;
12553 +
12554 +
12555 +#define NX_IPV4(n)     ((n)->v4.type != NXA_TYPE_NONE)
12556 +#ifdef  CONFIG_IPV6
12557 +#define NX_IPV6(n)     ((n)->v6.type != NXA_TYPE_NONE)
12558 +#else
12559 +#define NX_IPV6(n)     (0)
12560 +#endif
12561 +
12562 +#endif /* __KERNEL__ */
12563 +#endif /* _VX_NETWORK_H */
12564 diff -NurpP --minimal linux-2.6.32.1/include/linux/vserver/percpu.h linux-2.6.32.1-vs2.3.0.36.27/include/linux/vserver/percpu.h
12565 --- linux-2.6.32.1/include/linux/vserver/percpu.h       1970-01-01 01:00:00.000000000 +0100
12566 +++ linux-2.6.32.1-vs2.3.0.36.27/include/linux/vserver/percpu.h 2009-12-03 20:04:56.000000000 +0100
12567 @@ -0,0 +1,14 @@
12568 +#ifndef _VX_PERCPU_H
12569 +#define _VX_PERCPU_H
12570 +
12571 +#include "cvirt_def.h"
12572 +#include "sched_def.h"
12573 +
12574 +struct _vx_percpu {
12575 +       struct _vx_cvirt_pc cvirt;
12576 +       struct _vx_sched_pc sched;
12577 +};
12578 +
12579 +#define        PERCPU_PERCTX   (sizeof(struct _vx_percpu))
12580 +
12581 +#endif /* _VX_PERCPU_H */
12582 diff -NurpP --minimal linux-2.6.32.1/include/linux/vserver/pid.h linux-2.6.32.1-vs2.3.0.36.27/include/linux/vserver/pid.h
12583 --- linux-2.6.32.1/include/linux/vserver/pid.h  1970-01-01 01:00:00.000000000 +0100
12584 +++ linux-2.6.32.1-vs2.3.0.36.27/include/linux/vserver/pid.h    2009-12-03 20:04:56.000000000 +0100
12585 @@ -0,0 +1,51 @@
12586 +#ifndef _VSERVER_PID_H
12587 +#define _VSERVER_PID_H
12588 +
12589 +/* pid faking stuff */
12590 +
12591 +#define vx_info_map_pid(v, p) \
12592 +       __vx_info_map_pid((v), (p), __func__, __FILE__, __LINE__)
12593 +#define vx_info_map_tgid(v,p)  vx_info_map_pid(v,p)
12594 +#define vx_map_pid(p) vx_info_map_pid(current_vx_info(), p)
12595 +#define vx_map_tgid(p) vx_map_pid(p)
12596 +
12597 +static inline int __vx_info_map_pid(struct vx_info *vxi, int pid,
12598 +       const char *func, const char *file, int line)
12599 +{
12600 +       if (vx_info_flags(vxi, VXF_INFO_INIT, 0)) {
12601 +               vxfprintk(VXD_CBIT(cvirt, 2),
12602 +                       "vx_map_tgid: %p/%llx: %d -> %d",
12603 +                       vxi, (long long)vxi->vx_flags, pid,
12604 +                       (pid && pid == vxi->vx_initpid) ? 1 : pid,
12605 +                       func, file, line);
12606 +               if (pid == 0)
12607 +                       return 0;
12608 +               if (pid == vxi->vx_initpid)
12609 +                       return 1;
12610 +       }
12611 +       return pid;
12612 +}
12613 +
12614 +#define vx_info_rmap_pid(v, p) \
12615 +       __vx_info_rmap_pid((v), (p), __func__, __FILE__, __LINE__)
12616 +#define vx_rmap_pid(p) vx_info_rmap_pid(current_vx_info(), p)
12617 +#define vx_rmap_tgid(p) vx_rmap_pid(p)
12618 +
12619 +static inline int __vx_info_rmap_pid(struct vx_info *vxi, int pid,
12620 +       const char *func, const char *file, int line)
12621 +{
12622 +       if (vx_info_flags(vxi, VXF_INFO_INIT, 0)) {
12623 +               vxfprintk(VXD_CBIT(cvirt, 2),
12624 +                       "vx_rmap_tgid: %p/%llx: %d -> %d",
12625 +                       vxi, (long long)vxi->vx_flags, pid,
12626 +                       (pid == 1) ? vxi->vx_initpid : pid,
12627 +                       func, file, line);
12628 +               if ((pid == 1) && vxi->vx_initpid)
12629 +                       return vxi->vx_initpid;
12630 +               if (pid == vxi->vx_initpid)
12631 +                       return ~0U;
12632 +       }
12633 +       return pid;
12634 +}
12635 +
12636 +#endif
12637 diff -NurpP --minimal linux-2.6.32.1/include/linux/vserver/sched_cmd.h linux-2.6.32.1-vs2.3.0.36.27/include/linux/vserver/sched_cmd.h
12638 --- linux-2.6.32.1/include/linux/vserver/sched_cmd.h    1970-01-01 01:00:00.000000000 +0100
12639 +++ linux-2.6.32.1-vs2.3.0.36.27/include/linux/vserver/sched_cmd.h      2009-12-03 20:04:56.000000000 +0100
12640 @@ -0,0 +1,108 @@
12641 +#ifndef _VX_SCHED_CMD_H
12642 +#define _VX_SCHED_CMD_H
12643 +
12644 +
12645 +/*  sched vserver commands */
12646 +
12647 +#define VCMD_set_sched_v2      VC_CMD(SCHED, 1, 2)
12648 +#define VCMD_set_sched_v3      VC_CMD(SCHED, 1, 3)
12649 +#define VCMD_set_sched_v4      VC_CMD(SCHED, 1, 4)
12650 +
12651 +struct vcmd_set_sched_v2 {
12652 +       int32_t fill_rate;
12653 +       int32_t interval;
12654 +       int32_t tokens;
12655 +       int32_t tokens_min;
12656 +       int32_t tokens_max;
12657 +       uint64_t cpu_mask;
12658 +};
12659 +
12660 +struct vcmd_set_sched_v3 {
12661 +       uint32_t set_mask;
12662 +       int32_t fill_rate;
12663 +       int32_t interval;
12664 +       int32_t tokens;
12665 +       int32_t tokens_min;
12666 +       int32_t tokens_max;
12667 +       int32_t priority_bias;
12668 +};
12669 +
12670 +struct vcmd_set_sched_v4 {
12671 +       uint32_t set_mask;
12672 +       int32_t fill_rate;
12673 +       int32_t interval;
12674 +       int32_t tokens;
12675 +       int32_t tokens_min;
12676 +       int32_t tokens_max;
12677 +       int32_t prio_bias;
12678 +       int32_t cpu_id;
12679 +       int32_t bucket_id;
12680 +};
12681 +
12682 +#define VCMD_set_sched         VC_CMD(SCHED, 1, 5)
12683 +#define VCMD_get_sched         VC_CMD(SCHED, 2, 5)
12684 +
12685 +struct vcmd_sched_v5 {
12686 +       uint32_t mask;
12687 +       int32_t cpu_id;
12688 +       int32_t bucket_id;
12689 +       int32_t fill_rate[2];
12690 +       int32_t interval[2];
12691 +       int32_t tokens;
12692 +       int32_t tokens_min;
12693 +       int32_t tokens_max;
12694 +       int32_t prio_bias;
12695 +};
12696 +
12697 +#define VXSM_FILL_RATE         0x0001
12698 +#define VXSM_INTERVAL          0x0002
12699 +#define VXSM_FILL_RATE2                0x0004
12700 +#define VXSM_INTERVAL2         0x0008
12701 +#define VXSM_TOKENS            0x0010
12702 +#define VXSM_TOKENS_MIN                0x0020
12703 +#define VXSM_TOKENS_MAX                0x0040
12704 +#define VXSM_PRIO_BIAS         0x0100
12705 +
12706 +#define VXSM_IDLE_TIME         0x0200
12707 +#define VXSM_FORCE             0x0400
12708 +
12709 +#define        VXSM_V3_MASK            0x0173
12710 +#define        VXSM_SET_MASK           0x01FF
12711 +
12712 +#define VXSM_CPU_ID            0x1000
12713 +#define VXSM_BUCKET_ID         0x2000
12714 +
12715 +#define VXSM_MSEC              0x4000
12716 +
12717 +#define SCHED_KEEP             (-2)    /* only for v2 */
12718 +
12719 +#ifdef __KERNEL__
12720 +
12721 +#include <linux/compiler.h>
12722 +
12723 +extern int vc_set_sched_v2(struct vx_info *, void __user *);
12724 +extern int vc_set_sched_v3(struct vx_info *, void __user *);
12725 +extern int vc_set_sched_v4(struct vx_info *, void __user *);
12726 +extern int vc_set_sched(struct vx_info *, void __user *);
12727 +extern int vc_get_sched(struct vx_info *, void __user *);
12728 +
12729 +#endif /* __KERNEL__ */
12730 +
12731 +#define VCMD_sched_info                VC_CMD(SCHED, 3, 0)
12732 +
12733 +struct vcmd_sched_info {
12734 +       int32_t cpu_id;
12735 +       int32_t bucket_id;
12736 +       uint64_t user_msec;
12737 +       uint64_t sys_msec;
12738 +       uint64_t hold_msec;
12739 +       uint32_t token_usec;
12740 +       int32_t vavavoom;
12741 +};
12742 +
12743 +#ifdef __KERNEL__
12744 +
12745 +extern int vc_sched_info(struct vx_info *, void __user *);
12746 +
12747 +#endif /* __KERNEL__ */
12748 +#endif /* _VX_SCHED_CMD_H */
12749 diff -NurpP --minimal linux-2.6.32.1/include/linux/vserver/sched_def.h linux-2.6.32.1-vs2.3.0.36.27/include/linux/vserver/sched_def.h
12750 --- linux-2.6.32.1/include/linux/vserver/sched_def.h    1970-01-01 01:00:00.000000000 +0100
12751 +++ linux-2.6.32.1-vs2.3.0.36.27/include/linux/vserver/sched_def.h      2009-12-03 20:04:56.000000000 +0100
12752 @@ -0,0 +1,68 @@
12753 +#ifndef _VX_SCHED_DEF_H
12754 +#define _VX_SCHED_DEF_H
12755 +
12756 +#include <linux/spinlock.h>
12757 +#include <linux/jiffies.h>
12758 +#include <linux/cpumask.h>
12759 +#include <asm/atomic.h>
12760 +#include <asm/param.h>
12761 +
12762 +
12763 +/* context sub struct */
12764 +
12765 +struct _vx_sched {
12766 +       spinlock_t tokens_lock;         /* lock for token bucket */
12767 +
12768 +       int tokens;                     /* number of CPU tokens */
12769 +       int fill_rate[2];               /* Fill rate: add X tokens... */
12770 +       int interval[2];                /* Divisor:   per Y jiffies   */
12771 +       int tokens_min;                 /* Limit:     minimum for unhold */
12772 +       int tokens_max;                 /* Limit:     no more than N tokens */
12773 +
12774 +       int prio_bias;                  /* bias offset for priority */
12775 +
12776 +       unsigned update_mask;           /* which features should be updated */
12777 +       cpumask_t update;               /* CPUs which should update */
12778 +};
12779 +
12780 +struct _vx_sched_pc {
12781 +       int tokens;                     /* number of CPU tokens */
12782 +       int flags;                      /* bucket flags */
12783 +
12784 +       int fill_rate[2];               /* Fill rate: add X tokens... */
12785 +       int interval[2];                /* Divisor:   per Y jiffies   */
12786 +       int tokens_min;                 /* Limit:     minimum for unhold */
12787 +       int tokens_max;                 /* Limit:     no more than N tokens */
12788 +
12789 +       int prio_bias;                  /* bias offset for priority */
12790 +       int vavavoom;                   /* last calculated vavavoom */
12791 +
12792 +       unsigned long norm_time;        /* last time accounted */
12793 +       unsigned long idle_time;        /* non linear time for fair sched */
12794 +       unsigned long token_time;       /* token time for accounting */
12795 +       unsigned long onhold;           /* jiffies when put on hold */
12796 +
12797 +       uint64_t user_ticks;            /* token tick events */
12798 +       uint64_t sys_ticks;             /* token tick events */
12799 +       uint64_t hold_ticks;            /* token ticks paused */
12800 +};
12801 +
12802 +
12803 +#define VXSF_ONHOLD    0x0001
12804 +#define VXSF_IDLE_TIME 0x0100
12805 +
12806 +#ifdef CONFIG_VSERVER_DEBUG
12807 +
12808 +static inline void __dump_vx_sched(struct _vx_sched *sched)
12809 +{
12810 +       printk("\t_vx_sched:\n");
12811 +       printk("\t tokens: %4d/%4d, %4d/%4d, %4d, %4d\n",
12812 +               sched->fill_rate[0], sched->interval[0],
12813 +               sched->fill_rate[1], sched->interval[1],
12814 +               sched->tokens_min, sched->tokens_max);
12815 +       printk("\t priority = %4d\n", sched->prio_bias);
12816 +}
12817 +
12818 +#endif
12819 +
12820 +#endif /* _VX_SCHED_DEF_H */
12821 diff -NurpP --minimal linux-2.6.32.1/include/linux/vserver/sched.h linux-2.6.32.1-vs2.3.0.36.27/include/linux/vserver/sched.h
12822 --- linux-2.6.32.1/include/linux/vserver/sched.h        1970-01-01 01:00:00.000000000 +0100
12823 +++ linux-2.6.32.1-vs2.3.0.36.27/include/linux/vserver/sched.h  2009-12-03 20:04:56.000000000 +0100
12824 @@ -0,0 +1,26 @@
12825 +#ifndef _VX_SCHED_H
12826 +#define _VX_SCHED_H
12827 +
12828 +
12829 +#ifdef __KERNEL__
12830 +
12831 +struct timespec;
12832 +
12833 +void vx_vsi_uptime(struct timespec *, struct timespec *);
12834 +
12835 +
12836 +struct vx_info;
12837 +
12838 +void vx_update_load(struct vx_info *);
12839 +
12840 +
12841 +int vx_tokens_recalc(struct _vx_sched_pc *,
12842 +       unsigned long *, unsigned long *, int [2]);
12843 +
12844 +void vx_update_sched_param(struct _vx_sched *sched,
12845 +       struct _vx_sched_pc *sched_pc);
12846 +
12847 +#endif /* __KERNEL__ */
12848 +#else  /* _VX_SCHED_H */
12849 +#warning duplicate inclusion
12850 +#endif /* _VX_SCHED_H */
12851 diff -NurpP --minimal linux-2.6.32.1/include/linux/vserver/signal_cmd.h linux-2.6.32.1-vs2.3.0.36.27/include/linux/vserver/signal_cmd.h
12852 --- linux-2.6.32.1/include/linux/vserver/signal_cmd.h   1970-01-01 01:00:00.000000000 +0100
12853 +++ linux-2.6.32.1-vs2.3.0.36.27/include/linux/vserver/signal_cmd.h     2009-12-03 20:04:56.000000000 +0100
12854 @@ -0,0 +1,43 @@
12855 +#ifndef _VX_SIGNAL_CMD_H
12856 +#define _VX_SIGNAL_CMD_H
12857 +
12858 +
12859 +/*  signalling vserver commands */
12860 +
12861 +#define VCMD_ctx_kill          VC_CMD(PROCTRL, 1, 0)
12862 +#define VCMD_wait_exit         VC_CMD(EVENT, 99, 0)
12863 +
12864 +struct vcmd_ctx_kill_v0 {
12865 +       int32_t pid;
12866 +       int32_t sig;
12867 +};
12868 +
12869 +struct vcmd_wait_exit_v0 {
12870 +       int32_t reboot_cmd;
12871 +       int32_t exit_code;
12872 +};
12873 +
12874 +#ifdef __KERNEL__
12875 +
12876 +extern int vc_ctx_kill(struct vx_info *, void __user *);
12877 +extern int vc_wait_exit(struct vx_info *, void __user *);
12878 +
12879 +#endif /* __KERNEL__ */
12880 +
12881 +/*  process alteration commands */
12882 +
12883 +#define VCMD_get_pflags                VC_CMD(PROCALT, 5, 0)
12884 +#define VCMD_set_pflags                VC_CMD(PROCALT, 6, 0)
12885 +
12886 +struct vcmd_pflags_v0 {
12887 +       uint32_t flagword;
12888 +       uint32_t mask;
12889 +};
12890 +
12891 +#ifdef __KERNEL__
12892 +
12893 +extern int vc_get_pflags(uint32_t pid, void __user *);
12894 +extern int vc_set_pflags(uint32_t pid, void __user *);
12895 +
12896 +#endif /* __KERNEL__ */
12897 +#endif /* _VX_SIGNAL_CMD_H */
12898 diff -NurpP --minimal linux-2.6.32.1/include/linux/vserver/signal.h linux-2.6.32.1-vs2.3.0.36.27/include/linux/vserver/signal.h
12899 --- linux-2.6.32.1/include/linux/vserver/signal.h       1970-01-01 01:00:00.000000000 +0100
12900 +++ linux-2.6.32.1-vs2.3.0.36.27/include/linux/vserver/signal.h 2009-12-03 20:04:56.000000000 +0100
12901 @@ -0,0 +1,14 @@
12902 +#ifndef _VX_SIGNAL_H
12903 +#define _VX_SIGNAL_H
12904 +
12905 +
12906 +#ifdef __KERNEL__
12907 +
12908 +struct vx_info;
12909 +
12910 +int vx_info_kill(struct vx_info *, int, int);
12911 +
12912 +#endif /* __KERNEL__ */
12913 +#else  /* _VX_SIGNAL_H */
12914 +#warning duplicate inclusion
12915 +#endif /* _VX_SIGNAL_H */
12916 diff -NurpP --minimal linux-2.6.32.1/include/linux/vserver/space_cmd.h linux-2.6.32.1-vs2.3.0.36.27/include/linux/vserver/space_cmd.h
12917 --- linux-2.6.32.1/include/linux/vserver/space_cmd.h    1970-01-01 01:00:00.000000000 +0100
12918 +++ linux-2.6.32.1-vs2.3.0.36.27/include/linux/vserver/space_cmd.h      2009-12-03 20:04:56.000000000 +0100
12919 @@ -0,0 +1,38 @@
12920 +#ifndef _VX_SPACE_CMD_H
12921 +#define _VX_SPACE_CMD_H
12922 +
12923 +
12924 +#define VCMD_enter_space_v0    VC_CMD(PROCALT, 1, 0)
12925 +#define VCMD_enter_space_v1    VC_CMD(PROCALT, 1, 1)
12926 +#define VCMD_enter_space       VC_CMD(PROCALT, 1, 2)
12927 +
12928 +#define VCMD_set_space_v0      VC_CMD(PROCALT, 3, 0)
12929 +#define VCMD_set_space_v1      VC_CMD(PROCALT, 3, 1)
12930 +#define VCMD_set_space         VC_CMD(PROCALT, 3, 2)
12931 +
12932 +#define VCMD_get_space_mask_v0 VC_CMD(PROCALT, 4, 0)
12933 +
12934 +#define VCMD_get_space_mask    VC_CMD(VSPACE, 0, 1)
12935 +#define VCMD_get_space_default VC_CMD(VSPACE, 1, 0)
12936 +
12937 +
12938 +struct vcmd_space_mask_v1 {
12939 +       uint64_t mask;
12940 +};
12941 +
12942 +struct vcmd_space_mask_v2 {
12943 +       uint64_t mask;
12944 +       uint32_t index;
12945 +};
12946 +
12947 +
12948 +#ifdef __KERNEL__
12949 +
12950 +extern int vc_enter_space_v1(struct vx_info *, void __user *);
12951 +extern int vc_set_space_v1(struct vx_info *, void __user *);
12952 +extern int vc_enter_space(struct vx_info *, void __user *);
12953 +extern int vc_set_space(struct vx_info *, void __user *);
12954 +extern int vc_get_space_mask(void __user *, int);
12955 +
12956 +#endif /* __KERNEL__ */
12957 +#endif /* _VX_SPACE_CMD_H */
12958 diff -NurpP --minimal linux-2.6.32.1/include/linux/vserver/space.h linux-2.6.32.1-vs2.3.0.36.27/include/linux/vserver/space.h
12959 --- linux-2.6.32.1/include/linux/vserver/space.h        1970-01-01 01:00:00.000000000 +0100
12960 +++ linux-2.6.32.1-vs2.3.0.36.27/include/linux/vserver/space.h  2009-12-03 20:04:56.000000000 +0100
12961 @@ -0,0 +1,12 @@
12962 +#ifndef _VX_SPACE_H
12963 +#define _VX_SPACE_H
12964 +
12965 +#include <linux/types.h>
12966 +
12967 +struct vx_info;
12968 +
12969 +int vx_set_space(struct vx_info *vxi, unsigned long mask, unsigned index);
12970 +
12971 +#else  /* _VX_SPACE_H */
12972 +#warning duplicate inclusion
12973 +#endif /* _VX_SPACE_H */
12974 diff -NurpP --minimal linux-2.6.32.1/include/linux/vserver/switch.h linux-2.6.32.1-vs2.3.0.36.27/include/linux/vserver/switch.h
12975 --- linux-2.6.32.1/include/linux/vserver/switch.h       1970-01-01 01:00:00.000000000 +0100
12976 +++ linux-2.6.32.1-vs2.3.0.36.27/include/linux/vserver/switch.h 2009-12-03 20:04:56.000000000 +0100
12977 @@ -0,0 +1,98 @@
12978 +#ifndef _VX_SWITCH_H
12979 +#define _VX_SWITCH_H
12980 +
12981 +#include <linux/types.h>
12982 +
12983 +
12984 +#define VC_CATEGORY(c)         (((c) >> 24) & 0x3F)
12985 +#define VC_COMMAND(c)          (((c) >> 16) & 0xFF)
12986 +#define VC_VERSION(c)          ((c) & 0xFFF)
12987 +
12988 +#define VC_CMD(c, i, v)                ((((VC_CAT_ ## c) & 0x3F) << 24) \
12989 +                               | (((i) & 0xFF) << 16) | ((v) & 0xFFF))
12990 +
12991 +/*
12992 +
12993 +  Syscall Matrix V2.8
12994 +
12995 +        |VERSION|CREATE |MODIFY |MIGRATE|CONTROL|EXPERIM| |SPECIAL|SPECIAL|
12996 +        |STATS  |DESTROY|ALTER  |CHANGE |LIMIT  |TEST   | |       |       |
12997 +        |INFO   |SETUP  |       |MOVE   |       |       | |       |       |
12998 +  -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
12999 +  SYSTEM |VERSION|VSETUP |VHOST  |       |       |       | |DEVICE |       |
13000 +  HOST   |     00|     01|     02|     03|     04|     05| |     06|     07|
13001 +  -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
13002 +  CPU    |       |VPROC  |PROCALT|PROCMIG|PROCTRL|       | |SCHED. |       |
13003 +  PROCESS|     08|     09|     10|     11|     12|     13| |     14|     15|
13004 +  -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
13005 +  MEMORY |       |       |       |       |MEMCTRL|       | |SWAP   |       |
13006 +        |     16|     17|     18|     19|     20|     21| |     22|     23|
13007 +  -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
13008 +  NETWORK|       |VNET   |NETALT |NETMIG |NETCTL |       | |SERIAL |       |
13009 +        |     24|     25|     26|     27|     28|     29| |     30|     31|
13010 +  -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
13011 +  DISK   |       |       |       |TAGMIG |DLIMIT |       | |INODE  |       |
13012 +  VFS    |     32|     33|     34|     35|     36|     37| |     38|     39|
13013 +  -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
13014 +  OTHER  |VSTAT  |       |       |       |       |       | |VINFO  |       |
13015 +        |     40|     41|     42|     43|     44|     45| |     46|     47|
13016 +  =======+=======+=======+=======+=======+=======+=======+ +=======+=======+
13017 +  SPECIAL|EVENT  |       |       |       |FLAGS  |       | |VSPACE |       |
13018 +        |     48|     49|     50|     51|     52|     53| |     54|     55|
13019 +  -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
13020 +  SPECIAL|DEBUG  |       |       |       |RLIMIT |SYSCALL| |       |COMPAT |
13021 +        |     56|     57|     58|     59|     60|TEST 61| |     62|     63|
13022 +  -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
13023 +
13024 +*/
13025 +
13026 +#define VC_CAT_VERSION         0
13027 +
13028 +#define VC_CAT_VSETUP          1
13029 +#define VC_CAT_VHOST           2
13030 +
13031 +#define VC_CAT_DEVICE          6
13032 +
13033 +#define VC_CAT_VPROC           9
13034 +#define VC_CAT_PROCALT         10
13035 +#define VC_CAT_PROCMIG         11
13036 +#define VC_CAT_PROCTRL         12
13037 +
13038 +#define VC_CAT_SCHED           14
13039 +#define VC_CAT_MEMCTRL         20
13040 +
13041 +#define VC_CAT_VNET            25
13042 +#define VC_CAT_NETALT          26
13043 +#define VC_CAT_NETMIG          27
13044 +#define VC_CAT_NETCTRL         28
13045 +
13046 +#define VC_CAT_TAGMIG          35
13047 +#define VC_CAT_DLIMIT          36
13048 +#define VC_CAT_INODE           38
13049 +
13050 +#define VC_CAT_VSTAT           40
13051 +#define VC_CAT_VINFO           46
13052 +#define VC_CAT_EVENT           48
13053 +
13054 +#define VC_CAT_FLAGS           52
13055 +#define VC_CAT_VSPACE          54
13056 +#define VC_CAT_DEBUG           56
13057 +#define VC_CAT_RLIMIT          60
13058 +
13059 +#define VC_CAT_SYSTEST         61
13060 +#define VC_CAT_COMPAT          63
13061 +
13062 +/*  query version */
13063 +
13064 +#define VCMD_get_version       VC_CMD(VERSION, 0, 0)
13065 +#define VCMD_get_vci           VC_CMD(VERSION, 1, 0)
13066 +
13067 +
13068 +#ifdef __KERNEL__
13069 +
13070 +#include <linux/errno.h>
13071 +
13072 +#endif /* __KERNEL__ */
13073 +
13074 +#endif /* _VX_SWITCH_H */
13075 +
13076 diff -NurpP --minimal linux-2.6.32.1/include/linux/vserver/tag_cmd.h linux-2.6.32.1-vs2.3.0.36.27/include/linux/vserver/tag_cmd.h
13077 --- linux-2.6.32.1/include/linux/vserver/tag_cmd.h      1970-01-01 01:00:00.000000000 +0100
13078 +++ linux-2.6.32.1-vs2.3.0.36.27/include/linux/vserver/tag_cmd.h        2009-12-03 20:04:56.000000000 +0100
13079 @@ -0,0 +1,22 @@
13080 +#ifndef _VX_TAG_CMD_H
13081 +#define _VX_TAG_CMD_H
13082 +
13083 +
13084 +/* vinfo commands */
13085 +
13086 +#define VCMD_task_tag          VC_CMD(VINFO, 3, 0)
13087 +
13088 +#ifdef __KERNEL__
13089 +extern int vc_task_tag(uint32_t);
13090 +
13091 +#endif /* __KERNEL__ */
13092 +
13093 +/* context commands */
13094 +
13095 +#define VCMD_tag_migrate       VC_CMD(TAGMIG, 1, 0)
13096 +
13097 +#ifdef __KERNEL__
13098 +extern int vc_tag_migrate(uint32_t);
13099 +
13100 +#endif /* __KERNEL__ */
13101 +#endif /* _VX_TAG_CMD_H */
13102 diff -NurpP --minimal linux-2.6.32.1/include/linux/vserver/tag.h linux-2.6.32.1-vs2.3.0.36.27/include/linux/vserver/tag.h
13103 --- linux-2.6.32.1/include/linux/vserver/tag.h  1970-01-01 01:00:00.000000000 +0100
13104 +++ linux-2.6.32.1-vs2.3.0.36.27/include/linux/vserver/tag.h    2009-12-03 20:04:56.000000000 +0100
13105 @@ -0,0 +1,143 @@
13106 +#ifndef _DX_TAG_H
13107 +#define _DX_TAG_H
13108 +
13109 +#include <linux/types.h>
13110 +
13111 +
13112 +#define DX_TAG(in)     (IS_TAGGED(in))
13113 +
13114 +
13115 +#ifdef CONFIG_TAG_NFSD
13116 +#define DX_TAG_NFSD    1
13117 +#else
13118 +#define DX_TAG_NFSD    0
13119 +#endif
13120 +
13121 +
13122 +#ifdef CONFIG_TAGGING_NONE
13123 +
13124 +#define MAX_UID                0xFFFFFFFF
13125 +#define MAX_GID                0xFFFFFFFF
13126 +
13127 +#define INOTAG_TAG(cond, uid, gid, tag)        (0)
13128 +
13129 +#define TAGINO_UID(cond, uid, tag)     (uid)
13130 +#define TAGINO_GID(cond, gid, tag)     (gid)
13131 +
13132 +#endif
13133 +
13134 +
13135 +#ifdef CONFIG_TAGGING_GID16
13136 +
13137 +#define MAX_UID                0xFFFFFFFF
13138 +#define MAX_GID                0x0000FFFF
13139 +
13140 +#define INOTAG_TAG(cond, uid, gid, tag)        \
13141 +       ((cond) ? (((gid) >> 16) & 0xFFFF) : 0)
13142 +
13143 +#define TAGINO_UID(cond, uid, tag)     (uid)
13144 +#define TAGINO_GID(cond, gid, tag)     \
13145 +       ((cond) ? (((gid) & 0xFFFF) | ((tag) << 16)) : (gid))
13146 +
13147 +#endif
13148 +
13149 +
13150 +#ifdef CONFIG_TAGGING_ID24
13151 +
13152 +#define MAX_UID                0x00FFFFFF
13153 +#define MAX_GID                0x00FFFFFF
13154 +
13155 +#define INOTAG_TAG(cond, uid, gid, tag)        \
13156 +       ((cond) ? ((((uid) >> 16) & 0xFF00) | (((gid) >> 24) & 0xFF)) : 0)
13157 +
13158 +#define TAGINO_UID(cond, uid, tag)     \
13159 +       ((cond) ? (((uid) & 0xFFFFFF) | (((tag) & 0xFF00) << 16)) : (uid))
13160 +#define TAGINO_GID(cond, gid, tag)     \
13161 +       ((cond) ? (((gid) & 0xFFFFFF) | (((tag) & 0x00FF) << 24)) : (gid))
13162 +
13163 +#endif
13164 +
13165 +
13166 +#ifdef CONFIG_TAGGING_UID16
13167 +
13168 +#define MAX_UID                0x0000FFFF
13169 +#define MAX_GID                0xFFFFFFFF
13170 +
13171 +#define INOTAG_TAG(cond, uid, gid, tag)        \
13172 +       ((cond) ? (((uid) >> 16) & 0xFFFF) : 0)
13173 +
13174 +#define TAGINO_UID(cond, uid, tag)     \
13175 +       ((cond) ? (((uid) & 0xFFFF) | ((tag) << 16)) : (uid))
13176 +#define TAGINO_GID(cond, gid, tag)     (gid)
13177 +
13178 +#endif
13179 +
13180 +
13181 +#ifdef CONFIG_TAGGING_INTERN
13182 +
13183 +#define MAX_UID                0xFFFFFFFF
13184 +#define MAX_GID                0xFFFFFFFF
13185 +
13186 +#define INOTAG_TAG(cond, uid, gid, tag)        \
13187 +       ((cond) ? (tag) : 0)
13188 +
13189 +#define TAGINO_UID(cond, uid, tag)     (uid)
13190 +#define TAGINO_GID(cond, gid, tag)     (gid)
13191 +
13192 +#endif
13193 +
13194 +
13195 +#ifndef CONFIG_TAGGING_NONE
13196 +#define dx_current_fstag(sb)   \
13197 +       ((sb)->s_flags & MS_TAGGED ? dx_current_tag() : 0)
13198 +#else
13199 +#define dx_current_fstag(sb)   (0)
13200 +#endif
13201 +
13202 +#ifndef CONFIG_TAGGING_INTERN
13203 +#define TAGINO_TAG(cond, tag)  (0)
13204 +#else
13205 +#define TAGINO_TAG(cond, tag)  ((cond) ? (tag) : 0)
13206 +#endif
13207 +
13208 +#define INOTAG_UID(cond, uid, gid)     \
13209 +       ((cond) ? ((uid) & MAX_UID) : (uid))
13210 +#define INOTAG_GID(cond, uid, gid)     \
13211 +       ((cond) ? ((gid) & MAX_GID) : (gid))
13212 +
13213 +
13214 +static inline uid_t dx_map_uid(uid_t uid)
13215 +{
13216 +       if ((uid > MAX_UID) && (uid != -1))
13217 +               uid = -2;
13218 +       return (uid & MAX_UID);
13219 +}
13220 +
13221 +static inline gid_t dx_map_gid(gid_t gid)
13222 +{
13223 +       if ((gid > MAX_GID) && (gid != -1))
13224 +               gid = -2;
13225 +       return (gid & MAX_GID);
13226 +}
13227 +
13228 +struct peer_tag {
13229 +       int32_t xid;
13230 +       int32_t nid;
13231 +};
13232 +
13233 +#define dx_notagcheck(sb) ((sb) && ((sb)->s_flags & MS_NOTAGCHECK))
13234 +
13235 +int dx_parse_tag(char *string, tag_t *tag, int remove, int *mnt_flags,
13236 +                unsigned long *flags);
13237 +
13238 +#ifdef CONFIG_PROPAGATE
13239 +
13240 +void __dx_propagate_tag(struct nameidata *nd, struct inode *inode);
13241 +
13242 +#define dx_propagate_tag(n, i) __dx_propagate_tag(n, i)
13243 +
13244 +#else
13245 +#define dx_propagate_tag(n, i) do { } while (0)
13246 +#endif
13247 +
13248 +#endif /* _DX_TAG_H */
13249 diff -NurpP --minimal linux-2.6.32.1/include/linux/vs_inet6.h linux-2.6.32.1-vs2.3.0.36.27/include/linux/vs_inet6.h
13250 --- linux-2.6.32.1/include/linux/vs_inet6.h     1970-01-01 01:00:00.000000000 +0100
13251 +++ linux-2.6.32.1-vs2.3.0.36.27/include/linux/vs_inet6.h       2009-12-03 20:04:56.000000000 +0100
13252 @@ -0,0 +1,246 @@
13253 +#ifndef _VS_INET6_H
13254 +#define _VS_INET6_H
13255 +
13256 +#include "vserver/base.h"
13257 +#include "vserver/network.h"
13258 +#include "vserver/debug.h"
13259 +
13260 +#include <net/ipv6.h>
13261 +
13262 +#define NXAV6(a)       &(a)->ip, &(a)->mask, (a)->prefix, (a)->type
13263 +#define NXAV6_FMT      "[%pI6/%pI6/%d:%04x]"
13264 +
13265 +
13266 +#ifdef CONFIG_IPV6
13267 +
13268 +static inline
13269 +int v6_addr_match(struct nx_addr_v6 *nxa,
13270 +       const struct in6_addr *addr, uint16_t mask)
13271 +{
13272 +       int ret = 0;
13273 +
13274 +       switch (nxa->type & mask) {
13275 +       case NXA_TYPE_MASK:
13276 +               ret = ipv6_masked_addr_cmp(&nxa->ip, &nxa->mask, addr);
13277 +               break;
13278 +       case NXA_TYPE_ADDR:
13279 +               ret = ipv6_addr_equal(&nxa->ip, addr);
13280 +               break;
13281 +       case NXA_TYPE_ANY:
13282 +               ret = 1;
13283 +               break;
13284 +       }
13285 +       vxdprintk(VXD_CBIT(net, 0),
13286 +               "v6_addr_match(%p" NXAV6_FMT ",%pI6,%04x) = %d",
13287 +               nxa, NXAV6(nxa), addr, mask, ret);
13288 +       return ret;
13289 +}
13290 +
13291 +static inline
13292 +int v6_addr_in_nx_info(struct nx_info *nxi,
13293 +       const struct in6_addr *addr, uint16_t mask)
13294 +{
13295 +       struct nx_addr_v6 *nxa;
13296 +       int ret = 1;
13297 +
13298 +       if (!nxi)
13299 +               goto out;
13300 +       for (nxa = &nxi->v6; nxa; nxa = nxa->next)
13301 +               if (v6_addr_match(nxa, addr, mask))
13302 +                       goto out;
13303 +       ret = 0;
13304 +out:
13305 +       vxdprintk(VXD_CBIT(net, 0),
13306 +               "v6_addr_in_nx_info(%p[#%u],%pI6,%04x) = %d",
13307 +               nxi, nxi ? nxi->nx_id : 0, addr, mask, ret);
13308 +       return ret;
13309 +}
13310 +
13311 +static inline
13312 +int v6_nx_addr_match(struct nx_addr_v6 *nxa, struct nx_addr_v6 *addr, uint16_t mask)
13313 +{
13314 +       /* FIXME: needs full range checks */
13315 +       return v6_addr_match(nxa, &addr->ip, mask);
13316 +}
13317 +
13318 +static inline
13319 +int v6_nx_addr_in_nx_info(struct nx_info *nxi, struct nx_addr_v6 *nxa, uint16_t mask)
13320 +{
13321 +       struct nx_addr_v6 *ptr;
13322 +
13323 +       for (ptr = &nxi->v6; ptr; ptr = ptr->next)
13324 +               if (v6_nx_addr_match(ptr, nxa, mask))
13325 +                       return 1;
13326 +       return 0;
13327 +}
13328 +
13329 +
13330 +/*
13331 + *     Check if a given address matches for a socket
13332 + *
13333 + *     nxi:            the socket's nx_info if any
13334 + *     addr:           to be verified address
13335 + */
13336 +static inline
13337 +int v6_sock_addr_match (
13338 +       struct nx_info *nxi,
13339 +       struct inet_sock *inet,
13340 +       struct in6_addr *addr)
13341 +{
13342 +       struct sock *sk = &inet->sk;
13343 +       struct in6_addr *saddr = inet6_rcv_saddr(sk);
13344 +
13345 +       if (!ipv6_addr_any(addr) &&
13346 +               ipv6_addr_equal(saddr, addr))
13347 +               return 1;
13348 +       if (ipv6_addr_any(saddr))
13349 +               return v6_addr_in_nx_info(nxi, addr, -1);
13350 +       return 0;
13351 +}
13352 +
13353 +/*
13354 + *     check if address is covered by socket
13355 + *
13356 + *     sk:     the socket to check against
13357 + *     addr:   the address in question (must be != 0)
13358 + */
13359 +
13360 +static inline
13361 +int __v6_addr_match_socket(const struct sock *sk, struct nx_addr_v6 *nxa)
13362 +{
13363 +       struct nx_info *nxi = sk->sk_nx_info;
13364 +       struct in6_addr *saddr = inet6_rcv_saddr(sk);
13365 +
13366 +       vxdprintk(VXD_CBIT(net, 5),
13367 +               "__v6_addr_in_socket(%p," NXAV6_FMT ") %p:%pI6 %p;%lx",
13368 +               sk, NXAV6(nxa), nxi, saddr, sk->sk_socket,
13369 +               (sk->sk_socket?sk->sk_socket->flags:0));
13370 +
13371 +       if (!ipv6_addr_any(saddr)) {    /* direct address match */
13372 +               return v6_addr_match(nxa, saddr, -1);
13373 +       } else if (nxi) {               /* match against nx_info */
13374 +               return v6_nx_addr_in_nx_info(nxi, nxa, -1);
13375 +       } else {                        /* unrestricted any socket */
13376 +               return 1;
13377 +       }
13378 +}
13379 +
13380 +
13381 +/* inet related checks and helpers */
13382 +
13383 +
13384 +struct in_ifaddr;
13385 +struct net_device;
13386 +struct sock;
13387 +
13388 +
13389 +#include <linux/netdevice.h>
13390 +#include <linux/inetdevice.h>
13391 +#include <net/inet_timewait_sock.h>
13392 +
13393 +
13394 +int dev_in_nx_info(struct net_device *, struct nx_info *);
13395 +int v6_dev_in_nx_info(struct net_device *, struct nx_info *);
13396 +int nx_v6_addr_conflict(struct nx_info *, struct nx_info *);
13397 +
13398 +
13399 +
13400 +static inline
13401 +int v6_ifa_in_nx_info(struct inet6_ifaddr *ifa, struct nx_info *nxi)
13402 +{
13403 +       if (!nxi)
13404 +               return 1;
13405 +       if (!ifa)
13406 +               return 0;
13407 +       return v6_addr_in_nx_info(nxi, &ifa->addr, -1);
13408 +}
13409 +
13410 +static inline
13411 +int nx_v6_ifa_visible(struct nx_info *nxi, struct inet6_ifaddr *ifa)
13412 +{
13413 +       vxdprintk(VXD_CBIT(net, 1), "nx_v6_ifa_visible(%p[#%u],%p) %d",
13414 +               nxi, nxi ? nxi->nx_id : 0, ifa,
13415 +               nxi ? v6_ifa_in_nx_info(ifa, nxi) : 0);
13416 +
13417 +       if (!nx_info_flags(nxi, NXF_HIDE_NETIF, 0))
13418 +               return 1;
13419 +       if (v6_ifa_in_nx_info(ifa, nxi))
13420 +               return 1;
13421 +       return 0;
13422 +}
13423 +
13424 +
13425 +struct nx_v6_sock_addr {
13426 +       struct in6_addr saddr;  /* Address used for validation */
13427 +       struct in6_addr baddr;  /* Address used for socket bind */
13428 +};
13429 +
13430 +static inline
13431 +int v6_map_sock_addr(struct inet_sock *inet, struct sockaddr_in6 *addr,
13432 +       struct nx_v6_sock_addr *nsa)
13433 +{
13434 +       // struct sock *sk = &inet->sk;
13435 +       // struct nx_info *nxi = sk->sk_nx_info;
13436 +       struct in6_addr saddr = addr->sin6_addr;
13437 +       struct in6_addr baddr = saddr;
13438 +
13439 +       nsa->saddr = saddr;
13440 +       nsa->baddr = baddr;
13441 +       return 0;
13442 +}
13443 +
13444 +static inline
13445 +void v6_set_sock_addr(struct inet_sock *inet, struct nx_v6_sock_addr *nsa)
13446 +{
13447 +       // struct sock *sk = &inet->sk;
13448 +       // struct in6_addr *saddr = inet6_rcv_saddr(sk);
13449 +
13450 +       // *saddr = nsa->baddr;
13451 +       // inet->saddr = nsa->baddr;
13452 +}
13453 +
13454 +static inline
13455 +int nx_info_has_v6(struct nx_info *nxi)
13456 +{
13457 +       if (!nxi)
13458 +               return 1;
13459 +       if (NX_IPV6(nxi))
13460 +               return 1;
13461 +       return 0;
13462 +}
13463 +
13464 +#else /* CONFIG_IPV6 */
13465 +
13466 +static inline
13467 +int nx_v6_dev_visible(struct nx_info *n, struct net_device *d)
13468 +{
13469 +       return 1;
13470 +}
13471 +
13472 +
13473 +static inline
13474 +int nx_v6_addr_conflict(struct nx_info *n, uint32_t a, const struct sock *s)
13475 +{
13476 +       return 1;
13477 +}
13478 +
13479 +static inline
13480 +int v6_ifa_in_nx_info(struct in_ifaddr *a, struct nx_info *n)
13481 +{
13482 +       return 1;
13483 +}
13484 +
13485 +static inline
13486 +int nx_info_has_v6(struct nx_info *nxi)
13487 +{
13488 +       return 0;
13489 +}
13490 +
13491 +#endif /* CONFIG_IPV6 */
13492 +
13493 +#define current_nx_info_has_v6() \
13494 +       nx_info_has_v6(current_nx_info())
13495 +
13496 +#else
13497 +#warning duplicate inclusion
13498 +#endif
13499 diff -NurpP --minimal linux-2.6.32.1/include/linux/vs_inet.h linux-2.6.32.1-vs2.3.0.36.27/include/linux/vs_inet.h
13500 --- linux-2.6.32.1/include/linux/vs_inet.h      1970-01-01 01:00:00.000000000 +0100
13501 +++ linux-2.6.32.1-vs2.3.0.36.27/include/linux/vs_inet.h        2009-12-03 20:04:56.000000000 +0100
13502 @@ -0,0 +1,342 @@
13503 +#ifndef _VS_INET_H
13504 +#define _VS_INET_H
13505 +
13506 +#include "vserver/base.h"
13507 +#include "vserver/network.h"
13508 +#include "vserver/debug.h"
13509 +
13510 +#define IPI_LOOPBACK   htonl(INADDR_LOOPBACK)
13511 +
13512 +#define NXAV4(a)       NIPQUAD((a)->ip[0]), NIPQUAD((a)->ip[1]), \
13513 +                       NIPQUAD((a)->mask), (a)->type
13514 +#define NXAV4_FMT      "[" NIPQUAD_FMT "-" NIPQUAD_FMT "/" NIPQUAD_FMT ":%04x]"
13515 +
13516 +
13517 +static inline
13518 +int v4_addr_match(struct nx_addr_v4 *nxa, __be32 addr, uint16_t tmask)
13519 +{
13520 +       __be32 ip = nxa->ip[0].s_addr;
13521 +       __be32 mask = nxa->mask.s_addr;
13522 +       __be32 bcast = ip | ~mask;
13523 +       int ret = 0;
13524 +
13525 +       switch (nxa->type & tmask) {
13526 +       case NXA_TYPE_MASK:
13527 +               ret = (ip == (addr & mask));
13528 +               break;
13529 +       case NXA_TYPE_ADDR:
13530 +               ret = 3;
13531 +               if (addr == ip)
13532 +                       break;
13533 +               /* fall through to broadcast */
13534 +       case NXA_MOD_BCAST:
13535 +               ret = ((tmask & NXA_MOD_BCAST) && (addr == bcast));
13536 +               break;
13537 +       case NXA_TYPE_RANGE:
13538 +               ret = ((nxa->ip[0].s_addr <= addr) &&
13539 +                       (nxa->ip[1].s_addr > addr));
13540 +               break;
13541 +       case NXA_TYPE_ANY:
13542 +               ret = 2;
13543 +               break;
13544 +       }
13545 +
13546 +       vxdprintk(VXD_CBIT(net, 0),
13547 +               "v4_addr_match(%p" NXAV4_FMT "," NIPQUAD_FMT ",%04x) = %d",
13548 +               nxa, NXAV4(nxa), NIPQUAD(addr), tmask, ret);
13549 +       return ret;
13550 +}
13551 +
13552 +static inline
13553 +int v4_addr_in_nx_info(struct nx_info *nxi, __be32 addr, uint16_t tmask)
13554 +{
13555 +       struct nx_addr_v4 *nxa;
13556 +       int ret = 1;
13557 +
13558 +       if (!nxi)
13559 +               goto out;
13560 +
13561 +       ret = 2;
13562 +       /* allow 127.0.0.1 when remapping lback */
13563 +       if ((tmask & NXA_LOOPBACK) &&
13564 +               (addr == IPI_LOOPBACK) &&
13565 +               nx_info_flags(nxi, NXF_LBACK_REMAP, 0))
13566 +               goto out;
13567 +       ret = 3;
13568 +       /* check for lback address */
13569 +       if ((tmask & NXA_MOD_LBACK) &&
13570 +               (nxi->v4_lback.s_addr == addr))
13571 +               goto out;
13572 +       ret = 4;
13573 +       /* check for broadcast address */
13574 +       if ((tmask & NXA_MOD_BCAST) &&
13575 +               (nxi->v4_bcast.s_addr == addr))
13576 +               goto out;
13577 +       ret = 5;
13578 +       /* check for v4 addresses */
13579 +       for (nxa = &nxi->v4; nxa; nxa = nxa->next)
13580 +               if (v4_addr_match(nxa, addr, tmask))
13581 +                       goto out;
13582 +       ret = 0;
13583 +out:
13584 +       vxdprintk(VXD_CBIT(net, 0),
13585 +               "v4_addr_in_nx_info(%p[#%u]," NIPQUAD_FMT ",%04x) = %d",
13586 +               nxi, nxi ? nxi->nx_id : 0, NIPQUAD(addr), tmask, ret);
13587 +       return ret;
13588 +}
13589 +
13590 +static inline
13591 +int v4_nx_addr_match(struct nx_addr_v4 *nxa, struct nx_addr_v4 *addr, uint16_t mask)
13592 +{
13593 +       /* FIXME: needs full range checks */
13594 +       return v4_addr_match(nxa, addr->ip[0].s_addr, mask);
13595 +}
13596 +
13597 +static inline
13598 +int v4_nx_addr_in_nx_info(struct nx_info *nxi, struct nx_addr_v4 *nxa, uint16_t mask)
13599 +{
13600 +       struct nx_addr_v4 *ptr;
13601 +
13602 +       for (ptr = &nxi->v4; ptr; ptr = ptr->next)
13603 +               if (v4_nx_addr_match(ptr, nxa, mask))
13604 +                       return 1;
13605 +       return 0;
13606 +}
13607 +
13608 +#include <net/inet_sock.h>
13609 +
13610 +/*
13611 + *     Check if a given address matches for a socket
13612 + *
13613 + *     nxi:            the socket's nx_info if any
13614 + *     addr:           to be verified address
13615 + */
13616 +static inline
13617 +int v4_sock_addr_match (
13618 +       struct nx_info *nxi,
13619 +       struct inet_sock *inet,
13620 +       __be32 addr)
13621 +{
13622 +       __be32 saddr = inet->rcv_saddr;
13623 +       __be32 bcast = nxi ? nxi->v4_bcast.s_addr : INADDR_BROADCAST;
13624 +
13625 +       if (addr && (saddr == addr || bcast == addr))
13626 +               return 1;
13627 +       if (!saddr)
13628 +               return v4_addr_in_nx_info(nxi, addr, NXA_MASK_BIND);
13629 +       return 0;
13630 +}
13631 +
13632 +
13633 +/* inet related checks and helpers */
13634 +
13635 +
13636 +struct in_ifaddr;
13637 +struct net_device;
13638 +struct sock;
13639 +
13640 +#ifdef CONFIG_INET
13641 +
13642 +#include <linux/netdevice.h>
13643 +#include <linux/inetdevice.h>
13644 +#include <net/inet_sock.h>
13645 +#include <net/inet_timewait_sock.h>
13646 +
13647 +
13648 +int dev_in_nx_info(struct net_device *, struct nx_info *);
13649 +int v4_dev_in_nx_info(struct net_device *, struct nx_info *);
13650 +int nx_v4_addr_conflict(struct nx_info *, struct nx_info *);
13651 +
13652 +
13653 +/*
13654 + *     check if address is covered by socket
13655 + *
13656 + *     sk:     the socket to check against
13657 + *     addr:   the address in question (must be != 0)
13658 + */
13659 +
13660 +static inline
13661 +int __v4_addr_match_socket(const struct sock *sk, struct nx_addr_v4 *nxa)
13662 +{
13663 +       struct nx_info *nxi = sk->sk_nx_info;
13664 +       __be32 saddr = inet_rcv_saddr(sk);
13665 +
13666 +       vxdprintk(VXD_CBIT(net, 5),
13667 +               "__v4_addr_in_socket(%p," NXAV4_FMT ") %p:" NIPQUAD_FMT " %p;%lx",
13668 +               sk, NXAV4(nxa), nxi, NIPQUAD(saddr), sk->sk_socket,
13669 +               (sk->sk_socket?sk->sk_socket->flags:0));
13670 +
13671 +       if (saddr) {            /* direct address match */
13672 +               return v4_addr_match(nxa, saddr, -1);
13673 +       } else if (nxi) {       /* match against nx_info */
13674 +               return v4_nx_addr_in_nx_info(nxi, nxa, -1);
13675 +       } else {                /* unrestricted any socket */
13676 +               return 1;
13677 +       }
13678 +}
13679 +
13680 +
13681 +
13682 +static inline
13683 +int nx_dev_visible(struct nx_info *nxi, struct net_device *dev)
13684 +{
13685 +       vxdprintk(VXD_CBIT(net, 1), "nx_dev_visible(%p[#%u],%p Â»%s«) %d",
13686 +               nxi, nxi ? nxi->nx_id : 0, dev, dev->name,
13687 +               nxi ? dev_in_nx_info(dev, nxi) : 0);
13688 +
13689 +       if (!nx_info_flags(nxi, NXF_HIDE_NETIF, 0))
13690 +               return 1;
13691 +       if (dev_in_nx_info(dev, nxi))
13692 +               return 1;
13693 +       return 0;
13694 +}
13695 +
13696 +
13697 +static inline
13698 +int v4_ifa_in_nx_info(struct in_ifaddr *ifa, struct nx_info *nxi)
13699 +{
13700 +       if (!nxi)
13701 +               return 1;
13702 +       if (!ifa)
13703 +               return 0;
13704 +       return v4_addr_in_nx_info(nxi, ifa->ifa_local, NXA_MASK_SHOW);
13705 +}
13706 +
13707 +static inline
13708 +int nx_v4_ifa_visible(struct nx_info *nxi, struct in_ifaddr *ifa)
13709 +{
13710 +       vxdprintk(VXD_CBIT(net, 1), "nx_v4_ifa_visible(%p[#%u],%p) %d",
13711 +               nxi, nxi ? nxi->nx_id : 0, ifa,
13712 +               nxi ? v4_ifa_in_nx_info(ifa, nxi) : 0);
13713 +
13714 +       if (!nx_info_flags(nxi, NXF_HIDE_NETIF, 0))
13715 +               return 1;
13716 +       if (v4_ifa_in_nx_info(ifa, nxi))
13717 +               return 1;
13718 +       return 0;
13719 +}
13720 +
13721 +
13722 +struct nx_v4_sock_addr {
13723 +       __be32 saddr;   /* Address used for validation */
13724 +       __be32 baddr;   /* Address used for socket bind */
13725 +};
13726 +
13727 +static inline
13728 +int v4_map_sock_addr(struct inet_sock *inet, struct sockaddr_in *addr,
13729 +       struct nx_v4_sock_addr *nsa)
13730 +{
13731 +       struct sock *sk = &inet->sk;
13732 +       struct nx_info *nxi = sk->sk_nx_info;
13733 +       __be32 saddr = addr->sin_addr.s_addr;
13734 +       __be32 baddr = saddr;
13735 +
13736 +       vxdprintk(VXD_CBIT(net, 3),
13737 +               "inet_bind(%p)* %p,%p;%lx " NIPQUAD_FMT,
13738 +               sk, sk->sk_nx_info, sk->sk_socket,
13739 +               (sk->sk_socket ? sk->sk_socket->flags : 0),
13740 +               NIPQUAD(saddr));
13741 +
13742 +       if (nxi) {
13743 +               if (saddr == INADDR_ANY) {
13744 +                       if (nx_info_flags(nxi, NXF_SINGLE_IP, 0))
13745 +                               baddr = nxi->v4.ip[0].s_addr;
13746 +               } else if (saddr == IPI_LOOPBACK) {
13747 +                       if (nx_info_flags(nxi, NXF_LBACK_REMAP, 0))
13748 +                               baddr = nxi->v4_lback.s_addr;
13749 +               } else {        /* normal address bind */
13750 +                       if (!v4_addr_in_nx_info(nxi, saddr, NXA_MASK_BIND))
13751 +                               return -EADDRNOTAVAIL;
13752 +               }
13753 +       }
13754 +
13755 +       vxdprintk(VXD_CBIT(net, 3),
13756 +               "inet_bind(%p) " NIPQUAD_FMT ", " NIPQUAD_FMT,
13757 +               sk, NIPQUAD(saddr), NIPQUAD(baddr));
13758 +
13759 +       nsa->saddr = saddr;
13760 +       nsa->baddr = baddr;
13761 +       return 0;
13762 +}
13763 +
13764 +static inline
13765 +void v4_set_sock_addr(struct inet_sock *inet, struct nx_v4_sock_addr *nsa)
13766 +{
13767 +       inet->saddr = nsa->baddr;
13768 +       inet->rcv_saddr = nsa->baddr;
13769 +}
13770 +
13771 +
13772 +/*
13773 + *      helper to simplify inet_lookup_listener
13774 + *
13775 + *      nxi:   the socket's nx_info if any
13776 + *      addr:  to be verified address
13777 + *      saddr: socket address
13778 + */
13779 +static inline int v4_inet_addr_match (
13780 +       struct nx_info *nxi,
13781 +       __be32 addr,
13782 +       __be32 saddr)
13783 +{
13784 +       if (addr && (saddr == addr))
13785 +               return 1;
13786 +       if (!saddr)
13787 +               return nxi ? v4_addr_in_nx_info(nxi, addr, NXA_MASK_BIND) : 1;
13788 +       return 0;
13789 +}
13790 +
13791 +static inline __be32 nx_map_sock_lback(struct nx_info *nxi, __be32 addr)
13792 +{
13793 +       if (nx_info_flags(nxi, NXF_HIDE_LBACK, 0) &&
13794 +               (addr == nxi->v4_lback.s_addr))
13795 +               return IPI_LOOPBACK;
13796 +       return addr;
13797 +}
13798 +
13799 +static inline
13800 +int nx_info_has_v4(struct nx_info *nxi)
13801 +{
13802 +       if (!nxi)
13803 +               return 1;
13804 +       if (NX_IPV4(nxi))
13805 +               return 1;
13806 +       if (nx_info_flags(nxi, NXF_LBACK_REMAP, 0))
13807 +               return 1;
13808 +       return 0;
13809 +}
13810 +
13811 +#else /* CONFIG_INET */
13812 +
13813 +static inline
13814 +int nx_dev_visible(struct nx_info *n, struct net_device *d)
13815 +{
13816 +       return 1;
13817 +}
13818 +
13819 +static inline
13820 +int nx_v4_addr_conflict(struct nx_info *n, uint32_t a, const struct sock *s)
13821 +{
13822 +       return 1;
13823 +}
13824 +
13825 +static inline
13826 +int v4_ifa_in_nx_info(struct in_ifaddr *a, struct nx_info *n)
13827 +{
13828 +       return 1;
13829 +}
13830 +
13831 +static inline
13832 +int nx_info_has_v4(struct nx_info *nxi)
13833 +{
13834 +       return 0;
13835 +}
13836 +
13837 +#endif /* CONFIG_INET */
13838 +
13839 +#define current_nx_info_has_v4() \
13840 +       nx_info_has_v4(current_nx_info())
13841 +
13842 +#else
13843 +// #warning duplicate inclusion
13844 +#endif
13845 diff -NurpP --minimal linux-2.6.32.1/include/linux/vs_limit.h linux-2.6.32.1-vs2.3.0.36.27/include/linux/vs_limit.h
13846 --- linux-2.6.32.1/include/linux/vs_limit.h     1970-01-01 01:00:00.000000000 +0100
13847 +++ linux-2.6.32.1-vs2.3.0.36.27/include/linux/vs_limit.h       2009-12-03 20:04:56.000000000 +0100
13848 @@ -0,0 +1,140 @@
13849 +#ifndef _VS_LIMIT_H
13850 +#define _VS_LIMIT_H
13851 +
13852 +#include "vserver/limit.h"
13853 +#include "vserver/base.h"
13854 +#include "vserver/context.h"
13855 +#include "vserver/debug.h"
13856 +#include "vserver/context.h"
13857 +#include "vserver/limit_int.h"
13858 +
13859 +
13860 +#define vx_acc_cres(v, d, p, r) \
13861 +       __vx_acc_cres(v, r, d, p, __FILE__, __LINE__)
13862 +
13863 +#define vx_acc_cres_cond(x, d, p, r) \
13864 +       __vx_acc_cres(((x) == vx_current_xid()) ? current_vx_info() : 0, \
13865 +       r, d, p, __FILE__, __LINE__)
13866 +
13867 +
13868 +#define vx_add_cres(v, a, p, r) \
13869 +       __vx_add_cres(v, r, a, p, __FILE__, __LINE__)
13870 +#define vx_sub_cres(v, a, p, r)                vx_add_cres(v, -(a), p, r)
13871 +
13872 +#define vx_add_cres_cond(x, a, p, r) \
13873 +       __vx_add_cres(((x) == vx_current_xid()) ? current_vx_info() : 0, \
13874 +       r, a, p, __FILE__, __LINE__)
13875 +#define vx_sub_cres_cond(x, a, p, r)   vx_add_cres_cond(x, -(a), p, r)
13876 +
13877 +
13878 +/* process and file limits */
13879 +
13880 +#define vx_nproc_inc(p) \
13881 +       vx_acc_cres((p)->vx_info, 1, p, RLIMIT_NPROC)
13882 +
13883 +#define vx_nproc_dec(p) \
13884 +       vx_acc_cres((p)->vx_info,-1, p, RLIMIT_NPROC)
13885 +
13886 +#define vx_files_inc(f) \
13887 +       vx_acc_cres_cond((f)->f_xid, 1, f, RLIMIT_NOFILE)
13888 +
13889 +#define vx_files_dec(f) \
13890 +       vx_acc_cres_cond((f)->f_xid,-1, f, RLIMIT_NOFILE)
13891 +
13892 +#define vx_locks_inc(l) \
13893 +       vx_acc_cres_cond((l)->fl_xid, 1, l, RLIMIT_LOCKS)
13894 +
13895 +#define vx_locks_dec(l) \
13896 +       vx_acc_cres_cond((l)->fl_xid,-1, l, RLIMIT_LOCKS)
13897 +
13898 +#define vx_openfd_inc(f) \
13899 +       vx_acc_cres(current_vx_info(), 1, (void *)(long)(f), VLIMIT_OPENFD)
13900 +
13901 +#define vx_openfd_dec(f) \
13902 +       vx_acc_cres(current_vx_info(),-1, (void *)(long)(f), VLIMIT_OPENFD)
13903 +
13904 +
13905 +#define vx_cres_avail(v, n, r) \
13906 +       __vx_cres_avail(v, r, n, __FILE__, __LINE__)
13907 +
13908 +
13909 +#define vx_nproc_avail(n) \
13910 +       vx_cres_avail(current_vx_info(), n, RLIMIT_NPROC)
13911 +
13912 +#define vx_files_avail(n) \
13913 +       vx_cres_avail(current_vx_info(), n, RLIMIT_NOFILE)
13914 +
13915 +#define vx_locks_avail(n) \
13916 +       vx_cres_avail(current_vx_info(), n, RLIMIT_LOCKS)
13917 +
13918 +#define vx_openfd_avail(n) \
13919 +       vx_cres_avail(current_vx_info(), n, VLIMIT_OPENFD)
13920 +
13921 +
13922 +/* dentry limits */
13923 +
13924 +#define vx_dentry_inc(d) do {                                          \
13925 +       if (atomic_read(&d->d_count) == 1)                              \
13926 +               vx_acc_cres(current_vx_info(), 1, d, VLIMIT_DENTRY);    \
13927 +       } while (0)
13928 +
13929 +#define vx_dentry_dec(d) do {                                          \
13930 +       if (atomic_read(&d->d_count) == 0)                              \
13931 +               vx_acc_cres(current_vx_info(),-1, d, VLIMIT_DENTRY);    \
13932 +       } while (0)
13933 +
13934 +#define vx_dentry_avail(n) \
13935 +       vx_cres_avail(current_vx_info(), n, VLIMIT_DENTRY)
13936 +
13937 +
13938 +/* socket limits */
13939 +
13940 +#define vx_sock_inc(s) \
13941 +       vx_acc_cres((s)->sk_vx_info, 1, s, VLIMIT_NSOCK)
13942 +
13943 +#define vx_sock_dec(s) \
13944 +       vx_acc_cres((s)->sk_vx_info,-1, s, VLIMIT_NSOCK)
13945 +
13946 +#define vx_sock_avail(n) \
13947 +       vx_cres_avail(current_vx_info(), n, VLIMIT_NSOCK)
13948 +
13949 +
13950 +/* ipc resource limits */
13951 +
13952 +#define vx_ipcmsg_add(v, u, a) \
13953 +       vx_add_cres(v, a, u, RLIMIT_MSGQUEUE)
13954 +
13955 +#define vx_ipcmsg_sub(v, u, a) \
13956 +       vx_sub_cres(v, a, u, RLIMIT_MSGQUEUE)
13957 +
13958 +#define vx_ipcmsg_avail(v, a) \
13959 +       vx_cres_avail(v, a, RLIMIT_MSGQUEUE)
13960 +
13961 +
13962 +#define vx_ipcshm_add(v, k, a) \
13963 +       vx_add_cres(v, a, (void *)(long)(k), VLIMIT_SHMEM)
13964 +
13965 +#define vx_ipcshm_sub(v, k, a) \
13966 +       vx_sub_cres(v, a, (void *)(long)(k), VLIMIT_SHMEM)
13967 +
13968 +#define vx_ipcshm_avail(v, a) \
13969 +       vx_cres_avail(v, a, VLIMIT_SHMEM)
13970 +
13971 +
13972 +#define vx_semary_inc(a) \
13973 +       vx_acc_cres(current_vx_info(), 1, a, VLIMIT_SEMARY)
13974 +
13975 +#define vx_semary_dec(a) \
13976 +       vx_acc_cres(current_vx_info(), -1, a, VLIMIT_SEMARY)
13977 +
13978 +
13979 +#define vx_nsems_add(a,n) \
13980 +       vx_add_cres(current_vx_info(), n, a, VLIMIT_NSEMS)
13981 +
13982 +#define vx_nsems_sub(a,n) \
13983 +       vx_sub_cres(current_vx_info(), n, a, VLIMIT_NSEMS)
13984 +
13985 +
13986 +#else
13987 +#warning duplicate inclusion
13988 +#endif
13989 diff -NurpP --minimal linux-2.6.32.1/include/linux/vs_memory.h linux-2.6.32.1-vs2.3.0.36.27/include/linux/vs_memory.h
13990 --- linux-2.6.32.1/include/linux/vs_memory.h    1970-01-01 01:00:00.000000000 +0100
13991 +++ linux-2.6.32.1-vs2.3.0.36.27/include/linux/vs_memory.h      2009-12-03 20:04:56.000000000 +0100
13992 @@ -0,0 +1,159 @@
13993 +#ifndef _VS_MEMORY_H
13994 +#define _VS_MEMORY_H
13995 +
13996 +#include "vserver/limit.h"
13997 +#include "vserver/base.h"
13998 +#include "vserver/context.h"
13999 +#include "vserver/debug.h"
14000 +#include "vserver/context.h"
14001 +#include "vserver/limit_int.h"
14002 +
14003 +
14004 +#define __acc_add_long(a, v)   (*(v) += (a))
14005 +#define __acc_inc_long(v)      (++*(v))
14006 +#define __acc_dec_long(v)      (--*(v))
14007 +
14008 +#if    NR_CPUS >= CONFIG_SPLIT_PTLOCK_CPUS
14009 +#define __acc_add_atomic(a, v) atomic_long_add(a, v)
14010 +#define __acc_inc_atomic(v)    atomic_long_inc(v)
14011 +#define __acc_dec_atomic(v)    atomic_long_dec(v)
14012 +#else  /* NR_CPUS < CONFIG_SPLIT_PTLOCK_CPUS */
14013 +#define __acc_add_atomic(a, v) __acc_add_long(a, v)
14014 +#define __acc_inc_atomic(v)    __acc_inc_long(v)
14015 +#define __acc_dec_atomic(v)    __acc_dec_long(v)
14016 +#endif /* NR_CPUS < CONFIG_SPLIT_PTLOCK_CPUS */
14017 +
14018 +
14019 +#define vx_acc_page(m, d, v, r) do {                                   \
14020 +       if ((d) > 0)                                                    \
14021 +               __acc_inc_long(&(m)->v);                                \
14022 +       else                                                            \
14023 +               __acc_dec_long(&(m)->v);                                \
14024 +       __vx_acc_cres(m->mm_vx_info, r, d, m, __FILE__, __LINE__);      \
14025 +} while (0)
14026 +
14027 +#define vx_acc_page_atomic(m, d, v, r) do {                            \
14028 +       if ((d) > 0)                                                    \
14029 +               __acc_inc_atomic(&(m)->v);                              \
14030 +       else                                                            \
14031 +               __acc_dec_atomic(&(m)->v);                              \
14032 +       __vx_acc_cres(m->mm_vx_info, r, d, m, __FILE__, __LINE__);      \
14033 +} while (0)
14034 +
14035 +
14036 +#define vx_acc_pages(m, p, v, r) do {                                  \
14037 +       unsigned long __p = (p);                                        \
14038 +       __acc_add_long(__p, &(m)->v);                                   \
14039 +       __vx_add_cres(m->mm_vx_info, r, __p, m, __FILE__, __LINE__);    \
14040 +} while (0)
14041 +
14042 +#define vx_acc_pages_atomic(m, p, v, r) do {                           \
14043 +       unsigned long __p = (p);                                        \
14044 +       __acc_add_atomic(__p, &(m)->v);                                 \
14045 +       __vx_add_cres(m->mm_vx_info, r, __p, m, __FILE__, __LINE__);    \
14046 +} while (0)
14047 +
14048 +
14049 +
14050 +#define vx_acc_vmpage(m, d) \
14051 +       vx_acc_page(m, d, total_vm,  RLIMIT_AS)
14052 +#define vx_acc_vmlpage(m, d) \
14053 +       vx_acc_page(m, d, locked_vm, RLIMIT_MEMLOCK)
14054 +#define vx_acc_file_rsspage(m, d) \
14055 +       vx_acc_page_atomic(m, d, _file_rss, VLIMIT_MAPPED)
14056 +#define vx_acc_anon_rsspage(m, d) \
14057 +       vx_acc_page_atomic(m, d, _anon_rss, VLIMIT_ANON)
14058 +
14059 +#define vx_acc_vmpages(m, p) \
14060 +       vx_acc_pages(m, p, total_vm,  RLIMIT_AS)
14061 +#define vx_acc_vmlpages(m, p) \
14062 +       vx_acc_pages(m, p, locked_vm, RLIMIT_MEMLOCK)
14063 +#define vx_acc_file_rsspages(m, p) \
14064 +       vx_acc_pages_atomic(m, p, _file_rss, VLIMIT_MAPPED)
14065 +#define vx_acc_anon_rsspages(m, p) \
14066 +       vx_acc_pages_atomic(m, p, _anon_rss, VLIMIT_ANON)
14067 +
14068 +#define vx_pages_add(s, r, p)  __vx_add_cres(s, r, p, 0, __FILE__, __LINE__)
14069 +#define vx_pages_sub(s, r, p)  vx_pages_add(s, r, -(p))
14070 +
14071 +#define vx_vmpages_inc(m)              vx_acc_vmpage(m, 1)
14072 +#define vx_vmpages_dec(m)              vx_acc_vmpage(m, -1)
14073 +#define vx_vmpages_add(m, p)           vx_acc_vmpages(m, p)
14074 +#define vx_vmpages_sub(m, p)           vx_acc_vmpages(m, -(p))
14075 +
14076 +#define vx_vmlocked_inc(m)             vx_acc_vmlpage(m, 1)
14077 +#define vx_vmlocked_dec(m)             vx_acc_vmlpage(m, -1)
14078 +#define vx_vmlocked_add(m, p)          vx_acc_vmlpages(m, p)
14079 +#define vx_vmlocked_sub(m, p)          vx_acc_vmlpages(m, -(p))
14080 +
14081 +#define vx_file_rsspages_inc(m)                vx_acc_file_rsspage(m, 1)
14082 +#define vx_file_rsspages_dec(m)                vx_acc_file_rsspage(m, -1)
14083 +#define vx_file_rsspages_add(m, p)     vx_acc_file_rsspages(m, p)
14084 +#define vx_file_rsspages_sub(m, p)     vx_acc_file_rsspages(m, -(p))
14085 +
14086 +#define vx_anon_rsspages_inc(m)                vx_acc_anon_rsspage(m, 1)
14087 +#define vx_anon_rsspages_dec(m)                vx_acc_anon_rsspage(m, -1)
14088 +#define vx_anon_rsspages_add(m, p)     vx_acc_anon_rsspages(m, p)
14089 +#define vx_anon_rsspages_sub(m, p)     vx_acc_anon_rsspages(m, -(p))
14090 +
14091 +
14092 +#define vx_pages_avail(m, p, r) \
14093 +       __vx_cres_avail((m)->mm_vx_info, r, p, __FILE__, __LINE__)
14094 +
14095 +#define vx_vmpages_avail(m, p) vx_pages_avail(m, p, RLIMIT_AS)
14096 +#define vx_vmlocked_avail(m, p)        vx_pages_avail(m, p, RLIMIT_MEMLOCK)
14097 +#define vx_anon_avail(m, p)    vx_pages_avail(m, p, VLIMIT_ANON)
14098 +#define vx_mapped_avail(m, p)  vx_pages_avail(m, p, VLIMIT_MAPPED)
14099 +
14100 +#define vx_rss_avail(m, p) \
14101 +       __vx_cres_array_avail((m)->mm_vx_info, VLA_RSS, p, __FILE__, __LINE__)
14102 +
14103 +
14104 +enum {
14105 +       VXPT_UNKNOWN = 0,
14106 +       VXPT_ANON,
14107 +       VXPT_NONE,
14108 +       VXPT_FILE,
14109 +       VXPT_SWAP,
14110 +       VXPT_WRITE
14111 +};
14112 +
14113 +#if 0
14114 +#define        vx_page_fault(mm, vma, type, ret)
14115 +#else
14116 +
14117 +static inline
14118 +void __vx_page_fault(struct mm_struct *mm,
14119 +       struct vm_area_struct *vma, int type, int ret)
14120 +{
14121 +       struct vx_info *vxi = mm->mm_vx_info;
14122 +       int what;
14123 +/*
14124 +       static char *page_type[6] =
14125 +               { "UNKNOWN", "ANON", "NONE", "FILE", "SWAP", "WRITE" };
14126 +       static char *page_what[4] =
14127 +               { "FAULT_OOM", "FAULT_SIGBUS", "FAULT_MINOR", "FAULT_MAJOR" };
14128 +*/
14129 +
14130 +       if (!vxi)
14131 +               return;
14132 +
14133 +       what = (ret & 0x3);
14134 +
14135 +/*     printk("[%d] page[%d][%d] %2x %s %s\n", vxi->vx_id,
14136 +               type, what, ret, page_type[type], page_what[what]);
14137 +*/
14138 +       if (ret & VM_FAULT_WRITE)
14139 +               what |= 0x4;
14140 +       atomic_inc(&vxi->cacct.page[type][what]);
14141 +}
14142 +
14143 +#define        vx_page_fault(mm, vma, type, ret)       __vx_page_fault(mm, vma, type, ret)
14144 +#endif
14145 +
14146 +
14147 +extern unsigned long vx_badness(struct task_struct *task, struct mm_struct *mm);
14148 +
14149 +#else
14150 +#warning duplicate inclusion
14151 +#endif
14152 diff -NurpP --minimal linux-2.6.32.1/include/linux/vs_network.h linux-2.6.32.1-vs2.3.0.36.27/include/linux/vs_network.h
14153 --- linux-2.6.32.1/include/linux/vs_network.h   1970-01-01 01:00:00.000000000 +0100
14154 +++ linux-2.6.32.1-vs2.3.0.36.27/include/linux/vs_network.h     2009-12-03 20:04:56.000000000 +0100
14155 @@ -0,0 +1,169 @@
14156 +#ifndef _NX_VS_NETWORK_H
14157 +#define _NX_VS_NETWORK_H
14158 +
14159 +#include "vserver/context.h"
14160 +#include "vserver/network.h"
14161 +#include "vserver/base.h"
14162 +#include "vserver/check.h"
14163 +#include "vserver/debug.h"
14164 +
14165 +#include <linux/sched.h>
14166 +
14167 +
14168 +#define get_nx_info(i) __get_nx_info(i, __FILE__, __LINE__)
14169 +
14170 +static inline struct nx_info *__get_nx_info(struct nx_info *nxi,
14171 +       const char *_file, int _line)
14172 +{
14173 +       if (!nxi)
14174 +               return NULL;
14175 +
14176 +       vxlprintk(VXD_CBIT(nid, 2), "get_nx_info(%p[#%d.%d])",
14177 +               nxi, nxi ? nxi->nx_id : 0,
14178 +               nxi ? atomic_read(&nxi->nx_usecnt) : 0,
14179 +               _file, _line);
14180 +
14181 +       atomic_inc(&nxi->nx_usecnt);
14182 +       return nxi;
14183 +}
14184 +
14185 +
14186 +extern void free_nx_info(struct nx_info *);
14187 +
14188 +#define put_nx_info(i) __put_nx_info(i, __FILE__, __LINE__)
14189 +
14190 +static inline void __put_nx_info(struct nx_info *nxi, const char *_file, int _line)
14191 +{
14192 +       if (!nxi)
14193 +               return;
14194 +
14195 +       vxlprintk(VXD_CBIT(nid, 2), "put_nx_info(%p[#%d.%d])",
14196 +               nxi, nxi ? nxi->nx_id : 0,
14197 +               nxi ? atomic_read(&nxi->nx_usecnt) : 0,
14198 +               _file, _line);
14199 +
14200 +       if (atomic_dec_and_test(&nxi->nx_usecnt))
14201 +               free_nx_info(nxi);
14202 +}
14203 +
14204 +
14205 +#define init_nx_info(p, i) __init_nx_info(p, i, __FILE__, __LINE__)
14206 +
14207 +static inline void __init_nx_info(struct nx_info **nxp, struct nx_info *nxi,
14208 +               const char *_file, int _line)
14209 +{
14210 +       if (nxi) {
14211 +               vxlprintk(VXD_CBIT(nid, 3),
14212 +                       "init_nx_info(%p[#%d.%d])",
14213 +                       nxi, nxi ? nxi->nx_id : 0,
14214 +                       nxi ? atomic_read(&nxi->nx_usecnt) : 0,
14215 +                       _file, _line);
14216 +
14217 +               atomic_inc(&nxi->nx_usecnt);
14218 +       }
14219 +       *nxp = nxi;
14220 +}
14221 +
14222 +
14223 +#define set_nx_info(p, i) __set_nx_info(p, i, __FILE__, __LINE__)
14224 +
14225 +static inline void __set_nx_info(struct nx_info **nxp, struct nx_info *nxi,
14226 +       const char *_file, int _line)
14227 +{
14228 +       struct nx_info *nxo;
14229 +
14230 +       if (!nxi)
14231 +               return;
14232 +
14233 +       vxlprintk(VXD_CBIT(nid, 3), "set_nx_info(%p[#%d.%d])",
14234 +               nxi, nxi ? nxi->nx_id : 0,
14235 +               nxi ? atomic_read(&nxi->nx_usecnt) : 0,
14236 +               _file, _line);
14237 +
14238 +       atomic_inc(&nxi->nx_usecnt);
14239 +       nxo = xchg(nxp, nxi);
14240 +       BUG_ON(nxo);
14241 +}
14242 +
14243 +#define clr_nx_info(p) __clr_nx_info(p, __FILE__, __LINE__)
14244 +
14245 +static inline void __clr_nx_info(struct nx_info **nxp,
14246 +       const char *_file, int _line)
14247 +{
14248 +       struct nx_info *nxo;
14249 +
14250 +       nxo = xchg(nxp, NULL);
14251 +       if (!nxo)
14252 +               return;
14253 +
14254 +       vxlprintk(VXD_CBIT(nid, 3), "clr_nx_info(%p[#%d.%d])",
14255 +               nxo, nxo ? nxo->nx_id : 0,
14256 +               nxo ? atomic_read(&nxo->nx_usecnt) : 0,
14257 +               _file, _line);
14258 +
14259 +       if (atomic_dec_and_test(&nxo->nx_usecnt))
14260 +               free_nx_info(nxo);
14261 +}
14262 +
14263 +
14264 +#define claim_nx_info(v, p) __claim_nx_info(v, p, __FILE__, __LINE__)
14265 +
14266 +static inline void __claim_nx_info(struct nx_info *nxi,
14267 +       struct task_struct *task, const char *_file, int _line)
14268 +{
14269 +       vxlprintk(VXD_CBIT(nid, 3), "claim_nx_info(%p[#%d.%d.%d]) %p",
14270 +               nxi, nxi ? nxi->nx_id : 0,
14271 +               nxi?atomic_read(&nxi->nx_usecnt):0,
14272 +               nxi?atomic_read(&nxi->nx_tasks):0,
14273 +               task, _file, _line);
14274 +
14275 +       atomic_inc(&nxi->nx_tasks);
14276 +}
14277 +
14278 +
14279 +extern void unhash_nx_info(struct nx_info *);
14280 +
14281 +#define release_nx_info(v, p) __release_nx_info(v, p, __FILE__, __LINE__)
14282 +
14283 +static inline void __release_nx_info(struct nx_info *nxi,
14284 +       struct task_struct *task, const char *_file, int _line)
14285 +{
14286 +       vxlprintk(VXD_CBIT(nid, 3), "release_nx_info(%p[#%d.%d.%d]) %p",
14287 +               nxi, nxi ? nxi->nx_id : 0,
14288 +               nxi ? atomic_read(&nxi->nx_usecnt) : 0,
14289 +               nxi ? atomic_read(&nxi->nx_tasks) : 0,
14290 +               task, _file, _line);
14291 +
14292 +       might_sleep();
14293 +
14294 +       if (atomic_dec_and_test(&nxi->nx_tasks))
14295 +               unhash_nx_info(nxi);
14296 +}
14297 +
14298 +
14299 +#define task_get_nx_info(i)    __task_get_nx_info(i, __FILE__, __LINE__)
14300 +
14301 +static __inline__ struct nx_info *__task_get_nx_info(struct task_struct *p,
14302 +       const char *_file, int _line)
14303 +{
14304 +       struct nx_info *nxi;
14305 +
14306 +       task_lock(p);
14307 +       vxlprintk(VXD_CBIT(nid, 5), "task_get_nx_info(%p)",
14308 +               p, _file, _line);
14309 +       nxi = __get_nx_info(p->nx_info, _file, _line);
14310 +       task_unlock(p);
14311 +       return nxi;
14312 +}
14313 +
14314 +
14315 +static inline void exit_nx_info(struct task_struct *p)
14316 +{
14317 +       if (p->nx_info)
14318 +               release_nx_info(p->nx_info, p);
14319 +}
14320 +
14321 +
14322 +#else
14323 +#warning duplicate inclusion
14324 +#endif
14325 diff -NurpP --minimal linux-2.6.32.1/include/linux/vs_pid.h linux-2.6.32.1-vs2.3.0.36.27/include/linux/vs_pid.h
14326 --- linux-2.6.32.1/include/linux/vs_pid.h       1970-01-01 01:00:00.000000000 +0100
14327 +++ linux-2.6.32.1-vs2.3.0.36.27/include/linux/vs_pid.h 2009-12-03 20:04:56.000000000 +0100
14328 @@ -0,0 +1,95 @@
14329 +#ifndef _VS_PID_H
14330 +#define _VS_PID_H
14331 +
14332 +#include "vserver/base.h"
14333 +#include "vserver/check.h"
14334 +#include "vserver/context.h"
14335 +#include "vserver/debug.h"
14336 +#include "vserver/pid.h"
14337 +#include <linux/pid_namespace.h>
14338 +
14339 +
14340 +#define VXF_FAKE_INIT  (VXF_INFO_INIT | VXF_STATE_INIT)
14341 +
14342 +static inline
14343 +int vx_proc_task_visible(struct task_struct *task)
14344 +{
14345 +       if ((task->pid == 1) &&
14346 +               !vx_flags(VXF_FAKE_INIT, VXF_FAKE_INIT))
14347 +               /* show a blend through init */
14348 +               goto visible;
14349 +       if (vx_check(vx_task_xid(task), VS_WATCH | VS_IDENT))
14350 +               goto visible;
14351 +       return 0;
14352 +visible:
14353 +       return 1;
14354 +}
14355 +
14356 +#define find_task_by_real_pid(pid) find_task_by_pid_ns(pid, &init_pid_ns)
14357 +
14358 +#if 0
14359 +
14360 +static inline
14361 +struct task_struct *vx_find_proc_task_by_pid(int pid)
14362 +{
14363 +       struct task_struct *task = find_task_by_real_pid(pid);
14364 +
14365 +       if (task && !vx_proc_task_visible(task)) {
14366 +               vxdprintk(VXD_CBIT(misc, 6),
14367 +                       "dropping task (find) %p[#%u,%u] for %p[#%u,%u]",
14368 +                       task, task->xid, task->pid,
14369 +                       current, current->xid, current->pid);
14370 +               task = NULL;
14371 +       }
14372 +       return task;
14373 +}
14374 +
14375 +#endif
14376 +
14377 +static inline
14378 +struct task_struct *vx_get_proc_task(struct inode *inode, struct pid *pid)
14379 +{
14380 +       struct task_struct *task = get_pid_task(pid, PIDTYPE_PID);
14381 +
14382 +       if (task && !vx_proc_task_visible(task)) {
14383 +               vxdprintk(VXD_CBIT(misc, 6),
14384 +                       "dropping task (get) %p[#%u,%u] for %p[#%u,%u]",
14385 +                       task, task->xid, task->pid,
14386 +                       current, current->xid, current->pid);
14387 +               put_task_struct(task);
14388 +               task = NULL;
14389 +       }
14390 +       return task;
14391 +}
14392 +
14393 +#if 0
14394 +
14395 +static inline
14396 +struct task_struct *vx_child_reaper(struct task_struct *p)
14397 +{
14398 +       struct vx_info *vxi = p->vx_info;
14399 +       struct task_struct *reaper = child_reaper(p);
14400 +
14401 +       if (!vxi)
14402 +               goto out;
14403 +
14404 +       BUG_ON(!p->vx_info->vx_reaper);
14405 +
14406 +       /* child reaper for the guest reaper */
14407 +       if (vxi->vx_reaper == p)
14408 +               goto out;
14409 +
14410 +       reaper = vxi->vx_reaper;
14411 +out:
14412 +       vxdprintk(VXD_CBIT(xid, 7),
14413 +               "vx_child_reaper(%p[#%u,%u]) = %p[#%u,%u]",
14414 +               p, p->xid, p->pid, reaper, reaper->xid, reaper->pid);
14415 +       return reaper;
14416 +}
14417 +
14418 +#endif
14419 +
14420 +
14421 +#else
14422 +#warning duplicate inclusion
14423 +#endif
14424 diff -NurpP --minimal linux-2.6.32.1/include/linux/vs_sched.h linux-2.6.32.1-vs2.3.0.36.27/include/linux/vs_sched.h
14425 --- linux-2.6.32.1/include/linux/vs_sched.h     1970-01-01 01:00:00.000000000 +0100
14426 +++ linux-2.6.32.1-vs2.3.0.36.27/include/linux/vs_sched.h       2009-12-03 20:04:56.000000000 +0100
14427 @@ -0,0 +1,110 @@
14428 +#ifndef _VS_SCHED_H
14429 +#define _VS_SCHED_H
14430 +
14431 +#include "vserver/base.h"
14432 +#include "vserver/context.h"
14433 +#include "vserver/sched.h"
14434 +
14435 +
14436 +#define VAVAVOOM_RATIO          50
14437 +
14438 +#define MAX_PRIO_BIAS           20
14439 +#define MIN_PRIO_BIAS          -20
14440 +
14441 +
14442 +#ifdef CONFIG_VSERVER_HARDCPU
14443 +
14444 +/*
14445 + * effective_prio - return the priority that is based on the static
14446 + * priority but is modified by bonuses/penalties.
14447 + *
14448 + * We scale the actual sleep average [0 .... MAX_SLEEP_AVG]
14449 + * into a -4 ... 0 ... +4 bonus/penalty range.
14450 + *
14451 + * Additionally, we scale another amount based on the number of
14452 + * CPU tokens currently held by the context, if the process is
14453 + * part of a context (and the appropriate SCHED flag is set).
14454 + * This ranges from -5 ... 0 ... +15, quadratically.
14455 + *
14456 + * So, the total bonus is -9 .. 0 .. +19
14457 + * We use ~50% of the full 0...39 priority range so that:
14458 + *
14459 + * 1) nice +19 interactive tasks do not preempt nice 0 CPU hogs.
14460 + * 2) nice -20 CPU hogs do not get preempted by nice 0 tasks.
14461 + *    unless that context is far exceeding its CPU allocation.
14462 + *
14463 + * Both properties are important to certain workloads.
14464 + */
14465 +static inline
14466 +int vx_effective_vavavoom(struct _vx_sched_pc *sched_pc, int max_prio)
14467 +{
14468 +       int vavavoom, max;
14469 +
14470 +       /* lots of tokens = lots of vavavoom
14471 +        *      no tokens = no vavavoom      */
14472 +       if ((vavavoom = sched_pc->tokens) >= 0) {
14473 +               max = sched_pc->tokens_max;
14474 +               vavavoom = max - vavavoom;
14475 +               max = max * max;
14476 +               vavavoom = max_prio * VAVAVOOM_RATIO / 100
14477 +                       * (vavavoom*vavavoom - (max >> 2)) / max;
14478 +               return vavavoom;
14479 +       }
14480 +       return 0;
14481 +}
14482 +
14483 +
14484 +static inline
14485 +int vx_adjust_prio(struct task_struct *p, int prio, int max_user)
14486 +{
14487 +       struct vx_info *vxi = p->vx_info;
14488 +       struct _vx_sched_pc *sched_pc;
14489 +
14490 +       if (!vxi)
14491 +               return prio;
14492 +
14493 +       sched_pc = &vx_cpu(vxi, sched_pc);
14494 +       if (vx_info_flags(vxi, VXF_SCHED_PRIO, 0)) {
14495 +               int vavavoom = vx_effective_vavavoom(sched_pc, max_user);
14496 +
14497 +               sched_pc->vavavoom = vavavoom;
14498 +               prio += vavavoom;
14499 +       }
14500 +       prio += sched_pc->prio_bias;
14501 +       return prio;
14502 +}
14503 +
14504 +#else /* !CONFIG_VSERVER_HARDCPU */
14505 +
14506 +static inline
14507 +int vx_adjust_prio(struct task_struct *p, int prio, int max_user)
14508 +{
14509 +       struct vx_info *vxi = p->vx_info;
14510 +
14511 +       if (vxi)
14512 +               prio += vx_cpu(vxi, sched_pc).prio_bias;
14513 +       return prio;
14514 +}
14515 +
14516 +#endif /* CONFIG_VSERVER_HARDCPU */
14517 +
14518 +
14519 +static inline void vx_account_user(struct vx_info *vxi,
14520 +       cputime_t cputime, int nice)
14521 +{
14522 +       if (!vxi)
14523 +               return;
14524 +       vx_cpu(vxi, sched_pc).user_ticks += cputime;
14525 +}
14526 +
14527 +static inline void vx_account_system(struct vx_info *vxi,
14528 +       cputime_t cputime, int idle)
14529 +{
14530 +       if (!vxi)
14531 +               return;
14532 +       vx_cpu(vxi, sched_pc).sys_ticks += cputime;
14533 +}
14534 +
14535 +#else
14536 +#warning duplicate inclusion
14537 +#endif
14538 diff -NurpP --minimal linux-2.6.32.1/include/linux/vs_socket.h linux-2.6.32.1-vs2.3.0.36.27/include/linux/vs_socket.h
14539 --- linux-2.6.32.1/include/linux/vs_socket.h    1970-01-01 01:00:00.000000000 +0100
14540 +++ linux-2.6.32.1-vs2.3.0.36.27/include/linux/vs_socket.h      2009-12-03 20:04:56.000000000 +0100
14541 @@ -0,0 +1,67 @@
14542 +#ifndef _VS_SOCKET_H
14543 +#define _VS_SOCKET_H
14544 +
14545 +#include "vserver/debug.h"
14546 +#include "vserver/base.h"
14547 +#include "vserver/cacct.h"
14548 +#include "vserver/context.h"
14549 +#include "vserver/tag.h"
14550 +
14551 +
14552 +/* socket accounting */
14553 +
14554 +#include <linux/socket.h>
14555 +
14556 +static inline int vx_sock_type(int family)
14557 +{
14558 +       switch (family) {
14559 +       case PF_UNSPEC:
14560 +               return VXA_SOCK_UNSPEC;
14561 +       case PF_UNIX:
14562 +               return VXA_SOCK_UNIX;
14563 +       case PF_INET:
14564 +               return VXA_SOCK_INET;
14565 +       case PF_INET6:
14566 +               return VXA_SOCK_INET6;
14567 +       case PF_PACKET:
14568 +               return VXA_SOCK_PACKET;
14569 +       default:
14570 +               return VXA_SOCK_OTHER;
14571 +       }
14572 +}
14573 +
14574 +#define vx_acc_sock(v, f, p, s) \
14575 +       __vx_acc_sock(v, f, p, s, __FILE__, __LINE__)
14576 +
14577 +static inline void __vx_acc_sock(struct vx_info *vxi,
14578 +       int family, int pos, int size, char *file, int line)
14579 +{
14580 +       if (vxi) {
14581 +               int type = vx_sock_type(family);
14582 +
14583 +               atomic_long_inc(&vxi->cacct.sock[type][pos].count);
14584 +               atomic_long_add(size, &vxi->cacct.sock[type][pos].total);
14585 +       }
14586 +}
14587 +
14588 +#define vx_sock_recv(sk, s) \
14589 +       vx_acc_sock((sk)->sk_vx_info, (sk)->sk_family, 0, s)
14590 +#define vx_sock_send(sk, s) \
14591 +       vx_acc_sock((sk)->sk_vx_info, (sk)->sk_family, 1, s)
14592 +#define vx_sock_fail(sk, s) \
14593 +       vx_acc_sock((sk)->sk_vx_info, (sk)->sk_family, 2, s)
14594 +
14595 +
14596 +#define sock_vx_init(s) do {           \
14597 +       (s)->sk_xid = 0;                \
14598 +       (s)->sk_vx_info = NULL;         \
14599 +       } while (0)
14600 +
14601 +#define sock_nx_init(s) do {           \
14602 +       (s)->sk_nid = 0;                \
14603 +       (s)->sk_nx_info = NULL;         \
14604 +       } while (0)
14605 +
14606 +#else
14607 +#warning duplicate inclusion
14608 +#endif
14609 diff -NurpP --minimal linux-2.6.32.1/include/linux/vs_tag.h linux-2.6.32.1-vs2.3.0.36.27/include/linux/vs_tag.h
14610 --- linux-2.6.32.1/include/linux/vs_tag.h       1970-01-01 01:00:00.000000000 +0100
14611 +++ linux-2.6.32.1-vs2.3.0.36.27/include/linux/vs_tag.h 2009-12-03 20:04:56.000000000 +0100
14612 @@ -0,0 +1,47 @@
14613 +#ifndef _VS_TAG_H
14614 +#define _VS_TAG_H
14615 +
14616 +#include <linux/vserver/tag.h>
14617 +
14618 +/* check conditions */
14619 +
14620 +#define DX_ADMIN       0x0001
14621 +#define DX_WATCH       0x0002
14622 +#define DX_HOSTID      0x0008
14623 +
14624 +#define DX_IDENT       0x0010
14625 +
14626 +#define DX_ARG_MASK    0x0010
14627 +
14628 +
14629 +#define dx_task_tag(t) ((t)->tag)
14630 +
14631 +#define dx_current_tag() dx_task_tag(current)
14632 +
14633 +#define dx_check(c, m) __dx_check(dx_current_tag(), c, m)
14634 +
14635 +#define dx_weak_check(c, m)    ((m) ? dx_check(c, m) : 1)
14636 +
14637 +
14638 +/*
14639 + * check current context for ADMIN/WATCH and
14640 + * optionally against supplied argument
14641 + */
14642 +static inline int __dx_check(tag_t cid, tag_t id, unsigned int mode)
14643 +{
14644 +       if (mode & DX_ARG_MASK) {
14645 +               if ((mode & DX_IDENT) && (id == cid))
14646 +                       return 1;
14647 +       }
14648 +       return (((mode & DX_ADMIN) && (cid == 0)) ||
14649 +               ((mode & DX_WATCH) && (cid == 1)) ||
14650 +               ((mode & DX_HOSTID) && (id == 0)));
14651 +}
14652 +
14653 +struct inode;
14654 +int dx_permission(const struct inode *inode, int mask);
14655 +
14656 +
14657 +#else
14658 +#warning duplicate inclusion
14659 +#endif
14660 diff -NurpP --minimal linux-2.6.32.1/include/linux/vs_time.h linux-2.6.32.1-vs2.3.0.36.27/include/linux/vs_time.h
14661 --- linux-2.6.32.1/include/linux/vs_time.h      1970-01-01 01:00:00.000000000 +0100
14662 +++ linux-2.6.32.1-vs2.3.0.36.27/include/linux/vs_time.h        2009-12-03 20:04:56.000000000 +0100
14663 @@ -0,0 +1,19 @@
14664 +#ifndef _VS_TIME_H
14665 +#define _VS_TIME_H
14666 +
14667 +
14668 +/* time faking stuff */
14669 +
14670 +#ifdef CONFIG_VSERVER_VTIME
14671 +
14672 +extern void vx_gettimeofday(struct timeval *tv);
14673 +extern int vx_settimeofday(struct timespec *ts);
14674 +
14675 +#else
14676 +#define        vx_gettimeofday(t)      do_gettimeofday(t)
14677 +#define        vx_settimeofday(t)      do_settimeofday(t)
14678 +#endif
14679 +
14680 +#else
14681 +#warning duplicate inclusion
14682 +#endif
14683 diff -NurpP --minimal linux-2.6.32.1/include/net/addrconf.h linux-2.6.32.1-vs2.3.0.36.27/include/net/addrconf.h
14684 --- linux-2.6.32.1/include/net/addrconf.h       2009-12-03 20:02:57.000000000 +0100
14685 +++ linux-2.6.32.1-vs2.3.0.36.27/include/net/addrconf.h 2009-12-03 20:04:56.000000000 +0100
14686 @@ -84,7 +84,8 @@ extern int                    ipv6_dev_get_saddr(struct n
14687                                                struct net_device *dev,
14688                                                const struct in6_addr *daddr,
14689                                                unsigned int srcprefs,
14690 -                                              struct in6_addr *saddr);
14691 +                                              struct in6_addr *saddr,
14692 +                                              struct nx_info *nxi);
14693  extern int                     ipv6_get_lladdr(struct net_device *dev,
14694                                                 struct in6_addr *addr,
14695                                                 unsigned char banned_flags);
14696 diff -NurpP --minimal linux-2.6.32.1/include/net/af_unix.h linux-2.6.32.1-vs2.3.0.36.27/include/net/af_unix.h
14697 --- linux-2.6.32.1/include/net/af_unix.h        2008-12-25 00:26:37.000000000 +0100
14698 +++ linux-2.6.32.1-vs2.3.0.36.27/include/net/af_unix.h  2009-12-03 20:04:56.000000000 +0100
14699 @@ -4,6 +4,7 @@
14700  #include <linux/socket.h>
14701  #include <linux/un.h>
14702  #include <linux/mutex.h>
14703 +#include <linux/vs_base.h>
14704  #include <net/sock.h>
14705  
14706  extern void unix_inflight(struct file *fp);
14707 diff -NurpP --minimal linux-2.6.32.1/include/net/inet_timewait_sock.h linux-2.6.32.1-vs2.3.0.36.27/include/net/inet_timewait_sock.h
14708 --- linux-2.6.32.1/include/net/inet_timewait_sock.h     2009-12-03 20:02:57.000000000 +0100
14709 +++ linux-2.6.32.1-vs2.3.0.36.27/include/net/inet_timewait_sock.h       2009-12-03 20:04:56.000000000 +0100
14710 @@ -117,6 +117,10 @@ struct inet_timewait_sock {
14711  #define tw_hash                        __tw_common.skc_hash
14712  #define tw_prot                        __tw_common.skc_prot
14713  #define tw_net                 __tw_common.skc_net
14714 +#define tw_xid                 __tw_common.skc_xid
14715 +#define tw_vx_info             __tw_common.skc_vx_info
14716 +#define tw_nid                 __tw_common.skc_nid
14717 +#define tw_nx_info             __tw_common.skc_nx_info
14718         int                     tw_timeout;
14719         volatile unsigned char  tw_substate;
14720         /* 3 bits hole, try to pack */
14721 diff -NurpP --minimal linux-2.6.32.1/include/net/route.h linux-2.6.32.1-vs2.3.0.36.27/include/net/route.h
14722 --- linux-2.6.32.1/include/net/route.h  2009-09-10 15:26:27.000000000 +0200
14723 +++ linux-2.6.32.1-vs2.3.0.36.27/include/net/route.h    2009-12-03 20:04:56.000000000 +0100
14724 @@ -135,6 +135,9 @@ static inline void ip_rt_put(struct rtab
14725                 dst_release(&rt->u.dst);
14726  }
14727  
14728 +#include <linux/vs_base.h>
14729 +#include <linux/vs_inet.h>
14730 +
14731  #define IPTOS_RT_MASK  (IPTOS_TOS_MASK & ~3)
14732  
14733  extern const __u8 ip_tos2prio[16];
14734 @@ -144,6 +147,9 @@ static inline char rt_tos2priority(u8 to
14735         return ip_tos2prio[IPTOS_TOS(tos)>>1];
14736  }
14737  
14738 +extern int ip_v4_find_src(struct net *net, struct nx_info *,
14739 +       struct rtable **, struct flowi *);
14740 +
14741  static inline int ip_route_connect(struct rtable **rp, __be32 dst,
14742                                    __be32 src, u32 tos, int oif, u8 protocol,
14743                                    __be16 sport, __be16 dport, struct sock *sk,
14744 @@ -161,11 +167,24 @@ static inline int ip_route_connect(struc
14745  
14746         int err;
14747         struct net *net = sock_net(sk);
14748 +       struct nx_info *nx_info = current_nx_info();
14749  
14750         if (inet_sk(sk)->transparent)
14751                 fl.flags |= FLOWI_FLAG_ANYSRC;
14752  
14753 -       if (!dst || !src) {
14754 +       if (sk)
14755 +               nx_info = sk->sk_nx_info;
14756 +
14757 +       vxdprintk(VXD_CBIT(net, 4),
14758 +               "ip_route_connect(%p) %p,%p;%lx",
14759 +               sk, nx_info, sk->sk_socket,
14760 +               (sk->sk_socket?sk->sk_socket->flags:0));
14761 +
14762 +       err = ip_v4_find_src(net, nx_info, rp, &fl);
14763 +       if (err)
14764 +               return err;
14765 +
14766 +       if (!fl.fl4_dst || !fl.fl4_src) {
14767                 err = __ip_route_output_key(net, rp, &fl);
14768                 if (err)
14769                         return err;
14770 diff -NurpP --minimal linux-2.6.32.1/include/net/sock.h linux-2.6.32.1-vs2.3.0.36.27/include/net/sock.h
14771 --- linux-2.6.32.1/include/net/sock.h   2009-12-03 20:02:57.000000000 +0100
14772 +++ linux-2.6.32.1-vs2.3.0.36.27/include/net/sock.h     2009-12-03 20:04:56.000000000 +0100
14773 @@ -139,6 +139,10 @@ struct sock_common {
14774  #ifdef CONFIG_NET_NS
14775         struct net              *skc_net;
14776  #endif
14777 +       xid_t                   skc_xid;
14778 +       struct vx_info          *skc_vx_info;
14779 +       nid_t                   skc_nid;
14780 +       struct nx_info          *skc_nx_info;
14781  };
14782  
14783  /**
14784 @@ -225,6 +229,10 @@ struct sock {
14785  #define sk_bind_node           __sk_common.skc_bind_node
14786  #define sk_prot                        __sk_common.skc_prot
14787  #define sk_net                 __sk_common.skc_net
14788 +#define sk_xid                 __sk_common.skc_xid
14789 +#define sk_vx_info             __sk_common.skc_vx_info
14790 +#define sk_nid                 __sk_common.skc_nid
14791 +#define sk_nx_info             __sk_common.skc_nx_info
14792         kmemcheck_bitfield_begin(flags);
14793         unsigned int            sk_shutdown  : 2,
14794                                 sk_no_check  : 2,
14795 diff -NurpP --minimal linux-2.6.32.1/init/Kconfig linux-2.6.32.1-vs2.3.0.36.27/init/Kconfig
14796 --- linux-2.6.32.1/init/Kconfig 2009-12-03 20:02:57.000000000 +0100
14797 +++ linux-2.6.32.1-vs2.3.0.36.27/init/Kconfig   2009-12-03 20:04:56.000000000 +0100
14798 @@ -477,6 +477,19 @@ config CGROUP_SCHED
14799  
14800  endchoice
14801  
14802 +config CFS_HARD_LIMITS
14803 +       bool "Hard Limits for CFS Group Scheduler"
14804 +       depends on EXPERIMENTAL
14805 +       depends on FAIR_GROUP_SCHED && CGROUP_SCHED
14806 +       default n
14807 +       help
14808 +         This option enables hard limiting of CPU time obtained by
14809 +         a fair task group. Use this if you want to throttle a group of tasks
14810 +         based on its CPU usage. For more details refer to
14811 +         Documentation/scheduler/sched-cfs-hard-limits.txt
14812 +
14813 +         Say N if unsure.
14814 +
14815  menuconfig CGROUPS
14816         boolean "Control Group support"
14817         help
14818 diff -NurpP --minimal linux-2.6.32.1/init/main.c linux-2.6.32.1-vs2.3.0.36.27/init/main.c
14819 --- linux-2.6.32.1/init/main.c  2009-12-03 20:02:57.000000000 +0100
14820 +++ linux-2.6.32.1-vs2.3.0.36.27/init/main.c    2009-12-03 20:04:56.000000000 +0100
14821 @@ -70,6 +70,7 @@
14822  #include <linux/sfi.h>
14823  #include <linux/shmem_fs.h>
14824  #include <trace/boot.h>
14825 +#include <linux/vserver/percpu.h>
14826  
14827  #include <asm/io.h>
14828  #include <asm/bugs.h>
14829 diff -NurpP --minimal linux-2.6.32.1/ipc/mqueue.c linux-2.6.32.1-vs2.3.0.36.27/ipc/mqueue.c
14830 --- linux-2.6.32.1/ipc/mqueue.c 2009-12-03 20:02:57.000000000 +0100
14831 +++ linux-2.6.32.1-vs2.3.0.36.27/ipc/mqueue.c   2009-12-03 20:04:56.000000000 +0100
14832 @@ -33,6 +33,8 @@
14833  #include <linux/pid.h>
14834  #include <linux/ipc_namespace.h>
14835  #include <linux/ima.h>
14836 +#include <linux/vs_context.h>
14837 +#include <linux/vs_limit.h>
14838  
14839  #include <net/sock.h>
14840  #include "util.h"
14841 @@ -66,6 +68,7 @@ struct mqueue_inode_info {
14842         struct sigevent notify;
14843         struct pid* notify_owner;
14844         struct user_struct *user;       /* user who created, for accounting */
14845 +       struct vx_info *vxi;
14846         struct sock *notify_sock;
14847         struct sk_buff *notify_cookie;
14848  
14849 @@ -125,6 +128,7 @@ static struct inode *mqueue_get_inode(st
14850                 if (S_ISREG(mode)) {
14851                         struct mqueue_inode_info *info;
14852                         struct task_struct *p = current;
14853 +                       struct vx_info *vxi = p->vx_info;
14854                         unsigned long mq_bytes, mq_msg_tblsz;
14855  
14856                         inode->i_fop = &mqueue_file_operations;
14857 @@ -139,6 +143,7 @@ static struct inode *mqueue_get_inode(st
14858                         info->notify_owner = NULL;
14859                         info->qsize = 0;
14860                         info->user = NULL;      /* set when all is ok */
14861 +                       info->vxi = NULL;
14862                         memset(&info->attr, 0, sizeof(info->attr));
14863                         info->attr.mq_maxmsg = ipc_ns->mq_msg_max;
14864                         info->attr.mq_msgsize = ipc_ns->mq_msgsize_max;
14865 @@ -153,22 +158,26 @@ static struct inode *mqueue_get_inode(st
14866                         spin_lock(&mq_lock);
14867                         if (u->mq_bytes + mq_bytes < u->mq_bytes ||
14868                             u->mq_bytes + mq_bytes >
14869 -                           p->signal->rlim[RLIMIT_MSGQUEUE].rlim_cur) {
14870 +                           p->signal->rlim[RLIMIT_MSGQUEUE].rlim_cur ||
14871 +                           !vx_ipcmsg_avail(vxi, mq_bytes)) {
14872                                 spin_unlock(&mq_lock);
14873                                 goto out_inode;
14874                         }
14875                         u->mq_bytes += mq_bytes;
14876 +                       vx_ipcmsg_add(vxi, u, mq_bytes);
14877                         spin_unlock(&mq_lock);
14878  
14879                         info->messages = kmalloc(mq_msg_tblsz, GFP_KERNEL);
14880                         if (!info->messages) {
14881                                 spin_lock(&mq_lock);
14882                                 u->mq_bytes -= mq_bytes;
14883 +                               vx_ipcmsg_sub(vxi, u, mq_bytes);
14884                                 spin_unlock(&mq_lock);
14885                                 goto out_inode;
14886                         }
14887                         /* all is ok */
14888                         info->user = get_uid(u);
14889 +                       info->vxi = get_vx_info(vxi);
14890                 } else if (S_ISDIR(mode)) {
14891                         inc_nlink(inode);
14892                         /* Some things misbehave if size == 0 on a directory */
14893 @@ -269,8 +278,11 @@ static void mqueue_delete_inode(struct i
14894                    (info->attr.mq_maxmsg * info->attr.mq_msgsize));
14895         user = info->user;
14896         if (user) {
14897 +               struct vx_info *vxi = info->vxi;
14898 +
14899                 spin_lock(&mq_lock);
14900                 user->mq_bytes -= mq_bytes;
14901 +               vx_ipcmsg_sub(vxi, user, mq_bytes);
14902                 /*
14903                  * get_ns_from_inode() ensures that the
14904                  * (ipc_ns = sb->s_fs_info) is either a valid ipc_ns
14905 @@ -280,6 +292,7 @@ static void mqueue_delete_inode(struct i
14906                 if (ipc_ns)
14907                         ipc_ns->mq_queues_count--;
14908                 spin_unlock(&mq_lock);
14909 +               put_vx_info(vxi);
14910                 free_uid(user);
14911         }
14912         if (ipc_ns)
14913 diff -NurpP --minimal linux-2.6.32.1/ipc/msg.c linux-2.6.32.1-vs2.3.0.36.27/ipc/msg.c
14914 --- linux-2.6.32.1/ipc/msg.c    2009-03-24 14:22:44.000000000 +0100
14915 +++ linux-2.6.32.1-vs2.3.0.36.27/ipc/msg.c      2009-12-03 20:04:56.000000000 +0100
14916 @@ -38,6 +38,7 @@
14917  #include <linux/rwsem.h>
14918  #include <linux/nsproxy.h>
14919  #include <linux/ipc_namespace.h>
14920 +#include <linux/vs_base.h>
14921  
14922  #include <asm/current.h>
14923  #include <asm/uaccess.h>
14924 @@ -190,6 +191,7 @@ static int newque(struct ipc_namespace *
14925  
14926         msq->q_perm.mode = msgflg & S_IRWXUGO;
14927         msq->q_perm.key = key;
14928 +       msq->q_perm.xid = vx_current_xid();
14929  
14930         msq->q_perm.security = NULL;
14931         retval = security_msg_queue_alloc(msq);
14932 diff -NurpP --minimal linux-2.6.32.1/ipc/namespace.c linux-2.6.32.1-vs2.3.0.36.27/ipc/namespace.c
14933 --- linux-2.6.32.1/ipc/namespace.c      2009-09-10 15:26:27.000000000 +0200
14934 +++ linux-2.6.32.1-vs2.3.0.36.27/ipc/namespace.c        2009-12-03 20:04:56.000000000 +0100
14935 @@ -11,6 +11,8 @@
14936  #include <linux/slab.h>
14937  #include <linux/fs.h>
14938  #include <linux/mount.h>
14939 +#include <linux/vs_base.h>
14940 +#include <linux/vserver/global.h>
14941  
14942  #include "util.h"
14943  
14944 diff -NurpP --minimal linux-2.6.32.1/ipc/sem.c linux-2.6.32.1-vs2.3.0.36.27/ipc/sem.c
14945 --- linux-2.6.32.1/ipc/sem.c    2009-09-10 15:26:27.000000000 +0200
14946 +++ linux-2.6.32.1-vs2.3.0.36.27/ipc/sem.c      2009-12-03 20:04:56.000000000 +0100
14947 @@ -83,6 +83,8 @@
14948  #include <linux/rwsem.h>
14949  #include <linux/nsproxy.h>
14950  #include <linux/ipc_namespace.h>
14951 +#include <linux/vs_base.h>
14952 +#include <linux/vs_limit.h>
14953  
14954  #include <asm/uaccess.h>
14955  #include "util.h"
14956 @@ -255,6 +257,7 @@ static int newary(struct ipc_namespace *
14957  
14958         sma->sem_perm.mode = (semflg & S_IRWXUGO);
14959         sma->sem_perm.key = key;
14960 +       sma->sem_perm.xid = vx_current_xid();
14961  
14962         sma->sem_perm.security = NULL;
14963         retval = security_sem_alloc(sma);
14964 @@ -270,6 +273,9 @@ static int newary(struct ipc_namespace *
14965                 return id;
14966         }
14967         ns->used_sems += nsems;
14968 +       /* FIXME: obsoleted? */
14969 +       vx_semary_inc(sma);
14970 +       vx_nsems_add(sma, nsems);
14971  
14972         sma->sem_base = (struct sem *) &sma[1];
14973         INIT_LIST_HEAD(&sma->sem_pending);
14974 @@ -546,6 +552,9 @@ static void freeary(struct ipc_namespace
14975         sem_unlock(sma);
14976  
14977         ns->used_sems -= sma->sem_nsems;
14978 +       /* FIXME: obsoleted? */
14979 +       vx_nsems_sub(sma, sma->sem_nsems);
14980 +       vx_semary_dec(sma);
14981         security_sem_free(sma);
14982         ipc_rcu_putref(sma);
14983  }
14984 diff -NurpP --minimal linux-2.6.32.1/ipc/shm.c linux-2.6.32.1-vs2.3.0.36.27/ipc/shm.c
14985 --- linux-2.6.32.1/ipc/shm.c    2009-12-03 20:02:57.000000000 +0100
14986 +++ linux-2.6.32.1-vs2.3.0.36.27/ipc/shm.c      2009-12-03 20:04:56.000000000 +0100
14987 @@ -40,6 +40,8 @@
14988  #include <linux/mount.h>
14989  #include <linux/ipc_namespace.h>
14990  #include <linux/ima.h>
14991 +#include <linux/vs_context.h>
14992 +#include <linux/vs_limit.h>
14993  
14994  #include <asm/uaccess.h>
14995  
14996 @@ -169,7 +171,12 @@ static void shm_open(struct vm_area_stru
14997   */
14998  static void shm_destroy(struct ipc_namespace *ns, struct shmid_kernel *shp)
14999  {
15000 -       ns->shm_tot -= (shp->shm_segsz + PAGE_SIZE - 1) >> PAGE_SHIFT;
15001 +       struct vx_info *vxi = lookup_vx_info(shp->shm_perm.xid);
15002 +       int numpages = (shp->shm_segsz + PAGE_SIZE - 1) >> PAGE_SHIFT;
15003 +
15004 +       vx_ipcshm_sub(vxi, shp, numpages);
15005 +       ns->shm_tot -= numpages;
15006 +
15007         shm_rmid(ns, shp);
15008         shm_unlock(shp);
15009         if (!is_file_hugepages(shp->shm_file))
15010 @@ -179,6 +186,7 @@ static void shm_destroy(struct ipc_names
15011                                                 shp->mlock_user);
15012         fput (shp->shm_file);
15013         security_shm_free(shp);
15014 +       put_vx_info(vxi);
15015         ipc_rcu_putref(shp);
15016  }
15017  
15018 @@ -349,11 +357,15 @@ static int newseg(struct ipc_namespace *
15019         if (ns->shm_tot + numpages > ns->shm_ctlall)
15020                 return -ENOSPC;
15021  
15022 +       if (!vx_ipcshm_avail(current_vx_info(), numpages))
15023 +               return -ENOSPC;
15024 +
15025         shp = ipc_rcu_alloc(sizeof(*shp));
15026         if (!shp)
15027                 return -ENOMEM;
15028  
15029         shp->shm_perm.key = key;
15030 +       shp->shm_perm.xid = vx_current_xid();
15031         shp->shm_perm.mode = (shmflg & S_IRWXUGO);
15032         shp->mlock_user = NULL;
15033  
15034 @@ -407,6 +419,7 @@ static int newseg(struct ipc_namespace *
15035         ns->shm_tot += numpages;
15036         error = shp->shm_perm.id;
15037         shm_unlock(shp);
15038 +       vx_ipcshm_add(current_vx_info(), key, numpages);
15039         return error;
15040  
15041  no_id:
15042 diff -NurpP --minimal linux-2.6.32.1/kernel/capability.c linux-2.6.32.1-vs2.3.0.36.27/kernel/capability.c
15043 --- linux-2.6.32.1/kernel/capability.c  2009-03-24 14:22:44.000000000 +0100
15044 +++ linux-2.6.32.1-vs2.3.0.36.27/kernel/capability.c    2009-12-03 20:04:56.000000000 +0100
15045 @@ -14,6 +14,7 @@
15046  #include <linux/security.h>
15047  #include <linux/syscalls.h>
15048  #include <linux/pid_namespace.h>
15049 +#include <linux/vs_context.h>
15050  #include <asm/uaccess.h>
15051  #include "cred-internals.h"
15052  
15053 @@ -122,6 +123,7 @@ static int cap_validate_magic(cap_user_h
15054         return 0;
15055  }
15056  
15057 +
15058  /*
15059   * The only thing that can change the capabilities of the current
15060   * process is the current process. As such, we can't be in this code
15061 @@ -289,6 +291,8 @@ error:
15062         return ret;
15063  }
15064  
15065 +#include <linux/vserver/base.h>
15066 +
15067  /**
15068   * capable - Determine if the current task has a superior capability in effect
15069   * @cap: The capability to be tested for
15070 @@ -301,6 +305,9 @@ error:
15071   */
15072  int capable(int cap)
15073  {
15074 +       /* here for now so we don't require task locking */
15075 +       if (vs_check_bit(VXC_CAP_MASK, cap) && !vx_mcaps(1L << cap))
15076 +               return 0;
15077         if (unlikely(!cap_valid(cap))) {
15078                 printk(KERN_CRIT "capable() called with invalid cap=%u\n", cap);
15079                 BUG();
15080 diff -NurpP --minimal linux-2.6.32.1/kernel/compat.c linux-2.6.32.1-vs2.3.0.36.27/kernel/compat.c
15081 --- linux-2.6.32.1/kernel/compat.c      2009-09-10 15:26:27.000000000 +0200
15082 +++ linux-2.6.32.1-vs2.3.0.36.27/kernel/compat.c        2009-12-03 20:04:56.000000000 +0100
15083 @@ -902,7 +902,7 @@ asmlinkage long compat_sys_time(compat_t
15084         compat_time_t i;
15085         struct timeval tv;
15086  
15087 -       do_gettimeofday(&tv);
15088 +       vx_gettimeofday(&tv);
15089         i = tv.tv_sec;
15090  
15091         if (tloc) {
15092 @@ -927,7 +927,7 @@ asmlinkage long compat_sys_stime(compat_
15093         if (err)
15094                 return err;
15095  
15096 -       do_settimeofday(&tv);
15097 +       vx_settimeofday(&tv);
15098         return 0;
15099  }
15100  
15101 diff -NurpP --minimal linux-2.6.32.1/kernel/exit.c linux-2.6.32.1-vs2.3.0.36.27/kernel/exit.c
15102 --- linux-2.6.32.1/kernel/exit.c        2009-12-03 20:02:57.000000000 +0100
15103 +++ linux-2.6.32.1-vs2.3.0.36.27/kernel/exit.c  2009-12-03 20:04:56.000000000 +0100
15104 @@ -48,6 +48,10 @@
15105  #include <linux/fs_struct.h>
15106  #include <linux/init_task.h>
15107  #include <linux/perf_event.h>
15108 +#include <linux/vs_limit.h>
15109 +#include <linux/vs_context.h>
15110 +#include <linux/vs_network.h>
15111 +#include <linux/vs_pid.h>
15112  #include <trace/events/sched.h>
15113  
15114  #include <asm/uaccess.h>
15115 @@ -488,9 +492,11 @@ static void close_files(struct files_str
15116                                         filp_close(file, files);
15117                                         cond_resched();
15118                                 }
15119 +                               vx_openfd_dec(i);
15120                         }
15121                         i++;
15122                         set >>= 1;
15123 +                       cond_resched();
15124                 }
15125         }
15126  }
15127 @@ -1011,11 +1017,16 @@ NORET_TYPE void do_exit(long code)
15128  
15129         validate_creds_for_do_exit(tsk);
15130  
15131 +       /* needs to stay after exit_notify() */
15132 +       exit_vx_info(tsk, code);
15133 +       exit_nx_info(tsk);
15134 +
15135         preempt_disable();
15136         exit_rcu();
15137         /* causes final put_task_struct in finish_task_switch(). */
15138         tsk->state = TASK_DEAD;
15139         schedule();
15140 +       printk("bad task: %p [%lx]\n", current, current->state);
15141         BUG();
15142         /* Avoid "noreturn function does return".  */
15143         for (;;)
15144 diff -NurpP --minimal linux-2.6.32.1/kernel/fork.c linux-2.6.32.1-vs2.3.0.36.27/kernel/fork.c
15145 --- linux-2.6.32.1/kernel/fork.c        2009-12-03 20:02:57.000000000 +0100
15146 +++ linux-2.6.32.1-vs2.3.0.36.27/kernel/fork.c  2009-12-03 20:04:56.000000000 +0100
15147 @@ -64,6 +64,10 @@
15148  #include <linux/magic.h>
15149  #include <linux/perf_event.h>
15150  #include <linux/posix-timers.h>
15151 +#include <linux/vs_context.h>
15152 +#include <linux/vs_network.h>
15153 +#include <linux/vs_limit.h>
15154 +#include <linux/vs_memory.h>
15155  
15156  #include <asm/pgtable.h>
15157  #include <asm/pgalloc.h>
15158 @@ -151,6 +155,8 @@ void free_task(struct task_struct *tsk)
15159         account_kernel_stack(tsk->stack, -1);
15160         free_thread_info(tsk->stack);
15161         rt_mutex_debug_task_free(tsk);
15162 +       clr_vx_info(&tsk->vx_info);
15163 +       clr_nx_info(&tsk->nx_info);
15164         ftrace_graph_exit_task(tsk);
15165         free_task_struct(tsk);
15166  }
15167 @@ -296,6 +302,8 @@ static int dup_mmap(struct mm_struct *mm
15168         mm->free_area_cache = oldmm->mmap_base;
15169         mm->cached_hole_size = ~0UL;
15170         mm->map_count = 0;
15171 +       __set_mm_counter(mm, file_rss, 0);
15172 +       __set_mm_counter(mm, anon_rss, 0);
15173         cpumask_clear(mm_cpumask(mm));
15174         mm->mm_rb = RB_ROOT;
15175         rb_link = &mm->mm_rb.rb_node;
15176 @@ -310,7 +318,7 @@ static int dup_mmap(struct mm_struct *mm
15177  
15178                 if (mpnt->vm_flags & VM_DONTCOPY) {
15179                         long pages = vma_pages(mpnt);
15180 -                       mm->total_vm -= pages;
15181 +                       vx_vmpages_sub(mm, pages);
15182                         vm_stat_account(mm, mpnt->vm_flags, mpnt->vm_file,
15183                                                                 -pages);
15184                         continue;
15185 @@ -452,8 +460,8 @@ static struct mm_struct * mm_init(struct
15186                 (current->mm->flags & MMF_INIT_MASK) : default_dump_filter;
15187         mm->core_state = NULL;
15188         mm->nr_ptes = 0;
15189 -       set_mm_counter(mm, file_rss, 0);
15190 -       set_mm_counter(mm, anon_rss, 0);
15191 +       __set_mm_counter(mm, file_rss, 0);
15192 +       __set_mm_counter(mm, anon_rss, 0);
15193         spin_lock_init(&mm->page_table_lock);
15194         mm->free_area_cache = TASK_UNMAPPED_BASE;
15195         mm->cached_hole_size = ~0UL;
15196 @@ -463,6 +471,7 @@ static struct mm_struct * mm_init(struct
15197         if (likely(!mm_alloc_pgd(mm))) {
15198                 mm->def_flags = 0;
15199                 mmu_notifier_mm_init(mm);
15200 +               set_vx_info(&mm->mm_vx_info, p->vx_info);
15201                 return mm;
15202         }
15203  
15204 @@ -496,6 +505,7 @@ void __mmdrop(struct mm_struct *mm)
15205         mm_free_pgd(mm);
15206         destroy_context(mm);
15207         mmu_notifier_mm_destroy(mm);
15208 +       clr_vx_info(&mm->mm_vx_info);
15209         free_mm(mm);
15210  }
15211  EXPORT_SYMBOL_GPL(__mmdrop);
15212 @@ -631,6 +641,7 @@ struct mm_struct *dup_mm(struct task_str
15213                 goto fail_nomem;
15214  
15215         memcpy(mm, oldmm, sizeof(*mm));
15216 +       mm->mm_vx_info = NULL;
15217  
15218         /* Initializing for Swap token stuff */
15219         mm->token_priority = 0;
15220 @@ -669,6 +680,7 @@ fail_nocontext:
15221          * If init_new_context() failed, we cannot use mmput() to free the mm
15222          * because it calls destroy_context()
15223          */
15224 +       clr_vx_info(&mm->mm_vx_info);
15225         mm_free_pgd(mm);
15226         free_mm(mm);
15227         return NULL;
15228 @@ -980,6 +992,8 @@ static struct task_struct *copy_process(
15229         int retval;
15230         struct task_struct *p;
15231         int cgroup_callbacks_done = 0;
15232 +       struct vx_info *vxi;
15233 +       struct nx_info *nxi;
15234  
15235         if ((clone_flags & (CLONE_NEWNS|CLONE_FS)) == (CLONE_NEWNS|CLONE_FS))
15236                 return ERR_PTR(-EINVAL);
15237 @@ -1026,12 +1040,28 @@ static struct task_struct *copy_process(
15238         DEBUG_LOCKS_WARN_ON(!p->hardirqs_enabled);
15239         DEBUG_LOCKS_WARN_ON(!p->softirqs_enabled);
15240  #endif
15241 +       init_vx_info(&p->vx_info, current_vx_info());
15242 +       init_nx_info(&p->nx_info, current_nx_info());
15243 +
15244 +       /* check vserver memory */
15245 +       if (p->mm && !(clone_flags & CLONE_VM)) {
15246 +               if (vx_vmpages_avail(p->mm, p->mm->total_vm))
15247 +                       vx_pages_add(p->vx_info, RLIMIT_AS, p->mm->total_vm);
15248 +               else
15249 +                       goto bad_fork_free;
15250 +       }
15251 +       if (p->mm && vx_flags(VXF_FORK_RSS, 0)) {
15252 +               if (!vx_rss_avail(p->mm, get_mm_counter(p->mm, file_rss)))
15253 +                       goto bad_fork_cleanup_vm;
15254 +       }
15255         retval = -EAGAIN;
15256 +       if (!vx_nproc_avail(1))
15257 +               goto bad_fork_cleanup_vm;
15258         if (atomic_read(&p->real_cred->user->processes) >=
15259                         p->signal->rlim[RLIMIT_NPROC].rlim_cur) {
15260                 if (!capable(CAP_SYS_ADMIN) && !capable(CAP_SYS_RESOURCE) &&
15261                     p->real_cred->user != INIT_USER)
15262 -                       goto bad_fork_free;
15263 +                       goto bad_fork_cleanup_vm;
15264         }
15265  
15266         retval = copy_creds(p, clone_flags);
15267 @@ -1300,6 +1330,18 @@ static struct task_struct *copy_process(
15268  
15269         total_forks++;
15270         spin_unlock(&current->sighand->siglock);
15271 +
15272 +       /* p is copy of current */
15273 +       vxi = p->vx_info;
15274 +       if (vxi) {
15275 +               claim_vx_info(vxi, p);
15276 +               atomic_inc(&vxi->cvirt.nr_threads);
15277 +               atomic_inc(&vxi->cvirt.total_forks);
15278 +               vx_nproc_inc(p);
15279 +       }
15280 +       nxi = p->nx_info;
15281 +       if (nxi)
15282 +               claim_nx_info(nxi, p);
15283         write_unlock_irq(&tasklist_lock);
15284         proc_fork_connector(p);
15285         cgroup_post_fork(p);
15286 @@ -1341,6 +1383,9 @@ bad_fork_cleanup_cgroup:
15287  bad_fork_cleanup_count:
15288         atomic_dec(&p->cred->user->processes);
15289         exit_creds(p);
15290 +bad_fork_cleanup_vm:
15291 +       if (p->mm && !(clone_flags & CLONE_VM))
15292 +               vx_pages_sub(p->vx_info, RLIMIT_AS, p->mm->total_vm);
15293  bad_fork_free:
15294         free_task(p);
15295  fork_out:
15296 diff -NurpP --minimal linux-2.6.32.1/kernel/kthread.c linux-2.6.32.1-vs2.3.0.36.27/kernel/kthread.c
15297 --- linux-2.6.32.1/kernel/kthread.c     2009-12-03 20:02:58.000000000 +0100
15298 +++ linux-2.6.32.1-vs2.3.0.36.27/kernel/kthread.c       2009-12-03 20:04:56.000000000 +0100
15299 @@ -14,6 +14,7 @@
15300  #include <linux/file.h>
15301  #include <linux/module.h>
15302  #include <linux/mutex.h>
15303 +#include <linux/vs_pid.h>
15304  #include <trace/events/sched.h>
15305  
15306  static DEFINE_SPINLOCK(kthread_create_lock);
15307 diff -NurpP --minimal linux-2.6.32.1/kernel/Makefile linux-2.6.32.1-vs2.3.0.36.27/kernel/Makefile
15308 --- linux-2.6.32.1/kernel/Makefile      2009-12-03 20:02:57.000000000 +0100
15309 +++ linux-2.6.32.1-vs2.3.0.36.27/kernel/Makefile        2009-12-03 20:04:56.000000000 +0100
15310 @@ -23,6 +23,7 @@ CFLAGS_REMOVE_cgroup-debug.o = -pg
15311  CFLAGS_REMOVE_sched_clock.o = -pg
15312  endif
15313  
15314 +obj-y += vserver/
15315  obj-$(CONFIG_FREEZER) += freezer.o
15316  obj-$(CONFIG_PROFILING) += profile.o
15317  obj-$(CONFIG_SYSCTL_SYSCALL_CHECK) += sysctl_check.o
15318 diff -NurpP --minimal linux-2.6.32.1/kernel/nsproxy.c linux-2.6.32.1-vs2.3.0.36.27/kernel/nsproxy.c
15319 --- linux-2.6.32.1/kernel/nsproxy.c     2009-09-10 15:26:28.000000000 +0200
15320 +++ linux-2.6.32.1-vs2.3.0.36.27/kernel/nsproxy.c       2009-12-03 20:04:56.000000000 +0100
15321 @@ -19,6 +19,8 @@
15322  #include <linux/mnt_namespace.h>
15323  #include <linux/utsname.h>
15324  #include <linux/pid_namespace.h>
15325 +#include <linux/vserver/global.h>
15326 +#include <linux/vserver/debug.h>
15327  #include <net/net_namespace.h>
15328  #include <linux/ipc_namespace.h>
15329  
15330 @@ -31,8 +33,11 @@ static inline struct nsproxy *create_nsp
15331         struct nsproxy *nsproxy;
15332  
15333         nsproxy = kmem_cache_alloc(nsproxy_cachep, GFP_KERNEL);
15334 -       if (nsproxy)
15335 +       if (nsproxy) {
15336                 atomic_set(&nsproxy->count, 1);
15337 +               atomic_inc(&vs_global_nsproxy);
15338 +       }
15339 +       vxdprintk(VXD_CBIT(space, 2), "create_nsproxy = %p[1]", nsproxy);
15340         return nsproxy;
15341  }
15342  
15343 @@ -41,41 +46,52 @@ static inline struct nsproxy *create_nsp
15344   * Return the newly created nsproxy.  Do not attach this to the task,
15345   * leave it to the caller to do proper locking and attach it to task.
15346   */
15347 -static struct nsproxy *create_new_namespaces(unsigned long flags,
15348 -                       struct task_struct *tsk, struct fs_struct *new_fs)
15349 +static struct nsproxy *unshare_namespaces(unsigned long flags,
15350 +                       struct nsproxy *orig, struct fs_struct *new_fs)
15351  {
15352         struct nsproxy *new_nsp;
15353         int err;
15354  
15355 +       vxdprintk(VXD_CBIT(space, 4),
15356 +               "unshare_namespaces(0x%08lx,%p,%p)",
15357 +               flags, orig, new_fs);
15358 +
15359         new_nsp = create_nsproxy();
15360         if (!new_nsp)
15361                 return ERR_PTR(-ENOMEM);
15362  
15363 -       new_nsp->mnt_ns = copy_mnt_ns(flags, tsk->nsproxy->mnt_ns, new_fs);
15364 +       new_nsp->mnt_ns = copy_mnt_ns(flags, orig->mnt_ns, new_fs);
15365         if (IS_ERR(new_nsp->mnt_ns)) {
15366                 err = PTR_ERR(new_nsp->mnt_ns);
15367                 goto out_ns;
15368         }
15369  
15370 -       new_nsp->uts_ns = copy_utsname(flags, tsk->nsproxy->uts_ns);
15371 +       new_nsp->uts_ns = copy_utsname(flags, orig->uts_ns);
15372         if (IS_ERR(new_nsp->uts_ns)) {
15373                 err = PTR_ERR(new_nsp->uts_ns);
15374                 goto out_uts;
15375         }
15376  
15377 -       new_nsp->ipc_ns = copy_ipcs(flags, tsk->nsproxy->ipc_ns);
15378 +       new_nsp->ipc_ns = copy_ipcs(flags, orig->ipc_ns);
15379         if (IS_ERR(new_nsp->ipc_ns)) {
15380                 err = PTR_ERR(new_nsp->ipc_ns);
15381                 goto out_ipc;
15382         }
15383  
15384 -       new_nsp->pid_ns = copy_pid_ns(flags, task_active_pid_ns(tsk));
15385 +       new_nsp->pid_ns = copy_pid_ns(flags, orig->pid_ns);
15386         if (IS_ERR(new_nsp->pid_ns)) {
15387                 err = PTR_ERR(new_nsp->pid_ns);
15388                 goto out_pid;
15389         }
15390  
15391 -       new_nsp->net_ns = copy_net_ns(flags, tsk->nsproxy->net_ns);
15392 +       /* disabled now?
15393 +       new_nsp->user_ns = copy_user_ns(flags, orig->user_ns);
15394 +       if (IS_ERR(new_nsp->user_ns)) {
15395 +               err = PTR_ERR(new_nsp->user_ns);
15396 +               goto out_user;
15397 +       } */
15398 +
15399 +       new_nsp->net_ns = copy_net_ns(flags, orig->net_ns);
15400         if (IS_ERR(new_nsp->net_ns)) {
15401                 err = PTR_ERR(new_nsp->net_ns);
15402                 goto out_net;
15403 @@ -100,6 +116,38 @@ out_ns:
15404         return ERR_PTR(err);
15405  }
15406  
15407 +static struct nsproxy *create_new_namespaces(int flags, struct task_struct *tsk,
15408 +                       struct fs_struct *new_fs)
15409 +{
15410 +       return unshare_namespaces(flags, tsk->nsproxy, new_fs);
15411 +}
15412 +
15413 +/*
15414 + * copies the nsproxy, setting refcount to 1, and grabbing a
15415 + * reference to all contained namespaces.
15416 + */
15417 +struct nsproxy *copy_nsproxy(struct nsproxy *orig)
15418 +{
15419 +       struct nsproxy *ns = create_nsproxy();
15420 +
15421 +       if (ns) {
15422 +               memcpy(ns, orig, sizeof(struct nsproxy));
15423 +               atomic_set(&ns->count, 1);
15424 +
15425 +               if (ns->mnt_ns)
15426 +                       get_mnt_ns(ns->mnt_ns);
15427 +               if (ns->uts_ns)
15428 +                       get_uts_ns(ns->uts_ns);
15429 +               if (ns->ipc_ns)
15430 +                       get_ipc_ns(ns->ipc_ns);
15431 +               if (ns->pid_ns)
15432 +                       get_pid_ns(ns->pid_ns);
15433 +               if (ns->net_ns)
15434 +                       get_net(ns->net_ns);
15435 +       }
15436 +       return ns;
15437 +}
15438 +
15439  /*
15440   * called from clone.  This now handles copy for nsproxy and all
15441   * namespaces therein.
15442 @@ -107,9 +155,12 @@ out_ns:
15443  int copy_namespaces(unsigned long flags, struct task_struct *tsk)
15444  {
15445         struct nsproxy *old_ns = tsk->nsproxy;
15446 -       struct nsproxy *new_ns;
15447 +       struct nsproxy *new_ns = NULL;
15448         int err = 0;
15449  
15450 +       vxdprintk(VXD_CBIT(space, 7), "copy_namespaces(0x%08lx,%p[%p])",
15451 +               flags, tsk, old_ns);
15452 +
15453         if (!old_ns)
15454                 return 0;
15455  
15456 @@ -119,7 +170,7 @@ int copy_namespaces(unsigned long flags,
15457                                 CLONE_NEWPID | CLONE_NEWNET)))
15458                 return 0;
15459  
15460 -       if (!capable(CAP_SYS_ADMIN)) {
15461 +       if (!vx_can_unshare(CAP_SYS_ADMIN, flags)) {
15462                 err = -EPERM;
15463                 goto out;
15464         }
15465 @@ -146,6 +197,9 @@ int copy_namespaces(unsigned long flags,
15466  
15467  out:
15468         put_nsproxy(old_ns);
15469 +       vxdprintk(VXD_CBIT(space, 3),
15470 +               "copy_namespaces(0x%08lx,%p[%p]) = %d [%p]",
15471 +               flags, tsk, old_ns, err, new_ns);
15472         return err;
15473  }
15474  
15475 @@ -159,7 +213,9 @@ void free_nsproxy(struct nsproxy *ns)
15476                 put_ipc_ns(ns->ipc_ns);
15477         if (ns->pid_ns)
15478                 put_pid_ns(ns->pid_ns);
15479 -       put_net(ns->net_ns);
15480 +       if (ns->net_ns)
15481 +               put_net(ns->net_ns);
15482 +       atomic_dec(&vs_global_nsproxy);
15483         kmem_cache_free(nsproxy_cachep, ns);
15484  }
15485  
15486 @@ -172,11 +228,15 @@ int unshare_nsproxy_namespaces(unsigned 
15487  {
15488         int err = 0;
15489  
15490 +       vxdprintk(VXD_CBIT(space, 4),
15491 +               "unshare_nsproxy_namespaces(0x%08lx,[%p])",
15492 +               unshare_flags, current->nsproxy);
15493 +
15494         if (!(unshare_flags & (CLONE_NEWNS | CLONE_NEWUTS | CLONE_NEWIPC |
15495                                CLONE_NEWNET)))
15496                 return 0;
15497  
15498 -       if (!capable(CAP_SYS_ADMIN))
15499 +       if (!vx_can_unshare(CAP_SYS_ADMIN, unshare_flags))
15500                 return -EPERM;
15501  
15502         *new_nsp = create_new_namespaces(unshare_flags, current,
15503 diff -NurpP --minimal linux-2.6.32.1/kernel/pid.c linux-2.6.32.1-vs2.3.0.36.27/kernel/pid.c
15504 --- linux-2.6.32.1/kernel/pid.c 2009-12-03 20:02:58.000000000 +0100
15505 +++ linux-2.6.32.1-vs2.3.0.36.27/kernel/pid.c   2009-12-03 20:04:56.000000000 +0100
15506 @@ -36,6 +36,7 @@
15507  #include <linux/pid_namespace.h>
15508  #include <linux/init_task.h>
15509  #include <linux/syscalls.h>
15510 +#include <linux/vs_pid.h>
15511  
15512  #define pid_hashfn(nr, ns)     \
15513         hash_long((unsigned long)nr + (unsigned long)ns, pidhash_shift)
15514 @@ -305,7 +306,7 @@ EXPORT_SYMBOL_GPL(find_pid_ns);
15515  
15516  struct pid *find_vpid(int nr)
15517  {
15518 -       return find_pid_ns(nr, current->nsproxy->pid_ns);
15519 +       return find_pid_ns(vx_rmap_pid(nr), current->nsproxy->pid_ns);
15520  }
15521  EXPORT_SYMBOL_GPL(find_vpid);
15522  
15523 @@ -365,6 +366,9 @@ void transfer_pid(struct task_struct *ol
15524  struct task_struct *pid_task(struct pid *pid, enum pid_type type)
15525  {
15526         struct task_struct *result = NULL;
15527 +
15528 +       if (type == PIDTYPE_REALPID)
15529 +               type = PIDTYPE_PID;
15530         if (pid) {
15531                 struct hlist_node *first;
15532                 first = rcu_dereference(pid->tasks[type].first);
15533 @@ -380,7 +384,7 @@ EXPORT_SYMBOL(pid_task);
15534   */
15535  struct task_struct *find_task_by_pid_ns(pid_t nr, struct pid_namespace *ns)
15536  {
15537 -       return pid_task(find_pid_ns(nr, ns), PIDTYPE_PID);
15538 +       return pid_task(find_pid_ns(vx_rmap_pid(nr), ns), PIDTYPE_PID);
15539  }
15540  
15541  struct task_struct *find_task_by_vpid(pid_t vnr)
15542 @@ -422,7 +426,7 @@ struct pid *find_get_pid(pid_t nr)
15543  }
15544  EXPORT_SYMBOL_GPL(find_get_pid);
15545  
15546 -pid_t pid_nr_ns(struct pid *pid, struct pid_namespace *ns)
15547 +pid_t pid_unmapped_nr_ns(struct pid *pid, struct pid_namespace *ns)
15548  {
15549         struct upid *upid;
15550         pid_t nr = 0;
15551 @@ -435,6 +439,11 @@ pid_t pid_nr_ns(struct pid *pid, struct 
15552         return nr;
15553  }
15554  
15555 +pid_t pid_nr_ns(struct pid *pid, struct pid_namespace *ns)
15556 +{
15557 +       return vx_map_pid(pid_unmapped_nr_ns(pid, ns));
15558 +}
15559 +
15560  pid_t pid_vnr(struct pid *pid)
15561  {
15562         return pid_nr_ns(pid, current->nsproxy->pid_ns);
15563 diff -NurpP --minimal linux-2.6.32.1/kernel/pid_namespace.c linux-2.6.32.1-vs2.3.0.36.27/kernel/pid_namespace.c
15564 --- linux-2.6.32.1/kernel/pid_namespace.c       2009-12-03 20:02:58.000000000 +0100
15565 +++ linux-2.6.32.1-vs2.3.0.36.27/kernel/pid_namespace.c 2009-12-03 20:04:56.000000000 +0100
15566 @@ -13,6 +13,7 @@
15567  #include <linux/syscalls.h>
15568  #include <linux/err.h>
15569  #include <linux/acct.h>
15570 +#include <linux/vserver/global.h>
15571  
15572  #define BITS_PER_PAGE          (PAGE_SIZE*8)
15573  
15574 @@ -86,6 +87,7 @@ static struct pid_namespace *create_pid_
15575                 goto out_free_map;
15576  
15577         kref_init(&ns->kref);
15578 +       atomic_inc(&vs_global_pid_ns);
15579         ns->level = level;
15580         ns->parent = get_pid_ns(parent_pid_ns);
15581  
15582 @@ -111,6 +113,7 @@ static void destroy_pid_namespace(struct
15583  
15584         for (i = 0; i < PIDMAP_ENTRIES; i++)
15585                 kfree(ns->pidmap[i].page);
15586 +       atomic_dec(&vs_global_pid_ns);
15587         kmem_cache_free(pid_ns_cachep, ns);
15588  }
15589  
15590 diff -NurpP --minimal linux-2.6.32.1/kernel/posix-timers.c linux-2.6.32.1-vs2.3.0.36.27/kernel/posix-timers.c
15591 --- linux-2.6.32.1/kernel/posix-timers.c        2009-12-03 20:02:58.000000000 +0100
15592 +++ linux-2.6.32.1-vs2.3.0.36.27/kernel/posix-timers.c  2009-12-03 20:04:56.000000000 +0100
15593 @@ -46,6 +46,7 @@
15594  #include <linux/wait.h>
15595  #include <linux/workqueue.h>
15596  #include <linux/module.h>
15597 +#include <linux/vs_context.h>
15598  
15599  /*
15600   * Management arrays for POSIX timers.  Timers are kept in slab memory
15601 @@ -363,6 +364,7 @@ int posix_timer_event(struct k_itimer *t
15602  {
15603         struct task_struct *task;
15604         int shared, ret = -1;
15605 +
15606         /*
15607          * FIXME: if ->sigq is queued we can race with
15608          * dequeue_signal()->do_schedule_next_timer().
15609 @@ -379,10 +381,18 @@ int posix_timer_event(struct k_itimer *t
15610         rcu_read_lock();
15611         task = pid_task(timr->it_pid, PIDTYPE_PID);
15612         if (task) {
15613 +               struct vx_info_save vxis;
15614 +               struct vx_info *vxi;
15615 +
15616 +               vxi = get_vx_info(task->vx_info);
15617 +               enter_vx_info(vxi, &vxis);
15618                 shared = !(timr->it_sigev_notify & SIGEV_THREAD_ID);
15619                 ret = send_sigqueue(timr->sigq, task, shared);
15620 +               leave_vx_info(&vxis);
15621 +               put_vx_info(vxi);
15622         }
15623         rcu_read_unlock();
15624 +
15625         /* If we failed to send the signal the timer stops. */
15626         return ret > 0;
15627  }
15628 diff -NurpP --minimal linux-2.6.32.1/kernel/printk.c linux-2.6.32.1-vs2.3.0.36.27/kernel/printk.c
15629 --- linux-2.6.32.1/kernel/printk.c      2009-12-03 20:02:58.000000000 +0100
15630 +++ linux-2.6.32.1-vs2.3.0.36.27/kernel/printk.c        2009-12-03 20:04:56.000000000 +0100
15631 @@ -33,6 +33,7 @@
15632  #include <linux/bootmem.h>
15633  #include <linux/syscalls.h>
15634  #include <linux/kexec.h>
15635 +#include <linux/vs_cvirt.h>
15636  
15637  #include <asm/uaccess.h>
15638  
15639 @@ -276,18 +277,13 @@ int do_syslog(int type, char __user *buf
15640         unsigned i, j, limit, count;
15641         int do_clear = 0;
15642         char c;
15643 -       int error = 0;
15644 +       int error;
15645  
15646         error = security_syslog(type);
15647         if (error)
15648                 return error;
15649  
15650 -       switch (type) {
15651 -       case 0:         /* Close log */
15652 -               break;
15653 -       case 1:         /* Open log */
15654 -               break;
15655 -       case 2:         /* Read from log */
15656 +       if ((type >= 2) && (type <= 4)) {
15657                 error = -EINVAL;
15658                 if (!buf || len < 0)
15659                         goto out;
15660 @@ -298,6 +294,16 @@ int do_syslog(int type, char __user *buf
15661                         error = -EFAULT;
15662                         goto out;
15663                 }
15664 +       }
15665 +       if (!vx_check(0, VS_ADMIN|VS_WATCH))
15666 +               return vx_do_syslog(type, buf, len);
15667 +
15668 +       switch (type) {
15669 +       case 0:         /* Close log */
15670 +               break;
15671 +       case 1:         /* Open log */
15672 +               break;
15673 +       case 2:         /* Read from log */
15674                 error = wait_event_interruptible(log_wait,
15675                                                         (log_start - log_end));
15676                 if (error)
15677 @@ -322,16 +328,6 @@ int do_syslog(int type, char __user *buf
15678                 do_clear = 1;
15679                 /* FALL THRU */
15680         case 3:         /* Read last kernel messages */
15681 -               error = -EINVAL;
15682 -               if (!buf || len < 0)
15683 -                       goto out;
15684 -               error = 0;
15685 -               if (!len)
15686 -                       goto out;
15687 -               if (!access_ok(VERIFY_WRITE, buf, len)) {
15688 -                       error = -EFAULT;
15689 -                       goto out;
15690 -               }
15691                 count = len;
15692                 if (count > log_buf_len)
15693                         count = log_buf_len;
15694 diff -NurpP --minimal linux-2.6.32.1/kernel/ptrace.c linux-2.6.32.1-vs2.3.0.36.27/kernel/ptrace.c
15695 --- linux-2.6.32.1/kernel/ptrace.c      2009-12-03 20:02:58.000000000 +0100
15696 +++ linux-2.6.32.1-vs2.3.0.36.27/kernel/ptrace.c        2009-12-03 20:04:56.000000000 +0100
15697 @@ -22,6 +22,7 @@
15698  #include <linux/pid_namespace.h>
15699  #include <linux/syscalls.h>
15700  #include <linux/uaccess.h>
15701 +#include <linux/vs_context.h>
15702  
15703  
15704  /*
15705 @@ -151,6 +152,11 @@ int __ptrace_may_access(struct task_stru
15706                 dumpable = get_dumpable(task->mm);
15707         if (!dumpable && !capable(CAP_SYS_PTRACE))
15708                 return -EPERM;
15709 +       if (!vx_check(task->xid, VS_ADMIN_P|VS_IDENT))
15710 +               return -EPERM;
15711 +       if (!vx_check(task->xid, VS_IDENT) &&
15712 +               !task_vx_flags(task, VXF_STATE_ADMIN, 0))
15713 +               return -EACCES;
15714  
15715         return security_ptrace_access_check(task, mode);
15716  }
15717 @@ -621,6 +627,10 @@ SYSCALL_DEFINE4(ptrace, long, request, l
15718                 goto out;
15719         }
15720  
15721 +       ret = -EPERM;
15722 +       if (!vx_check(vx_task_xid(child), VS_WATCH_P | VS_IDENT))
15723 +               goto out_put_task_struct;
15724 +
15725         if (request == PTRACE_ATTACH) {
15726                 ret = ptrace_attach(child);
15727                 /*
15728 diff -NurpP --minimal linux-2.6.32.1/kernel/sched.c linux-2.6.32.1-vs2.3.0.36.27/kernel/sched.c
15729 --- linux-2.6.32.1/kernel/sched.c       2009-12-03 20:02:58.000000000 +0100
15730 +++ linux-2.6.32.1-vs2.3.0.36.27/kernel/sched.c 2009-12-03 20:04:56.000000000 +0100
15731 @@ -71,6 +71,8 @@
15732  #include <linux/debugfs.h>
15733  #include <linux/ctype.h>
15734  #include <linux/ftrace.h>
15735 +#include <linux/vs_sched.h>
15736 +#include <linux/vs_cvirt.h>
15737  
15738  #include <asm/tlb.h>
15739  #include <asm/irq_regs.h>
15740 @@ -237,6 +239,15 @@ static DEFINE_MUTEX(sched_domains_mutex)
15741  
15742  #include <linux/cgroup.h>
15743  
15744 +#if defined(CONFIG_FAIR_GROUP_SCHED) && defined(CONFIG_CFS_HARD_LIMITS)
15745 +struct cfs_bandwidth {
15746 +       spinlock_t              cfs_runtime_lock;
15747 +       ktime_t                 cfs_period;
15748 +       u64                     cfs_runtime;
15749 +       struct hrtimer          cfs_period_timer;
15750 +};
15751 +#endif
15752 +
15753  struct cfs_rq;
15754  
15755  static LIST_HEAD(task_groups);
15756 @@ -257,6 +268,9 @@ struct task_group {
15757         /* runqueue "owned" by this group on each cpu */
15758         struct cfs_rq **cfs_rq;
15759         unsigned long shares;
15760 +#ifdef CONFIG_CFS_HARD_LIMITS
15761 +       struct cfs_bandwidth cfs_bandwidth;
15762 +#endif
15763  #endif
15764  
15765  #ifdef CONFIG_RT_GROUP_SCHED
15766 @@ -446,6 +460,19 @@ struct cfs_rq {
15767         unsigned long rq_weight;
15768  #endif
15769  #endif
15770 +#ifdef CONFIG_CFS_HARD_LIMITS
15771 +       /* set when the group is throttled  on this cpu */
15772 +       int cfs_throttled;
15773 +
15774 +       /* runtime currently consumed by the group on this rq */
15775 +       u64 cfs_time;
15776 +
15777 +       /* runtime available to the group on this rq */
15778 +       u64 cfs_runtime;
15779 +
15780 +       /* Protects the cfs runtime related fields of this cfs_rq */
15781 +       spinlock_t cfs_runtime_lock;
15782 +#endif
15783  };
15784  
15785  /* Real-Time classes' related field in a runqueue: */
15786 @@ -1607,6 +1634,7 @@ static void update_group_shares_cpu(stru
15787         }
15788  }
15789  
15790 +static inline int cfs_rq_throttled(struct cfs_rq *cfs_rq);
15791  /*
15792   * Re-compute the task group their per cpu shares over the given domain.
15793   * This needs to be done in a bottom-up fashion because the rq weight of a
15794 @@ -1634,8 +1662,10 @@ static int tg_shares_up(struct task_grou
15795                  * If there are currently no tasks on the cpu pretend there
15796                  * is one of average load so that when a new task gets to
15797                  * run here it will not get delayed by group starvation.
15798 +                * Also if the group is throttled on this cpu, pretend that
15799 +                * it has no tasks.
15800                  */
15801 -               if (!weight)
15802 +               if (!weight || cfs_rq_throttled(tg->cfs_rq[i]))
15803                         weight = NICE_0_LOAD;
15804  
15805                 rq_weight += weight;
15806 @@ -1811,6 +1841,175 @@ static void cfs_rq_set_shares(struct cfs
15807  
15808  static void calc_load_account_active(struct rq *this_rq);
15809  
15810 +
15811 +#if defined(CONFIG_RT_GROUP_SCHED) || defined(CONFIG_FAIR_GROUP_SCHED)
15812 +
15813 +#ifdef CONFIG_SMP
15814 +static inline const struct cpumask *sched_bw_period_mask(void)
15815 +{
15816 +       return cpu_rq(smp_processor_id())->rd->span;
15817 +}
15818 +#else /* !CONFIG_SMP */
15819 +static inline const struct cpumask *sched_bw_period_mask(void)
15820 +{
15821 +       return cpu_online_mask;
15822 +}
15823 +#endif /* CONFIG_SMP */
15824 +
15825 +#else
15826 +static inline const struct cpumask *sched_bw_period_mask(void)
15827 +{
15828 +       return cpu_online_mask;
15829 +}
15830 +
15831 +#endif
15832 +
15833 +#ifdef CONFIG_FAIR_GROUP_SCHED
15834 +#ifdef CONFIG_CFS_HARD_LIMITS
15835 +
15836 +/*
15837 + * Runtime allowed for a cfs group before it is hard limited.
15838 + * default: Infinite which means no hard limiting.
15839 + */
15840 +u64 sched_cfs_runtime = RUNTIME_INF;
15841 +
15842 +/*
15843 + * period over which we hard limit the cfs group's bandwidth.
15844 + * default: 0.5s
15845 + */
15846 +u64 sched_cfs_period = 500000;
15847 +
15848 +static inline u64 global_cfs_period(void)
15849 +{
15850 +       return sched_cfs_period * NSEC_PER_USEC;
15851 +}
15852 +
15853 +static inline u64 global_cfs_runtime(void)
15854 +{
15855 +       return RUNTIME_INF;
15856 +}
15857 +
15858 +void do_sched_cfs_period_timer(struct cfs_bandwidth *cfs_b);
15859 +
15860 +static inline void cfs_rq_runtime_lock(struct cfs_rq *cfs_rq)
15861 +{
15862 +       spin_lock(&cfs_rq->cfs_runtime_lock);
15863 +}
15864 +
15865 +static inline void cfs_rq_runtime_unlock(struct cfs_rq *cfs_rq)
15866 +{
15867 +       spin_unlock(&cfs_rq->cfs_runtime_lock);
15868 +}
15869 +
15870 +/*
15871 + * Refresh the runtimes of the throttled groups.
15872 + * But nothing much to do now, will populate this in later patches.
15873 + */
15874 +static enum hrtimer_restart sched_cfs_period_timer(struct hrtimer *timer)
15875 +{
15876 +       struct cfs_bandwidth *cfs_b =
15877 +               container_of(timer, struct cfs_bandwidth, cfs_period_timer);
15878 +
15879 +       do_sched_cfs_period_timer(cfs_b);
15880 +       hrtimer_add_expires_ns(timer, ktime_to_ns(cfs_b->cfs_period));
15881 +       return HRTIMER_RESTART;
15882 +}
15883 +
15884 +/*
15885 + * TODO: Check if this kind of timer setup is sufficient for cfs or
15886 + * should we do what rt is doing.
15887 + */
15888 +static void start_cfs_bandwidth(struct task_group *tg)
15889 +{
15890 +       struct cfs_bandwidth *cfs_b = &tg->cfs_bandwidth;
15891 +
15892 +       /*
15893 +        * Timer isn't setup for groups with infinite runtime
15894 +        */
15895 +       if (cfs_b->cfs_runtime == RUNTIME_INF)
15896 +               return;
15897 +
15898 +       if (hrtimer_active(&cfs_b->cfs_period_timer))
15899 +               return;
15900 +
15901 +       hrtimer_start_range_ns(&cfs_b->cfs_period_timer, cfs_b->cfs_period,
15902 +                       0, HRTIMER_MODE_REL);
15903 +}
15904 +
15905 +static void init_cfs_bandwidth(struct task_group *tg)
15906 +{
15907 +       struct cfs_bandwidth *cfs_b = &tg->cfs_bandwidth;
15908 +
15909 +       cfs_b->cfs_period = ns_to_ktime(global_cfs_period());
15910 +       cfs_b->cfs_runtime = global_cfs_runtime();
15911 +
15912 +       spin_lock_init(&cfs_b->cfs_runtime_lock);
15913 +
15914 +       hrtimer_init(&cfs_b->cfs_period_timer,
15915 +                       CLOCK_MONOTONIC, HRTIMER_MODE_REL);
15916 +       cfs_b->cfs_period_timer.function = &sched_cfs_period_timer;
15917 +}
15918 +
15919 +static inline void destroy_cfs_bandwidth(struct task_group *tg)
15920 +{
15921 +       hrtimer_cancel(&tg->cfs_bandwidth.cfs_period_timer);
15922 +}
15923 +
15924 +static void init_cfs_hard_limits(struct cfs_rq *cfs_rq, struct task_group *tg)
15925 +{
15926 +       cfs_rq->cfs_time = 0;
15927 +       cfs_rq->cfs_throttled = 0;
15928 +       cfs_rq->cfs_runtime = tg->cfs_bandwidth.cfs_runtime;
15929 +       spin_lock_init(&cfs_rq->cfs_runtime_lock);
15930 +}
15931 +
15932 +#else /* !CONFIG_CFS_HARD_LIMITS */
15933 +
15934 +static void init_cfs_bandwidth(struct task_group *tg)
15935 +{
15936 +       return;
15937 +}
15938 +
15939 +static inline void destroy_cfs_bandwidth(struct task_group *tg)
15940 +{
15941 +       return;
15942 +}
15943 +
15944 +static void init_cfs_hard_limits(struct cfs_rq *cfs_rq, struct task_group *tg)
15945 +{
15946 +       return;
15947 +}
15948 +
15949 +static inline void cfs_rq_runtime_lock(struct cfs_rq *cfs_rq)
15950 +{
15951 +       return;
15952 +}
15953 +
15954 +static inline void cfs_rq_runtime_unlock(struct cfs_rq *cfs_rq)
15955 +{
15956 +       return;
15957 +}
15958 +
15959 +#endif /* CONFIG_CFS_HARD_LIMITS */
15960 +#else /* !CONFIG_FAIR_GROUP_SCHED */
15961 +
15962 +static inline void cfs_rq_runtime_lock(struct cfs_rq *cfs_rq)
15963 +{
15964 +       return;
15965 +}
15966 +
15967 +static inline void cfs_rq_runtime_unlock(struct cfs_rq *cfs_rq)
15968 +{
15969 +       return;
15970 +}
15971 +
15972 +static inline int cfs_rq_throttled(struct cfs_rq *cfs_rq)
15973 +{
15974 +       return 0;
15975 +}
15976 +
15977 +#endif /* CONFIG_FAIR_GROUP_SCHED */
15978 +
15979  #include "sched_stats.h"
15980  #include "sched_idletask.c"
15981  #include "sched_fair.c"
15982 @@ -2965,9 +3164,17 @@ EXPORT_SYMBOL(avenrun);
15983   */
15984  void get_avenrun(unsigned long *loads, unsigned long offset, int shift)
15985  {
15986 -       loads[0] = (avenrun[0] + offset) << shift;
15987 -       loads[1] = (avenrun[1] + offset) << shift;
15988 -       loads[2] = (avenrun[2] + offset) << shift;
15989 +       if (vx_flags(VXF_VIRT_LOAD, 0)) {
15990 +               struct vx_info *vxi = current_vx_info();
15991 +
15992 +               loads[0] = (vxi->cvirt.load[0] + offset) << shift;
15993 +               loads[1] = (vxi->cvirt.load[1] + offset) << shift;
15994 +               loads[2] = (vxi->cvirt.load[2] + offset) << shift;
15995 +       } else {
15996 +               loads[0] = (avenrun[0] + offset) << shift;
15997 +               loads[1] = (avenrun[1] + offset) << shift;
15998 +               loads[2] = (avenrun[2] + offset) << shift;
15999 +       }
16000  }
16001  
16002  static unsigned long
16003 @@ -5006,16 +5213,19 @@ void account_user_time(struct task_struc
16004                        cputime_t cputime_scaled)
16005  {
16006         struct cpu_usage_stat *cpustat = &kstat_this_cpu.cpustat;
16007 +       struct vx_info *vxi = p->vx_info;  /* p is _always_ current */
16008         cputime64_t tmp;
16009 +       int nice = (TASK_NICE(p) > 0);
16010  
16011         /* Add user time to process. */
16012         p->utime = cputime_add(p->utime, cputime);
16013         p->utimescaled = cputime_add(p->utimescaled, cputime_scaled);
16014 +       vx_account_user(vxi, cputime, nice);
16015         account_group_user_time(p, cputime);
16016  
16017         /* Add user time to cpustat. */
16018         tmp = cputime_to_cputime64(cputime);
16019 -       if (TASK_NICE(p) > 0)
16020 +       if (nice)
16021                 cpustat->nice = cputime64_add(cpustat->nice, tmp);
16022         else
16023                 cpustat->user = cputime64_add(cpustat->user, tmp);
16024 @@ -5061,6 +5271,7 @@ void account_system_time(struct task_str
16025                          cputime_t cputime, cputime_t cputime_scaled)
16026  {
16027         struct cpu_usage_stat *cpustat = &kstat_this_cpu.cpustat;
16028 +       struct vx_info *vxi = p->vx_info;  /* p is _always_ current */
16029         cputime64_t tmp;
16030  
16031         if ((p->flags & PF_VCPU) && (irq_count() - hardirq_offset == 0)) {
16032 @@ -5071,6 +5282,7 @@ void account_system_time(struct task_str
16033         /* Add system time to process. */
16034         p->stime = cputime_add(p->stime, cputime);
16035         p->stimescaled = cputime_add(p->stimescaled, cputime_scaled);
16036 +       vx_account_system(vxi, cputime, 0 /* do we have idle time? */);
16037         account_group_system_time(p, cputime);
16038  
16039         /* Add system time to cpustat. */
16040 @@ -6106,7 +6318,7 @@ SYSCALL_DEFINE1(nice, int, increment)
16041                 nice = 19;
16042  
16043         if (increment < 0 && !can_nice(current, nice))
16044 -               return -EPERM;
16045 +               return vx_flags(VXF_IGNEG_NICE, 0) ? 0 : -EPERM;
16046  
16047         retval = security_task_setnice(current, nice);
16048         if (retval)
16049 @@ -9164,6 +9376,32 @@ static int update_sched_domains(struct n
16050  }
16051  #endif
16052  
16053 +#ifdef CONFIG_SMP
16054 +static void disable_runtime(struct rq *rq)
16055 +{
16056 +       unsigned long flags;
16057 +
16058 +       spin_lock_irqsave(&rq->lock, flags);
16059 +#if defined(CONFIG_FAIR_GROUP_SCHED) && defined(CONFIG_CFS_HARD_LIMITS)
16060 +       disable_runtime_cfs(rq);
16061 +#endif
16062 +       disable_runtime_rt(rq);
16063 +       spin_unlock_irqrestore(&rq->lock, flags);
16064 +}
16065 +
16066 +static void enable_runtime(struct rq *rq)
16067 +{
16068 +       unsigned long flags;
16069 +
16070 +       spin_lock_irqsave(&rq->lock, flags);
16071 +#if defined(CONFIG_FAIR_GROUP_SCHED) && defined(CONFIG_CFS_HARD_LIMITS)
16072 +       enable_runtime_cfs(rq);
16073 +#endif
16074 +       enable_runtime_rt(rq);
16075 +       spin_unlock_irqrestore(&rq->lock, flags);
16076 +}
16077 +#endif
16078 +
16079  static int update_runtime(struct notifier_block *nfb,
16080                                 unsigned long action, void *hcpu)
16081  {
16082 @@ -9296,6 +9534,7 @@ static void init_tg_cfs_entry(struct tas
16083         struct rq *rq = cpu_rq(cpu);
16084         tg->cfs_rq[cpu] = cfs_rq;
16085         init_cfs_rq(cfs_rq, rq);
16086 +       init_cfs_hard_limits(cfs_rq, tg);
16087         cfs_rq->tg = tg;
16088         if (add)
16089                 list_add(&cfs_rq->leaf_cfs_rq_list, &rq->leaf_cfs_rq_list);
16090 @@ -9425,6 +9664,10 @@ void __init sched_init(void)
16091  #endif /* CONFIG_USER_SCHED */
16092  #endif /* CONFIG_RT_GROUP_SCHED */
16093  
16094 +#ifdef CONFIG_FAIR_GROUP_SCHED
16095 +       init_cfs_bandwidth(&init_task_group);
16096 +#endif
16097 +
16098  #ifdef CONFIG_GROUP_SCHED
16099         list_add(&init_task_group.list, &task_groups);
16100         INIT_LIST_HEAD(&init_task_group.children);
16101 @@ -9451,6 +9694,7 @@ void __init sched_init(void)
16102                 init_cfs_rq(&rq->cfs, rq);
16103                 init_rt_rq(&rq->rt, rq);
16104  #ifdef CONFIG_FAIR_GROUP_SCHED
16105 +               init_cfs_hard_limits(&rq->cfs, &init_task_group);
16106                 init_task_group.shares = init_task_group_load;
16107                 INIT_LIST_HEAD(&rq->leaf_cfs_rq_list);
16108  #ifdef CONFIG_CGROUP_SCHED
16109 @@ -9726,6 +9970,7 @@ static void free_fair_sched_group(struct
16110  {
16111         int i;
16112  
16113 +       destroy_cfs_bandwidth(tg);
16114         for_each_possible_cpu(i) {
16115                 if (tg->cfs_rq)
16116                         kfree(tg->cfs_rq[i]);
16117 @@ -9752,6 +9997,7 @@ int alloc_fair_sched_group(struct task_g
16118         if (!tg->se)
16119                 goto err;
16120  
16121 +       init_cfs_bandwidth(tg);
16122         tg->shares = NICE_0_LOAD;
16123  
16124         for_each_possible_cpu(i) {
16125 @@ -10475,6 +10721,100 @@ static u64 cpu_shares_read_u64(struct cg
16126  
16127         return (u64) tg->shares;
16128  }
16129 +
16130 +#ifdef CONFIG_CFS_HARD_LIMITS
16131 +
16132 +static int tg_set_cfs_bandwidth(struct task_group *tg,
16133 +               u64 cfs_period, u64 cfs_runtime)
16134 +{
16135 +       int i;
16136 +
16137 +       spin_lock_irq(&tg->cfs_bandwidth.cfs_runtime_lock);
16138 +       tg->cfs_bandwidth.cfs_period = ns_to_ktime(cfs_period);
16139 +       tg->cfs_bandwidth.cfs_runtime = cfs_runtime;
16140 +
16141 +       for_each_possible_cpu(i) {
16142 +               struct cfs_rq *cfs_rq = tg->cfs_rq[i];
16143 +
16144 +               cfs_rq_runtime_lock(cfs_rq);
16145 +               cfs_rq->cfs_runtime = cfs_runtime;
16146 +               cfs_rq_runtime_unlock(cfs_rq);
16147 +       }
16148 +
16149 +       start_cfs_bandwidth(tg);
16150 +       spin_unlock_irq(&tg->cfs_bandwidth.cfs_runtime_lock);
16151 +       return 0;
16152 +}
16153 +
16154 +int tg_set_cfs_runtime(struct task_group *tg, long cfs_runtime_us)
16155 +{
16156 +       u64 cfs_runtime, cfs_period;
16157 +
16158 +       cfs_period = ktime_to_ns(tg->cfs_bandwidth.cfs_period);
16159 +       cfs_runtime = (u64)cfs_runtime_us * NSEC_PER_USEC;
16160 +       if (cfs_runtime_us < 0)
16161 +               cfs_runtime = RUNTIME_INF;
16162 +
16163 +       return tg_set_cfs_bandwidth(tg, cfs_period, cfs_runtime);
16164 +}
16165 +
16166 +long tg_get_cfs_runtime(struct task_group *tg)
16167 +{
16168 +       u64 cfs_runtime_us;
16169 +
16170 +       if (tg->cfs_bandwidth.cfs_runtime == RUNTIME_INF)
16171 +               return -1;
16172 +
16173 +       cfs_runtime_us = tg->cfs_bandwidth.cfs_runtime;
16174 +       do_div(cfs_runtime_us, NSEC_PER_USEC);
16175 +       return cfs_runtime_us;
16176 +}
16177 +
16178 +int tg_set_cfs_period(struct task_group *tg, long cfs_period_us)
16179 +{
16180 +       u64 cfs_runtime, cfs_period;
16181 +
16182 +       cfs_period = (u64)cfs_period_us * NSEC_PER_USEC;
16183 +       cfs_runtime = tg->cfs_bandwidth.cfs_runtime;
16184 +
16185 +       if (cfs_period == 0)
16186 +               return -EINVAL;
16187 +
16188 +       return tg_set_cfs_bandwidth(tg, cfs_period, cfs_runtime);
16189 +}
16190 +
16191 +long tg_get_cfs_period(struct task_group *tg)
16192 +{
16193 +       u64 cfs_period_us;
16194 +
16195 +       cfs_period_us = ktime_to_ns(tg->cfs_bandwidth.cfs_period);
16196 +       do_div(cfs_period_us, NSEC_PER_USEC);
16197 +       return cfs_period_us;
16198 +}
16199 +
16200 +static s64 cpu_cfs_runtime_read_s64(struct cgroup *cgrp, struct cftype *cft)
16201 +{
16202 +       return tg_get_cfs_runtime(cgroup_tg(cgrp));
16203 +}
16204 +
16205 +static int cpu_cfs_runtime_write_s64(struct cgroup *cgrp, struct cftype *cftype,
16206 +                               s64 cfs_runtime_us)
16207 +{
16208 +       return tg_set_cfs_runtime(cgroup_tg(cgrp), cfs_runtime_us);
16209 +}
16210 +
16211 +static u64 cpu_cfs_period_read_u64(struct cgroup *cgrp, struct cftype *cft)
16212 +{
16213 +       return tg_get_cfs_period(cgroup_tg(cgrp));
16214 +}
16215 +
16216 +static int cpu_cfs_period_write_u64(struct cgroup *cgrp, struct cftype *cftype,
16217 +                               u64 cfs_period_us)
16218 +{
16219 +       return tg_set_cfs_period(cgroup_tg(cgrp), cfs_period_us);
16220 +}
16221 +
16222 +#endif /* CONFIG_CFS_HARD_LIMITS */
16223  #endif /* CONFIG_FAIR_GROUP_SCHED */
16224  
16225  #ifdef CONFIG_RT_GROUP_SCHED
16226 @@ -10508,6 +10848,18 @@ static struct cftype cpu_files[] = {
16227                 .read_u64 = cpu_shares_read_u64,
16228                 .write_u64 = cpu_shares_write_u64,
16229         },
16230 +#ifdef CONFIG_CFS_HARD_LIMITS
16231 +       {
16232 +               .name = "cfs_runtime_us",
16233 +               .read_s64 = cpu_cfs_runtime_read_s64,
16234 +               .write_s64 = cpu_cfs_runtime_write_s64,
16235 +       },
16236 +       {
16237 +               .name = "cfs_period_us",
16238 +               .read_u64 = cpu_cfs_period_read_u64,
16239 +               .write_u64 = cpu_cfs_period_write_u64,
16240 +       },
16241 +#endif /* CONFIG_CFS_HARD_LIMITS */
16242  #endif
16243  #ifdef CONFIG_RT_GROUP_SCHED
16244         {
16245 diff -NurpP --minimal linux-2.6.32.1/kernel/sched_debug.c linux-2.6.32.1-vs2.3.0.36.27/kernel/sched_debug.c
16246 --- linux-2.6.32.1/kernel/sched_debug.c 2009-12-03 20:02:58.000000000 +0100
16247 +++ linux-2.6.32.1-vs2.3.0.36.27/kernel/sched_debug.c   2009-12-03 20:04:56.000000000 +0100
16248 @@ -80,6 +80,11 @@ static void print_cfs_group_stats(struct
16249         PN(se->wait_max);
16250         PN(se->wait_sum);
16251         P(se->wait_count);
16252 +#ifdef CONFIG_CFS_HARD_LIMITS
16253 +       PN(se->throttle_max);
16254 +       PN(se->throttle_sum);
16255 +       P(se->throttle_count);
16256 +#endif
16257  #endif
16258         P(se->load.weight);
16259  #undef PN
16260 @@ -214,6 +219,16 @@ void print_cfs_rq(struct seq_file *m, in
16261  #ifdef CONFIG_SMP
16262         SEQ_printf(m, "  .%-30s: %lu\n", "shares", cfs_rq->shares);
16263  #endif
16264 +#ifdef CONFIG_CFS_HARD_LIMITS
16265 +       spin_lock_irqsave(&rq->lock, flags);
16266 +       SEQ_printf(m, "  .%-30s: %d\n", "cfs_throttled",
16267 +                       cfs_rq->cfs_throttled);
16268 +       SEQ_printf(m, "  .%-30s: %Ld.%06ld\n", "cfs_time",
16269 +                       SPLIT_NS(cfs_rq->cfs_time));
16270 +       SEQ_printf(m, "  .%-30s: %Ld.%06ld\n", "cfs_runtime",
16271 +                       SPLIT_NS(cfs_rq->cfs_runtime));
16272 +       spin_unlock_irqrestore(&rq->lock, flags);
16273 +#endif /* CONFIG_CFS_HARD_LIMITS */
16274         print_cfs_group_stats(m, cpu, cfs_rq->tg);
16275  #endif
16276  }
16277 @@ -310,7 +325,7 @@ static int sched_debug_show(struct seq_f
16278         u64 now = ktime_to_ns(ktime_get());
16279         int cpu;
16280  
16281 -       SEQ_printf(m, "Sched Debug Version: v0.09, %s %.*s\n",
16282 +       SEQ_printf(m, "Sched Debug Version: v0.10, %s %.*s\n",
16283                 init_utsname()->release,
16284                 (int)strcspn(init_utsname()->version, " "),
16285                 init_utsname()->version);
16286 diff -NurpP --minimal linux-2.6.32.1/kernel/sched_fair.c linux-2.6.32.1-vs2.3.0.36.27/kernel/sched_fair.c
16287 --- linux-2.6.32.1/kernel/sched_fair.c  2009-12-03 20:02:58.000000000 +0100
16288 +++ linux-2.6.32.1-vs2.3.0.36.27/kernel/sched_fair.c    2009-12-03 20:04:56.000000000 +0100
16289 @@ -189,7 +189,308 @@ find_matching_se(struct sched_entity **s
16290         }
16291  }
16292  
16293 -#else  /* !CONFIG_FAIR_GROUP_SCHED */
16294 +#ifdef CONFIG_CFS_HARD_LIMITS
16295 +
16296 +static inline void update_stats_throttle_start(struct cfs_rq *cfs_rq,
16297 +                       struct sched_entity *se)
16298 +{
16299 +       schedstat_set(se->throttle_start, rq_of(cfs_rq)->clock);
16300 +}
16301 +
16302 +static inline void update_stats_throttle_end(struct cfs_rq *cfs_rq,
16303 +                       struct sched_entity *se)
16304 +{
16305 +       schedstat_set(se->throttle_max, max(se->throttle_max,
16306 +                       rq_of(cfs_rq)->clock - se->throttle_start));
16307 +       schedstat_set(se->throttle_count, se->throttle_count + 1);
16308 +       schedstat_set(se->throttle_sum, se->throttle_sum +
16309 +                       rq_of(cfs_rq)->clock - se->throttle_start);
16310 +       schedstat_set(se->throttle_start, 0);
16311 +}
16312 +
16313 +static inline
16314 +struct cfs_rq *sched_cfs_period_cfs_rq(struct cfs_bandwidth *cfs_b, int cpu)
16315 +{
16316 +       return container_of(cfs_b, struct task_group,
16317 +                       cfs_bandwidth)->cfs_rq[cpu];
16318 +}
16319 +
16320 +static inline int cfs_rq_throttled(struct cfs_rq *cfs_rq)
16321 +{
16322 +       return cfs_rq->cfs_throttled;
16323 +}
16324 +
16325 +#ifdef CONFIG_SMP
16326 +/*
16327 + * Ensure this RQ takes back all the runtime it lend to its neighbours.
16328 + */
16329 +static void disable_runtime_cfs(struct rq *rq)
16330 +{
16331 +       struct root_domain *rd = rq->rd;
16332 +       struct cfs_rq *cfs_rq;
16333 +
16334 +       if (unlikely(!scheduler_running))
16335 +               return;
16336 +
16337 +       for_each_leaf_cfs_rq(rq, cfs_rq) {
16338 +               struct cfs_bandwidth *cfs_b = &cfs_rq->tg->cfs_bandwidth;
16339 +               s64 want;
16340 +               int i;
16341 +
16342 +               spin_lock(&cfs_b->cfs_runtime_lock);
16343 +               spin_lock(&cfs_rq->cfs_runtime_lock);
16344 +
16345 +               /*
16346 +                * Either we're all are infinity and nobody needs to borrow,
16347 +                * or we're already disabled and this have nothing to do, or
16348 +                * we have exactly the right amount of runtime to take out.
16349 +                */
16350 +                if (cfs_rq->cfs_runtime == RUNTIME_INF ||
16351 +                               cfs_rq->cfs_runtime == cfs_b->cfs_runtime)
16352 +                       goto balanced;
16353 +               spin_unlock(&cfs_rq->cfs_runtime_lock);
16354 +
16355 +               /*
16356 +                * Calculate the difference between what we started out with
16357 +                * and what we current have, that's the amount of runtime
16358 +                * we lend and now have to reclaim.
16359 +                */
16360 +                want = cfs_b->cfs_runtime - cfs_rq->cfs_runtime;
16361 +
16362 +               /*
16363 +                * Greedy reclaim, take back as much as possible.
16364 +                */
16365 +               for_each_cpu(i, rd->span) {
16366 +                       struct cfs_rq *iter = sched_cfs_period_cfs_rq(cfs_b, i);
16367 +                       s64 diff;
16368 +
16369 +                       /*
16370 +                        * Can't reclaim from ourselves or disabled runqueues.
16371 +                        */
16372 +                       if (iter == cfs_rq || iter->cfs_runtime == RUNTIME_INF)
16373 +                               continue;
16374 +
16375 +                       spin_lock(&iter->cfs_runtime_lock);
16376 +                       if (want > 0) {
16377 +                               diff = min_t(s64, iter->cfs_runtime, want);
16378 +                               iter->cfs_runtime -= diff;
16379 +                               want -= diff;
16380 +                       } else {
16381 +                               iter->cfs_runtime -= want;
16382 +                               want -= want;
16383 +                       }
16384 +
16385 +                       spin_unlock(&iter->cfs_runtime_lock);
16386 +                       if (!want)
16387 +                               break;
16388 +               }
16389 +
16390 +               spin_lock(&cfs_rq->cfs_runtime_lock);
16391 +               /*
16392 +                * We cannot be left wanting - that would mean some
16393 +                * runtime leaked out of the system.
16394 +                */
16395 +               BUG_ON(want);
16396 +balanced:
16397 +               /*
16398 +                * Disable all the borrow logic by pretending we have infinite
16399 +                * runtime - in which case borrowing doesn't make sense.
16400 +                */
16401 +                cfs_rq->cfs_runtime = RUNTIME_INF;
16402 +                spin_unlock(&cfs_rq->cfs_runtime_lock);
16403 +                spin_unlock(&cfs_b->cfs_runtime_lock);
16404 +       }
16405 +}
16406 +
16407 +static void enable_runtime_cfs(struct rq *rq)
16408 +{
16409 +       struct cfs_rq *cfs_rq;
16410 +
16411 +       if (unlikely(!scheduler_running))
16412 +               return;
16413 +
16414 +       /*
16415 +        * Reset each runqueue's bandwidth settings
16416 +        */
16417 +       for_each_leaf_cfs_rq(rq, cfs_rq) {
16418 +               struct cfs_bandwidth *cfs_b = &cfs_rq->tg->cfs_bandwidth;
16419 +
16420 +               spin_lock(&cfs_b->cfs_runtime_lock);
16421 +               spin_lock(&cfs_rq->cfs_runtime_lock);
16422 +               cfs_rq->cfs_runtime = cfs_b->cfs_runtime;
16423 +               cfs_rq->cfs_time = 0;
16424 +               cfs_rq->cfs_throttled = 0;
16425 +               spin_unlock(&cfs_rq->cfs_runtime_lock);
16426 +               spin_unlock(&cfs_b->cfs_runtime_lock);
16427 +       }
16428 +}
16429 +
16430 +/*
16431 + * Ran out of runtime, check if we can borrow some from others
16432 + * instead of getting throttled right away.
16433 + */
16434 +static void do_cfs_balance_runtime(struct cfs_rq *cfs_rq)
16435 +{
16436 +       struct cfs_bandwidth *cfs_b = &cfs_rq->tg->cfs_bandwidth;
16437 +       const struct cpumask *span = sched_bw_period_mask();
16438 +       int i, weight;
16439 +       u64 cfs_period;
16440 +
16441 +       weight = cpumask_weight(span);
16442 +       spin_lock(&cfs_b->cfs_runtime_lock);
16443 +       cfs_period = ktime_to_ns(cfs_b->cfs_period);
16444 +
16445 +       for_each_cpu(i, span) {
16446 +               struct cfs_rq *borrow_cfs_rq =
16447 +                               sched_cfs_period_cfs_rq(cfs_b, i);
16448 +               s64 diff;
16449 +
16450 +               if (borrow_cfs_rq == cfs_rq)
16451 +                       continue;
16452 +
16453 +               cfs_rq_runtime_lock(borrow_cfs_rq);
16454 +               if (borrow_cfs_rq->cfs_runtime == RUNTIME_INF) {
16455 +                       cfs_rq_runtime_unlock(borrow_cfs_rq);
16456 +                       continue;
16457 +               }
16458 +
16459 +               diff = borrow_cfs_rq->cfs_runtime - borrow_cfs_rq->cfs_time;
16460 +               if (diff > 0) {
16461 +                       diff = div_u64((u64)diff, weight);
16462 +                       if (cfs_rq->cfs_runtime + diff > cfs_period)
16463 +                               diff = cfs_period - cfs_rq->cfs_runtime;
16464 +                       borrow_cfs_rq->cfs_runtime -= diff;
16465 +                       cfs_rq->cfs_runtime += diff;
16466 +                       if (cfs_rq->cfs_runtime == cfs_period) {
16467 +                               cfs_rq_runtime_unlock(borrow_cfs_rq);
16468 +                               break;
16469 +                       }
16470 +               }
16471 +               cfs_rq_runtime_unlock(borrow_cfs_rq);
16472 +       }
16473 +       spin_unlock(&cfs_b->cfs_runtime_lock);
16474 +}
16475 +
16476 +/*
16477 + * Called with rq->runtime_lock held.
16478 + */
16479 +static void cfs_balance_runtime(struct cfs_rq *cfs_rq)
16480 +{
16481 +       cfs_rq_runtime_unlock(cfs_rq);
16482 +       do_cfs_balance_runtime(cfs_rq);
16483 +       cfs_rq_runtime_lock(cfs_rq);
16484 +}
16485 +
16486 +#else /* !CONFIG_SMP */
16487 +
16488 +static void cfs_balance_runtime(struct cfs_rq *cfs_rq)
16489 +{
16490 +       return;
16491 +}
16492 +#endif /* CONFIG_SMP */
16493 +
16494 +/*
16495 + * Check if group entity exceeded its runtime. If so, mark the cfs_rq as
16496 + * throttled mark the current task for reschedling.
16497 + */
16498 +static void sched_cfs_runtime_exceeded(struct sched_entity *se,
16499 +       struct task_struct *tsk_curr, unsigned long delta_exec)
16500 +{
16501 +       struct cfs_rq *cfs_rq;
16502 +
16503 +       cfs_rq = group_cfs_rq(se);
16504 +
16505 +       if (cfs_rq->cfs_runtime == RUNTIME_INF)
16506 +               return;
16507 +
16508 +       cfs_rq->cfs_time += delta_exec;
16509 +
16510 +       if (cfs_rq_throttled(cfs_rq))
16511 +               return;
16512 +
16513 +       if (cfs_rq->cfs_time > cfs_rq->cfs_runtime)
16514 +               cfs_balance_runtime(cfs_rq);
16515 +
16516 +       if (cfs_rq->cfs_time > cfs_rq->cfs_runtime) {
16517 +               cfs_rq->cfs_throttled = 1;
16518 +               update_stats_throttle_start(cfs_rq, se);
16519 +               resched_task(tsk_curr);
16520 +       }
16521 +}
16522 +
16523 +static inline void update_curr_group(struct sched_entity *curr,
16524 +               unsigned long delta_exec, struct task_struct *tsk_curr)
16525 +{
16526 +       sched_cfs_runtime_exceeded(curr, tsk_curr, delta_exec);
16527 +}
16528 +
16529 +static void enqueue_entity_locked(struct cfs_rq *cfs_rq,
16530 +               struct sched_entity *se, int wakeup);
16531 +
16532 +static void enqueue_throttled_entity(struct rq *rq, struct sched_entity *se)
16533 +{
16534 +       for_each_sched_entity(se) {
16535 +               struct cfs_rq *gcfs_rq = group_cfs_rq(se);
16536 +
16537 +               if (se->on_rq || cfs_rq_throttled(gcfs_rq) ||
16538 +                               !gcfs_rq->nr_running)
16539 +                       break;
16540 +               enqueue_entity_locked(cfs_rq_of(se), se, 0);
16541 +       }
16542 +}
16543 +
16544 +/*
16545 + * Refresh runtimes of all cfs_rqs in this group, i,e.,
16546 + * refresh runtimes of the representative cfs_rq of this
16547 + * tg on all cpus. Enqueue any throttled entity back.
16548 + */
16549 +void do_sched_cfs_period_timer(struct cfs_bandwidth *cfs_b)
16550 +{
16551 +       int i;
16552 +       const struct cpumask *span = sched_bw_period_mask();
16553 +       unsigned long flags;
16554 +
16555 +       for_each_cpu(i, span) {
16556 +               struct rq *rq = cpu_rq(i);
16557 +               struct cfs_rq *cfs_rq = sched_cfs_period_cfs_rq(cfs_b, i);
16558 +               struct sched_entity *se = cfs_rq->tg->se[i];
16559 +
16560 +               spin_lock_irqsave(&rq->lock, flags);
16561 +               cfs_rq_runtime_lock(cfs_rq);
16562 +               cfs_rq->cfs_time = 0;
16563 +               if (cfs_rq_throttled(cfs_rq)) {
16564 +                       update_rq_clock(rq);
16565 +                       update_stats_throttle_end(cfs_rq, se);
16566 +                       cfs_rq->cfs_throttled = 0;
16567 +                       enqueue_throttled_entity(rq, se);
16568 +               }
16569 +               cfs_rq_runtime_unlock(cfs_rq);
16570 +               spin_unlock_irqrestore(&rq->lock, flags);
16571 +       }
16572 +}
16573 +
16574 +#else
16575 +
16576 +static inline void update_curr_group(struct sched_entity *curr,
16577 +               unsigned long delta_exec, struct task_struct *tsk_curr)
16578 +{
16579 +       return;
16580 +}
16581 +
16582 +static inline int cfs_rq_throttled(struct cfs_rq *cfs_rq)
16583 +{
16584 +       return 0;
16585 +}
16586 +
16587 +#endif /* CONFIG_CFS_HARD_LIMITS */
16588 +
16589 +#else  /* CONFIG_FAIR_GROUP_SCHED */
16590 +
16591 +static inline void update_curr_group(struct sched_entity *curr,
16592 +               unsigned long delta_exec, struct task_struct *tsk_curr)
16593 +{
16594 +       return;
16595 +}
16596  
16597  static inline struct task_struct *task_of(struct sched_entity *se)
16598  {
16599 @@ -251,7 +552,6 @@ find_matching_se(struct sched_entity **s
16600  
16601  #endif /* CONFIG_FAIR_GROUP_SCHED */
16602  
16603 -
16604  /**************************************************************
16605   * Scheduling class tree data structure manipulation methods:
16606   */
16607 @@ -489,14 +789,25 @@ __update_curr(struct cfs_rq *cfs_rq, str
16608         update_min_vruntime(cfs_rq);
16609  }
16610  
16611 -static void update_curr(struct cfs_rq *cfs_rq)
16612 +static void update_curr_task(struct sched_entity *curr,
16613 +               unsigned long delta_exec)
16614 +{
16615 +       struct task_struct *curtask = task_of(curr);
16616 +
16617 +       trace_sched_stat_runtime(curtask, delta_exec, curr->vruntime);
16618 +       cpuacct_charge(curtask, delta_exec);
16619 +       account_group_exec_runtime(curtask, delta_exec);
16620 +}
16621 +
16622 +static int update_curr_common(struct cfs_rq *cfs_rq, unsigned long *delta)
16623  {
16624         struct sched_entity *curr = cfs_rq->curr;
16625 -       u64 now = rq_of(cfs_rq)->clock;
16626 +       struct rq *rq = rq_of(cfs_rq);
16627 +       u64 now = rq->clock;
16628         unsigned long delta_exec;
16629  
16630         if (unlikely(!curr))
16631 -               return;
16632 +               return 1;
16633  
16634         /*
16635          * Get the amount of time the current task was running
16636 @@ -505,20 +816,47 @@ static void update_curr(struct cfs_rq *c
16637          */
16638         delta_exec = (unsigned long)(now - curr->exec_start);
16639         if (!delta_exec)
16640 -               return;
16641 +               return 1;
16642  
16643         __update_curr(cfs_rq, curr, delta_exec);
16644         curr->exec_start = now;
16645 +       *delta = delta_exec;
16646 +       return 0;
16647 +}
16648  
16649 -       if (entity_is_task(curr)) {
16650 -               struct task_struct *curtask = task_of(curr);
16651 +static void update_curr(struct cfs_rq *cfs_rq)
16652 +{
16653 +       struct sched_entity *curr = cfs_rq->curr;
16654 +       struct rq *rq = rq_of(cfs_rq);
16655 +       unsigned long delta_exec;
16656  
16657 -               trace_sched_stat_runtime(curtask, delta_exec, curr->vruntime);
16658 -               cpuacct_charge(curtask, delta_exec);
16659 -               account_group_exec_runtime(curtask, delta_exec);
16660 +       if (update_curr_common(cfs_rq, &delta_exec))
16661 +               return ;
16662 +
16663 +       if (entity_is_task(curr))
16664 +               update_curr_task(curr, delta_exec);
16665 +       else {
16666 +               cfs_rq_runtime_lock(group_cfs_rq(curr));
16667 +               update_curr_group(curr, delta_exec, rq->curr);
16668 +               cfs_rq_runtime_unlock(group_cfs_rq(curr));
16669         }
16670  }
16671  
16672 +static void update_curr_locked(struct cfs_rq *cfs_rq)
16673 +{
16674 +       struct sched_entity *curr = cfs_rq->curr;
16675 +       struct rq *rq = rq_of(cfs_rq);
16676 +       unsigned long delta_exec;
16677 +
16678 +       if (update_curr_common(cfs_rq, &delta_exec))
16679 +               return ;
16680 +
16681 +       if (entity_is_task(curr))
16682 +               update_curr_task(curr, delta_exec);
16683 +       else
16684 +               update_curr_group(curr, delta_exec, rq->curr);
16685 +}
16686 +
16687  static inline void
16688  update_stats_wait_start(struct cfs_rq *cfs_rq, struct sched_entity *se)
16689  {
16690 @@ -740,13 +1078,9 @@ place_entity(struct cfs_rq *cfs_rq, stru
16691         se->vruntime = vruntime;
16692  }
16693  
16694 -static void
16695 -enqueue_entity(struct cfs_rq *cfs_rq, struct sched_entity *se, int wakeup)
16696 +static void enqueue_entity_common(struct cfs_rq *cfs_rq,
16697 +               struct sched_entity *se, int wakeup)
16698  {
16699 -       /*
16700 -        * Update run-time statistics of the 'current'.
16701 -        */
16702 -       update_curr(cfs_rq);
16703         account_entity_enqueue(cfs_rq, se);
16704  
16705         if (wakeup) {
16706 @@ -758,6 +1092,29 @@ enqueue_entity(struct cfs_rq *cfs_rq, st
16707         check_spread(cfs_rq, se);
16708         if (se != cfs_rq->curr)
16709                 __enqueue_entity(cfs_rq, se);
16710 +
16711 +       if (entity_is_task(se))
16712 +               vx_activate_task(task_of(se));
16713 +}
16714 +
16715 +static void enqueue_entity(struct cfs_rq *cfs_rq, struct sched_entity *se,
16716 +               int wakeup)
16717 +{
16718 +       /*
16719 +        * Update run-time statistics of the 'current'.
16720 +        */
16721 +       update_curr(cfs_rq);
16722 +       enqueue_entity_common(cfs_rq, se, wakeup);
16723 +}
16724 +
16725 +static void enqueue_entity_locked(struct cfs_rq *cfs_rq,
16726 +               struct sched_entity *se, int wakeup)
16727 +{
16728 +       /*
16729 +        * Update run-time statistics of the 'current'.
16730 +        */
16731 +       update_curr_locked(cfs_rq);
16732 +       enqueue_entity_common(cfs_rq, se, wakeup);
16733  }
16734  
16735  static void __clear_buddies(struct cfs_rq *cfs_rq, struct sched_entity *se)
16736 @@ -801,6 +1158,8 @@ dequeue_entity(struct cfs_rq *cfs_rq, st
16737  
16738         if (se != cfs_rq->curr)
16739                 __dequeue_entity(cfs_rq, se);
16740 +       if (entity_is_task(se))
16741 +               vx_deactivate_task(task_of(se));
16742         account_entity_dequeue(cfs_rq, se);
16743         update_min_vruntime(cfs_rq);
16744  }
16745 @@ -897,6 +1256,32 @@ static struct sched_entity *pick_next_en
16746         return se;
16747  }
16748  
16749 +/*
16750 + * Called from put_prev_entity()
16751 + * If a group entity (@se) is found to be throttled, it will not be put back
16752 + * on @cfs_rq, which is equivalent to dequeing it.
16753 + */
16754 +static int dequeue_throttled_entity(struct cfs_rq *cfs_rq,
16755 +               struct sched_entity *se)
16756 +{
16757 +       struct cfs_rq *gcfs_rq = group_cfs_rq(se);
16758 +
16759 +       if (entity_is_task(se))
16760 +               return 0;
16761 +
16762 +       cfs_rq_runtime_lock(gcfs_rq);
16763 +       if (!cfs_rq_throttled(gcfs_rq) && gcfs_rq->nr_running) {
16764 +               cfs_rq_runtime_unlock(gcfs_rq);
16765 +               return 0;
16766 +       }
16767 +
16768 +       __clear_buddies(cfs_rq, se);
16769 +       account_entity_dequeue(cfs_rq, se);
16770 +       cfs_rq->curr = NULL;
16771 +       cfs_rq_runtime_unlock(gcfs_rq);
16772 +       return 1;
16773 +}
16774 +
16775  static void put_prev_entity(struct cfs_rq *cfs_rq, struct sched_entity *prev)
16776  {
16777         /*
16778 @@ -908,6 +1293,8 @@ static void put_prev_entity(struct cfs_r
16779  
16780         check_spread(cfs_rq, prev);
16781         if (prev->on_rq) {
16782 +               if (dequeue_throttled_entity(cfs_rq, prev))
16783 +                       return;
16784                 update_stats_wait_start(cfs_rq, prev);
16785                 /* Put 'current' back into the tree. */
16786                 __enqueue_entity(cfs_rq, prev);
16787 @@ -1004,10 +1391,28 @@ static inline void hrtick_update(struct 
16788  }
16789  #endif
16790  
16791 +static int enqueue_group_entity(struct cfs_rq *cfs_rq, struct sched_entity *se,
16792 +                int wakeup)
16793 +{
16794 +       struct cfs_rq *gcfs_rq = group_cfs_rq(se);
16795 +       int ret = 0;
16796 +
16797 +       cfs_rq_runtime_lock(gcfs_rq);
16798 +       if (cfs_rq_throttled(gcfs_rq)) {
16799 +               ret = 1;
16800 +               goto out;
16801 +       }
16802 +       enqueue_entity_locked(cfs_rq, se, wakeup);
16803 +out:
16804 +       cfs_rq_runtime_unlock(gcfs_rq);
16805 +       return ret;
16806 +}
16807 +
16808  /*
16809   * The enqueue_task method is called before nr_running is
16810   * increased. Here we update the fair scheduling stats and
16811   * then put the task into the rbtree:
16812 + * Don't enqueue a throttled entity further into the hierarchy.
16813   */
16814  static void enqueue_task_fair(struct rq *rq, struct task_struct *p, int wakeup)
16815  {
16816 @@ -1017,11 +1422,15 @@ static void enqueue_task_fair(struct rq 
16817         for_each_sched_entity(se) {
16818                 if (se->on_rq)
16819                         break;
16820 +
16821                 cfs_rq = cfs_rq_of(se);
16822 -               enqueue_entity(cfs_rq, se, wakeup);
16823 +               if (entity_is_task(se))
16824 +                       enqueue_entity(cfs_rq, se, wakeup);
16825 +               else
16826 +                       if (enqueue_group_entity(cfs_rq, se, wakeup))
16827 +                               break;
16828                 wakeup = 1;
16829         }
16830 -
16831         hrtick_update(rq);
16832  }
16833  
16834 @@ -1041,6 +1450,17 @@ static void dequeue_task_fair(struct rq 
16835                 /* Don't dequeue parent if it has other entities besides us */
16836                 if (cfs_rq->load.weight)
16837                         break;
16838 +
16839 +               /*
16840 +                * If this cfs_rq is throttled, then it is already
16841 +                * dequeued.
16842 +                */
16843 +               cfs_rq_runtime_lock(cfs_rq);
16844 +               if (cfs_rq_throttled(cfs_rq)) {
16845 +                       cfs_rq_runtime_unlock(cfs_rq);
16846 +                       break;
16847 +               }
16848 +               cfs_rq_runtime_unlock(cfs_rq);
16849                 sleep = 1;
16850         }
16851  
16852 @@ -1788,9 +2208,10 @@ load_balance_fair(struct rq *this_rq, in
16853                 u64 rem_load, moved_load;
16854  
16855                 /*
16856 -                * empty group
16857 +                * empty group or throttled group
16858                  */
16859 -               if (!busiest_cfs_rq->task_weight)
16860 +               if (!busiest_cfs_rq->task_weight ||
16861 +                               cfs_rq_throttled(busiest_cfs_rq))
16862                         continue;
16863  
16864                 rem_load = (u64)rem_load_move * busiest_weight;
16865 @@ -1839,6 +2260,12 @@ move_one_task_fair(struct rq *this_rq, i
16866  
16867         for_each_leaf_cfs_rq(busiest, busy_cfs_rq) {
16868                 /*
16869 +                * Don't move task from a throttled cfs_rq
16870 +                */
16871 +               if (cfs_rq_throttled(busy_cfs_rq))
16872 +                       continue;
16873 +
16874 +               /*
16875                  * pass busy_cfs_rq argument into
16876                  * load_balance_[start|next]_fair iterators
16877                  */
16878 diff -NurpP --minimal linux-2.6.32.1/kernel/sched_rt.c linux-2.6.32.1-vs2.3.0.36.27/kernel/sched_rt.c
16879 --- linux-2.6.32.1/kernel/sched_rt.c    2009-12-03 20:02:58.000000000 +0100
16880 +++ linux-2.6.32.1-vs2.3.0.36.27/kernel/sched_rt.c      2009-12-03 20:04:56.000000000 +0100
16881 @@ -235,18 +235,6 @@ static int rt_se_boosted(struct sched_rt
16882         return p->prio != p->normal_prio;
16883  }
16884  
16885 -#ifdef CONFIG_SMP
16886 -static inline const struct cpumask *sched_rt_period_mask(void)
16887 -{
16888 -       return cpu_rq(smp_processor_id())->rd->span;
16889 -}
16890 -#else
16891 -static inline const struct cpumask *sched_rt_period_mask(void)
16892 -{
16893 -       return cpu_online_mask;
16894 -}
16895 -#endif
16896 -
16897  static inline
16898  struct rt_rq *sched_rt_period_rt_rq(struct rt_bandwidth *rt_b, int cpu)
16899  {
16900 @@ -296,11 +284,6 @@ static inline int rt_rq_throttled(struct
16901         return rt_rq->rt_throttled;
16902  }
16903  
16904 -static inline const struct cpumask *sched_rt_period_mask(void)
16905 -{
16906 -       return cpu_online_mask;
16907 -}
16908 -
16909  static inline
16910  struct rt_rq *sched_rt_period_rt_rq(struct rt_bandwidth *rt_b, int cpu)
16911  {
16912 @@ -373,7 +356,7 @@ next:
16913  /*
16914   * Ensure this RQ takes back all the runtime it lend to its neighbours.
16915   */
16916 -static void __disable_runtime(struct rq *rq)
16917 +static void disable_runtime_rt(struct rq *rq)
16918  {
16919         struct root_domain *rd = rq->rd;
16920         struct rt_rq *rt_rq;
16921 @@ -450,16 +433,7 @@ balanced:
16922         }
16923  }
16924  
16925 -static void disable_runtime(struct rq *rq)
16926 -{
16927 -       unsigned long flags;
16928 -
16929 -       spin_lock_irqsave(&rq->lock, flags);
16930 -       __disable_runtime(rq);
16931 -       spin_unlock_irqrestore(&rq->lock, flags);
16932 -}
16933 -
16934 -static void __enable_runtime(struct rq *rq)
16935 +static void enable_runtime_rt(struct rq *rq)
16936  {
16937         struct rt_rq *rt_rq;
16938  
16939 @@ -482,15 +456,6 @@ static void __enable_runtime(struct rq *
16940         }
16941  }
16942  
16943 -static void enable_runtime(struct rq *rq)
16944 -{
16945 -       unsigned long flags;
16946 -
16947 -       spin_lock_irqsave(&rq->lock, flags);
16948 -       __enable_runtime(rq);
16949 -       spin_unlock_irqrestore(&rq->lock, flags);
16950 -}
16951 -
16952  static int balance_runtime(struct rt_rq *rt_rq)
16953  {
16954         int more = 0;
16955 @@ -518,7 +483,7 @@ static int do_sched_rt_period_timer(stru
16956         if (!rt_bandwidth_enabled() || rt_b->rt_runtime == RUNTIME_INF)
16957                 return 1;
16958  
16959 -       span = sched_rt_period_mask();
16960 +       span = sched_bw_period_mask();
16961         for_each_cpu(i, span) {
16962                 int enqueue = 0;
16963                 struct rt_rq *rt_rq = sched_rt_period_rt_rq(rt_b, i);
16964 @@ -1564,7 +1529,7 @@ static void rq_online_rt(struct rq *rq)
16965         if (rq->rt.overloaded)
16966                 rt_set_overload(rq);
16967  
16968 -       __enable_runtime(rq);
16969 +       enable_runtime_rt(rq);
16970  
16971         cpupri_set(&rq->rd->cpupri, rq->cpu, rq->rt.highest_prio.curr);
16972  }
16973 @@ -1575,7 +1540,7 @@ static void rq_offline_rt(struct rq *rq)
16974         if (rq->rt.overloaded)
16975                 rt_clear_overload(rq);
16976  
16977 -       __disable_runtime(rq);
16978 +       disable_runtime_rt(rq);
16979  
16980         cpupri_set(&rq->rd->cpupri, rq->cpu, CPUPRI_INVALID);
16981  }
16982 diff -NurpP --minimal linux-2.6.32.1/kernel/signal.c linux-2.6.32.1-vs2.3.0.36.27/kernel/signal.c
16983 --- linux-2.6.32.1/kernel/signal.c      2009-12-03 20:02:58.000000000 +0100
16984 +++ linux-2.6.32.1-vs2.3.0.36.27/kernel/signal.c        2009-12-03 20:04:56.000000000 +0100
16985 @@ -27,6 +27,8 @@
16986  #include <linux/freezer.h>
16987  #include <linux/pid_namespace.h>
16988  #include <linux/nsproxy.h>
16989 +#include <linux/vs_context.h>
16990 +#include <linux/vs_pid.h>
16991  #include <trace/events/sched.h>
16992  
16993  #include <asm/param.h>
16994 @@ -598,6 +600,14 @@ static int check_kill_permission(int sig
16995         if (!valid_signal(sig))
16996                 return -EINVAL;
16997  
16998 +       if ((info != SEND_SIG_NOINFO) &&
16999 +               (is_si_special(info) || !SI_FROMUSER(info)))
17000 +               goto skip;
17001 +
17002 +       vxdprintk(VXD_CBIT(misc, 7),
17003 +               "check_kill_permission(%d,%p,%p[#%u,%u])",
17004 +               sig, info, t, vx_task_xid(t), t->pid);
17005 +
17006         if (info != SEND_SIG_NOINFO && (is_si_special(info) || SI_FROMKERNEL(info)))
17007                 return 0;
17008  
17009 @@ -625,6 +635,20 @@ static int check_kill_permission(int sig
17010                 }
17011         }
17012  
17013 +       error = -EPERM;
17014 +       if (t->pid == 1 && current->xid)
17015 +               return error;
17016 +
17017 +       error = -ESRCH;
17018 +       /* FIXME: we shouldn't return ESRCH ever, to avoid
17019 +                 loops, maybe ENOENT or EACCES? */
17020 +       if (!vx_check(vx_task_xid(t), VS_WATCH_P | VS_IDENT)) {
17021 +               vxdprintk(current->xid || VXD_CBIT(misc, 7),
17022 +                       "signal %d[%p] xid mismatch %p[#%u,%u] xid=#%u",
17023 +                       sig, info, t, vx_task_xid(t), t->pid, current->xid);
17024 +               return error;
17025 +       }
17026 +skip:
17027         return security_task_kill(t, info, sig, 0);
17028  }
17029  
17030 @@ -1112,7 +1136,7 @@ int kill_pid_info(int sig, struct siginf
17031         rcu_read_lock();
17032  retry:
17033         p = pid_task(pid, PIDTYPE_PID);
17034 -       if (p) {
17035 +       if (p && vx_check(vx_task_xid(p), VS_IDENT)) {
17036                 error = group_send_sig_info(sig, info, p);
17037                 if (unlikely(error == -ESRCH))
17038                         /*
17039 @@ -1151,7 +1175,7 @@ int kill_pid_info_as_uid(int sig, struct
17040  
17041         read_lock(&tasklist_lock);
17042         p = pid_task(pid, PIDTYPE_PID);
17043 -       if (!p) {
17044 +       if (!p || !vx_check(vx_task_xid(p), VS_IDENT)) {
17045                 ret = -ESRCH;
17046                 goto out_unlock;
17047         }
17048 @@ -1205,8 +1229,10 @@ static int kill_something_info(int sig, 
17049                 struct task_struct * p;
17050  
17051                 for_each_process(p) {
17052 -                       if (task_pid_vnr(p) > 1 &&
17053 -                                       !same_thread_group(p, current)) {
17054 +                       if (vx_check(vx_task_xid(p), VS_ADMIN|VS_IDENT) &&
17055 +                               task_pid_vnr(p) > 1 &&
17056 +                               !same_thread_group(p, current) &&
17057 +                               !vx_current_initpid(p->pid)) {
17058                                 int err = group_send_sig_info(sig, info, p);
17059                                 ++count;
17060                                 if (err != -EPERM)
17061 @@ -1871,6 +1897,11 @@ relock:
17062                                 !sig_kernel_only(signr))
17063                         continue;
17064  
17065 +               /* virtual init is protected against user signals */
17066 +               if ((info->si_code == SI_USER) &&
17067 +                       vx_current_initpid(current->pid))
17068 +                       continue;
17069 +
17070                 if (sig_kernel_stop(signr)) {
17071                         /*
17072                          * The default action is to stop all threads in
17073 diff -NurpP --minimal linux-2.6.32.1/kernel/softirq.c linux-2.6.32.1-vs2.3.0.36.27/kernel/softirq.c
17074 --- linux-2.6.32.1/kernel/softirq.c     2009-12-03 20:02:58.000000000 +0100
17075 +++ linux-2.6.32.1-vs2.3.0.36.27/kernel/softirq.c       2009-12-03 20:04:56.000000000 +0100
17076 @@ -24,6 +24,7 @@
17077  #include <linux/ftrace.h>
17078  #include <linux/smp.h>
17079  #include <linux/tick.h>
17080 +#include <linux/vs_context.h>
17081  
17082  #define CREATE_TRACE_POINTS
17083  #include <trace/events/irq.h>
17084 diff -NurpP --minimal linux-2.6.32.1/kernel/sys.c linux-2.6.32.1-vs2.3.0.36.27/kernel/sys.c
17085 --- linux-2.6.32.1/kernel/sys.c 2009-12-03 20:02:58.000000000 +0100
17086 +++ linux-2.6.32.1-vs2.3.0.36.27/kernel/sys.c   2009-12-03 20:04:56.000000000 +0100
17087 @@ -41,6 +41,7 @@
17088  #include <linux/syscalls.h>
17089  #include <linux/kprobes.h>
17090  #include <linux/user_namespace.h>
17091 +#include <linux/vs_pid.h>
17092  
17093  #include <asm/uaccess.h>
17094  #include <asm/io.h>
17095 @@ -130,7 +131,10 @@ static int set_one_prio(struct task_stru
17096                 goto out;
17097         }
17098         if (niceval < task_nice(p) && !can_nice(p, niceval)) {
17099 -               error = -EACCES;
17100 +               if (vx_flags(VXF_IGNEG_NICE, 0))
17101 +                       error = 0;
17102 +               else
17103 +                       error = -EACCES;
17104                 goto out;
17105         }
17106         no_nice = security_task_setnice(p, niceval);
17107 @@ -179,6 +183,8 @@ SYSCALL_DEFINE3(setpriority, int, which,
17108                         else
17109                                 pgrp = task_pgrp(current);
17110                         do_each_pid_thread(pgrp, PIDTYPE_PGID, p) {
17111 +                               if (!vx_check(p->xid, VS_ADMIN_P | VS_IDENT))
17112 +                                       continue;
17113                                 error = set_one_prio(p, niceval, error);
17114                         } while_each_pid_thread(pgrp, PIDTYPE_PGID, p);
17115                         break;
17116 @@ -240,6 +246,8 @@ SYSCALL_DEFINE2(getpriority, int, which,
17117                         else
17118                                 pgrp = task_pgrp(current);
17119                         do_each_pid_thread(pgrp, PIDTYPE_PGID, p) {
17120 +                               if (!vx_check(p->xid, VS_ADMIN_P | VS_IDENT))
17121 +                                       continue;
17122                                 niceval = 20 - task_nice(p);
17123                                 if (niceval > retval)
17124                                         retval = niceval;
17125 @@ -349,6 +357,9 @@ void kernel_power_off(void)
17126         machine_power_off();
17127  }
17128  EXPORT_SYMBOL_GPL(kernel_power_off);
17129 +
17130 +long vs_reboot(unsigned int, void __user *);
17131 +
17132  /*
17133   * Reboot system call: for obvious reasons only root may call it,
17134   * and even root needs to set up some magic numbers in the registers
17135 @@ -381,6 +392,9 @@ SYSCALL_DEFINE4(reboot, int, magic1, int
17136         if ((cmd == LINUX_REBOOT_CMD_POWER_OFF) && !pm_power_off)
17137                 cmd = LINUX_REBOOT_CMD_HALT;
17138  
17139 +       if (!vx_check(0, VS_ADMIN|VS_WATCH))
17140 +               return vs_reboot(cmd, arg);
17141 +
17142         lock_kernel();
17143         switch (cmd) {
17144         case LINUX_REBOOT_CMD_RESTART:
17145 @@ -1133,7 +1147,7 @@ SYSCALL_DEFINE2(sethostname, char __user
17146         int errno;
17147         char tmp[__NEW_UTS_LEN];
17148  
17149 -       if (!capable(CAP_SYS_ADMIN))
17150 +       if (!vx_capable(CAP_SYS_ADMIN, VXC_SET_UTSNAME))
17151                 return -EPERM;
17152         if (len < 0 || len > __NEW_UTS_LEN)
17153                 return -EINVAL;
17154 @@ -1182,7 +1196,7 @@ SYSCALL_DEFINE2(setdomainname, char __us
17155         int errno;
17156         char tmp[__NEW_UTS_LEN];
17157  
17158 -       if (!capable(CAP_SYS_ADMIN))
17159 +       if (!vx_capable(CAP_SYS_ADMIN, VXC_SET_UTSNAME))
17160                 return -EPERM;
17161         if (len < 0 || len > __NEW_UTS_LEN)
17162                 return -EINVAL;
17163 @@ -1251,7 +1265,7 @@ SYSCALL_DEFINE2(setrlimit, unsigned int,
17164                 return -EINVAL;
17165         old_rlim = current->signal->rlim + resource;
17166         if ((new_rlim.rlim_max > old_rlim->rlim_max) &&
17167 -           !capable(CAP_SYS_RESOURCE))
17168 +           !vx_capable(CAP_SYS_RESOURCE, VXC_SET_RLIMIT))
17169                 return -EPERM;
17170         if (resource == RLIMIT_NOFILE && new_rlim.rlim_max > sysctl_nr_open)
17171                 return -EPERM;
17172 diff -NurpP --minimal linux-2.6.32.1/kernel/sysctl.c linux-2.6.32.1-vs2.3.0.36.27/kernel/sysctl.c
17173 --- linux-2.6.32.1/kernel/sysctl.c      2009-12-03 20:02:58.000000000 +0100
17174 +++ linux-2.6.32.1-vs2.3.0.36.27/kernel/sysctl.c        2009-12-03 20:04:56.000000000 +0100
17175 @@ -124,6 +124,7 @@ static int ngroups_max = NGROUPS_MAX;
17176  extern char modprobe_path[];
17177  extern int modules_disabled;
17178  #endif
17179 +extern char vshelper_path[];
17180  #ifdef CONFIG_CHR_DEV_SG
17181  extern int sg_big_buff;
17182  #endif
17183 @@ -593,6 +594,15 @@ static struct ctl_table kern_table[] = {
17184                 .strategy       = &sysctl_string,
17185         },
17186  #endif
17187 +       {
17188 +               .ctl_name       = KERN_VSHELPER,
17189 +               .procname       = "vshelper",
17190 +               .data           = &vshelper_path,
17191 +               .maxlen         = 256,
17192 +               .mode           = 0644,
17193 +               .proc_handler   = &proc_dostring,
17194 +               .strategy       = &sysctl_string,
17195 +       },
17196  #ifdef CONFIG_CHR_DEV_SG
17197         {
17198                 .ctl_name       = KERN_SG_BIG_BUFF,
17199 diff -NurpP --minimal linux-2.6.32.1/kernel/sysctl_check.c linux-2.6.32.1-vs2.3.0.36.27/kernel/sysctl_check.c
17200 --- linux-2.6.32.1/kernel/sysctl_check.c        2009-12-03 20:02:58.000000000 +0100
17201 +++ linux-2.6.32.1-vs2.3.0.36.27/kernel/sysctl_check.c  2009-12-03 20:04:56.000000000 +0100
17202 @@ -39,6 +39,7 @@ static const struct trans_ctl_table tran
17203  
17204         { KERN_PANIC,                   "panic" },
17205         { KERN_REALROOTDEV,             "real-root-dev" },
17206 +       { KERN_VSHELPER,                "vshelper", },
17207  
17208         { KERN_SPARC_REBOOT,            "reboot-cmd" },
17209         { KERN_CTLALTDEL,               "ctrl-alt-del" },
17210 @@ -1217,6 +1218,22 @@ static const struct trans_ctl_table tran
17211         {}
17212  };
17213  
17214 +static struct trans_ctl_table trans_vserver_table[] = {
17215 +       { 1,    "debug_switch" },
17216 +       { 2,    "debug_xid" },
17217 +       { 3,    "debug_nid" },
17218 +       { 4,    "debug_tag" },
17219 +       { 5,    "debug_net" },
17220 +       { 6,    "debug_limit" },
17221 +       { 7,    "debug_cres" },
17222 +       { 8,    "debug_dlim" },
17223 +       { 9,    "debug_quota" },
17224 +       { 10,   "debug_cvirt" },
17225 +       { 11,   "debug_space" },
17226 +       { 12,   "debug_misc" },
17227 +       {}
17228 +};
17229 +
17230  static const struct trans_ctl_table trans_root_table[] = {
17231         { CTL_KERN,     "kernel",       trans_kern_table },
17232         { CTL_VM,       "vm",           trans_vm_table },
17233 @@ -1233,6 +1250,7 @@ static const struct trans_ctl_table tran
17234         { CTL_SUNRPC,   "sunrpc",       trans_sunrpc_table },
17235         { CTL_PM,       "pm",           trans_pm_table },
17236         { CTL_FRV,      "frv",          trans_frv_table },
17237 +       { CTL_VSERVER,  "vserver",      trans_vserver_table },
17238         {}
17239  };
17240  
17241 diff -NurpP --minimal linux-2.6.32.1/kernel/time.c linux-2.6.32.1-vs2.3.0.36.27/kernel/time.c
17242 --- linux-2.6.32.1/kernel/time.c        2009-12-03 20:02:58.000000000 +0100
17243 +++ linux-2.6.32.1-vs2.3.0.36.27/kernel/time.c  2009-12-03 20:04:56.000000000 +0100
17244 @@ -63,6 +63,7 @@ EXPORT_SYMBOL(sys_tz);
17245  SYSCALL_DEFINE1(time, time_t __user *, tloc)
17246  {
17247         time_t i = get_seconds();
17248 +/*     FIXME: do_gettimeofday(&tv) -> vx_gettimeofday(&tv) */
17249  
17250         if (tloc) {
17251                 if (put_user(i,tloc))
17252 @@ -93,7 +94,7 @@ SYSCALL_DEFINE1(stime, time_t __user *, 
17253         if (err)
17254                 return err;
17255  
17256 -       do_settimeofday(&tv);
17257 +       vx_settimeofday(&tv);
17258         return 0;
17259  }
17260  
17261 @@ -104,7 +105,7 @@ SYSCALL_DEFINE2(gettimeofday, struct tim
17262  {
17263         if (likely(tv != NULL)) {
17264                 struct timeval ktv;
17265 -               do_gettimeofday(&ktv);
17266 +               vx_gettimeofday(&ktv);
17267                 if (copy_to_user(tv, &ktv, sizeof(ktv)))
17268                         return -EFAULT;
17269         }
17270 @@ -179,7 +180,7 @@ int do_sys_settimeofday(struct timespec 
17271                 /* SMP safe, again the code in arch/foo/time.c should
17272                  * globally block out interrupts when it runs.
17273                  */
17274 -               return do_settimeofday(tv);
17275 +               return vx_settimeofday(tv);
17276         }
17277         return 0;
17278  }
17279 @@ -311,7 +312,7 @@ void getnstimeofday(struct timespec *tv)
17280  {
17281         struct timeval x;
17282  
17283 -       do_gettimeofday(&x);
17284 +       vx_gettimeofday(&x);
17285         tv->tv_sec = x.tv_sec;
17286         tv->tv_nsec = x.tv_usec * NSEC_PER_USEC;
17287  }
17288 diff -NurpP --minimal linux-2.6.32.1/kernel/timer.c linux-2.6.32.1-vs2.3.0.36.27/kernel/timer.c
17289 --- linux-2.6.32.1/kernel/timer.c       2009-12-03 20:02:58.000000000 +0100
17290 +++ linux-2.6.32.1-vs2.3.0.36.27/kernel/timer.c 2009-12-03 20:04:56.000000000 +0100
17291 @@ -39,6 +39,10 @@
17292  #include <linux/kallsyms.h>
17293  #include <linux/perf_event.h>
17294  #include <linux/sched.h>
17295 +#include <linux/vs_base.h>
17296 +#include <linux/vs_cvirt.h>
17297 +#include <linux/vs_pid.h>
17298 +#include <linux/vserver/sched.h>
17299  
17300  #include <asm/uaccess.h>
17301  #include <asm/unistd.h>
17302 @@ -1255,12 +1259,6 @@ SYSCALL_DEFINE1(alarm, unsigned int, sec
17303  
17304  #endif
17305  
17306 -#ifndef __alpha__
17307 -
17308 -/*
17309 - * The Alpha uses getxpid, getxuid, and getxgid instead.  Maybe this
17310 - * should be moved into arch/i386 instead?
17311 - */
17312  
17313  /**
17314   * sys_getpid - return the thread group id of the current process
17315 @@ -1289,10 +1287,23 @@ SYSCALL_DEFINE0(getppid)
17316         rcu_read_lock();
17317         pid = task_tgid_vnr(current->real_parent);
17318         rcu_read_unlock();
17319 +       return vx_map_pid(pid);
17320 +}
17321  
17322 -       return pid;
17323 +#ifdef __alpha__
17324 +
17325 +/*
17326 + * The Alpha uses getxpid, getxuid, and getxgid instead.
17327 + */
17328 +
17329 +asmlinkage long do_getxpid(long *ppid)
17330 +{
17331 +       *ppid = sys_getppid();
17332 +       return sys_getpid();
17333  }
17334  
17335 +#else /* _alpha_ */
17336 +
17337  SYSCALL_DEFINE0(getuid)
17338  {
17339         /* Only we change this so SMP safe */
17340 diff -NurpP --minimal linux-2.6.32.1/kernel/user.c linux-2.6.32.1-vs2.3.0.36.27/kernel/user.c
17341 --- linux-2.6.32.1/kernel/user.c        2009-12-03 20:02:58.000000000 +0100
17342 +++ linux-2.6.32.1-vs2.3.0.36.27/kernel/user.c  2009-12-03 20:04:56.000000000 +0100
17343 @@ -251,10 +251,10 @@ static struct kobj_type uids_ktype = {
17344   *
17345   * See Documentation/scheduler/sched-design-CFS.txt for ramifications.
17346   */
17347 -static int uids_user_create(struct user_struct *up)
17348 +static int uids_user_create(struct user_namespace *ns, struct user_struct *up)
17349  {
17350         struct kobject *kobj = &up->kobj;
17351 -       int error;
17352 +       int error = 0;
17353  
17354         memset(kobj, 0, sizeof(struct kobject));
17355         if (up->user_ns != &init_user_ns)
17356 @@ -282,7 +282,7 @@ int __init uids_sysfs_init(void)
17357         if (!uids_kset)
17358                 return -ENOMEM;
17359  
17360 -       return uids_user_create(&root_user);
17361 +       return uids_user_create(NULL, &root_user);
17362  }
17363  
17364  /* delayed work function to remove sysfs directory for a user and free up
17365 @@ -353,7 +353,8 @@ static struct user_struct *uid_hash_find
17366  }
17367  
17368  int uids_sysfs_init(void) { return 0; }
17369 -static inline int uids_user_create(struct user_struct *up) { return 0; }
17370 +static inline int uids_user_create(struct user_namespace *ns,
17371 +       struct user_struct *up) { return 0; }
17372  static inline void uids_mutex_lock(void) { }
17373  static inline void uids_mutex_unlock(void) { }
17374  
17375 @@ -450,7 +451,7 @@ struct user_struct *alloc_uid(struct use
17376  
17377                 new->user_ns = get_user_ns(ns);
17378  
17379 -               if (uids_user_create(new))
17380 +               if (uids_user_create(ns, new))
17381                         goto out_destoy_sched;
17382  
17383                 /*
17384 diff -NurpP --minimal linux-2.6.32.1/kernel/user_namespace.c linux-2.6.32.1-vs2.3.0.36.27/kernel/user_namespace.c
17385 --- linux-2.6.32.1/kernel/user_namespace.c      2009-03-24 14:22:45.000000000 +0100
17386 +++ linux-2.6.32.1-vs2.3.0.36.27/kernel/user_namespace.c        2009-12-03 20:04:56.000000000 +0100
17387 @@ -10,6 +10,7 @@
17388  #include <linux/slab.h>
17389  #include <linux/user_namespace.h>
17390  #include <linux/cred.h>
17391 +#include <linux/vserver/global.h>
17392  
17393  /*
17394   * Create a new user namespace, deriving the creator from the user in the
17395 @@ -30,6 +31,7 @@ int create_user_ns(struct cred *new)
17396                 return -ENOMEM;
17397  
17398         kref_init(&ns->kref);
17399 +       atomic_inc(&vs_global_user_ns);
17400  
17401         for (n = 0; n < UIDHASH_SZ; ++n)
17402                 INIT_HLIST_HEAD(ns->uidhash_table + n);
17403 @@ -78,6 +80,8 @@ void free_user_ns(struct kref *kref)
17404         struct user_namespace *ns =
17405                 container_of(kref, struct user_namespace, kref);
17406  
17407 +       /* FIXME: maybe move into destroyer? */
17408 +       atomic_dec(&vs_global_user_ns);
17409         INIT_WORK(&ns->destroyer, free_user_ns_work);
17410         schedule_work(&ns->destroyer);
17411  }
17412 diff -NurpP --minimal linux-2.6.32.1/kernel/utsname.c linux-2.6.32.1-vs2.3.0.36.27/kernel/utsname.c
17413 --- linux-2.6.32.1/kernel/utsname.c     2009-09-10 15:26:28.000000000 +0200
17414 +++ linux-2.6.32.1-vs2.3.0.36.27/kernel/utsname.c       2009-12-03 20:04:56.000000000 +0100
17415 @@ -14,14 +14,17 @@
17416  #include <linux/utsname.h>
17417  #include <linux/err.h>
17418  #include <linux/slab.h>
17419 +#include <linux/vserver/global.h>
17420  
17421  static struct uts_namespace *create_uts_ns(void)
17422  {
17423         struct uts_namespace *uts_ns;
17424  
17425         uts_ns = kmalloc(sizeof(struct uts_namespace), GFP_KERNEL);
17426 -       if (uts_ns)
17427 +       if (uts_ns) {
17428                 kref_init(&uts_ns->kref);
17429 +               atomic_inc(&vs_global_uts_ns);
17430 +       }
17431         return uts_ns;
17432  }
17433  
17434 @@ -71,5 +74,6 @@ void free_uts_ns(struct kref *kref)
17435         struct uts_namespace *ns;
17436  
17437         ns = container_of(kref, struct uts_namespace, kref);
17438 +       atomic_dec(&vs_global_uts_ns);
17439         kfree(ns);
17440  }
17441 diff -NurpP --minimal linux-2.6.32.1/kernel/vserver/cacct.c linux-2.6.32.1-vs2.3.0.36.27/kernel/vserver/cacct.c
17442 --- linux-2.6.32.1/kernel/vserver/cacct.c       1970-01-01 01:00:00.000000000 +0100
17443 +++ linux-2.6.32.1-vs2.3.0.36.27/kernel/vserver/cacct.c 2009-12-03 20:04:56.000000000 +0100
17444 @@ -0,0 +1,42 @@
17445 +/*
17446 + *  linux/kernel/vserver/cacct.c
17447 + *
17448 + *  Virtual Server: Context Accounting
17449 + *
17450 + *  Copyright (C) 2006-2007 Herbert Pötzl
17451 + *
17452 + *  V0.01  added accounting stats
17453 + *
17454 + */
17455 +
17456 +#include <linux/types.h>
17457 +#include <linux/vs_context.h>
17458 +#include <linux/vserver/cacct_cmd.h>
17459 +#include <linux/vserver/cacct_int.h>
17460 +
17461 +#include <asm/errno.h>
17462 +#include <asm/uaccess.h>
17463 +
17464 +
17465 +int vc_sock_stat(struct vx_info *vxi, void __user *data)
17466 +{
17467 +       struct vcmd_sock_stat_v0 vc_data;
17468 +       int j, field;
17469 +
17470 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
17471 +               return -EFAULT;
17472 +
17473 +       field = vc_data.field;
17474 +       if ((field < 0) || (field >= VXA_SOCK_SIZE))
17475 +               return -EINVAL;
17476 +
17477 +       for (j = 0; j < 3; j++) {
17478 +               vc_data.count[j] = vx_sock_count(&vxi->cacct, field, j);
17479 +               vc_data.total[j] = vx_sock_total(&vxi->cacct, field, j);
17480 +       }
17481 +
17482 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
17483 +               return -EFAULT;
17484 +       return 0;
17485 +}
17486 +
17487 diff -NurpP --minimal linux-2.6.32.1/kernel/vserver/cacct_init.h linux-2.6.32.1-vs2.3.0.36.27/kernel/vserver/cacct_init.h
17488 --- linux-2.6.32.1/kernel/vserver/cacct_init.h  1970-01-01 01:00:00.000000000 +0100
17489 +++ linux-2.6.32.1-vs2.3.0.36.27/kernel/vserver/cacct_init.h    2009-12-03 20:04:56.000000000 +0100
17490 @@ -0,0 +1,25 @@
17491 +
17492 +
17493 +static inline void vx_info_init_cacct(struct _vx_cacct *cacct)
17494 +{
17495 +       int i, j;
17496 +
17497 +
17498 +       for (i = 0; i < VXA_SOCK_SIZE; i++) {
17499 +               for (j = 0; j < 3; j++) {
17500 +                       atomic_long_set(&cacct->sock[i][j].count, 0);
17501 +                       atomic_long_set(&cacct->sock[i][j].total, 0);
17502 +               }
17503 +       }
17504 +       for (i = 0; i < 8; i++)
17505 +               atomic_set(&cacct->slab[i], 0);
17506 +       for (i = 0; i < 5; i++)
17507 +               for (j = 0; j < 4; j++)
17508 +                       atomic_set(&cacct->page[i][j], 0);
17509 +}
17510 +
17511 +static inline void vx_info_exit_cacct(struct _vx_cacct *cacct)
17512 +{
17513 +       return;
17514 +}
17515 +
17516 diff -NurpP --minimal linux-2.6.32.1/kernel/vserver/cacct_proc.h linux-2.6.32.1-vs2.3.0.36.27/kernel/vserver/cacct_proc.h
17517 --- linux-2.6.32.1/kernel/vserver/cacct_proc.h  1970-01-01 01:00:00.000000000 +0100
17518 +++ linux-2.6.32.1-vs2.3.0.36.27/kernel/vserver/cacct_proc.h    2009-12-03 20:04:56.000000000 +0100
17519 @@ -0,0 +1,53 @@
17520 +#ifndef _VX_CACCT_PROC_H
17521 +#define _VX_CACCT_PROC_H
17522 +
17523 +#include <linux/vserver/cacct_int.h>
17524 +
17525 +
17526 +#define VX_SOCKA_TOP   \
17527 +       "Type\t    recv #/bytes\t\t   send #/bytes\t\t    fail #/bytes\n"
17528 +
17529 +static inline int vx_info_proc_cacct(struct _vx_cacct *cacct, char *buffer)
17530 +{
17531 +       int i, j, length = 0;
17532 +       static char *type[VXA_SOCK_SIZE] = {
17533 +               "UNSPEC", "UNIX", "INET", "INET6", "PACKET", "OTHER"
17534 +       };
17535 +
17536 +       length += sprintf(buffer + length, VX_SOCKA_TOP);
17537 +       for (i = 0; i < VXA_SOCK_SIZE; i++) {
17538 +               length += sprintf(buffer + length, "%s:", type[i]);
17539 +               for (j = 0; j < 3; j++) {
17540 +                       length += sprintf(buffer + length,
17541 +                               "\t%10lu/%-10lu",
17542 +                               vx_sock_count(cacct, i, j),
17543 +                               vx_sock_total(cacct, i, j));
17544 +               }
17545 +               buffer[length++] = '\n';
17546 +       }
17547 +
17548 +       length += sprintf(buffer + length, "\n");
17549 +       length += sprintf(buffer + length,
17550 +               "slab:\t %8u %8u %8u %8u\n",
17551 +               atomic_read(&cacct->slab[1]),
17552 +               atomic_read(&cacct->slab[4]),
17553 +               atomic_read(&cacct->slab[0]),
17554 +               atomic_read(&cacct->slab[2]));
17555 +
17556 +       length += sprintf(buffer + length, "\n");
17557 +       for (i = 0; i < 5; i++) {
17558 +               length += sprintf(buffer + length,
17559 +                       "page[%d]: %8u %8u %8u %8u\t %8u %8u %8u %8u\n", i,
17560 +                       atomic_read(&cacct->page[i][0]),
17561 +                       atomic_read(&cacct->page[i][1]),
17562 +                       atomic_read(&cacct->page[i][2]),
17563 +                       atomic_read(&cacct->page[i][3]),
17564 +                       atomic_read(&cacct->page[i][4]),
17565 +                       atomic_read(&cacct->page[i][5]),
17566 +                       atomic_read(&cacct->page[i][6]),
17567 +                       atomic_read(&cacct->page[i][7]));
17568 +       }
17569 +       return length;
17570 +}
17571 +
17572 +#endif /* _VX_CACCT_PROC_H */
17573 diff -NurpP --minimal linux-2.6.32.1/kernel/vserver/context.c linux-2.6.32.1-vs2.3.0.36.27/kernel/vserver/context.c
17574 --- linux-2.6.32.1/kernel/vserver/context.c     1970-01-01 01:00:00.000000000 +0100
17575 +++ linux-2.6.32.1-vs2.3.0.36.27/kernel/vserver/context.c       2009-12-03 20:04:56.000000000 +0100
17576 @@ -0,0 +1,1057 @@
17577 +/*
17578 + *  linux/kernel/vserver/context.c
17579 + *
17580 + *  Virtual Server: Context Support
17581 + *
17582 + *  Copyright (C) 2003-2007  Herbert Pötzl
17583 + *
17584 + *  V0.01  context helper
17585 + *  V0.02  vx_ctx_kill syscall command
17586 + *  V0.03  replaced context_info calls
17587 + *  V0.04  redesign of struct (de)alloc
17588 + *  V0.05  rlimit basic implementation
17589 + *  V0.06  task_xid and info commands
17590 + *  V0.07  context flags and caps
17591 + *  V0.08  switch to RCU based hash
17592 + *  V0.09  revert to non RCU for now
17593 + *  V0.10  and back to working RCU hash
17594 + *  V0.11  and back to locking again
17595 + *  V0.12  referenced context store
17596 + *  V0.13  separate per cpu data
17597 + *  V0.14  changed vcmds to vxi arg
17598 + *  V0.15  added context stat
17599 + *  V0.16  have __create claim() the vxi
17600 + *  V0.17  removed older and legacy stuff
17601 + *
17602 + */
17603 +
17604 +#include <linux/slab.h>
17605 +#include <linux/types.h>
17606 +#include <linux/security.h>
17607 +#include <linux/pid_namespace.h>
17608 +
17609 +#include <linux/vserver/context.h>
17610 +#include <linux/vserver/network.h>
17611 +#include <linux/vserver/debug.h>
17612 +#include <linux/vserver/limit.h>
17613 +#include <linux/vserver/limit_int.h>
17614 +#include <linux/vserver/space.h>
17615 +#include <linux/init_task.h>
17616 +#include <linux/fs_struct.h>
17617 +
17618 +#include <linux/vs_context.h>
17619 +#include <linux/vs_limit.h>
17620 +#include <linux/vs_pid.h>
17621 +#include <linux/vserver/context_cmd.h>
17622 +
17623 +#include "cvirt_init.h"
17624 +#include "cacct_init.h"
17625 +#include "limit_init.h"
17626 +#include "sched_init.h"
17627 +
17628 +
17629 +atomic_t vx_global_ctotal      = ATOMIC_INIT(0);
17630 +atomic_t vx_global_cactive     = ATOMIC_INIT(0);
17631 +
17632 +
17633 +/*     now inactive context structures */
17634 +
17635 +static struct hlist_head vx_info_inactive = HLIST_HEAD_INIT;
17636 +
17637 +static spinlock_t vx_info_inactive_lock = SPIN_LOCK_UNLOCKED;
17638 +
17639 +
17640 +/*     __alloc_vx_info()
17641 +
17642 +       * allocate an initialized vx_info struct
17643 +       * doesn't make it visible (hash)                        */
17644 +
17645 +static struct vx_info *__alloc_vx_info(xid_t xid)
17646 +{
17647 +       struct vx_info *new = NULL;
17648 +       int cpu, index;
17649 +
17650 +       vxdprintk(VXD_CBIT(xid, 0), "alloc_vx_info(%d)*", xid);
17651 +
17652 +       /* would this benefit from a slab cache? */
17653 +       new = kmalloc(sizeof(struct vx_info), GFP_KERNEL);
17654 +       if (!new)
17655 +               return 0;
17656 +
17657 +       memset(new, 0, sizeof(struct vx_info));
17658 +#ifdef CONFIG_SMP
17659 +       new->ptr_pc = alloc_percpu(struct _vx_info_pc);
17660 +       if (!new->ptr_pc)
17661 +               goto error;
17662 +#endif
17663 +       new->vx_id = xid;
17664 +       INIT_HLIST_NODE(&new->vx_hlist);
17665 +       atomic_set(&new->vx_usecnt, 0);
17666 +       atomic_set(&new->vx_tasks, 0);
17667 +       new->vx_parent = NULL;
17668 +       new->vx_state = 0;
17669 +       init_waitqueue_head(&new->vx_wait);
17670 +
17671 +       /* prepare reaper */
17672 +       get_task_struct(init_pid_ns.child_reaper);
17673 +       new->vx_reaper = init_pid_ns.child_reaper;
17674 +       new->vx_badness_bias = 0;
17675 +
17676 +       /* rest of init goes here */
17677 +       vx_info_init_limit(&new->limit);
17678 +       vx_info_init_sched(&new->sched);
17679 +       vx_info_init_cvirt(&new->cvirt);
17680 +       vx_info_init_cacct(&new->cacct);
17681 +
17682 +       /* per cpu data structures */
17683 +       for_each_possible_cpu(cpu) {
17684 +               vx_info_init_sched_pc(
17685 +                       &vx_per_cpu(new, sched_pc, cpu), cpu);
17686 +               vx_info_init_cvirt_pc(
17687 +                       &vx_per_cpu(new, cvirt_pc, cpu), cpu);
17688 +       }
17689 +
17690 +       new->vx_flags = VXF_INIT_SET;
17691 +       cap_set_init_eff(new->vx_bcaps);
17692 +       new->vx_ccaps = 0;
17693 +       new->vx_umask = 0;
17694 +
17695 +       new->reboot_cmd = 0;
17696 +       new->exit_code = 0;
17697 +
17698 +       // preconfig fs entries
17699 +       for (index = 0; index < VX_SPACES; index++) {
17700 +               write_lock(&init_fs.lock);
17701 +               init_fs.users++;
17702 +               write_unlock(&init_fs.lock);
17703 +               new->vx_fs[index] = &init_fs;
17704 +       }
17705 +
17706 +       vxdprintk(VXD_CBIT(xid, 0),
17707 +               "alloc_vx_info(%d) = %p", xid, new);
17708 +       vxh_alloc_vx_info(new);
17709 +       atomic_inc(&vx_global_ctotal);
17710 +       return new;
17711 +#ifdef CONFIG_SMP
17712 +error:
17713 +       kfree(new);
17714 +       return 0;
17715 +#endif
17716 +}
17717 +
17718 +/*     __dealloc_vx_info()
17719 +
17720 +       * final disposal of vx_info                             */
17721 +
17722 +static void __dealloc_vx_info(struct vx_info *vxi)
17723 +{
17724 +       struct vx_info_save vxis;
17725 +       int cpu;
17726 +
17727 +       vxdprintk(VXD_CBIT(xid, 0),
17728 +               "dealloc_vx_info(%p)", vxi);
17729 +       vxh_dealloc_vx_info(vxi);
17730 +
17731 +#ifdef CONFIG_VSERVER_WARN
17732 +       enter_vx_info(vxi, &vxis);
17733 +       vx_info_exit_limit(&vxi->limit);
17734 +       vx_info_exit_sched(&vxi->sched);
17735 +       vx_info_exit_cvirt(&vxi->cvirt);
17736 +       vx_info_exit_cacct(&vxi->cacct);
17737 +
17738 +       for_each_possible_cpu(cpu) {
17739 +               vx_info_exit_sched_pc(
17740 +                       &vx_per_cpu(vxi, sched_pc, cpu), cpu);
17741 +               vx_info_exit_cvirt_pc(
17742 +                       &vx_per_cpu(vxi, cvirt_pc, cpu), cpu);
17743 +       }
17744 +       leave_vx_info(&vxis);
17745 +#endif
17746 +
17747 +       vxi->vx_id = -1;
17748 +       vxi->vx_state |= VXS_RELEASED;
17749 +
17750 +#ifdef CONFIG_SMP
17751 +       free_percpu(vxi->ptr_pc);
17752 +#endif
17753 +       kfree(vxi);
17754 +       atomic_dec(&vx_global_ctotal);
17755 +}
17756 +
17757 +static void __shutdown_vx_info(struct vx_info *vxi)
17758 +{
17759 +       struct nsproxy *nsproxy;
17760 +       struct fs_struct *fs;
17761 +       int index, kill;
17762 +
17763 +       might_sleep();
17764 +
17765 +       vxi->vx_state |= VXS_SHUTDOWN;
17766 +       vs_state_change(vxi, VSC_SHUTDOWN);
17767 +
17768 +       for (index = 0; index < VX_SPACES; index++) {
17769 +               nsproxy = xchg(&vxi->vx_nsproxy[index], NULL);
17770 +               if (nsproxy)
17771 +                       put_nsproxy(nsproxy);
17772 +
17773 +               fs = xchg(&vxi->vx_fs[index], NULL);
17774 +               write_lock(&fs->lock);
17775 +               kill = !--fs->users;
17776 +               write_unlock(&fs->lock);
17777 +               if (kill)
17778 +                       free_fs_struct(fs);
17779 +       }
17780 +}
17781 +
17782 +/* exported stuff */
17783 +
17784 +void free_vx_info(struct vx_info *vxi)
17785 +{
17786 +       unsigned long flags;
17787 +       unsigned index;
17788 +
17789 +       /* check for reference counts first */
17790 +       BUG_ON(atomic_read(&vxi->vx_usecnt));
17791 +       BUG_ON(atomic_read(&vxi->vx_tasks));
17792 +
17793 +       /* context must not be hashed */
17794 +       BUG_ON(vx_info_state(vxi, VXS_HASHED));
17795 +
17796 +       /* context shutdown is mandatory */
17797 +       BUG_ON(!vx_info_state(vxi, VXS_SHUTDOWN));
17798 +
17799 +       /* nsproxy and fs check */
17800 +       for (index = 0; index < VX_SPACES; index++) {
17801 +               BUG_ON(vxi->vx_nsproxy[index]);
17802 +               BUG_ON(vxi->vx_fs[index]);
17803 +       }
17804 +
17805 +       spin_lock_irqsave(&vx_info_inactive_lock, flags);
17806 +       hlist_del(&vxi->vx_hlist);
17807 +       spin_unlock_irqrestore(&vx_info_inactive_lock, flags);
17808 +
17809 +       __dealloc_vx_info(vxi);
17810 +}
17811 +
17812 +
17813 +/*     hash table for vx_info hash */
17814 +
17815 +#define VX_HASH_SIZE   13
17816 +
17817 +static struct hlist_head vx_info_hash[VX_HASH_SIZE] =
17818 +       { [0 ... VX_HASH_SIZE-1] = HLIST_HEAD_INIT };
17819 +
17820 +static spinlock_t vx_info_hash_lock = SPIN_LOCK_UNLOCKED;
17821 +
17822 +
17823 +static inline unsigned int __hashval(xid_t xid)
17824 +{
17825 +       return (xid % VX_HASH_SIZE);
17826 +}
17827 +
17828 +
17829 +
17830 +/*     __hash_vx_info()
17831 +
17832 +       * add the vxi to the global hash table
17833 +       * requires the hash_lock to be held                     */
17834 +
17835 +static inline void __hash_vx_info(struct vx_info *vxi)
17836 +{
17837 +       struct hlist_head *head;
17838 +
17839 +       vxd_assert_lock(&vx_info_hash_lock);
17840 +       vxdprintk(VXD_CBIT(xid, 4),
17841 +               "__hash_vx_info: %p[#%d]", vxi, vxi->vx_id);
17842 +       vxh_hash_vx_info(vxi);
17843 +
17844 +       /* context must not be hashed */
17845 +       BUG_ON(vx_info_state(vxi, VXS_HASHED));
17846 +
17847 +       vxi->vx_state |= VXS_HASHED;
17848 +       head = &vx_info_hash[__hashval(vxi->vx_id)];
17849 +       hlist_add_head(&vxi->vx_hlist, head);
17850 +       atomic_inc(&vx_global_cactive);
17851 +}
17852 +
17853 +/*     __unhash_vx_info()
17854 +
17855 +       * remove the vxi from the global hash table
17856 +       * requires the hash_lock to be held                     */
17857 +
17858 +static inline void __unhash_vx_info(struct vx_info *vxi)
17859 +{
17860 +       unsigned long flags;
17861 +
17862 +       vxd_assert_lock(&vx_info_hash_lock);
17863 +       vxdprintk(VXD_CBIT(xid, 4),
17864 +               "__unhash_vx_info: %p[#%d.%d.%d]", vxi, vxi->vx_id,
17865 +               atomic_read(&vxi->vx_usecnt), atomic_read(&vxi->vx_tasks));
17866 +       vxh_unhash_vx_info(vxi);
17867 +
17868 +       /* context must be hashed */
17869 +       BUG_ON(!vx_info_state(vxi, VXS_HASHED));
17870 +       /* but without tasks */
17871 +       BUG_ON(atomic_read(&vxi->vx_tasks));
17872 +
17873 +       vxi->vx_state &= ~VXS_HASHED;
17874 +       hlist_del_init(&vxi->vx_hlist);
17875 +       spin_lock_irqsave(&vx_info_inactive_lock, flags);
17876 +       hlist_add_head(&vxi->vx_hlist, &vx_info_inactive);
17877 +       spin_unlock_irqrestore(&vx_info_inactive_lock, flags);
17878 +       atomic_dec(&vx_global_cactive);
17879 +}
17880 +
17881 +
17882 +/*     __lookup_vx_info()
17883 +
17884 +       * requires the hash_lock to be held
17885 +       * doesn't increment the vx_refcnt                       */
17886 +
17887 +static inline struct vx_info *__lookup_vx_info(xid_t xid)
17888 +{
17889 +       struct hlist_head *head = &vx_info_hash[__hashval(xid)];
17890 +       struct hlist_node *pos;
17891 +       struct vx_info *vxi;
17892 +
17893 +       vxd_assert_lock(&vx_info_hash_lock);
17894 +       hlist_for_each(pos, head) {
17895 +               vxi = hlist_entry(pos, struct vx_info, vx_hlist);
17896 +
17897 +               if (vxi->vx_id == xid)
17898 +                       goto found;
17899 +       }
17900 +       vxi = NULL;
17901 +found:
17902 +       vxdprintk(VXD_CBIT(xid, 0),
17903 +               "__lookup_vx_info(#%u): %p[#%u]",
17904 +               xid, vxi, vxi ? vxi->vx_id : 0);
17905 +       vxh_lookup_vx_info(vxi, xid);
17906 +       return vxi;
17907 +}
17908 +
17909 +
17910 +/*     __create_vx_info()
17911 +
17912 +       * create the requested context
17913 +       * get(), claim() and hash it                            */
17914 +
17915 +static struct vx_info *__create_vx_info(int id)
17916 +{
17917 +       struct vx_info *new, *vxi = NULL;
17918 +
17919 +       vxdprintk(VXD_CBIT(xid, 1), "create_vx_info(%d)*", id);
17920 +
17921 +       if (!(new = __alloc_vx_info(id)))
17922 +               return ERR_PTR(-ENOMEM);
17923 +
17924 +       /* required to make dynamic xids unique */
17925 +       spin_lock(&vx_info_hash_lock);
17926 +
17927 +       /* static context requested */
17928 +       if ((vxi = __lookup_vx_info(id))) {
17929 +               vxdprintk(VXD_CBIT(xid, 0),
17930 +                       "create_vx_info(%d) = %p (already there)", id, vxi);
17931 +               if (vx_info_flags(vxi, VXF_STATE_SETUP, 0))
17932 +                       vxi = ERR_PTR(-EBUSY);
17933 +               else
17934 +                       vxi = ERR_PTR(-EEXIST);
17935 +               goto out_unlock;
17936 +       }
17937 +       /* new context */
17938 +       vxdprintk(VXD_CBIT(xid, 0),
17939 +               "create_vx_info(%d) = %p (new)", id, new);
17940 +       claim_vx_info(new, NULL);
17941 +       __hash_vx_info(get_vx_info(new));
17942 +       vxi = new, new = NULL;
17943 +
17944 +out_unlock:
17945 +       spin_unlock(&vx_info_hash_lock);
17946 +       vxh_create_vx_info(IS_ERR(vxi) ? NULL : vxi, id);
17947 +       if (new)
17948 +               __dealloc_vx_info(new);
17949 +       return vxi;
17950 +}
17951 +
17952 +
17953 +/*     exported stuff                                          */
17954 +
17955 +
17956 +void unhash_vx_info(struct vx_info *vxi)
17957 +{
17958 +       __shutdown_vx_info(vxi);
17959 +       spin_lock(&vx_info_hash_lock);
17960 +       __unhash_vx_info(vxi);
17961 +       spin_unlock(&vx_info_hash_lock);
17962 +       __wakeup_vx_info(vxi);
17963 +}
17964 +
17965 +
17966 +/*     lookup_vx_info()
17967 +
17968 +       * search for a vx_info and get() it
17969 +       * negative id means current                             */
17970 +
17971 +struct vx_info *lookup_vx_info(int id)
17972 +{
17973 +       struct vx_info *vxi = NULL;
17974 +
17975 +       if (id < 0) {
17976 +               vxi = get_vx_info(current_vx_info());
17977 +       } else if (id > 1) {
17978 +               spin_lock(&vx_info_hash_lock);
17979 +               vxi = get_vx_info(__lookup_vx_info(id));
17980 +               spin_unlock(&vx_info_hash_lock);
17981 +       }
17982 +       return vxi;
17983 +}
17984 +
17985 +/*     xid_is_hashed()
17986 +
17987 +       * verify that xid is still hashed                       */
17988 +
17989 +int xid_is_hashed(xid_t xid)
17990 +{
17991 +       int hashed;
17992 +
17993 +       spin_lock(&vx_info_hash_lock);
17994 +       hashed = (__lookup_vx_info(xid) != NULL);
17995 +       spin_unlock(&vx_info_hash_lock);
17996 +       return hashed;
17997 +}
17998 +
17999 +#ifdef CONFIG_PROC_FS
18000 +
18001 +/*     get_xid_list()
18002 +
18003 +       * get a subset of hashed xids for proc
18004 +       * assumes size is at least one                          */
18005 +
18006 +int get_xid_list(int index, unsigned int *xids, int size)
18007 +{
18008 +       int hindex, nr_xids = 0;
18009 +
18010 +       /* only show current and children */
18011 +       if (!vx_check(0, VS_ADMIN | VS_WATCH)) {
18012 +               if (index > 0)
18013 +                       return 0;
18014 +               xids[nr_xids] = vx_current_xid();
18015 +               return 1;
18016 +       }
18017 +
18018 +       for (hindex = 0; hindex < VX_HASH_SIZE; hindex++) {
18019 +               struct hlist_head *head = &vx_info_hash[hindex];
18020 +               struct hlist_node *pos;
18021 +
18022 +               spin_lock(&vx_info_hash_lock);
18023 +               hlist_for_each(pos, head) {
18024 +                       struct vx_info *vxi;
18025 +
18026 +                       if (--index > 0)
18027 +                               continue;
18028 +
18029 +                       vxi = hlist_entry(pos, struct vx_info, vx_hlist);
18030 +                       xids[nr_xids] = vxi->vx_id;
18031 +                       if (++nr_xids >= size) {
18032 +                               spin_unlock(&vx_info_hash_lock);
18033 +                               goto out;
18034 +                       }
18035 +               }
18036 +               /* keep the lock time short */
18037 +               spin_unlock(&vx_info_hash_lock);
18038 +       }
18039 +out:
18040 +       return nr_xids;
18041 +}
18042 +#endif
18043 +
18044 +#ifdef CONFIG_VSERVER_DEBUG
18045 +
18046 +void   dump_vx_info_inactive(int level)
18047 +{
18048 +       struct hlist_node *entry, *next;
18049 +
18050 +       hlist_for_each_safe(entry, next, &vx_info_inactive) {
18051 +               struct vx_info *vxi =
18052 +                       list_entry(entry, struct vx_info, vx_hlist);
18053 +
18054 +               dump_vx_info(vxi, level);
18055 +       }
18056 +}
18057 +
18058 +#endif
18059 +
18060 +#if 0
18061 +int vx_migrate_user(struct task_struct *p, struct vx_info *vxi)
18062 +{
18063 +       struct user_struct *new_user, *old_user;
18064 +
18065 +       if (!p || !vxi)
18066 +               BUG();
18067 +
18068 +       if (vx_info_flags(vxi, VXF_INFO_PRIVATE, 0))
18069 +               return -EACCES;
18070 +
18071 +       new_user = alloc_uid(vxi->vx_id, p->uid);
18072 +       if (!new_user)
18073 +               return -ENOMEM;
18074 +
18075 +       old_user = p->user;
18076 +       if (new_user != old_user) {
18077 +               atomic_inc(&new_user->processes);
18078 +               atomic_dec(&old_user->processes);
18079 +               p->user = new_user;
18080 +       }
18081 +       free_uid(old_user);
18082 +       return 0;
18083 +}
18084 +#endif
18085 +
18086 +#if 0
18087 +void vx_mask_cap_bset(struct vx_info *vxi, struct task_struct *p)
18088 +{
18089 +       // p->cap_effective &= vxi->vx_cap_bset;
18090 +       p->cap_effective =
18091 +               cap_intersect(p->cap_effective, vxi->cap_bset);
18092 +       // p->cap_inheritable &= vxi->vx_cap_bset;
18093 +       p->cap_inheritable =
18094 +               cap_intersect(p->cap_inheritable, vxi->cap_bset);
18095 +       // p->cap_permitted &= vxi->vx_cap_bset;
18096 +       p->cap_permitted =
18097 +               cap_intersect(p->cap_permitted, vxi->cap_bset);
18098 +}
18099 +#endif
18100 +
18101 +
18102 +#include <linux/file.h>
18103 +#include <linux/fdtable.h>
18104 +
18105 +static int vx_openfd_task(struct task_struct *tsk)
18106 +{
18107 +       struct files_struct *files = tsk->files;
18108 +       struct fdtable *fdt;
18109 +       const unsigned long *bptr;
18110 +       int count, total;
18111 +
18112 +       /* no rcu_read_lock() because of spin_lock() */
18113 +       spin_lock(&files->file_lock);
18114 +       fdt = files_fdtable(files);
18115 +       bptr = fdt->open_fds->fds_bits;
18116 +       count = fdt->max_fds / (sizeof(unsigned long) * 8);
18117 +       for (total = 0; count > 0; count--) {
18118 +               if (*bptr)
18119 +                       total += hweight_long(*bptr);
18120 +               bptr++;
18121 +       }
18122 +       spin_unlock(&files->file_lock);
18123 +       return total;
18124 +}
18125 +
18126 +
18127 +/*     for *space compatibility */
18128 +
18129 +asmlinkage long sys_unshare(unsigned long);
18130 +
18131 +/*
18132 + *     migrate task to new context
18133 + *     gets vxi, puts old_vxi on change
18134 + *     optionally unshares namespaces (hack)
18135 + */
18136 +
18137 +int vx_migrate_task(struct task_struct *p, struct vx_info *vxi, int unshare)
18138 +{
18139 +       struct vx_info *old_vxi;
18140 +       int ret = 0;
18141 +
18142 +       if (!p || !vxi)
18143 +               BUG();
18144 +
18145 +       vxdprintk(VXD_CBIT(xid, 5),
18146 +               "vx_migrate_task(%p,%p[#%d.%d])", p, vxi,
18147 +               vxi->vx_id, atomic_read(&vxi->vx_usecnt));
18148 +
18149 +       if (vx_info_flags(vxi, VXF_INFO_PRIVATE, 0) &&
18150 +               !vx_info_flags(vxi, VXF_STATE_SETUP, 0))
18151 +               return -EACCES;
18152 +
18153 +       if (vx_info_state(vxi, VXS_SHUTDOWN))
18154 +               return -EFAULT;
18155 +
18156 +       old_vxi = task_get_vx_info(p);
18157 +       if (old_vxi == vxi)
18158 +               goto out;
18159 +
18160 +//     if (!(ret = vx_migrate_user(p, vxi))) {
18161 +       {
18162 +               int openfd;
18163 +
18164 +               task_lock(p);
18165 +               openfd = vx_openfd_task(p);
18166 +
18167 +               if (old_vxi) {
18168 +                       atomic_dec(&old_vxi->cvirt.nr_threads);
18169 +                       atomic_dec(&old_vxi->cvirt.nr_running);
18170 +                       __rlim_dec(&old_vxi->limit, RLIMIT_NPROC);
18171 +                       /* FIXME: what about the struct files here? */
18172 +                       __rlim_sub(&old_vxi->limit, VLIMIT_OPENFD, openfd);
18173 +                       /* account for the executable */
18174 +                       __rlim_dec(&old_vxi->limit, VLIMIT_DENTRY);
18175 +               }
18176 +               atomic_inc(&vxi->cvirt.nr_threads);
18177 +               atomic_inc(&vxi->cvirt.nr_running);
18178 +               __rlim_inc(&vxi->limit, RLIMIT_NPROC);
18179 +               /* FIXME: what about the struct files here? */
18180 +               __rlim_add(&vxi->limit, VLIMIT_OPENFD, openfd);
18181 +               /* account for the executable */
18182 +               __rlim_inc(&vxi->limit, VLIMIT_DENTRY);
18183 +
18184 +               if (old_vxi) {
18185 +                       release_vx_info(old_vxi, p);
18186 +                       clr_vx_info(&p->vx_info);
18187 +               }
18188 +               claim_vx_info(vxi, p);
18189 +               set_vx_info(&p->vx_info, vxi);
18190 +               p->xid = vxi->vx_id;
18191 +
18192 +               vxdprintk(VXD_CBIT(xid, 5),
18193 +                       "moved task %p into vxi:%p[#%d]",
18194 +                       p, vxi, vxi->vx_id);
18195 +
18196 +               // vx_mask_cap_bset(vxi, p);
18197 +               task_unlock(p);
18198 +
18199 +               /* hack for *spaces to provide compatibility */
18200 +               if (unshare) {
18201 +                       struct nsproxy *old_nsp, *new_nsp;
18202 +
18203 +                       ret = unshare_nsproxy_namespaces(
18204 +                               CLONE_NEWUTS | CLONE_NEWIPC | CLONE_NEWUSER,
18205 +                               &new_nsp, NULL);
18206 +                       if (ret)
18207 +                               goto out;
18208 +
18209 +                       old_nsp = xchg(&p->nsproxy, new_nsp);
18210 +                       vx_set_space(vxi,
18211 +                               CLONE_NEWUTS | CLONE_NEWIPC | CLONE_NEWUSER, 0);
18212 +                       put_nsproxy(old_nsp);
18213 +               }
18214 +       }
18215 +out:
18216 +       put_vx_info(old_vxi);
18217 +       return ret;
18218 +}
18219 +
18220 +int vx_set_reaper(struct vx_info *vxi, struct task_struct *p)
18221 +{
18222 +       struct task_struct *old_reaper;
18223 +
18224 +       if (!vxi)
18225 +               return -EINVAL;
18226 +
18227 +       vxdprintk(VXD_CBIT(xid, 6),
18228 +               "vx_set_reaper(%p[#%d],%p[#%d,%d])",
18229 +               vxi, vxi->vx_id, p, p->xid, p->pid);
18230 +
18231 +       old_reaper = vxi->vx_reaper;
18232 +       if (old_reaper == p)
18233 +               return 0;
18234 +
18235 +       /* set new child reaper */
18236 +       get_task_struct(p);
18237 +       vxi->vx_reaper = p;
18238 +       put_task_struct(old_reaper);
18239 +       return 0;
18240 +}
18241 +
18242 +int vx_set_init(struct vx_info *vxi, struct task_struct *p)
18243 +{
18244 +       if (!vxi)
18245 +               return -EINVAL;
18246 +
18247 +       vxdprintk(VXD_CBIT(xid, 6),
18248 +               "vx_set_init(%p[#%d],%p[#%d,%d,%d])",
18249 +               vxi, vxi->vx_id, p, p->xid, p->pid, p->tgid);
18250 +
18251 +       vxi->vx_flags &= ~VXF_STATE_INIT;
18252 +       // vxi->vx_initpid = p->tgid;
18253 +       vxi->vx_initpid = p->pid;
18254 +       return 0;
18255 +}
18256 +
18257 +void vx_exit_init(struct vx_info *vxi, struct task_struct *p, int code)
18258 +{
18259 +       vxdprintk(VXD_CBIT(xid, 6),
18260 +               "vx_exit_init(%p[#%d],%p[#%d,%d,%d])",
18261 +               vxi, vxi->vx_id, p, p->xid, p->pid, p->tgid);
18262 +
18263 +       vxi->exit_code = code;
18264 +       vxi->vx_initpid = 0;
18265 +}
18266 +
18267 +
18268 +void vx_set_persistent(struct vx_info *vxi)
18269 +{
18270 +       vxdprintk(VXD_CBIT(xid, 6),
18271 +               "vx_set_persistent(%p[#%d])", vxi, vxi->vx_id);
18272 +
18273 +       get_vx_info(vxi);
18274 +       claim_vx_info(vxi, NULL);
18275 +}
18276 +
18277 +void vx_clear_persistent(struct vx_info *vxi)
18278 +{
18279 +       vxdprintk(VXD_CBIT(xid, 6),
18280 +               "vx_clear_persistent(%p[#%d])", vxi, vxi->vx_id);
18281 +
18282 +       release_vx_info(vxi, NULL);
18283 +       put_vx_info(vxi);
18284 +}
18285 +
18286 +void vx_update_persistent(struct vx_info *vxi)
18287 +{
18288 +       if (vx_info_flags(vxi, VXF_PERSISTENT, 0))
18289 +               vx_set_persistent(vxi);
18290 +       else
18291 +               vx_clear_persistent(vxi);
18292 +}
18293 +
18294 +
18295 +/*     task must be current or locked          */
18296 +
18297 +void   exit_vx_info(struct task_struct *p, int code)
18298 +{
18299 +       struct vx_info *vxi = p->vx_info;
18300 +
18301 +       if (vxi) {
18302 +               atomic_dec(&vxi->cvirt.nr_threads);
18303 +               vx_nproc_dec(p);
18304 +
18305 +               vxi->exit_code = code;
18306 +               release_vx_info(vxi, p);
18307 +       }
18308 +}
18309 +
18310 +void   exit_vx_info_early(struct task_struct *p, int code)
18311 +{
18312 +       struct vx_info *vxi = p->vx_info;
18313 +
18314 +       if (vxi) {
18315 +               if (vxi->vx_initpid == p->pid)
18316 +                       vx_exit_init(vxi, p, code);
18317 +               if (vxi->vx_reaper == p)
18318 +                       vx_set_reaper(vxi, init_pid_ns.child_reaper);
18319 +       }
18320 +}
18321 +
18322 +
18323 +/* vserver syscall commands below here */
18324 +
18325 +/* taks xid and vx_info functions */
18326 +
18327 +#include <asm/uaccess.h>
18328 +
18329 +
18330 +int vc_task_xid(uint32_t id)
18331 +{
18332 +       xid_t xid;
18333 +
18334 +       if (id) {
18335 +               struct task_struct *tsk;
18336 +
18337 +               read_lock(&tasklist_lock);
18338 +               tsk = find_task_by_real_pid(id);
18339 +               xid = (tsk) ? tsk->xid : -ESRCH;
18340 +               read_unlock(&tasklist_lock);
18341 +       } else
18342 +               xid = vx_current_xid();
18343 +       return xid;
18344 +}
18345 +
18346 +
18347 +int vc_vx_info(struct vx_info *vxi, void __user *data)
18348 +{
18349 +       struct vcmd_vx_info_v0 vc_data;
18350 +
18351 +       vc_data.xid = vxi->vx_id;
18352 +       vc_data.initpid = vxi->vx_initpid;
18353 +
18354 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
18355 +               return -EFAULT;
18356 +       return 0;
18357 +}
18358 +
18359 +
18360 +int vc_ctx_stat(struct vx_info *vxi, void __user *data)
18361 +{
18362 +       struct vcmd_ctx_stat_v0 vc_data;
18363 +
18364 +       vc_data.usecnt = atomic_read(&vxi->vx_usecnt);
18365 +       vc_data.tasks = atomic_read(&vxi->vx_tasks);
18366 +
18367 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
18368 +               return -EFAULT;
18369 +       return 0;
18370 +}
18371 +
18372 +
18373 +/* context functions */
18374 +
18375 +int vc_ctx_create(uint32_t xid, void __user *data)
18376 +{
18377 +       struct vcmd_ctx_create vc_data = { .flagword = VXF_INIT_SET };
18378 +       struct vx_info *new_vxi;
18379 +       int ret;
18380 +
18381 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
18382 +               return -EFAULT;
18383 +
18384 +       if ((xid > MAX_S_CONTEXT) || (xid < 2))
18385 +               return -EINVAL;
18386 +
18387 +       new_vxi = __create_vx_info(xid);
18388 +       if (IS_ERR(new_vxi))
18389 +               return PTR_ERR(new_vxi);
18390 +
18391 +       /* initial flags */
18392 +       new_vxi->vx_flags = vc_data.flagword;
18393 +
18394 +       ret = -ENOEXEC;
18395 +       if (vs_state_change(new_vxi, VSC_STARTUP))
18396 +               goto out;
18397 +
18398 +       ret = vx_migrate_task(current, new_vxi, (!data));
18399 +       if (ret)
18400 +               goto out;
18401 +
18402 +       /* return context id on success */
18403 +       ret = new_vxi->vx_id;
18404 +
18405 +       /* get a reference for persistent contexts */
18406 +       if ((vc_data.flagword & VXF_PERSISTENT))
18407 +               vx_set_persistent(new_vxi);
18408 +out:
18409 +       release_vx_info(new_vxi, NULL);
18410 +       put_vx_info(new_vxi);
18411 +       return ret;
18412 +}
18413 +
18414 +
18415 +int vc_ctx_migrate(struct vx_info *vxi, void __user *data)
18416 +{
18417 +       struct vcmd_ctx_migrate vc_data = { .flagword = 0 };
18418 +       int ret;
18419 +
18420 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
18421 +               return -EFAULT;
18422 +
18423 +       ret = vx_migrate_task(current, vxi, 0);
18424 +       if (ret)
18425 +               return ret;
18426 +       if (vc_data.flagword & VXM_SET_INIT)
18427 +               ret = vx_set_init(vxi, current);
18428 +       if (ret)
18429 +               return ret;
18430 +       if (vc_data.flagword & VXM_SET_REAPER)
18431 +               ret = vx_set_reaper(vxi, current);
18432 +       return ret;
18433 +}
18434 +
18435 +
18436 +int vc_get_cflags(struct vx_info *vxi, void __user *data)
18437 +{
18438 +       struct vcmd_ctx_flags_v0 vc_data;
18439 +
18440 +       vc_data.flagword = vxi->vx_flags;
18441 +
18442 +       /* special STATE flag handling */
18443 +       vc_data.mask = vs_mask_flags(~0ULL, vxi->vx_flags, VXF_ONE_TIME);
18444 +
18445 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
18446 +               return -EFAULT;
18447 +       return 0;
18448 +}
18449 +
18450 +int vc_set_cflags(struct vx_info *vxi, void __user *data)
18451 +{
18452 +       struct vcmd_ctx_flags_v0 vc_data;
18453 +       uint64_t mask, trigger;
18454 +
18455 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18456 +               return -EFAULT;
18457 +
18458 +       /* special STATE flag handling */
18459 +       mask = vs_mask_mask(vc_data.mask, vxi->vx_flags, VXF_ONE_TIME);
18460 +       trigger = (mask & vxi->vx_flags) ^ (mask & vc_data.flagword);
18461 +
18462 +       if (vxi == current_vx_info()) {
18463 +               /* if (trigger & VXF_STATE_SETUP)
18464 +                       vx_mask_cap_bset(vxi, current); */
18465 +               if (trigger & VXF_STATE_INIT) {
18466 +                       int ret;
18467 +
18468 +                       ret = vx_set_init(vxi, current);
18469 +                       if (ret)
18470 +                               return ret;
18471 +                       ret = vx_set_reaper(vxi, current);
18472 +                       if (ret)
18473 +                               return ret;
18474 +               }
18475 +       }
18476 +
18477 +       vxi->vx_flags = vs_mask_flags(vxi->vx_flags,
18478 +               vc_data.flagword, mask);
18479 +       if (trigger & VXF_PERSISTENT)
18480 +               vx_update_persistent(vxi);
18481 +
18482 +       return 0;
18483 +}
18484 +
18485 +
18486 +static inline uint64_t caps_from_cap_t(kernel_cap_t c)
18487 +{
18488 +       uint64_t v = c.cap[0] | ((uint64_t)c.cap[1] << 32);
18489 +
18490 +       // printk("caps_from_cap_t(%08x:%08x) = %016llx\n", c.cap[1], c.cap[0], v);
18491 +       return v;
18492 +}
18493 +
18494 +static inline kernel_cap_t cap_t_from_caps(uint64_t v)
18495 +{
18496 +       kernel_cap_t c = __cap_empty_set;
18497 +
18498 +       c.cap[0] = v & 0xFFFFFFFF;
18499 +       c.cap[1] = (v >> 32) & 0xFFFFFFFF;
18500 +
18501 +       // printk("cap_t_from_caps(%016llx) = %08x:%08x\n", v, c.cap[1], c.cap[0]);
18502 +       return c;
18503 +}
18504 +
18505 +
18506 +static int do_get_caps(struct vx_info *vxi, uint64_t *bcaps, uint64_t *ccaps)
18507 +{
18508 +       if (bcaps)
18509 +               *bcaps = caps_from_cap_t(vxi->vx_bcaps);
18510 +       if (ccaps)
18511 +               *ccaps = vxi->vx_ccaps;
18512 +
18513 +       return 0;
18514 +}
18515 +
18516 +int vc_get_ccaps(struct vx_info *vxi, void __user *data)
18517 +{
18518 +       struct vcmd_ctx_caps_v1 vc_data;
18519 +       int ret;
18520 +
18521 +       ret = do_get_caps(vxi, NULL, &vc_data.ccaps);
18522 +       if (ret)
18523 +               return ret;
18524 +       vc_data.cmask = ~0ULL;
18525 +
18526 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
18527 +               return -EFAULT;
18528 +       return 0;
18529 +}
18530 +
18531 +static int do_set_caps(struct vx_info *vxi,
18532 +       uint64_t bcaps, uint64_t bmask, uint64_t ccaps, uint64_t cmask)
18533 +{
18534 +       uint64_t bcold = caps_from_cap_t(vxi->vx_bcaps);
18535 +
18536 +#if 0
18537 +       printk("do_set_caps(%16llx, %16llx, %16llx, %16llx)\n",
18538 +               bcaps, bmask, ccaps, cmask);
18539 +#endif
18540 +       vxi->vx_bcaps = cap_t_from_caps(
18541 +               vs_mask_flags(bcold, bcaps, bmask));
18542 +       vxi->vx_ccaps = vs_mask_flags(vxi->vx_ccaps, ccaps, cmask);
18543 +
18544 +       return 0;
18545 +}
18546 +
18547 +int vc_set_ccaps(struct vx_info *vxi, void __user *data)
18548 +{
18549 +       struct vcmd_ctx_caps_v1 vc_data;
18550 +
18551 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18552 +               return -EFAULT;
18553 +
18554 +       return do_set_caps(vxi, 0, 0, vc_data.ccaps, vc_data.cmask);
18555 +}
18556 +
18557 +int vc_get_bcaps(struct vx_info *vxi, void __user *data)
18558 +{
18559 +       struct vcmd_bcaps vc_data;
18560 +       int ret;
18561 +
18562 +       ret = do_get_caps(vxi, &vc_data.bcaps, NULL);
18563 +       if (ret)
18564 +               return ret;
18565 +       vc_data.bmask = ~0ULL;
18566 +
18567 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
18568 +               return -EFAULT;
18569 +       return 0;
18570 +}
18571 +
18572 +int vc_set_bcaps(struct vx_info *vxi, void __user *data)
18573 +{
18574 +       struct vcmd_bcaps vc_data;
18575 +
18576 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18577 +               return -EFAULT;
18578 +
18579 +       return do_set_caps(vxi, vc_data.bcaps, vc_data.bmask, 0, 0);
18580 +}
18581 +
18582 +
18583 +int vc_get_umask(struct vx_info *vxi, void __user *data)
18584 +{
18585 +       struct vcmd_umask vc_data;
18586 +
18587 +       vc_data.umask = vxi->vx_umask;
18588 +       vc_data.mask = ~0ULL;
18589 +
18590 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
18591 +               return -EFAULT;
18592 +       return 0;
18593 +}
18594 +
18595 +int vc_set_umask(struct vx_info *vxi, void __user *data)
18596 +{
18597 +       struct vcmd_umask vc_data;
18598 +
18599 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18600 +               return -EFAULT;
18601 +
18602 +       vxi->vx_umask = vs_mask_flags(vxi->vx_umask,
18603 +               vc_data.umask, vc_data.mask);
18604 +       return 0;
18605 +}
18606 +
18607 +
18608 +int vc_get_badness(struct vx_info *vxi, void __user *data)
18609 +{
18610 +       struct vcmd_badness_v0 vc_data;
18611 +
18612 +       vc_data.bias = vxi->vx_badness_bias;
18613 +
18614 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
18615 +               return -EFAULT;
18616 +       return 0;
18617 +}
18618 +
18619 +int vc_set_badness(struct vx_info *vxi, void __user *data)
18620 +{
18621 +       struct vcmd_badness_v0 vc_data;
18622 +
18623 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18624 +               return -EFAULT;
18625 +
18626 +       vxi->vx_badness_bias = vc_data.bias;
18627 +       return 0;
18628 +}
18629 +
18630 +#include <linux/module.h>
18631 +
18632 +EXPORT_SYMBOL_GPL(free_vx_info);
18633 +
18634 diff -NurpP --minimal linux-2.6.32.1/kernel/vserver/cvirt.c linux-2.6.32.1-vs2.3.0.36.27/kernel/vserver/cvirt.c
18635 --- linux-2.6.32.1/kernel/vserver/cvirt.c       1970-01-01 01:00:00.000000000 +0100
18636 +++ linux-2.6.32.1-vs2.3.0.36.27/kernel/vserver/cvirt.c 2009-12-03 20:04:56.000000000 +0100
18637 @@ -0,0 +1,304 @@
18638 +/*
18639 + *  linux/kernel/vserver/cvirt.c
18640 + *
18641 + *  Virtual Server: Context Virtualization
18642 + *
18643 + *  Copyright (C) 2004-2007  Herbert Pötzl
18644 + *
18645 + *  V0.01  broken out from limit.c
18646 + *  V0.02  added utsname stuff
18647 + *  V0.03  changed vcmds to vxi arg
18648 + *
18649 + */
18650 +
18651 +#include <linux/types.h>
18652 +#include <linux/utsname.h>
18653 +#include <linux/vs_cvirt.h>
18654 +#include <linux/vserver/switch.h>
18655 +#include <linux/vserver/cvirt_cmd.h>
18656 +
18657 +#include <asm/uaccess.h>
18658 +
18659 +
18660 +void vx_vsi_uptime(struct timespec *uptime, struct timespec *idle)
18661 +{
18662 +       struct vx_info *vxi = current_vx_info();
18663 +
18664 +       set_normalized_timespec(uptime,
18665 +               uptime->tv_sec - vxi->cvirt.bias_uptime.tv_sec,
18666 +               uptime->tv_nsec - vxi->cvirt.bias_uptime.tv_nsec);
18667 +       if (!idle)
18668 +               return;
18669 +       set_normalized_timespec(idle,
18670 +               idle->tv_sec - vxi->cvirt.bias_idle.tv_sec,
18671 +               idle->tv_nsec - vxi->cvirt.bias_idle.tv_nsec);
18672 +       return;
18673 +}
18674 +
18675 +uint64_t vx_idle_jiffies(void)
18676 +{
18677 +       return init_task.utime + init_task.stime;
18678 +}
18679 +
18680 +
18681 +
18682 +static inline uint32_t __update_loadavg(uint32_t load,
18683 +       int wsize, int delta, int n)
18684 +{
18685 +       unsigned long long calc, prev;
18686 +
18687 +       /* just set it to n */
18688 +       if (unlikely(delta >= wsize))
18689 +               return (n << FSHIFT);
18690 +
18691 +       calc = delta * n;
18692 +       calc <<= FSHIFT;
18693 +       prev = (wsize - delta);
18694 +       prev *= load;
18695 +       calc += prev;
18696 +       do_div(calc, wsize);
18697 +       return calc;
18698 +}
18699 +
18700 +
18701 +void vx_update_load(struct vx_info *vxi)
18702 +{
18703 +       uint32_t now, last, delta;
18704 +       unsigned int nr_running, nr_uninterruptible;
18705 +       unsigned int total;
18706 +       unsigned long flags;
18707 +
18708 +       spin_lock_irqsave(&vxi->cvirt.load_lock, flags);
18709 +
18710 +       now = jiffies;
18711 +       last = vxi->cvirt.load_last;
18712 +       delta = now - last;
18713 +
18714 +       if (delta < 5*HZ)
18715 +               goto out;
18716 +
18717 +       nr_running = atomic_read(&vxi->cvirt.nr_running);
18718 +       nr_uninterruptible = atomic_read(&vxi->cvirt.nr_uninterruptible);
18719 +       total = nr_running + nr_uninterruptible;
18720 +
18721 +       vxi->cvirt.load[0] = __update_loadavg(vxi->cvirt.load[0],
18722 +               60*HZ, delta, total);
18723 +       vxi->cvirt.load[1] = __update_loadavg(vxi->cvirt.load[1],
18724 +               5*60*HZ, delta, total);
18725 +       vxi->cvirt.load[2] = __update_loadavg(vxi->cvirt.load[2],
18726 +               15*60*HZ, delta, total);
18727 +
18728 +       vxi->cvirt.load_last = now;
18729 +out:
18730 +       atomic_inc(&vxi->cvirt.load_updates);
18731 +       spin_unlock_irqrestore(&vxi->cvirt.load_lock, flags);
18732 +}
18733 +
18734 +
18735 +/*
18736 + * Commands to do_syslog:
18737 + *
18738 + *      0 -- Close the log.  Currently a NOP.
18739 + *      1 -- Open the log. Currently a NOP.
18740 + *      2 -- Read from the log.
18741 + *      3 -- Read all messages remaining in the ring buffer.
18742 + *      4 -- Read and clear all messages remaining in the ring buffer
18743 + *      5 -- Clear ring buffer.
18744 + *      6 -- Disable printk's to console
18745 + *      7 -- Enable printk's to console
18746 + *      8 -- Set level of messages printed to console
18747 + *      9 -- Return number of unread characters in the log buffer
18748 + *     10 -- Return size of the log buffer
18749 + */
18750 +int vx_do_syslog(int type, char __user *buf, int len)
18751 +{
18752 +       int error = 0;
18753 +       int do_clear = 0;
18754 +       struct vx_info *vxi = current_vx_info();
18755 +       struct _vx_syslog *log;
18756 +
18757 +       if (!vxi)
18758 +               return -EINVAL;
18759 +       log = &vxi->cvirt.syslog;
18760 +
18761 +       switch (type) {
18762 +       case 0:         /* Close log */
18763 +       case 1:         /* Open log */
18764 +               break;
18765 +       case 2:         /* Read from log */
18766 +               error = wait_event_interruptible(log->log_wait,
18767 +                       (log->log_start - log->log_end));
18768 +               if (error)
18769 +                       break;
18770 +               spin_lock_irq(&log->logbuf_lock);
18771 +               spin_unlock_irq(&log->logbuf_lock);
18772 +               break;
18773 +       case 4:         /* Read/clear last kernel messages */
18774 +               do_clear = 1;
18775 +               /* fall through */
18776 +       case 3:         /* Read last kernel messages */
18777 +               return 0;
18778 +
18779 +       case 5:         /* Clear ring buffer */
18780 +               return 0;
18781 +
18782 +       case 6:         /* Disable logging to console */
18783 +       case 7:         /* Enable logging to console */
18784 +       case 8:         /* Set level of messages printed to console */
18785 +               break;
18786 +
18787 +       case 9:         /* Number of chars in the log buffer */
18788 +               return 0;
18789 +       case 10:        /* Size of the log buffer */
18790 +               return 0;
18791 +       default:
18792 +               error = -EINVAL;
18793 +               break;
18794 +       }
18795 +       return error;
18796 +}
18797 +
18798 +
18799 +/* virtual host info names */
18800 +
18801 +static char *vx_vhi_name(struct vx_info *vxi, int id)
18802 +{
18803 +       struct nsproxy *nsproxy;
18804 +       struct uts_namespace *uts;
18805 +
18806 +       if (id == VHIN_CONTEXT)
18807 +               return vxi->vx_name;
18808 +
18809 +       nsproxy = vxi->vx_nsproxy[0];
18810 +       if (!nsproxy)
18811 +               return NULL;
18812 +
18813 +       uts = nsproxy->uts_ns;
18814 +       if (!uts)
18815 +               return NULL;
18816 +
18817 +       switch (id) {
18818 +       case VHIN_SYSNAME:
18819 +               return uts->name.sysname;
18820 +       case VHIN_NODENAME:
18821 +               return uts->name.nodename;
18822 +       case VHIN_RELEASE:
18823 +               return uts->name.release;
18824 +       case VHIN_VERSION:
18825 +               return uts->name.version;
18826 +       case VHIN_MACHINE:
18827 +               return uts->name.machine;
18828 +       case VHIN_DOMAINNAME:
18829 +               return uts->name.domainname;
18830 +       default:
18831 +               return NULL;
18832 +       }
18833 +       return NULL;
18834 +}
18835 +
18836 +int vc_set_vhi_name(struct vx_info *vxi, void __user *data)
18837 +{
18838 +       struct vcmd_vhi_name_v0 vc_data;
18839 +       char *name;
18840 +
18841 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18842 +               return -EFAULT;
18843 +
18844 +       name = vx_vhi_name(vxi, vc_data.field);
18845 +       if (!name)
18846 +               return -EINVAL;
18847 +
18848 +       memcpy(name, vc_data.name, 65);
18849 +       return 0;
18850 +}
18851 +
18852 +int vc_get_vhi_name(struct vx_info *vxi, void __user *data)
18853 +{
18854 +       struct vcmd_vhi_name_v0 vc_data;
18855 +       char *name;
18856 +
18857 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18858 +               return -EFAULT;
18859 +
18860 +       name = vx_vhi_name(vxi, vc_data.field);
18861 +       if (!name)
18862 +               return -EINVAL;
18863 +
18864 +       memcpy(vc_data.name, name, 65);
18865 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
18866 +               return -EFAULT;
18867 +       return 0;
18868 +}
18869 +
18870 +
18871 +int vc_virt_stat(struct vx_info *vxi, void __user *data)
18872 +{
18873 +       struct vcmd_virt_stat_v0 vc_data;
18874 +       struct _vx_cvirt *cvirt = &vxi->cvirt;
18875 +       struct timespec uptime;
18876 +
18877 +       do_posix_clock_monotonic_gettime(&uptime);
18878 +       set_normalized_timespec(&uptime,
18879 +               uptime.tv_sec - cvirt->bias_uptime.tv_sec,
18880 +               uptime.tv_nsec - cvirt->bias_uptime.tv_nsec);
18881 +
18882 +       vc_data.offset = timeval_to_ns(&cvirt->bias_tv);
18883 +       vc_data.uptime = timespec_to_ns(&uptime);
18884 +       vc_data.nr_threads = atomic_read(&cvirt->nr_threads);
18885 +       vc_data.nr_running = atomic_read(&cvirt->nr_running);
18886 +       vc_data.nr_uninterruptible = atomic_read(&cvirt->nr_uninterruptible);
18887 +       vc_data.nr_onhold = atomic_read(&cvirt->nr_onhold);
18888 +       vc_data.nr_forks = atomic_read(&cvirt->total_forks);
18889 +       vc_data.load[0] = cvirt->load[0];
18890 +       vc_data.load[1] = cvirt->load[1];
18891 +       vc_data.load[2] = cvirt->load[2];
18892 +
18893 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
18894 +               return -EFAULT;
18895 +       return 0;
18896 +}
18897 +
18898 +
18899 +#ifdef CONFIG_VSERVER_VTIME
18900 +
18901 +/* virtualized time base */
18902 +
18903 +void vx_gettimeofday(struct timeval *tv)
18904 +{
18905 +       struct vx_info *vxi;
18906 +
18907 +       do_gettimeofday(tv);
18908 +       if (!vx_flags(VXF_VIRT_TIME, 0))
18909 +               return;
18910 +
18911 +       vxi = current_vx_info();
18912 +       tv->tv_sec += vxi->cvirt.bias_tv.tv_sec;
18913 +       tv->tv_usec += vxi->cvirt.bias_tv.tv_usec;
18914 +
18915 +       if (tv->tv_usec >= USEC_PER_SEC) {
18916 +               tv->tv_sec++;
18917 +               tv->tv_usec -= USEC_PER_SEC;
18918 +       } else if (tv->tv_usec < 0) {
18919 +               tv->tv_sec--;
18920 +               tv->tv_usec += USEC_PER_SEC;
18921 +       }
18922 +}
18923 +
18924 +int vx_settimeofday(struct timespec *ts)
18925 +{
18926 +       struct timeval tv;
18927 +       struct vx_info *vxi;
18928 +
18929 +       if (!vx_flags(VXF_VIRT_TIME, 0))
18930 +               return do_settimeofday(ts);
18931 +
18932 +       do_gettimeofday(&tv);
18933 +       vxi = current_vx_info();
18934 +       vxi->cvirt.bias_tv.tv_sec = ts->tv_sec - tv.tv_sec;
18935 +       vxi->cvirt.bias_tv.tv_usec =
18936 +               (ts->tv_nsec/NSEC_PER_USEC) - tv.tv_usec;
18937 +       return 0;
18938 +}
18939 +
18940 +#endif
18941 +
18942 diff -NurpP --minimal linux-2.6.32.1/kernel/vserver/cvirt_init.h linux-2.6.32.1-vs2.3.0.36.27/kernel/vserver/cvirt_init.h
18943 --- linux-2.6.32.1/kernel/vserver/cvirt_init.h  1970-01-01 01:00:00.000000000 +0100
18944 +++ linux-2.6.32.1-vs2.3.0.36.27/kernel/vserver/cvirt_init.h    2009-12-03 20:04:56.000000000 +0100
18945 @@ -0,0 +1,69 @@
18946 +
18947 +
18948 +extern uint64_t vx_idle_jiffies(void);
18949 +
18950 +static inline void vx_info_init_cvirt(struct _vx_cvirt *cvirt)
18951 +{
18952 +       uint64_t idle_jiffies = vx_idle_jiffies();
18953 +       uint64_t nsuptime;
18954 +
18955 +       do_posix_clock_monotonic_gettime(&cvirt->bias_uptime);
18956 +       nsuptime = (unsigned long long)cvirt->bias_uptime.tv_sec
18957 +               * NSEC_PER_SEC + cvirt->bias_uptime.tv_nsec;
18958 +       cvirt->bias_clock = nsec_to_clock_t(nsuptime);
18959 +       cvirt->bias_tv.tv_sec = 0;
18960 +       cvirt->bias_tv.tv_usec = 0;
18961 +
18962 +       jiffies_to_timespec(idle_jiffies, &cvirt->bias_idle);
18963 +       atomic_set(&cvirt->nr_threads, 0);
18964 +       atomic_set(&cvirt->nr_running, 0);
18965 +       atomic_set(&cvirt->nr_uninterruptible, 0);
18966 +       atomic_set(&cvirt->nr_onhold, 0);
18967 +
18968 +       spin_lock_init(&cvirt->load_lock);
18969 +       cvirt->load_last = jiffies;
18970 +       atomic_set(&cvirt->load_updates, 0);
18971 +       cvirt->load[0] = 0;
18972 +       cvirt->load[1] = 0;
18973 +       cvirt->load[2] = 0;
18974 +       atomic_set(&cvirt->total_forks, 0);
18975 +
18976 +       spin_lock_init(&cvirt->syslog.logbuf_lock);
18977 +       init_waitqueue_head(&cvirt->syslog.log_wait);
18978 +       cvirt->syslog.log_start = 0;
18979 +       cvirt->syslog.log_end = 0;
18980 +       cvirt->syslog.con_start = 0;
18981 +       cvirt->syslog.logged_chars = 0;
18982 +}
18983 +
18984 +static inline
18985 +void vx_info_init_cvirt_pc(struct _vx_cvirt_pc *cvirt_pc, int cpu)
18986 +{
18987 +       // cvirt_pc->cpustat = { 0 };
18988 +}
18989 +
18990 +static inline void vx_info_exit_cvirt(struct _vx_cvirt *cvirt)
18991 +{
18992 +       int value;
18993 +
18994 +       vxwprintk_xid((value = atomic_read(&cvirt->nr_threads)),
18995 +               "!!! cvirt: %p[nr_threads] = %d on exit.",
18996 +               cvirt, value);
18997 +       vxwprintk_xid((value = atomic_read(&cvirt->nr_running)),
18998 +               "!!! cvirt: %p[nr_running] = %d on exit.",
18999 +               cvirt, value);
19000 +       vxwprintk_xid((value = atomic_read(&cvirt->nr_uninterruptible)),
19001 +               "!!! cvirt: %p[nr_uninterruptible] = %d on exit.",
19002 +               cvirt, value);
19003 +       vxwprintk_xid((value = atomic_read(&cvirt->nr_onhold)),
19004 +               "!!! cvirt: %p[nr_onhold] = %d on exit.",
19005 +               cvirt, value);
19006 +       return;
19007 +}
19008 +
19009 +static inline
19010 +void vx_info_exit_cvirt_pc(struct _vx_cvirt_pc *cvirt_pc, int cpu)
19011 +{
19012 +       return;
19013 +}
19014 +
19015 diff -NurpP --minimal linux-2.6.32.1/kernel/vserver/cvirt_proc.h linux-2.6.32.1-vs2.3.0.36.27/kernel/vserver/cvirt_proc.h
19016 --- linux-2.6.32.1/kernel/vserver/cvirt_proc.h  1970-01-01 01:00:00.000000000 +0100
19017 +++ linux-2.6.32.1-vs2.3.0.36.27/kernel/vserver/cvirt_proc.h    2009-12-03 20:04:56.000000000 +0100
19018 @@ -0,0 +1,135 @@
19019 +#ifndef _VX_CVIRT_PROC_H
19020 +#define _VX_CVIRT_PROC_H
19021 +
19022 +#include <linux/nsproxy.h>
19023 +#include <linux/mnt_namespace.h>
19024 +#include <linux/ipc_namespace.h>
19025 +#include <linux/utsname.h>
19026 +#include <linux/ipc.h>
19027 +
19028 +
19029 +static inline
19030 +int vx_info_proc_nsproxy(struct nsproxy *nsproxy, char *buffer)
19031 +{
19032 +       struct mnt_namespace *ns;
19033 +       struct uts_namespace *uts;
19034 +       struct ipc_namespace *ipc;
19035 +       struct path path;
19036 +       char *pstr, *root;
19037 +       int length = 0;
19038 +
19039 +       if (!nsproxy)
19040 +               goto out;
19041 +
19042 +       length += sprintf(buffer + length,
19043 +               "NSProxy:\t%p [%p,%p,%p]\n",
19044 +               nsproxy, nsproxy->mnt_ns,
19045 +               nsproxy->uts_ns, nsproxy->ipc_ns);
19046 +
19047 +       ns = nsproxy->mnt_ns;
19048 +       if (!ns)
19049 +               goto skip_ns;
19050 +
19051 +       pstr = kmalloc(PATH_MAX, GFP_KERNEL);
19052 +       if (!pstr)
19053 +               goto skip_ns;
19054 +
19055 +       path.mnt = ns->root;
19056 +       path.dentry = ns->root->mnt_root;
19057 +       root = d_path(&path, pstr, PATH_MAX - 2);
19058 +       length += sprintf(buffer + length,
19059 +               "Namespace:\t%p [#%u]\n"
19060 +               "RootPath:\t%s\n",
19061 +               ns, atomic_read(&ns->count),
19062 +               root);
19063 +       kfree(pstr);
19064 +skip_ns:
19065 +
19066 +       uts = nsproxy->uts_ns;
19067 +       if (!uts)
19068 +               goto skip_uts;
19069 +
19070 +       length += sprintf(buffer + length,
19071 +               "SysName:\t%.*s\n"
19072 +               "NodeName:\t%.*s\n"
19073 +               "Release:\t%.*s\n"
19074 +               "Version:\t%.*s\n"
19075 +               "Machine:\t%.*s\n"
19076 +               "DomainName:\t%.*s\n",
19077 +               __NEW_UTS_LEN, uts->name.sysname,
19078 +               __NEW_UTS_LEN, uts->name.nodename,
19079 +               __NEW_UTS_LEN, uts->name.release,
19080 +               __NEW_UTS_LEN, uts->name.version,
19081 +               __NEW_UTS_LEN, uts->name.machine,
19082 +               __NEW_UTS_LEN, uts->name.domainname);
19083 +skip_uts:
19084 +
19085 +       ipc = nsproxy->ipc_ns;
19086 +       if (!ipc)
19087 +               goto skip_ipc;
19088 +
19089 +       length += sprintf(buffer + length,
19090 +               "SEMS:\t\t%d %d %d %d  %d\n"
19091 +               "MSG:\t\t%d %d %d\n"
19092 +               "SHM:\t\t%lu %lu  %d %d\n",
19093 +               ipc->sem_ctls[0], ipc->sem_ctls[1],
19094 +               ipc->sem_ctls[2], ipc->sem_ctls[3],
19095 +               ipc->used_sems,
19096 +               ipc->msg_ctlmax, ipc->msg_ctlmnb, ipc->msg_ctlmni,
19097 +               (unsigned long)ipc->shm_ctlmax,
19098 +               (unsigned long)ipc->shm_ctlall,
19099 +               ipc->shm_ctlmni, ipc->shm_tot);
19100 +skip_ipc:
19101 +out:
19102 +       return length;
19103 +}
19104 +
19105 +
19106 +#include <linux/sched.h>
19107 +
19108 +#define LOAD_INT(x) ((x) >> FSHIFT)
19109 +#define LOAD_FRAC(x) LOAD_INT(((x) & (FIXED_1 - 1)) * 100)
19110 +
19111 +static inline
19112 +int vx_info_proc_cvirt(struct _vx_cvirt *cvirt, char *buffer)
19113 +{
19114 +       int length = 0;
19115 +       int a, b, c;
19116 +
19117 +       length += sprintf(buffer + length,
19118 +               "BiasUptime:\t%lu.%02lu\n",
19119 +               (unsigned long)cvirt->bias_uptime.tv_sec,
19120 +               (cvirt->bias_uptime.tv_nsec / (NSEC_PER_SEC / 100)));
19121 +
19122 +       a = cvirt->load[0] + (FIXED_1 / 200);
19123 +       b = cvirt->load[1] + (FIXED_1 / 200);
19124 +       c = cvirt->load[2] + (FIXED_1 / 200);
19125 +       length += sprintf(buffer + length,
19126 +               "nr_threads:\t%d\n"
19127 +               "nr_running:\t%d\n"
19128 +               "nr_unintr:\t%d\n"
19129 +               "nr_onhold:\t%d\n"
19130 +               "load_updates:\t%d\n"
19131 +               "loadavg:\t%d.%02d %d.%02d %d.%02d\n"
19132 +               "total_forks:\t%d\n",
19133 +               atomic_read(&cvirt->nr_threads),
19134 +               atomic_read(&cvirt->nr_running),
19135 +               atomic_read(&cvirt->nr_uninterruptible),
19136 +               atomic_read(&cvirt->nr_onhold),
19137 +               atomic_read(&cvirt->load_updates),
19138 +               LOAD_INT(a), LOAD_FRAC(a),
19139 +               LOAD_INT(b), LOAD_FRAC(b),
19140 +               LOAD_INT(c), LOAD_FRAC(c),
19141 +               atomic_read(&cvirt->total_forks));
19142 +       return length;
19143 +}
19144 +
19145 +static inline
19146 +int vx_info_proc_cvirt_pc(struct _vx_cvirt_pc *cvirt_pc,
19147 +       char *buffer, int cpu)
19148 +{
19149 +       int length = 0;
19150 +       return length;
19151 +}
19152 +
19153 +#endif /* _VX_CVIRT_PROC_H */
19154 diff -NurpP --minimal linux-2.6.32.1/kernel/vserver/debug.c linux-2.6.32.1-vs2.3.0.36.27/kernel/vserver/debug.c
19155 --- linux-2.6.32.1/kernel/vserver/debug.c       1970-01-01 01:00:00.000000000 +0100
19156 +++ linux-2.6.32.1-vs2.3.0.36.27/kernel/vserver/debug.c 2009-12-03 20:04:56.000000000 +0100
19157 @@ -0,0 +1,32 @@
19158 +/*
19159 + *  kernel/vserver/debug.c
19160 + *
19161 + *  Copyright (C) 2005-2007 Herbert Pötzl
19162 + *
19163 + *  V0.01  vx_info dump support
19164 + *
19165 + */
19166 +
19167 +#include <linux/module.h>
19168 +
19169 +#include <linux/vserver/context.h>
19170 +
19171 +
19172 +void   dump_vx_info(struct vx_info *vxi, int level)
19173 +{
19174 +       printk("vx_info %p[#%d, %d.%d, %4x]\n", vxi, vxi->vx_id,
19175 +               atomic_read(&vxi->vx_usecnt),
19176 +               atomic_read(&vxi->vx_tasks),
19177 +               vxi->vx_state);
19178 +       if (level > 0) {
19179 +               __dump_vx_limit(&vxi->limit);
19180 +               __dump_vx_sched(&vxi->sched);
19181 +               __dump_vx_cvirt(&vxi->cvirt);
19182 +               __dump_vx_cacct(&vxi->cacct);
19183 +       }
19184 +       printk("---\n");
19185 +}
19186 +
19187 +
19188 +EXPORT_SYMBOL_GPL(dump_vx_info);
19189 +
19190 diff -NurpP --minimal linux-2.6.32.1/kernel/vserver/device.c linux-2.6.32.1-vs2.3.0.36.27/kernel/vserver/device.c
19191 --- linux-2.6.32.1/kernel/vserver/device.c      1970-01-01 01:00:00.000000000 +0100
19192 +++ linux-2.6.32.1-vs2.3.0.36.27/kernel/vserver/device.c        2009-12-03 20:04:56.000000000 +0100
19193 @@ -0,0 +1,443 @@
19194 +/*
19195 + *  linux/kernel/vserver/device.c
19196 + *
19197 + *  Linux-VServer: Device Support
19198 + *
19199 + *  Copyright (C) 2006  Herbert Pötzl
19200 + *  Copyright (C) 2007  Daniel Hokka Zakrisson
19201 + *
19202 + *  V0.01  device mapping basics
19203 + *  V0.02  added defaults
19204 + *
19205 + */
19206 +
19207 +#include <linux/slab.h>
19208 +#include <linux/rcupdate.h>
19209 +#include <linux/fs.h>
19210 +#include <linux/namei.h>
19211 +#include <linux/hash.h>
19212 +
19213 +#include <asm/errno.h>
19214 +#include <asm/uaccess.h>
19215 +#include <linux/vserver/base.h>
19216 +#include <linux/vserver/debug.h>
19217 +#include <linux/vserver/context.h>
19218 +#include <linux/vserver/device.h>
19219 +#include <linux/vserver/device_cmd.h>
19220 +
19221 +
19222 +#define DMAP_HASH_BITS 4
19223 +
19224 +
19225 +struct vs_mapping {
19226 +       union {
19227 +               struct hlist_node hlist;
19228 +               struct list_head list;
19229 +       } u;
19230 +#define dm_hlist       u.hlist
19231 +#define dm_list                u.list
19232 +       xid_t xid;
19233 +       dev_t device;
19234 +       struct vx_dmap_target target;
19235 +};
19236 +
19237 +
19238 +static struct hlist_head dmap_main_hash[1 << DMAP_HASH_BITS];
19239 +
19240 +static spinlock_t dmap_main_hash_lock = SPIN_LOCK_UNLOCKED;
19241 +
19242 +static struct vx_dmap_target dmap_defaults[2] = {
19243 +       { .flags = DATTR_OPEN },
19244 +       { .flags = DATTR_OPEN },
19245 +};
19246 +
19247 +
19248 +struct kmem_cache *dmap_cachep __read_mostly;
19249 +
19250 +int __init dmap_cache_init(void)
19251 +{
19252 +       dmap_cachep = kmem_cache_create("dmap_cache",
19253 +               sizeof(struct vs_mapping), 0,
19254 +               SLAB_HWCACHE_ALIGN|SLAB_PANIC, NULL);
19255 +       return 0;
19256 +}
19257 +
19258 +__initcall(dmap_cache_init);
19259 +
19260 +
19261 +static inline unsigned int __hashval(dev_t dev, int bits)
19262 +{
19263 +       return hash_long((unsigned long)dev, bits);
19264 +}
19265 +
19266 +
19267 +/*     __hash_mapping()
19268 + *     add the mapping to the hash table
19269 + */
19270 +static inline void __hash_mapping(struct vx_info *vxi, struct vs_mapping *vdm)
19271 +{
19272 +       spinlock_t *hash_lock = &dmap_main_hash_lock;
19273 +       struct hlist_head *head, *hash = dmap_main_hash;
19274 +       int device = vdm->device;
19275 +
19276 +       spin_lock(hash_lock);
19277 +       vxdprintk(VXD_CBIT(misc, 8), "__hash_mapping: %p[#%d] %08x:%08x",
19278 +               vxi, vxi ? vxi->vx_id : 0, device, vdm->target.target);
19279 +
19280 +       head = &hash[__hashval(device, DMAP_HASH_BITS)];
19281 +       hlist_add_head(&vdm->dm_hlist, head);
19282 +       spin_unlock(hash_lock);
19283 +}
19284 +
19285 +
19286 +static inline int __mode_to_default(umode_t mode)
19287 +{
19288 +       switch (mode) {
19289 +       case S_IFBLK:
19290 +               return 0;
19291 +       case S_IFCHR:
19292 +               return 1;
19293 +       default:
19294 +               BUG();
19295 +       }
19296 +}
19297 +
19298 +
19299 +/*     __set_default()
19300 + *     set a default
19301 + */
19302 +static inline void __set_default(struct vx_info *vxi, umode_t mode,
19303 +       struct vx_dmap_target *vdmt)
19304 +{
19305 +       spinlock_t *hash_lock = &dmap_main_hash_lock;
19306 +       spin_lock(hash_lock);
19307 +
19308 +       if (vxi)
19309 +               vxi->dmap.targets[__mode_to_default(mode)] = *vdmt;
19310 +       else
19311 +               dmap_defaults[__mode_to_default(mode)] = *vdmt;
19312 +
19313 +
19314 +       spin_unlock(hash_lock);
19315 +
19316 +       vxdprintk(VXD_CBIT(misc, 8), "__set_default: %p[#%u] %08x %04x",
19317 +                 vxi, vxi ? vxi->vx_id : 0, vdmt->target, vdmt->flags);
19318 +}
19319 +
19320 +
19321 +/*     __remove_default()
19322 + *     remove a default
19323 + */
19324 +static inline int __remove_default(struct vx_info *vxi, umode_t mode)
19325 +{
19326 +       spinlock_t *hash_lock = &dmap_main_hash_lock;
19327 +       spin_lock(hash_lock);
19328 +
19329 +       if (vxi)
19330 +               vxi->dmap.targets[__mode_to_default(mode)].flags = 0;
19331 +       else    /* remove == reset */
19332 +               dmap_defaults[__mode_to_default(mode)].flags = DATTR_OPEN | mode;
19333 +
19334 +       spin_unlock(hash_lock);
19335 +       return 0;
19336 +}
19337 +
19338 +
19339 +/*     __find_mapping()
19340 + *     find a mapping in the hash table
19341 + *
19342 + *     caller must hold hash_lock
19343 + */
19344 +static inline int __find_mapping(xid_t xid, dev_t device, umode_t mode,
19345 +       struct vs_mapping **local, struct vs_mapping **global)
19346 +{
19347 +       struct hlist_head *hash = dmap_main_hash;
19348 +       struct hlist_head *head = &hash[__hashval(device, DMAP_HASH_BITS)];
19349 +       struct hlist_node *pos;
19350 +       struct vs_mapping *vdm;
19351 +
19352 +       *local = NULL;
19353 +       if (global)
19354 +               *global = NULL;
19355 +
19356 +       hlist_for_each(pos, head) {
19357 +               vdm = hlist_entry(pos, struct vs_mapping, dm_hlist);
19358 +
19359 +               if ((vdm->device == device) &&
19360 +                       !((vdm->target.flags ^ mode) & S_IFMT)) {
19361 +                       if (vdm->xid == xid) {
19362 +                               *local = vdm;
19363 +                               return 1;
19364 +                       } else if (global && vdm->xid == 0)
19365 +                               *global = vdm;
19366 +               }
19367 +       }
19368 +
19369 +       if (global && *global)
19370 +               return 0;
19371 +       else
19372 +               return -ENOENT;
19373 +}
19374 +
19375 +
19376 +/*     __lookup_mapping()
19377 + *     find a mapping and store the result in target and flags
19378 + */
19379 +static inline int __lookup_mapping(struct vx_info *vxi,
19380 +       dev_t device, dev_t *target, int *flags, umode_t mode)
19381 +{
19382 +       spinlock_t *hash_lock = &dmap_main_hash_lock;
19383 +       struct vs_mapping *vdm, *global;
19384 +       struct vx_dmap_target *vdmt;
19385 +       int ret = 0;
19386 +       xid_t xid = vxi->vx_id;
19387 +       int index;
19388 +
19389 +       spin_lock(hash_lock);
19390 +       if (__find_mapping(xid, device, mode, &vdm, &global) > 0) {
19391 +               ret = 1;
19392 +               vdmt = &vdm->target;
19393 +               goto found;
19394 +       }
19395 +
19396 +       index = __mode_to_default(mode);
19397 +       if (vxi && vxi->dmap.targets[index].flags) {
19398 +               ret = 2;
19399 +               vdmt = &vxi->dmap.targets[index];
19400 +       } else if (global) {
19401 +               ret = 3;
19402 +               vdmt = &global->target;
19403 +               goto found;
19404 +       } else {
19405 +               ret = 4;
19406 +               vdmt = &dmap_defaults[index];
19407 +       }
19408 +
19409 +found:
19410 +       if (target && (vdmt->flags & DATTR_REMAP))
19411 +               *target = vdmt->target;
19412 +       else if (target)
19413 +               *target = device;
19414 +       if (flags)
19415 +               *flags = vdmt->flags;
19416 +
19417 +       spin_unlock(hash_lock);
19418 +
19419 +       return ret;
19420 +}
19421 +
19422 +
19423 +/*     __remove_mapping()
19424 + *     remove a mapping from the hash table
19425 + */
19426 +static inline int __remove_mapping(struct vx_info *vxi, dev_t device,
19427 +       umode_t mode)
19428 +{
19429 +       spinlock_t *hash_lock = &dmap_main_hash_lock;
19430 +       struct vs_mapping *vdm = NULL;
19431 +       int ret = 0;
19432 +
19433 +       spin_lock(hash_lock);
19434 +
19435 +       ret = __find_mapping((vxi ? vxi->vx_id : 0), device, mode, &vdm,
19436 +               NULL);
19437 +       vxdprintk(VXD_CBIT(misc, 8), "__remove_mapping: %p[#%d] %08x %04x",
19438 +               vxi, vxi ? vxi->vx_id : 0, device, mode);
19439 +       if (ret < 0)
19440 +               goto out;
19441 +       hlist_del(&vdm->dm_hlist);
19442 +
19443 +out:
19444 +       spin_unlock(hash_lock);
19445 +       if (vdm)
19446 +               kmem_cache_free(dmap_cachep, vdm);
19447 +       return ret;
19448 +}
19449 +
19450 +
19451 +
19452 +int vs_map_device(struct vx_info *vxi,
19453 +       dev_t device, dev_t *target, umode_t mode)
19454 +{
19455 +       int ret, flags = DATTR_MASK;
19456 +
19457 +       if (!vxi) {
19458 +               if (target)
19459 +                       *target = device;
19460 +               goto out;
19461 +       }
19462 +       ret = __lookup_mapping(vxi, device, target, &flags, mode);
19463 +       vxdprintk(VXD_CBIT(misc, 8), "vs_map_device: %08x target: %08x flags: %04x mode: %04x mapped=%d",
19464 +               device, target ? *target : 0, flags, mode, ret);
19465 +out:
19466 +       return (flags & DATTR_MASK);
19467 +}
19468 +
19469 +
19470 +
19471 +static int do_set_mapping(struct vx_info *vxi,
19472 +       dev_t device, dev_t target, int flags, umode_t mode)
19473 +{
19474 +       if (device) {
19475 +               struct vs_mapping *new;
19476 +
19477 +               new = kmem_cache_alloc(dmap_cachep, GFP_KERNEL);
19478 +               if (!new)
19479 +                       return -ENOMEM;
19480 +
19481 +               INIT_HLIST_NODE(&new->dm_hlist);
19482 +               new->device = device;
19483 +               new->target.target = target;
19484 +               new->target.flags = flags | mode;
19485 +               new->xid = (vxi ? vxi->vx_id : 0);
19486 +
19487 +               vxdprintk(VXD_CBIT(misc, 8), "do_set_mapping: %08x target: %08x flags: %04x", device, target, flags);
19488 +               __hash_mapping(vxi, new);
19489 +       } else {
19490 +               struct vx_dmap_target new = {
19491 +                       .target = target,
19492 +                       .flags = flags | mode,
19493 +               };
19494 +               __set_default(vxi, mode, &new);
19495 +       }
19496 +       return 0;
19497 +}
19498 +
19499 +
19500 +static int do_unset_mapping(struct vx_info *vxi,
19501 +       dev_t device, dev_t target, int flags, umode_t mode)
19502 +{
19503 +       int ret = -EINVAL;
19504 +
19505 +       if (device) {
19506 +               ret = __remove_mapping(vxi, device, mode);
19507 +               if (ret < 0)
19508 +                       goto out;
19509 +       } else {
19510 +               ret = __remove_default(vxi, mode);
19511 +               if (ret < 0)
19512 +                       goto out;
19513 +       }
19514 +
19515 +out:
19516 +       return ret;
19517 +}
19518 +
19519 +
19520 +static inline int __user_device(const char __user *name, dev_t *dev,
19521 +       umode_t *mode)
19522 +{
19523 +       struct nameidata nd;
19524 +       int ret;
19525 +
19526 +       if (!name) {
19527 +               *dev = 0;
19528 +               return 0;
19529 +       }
19530 +       ret = user_lpath(name, &nd.path);
19531 +       if (ret)
19532 +               return ret;
19533 +       if (nd.path.dentry->d_inode) {
19534 +               *dev = nd.path.dentry->d_inode->i_rdev;
19535 +               *mode = nd.path.dentry->d_inode->i_mode;
19536 +       }
19537 +       path_put(&nd.path);
19538 +       return 0;
19539 +}
19540 +
19541 +static inline int __mapping_mode(dev_t device, dev_t target,
19542 +       umode_t device_mode, umode_t target_mode, umode_t *mode)
19543 +{
19544 +       if (device)
19545 +               *mode = device_mode & S_IFMT;
19546 +       else if (target)
19547 +               *mode = target_mode & S_IFMT;
19548 +       else
19549 +               return -EINVAL;
19550 +
19551 +       /* if both given, device and target mode have to match */
19552 +       if (device && target &&
19553 +               ((device_mode ^ target_mode) & S_IFMT))
19554 +               return -EINVAL;
19555 +       return 0;
19556 +}
19557 +
19558 +
19559 +static inline int do_mapping(struct vx_info *vxi, const char __user *device_path,
19560 +       const char __user *target_path, int flags, int set)
19561 +{
19562 +       dev_t device = ~0, target = ~0;
19563 +       umode_t device_mode = 0, target_mode = 0, mode;
19564 +       int ret;
19565 +
19566 +       ret = __user_device(device_path, &device, &device_mode);
19567 +       if (ret)
19568 +               return ret;
19569 +       ret = __user_device(target_path, &target, &target_mode);
19570 +       if (ret)
19571 +               return ret;
19572 +
19573 +       ret = __mapping_mode(device, target,
19574 +               device_mode, target_mode, &mode);
19575 +       if (ret)
19576 +               return ret;
19577 +
19578 +       if (set)
19579 +               return do_set_mapping(vxi, device, target,
19580 +                       flags, mode);
19581 +       else
19582 +               return do_unset_mapping(vxi, device, target,
19583 +                       flags, mode);
19584 +}
19585 +
19586 +
19587 +int vc_set_mapping(struct vx_info *vxi, void __user *data)
19588 +{
19589 +       struct vcmd_set_mapping_v0 vc_data;
19590 +
19591 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19592 +               return -EFAULT;
19593 +
19594 +       return do_mapping(vxi, vc_data.device, vc_data.target,
19595 +               vc_data.flags, 1);
19596 +}
19597 +
19598 +int vc_unset_mapping(struct vx_info *vxi, void __user *data)
19599 +{
19600 +       struct vcmd_set_mapping_v0 vc_data;
19601 +
19602 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19603 +               return -EFAULT;
19604 +
19605 +       return do_mapping(vxi, vc_data.device, vc_data.target,
19606 +               vc_data.flags, 0);
19607 +}
19608 +
19609 +
19610 +#ifdef CONFIG_COMPAT
19611 +
19612 +int vc_set_mapping_x32(struct vx_info *vxi, void __user *data)
19613 +{
19614 +       struct vcmd_set_mapping_v0_x32 vc_data;
19615 +
19616 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19617 +               return -EFAULT;
19618 +
19619 +       return do_mapping(vxi, compat_ptr(vc_data.device_ptr),
19620 +               compat_ptr(vc_data.target_ptr), vc_data.flags, 1);
19621 +}
19622 +
19623 +int vc_unset_mapping_x32(struct vx_info *vxi, void __user *data)
19624 +{
19625 +       struct vcmd_set_mapping_v0_x32 vc_data;
19626 +
19627 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19628 +               return -EFAULT;
19629 +
19630 +       return do_mapping(vxi, compat_ptr(vc_data.device_ptr),
19631 +               compat_ptr(vc_data.target_ptr), vc_data.flags, 0);
19632 +}
19633 +
19634 +#endif /* CONFIG_COMPAT */
19635 +
19636 +
19637 diff -NurpP --minimal linux-2.6.32.1/kernel/vserver/dlimit.c linux-2.6.32.1-vs2.3.0.36.27/kernel/vserver/dlimit.c
19638 --- linux-2.6.32.1/kernel/vserver/dlimit.c      1970-01-01 01:00:00.000000000 +0100
19639 +++ linux-2.6.32.1-vs2.3.0.36.27/kernel/vserver/dlimit.c        2009-12-03 20:04:56.000000000 +0100
19640 @@ -0,0 +1,529 @@
19641 +/*
19642 + *  linux/kernel/vserver/dlimit.c
19643 + *
19644 + *  Virtual Server: Context Disk Limits
19645 + *
19646 + *  Copyright (C) 2004-2009  Herbert Pötzl
19647 + *
19648 + *  V0.01  initial version
19649 + *  V0.02  compat32 splitup
19650 + *  V0.03  extended interface
19651 + *
19652 + */
19653 +
19654 +#include <linux/statfs.h>
19655 +#include <linux/sched.h>
19656 +#include <linux/namei.h>
19657 +#include <linux/vs_tag.h>
19658 +#include <linux/vs_dlimit.h>
19659 +#include <linux/vserver/dlimit_cmd.h>
19660 +
19661 +#include <asm/uaccess.h>
19662 +
19663 +/*     __alloc_dl_info()
19664 +
19665 +       * allocate an initialized dl_info struct
19666 +       * doesn't make it visible (hash)                        */
19667 +
19668 +static struct dl_info *__alloc_dl_info(struct super_block *sb, tag_t tag)
19669 +{
19670 +       struct dl_info *new = NULL;
19671 +
19672 +       vxdprintk(VXD_CBIT(dlim, 5),
19673 +               "alloc_dl_info(%p,%d)*", sb, tag);
19674 +
19675 +       /* would this benefit from a slab cache? */
19676 +       new = kmalloc(sizeof(struct dl_info), GFP_KERNEL);
19677 +       if (!new)
19678 +               return 0;
19679 +
19680 +       memset(new, 0, sizeof(struct dl_info));
19681 +       new->dl_tag = tag;
19682 +       new->dl_sb = sb;
19683 +       INIT_RCU_HEAD(&new->dl_rcu);
19684 +       INIT_HLIST_NODE(&new->dl_hlist);
19685 +       spin_lock_init(&new->dl_lock);
19686 +       atomic_set(&new->dl_refcnt, 0);
19687 +       atomic_set(&new->dl_usecnt, 0);
19688 +
19689 +       /* rest of init goes here */
19690 +
19691 +       vxdprintk(VXD_CBIT(dlim, 4),
19692 +               "alloc_dl_info(%p,%d) = %p", sb, tag, new);
19693 +       return new;
19694 +}
19695 +
19696 +/*     __dealloc_dl_info()
19697 +
19698 +       * final disposal of dl_info                             */
19699 +
19700 +static void __dealloc_dl_info(struct dl_info *dli)
19701 +{
19702 +       vxdprintk(VXD_CBIT(dlim, 4),
19703 +               "dealloc_dl_info(%p)", dli);
19704 +
19705 +       dli->dl_hlist.next = LIST_POISON1;
19706 +       dli->dl_tag = -1;
19707 +       dli->dl_sb = 0;
19708 +
19709 +       BUG_ON(atomic_read(&dli->dl_usecnt));
19710 +       BUG_ON(atomic_read(&dli->dl_refcnt));
19711 +
19712 +       kfree(dli);
19713 +}
19714 +
19715 +
19716 +/*     hash table for dl_info hash */
19717 +
19718 +#define DL_HASH_SIZE   13
19719 +
19720 +struct hlist_head dl_info_hash[DL_HASH_SIZE];
19721 +
19722 +static spinlock_t dl_info_hash_lock = SPIN_LOCK_UNLOCKED;
19723 +
19724 +
19725 +static inline unsigned int __hashval(struct super_block *sb, tag_t tag)
19726 +{
19727 +       return ((tag ^ (unsigned long)sb) % DL_HASH_SIZE);
19728 +}
19729 +
19730 +
19731 +
19732 +/*     __hash_dl_info()
19733 +
19734 +       * add the dli to the global hash table
19735 +       * requires the hash_lock to be held                     */
19736 +
19737 +static inline void __hash_dl_info(struct dl_info *dli)
19738 +{
19739 +       struct hlist_head *head;
19740 +
19741 +       vxdprintk(VXD_CBIT(dlim, 6),
19742 +               "__hash_dl_info: %p[#%d]", dli, dli->dl_tag);
19743 +       get_dl_info(dli);
19744 +       head = &dl_info_hash[__hashval(dli->dl_sb, dli->dl_tag)];
19745 +       hlist_add_head_rcu(&dli->dl_hlist, head);
19746 +}
19747 +
19748 +/*     __unhash_dl_info()
19749 +
19750 +       * remove the dli from the global hash table
19751 +       * requires the hash_lock to be held                     */
19752 +
19753 +static inline void __unhash_dl_info(struct dl_info *dli)
19754 +{
19755 +       vxdprintk(VXD_CBIT(dlim, 6),
19756 +               "__unhash_dl_info: %p[#%d]", dli, dli->dl_tag);
19757 +       hlist_del_rcu(&dli->dl_hlist);
19758 +       put_dl_info(dli);
19759 +}
19760 +
19761 +
19762 +/*     __lookup_dl_info()
19763 +
19764 +       * requires the rcu_read_lock()
19765 +       * doesn't increment the dl_refcnt                       */
19766 +
19767 +static inline struct dl_info *__lookup_dl_info(struct super_block *sb, tag_t tag)
19768 +{
19769 +       struct hlist_head *head = &dl_info_hash[__hashval(sb, tag)];
19770 +       struct hlist_node *pos;
19771 +       struct dl_info *dli;
19772 +
19773 +       hlist_for_each_entry_rcu(dli, pos, head, dl_hlist) {
19774 +
19775 +               if (dli->dl_tag == tag && dli->dl_sb == sb) {
19776 +                       return dli;
19777 +               }
19778 +       }
19779 +       return NULL;
19780 +}
19781 +
19782 +
19783 +struct dl_info *locate_dl_info(struct super_block *sb, tag_t tag)
19784 +{
19785 +       struct dl_info *dli;
19786 +
19787 +       rcu_read_lock();
19788 +       dli = get_dl_info(__lookup_dl_info(sb, tag));
19789 +       vxdprintk(VXD_CBIT(dlim, 7),
19790 +               "locate_dl_info(%p,#%d) = %p", sb, tag, dli);
19791 +       rcu_read_unlock();
19792 +       return dli;
19793 +}
19794 +
19795 +void rcu_free_dl_info(struct rcu_head *head)
19796 +{
19797 +       struct dl_info *dli = container_of(head, struct dl_info, dl_rcu);
19798 +       int usecnt, refcnt;
19799 +
19800 +       BUG_ON(!dli || !head);
19801 +
19802 +       usecnt = atomic_read(&dli->dl_usecnt);
19803 +       BUG_ON(usecnt < 0);
19804 +
19805 +       refcnt = atomic_read(&dli->dl_refcnt);
19806 +       BUG_ON(refcnt < 0);
19807 +
19808 +       vxdprintk(VXD_CBIT(dlim, 3),
19809 +               "rcu_free_dl_info(%p)", dli);
19810 +       if (!usecnt)
19811 +               __dealloc_dl_info(dli);
19812 +       else
19813 +               printk("!!! rcu didn't free\n");
19814 +}
19815 +
19816 +
19817 +
19818 +
19819 +static int do_addrem_dlimit(uint32_t id, const char __user *name,
19820 +       uint32_t flags, int add)
19821 +{
19822 +       struct path path;
19823 +       int ret;
19824 +
19825 +       ret = user_lpath(name, &path);
19826 +       if (!ret) {
19827 +               struct super_block *sb;
19828 +               struct dl_info *dli;
19829 +
19830 +               ret = -EINVAL;
19831 +               if (!path.dentry->d_inode)
19832 +                       goto out_release;
19833 +               if (!(sb = path.dentry->d_inode->i_sb))
19834 +                       goto out_release;
19835 +
19836 +               if (add) {
19837 +                       dli = __alloc_dl_info(sb, id);
19838 +                       spin_lock(&dl_info_hash_lock);
19839 +
19840 +                       ret = -EEXIST;
19841 +                       if (__lookup_dl_info(sb, id))
19842 +                               goto out_unlock;
19843 +                       __hash_dl_info(dli);
19844 +                       dli = NULL;
19845 +               } else {
19846 +                       spin_lock(&dl_info_hash_lock);
19847 +                       dli = __lookup_dl_info(sb, id);
19848 +
19849 +                       ret = -ESRCH;
19850 +                       if (!dli)
19851 +                               goto out_unlock;
19852 +                       __unhash_dl_info(dli);
19853 +               }
19854 +               ret = 0;
19855 +       out_unlock:
19856 +               spin_unlock(&dl_info_hash_lock);
19857 +               if (add && dli)
19858 +                       __dealloc_dl_info(dli);
19859 +       out_release:
19860 +               path_put(&path);
19861 +       }
19862 +       return ret;
19863 +}
19864 +
19865 +int vc_add_dlimit(uint32_t id, void __user *data)
19866 +{
19867 +       struct vcmd_ctx_dlimit_base_v0 vc_data;
19868 +
19869 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19870 +               return -EFAULT;
19871 +
19872 +       return do_addrem_dlimit(id, vc_data.name, vc_data.flags, 1);
19873 +}
19874 +
19875 +int vc_rem_dlimit(uint32_t id, void __user *data)
19876 +{
19877 +       struct vcmd_ctx_dlimit_base_v0 vc_data;
19878 +
19879 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19880 +               return -EFAULT;
19881 +
19882 +       return do_addrem_dlimit(id, vc_data.name, vc_data.flags, 0);
19883 +}
19884 +
19885 +#ifdef CONFIG_COMPAT
19886 +
19887 +int vc_add_dlimit_x32(uint32_t id, void __user *data)
19888 +{
19889 +       struct vcmd_ctx_dlimit_base_v0_x32 vc_data;
19890 +
19891 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19892 +               return -EFAULT;
19893 +
19894 +       return do_addrem_dlimit(id,
19895 +               compat_ptr(vc_data.name_ptr), vc_data.flags, 1);
19896 +}
19897 +
19898 +int vc_rem_dlimit_x32(uint32_t id, void __user *data)
19899 +{
19900 +       struct vcmd_ctx_dlimit_base_v0_x32 vc_data;
19901 +
19902 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19903 +               return -EFAULT;
19904 +
19905 +       return do_addrem_dlimit(id,
19906 +               compat_ptr(vc_data.name_ptr), vc_data.flags, 0);
19907 +}
19908 +
19909 +#endif /* CONFIG_COMPAT */
19910 +
19911 +
19912 +static inline
19913 +int do_set_dlimit(uint32_t id, const char __user *name,
19914 +       uint32_t space_used, uint32_t space_total,
19915 +       uint32_t inodes_used, uint32_t inodes_total,
19916 +       uint32_t reserved, uint32_t flags)
19917 +{
19918 +       struct path path;
19919 +       int ret;
19920 +
19921 +       ret = user_lpath(name, &path);
19922 +       if (!ret) {
19923 +               struct super_block *sb;
19924 +               struct dl_info *dli;
19925 +
19926 +               ret = -EINVAL;
19927 +               if (!path.dentry->d_inode)
19928 +                       goto out_release;
19929 +               if (!(sb = path.dentry->d_inode->i_sb))
19930 +                       goto out_release;
19931 +
19932 +               /* sanity checks */
19933 +               if ((reserved != CDLIM_KEEP &&
19934 +                       reserved > 100) ||
19935 +                       (inodes_used != CDLIM_KEEP &&
19936 +                       inodes_used > inodes_total) ||
19937 +                       (space_used != CDLIM_KEEP &&
19938 +                       space_used > space_total))
19939 +                       goto out_release;
19940 +
19941 +               ret = -ESRCH;
19942 +               dli = locate_dl_info(sb, id);
19943 +               if (!dli)
19944 +                       goto out_release;
19945 +
19946 +               spin_lock(&dli->dl_lock);
19947 +
19948 +               if (inodes_used != CDLIM_KEEP)
19949 +                       dli->dl_inodes_used = inodes_used;
19950 +               if (inodes_total != CDLIM_KEEP)
19951 +                       dli->dl_inodes_total = inodes_total;
19952 +               if (space_used != CDLIM_KEEP)
19953 +                       dli->dl_space_used = dlimit_space_32to64(
19954 +                               space_used, flags, DLIMS_USED);
19955 +
19956 +               if (space_total == CDLIM_INFINITY)
19957 +                       dli->dl_space_total = DLIM_INFINITY;
19958 +               else if (space_total != CDLIM_KEEP)
19959 +                       dli->dl_space_total = dlimit_space_32to64(
19960 +                               space_total, flags, DLIMS_TOTAL);
19961 +
19962 +               if (reserved != CDLIM_KEEP)
19963 +                       dli->dl_nrlmult = (1 << 10) * (100 - reserved) / 100;
19964 +
19965 +               spin_unlock(&dli->dl_lock);
19966 +
19967 +               put_dl_info(dli);
19968 +               ret = 0;
19969 +
19970 +       out_release:
19971 +               path_put(&path);
19972 +       }
19973 +       return ret;
19974 +}
19975 +
19976 +int vc_set_dlimit(uint32_t id, void __user *data)
19977 +{
19978 +       struct vcmd_ctx_dlimit_v0 vc_data;
19979 +
19980 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19981 +               return -EFAULT;
19982 +
19983 +       return do_set_dlimit(id, vc_data.name,
19984 +               vc_data.space_used, vc_data.space_total,
19985 +               vc_data.inodes_used, vc_data.inodes_total,
19986 +               vc_data.reserved, vc_data.flags);
19987 +}
19988 +
19989 +#ifdef CONFIG_COMPAT
19990 +
19991 +int vc_set_dlimit_x32(uint32_t id, void __user *data)
19992 +{
19993 +       struct vcmd_ctx_dlimit_v0_x32 vc_data;
19994 +
19995 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19996 +               return -EFAULT;
19997 +
19998 +       return do_set_dlimit(id, compat_ptr(vc_data.name_ptr),
19999 +               vc_data.space_used, vc_data.space_total,
20000 +               vc_data.inodes_used, vc_data.inodes_total,
20001 +               vc_data.reserved, vc_data.flags);
20002 +}
20003 +
20004 +#endif /* CONFIG_COMPAT */
20005 +
20006 +
20007 +static inline
20008 +int do_get_dlimit(uint32_t id, const char __user *name,
20009 +       uint32_t *space_used, uint32_t *space_total,
20010 +       uint32_t *inodes_used, uint32_t *inodes_total,
20011 +       uint32_t *reserved, uint32_t *flags)
20012 +{
20013 +       struct path path;
20014 +       int ret;
20015 +
20016 +       ret = user_lpath(name, &path);
20017 +       if (!ret) {
20018 +               struct super_block *sb;
20019 +               struct dl_info *dli;
20020 +
20021 +               ret = -EINVAL;
20022 +               if (!path.dentry->d_inode)
20023 +                       goto out_release;
20024 +               if (!(sb = path.dentry->d_inode->i_sb))
20025 +                       goto out_release;
20026 +
20027 +               ret = -ESRCH;
20028 +               dli = locate_dl_info(sb, id);
20029 +               if (!dli)
20030 +                       goto out_release;
20031 +
20032 +               spin_lock(&dli->dl_lock);
20033 +               *inodes_used = dli->dl_inodes_used;
20034 +               *inodes_total = dli->dl_inodes_total;
20035 +
20036 +               *space_used = dlimit_space_64to32(
20037 +                       dli->dl_space_used, flags, DLIMS_USED);
20038 +
20039 +               if (dli->dl_space_total == DLIM_INFINITY)
20040 +                       *space_total = CDLIM_INFINITY;
20041 +               else
20042 +                       *space_total = dlimit_space_64to32(
20043 +                               dli->dl_space_total, flags, DLIMS_TOTAL);
20044 +
20045 +               *reserved = 100 - ((dli->dl_nrlmult * 100 + 512) >> 10);
20046 +               spin_unlock(&dli->dl_lock);
20047 +
20048 +               put_dl_info(dli);
20049 +               ret = -EFAULT;
20050 +
20051 +               ret = 0;
20052 +       out_release:
20053 +               path_put(&path);
20054 +       }
20055 +       return ret;
20056 +}
20057 +
20058 +
20059 +int vc_get_dlimit(uint32_t id, void __user *data)
20060 +{
20061 +       struct vcmd_ctx_dlimit_v0 vc_data;
20062 +       int ret;
20063 +
20064 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
20065 +               return -EFAULT;
20066 +
20067 +       ret = do_get_dlimit(id, vc_data.name,
20068 +               &vc_data.space_used, &vc_data.space_total,
20069 +               &vc_data.inodes_used, &vc_data.inodes_total,
20070 +               &vc_data.reserved, &vc_data.flags);
20071 +       if (ret)
20072 +               return ret;
20073 +
20074 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
20075 +               return -EFAULT;
20076 +       return 0;
20077 +}
20078 +
20079 +#ifdef CONFIG_COMPAT
20080 +
20081 +int vc_get_dlimit_x32(uint32_t id, void __user *data)
20082 +{
20083 +       struct vcmd_ctx_dlimit_v0_x32 vc_data;
20084 +       int ret;
20085 +
20086 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
20087 +               return -EFAULT;
20088 +
20089 +       ret = do_get_dlimit(id, compat_ptr(vc_data.name_ptr),
20090 +               &vc_data.space_used, &vc_data.space_total,
20091 +               &vc_data.inodes_used, &vc_data.inodes_total,
20092 +               &vc_data.reserved, &vc_data.flags);
20093 +       if (ret)
20094 +               return ret;
20095 +
20096 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
20097 +               return -EFAULT;
20098 +       return 0;
20099 +}
20100 +
20101 +#endif /* CONFIG_COMPAT */
20102 +
20103 +
20104 +void vx_vsi_statfs(struct super_block *sb, struct kstatfs *buf)
20105 +{
20106 +       struct dl_info *dli;
20107 +       __u64 blimit, bfree, bavail;
20108 +       __u32 ifree;
20109 +
20110 +       dli = locate_dl_info(sb, dx_current_tag());
20111 +       if (!dli)
20112 +               return;
20113 +
20114 +       spin_lock(&dli->dl_lock);
20115 +       if (dli->dl_inodes_total == (unsigned long)DLIM_INFINITY)
20116 +               goto no_ilim;
20117 +
20118 +       /* reduce max inodes available to limit */
20119 +       if (buf->f_files > dli->dl_inodes_total)
20120 +               buf->f_files = dli->dl_inodes_total;
20121 +
20122 +       ifree = dli->dl_inodes_total - dli->dl_inodes_used;
20123 +       /* reduce free inodes to min */
20124 +       if (ifree < buf->f_ffree)
20125 +               buf->f_ffree = ifree;
20126 +
20127 +no_ilim:
20128 +       if (dli->dl_space_total == DLIM_INFINITY)
20129 +               goto no_blim;
20130 +
20131 +       blimit = dli->dl_space_total >> sb->s_blocksize_bits;
20132 +
20133 +       if (dli->dl_space_total < dli->dl_space_used)
20134 +               bfree = 0;
20135 +       else
20136 +               bfree = (dli->dl_space_total - dli->dl_space_used)
20137 +                       >> sb->s_blocksize_bits;
20138 +
20139 +       bavail = ((dli->dl_space_total >> 10) * dli->dl_nrlmult);
20140 +       if (bavail < dli->dl_space_used)
20141 +               bavail = 0;
20142 +       else
20143 +               bavail = (bavail - dli->dl_space_used)
20144 +                       >> sb->s_blocksize_bits;
20145 +
20146 +       /* reduce max space available to limit */
20147 +       if (buf->f_blocks > blimit)
20148 +               buf->f_blocks = blimit;
20149 +
20150 +       /* reduce free space to min */
20151 +       if (bfree < buf->f_bfree)
20152 +               buf->f_bfree = bfree;
20153 +
20154 +       /* reduce avail space to min */
20155 +       if (bavail < buf->f_bavail)
20156 +               buf->f_bavail = bavail;
20157 +
20158 +no_blim:
20159 +       spin_unlock(&dli->dl_lock);
20160 +       put_dl_info(dli);
20161 +
20162 +       return;
20163 +}
20164 +
20165 +#include <linux/module.h>
20166 +
20167 +EXPORT_SYMBOL_GPL(locate_dl_info);
20168 +EXPORT_SYMBOL_GPL(rcu_free_dl_info);
20169 +
20170 diff -NurpP --minimal linux-2.6.32.1/kernel/vserver/helper.c linux-2.6.32.1-vs2.3.0.36.27/kernel/vserver/helper.c
20171 --- linux-2.6.32.1/kernel/vserver/helper.c      1970-01-01 01:00:00.000000000 +0100
20172 +++ linux-2.6.32.1-vs2.3.0.36.27/kernel/vserver/helper.c        2009-12-03 22:20:22.000000000 +0100
20173 @@ -0,0 +1,223 @@
20174 +/*
20175 + *  linux/kernel/vserver/helper.c
20176 + *
20177 + *  Virtual Context Support
20178 + *
20179 + *  Copyright (C) 2004-2007  Herbert Pötzl
20180 + *
20181 + *  V0.01  basic helper
20182 + *
20183 + */
20184 +
20185 +#include <linux/kmod.h>
20186 +#include <linux/reboot.h>
20187 +#include <linux/vs_context.h>
20188 +#include <linux/vs_network.h>
20189 +#include <linux/vserver/signal.h>
20190 +
20191 +
20192 +char vshelper_path[255] = "/sbin/vshelper";
20193 +
20194 +
20195 +static int do_vshelper(char *name, char *argv[], char *envp[], int sync)
20196 +{
20197 +       int ret;
20198 +
20199 +       if ((ret = call_usermodehelper(name, argv, envp, sync))) {
20200 +               printk( KERN_WARNING
20201 +                       "%s: (%s %s) returned %s with %d\n",
20202 +                       name, argv[1], argv[2],
20203 +                       sync ? "sync" : "async", ret);
20204 +       }
20205 +       vxdprintk(VXD_CBIT(switch, 4),
20206 +               "%s: (%s %s) returned %s with %d",
20207 +               name, argv[1], argv[2], sync ? "sync" : "async", ret);
20208 +       return ret;
20209 +}
20210 +
20211 +/*
20212 + *      vshelper path is set via /proc/sys
20213 + *      invoked by vserver sys_reboot(), with
20214 + *      the following arguments
20215 + *
20216 + *      argv [0] = vshelper_path;
20217 + *      argv [1] = action: "restart", "halt", "poweroff", ...
20218 + *      argv [2] = context identifier
20219 + *
20220 + *      envp [*] = type-specific parameters
20221 + */
20222 +
20223 +long vs_reboot_helper(struct vx_info *vxi, int cmd, void __user *arg)
20224 +{
20225 +       char id_buf[8], cmd_buf[16];
20226 +       char uid_buf[16], pid_buf[16];
20227 +       int ret;
20228 +
20229 +       char *argv[] = {vshelper_path, NULL, id_buf, 0};
20230 +       char *envp[] = {"HOME=/", "TERM=linux",
20231 +                       "PATH=/sbin:/usr/sbin:/bin:/usr/bin",
20232 +                       uid_buf, pid_buf, cmd_buf, 0};
20233 +
20234 +       if (vx_info_state(vxi, VXS_HELPER))
20235 +               return -EAGAIN;
20236 +       vxi->vx_state |= VXS_HELPER;
20237 +
20238 +       snprintf(id_buf, sizeof(id_buf)-1, "%d", vxi->vx_id);
20239 +
20240 +       snprintf(cmd_buf, sizeof(cmd_buf)-1, "VS_CMD=%08x", cmd);
20241 +       snprintf(uid_buf, sizeof(uid_buf)-1, "VS_UID=%d", current_uid());
20242 +       snprintf(pid_buf, sizeof(pid_buf)-1, "VS_PID=%d", current->pid);
20243 +
20244 +       switch (cmd) {
20245 +       case LINUX_REBOOT_CMD_RESTART:
20246 +               argv[1] = "restart";
20247 +               break;
20248 +
20249 +       case LINUX_REBOOT_CMD_HALT:
20250 +               argv[1] = "halt";
20251 +               break;
20252 +
20253 +       case LINUX_REBOOT_CMD_POWER_OFF:
20254 +               argv[1] = "poweroff";
20255 +               break;
20256 +
20257 +       case LINUX_REBOOT_CMD_SW_SUSPEND:
20258 +               argv[1] = "swsusp";
20259 +               break;
20260 +
20261 +       case LINUX_REBOOT_CMD_OOM:
20262 +               argv[1] = "oom";
20263 +               break;
20264 +
20265 +       default:
20266 +               vxi->vx_state &= ~VXS_HELPER;
20267 +               return 0;
20268 +       }
20269 +
20270 +       ret = do_vshelper(vshelper_path, argv, envp, 0);
20271 +       vxi->vx_state &= ~VXS_HELPER;
20272 +       __wakeup_vx_info(vxi);
20273 +       return (ret) ? -EPERM : 0;
20274 +}
20275 +
20276 +
20277 +long vs_reboot(unsigned int cmd, void __user *arg)
20278 +{
20279 +       struct vx_info *vxi = current_vx_info();
20280 +       long ret = 0;
20281 +
20282 +       vxdprintk(VXD_CBIT(misc, 5),
20283 +               "vs_reboot(%p[#%d],%u)",
20284 +               vxi, vxi ? vxi->vx_id : 0, cmd);
20285 +
20286 +       ret = vs_reboot_helper(vxi, cmd, arg);
20287 +       if (ret)
20288 +               return ret;
20289 +
20290 +       vxi->reboot_cmd = cmd;
20291 +       if (vx_info_flags(vxi, VXF_REBOOT_KILL, 0)) {
20292 +               switch (cmd) {
20293 +               case LINUX_REBOOT_CMD_RESTART:
20294 +               case LINUX_REBOOT_CMD_HALT:
20295 +               case LINUX_REBOOT_CMD_POWER_OFF:
20296 +                       vx_info_kill(vxi, 0, SIGKILL);
20297 +                       vx_info_kill(vxi, 1, SIGKILL);
20298 +               default:
20299 +                       break;
20300 +               }
20301 +       }
20302 +       return 0;
20303 +}
20304 +
20305 +long vs_oom_action(unsigned int cmd)
20306 +{
20307 +       struct vx_info *vxi = current_vx_info();
20308 +       long ret = 0;
20309 +
20310 +       vxdprintk(VXD_CBIT(misc, 5),
20311 +               "vs_oom_action(%p[#%d],%u)",
20312 +               vxi, vxi ? vxi->vx_id : 0, cmd);
20313 +
20314 +       ret = vs_reboot_helper(vxi, cmd, NULL);
20315 +       if (ret)
20316 +               return ret;
20317 +
20318 +       vxi->reboot_cmd = cmd;
20319 +       if (vx_info_flags(vxi, VXF_REBOOT_KILL, 0)) {
20320 +               vx_info_kill(vxi, 0, SIGKILL);
20321 +               vx_info_kill(vxi, 1, SIGKILL);
20322 +       }
20323 +       return 0;
20324 +}
20325 +
20326 +/*
20327 + *      argv [0] = vshelper_path;
20328 + *      argv [1] = action: "startup", "shutdown"
20329 + *      argv [2] = context identifier
20330 + *
20331 + *      envp [*] = type-specific parameters
20332 + */
20333 +
20334 +long vs_state_change(struct vx_info *vxi, unsigned int cmd)
20335 +{
20336 +       char id_buf[8], cmd_buf[16];
20337 +       char *argv[] = {vshelper_path, NULL, id_buf, 0};
20338 +       char *envp[] = {"HOME=/", "TERM=linux",
20339 +                       "PATH=/sbin:/usr/sbin:/bin:/usr/bin", cmd_buf, 0};
20340 +
20341 +       if (!vx_info_flags(vxi, VXF_SC_HELPER, 0))
20342 +               return 0;
20343 +
20344 +       snprintf(id_buf, sizeof(id_buf)-1, "%d", vxi->vx_id);
20345 +       snprintf(cmd_buf, sizeof(cmd_buf)-1, "VS_CMD=%08x", cmd);
20346 +
20347 +       switch (cmd) {
20348 +       case VSC_STARTUP:
20349 +               argv[1] = "startup";
20350 +               break;
20351 +       case VSC_SHUTDOWN:
20352 +               argv[1] = "shutdown";
20353 +               break;
20354 +       default:
20355 +               return 0;
20356 +       }
20357 +
20358 +       return do_vshelper(vshelper_path, argv, envp, 1);
20359 +}
20360 +
20361 +
20362 +/*
20363 + *      argv [0] = vshelper_path;
20364 + *      argv [1] = action: "netup", "netdown"
20365 + *      argv [2] = context identifier
20366 + *
20367 + *      envp [*] = type-specific parameters
20368 + */
20369 +
20370 +long vs_net_change(struct nx_info *nxi, unsigned int cmd)
20371 +{
20372 +       char id_buf[8], cmd_buf[16];
20373 +       char *argv[] = {vshelper_path, NULL, id_buf, 0};
20374 +       char *envp[] = {"HOME=/", "TERM=linux",
20375 +                       "PATH=/sbin:/usr/sbin:/bin:/usr/bin", cmd_buf, 0};
20376 +
20377 +       if (!nx_info_flags(nxi, NXF_SC_HELPER, 0))
20378 +               return 0;
20379 +
20380 +       snprintf(id_buf, sizeof(id_buf)-1, "%d", nxi->nx_id);
20381 +       snprintf(cmd_buf, sizeof(cmd_buf)-1, "VS_CMD=%08x", cmd);
20382 +
20383 +       switch (cmd) {
20384 +       case VSC_NETUP:
20385 +               argv[1] = "netup";
20386 +               break;
20387 +       case VSC_NETDOWN:
20388 +               argv[1] = "netdown";
20389 +               break;
20390 +       default:
20391 +               return 0;
20392 +       }
20393 +
20394 +       return do_vshelper(vshelper_path, argv, envp, 1);
20395 +}
20396 +
20397 diff -NurpP --minimal linux-2.6.32.1/kernel/vserver/history.c linux-2.6.32.1-vs2.3.0.36.27/kernel/vserver/history.c
20398 --- linux-2.6.32.1/kernel/vserver/history.c     1970-01-01 01:00:00.000000000 +0100
20399 +++ linux-2.6.32.1-vs2.3.0.36.27/kernel/vserver/history.c       2009-12-03 20:04:56.000000000 +0100
20400 @@ -0,0 +1,258 @@
20401 +/*
20402 + *  kernel/vserver/history.c
20403 + *
20404 + *  Virtual Context History Backtrace
20405 + *
20406 + *  Copyright (C) 2004-2007  Herbert Pötzl
20407 + *
20408 + *  V0.01  basic structure
20409 + *  V0.02  hash/unhash and trace
20410 + *  V0.03  preemption fixes
20411 + *
20412 + */
20413 +
20414 +#include <linux/module.h>
20415 +#include <asm/uaccess.h>
20416 +
20417 +#include <linux/vserver/context.h>
20418 +#include <linux/vserver/debug.h>
20419 +#include <linux/vserver/debug_cmd.h>
20420 +#include <linux/vserver/history.h>
20421 +
20422 +
20423 +#ifdef CONFIG_VSERVER_HISTORY
20424 +#define VXH_SIZE       CONFIG_VSERVER_HISTORY_SIZE
20425 +#else
20426 +#define VXH_SIZE       64
20427 +#endif
20428 +
20429 +struct _vx_history {
20430 +       unsigned int counter;
20431 +
20432 +       struct _vx_hist_entry entry[VXH_SIZE + 1];
20433 +};
20434 +
20435 +
20436 +DEFINE_PER_CPU(struct _vx_history, vx_history_buffer);
20437 +
20438 +unsigned volatile int vxh_active = 1;
20439 +
20440 +static atomic_t sequence = ATOMIC_INIT(0);
20441 +
20442 +
20443 +/*     vxh_advance()
20444 +
20445 +       * requires disabled preemption                          */
20446 +
20447 +struct _vx_hist_entry *vxh_advance(void *loc)
20448 +{
20449 +       unsigned int cpu = smp_processor_id();
20450 +       struct _vx_history *hist = &per_cpu(vx_history_buffer, cpu);
20451 +       struct _vx_hist_entry *entry;
20452 +       unsigned int index;
20453 +
20454 +       index = vxh_active ? (hist->counter++ % VXH_SIZE) : VXH_SIZE;
20455 +       entry = &hist->entry[index];
20456 +
20457 +       entry->seq = atomic_inc_return(&sequence);
20458 +       entry->loc = loc;
20459 +       return entry;
20460 +}
20461 +
20462 +EXPORT_SYMBOL_GPL(vxh_advance);
20463 +
20464 +
20465 +#define VXH_LOC_FMTS   "(#%04x,*%d):%p"
20466 +
20467 +#define VXH_LOC_ARGS(e)        (e)->seq, cpu, (e)->loc
20468 +
20469 +
20470 +#define VXH_VXI_FMTS   "%p[#%d,%d.%d]"
20471 +
20472 +#define VXH_VXI_ARGS(e)        (e)->vxi.ptr,                           \
20473 +                       (e)->vxi.ptr ? (e)->vxi.xid : 0,        \
20474 +                       (e)->vxi.ptr ? (e)->vxi.usecnt : 0,     \
20475 +                       (e)->vxi.ptr ? (e)->vxi.tasks : 0
20476 +
20477 +void   vxh_dump_entry(struct _vx_hist_entry *e, unsigned cpu)
20478 +{
20479 +       switch (e->type) {
20480 +       case VXH_THROW_OOPS:
20481 +               printk( VXH_LOC_FMTS " oops \n", VXH_LOC_ARGS(e));
20482 +               break;
20483 +
20484 +       case VXH_GET_VX_INFO:
20485 +       case VXH_PUT_VX_INFO:
20486 +               printk( VXH_LOC_FMTS " %s_vx_info " VXH_VXI_FMTS "\n",
20487 +                       VXH_LOC_ARGS(e),
20488 +                       (e->type == VXH_GET_VX_INFO) ? "get" : "put",
20489 +                       VXH_VXI_ARGS(e));
20490 +               break;
20491 +
20492 +       case VXH_INIT_VX_INFO:
20493 +       case VXH_SET_VX_INFO:
20494 +       case VXH_CLR_VX_INFO:
20495 +               printk( VXH_LOC_FMTS " %s_vx_info " VXH_VXI_FMTS " @%p\n",
20496 +                       VXH_LOC_ARGS(e),
20497 +                       (e->type == VXH_INIT_VX_INFO) ? "init" :
20498 +                       ((e->type == VXH_SET_VX_INFO) ? "set" : "clr"),
20499 +                       VXH_VXI_ARGS(e), e->sc.data);
20500 +               break;
20501 +
20502 +       case VXH_CLAIM_VX_INFO:
20503 +       case VXH_RELEASE_VX_INFO:
20504 +               printk( VXH_LOC_FMTS " %s_vx_info " VXH_VXI_FMTS " @%p\n",
20505 +                       VXH_LOC_ARGS(e),
20506 +                       (e->type == VXH_CLAIM_VX_INFO) ? "claim" : "release",
20507 +                       VXH_VXI_ARGS(e), e->sc.data);
20508 +               break;
20509 +
20510 +       case VXH_ALLOC_VX_INFO:
20511 +       case VXH_DEALLOC_VX_INFO:
20512 +               printk( VXH_LOC_FMTS " %s_vx_info " VXH_VXI_FMTS "\n",
20513 +                       VXH_LOC_ARGS(e),
20514 +                       (e->type == VXH_ALLOC_VX_INFO) ? "alloc" : "dealloc",
20515 +                       VXH_VXI_ARGS(e));
20516 +               break;
20517 +
20518 +       case VXH_HASH_VX_INFO:
20519 +       case VXH_UNHASH_VX_INFO:
20520 +               printk( VXH_LOC_FMTS " __%s_vx_info " VXH_VXI_FMTS "\n",
20521 +                       VXH_LOC_ARGS(e),
20522 +                       (e->type == VXH_HASH_VX_INFO) ? "hash" : "unhash",
20523 +                       VXH_VXI_ARGS(e));
20524 +               break;
20525 +
20526 +       case VXH_LOC_VX_INFO:
20527 +       case VXH_LOOKUP_VX_INFO:
20528 +       case VXH_CREATE_VX_INFO:
20529 +               printk( VXH_LOC_FMTS " __%s_vx_info [#%d] -> " VXH_VXI_FMTS "\n",
20530 +                       VXH_LOC_ARGS(e),
20531 +                       (e->type == VXH_CREATE_VX_INFO) ? "create" :
20532 +                       ((e->type == VXH_LOC_VX_INFO) ? "loc" : "lookup"),
20533 +                       e->ll.arg, VXH_VXI_ARGS(e));
20534 +               break;
20535 +       }
20536 +}
20537 +
20538 +static void __vxh_dump_history(void)
20539 +{
20540 +       unsigned int i, cpu;
20541 +
20542 +       printk("History:\tSEQ: %8x\tNR_CPUS: %d\n",
20543 +               atomic_read(&sequence), NR_CPUS);
20544 +
20545 +       for (i = 0; i < VXH_SIZE; i++) {
20546 +               for_each_online_cpu(cpu) {
20547 +                       struct _vx_history *hist =
20548 +                               &per_cpu(vx_history_buffer, cpu);
20549 +                       unsigned int index = (hist->counter - i) % VXH_SIZE;
20550 +                       struct _vx_hist_entry *entry = &hist->entry[index];
20551 +
20552 +                       vxh_dump_entry(entry, cpu);
20553 +               }
20554 +       }
20555 +}
20556 +
20557 +void   vxh_dump_history(void)
20558 +{
20559 +       vxh_active = 0;
20560 +#ifdef CONFIG_SMP
20561 +       local_irq_enable();
20562 +       smp_send_stop();
20563 +       local_irq_disable();
20564 +#endif
20565 +       __vxh_dump_history();
20566 +}
20567 +
20568 +
20569 +/* vserver syscall commands below here */
20570 +
20571 +
20572 +int vc_dump_history(uint32_t id)
20573 +{
20574 +       vxh_active = 0;
20575 +       __vxh_dump_history();
20576 +       vxh_active = 1;
20577 +
20578 +       return 0;
20579 +}
20580 +
20581 +
20582 +int do_read_history(struct __user _vx_hist_entry *data,
20583 +       int cpu, uint32_t *index, uint32_t *count)
20584 +{
20585 +       int pos, ret = 0;
20586 +       struct _vx_history *hist = &per_cpu(vx_history_buffer, cpu);
20587 +       int end = hist->counter;
20588 +       int start = end - VXH_SIZE + 2;
20589 +       int idx = *index;
20590 +
20591 +       /* special case: get current pos */
20592 +       if (!*count) {
20593 +               *index = end;
20594 +               return 0;
20595 +       }
20596 +
20597 +       /* have we lost some data? */
20598 +       if (idx < start)
20599 +               idx = start;
20600 +
20601 +       for (pos = 0; (pos < *count) && (idx < end); pos++, idx++) {
20602 +               struct _vx_hist_entry *entry =
20603 +                       &hist->entry[idx % VXH_SIZE];
20604 +
20605 +               /* send entry to userspace */
20606 +               ret = copy_to_user(&data[pos], entry, sizeof(*entry));
20607 +               if (ret)
20608 +                       break;
20609 +       }
20610 +       /* save new index and count */
20611 +       *index = idx;
20612 +       *count = pos;
20613 +       return ret ? ret : (*index < end);
20614 +}
20615 +
20616 +int vc_read_history(uint32_t id, void __user *data)
20617 +{
20618 +       struct vcmd_read_history_v0 vc_data;
20619 +       int ret;
20620 +
20621 +       if (id >= NR_CPUS)
20622 +               return -EINVAL;
20623 +
20624 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
20625 +               return -EFAULT;
20626 +
20627 +       ret = do_read_history((struct __user _vx_hist_entry *)vc_data.data,
20628 +               id, &vc_data.index, &vc_data.count);
20629 +
20630 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
20631 +               return -EFAULT;
20632 +       return ret;
20633 +}
20634 +
20635 +#ifdef CONFIG_COMPAT
20636 +
20637 +int vc_read_history_x32(uint32_t id, void __user *data)
20638 +{
20639 +       struct vcmd_read_history_v0_x32 vc_data;
20640 +       int ret;
20641 +
20642 +       if (id >= NR_CPUS)
20643 +               return -EINVAL;
20644 +
20645 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
20646 +               return -EFAULT;
20647 +
20648 +       ret = do_read_history((struct __user _vx_hist_entry *)
20649 +               compat_ptr(vc_data.data_ptr),
20650 +               id, &vc_data.index, &vc_data.count);
20651 +
20652 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
20653 +               return -EFAULT;
20654 +       return ret;
20655 +}
20656 +
20657 +#endif /* CONFIG_COMPAT */
20658 +
20659 diff -NurpP --minimal linux-2.6.32.1/kernel/vserver/inet.c linux-2.6.32.1-vs2.3.0.36.27/kernel/vserver/inet.c
20660 --- linux-2.6.32.1/kernel/vserver/inet.c        1970-01-01 01:00:00.000000000 +0100
20661 +++ linux-2.6.32.1-vs2.3.0.36.27/kernel/vserver/inet.c  2009-12-03 20:04:56.000000000 +0100
20662 @@ -0,0 +1,225 @@
20663 +
20664 +#include <linux/in.h>
20665 +#include <linux/inetdevice.h>
20666 +#include <linux/vs_inet.h>
20667 +#include <linux/vs_inet6.h>
20668 +#include <linux/vserver/debug.h>
20669 +#include <net/route.h>
20670 +#include <net/addrconf.h>
20671 +
20672 +
20673 +int nx_v4_addr_conflict(struct nx_info *nxi1, struct nx_info *nxi2)
20674 +{
20675 +       int ret = 0;
20676 +
20677 +       if (!nxi1 || !nxi2 || nxi1 == nxi2)
20678 +               ret = 1;
20679 +       else {
20680 +               struct nx_addr_v4 *ptr;
20681 +
20682 +               for (ptr = &nxi1->v4; ptr; ptr = ptr->next) {
20683 +                       if (v4_nx_addr_in_nx_info(nxi2, ptr, -1)) {
20684 +                               ret = 1;
20685 +                               break;
20686 +                       }
20687 +               }
20688 +       }
20689 +
20690 +       vxdprintk(VXD_CBIT(net, 2),
20691 +               "nx_v4_addr_conflict(%p,%p): %d",
20692 +               nxi1, nxi2, ret);
20693 +
20694 +       return ret;
20695 +}
20696 +
20697 +
20698 +#ifdef CONFIG_IPV6
20699 +
20700 +int nx_v6_addr_conflict(struct nx_info *nxi1, struct nx_info *nxi2)
20701 +{
20702 +       int ret = 0;
20703 +
20704 +       if (!nxi1 || !nxi2 || nxi1 == nxi2)
20705 +               ret = 1;
20706 +       else {
20707 +               struct nx_addr_v6 *ptr;
20708 +
20709 +               for (ptr = &nxi1->v6; ptr; ptr = ptr->next) {
20710 +                       if (v6_nx_addr_in_nx_info(nxi2, ptr, -1)) {
20711 +                               ret = 1;
20712 +                               break;
20713 +                       }
20714 +               }
20715 +       }
20716 +
20717 +       vxdprintk(VXD_CBIT(net, 2),
20718 +               "nx_v6_addr_conflict(%p,%p): %d",
20719 +               nxi1, nxi2, ret);
20720 +
20721 +       return ret;
20722 +}
20723 +
20724 +#endif
20725 +
20726 +int v4_dev_in_nx_info(struct net_device *dev, struct nx_info *nxi)
20727 +{
20728 +       struct in_device *in_dev;
20729 +       struct in_ifaddr **ifap;
20730 +       struct in_ifaddr *ifa;
20731 +       int ret = 0;
20732 +
20733 +       if (!dev)
20734 +               goto out;
20735 +       in_dev = in_dev_get(dev);
20736 +       if (!in_dev)
20737 +               goto out;
20738 +
20739 +       for (ifap = &in_dev->ifa_list; (ifa = *ifap) != NULL;
20740 +               ifap = &ifa->ifa_next) {
20741 +               if (v4_addr_in_nx_info(nxi, ifa->ifa_local, NXA_MASK_SHOW)) {
20742 +                       ret = 1;
20743 +                       break;
20744 +               }
20745 +       }
20746 +       in_dev_put(in_dev);
20747 +out:
20748 +       return ret;
20749 +}
20750 +
20751 +
20752 +#ifdef CONFIG_IPV6
20753 +
20754 +int v6_dev_in_nx_info(struct net_device *dev, struct nx_info *nxi)
20755 +{
20756 +       struct inet6_dev *in_dev;
20757 +       struct inet6_ifaddr **ifap;
20758 +       struct inet6_ifaddr *ifa;
20759 +       int ret = 0;
20760 +
20761 +       if (!dev)
20762 +               goto out;
20763 +       in_dev = in6_dev_get(dev);
20764 +       if (!in_dev)
20765 +               goto out;
20766 +
20767 +       for (ifap = &in_dev->addr_list; (ifa = *ifap) != NULL;
20768 +               ifap = &ifa->if_next) {
20769 +               if (v6_addr_in_nx_info(nxi, &ifa->addr, -1)) {
20770 +                       ret = 1;
20771 +                       break;
20772 +               }
20773 +       }
20774 +       in6_dev_put(in_dev);
20775 +out:
20776 +       return ret;
20777 +}
20778 +
20779 +#endif
20780 +
20781 +int dev_in_nx_info(struct net_device *dev, struct nx_info *nxi)
20782 +{
20783 +       int ret = 1;
20784 +
20785 +       if (!nxi)
20786 +               goto out;
20787 +       if (nxi->v4.type && v4_dev_in_nx_info(dev, nxi))
20788 +               goto out;
20789 +#ifdef CONFIG_IPV6
20790 +       ret = 2;
20791 +       if (nxi->v6.type && v6_dev_in_nx_info(dev, nxi))
20792 +               goto out;
20793 +#endif
20794 +       ret = 0;
20795 +out:
20796 +       vxdprintk(VXD_CBIT(net, 3),
20797 +               "dev_in_nx_info(%p,%p[#%d]) = %d",
20798 +               dev, nxi, nxi ? nxi->nx_id : 0, ret);
20799 +       return ret;
20800 +}
20801 +
20802 +int ip_v4_find_src(struct net *net, struct nx_info *nxi,
20803 +       struct rtable **rp, struct flowi *fl)
20804 +{
20805 +       if (!nxi)
20806 +               return 0;
20807 +
20808 +       /* FIXME: handle lback only case */
20809 +       if (!NX_IPV4(nxi))
20810 +               return -EPERM;
20811 +
20812 +       vxdprintk(VXD_CBIT(net, 4),
20813 +               "ip_v4_find_src(%p[#%u]) " NIPQUAD_FMT " -> " NIPQUAD_FMT,
20814 +               nxi, nxi ? nxi->nx_id : 0,
20815 +               NIPQUAD(fl->fl4_src), NIPQUAD(fl->fl4_dst));
20816 +
20817 +       /* single IP is unconditional */
20818 +       if (nx_info_flags(nxi, NXF_SINGLE_IP, 0) &&
20819 +               (fl->fl4_src == INADDR_ANY))
20820 +               fl->fl4_src = nxi->v4.ip[0].s_addr;
20821 +
20822 +       if (fl->fl4_src == INADDR_ANY) {
20823 +               struct nx_addr_v4 *ptr;
20824 +               __be32 found = 0;
20825 +               int err;
20826 +
20827 +               err = __ip_route_output_key(net, rp, fl);
20828 +               if (!err) {
20829 +                       found = (*rp)->rt_src;
20830 +                       ip_rt_put(*rp);
20831 +                       vxdprintk(VXD_CBIT(net, 4),
20832 +                               "ip_v4_find_src(%p[#%u]) rok[%u]: " NIPQUAD_FMT,
20833 +                               nxi, nxi ? nxi->nx_id : 0, fl->oif, NIPQUAD(found));
20834 +                       if (v4_addr_in_nx_info(nxi, found, NXA_MASK_BIND))
20835 +                               goto found;
20836 +               }
20837 +
20838 +               for (ptr = &nxi->v4; ptr; ptr = ptr->next) {
20839 +                       __be32 primary = ptr->ip[0].s_addr;
20840 +                       __be32 mask = ptr->mask.s_addr;
20841 +                       __be32 neta = primary & mask;
20842 +
20843 +                       vxdprintk(VXD_CBIT(net, 4), "ip_v4_find_src(%p[#%u]) chk: "
20844 +                               NIPQUAD_FMT "/" NIPQUAD_FMT "/" NIPQUAD_FMT,
20845 +                               nxi, nxi ? nxi->nx_id : 0, NIPQUAD(primary),
20846 +                               NIPQUAD(mask), NIPQUAD(neta));
20847 +                       if ((found & mask) != neta)
20848 +                               continue;
20849 +
20850 +                       fl->fl4_src = primary;
20851 +                       err = __ip_route_output_key(net, rp, fl);
20852 +                       vxdprintk(VXD_CBIT(net, 4),
20853 +                               "ip_v4_find_src(%p[#%u]) rok[%u]: " NIPQUAD_FMT,
20854 +                               nxi, nxi ? nxi->nx_id : 0, fl->oif, NIPQUAD(primary));
20855 +                       if (!err) {
20856 +                               found = (*rp)->rt_src;
20857 +                               ip_rt_put(*rp);
20858 +                               if (found == primary)
20859 +                                       goto found;
20860 +                       }
20861 +               }
20862 +               /* still no source ip? */
20863 +               found = ipv4_is_loopback(fl->fl4_dst)
20864 +                       ? IPI_LOOPBACK : nxi->v4.ip[0].s_addr;
20865 +       found:
20866 +               /* assign src ip to flow */
20867 +               fl->fl4_src = found;
20868 +
20869 +       } else {
20870 +               if (!v4_addr_in_nx_info(nxi, fl->fl4_src, NXA_MASK_BIND))
20871 +                       return -EPERM;
20872 +       }
20873 +
20874 +       if (nx_info_flags(nxi, NXF_LBACK_REMAP, 0)) {
20875 +               if (ipv4_is_loopback(fl->fl4_dst))
20876 +                       fl->fl4_dst = nxi->v4_lback.s_addr;
20877 +               if (ipv4_is_loopback(fl->fl4_src))
20878 +                       fl->fl4_src = nxi->v4_lback.s_addr;
20879 +       } else if (ipv4_is_loopback(fl->fl4_dst) &&
20880 +               !nx_info_flags(nxi, NXF_LBACK_ALLOW, 0))
20881 +               return -EPERM;
20882 +
20883 +       return 0;
20884 +}
20885 +
20886 +EXPORT_SYMBOL_GPL(ip_v4_find_src);
20887 +
20888 diff -NurpP --minimal linux-2.6.32.1/kernel/vserver/init.c linux-2.6.32.1-vs2.3.0.36.27/kernel/vserver/init.c
20889 --- linux-2.6.32.1/kernel/vserver/init.c        1970-01-01 01:00:00.000000000 +0100
20890 +++ linux-2.6.32.1-vs2.3.0.36.27/kernel/vserver/init.c  2009-12-03 20:04:56.000000000 +0100
20891 @@ -0,0 +1,45 @@
20892 +/*
20893 + *  linux/kernel/init.c
20894 + *
20895 + *  Virtual Server Init
20896 + *
20897 + *  Copyright (C) 2004-2007  Herbert Pötzl
20898 + *
20899 + *  V0.01  basic structure
20900 + *
20901 + */
20902 +
20903 +#include <linux/init.h>
20904 +
20905 +int    vserver_register_sysctl(void);
20906 +void   vserver_unregister_sysctl(void);
20907 +
20908 +
20909 +static int __init init_vserver(void)
20910 +{
20911 +       int ret = 0;
20912 +
20913 +#ifdef CONFIG_VSERVER_DEBUG
20914 +       vserver_register_sysctl();
20915 +#endif
20916 +       return ret;
20917 +}
20918 +
20919 +
20920 +static void __exit exit_vserver(void)
20921 +{
20922 +
20923 +#ifdef CONFIG_VSERVER_DEBUG
20924 +       vserver_unregister_sysctl();
20925 +#endif
20926 +       return;
20927 +}
20928 +
20929 +/* FIXME: GFP_ZONETYPES gone
20930 +long vx_slab[GFP_ZONETYPES]; */
20931 +long vx_area;
20932 +
20933 +
20934 +module_init(init_vserver);
20935 +module_exit(exit_vserver);
20936 +
20937 diff -NurpP --minimal linux-2.6.32.1/kernel/vserver/inode.c linux-2.6.32.1-vs2.3.0.36.27/kernel/vserver/inode.c
20938 --- linux-2.6.32.1/kernel/vserver/inode.c       1970-01-01 01:00:00.000000000 +0100
20939 +++ linux-2.6.32.1-vs2.3.0.36.27/kernel/vserver/inode.c 2009-12-03 20:04:56.000000000 +0100
20940 @@ -0,0 +1,433 @@
20941 +/*
20942 + *  linux/kernel/vserver/inode.c
20943 + *
20944 + *  Virtual Server: File System Support
20945 + *
20946 + *  Copyright (C) 2004-2007  Herbert Pötzl
20947 + *
20948 + *  V0.01  separated from vcontext V0.05
20949 + *  V0.02  moved to tag (instead of xid)
20950 + *
20951 + */
20952 +
20953 +#include <linux/tty.h>
20954 +#include <linux/proc_fs.h>
20955 +#include <linux/devpts_fs.h>
20956 +#include <linux/fs.h>
20957 +#include <linux/file.h>
20958 +#include <linux/mount.h>
20959 +#include <linux/parser.h>
20960 +#include <linux/namei.h>
20961 +#include <linux/vserver/inode.h>
20962 +#include <linux/vserver/inode_cmd.h>
20963 +#include <linux/vs_base.h>
20964 +#include <linux/vs_tag.h>
20965 +
20966 +#include <asm/uaccess.h>
20967 +
20968 +
20969 +static int __vc_get_iattr(struct inode *in, uint32_t *tag, uint32_t *flags, uint32_t *mask)
20970 +{
20971 +       struct proc_dir_entry *entry;
20972 +
20973 +       if (!in || !in->i_sb)
20974 +               return -ESRCH;
20975 +
20976 +       *flags = IATTR_TAG
20977 +               | (IS_IMMUTABLE(in) ? IATTR_IMMUTABLE : 0)
20978 +               | (IS_IXUNLINK(in) ? IATTR_IXUNLINK : 0)
20979 +               | (IS_BARRIER(in) ? IATTR_BARRIER : 0)
20980 +               | (IS_COW(in) ? IATTR_COW : 0);
20981 +       *mask = IATTR_IXUNLINK | IATTR_IMMUTABLE | IATTR_COW;
20982 +
20983 +       if (S_ISDIR(in->i_mode))
20984 +               *mask |= IATTR_BARRIER;
20985 +
20986 +       if (IS_TAGGED(in)) {
20987 +               *tag = in->i_tag;
20988 +               *mask |= IATTR_TAG;
20989 +       }
20990 +
20991 +       switch (in->i_sb->s_magic) {
20992 +       case PROC_SUPER_MAGIC:
20993 +               entry = PROC_I(in)->pde;
20994 +
20995 +               /* check for specific inodes? */
20996 +               if (entry)
20997 +                       *mask |= IATTR_FLAGS;
20998 +               if (entry)
20999 +                       *flags |= (entry->vx_flags & IATTR_FLAGS);
21000 +               else
21001 +                       *flags |= (PROC_I(in)->vx_flags & IATTR_FLAGS);
21002 +               break;
21003 +
21004 +       case DEVPTS_SUPER_MAGIC:
21005 +               *tag = in->i_tag;
21006 +               *mask |= IATTR_TAG;
21007 +               break;
21008 +
21009 +       default:
21010 +               break;
21011 +       }
21012 +       return 0;
21013 +}
21014 +
21015 +int vc_get_iattr(void __user *data)
21016 +{
21017 +       struct path path;
21018 +       struct vcmd_ctx_iattr_v1 vc_data = { .tag = -1 };
21019 +       int ret;
21020 +
21021 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
21022 +               return -EFAULT;
21023 +
21024 +       ret = user_lpath(vc_data.name, &path);
21025 +       if (!ret) {
21026 +               ret = __vc_get_iattr(path.dentry->d_inode,
21027 +                       &vc_data.tag, &vc_data.flags, &vc_data.mask);
21028 +               path_put(&path);
21029 +       }
21030 +       if (ret)
21031 +               return ret;
21032 +
21033 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
21034 +               ret = -EFAULT;
21035 +       return ret;
21036 +}
21037 +
21038 +#ifdef CONFIG_COMPAT
21039 +
21040 +int vc_get_iattr_x32(void __user *data)
21041 +{
21042 +       struct path path;
21043 +       struct vcmd_ctx_iattr_v1_x32 vc_data = { .tag = -1 };
21044 +       int ret;
21045 +
21046 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
21047 +               return -EFAULT;
21048 +
21049 +       ret = user_lpath(compat_ptr(vc_data.name_ptr), &path);
21050 +       if (!ret) {
21051 +               ret = __vc_get_iattr(path.dentry->d_inode,
21052 +                       &vc_data.tag, &vc_data.flags, &vc_data.mask);
21053 +               path_put(&path);
21054 +       }
21055 +       if (ret)
21056 +               return ret;
21057 +
21058 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
21059 +               ret = -EFAULT;
21060 +       return ret;
21061 +}
21062 +
21063 +#endif /* CONFIG_COMPAT */
21064 +
21065 +
21066 +int vc_fget_iattr(uint32_t fd, void __user *data)
21067 +{
21068 +       struct file *filp;
21069 +       struct vcmd_ctx_fiattr_v0 vc_data = { .tag = -1 };
21070 +       int ret;
21071 +
21072 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
21073 +               return -EFAULT;
21074 +
21075 +       filp = fget(fd);
21076 +       if (!filp || !filp->f_dentry || !filp->f_dentry->d_inode)
21077 +               return -EBADF;
21078 +
21079 +       ret = __vc_get_iattr(filp->f_dentry->d_inode,
21080 +               &vc_data.tag, &vc_data.flags, &vc_data.mask);
21081 +
21082 +       fput(filp);
21083 +
21084 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
21085 +               ret = -EFAULT;
21086 +       return ret;
21087 +}
21088 +
21089 +
21090 +static int __vc_set_iattr(struct dentry *de, uint32_t *tag, uint32_t *flags, uint32_t *mask)
21091 +{
21092 +       struct inode *in = de->d_inode;
21093 +       int error = 0, is_proc = 0, has_tag = 0;
21094 +       struct iattr attr = { 0 };
21095 +
21096 +       if (!in || !in->i_sb)
21097 +               return -ESRCH;
21098 +
21099 +       is_proc = (in->i_sb->s_magic == PROC_SUPER_MAGIC);
21100 +       if ((*mask & IATTR_FLAGS) && !is_proc)
21101 +               return -EINVAL;
21102 +
21103 +       has_tag = IS_TAGGED(in) ||
21104 +               (in->i_sb->s_magic == DEVPTS_SUPER_MAGIC);
21105 +       if ((*mask & IATTR_TAG) && !has_tag)
21106 +               return -EINVAL;
21107 +
21108 +       mutex_lock(&in->i_mutex);
21109 +       if (*mask & IATTR_TAG) {
21110 +               attr.ia_tag = *tag;
21111 +               attr.ia_valid |= ATTR_TAG;
21112 +       }
21113 +
21114 +       if (*mask & IATTR_FLAGS) {
21115 +               struct proc_dir_entry *entry = PROC_I(in)->pde;
21116 +               unsigned int iflags = PROC_I(in)->vx_flags;
21117 +
21118 +               iflags = (iflags & ~(*mask & IATTR_FLAGS))
21119 +                       | (*flags & IATTR_FLAGS);
21120 +               PROC_I(in)->vx_flags = iflags;
21121 +               if (entry)
21122 +                       entry->vx_flags = iflags;
21123 +       }
21124 +
21125 +       if (*mask & (IATTR_IMMUTABLE | IATTR_IXUNLINK |
21126 +               IATTR_BARRIER | IATTR_COW)) {
21127 +               int iflags = in->i_flags;
21128 +               int vflags = in->i_vflags;
21129 +
21130 +               if (*mask & IATTR_IMMUTABLE) {
21131 +                       if (*flags & IATTR_IMMUTABLE)
21132 +                               iflags |= S_IMMUTABLE;
21133 +                       else
21134 +                               iflags &= ~S_IMMUTABLE;
21135 +               }
21136 +               if (*mask & IATTR_IXUNLINK) {
21137 +                       if (*flags & IATTR_IXUNLINK)
21138 +                               iflags |= S_IXUNLINK;
21139 +                       else
21140 +                               iflags &= ~S_IXUNLINK;
21141 +               }
21142 +               if (S_ISDIR(in->i_mode) && (*mask & IATTR_BARRIER)) {
21143 +                       if (*flags & IATTR_BARRIER)
21144 +                               vflags |= V_BARRIER;
21145 +                       else
21146 +                               vflags &= ~V_BARRIER;
21147 +               }
21148 +               if (S_ISREG(in->i_mode) && (*mask & IATTR_COW)) {
21149 +                       if (*flags & IATTR_COW)
21150 +                               vflags |= V_COW;
21151 +                       else
21152 +                               vflags &= ~V_COW;
21153 +               }
21154 +               if (in->i_op && in->i_op->sync_flags) {
21155 +                       error = in->i_op->sync_flags(in, iflags, vflags);
21156 +                       if (error)
21157 +                               goto out;
21158 +               }
21159 +       }
21160 +
21161 +       if (attr.ia_valid) {
21162 +               if (in->i_op && in->i_op->setattr)
21163 +                       error = in->i_op->setattr(de, &attr);
21164 +               else {
21165 +                       error = inode_change_ok(in, &attr);
21166 +                       if (!error)
21167 +                               error = inode_setattr(in, &attr);
21168 +               }
21169 +       }
21170 +
21171 +out:
21172 +       mutex_unlock(&in->i_mutex);
21173 +       return error;
21174 +}
21175 +
21176 +int vc_set_iattr(void __user *data)
21177 +{
21178 +       struct path path;
21179 +       struct vcmd_ctx_iattr_v1 vc_data;
21180 +       int ret;
21181 +
21182 +       if (!capable(CAP_LINUX_IMMUTABLE))
21183 +               return -EPERM;
21184 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
21185 +               return -EFAULT;
21186 +
21187 +       ret = user_lpath(vc_data.name, &path);
21188 +       if (!ret) {
21189 +               ret = __vc_set_iattr(path.dentry,
21190 +                       &vc_data.tag, &vc_data.flags, &vc_data.mask);
21191 +               path_put(&path);
21192 +       }
21193 +
21194 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
21195 +               ret = -EFAULT;
21196 +       return ret;
21197 +}
21198 +
21199 +#ifdef CONFIG_COMPAT
21200 +
21201 +int vc_set_iattr_x32(void __user *data)
21202 +{
21203 +       struct path path;
21204 +       struct vcmd_ctx_iattr_v1_x32 vc_data;
21205 +       int ret;
21206 +
21207 +       if (!capable(CAP_LINUX_IMMUTABLE))
21208 +               return -EPERM;
21209 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
21210 +               return -EFAULT;
21211 +
21212 +       ret = user_lpath(compat_ptr(vc_data.name_ptr), &path);
21213 +       if (!ret) {
21214 +               ret = __vc_set_iattr(path.dentry,
21215 +                       &vc_data.tag, &vc_data.flags, &vc_data.mask);
21216 +               path_put(&path);
21217 +       }
21218 +
21219 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
21220 +               ret = -EFAULT;
21221 +       return ret;
21222 +}
21223 +
21224 +#endif /* CONFIG_COMPAT */
21225 +
21226 +int vc_fset_iattr(uint32_t fd, void __user *data)
21227 +{
21228 +       struct file *filp;
21229 +       struct vcmd_ctx_fiattr_v0 vc_data;
21230 +       int ret;
21231 +
21232 +       if (!capable(CAP_LINUX_IMMUTABLE))
21233 +               return -EPERM;
21234 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
21235 +               return -EFAULT;
21236 +
21237 +       filp = fget(fd);
21238 +       if (!filp || !filp->f_dentry || !filp->f_dentry->d_inode)
21239 +               return -EBADF;
21240 +
21241 +       ret = __vc_set_iattr(filp->f_dentry, &vc_data.tag,
21242 +               &vc_data.flags, &vc_data.mask);
21243 +
21244 +       fput(filp);
21245 +
21246 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
21247 +               return -EFAULT;
21248 +       return ret;
21249 +}
21250 +
21251 +
21252 +enum { Opt_notagcheck, Opt_tag, Opt_notag, Opt_tagid, Opt_err };
21253 +
21254 +static match_table_t tokens = {
21255 +       {Opt_notagcheck, "notagcheck"},
21256 +#ifdef CONFIG_PROPAGATE
21257 +       {Opt_notag, "notag"},
21258 +       {Opt_tag, "tag"},
21259 +       {Opt_tagid, "tagid=%u"},
21260 +#endif
21261 +       {Opt_err, NULL}
21262 +};
21263 +
21264 +
21265 +static void __dx_parse_remove(char *string, char *opt)
21266 +{
21267 +       char *p = strstr(string, opt);
21268 +       char *q = p;
21269 +
21270 +       if (p) {
21271 +               while (*q != '\0' && *q != ',')
21272 +                       q++;
21273 +               while (*q)
21274 +                       *p++ = *q++;
21275 +               while (*p)
21276 +                       *p++ = '\0';
21277 +       }
21278 +}
21279 +
21280 +int dx_parse_tag(char *string, tag_t *tag, int remove, int *mnt_flags,
21281 +                unsigned long *flags)
21282 +{
21283 +       int set = 0;
21284 +       substring_t args[MAX_OPT_ARGS];
21285 +       int token, option = 0;
21286 +       char *s, *p, *opts;
21287 +
21288 +       if (!string)
21289 +               return 0;
21290 +       s = kstrdup(string, GFP_KERNEL | GFP_ATOMIC);
21291 +       if (!s)
21292 +               return 0;
21293 +
21294 +       opts = s;
21295 +       while ((p = strsep(&opts, ",")) != NULL) {
21296 +               token = match_token(p, tokens, args);
21297 +
21298 +               vxdprintk(VXD_CBIT(tag, 7),
21299 +                       "dx_parse_tag(»%s«): %d:#%d",
21300 +                       p, token, option);
21301 +
21302 +               switch (token) {
21303 +#ifdef CONFIG_PROPAGATE
21304 +               case Opt_tag:
21305 +                       if (tag)
21306 +                               *tag = 0;
21307 +                       if (remove)
21308 +                               __dx_parse_remove(s, "tag");
21309 +                       *mnt_flags |= MNT_TAGID;
21310 +                       set |= MNT_TAGID;
21311 +                       break;
21312 +               case Opt_notag:
21313 +                       if (remove)
21314 +                               __dx_parse_remove(s, "notag");
21315 +                       *mnt_flags |= MNT_NOTAG;
21316 +                       set |= MNT_NOTAG;
21317 +                       break;
21318 +               case Opt_tagid:
21319 +                       if (tag && !match_int(args, &option))
21320 +                               *tag = option;
21321 +                       if (remove)
21322 +                               __dx_parse_remove(s, "tagid");
21323 +                       *mnt_flags |= MNT_TAGID;
21324 +                       set |= MNT_TAGID;
21325 +                       break;
21326 +#endif
21327 +               case Opt_notagcheck:
21328 +                       if (remove)
21329 +                               __dx_parse_remove(s, "notagcheck");
21330 +                       *flags |= MS_NOTAGCHECK;
21331 +                       set |= MS_NOTAGCHECK;
21332 +                       break;
21333 +               }
21334 +       }
21335 +       if (set)
21336 +               strcpy(string, s);
21337 +       kfree(s);
21338 +       return set;
21339 +}
21340 +
21341 +#ifdef CONFIG_PROPAGATE
21342 +
21343 +void __dx_propagate_tag(struct nameidata *nd, struct inode *inode)
21344 +{
21345 +       tag_t new_tag = 0;
21346 +       struct vfsmount *mnt;
21347 +       int propagate;
21348 +
21349 +       if (!nd)
21350 +               return;
21351 +       mnt = nd->path.mnt;
21352 +       if (!mnt)
21353 +               return;
21354 +
21355 +       propagate = (mnt->mnt_flags & MNT_TAGID);
21356 +       if (propagate)
21357 +               new_tag = mnt->mnt_tag;
21358 +
21359 +       vxdprintk(VXD_CBIT(tag, 7),
21360 +               "dx_propagate_tag(%p[#%lu.%d]): %d,%d",
21361 +               inode, inode->i_ino, inode->i_tag,
21362 +               new_tag, (propagate) ? 1 : 0);
21363 +
21364 +       if (propagate)
21365 +               inode->i_tag = new_tag;
21366 +}
21367 +
21368 +#include <linux/module.h>
21369 +
21370 +EXPORT_SYMBOL_GPL(__dx_propagate_tag);
21371 +
21372 +#endif /* CONFIG_PROPAGATE */
21373 +
21374 diff -NurpP --minimal linux-2.6.32.1/kernel/vserver/Kconfig linux-2.6.32.1-vs2.3.0.36.27/kernel/vserver/Kconfig
21375 --- linux-2.6.32.1/kernel/vserver/Kconfig       1970-01-01 01:00:00.000000000 +0100
21376 +++ linux-2.6.32.1-vs2.3.0.36.27/kernel/vserver/Kconfig 2009-12-03 20:04:56.000000000 +0100
21377 @@ -0,0 +1,251 @@
21378 +#
21379 +# Linux VServer configuration
21380 +#
21381 +
21382 +menu "Linux VServer"
21383 +
21384 +config VSERVER_AUTO_LBACK
21385 +       bool    "Automatically Assign Loopback IP"
21386 +       default y
21387 +       help
21388 +         Automatically assign a guest specific loopback
21389 +         IP and add it to the kernel network stack on
21390 +         startup.
21391 +
21392 +config VSERVER_AUTO_SINGLE
21393 +       bool    "Automatic Single IP Special Casing"
21394 +       depends on EXPERIMENTAL
21395 +       default y
21396 +       help
21397 +         This allows network contexts with a single IP to
21398 +         automatically remap 0.0.0.0 bindings to that IP,
21399 +         avoiding further network checks and improving
21400 +         performance.
21401 +
21402 +         (note: such guests do not allow to change the ip
21403 +          on the fly and do not show loopback addresses)
21404 +
21405 +config VSERVER_COWBL
21406 +       bool    "Enable COW Immutable Link Breaking"
21407 +       default y
21408 +       help
21409 +         This enables the COW (Copy-On-Write) link break code.
21410 +         It allows you to treat unified files like normal files
21411 +         when writing to them (which will implicitely break the
21412 +         link and create a copy of the unified file)
21413 +
21414 +config VSERVER_VTIME
21415 +       bool    "Enable Virtualized Guest Time"
21416 +       depends on EXPERIMENTAL
21417 +       default n
21418 +       help
21419 +         This enables per guest time offsets to allow for
21420 +         adjusting the system clock individually per guest.
21421 +         this adds some overhead to the time functions and
21422 +         therefore should not be enabled without good reason.
21423 +
21424 +config VSERVER_DEVICE
21425 +       bool    "Enable Guest Device Mapping"
21426 +       depends on EXPERIMENTAL
21427 +       default n
21428 +       help
21429 +         This enables generic device remapping.
21430 +
21431 +config VSERVER_PROC_SECURE
21432 +       bool    "Enable Proc Security"
21433 +       depends on PROC_FS
21434 +       default y
21435 +       help
21436 +         This configures ProcFS security to initially hide
21437 +         non-process entries for all contexts except the main and
21438 +         spectator context (i.e. for all guests), which is a secure
21439 +         default.
21440 +
21441 +         (note: on 1.2x the entries were visible by default)
21442 +
21443 +config VSERVER_HARDCPU
21444 +       bool    "Enable Hard CPU Limits"
21445 +       default y
21446 +       help
21447 +         Activate the Hard CPU Limits
21448 +
21449 +         This will compile in code that allows the Token Bucket
21450 +         Scheduler to put processes on hold when a context's
21451 +         tokens are depleted (provided that its per-context
21452 +         sched_hard flag is set).
21453 +
21454 +         Processes belonging to that context will not be able
21455 +         to consume CPU resources again until a per-context
21456 +         configured minimum of tokens has been reached.
21457 +
21458 +config VSERVER_IDLETIME
21459 +       bool    "Avoid idle CPUs by skipping Time"
21460 +       depends on VSERVER_HARDCPU
21461 +       default y
21462 +       help
21463 +         This option allows the scheduler to artificially
21464 +         advance time (per cpu) when otherwise the idle
21465 +         task would be scheduled, thus keeping the cpu
21466 +         busy and sharing the available resources among
21467 +         certain contexts.
21468 +
21469 +config VSERVER_IDLELIMIT
21470 +       bool    "Limit the IDLE task"
21471 +       depends on VSERVER_HARDCPU
21472 +       default n
21473 +       help
21474 +         Limit the idle slices, so the the next context
21475 +         will be scheduled as soon as possible.
21476 +
21477 +         This might improve interactivity and latency, but
21478 +         will also marginally increase scheduling overhead.
21479 +
21480 +choice
21481 +       prompt  "Persistent Inode Tagging"
21482 +       default TAGGING_ID24
21483 +       help
21484 +         This adds persistent context information to filesystems
21485 +         mounted with the tagxid option. Tagging is a requirement
21486 +         for per-context disk limits and per-context quota.
21487 +
21488 +
21489 +config TAGGING_NONE
21490 +       bool    "Disabled"
21491 +       help
21492 +         do not store per-context information in inodes.
21493 +
21494 +config TAGGING_UID16
21495 +       bool    "UID16/GID32"
21496 +       help
21497 +         reduces UID to 16 bit, but leaves GID at 32 bit.
21498 +
21499 +config TAGGING_GID16
21500 +       bool    "UID32/GID16"
21501 +       help
21502 +         reduces GID to 16 bit, but leaves UID at 32 bit.
21503 +
21504 +config TAGGING_ID24
21505 +       bool    "UID24/GID24"
21506 +       help
21507 +         uses the upper 8bit from UID and GID for XID tagging
21508 +         which leaves 24bit for UID/GID each, which should be
21509 +         more than sufficient for normal use.
21510 +
21511 +config TAGGING_INTERN
21512 +       bool    "UID32/GID32"
21513 +       help
21514 +         this uses otherwise reserved inode fields in the on
21515 +         disk representation, which limits the use to a few
21516 +         filesystems (currently ext2 and ext3)
21517 +
21518 +endchoice
21519 +
21520 +config TAG_NFSD
21521 +       bool    "Tag NFSD User Auth and Files"
21522 +       default n
21523 +       help
21524 +         Enable this if you do want the in-kernel NFS
21525 +         Server to use the tagging specified above.
21526 +         (will require patched clients too)
21527 +
21528 +config VSERVER_PRIVACY
21529 +       bool    "Honor Privacy Aspects of Guests"
21530 +       default n
21531 +       help
21532 +         When enabled, most context checks will disallow
21533 +         access to structures assigned to a specific context,
21534 +         like ptys or loop devices.
21535 +
21536 +config VSERVER_CONTEXTS
21537 +       int     "Maximum number of Contexts (1-65533)"  if EMBEDDED
21538 +       range 1 65533
21539 +       default "768"   if 64BIT
21540 +       default "256"
21541 +       help
21542 +         This setting will optimize certain data structures
21543 +         and memory allocations according to the expected
21544 +         maximum.
21545 +
21546 +         note: this is not a strict upper limit.
21547 +
21548 +config VSERVER_WARN
21549 +       bool    "VServer Warnings"
21550 +       default y
21551 +       help
21552 +         This enables various runtime warnings, which will
21553 +         notify about potential manipulation attempts or
21554 +         resource shortage. It is generally considered to
21555 +         be a good idea to have that enabled.
21556 +
21557 +config VSERVER_DEBUG
21558 +       bool    "VServer Debugging Code"
21559 +       default n
21560 +       help
21561 +         Set this to yes if you want to be able to activate
21562 +         debugging output at runtime. It adds a very small
21563 +         overhead to all vserver related functions and
21564 +         increases the kernel size by about 20k.
21565 +
21566 +config VSERVER_HISTORY
21567 +       bool    "VServer History Tracing"
21568 +       depends on VSERVER_DEBUG
21569 +       default n
21570 +       help
21571 +         Set this to yes if you want to record the history of
21572 +         linux-vserver activities, so they can be replayed in
21573 +         the event of a kernel panic or oops.
21574 +
21575 +config VSERVER_HISTORY_SIZE
21576 +       int     "Per-CPU History Size (32-65536)"
21577 +       depends on VSERVER_HISTORY
21578 +       range 32 65536
21579 +       default 64
21580 +       help
21581 +         This allows you to specify the number of entries in
21582 +         the per-CPU history buffer.
21583 +
21584 +config VSERVER_MONITOR
21585 +       bool    "VServer Scheduling Monitor"
21586 +       depends on VSERVER_DISABLED
21587 +       default n
21588 +       help
21589 +         Set this to yes if you want to record the scheduling
21590 +         decisions, so that they can be relayed to userspace
21591 +         for detailed analysis.
21592 +
21593 +config VSERVER_MONITOR_SIZE
21594 +       int     "Per-CPU Monitor Queue Size (32-65536)"
21595 +       depends on VSERVER_MONITOR
21596 +       range 32 65536
21597 +       default 1024
21598 +       help
21599 +         This allows you to specify the number of entries in
21600 +         the per-CPU scheduling monitor buffer.
21601 +
21602 +config VSERVER_MONITOR_SYNC
21603 +       int     "Per-CPU Monitor Sync Interval (0-65536)"
21604 +       depends on VSERVER_MONITOR
21605 +       range 0 65536
21606 +       default 256
21607 +       help
21608 +         This allows you to specify the interval in ticks
21609 +         when a time sync entry is inserted.
21610 +
21611 +endmenu
21612 +
21613 +
21614 +config VSERVER
21615 +       bool
21616 +       default y
21617 +       select NAMESPACES
21618 +       select UTS_NS
21619 +       select IPC_NS
21620 +       select USER_NS
21621 +       select SYSVIPC
21622 +
21623 +config VSERVER_SECURITY
21624 +       bool
21625 +       depends on SECURITY
21626 +       default y
21627 +       select SECURITY_CAPABILITIES
21628 +
21629 diff -NurpP --minimal linux-2.6.32.1/kernel/vserver/limit.c linux-2.6.32.1-vs2.3.0.36.27/kernel/vserver/limit.c
21630 --- linux-2.6.32.1/kernel/vserver/limit.c       1970-01-01 01:00:00.000000000 +0100
21631 +++ linux-2.6.32.1-vs2.3.0.36.27/kernel/vserver/limit.c 2009-12-03 20:04:56.000000000 +0100
21632 @@ -0,0 +1,333 @@
21633 +/*
21634 + *  linux/kernel/vserver/limit.c
21635 + *
21636 + *  Virtual Server: Context Limits
21637 + *
21638 + *  Copyright (C) 2004-2007  Herbert Pötzl
21639 + *
21640 + *  V0.01  broken out from vcontext V0.05
21641 + *  V0.02  changed vcmds to vxi arg
21642 + *
21643 + */
21644 +
21645 +#include <linux/sched.h>
21646 +#include <linux/module.h>
21647 +#include <linux/vs_limit.h>
21648 +#include <linux/vserver/limit.h>
21649 +#include <linux/vserver/limit_cmd.h>
21650 +
21651 +#include <asm/uaccess.h>
21652 +
21653 +
21654 +const char *vlimit_name[NUM_LIMITS] = {
21655 +       [RLIMIT_CPU]            = "CPU",
21656 +       [RLIMIT_RSS]            = "RSS",
21657 +       [RLIMIT_NPROC]          = "NPROC",
21658 +       [RLIMIT_NOFILE]         = "NOFILE",
21659 +       [RLIMIT_MEMLOCK]        = "VML",
21660 +       [RLIMIT_AS]             = "VM",
21661 +       [RLIMIT_LOCKS]          = "LOCKS",
21662 +       [RLIMIT_SIGPENDING]     = "SIGP",
21663 +       [RLIMIT_MSGQUEUE]       = "MSGQ",
21664 +
21665 +       [VLIMIT_NSOCK]          = "NSOCK",
21666 +       [VLIMIT_OPENFD]         = "OPENFD",
21667 +       [VLIMIT_ANON]           = "ANON",
21668 +       [VLIMIT_SHMEM]          = "SHMEM",
21669 +       [VLIMIT_DENTRY]         = "DENTRY",
21670 +};
21671 +
21672 +EXPORT_SYMBOL_GPL(vlimit_name);
21673 +
21674 +#define MASK_ENTRY(x)  (1 << (x))
21675 +
21676 +const struct vcmd_ctx_rlimit_mask_v0 vlimit_mask = {
21677 +               /* minimum */
21678 +       0
21679 +       ,       /* softlimit */
21680 +       MASK_ENTRY( RLIMIT_RSS          ) |
21681 +       MASK_ENTRY( VLIMIT_ANON         ) |
21682 +       0
21683 +       ,       /* maximum */
21684 +       MASK_ENTRY( RLIMIT_RSS          ) |
21685 +       MASK_ENTRY( RLIMIT_NPROC        ) |
21686 +       MASK_ENTRY( RLIMIT_NOFILE       ) |
21687 +       MASK_ENTRY( RLIMIT_MEMLOCK      ) |
21688 +       MASK_ENTRY( RLIMIT_AS           ) |
21689 +       MASK_ENTRY( RLIMIT_LOCKS        ) |
21690 +       MASK_ENTRY( RLIMIT_MSGQUEUE     ) |
21691 +
21692 +       MASK_ENTRY( VLIMIT_NSOCK        ) |
21693 +       MASK_ENTRY( VLIMIT_OPENFD       ) |
21694 +       MASK_ENTRY( VLIMIT_ANON         ) |
21695 +       MASK_ENTRY( VLIMIT_SHMEM        ) |
21696 +       MASK_ENTRY( VLIMIT_DENTRY       ) |
21697 +       0
21698 +};
21699 +               /* accounting only */
21700 +uint32_t account_mask =
21701 +       MASK_ENTRY( VLIMIT_SEMARY       ) |
21702 +       MASK_ENTRY( VLIMIT_NSEMS        ) |
21703 +       MASK_ENTRY( VLIMIT_MAPPED       ) |
21704 +       0;
21705 +
21706 +
21707 +static int is_valid_vlimit(int id)
21708 +{
21709 +       uint32_t mask = vlimit_mask.minimum |
21710 +               vlimit_mask.softlimit | vlimit_mask.maximum;
21711 +       return mask & (1 << id);
21712 +}
21713 +
21714 +static int is_accounted_vlimit(int id)
21715 +{
21716 +       if (is_valid_vlimit(id))
21717 +               return 1;
21718 +       return account_mask & (1 << id);
21719 +}
21720 +
21721 +
21722 +static inline uint64_t vc_get_soft(struct vx_info *vxi, int id)
21723 +{
21724 +       rlim_t limit = __rlim_soft(&vxi->limit, id);
21725 +       return VX_VLIM(limit);
21726 +}
21727 +
21728 +static inline uint64_t vc_get_hard(struct vx_info *vxi, int id)
21729 +{
21730 +       rlim_t limit = __rlim_hard(&vxi->limit, id);
21731 +       return VX_VLIM(limit);
21732 +}
21733 +
21734 +static int do_get_rlimit(struct vx_info *vxi, uint32_t id,
21735 +       uint64_t *minimum, uint64_t *softlimit, uint64_t *maximum)
21736 +{
21737 +       if (!is_valid_vlimit(id))
21738 +               return -EINVAL;
21739 +
21740 +       if (minimum)
21741 +               *minimum = CRLIM_UNSET;
21742 +       if (softlimit)
21743 +               *softlimit = vc_get_soft(vxi, id);
21744 +       if (maximum)
21745 +               *maximum = vc_get_hard(vxi, id);
21746 +       return 0;
21747 +}
21748 +
21749 +int vc_get_rlimit(struct vx_info *vxi, void __user *data)
21750 +{
21751 +       struct vcmd_ctx_rlimit_v0 vc_data;
21752 +       int ret;
21753 +
21754 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
21755 +               return -EFAULT;
21756 +
21757 +       ret = do_get_rlimit(vxi, vc_data.id,
21758 +               &vc_data.minimum, &vc_data.softlimit, &vc_data.maximum);
21759 +       if (ret)
21760 +               return ret;
21761 +
21762 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
21763 +               return -EFAULT;
21764 +       return 0;
21765 +}
21766 +
21767 +static int do_set_rlimit(struct vx_info *vxi, uint32_t id,
21768 +       uint64_t minimum, uint64_t softlimit, uint64_t maximum)
21769 +{
21770 +       if (!is_valid_vlimit(id))
21771 +               return -EINVAL;
21772 +
21773 +       if (maximum != CRLIM_KEEP)
21774 +               __rlim_hard(&vxi->limit, id) = VX_RLIM(maximum);
21775 +       if (softlimit != CRLIM_KEEP)
21776 +               __rlim_soft(&vxi->limit, id) = VX_RLIM(softlimit);
21777 +
21778 +       /* clamp soft limit */
21779 +       if (__rlim_soft(&vxi->limit, id) > __rlim_hard(&vxi->limit, id))
21780 +               __rlim_soft(&vxi->limit, id) = __rlim_hard(&vxi->limit, id);
21781 +
21782 +       return 0;
21783 +}
21784 +
21785 +int vc_set_rlimit(struct vx_info *vxi, void __user *data)
21786 +{
21787 +       struct vcmd_ctx_rlimit_v0 vc_data;
21788 +
21789 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
21790 +               return -EFAULT;
21791 +
21792 +       return do_set_rlimit(vxi, vc_data.id,
21793 +               vc_data.minimum, vc_data.softlimit, vc_data.maximum);
21794 +}
21795 +
21796 +#ifdef CONFIG_IA32_EMULATION
21797 +
21798 +int vc_set_rlimit_x32(struct vx_info *vxi, void __user *data)
21799 +{
21800 +       struct vcmd_ctx_rlimit_v0_x32 vc_data;
21801 +
21802 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
21803 +               return -EFAULT;
21804 +
21805 +       return do_set_rlimit(vxi, vc_data.id,
21806 +               vc_data.minimum, vc_data.softlimit, vc_data.maximum);
21807 +}
21808 +
21809 +int vc_get_rlimit_x32(struct vx_info *vxi, void __user *data)
21810 +{
21811 +       struct vcmd_ctx_rlimit_v0_x32 vc_data;
21812 +       int ret;
21813 +
21814 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
21815 +               return -EFAULT;
21816 +
21817 +       ret = do_get_rlimit(vxi, vc_data.id,
21818 +               &vc_data.minimum, &vc_data.softlimit, &vc_data.maximum);
21819 +       if (ret)
21820 +               return ret;
21821 +
21822 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
21823 +               return -EFAULT;
21824 +       return 0;
21825 +}
21826 +
21827 +#endif /* CONFIG_IA32_EMULATION */
21828 +
21829 +
21830 +int vc_get_rlimit_mask(uint32_t id, void __user *data)
21831 +{
21832 +       if (copy_to_user(data, &vlimit_mask, sizeof(vlimit_mask)))
21833 +               return -EFAULT;
21834 +       return 0;
21835 +}
21836 +
21837 +
21838 +static inline void vx_reset_hits(struct _vx_limit *limit)
21839 +{
21840 +       int lim;
21841 +
21842 +       for (lim = 0; lim < NUM_LIMITS; lim++) {
21843 +               atomic_set(&__rlim_lhit(limit, lim), 0);
21844 +       }
21845 +}
21846 +
21847 +int vc_reset_hits(struct vx_info *vxi, void __user *data)
21848 +{
21849 +       vx_reset_hits(&vxi->limit);
21850 +       return 0;
21851 +}
21852 +
21853 +static inline void vx_reset_minmax(struct _vx_limit *limit)
21854 +{
21855 +       rlim_t value;
21856 +       int lim;
21857 +
21858 +       for (lim = 0; lim < NUM_LIMITS; lim++) {
21859 +               value = __rlim_get(limit, lim);
21860 +               __rlim_rmax(limit, lim) = value;
21861 +               __rlim_rmin(limit, lim) = value;
21862 +       }
21863 +}
21864 +
21865 +int vc_reset_minmax(struct vx_info *vxi, void __user *data)
21866 +{
21867 +       vx_reset_minmax(&vxi->limit);
21868 +       return 0;
21869 +}
21870 +
21871 +
21872 +int vc_rlimit_stat(struct vx_info *vxi, void __user *data)
21873 +{
21874 +       struct vcmd_rlimit_stat_v0 vc_data;
21875 +       struct _vx_limit *limit = &vxi->limit;
21876 +       int id;
21877 +
21878 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
21879 +               return -EFAULT;
21880 +
21881 +       id = vc_data.id;
21882 +       if (!is_accounted_vlimit(id))
21883 +               return -EINVAL;
21884 +
21885 +       vx_limit_fixup(limit, id);
21886 +       vc_data.hits = atomic_read(&__rlim_lhit(limit, id));
21887 +       vc_data.value = __rlim_get(limit, id);
21888 +       vc_data.minimum = __rlim_rmin(limit, id);
21889 +       vc_data.maximum = __rlim_rmax(limit, id);
21890 +
21891 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
21892 +               return -EFAULT;
21893 +       return 0;
21894 +}
21895 +
21896 +
21897 +void vx_vsi_meminfo(struct sysinfo *val)
21898 +{
21899 +       struct vx_info *vxi = current_vx_info();
21900 +       unsigned long totalram, freeram;
21901 +       rlim_t v;
21902 +
21903 +       /* we blindly accept the max */
21904 +       v = __rlim_soft(&vxi->limit, RLIMIT_RSS);
21905 +       totalram = (v != RLIM_INFINITY) ? v : val->totalram;
21906 +
21907 +       /* total minus used equals free */
21908 +       v = __vx_cres_array_fixup(&vxi->limit, VLA_RSS);
21909 +       freeram = (v < totalram) ? totalram - v : 0;
21910 +
21911 +       val->totalram = totalram;
21912 +       val->freeram = freeram;
21913 +       val->bufferram = 0;
21914 +       val->totalhigh = 0;
21915 +       val->freehigh = 0;
21916 +       return;
21917 +}
21918 +
21919 +void vx_vsi_swapinfo(struct sysinfo *val)
21920 +{
21921 +       struct vx_info *vxi = current_vx_info();
21922 +       unsigned long totalswap, freeswap;
21923 +       rlim_t v, w;
21924 +
21925 +       v = __rlim_soft(&vxi->limit, RLIMIT_RSS);
21926 +       if (v == RLIM_INFINITY) {
21927 +               val->freeswap = val->totalswap;
21928 +               return;
21929 +       }
21930 +
21931 +       /* we blindly accept the max */
21932 +       w = __rlim_hard(&vxi->limit, RLIMIT_RSS);
21933 +       totalswap = (w != RLIM_INFINITY) ? (w - v) : val->totalswap;
21934 +
21935 +       /* currently 'used' swap */
21936 +       w = __vx_cres_array_fixup(&vxi->limit, VLA_RSS);
21937 +       w -= (w > v) ? v : w;
21938 +
21939 +       /* total minus used equals free */
21940 +       freeswap = (w < totalswap) ? totalswap - w : 0;
21941 +
21942 +       val->totalswap = totalswap;
21943 +       val->freeswap = freeswap;
21944 +       return;
21945 +}
21946 +
21947 +
21948 +unsigned long vx_badness(struct task_struct *task, struct mm_struct *mm)
21949 +{
21950 +       struct vx_info *vxi = mm->mm_vx_info;
21951 +       unsigned long points;
21952 +       rlim_t v, w;
21953 +
21954 +       if (!vxi)
21955 +               return 0;
21956 +
21957 +       points = vxi->vx_badness_bias;
21958 +
21959 +       v = __vx_cres_array_fixup(&vxi->limit, VLA_RSS);
21960 +       w = __rlim_soft(&vxi->limit, RLIMIT_RSS);
21961 +       points += (v > w) ? (v - w) : 0;
21962 +
21963 +       return points;
21964 +}
21965 +
21966 diff -NurpP --minimal linux-2.6.32.1/kernel/vserver/limit_init.h linux-2.6.32.1-vs2.3.0.36.27/kernel/vserver/limit_init.h
21967 --- linux-2.6.32.1/kernel/vserver/limit_init.h  1970-01-01 01:00:00.000000000 +0100
21968 +++ linux-2.6.32.1-vs2.3.0.36.27/kernel/vserver/limit_init.h    2009-12-03 20:04:56.000000000 +0100
21969 @@ -0,0 +1,31 @@
21970 +
21971 +
21972 +static inline void vx_info_init_limit(struct _vx_limit *limit)
21973 +{
21974 +       int lim;
21975 +
21976 +       for (lim = 0; lim < NUM_LIMITS; lim++) {
21977 +               __rlim_soft(limit, lim) = RLIM_INFINITY;
21978 +               __rlim_hard(limit, lim) = RLIM_INFINITY;
21979 +               __rlim_set(limit, lim, 0);
21980 +               atomic_set(&__rlim_lhit(limit, lim), 0);
21981 +               __rlim_rmin(limit, lim) = 0;
21982 +               __rlim_rmax(limit, lim) = 0;
21983 +       }
21984 +}
21985 +
21986 +static inline void vx_info_exit_limit(struct _vx_limit *limit)
21987 +{
21988 +       rlim_t value;
21989 +       int lim;
21990 +
21991 +       for (lim = 0; lim < NUM_LIMITS; lim++) {
21992 +               if ((1 << lim) & VLIM_NOCHECK)
21993 +                       continue;
21994 +               value = __rlim_get(limit, lim);
21995 +               vxwprintk_xid(value,
21996 +                       "!!! limit: %p[%s,%d] = %ld on exit.",
21997 +                       limit, vlimit_name[lim], lim, (long)value);
21998 +       }
21999 +}
22000 +
22001 diff -NurpP --minimal linux-2.6.32.1/kernel/vserver/limit_proc.h linux-2.6.32.1-vs2.3.0.36.27/kernel/vserver/limit_proc.h
22002 --- linux-2.6.32.1/kernel/vserver/limit_proc.h  1970-01-01 01:00:00.000000000 +0100
22003 +++ linux-2.6.32.1-vs2.3.0.36.27/kernel/vserver/limit_proc.h    2009-12-03 20:04:56.000000000 +0100
22004 @@ -0,0 +1,57 @@
22005 +#ifndef _VX_LIMIT_PROC_H
22006 +#define _VX_LIMIT_PROC_H
22007 +
22008 +#include <linux/vserver/limit_int.h>
22009 +
22010 +
22011 +#define VX_LIMIT_FMT   ":\t%8ld\t%8ld/%8ld\t%8lld/%8lld\t%6d\n"
22012 +#define VX_LIMIT_TOP   \
22013 +       "Limit\t current\t     min/max\t\t    soft/hard\t\thits\n"
22014 +
22015 +#define VX_LIMIT_ARG(r)                                \
22016 +       (unsigned long)__rlim_get(limit, r),    \
22017 +       (unsigned long)__rlim_rmin(limit, r),   \
22018 +       (unsigned long)__rlim_rmax(limit, r),   \
22019 +       VX_VLIM(__rlim_soft(limit, r)),         \
22020 +       VX_VLIM(__rlim_hard(limit, r)),         \
22021 +       atomic_read(&__rlim_lhit(limit, r))
22022 +
22023 +static inline int vx_info_proc_limit(struct _vx_limit *limit, char *buffer)
22024 +{
22025 +       vx_limit_fixup(limit, -1);
22026 +       return sprintf(buffer, VX_LIMIT_TOP
22027 +               "PROC"  VX_LIMIT_FMT
22028 +               "VM"    VX_LIMIT_FMT
22029 +               "VML"   VX_LIMIT_FMT
22030 +               "RSS"   VX_LIMIT_FMT
22031 +               "ANON"  VX_LIMIT_FMT
22032 +               "RMAP"  VX_LIMIT_FMT
22033 +               "FILES" VX_LIMIT_FMT
22034 +               "OFD"   VX_LIMIT_FMT
22035 +               "LOCKS" VX_LIMIT_FMT
22036 +               "SOCK"  VX_LIMIT_FMT
22037 +               "MSGQ"  VX_LIMIT_FMT
22038 +               "SHM"   VX_LIMIT_FMT
22039 +               "SEMA"  VX_LIMIT_FMT
22040 +               "SEMS"  VX_LIMIT_FMT
22041 +               "DENT"  VX_LIMIT_FMT,
22042 +               VX_LIMIT_ARG(RLIMIT_NPROC),
22043 +               VX_LIMIT_ARG(RLIMIT_AS),
22044 +               VX_LIMIT_ARG(RLIMIT_MEMLOCK),
22045 +               VX_LIMIT_ARG(RLIMIT_RSS),
22046 +               VX_LIMIT_ARG(VLIMIT_ANON),
22047 +               VX_LIMIT_ARG(VLIMIT_MAPPED),
22048 +               VX_LIMIT_ARG(RLIMIT_NOFILE),
22049 +               VX_LIMIT_ARG(VLIMIT_OPENFD),
22050 +               VX_LIMIT_ARG(RLIMIT_LOCKS),
22051 +               VX_LIMIT_ARG(VLIMIT_NSOCK),
22052 +               VX_LIMIT_ARG(RLIMIT_MSGQUEUE),
22053 +               VX_LIMIT_ARG(VLIMIT_SHMEM),
22054 +               VX_LIMIT_ARG(VLIMIT_SEMARY),
22055 +               VX_LIMIT_ARG(VLIMIT_NSEMS),
22056 +               VX_LIMIT_ARG(VLIMIT_DENTRY));
22057 +}
22058 +
22059 +#endif /* _VX_LIMIT_PROC_H */
22060 +
22061 +
22062 diff -NurpP --minimal linux-2.6.32.1/kernel/vserver/Makefile linux-2.6.32.1-vs2.3.0.36.27/kernel/vserver/Makefile
22063 --- linux-2.6.32.1/kernel/vserver/Makefile      1970-01-01 01:00:00.000000000 +0100
22064 +++ linux-2.6.32.1-vs2.3.0.36.27/kernel/vserver/Makefile        2009-12-03 20:04:56.000000000 +0100
22065 @@ -0,0 +1,18 @@
22066 +#
22067 +# Makefile for the Linux vserver routines.
22068 +#
22069 +
22070 +
22071 +obj-y          += vserver.o
22072 +
22073 +vserver-y      := switch.o context.o space.o sched.o network.o inode.o \
22074 +                  limit.o cvirt.o cacct.o signal.o helper.o init.o \
22075 +                  dlimit.o tag.o
22076 +
22077 +vserver-$(CONFIG_INET) += inet.o
22078 +vserver-$(CONFIG_PROC_FS) += proc.o
22079 +vserver-$(CONFIG_VSERVER_DEBUG) += sysctl.o debug.o
22080 +vserver-$(CONFIG_VSERVER_HISTORY) += history.o
22081 +vserver-$(CONFIG_VSERVER_MONITOR) += monitor.o
22082 +vserver-$(CONFIG_VSERVER_DEVICE) += device.o
22083 +
22084 diff -NurpP --minimal linux-2.6.32.1/kernel/vserver/monitor.c linux-2.6.32.1-vs2.3.0.36.27/kernel/vserver/monitor.c
22085 --- linux-2.6.32.1/kernel/vserver/monitor.c     1970-01-01 01:00:00.000000000 +0100
22086 +++ linux-2.6.32.1-vs2.3.0.36.27/kernel/vserver/monitor.c       2009-12-03 20:04:56.000000000 +0100
22087 @@ -0,0 +1,138 @@
22088 +/*
22089 + *  kernel/vserver/monitor.c
22090 + *
22091 + *  Virtual Context Scheduler Monitor
22092 + *
22093 + *  Copyright (C) 2006-2007 Herbert Pötzl
22094 + *
22095 + *  V0.01  basic design
22096 + *
22097 + */
22098 +
22099 +#include <linux/module.h>
22100 +#include <linux/jiffies.h>
22101 +#include <asm/uaccess.h>
22102 +#include <asm/atomic.h>
22103 +
22104 +#include <linux/vserver/monitor.h>
22105 +#include <linux/vserver/debug_cmd.h>
22106 +
22107 +
22108 +#ifdef CONFIG_VSERVER_MONITOR
22109 +#define VXM_SIZE       CONFIG_VSERVER_MONITOR_SIZE
22110 +#else
22111 +#define VXM_SIZE       64
22112 +#endif
22113 +
22114 +struct _vx_monitor {
22115 +       unsigned int counter;
22116 +
22117 +       struct _vx_mon_entry entry[VXM_SIZE+1];
22118 +};
22119 +
22120 +
22121 +DEFINE_PER_CPU(struct _vx_monitor, vx_monitor_buffer);
22122 +
22123 +unsigned volatile int vxm_active = 1;
22124 +
22125 +static atomic_t sequence = ATOMIC_INIT(0);
22126 +
22127 +
22128 +/*     vxm_advance()
22129 +
22130 +       * requires disabled preemption                          */
22131 +
22132 +struct _vx_mon_entry *vxm_advance(int cpu)
22133 +{
22134 +       struct _vx_monitor *mon = &per_cpu(vx_monitor_buffer, cpu);
22135 +       struct _vx_mon_entry *entry;
22136 +       unsigned int index;
22137 +
22138 +       index = vxm_active ? (mon->counter++ % VXM_SIZE) : VXM_SIZE;
22139 +       entry = &mon->entry[index];
22140 +
22141 +       entry->ev.seq = atomic_inc_return(&sequence);
22142 +       entry->ev.jif = jiffies;
22143 +       return entry;
22144 +}
22145 +
22146 +EXPORT_SYMBOL_GPL(vxm_advance);
22147 +
22148 +
22149 +int do_read_monitor(struct __user _vx_mon_entry *data,
22150 +       int cpu, uint32_t *index, uint32_t *count)
22151 +{
22152 +       int pos, ret = 0;
22153 +       struct _vx_monitor *mon = &per_cpu(vx_monitor_buffer, cpu);
22154 +       int end = mon->counter;
22155 +       int start = end - VXM_SIZE + 2;
22156 +       int idx = *index;
22157 +
22158 +       /* special case: get current pos */
22159 +       if (!*count) {
22160 +               *index = end;
22161 +               return 0;
22162 +       }
22163 +
22164 +       /* have we lost some data? */
22165 +       if (idx < start)
22166 +               idx = start;
22167 +
22168 +       for (pos = 0; (pos < *count) && (idx < end); pos++, idx++) {
22169 +               struct _vx_mon_entry *entry =
22170 +                       &mon->entry[idx % VXM_SIZE];
22171 +
22172 +               /* send entry to userspace */
22173 +               ret = copy_to_user(&data[pos], entry, sizeof(*entry));
22174 +               if (ret)
22175 +                       break;
22176 +       }
22177 +       /* save new index and count */
22178 +       *index = idx;
22179 +       *count = pos;
22180 +       return ret ? ret : (*index < end);
22181 +}
22182 +
22183 +int vc_read_monitor(uint32_t id, void __user *data)
22184 +{
22185 +       struct vcmd_read_monitor_v0 vc_data;
22186 +       int ret;
22187 +
22188 +       if (id >= NR_CPUS)
22189 +               return -EINVAL;
22190 +
22191 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
22192 +               return -EFAULT;
22193 +
22194 +       ret = do_read_monitor((struct __user _vx_mon_entry *)vc_data.data,
22195 +               id, &vc_data.index, &vc_data.count);
22196 +
22197 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
22198 +               return -EFAULT;
22199 +       return ret;
22200 +}
22201 +
22202 +#ifdef CONFIG_COMPAT
22203 +
22204 +int vc_read_monitor_x32(uint32_t id, void __user *data)
22205 +{
22206 +       struct vcmd_read_monitor_v0_x32 vc_data;
22207 +       int ret;
22208 +
22209 +       if (id >= NR_CPUS)
22210 +               return -EINVAL;
22211 +
22212 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
22213 +               return -EFAULT;
22214 +
22215 +       ret = do_read_monitor((struct __user _vx_mon_entry *)
22216 +               compat_ptr(vc_data.data_ptr),
22217 +               id, &vc_data.index, &vc_data.count);
22218 +
22219 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
22220 +               return -EFAULT;
22221 +       return ret;
22222 +}
22223 +
22224 +#endif /* CONFIG_COMPAT */
22225 +
22226 diff -NurpP --minimal linux-2.6.32.1/kernel/vserver/network.c linux-2.6.32.1-vs2.3.0.36.27/kernel/vserver/network.c
22227 --- linux-2.6.32.1/kernel/vserver/network.c     1970-01-01 01:00:00.000000000 +0100
22228 +++ linux-2.6.32.1-vs2.3.0.36.27/kernel/vserver/network.c       2009-12-03 20:04:56.000000000 +0100
22229 @@ -0,0 +1,864 @@
22230 +/*
22231 + *  linux/kernel/vserver/network.c
22232 + *
22233 + *  Virtual Server: Network Support
22234 + *
22235 + *  Copyright (C) 2003-2007  Herbert Pötzl
22236 + *
22237 + *  V0.01  broken out from vcontext V0.05
22238 + *  V0.02  cleaned up implementation
22239 + *  V0.03  added equiv nx commands
22240 + *  V0.04  switch to RCU based hash
22241 + *  V0.05  and back to locking again
22242 + *  V0.06  changed vcmds to nxi arg
22243 + *  V0.07  have __create claim() the nxi
22244 + *
22245 + */
22246 +
22247 +#include <linux/err.h>
22248 +#include <linux/slab.h>
22249 +#include <linux/rcupdate.h>
22250 +
22251 +#include <linux/vs_network.h>
22252 +#include <linux/vs_pid.h>
22253 +#include <linux/vserver/network_cmd.h>
22254 +
22255 +
22256 +atomic_t nx_global_ctotal      = ATOMIC_INIT(0);
22257 +atomic_t nx_global_cactive     = ATOMIC_INIT(0);
22258 +
22259 +static struct kmem_cache *nx_addr_v4_cachep = NULL;
22260 +static struct kmem_cache *nx_addr_v6_cachep = NULL;
22261 +
22262 +
22263 +static int __init init_network(void)
22264 +{
22265 +       nx_addr_v4_cachep = kmem_cache_create("nx_v4_addr_cache",
22266 +               sizeof(struct nx_addr_v4), 0,
22267 +               SLAB_HWCACHE_ALIGN|SLAB_PANIC, NULL);
22268 +       nx_addr_v6_cachep = kmem_cache_create("nx_v6_addr_cache",
22269 +               sizeof(struct nx_addr_v6), 0,
22270 +               SLAB_HWCACHE_ALIGN|SLAB_PANIC, NULL);
22271 +       return 0;
22272 +}
22273 +
22274 +
22275 +/*     __alloc_nx_addr_v4()                                    */
22276 +
22277 +static inline struct nx_addr_v4 *__alloc_nx_addr_v4(void)
22278 +{
22279 +       struct nx_addr_v4 *nxa = kmem_cache_alloc(
22280 +               nx_addr_v4_cachep, GFP_KERNEL);
22281 +
22282 +       if (!IS_ERR(nxa))
22283 +               memset(nxa, 0, sizeof(*nxa));
22284 +       return nxa;
22285 +}
22286 +
22287 +/*     __dealloc_nx_addr_v4()                                  */
22288 +
22289 +static inline void __dealloc_nx_addr_v4(struct nx_addr_v4 *nxa)
22290 +{
22291 +       kmem_cache_free(nx_addr_v4_cachep, nxa);
22292 +}
22293 +
22294 +/*     __dealloc_nx_addr_v4_all()                              */
22295 +
22296 +static inline void __dealloc_nx_addr_v4_all(struct nx_addr_v4 *nxa)
22297 +{
22298 +       while (nxa) {
22299 +               struct nx_addr_v4 *next = nxa->next;
22300 +
22301 +               __dealloc_nx_addr_v4(nxa);
22302 +               nxa = next;
22303 +       }
22304 +}
22305 +
22306 +
22307 +#ifdef CONFIG_IPV6
22308 +
22309 +/*     __alloc_nx_addr_v6()                                    */
22310 +
22311 +static inline struct nx_addr_v6 *__alloc_nx_addr_v6(void)
22312 +{
22313 +       struct nx_addr_v6 *nxa = kmem_cache_alloc(
22314 +               nx_addr_v6_cachep, GFP_KERNEL);
22315 +
22316 +       if (!IS_ERR(nxa))
22317 +               memset(nxa, 0, sizeof(*nxa));
22318 +       return nxa;
22319 +}
22320 +
22321 +/*     __dealloc_nx_addr_v6()                                  */
22322 +
22323 +static inline void __dealloc_nx_addr_v6(struct nx_addr_v6 *nxa)
22324 +{
22325 +       kmem_cache_free(nx_addr_v6_cachep, nxa);
22326 +}
22327 +
22328 +/*     __dealloc_nx_addr_v6_all()                              */
22329 +
22330 +static inline void __dealloc_nx_addr_v6_all(struct nx_addr_v6 *nxa)
22331 +{
22332 +       while (nxa) {
22333 +               struct nx_addr_v6 *next = nxa->next;
22334 +
22335 +               __dealloc_nx_addr_v6(nxa);
22336 +               nxa = next;
22337 +       }
22338 +}
22339 +
22340 +#endif /* CONFIG_IPV6 */
22341 +
22342 +/*     __alloc_nx_info()
22343 +
22344 +       * allocate an initialized nx_info struct
22345 +       * doesn't make it visible (hash)                        */
22346 +
22347 +static struct nx_info *__alloc_nx_info(nid_t nid)
22348 +{
22349 +       struct nx_info *new = NULL;
22350 +
22351 +       vxdprintk(VXD_CBIT(nid, 1), "alloc_nx_info(%d)*", nid);
22352 +
22353 +       /* would this benefit from a slab cache? */
22354 +       new = kmalloc(sizeof(struct nx_info), GFP_KERNEL);
22355 +       if (!new)
22356 +               return 0;
22357 +
22358 +       memset(new, 0, sizeof(struct nx_info));
22359 +       new->nx_id = nid;
22360 +       INIT_HLIST_NODE(&new->nx_hlist);
22361 +       atomic_set(&new->nx_usecnt, 0);
22362 +       atomic_set(&new->nx_tasks, 0);
22363 +       new->nx_state = 0;
22364 +
22365 +       new->nx_flags = NXF_INIT_SET;
22366 +
22367 +       /* rest of init goes here */
22368 +
22369 +       new->v4_lback.s_addr = htonl(INADDR_LOOPBACK);
22370 +       new->v4_bcast.s_addr = htonl(INADDR_BROADCAST);
22371 +
22372 +       vxdprintk(VXD_CBIT(nid, 0),
22373 +               "alloc_nx_info(%d) = %p", nid, new);
22374 +       atomic_inc(&nx_global_ctotal);
22375 +       return new;
22376 +}
22377 +
22378 +/*     __dealloc_nx_info()
22379 +
22380 +       * final disposal of nx_info                             */
22381 +
22382 +static void __dealloc_nx_info(struct nx_info *nxi)
22383 +{
22384 +       vxdprintk(VXD_CBIT(nid, 0),
22385 +               "dealloc_nx_info(%p)", nxi);
22386 +
22387 +       nxi->nx_hlist.next = LIST_POISON1;
22388 +       nxi->nx_id = -1;
22389 +
22390 +       BUG_ON(atomic_read(&nxi->nx_usecnt));
22391 +       BUG_ON(atomic_read(&nxi->nx_tasks));
22392 +
22393 +       __dealloc_nx_addr_v4_all(nxi->v4.next);
22394 +
22395 +       nxi->nx_state |= NXS_RELEASED;
22396 +       kfree(nxi);
22397 +       atomic_dec(&nx_global_ctotal);
22398 +}
22399 +
22400 +static void __shutdown_nx_info(struct nx_info *nxi)
22401 +{
22402 +       nxi->nx_state |= NXS_SHUTDOWN;
22403 +       vs_net_change(nxi, VSC_NETDOWN);
22404 +}
22405 +
22406 +/*     exported stuff                                          */
22407 +
22408 +void free_nx_info(struct nx_info *nxi)
22409 +{
22410 +       /* context shutdown is mandatory */
22411 +       BUG_ON(nxi->nx_state != NXS_SHUTDOWN);
22412 +
22413 +       /* context must not be hashed */
22414 +       BUG_ON(nxi->nx_state & NXS_HASHED);
22415 +
22416 +       BUG_ON(atomic_read(&nxi->nx_usecnt));
22417 +       BUG_ON(atomic_read(&nxi->nx_tasks));
22418 +
22419 +       __dealloc_nx_info(nxi);
22420 +}
22421 +
22422 +
22423 +void __nx_set_lback(struct nx_info *nxi)
22424 +{
22425 +       int nid = nxi->nx_id;
22426 +       __be32 lback = htonl(INADDR_LOOPBACK ^ ((nid & 0xFFFF) << 8));
22427 +
22428 +       nxi->v4_lback.s_addr = lback;
22429 +}
22430 +
22431 +extern int __nx_inet_add_lback(__be32 addr);
22432 +extern int __nx_inet_del_lback(__be32 addr);
22433 +
22434 +
22435 +/*     hash table for nx_info hash */
22436 +
22437 +#define NX_HASH_SIZE   13
22438 +
22439 +struct hlist_head nx_info_hash[NX_HASH_SIZE];
22440 +
22441 +static spinlock_t nx_info_hash_lock = SPIN_LOCK_UNLOCKED;
22442 +
22443 +
22444 +static inline unsigned int __hashval(nid_t nid)
22445 +{
22446 +       return (nid % NX_HASH_SIZE);
22447 +}
22448 +
22449 +
22450 +
22451 +/*     __hash_nx_info()
22452 +
22453 +       * add the nxi to the global hash table
22454 +       * requires the hash_lock to be held                     */
22455 +
22456 +static inline void __hash_nx_info(struct nx_info *nxi)
22457 +{
22458 +       struct hlist_head *head;
22459 +
22460 +       vxd_assert_lock(&nx_info_hash_lock);
22461 +       vxdprintk(VXD_CBIT(nid, 4),
22462 +               "__hash_nx_info: %p[#%d]", nxi, nxi->nx_id);
22463 +
22464 +       /* context must not be hashed */
22465 +       BUG_ON(nx_info_state(nxi, NXS_HASHED));
22466 +
22467 +       nxi->nx_state |= NXS_HASHED;
22468 +       head = &nx_info_hash[__hashval(nxi->nx_id)];
22469 +       hlist_add_head(&nxi->nx_hlist, head);
22470 +       atomic_inc(&nx_global_cactive);
22471 +}
22472 +
22473 +/*     __unhash_nx_info()
22474 +
22475 +       * remove the nxi from the global hash table
22476 +       * requires the hash_lock to be held                     */
22477 +
22478 +static inline void __unhash_nx_info(struct nx_info *nxi)
22479 +{
22480 +       vxd_assert_lock(&nx_info_hash_lock);
22481 +       vxdprintk(VXD_CBIT(nid, 4),
22482 +               "__unhash_nx_info: %p[#%d.%d.%d]", nxi, nxi->nx_id,
22483 +               atomic_read(&nxi->nx_usecnt), atomic_read(&nxi->nx_tasks));
22484 +
22485 +       /* context must be hashed */
22486 +       BUG_ON(!nx_info_state(nxi, NXS_HASHED));
22487 +       /* but without tasks */
22488 +       BUG_ON(atomic_read(&nxi->nx_tasks));
22489 +
22490 +       nxi->nx_state &= ~NXS_HASHED;
22491 +       hlist_del(&nxi->nx_hlist);
22492 +       atomic_dec(&nx_global_cactive);
22493 +}
22494 +
22495 +
22496 +/*     __lookup_nx_info()
22497 +
22498 +       * requires the hash_lock to be held
22499 +       * doesn't increment the nx_refcnt                       */
22500 +
22501 +static inline struct nx_info *__lookup_nx_info(nid_t nid)
22502 +{
22503 +       struct hlist_head *head = &nx_info_hash[__hashval(nid)];
22504 +       struct hlist_node *pos;
22505 +       struct nx_info *nxi;
22506 +
22507 +       vxd_assert_lock(&nx_info_hash_lock);
22508 +       hlist_for_each(pos, head) {
22509 +               nxi = hlist_entry(pos, struct nx_info, nx_hlist);
22510 +
22511 +               if (nxi->nx_id == nid)
22512 +                       goto found;
22513 +       }
22514 +       nxi = NULL;
22515 +found:
22516 +       vxdprintk(VXD_CBIT(nid, 0),
22517 +               "__lookup_nx_info(#%u): %p[#%u]",
22518 +               nid, nxi, nxi ? nxi->nx_id : 0);
22519 +       return nxi;
22520 +}
22521 +
22522 +
22523 +/*     __create_nx_info()
22524 +
22525 +       * create the requested context
22526 +       * get(), claim() and hash it                            */
22527 +
22528 +static struct nx_info *__create_nx_info(int id)
22529 +{
22530 +       struct nx_info *new, *nxi = NULL;
22531 +
22532 +       vxdprintk(VXD_CBIT(nid, 1), "create_nx_info(%d)*", id);
22533 +
22534 +       if (!(new = __alloc_nx_info(id)))
22535 +               return ERR_PTR(-ENOMEM);
22536 +
22537 +       /* required to make dynamic xids unique */
22538 +       spin_lock(&nx_info_hash_lock);
22539 +
22540 +       /* static context requested */
22541 +       if ((nxi = __lookup_nx_info(id))) {
22542 +               vxdprintk(VXD_CBIT(nid, 0),
22543 +                       "create_nx_info(%d) = %p (already there)", id, nxi);
22544 +               if (nx_info_flags(nxi, NXF_STATE_SETUP, 0))
22545 +                       nxi = ERR_PTR(-EBUSY);
22546 +               else
22547 +                       nxi = ERR_PTR(-EEXIST);
22548 +               goto out_unlock;
22549 +       }
22550 +       /* new context */
22551 +       vxdprintk(VXD_CBIT(nid, 0),
22552 +               "create_nx_info(%d) = %p (new)", id, new);
22553 +       claim_nx_info(new, NULL);
22554 +       __nx_set_lback(new);
22555 +       __hash_nx_info(get_nx_info(new));
22556 +       nxi = new, new = NULL;
22557 +
22558 +out_unlock:
22559 +       spin_unlock(&nx_info_hash_lock);
22560 +       if (new)
22561 +               __dealloc_nx_info(new);
22562 +       return nxi;
22563 +}
22564 +
22565 +
22566 +
22567 +/*     exported stuff                                          */
22568 +
22569 +
22570 +void unhash_nx_info(struct nx_info *nxi)
22571 +{
22572 +       __shutdown_nx_info(nxi);
22573 +       spin_lock(&nx_info_hash_lock);
22574 +       __unhash_nx_info(nxi);
22575 +       spin_unlock(&nx_info_hash_lock);
22576 +}
22577 +
22578 +/*     lookup_nx_info()
22579 +
22580 +       * search for a nx_info and get() it
22581 +       * negative id means current                             */
22582 +
22583 +struct nx_info *lookup_nx_info(int id)
22584 +{
22585 +       struct nx_info *nxi = NULL;
22586 +
22587 +       if (id < 0) {
22588 +               nxi = get_nx_info(current_nx_info());
22589 +       } else if (id > 1) {
22590 +               spin_lock(&nx_info_hash_lock);
22591 +               nxi = get_nx_info(__lookup_nx_info(id));
22592 +               spin_unlock(&nx_info_hash_lock);
22593 +       }
22594 +       return nxi;
22595 +}
22596 +
22597 +/*     nid_is_hashed()
22598 +
22599 +       * verify that nid is still hashed                       */
22600 +
22601 +int nid_is_hashed(nid_t nid)
22602 +{
22603 +       int hashed;
22604 +
22605 +       spin_lock(&nx_info_hash_lock);
22606 +       hashed = (__lookup_nx_info(nid) != NULL);
22607 +       spin_unlock(&nx_info_hash_lock);
22608 +       return hashed;
22609 +}
22610 +
22611 +
22612 +#ifdef CONFIG_PROC_FS
22613 +
22614 +/*     get_nid_list()
22615 +
22616 +       * get a subset of hashed nids for proc
22617 +       * assumes size is at least one                          */
22618 +
22619 +int get_nid_list(int index, unsigned int *nids, int size)
22620 +{
22621 +       int hindex, nr_nids = 0;
22622 +
22623 +       /* only show current and children */
22624 +       if (!nx_check(0, VS_ADMIN | VS_WATCH)) {
22625 +               if (index > 0)
22626 +                       return 0;
22627 +               nids[nr_nids] = nx_current_nid();
22628 +               return 1;
22629 +       }
22630 +
22631 +       for (hindex = 0; hindex < NX_HASH_SIZE; hindex++) {
22632 +               struct hlist_head *head = &nx_info_hash[hindex];
22633 +               struct hlist_node *pos;
22634 +
22635 +               spin_lock(&nx_info_hash_lock);
22636 +               hlist_for_each(pos, head) {
22637 +                       struct nx_info *nxi;
22638 +
22639 +                       if (--index > 0)
22640 +                               continue;
22641 +
22642 +                       nxi = hlist_entry(pos, struct nx_info, nx_hlist);
22643 +                       nids[nr_nids] = nxi->nx_id;
22644 +                       if (++nr_nids >= size) {
22645 +                               spin_unlock(&nx_info_hash_lock);
22646 +                               goto out;
22647 +                       }
22648 +               }
22649 +               /* keep the lock time short */
22650 +               spin_unlock(&nx_info_hash_lock);
22651 +       }
22652 +out:
22653 +       return nr_nids;
22654 +}
22655 +#endif
22656 +
22657 +
22658 +/*
22659 + *     migrate task to new network
22660 + *     gets nxi, puts old_nxi on change
22661 + */
22662 +
22663 +int nx_migrate_task(struct task_struct *p, struct nx_info *nxi)
22664 +{
22665 +       struct nx_info *old_nxi;
22666 +       int ret = 0;
22667 +
22668 +       if (!p || !nxi)
22669 +               BUG();
22670 +
22671 +       vxdprintk(VXD_CBIT(nid, 5),
22672 +               "nx_migrate_task(%p,%p[#%d.%d.%d])",
22673 +               p, nxi, nxi->nx_id,
22674 +               atomic_read(&nxi->nx_usecnt),
22675 +               atomic_read(&nxi->nx_tasks));
22676 +
22677 +       if (nx_info_flags(nxi, NXF_INFO_PRIVATE, 0) &&
22678 +               !nx_info_flags(nxi, NXF_STATE_SETUP, 0))
22679 +               return -EACCES;
22680 +
22681 +       if (nx_info_state(nxi, NXS_SHUTDOWN))
22682 +               return -EFAULT;
22683 +
22684 +       /* maybe disallow this completely? */
22685 +       old_nxi = task_get_nx_info(p);
22686 +       if (old_nxi == nxi)
22687 +               goto out;
22688 +
22689 +       task_lock(p);
22690 +       if (old_nxi)
22691 +               clr_nx_info(&p->nx_info);
22692 +       claim_nx_info(nxi, p);
22693 +       set_nx_info(&p->nx_info, nxi);
22694 +       p->nid = nxi->nx_id;
22695 +       task_unlock(p);
22696 +
22697 +       vxdprintk(VXD_CBIT(nid, 5),
22698 +               "moved task %p into nxi:%p[#%d]",
22699 +               p, nxi, nxi->nx_id);
22700 +
22701 +       if (old_nxi)
22702 +               release_nx_info(old_nxi, p);
22703 +       ret = 0;
22704 +out:
22705 +       put_nx_info(old_nxi);
22706 +       return ret;
22707 +}
22708 +
22709 +
22710 +void nx_set_persistent(struct nx_info *nxi)
22711 +{
22712 +       vxdprintk(VXD_CBIT(nid, 6),
22713 +               "nx_set_persistent(%p[#%d])", nxi, nxi->nx_id);
22714 +
22715 +       get_nx_info(nxi);
22716 +       claim_nx_info(nxi, NULL);
22717 +}
22718 +
22719 +void nx_clear_persistent(struct nx_info *nxi)
22720 +{
22721 +       vxdprintk(VXD_CBIT(nid, 6),
22722 +               "nx_clear_persistent(%p[#%d])", nxi, nxi->nx_id);
22723 +
22724 +       release_nx_info(nxi, NULL);
22725 +       put_nx_info(nxi);
22726 +}
22727 +
22728 +void nx_update_persistent(struct nx_info *nxi)
22729 +{
22730 +       if (nx_info_flags(nxi, NXF_PERSISTENT, 0))
22731 +               nx_set_persistent(nxi);
22732 +       else
22733 +               nx_clear_persistent(nxi);
22734 +}
22735 +
22736 +/* vserver syscall commands below here */
22737 +
22738 +/* taks nid and nx_info functions */
22739 +
22740 +#include <asm/uaccess.h>
22741 +
22742 +
22743 +int vc_task_nid(uint32_t id)
22744 +{
22745 +       nid_t nid;
22746 +
22747 +       if (id) {
22748 +               struct task_struct *tsk;
22749 +
22750 +               read_lock(&tasklist_lock);
22751 +               tsk = find_task_by_real_pid(id);
22752 +               nid = (tsk) ? tsk->nid : -ESRCH;
22753 +               read_unlock(&tasklist_lock);
22754 +       } else
22755 +               nid = nx_current_nid();
22756 +       return nid;
22757 +}
22758 +
22759 +
22760 +int vc_nx_info(struct nx_info *nxi, void __user *data)
22761 +{
22762 +       struct vcmd_nx_info_v0 vc_data;
22763 +
22764 +       vc_data.nid = nxi->nx_id;
22765 +
22766 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
22767 +               return -EFAULT;
22768 +       return 0;
22769 +}
22770 +
22771 +
22772 +/* network functions */
22773 +
22774 +int vc_net_create(uint32_t nid, void __user *data)
22775 +{
22776 +       struct vcmd_net_create vc_data = { .flagword = NXF_INIT_SET };
22777 +       struct nx_info *new_nxi;
22778 +       int ret;
22779 +
22780 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
22781 +               return -EFAULT;
22782 +
22783 +       if ((nid > MAX_S_CONTEXT) || (nid < 2))
22784 +               return -EINVAL;
22785 +
22786 +       new_nxi = __create_nx_info(nid);
22787 +       if (IS_ERR(new_nxi))
22788 +               return PTR_ERR(new_nxi);
22789 +
22790 +       /* initial flags */
22791 +       new_nxi->nx_flags = vc_data.flagword;
22792 +
22793 +       ret = -ENOEXEC;
22794 +       if (vs_net_change(new_nxi, VSC_NETUP))
22795 +               goto out;
22796 +
22797 +       ret = nx_migrate_task(current, new_nxi);
22798 +       if (ret)
22799 +               goto out;
22800 +
22801 +       /* return context id on success */
22802 +       ret = new_nxi->nx_id;
22803 +
22804 +       /* get a reference for persistent contexts */
22805 +       if ((vc_data.flagword & NXF_PERSISTENT))
22806 +               nx_set_persistent(new_nxi);
22807 +out:
22808 +       release_nx_info(new_nxi, NULL);
22809 +       put_nx_info(new_nxi);
22810 +       return ret;
22811 +}
22812 +
22813 +
22814 +int vc_net_migrate(struct nx_info *nxi, void __user *data)
22815 +{
22816 +       return nx_migrate_task(current, nxi);
22817 +}
22818 +
22819 +
22820 +
22821 +int do_add_v4_addr(struct nx_info *nxi, __be32 ip, __be32 ip2, __be32 mask,
22822 +       uint16_t type, uint16_t flags)
22823 +{
22824 +       struct nx_addr_v4 *nxa = &nxi->v4;
22825 +
22826 +       if (NX_IPV4(nxi)) {
22827 +               /* locate last entry */
22828 +               for (; nxa->next; nxa = nxa->next);
22829 +               nxa->next = __alloc_nx_addr_v4();
22830 +               nxa = nxa->next;
22831 +
22832 +               if (IS_ERR(nxa))
22833 +                       return PTR_ERR(nxa);
22834 +       }
22835 +
22836 +       if (nxi->v4.next)
22837 +               /* remove single ip for ip list */
22838 +               nxi->nx_flags &= ~NXF_SINGLE_IP;
22839 +
22840 +       nxa->ip[0].s_addr = ip;
22841 +       nxa->ip[1].s_addr = ip2;
22842 +       nxa->mask.s_addr = mask;
22843 +       nxa->type = type;
22844 +       nxa->flags = flags;
22845 +       return 0;
22846 +}
22847 +
22848 +
22849 +int vc_net_add(struct nx_info *nxi, void __user *data)
22850 +{
22851 +       struct vcmd_net_addr_v0 vc_data;
22852 +       int index, ret = 0;
22853 +
22854 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
22855 +               return -EFAULT;
22856 +
22857 +       switch (vc_data.type) {
22858 +       case NXA_TYPE_IPV4:
22859 +               if ((vc_data.count < 1) || (vc_data.count > 4))
22860 +                       return -EINVAL;
22861 +
22862 +               index = 0;
22863 +               while (index < vc_data.count) {
22864 +                       ret = do_add_v4_addr(nxi, vc_data.ip[index].s_addr, 0,
22865 +                               vc_data.mask[index].s_addr, NXA_TYPE_ADDR, 0);
22866 +                       if (ret)
22867 +                               return ret;
22868 +                       index++;
22869 +               }
22870 +               ret = index;
22871 +               break;
22872 +
22873 +       case NXA_TYPE_IPV4|NXA_MOD_BCAST:
22874 +               nxi->v4_bcast = vc_data.ip[0];
22875 +               ret = 1;
22876 +               break;
22877 +
22878 +       case NXA_TYPE_IPV4|NXA_MOD_LBACK:
22879 +               nxi->v4_lback = vc_data.ip[0];
22880 +               ret = 1;
22881 +               break;
22882 +
22883 +       default:
22884 +               ret = -EINVAL;
22885 +               break;
22886 +       }
22887 +       return ret;
22888 +}
22889 +
22890 +int vc_net_remove(struct nx_info *nxi, void __user *data)
22891 +{
22892 +       struct vcmd_net_addr_v0 vc_data;
22893 +
22894 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
22895 +               return -EFAULT;
22896 +
22897 +       switch (vc_data.type) {
22898 +       case NXA_TYPE_ANY:
22899 +               __dealloc_nx_addr_v4_all(xchg(&nxi->v4.next, NULL));
22900 +               memset(&nxi->v4, 0, sizeof(nxi->v4));
22901 +               break;
22902 +
22903 +       default:
22904 +               return -EINVAL;
22905 +       }
22906 +       return 0;
22907 +}
22908 +
22909 +
22910 +int vc_net_add_ipv4(struct nx_info *nxi, void __user *data)
22911 +{
22912 +       struct vcmd_net_addr_ipv4_v1 vc_data;
22913 +
22914 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
22915 +               return -EFAULT;
22916 +
22917 +       switch (vc_data.type) {
22918 +       case NXA_TYPE_ADDR:
22919 +       case NXA_TYPE_RANGE:
22920 +       case NXA_TYPE_MASK:
22921 +               return do_add_v4_addr(nxi, vc_data.ip.s_addr, 0,
22922 +                       vc_data.mask.s_addr, vc_data.type, vc_data.flags);
22923 +
22924 +       case NXA_TYPE_ADDR | NXA_MOD_BCAST:
22925 +               nxi->v4_bcast = vc_data.ip;
22926 +               break;
22927 +
22928 +       case NXA_TYPE_ADDR | NXA_MOD_LBACK:
22929 +               nxi->v4_lback = vc_data.ip;
22930 +               break;
22931 +
22932 +       default:
22933 +               return -EINVAL;
22934 +       }
22935 +       return 0;
22936 +}
22937 +
22938 +int vc_net_remove_ipv4(struct nx_info *nxi, void __user *data)
22939 +{
22940 +       struct vcmd_net_addr_ipv4_v1 vc_data;
22941 +
22942 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
22943 +               return -EFAULT;
22944 +
22945 +       switch (vc_data.type) {
22946 +/*     case NXA_TYPE_ADDR:
22947 +               break;          */
22948 +
22949 +       case NXA_TYPE_ANY:
22950 +               __dealloc_nx_addr_v4_all(xchg(&nxi->v4.next, NULL));
22951 +               memset(&nxi->v4, 0, sizeof(nxi->v4));
22952 +               break;
22953 +
22954 +       default:
22955 +               return -EINVAL;
22956 +       }
22957 +       return 0;
22958 +}
22959 +
22960 +
22961 +#ifdef CONFIG_IPV6
22962 +
22963 +int do_add_v6_addr(struct nx_info *nxi,
22964 +       struct in6_addr *ip, struct in6_addr *mask,
22965 +       uint32_t prefix, uint16_t type, uint16_t flags)
22966 +{
22967 +       struct nx_addr_v6 *nxa = &nxi->v6;
22968 +
22969 +       if (NX_IPV6(nxi)) {
22970 +               /* locate last entry */
22971 +               for (; nxa->next; nxa = nxa->next);
22972 +               nxa->next = __alloc_nx_addr_v6();
22973 +               nxa = nxa->next;
22974 +
22975 +               if (IS_ERR(nxa))
22976 +                       return PTR_ERR(nxa);
22977 +       }
22978 +
22979 +       nxa->ip = *ip;
22980 +       nxa->mask = *mask;
22981 +       nxa->prefix = prefix;
22982 +       nxa->type = type;
22983 +       nxa->flags = flags;
22984 +       return 0;
22985 +}
22986 +
22987 +
22988 +int vc_net_add_ipv6(struct nx_info *nxi, void __user *data)
22989 +{
22990 +       struct vcmd_net_addr_ipv6_v1 vc_data;
22991 +
22992 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
22993 +               return -EFAULT;
22994 +
22995 +       switch (vc_data.type) {
22996 +       case NXA_TYPE_ADDR:
22997 +       case NXA_TYPE_MASK:
22998 +               return do_add_v6_addr(nxi, &vc_data.ip, &vc_data.mask,
22999 +                       vc_data.prefix, vc_data.type, vc_data.flags);
23000 +       default:
23001 +               return -EINVAL;
23002 +       }
23003 +       return 0;
23004 +}
23005 +
23006 +int vc_net_remove_ipv6(struct nx_info *nxi, void __user *data)
23007 +{
23008 +       struct vcmd_net_addr_ipv6_v1 vc_data;
23009 +
23010 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
23011 +               return -EFAULT;
23012 +
23013 +       switch (vc_data.type) {
23014 +       case NXA_TYPE_ANY:
23015 +               __dealloc_nx_addr_v6_all(xchg(&nxi->v6.next, NULL));
23016 +               memset(&nxi->v6, 0, sizeof(nxi->v6));
23017 +               break;
23018 +
23019 +       default:
23020 +               return -EINVAL;
23021 +       }
23022 +       return 0;
23023 +}
23024 +
23025 +#endif /* CONFIG_IPV6 */
23026 +
23027 +
23028 +int vc_get_nflags(struct nx_info *nxi, void __user *data)
23029 +{
23030 +       struct vcmd_net_flags_v0 vc_data;
23031 +
23032 +       vc_data.flagword = nxi->nx_flags;
23033 +
23034 +       /* special STATE flag handling */
23035 +       vc_data.mask = vs_mask_flags(~0ULL, nxi->nx_flags, NXF_ONE_TIME);
23036 +
23037 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
23038 +               return -EFAULT;
23039 +       return 0;
23040 +}
23041 +
23042 +int vc_set_nflags(struct nx_info *nxi, void __user *data)
23043 +{
23044 +       struct vcmd_net_flags_v0 vc_data;
23045 +       uint64_t mask, trigger;
23046 +
23047 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
23048 +               return -EFAULT;
23049 +
23050 +       /* special STATE flag handling */
23051 +       mask = vs_mask_mask(vc_data.mask, nxi->nx_flags, NXF_ONE_TIME);
23052 +       trigger = (mask & nxi->nx_flags) ^ (mask & vc_data.flagword);
23053 +
23054 +       nxi->nx_flags = vs_mask_flags(nxi->nx_flags,
23055 +               vc_data.flagword, mask);
23056 +       if (trigger & NXF_PERSISTENT)
23057 +               nx_update_persistent(nxi);
23058 +
23059 +       return 0;
23060 +}
23061 +
23062 +int vc_get_ncaps(struct nx_info *nxi, void __user *data)
23063 +{
23064 +       struct vcmd_net_caps_v0 vc_data;
23065 +
23066 +       vc_data.ncaps = nxi->nx_ncaps;
23067 +       vc_data.cmask = ~0ULL;
23068 +
23069 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
23070 +               return -EFAULT;
23071 +       return 0;
23072 +}
23073 +
23074 +int vc_set_ncaps(struct nx_info *nxi, void __user *data)
23075 +{
23076 +       struct vcmd_net_caps_v0 vc_data;
23077 +
23078 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
23079 +               return -EFAULT;
23080 +
23081 +       nxi->nx_ncaps = vs_mask_flags(nxi->nx_ncaps,
23082 +               vc_data.ncaps, vc_data.cmask);
23083 +       return 0;
23084 +}
23085 +
23086 +
23087 +#include <linux/module.h>
23088 +
23089 +module_init(init_network);
23090 +
23091 +EXPORT_SYMBOL_GPL(free_nx_info);
23092 +EXPORT_SYMBOL_GPL(unhash_nx_info);
23093 +
23094 diff -NurpP --minimal linux-2.6.32.1/kernel/vserver/proc.c linux-2.6.32.1-vs2.3.0.36.27/kernel/vserver/proc.c
23095 --- linux-2.6.32.1/kernel/vserver/proc.c        1970-01-01 01:00:00.000000000 +0100
23096 +++ linux-2.6.32.1-vs2.3.0.36.27/kernel/vserver/proc.c  2009-12-03 20:04:56.000000000 +0100
23097 @@ -0,0 +1,1098 @@
23098 +/*
23099 + *  linux/kernel/vserver/proc.c
23100 + *
23101 + *  Virtual Context Support
23102 + *
23103 + *  Copyright (C) 2003-2007  Herbert Pötzl
23104 + *
23105 + *  V0.01  basic structure
23106 + *  V0.02  adaptation vs1.3.0
23107 + *  V0.03  proc permissions
23108 + *  V0.04  locking/generic
23109 + *  V0.05  next generation procfs
23110 + *  V0.06  inode validation
23111 + *  V0.07  generic rewrite vid
23112 + *  V0.08  remove inode type
23113 + *
23114 + */
23115 +
23116 +#include <linux/proc_fs.h>
23117 +#include <linux/fs_struct.h>
23118 +#include <linux/mount.h>
23119 +#include <asm/unistd.h>
23120 +
23121 +#include <linux/vs_context.h>
23122 +#include <linux/vs_network.h>
23123 +#include <linux/vs_cvirt.h>
23124 +
23125 +#include <linux/in.h>
23126 +#include <linux/inetdevice.h>
23127 +#include <linux/vs_inet.h>
23128 +#include <linux/vs_inet6.h>
23129 +
23130 +#include <linux/vserver/global.h>
23131 +
23132 +#include "cvirt_proc.h"
23133 +#include "cacct_proc.h"
23134 +#include "limit_proc.h"
23135 +#include "sched_proc.h"
23136 +#include "vci_config.h"
23137 +
23138 +
23139 +static inline char *print_cap_t(char *buffer, kernel_cap_t *c)
23140 +{
23141 +       unsigned __capi;
23142 +
23143 +       CAP_FOR_EACH_U32(__capi) {
23144 +               buffer += sprintf(buffer, "%08x",
23145 +                       c->cap[(_KERNEL_CAPABILITY_U32S-1) - __capi]);
23146 +       }
23147 +       return buffer;
23148 +}
23149 +
23150 +
23151 +static struct proc_dir_entry *proc_virtual;
23152 +
23153 +static struct proc_dir_entry *proc_virtnet;
23154 +
23155 +
23156 +/* first the actual feeds */
23157 +
23158 +
23159 +static int proc_vci(char *buffer)
23160 +{
23161 +       return sprintf(buffer,
23162 +               "VCIVersion:\t%04x:%04x\n"
23163 +               "VCISyscall:\t%d\n"
23164 +               "VCIKernel:\t%08x\n",
23165 +               VCI_VERSION >> 16,
23166 +               VCI_VERSION & 0xFFFF,
23167 +               __NR_vserver,
23168 +               vci_kernel_config());
23169 +}
23170 +
23171 +static int proc_virtual_info(char *buffer)
23172 +{
23173 +       return proc_vci(buffer);
23174 +}
23175 +
23176 +static int proc_virtual_status(char *buffer)
23177 +{
23178 +       return sprintf(buffer,
23179 +               "#CTotal:\t%d\n"
23180 +               "#CActive:\t%d\n"
23181 +               "#NSProxy:\t%d\t%d %d %d %d %d %d\n"
23182 +               "#InitTask:\t%d\t%d %d\n",
23183 +               atomic_read(&vx_global_ctotal),
23184 +               atomic_read(&vx_global_cactive),
23185 +               atomic_read(&vs_global_nsproxy),
23186 +               atomic_read(&vs_global_fs),
23187 +               atomic_read(&vs_global_mnt_ns),
23188 +               atomic_read(&vs_global_uts_ns),
23189 +               atomic_read(&nr_ipc_ns),
23190 +               atomic_read(&vs_global_user_ns),
23191 +               atomic_read(&vs_global_pid_ns),
23192 +               atomic_read(&init_task.usage),
23193 +               atomic_read(&init_task.nsproxy->count),
23194 +               init_task.fs->users);
23195 +}
23196 +
23197 +
23198 +int proc_vxi_info(struct vx_info *vxi, char *buffer)
23199 +{
23200 +       int length;
23201 +
23202 +       length = sprintf(buffer,
23203 +               "ID:\t%d\n"
23204 +               "Info:\t%p\n"
23205 +               "Init:\t%d\n"
23206 +               "OOM:\t%lld\n",
23207 +               vxi->vx_id,
23208 +               vxi,
23209 +               vxi->vx_initpid,
23210 +               vxi->vx_badness_bias);
23211 +       return length;
23212 +}
23213 +
23214 +int proc_vxi_status(struct vx_info *vxi, char *buffer)
23215 +{
23216 +       char *orig = buffer;
23217 +
23218 +       buffer += sprintf(buffer,
23219 +               "UseCnt:\t%d\n"
23220 +               "Tasks:\t%d\n"
23221 +               "Flags:\t%016llx\n",
23222 +               atomic_read(&vxi->vx_usecnt),
23223 +               atomic_read(&vxi->vx_tasks),
23224 +               (unsigned long long)vxi->vx_flags);
23225 +
23226 +       buffer += sprintf(buffer, "BCaps:\t");
23227 +       buffer = print_cap_t(buffer, &vxi->vx_bcaps);
23228 +       buffer += sprintf(buffer, "\n");
23229 +
23230 +       buffer += sprintf(buffer,
23231 +               "CCaps:\t%016llx\n"
23232 +               "Spaces:\t%08lx %08lx\n",
23233 +               (unsigned long long)vxi->vx_ccaps,
23234 +               vxi->vx_nsmask[0], vxi->vx_nsmask[1]);
23235 +       return buffer - orig;
23236 +}
23237 +
23238 +int proc_vxi_limit(struct vx_info *vxi, char *buffer)
23239 +{
23240 +       return vx_info_proc_limit(&vxi->limit, buffer);
23241 +}
23242 +
23243 +int proc_vxi_sched(struct vx_info *vxi, char *buffer)
23244 +{
23245 +       int cpu, length;
23246 +
23247 +       length = vx_info_proc_sched(&vxi->sched, buffer);
23248 +       for_each_online_cpu(cpu) {
23249 +               length += vx_info_proc_sched_pc(
23250 +                       &vx_per_cpu(vxi, sched_pc, cpu),
23251 +                       buffer + length, cpu);
23252 +       }
23253 +       return length;
23254 +}
23255 +
23256 +int proc_vxi_nsproxy0(struct vx_info *vxi, char *buffer)
23257 +{
23258 +       return vx_info_proc_nsproxy(vxi->vx_nsproxy[0], buffer);
23259 +}
23260 +
23261 +int proc_vxi_nsproxy1(struct vx_info *vxi, char *buffer)
23262 +{
23263 +       return vx_info_proc_nsproxy(vxi->vx_nsproxy[1], buffer);
23264 +}
23265 +
23266 +int proc_vxi_cvirt(struct vx_info *vxi, char *buffer)
23267 +{
23268 +       int cpu, length;
23269 +
23270 +       vx_update_load(vxi);
23271 +       length = vx_info_proc_cvirt(&vxi->cvirt, buffer);
23272 +       for_each_online_cpu(cpu) {
23273 +               length += vx_info_proc_cvirt_pc(
23274 +                       &vx_per_cpu(vxi, cvirt_pc, cpu),
23275 +                       buffer + length, cpu);
23276 +       }
23277 +       return length;
23278 +}
23279 +
23280 +int proc_vxi_cacct(struct vx_info *vxi, char *buffer)
23281 +{
23282 +       return vx_info_proc_cacct(&vxi->cacct, buffer);
23283 +}
23284 +
23285 +
23286 +static int proc_virtnet_info(char *buffer)
23287 +{
23288 +       return proc_vci(buffer);
23289 +}
23290 +
23291 +static int proc_virtnet_status(char *buffer)
23292 +{
23293 +       return sprintf(buffer,
23294 +               "#CTotal:\t%d\n"
23295 +               "#CActive:\t%d\n",
23296 +               atomic_read(&nx_global_ctotal),
23297 +               atomic_read(&nx_global_cactive));
23298 +}
23299 +
23300 +int proc_nxi_info(struct nx_info *nxi, char *buffer)
23301 +{
23302 +       struct nx_addr_v4 *v4a;
23303 +#ifdef CONFIG_IPV6
23304 +       struct nx_addr_v6 *v6a;
23305 +#endif
23306 +       int length, i;
23307 +
23308 +       length = sprintf(buffer,
23309 +               "ID:\t%d\n"
23310 +               "Info:\t%p\n"
23311 +               "Bcast:\t" NIPQUAD_FMT "\n"
23312 +               "Lback:\t" NIPQUAD_FMT "\n",
23313 +               nxi->nx_id,
23314 +               nxi,
23315 +               NIPQUAD(nxi->v4_bcast.s_addr),
23316 +               NIPQUAD(nxi->v4_lback.s_addr));
23317 +
23318 +       if (!NX_IPV4(nxi))
23319 +               goto skip_v4;
23320 +       for (i = 0, v4a = &nxi->v4; v4a; i++, v4a = v4a->next)
23321 +               length += sprintf(buffer + length, "%d:\t" NXAV4_FMT "\n",
23322 +                       i, NXAV4(v4a));
23323 +skip_v4:
23324 +#ifdef CONFIG_IPV6
23325 +       if (!NX_IPV6(nxi))
23326 +               goto skip_v6;
23327 +       for (i = 0, v6a = &nxi->v6; v6a; i++, v6a = v6a->next)
23328 +               length += sprintf(buffer + length, "%d:\t" NXAV6_FMT "\n",
23329 +                       i, NXAV6(v6a));
23330 +skip_v6:
23331 +#endif
23332 +       return length;
23333 +}
23334 +
23335 +int proc_nxi_status(struct nx_info *nxi, char *buffer)
23336 +{
23337 +       int length;
23338 +
23339 +       length = sprintf(buffer,
23340 +               "UseCnt:\t%d\n"
23341 +               "Tasks:\t%d\n"
23342 +               "Flags:\t%016llx\n"
23343 +               "NCaps:\t%016llx\n",
23344 +               atomic_read(&nxi->nx_usecnt),
23345 +               atomic_read(&nxi->nx_tasks),
23346 +               (unsigned long long)nxi->nx_flags,
23347 +               (unsigned long long)nxi->nx_ncaps);
23348 +       return length;
23349 +}
23350 +
23351 +
23352 +
23353 +/* here the inode helpers */
23354 +
23355 +struct vs_entry {
23356 +       int len;
23357 +       char *name;
23358 +       mode_t mode;
23359 +       struct inode_operations *iop;
23360 +       struct file_operations *fop;
23361 +       union proc_op op;
23362 +};
23363 +
23364 +static struct inode *vs_proc_make_inode(struct super_block *sb, struct vs_entry *p)
23365 +{
23366 +       struct inode *inode = new_inode(sb);
23367 +
23368 +       if (!inode)
23369 +               goto out;
23370 +
23371 +       inode->i_mode = p->mode;
23372 +       if (p->iop)
23373 +               inode->i_op = p->iop;
23374 +       if (p->fop)
23375 +               inode->i_fop = p->fop;
23376 +
23377 +       inode->i_nlink = (p->mode & S_IFDIR) ? 2 : 1;
23378 +       inode->i_flags |= S_IMMUTABLE;
23379 +
23380 +       inode->i_mtime = inode->i_atime = inode->i_ctime = CURRENT_TIME;
23381 +
23382 +       inode->i_uid = 0;
23383 +       inode->i_gid = 0;
23384 +       inode->i_tag = 0;
23385 +out:
23386 +       return inode;
23387 +}
23388 +
23389 +static struct dentry *vs_proc_instantiate(struct inode *dir,
23390 +       struct dentry *dentry, int id, void *ptr)
23391 +{
23392 +       struct vs_entry *p = ptr;
23393 +       struct inode *inode = vs_proc_make_inode(dir->i_sb, p);
23394 +       struct dentry *error = ERR_PTR(-EINVAL);
23395 +
23396 +       if (!inode)
23397 +               goto out;
23398 +
23399 +       PROC_I(inode)->op = p->op;
23400 +       PROC_I(inode)->fd = id;
23401 +       d_add(dentry, inode);
23402 +       error = NULL;
23403 +out:
23404 +       return error;
23405 +}
23406 +
23407 +/* Lookups */
23408 +
23409 +typedef struct dentry *instantiate_t(struct inode *, struct dentry *, int, void *);
23410 +
23411 +/*
23412 + * Fill a directory entry.
23413 + *
23414 + * If possible create the dcache entry and derive our inode number and
23415 + * file type from dcache entry.
23416 + *
23417 + * Since all of the proc inode numbers are dynamically generated, the inode
23418 + * numbers do not exist until the inode is cache.  This means creating the
23419 + * the dcache entry in readdir is necessary to keep the inode numbers
23420 + * reported by readdir in sync with the inode numbers reported
23421 + * by stat.
23422 + */
23423 +static int proc_fill_cache(struct file *filp, void *dirent, filldir_t filldir,
23424 +       char *name, int len, instantiate_t instantiate, int id, void *ptr)
23425 +{
23426 +       struct dentry *child, *dir = filp->f_dentry;
23427 +       struct inode *inode;
23428 +       struct qstr qname;
23429 +       ino_t ino = 0;
23430 +       unsigned type = DT_UNKNOWN;
23431 +
23432 +       qname.name = name;
23433 +       qname.len  = len;
23434 +       qname.hash = full_name_hash(name, len);
23435 +
23436 +       child = d_lookup(dir, &qname);
23437 +       if (!child) {
23438 +               struct dentry *new;
23439 +               new = d_alloc(dir, &qname);
23440 +               if (new) {
23441 +                       child = instantiate(dir->d_inode, new, id, ptr);
23442 +                       if (child)
23443 +                               dput(new);
23444 +                       else
23445 +                               child = new;
23446 +               }
23447 +       }
23448 +       if (!child || IS_ERR(child) || !child->d_inode)
23449 +               goto end_instantiate;
23450 +       inode = child->d_inode;
23451 +       if (inode) {
23452 +               ino = inode->i_ino;
23453 +               type = inode->i_mode >> 12;
23454 +       }
23455 +       dput(child);
23456 +end_instantiate:
23457 +       if (!ino)
23458 +               ino = find_inode_number(dir, &qname);
23459 +       if (!ino)
23460 +               ino = 1;
23461 +       return filldir(dirent, name, len, filp->f_pos, ino, type);
23462 +}
23463 +
23464 +
23465 +
23466 +/* get and revalidate vx_info/xid */
23467 +
23468 +static inline
23469 +struct vx_info *get_proc_vx_info(struct inode *inode)
23470 +{
23471 +       return lookup_vx_info(PROC_I(inode)->fd);
23472 +}
23473 +
23474 +static int proc_xid_revalidate(struct dentry *dentry, struct nameidata *nd)
23475 +{
23476 +       struct inode *inode = dentry->d_inode;
23477 +       xid_t xid = PROC_I(inode)->fd;
23478 +
23479 +       if (!xid || xid_is_hashed(xid))
23480 +               return 1;
23481 +       d_drop(dentry);
23482 +       return 0;
23483 +}
23484 +
23485 +
23486 +/* get and revalidate nx_info/nid */
23487 +
23488 +static int proc_nid_revalidate(struct dentry *dentry, struct nameidata *nd)
23489 +{
23490 +       struct inode *inode = dentry->d_inode;
23491 +       nid_t nid = PROC_I(inode)->fd;
23492 +
23493 +       if (!nid || nid_is_hashed(nid))
23494 +               return 1;
23495 +       d_drop(dentry);
23496 +       return 0;
23497 +}
23498 +
23499 +
23500 +
23501 +#define PROC_BLOCK_SIZE (PAGE_SIZE - 1024)
23502 +
23503 +static ssize_t proc_vs_info_read(struct file *file, char __user *buf,
23504 +                         size_t count, loff_t *ppos)
23505 +{
23506 +       struct inode *inode = file->f_dentry->d_inode;
23507 +       unsigned long page;
23508 +       ssize_t length = 0;
23509 +
23510 +       if (count > PROC_BLOCK_SIZE)
23511 +               count = PROC_BLOCK_SIZE;
23512 +
23513 +       /* fade that out as soon as stable */
23514 +       WARN_ON(PROC_I(inode)->fd);
23515 +
23516 +       if (!(page = __get_free_page(GFP_KERNEL)))
23517 +               return -ENOMEM;
23518 +
23519 +       BUG_ON(!PROC_I(inode)->op.proc_vs_read);
23520 +       length = PROC_I(inode)->op.proc_vs_read((char *)page);
23521 +
23522 +       if (length >= 0)
23523 +               length = simple_read_from_buffer(buf, count, ppos,
23524 +                       (char *)page, length);
23525 +
23526 +       free_page(page);
23527 +       return length;
23528 +}
23529 +
23530 +static ssize_t proc_vx_info_read(struct file *file, char __user *buf,
23531 +                         size_t count, loff_t *ppos)
23532 +{
23533 +       struct inode *inode = file->f_dentry->d_inode;
23534 +       struct vx_info *vxi = NULL;
23535 +       xid_t xid = PROC_I(inode)->fd;
23536 +       unsigned long page;
23537 +       ssize_t length = 0;
23538 +
23539 +       if (count > PROC_BLOCK_SIZE)
23540 +               count = PROC_BLOCK_SIZE;
23541 +
23542 +       /* fade that out as soon as stable */
23543 +       WARN_ON(!xid);
23544 +       vxi = lookup_vx_info(xid);
23545 +       if (!vxi)
23546 +               goto out;
23547 +
23548 +       length = -ENOMEM;
23549 +       if (!(page = __get_free_page(GFP_KERNEL)))
23550 +               goto out_put;
23551 +
23552 +       BUG_ON(!PROC_I(inode)->op.proc_vxi_read);
23553 +       length = PROC_I(inode)->op.proc_vxi_read(vxi, (char *)page);
23554 +
23555 +       if (length >= 0)
23556 +               length = simple_read_from_buffer(buf, count, ppos,
23557 +                       (char *)page, length);
23558 +
23559 +       free_page(page);
23560 +out_put:
23561 +       put_vx_info(vxi);
23562 +out:
23563 +       return length;
23564 +}
23565 +
23566 +static ssize_t proc_nx_info_read(struct file *file, char __user *buf,
23567 +                         size_t count, loff_t *ppos)
23568 +{
23569 +       struct inode *inode = file->f_dentry->d_inode;
23570 +       struct nx_info *nxi = NULL;
23571 +       nid_t nid = PROC_I(inode)->fd;
23572 +       unsigned long page;
23573 +       ssize_t length = 0;
23574 +
23575 +       if (count > PROC_BLOCK_SIZE)
23576 +               count = PROC_BLOCK_SIZE;
23577 +
23578 +       /* fade that out as soon as stable */
23579 +       WARN_ON(!nid);
23580 +       nxi = lookup_nx_info(nid);
23581 +       if (!nxi)
23582 +               goto out;
23583 +
23584 +       length = -ENOMEM;
23585 +       if (!(page = __get_free_page(GFP_KERNEL)))
23586 +               goto out_put;
23587 +
23588 +       BUG_ON(!PROC_I(inode)->op.proc_nxi_read);
23589 +       length = PROC_I(inode)->op.proc_nxi_read(nxi, (char *)page);
23590 +
23591 +       if (length >= 0)
23592 +               length = simple_read_from_buffer(buf, count, ppos,
23593 +                       (char *)page, length);
23594 +
23595 +       free_page(page);
23596 +out_put:
23597 +       put_nx_info(nxi);
23598 +out:
23599 +       return length;
23600 +}
23601 +
23602 +
23603 +
23604 +/* here comes the lower level */
23605 +
23606 +
23607 +#define NOD(NAME, MODE, IOP, FOP, OP) {        \
23608 +       .len  = sizeof(NAME) - 1,       \
23609 +       .name = (NAME),                 \
23610 +       .mode = MODE,                   \
23611 +       .iop  = IOP,                    \
23612 +       .fop  = FOP,                    \
23613 +       .op   = OP,                     \
23614 +}
23615 +
23616 +
23617 +#define DIR(NAME, MODE, OTYPE)                         \
23618 +       NOD(NAME, (S_IFDIR | (MODE)),                   \
23619 +               &proc_ ## OTYPE ## _inode_operations,   \
23620 +               &proc_ ## OTYPE ## _file_operations, { } )
23621 +
23622 +#define INF(NAME, MODE, OTYPE)                         \
23623 +       NOD(NAME, (S_IFREG | (MODE)), NULL,             \
23624 +               &proc_vs_info_file_operations,          \
23625 +               { .proc_vs_read = &proc_##OTYPE } )
23626 +
23627 +#define VINF(NAME, MODE, OTYPE)                                \
23628 +       NOD(NAME, (S_IFREG | (MODE)), NULL,             \
23629 +               &proc_vx_info_file_operations,          \
23630 +               { .proc_vxi_read = &proc_##OTYPE } )
23631 +
23632 +#define NINF(NAME, MODE, OTYPE)                                \
23633 +       NOD(NAME, (S_IFREG | (MODE)), NULL,             \
23634 +               &proc_nx_info_file_operations,          \
23635 +               { .proc_nxi_read = &proc_##OTYPE } )
23636 +
23637 +
23638 +static struct file_operations proc_vs_info_file_operations = {
23639 +       .read =         proc_vs_info_read,
23640 +};
23641 +
23642 +static struct file_operations proc_vx_info_file_operations = {
23643 +       .read =         proc_vx_info_read,
23644 +};
23645 +
23646 +static struct dentry_operations proc_xid_dentry_operations = {
23647 +       .d_revalidate = proc_xid_revalidate,
23648 +};
23649 +
23650 +static struct vs_entry vx_base_stuff[] = {
23651 +       VINF("info",    S_IRUGO, vxi_info),
23652 +       VINF("status",  S_IRUGO, vxi_status),
23653 +       VINF("limit",   S_IRUGO, vxi_limit),
23654 +       VINF("sched",   S_IRUGO, vxi_sched),
23655 +       VINF("nsproxy", S_IRUGO, vxi_nsproxy0),
23656 +       VINF("nsproxy1",S_IRUGO, vxi_nsproxy1),
23657 +       VINF("cvirt",   S_IRUGO, vxi_cvirt),
23658 +       VINF("cacct",   S_IRUGO, vxi_cacct),
23659 +       {}
23660 +};
23661 +
23662 +
23663 +
23664 +
23665 +static struct dentry *proc_xid_instantiate(struct inode *dir,
23666 +       struct dentry *dentry, int id, void *ptr)
23667 +{
23668 +       dentry->d_op = &proc_xid_dentry_operations;
23669 +       return vs_proc_instantiate(dir, dentry, id, ptr);
23670 +}
23671 +
23672 +static struct dentry *proc_xid_lookup(struct inode *dir,
23673 +       struct dentry *dentry, struct nameidata *nd)
23674 +{
23675 +       struct vs_entry *p = vx_base_stuff;
23676 +       struct dentry *error = ERR_PTR(-ENOENT);
23677 +
23678 +       for (; p->name; p++) {
23679 +               if (p->len != dentry->d_name.len)
23680 +                       continue;
23681 +               if (!memcmp(dentry->d_name.name, p->name, p->len))
23682 +                       break;
23683 +       }
23684 +       if (!p->name)
23685 +               goto out;
23686 +
23687 +       error = proc_xid_instantiate(dir, dentry, PROC_I(dir)->fd, p);
23688 +out:
23689 +       return error;
23690 +}
23691 +
23692 +static int proc_xid_readdir(struct file *filp,
23693 +       void *dirent, filldir_t filldir)
23694 +{
23695 +       struct dentry *dentry = filp->f_dentry;
23696 +       struct inode *inode = dentry->d_inode;
23697 +       struct vs_entry *p = vx_base_stuff;
23698 +       int size = sizeof(vx_base_stuff) / sizeof(struct vs_entry);
23699 +       int pos, index;
23700 +       u64 ino;
23701 +
23702 +       pos = filp->f_pos;
23703 +       switch (pos) {
23704 +       case 0:
23705 +               ino = inode->i_ino;
23706 +               if (filldir(dirent, ".", 1, pos, ino, DT_DIR) < 0)
23707 +                       goto out;
23708 +               pos++;
23709 +               /* fall through */
23710 +       case 1:
23711 +               ino = parent_ino(dentry);
23712 +               if (filldir(dirent, "..", 2, pos, ino, DT_DIR) < 0)
23713 +                       goto out;
23714 +               pos++;
23715 +               /* fall through */
23716 +       default:
23717 +               index = pos - 2;
23718 +               if (index >= size)
23719 +                       goto out;
23720 +               for (p += index; p->name; p++) {
23721 +                       if (proc_fill_cache(filp, dirent, filldir, p->name, p->len,
23722 +                               vs_proc_instantiate, PROC_I(inode)->fd, p))
23723 +                               goto out;
23724 +                       pos++;
23725 +               }
23726 +       }
23727 +out:
23728 +       filp->f_pos = pos;
23729 +       return 1;
23730 +}
23731 +
23732 +
23733 +
23734 +static struct file_operations proc_nx_info_file_operations = {
23735 +       .read =         proc_nx_info_read,
23736 +};
23737 +
23738 +static struct dentry_operations proc_nid_dentry_operations = {
23739 +       .d_revalidate = proc_nid_revalidate,
23740 +};
23741 +
23742 +static struct vs_entry nx_base_stuff[] = {
23743 +       NINF("info",    S_IRUGO, nxi_info),
23744 +       NINF("status",  S_IRUGO, nxi_status),
23745 +       {}
23746 +};
23747 +
23748 +
23749 +static struct dentry *proc_nid_instantiate(struct inode *dir,
23750 +       struct dentry *dentry, int id, void *ptr)
23751 +{
23752 +       dentry->d_op = &proc_nid_dentry_operations;
23753 +       return vs_proc_instantiate(dir, dentry, id, ptr);
23754 +}
23755 +
23756 +static struct dentry *proc_nid_lookup(struct inode *dir,
23757 +       struct dentry *dentry, struct nameidata *nd)
23758 +{
23759 +       struct vs_entry *p = nx_base_stuff;
23760 +       struct dentry *error = ERR_PTR(-ENOENT);
23761 +
23762 +       for (; p->name; p++) {
23763 +               if (p->len != dentry->d_name.len)
23764 +                       continue;
23765 +               if (!memcmp(dentry->d_name.name, p->name, p->len))
23766 +                       break;
23767 +       }
23768 +       if (!p->name)
23769 +               goto out;
23770 +
23771 +       error = proc_nid_instantiate(dir, dentry, PROC_I(dir)->fd, p);
23772 +out:
23773 +       return error;
23774 +}
23775 +
23776 +static int proc_nid_readdir(struct file *filp,
23777 +       void *dirent, filldir_t filldir)
23778 +{
23779 +       struct dentry *dentry = filp->f_dentry;
23780 +       struct inode *inode = dentry->d_inode;
23781 +       struct vs_entry *p = nx_base_stuff;
23782 +       int size = sizeof(nx_base_stuff) / sizeof(struct vs_entry);
23783 +       int pos, index;
23784 +       u64 ino;
23785 +
23786 +       pos = filp->f_pos;
23787 +       switch (pos) {
23788 +       case 0:
23789 +               ino = inode->i_ino;
23790 +               if (filldir(dirent, ".", 1, pos, ino, DT_DIR) < 0)
23791 +                       goto out;
23792 +               pos++;
23793 +               /* fall through */
23794 +       case 1:
23795 +               ino = parent_ino(dentry);
23796 +               if (filldir(dirent, "..", 2, pos, ino, DT_DIR) < 0)
23797 +                       goto out;
23798 +               pos++;
23799 +               /* fall through */
23800 +       default:
23801 +               index = pos - 2;
23802 +               if (index >= size)
23803 +                       goto out;
23804 +               for (p += index; p->name; p++) {
23805 +                       if (proc_fill_cache(filp, dirent, filldir, p->name, p->len,
23806 +                               vs_proc_instantiate, PROC_I(inode)->fd, p))
23807 +                               goto out;
23808 +                       pos++;
23809 +               }
23810 +       }
23811 +out:
23812 +       filp->f_pos = pos;
23813 +       return 1;
23814 +}
23815 +
23816 +
23817 +#define MAX_MULBY10    ((~0U - 9) / 10)
23818 +
23819 +static inline int atovid(const char *str, int len)
23820 +{
23821 +       int vid, c;
23822 +
23823 +       vid = 0;
23824 +       while (len-- > 0) {
23825 +               c = *str - '0';
23826 +               str++;
23827 +               if (c > 9)
23828 +                       return -1;
23829 +               if (vid >= MAX_MULBY10)
23830 +                       return -1;
23831 +               vid *= 10;
23832 +               vid += c;
23833 +               if (!vid)
23834 +                       return -1;
23835 +       }
23836 +       return vid;
23837 +}
23838 +
23839 +/* now the upper level (virtual) */
23840 +
23841 +
23842 +static struct file_operations proc_xid_file_operations = {
23843 +       .read =         generic_read_dir,
23844 +       .readdir =      proc_xid_readdir,
23845 +};
23846 +
23847 +static struct inode_operations proc_xid_inode_operations = {
23848 +       .lookup =       proc_xid_lookup,
23849 +};
23850 +
23851 +static struct vs_entry vx_virtual_stuff[] = {
23852 +       INF("info",     S_IRUGO, virtual_info),
23853 +       INF("status",   S_IRUGO, virtual_status),
23854 +       DIR(NULL,       S_IRUGO | S_IXUGO, xid),
23855 +};
23856 +
23857 +
23858 +static struct dentry *proc_virtual_lookup(struct inode *dir,
23859 +       struct dentry *dentry, struct nameidata *nd)
23860 +{
23861 +       struct vs_entry *p = vx_virtual_stuff;
23862 +       struct dentry *error = ERR_PTR(-ENOENT);
23863 +       int id = 0;
23864 +
23865 +       for (; p->name; p++) {
23866 +               if (p->len != dentry->d_name.len)
23867 +                       continue;
23868 +               if (!memcmp(dentry->d_name.name, p->name, p->len))
23869 +                       break;
23870 +       }
23871 +       if (p->name)
23872 +               goto instantiate;
23873 +
23874 +       id = atovid(dentry->d_name.name, dentry->d_name.len);
23875 +       if ((id < 0) || !xid_is_hashed(id))
23876 +               goto out;
23877 +
23878 +instantiate:
23879 +       error = proc_xid_instantiate(dir, dentry, id, p);
23880 +out:
23881 +       return error;
23882 +}
23883 +
23884 +static struct file_operations proc_nid_file_operations = {
23885 +       .read =         generic_read_dir,
23886 +       .readdir =      proc_nid_readdir,
23887 +};
23888 +
23889 +static struct inode_operations proc_nid_inode_operations = {
23890 +       .lookup =       proc_nid_lookup,
23891 +};
23892 +
23893 +static struct vs_entry nx_virtnet_stuff[] = {
23894 +       INF("info",     S_IRUGO, virtnet_info),
23895 +       INF("status",   S_IRUGO, virtnet_status),
23896 +       DIR(NULL,       S_IRUGO | S_IXUGO, nid),
23897 +};
23898 +
23899 +
23900 +static struct dentry *proc_virtnet_lookup(struct inode *dir,
23901 +       struct dentry *dentry, struct nameidata *nd)
23902 +{
23903 +       struct vs_entry *p = nx_virtnet_stuff;
23904 +       struct dentry *error = ERR_PTR(-ENOENT);
23905 +       int id = 0;
23906 +
23907 +       for (; p->name; p++) {
23908 +               if (p->len != dentry->d_name.len)
23909 +                       continue;
23910 +               if (!memcmp(dentry->d_name.name, p->name, p->len))
23911 +                       break;
23912 +       }
23913 +       if (p->name)
23914 +               goto instantiate;
23915 +
23916 +       id = atovid(dentry->d_name.name, dentry->d_name.len);
23917 +       if ((id < 0) || !nid_is_hashed(id))
23918 +               goto out;
23919 +
23920 +instantiate:
23921 +       error = proc_nid_instantiate(dir, dentry, id, p);
23922 +out:
23923 +       return error;
23924 +}
23925 +
23926 +
23927 +#define PROC_MAXVIDS 32
23928 +
23929 +int proc_virtual_readdir(struct file *filp,
23930 +       void *dirent, filldir_t filldir)
23931 +{
23932 +       struct dentry *dentry = filp->f_dentry;
23933 +       struct inode *inode = dentry->d_inode;
23934 +       struct vs_entry *p = vx_virtual_stuff;
23935 +       int size = sizeof(vx_virtual_stuff) / sizeof(struct vs_entry);
23936 +       int pos, index;
23937 +       unsigned int xid_array[PROC_MAXVIDS];
23938 +       char buf[PROC_NUMBUF];
23939 +       unsigned int nr_xids, i;
23940 +       u64 ino;
23941 +
23942 +       pos = filp->f_pos;
23943 +       switch (pos) {
23944 +       case 0:
23945 +               ino = inode->i_ino;
23946 +               if (filldir(dirent, ".", 1, pos, ino, DT_DIR) < 0)
23947 +                       goto out;
23948 +               pos++;
23949 +               /* fall through */
23950 +       case 1:
23951 +               ino = parent_ino(dentry);
23952 +               if (filldir(dirent, "..", 2, pos, ino, DT_DIR) < 0)
23953 +                       goto out;
23954 +               pos++;
23955 +               /* fall through */
23956 +       default:
23957 +               index = pos - 2;
23958 +               if (index >= size)
23959 +                       goto entries;
23960 +               for (p += index; p->name; p++) {
23961 +                       if (proc_fill_cache(filp, dirent, filldir, p->name, p->len,
23962 +                               vs_proc_instantiate, 0, p))
23963 +                               goto out;
23964 +                       pos++;
23965 +               }
23966 +       entries:
23967 +               index = pos - size;
23968 +               p = &vx_virtual_stuff[size - 1];
23969 +               nr_xids = get_xid_list(index, xid_array, PROC_MAXVIDS);
23970 +               for (i = 0; i < nr_xids; i++) {
23971 +                       int n, xid = xid_array[i];
23972 +                       unsigned int j = PROC_NUMBUF;
23973 +
23974 +                       n = xid;
23975 +                       do
23976 +                               buf[--j] = '0' + (n % 10);
23977 +                       while (n /= 10);
23978 +
23979 +                       if (proc_fill_cache(filp, dirent, filldir,
23980 +                               buf + j, PROC_NUMBUF - j,
23981 +                               vs_proc_instantiate, xid, p))
23982 +                               goto out;
23983 +                       pos++;
23984 +               }
23985 +       }
23986 +out:
23987 +       filp->f_pos = pos;
23988 +       return 0;
23989 +}
23990 +
23991 +static int proc_virtual_getattr(struct vfsmount *mnt,
23992 +       struct dentry *dentry, struct kstat *stat)
23993 +{
23994 +       struct inode *inode = dentry->d_inode;
23995 +
23996 +       generic_fillattr(inode, stat);
23997 +       stat->nlink = 2 + atomic_read(&vx_global_cactive);
23998 +       return 0;
23999 +}
24000 +
24001 +static struct file_operations proc_virtual_dir_operations = {
24002 +       .read =         generic_read_dir,
24003 +       .readdir =      proc_virtual_readdir,
24004 +};
24005 +
24006 +static struct inode_operations proc_virtual_dir_inode_operations = {
24007 +       .getattr =      proc_virtual_getattr,
24008 +       .lookup =       proc_virtual_lookup,
24009 +};
24010 +
24011 +
24012 +
24013 +
24014 +
24015 +int proc_virtnet_readdir(struct file *filp,
24016 +       void *dirent, filldir_t filldir)
24017 +{
24018 +       struct dentry *dentry = filp->f_dentry;
24019 +       struct inode *inode = dentry->d_inode;
24020 +       struct vs_entry *p = nx_virtnet_stuff;
24021 +       int size = sizeof(nx_virtnet_stuff) / sizeof(struct vs_entry);
24022 +       int pos, index;
24023 +       unsigned int nid_array[PROC_MAXVIDS];
24024 +       char buf[PROC_NUMBUF];
24025 +       unsigned int nr_nids, i;
24026 +       u64 ino;
24027 +
24028 +       pos = filp->f_pos;
24029 +       switch (pos) {
24030 +       case 0:
24031 +               ino = inode->i_ino;
24032 +               if (filldir(dirent, ".", 1, pos, ino, DT_DIR) < 0)
24033 +                       goto out;
24034 +               pos++;
24035 +               /* fall through */
24036 +       case 1:
24037 +               ino = parent_ino(dentry);
24038 +               if (filldir(dirent, "..", 2, pos, ino, DT_DIR) < 0)
24039 +                       goto out;
24040 +               pos++;
24041 +               /* fall through */
24042 +       default:
24043 +               index = pos - 2;
24044 +               if (index >= size)
24045 +                       goto entries;
24046 +               for (p += index; p->name; p++) {
24047 +                       if (proc_fill_cache(filp, dirent, filldir, p->name, p->len,
24048 +                               vs_proc_instantiate, 0, p))
24049 +                               goto out;
24050 +                       pos++;
24051 +               }
24052 +       entries:
24053 +               index = pos - size;
24054 +               p = &nx_virtnet_stuff[size - 1];
24055 +               nr_nids = get_nid_list(index, nid_array, PROC_MAXVIDS);
24056 +               for (i = 0; i < nr_nids; i++) {
24057 +                       int n, nid = nid_array[i];
24058 +                       unsigned int j = PROC_NUMBUF;
24059 +
24060 +                       n = nid;
24061 +                       do
24062 +                               buf[--j] = '0' + (n % 10);
24063 +                       while (n /= 10);
24064 +
24065 +                       if (proc_fill_cache(filp, dirent, filldir,
24066 +                               buf + j, PROC_NUMBUF - j,
24067 +                               vs_proc_instantiate, nid, p))
24068 +                               goto out;
24069 +                       pos++;
24070 +               }
24071 +       }
24072 +out:
24073 +       filp->f_pos = pos;
24074 +       return 0;
24075 +}
24076 +
24077 +static int proc_virtnet_getattr(struct vfsmount *mnt,
24078 +       struct dentry *dentry, struct kstat *stat)
24079 +{
24080 +       struct inode *inode = dentry->d_inode;
24081 +
24082 +       generic_fillattr(inode, stat);
24083 +       stat->nlink = 2 + atomic_read(&nx_global_cactive);
24084 +       return 0;
24085 +}
24086 +
24087 +static struct file_operations proc_virtnet_dir_operations = {
24088 +       .read =         generic_read_dir,
24089 +       .readdir =      proc_virtnet_readdir,
24090 +};
24091 +
24092 +static struct inode_operations proc_virtnet_dir_inode_operations = {
24093 +       .getattr =      proc_virtnet_getattr,
24094 +       .lookup =       proc_virtnet_lookup,
24095 +};
24096 +
24097 +
24098 +
24099 +void proc_vx_init(void)
24100 +{
24101 +       struct proc_dir_entry *ent;
24102 +
24103 +       ent = proc_mkdir("virtual", 0);
24104 +       if (ent) {
24105 +               ent->proc_fops = &proc_virtual_dir_operations;
24106 +               ent->proc_iops = &proc_virtual_dir_inode_operations;
24107 +       }
24108 +       proc_virtual = ent;
24109 +
24110 +       ent = proc_mkdir("virtnet", 0);
24111 +       if (ent) {
24112 +               ent->proc_fops = &proc_virtnet_dir_operations;
24113 +               ent->proc_iops = &proc_virtnet_dir_inode_operations;
24114 +       }
24115 +       proc_virtnet = ent;
24116 +}
24117 +
24118 +
24119 +
24120 +
24121 +/* per pid info */
24122 +
24123 +
24124 +int proc_pid_vx_info(struct task_struct *p, char *buffer)
24125 +{
24126 +       struct vx_info *vxi;
24127 +       char *orig = buffer;
24128 +
24129 +       buffer += sprintf(buffer, "XID:\t%d\n", vx_task_xid(p));
24130 +
24131 +       vxi = task_get_vx_info(p);
24132 +       if (!vxi)
24133 +               goto out;
24134 +
24135 +       buffer += sprintf(buffer, "BCaps:\t");
24136 +       buffer = print_cap_t(buffer, &vxi->vx_bcaps);
24137 +       buffer += sprintf(buffer, "\n");
24138 +       buffer += sprintf(buffer, "CCaps:\t%016llx\n",
24139 +               (unsigned long long)vxi->vx_ccaps);
24140 +       buffer += sprintf(buffer, "CFlags:\t%016llx\n",
24141 +               (unsigned long long)vxi->vx_flags);
24142 +       buffer += sprintf(buffer, "CIPid:\t%d\n", vxi->vx_initpid);
24143 +
24144 +       put_vx_info(vxi);
24145 +out:
24146 +       return buffer - orig;
24147 +}
24148 +
24149 +
24150 +int proc_pid_nx_info(struct task_struct *p, char *buffer)
24151 +{
24152 +       struct nx_info *nxi;
24153 +       struct nx_addr_v4 *v4a;
24154 +#ifdef CONFIG_IPV6
24155 +       struct nx_addr_v6 *v6a;
24156 +#endif
24157 +       char *orig = buffer;
24158 +       int i;
24159 +
24160 +       buffer += sprintf(buffer, "NID:\t%d\n", nx_task_nid(p));
24161 +
24162 +       nxi = task_get_nx_info(p);
24163 +       if (!nxi)
24164 +               goto out;
24165 +
24166 +       buffer += sprintf(buffer, "NCaps:\t%016llx\n",
24167 +               (unsigned long long)nxi->nx_ncaps);
24168 +       buffer += sprintf(buffer, "NFlags:\t%016llx\n",
24169 +               (unsigned long long)nxi->nx_flags);
24170 +
24171 +       buffer += sprintf(buffer,
24172 +               "V4Root[bcast]:\t" NIPQUAD_FMT "\n",
24173 +               NIPQUAD(nxi->v4_bcast.s_addr));
24174 +       buffer += sprintf (buffer,
24175 +               "V4Root[lback]:\t" NIPQUAD_FMT "\n",
24176 +               NIPQUAD(nxi->v4_lback.s_addr));
24177 +       if (!NX_IPV4(nxi))
24178 +               goto skip_v4;
24179 +       for (i = 0, v4a = &nxi->v4; v4a; i++, v4a = v4a->next)
24180 +               buffer += sprintf(buffer, "V4Root[%d]:\t" NXAV4_FMT "\n",
24181 +                       i, NXAV4(v4a));
24182 +skip_v4:
24183 +#ifdef CONFIG_IPV6
24184 +       if (!NX_IPV6(nxi))
24185 +               goto skip_v6;
24186 +       for (i = 0, v6a = &nxi->v6; v6a; i++, v6a = v6a->next)
24187 +               buffer += sprintf(buffer, "V6Root[%d]:\t" NXAV6_FMT "\n",
24188 +                       i, NXAV6(v6a));
24189 +skip_v6:
24190 +#endif
24191 +       put_nx_info(nxi);
24192 +out:
24193 +       return buffer - orig;
24194 +}
24195 +
24196 diff -NurpP --minimal linux-2.6.32.1/kernel/vserver/sched.c linux-2.6.32.1-vs2.3.0.36.27/kernel/vserver/sched.c
24197 --- linux-2.6.32.1/kernel/vserver/sched.c       1970-01-01 01:00:00.000000000 +0100
24198 +++ linux-2.6.32.1-vs2.3.0.36.27/kernel/vserver/sched.c 2009-12-03 20:04:56.000000000 +0100
24199 @@ -0,0 +1,414 @@
24200 +/*
24201 + *  linux/kernel/vserver/sched.c
24202 + *
24203 + *  Virtual Server: Scheduler Support
24204 + *
24205 + *  Copyright (C) 2004-2007  Herbert Pötzl
24206 + *
24207 + *  V0.01  adapted Sam Vilains version to 2.6.3
24208 + *  V0.02  removed legacy interface
24209 + *  V0.03  changed vcmds to vxi arg
24210 + *  V0.04  removed older and legacy interfaces
24211 + *
24212 + */
24213 +
24214 +#include <linux/vs_context.h>
24215 +#include <linux/vs_sched.h>
24216 +#include <linux/vserver/sched_cmd.h>
24217 +
24218 +#include <asm/uaccess.h>
24219 +
24220 +
24221 +#define vxd_check_range(val, min, max) do {            \
24222 +       vxlprintk((val < min) || (val > max),           \
24223 +               "check_range(%ld,%ld,%ld)",             \
24224 +               (long)val, (long)min, (long)max,        \
24225 +               __FILE__, __LINE__);                    \
24226 +       } while (0)
24227 +
24228 +
24229 +void vx_update_sched_param(struct _vx_sched *sched,
24230 +       struct _vx_sched_pc *sched_pc)
24231 +{
24232 +       unsigned int set_mask = sched->update_mask;
24233 +
24234 +       if (set_mask & VXSM_FILL_RATE)
24235 +               sched_pc->fill_rate[0] = sched->fill_rate[0];
24236 +       if (set_mask & VXSM_INTERVAL)
24237 +               sched_pc->interval[0] = sched->interval[0];
24238 +       if (set_mask & VXSM_FILL_RATE2)
24239 +               sched_pc->fill_rate[1] = sched->fill_rate[1];
24240 +       if (set_mask & VXSM_INTERVAL2)
24241 +               sched_pc->interval[1] = sched->interval[1];
24242 +       if (set_mask & VXSM_TOKENS)
24243 +               sched_pc->tokens = sched->tokens;
24244 +       if (set_mask & VXSM_TOKENS_MIN)
24245 +               sched_pc->tokens_min = sched->tokens_min;
24246 +       if (set_mask & VXSM_TOKENS_MAX)
24247 +               sched_pc->tokens_max = sched->tokens_max;
24248 +       if (set_mask & VXSM_PRIO_BIAS)
24249 +               sched_pc->prio_bias = sched->prio_bias;
24250 +
24251 +       if (set_mask & VXSM_IDLE_TIME)
24252 +               sched_pc->flags |= VXSF_IDLE_TIME;
24253 +       else
24254 +               sched_pc->flags &= ~VXSF_IDLE_TIME;
24255 +
24256 +       /* reset time */
24257 +       sched_pc->norm_time = jiffies;
24258 +}
24259 +
24260 +
24261 +/*
24262 + * recalculate the context's scheduling tokens
24263 + *
24264 + * ret > 0 : number of tokens available
24265 + * ret < 0 : on hold, check delta_min[]
24266 + *          -1 only jiffies
24267 + *          -2 also idle time
24268 + *
24269 + */
24270 +int vx_tokens_recalc(struct _vx_sched_pc *sched_pc,
24271 +       unsigned long *norm_time, unsigned long *idle_time, int delta_min[2])
24272 +{
24273 +       long delta;
24274 +       long tokens = 0;
24275 +       int flags = sched_pc->flags;
24276 +
24277 +       /* how much time did pass? */
24278 +       delta = *norm_time - sched_pc->norm_time;
24279 +       // printk("@ %ld, %ld, %ld\n", *norm_time, sched_pc->norm_time, jiffies);
24280 +       vxd_check_range(delta, 0, INT_MAX);
24281 +
24282 +       if (delta >= sched_pc->interval[0]) {
24283 +               long tokens, integral;
24284 +
24285 +               /* calc integral token part */
24286 +               tokens = delta / sched_pc->interval[0];
24287 +               integral = tokens * sched_pc->interval[0];
24288 +               tokens *= sched_pc->fill_rate[0];
24289 +#ifdef CONFIG_VSERVER_HARDCPU
24290 +               delta_min[0] = delta - integral;
24291 +               vxd_check_range(delta_min[0], 0, sched_pc->interval[0]);
24292 +#endif
24293 +               /* advance time */
24294 +               sched_pc->norm_time += delta;
24295 +
24296 +               /* add tokens */
24297 +               sched_pc->tokens += tokens;
24298 +               sched_pc->token_time += tokens;
24299 +       } else
24300 +               delta_min[0] = delta;
24301 +
24302 +#ifdef CONFIG_VSERVER_IDLETIME
24303 +       if (!(flags & VXSF_IDLE_TIME))
24304 +               goto skip_idle;
24305 +
24306 +       /* how much was the idle skip? */
24307 +       delta = *idle_time - sched_pc->idle_time;
24308 +       vxd_check_range(delta, 0, INT_MAX);
24309 +
24310 +       if (delta >= sched_pc->interval[1]) {
24311 +               long tokens, integral;
24312 +
24313 +               /* calc fair share token part */
24314 +               tokens = delta / sched_pc->interval[1];
24315 +               integral = tokens * sched_pc->interval[1];
24316 +               tokens *= sched_pc->fill_rate[1];
24317 +               delta_min[1] = delta - integral;
24318 +               vxd_check_range(delta_min[1], 0, sched_pc->interval[1]);
24319 +
24320 +               /* advance idle time */
24321 +               sched_pc->idle_time += integral;
24322 +
24323 +               /* add tokens */
24324 +               sched_pc->tokens += tokens;
24325 +               sched_pc->token_time += tokens;
24326 +       } else
24327 +               delta_min[1] = delta;
24328 +skip_idle:
24329 +#endif
24330 +
24331 +       /* clip at maximum */
24332 +       if (sched_pc->tokens > sched_pc->tokens_max)
24333 +               sched_pc->tokens = sched_pc->tokens_max;
24334 +       tokens = sched_pc->tokens;
24335 +
24336 +       if ((flags & VXSF_ONHOLD)) {
24337 +               /* can we unhold? */
24338 +               if (tokens >= sched_pc->tokens_min) {
24339 +                       flags &= ~VXSF_ONHOLD;
24340 +                       sched_pc->hold_ticks +=
24341 +                               *norm_time - sched_pc->onhold;
24342 +               } else
24343 +                       goto on_hold;
24344 +       } else {
24345 +               /* put on hold? */
24346 +               if (tokens <= 0) {
24347 +                       flags |= VXSF_ONHOLD;
24348 +                       sched_pc->onhold = *norm_time;
24349 +                       goto on_hold;
24350 +               }
24351 +       }
24352 +       sched_pc->flags = flags;
24353 +       return tokens;
24354 +
24355 +on_hold:
24356 +       tokens = sched_pc->tokens_min - tokens;
24357 +       sched_pc->flags = flags;
24358 +       // BUG_ON(tokens < 0); probably doesn't hold anymore
24359 +
24360 +#ifdef CONFIG_VSERVER_HARDCPU
24361 +       /* next interval? */
24362 +       if (!sched_pc->fill_rate[0])
24363 +               delta_min[0] = HZ;
24364 +       else if (tokens > sched_pc->fill_rate[0])
24365 +               delta_min[0] += sched_pc->interval[0] *
24366 +                       tokens / sched_pc->fill_rate[0];
24367 +       else
24368 +               delta_min[0] = sched_pc->interval[0] - delta_min[0];
24369 +       vxd_check_range(delta_min[0], 0, INT_MAX);
24370 +
24371 +#ifdef CONFIG_VSERVER_IDLETIME
24372 +       if (!(flags & VXSF_IDLE_TIME))
24373 +               return -1;
24374 +
24375 +       /* next interval? */
24376 +       if (!sched_pc->fill_rate[1])
24377 +               delta_min[1] = HZ;
24378 +       else if (tokens > sched_pc->fill_rate[1])
24379 +               delta_min[1] += sched_pc->interval[1] *
24380 +                       tokens / sched_pc->fill_rate[1];
24381 +       else
24382 +               delta_min[1] = sched_pc->interval[1] - delta_min[1];
24383 +       vxd_check_range(delta_min[1], 0, INT_MAX);
24384 +
24385 +       return -2;
24386 +#else
24387 +       return -1;
24388 +#endif /* CONFIG_VSERVER_IDLETIME */
24389 +#else
24390 +       return 0;
24391 +#endif /* CONFIG_VSERVER_HARDCPU */
24392 +}
24393 +
24394 +static inline unsigned long msec_to_ticks(unsigned long msec)
24395 +{
24396 +       return msecs_to_jiffies(msec);
24397 +}
24398 +
24399 +static inline unsigned long ticks_to_msec(unsigned long ticks)
24400 +{
24401 +       return jiffies_to_msecs(ticks);
24402 +}
24403 +
24404 +static inline unsigned long ticks_to_usec(unsigned long ticks)
24405 +{
24406 +       return jiffies_to_usecs(ticks);
24407 +}
24408 +
24409 +
24410 +static int do_set_sched(struct vx_info *vxi, struct vcmd_sched_v5 *data)
24411 +{
24412 +       unsigned int set_mask = data->mask;
24413 +       unsigned int update_mask;
24414 +       int i, cpu;
24415 +
24416 +       /* Sanity check data values */
24417 +       if (data->tokens_max <= 0)
24418 +               data->tokens_max = HZ;
24419 +       if (data->tokens_min < 0)
24420 +               data->tokens_min = HZ / 3;
24421 +       if (data->tokens_min >= data->tokens_max)
24422 +               data->tokens_min = data->tokens_max;
24423 +
24424 +       if (data->prio_bias > MAX_PRIO_BIAS)
24425 +               data->prio_bias = MAX_PRIO_BIAS;
24426 +       if (data->prio_bias < MIN_PRIO_BIAS)
24427 +               data->prio_bias = MIN_PRIO_BIAS;
24428 +
24429 +       spin_lock(&vxi->sched.tokens_lock);
24430 +
24431 +       /* sync up on delayed updates */
24432 +       for_each_cpu_mask(cpu, vxi->sched.update)
24433 +               vx_update_sched_param(&vxi->sched,
24434 +                       &vx_per_cpu(vxi, sched_pc, cpu));
24435 +
24436 +       if (set_mask & VXSM_FILL_RATE)
24437 +               vxi->sched.fill_rate[0] = data->fill_rate[0];
24438 +       if (set_mask & VXSM_FILL_RATE2)
24439 +               vxi->sched.fill_rate[1] = data->fill_rate[1];
24440 +       if (set_mask & VXSM_INTERVAL)
24441 +               vxi->sched.interval[0] = (set_mask & VXSM_MSEC) ?
24442 +                       msec_to_ticks(data->interval[0]) : data->interval[0];
24443 +       if (set_mask & VXSM_INTERVAL2)
24444 +               vxi->sched.interval[1] = (set_mask & VXSM_MSEC) ?
24445 +                       msec_to_ticks(data->interval[1]) : data->interval[1];
24446 +       if (set_mask & VXSM_TOKENS)
24447 +               vxi->sched.tokens = data->tokens;
24448 +       if (set_mask & VXSM_TOKENS_MIN)
24449 +               vxi->sched.tokens_min = data->tokens_min;
24450 +       if (set_mask & VXSM_TOKENS_MAX)
24451 +               vxi->sched.tokens_max = data->tokens_max;
24452 +       if (set_mask & VXSM_PRIO_BIAS)
24453 +               vxi->sched.prio_bias = data->prio_bias;
24454 +
24455 +       /* Sanity check rate/interval */
24456 +       for (i = 0; i < 2; i++) {
24457 +               if (data->fill_rate[i] < 0)
24458 +                       data->fill_rate[i] = 0;
24459 +               if (data->interval[i] <= 0)
24460 +                       data->interval[i] = HZ;
24461 +       }
24462 +
24463 +       update_mask = vxi->sched.update_mask & VXSM_SET_MASK;
24464 +       update_mask |= (set_mask & (VXSM_SET_MASK | VXSM_IDLE_TIME));
24465 +       vxi->sched.update_mask = update_mask;
24466 +
24467 +#ifdef CONFIG_SMP
24468 +       rmb();
24469 +       if (set_mask & VXSM_CPU_ID) {
24470 +               vxi->sched.update = cpumask_of_cpu(data->cpu_id);
24471 +               cpus_and(vxi->sched.update, cpu_online_map,
24472 +                       vxi->sched.update);
24473 +       } else
24474 +               vxi->sched.update = cpu_online_map;
24475 +
24476 +       /* forced reload? */
24477 +       if (set_mask & VXSM_FORCE) {
24478 +               for_each_cpu_mask(cpu, vxi->sched.update)
24479 +                       vx_update_sched_param(&vxi->sched,
24480 +                               &vx_per_cpu(vxi, sched_pc, cpu));
24481 +               vxi->sched.update = CPU_MASK_NONE;
24482 +       }
24483 +#else
24484 +       /* on UP we update immediately */
24485 +       vx_update_sched_param(&vxi->sched,
24486 +               &vx_per_cpu(vxi, sched_pc, 0));
24487 +#endif
24488 +
24489 +       spin_unlock(&vxi->sched.tokens_lock);
24490 +       return 0;
24491 +}
24492 +
24493 +
24494 +#define COPY_IDS(C) C(cpu_id); C(bucket_id)
24495 +#define COPY_PRI(C) C(prio_bias)
24496 +#define COPY_TOK(C) C(tokens); C(tokens_min); C(tokens_max)
24497 +#define COPY_FRI(C) C(fill_rate[0]); C(interval[0]);   \
24498 +                   C(fill_rate[1]); C(interval[1]);
24499 +
24500 +#define COPY_VALUE(name) vc_data.name = data->name
24501 +
24502 +static int do_set_sched_v4(struct vx_info *vxi, struct vcmd_set_sched_v4 *data)
24503 +{
24504 +       struct vcmd_sched_v5 vc_data;
24505 +
24506 +       vc_data.mask = data->set_mask;
24507 +       COPY_IDS(COPY_VALUE);
24508 +       COPY_PRI(COPY_VALUE);
24509 +       COPY_TOK(COPY_VALUE);
24510 +       vc_data.fill_rate[0] = vc_data.fill_rate[1] = data->fill_rate;
24511 +       vc_data.interval[0] = vc_data.interval[1] = data->interval;
24512 +       return do_set_sched(vxi, &vc_data);
24513 +}
24514 +
24515 +int vc_set_sched_v4(struct vx_info *vxi, void __user *data)
24516 +{
24517 +       struct vcmd_set_sched_v4 vc_data;
24518 +
24519 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
24520 +               return -EFAULT;
24521 +
24522 +       return do_set_sched_v4(vxi, &vc_data);
24523 +}
24524 +
24525 +       /* latest interface is v5 */
24526 +
24527 +int vc_set_sched(struct vx_info *vxi, void __user *data)
24528 +{
24529 +       struct vcmd_sched_v5 vc_data;
24530 +
24531 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
24532 +               return -EFAULT;
24533 +
24534 +       return do_set_sched(vxi, &vc_data);
24535 +}
24536 +
24537 +
24538 +#define COPY_PRI(C) C(prio_bias)
24539 +#define COPY_TOK(C) C(tokens); C(tokens_min); C(tokens_max)
24540 +#define COPY_FRI(C) C(fill_rate[0]); C(interval[0]);    \
24541 +                   C(fill_rate[1]); C(interval[1]);
24542 +
24543 +#define COPY_VALUE(name) vc_data.name = data->name
24544 +
24545 +
24546 +int vc_get_sched(struct vx_info *vxi, void __user *data)
24547 +{
24548 +       struct vcmd_sched_v5 vc_data;
24549 +
24550 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
24551 +               return -EFAULT;
24552 +
24553 +       if (vc_data.mask & VXSM_CPU_ID) {
24554 +               int cpu = vc_data.cpu_id;
24555 +               struct _vx_sched_pc *data;
24556 +
24557 +               if (!cpu_possible(cpu))
24558 +                       return -EINVAL;
24559 +
24560 +               data = &vx_per_cpu(vxi, sched_pc, cpu);
24561 +               COPY_TOK(COPY_VALUE);
24562 +               COPY_PRI(COPY_VALUE);
24563 +               COPY_FRI(COPY_VALUE);
24564 +
24565 +               if (data->flags & VXSF_IDLE_TIME)
24566 +                       vc_data.mask |= VXSM_IDLE_TIME;
24567 +       } else {
24568 +               struct _vx_sched *data = &vxi->sched;
24569 +
24570 +               COPY_TOK(COPY_VALUE);
24571 +               COPY_PRI(COPY_VALUE);
24572 +               COPY_FRI(COPY_VALUE);
24573 +       }
24574 +
24575 +       if (vc_data.mask & VXSM_MSEC) {
24576 +               vc_data.interval[0] = ticks_to_msec(vc_data.interval[0]);
24577 +               vc_data.interval[1] = ticks_to_msec(vc_data.interval[1]);
24578 +       }
24579 +
24580 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
24581 +               return -EFAULT;
24582 +       return 0;
24583 +}
24584 +
24585 +
24586 +int vc_sched_info(struct vx_info *vxi, void __user *data)
24587 +{
24588 +       struct vcmd_sched_info vc_data;
24589 +       int cpu;
24590 +
24591 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
24592 +               return -EFAULT;
24593 +
24594 +       cpu = vc_data.cpu_id;
24595 +       if (!cpu_possible(cpu))
24596 +               return -EINVAL;
24597 +
24598 +       if (vxi) {
24599 +               struct _vx_sched_pc *sched_pc =
24600 +                       &vx_per_cpu(vxi, sched_pc, cpu);
24601 +
24602 +               vc_data.user_msec = ticks_to_msec(sched_pc->user_ticks);
24603 +               vc_data.sys_msec = ticks_to_msec(sched_pc->sys_ticks);
24604 +               vc_data.hold_msec = ticks_to_msec(sched_pc->hold_ticks);
24605 +               vc_data.vavavoom = sched_pc->vavavoom;
24606 +       }
24607 +       vc_data.token_usec = ticks_to_usec(1);
24608 +
24609 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
24610 +               return -EFAULT;
24611 +       return 0;
24612 +}
24613 +
24614 diff -NurpP --minimal linux-2.6.32.1/kernel/vserver/sched_init.h linux-2.6.32.1-vs2.3.0.36.27/kernel/vserver/sched_init.h
24615 --- linux-2.6.32.1/kernel/vserver/sched_init.h  1970-01-01 01:00:00.000000000 +0100
24616 +++ linux-2.6.32.1-vs2.3.0.36.27/kernel/vserver/sched_init.h    2009-12-03 20:04:56.000000000 +0100
24617 @@ -0,0 +1,50 @@
24618 +
24619 +static inline void vx_info_init_sched(struct _vx_sched *sched)
24620 +{
24621 +       static struct lock_class_key tokens_lock_key;
24622 +
24623 +       /* scheduling; hard code starting values as constants */
24624 +       sched->fill_rate[0]     = 1;
24625 +       sched->interval[0]      = 4;
24626 +       sched->fill_rate[1]     = 1;
24627 +       sched->interval[1]      = 8;
24628 +       sched->tokens           = HZ >> 2;
24629 +       sched->tokens_min       = HZ >> 4;
24630 +       sched->tokens_max       = HZ >> 1;
24631 +       sched->tokens_lock      = SPIN_LOCK_UNLOCKED;
24632 +       sched->prio_bias        = 0;
24633 +
24634 +       lockdep_set_class(&sched->tokens_lock, &tokens_lock_key);
24635 +}
24636 +
24637 +static inline
24638 +void vx_info_init_sched_pc(struct _vx_sched_pc *sched_pc, int cpu)
24639 +{
24640 +       sched_pc->fill_rate[0]  = 1;
24641 +       sched_pc->interval[0]   = 4;
24642 +       sched_pc->fill_rate[1]  = 1;
24643 +       sched_pc->interval[1]   = 8;
24644 +       sched_pc->tokens        = HZ >> 2;
24645 +       sched_pc->tokens_min    = HZ >> 4;
24646 +       sched_pc->tokens_max    = HZ >> 1;
24647 +       sched_pc->prio_bias     = 0;
24648 +       sched_pc->vavavoom      = 0;
24649 +       sched_pc->token_time    = 0;
24650 +       sched_pc->idle_time     = 0;
24651 +       sched_pc->norm_time     = jiffies;
24652 +
24653 +       sched_pc->user_ticks = 0;
24654 +       sched_pc->sys_ticks = 0;
24655 +       sched_pc->hold_ticks = 0;
24656 +}
24657 +
24658 +static inline void vx_info_exit_sched(struct _vx_sched *sched)
24659 +{
24660 +       return;
24661 +}
24662 +
24663 +static inline
24664 +void vx_info_exit_sched_pc(struct _vx_sched_pc *sched_pc, int cpu)
24665 +{
24666 +       return;
24667 +}
24668 diff -NurpP --minimal linux-2.6.32.1/kernel/vserver/sched_proc.h linux-2.6.32.1-vs2.3.0.36.27/kernel/vserver/sched_proc.h
24669 --- linux-2.6.32.1/kernel/vserver/sched_proc.h  1970-01-01 01:00:00.000000000 +0100
24670 +++ linux-2.6.32.1-vs2.3.0.36.27/kernel/vserver/sched_proc.h    2009-12-03 20:04:56.000000000 +0100
24671 @@ -0,0 +1,57 @@
24672 +#ifndef _VX_SCHED_PROC_H
24673 +#define _VX_SCHED_PROC_H
24674 +
24675 +
24676 +static inline
24677 +int vx_info_proc_sched(struct _vx_sched *sched, char *buffer)
24678 +{
24679 +       int length = 0;
24680 +
24681 +       length += sprintf(buffer,
24682 +               "FillRate:\t%8d,%d\n"
24683 +               "Interval:\t%8d,%d\n"
24684 +               "TokensMin:\t%8d\n"
24685 +               "TokensMax:\t%8d\n"
24686 +               "PrioBias:\t%8d\n",
24687 +               sched->fill_rate[0],
24688 +               sched->fill_rate[1],
24689 +               sched->interval[0],
24690 +               sched->interval[1],
24691 +               sched->tokens_min,
24692 +               sched->tokens_max,
24693 +               sched->prio_bias);
24694 +       return length;
24695 +}
24696 +
24697 +static inline
24698 +int vx_info_proc_sched_pc(struct _vx_sched_pc *sched_pc,
24699 +       char *buffer, int cpu)
24700 +{
24701 +       int length = 0;
24702 +
24703 +       length += sprintf(buffer + length,
24704 +               "cpu %d: %lld %lld %lld %ld %ld", cpu,
24705 +               (unsigned long long)sched_pc->user_ticks,
24706 +               (unsigned long long)sched_pc->sys_ticks,
24707 +               (unsigned long long)sched_pc->hold_ticks,
24708 +               sched_pc->token_time,
24709 +               sched_pc->idle_time);
24710 +       length += sprintf(buffer + length,
24711 +               " %c%c %d %d %d %d/%d %d/%d",
24712 +               (sched_pc->flags & VXSF_ONHOLD) ? 'H' : 'R',
24713 +               (sched_pc->flags & VXSF_IDLE_TIME) ? 'I' : '-',
24714 +               sched_pc->tokens,
24715 +               sched_pc->tokens_min,
24716 +               sched_pc->tokens_max,
24717 +               sched_pc->fill_rate[0],
24718 +               sched_pc->interval[0],
24719 +               sched_pc->fill_rate[1],
24720 +               sched_pc->interval[1]);
24721 +       length += sprintf(buffer + length,
24722 +               " %d %d\n",
24723 +               sched_pc->prio_bias,
24724 +               sched_pc->vavavoom);
24725 +       return length;
24726 +}
24727 +
24728 +#endif /* _VX_SCHED_PROC_H */
24729 diff -NurpP --minimal linux-2.6.32.1/kernel/vserver/signal.c linux-2.6.32.1-vs2.3.0.36.27/kernel/vserver/signal.c
24730 --- linux-2.6.32.1/kernel/vserver/signal.c      1970-01-01 01:00:00.000000000 +0100
24731 +++ linux-2.6.32.1-vs2.3.0.36.27/kernel/vserver/signal.c        2009-12-03 20:04:56.000000000 +0100
24732 @@ -0,0 +1,132 @@
24733 +/*
24734 + *  linux/kernel/vserver/signal.c
24735 + *
24736 + *  Virtual Server: Signal Support
24737 + *
24738 + *  Copyright (C) 2003-2007  Herbert Pötzl
24739 + *
24740 + *  V0.01  broken out from vcontext V0.05
24741 + *  V0.02  changed vcmds to vxi arg
24742 + *  V0.03  adjusted siginfo for kill
24743 + *
24744 + */
24745 +
24746 +#include <asm/uaccess.h>
24747 +
24748 +#include <linux/vs_context.h>
24749 +#include <linux/vs_pid.h>
24750 +#include <linux/vserver/signal_cmd.h>
24751 +
24752 +
24753 +int vx_info_kill(struct vx_info *vxi, int pid, int sig)
24754 +{
24755 +       int retval, count = 0;
24756 +       struct task_struct *p;
24757 +       struct siginfo *sip = SEND_SIG_PRIV;
24758 +
24759 +       retval = -ESRCH;
24760 +       vxdprintk(VXD_CBIT(misc, 4),
24761 +               "vx_info_kill(%p[#%d],%d,%d)*",
24762 +               vxi, vxi->vx_id, pid, sig);
24763 +       read_lock(&tasklist_lock);
24764 +       switch (pid) {
24765 +       case  0:
24766 +       case -1:
24767 +               for_each_process(p) {
24768 +                       int err = 0;
24769 +
24770 +                       if (vx_task_xid(p) != vxi->vx_id || p->pid <= 1 ||
24771 +                               (pid && vxi->vx_initpid == p->pid))
24772 +                               continue;
24773 +
24774 +                       err = group_send_sig_info(sig, sip, p);
24775 +                       ++count;
24776 +                       if (err != -EPERM)
24777 +                               retval = err;
24778 +               }
24779 +               break;
24780 +
24781 +       case 1:
24782 +               if (vxi->vx_initpid) {
24783 +                       pid = vxi->vx_initpid;
24784 +                       /* for now, only SIGINT to private init ... */
24785 +                       if (!vx_info_flags(vxi, VXF_STATE_ADMIN, 0) &&
24786 +                               /* ... as long as there are tasks left */
24787 +                               (atomic_read(&vxi->vx_tasks) > 1))
24788 +                               sig = SIGINT;
24789 +               }
24790 +               /* fallthrough */
24791 +       default:
24792 +               p = find_task_by_real_pid(pid);
24793 +               if (p) {
24794 +                       if (vx_task_xid(p) == vxi->vx_id)
24795 +                               retval = group_send_sig_info(sig, sip, p);
24796 +               }
24797 +               break;
24798 +       }
24799 +       read_unlock(&tasklist_lock);
24800 +       vxdprintk(VXD_CBIT(misc, 4),
24801 +               "vx_info_kill(%p[#%d],%d,%d,%ld) = %d",
24802 +               vxi, vxi->vx_id, pid, sig, (long)sip, retval);
24803 +       return retval;
24804 +}
24805 +
24806 +int vc_ctx_kill(struct vx_info *vxi, void __user *data)
24807 +{
24808 +       struct vcmd_ctx_kill_v0 vc_data;
24809 +
24810 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
24811 +               return -EFAULT;
24812 +
24813 +       /* special check to allow guest shutdown */
24814 +       if (!vx_info_flags(vxi, VXF_STATE_ADMIN, 0) &&
24815 +               /* forbid killall pid=0 when init is present */
24816 +               (((vc_data.pid < 1) && vxi->vx_initpid) ||
24817 +               (vc_data.pid > 1)))
24818 +               return -EACCES;
24819 +
24820 +       return vx_info_kill(vxi, vc_data.pid, vc_data.sig);
24821 +}
24822 +
24823 +
24824 +static int __wait_exit(struct vx_info *vxi)
24825 +{
24826 +       DECLARE_WAITQUEUE(wait, current);
24827 +       int ret = 0;
24828 +
24829 +       add_wait_queue(&vxi->vx_wait, &wait);
24830 +       set_current_state(TASK_INTERRUPTIBLE);
24831 +
24832 +wait:
24833 +       if (vx_info_state(vxi,
24834 +               VXS_SHUTDOWN | VXS_HASHED | VXS_HELPER) == VXS_SHUTDOWN)
24835 +               goto out;
24836 +       if (signal_pending(current)) {
24837 +               ret = -ERESTARTSYS;
24838 +               goto out;
24839 +       }
24840 +       schedule();
24841 +       goto wait;
24842 +
24843 +out:
24844 +       set_current_state(TASK_RUNNING);
24845 +       remove_wait_queue(&vxi->vx_wait, &wait);
24846 +       return ret;
24847 +}
24848 +
24849 +
24850 +
24851 +int vc_wait_exit(struct vx_info *vxi, void __user *data)
24852 +{
24853 +       struct vcmd_wait_exit_v0 vc_data;
24854 +       int ret;
24855 +
24856 +       ret = __wait_exit(vxi);
24857 +       vc_data.reboot_cmd = vxi->reboot_cmd;
24858 +       vc_data.exit_code = vxi->exit_code;
24859 +
24860 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
24861 +               ret = -EFAULT;
24862 +       return ret;
24863 +}
24864 +
24865 diff -NurpP --minimal linux-2.6.32.1/kernel/vserver/space.c linux-2.6.32.1-vs2.3.0.36.27/kernel/vserver/space.c
24866 --- linux-2.6.32.1/kernel/vserver/space.c       1970-01-01 01:00:00.000000000 +0100
24867 +++ linux-2.6.32.1-vs2.3.0.36.27/kernel/vserver/space.c 2009-12-03 20:04:56.000000000 +0100
24868 @@ -0,0 +1,375 @@
24869 +/*
24870 + *  linux/kernel/vserver/space.c
24871 + *
24872 + *  Virtual Server: Context Space Support
24873 + *
24874 + *  Copyright (C) 2003-2007  Herbert Pötzl
24875 + *
24876 + *  V0.01  broken out from context.c 0.07
24877 + *  V0.02  added task locking for namespace
24878 + *  V0.03  broken out vx_enter_namespace
24879 + *  V0.04  added *space support and commands
24880 + *
24881 + */
24882 +
24883 +#include <linux/utsname.h>
24884 +#include <linux/nsproxy.h>
24885 +#include <linux/err.h>
24886 +#include <linux/fs_struct.h>
24887 +#include <asm/uaccess.h>
24888 +
24889 +#include <linux/vs_context.h>
24890 +#include <linux/vserver/space.h>
24891 +#include <linux/vserver/space_cmd.h>
24892 +
24893 +atomic_t vs_global_nsproxy     = ATOMIC_INIT(0);
24894 +atomic_t vs_global_fs          = ATOMIC_INIT(0);
24895 +atomic_t vs_global_mnt_ns      = ATOMIC_INIT(0);
24896 +atomic_t vs_global_uts_ns      = ATOMIC_INIT(0);
24897 +atomic_t vs_global_user_ns     = ATOMIC_INIT(0);
24898 +atomic_t vs_global_pid_ns      = ATOMIC_INIT(0);
24899 +
24900 +
24901 +/* namespace functions */
24902 +
24903 +#include <linux/mnt_namespace.h>
24904 +#include <linux/user_namespace.h>
24905 +#include <linux/pid_namespace.h>
24906 +#include <linux/ipc_namespace.h>
24907 +#include <net/net_namespace.h>
24908 +
24909 +
24910 +static const struct vcmd_space_mask_v1 space_mask_v0 = {
24911 +       .mask = CLONE_FS |
24912 +               CLONE_NEWNS |
24913 +               CLONE_NEWUTS |
24914 +               CLONE_NEWIPC |
24915 +               CLONE_NEWUSER |
24916 +               0
24917 +};
24918 +
24919 +static const struct vcmd_space_mask_v1 space_mask = {
24920 +       .mask = CLONE_FS |
24921 +               CLONE_NEWNS |
24922 +               CLONE_NEWUTS |
24923 +               CLONE_NEWIPC |
24924 +               CLONE_NEWUSER |
24925 +#ifdef CONFIG_PID_NS
24926 +               CLONE_NEWPID |
24927 +#endif
24928 +#ifdef CONFIG_NET_NS
24929 +               CLONE_NEWNET |
24930 +#endif
24931 +               0
24932 +};
24933 +
24934 +static const struct vcmd_space_mask_v1 default_space_mask = {
24935 +       .mask = CLONE_FS |
24936 +               CLONE_NEWNS |
24937 +               CLONE_NEWUTS |
24938 +               CLONE_NEWIPC |
24939 +               CLONE_NEWUSER |
24940 +#ifdef CONFIG_PID_NS
24941 +//             CLONE_NEWPID |
24942 +#endif
24943 +               0
24944 +};
24945 +
24946 +/*
24947 + *     build a new nsproxy mix
24948 + *      assumes that both proxies are 'const'
24949 + *     does not touch nsproxy refcounts
24950 + *     will hold a reference on the result.
24951 + */
24952 +
24953 +struct nsproxy *vs_mix_nsproxy(struct nsproxy *old_nsproxy,
24954 +       struct nsproxy *new_nsproxy, unsigned long mask)
24955 +{
24956 +       struct mnt_namespace *old_ns;
24957 +       struct uts_namespace *old_uts;
24958 +       struct ipc_namespace *old_ipc;
24959 +#ifdef CONFIG_PID_NS
24960 +       struct pid_namespace *old_pid;
24961 +#endif
24962 +#ifdef CONFIG_NET_NS
24963 +       struct net *old_net;
24964 +#endif
24965 +       struct nsproxy *nsproxy;
24966 +
24967 +       nsproxy = copy_nsproxy(old_nsproxy);
24968 +       if (!nsproxy)
24969 +               goto out;
24970 +
24971 +       if (mask & CLONE_NEWNS) {
24972 +               old_ns = nsproxy->mnt_ns;
24973 +               nsproxy->mnt_ns = new_nsproxy->mnt_ns;
24974 +               if (nsproxy->mnt_ns)
24975 +                       get_mnt_ns(nsproxy->mnt_ns);
24976 +       } else
24977 +               old_ns = NULL;
24978 +
24979 +       if (mask & CLONE_NEWUTS) {
24980 +               old_uts = nsproxy->uts_ns;
24981 +               nsproxy->uts_ns = new_nsproxy->uts_ns;
24982 +               if (nsproxy->uts_ns)
24983 +                       get_uts_ns(nsproxy->uts_ns);
24984 +       } else
24985 +               old_uts = NULL;
24986 +
24987 +       if (mask & CLONE_NEWIPC) {
24988 +               old_ipc = nsproxy->ipc_ns;
24989 +               nsproxy->ipc_ns = new_nsproxy->ipc_ns;
24990 +               if (nsproxy->ipc_ns)
24991 +                       get_ipc_ns(nsproxy->ipc_ns);
24992 +       } else
24993 +               old_ipc = NULL;
24994 +
24995 +#ifdef CONFIG_PID_NS
24996 +       if (mask & CLONE_NEWPID) {
24997 +               old_pid = nsproxy->pid_ns;
24998 +               nsproxy->pid_ns = new_nsproxy->pid_ns;
24999 +               if (nsproxy->pid_ns)
25000 +                       get_pid_ns(nsproxy->pid_ns);
25001 +       } else
25002 +               old_pid = NULL;
25003 +#endif
25004 +#ifdef CONFIG_NET_NS
25005 +       if (mask & CLONE_NEWNET) {
25006 +               old_net = nsproxy->net_ns;
25007 +               nsproxy->net_ns = new_nsproxy->net_ns;
25008 +               if (nsproxy->net_ns)
25009 +                       get_net(nsproxy->net_ns);
25010 +       } else
25011 +               old_net = NULL;
25012 +#endif
25013 +       if (old_ns)
25014 +               put_mnt_ns(old_ns);
25015 +       if (old_uts)
25016 +               put_uts_ns(old_uts);
25017 +       if (old_ipc)
25018 +               put_ipc_ns(old_ipc);
25019 +#ifdef CONFIG_PID_NS
25020 +       if (old_pid)
25021 +               put_pid_ns(old_pid);
25022 +#endif
25023 +#ifdef CONFIG_NET_NS
25024 +       if (old_net)
25025 +               put_net(old_net);
25026 +#endif
25027 +out:
25028 +       return nsproxy;
25029 +}
25030 +
25031 +
25032 +/*
25033 + *     merge two nsproxy structs into a new one.
25034 + *     will hold a reference on the result.
25035 + */
25036 +
25037 +static inline
25038 +struct nsproxy *__vs_merge_nsproxy(struct nsproxy *old,
25039 +       struct nsproxy *proxy, unsigned long mask)
25040 +{
25041 +       struct nsproxy null_proxy = { .mnt_ns = NULL };
25042 +
25043 +       if (!proxy)
25044 +               return NULL;
25045 +
25046 +       if (mask) {
25047 +               /* vs_mix_nsproxy returns with reference */
25048 +               return vs_mix_nsproxy(old ? old : &null_proxy,
25049 +                       proxy, mask);
25050 +       }
25051 +       get_nsproxy(proxy);
25052 +       return proxy;
25053 +}
25054 +
25055 +
25056 +int vx_enter_space(struct vx_info *vxi, unsigned long mask, unsigned index)
25057 +{
25058 +       struct nsproxy *proxy, *proxy_cur, *proxy_new;
25059 +       struct fs_struct *fs_cur, *fs = NULL;
25060 +       int ret, kill = 0;
25061 +
25062 +       vxdprintk(VXD_CBIT(space, 8), "vx_enter_space(%p[#%u],0x%08lx,%d)",
25063 +               vxi, vxi->vx_id, mask, index);
25064 +
25065 +       if (vx_info_flags(vxi, VXF_INFO_PRIVATE, 0))
25066 +               return -EACCES;
25067 +
25068 +       if (!mask)
25069 +               mask = vxi->vx_nsmask[index];
25070 +
25071 +       if ((mask & vxi->vx_nsmask[index]) != mask)
25072 +               return -EINVAL;
25073 +
25074 +       if (mask & CLONE_FS) {
25075 +               fs = copy_fs_struct(vxi->vx_fs[index]);
25076 +               if (!fs)
25077 +                       return -ENOMEM;
25078 +       }
25079 +       proxy = vxi->vx_nsproxy[index];
25080 +
25081 +       vxdprintk(VXD_CBIT(space, 9),
25082 +               "vx_enter_space(%p[#%u],0x%08lx,%d) -> (%p,%p)",
25083 +               vxi, vxi->vx_id, mask, index, proxy, fs);
25084 +
25085 +       task_lock(current);
25086 +       fs_cur = current->fs;
25087 +
25088 +       if (mask & CLONE_FS) {
25089 +               write_lock(&fs_cur->lock);
25090 +               current->fs = fs;
25091 +               kill = !--fs_cur->users;
25092 +               write_unlock(&fs_cur->lock);
25093 +       }
25094 +
25095 +       proxy_cur = current->nsproxy;
25096 +       get_nsproxy(proxy_cur);
25097 +       task_unlock(current);
25098 +
25099 +       if (kill)
25100 +               free_fs_struct(fs_cur);
25101 +
25102 +       proxy_new = __vs_merge_nsproxy(proxy_cur, proxy, mask);
25103 +       if (IS_ERR(proxy_new)) {
25104 +               ret = PTR_ERR(proxy_new);
25105 +               goto out_put;
25106 +       }
25107 +
25108 +       proxy_new = xchg(&current->nsproxy, proxy_new);
25109 +       ret = 0;
25110 +
25111 +       if (proxy_new)
25112 +               put_nsproxy(proxy_new);
25113 +out_put:
25114 +       if (proxy_cur)
25115 +               put_nsproxy(proxy_cur);
25116 +       return ret;
25117 +}
25118 +
25119 +
25120 +int vx_set_space(struct vx_info *vxi, unsigned long mask, unsigned index)
25121 +{
25122 +       struct nsproxy *proxy_vxi, *proxy_cur, *proxy_new;
25123 +       struct fs_struct *fs_vxi, *fs;
25124 +       int ret, kill = 0;
25125 +
25126 +       vxdprintk(VXD_CBIT(space, 8), "vx_set_space(%p[#%u],0x%08lx,%d)",
25127 +               vxi, vxi->vx_id, mask, index);
25128 +#if 0
25129 +       if (!mask)
25130 +               mask = default_space_mask.mask;
25131 +#endif
25132 +       if ((mask & space_mask.mask) != mask)
25133 +               return -EINVAL;
25134 +
25135 +       proxy_vxi = vxi->vx_nsproxy[index];
25136 +       fs_vxi = vxi->vx_fs[index];
25137 +
25138 +       if (mask & CLONE_FS) {
25139 +               fs = copy_fs_struct(current->fs);
25140 +               if (!fs)
25141 +                       return -ENOMEM;
25142 +       }
25143 +
25144 +       task_lock(current);
25145 +
25146 +       if (mask & CLONE_FS) {
25147 +               write_lock(&fs_vxi->lock);
25148 +               vxi->vx_fs[index] = fs;
25149 +               kill = !--fs_vxi->users;
25150 +               write_unlock(&fs_vxi->lock);
25151 +       }
25152 +
25153 +       proxy_cur = current->nsproxy;
25154 +       get_nsproxy(proxy_cur);
25155 +       task_unlock(current);
25156 +
25157 +       if (kill)
25158 +               free_fs_struct(fs_vxi);
25159 +
25160 +       proxy_new = __vs_merge_nsproxy(proxy_vxi, proxy_cur, mask);
25161 +       if (IS_ERR(proxy_new)) {
25162 +               ret = PTR_ERR(proxy_new);
25163 +               goto out_put;
25164 +       }
25165 +
25166 +       proxy_new = xchg(&vxi->vx_nsproxy[index], proxy_new);
25167 +       vxi->vx_nsmask[index] |= mask;
25168 +       ret = 0;
25169 +
25170 +       if (proxy_new)
25171 +               put_nsproxy(proxy_new);
25172 +out_put:
25173 +       if (proxy_cur)
25174 +               put_nsproxy(proxy_cur);
25175 +       return ret;
25176 +}
25177 +
25178 +
25179 +int vc_enter_space_v1(struct vx_info *vxi, void __user *data)
25180 +{
25181 +       struct vcmd_space_mask_v1 vc_data = { .mask = 0 };
25182 +
25183 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
25184 +               return -EFAULT;
25185 +
25186 +       return vx_enter_space(vxi, vc_data.mask, 0);
25187 +}
25188 +
25189 +int vc_enter_space(struct vx_info *vxi, void __user *data)
25190 +{
25191 +       struct vcmd_space_mask_v2 vc_data = { .mask = 0 };
25192 +
25193 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
25194 +               return -EFAULT;
25195 +
25196 +       if (vc_data.index >= VX_SPACES)
25197 +               return -EINVAL;
25198 +
25199 +       return vx_enter_space(vxi, vc_data.mask, vc_data.index);
25200 +}
25201 +
25202 +int vc_set_space_v1(struct vx_info *vxi, void __user *data)
25203 +{
25204 +       struct vcmd_space_mask_v1 vc_data = { .mask = 0 };
25205 +
25206 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
25207 +               return -EFAULT;
25208 +
25209 +       return vx_set_space(vxi, vc_data.mask, 0);
25210 +}
25211 +
25212 +int vc_set_space(struct vx_info *vxi, void __user *data)
25213 +{
25214 +       struct vcmd_space_mask_v2 vc_data = { .mask = 0 };
25215 +
25216 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
25217 +               return -EFAULT;
25218 +
25219 +       if (vc_data.index >= VX_SPACES)
25220 +               return -EINVAL;
25221 +
25222 +       return vx_set_space(vxi, vc_data.mask, vc_data.index);
25223 +}
25224 +
25225 +int vc_get_space_mask(void __user *data, int type)
25226 +{
25227 +       const struct vcmd_space_mask_v1 *mask;
25228 +
25229 +       if (type == 0)
25230 +               mask = &space_mask_v0;
25231 +       else if (type == 1)
25232 +               mask = &space_mask;
25233 +       else
25234 +               mask = &default_space_mask;
25235 +
25236 +       vxdprintk(VXD_CBIT(space, 10),
25237 +               "vc_get_space_mask(%d) = %08llx", type, mask->mask);
25238 +
25239 +       if (copy_to_user(data, mask, sizeof(*mask)))
25240 +               return -EFAULT;
25241 +       return 0;
25242 +}
25243 +
25244 diff -NurpP --minimal linux-2.6.32.1/kernel/vserver/switch.c linux-2.6.32.1-vs2.3.0.36.27/kernel/vserver/switch.c
25245 --- linux-2.6.32.1/kernel/vserver/switch.c      1970-01-01 01:00:00.000000000 +0100
25246 +++ linux-2.6.32.1-vs2.3.0.36.27/kernel/vserver/switch.c        2009-12-03 20:04:56.000000000 +0100
25247 @@ -0,0 +1,546 @@
25248 +/*
25249 + *  linux/kernel/vserver/switch.c
25250 + *
25251 + *  Virtual Server: Syscall Switch
25252 + *
25253 + *  Copyright (C) 2003-2007  Herbert Pötzl
25254 + *
25255 + *  V0.01  syscall switch
25256 + *  V0.02  added signal to context
25257 + *  V0.03  added rlimit functions
25258 + *  V0.04  added iattr, task/xid functions
25259 + *  V0.05  added debug/history stuff
25260 + *  V0.06  added compat32 layer
25261 + *  V0.07  vcmd args and perms
25262 + *  V0.08  added status commands
25263 + *  V0.09  added tag commands
25264 + *  V0.10  added oom bias
25265 + *  V0.11  added device commands
25266 + *
25267 + */
25268 +
25269 +#include <linux/vs_context.h>
25270 +#include <linux/vs_network.h>
25271 +#include <linux/vserver/switch.h>
25272 +
25273 +#include "vci_config.h"
25274 +
25275 +
25276 +static inline
25277 +int vc_get_version(uint32_t id)
25278 +{
25279 +       return VCI_VERSION;
25280 +}
25281 +
25282 +static inline
25283 +int vc_get_vci(uint32_t id)
25284 +{
25285 +       return vci_kernel_config();
25286 +}
25287 +
25288 +#include <linux/vserver/context_cmd.h>
25289 +#include <linux/vserver/cvirt_cmd.h>
25290 +#include <linux/vserver/cacct_cmd.h>
25291 +#include <linux/vserver/limit_cmd.h>
25292 +#include <linux/vserver/network_cmd.h>
25293 +#include <linux/vserver/sched_cmd.h>
25294 +#include <linux/vserver/debug_cmd.h>
25295 +#include <linux/vserver/inode_cmd.h>
25296 +#include <linux/vserver/dlimit_cmd.h>
25297 +#include <linux/vserver/signal_cmd.h>
25298 +#include <linux/vserver/space_cmd.h>
25299 +#include <linux/vserver/tag_cmd.h>
25300 +#include <linux/vserver/device_cmd.h>
25301 +
25302 +#include <linux/vserver/inode.h>
25303 +#include <linux/vserver/dlimit.h>
25304 +
25305 +
25306 +#ifdef CONFIG_COMPAT
25307 +#define __COMPAT(name, id, data, compat)       \
25308 +       (compat) ? name ## _x32(id, data) : name(id, data)
25309 +#define __COMPAT_NO_ID(name, data, compat)     \
25310 +       (compat) ? name ## _x32(data) : name(data)
25311 +#else
25312 +#define __COMPAT(name, id, data, compat)       \
25313 +       name(id, data)
25314 +#define __COMPAT_NO_ID(name, data, compat)     \
25315 +       name(data)
25316 +#endif
25317 +
25318 +
25319 +static inline
25320 +long do_vcmd(uint32_t cmd, uint32_t id,
25321 +       struct vx_info *vxi, struct nx_info *nxi,
25322 +       void __user *data, int compat)
25323 +{
25324 +       switch (cmd) {
25325 +
25326 +       case VCMD_get_version:
25327 +               return vc_get_version(id);
25328 +       case VCMD_get_vci:
25329 +               return vc_get_vci(id);
25330 +
25331 +       case VCMD_task_xid:
25332 +               return vc_task_xid(id);
25333 +       case VCMD_vx_info:
25334 +               return vc_vx_info(vxi, data);
25335 +
25336 +       case VCMD_task_nid:
25337 +               return vc_task_nid(id);
25338 +       case VCMD_nx_info:
25339 +               return vc_nx_info(nxi, data);
25340 +
25341 +       case VCMD_task_tag:
25342 +               return vc_task_tag(id);
25343 +
25344 +       case VCMD_set_space_v1:
25345 +               return vc_set_space_v1(vxi, data);
25346 +       /* this is version 2 */
25347 +       case VCMD_set_space:
25348 +               return vc_set_space(vxi, data);
25349 +
25350 +       case VCMD_get_space_mask_v0:
25351 +               return vc_get_space_mask(data, 0);
25352 +       /* this is version 1 */
25353 +       case VCMD_get_space_mask:
25354 +               return vc_get_space_mask(data, 1);
25355 +
25356 +       case VCMD_get_space_default:
25357 +               return vc_get_space_mask(data, -1);
25358 +
25359 +#ifdef CONFIG_IA32_EMULATION
25360 +       case VCMD_get_rlimit:
25361 +               return __COMPAT(vc_get_rlimit, vxi, data, compat);
25362 +       case VCMD_set_rlimit:
25363 +               return __COMPAT(vc_set_rlimit, vxi, data, compat);
25364 +#else
25365 +       case VCMD_get_rlimit:
25366 +               return vc_get_rlimit(vxi, data);
25367 +       case VCMD_set_rlimit:
25368 +               return vc_set_rlimit(vxi, data);
25369 +#endif
25370 +       case VCMD_get_rlimit_mask:
25371 +               return vc_get_rlimit_mask(id, data);
25372 +       case VCMD_reset_hits:
25373 +               return vc_reset_hits(vxi, data);
25374 +       case VCMD_reset_minmax:
25375 +               return vc_reset_minmax(vxi, data);
25376 +
25377 +       case VCMD_get_vhi_name:
25378 +               return vc_get_vhi_name(vxi, data);
25379 +       case VCMD_set_vhi_name:
25380 +               return vc_set_vhi_name(vxi, data);
25381 +
25382 +       case VCMD_ctx_stat:
25383 +               return vc_ctx_stat(vxi, data);
25384 +       case VCMD_virt_stat:
25385 +               return vc_virt_stat(vxi, data);
25386 +       case VCMD_sock_stat:
25387 +               return vc_sock_stat(vxi, data);
25388 +       case VCMD_rlimit_stat:
25389 +               return vc_rlimit_stat(vxi, data);
25390 +
25391 +       case VCMD_set_cflags:
25392 +               return vc_set_cflags(vxi, data);
25393 +       case VCMD_get_cflags:
25394 +               return vc_get_cflags(vxi, data);
25395 +
25396 +       /* this is version 1 */
25397 +       case VCMD_set_ccaps:
25398 +               return vc_set_ccaps(vxi, data);
25399 +       /* this is version 1 */
25400 +       case VCMD_get_ccaps:
25401 +               return vc_get_ccaps(vxi, data);
25402 +       case VCMD_set_bcaps:
25403 +               return vc_set_bcaps(vxi, data);
25404 +       case VCMD_get_bcaps:
25405 +               return vc_get_bcaps(vxi, data);
25406 +
25407 +       case VCMD_set_badness:
25408 +               return vc_set_badness(vxi, data);
25409 +       case VCMD_get_badness:
25410 +               return vc_get_badness(vxi, data);
25411 +
25412 +       case VCMD_set_nflags:
25413 +               return vc_set_nflags(nxi, data);
25414 +       case VCMD_get_nflags:
25415 +               return vc_get_nflags(nxi, data);
25416 +
25417 +       case VCMD_set_ncaps:
25418 +               return vc_set_ncaps(nxi, data);
25419 +       case VCMD_get_ncaps:
25420 +               return vc_get_ncaps(nxi, data);
25421 +
25422 +       case VCMD_set_sched_v4:
25423 +               return vc_set_sched_v4(vxi, data);
25424 +       /* this is version 5 */
25425 +       case VCMD_set_sched:
25426 +               return vc_set_sched(vxi, data);
25427 +       case VCMD_get_sched:
25428 +               return vc_get_sched(vxi, data);
25429 +       case VCMD_sched_info:
25430 +               return vc_sched_info(vxi, data);
25431 +
25432 +       case VCMD_add_dlimit:
25433 +               return __COMPAT(vc_add_dlimit, id, data, compat);
25434 +       case VCMD_rem_dlimit:
25435 +               return __COMPAT(vc_rem_dlimit, id, data, compat);
25436 +       case VCMD_set_dlimit:
25437 +               return __COMPAT(vc_set_dlimit, id, data, compat);
25438 +       case VCMD_get_dlimit:
25439 +               return __COMPAT(vc_get_dlimit, id, data, compat);
25440 +
25441 +       case VCMD_ctx_kill:
25442 +               return vc_ctx_kill(vxi, data);
25443 +
25444 +       case VCMD_wait_exit:
25445 +               return vc_wait_exit(vxi, data);
25446 +
25447 +       case VCMD_get_iattr:
25448 +               return __COMPAT_NO_ID(vc_get_iattr, data, compat);
25449 +       case VCMD_set_iattr:
25450 +               return __COMPAT_NO_ID(vc_set_iattr, data, compat);
25451 +
25452 +       case VCMD_fget_iattr:
25453 +               return vc_fget_iattr(id, data);
25454 +       case VCMD_fset_iattr:
25455 +               return vc_fset_iattr(id, data);
25456 +
25457 +       case VCMD_enter_space_v0:
25458 +               return vc_enter_space_v1(vxi, NULL);
25459 +       case VCMD_enter_space_v1:
25460 +               return vc_enter_space_v1(vxi, data);
25461 +       /* this is version 2 */
25462 +       case VCMD_enter_space:
25463 +               return vc_enter_space(vxi, data);
25464 +
25465 +       case VCMD_ctx_create_v0:
25466 +               return vc_ctx_create(id, NULL);
25467 +       case VCMD_ctx_create:
25468 +               return vc_ctx_create(id, data);
25469 +       case VCMD_ctx_migrate_v0:
25470 +               return vc_ctx_migrate(vxi, NULL);
25471 +       case VCMD_ctx_migrate:
25472 +               return vc_ctx_migrate(vxi, data);
25473 +
25474 +       case VCMD_net_create_v0:
25475 +               return vc_net_create(id, NULL);
25476 +       case VCMD_net_create:
25477 +               return vc_net_create(id, data);
25478 +       case VCMD_net_migrate:
25479 +               return vc_net_migrate(nxi, data);
25480 +
25481 +       case VCMD_tag_migrate:
25482 +               return vc_tag_migrate(id);
25483 +
25484 +       case VCMD_net_add:
25485 +               return vc_net_add(nxi, data);
25486 +       case VCMD_net_remove:
25487 +               return vc_net_remove(nxi, data);
25488 +
25489 +       case VCMD_net_add_ipv4:
25490 +               return vc_net_add_ipv4(nxi, data);
25491 +       case VCMD_net_remove_ipv4:
25492 +               return vc_net_remove_ipv4(nxi, data);
25493 +#ifdef CONFIG_IPV6
25494 +       case VCMD_net_add_ipv6:
25495 +               return vc_net_add_ipv6(nxi, data);
25496 +       case VCMD_net_remove_ipv6:
25497 +               return vc_net_remove_ipv6(nxi, data);
25498 +#endif
25499 +/*     case VCMD_add_match_ipv4:
25500 +               return vc_add_match_ipv4(nxi, data);
25501 +       case VCMD_get_match_ipv4:
25502 +               return vc_get_match_ipv4(nxi, data);
25503 +#ifdef CONFIG_IPV6
25504 +       case VCMD_add_match_ipv6:
25505 +               return vc_add_match_ipv6(nxi, data);
25506 +       case VCMD_get_match_ipv6:
25507 +               return vc_get_match_ipv6(nxi, data);
25508 +#endif */
25509 +
25510 +#ifdef CONFIG_VSERVER_DEVICE
25511 +       case VCMD_set_mapping:
25512 +               return __COMPAT(vc_set_mapping, vxi, data, compat);
25513 +       case VCMD_unset_mapping:
25514 +               return __COMPAT(vc_unset_mapping, vxi, data, compat);
25515 +#endif
25516 +#ifdef CONFIG_VSERVER_HISTORY
25517 +       case VCMD_dump_history:
25518 +               return vc_dump_history(id);
25519 +       case VCMD_read_history:
25520 +               return __COMPAT(vc_read_history, id, data, compat);
25521 +#endif
25522 +#ifdef CONFIG_VSERVER_MONITOR
25523 +       case VCMD_read_monitor:
25524 +               return __COMPAT(vc_read_monitor, id, data, compat);
25525 +#endif
25526 +       default:
25527 +               vxwprintk_task(1, "unimplemented VCMD_%02d_%d[%d]",
25528 +                       VC_CATEGORY(cmd), VC_COMMAND(cmd), VC_VERSION(cmd));
25529 +       }
25530 +       return -ENOSYS;
25531 +}
25532 +
25533 +
25534 +#define        __VCMD(vcmd, _perm, _args, _flags)              \
25535 +       case VCMD_ ## vcmd: perm = _perm;               \
25536 +               args = _args; flags = _flags; break
25537 +
25538 +
25539 +#define VCA_NONE       0x00
25540 +#define VCA_VXI                0x01
25541 +#define VCA_NXI                0x02
25542 +
25543 +#define VCF_NONE       0x00
25544 +#define VCF_INFO       0x01
25545 +#define VCF_ADMIN      0x02
25546 +#define VCF_ARES       0x06    /* includes admin */
25547 +#define VCF_SETUP      0x08
25548 +
25549 +#define VCF_ZIDOK      0x10    /* zero id okay */
25550 +
25551 +
25552 +static inline
25553 +long do_vserver(uint32_t cmd, uint32_t id, void __user *data, int compat)
25554 +{
25555 +       long ret;
25556 +       int permit = -1, state = 0;
25557 +       int perm = -1, args = 0, flags = 0;
25558 +       struct vx_info *vxi = NULL;
25559 +       struct nx_info *nxi = NULL;
25560 +
25561 +       switch (cmd) {
25562 +       /* unpriviledged commands */
25563 +       __VCMD(get_version,      0, VCA_NONE,   0);
25564 +       __VCMD(get_vci,          0, VCA_NONE,   0);
25565 +       __VCMD(get_rlimit_mask,  0, VCA_NONE,   0);
25566 +       __VCMD(get_space_mask_v0,0, VCA_NONE,   0);
25567 +       __VCMD(get_space_mask,   0, VCA_NONE,   0);
25568 +       __VCMD(get_space_default,0, VCA_NONE,   0);
25569 +
25570 +       /* info commands */
25571 +       __VCMD(task_xid,         2, VCA_NONE,   0);
25572 +       __VCMD(reset_hits,       2, VCA_VXI,    0);
25573 +       __VCMD(reset_minmax,     2, VCA_VXI,    0);
25574 +       __VCMD(vx_info,          3, VCA_VXI,    VCF_INFO);
25575 +       __VCMD(get_bcaps,        3, VCA_VXI,    VCF_INFO);
25576 +       __VCMD(get_ccaps,        3, VCA_VXI,    VCF_INFO);
25577 +       __VCMD(get_cflags,       3, VCA_VXI,    VCF_INFO);
25578 +       __VCMD(get_badness,      3, VCA_VXI,    VCF_INFO);
25579 +       __VCMD(get_vhi_name,     3, VCA_VXI,    VCF_INFO);
25580 +       __VCMD(get_rlimit,       3, VCA_VXI,    VCF_INFO);
25581 +
25582 +       __VCMD(ctx_stat,         3, VCA_VXI,    VCF_INFO);
25583 +       __VCMD(virt_stat,        3, VCA_VXI,    VCF_INFO);
25584 +       __VCMD(sock_stat,        3, VCA_VXI,    VCF_INFO);
25585 +       __VCMD(rlimit_stat,      3, VCA_VXI,    VCF_INFO);
25586 +
25587 +       __VCMD(task_nid,         2, VCA_NONE,   0);
25588 +       __VCMD(nx_info,          3, VCA_NXI,    VCF_INFO);
25589 +       __VCMD(get_ncaps,        3, VCA_NXI,    VCF_INFO);
25590 +       __VCMD(get_nflags,       3, VCA_NXI,    VCF_INFO);
25591 +
25592 +       __VCMD(task_tag,         2, VCA_NONE,   0);
25593 +
25594 +       __VCMD(get_iattr,        2, VCA_NONE,   0);
25595 +       __VCMD(fget_iattr,       2, VCA_NONE,   0);
25596 +       __VCMD(get_dlimit,       3, VCA_NONE,   VCF_INFO);
25597 +       __VCMD(get_sched,        3, VCA_VXI,    VCF_INFO);
25598 +       __VCMD(sched_info,       3, VCA_VXI,    VCF_INFO | VCF_ZIDOK);
25599 +
25600 +       /* lower admin commands */
25601 +       __VCMD(wait_exit,        4, VCA_VXI,    VCF_INFO);
25602 +       __VCMD(ctx_create_v0,    5, VCA_NONE,   0);
25603 +       __VCMD(ctx_create,       5, VCA_NONE,   0);
25604 +       __VCMD(ctx_migrate_v0,   5, VCA_VXI,    VCF_ADMIN);
25605 +       __VCMD(ctx_migrate,      5, VCA_VXI,    VCF_ADMIN);
25606 +       __VCMD(enter_space_v0,   5, VCA_VXI,    VCF_ADMIN);
25607 +       __VCMD(enter_space_v1,   5, VCA_VXI,    VCF_ADMIN);
25608 +       __VCMD(enter_space,      5, VCA_VXI,    VCF_ADMIN);
25609 +
25610 +       __VCMD(net_create_v0,    5, VCA_NONE,   0);
25611 +       __VCMD(net_create,       5, VCA_NONE,   0);
25612 +       __VCMD(net_migrate,      5, VCA_NXI,    VCF_ADMIN);
25613 +
25614 +       __VCMD(tag_migrate,      5, VCA_NONE,   VCF_ADMIN);
25615 +
25616 +       /* higher admin commands */
25617 +       __VCMD(ctx_kill,         6, VCA_VXI,    VCF_ARES);
25618 +       __VCMD(set_space_v1,     7, VCA_VXI,    VCF_ARES | VCF_SETUP);
25619 +       __VCMD(set_space,        7, VCA_VXI,    VCF_ARES | VCF_SETUP);
25620 +
25621 +       __VCMD(set_ccaps,        7, VCA_VXI,    VCF_ARES | VCF_SETUP);
25622 +       __VCMD(set_bcaps,        7, VCA_VXI,    VCF_ARES | VCF_SETUP);
25623 +       __VCMD(set_cflags,       7, VCA_VXI,    VCF_ARES | VCF_SETUP);
25624 +       __VCMD(set_badness,      7, VCA_VXI,    VCF_ARES | VCF_SETUP);
25625 +
25626 +       __VCMD(set_vhi_name,     7, VCA_VXI,    VCF_ARES | VCF_SETUP);
25627 +       __VCMD(set_rlimit,       7, VCA_VXI,    VCF_ARES | VCF_SETUP);
25628 +       __VCMD(set_sched,        7, VCA_VXI,    VCF_ARES | VCF_SETUP);
25629 +       __VCMD(set_sched_v4,     7, VCA_VXI,    VCF_ARES | VCF_SETUP);
25630 +
25631 +       __VCMD(set_ncaps,        7, VCA_NXI,    VCF_ARES | VCF_SETUP);
25632 +       __VCMD(set_nflags,       7, VCA_NXI,    VCF_ARES | VCF_SETUP);
25633 +       __VCMD(net_add,          8, VCA_NXI,    VCF_ARES | VCF_SETUP);
25634 +       __VCMD(net_remove,       8, VCA_NXI,    VCF_ARES | VCF_SETUP);
25635 +       __VCMD(net_add_ipv4,     8, VCA_NXI,    VCF_ARES | VCF_SETUP);
25636 +       __VCMD(net_remove_ipv4,  8, VCA_NXI,    VCF_ARES | VCF_SETUP);
25637 +#ifdef CONFIG_IPV6
25638 +       __VCMD(net_add_ipv6,     8, VCA_NXI,    VCF_ARES | VCF_SETUP);
25639 +       __VCMD(net_remove_ipv6,  8, VCA_NXI,    VCF_ARES | VCF_SETUP);
25640 +#endif
25641 +       __VCMD(set_iattr,        7, VCA_NONE,   0);
25642 +       __VCMD(fset_iattr,       7, VCA_NONE,   0);
25643 +       __VCMD(set_dlimit,       7, VCA_NONE,   VCF_ARES);
25644 +       __VCMD(add_dlimit,       8, VCA_NONE,   VCF_ARES);
25645 +       __VCMD(rem_dlimit,       8, VCA_NONE,   VCF_ARES);
25646 +
25647 +#ifdef CONFIG_VSERVER_DEVICE
25648 +       __VCMD(set_mapping,      8, VCA_VXI,    VCF_ARES|VCF_ZIDOK);
25649 +       __VCMD(unset_mapping,    8, VCA_VXI,    VCF_ARES|VCF_ZIDOK);
25650 +#endif
25651 +       /* debug level admin commands */
25652 +#ifdef CONFIG_VSERVER_HISTORY
25653 +       __VCMD(dump_history,     9, VCA_NONE,   0);
25654 +       __VCMD(read_history,     9, VCA_NONE,   0);
25655 +#endif
25656 +#ifdef CONFIG_VSERVER_MONITOR
25657 +       __VCMD(read_monitor,     9, VCA_NONE,   0);
25658 +#endif
25659 +
25660 +       default:
25661 +               perm = -1;
25662 +       }
25663 +
25664 +       vxdprintk(VXD_CBIT(switch, 0),
25665 +               "vc: VCMD_%02d_%d[%d], %d,%p [%d,%d,%x,%x]",
25666 +               VC_CATEGORY(cmd), VC_COMMAND(cmd),
25667 +               VC_VERSION(cmd), id, data, compat,
25668 +               perm, args, flags);
25669 +
25670 +       ret = -ENOSYS;
25671 +       if (perm < 0)
25672 +               goto out;
25673 +
25674 +       state = 1;
25675 +       if (!capable(CAP_CONTEXT))
25676 +               goto out;
25677 +
25678 +       state = 2;
25679 +       /* moved here from the individual commands */
25680 +       ret = -EPERM;
25681 +       if ((perm > 1) && !capable(CAP_SYS_ADMIN))
25682 +               goto out;
25683 +
25684 +       state = 3;
25685 +       /* vcmd involves resource management  */
25686 +       ret = -EPERM;
25687 +       if ((flags & VCF_ARES) && !capable(CAP_SYS_RESOURCE))
25688 +               goto out;
25689 +
25690 +       state = 4;
25691 +       /* various legacy exceptions */
25692 +       switch (cmd) {
25693 +       /* will go away when spectator is a cap */
25694 +       case VCMD_ctx_migrate_v0:
25695 +       case VCMD_ctx_migrate:
25696 +               if (id == 1) {
25697 +                       current->xid = 1;
25698 +                       ret = 1;
25699 +                       goto out;
25700 +               }
25701 +               break;
25702 +
25703 +       /* will go away when spectator is a cap */
25704 +       case VCMD_net_migrate:
25705 +               if (id == 1) {
25706 +                       current->nid = 1;
25707 +                       ret = 1;
25708 +                       goto out;
25709 +               }
25710 +               break;
25711 +       }
25712 +
25713 +       /* vcmds are fine by default */
25714 +       permit = 1;
25715 +
25716 +       /* admin type vcmds require admin ... */
25717 +       if (flags & VCF_ADMIN)
25718 +               permit = vx_check(0, VS_ADMIN) ? 1 : 0;
25719 +
25720 +       /* ... but setup type vcmds override that */
25721 +       if (!permit && (flags & VCF_SETUP))
25722 +               permit = vx_flags(VXF_STATE_SETUP, 0) ? 2 : 0;
25723 +
25724 +       state = 5;
25725 +       ret = -EPERM;
25726 +       if (!permit)
25727 +               goto out;
25728 +
25729 +       state = 6;
25730 +       if (!id && (flags & VCF_ZIDOK))
25731 +               goto skip_id;
25732 +
25733 +       ret = -ESRCH;
25734 +       if (args & VCA_VXI) {
25735 +               vxi = lookup_vx_info(id);
25736 +               if (!vxi)
25737 +                       goto out;
25738 +
25739 +               if ((flags & VCF_ADMIN) &&
25740 +                       /* special case kill for shutdown */
25741 +                       (cmd != VCMD_ctx_kill) &&
25742 +                       /* can context be administrated? */
25743 +                       !vx_info_flags(vxi, VXF_STATE_ADMIN, 0)) {
25744 +                       ret = -EACCES;
25745 +                       goto out_vxi;
25746 +               }
25747 +       }
25748 +       state = 7;
25749 +       if (args & VCA_NXI) {
25750 +               nxi = lookup_nx_info(id);
25751 +               if (!nxi)
25752 +                       goto out_vxi;
25753 +
25754 +               if ((flags & VCF_ADMIN) &&
25755 +                       /* can context be administrated? */
25756 +                       !nx_info_flags(nxi, NXF_STATE_ADMIN, 0)) {
25757 +                       ret = -EACCES;
25758 +                       goto out_nxi;
25759 +               }
25760 +       }
25761 +skip_id:
25762 +       state = 8;
25763 +       ret = do_vcmd(cmd, id, vxi, nxi, data, compat);
25764 +
25765 +out_nxi:
25766 +       if ((args & VCA_NXI) && nxi)
25767 +               put_nx_info(nxi);
25768 +out_vxi:
25769 +       if ((args & VCA_VXI) && vxi)
25770 +               put_vx_info(vxi);
25771 +out:
25772 +       vxdprintk(VXD_CBIT(switch, 1),
25773 +               "vc: VCMD_%02d_%d[%d] = %08lx(%ld) [%d,%d]",
25774 +               VC_CATEGORY(cmd), VC_COMMAND(cmd),
25775 +               VC_VERSION(cmd), ret, ret, state, permit);
25776 +       return ret;
25777 +}
25778 +
25779 +asmlinkage long
25780 +sys_vserver(uint32_t cmd, uint32_t id, void __user *data)
25781 +{
25782 +       return do_vserver(cmd, id, data, 0);
25783 +}
25784 +
25785 +#ifdef CONFIG_COMPAT
25786 +
25787 +asmlinkage long
25788 +sys32_vserver(uint32_t cmd, uint32_t id, void __user *data)
25789 +{
25790 +       return do_vserver(cmd, id, data, 1);
25791 +}
25792 +
25793 +#endif /* CONFIG_COMPAT */
25794 diff -NurpP --minimal linux-2.6.32.1/kernel/vserver/sysctl.c linux-2.6.32.1-vs2.3.0.36.27/kernel/vserver/sysctl.c
25795 --- linux-2.6.32.1/kernel/vserver/sysctl.c      1970-01-01 01:00:00.000000000 +0100
25796 +++ linux-2.6.32.1-vs2.3.0.36.27/kernel/vserver/sysctl.c        2009-12-03 20:04:56.000000000 +0100
25797 @@ -0,0 +1,244 @@
25798 +/*
25799 + *  kernel/vserver/sysctl.c
25800 + *
25801 + *  Virtual Context Support
25802 + *
25803 + *  Copyright (C) 2004-2007  Herbert Pötzl
25804 + *
25805 + *  V0.01  basic structure
25806 + *
25807 + */
25808 +
25809 +#include <linux/module.h>
25810 +#include <linux/ctype.h>
25811 +#include <linux/sysctl.h>
25812 +#include <linux/parser.h>
25813 +#include <asm/uaccess.h>
25814 +
25815 +
25816 +enum {
25817 +       CTL_DEBUG_ERROR         = 0,
25818 +       CTL_DEBUG_SWITCH        = 1,
25819 +       CTL_DEBUG_XID,
25820 +       CTL_DEBUG_NID,
25821 +       CTL_DEBUG_TAG,
25822 +       CTL_DEBUG_NET,
25823 +       CTL_DEBUG_LIMIT,
25824 +       CTL_DEBUG_CRES,
25825 +       CTL_DEBUG_DLIM,
25826 +       CTL_DEBUG_QUOTA,
25827 +       CTL_DEBUG_CVIRT,
25828 +       CTL_DEBUG_SPACE,
25829 +       CTL_DEBUG_MISC,
25830 +};
25831 +
25832 +
25833 +unsigned int vx_debug_switch   = 0;
25834 +unsigned int vx_debug_xid      = 0;
25835 +unsigned int vx_debug_nid      = 0;
25836 +unsigned int vx_debug_tag      = 0;
25837 +unsigned int vx_debug_net      = 0;
25838 +unsigned int vx_debug_limit    = 0;
25839 +unsigned int vx_debug_cres     = 0;
25840 +unsigned int vx_debug_dlim     = 0;
25841 +unsigned int vx_debug_quota    = 0;
25842 +unsigned int vx_debug_cvirt    = 0;
25843 +unsigned int vx_debug_space    = 0;
25844 +unsigned int vx_debug_misc     = 0;
25845 +
25846 +
25847 +static struct ctl_table_header *vserver_table_header;
25848 +static ctl_table vserver_root_table[];
25849 +
25850 +
25851 +void vserver_register_sysctl(void)
25852 +{
25853 +       if (!vserver_table_header) {
25854 +               vserver_table_header = register_sysctl_table(vserver_root_table);
25855 +       }
25856 +
25857 +}
25858 +
25859 +void vserver_unregister_sysctl(void)
25860 +{
25861 +       if (vserver_table_header) {
25862 +               unregister_sysctl_table(vserver_table_header);
25863 +               vserver_table_header = NULL;
25864 +       }
25865 +}
25866 +
25867 +
25868 +static int proc_dodebug(ctl_table *table, int write,
25869 +       struct file *filp, void __user *buffer, size_t *lenp, loff_t *ppos)
25870 +{
25871 +       char            tmpbuf[20], *p, c;
25872 +       unsigned int    value;
25873 +       size_t          left, len;
25874 +
25875 +       if ((*ppos && !write) || !*lenp) {
25876 +               *lenp = 0;
25877 +               return 0;
25878 +       }
25879 +
25880 +       left = *lenp;
25881 +
25882 +       if (write) {
25883 +               if (!access_ok(VERIFY_READ, buffer, left))
25884 +                       return -EFAULT;
25885 +               p = (char *)buffer;
25886 +               while (left && __get_user(c, p) >= 0 && isspace(c))
25887 +                       left--, p++;
25888 +               if (!left)
25889 +                       goto done;
25890 +
25891 +               if (left > sizeof(tmpbuf) - 1)
25892 +                       return -EINVAL;
25893 +               if (copy_from_user(tmpbuf, p, left))
25894 +                       return -EFAULT;
25895 +               tmpbuf[left] = '\0';
25896 +
25897 +               for (p = tmpbuf, value = 0; '0' <= *p && *p <= '9'; p++, left--)
25898 +                       value = 10 * value + (*p - '0');
25899 +               if (*p && !isspace(*p))
25900 +                       return -EINVAL;
25901 +               while (left && isspace(*p))
25902 +                       left--, p++;
25903 +               *(unsigned int *)table->data = value;
25904 +       } else {
25905 +               if (!access_ok(VERIFY_WRITE, buffer, left))
25906 +                       return -EFAULT;
25907 +               len = sprintf(tmpbuf, "%d", *(unsigned int *)table->data);
25908 +               if (len > left)
25909 +                       len = left;
25910 +               if (__copy_to_user(buffer, tmpbuf, len))
25911 +                       return -EFAULT;
25912 +               if ((left -= len) > 0) {
25913 +                       if (put_user('\n', (char *)buffer + len))
25914 +                               return -EFAULT;
25915 +                       left--;
25916 +               }
25917 +       }
25918 +
25919 +done:
25920 +       *lenp -= left;
25921 +       *ppos += *lenp;
25922 +       return 0;
25923 +}
25924 +
25925 +static int zero;
25926 +
25927 +#define        CTL_ENTRY(ctl, name)                            \
25928 +       {                                               \
25929 +               .ctl_name       = ctl,                  \
25930 +               .procname       = #name,                \
25931 +               .data           = &vx_ ## name,         \
25932 +               .maxlen         = sizeof(int),          \
25933 +               .mode           = 0644,                 \
25934 +               .proc_handler   = &proc_dodebug,        \
25935 +               .strategy       = &sysctl_intvec,       \
25936 +               .extra1         = &zero,                \
25937 +       }
25938 +
25939 +static ctl_table vserver_debug_table[] = {
25940 +       CTL_ENTRY(CTL_DEBUG_SWITCH,     debug_switch),
25941 +       CTL_ENTRY(CTL_DEBUG_XID,        debug_xid),
25942 +       CTL_ENTRY(CTL_DEBUG_NID,        debug_nid),
25943 +       CTL_ENTRY(CTL_DEBUG_TAG,        debug_tag),
25944 +       CTL_ENTRY(CTL_DEBUG_NET,        debug_net),
25945 +       CTL_ENTRY(CTL_DEBUG_LIMIT,      debug_limit),
25946 +       CTL_ENTRY(CTL_DEBUG_CRES,       debug_cres),
25947 +       CTL_ENTRY(CTL_DEBUG_DLIM,       debug_dlim),
25948 +       CTL_ENTRY(CTL_DEBUG_QUOTA,      debug_quota),
25949 +       CTL_ENTRY(CTL_DEBUG_CVIRT,      debug_cvirt),
25950 +       CTL_ENTRY(CTL_DEBUG_SPACE,      debug_space),
25951 +       CTL_ENTRY(CTL_DEBUG_MISC,       debug_misc),
25952 +       { .ctl_name = 0 }
25953 +};
25954 +
25955 +static ctl_table vserver_root_table[] = {
25956 +       {
25957 +               .ctl_name       = CTL_VSERVER,
25958 +               .procname       = "vserver",
25959 +               .mode           = 0555,
25960 +               .child          = vserver_debug_table
25961 +       },
25962 +       { .ctl_name = 0 }
25963 +};
25964 +
25965 +
25966 +static match_table_t tokens = {
25967 +       { CTL_DEBUG_SWITCH,     "switch=%x"     },
25968 +       { CTL_DEBUG_XID,        "xid=%x"        },
25969 +       { CTL_DEBUG_NID,        "nid=%x"        },
25970 +       { CTL_DEBUG_TAG,        "tag=%x"        },
25971 +       { CTL_DEBUG_NET,        "net=%x"        },
25972 +       { CTL_DEBUG_LIMIT,      "limit=%x"      },
25973 +       { CTL_DEBUG_CRES,       "cres=%x"       },
25974 +       { CTL_DEBUG_DLIM,       "dlim=%x"       },
25975 +       { CTL_DEBUG_QUOTA,      "quota=%x"      },
25976 +       { CTL_DEBUG_CVIRT,      "cvirt=%x"      },
25977 +       { CTL_DEBUG_SPACE,      "space=%x"      },
25978 +       { CTL_DEBUG_MISC,       "misc=%x"       },
25979 +       { CTL_DEBUG_ERROR,      NULL            }
25980 +};
25981 +
25982 +#define        HANDLE_CASE(id, name, val)                              \
25983 +       case CTL_DEBUG_ ## id:                                  \
25984 +               vx_debug_ ## name = val;                        \
25985 +               printk("vs_debug_" #name "=0x%x\n", val);       \
25986 +               break
25987 +
25988 +
25989 +static int __init vs_debug_setup(char *str)
25990 +{
25991 +       char *p;
25992 +       int token;
25993 +
25994 +       printk("vs_debug_setup(%s)\n", str);
25995 +       while ((p = strsep(&str, ",")) != NULL) {
25996 +               substring_t args[MAX_OPT_ARGS];
25997 +               unsigned int value;
25998 +
25999 +               if (!*p)
26000 +                       continue;
26001 +
26002 +               token = match_token(p, tokens, args);
26003 +               value = (token > 0) ? simple_strtoul(args[0].from, NULL, 0) : 0;
26004 +
26005 +               switch (token) {
26006 +               HANDLE_CASE(SWITCH, switch, value);
26007 +               HANDLE_CASE(XID,    xid,    value);
26008 +               HANDLE_CASE(NID,    nid,    value);
26009 +               HANDLE_CASE(TAG,    tag,    value);
26010 +               HANDLE_CASE(NET,    net,    value);
26011 +               HANDLE_CASE(LIMIT,  limit,  value);
26012 +               HANDLE_CASE(CRES,   cres,   value);
26013 +               HANDLE_CASE(DLIM,   dlim,   value);
26014 +               HANDLE_CASE(QUOTA,  quota,  value);
26015 +               HANDLE_CASE(CVIRT,  cvirt,  value);
26016 +               HANDLE_CASE(SPACE,  space,  value);
26017 +               HANDLE_CASE(MISC,   misc,   value);
26018 +               default:
26019 +                       return -EINVAL;
26020 +                       break;
26021 +               }
26022 +       }
26023 +       return 1;
26024 +}
26025 +
26026 +__setup("vsdebug=", vs_debug_setup);
26027 +
26028 +
26029 +
26030 +EXPORT_SYMBOL_GPL(vx_debug_switch);
26031 +EXPORT_SYMBOL_GPL(vx_debug_xid);
26032 +EXPORT_SYMBOL_GPL(vx_debug_nid);
26033 +EXPORT_SYMBOL_GPL(vx_debug_net);
26034 +EXPORT_SYMBOL_GPL(vx_debug_limit);
26035 +EXPORT_SYMBOL_GPL(vx_debug_cres);
26036 +EXPORT_SYMBOL_GPL(vx_debug_dlim);
26037 +EXPORT_SYMBOL_GPL(vx_debug_quota);
26038 +EXPORT_SYMBOL_GPL(vx_debug_cvirt);
26039 +EXPORT_SYMBOL_GPL(vx_debug_space);
26040 +EXPORT_SYMBOL_GPL(vx_debug_misc);
26041 +
26042 diff -NurpP --minimal linux-2.6.32.1/kernel/vserver/tag.c linux-2.6.32.1-vs2.3.0.36.27/kernel/vserver/tag.c
26043 --- linux-2.6.32.1/kernel/vserver/tag.c 1970-01-01 01:00:00.000000000 +0100
26044 +++ linux-2.6.32.1-vs2.3.0.36.27/kernel/vserver/tag.c   2009-12-03 20:04:56.000000000 +0100
26045 @@ -0,0 +1,63 @@
26046 +/*
26047 + *  linux/kernel/vserver/tag.c
26048 + *
26049 + *  Virtual Server: Shallow Tag Space
26050 + *
26051 + *  Copyright (C) 2007  Herbert Pötzl
26052 + *
26053 + *  V0.01  basic implementation
26054 + *
26055 + */
26056 +
26057 +#include <linux/sched.h>
26058 +#include <linux/vserver/debug.h>
26059 +#include <linux/vs_pid.h>
26060 +#include <linux/vs_tag.h>
26061 +
26062 +#include <linux/vserver/tag_cmd.h>
26063 +
26064 +
26065 +int dx_migrate_task(struct task_struct *p, tag_t tag)
26066 +{
26067 +       if (!p)
26068 +               BUG();
26069 +
26070 +       vxdprintk(VXD_CBIT(tag, 5),
26071 +               "dx_migrate_task(%p[#%d],#%d)", p, p->tag, tag);
26072 +
26073 +       task_lock(p);
26074 +       p->tag = tag;
26075 +       task_unlock(p);
26076 +
26077 +       vxdprintk(VXD_CBIT(tag, 5),
26078 +               "moved task %p into [#%d]", p, tag);
26079 +       return 0;
26080 +}
26081 +
26082 +/* vserver syscall commands below here */
26083 +
26084 +/* taks xid and vx_info functions */
26085 +
26086 +
26087 +int vc_task_tag(uint32_t id)
26088 +{
26089 +       tag_t tag;
26090 +
26091 +       if (id) {
26092 +               struct task_struct *tsk;
26093 +               read_lock(&tasklist_lock);
26094 +               tsk = find_task_by_real_pid(id);
26095 +               tag = (tsk) ? tsk->tag : -ESRCH;
26096 +               read_unlock(&tasklist_lock);
26097 +       } else
26098 +               tag = dx_current_tag();
26099 +       return tag;
26100 +}
26101 +
26102 +
26103 +int vc_tag_migrate(uint32_t tag)
26104 +{
26105 +       return dx_migrate_task(current, tag & 0xFFFF);
26106 +}
26107 +
26108 +
26109 diff -NurpP --minimal linux-2.6.32.1/kernel/vserver/vci_config.h linux-2.6.32.1-vs2.3.0.36.27/kernel/vserver/vci_config.h
26110 --- linux-2.6.32.1/kernel/vserver/vci_config.h  1970-01-01 01:00:00.000000000 +0100
26111 +++ linux-2.6.32.1-vs2.3.0.36.27/kernel/vserver/vci_config.h    2009-12-03 20:04:56.000000000 +0100
26112 @@ -0,0 +1,81 @@
26113 +
26114 +/*  interface version */
26115 +
26116 +#define VCI_VERSION            0x00020305
26117 +
26118 +
26119 +enum {
26120 +       VCI_KCBIT_NO_DYNAMIC = 0,
26121 +
26122 +       VCI_KCBIT_PROC_SECURE = 4,
26123 +       VCI_KCBIT_HARDCPU = 5,
26124 +       VCI_KCBIT_IDLELIMIT = 6,
26125 +       VCI_KCBIT_IDLETIME = 7,
26126 +
26127 +       VCI_KCBIT_COWBL = 8,
26128 +       VCI_KCBIT_FULLCOWBL = 9,
26129 +       VCI_KCBIT_SPACES = 10,
26130 +       VCI_KCBIT_NETV2 = 11,
26131 +
26132 +       VCI_KCBIT_DEBUG = 16,
26133 +       VCI_KCBIT_HISTORY = 20,
26134 +       VCI_KCBIT_TAGGED = 24,
26135 +       VCI_KCBIT_PPTAG = 28,
26136 +
26137 +       VCI_KCBIT_MORE = 31,
26138 +};
26139 +
26140 +
26141 +static inline uint32_t vci_kernel_config(void)
26142 +{
26143 +       return
26144 +       (1 << VCI_KCBIT_NO_DYNAMIC) |
26145 +
26146 +       /* configured features */
26147 +#ifdef CONFIG_VSERVER_PROC_SECURE
26148 +       (1 << VCI_KCBIT_PROC_SECURE) |
26149 +#endif
26150 +#ifdef CONFIG_VSERVER_HARDCPU
26151 +       (1 << VCI_KCBIT_HARDCPU) |
26152 +#endif
26153 +#ifdef CONFIG_VSERVER_IDLELIMIT
26154 +       (1 << VCI_KCBIT_IDLELIMIT) |
26155 +#endif
26156 +#ifdef CONFIG_VSERVER_IDLETIME
26157 +       (1 << VCI_KCBIT_IDLETIME) |
26158 +#endif
26159 +#ifdef CONFIG_VSERVER_COWBL
26160 +       (1 << VCI_KCBIT_COWBL) |
26161 +       (1 << VCI_KCBIT_FULLCOWBL) |
26162 +#endif
26163 +       (1 << VCI_KCBIT_SPACES) |
26164 +       (1 << VCI_KCBIT_NETV2) |
26165 +
26166 +       /* debug options */
26167 +#ifdef CONFIG_VSERVER_DEBUG
26168 +       (1 << VCI_KCBIT_DEBUG) |
26169 +#endif
26170 +#ifdef CONFIG_VSERVER_HISTORY
26171 +       (1 << VCI_KCBIT_HISTORY) |
26172 +#endif
26173 +
26174 +       /* inode context tagging */
26175 +#if    defined(CONFIG_TAGGING_NONE)
26176 +       (0 << VCI_KCBIT_TAGGED) |
26177 +#elif  defined(CONFIG_TAGGING_UID16)
26178 +       (1 << VCI_KCBIT_TAGGED) |
26179 +#elif  defined(CONFIG_TAGGING_GID16)
26180 +       (2 << VCI_KCBIT_TAGGED) |
26181 +#elif  defined(CONFIG_TAGGING_ID24)
26182 +       (3 << VCI_KCBIT_TAGGED) |
26183 +#elif  defined(CONFIG_TAGGING_INTERN)
26184 +       (4 << VCI_KCBIT_TAGGED) |
26185 +#elif  defined(CONFIG_TAGGING_RUNTIME)
26186 +       (5 << VCI_KCBIT_TAGGED) |
26187 +#else
26188 +       (7 << VCI_KCBIT_TAGGED) |
26189 +#endif
26190 +       (1 << VCI_KCBIT_PPTAG) |
26191 +       0;
26192 +}
26193 +
26194 diff -NurpP --minimal linux-2.6.32.1/mm/allocpercpu.c linux-2.6.32.1-vs2.3.0.36.27/mm/allocpercpu.c
26195 --- linux-2.6.32.1/mm/allocpercpu.c     2009-12-03 20:02:58.000000000 +0100
26196 +++ linux-2.6.32.1-vs2.3.0.36.27/mm/allocpercpu.c       2009-12-03 20:04:56.000000000 +0100
26197 @@ -160,12 +160,14 @@ EXPORT_SYMBOL(__per_cpu_offset);
26198  
26199  void __init setup_per_cpu_areas(void)
26200  {
26201 -       unsigned long size, i;
26202 +       unsigned long size, vspc, i;
26203         char *ptr;
26204         unsigned long nr_possible_cpus = num_possible_cpus();
26205  
26206 +       vspc = PERCPU_PERCTX * CONFIG_VSERVER_CONTEXTS;
26207 +
26208         /* Copy section for each CPU (we discard the original) */
26209 -       size = ALIGN(PERCPU_ENOUGH_ROOM, PAGE_SIZE);
26210 +       size = ALIGN(PERCPU_ENOUGH_ROOM + vspc, PAGE_SIZE);
26211         ptr = alloc_bootmem_pages(size * nr_possible_cpus);
26212  
26213         for_each_possible_cpu(i) {
26214 diff -NurpP --minimal linux-2.6.32.1/mm/filemap_xip.c linux-2.6.32.1-vs2.3.0.36.27/mm/filemap_xip.c
26215 --- linux-2.6.32.1/mm/filemap_xip.c     2009-12-03 20:02:58.000000000 +0100
26216 +++ linux-2.6.32.1-vs2.3.0.36.27/mm/filemap_xip.c       2009-12-03 20:04:56.000000000 +0100
26217 @@ -17,6 +17,7 @@
26218  #include <linux/sched.h>
26219  #include <linux/seqlock.h>
26220  #include <linux/mutex.h>
26221 +#include <linux/vs_memory.h>
26222  #include <asm/tlbflush.h>
26223  #include <asm/io.h>
26224  
26225 diff -NurpP --minimal linux-2.6.32.1/mm/fremap.c linux-2.6.32.1-vs2.3.0.36.27/mm/fremap.c
26226 --- linux-2.6.32.1/mm/fremap.c  2009-03-24 14:22:45.000000000 +0100
26227 +++ linux-2.6.32.1-vs2.3.0.36.27/mm/fremap.c    2009-12-03 20:04:56.000000000 +0100
26228 @@ -16,6 +16,7 @@
26229  #include <linux/module.h>
26230  #include <linux/syscalls.h>
26231  #include <linux/mmu_notifier.h>
26232 +#include <linux/vs_memory.h>
26233  
26234  #include <asm/mmu_context.h>
26235  #include <asm/cacheflush.h>
26236 diff -NurpP --minimal linux-2.6.32.1/mm/hugetlb.c linux-2.6.32.1-vs2.3.0.36.27/mm/hugetlb.c
26237 --- linux-2.6.32.1/mm/hugetlb.c 2009-12-03 20:02:58.000000000 +0100
26238 +++ linux-2.6.32.1-vs2.3.0.36.27/mm/hugetlb.c   2009-12-03 20:04:56.000000000 +0100
26239 @@ -24,6 +24,7 @@
26240  #include <asm/io.h>
26241  
26242  #include <linux/hugetlb.h>
26243 +#include <linux/vs_memory.h>
26244  #include "internal.h"
26245  
26246  const unsigned long hugetlb_zero = 0, hugetlb_infinity = ~0UL;
26247 diff -NurpP --minimal linux-2.6.32.1/mm/memory.c linux-2.6.32.1-vs2.3.0.36.27/mm/memory.c
26248 --- linux-2.6.32.1/mm/memory.c  2009-12-03 20:02:58.000000000 +0100
26249 +++ linux-2.6.32.1-vs2.3.0.36.27/mm/memory.c    2009-12-03 20:04:56.000000000 +0100
26250 @@ -56,6 +56,7 @@
26251  #include <linux/kallsyms.h>
26252  #include <linux/swapops.h>
26253  #include <linux/elf.h>
26254 +// #include <linux/vs_memory.h>
26255  
26256  #include <asm/io.h>
26257  #include <asm/pgalloc.h>
26258 @@ -647,6 +648,9 @@ static int copy_pte_range(struct mm_stru
26259         int progress = 0;
26260         int rss[2];
26261  
26262 +       if (!vx_rss_avail(dst_mm, ((end - addr)/PAGE_SIZE + 1)))
26263 +               return -ENOMEM;
26264 +
26265  again:
26266         rss[1] = rss[0] = 0;
26267         dst_pte = pte_alloc_map_lock(dst_mm, dst_pmd, addr, &dst_ptl);
26268 @@ -2645,6 +2649,8 @@ static int do_anonymous_page(struct mm_s
26269         /* Allocate our own private page. */
26270         pte_unmap(page_table);
26271  
26272 +       if (!vx_rss_avail(mm, 1))
26273 +               goto oom;
26274         if (unlikely(anon_vma_prepare(vma)))
26275                 goto oom;
26276         page = alloc_zeroed_user_highpage_movable(vma, address);
26277 @@ -2936,6 +2942,7 @@ static inline int handle_pte_fault(struc
26278  {
26279         pte_t entry;
26280         spinlock_t *ptl;
26281 +       int ret = 0, type = VXPT_UNKNOWN;
26282  
26283         entry = *pte;
26284         if (!pte_present(entry)) {
26285 @@ -2960,9 +2967,12 @@ static inline int handle_pte_fault(struc
26286         if (unlikely(!pte_same(*pte, entry)))
26287                 goto unlock;
26288         if (flags & FAULT_FLAG_WRITE) {
26289 -               if (!pte_write(entry))
26290 -                       return do_wp_page(mm, vma, address,
26291 +               if (!pte_write(entry)) {
26292 +                       ret = do_wp_page(mm, vma, address,
26293                                         pte, pmd, ptl, entry);
26294 +                       type = VXPT_WRITE;
26295 +                       goto out;
26296 +               }
26297                 entry = pte_mkdirty(entry);
26298         }
26299         entry = pte_mkyoung(entry);
26300 @@ -2980,7 +2990,10 @@ static inline int handle_pte_fault(struc
26301         }
26302  unlock:
26303         pte_unmap_unlock(pte, ptl);
26304 -       return 0;
26305 +       ret = 0;
26306 +out:
26307 +       vx_page_fault(mm, vma, type, ret);
26308 +       return ret;
26309  }
26310  
26311  /*
26312 diff -NurpP --minimal linux-2.6.32.1/mm/mlock.c linux-2.6.32.1-vs2.3.0.36.27/mm/mlock.c
26313 --- linux-2.6.32.1/mm/mlock.c   2009-12-03 20:02:58.000000000 +0100
26314 +++ linux-2.6.32.1-vs2.3.0.36.27/mm/mlock.c     2009-12-03 20:04:56.000000000 +0100
26315 @@ -18,6 +18,7 @@
26316  #include <linux/rmap.h>
26317  #include <linux/mmzone.h>
26318  #include <linux/hugetlb.h>
26319 +#include <linux/vs_memory.h>
26320  
26321  #include "internal.h"
26322  
26323 @@ -401,7 +402,7 @@ success:
26324         nr_pages = (end - start) >> PAGE_SHIFT;
26325         if (!lock)
26326                 nr_pages = -nr_pages;
26327 -       mm->locked_vm += nr_pages;
26328 +       vx_vmlocked_add(mm, nr_pages);
26329  
26330         /*
26331          * vm_flags is protected by the mmap_sem held in write mode.
26332 @@ -474,7 +475,7 @@ static int do_mlock(unsigned long start,
26333  
26334  SYSCALL_DEFINE2(mlock, unsigned long, start, size_t, len)
26335  {
26336 -       unsigned long locked;
26337 +       unsigned long locked, grow;
26338         unsigned long lock_limit;
26339         int error = -ENOMEM;
26340  
26341 @@ -487,8 +488,10 @@ SYSCALL_DEFINE2(mlock, unsigned long, st
26342         len = PAGE_ALIGN(len + (start & ~PAGE_MASK));
26343         start &= PAGE_MASK;
26344  
26345 -       locked = len >> PAGE_SHIFT;
26346 -       locked += current->mm->locked_vm;
26347 +       grow = len >> PAGE_SHIFT;
26348 +       if (!vx_vmlocked_avail(current->mm, grow))
26349 +               goto out;
26350 +       locked = current->mm->locked_vm + grow;
26351  
26352         lock_limit = current->signal->rlim[RLIMIT_MEMLOCK].rlim_cur;
26353         lock_limit >>= PAGE_SHIFT;
26354 @@ -496,6 +499,7 @@ SYSCALL_DEFINE2(mlock, unsigned long, st
26355         /* check against resource limits */
26356         if ((locked <= lock_limit) || capable(CAP_IPC_LOCK))
26357                 error = do_mlock(start, len, 1);
26358 +out:
26359         up_write(&current->mm->mmap_sem);
26360         return error;
26361  }
26362 @@ -557,6 +561,8 @@ SYSCALL_DEFINE1(mlockall, int, flags)
26363         lock_limit >>= PAGE_SHIFT;
26364  
26365         ret = -ENOMEM;
26366 +       if (!vx_vmlocked_avail(current->mm, current->mm->total_vm))
26367 +               goto out;
26368         if (!(flags & MCL_CURRENT) || (current->mm->total_vm <= lock_limit) ||
26369             capable(CAP_IPC_LOCK))
26370                 ret = do_mlockall(flags);
26371 @@ -631,8 +637,10 @@ int account_locked_memory(struct mm_stru
26372         if (lim < vm)
26373                 goto out;
26374  
26375 -       mm->total_vm  += pgsz;
26376 -       mm->locked_vm += pgsz;
26377 +       // mm->total_vm  += pgsz;
26378 +       vx_vmpages_add(mm, pgsz);
26379 +       // mm->locked_vm += pgsz;
26380 +       vx_vmlocked_add(mm, pgsz);
26381  
26382         error = 0;
26383   out:
26384 @@ -646,8 +654,10 @@ void refund_locked_memory(struct mm_stru
26385  
26386         down_write(&mm->mmap_sem);
26387  
26388 -       mm->total_vm  -= pgsz;
26389 -       mm->locked_vm -= pgsz;
26390 +       // mm->total_vm  -= pgsz;
26391 +       vx_vmpages_sub(mm, pgsz);
26392 +       // mm->locked_vm -= pgsz;
26393 +       vx_vmlocked_sub(mm, pgsz);
26394  
26395         up_write(&mm->mmap_sem);
26396  }
26397 diff -NurpP --minimal linux-2.6.32.1/mm/mmap.c linux-2.6.32.1-vs2.3.0.36.27/mm/mmap.c
26398 --- linux-2.6.32.1/mm/mmap.c    2009-12-03 20:02:58.000000000 +0100
26399 +++ linux-2.6.32.1-vs2.3.0.36.27/mm/mmap.c      2009-12-03 20:04:56.000000000 +0100
26400 @@ -1236,7 +1236,8 @@ munmap_back:
26401  out:
26402         perf_event_mmap(vma);
26403  
26404 -       mm->total_vm += len >> PAGE_SHIFT;
26405 +       // mm->total_vm += len >> PAGE_SHIFT;
26406 +       vx_vmpages_add(mm, len >> PAGE_SHIFT);
26407         vm_stat_account(mm, vm_flags, file, len >> PAGE_SHIFT);
26408         if (vm_flags & VM_LOCKED) {
26409                 /*
26410 @@ -1245,7 +1246,8 @@ out:
26411                 long nr_pages = mlock_vma_pages_range(vma, addr, addr + len);
26412                 if (nr_pages < 0)
26413                         return nr_pages;        /* vma gone! */
26414 -               mm->locked_vm += (len >> PAGE_SHIFT) - nr_pages;
26415 +               // mm->locked_vm += (len >> PAGE_SHIFT) - nr_pages;
26416 +               vx_vmlocked_add(mm, (len >> PAGE_SHIFT) - nr_pages);
26417         } else if ((flags & MAP_POPULATE) && !(flags & MAP_NONBLOCK))
26418                 make_pages_present(addr, addr + len);
26419         return addr;
26420 @@ -1592,9 +1594,9 @@ static int acct_stack_growth(struct vm_a
26421                 return -ENOMEM;
26422  
26423         /* Ok, everything looks good - let it rip */
26424 -       mm->total_vm += grow;
26425 +       vx_vmpages_add(mm, grow);
26426         if (vma->vm_flags & VM_LOCKED)
26427 -               mm->locked_vm += grow;
26428 +               vx_vmlocked_add(mm, grow);
26429         vm_stat_account(mm, vma->vm_flags, vma->vm_file, grow);
26430         return 0;
26431  }
26432 @@ -1769,7 +1771,8 @@ static void remove_vma_list(struct mm_st
26433         do {
26434                 long nrpages = vma_pages(vma);
26435  
26436 -               mm->total_vm -= nrpages;
26437 +               // mm->total_vm -= nrpages;
26438 +               vx_vmpages_sub(mm, nrpages);
26439                 vm_stat_account(mm, vma->vm_flags, vma->vm_file, -nrpages);
26440                 vma = remove_vma(vma);
26441         } while (vma);
26442 @@ -1941,7 +1944,8 @@ int do_munmap(struct mm_struct *mm, unsi
26443                 struct vm_area_struct *tmp = vma;
26444                 while (tmp && tmp->vm_start < end) {
26445                         if (tmp->vm_flags & VM_LOCKED) {
26446 -                               mm->locked_vm -= vma_pages(tmp);
26447 +                               // mm->locked_vm -= vma_pages(tmp);
26448 +                               vx_vmlocked_sub(mm, vma_pages(tmp));
26449                                 munlock_vma_pages_all(tmp);
26450                         }
26451                         tmp = tmp->vm_next;
26452 @@ -2030,6 +2034,8 @@ unsigned long do_brk(unsigned long addr,
26453                 lock_limit >>= PAGE_SHIFT;
26454                 if (locked > lock_limit && !capable(CAP_IPC_LOCK))
26455                         return -EAGAIN;
26456 +               if (!vx_vmlocked_avail(mm, len >> PAGE_SHIFT))
26457 +                       return -ENOMEM;
26458         }
26459  
26460         /*
26461 @@ -2056,7 +2062,8 @@ unsigned long do_brk(unsigned long addr,
26462         if (mm->map_count > sysctl_max_map_count)
26463                 return -ENOMEM;
26464  
26465 -       if (security_vm_enough_memory(len >> PAGE_SHIFT))
26466 +       if (security_vm_enough_memory(len >> PAGE_SHIFT) ||
26467 +               !vx_vmpages_avail(mm, len >> PAGE_SHIFT))
26468                 return -ENOMEM;
26469  
26470         /* Can we just expand an old private anonymous mapping? */
26471 @@ -2082,10 +2089,13 @@ unsigned long do_brk(unsigned long addr,
26472         vma->vm_page_prot = vm_get_page_prot(flags);
26473         vma_link(mm, vma, prev, rb_link, rb_parent);
26474  out:
26475 -       mm->total_vm += len >> PAGE_SHIFT;
26476 +       // mm->total_vm += len >> PAGE_SHIFT;
26477 +       vx_vmpages_add(mm, len >> PAGE_SHIFT);
26478 +
26479         if (flags & VM_LOCKED) {
26480                 if (!mlock_vma_pages_range(vma, addr, addr + len))
26481 -                       mm->locked_vm += (len >> PAGE_SHIFT);
26482 +                       // mm->locked_vm += (len >> PAGE_SHIFT);
26483 +                       vx_vmlocked_add(mm, len >> PAGE_SHIFT);
26484         }
26485         return addr;
26486  }
26487 @@ -2129,6 +2139,11 @@ void exit_mmap(struct mm_struct *mm)
26488         free_pgtables(tlb, vma, FIRST_USER_ADDRESS, 0);
26489         tlb_finish_mmu(tlb, 0, end);
26490  
26491 +       set_mm_counter(mm, file_rss, 0);
26492 +       set_mm_counter(mm, anon_rss, 0);
26493 +       vx_vmpages_sub(mm, mm->total_vm);
26494 +       vx_vmlocked_sub(mm, mm->locked_vm);
26495 +
26496         /*
26497          * Walk the list again, actually closing and freeing it,
26498          * with preemption enabled, without holding any MM locks.
26499 @@ -2168,7 +2183,8 @@ int insert_vm_struct(struct mm_struct * 
26500         if (__vma && __vma->vm_start < vma->vm_end)
26501                 return -ENOMEM;
26502         if ((vma->vm_flags & VM_ACCOUNT) &&
26503 -            security_vm_enough_memory_mm(mm, vma_pages(vma)))
26504 +               (security_vm_enough_memory_mm(mm, vma_pages(vma)) ||
26505 +               !vx_vmpages_avail(mm, vma_pages(vma))))
26506                 return -ENOMEM;
26507         vma_link(mm, vma, prev, rb_link, rb_parent);
26508         return 0;
26509 @@ -2244,6 +2260,8 @@ int may_expand_vm(struct mm_struct *mm, 
26510  
26511         if (cur + npages > lim)
26512                 return 0;
26513 +       if (!vx_vmpages_avail(mm, npages))
26514 +               return 0;
26515         return 1;
26516  }
26517  
26518 @@ -2321,7 +2339,7 @@ int install_special_mapping(struct mm_st
26519                 return -ENOMEM;
26520         }
26521  
26522 -       mm->total_vm += len >> PAGE_SHIFT;
26523 +       vx_vmpages_add(mm, len >> PAGE_SHIFT);
26524  
26525         perf_event_mmap(vma);
26526  
26527 diff -NurpP --minimal linux-2.6.32.1/mm/mremap.c linux-2.6.32.1-vs2.3.0.36.27/mm/mremap.c
26528 --- linux-2.6.32.1/mm/mremap.c  2009-12-03 20:02:58.000000000 +0100
26529 +++ linux-2.6.32.1-vs2.3.0.36.27/mm/mremap.c    2009-12-03 20:04:56.000000000 +0100
26530 @@ -20,6 +20,7 @@
26531  #include <linux/security.h>
26532  #include <linux/syscalls.h>
26533  #include <linux/mmu_notifier.h>
26534 +#include <linux/vs_memory.h>
26535  
26536  #include <asm/uaccess.h>
26537  #include <asm/cacheflush.h>
26538 @@ -234,7 +235,7 @@ static unsigned long move_vma(struct vm_
26539          * If this were a serious issue, we'd add a flag to do_munmap().
26540          */
26541         hiwater_vm = mm->hiwater_vm;
26542 -       mm->total_vm += new_len >> PAGE_SHIFT;
26543 +       vx_vmpages_add(mm, new_len >> PAGE_SHIFT);
26544         vm_stat_account(mm, vma->vm_flags, vma->vm_file, new_len>>PAGE_SHIFT);
26545  
26546         if (do_munmap(mm, old_addr, old_len) < 0) {
26547 @@ -252,7 +253,7 @@ static unsigned long move_vma(struct vm_
26548         }
26549  
26550         if (vm_flags & VM_LOCKED) {
26551 -               mm->locked_vm += new_len >> PAGE_SHIFT;
26552 +               vx_vmlocked_add(mm, new_len >> PAGE_SHIFT);
26553                 if (new_len > old_len)
26554                         mlock_vma_pages_range(new_vma, new_addr + old_len,
26555                                                        new_addr + new_len);
26556 @@ -363,6 +364,9 @@ unsigned long do_mremap(unsigned long ad
26557                 ret = -EAGAIN;
26558                 if (locked > lock_limit && !capable(CAP_IPC_LOCK))
26559                         goto out;
26560 +               if (!vx_vmlocked_avail(current->mm,
26561 +                       (new_len - old_len) >> PAGE_SHIFT))
26562 +                       goto out;
26563         }
26564         if (!may_expand_vm(mm, (new_len - old_len) >> PAGE_SHIFT)) {
26565                 ret = -ENOMEM;
26566 @@ -391,10 +395,12 @@ unsigned long do_mremap(unsigned long ad
26567                         vma_adjust(vma, vma->vm_start,
26568                                 addr + new_len, vma->vm_pgoff, NULL);
26569  
26570 -                       mm->total_vm += pages;
26571 +                       // mm->total_vm += pages;
26572 +                       vx_vmpages_add(mm, pages);
26573                         vm_stat_account(mm, vma->vm_flags, vma->vm_file, pages);
26574                         if (vma->vm_flags & VM_LOCKED) {
26575 -                               mm->locked_vm += pages;
26576 +                               // mm->locked_vm += pages;
26577 +                               vx_vmlocked_add(mm, pages);
26578                                 mlock_vma_pages_range(vma, addr + old_len,
26579                                                    addr + new_len);
26580                         }
26581 diff -NurpP --minimal linux-2.6.32.1/mm/nommu.c linux-2.6.32.1-vs2.3.0.36.27/mm/nommu.c
26582 --- linux-2.6.32.1/mm/nommu.c   2009-12-03 20:02:58.000000000 +0100
26583 +++ linux-2.6.32.1-vs2.3.0.36.27/mm/nommu.c     2009-12-03 20:04:56.000000000 +0100
26584 @@ -1346,7 +1346,7 @@ unsigned long do_mmap_pgoff(struct file 
26585         /* okay... we have a mapping; now we have to register it */
26586         result = vma->vm_start;
26587  
26588 -       current->mm->total_vm += len >> PAGE_SHIFT;
26589 +       vx_vmpages_add(current->mm, len >> PAGE_SHIFT);
26590  
26591  share:
26592         add_vma_to_mm(current->mm, vma);
26593 @@ -1606,7 +1606,7 @@ void exit_mmap(struct mm_struct *mm)
26594  
26595         kenter("");
26596  
26597 -       mm->total_vm = 0;
26598 +       vx_vmpages_sub(mm, mm->total_vm);
26599  
26600         while ((vma = mm->mmap)) {
26601                 mm->mmap = vma->vm_next;
26602 diff -NurpP --minimal linux-2.6.32.1/mm/oom_kill.c linux-2.6.32.1-vs2.3.0.36.27/mm/oom_kill.c
26603 --- linux-2.6.32.1/mm/oom_kill.c        2009-12-03 20:02:58.000000000 +0100
26604 +++ linux-2.6.32.1-vs2.3.0.36.27/mm/oom_kill.c  2009-12-03 22:26:55.000000000 +0100
26605 @@ -27,6 +27,9 @@
26606  #include <linux/notifier.h>
26607  #include <linux/memcontrol.h>
26608  #include <linux/security.h>
26609 +#include <linux/reboot.h>
26610 +#include <linux/vs_memory.h>
26611 +#include <linux/vs_context.h>
26612  
26613  int sysctl_panic_on_oom;
26614  int sysctl_oom_kill_allocating_task;
26615 @@ -186,9 +189,21 @@ unsigned long badness(struct task_struct
26616                         points >>= -(oom_adj);
26617         }
26618  
26619 +       /*
26620 +        * add points for context badness and
26621 +        * reduce badness for processes belonging to
26622 +        * a different context
26623 +        */
26624 +
26625 +       points += vx_badness(p, mm);
26626 +
26627 +       if ((vx_current_xid() > 1) &&
26628 +               vx_current_xid() != vx_task_xid(p))
26629 +               points /= 16;
26630 +
26631  #ifdef DEBUG
26632 -       printk(KERN_DEBUG "OOMkill: task %d (%s) got %lu points\n",
26633 -       p->pid, p->comm, points);
26634 +       printk(KERN_DEBUG "OOMkill: task %d:#%u (%s) got %d points\n",
26635 +               task_pid_nr(p), p->xid, p->comm, points);
26636  #endif
26637         return points;
26638  }
26639 @@ -230,6 +245,7 @@ static struct task_struct *select_bad_pr
26640         struct task_struct *p;
26641         struct task_struct *chosen = NULL;
26642         struct timespec uptime;
26643 +       unsigned xid = vx_current_xid();
26644         *ppoints = 0;
26645  
26646         do_posix_clock_monotonic_gettime(&uptime);
26647 @@ -242,11 +258,14 @@ static struct task_struct *select_bad_pr
26648                  */
26649                 if (!p->mm)
26650                         continue;
26651 -               /* skip the init task */
26652 -               if (is_global_init(p))
26653 +               /* skip the init task, global and per guest */
26654 +               if (task_is_init(p))
26655                         continue;
26656                 if (mem && !task_in_mem_cgroup(p, mem))
26657                         continue;
26658 +               /* skip other guest and host processes if oom in guest */
26659 +               if (xid && vx_task_xid(p) != xid)
26660 +                       continue;
26661  
26662                 /*
26663                  * This task already has access to memory reserves and is
26664 @@ -357,8 +376,8 @@ static void __oom_kill_task(struct task_
26665         }
26666  
26667         if (verbose)
26668 -               printk(KERN_ERR "Killed process %d (%s)\n",
26669 -                               task_pid_nr(p), p->comm);
26670 +               printk(KERN_ERR "Killed process %s(%d:#%u)\n",
26671 +                       p->comm, task_pid_nr(p), p->xid);
26672  
26673         /*
26674          * We give our sacrificial lamb high priority and access to
26675 @@ -419,8 +438,8 @@ static int oom_kill_process(struct task_
26676                 return 0;
26677         }
26678  
26679 -       printk(KERN_ERR "%s: kill process %d (%s) score %li or a child\n",
26680 -                                       message, task_pid_nr(p), p->comm, points);
26681 +       printk(KERN_ERR "%s: kill process %s(%d:#%u) score %li or a child\n",
26682 +               message, p->comm, task_pid_nr(p), p->xid, points);
26683  
26684         /* Try to kill a child first */
26685         list_for_each_entry(c, &p->children, sibling) {
26686 @@ -519,6 +538,8 @@ void clear_zonelist_oom(struct zonelist 
26687         spin_unlock(&zone_scan_lock);
26688  }
26689  
26690 +long vs_oom_action(unsigned int);
26691 +
26692  /*
26693   * Must be called with tasklist_lock held for read.
26694   */
26695 @@ -544,7 +565,11 @@ retry:
26696         /* Found nothing?!?! Either we hang forever, or we panic. */
26697         if (!p) {
26698                 read_unlock(&tasklist_lock);
26699 -               panic("Out of memory and no killable processes...\n");
26700 +               /* avoid panic for guest OOM */
26701 +               if (current->xid)
26702 +                       vs_oom_action(LINUX_REBOOT_CMD_OOM);
26703 +               else
26704 +                       panic("Out of memory and no killable processes...\n");
26705         }
26706  
26707         if (oom_kill_process(p, gfp_mask, order, points, NULL,
26708 diff -NurpP --minimal linux-2.6.32.1/mm/page_alloc.c linux-2.6.32.1-vs2.3.0.36.27/mm/page_alloc.c
26709 --- linux-2.6.32.1/mm/page_alloc.c      2009-12-03 20:02:58.000000000 +0100
26710 +++ linux-2.6.32.1-vs2.3.0.36.27/mm/page_alloc.c        2009-12-03 20:04:56.000000000 +0100
26711 @@ -48,6 +48,8 @@
26712  #include <linux/page_cgroup.h>
26713  #include <linux/debugobjects.h>
26714  #include <linux/kmemleak.h>
26715 +#include <linux/vs_base.h>
26716 +#include <linux/vs_limit.h>
26717  #include <trace/events/kmem.h>
26718  
26719  #include <asm/tlbflush.h>
26720 @@ -2130,6 +2132,9 @@ void si_meminfo(struct sysinfo *val)
26721         val->totalhigh = totalhigh_pages;
26722         val->freehigh = nr_free_highpages();
26723         val->mem_unit = PAGE_SIZE;
26724 +
26725 +       if (vx_flags(VXF_VIRT_MEM, 0))
26726 +               vx_vsi_meminfo(val);
26727  }
26728  
26729  EXPORT_SYMBOL(si_meminfo);
26730 @@ -2150,6 +2155,9 @@ void si_meminfo_node(struct sysinfo *val
26731         val->freehigh = 0;
26732  #endif
26733         val->mem_unit = PAGE_SIZE;
26734 +
26735 +       if (vx_flags(VXF_VIRT_MEM, 0))
26736 +               vx_vsi_meminfo(val);
26737  }
26738  #endif
26739  
26740 diff -NurpP --minimal linux-2.6.32.1/mm/rmap.c linux-2.6.32.1-vs2.3.0.36.27/mm/rmap.c
26741 --- linux-2.6.32.1/mm/rmap.c    2009-12-03 20:02:58.000000000 +0100
26742 +++ linux-2.6.32.1-vs2.3.0.36.27/mm/rmap.c      2009-12-03 20:04:56.000000000 +0100
26743 @@ -55,6 +55,7 @@
26744  #include <linux/memcontrol.h>
26745  #include <linux/mmu_notifier.h>
26746  #include <linux/migrate.h>
26747 +#include <linux/vs_memory.h>
26748  
26749  #include <asm/tlbflush.h>
26750  
26751 diff -NurpP --minimal linux-2.6.32.1/mm/shmem.c linux-2.6.32.1-vs2.3.0.36.27/mm/shmem.c
26752 --- linux-2.6.32.1/mm/shmem.c   2009-12-03 20:02:58.000000000 +0100
26753 +++ linux-2.6.32.1-vs2.3.0.36.27/mm/shmem.c     2009-12-03 20:04:56.000000000 +0100
26754 @@ -1781,7 +1781,7 @@ static int shmem_statfs(struct dentry *d
26755  {
26756         struct shmem_sb_info *sbinfo = SHMEM_SB(dentry->d_sb);
26757  
26758 -       buf->f_type = TMPFS_MAGIC;
26759 +       buf->f_type = TMPFS_SUPER_MAGIC;
26760         buf->f_bsize = PAGE_CACHE_SIZE;
26761         buf->f_namelen = NAME_MAX;
26762         spin_lock(&sbinfo->stat_lock);
26763 @@ -2346,7 +2346,7 @@ int shmem_fill_super(struct super_block 
26764         sb->s_maxbytes = SHMEM_MAX_BYTES;
26765         sb->s_blocksize = PAGE_CACHE_SIZE;
26766         sb->s_blocksize_bits = PAGE_CACHE_SHIFT;
26767 -       sb->s_magic = TMPFS_MAGIC;
26768 +       sb->s_magic = TMPFS_SUPER_MAGIC;
26769         sb->s_op = &shmem_ops;
26770         sb->s_time_gran = 1;
26771  #ifdef CONFIG_TMPFS_POSIX_ACL
26772 diff -NurpP --minimal linux-2.6.32.1/mm/slab.c linux-2.6.32.1-vs2.3.0.36.27/mm/slab.c
26773 --- linux-2.6.32.1/mm/slab.c    2009-12-03 20:02:58.000000000 +0100
26774 +++ linux-2.6.32.1-vs2.3.0.36.27/mm/slab.c      2009-12-03 20:04:56.000000000 +0100
26775 @@ -431,6 +431,8 @@ static void kmem_list3_init(struct kmem_
26776  #define STATS_INC_FREEMISS(x)  do { } while (0)
26777  #endif
26778  
26779 +#include "slab_vs.h"
26780 +
26781  #if DEBUG
26782  
26783  /*
26784 @@ -3253,6 +3255,7 @@ retry:
26785  
26786         obj = slab_get_obj(cachep, slabp, nodeid);
26787         check_slabp(cachep, slabp);
26788 +       vx_slab_alloc(cachep, flags);
26789         l3->free_objects--;
26790         /* move slabp to correct slabp list: */
26791         list_del(&slabp->list);
26792 @@ -3329,6 +3332,7 @@ __cache_alloc_node(struct kmem_cache *ca
26793         /* ___cache_alloc_node can fall back to other nodes */
26794         ptr = ____cache_alloc_node(cachep, flags, nodeid);
26795    out:
26796 +       vx_slab_alloc(cachep, flags);
26797         local_irq_restore(save_flags);
26798         ptr = cache_alloc_debugcheck_after(cachep, flags, ptr, caller);
26799         kmemleak_alloc_recursive(ptr, obj_size(cachep), 1, cachep->flags,
26800 @@ -3515,6 +3519,7 @@ static inline void __cache_free(struct k
26801         check_irq_off();
26802         kmemleak_free_recursive(objp, cachep->flags);
26803         objp = cache_free_debugcheck(cachep, objp, __builtin_return_address(0));
26804 +       vx_slab_free(cachep);
26805  
26806         kmemcheck_slab_free(cachep, objp, obj_size(cachep));
26807  
26808 diff -NurpP --minimal linux-2.6.32.1/mm/slab_vs.h linux-2.6.32.1-vs2.3.0.36.27/mm/slab_vs.h
26809 --- linux-2.6.32.1/mm/slab_vs.h 1970-01-01 01:00:00.000000000 +0100
26810 +++ linux-2.6.32.1-vs2.3.0.36.27/mm/slab_vs.h   2009-12-03 20:04:56.000000000 +0100
26811 @@ -0,0 +1,29 @@
26812 +
26813 +#include <linux/vserver/context.h>
26814 +
26815 +#include <linux/vs_context.h>
26816 +
26817 +static inline
26818 +void vx_slab_alloc(struct kmem_cache *cachep, gfp_t flags)
26819 +{
26820 +       int what = gfp_zone(cachep->gfpflags);
26821 +       struct vx_info *vxi = current_vx_info();
26822 +
26823 +       if (!vxi)
26824 +               return;
26825 +
26826 +       atomic_add(cachep->buffer_size, &vxi->cacct.slab[what]);
26827 +}
26828 +
26829 +static inline
26830 +void vx_slab_free(struct kmem_cache *cachep)
26831 +{
26832 +       int what = gfp_zone(cachep->gfpflags);
26833 +       struct vx_info *vxi = current_vx_info();
26834 +
26835 +       if (!vxi)
26836 +               return;
26837 +
26838 +       atomic_sub(cachep->buffer_size, &vxi->cacct.slab[what]);
26839 +}
26840 +
26841 diff -NurpP --minimal linux-2.6.32.1/mm/swapfile.c linux-2.6.32.1-vs2.3.0.36.27/mm/swapfile.c
26842 --- linux-2.6.32.1/mm/swapfile.c        2009-12-03 20:02:58.000000000 +0100
26843 +++ linux-2.6.32.1-vs2.3.0.36.27/mm/swapfile.c  2009-12-03 20:04:56.000000000 +0100
26844 @@ -34,6 +34,8 @@
26845  #include <asm/tlbflush.h>
26846  #include <linux/swapops.h>
26847  #include <linux/page_cgroup.h>
26848 +#include <linux/vs_base.h>
26849 +#include <linux/vs_memory.h>
26850  
26851  static DEFINE_SPINLOCK(swap_lock);
26852  static unsigned int nr_swapfiles;
26853 @@ -1680,6 +1682,8 @@ static void *swap_next(struct seq_file *
26854         if (v == SEQ_START_TOKEN)
26855                 ptr = swap_info;
26856         else {
26857 +               if (vx_flags(VXF_VIRT_MEM, 0))
26858 +                       return NULL;
26859                 ptr = v;
26860                 ptr++;
26861         }
26862 @@ -1707,6 +1711,16 @@ static int swap_show(struct seq_file *sw
26863  
26864         if (ptr == SEQ_START_TOKEN) {
26865                 seq_puts(swap,"Filename\t\t\t\tType\t\tSize\tUsed\tPriority\n");
26866 +               if (vx_flags(VXF_VIRT_MEM, 0)) {
26867 +                       struct sysinfo si;
26868 +
26869 +                       vx_vsi_swapinfo(&si);
26870 +                       if (si.totalswap < (1 << 10))
26871 +                               return 0;
26872 +                       seq_printf(swap, "%s\t\t\t\t\t%s\t%lu\t%lu\t%d\n",
26873 +                               "hdv0", "partition", si.totalswap >> 10,
26874 +                               (si.totalswap - si.freeswap) >> 10, -1);
26875 +               }
26876                 return 0;
26877         }
26878  
26879 @@ -2064,6 +2078,8 @@ void si_swapinfo(struct sysinfo *val)
26880         val->freeswap = nr_swap_pages + nr_to_be_unused;
26881         val->totalswap = total_swap_pages + nr_to_be_unused;
26882         spin_unlock(&swap_lock);
26883 +       if (vx_flags(VXF_VIRT_MEM, 0))
26884 +               vx_vsi_swapinfo(val);
26885  }
26886  
26887  /*
26888 diff -NurpP --minimal linux-2.6.32.1/net/core/dev.c linux-2.6.32.1-vs2.3.0.36.27/net/core/dev.c
26889 --- linux-2.6.32.1/net/core/dev.c       2009-12-03 20:02:59.000000000 +0100
26890 +++ linux-2.6.32.1-vs2.3.0.36.27/net/core/dev.c 2009-12-03 20:04:56.000000000 +0100
26891 @@ -126,6 +126,7 @@
26892  #include <linux/in.h>
26893  #include <linux/jhash.h>
26894  #include <linux/random.h>
26895 +#include <linux/vs_inet.h>
26896  #include <trace/events/napi.h>
26897  
26898  #include "net-sysfs.h"
26899 @@ -591,7 +592,8 @@ struct net_device *__dev_get_by_name(str
26900         hlist_for_each(p, dev_name_hash(net, name)) {
26901                 struct net_device *dev
26902                         = hlist_entry(p, struct net_device, name_hlist);
26903 -               if (!strncmp(dev->name, name, IFNAMSIZ))
26904 +               if (!strncmp(dev->name, name, IFNAMSIZ) &&
26905 +                   nx_dev_visible(current_nx_info(), dev))
26906                         return dev;
26907         }
26908         return NULL;
26909 @@ -642,7 +644,8 @@ struct net_device *__dev_get_by_index(st
26910         hlist_for_each(p, dev_index_hash(net, ifindex)) {
26911                 struct net_device *dev
26912                         = hlist_entry(p, struct net_device, index_hlist);
26913 -               if (dev->ifindex == ifindex)
26914 +               if ((dev->ifindex == ifindex) &&
26915 +                   nx_dev_visible(current_nx_info(), dev))
26916                         return dev;
26917         }
26918         return NULL;
26919 @@ -695,10 +698,12 @@ struct net_device *dev_getbyhwaddr(struc
26920  
26921         ASSERT_RTNL();
26922  
26923 -       for_each_netdev(net, dev)
26924 +       for_each_netdev(net, dev) {
26925                 if (dev->type == type &&
26926 -                   !memcmp(dev->dev_addr, ha, dev->addr_len))
26927 +                   !memcmp(dev->dev_addr, ha, dev->addr_len) &&
26928 +                   nx_dev_visible(current_nx_info(), dev))
26929                         return dev;
26930 +       }
26931  
26932         return NULL;
26933  }
26934 @@ -709,9 +714,11 @@ struct net_device *__dev_getfirstbyhwtyp
26935         struct net_device *dev;
26936  
26937         ASSERT_RTNL();
26938 -       for_each_netdev(net, dev)
26939 -               if (dev->type == type)
26940 +       for_each_netdev(net, dev) {
26941 +               if ((dev->type == type) &&
26942 +                   nx_dev_visible(current_nx_info(), dev))
26943                         return dev;
26944 +       }
26945  
26946         return NULL;
26947  }
26948 @@ -830,6 +837,8 @@ static int __dev_alloc_name(struct net *
26949                                 continue;
26950                         if (i < 0 || i >= max_netdevices)
26951                                 continue;
26952 +                       if (!nx_dev_visible(current_nx_info(), d))
26953 +                               continue;
26954  
26955                         /*  avoid cases where sscanf is not exact inverse of printf */
26956                         snprintf(buf, IFNAMSIZ, name, i);
26957 @@ -2984,6 +2993,8 @@ static int dev_ifconf(struct net *net, c
26958  
26959         total = 0;
26960         for_each_netdev(net, dev) {
26961 +               if (!nx_dev_visible(current_nx_info(), dev))
26962 +                       continue;
26963                 for (i = 0; i < NPROTO; i++) {
26964                         if (gifconf_list[i]) {
26965                                 int done;
26966 @@ -3052,6 +3063,9 @@ static void dev_seq_printf_stats(struct 
26967  {
26968         const struct net_device_stats *stats = dev_get_stats(dev);
26969  
26970 +       if (!nx_dev_visible(current_nx_info(), dev))
26971 +               return;
26972 +
26973         seq_printf(seq, "%6s:%8lu %7lu %4lu %4lu %4lu %5lu %10lu %9lu "
26974                    "%8lu %7lu %4lu %4lu %4lu %5lu %7lu %10lu\n",
26975                    dev->name, stats->rx_bytes, stats->rx_packets,
26976 @@ -5313,6 +5327,15 @@ int dev_change_net_namespace(struct net_
26977                 goto out;
26978  #endif
26979  
26980 +#ifdef CONFIG_SYSFS
26981 +       /* Don't allow real devices to be moved when sysfs
26982 +        * is enabled.
26983 +        */
26984 +       err = -EINVAL;
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.1/net/core/rtnetlink.c linux-2.6.32.1-vs2.3.0.36.27/net/core/rtnetlink.c
26993 --- linux-2.6.32.1/net/core/rtnetlink.c 2009-12-03 20:02:59.000000000 +0100
26994 +++ linux-2.6.32.1-vs2.3.0.36.27/net/core/rtnetlink.c   2009-12-03 20:04:56.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.1/net/core/sock.c linux-2.6.32.1-vs2.3.0.36.27/net/core/sock.c
27015 --- linux-2.6.32.1/net/core/sock.c      2009-12-03 20:02:59.000000000 +0100
27016 +++ linux-2.6.32.1-vs2.3.0.36.27/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.1/net/ipv4/af_inet.c linux-2.6.32.1-vs2.3.0.36.27/net/ipv4/af_inet.c
27085 --- linux-2.6.32.1/net/ipv4/af_inet.c   2009-12-03 20:02:59.000000000 +0100
27086 +++ linux-2.6.32.1-vs2.3.0.36.27/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.1/net/ipv4/devinet.c linux-2.6.32.1-vs2.3.0.36.27/net/ipv4/devinet.c
27164 --- linux-2.6.32.1/net/ipv4/devinet.c   2009-12-03 20:02:59.000000000 +0100
27165 +++ linux-2.6.32.1-vs2.3.0.36.27/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.1/net/ipv4/fib_hash.c linux-2.6.32.1-vs2.3.0.36.27/net/ipv4/fib_hash.c
27233 --- linux-2.6.32.1/net/ipv4/fib_hash.c  2009-09-10 15:26:29.000000000 +0200
27234 +++ linux-2.6.32.1-vs2.3.0.36.27/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.1/net/ipv4/inet_connection_sock.c linux-2.6.32.1-vs2.3.0.36.27/net/ipv4/inet_connection_sock.c
27245 --- linux-2.6.32.1/net/ipv4/inet_connection_sock.c      2009-12-03 20:02:59.000000000 +0100
27246 +++ linux-2.6.32.1-vs2.3.0.36.27/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.1/net/ipv4/inet_diag.c linux-2.6.32.1-vs2.3.0.36.27/net/ipv4/inet_diag.c
27301 --- linux-2.6.32.1/net/ipv4/inet_diag.c 2009-09-10 15:26:29.000000000 +0200
27302 +++ linux-2.6.32.1-vs2.3.0.36.27/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.1/net/ipv4/inet_hashtables.c linux-2.6.32.1-vs2.3.0.36.27/net/ipv4/inet_hashtables.c
27405 --- linux-2.6.32.1/net/ipv4/inet_hashtables.c   2009-06-11 17:13:29.000000000 +0200
27406 +++ linux-2.6.32.1-vs2.3.0.36.27/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.1/net/ipv4/netfilter/nf_nat_helper.c linux-2.6.32.1-vs2.3.0.36.27/net/ipv4/netfilter/nf_nat_helper.c
27444 --- linux-2.6.32.1/net/ipv4/netfilter/nf_nat_helper.c   2009-12-03 20:02:59.000000000 +0100
27445 +++ linux-2.6.32.1-vs2.3.0.36.27/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.1/net/ipv4/netfilter.c linux-2.6.32.1-vs2.3.0.36.27/net/ipv4/netfilter.c
27455 --- linux-2.6.32.1/net/ipv4/netfilter.c 2009-09-10 15:26:29.000000000 +0200
27456 +++ linux-2.6.32.1-vs2.3.0.36.27/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.1/net/ipv4/raw.c linux-2.6.32.1-vs2.3.0.36.27/net/ipv4/raw.c
27467 --- linux-2.6.32.1/net/ipv4/raw.c       2009-12-03 20:02:59.000000000 +0100
27468 +++ linux-2.6.32.1-vs2.3.0.36.27/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.1/net/ipv4/tcp.c linux-2.6.32.1-vs2.3.0.36.27/net/ipv4/tcp.c
27571 --- linux-2.6.32.1/net/ipv4/tcp.c       2009-12-03 20:02:59.000000000 +0100
27572 +++ linux-2.6.32.1-vs2.3.0.36.27/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.1/net/ipv4/tcp_ipv4.c linux-2.6.32.1-vs2.3.0.36.27/net/ipv4/tcp_ipv4.c
27582 --- linux-2.6.32.1/net/ipv4/tcp_ipv4.c  2009-12-03 20:03:00.000000000 +0100
27583 +++ linux-2.6.32.1-vs2.3.0.36.27/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.1/net/ipv4/tcp_minisocks.c linux-2.6.32.1-vs2.3.0.36.27/net/ipv4/tcp_minisocks.c
27692 --- linux-2.6.32.1/net/ipv4/tcp_minisocks.c     2009-12-03 20:03:00.000000000 +0100
27693 +++ linux-2.6.32.1-vs2.3.0.36.27/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.1/net/ipv4/udp.c linux-2.6.32.1-vs2.3.0.36.27/net/ipv4/udp.c
27718 --- linux-2.6.32.1/net/ipv4/udp.c       2009-12-03 20:03:00.000000000 +0100
27719 +++ linux-2.6.32.1-vs2.3.0.36.27/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.1/net/ipv6/addrconf.c linux-2.6.32.1-vs2.3.0.36.27/net/ipv6/addrconf.c
27850 --- linux-2.6.32.1/net/ipv6/addrconf.c  2009-12-03 20:03:00.000000000 +0100
27851 +++ linux-2.6.32.1-vs2.3.0.36.27/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.1/net/ipv6/af_inet6.c linux-2.6.32.1-vs2.3.0.36.27/net/ipv6/af_inet6.c
27952 --- linux-2.6.32.1/net/ipv6/af_inet6.c  2009-12-03 20:03:00.000000000 +0100
27953 +++ linux-2.6.32.1-vs2.3.0.36.27/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.1/net/ipv6/fib6_rules.c linux-2.6.32.1-vs2.3.0.36.27/net/ipv6/fib6_rules.c
28050 --- linux-2.6.32.1/net/ipv6/fib6_rules.c        2009-09-10 15:26:30.000000000 +0200
28051 +++ linux-2.6.32.1-vs2.3.0.36.27/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.1/net/ipv6/inet6_hashtables.c linux-2.6.32.1-vs2.3.0.36.27/net/ipv6/inet6_hashtables.c
28062 --- linux-2.6.32.1/net/ipv6/inet6_hashtables.c  2009-03-24 14:22:46.000000000 +0100
28063 +++ linux-2.6.32.1-vs2.3.0.36.27/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.1/net/ipv6/ip6_output.c linux-2.6.32.1-vs2.3.0.36.27/net/ipv6/ip6_output.c
28100 --- linux-2.6.32.1/net/ipv6/ip6_output.c        2009-12-03 20:03:00.000000000 +0100
28101 +++ linux-2.6.32.1-vs2.3.0.36.27/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.1/net/ipv6/Kconfig linux-2.6.32.1-vs2.3.0.36.27/net/ipv6/Kconfig
28112 --- linux-2.6.32.1/net/ipv6/Kconfig     2009-09-10 15:26:30.000000000 +0200
28113 +++ linux-2.6.32.1-vs2.3.0.36.27/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.1/net/ipv6/ndisc.c linux-2.6.32.1-vs2.3.0.36.27/net/ipv6/ndisc.c
28126 --- linux-2.6.32.1/net/ipv6/ndisc.c     2009-12-03 20:03:00.000000000 +0100
28127 +++ linux-2.6.32.1-vs2.3.0.36.27/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.1/net/ipv6/raw.c linux-2.6.32.1-vs2.3.0.36.27/net/ipv6/raw.c
28138 --- linux-2.6.32.1/net/ipv6/raw.c       2009-12-03 20:03:00.000000000 +0100
28139 +++ linux-2.6.32.1-vs2.3.0.36.27/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.1/net/ipv6/route.c linux-2.6.32.1-vs2.3.0.36.27/net/ipv6/route.c
28163 --- linux-2.6.32.1/net/ipv6/route.c     2009-12-03 20:03:00.000000000 +0100
28164 +++ linux-2.6.32.1-vs2.3.0.36.27/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.1/net/ipv6/tcp_ipv6.c linux-2.6.32.1-vs2.3.0.36.27/net/ipv6/tcp_ipv6.c
28176 --- linux-2.6.32.1/net/ipv6/tcp_ipv6.c  2009-12-03 20:03:00.000000000 +0100
28177 +++ linux-2.6.32.1-vs2.3.0.36.27/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.1/net/ipv6/udp.c linux-2.6.32.1-vs2.3.0.36.27/net/ipv6/udp.c
28205 --- linux-2.6.32.1/net/ipv6/udp.c       2009-12-03 20:03:00.000000000 +0100
28206 +++ linux-2.6.32.1-vs2.3.0.36.27/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.1/net/ipv6/xfrm6_policy.c linux-2.6.32.1-vs2.3.0.36.27/net/ipv6/xfrm6_policy.c
28283 --- linux-2.6.32.1/net/ipv6/xfrm6_policy.c      2009-12-03 20:03:00.000000000 +0100
28284 +++ linux-2.6.32.1-vs2.3.0.36.27/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.1/net/netlink/af_netlink.c linux-2.6.32.1-vs2.3.0.36.27/net/netlink/af_netlink.c
28295 --- linux-2.6.32.1/net/netlink/af_netlink.c     2009-12-03 20:03:01.000000000 +0100
28296 +++ linux-2.6.32.1-vs2.3.0.36.27/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.1/net/sctp/ipv6.c linux-2.6.32.1-vs2.3.0.36.27/net/sctp/ipv6.c
28337 --- linux-2.6.32.1/net/sctp/ipv6.c      2009-12-03 20:03:01.000000000 +0100
28338 +++ linux-2.6.32.1-vs2.3.0.36.27/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.1/net/socket.c linux-2.6.32.1-vs2.3.0.36.27/net/socket.c
28350 --- linux-2.6.32.1/net/socket.c 2009-12-03 20:03:01.000000000 +0100
28351 +++ linux-2.6.32.1-vs2.3.0.36.27/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.1/net/sunrpc/auth.c linux-2.6.32.1-vs2.3.0.36.27/net/sunrpc/auth.c
28461 --- linux-2.6.32.1/net/sunrpc/auth.c    2009-12-03 20:03:01.000000000 +0100
28462 +++ linux-2.6.32.1-vs2.3.0.36.27/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.1/net/sunrpc/auth_unix.c linux-2.6.32.1-vs2.3.0.36.27/net/sunrpc/auth_unix.c
28488 --- linux-2.6.32.1/net/sunrpc/auth_unix.c       2008-12-25 00:26:37.000000000 +0100
28489 +++ linux-2.6.32.1-vs2.3.0.36.27/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.1/net/sunrpc/clnt.c linux-2.6.32.1-vs2.3.0.36.27/net/sunrpc/clnt.c
28549 --- linux-2.6.32.1/net/sunrpc/clnt.c    2009-12-03 20:03:01.000000000 +0100
28550 +++ linux-2.6.32.1-vs2.3.0.36.27/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.1/net/unix/af_unix.c linux-2.6.32.1-vs2.3.0.36.27/net/unix/af_unix.c
28570 --- linux-2.6.32.1/net/unix/af_unix.c   2009-12-03 20:03:01.000000000 +0100
28571 +++ linux-2.6.32.1-vs2.3.0.36.27/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.1/net/x25/af_x25.c linux-2.6.32.1-vs2.3.0.36.27/net/x25/af_x25.c
28610 --- linux-2.6.32.1/net/x25/af_x25.c     2009-12-03 20:03:01.000000000 +0100
28611 +++ linux-2.6.32.1-vs2.3.0.36.27/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.1/scripts/checksyscalls.sh linux-2.6.32.1-vs2.3.0.36.27/scripts/checksyscalls.sh
28625 --- linux-2.6.32.1/scripts/checksyscalls.sh     2009-09-10 15:26:31.000000000 +0200
28626 +++ linux-2.6.32.1-vs2.3.0.36.27/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.1/security/commoncap.c linux-2.6.32.1-vs2.3.0.36.27/security/commoncap.c
28636 --- linux-2.6.32.1/security/commoncap.c 2009-12-03 20:03:02.000000000 +0100
28637 +++ linux-2.6.32.1-vs2.3.0.36.27/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.1/security/selinux/hooks.c linux-2.6.32.1-vs2.3.0.36.27/security/selinux/hooks.c
28712 --- linux-2.6.32.1/security/selinux/hooks.c     2009-12-03 20:03:02.000000000 +0100
28713 +++ linux-2.6.32.1-vs2.3.0.36.27/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.1/security/selinux/include/av_permissions.h linux-2.6.32.1-vs2.3.0.36.27/security/selinux/include/av_permissions.h
28723 --- linux-2.6.32.1/security/selinux/include/av_permissions.h    2009-12-03 20:03:02.000000000 +0100
28724 +++ linux-2.6.32.1-vs2.3.0.36.27/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.1/security/selinux/include/av_perm_to_string.h linux-2.6.32.1-vs2.3.0.36.27/security/selinux/include/av_perm_to_string.h
28734 --- linux-2.6.32.1/security/selinux/include/av_perm_to_string.h 2009-12-03 20:03:02.000000000 +0100
28735 +++ linux-2.6.32.1-vs2.3.0.36.27/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.359994 seconds and 3 git commands to generate.